public static void HandleBuildHQ(int fromClient, Packet packet) { int clientIDCheck = packet.ReadInt(); if (fromClient != clientIDCheck) { Console.WriteLine($"Player with ID: \"{fromClient}\" has assumed the wrong client ID: \"{clientIDCheck}\"!"); } Player player = Server.clients[fromClient].Player; HexCoordinates coordinates = packet.ReadHexCoordinates(); Headquarter hq = new Headquarter(); if (GameLogic.VerifyBuildHQ(coordinates, hq, player)) { Tribe tribe = GameLogic.ApplyBuildHQ(coordinates, hq); player.Tribe = tribe; ServerSend.BroadcastApplyBuildHQ(coordinates); ServerSend.BroadcastPlayer(player); Console.WriteLine("Player: " + player.Name + " successfully placed a HQ."); } else { Console.WriteLine("Player: " + player.Name + " failed to build HQ"); } Server.SaveGame(); }
public static void HandlePlaceBuilding(int fromClient, Packet packet) { int clientIDCheck = packet.ReadInt(); if (fromClient != clientIDCheck) { Console.WriteLine($"Player with ID: \"{fromClient}\" has assumed the wrong client ID: \"{clientIDCheck}\"!"); } Player player = Server.clients[fromClient].Player; HexCoordinates coordinates = packet.ReadHexCoordinates(); Type type = packet.ReadType(); Building building = (Building)Activator.CreateInstance(type); if (GameLogic.VerifyBuild(coordinates, type, player)) { GameLogic.ApplyBuild(coordinates, type, player.Tribe); ServerSend.BroadcastApplyBuild(coordinates, type, player.Tribe.Id); Console.WriteLine("Player: " + player.Name + " of tribe " + player.Tribe.Id.ToString() + " successfully placed a " + building.GetName() + "."); } else { Console.WriteLine("Player: " + player.Name + " of tribe " + player.Tribe.Id.ToString() + " failed to build " + building.GetName() + "."); } Server.SaveGame(); }