Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// receive commands from clients
        /// </summary>
        /// <param name="value"></param>
        public void OnNext(List <Command> value)
        {
            try
            {
                if (value != null)
                {
                    foreach (Command c in value)
                    {
                        string commandType = c.commandType;

                        switch (commandType)
                        {
                        case "HitCommand":
                            HitCommand hit = (HitCommand)c;
                            HitHandler(hit);
                            break;

                        case "UpdatePlayerCommand":
                            UpdatePlayerCommand uPlayerCmd = (UpdatePlayerCommand)c;
                            PlayerUpdateHandler(uPlayerCmd);
                            break;

                        case "DeleteObjectCommand":
                            DeleteObjectCommand deleteObjectCmd = (DeleteObjectCommand)c;
                            PlayerDisconnectHandler(deleteObjectCmd);
                            break;

                        case "FireCommand":
                            SendCommandsToObservers(c);
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine('\n');
                System.Diagnostics.Debug.WriteLine(e);
                System.Diagnostics.Debug.WriteLine('\n');
            }
        }