Esempio n. 1
0
        //客户端丢弃物品
        public void DeleteItem(int clientId, C2SDeleteItem c2SDeleteItem)
        {
            Player player = PlayerManager.instance.GetPlayer(Server.instance.GetPlayerId(clientId));

            if (player == null)
            {
                return;
            }
            if (ItemController.instance.IsHaveItem(player, c2SDeleteItem.index))
            {
                GameMap gameMap = GameMapManager.instance.GetGameMap(0);
                var     ret     = MapController.instance.GetEmptyCell(player, gameMap, c2SDeleteItem.itemId);
                SendMapChange(ret[0], ret[1], c2SDeleteItem.index);
                ItemController.instance.DeleteItem(player, c2SDeleteItem.index);
                SyncItem(player);
                //SendDeleteItem(ret[0], ret[1], player.playerId, c2SDeleteItem.index, 1);
                ConsoleLog.instance.Info(string.Format("Player {0} 丢弃道具 {1}, 位置 {2},{3}", player.playerId, c2SDeleteItem.index, ret[0], ret[1]));
            }
            else
            {
                ConsoleLog.instance.Info(string.Format("Player {0} 没有道具 {1}", player.playerId, c2SDeleteItem.index));
            }
        }
Esempio n. 2
0
        //消息分发
        public void ReceiveMsgControl(Message msg)
        {
            if (Server.instance.isGaming == false)
            {
                return;
            }
            switch (msg.messageType)
            {
            case (int)messageType.C2SMove:
                C2SMove c2SMove  = SerializeFunc.instance.DeSerialize <C2SMove>(msg.msg);
                int     playerId = Server.instance.GetPlayerId(msg.clientId);
                lock (PlayerManager.instance.playerMove)
                {
                    if (!PlayerManager.instance.playerMove.ContainsKey(playerId))
                    {
                        PlayerManager.instance.playerMove.Add(playerId, c2SMove);
                    }
                    else
                    {
                        PlayerManager.instance.playerMove[playerId] = c2SMove;
                    }
                }

                break;

            case (int)messageType.C2SAttack:
                C2SAttack c2SAttack = SerializeFunc.instance.DeSerialize <C2SAttack>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.ClientAttack(msg.clientId, c2SAttack);
                });
                break;

            case (int)messageType.C2SChooseChar:
                C2SChooseChar c2SChooseChar = SerializeFunc.instance.DeSerialize <C2SChooseChar>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.ChooseChar(msg.clientId, c2SChooseChar);
                });
                break;

            case (int)messageType.C2SChooseLocation:
                C2SChooseLocation c2SChooseLocation = SerializeFunc.instance.DeSerialize <C2SChooseLocation>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.ChooseLocation(msg.clientId, c2SChooseLocation);
                });
                break;

            case (int)messageType.C2SDeleteItem:
                C2SDeleteItem c2SDeleteItem = SerializeFunc.instance.DeSerialize <C2SDeleteItem>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.DeleteItem(msg.clientId, c2SDeleteItem);
                });
                break;

            case (int)messageType.C2SUseItem:
                C2SUseItem c2SUseItem = SerializeFunc.instance.DeSerialize <C2SUseItem>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.UseItem(msg.clientId, c2SUseItem);
                });
                break;

            case (int)messageType.C2SChangeWeapon:
                C2SChangeWeapon c2SChangeWeapon = SerializeFunc.instance.DeSerialize <C2SChangeWeapon>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.ClientChangeWeapon(msg.clientId, c2SChangeWeapon);
                });
                break;

            case (int)messageType.C2SDeleteChicken:
                C2SDeleteChicken c2SDeleteChicken = SerializeFunc.instance.DeSerialize <C2SDeleteChicken>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.ClientDeleteChicken(msg.clientId, c2SDeleteChicken);
                });
                break;

            case (int)messageType.C2SAction:
                C2SAction c2SAction = SerializeFunc.instance.DeSerialize <C2SAction>(msg.msg);
                EventManager.instance.AddEvent(() =>
                {
                    GameProcess.instance.ClientAction(msg.clientId, c2SAction);
                });
                break;

            default:
                return;
            }
        }