Пример #1
0
        //地形收到伤害
        public void Damage(GroundMap groundMap, int x, int z, int damage)
        {
            var gameMap = GameMapManager.instance.GetGameMap(0);

            if (groundMap.groundMap[x, z] - damage <= 0)
            {
                var itemMap = GameMapManager.instance.GetItemMap(0);
                if (itemMap.itemMap[x, z] >= 2001 && itemMap.itemMap[x, z] <= 4000)
                {
                    gameMap.gameMap[x, z] = itemMap.itemMap[x, z];
                }
                else
                {
                    gameMap.gameMap[x, z] = 0;
                }

                GameProcess.instance.SendCellChange(gameMap.mapId, x, z, gameMap.gameMap[x, z]);
                ConsoleLog.instance.Info(string.Format("地形破坏 位置:{0},{1} 伤害量{2}", x, z, damage));
            }
            else
            {
                groundMap.groundMap[x, z] -= damage;
                SendCellBroken(x, z);
                ConsoleLog.instance.Info(string.Format("地形收到伤害 位置:{0},{1} 伤害量{2}", x, z, damage));
            }
        }
Пример #2
0
        //创建地图
        public void CreateMap(int width, int height, int[,] configMap, int[,] configItemMap, int[,] configGroundMap)
        {
            if (Server.instance.whichGame == 1)
            {
                GameMap   gameMap   = MapController.instance.Create(width, height);
                ItemMap   itemMap   = MapController.instance.CreateItemMap(width, height);
                GroundMap groundMap = MapController.instance.CreateGroundMap(width, height);

                mapDic.TryAdd(gameMap.mapId, gameMap);
                itemMapDic.TryAdd(itemMap.mapId, itemMap);
                groundMapDic.TryAdd(groundMap.mapId, groundMap);
            }
            else if (Server.instance.whichGame == 3)
            {
                mapDic[0].gameMap         = new int[width, height];
                mapDic[0].width           = width;
                mapDic[0].height          = height;
                itemMapDic[0].itemMap     = new int[width, height];
                itemMapDic[0].width       = width;
                itemMapDic[0].height      = height;
                groundMapDic[0].groundMap = new int[width, height];
                groundMapDic[0].width     = width;
                groundMapDic[0].height    = height;
            }

            MapController.instance.Init(mapDic[0], width, height, configMap);
            MapController.instance.InitItemMap(itemMapDic[0], width, height, configItemMap);
            MapController.instance.InitGroundMap(groundMapDic[0], width, height, configGroundMap);

            ConsoleLog.instance.Info(string.Format("创建地图,地图Id: {0}", 0));
        }
Пример #3
0
 public void InitGroundMap(GroundMap groundMap, int width, int height, int[,] map)
 {
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             groundMap.groundMap[i, j] = map[i, j];
         }
     }
 }
Пример #4
0
        public GroundMap CreateGroundMap(int width, int height)
        {
            GroundMap groundMap = new GroundMap();

            groundMap.mapId  = groundMapGuid;
            groundMap.width  = width;
            groundMap.height = height;
            groundMapGuid++;
            groundMap.groundMap = new int[width, height];
            return(groundMap);
        }
Пример #5
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;
        }
Пример #6
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);
            }
        }