public void HandleInput(string input) { input = input.Trim(); if (status != InterpreterState.Standard) { Initialize(input); return; } input = input.ToLower(); string[] inputArgs = input.Split(' '); string command = inputArgs[0].ToLower(); string commandargs = input.Substring(command.Length).Trim();; if (inputArgs.Length >= 1) { ActionArgs a = null; string arg = input.Remove(0, command.Length); try { ActionBuilder builder = Player.GetAction(command); if (builder != null) { a = builder.TranslateArgs(Player, input); } if (builder != null && a != null) { CharacterAction act = builder.BuildAction(a); if (act != null) { if (act is TargetedAction && ((TargetedAction)act).Target == null) { Player.NotifyPlayer("Targeted actions must have a valid target"); return; } Player.Room.AddActionToQueue(builder.BuildAction(a)); } } }catch (ArgumentException ex) { Player.NotifyPlayer(ex.Message); } } if (Commands.ContainsKey(command)) { Commands[command](commandargs); } }
public override void StartTurn() { base.StartTurn(); PlayerCharacter[] players = null; ActionBuilder[] actions = new ActionBuilder[ActionList.Values.Count]; ActionList.Values.CopyTo(actions, 0); Random rand = new Random(); players = Room.GetPlayersInRoom(); int index; index = rand.Next(0, players.Length); ActionBuilder a = actions[rand.Next(0, ActionList.Values.Count)]; Room.AddActionToQueue(a.BuildAction(new ActionArgs(this, players[index]))); }
TResult Add <TResult>(IEnumerable <TDocument> liToAdd) where TResult : BasicResult, new() { var liAction = new List <BasicDocumentAction>(); const int maxBatchSize = 5242880; // 5 MB in bytes var currentBatchSize = 0; var results = new List <TResult>(); foreach (var toAdd in liToAdd) { var action = _actionBuilder.BuildAction(toAdd, ActionType.ADD); liAction.Add(action); currentBatchSize += liAction.GetSize(); if (currentBatchSize > maxBatchSize) { liAction.Remove(action); // Push this batch which has reached the 5 MB max on AWS and start // a new batch. results.Add(PerformDocumentAction <TResult>(liAction)); // Reset, start of new batch liAction.Clear(); liAction.Add(action); currentBatchSize = liAction.GetSize(); } } if (liAction.Any()) { results.Add(PerformDocumentAction <TResult>(liAction)); } var result = combineResults(liAction, results); return(result); }
public void RunGame() { Dungeon d = new Dungeon(3, 3, new DungeonPosition(2, 2)); MudCharacter mob = new Weakling("Skeleton"); d.AddNpcsToRoom((new string[] { "goblin" }), new DungeonPosition(1, 2)); d.AddNpcsToRoom((new string[] { "goblin" }), new DungeonPosition(0, 2)); d.AddNpcsToRoom((new string[] { "skeleton" }), new DungeonPosition(2, 1)); d.AddNpcsToRoom((new string[] { "skeleton" }), new DungeonPosition(1, 1)); d.AddNpcsToRoom((new string[] { "orc" }), new DungeonPosition(0, 0)); d.AddNpcsToRoom((new string[] { "orc" }), new DungeonPosition(1, 0)); d.AddNpcsToRoom((new string[] { "orc", "orc" }), new DungeonPosition(2, 0)); d.SetRoom(new DungeonPosition(0, 1), new HealingRoom(d, new DungeonPosition(0, 1))); d.SetRoom(new DungeonPosition(2, 2), new HealingRoom(d, new DungeonPosition(2, 2))); while (true) { string input = Console.ReadLine(); string[] inputArgs = input.Split(' '); if (inputArgs.Length >= 1) { string action = inputArgs[0].ToLower(); string arg = input.Remove(0, action.Length); try{ ActionBuilder builder = player.GetAction(action); ActionArgs a = ActionArgs.GetActionArgs(player, arg); if (builder != null && a != null) { CharacterAction act = builder.BuildAction(a); if (act != null) { if (act is TargetedAction && ((TargetedAction)act).Target == null) { player.NotifyPlayer("Targeted actions must have a valid target"); continue; } player.Room.AddActionToQueue(builder.BuildAction(a)); } } }catch (ArgumentException ex) { player.NotifyPlayer(ex.Message); } } if (inputArgs[0].ToLower() == "help") { Console.Write("available actions: "); foreach (string s in player.GetActionList()) { Console.Write("{0} ", s); } Console.WriteLine(""); Console.Out.Flush(); } if (inputArgs[0].ToLower() == "inventory") { foreach (string s in player.GetInventory()) { Console.WriteLine(s); } } if (inputArgs[0].ToLower() == "status") { Console.WriteLine(player.StatusString()); Console.Out.Flush(); } } }