コード例 #1
0
        /// <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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <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);
            }
        }