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; } }