Пример #1
0
 /// <summary>
 /// Converts a given line to an <see cref="Action"/> of type actionType.
 /// </summary>
 /// <param name="line"></param>
 /// <param name="actionType"></param>
 /// <param name="actionText"></param>
 /// <returns></returns>
 public Action StringToAction(string line, GameSystem.ActionEnum actionType, string actionText, Game game)
 {
     string param = line.GetTextAfter(actionText).Trim();
     Player target = null;
     if (game != null) target = game.GetPlayer(param, "");
     Action action = new Action(actionType);
     if (target == null) action.Text = param;
     else action.Target = target;
     return action;
 }
Пример #2
0
        /// <summary>
        /// Processes all actions in the message, calls <see cref="ParseActions(SimpleMessage)"/> to get a list of valid actions.
        /// Passes each action to <see cref="GameSystem.PerformAction(Game, Player, Action)"/>.
        /// </summary>
        /// <param name="message">The message to process</param>
        /// <param name="game">The game the player is playing in</param>
        /// <seealso cref="ParseActions(SimpleMessage)"/>
        private void ProcessActions(SimpleMessage message, Game game)
        {
            GameSystem gameSystem = GameSystem.Instance;
            string address = message.From;
            Player player = null;
            if (game != null) player = game.GetPlayer("", address);
            List<Action> actions = ParseActions(message, player, game);

            if (game == null) gameSystem.NewGame(message, actions);
            else if (player == null) gameSystem.ValidateJoinAction(address, actions, game);
            else
            {
                foreach (Action action in actions)
                {
                    gameSystem.PerformAction(game, player, action);
                }
            }
        }
Пример #3
0
 /// <summary>
 /// The given player isn't playing in any games, but they did reference a valid game id.  See if they want to join it.
 /// </summary>
 /// <param name="address"></param>
 /// <param name="actions"></param>
 /// <param name="game"></param>
 public void ValidateJoinAction(string address, List<Action> actions, Game game)
 {
     foreach (Action action in actions)
     {
         if (action.Type == ActionEnum.JoinAs)
         {
             Player player = new Player(action.Text.ToTitleCase(), address);
             if (String.IsNullOrEmpty(player.Name))
             {
                 HandleBadAction(game, player, action, "You didn't specify the name you wished to join the game as. To do this reply to this message with \"Join as <i>name</i>\" where <i>name</i> is your name.");
                 return;
             }
             else if (game.IsInProgress)
             {
                 HandleBadAction(game, player, action, "You cannot join " + game + " because it is in progress.");
             }
             else if (game.GetPlayer(player.Name, "") != null)
             {
                 HandleBadAction(game, player, action, "Someone else is already using " + player.Name.b() + " as their name, please choose a different name.");
             }
             else
             {
                 ProcessJoinAction(player, action, game);
             }
             return;
         }
     }
     //None of the actions were join actions, and they aren't playing in any games so...
     string msg = "You aren't playing any games, the only action you may take is joining a game or creating a game. To start a new game reply to this message with \"Join as <i>name</i>\" where <i>name</i> is your name.";
     log.Warn("Unknown malformed action from " + address);
     Gmail.MessagePerson(address, game.Subject, msg);
 }