예제 #1
0
파일: eightball.c 프로젝트: danopia/atheme
static void command_eightball(sourceinfo_t *si, int parc, char *parv[])
{
	static const char *eightball_responses[28] = {
		N_("Absolutely yes!"),
		N_("Prospect looks hopeful."),
		N_("I'd like to think so."),
		N_("Yes, yes, yes, and yes again."),
		N_("Most likely."),
		N_("All signs point to yes."),
		N_("Yes."),
		N_("Without a doubt."),
		N_("Sometime in the near future."),
		N_("Of course!"),
		N_("Definitely."),
		N_("Answer hazy."),
		N_("Prospect looks bleak."),
		N_("That's a question you should ask yourself."),
		N_("Maybe."),
		N_("That question is better remained unanswered."),
		N_("The stars would have to align for that to happen."),
		N_("No."),
		N_("Not even on a GOOD day."),
		N_("It would take a disturbed person to even ask."),
		N_("You wish."),
		N_("Not bloody likely."),
		N_("No way."),
		N_("Never."),
		N_("NO!"),
		N_("Over my dead body."),
		N_("We won't go there"),
		N_("No chance at all!")
	};

	gs_command_report(si, "%s", eightball_responses[rand() % 28]);
}
static void command_roulette(sourceinfo_t *si, int parc, char *parv[])
{
	static const char *roulette_responses[2] = {
		N_("*BANG*"),
		N_("*CLICK*")
	};

	gs_command_report(si, "%s", roulette_responses[rand() % 6 == 0]);
}
예제 #3
0
static void command_rps(sourceinfo_t *si, int parc, char *parv[])
{
	mychan_t *mc;
	static const char *rps_responses[3] = {
		N_("Rock"),
		N_("Paper"),
		N_("Scissors")
	};

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;

	gs_command_report(si, "%s", _(rps_responses[rand() % 3]));
}
예제 #4
0
파일: dice.c 프로젝트: Acidburn0zzz/atheme
static void command_dice(sourceinfo_t *si, int parc, char *parv[])
{
	char *arg;
	mychan_t *mc;
	int i, times = 1;

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;
	if (parc < 1)
	{
		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "ROLL");
		command_fail(si, fault_needmoreparams, _("Syntax: ROLL [times] [dice]d<sides>"));
		return;
	}
	if (parc < 2)
		arg = parv[0];
	else
	{
		times = atoi(parv[0]);
		arg = parv[1];

		if (times > 10)
			times = 10;
	}

	if (!strcasecmp("RICK", arg))
	{
		gs_command_report(si, "Never gonna give you up; Never gonna let you down");
		gs_command_report(si, "Never gonna run around and desert you; Never gonna make you cry");
		gs_command_report(si, "Never gonna say goodbye; Never gonna tell a lie and hurt you");
		return;
	}

	for (i = 0; i < times; i++)
		if(!eval_dice(si, arg))
			break;
}
예제 #5
0
static void
command_namegen(struct sourceinfo *si, int parc, char *parv[])
{
	unsigned int iter;
	unsigned int amt = 20;
	char buf[BUFSIZE];
	struct mychan *mc;

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;

	if (parv[0])
		amt = atoi(parv[0]);


	// limit to 20
	if (amt > 20)
		amt = 20;

	*buf = '\0';

	for (iter = 0; iter < amt; iter++)
	{
		char namebuf[BUFSIZE];
		unsigned int medial_iter;

		// Here we generate the name.
		mowgli_strlcpy(namebuf, begin_sym[rand() % BEGIN_SYM_SZ], BUFSIZE);

		for (medial_iter = rand() % 3; medial_iter > 0; medial_iter--)
			mowgli_strlcat(namebuf, medial_sym[rand() % MEDIAL_SYM_SZ], BUFSIZE);

		mowgli_strlcat(namebuf, end_sym[rand() % END_SYM_SZ], BUFSIZE);

		if (iter == 0)
			mowgli_strlcpy(buf, namebuf, BUFSIZE);
		else
			mowgli_strlcat(buf, namebuf, BUFSIZE);

		mowgli_strlcat(buf, iter + 1 < amt ? ", " : ".", BUFSIZE);
	}

	gs_command_report(si, _("Some names to ponder: %s"), buf);
}
예제 #6
0
파일: lottery.c 프로젝트: Gryllida/atheme
static void command_lottery(sourceinfo_t *si, int parc, char *parv[])
{
	mychan_t *mc;
	user_t *u;

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;

	if (si->c == NULL)
	{
		command_fail(si, fault_nosuch_target, _("This command may only be used on a channel."));
		return;
	}

	u = pick_a_sucker(si->c);
	return_if_fail(u != NULL);

	gs_command_report(si, "%s", u->nick);
}
예제 #7
0
파일: gamecalc.c 프로젝트: Canternet/atheme
static void command_df(sourceinfo_t *si, int parc, char *parv[])
{
	mychan_t *mc;
	char *arg_dice;
	char buf[BUFSIZE];
	int i, dice;

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;
	if (parc < 1)
	{
		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "DF");
		command_fail(si, fault_needmoreparams, _("Syntax: DF <dice>"));
		return;
	}
	arg_dice = parv[0];

	dice = atoi(arg_dice);
	*buf = '\0';

	if (dice > 30 || dice < 1)
	{
		command_fail(si, fault_badparams, _("Only 1-30 dice may be thrown at one time."));
		return;
	}

	for (i = 0; i < dice; i++)
	{
		int roll = arc4random() % 3;

		if (*buf != '\0')
			mowgli_strlcat(buf, df_dice_table[roll], BUFSIZE);
		else
			mowgli_strlcpy(buf, df_dice_table[roll], BUFSIZE);
	}

	gs_command_report(si, _("Result: %s"), buf);
}
예제 #8
0
파일: gamecalc.c 프로젝트: Canternet/atheme
static void command_wod(sourceinfo_t *si, int parc, char *parv[])
{
	mychan_t *mc;
	char *arg_dice, *arg_difficulty;
	int ii = 0;
	int dice, difficulty;
	int roll, total, roll_count = 0, i;
	int success = 0, failure = 0, botches = 0, rerolls = 0;
	static char buf[BUFSIZE];
	char *end_p;

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;
	if (parc < 2)
	{
		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "WOD");
		command_fail(si, fault_needmoreparams, _("Syntax: WOD <dice> <difficulty>"));
		return;
	}
	arg_dice = parv[ii++];
	arg_difficulty = parv[ii++];

	while (roll_count < 3 && arg_dice != NULL && arg_difficulty != NULL)
	{
		success = 0, failure = 0, botches = 0, rerolls = 0;
		roll_count++;

		dice = atoi(arg_dice);
		difficulty = atoi(arg_difficulty);

		if (dice > 30 || dice < 1)
		{
			command_fail(si, fault_badparams, _("Only 1-30 dice may be thrown at one time."));
			return;
		}
		else if (difficulty > 10 || difficulty < 1)
		{
			command_fail(si, fault_badparams, _("Difficulty setting must be between 1 and 10."));
			return;
		}
		else
		{
			end_p = buf;

			for (i = 0; i < dice; i++)
			{
				roll = (arc4random() % 10) + 1;

				end_p += snprintf(end_p, BUFSIZE - (end_p - buf), "%d  ", roll);

				if (roll == 1)
				{
					botches++;
					continue;
				}
				else if (roll == 10)
					rerolls++;

				if (roll >= difficulty)
					success++;
				else
					failure++;
			}

			rerolls = rerolls - botches;
			total = success - botches;

			gs_command_report(si, _("%s rolls %d dice at difficulty %d: %s"), si->su->nick, dice, difficulty, buf);

			if (rerolls > 0)
				gs_command_report(si, _("Successes: %d, Failures: %d, Botches: %d, Total: %d. You may reroll %d if you have a specialty."),
					success, failure, botches, total, rerolls);
			else
				gs_command_report(si, _("Successes: %d, Failures: %d, Botches: %d, Total: %d."),
					success, failure, botches, total);
		}

		/* prepare for another go. */
		arg_dice = parv[ii++];
		arg_difficulty = parv[ii++];
	}
}
예제 #9
0
파일: gamecalc.c 프로젝트: Canternet/atheme
static void command_nwod(sourceinfo_t *si, int parc, char *parv[])
{
	mychan_t *mc;
	char *arg_dice, *arg_rerollflag;
	int ii = 0;
	int dice, reroll;
	int roll, total, roll_count = 0, i;
	int success = 0, failure = 0, botches = 0, rerolls = 0;
	static char buf[BUFSIZE];
	char *end_p;

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;
	if (parc < 2)
	{
		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "NWOD");
		command_fail(si, fault_needmoreparams, _("Syntax: NWOD [-chance] <dice> [-reroll] [reroll]"));
		return;
	}
	arg_dice = parv[ii++];
	arg_rerollflag = parv[ii++];

	while (roll_count < 3 && arg_dice != NULL)
	{
		success = 0, failure = 0, botches = 0, rerolls = 0;
		roll_count++;

		dice = atoi(arg_dice);

		if (dice == 0 && !strcasecmp(arg_dice, "-chance"))
		{
			roll = (arc4random() % 10) + 1;

			if (roll == 1)
				botches++;

			if (roll == 10)
				success++;

			gs_command_report(si, _("%s rolls a chance die: %d"), si->su->nick, roll);
			gs_command_report(si, _("Successes: %d, Failures: %d, Botches: %d."), success, failure, botches);
			return;
		}

		if (dice > 30 || dice < 1)
		{
			command_fail(si, fault_badparams, _("Only 1-30 dice may be thrown at one time."));
			return;
		}

		if (arg_rerollflag != NULL && !strcasecmp(arg_rerollflag, "-reroll") && parv[ii + 1] != NULL)
			reroll = atoi(parv[ii++]);
		else
			reroll = 10;

		{
			end_p = buf;

			for (i = 0; i < dice; i++)
			{
				roll = (arc4random() % 10) + 1;

				end_p += snprintf(end_p, BUFSIZE - (end_p - buf), "%d  ", roll);

				if (roll == 1)
				{
					botches++;
					continue;
				}
				else if (roll >= reroll)
					rerolls++;

				if (roll >= 8)
					success++;
				else
					failure++;
			}

			rerolls = rerolls - botches;
			total = success - botches;

			gs_command_report(si, _("%s rolls %d dice: %s"), si->su->nick, dice, buf);

			if (rerolls > 0)
				gs_command_report(si, _("Successes: %d, Failures: %d, Botches: %d, Total: %d. You may reroll %d."),
					success, failure, botches, total, rerolls);
			else
				gs_command_report(si, _("Successes: %d, Failures: %d, Botches: %d, Total: %d."),
					success, failure, botches, total);
		}

		/* prepare for another go. */
		arg_dice = parv[ii++];
		arg_rerollflag = parv[ii++];
	}
}
예제 #10
0
파일: dice.c 프로젝트: Snoonet/atheme
//
// <expr>
//   expr = {<op>(<expr>)}|{<op><expr>}
//   op   = { ~ ! d * / % \ ^ + - & $ | }
//
// [Rank 1]                        |  [Rank 4]
// ~   = One's compliment          |  + - = Add / Subtract
// !   = Logical NOT               |
// d   = Dice Generator, LOL.      |  [Rank 5]
//                                 |  &   = Bitwise AND
// [Rank 2]                        |  
// ^   = Power                     |  [Rank 6]
//                                 |  $   = Bitwise XOR (eXclusive OR)
// [Rank 3]                        |  
// * / = Multiply / Divide         |  [Rank 7]
// % \ = Modulus / Integer-divide  |  |   = Bitwise inclusive OR
//
static void eval_calc(sourceinfo_t *si, char *s_input)
{
	static char buffer[1024];

	char *ci = s_input;

	int err, braces = 0;
	double expr;


	if (s_input == NULL)
	{
		command_fail(si, fault_badparams, _("Error: You typed an invalid expression."));
		return;
	}

	// Skip leading whitespace
	while (*ci && isspace(*ci))
		ci++;

	if (!*ci)
	{
		command_fail(si, fault_badparams, _("Error: You typed an invalid expression."));
		return;
	}

	// Validate braces
	while (*ci)
	{
		if (*ci == '(')
		{
			braces++;
		}
		else if (*ci == ')')
		{
			if (--braces < 0)
				break;	// mismatched!
		}
		else if (!isspace(*ci) && !isdigit(*ci) && *ci != '.' && !is_calcoper(*ci))
		{
			command_fail(si, fault_badparams, _("Error: You typed an invalid expression."));
			return;
		}
		ci++;
	}

	if (braces != 0)
	{
		command_fail(si, fault_badparams, _("Error: Mismatched braces '( )' in expression."));
		return;
	}

	err = do_calc_expr(si, s_input, buffer, &expr);

	if (!err)
	{
		if (strlen(s_input) > 250)
		{
			mowgli_strlcpy(buffer, s_input, 150);
			sprintf(&buffer[150], "...%s = %.8g", &s_input[strlen(s_input) - 10], expr);
		}
		else
		{
			sprintf(buffer, "%s = %.8g", s_input, expr);
		}
	}
	else
		return;

	gs_command_report(si, "%s", buffer);
}
예제 #11
0
파일: dice.c 프로젝트: Snoonet/atheme
static void eval_dice(sourceinfo_t *si, char *s_input)
{
	static char buffer[1024], result[32];

	char op = '\0', *c = s_input;
	unsigned int dice, roll, x, y, z = 0;
	double total;

	while (*c && isspace(*c))
		++c;
	if (!*c || !isdigit(*c))
	{
		gs_command_report(si, _("Syntax: XdY [ {-|+|*|/} Z ]"));
		return;
	}

	x = strtoul(c, &c, 10);
	if (x == 0 || c == NULL || ToLower(*c++) != 'd' || !isdigit(*c))
	{
		if (x < 1 || x > DICE_MAX_DICE)
		{
			gs_command_report(si, _("Only 1-100 dice may be thrown at once."));
			return;
		}

		gs_command_report(si, _("Syntax: XdY [ {-|+|*|/} Z ]"));
		return;
	}

	y = strtoul(c, &c, 10);
	if (c != NULL)
	{
		while (*c && isspace(*c))
			++c;

		if (*c && strchr("-+*/", *c) == NULL)
		{
			gs_command_report(si, _("Syntax: XdY [ {-|+|*|/} Z ]"));
			return;
		}
	}

	if (x < 1 || x > 100)
	{
		gs_command_report(si, _("Syntax: XdY [ {-|+|*|/} Z ]"));
		return;
	}

	if (y < 1 || y > DICE_MAX_SIDES)
	{
		gs_command_report(si, _("Only 1-100 sides may be used on a dice."));
		return;
	}

	if (*c)
	{
		op = *c++;

		z = strtoul(c, &c, 10);

		while (*c && isspace(*c))
			++c;

		if (*c)
		{
			gs_command_report(si, _("Syntax: XdY [ {-|+|*|/} Z ]"));
			return;
		}
		else if (op == '/' && z == 0)
		{
			gs_command_report(si, _("Can't divide by zero."));
			return;
		}
	}

	total = 0.0;
	snprintf(buffer, 1024, "\2%s\2 rolled %ud%u: ", si->su->nick, x, y);
	for (roll = 0; roll < x; ++roll)
	{
		snprintf(result, 32, "%d ", dice = (1 + (arc4random() % y)));
		mowgli_strlcat(buffer, result, sizeof(buffer));
		total += dice;
	}

	if (op == '\0')
		snprintf(result, 32, " <Total: %g>", total);
	else
	{
		snprintf(result, 32, " <Total: %g(%c%u) = ", total, op, z);
		mowgli_strlcat(buffer, result, sizeof(buffer));
		switch (op)
		{
		  case '+':
			  total += z;
			  break;
		  case '-':
			  total -= z;
			  break;
		  case '/':
			  total /= z;
			  break;
		  case '*':
			  total *= z;
			  break;
		  default:
			  break;
		}
		snprintf(result, 32, "%g>", total);
	}
	mowgli_strlcat(buffer, result, sizeof(buffer));

	gs_command_report(si, "%s", buffer);
}
예제 #12
0
static void command_eightball(sourceinfo_t *si, int parc, char *parv[])
{
	mychan_t *mc;

	if (!gs_do_parameters(si, &parc, &parv, &mc))
		return;

	static const char *eightball_responses[28] = {
		N_("Absolutely yes!"),
		N_("Prospect looks hopeful."),
		N_("I'd like to think so."),
		N_("Yes, yes, yes, and yes again."),
		N_("Most likely."),
		N_("All signs point to yes."),
		N_("Yes."),
		N_("Without a doubt."),
		N_("Sometime in the near future."),
		N_("Of course!"),
		N_("Definitely."),
		N_("Answer hazy."),
		N_("Prospect looks bleak."),
		N_("That's a question you should ask yourself."),
		N_("Maybe."),
		N_("That question is better remained unanswered."),
		N_("The stars would have to align for that to happen."),
		N_("No."),
		N_("Not even on a GOOD day."),
		N_("It would take a disturbed person to even ask."),
		N_("You wish."),
		N_("Not bloody likely."),
		N_("No way."),
		N_("Never."),
		N_("NO!"),
		N_("Over my dead body."),
		N_("We won't go there"),
		N_("No chance at all!")
	};

	static const char *alcohol[21] = {
		"booze",
		"rum",
		"vodka",
		"gin",
		"tequila",
		"beer",
		"wine",
		"cider",
		"liquor",
		"bourbon",
		"drink",
		"whiskey",
		"scotch",
		"mead",
		"schnapps",
		"liquer",
		"sake",
		"sochu",
		"rye",
		"absinthe",
		"jager"
	};


        if(parv)
        {
		for(int i = 0; i < parc; i++)
			for(int j = 0; parv[i][j]; j++)
				parv[i][j] = tolower(parv[i][j]);
                
		for(int i = 0; i < parc; i++)
		{
			for(int j = 0; j < 21; j++)
			{
				if(strstr(parv[i],alcohol[j]) != 0)
	                	{
                        	gs_command_report(si, "%s", eightball_responses[rand() % 11]);
				return;
            		 	}
			}
		}
        }

	gs_command_report(si, "%s", eightball_responses[rand() % 28]);
}