Beispiel #1
0
        public static void HandleMoveTroops(int fromClient, Packet packet)
        {
            int clientIDCheck = packet.ReadInt();

            if (fromClient != clientIDCheck)
            {
                Console.WriteLine($"Player with ID: \"{fromClient}\" has assumed the wrong client ID: \"{clientIDCheck}\"!");
            }

            HexCoordinates coordinates = packet.ReadHexCoordinates();
            TroopType      troopType   = (TroopType)packet.ReadByte();
            int            amount      = packet.ReadInt();

            Player         player            = Server.clients[fromClient].Player;
            TroopInventory buildingInventory = ((ProtectedBuilding)GameLogic.grid.GetCell(coordinates).Structure).TroopInventory;

            if (GameLogic.MoveTroops(player, coordinates, troopType, amount))
            {
                ServerSend.BroadcastMoveTroops(player, coordinates, troopType, amount);
                Console.WriteLine("Player: " + player.Name + "of tribe " + player.Tribe.Id.ToString() + " successfully exchanged " + amount.ToString() + troopType.ToString() + " with a building at" + coordinates.ToString() + ".");
            }
            else
            {
                Console.WriteLine("Player: " + player.Name + "of tribe " + player.Tribe.Id.ToString() + " failed to exchange " + amount.ToString() + troopType.ToString() + " with building at " + coordinates.ToString() + ".");
            }
        }