private static void OnMessage(IWebSocketConnection socket, string messageStr) { Console.WriteLine("Message received: " + messageStr); ServerMessage messageIn = JsonConvert.DeserializeObject <ServerMessage>(messageStr); ClientSession session = null; if (!clients.TryGetValue(socket, out session)) { Console.WriteLine("Error! No session for the message: " + messageStr); return; } if (session.IsLoose) { return; } switch (messageIn.Command) { case "move": if (session.DoAction()) { Enum.TryParse(messageIn.Datas.ToString(), out Direction d); gameActions.Add(new GameAction(GameActionType.MOVE, session, d)); } break; case "extract": if (session.DoAction()) { gameActions.Add(new GameAction(GameActionType.EXTRACT, session, messageIn.Datas.ToString())); } break; case "inventory": MessageSender.InventoryMessage(session, socket); break; case "equipement": MessageSender.EquipementMessage(session, socket); break; case "map": MessageSender.MapMessage(session, socket, grid); break; case "use": session.SessionPlayer.UseItem(messageIn.Datas.ToString()); MessageSender.InventoryMessage(session, socket); MessageSender.InfoMessage(session, socket); break; case "craft": session.SessionPlayer.Craft(messageIn.Datas.ToString(), grid); MessageSender.InventoryMessage(session, socket); break; case "receipes": MessageSender.ReceipeMessage(session, socket); break; case "start_battle": if (session.DoAction()) { if (int.TryParse(messageIn.Datas.ToString(), out int idDefender)) { gameActions.Add(new GameAction(GameActionType.START_FIGHT, session, idDefender)); } } break; case "action_battle": if (session.DoActionBattle()) { gameActions.Add(new GameAction(GameActionType.ACTION_FIGHT, session, messageIn.Datas.ToString())); } break; case "pick": if (session.DoAction()) { gameActions.Add(new GameAction(GameActionType.PICK, session, messageIn.Datas.ToString())); } break; case "drop": grid.DropItem(session.SessionPlayer, messageIn.Datas.ToString()); MessageSender.InventoryMessage(session, socket); break; case "equip": grid.EquipItem(session.SessionPlayer, messageIn.Datas.ToString()); MessageSender.InventoryMessage(session, socket); MessageSender.EquipementMessage(session, socket); break; case "unequip": grid.UnequipItem(session.SessionPlayer, messageIn.Datas.ToString()); MessageSender.InventoryMessage(session, socket); MessageSender.EquipementMessage(session, socket); break; default: break; } }
public GameAction(GameActionType type, ClientSession session, object param) { this.type = type; this.session = session; this.param = param; }