/// <summary> /// checks if a player is currently on a pickup and if so sends the player a pickupcommand with the items details of the item he picked up /// </summary> /// <param name="uPlayer">the current position update received from the client</param> /// <param name="obj">the previous position of the player</param> /// <returns></returns> public List <Object3D> CheckForPickup(UpdatePlayerCommand uPlayer, Object3D obj) { List <Object3D> deleteCueue = new List <Object3D>(); foreach (SpawnLocation s in spawnList) { if (s.item != null) { if (s.item.type != "DamageBoost") { if (uPlayer.x > (s.item.x - 0.6) && uPlayer.x < (s.item.x + 0.6) && uPlayer.y > (s.item.y + 1.4) && uPlayer.y < (s.item.y + 2.6) && uPlayer.z > (s.item.z - 0.6) && uPlayer.z < (s.item.z + 0.6)) { if (s.item.type == "HealthItem") { ((Player)obj).addHealth(((HealthItem)s.item).itemValue); UpdatePlayerStatsCommand cmd = new UpdatePlayerStatsCommand((Player)obj); SendCommandsToObservers(cmd); } if (s.item.type == "ArmourItem") { ((Player)obj).addArmour(((ArmourItem)s.item).itemValue); UpdatePlayerStatsCommand cmd = new UpdatePlayerStatsCommand((Player)obj); SendCommandsToObservers(cmd); } if (s.item.type == "SpeedBoost") { PlayerPickupCommand cmd = new PlayerPickupCommand(s.item, ((Player)obj).guid); SendCommandsToObservers(cmd); } if (s.item.type == "AmmoItem") { PlayerPickupCommand cmd = new PlayerPickupCommand(s.item, ((Player)obj).guid); SendCommandsToObservers(cmd); } DeleteObjectCommand cmd1 = new DeleteObjectCommand(s.item); SendCommandsToObservers(cmd1); deleteCueue.Add(s.item); s.dellItem(); } } else { if (uPlayer.x > (s.item.x - 1.45) && uPlayer.x < (s.item.x + 1.45) && uPlayer.y > (s.item.y + 0.75) && uPlayer.y < (s.item.y + 3.25) && uPlayer.z > (s.item.z - 1.45) && uPlayer.z < (s.item.z + 1.45)) { DeleteObjectCommand cmd3 = new DeleteObjectCommand(s.item); PlayerPickupCommand cmd4 = new PlayerPickupCommand(s.item, ((Player)obj).guid); SendCommandsToObservers(cmd3); SendCommandsToObservers(cmd4); deleteCueue.Add(s.item); s.dellItem(); } } } } return(deleteCueue); }
/// <summary> /// handle updateplayer commands from clients /// </summary> /// <param name="uPlayer">a command message contiaing details about hte player/client</param> public void PlayerUpdateHandler(UpdatePlayerCommand uPlayer) { List <Object3D> worldObjects = game.getWorldObjects(); List <Object3D> deleteCueue = new List <Object3D>(); for (int i = 0; i < worldObjects.Count; i++) { if (worldObjects[i] == null) { continue; } else if (worldObjects[i] is Player) { if (worldObjects[i].guid == uPlayer.playerGuid) { if (uPlayer.y > -100) { worldObjects[i].Move(uPlayer.x, uPlayer.y, uPlayer.z); worldObjects[i].Rotate(uPlayer.rotationX, uPlayer.rotationY, uPlayer.rotationZ); deleteCueue = CheckForPickup(uPlayer, worldObjects[i]); for (int j = 0; j < deleteCueue.Count; j++) { if (worldObjects.Contains(deleteCueue[j])) { worldObjects.Remove(deleteCueue[j]); } } deleteCueue.Clear(); UpdateObjectCommand cmd = new UpdateObjectCommand(worldObjects[i]); SendCommandsToObservers(cmd); } else { PlayerSpawnLocation respawnLocation = playerSpawnList.GetSpawnLocation(); DeathCommand cmd = new DeathCommand((Player)worldObjects[i], respawnLocation); ((Player)worldObjects[i]).addDeath(); UpdatePlayerStatsCommand cmd2 = new UpdatePlayerStatsCommand((Player)worldObjects[i]); SendCommandsToObservers(cmd); SendCommandsToObservers(cmd2); } } } } }
/// <summary> /// handlees hit messages from clients and determines if one scored a kill or died /// </summary> /// <param name="hit">a hitcommand containing detail about a hit</param> public void HitHandler(HitCommand hit) { List <Object3D> worldObjects = game.getWorldObjects(); Player hitPlayer = null; Player shootingPlayer = null; foreach (Object3D obj in worldObjects) { if (obj is Player) { if (obj.guid == hit.hitPlayerGuid) { hitPlayer = (Player)obj; } else if (obj.guid == hit.shootingPlayerGuid) { shootingPlayer = (Player)obj; } } } if (hitPlayer.DoDamage(hit.damage)) { shootingPlayer.addKill(); PlayerSpawnLocation respawnLocation = playerSpawnList.GetSpawnLocation(); DeathCommand cmd = new DeathCommand(hitPlayer, respawnLocation); UpdatePlayerStatsCommand cmd2 = new UpdatePlayerStatsCommand(shootingPlayer); SendCommandsToObservers(cmd); SendCommandsToObservers(cmd2); } else { UpdatePlayerStatsCommand cmd = new UpdatePlayerStatsCommand(hitPlayer); SendCommandsToObservers(cmd); } }