static void ListenForKills(string line) { if (!ParseIRC.IsMessage(line)) { return; } string name = ParseIRC.GetUsernameSpeaking(line); string host = ParseIRC.GetHostSpeaking(line); string message = ParseIRC.GetSpokenLine(line); Player player = new Player(name, host); if (coercion.IsPlayerInGame(name, host)) { List <Mission> relevantMissons = coercion.MissionsWithTarget(player); if (relevantMissons.Count > 0) { foreach (Mission m in relevantMissons) { // If the mission's word appears *somewhere* in this message, count it if (message.ToLower().IndexOf(m.Word) > -1) { coercion.CompleteMission(m); irc.MessageUser(m.Assassin.Name, "Congratulations, you've successfully coerced " + m.Target.Name + " to say " + m.Word + ". I'll be awarding you an Assassin's Mark (type !scores to see how many you've accumulated, and !scoreboard to compare yourself with others) and will be in contact with a new target soon. Good work."); irc.MessageChannel("#guild", m.Assassin.Name + " has convinced " + m.Target.Name + " to say " + m.Word + ". +1 marks (" + coercion.scoreboard.ScoreFor(m.Assassin.Name) + " total marks)"); // Can assign new mission here immediately or wait until next line said } } } } }
public static string FormatIncomingLine(string line) { string[] line_parts = line.Split(' '); switch (line_parts[1]) { case "NOTICE": if (line_parts[2] == "Auth") { return("<AuthServ>" + ParseIRC.GetSpokenLine(line)); } else { return("<" + ParseIRC.GetUsernameSpeaking(line) + "@notice>" + ParseIRC.GetSpokenLine(line)); } // Private messages can come from other users or channels case "PRIVMSG": return("<" + ParseIRC.GetUsernameSpeaking(line) + "> " + ParseIRC.GetSpokenLine(line)); // We don't really care about mode changes yet case "MODE": return(line); // We also don't really care about people joining/leaving channels yet either case "JOIN": return(line_parts[2].Split(':')[1]); // Server-relevant messages case "001": case "002": case "003": case "004": case "005": case "042": case "251": case "252": case "254": case "255": case "265": case "266": case "372": case "375": case "376": case "396": return(line_parts[0]); // Channel-relevant messages case "332": // TOPIC case "333": // TOPIC set-by line case "366": // End-of-NAMES message return(line_parts[3]); case "353": // NAMES list return(line_parts[4]); default: return("RAW: " + line); } }
static void ConversationLog(string line) { if (ParseIRC.IsMessage(line)) { Console.WriteLine("{0}: {1}", ParseIRC.GetUsernameSpeaking(line), ParseIRC.GetSpokenLine(line)); } else { Console.WriteLine(line); } }
static void ListenForTargets(string line) { string[] splitLine = line.Split(' '); if (splitLine.Length > 1 && splitLine[1] == "QUIT") { string name = ParseIRC.GetUsernameSpeaking(line); string host = ParseIRC.GetHostSpeaking(line); coercion.RemovePlayer(irc, name, host); } // :[email protected] NICK :dru if (splitLine.Length > 1 && splitLine[1] == "NICK") { string name = ParseIRC.GetUsernameSpeaking(line); string host = ParseIRC.GetHostSpeaking(line); coercion.RemovePlayer(irc, name, host); } }
// TODO: We could (should?) probably just have a custom control that inherits from ListView, and have an AddMessage handler there private void AddMessageToMessageView(ListView message_view, string message) { string timestamp = DateTime.Now.ToString("hh:mm:ss"); string person = ParseIRC.GetUsernameSpeaking(message); string formatted_line = ParseIRC.GetSpokenLine(message); // CODESMELL: It's pretty funky that we need to specify our first column's data in the ListViewItem constructor instead of as a Subitem... ListViewItem message_item = new ListViewItem(timestamp); message_item.SubItems.Add(person); if (ParseIRC.IsMessage(message)) { message_item.SubItems.Add(formatted_line); } else { message_item.SubItems.Add(message); } message_view.Invoke((Action) delegate { message_view.Items.Add(message_item); }); }
static void GameLogic(string line) { // Ensure we have enough players to continue playing coercion.PauseIfNecessary(irc); // Make sure everyone playing has a mission coercion.EnsureEveryoneHasAMission(irc); // Update game target words coercion.UpdateGameWords(""); // Handle user commands if (ParseIRC.IsMessage(line)) { string player = ParseIRC.GetUsernameSpeaking(line); string host = ParseIRC.GetHostSpeaking(line); string message = ParseIRC.GetSpokenLine(line); string channel = ParseIRC.GetChannel(line); switch (message.Split(' ')[0]) { case "!start": case "!assassin": case "!play": bool newPlayer = coercion.AddPlayer(player, host); if (newPlayer) { coercion.NotifyPlayer(irc, player, "You there -- yes, you. I've noticed you lurking these channels for a while now, and I have a job for you. A... dark job, if you think you can handle it. My name is Boros, and I am the leader of the Assassin Guild here on TDDIRC."); Mission mission = coercion.AssignMissionTo(irc, new Player(player, host)); if (mission == null) { coercion.NotifyPlayer(irc, player, "It's in everyone's best interest to wait until there are more assassins in the Guild (there are currently " + coercion.activePlayers.Count + "). You will be assigned your first mission when the head count is high enough."); } else { coercion.NotifyPlayer(irc, player, "Pssst. I have a mission for you: I need you to slyly make " + mission.Target.Name + " say '" + mission.Word + "' using any means neccessary. Good luck."); } } break; case "!stop": case "!quit": case "!optout": bool removedPlayer = coercion.RemovePlayer(irc, player, host); if (removedPlayer) { coercion.NotifyPlayer(irc, player, "You can run, but you can't hide..."); } break; case "!reminder": case "!mission": if (coercion.IsPlayerInGame(player, host) && coercion.HasAMission(new Player(player, host))) { Player p = new Player(player, host); Mission mission = coercion.GetMissionFor(p); coercion.NotifyPlayer(irc, player, "Your mission is to make <" + mission.Target.Name + "> say '" + mission.Word + "'. If you can't, I could probably find you some new work if you type !newmission, but it'll cost you a mark."); } break; case "!skipmission": case "!nextmission": case "!newmission": if (coercion.IsPlayerInGame(player, host) && coercion.HasAMission(new Player(player, host))) { if (coercion.scoreboard.ScoreFor(player) > 0) { coercion.NotifyPlayer(irc, player, "I see. Well, if you can't handle it, you can't handle it. Fortunately for you, an Assassin's work is never done. I'll give you a new mission... but it's going to cost you a mark. I'll be in touch."); coercion.FailMission(new Player(player, host)); } else if (coercion.scoreboard.ScoreFor(player) > -3) { coercion.NotifyPlayer(irc, player, "Maybe you're not cut out to be an assassin after all; to think I saw potential in you! Maybe.. maybe you'll manage it. A new target usually costs a mark but, seeing you don't have any, lets just drop you negative and look the other way. I'll be in touch with a new job soon: a chance to redeem yourself."); coercion.FailMission(new Player(player, host)); } else { coercion.NotifyPlayer(irc, player, "You've had your chances. Either prove yourself as an assassin or leave the guild. No more do-overs, no more lenience, no more new missions. Take down your target first if you want another job."); } } break; case "!score": case "!scores": int score = coercion.scoreboard.People().Contains(player) == false ? 0 : coercion.scoreboard.ScoreFor(player); coercion.NotifyPlayer(irc, player, "You have " + score + " marks."); break; case "!leaderboard": case "!scoreboard": foreach (string p in coercion.scoreboard.People()) { if (coercion.scoreboard.ScoreFor(p) > 0) { coercion.NotifyPlayer(irc, player, p + " has " + coercion.scoreboard.ScoreFor(p) + " marks."); } } break; case "!addword": case "!add": case "!word": if (coercion.scoreboard.ScoreFor(player) > 3) { string phrase = message.Substring("!addword ".Length).Split(' ')[0]; coercion.AddToWordlist(phrase, channel.Substring(1)); coercion.NotifyPlayer(irc, player, "So you want to put a hit out for '" + phrase + "', huh? I know some good guys, I will make it happen. For a price, of course; I'll be taking one of your marks now."); coercion.scoreboard.RemoveScoreFor(player); } else { coercion.NotifyPlayer(irc, player, "You've yet to prove yourself as a worthwhile assassin. Lets talk again when you get, say, three marks? You have " + coercion.scoreboard.ScoreFor(player) + " right now; you can do better than that."); } break; case "!rules": coercion.NotifyPlayer(irc, player, "The rules are simple. I assign you a target and a word; and it is your mission to make your target say that word using any means neccessary. A successful mission will result in a nice reward for you. To get started, type !play"); break; case "!assassins": case "!players": coercion.NotifyPlayer(irc, player, "There are currently " + coercion.activePlayers.Count + " assassins in the guild."); break; case "!halp": case "!wat": case "!help": coercion.NotifyPlayer(irc, player, "Looking for help, I see? You're a lucky one; I just happen to overhear. I've noticed you here a few times and would like to extend a.. dangerous offer. If you're interested, type !rules to hear more."); break; } } }