/// <summary> /// Starts a vote on a question or whatever. /// </summary> /// <param name="callback"></param> /// <param name="args"></param> public void Vote(SteamFriends.ChatMsgCallback callback, string[] args) { if (_voting || args.Length < 2) { return; } var sentence = args.Skip(1).Aggregate((current, next) => current + " " + next); sentence = sentence.Trim(); SteamNerd.SendMessage("Voting has started! Type aye or nay to vote.", callback.ChatRoomID); SteamNerd.SendMessage(sentence, callback.ChatRoomID); // Reset ayes and nays _ayes = _nays = 0; _voters = new List <SteamID>(); _voting = true; _voteTimer = new Timer(30000); _voteTimer.AutoReset = false; _voteTimer.Elapsed += (src, e) => TallyVotes(callback); _voteTimer.Start(); }
public void Insure(SteamFriends.ChatMsgCallback callback, string[] args) { if (!_canInsure) { return; } var chat = callback.ChatRoomID; var playerID = callback.ChatterID; var name = SteamNerd.ChatterNames[playerID]; var player = _players[playerID]; var bet = player.Bet / 2; if (player.HasInsurance == false) { if (_moneyModule.GetPlayerMoney(playerID) < bet) { SteamNerd.SendMessage(string.Format("{0}, you don't have ${1}! You can't buy insurance!", name, bet), chat); return; } player.HasInsurance = true; SteamNerd.SendMessage(string.Format("{0} bought insurance for ${1}.", name, bet), chat); _moneyModule.AddMoney(playerID, chat, -bet); } // Done paying out _canInsure = false; }
public void GetLoan(SteamFriends.ChatMsgCallback callback, string[] args) { if (args.Length < 2) { SteamNerd.SendMessage(string.Format("Usage: {0}loan [money]", SteamNerd.CommandChar), callback.ChatRoomID); return; } var chatter = callback.ChatterID; if (!_money.ContainsKey(chatter)) { AddSteamID(chatter); } var name = SteamNerd.ChatterNames[chatter]; var money = _money[chatter]; var loans = _loans[chatter]; int amount; if (!int.TryParse(args[1], out amount)) { SteamNerd.SendMessage(string.Format("{0}, that's not a number", name), callback.ChatRoomID); return; } if (amount < 0) { SteamNerd.SendMessage(string.Format("{0}, you can't borrow negative money", name), callback.ChatRoomID); return; } AddMoney(chatter, callback.ChatRoomID, amount); AddLoan(chatter, callback.ChatRoomID, amount); }
public void GetTodo(SteamFriends.ChatMsgCallback callback, string[] args) { if (args.Length == 1) { PrintTodo(callback); } else { var subcommand = args[1]; switch (subcommand) { case "add": AddTodo(callback.ChatRoomID, args); break; case "remove": RemoveTodo(callback.ChatRoomID, args); break; default: var message = string.Format("Unknown subcommand. Use {0}help for help.", SteamNerd.CommandChar); SteamNerd.SendMessage(message, callback.ChatRoomID); break; } } }
/// <summary> /// Hits the dealer. /// </summary> /// <param name="chat">The chatroom for printing.</param> /// <returns>The dealt card was an Ace.</returns> private bool DealerHit() { SteamNerd.SendMessage("Dealer hits!", _chat); Deal(_dealerHand); return(_dealerHand.Cards.Last().Rank == Deck.Rank.Ace); }
public void DoTheBet(SteamFriends.ChatMsgCallback callback, string[] args) { var chat = callback.ChatRoomID; var chatter = callback.ChatterID; var name = SteamNerd.ChatterNames[chatter]; // If someone bets early if (!_inProgress) { SteamNerd.SendMessage(string.Format("There's no match to bet on, {0}. Good job, idiot.", name), chat); } else if (!_betTimerOver) { if (args.Length < 3) { SteamNerd.SendMessage(string.Format("Usage: {0}bet [player] [money]", SteamNerd.CommandChar), chat); return; } int bet; if (!int.TryParse(args[2], out bet)) { SteamNerd.SendMessage(string.Format("Usage: {0}bet [player] [money]", SteamNerd.CommandChar), chat); return; } AddBet(callback.ChatterID, callback.ChatRoomID, args[1], bet); } }
private void StartBetting(SteamID chatroom) { // Get names var player1 = SteamNerd.ChatterNames[_players[0]]; var player2 = SteamNerd.ChatterNames[_players[1]]; // Set flags _betTimerOver = false; _inProgress = true; // Calculate the player pool _pool = _currentBet * 2; var startMessage = string.Format("Wow! {0} and {1} are going head to head!\n" + "Place your bets using !bet [player] [money].\n" + "You have 30 seconds. All bets are double or nothing.", player1, player2); SteamNerd.SendMessage(startMessage, chatroom); _betTimer = new Timer(30000); _betTimer.Elapsed += (src, e) => { StartRoulette(chatroom); }; _betTimer.AutoReset = false; _betTimer.Start(); for (int i = 3; i > 0; i--) { var timer = _countdown[i - 1]; var countdownString = string.Format("{0}...", i); timer = new Timer(30000 - i * 1000); timer.AutoReset = false; timer.Elapsed += (src, e) => SteamNerd.SendMessage(countdownString, chatroom);; timer.Start(); } }
private void AddBet(SteamID chatter, SteamID chat, string side, int bet) { var chatterName = SteamNerd.ChatterNames[chatter]; if (bet <= 0) { SteamNerd.SendMessage(string.Format("{0}, you gotta bet more than $0.", chatterName), chat); return; } if (_moneyModule.GetPlayerMoney(chatter) < bet) { SteamNerd.SendMessage(string.Format("{0}, you don't have ${1}", chatterName, bet), chat); return; } foreach (var player in _players) { var name = SteamNerd.ChatterNames[player].ToLower(); if (name.Contains(side)) { _moneyModule.AddMoney(chatter, chat, -bet); _bets.Add(new Bet { Better = chatter, Side = player, Money = bet }); return; } } SteamNerd.SendMessage(string.Format("Can't find player {0}", side), chat); }
/// <summary> /// Creates a /// </summary> /// <param name="callback"></param> /// <param name="time"></param> /// <param name="countdownStart"></param> public Countdown(SteamNerd steamNerd, SteamID chat, ElapsedEventHandler callback, float seconds, int countdownStart) { _countdownTimers = new Timer[countdownStart]; MainTimer = new Timer(seconds * 1000); MainTimer.AutoReset = false; MainTimer.Elapsed += callback; MainTimer.Start(); for (var i = 1; i <= countdownStart; i++) { if (seconds - i <= 0) { return; } var timer = new Timer(seconds - i); var countdownString = string.Format("{0}...", i); timer = new Timer((seconds - i) * 1000); timer.AutoReset = false; timer.Elapsed += (src, e) => steamNerd.SendMessage(countdownString, chat); timer.Start(); _countdownTimers[i - 1] = timer; } }
public void DoubleDown(SteamFriends.ChatMsgCallback callback, string[] args) { var playerID = callback.ChatterID; var player = _players[playerID]; var name = SteamNerd.ChatterNames[playerID]; var handNum = ParseHand(player, args); var hand = player.Hands[handNum]; if (hand.State != HandState.None || hand.Cards.Count > 2) { var errMsg = string.Format("{0}, you can't double down with this hand.", name); SteamNerd.SendMessage(errMsg, _chat); return; } if (_moneyModule.GetPlayerMoney(playerID) < player.Bet) { var errMsg = string.Format("{0}, don't have enough money to double down!", name); SteamNerd.SendMessage(errMsg, _chat); return; } _moneyModule.AddMoney(playerID, _chat, -player.Bet); Deal(hand); var value = hand.GetValue(); hand.State = value > 21 ? HandState.Bust : HandState.DoubleDown; PrintPlayersHands(playerID); CheckHands(); }
/// <summary> /// Checks if what a person typed was a vote and counts them. /// </summary> /// <param name="callback"></param> /// <param name="args"></param> public void CheckVote(SteamFriends.ChatMsgCallback callback, string[] args) { var name = SteamNerd.ChatterNames[callback.ChatterID]; var message = callback.Message.ToLower(); if (!_voting || _voters.Contains(callback.ChatterID)) { return; } if (message == "aye") { _ayes++; SteamNerd.SendMessage(string.Format("{0} voted aye", name), callback.ChatRoomID); } else if (message == "nay") { _nays++; SteamNerd.SendMessage(string.Format("{0} voted nay", name), callback.ChatRoomID); } else { return; } _voters.Add(callback.ChatterID); if (_voters.Count == SteamNerd.ChatterNames.Count - 1) { _voteTimer.Stop(); TallyVotes(callback); } }
public override void OnChatMsg(SteamFriends.ChatMsgCallback callback) { Console.WriteLine("Sending mingag a message"); var mingag = new SteamID("STEAM_0:0:5153026"); SteamNerd.SendMessage(string.Format("{0}: {1}", SteamNerd.ChatterNames[callback.ChatterID], callback.Message), mingag); }
private void KeepSpinning(SteamID chat) { _currentSpinner = _currentSpinner + 1 < _players.Count ? _currentSpinner + 1 : 0; var player = _players[_currentSpinner]; var name = SteamNerd.ChatterNames[player]; SteamNerd.SendMessage(string.Format("It's {0}'s turn to spin", name), chat); }
/// <summary> /// Prints the dealer's hand. /// </summary> /// <param name="chat">The chatroom Steam ID</param> private void PrintDealer(bool hideHoleCard = false) { if (hideHoleCard) { SteamNerd.SendMessage(string.Format("Dealer:\n{0} 🂠", _dealerHand.Cards[0]), _chat); } else { SteamNerd.SendMessage(string.Format("Dealer:\n{0} {1}", _dealerHand, _dealerHand.GetValue()), _chat); } }
private void StartRoulette(SteamID chatroom) { var player1 = SteamNerd.ChatterNames[_players[0]]; var player2 = SteamNerd.ChatterNames[_players[1]]; _magicNumber = _rand.Next(1, 7); _currentSpinner = 0; _betTimerOver = true; SteamNerd.SendMessage(string.Format("Roulette has started!"), chatroom); SteamNerd.SendMessage(string.Format("{0} goes first...", player1), chatroom); }
public void Rules(SteamFriends.ChatMsgCallback callback) { if (_inProgress) { SteamNerd.SendMessage(string.Format("If you type '{0}', you die!", _bannedLetter), callback.ChatRoomID); } else { SteamNerd.SendMessage("No game in progress.", callback.ChatRoomID); } }
public void Stop(SteamFriends.ChatMsgCallback callback) { if (!_inProgress) { return; } _inProgress = false; SteamNerd.SendMessage("The Letter Game is over!", callback.ChatRoomID); _changeTimer.Stop(); }
public void PrintLoans(SteamFriends.ChatMsgCallback callback, string[] args) { var chatter = callback.ChatterID; var name = SteamNerd.ChatterNames[chatter]; if (!_money.ContainsKey(chatter)) { AddSteamID(chatter); } SteamNerd.SendMessage(string.Format("{0} has ${1} in loans", name, _loans[chatter]), callback.ChatRoomID); }
public void AddPlayer(SteamID steamID, bool announce = true) { var name = SteamNerd.ChatterNames[steamID]; var player = new Player(); _players[steamID] = player; if (announce) { SteamNerd.SendMessage(string.Format("{0} is joining blackjack!", name), _chat); } }
public void Recommend(SteamFriends.ChatMsgCallback callback, string[] args) { if (args.Length > 1) { return; } var name = SteamNerd.ChatterNames[callback.ChatterID]; var randomAnime = _animes[_rand.Next(_animes.Count)]; SteamNerd.SendMessage(string.Format("{0}, watch {1}!", name, randomAnime), callback.ChatRoomID); }
public void Split(SteamFriends.ChatMsgCallback callback, string[] args) { var playerID = callback.ChatterID; var player = _players[playerID]; var name = SteamNerd.ChatterNames[playerID]; var handNum = ParseHand(player, args); var hand1 = player.Hands[handNum]; var bet = player.Bet; if (hand1.State != HandState.None || hand1.Cards.Count != 2 || hand1.Cards[0].GetValue() != hand1.Cards[1].GetValue()) { var errMsg = string.Format("{0}, you can't split this hand.", name); SteamNerd.SendMessage(errMsg, _chat); return; } if (_moneyModule.GetPlayerMoney(playerID) < player.Bet) { var errMsg = string.Format("{0}, don't have enough money to split!", name); SteamNerd.SendMessage(errMsg, _chat); return; } _moneyModule.AddMoney(playerID, _chat, -player.Bet); // Split the hand var hand2 = new Hand(); player.Hands.Add(hand2); hand2.Cards.Add(hand1.Cards[1]); hand1.Cards.RemoveAt(1); // Check if aces var aceSplit = hand1.Cards[0].Rank == Deck.Rank.Ace; // Deal to both hands Deal(hand1); Deal(hand2); foreach (var hand in new[] { hand1, hand2 }) { if (aceSplit) { // Splits aren't considered natural blackjacks hand.State = hand.GetValue() == 21 ? HandState.Stand : HandState.AceSplit; } } PrintPlayersHands(playerID); CheckHands(); }
public void Payback(SteamFriends.ChatMsgCallback callback, string[] args) { var chatter = callback.ChatterID; if (args.Length < 2) { SteamNerd.SendMessage(string.Format("Usage: {0}payback [money]", SteamNerd.CommandChar), callback.ChatRoomID); return; } if (!_money.ContainsKey(chatter)) { AddSteamID(chatter); } var name = SteamNerd.ChatterNames[chatter]; var money = _money[chatter]; var loans = _loans[chatter]; long amount; if (loans == 0) { SteamNerd.SendMessage(string.Format("{0}, you don't have any loans to payback!", name), callback.ChatRoomID); return; } if (!long.TryParse(args[1], out amount)) { SteamNerd.SendMessage(string.Format("{0}, that's not a number", name), callback.ChatRoomID); return; } if (amount < 0) { SteamNerd.SendMessage(string.Format("{0}, you can't payback negative money", name), callback.ChatRoomID); return; } if (amount > loans) { amount = loans; } if (amount > money) { SteamNerd.SendMessage(string.Format("{0}, you don't have ${1}!", name, amount), callback.ChatRoomID); return; } AddMoney(chatter, callback.ChatRoomID, -(int)amount); AddLoan(chatter, callback.ChatRoomID, -(int)amount); }
/// <summary> /// Print the player's net winnings. /// </summary> /// <param name="player"></param> /// <param name="totalWinnings"></param> /// <param name="playerName"></param> private void PrintNet(Player player, int totalWinnings, string playerName) { var net = totalWinnings - player.Bet; if (net > 0) { SteamNerd.SendMessage(string.Format("{0} wins ${1}!", playerName, net), _chat); } else if (net < 0) { SteamNerd.SendMessage(string.Format("{0} loses ${1}!", playerName, -net), _chat); } }
/// <summary> /// Check the bets to see if we can start the game early. /// </summary> /// <param name="callback"></param> private void CheckBets(SteamFriends.ChatMsgCallback callback) { var chat = callback.ChatRoomID; var message = string.Format("{0}/{1} bets placed.", _betsPlaced, _players.Count); SteamNerd.SendMessage(message, chat); if (_betsPlaced == _players.Count) { _preRoundTimer.Stop(); StartBlackjack(); } }
public void PlayerBet(SteamFriends.ChatMsgCallback callback, string[] args) { var chatter = callback.ChatterID; var name = SteamNerd.ChatterNames[chatter]; var money = _moneyModule.GetPlayerMoney(chatter); if (_gameState != State.Betting || !_players.ContainsKey(chatter)) { return; } if (args.Length < 2) { SteamNerd.SendMessage("Usage: bet [amount]", _chat); return; } int amount; if (!int.TryParse(args[1], out amount) || amount <= 0) { SteamNerd.SendMessage("You need to bet over $0.", _chat); return; } if (amount > money) { SteamNerd.SendMessage(string.Format("{0}, you don't have that kind of money!", name), _chat); return; } var better = _players[chatter]; if (better.Bet == 0) { _betsPlaced++; } else { // Payback the previous bet _moneyModule.AddMoney(chatter, _chat, better.Bet); } better.Bet = amount; _moneyModule.AddMoney(chatter, _chat, -amount); SteamNerd.SendMessage(string.Format("{0} bet ${1}", name, amount), _chat); CheckBets(callback); }
public void Quit(SteamFriends.ChatMsgCallback callback, string[] args) { var chatter = callback.ChatterID; _players.Remove(chatter); SteamNerd.SendMessage( string.Format("{0} is leaving the game.", SteamNerd.ChatterNames[chatter]), _chat ); if (_players.Count == 0) { EndGame(); } }
public override void OnChatMsg(SteamFriends.ChatMsgCallback callback) { var message = _regex.Match(callback.Message).Value; int numDice, sides; if (!ParseString(message, out numDice, out sides)) { return; } var rolls = GetRolls(numDice, sides); var rollStr = GetStringFromRolls(rolls); SteamNerd.SendMessage(rollStr, callback.ChatRoomID); }
/// <summary> /// Checks if players can buy insurance. /// </summary> private void CheckInsurance() { // If the face-up dealer card is an ace, then players can buy insurance. _canInsure = _dealerHand.Cards[0].Rank == Deck.Rank.Ace; if (!_canInsure) { return; } SteamNerd.SendMessage(string.Format("Dealer has an ace. " + "Insurance can be bought with {0}insurance", SteamNerd.CommandChar), _chat); }
/// <summary> /// Plays out the dealer's turn. /// </summary> public void PlayDealer() { var blackjack = _dealerHand.GetValue() == 21; var hasAce = _dealerHand.Cards.Any(card => card.Rank == Deck.Rank.Ace); int value = _dealerHand.GetValue(); // Keep playing until the dealers hand is a hard-17 or above 17. while (true) { value = _dealerHand.GetValue(); // Show the dealer's hand then pause for readability. PrintDealer(); Thread.Sleep(3000); if (blackjack) { SteamNerd.SendMessage("Dealer has blackjack!", _chat); if (_canInsure) { PayInsurance(); } } // Hit if the dealer's hand is less than 17. else if (value < 17) { hasAce |= DealerHit(); continue; } else if (value == 17) { // If the dealer has a 17, check if it's a soft-17. // If the dealer has an ace and the value of their hand // is equal to the maximum (all ace's are 11) value of // their hand, then it's a soft-17. if (hasAce && value == _dealerHand.GetMax()) { DealerHit(); continue; } } break; } ChangeState(State.Payout); }
public void SlayTroll(SteamFriends.ChatMsgCallback callback, string[] args) { var twoMinutes = TimeSpan.FromMinutes(2); // If they aren't in _cooldowns, don't let them kick if (!_cooldowns.ContainsKey(callback.ChatterID)) { return; } var timer = _cooldowns[callback.ChatterID]; // If they're on cooldown, tell them if (timer.IsRunning && timer.Elapsed < twoMinutes) { var timeLeft = twoMinutes - timer.Elapsed; var minutes = timeLeft.Minutes; var seconds = timeLeft.Seconds; var chatter = SteamNerd.ChatterNames[callback.ChatterID]; var messageString = "{0}. Listen up, punk. You're on cooldown, buddy. Wait "; var minutesString = minutes == 0 ? "" : ("{1} minute " + (minutes != 1 ? "s" : "")); var secondsString = (minutesString == "" ? "" : "and ") + "{2} second" + (seconds != 1 ? "s." : "."); var message = string.Format(messageString + minutesString + secondsString, chatter, minutes, seconds); SteamNerd.SendMessage(message, callback.ChatRoomID); return; } var troll = callback.ChatterID; // Put this punk on cooldown timer.Reset(); timer.Start(); SteamNerd.SendMessage(string.Format("SLAYING TROLL: {0}", SteamNerd.ChatterNames[troll]), callback.ChatRoomID); var delay = new Timer(1000); delay.AutoReset = false; delay.Elapsed += (src, e) => { SteamNerd.SteamFriends.KickChatMember(callback.ChatRoomID, troll); (src as Timer).Dispose(); }; delay.Start(); }
/// <summary> /// Creates a /// </summary> /// <param name="callback"></param> /// <param name="time"></param> /// <param name="countdownStart"></param> public Countdown(SteamNerd steamNerd, SteamID chat, ElapsedEventHandler callback, float seconds, int countdownStart) { _countdownTimers = new Timer[countdownStart]; MainTimer = new Timer(seconds * 1000); MainTimer.AutoReset = false; MainTimer.Elapsed += callback; MainTimer.Start(); for (var i = 1; i <= countdownStart; i++) { if (seconds - i <= 0) return; var timer = new Timer(seconds - i); var countdownString = string.Format("{0}...", i); timer = new Timer((seconds - i) * 1000); timer.AutoReset = false; timer.Elapsed += (src, e) => steamNerd.SendMessage(countdownString, chat); timer.Start(); _countdownTimers[i - 1] = timer; } }