public static void UpdateClientPositions(Simulation World) { foreach (ClientConnection UpdatedClient in ClientSubsetFinder.GetUpdatedClients()) { if (UpdatedClient.ConnectionDead || !UpdatedClient.Character.InGame) { continue; } UpdatedClient.Character.UpdateBody(World); } }
public static void PerformPlayerAttacks(Simulation World) { //Get a list of every client who's character is performing an attack this turn, and a list of every client who's character is currently inside the PVP battle arena List <ClientConnection> AttackingClients = ClientSubsetFinder.GetClientsAttacking(); List <ClientConnection> ClientsInArena = PVPBattleArena.GetClientsInside(); //Loop through all of the attacking clients so their attacks can be processed foreach (ClientConnection AttackingClient in AttackingClients) { //If the AttackingClient is inside the BattleArena, check their attack against the other players also in the arena if (ClientsInArena.Contains(AttackingClient)) { //Get a list of all the other clients in the arena to check the attack against List <ClientConnection> OtherClients = PVPBattleArena.GetClientsInside(); OtherClients.Remove(AttackingClient); foreach (ClientConnection OtherClient in OtherClients) { //Check the distance between the clients attack position and the other client to see if the attack hit float AttackDistance = Vector3.Distance(AttackingClient.Character.AttackPosition, OtherClient.Character.Position); if (AttackDistance <= 1.5f) { //Reduce the other characters health OtherClient.Character.CurrentHealth -= 1; //Send a damage alert to all clients if they survive the attack if (OtherClient.Character.CurrentHealth > 0) { CombatPacketSenders.SendLocalPlayerTakeHit(OtherClient.ClientID, OtherClient.Character.CurrentHealth); foreach (ClientConnection OtherOtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(OtherClient.ClientID)) { CombatPacketSenders.SendRemotePlayerTakeHit(OtherOtherClient.ClientID, OtherClient.Character.Name, OtherClient.Character.CurrentHealth); } } //Send a death alert to all clients if they are killed by the attack if (OtherClient.Character.CurrentHealth <= 0) { OtherClient.Character.IsAlive = false; OtherClient.Character.RemoveBody(World); CombatPacketSenders.SendLocalPlayerDead(OtherClient.ClientID); foreach (ClientConnection OtherOtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(OtherClient.ClientID)) { CombatPacketSenders.SendRemotePlayerDead(OtherOtherClient.ClientID, OtherClient.Character.Name); } } } } } //Disable the clients Attack flag now that the attack has been processed AttackingClient.Character.AttackPerformed = false; } }
//Adds any clients into the game world who are waiting for it public static void AddNewClients(Simulation World) { foreach (ClientConnection NewClient in ClientSubsetFinder.GetClientsReadyToEnter()) { NewClient.Character.InitializeBody(World, NewClient.Character.Position); NewClient.Character.WaitingToEnter = false; NewClient.Character.InGame = true; PlayerManagementPacketSender.SendPlayerBegin(NewClient.ClientID); foreach (ClientConnection OtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(NewClient.ClientID)) { PlayerManagementPacketSender.SendAddRemotePlayer(OtherClient.ClientID, NewClient.Character); } } }
//Respawns any clients characters who were dead and clicked the respawn button public static void RespawnDeadPlayers(Simulation World) { foreach (ClientConnection RespawningClient in ClientSubsetFinder.GetClientsAwaitingRespawn()) { RespawningClient.Character.SetDefaultValues(); RespawningClient.Character.InitializeBody(World, RespawningClient.Character.Position); RespawningClient.Character.IsAlive = true; CombatPacketSenders.SendLocalPlayerRespawn(RespawningClient.ClientID, RespawningClient.Character); foreach (ClientConnection OtherClient in ClientSubsetFinder.GetInGameClientsExceptFor(RespawningClient.ClientID)) { CombatPacketSenders.SendRemotePlayerRespawn(OtherClient.ClientID, RespawningClient.Character); } RespawningClient.Character.WaitingToRespawn = false; } }
//Cleans up any dead connections, removing their character from the world, and telling other clients to do the same on their end public static void CleanDeadClients(Simulation World) { foreach (ClientConnection DeadClient in ClientSubsetFinder.GetDeadClients()) { //Backup / Remove from World and alert other clients about any ingame dead clients if (DeadClient.Character.InGame) { CharactersDatabase.SaveCharacterData(DeadClient.Character); DeadClient.Character.RemoveBody(World); foreach (ClientConnection LivingClient in ClientSubsetFinder.GetInGameLivingClientsExceptFor(DeadClient.ClientID)) { PlayerManagementPacketSender.SendRemoveRemotePlayer(LivingClient.ClientID, DeadClient.Character.Name, DeadClient.Character.IsAlive); } } ActiveConnections.Remove(DeadClient.ClientID); } }