예제 #1
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;
            }
        }
예제 #2
0
        //客户端攻击
        public void ClientAttack(int clientId, C2SAttack data)
        {
            int playerId = Server.instance.GetPlayerId(clientId);
            var player   = PlayerManager.instance.GetPlayer(playerId);

            if (player == null)
            {
                return;
            }
            var       weaponId  = data.weaponId;
            GameMap   gameMap   = GameMapManager.instance.GetGameMap(0);
            GroundMap groundMap = GameMapManager.instance.GetGroundMap(0);

            S2CAttack s2CAttack = new S2CAttack();

            s2CAttack.playerId = playerId;
            SendAttack(s2CAttack);

            if (weaponId == -1)
            {
                switch (player.toward)
                {
                case 1:
                    var x1 = player.x;
                    var z1 = player.z + 1;
                    if (z1 < 0 || z1 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x1, z1] > 0 && gameMap.gameMap[x1, z1] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x1, z1, player.damageCommon1);
                    }
                    break;

                case 2:
                    var x2 = player.x + 1;
                    var z2 = player.z;
                    if (x2 < 0 || x2 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x2, z2] > 0 && gameMap.gameMap[x2, z2] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x2, z2, player.damageCommon1);
                    }
                    break;

                case 3:
                    var x3 = player.x;
                    var z3 = player.z - 1;
                    if (z3 < 0 || z3 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x3, z3] > 0 && gameMap.gameMap[x3, z3] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x3, z3, player.damageCommon1);
                    }
                    break;

                case 4:
                    var x4 = player.x - 1;
                    var z4 = player.z;
                    if (x4 < 0 || x4 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x4, z4] > 0 && gameMap.gameMap[x4, z4] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x4, z4, player.damageCommon1);
                    }
                    break;
                }
            }
            else if (weaponId == -2)
            {
                switch (player.toward)
                {
                case 1:
                    var x1 = player.x;
                    var z1 = player.z + 1;
                    if (z1 < 0 || z1 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x1, z1] > 0 && gameMap.gameMap[x1, z1] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x1, z1, player.damageCommon2);
                    }
                    break;

                case 2:
                    var x2 = player.x + 1;
                    var z2 = player.z;
                    if (x2 < 0 || x2 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x2, z2] > 0 && gameMap.gameMap[x2, z2] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x2, z2, player.damageCommon2);
                    }
                    break;

                case 3:
                    var x3 = player.x;
                    var z3 = player.z - 1;
                    if (z3 < 0 || z3 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x3, z3] > 0 && gameMap.gameMap[x3, z3] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x3, z3, player.damageCommon2);
                    }
                    break;

                case 4:
                    var x4 = player.x - 1;
                    var z4 = player.z;
                    if (x4 < 0 || x4 > 47)
                    {
                        return;
                    }
                    if (gameMap.gameMap[x4, z4] > 0 && gameMap.gameMap[x4, z4] <= 1000)
                    {
                        MapController.instance.Damage(groundMap, x4, z4, player.damageCommon2);
                    }
                    break;
                }
            }
            else if (weaponId == -3)
            {
                if (player.bombCount <= 0)
                {
                    SendBombNone(playerId);
                    return;
                }

                player.bombCount--;

                var x = CDT2Cell.instance.CDT2X(data.locationX);
                var z = CDT2Cell.instance.CDT2Z(data.locationZ);

                if (gameMap.gameMap[x, z] == 3001 || gameMap.gameMap[x, z] == 3002 || gameMap.gameMap[x, z] == 3003)
                {
                    return;
                }

                Bomb bomb = BombManager.instance.CreateBomb(player, x, z);

                MapController.instance.SetMapValue(gameMap, x, z, bomb.id);

                ConsoleLog.instance.Info(string.Format("角色攻击,武器Id: {0},泡泡位置: {1} {2}", weaponId, x, z));

                bomb.timer = new Timer(new TimerCallback(BombController.instance.BombTrigger), bomb, ReadConfig.instance.bombTime * 1000, Timeout.Infinite);
            }
        }