示例#1
0
        //计算伤害范围
        public void BombRange(Bomb bomb)
        {
            bomb.timer.Change(Timeout.Infinite, Timeout.Infinite);
            GameMap gameMap = GameMapManager.instance.GetGameMap(0);

            MapController.instance.SetMapValue(gameMap, bomb.x, bomb.z, 0);
            ConsoleLog.instance.Info(string.Format("泡泡爆炸,武器Id: {0},泡泡位置: {1} {2}", bomb.weaponId, bomb.x, bomb.z));

            for (int i = bomb.x; i >= bomb.x - bomb.damageX; i--)
            {
                if (i < 0 || i >= gameMap.width)
                {
                    continue;
                }

                foreach (var item in PlayerManager.instance.playerDic)
                {
                    var playerId = item.Key;
                    var player   = item.Value;

                    if (player.x == i && player.z == bomb.z)
                    {
                        if (playerId2Damage.ContainsKey(playerId))
                        {
                            playerId2Damage[playerId] += bomb.damage;
                        }
                        else
                        {
                            playerId2Damage[playerId] = bomb.damage;
                        }
                    }
                }
                if (gameMap.gameMap[i, bomb.z] >= 1 && gameMap.gameMap[i, bomb.z] <= 1000)
                {
                    GroundMap groundMap = GameMapManager.instance.GetGroundMap(0);
                    MapController.instance.Damage(groundMap, i, bomb.z, bomb.damage);
                    AddBombRange(i, bomb.z, wORh.w);
                    break;
                }
                else if (gameMap.gameMap[i, bomb.z] >= 100001)
                {
                    AddBombRange(i, bomb.z, wORh.w);
                    var  bombId  = gameMap.gameMap[i, bomb.z];
                    Bomb newBomb = BombManager.instance.GetBomb(bombId);
                    BombRange(newBomb);
                    break;
                }
                else if (gameMap.gameMap[i, bomb.z] >= 10001 && gameMap.gameMap[i, bomb.z] <= 99999)
                {
                    break;
                }
                else if (gameMap.gameMap[i, bomb.z] >= 2001 && gameMap.gameMap[i, bomb.z] <= 3000)
                {
                    AddBombRange(i, bomb.z, wORh.w);
                }
                else if (gameMap.gameMap[i, bomb.z] == 0)
                {
                    AddBombRange(i, bomb.z, wORh.w);
                }
            }
            for (int i = bomb.x + 1; i <= bomb.x + bomb.damageX; i++)
            {
                if (i < 0 || i >= gameMap.width)
                {
                    continue;
                }

                foreach (var item in PlayerManager.instance.playerDic)
                {
                    var playerId = item.Key;
                    var player   = item.Value;

                    if (player.x == i && player.z == bomb.z)
                    {
                        if (playerId2Damage.ContainsKey(playerId))
                        {
                            playerId2Damage[playerId] += bomb.damage;
                        }
                        else
                        {
                            playerId2Damage[playerId] = bomb.damage;
                        }
                    }
                }
                if (gameMap.gameMap[i, bomb.z] >= 1 && gameMap.gameMap[i, bomb.z] <= 1000)
                {
                    GroundMap groundMap = GameMapManager.instance.GetGroundMap(0);
                    MapController.instance.Damage(groundMap, i, bomb.z, bomb.damage);
                    AddBombRange(i, bomb.z, wORh.w);
                    break;
                }
                else if (gameMap.gameMap[i, bomb.z] >= 100001)
                {
                    AddBombRange(i, bomb.z, wORh.w);
                    var  bombId  = gameMap.gameMap[i, bomb.z];
                    Bomb newBomb = BombManager.instance.GetBomb(bombId);
                    BombRange(newBomb);
                    break;
                }
                else if (gameMap.gameMap[i, bomb.z] >= 10001 && gameMap.gameMap[i, bomb.z] <= 99999)
                {
                    break;
                }
                else if (gameMap.gameMap[i, bomb.z] >= 2001 && gameMap.gameMap[i, bomb.z] <= 3000)
                {
                    AddBombRange(i, bomb.z, wORh.w);
                }
                else if (gameMap.gameMap[i, bomb.z] == 0)
                {
                    AddBombRange(i, bomb.z, wORh.w);
                }
            }
            for (int i = bomb.z - 1; i >= bomb.z - bomb.damageZ; i--)
            {
                if (i < 0 || i >= gameMap.height)
                {
                    continue;
                }

                foreach (var item in PlayerManager.instance.playerDic)
                {
                    var playerId = item.Key;
                    var player   = item.Value;

                    if (player.x == bomb.x && player.z == i)
                    {
                        if (playerId2Damage.ContainsKey(playerId))
                        {
                            playerId2Damage[playerId] += bomb.damage;
                        }
                        else
                        {
                            playerId2Damage[playerId] = bomb.damage;
                        }
                    }
                }
                if (gameMap.gameMap[bomb.x, i] >= 1 && gameMap.gameMap[bomb.x, i] <= 1000)
                {
                    GroundMap groundMap = GameMapManager.instance.GetGroundMap(0);
                    MapController.instance.Damage(groundMap, bomb.x, i, bomb.damage);
                    AddBombRange(bomb.x, i, wORh.h);
                    break;
                }
                else if (gameMap.gameMap[bomb.x, i] >= 100001)
                {
                    AddBombRange(bomb.x, i, wORh.h);
                    var  bombId  = gameMap.gameMap[bomb.x, i];
                    Bomb newBomb = BombManager.instance.GetBomb(bombId);
                    BombRange(newBomb);
                    break;
                }
                else if (gameMap.gameMap[bomb.x, i] >= 10001 && gameMap.gameMap[bomb.x, i] <= 99999)
                {
                    break;
                }
                else if (gameMap.gameMap[bomb.x, i] >= 2001 && gameMap.gameMap[bomb.x, i] <= 3000)
                {
                    AddBombRange(bomb.x, i, wORh.h);
                }
                else if (gameMap.gameMap[bomb.x, i] == 0)
                {
                    AddBombRange(bomb.x, i, wORh.h);
                }
            }
            for (int i = bomb.z + 1; i <= bomb.z + bomb.damageZ; i++)
            {
                if (i < 0 || i >= gameMap.height)
                {
                    continue;
                }

                foreach (var item in PlayerManager.instance.playerDic)
                {
                    var playerId = item.Key;
                    var player   = item.Value;

                    if (player.x == bomb.x && player.z == i)
                    {
                        if (playerId2Damage.ContainsKey(playerId))
                        {
                            playerId2Damage[playerId] += bomb.damage;
                        }
                        else
                        {
                            playerId2Damage[playerId] = bomb.damage;
                        }
                    }
                }
                if (gameMap.gameMap[bomb.x, i] >= 1 && gameMap.gameMap[bomb.x, i] <= 1000)
                {
                    GroundMap groundMap = GameMapManager.instance.GetGroundMap(0);
                    MapController.instance.Damage(groundMap, bomb.x, i, bomb.damage);
                    AddBombRange(bomb.x, i, wORh.h);
                    break;
                }
                else if (gameMap.gameMap[bomb.x, i] >= 100001)
                {
                    AddBombRange(bomb.x, i, wORh.h);
                    var  bombId  = gameMap.gameMap[bomb.x, i];
                    Bomb newBomb = BombManager.instance.GetBomb(bombId);
                    BombRange(newBomb);
                    break;
                }
                else if (gameMap.gameMap[bomb.x, i] >= 10001 && gameMap.gameMap[bomb.x, i] <= 99999)
                {
                    break;
                }
                else if (gameMap.gameMap[bomb.x, i] >= 2001 && gameMap.gameMap[bomb.x, i] <= 3000)
                {
                    AddBombRange(bomb.x, i, wORh.h);
                }
                else if (gameMap.gameMap[bomb.x, i] == 0)
                {
                    AddBombRange(bomb.x, i, wORh.h);
                }
            }

            //for (int i = bomb.x - bomb.damageX; i < bomb.x + 1 + bomb.damageX; i++)
            //{
            //    if (i < 0 || i >= gameMap.width)
            //    {
            //        continue;
            //    }
            //    foreach (var item in PlayerManager.instance.playerDic)
            //    {
            //        var playerId = item.Key;
            //        var player = item.Value;

            //        if (player.x == i && player.z == bomb.z)
            //        {
            //            if (playerId2Damage.ContainsKey(playerId))
            //            {
            //                playerId2Damage[playerId] += bomb.damage;
            //            }
            //            else
            //            {
            //                playerId2Damage[playerId] = bomb.damage;
            //            }
            //        }
            //    }
            //    if (gameMap.gameMap[i, bomb.z] >= 1 && gameMap.gameMap[i, bomb.z] <= 1000)
            //    {
            //        GroundMap groundMap = GameMapManager.instance.GetGroundMap(0);
            //        MapController.instance.Damage(groundMap, i, bomb.z, bomb.damage);
            //    }
            //    else if (gameMap.gameMap[i, bomb.z] >= 10001)
            //    {
            //        var bombId = gameMap.gameMap[i, bomb.z];
            //        Bomb newBomb = BombManager.instance.GetBomb(bombId);
            //        BombRange(newBomb);
            //    }
            //}

            //for (int i = bomb.z - bomb.damageZ; i < bomb.z + 1 + bomb.damageZ; i++)
            //{
            //    if (i < 0 || i >= gameMap.height)
            //    {
            //        continue;
            //    }
            //    foreach (var item in PlayerManager.instance.playerDic)
            //    {
            //        var playerId = item.Key;
            //        var player = item.Value;

            //        if (player.x == bomb.x && player.z == i)
            //        {
            //            if (playerId2Damage.ContainsKey(playerId))
            //            {
            //                playerId2Damage[playerId] += bomb.damage;
            //            }
            //            else
            //            {
            //                playerId2Damage[playerId] = bomb.damage;
            //            }
            //        }
            //    }
            //    if (gameMap.gameMap[bomb.x, i] >= 1 && gameMap.gameMap[bomb.x, i] <= 1000)
            //    {
            //        GroundMap groundMap = GameMapManager.instance.GetGroundMap(0);
            //        MapController.instance.Damage(groundMap, bomb.x, i, bomb.damage);
            //    }
            //    else if (gameMap.gameMap[bomb.x, i] >= 10001)
            //    {
            //        var bombId = gameMap.gameMap[bomb.x, i];
            //        Bomb newBomb = BombManager.instance.GetBomb(bombId);
            //        BombRange(newBomb);
            //    }
            //}

            BombManager.instance.DeleteBomb(bomb.id);
            bomb = null;
        }
示例#2
0
 public void AddBomb(int id, Bomb bomb)
 {
     bombDic.TryAdd(id, bomb);
 }
示例#3
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);
            }
        }