private double EvaluateReward(SlotInternalNames[] slotsChosen, out SlotResults slotResult) { //For this implementation, reward the user only if all of the slots match SlotInternalNames firstSlot = slotsChosen[0]; for (int i = 1; i < slotsChosen.Length; i++) { //Slots don't match, so no reward if (slotsChosen[i] != firstSlot) { slotResult = SlotResults.Nothing; return(0d); } } //Get the reward modifier for this slot double modifier = SlotRewardModifiers[firstSlot]; //If the user didn't actually win anything, show it as a loss if (modifier <= 0d) { slotResult = SlotResults.Nothing; } //If the user got the highest reward modifier, they hit the jackpot! else if (modifier == HighestRewardMod) { slotResult = SlotResults.Jackpot; } //Standard result else { slotResult = SlotResults.Standard; } return(modifier); }
public override void ExecuteCommand(EvtChatCommandArgs args) { List <string> arguments = args.Command.ArgumentsAsList; if (arguments.Count != 1) { QueueMessage(UsageMessage); return; } //Start off getting the credits name string creditsName = DataHelper.GetCreditsName(); string userName = args.Command.ChatMessage.Username; long curUserCredits = 0; using (BotDBContext context = DatabaseManager.OpenContext()) { //Get the user User user = DataHelper.GetUserNoOpen(userName, context); if (user == null) { QueueMessage("You're somehow not in the database!"); return; } //Can't play without the ability if (user.HasEnabledAbility(PermissionConstants.SLOTS_ABILITY) == false) { QueueMessage("You don't have the ability to play the slots!"); return; } //Check for opt-out if (user.IsOptedOut == true) { QueueMessage("You cannot play the slots while opted out of stats."); return; } curUserCredits = user.Stats.Credits; } string buyInStr = arguments[0]; //If the user asks for info, print the infom essage if (buyInStr == INFO_ARG) { PrintInfoMessage(); return; } //Validate argument if (long.TryParse(buyInStr, out long buyInAmount) == false) { QueueMessage(UsageMessage); return; } if (buyInAmount <= 0) { QueueMessage("Buy-in amount must be greater than 0!"); return; } if (buyInAmount > curUserCredits) { QueueMessage($"Buy-in amount is greater than {creditsName.Pluralize(false, 0)}!"); return; } //Roll the slots! StringBuilder strBuilder = new StringBuilder(128); strBuilder.Append('(').Append(' '); SlotInternalNames[] slotsChosen = new SlotInternalNames[WeightTable.Count]; int i = 0; foreach (KeyValuePair <int, List <ReelWeight> > weight in WeightTable) { SlotInternalNames chosenSlot = ChooseSlot(weight.Value); slotsChosen[i] = chosenSlot; string emote = DataHelper.GetSettingString(SlotToEmoteMap[chosenSlot], string.Empty); strBuilder.Append(emote).Append(' ').Append('|').Append(' '); i++; } strBuilder.Remove(strBuilder.Length - 3, 3); strBuilder.Append(' ').Append(')').Append(" = "); //Evaluate the reward based on what we got double rewardModifier = EvaluateReward(slotsChosen, out SlotResults slotResult); //Intentionally floor the reward - slots are like that :P long reward = (long)(buyInAmount * rewardModifier); //Change the message based on the result switch (slotResult) { case SlotResults.Nothing: strBuilder.Append(userName).Append(" didn't win BibleThump Better luck next time!"); break; case SlotResults.Standard: strBuilder.Append(userName).Append(" won ").Append(reward).Append(' ').Append(creditsName.Pluralize(false, reward)).Append(", nice! SeemsGood"); break; case SlotResults.Jackpot: strBuilder.Append(userName).Append(" hit the JACKPOT and won ").Append(reward).Append(' ').Append(creditsName.Pluralize(false, reward)).Append("!! Congratulations!! PogChamp PogChamp PogChamp"); break; } using (BotDBContext context = DatabaseManager.OpenContext()) { //Modify credits User user = DataHelper.GetUserNoOpen(userName, context); //Adjust credits and save user.Stats.Credits -= buyInAmount; user.Stats.Credits += reward; context.SaveChanges(); } QueueMessage(strBuilder.ToString()); }