Пример #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);
        }
Пример #2
0
        /// <summary>
        /// deletes a player on all other clients when said player loses connection to the server
        /// </summary>
        /// <param name="cmd">the command containing the details about the player that needs to be deleted</param>
        public void PlayerDisconnectHandler(DeleteObjectCommand cmd)
        {
            game.getWorldObjects().Remove(cmd.obj);
            Player p = (Player)cmd.obj;
            Unsubscriber <Command> unsubscriber = new Unsubscriber <Command>(observers, p.GetClient());

            unsubscriber.Dispose();
            if (game.GetPlayerCount() == 0)
            {
                game.Dispose();
            }
            SendCommandsToObservers(cmd);
        }
Пример #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');
            }
        }