示例#1
0
 public virtual void OnDisable()
 {
     BattleServer.RemoveEntity(this);
     if (EntityLifeComponent != null)
     {
         EntityLifeComponent.OnNoLife -= Life_OnNoLife;
     }
 }
示例#2
0
    static void Main(string[] args)
    {
        BattleServer server = new BattleServer();

        if (server.Init())
        {
            server.Run();
        }

        server.UnInit();
    }
示例#3
0
        public virtual void OnEnable()
        {
            if (EntityType != EntityEnum.None)
            {
                BattleServer.AddEntity(this);
            }

            if (EntityLifeComponent != null)
            {
                EntityLifeComponent.ResetLife();
                EntityLifeComponent.OnNoLife += Life_OnNoLife;
            }
        }
示例#4
0
        // 进入战斗
        private static void EnterBattleScene(AsyncSocketUserToken client, JSONObject data)
        {
            int        userId  = (int)data["userId"].i;
            int        levelId = (int)data["levelId"].i;
            User       user    = DataManager.Instance.ReadUser(userId);
            Entity     role    = DataManager.Instance.ReadRole(user.roleId);
            PlayerInfo player  = new PlayerInfo();

            player.userId = userId;
            player.role   = role;
            player.client = client;

            BattleServer bs = ServerManager.Instance.CreateBattleScene(levelId);

            bs.EnterPlayer(player);

            JSONObject db = DataPool.Instance.Pop(CMD.EnterBattleScene, 0);

            db.Add(bs.serverId);
            client.SendMessage(db);
        }
示例#5
0
        public void Execute()
        {
            if (m_room.CanStart())
            {
                List <GamePlayer> players = m_room.GetPlayers();
                if (m_room.RoomType == eRoomType.Freedom)
                {
                    List <IGamePlayer> red  = new List <IGamePlayer>();
                    List <IGamePlayer> blue = new List <IGamePlayer>();
                    foreach (GamePlayer p in players)
                    {
                        if (p != null)
                        {
                            if (p.CurrentRoomTeam == 1)
                            {
                                red.Add(p);
                            }
                            else
                            {
                                blue.Add(p);
                            }
                        }
                    }

                    BaseGame game = GameMgr.StartPVPGame(m_room.RoomId, red, blue, m_room.MapId, m_room.RoomType, m_room.GameType, m_room.TimeMode);
                    StartGame(game);
                }
                else if (m_room.RoomType == eRoomType.Exploration || m_room.RoomType == eRoomType.Boss || m_room.RoomType == eRoomType.Treasure)
                {
                    List <IGamePlayer> matchPlayers = new List <IGamePlayer>();
                    foreach (GamePlayer p in players)
                    {
                        if (p != null)
                        {
                            matchPlayers.Add(p);
                        }
                    }
                    //更新房间的时间类型
                    UpdatePveRoomTimeMode();
                    BaseGame game = GameMgr.StartPVEGame(m_room.RoomId, matchPlayers, m_room.MapId, m_room.RoomType, m_room.GameType, m_room.TimeMode, m_room.HardLevel, m_room.LevelLimits);
                    StartGame(game);
                }
                else if (m_room.RoomType == eRoomType.Match)
                {
                    m_room.UpdateAvgLevel();
                    // m_room.GameType = eGameType.Guild;

                    BattleServer server = BattleMgr.AddRoom(m_room);
                    if (server != null)
                    {
                        m_room.BattleServer = server;
                        m_room.IsPlaying    = true;
                        m_room.SendStartPickUp();
                    }
                    else
                    {
                        GSPacketIn pkg = m_room.Host.Out.SendMessage(eMessageType.ChatERROR, "没有可用的战场服务器!");
                        m_room.SendToAll(pkg, m_room.Host);
                        m_room.SendCancelPickUp();
                    }
                }

                RoomMgr.WaitingRoom.SendUpdateRoom(m_room);
            }
        }
 public CancelPickupAction(BattleServer server, BaseRoom room)
 {
     this.m_room   = room;
     this.m_server = server;
 }
示例#7
0
 public void ToBinary(BinaryWriter writer)
 {
     writer.Write((int)Code);
     BattleServer.ToBinary(writer);
     writer.Write(MapID);
 }
示例#8
0
 public void Execute()
 {
     if (this.m_room.CanStart())
     {
         List <GamePlayer> players = this.m_room.GetPlayers();
         if (this.m_room.RoomType == eRoomType.Freedom)
         {
             List <IGamePlayer> red  = new List <IGamePlayer>();
             List <IGamePlayer> blue = new List <IGamePlayer>();
             foreach (GamePlayer p in players)
             {
                 if (p != null)
                 {
                     if (p.CurrentRoomTeam == 1)
                     {
                         red.Add(p);
                     }
                     else
                     {
                         blue.Add(p);
                     }
                 }
             }
             BaseGame game = GameMgr.StartPVPGame(this.m_room.RoomId, red, blue, this.m_room.MapId, this.m_room.RoomType, this.m_room.GameType, (int)this.m_room.TimeMode);
             this.StartGame(game);
         }
         else
         {
             if (this.m_room.RoomType == eRoomType.Exploration || this.m_room.RoomType == eRoomType.Boss || this.m_room.RoomType == eRoomType.Treasure || this.m_room.RoomType == eRoomType.Training || this.m_room.RoomType == eRoomType.FightLab || this.m_room.RoomType == eRoomType.FightNPC || this.m_room.RoomType == eRoomType.WorldBoss)
             {
                 List <IGamePlayer> matchPlayers = new List <IGamePlayer>();
                 foreach (GamePlayer p in players)
                 {
                     if (p != null)
                     {
                         matchPlayers.Add(p);
                     }
                 }
                 this.m_room.UpdatePveRoomTimeMode();
                 BaseGame game = GameMgr.StartPVEGame(this.m_room.RoomId, matchPlayers, this.m_room.MapId, this.m_room.RoomType, this.m_room.GameType, (int)this.m_room.TimeMode, this.m_room.HardLevel, this.m_room.LevelLimits);
                 this.StartGame(game);
             }
             else
             {
                 if (this.m_room.RoomType == eRoomType.Match)
                 {
                     this.m_room.UpdateAvgLevel();
                     BattleServer server = BattleMgr.AddRoom(this.m_room);
                     if (server != null)
                     {
                         this.m_room.BattleServer = server;
                         this.m_room.IsPlaying    = true;
                         this.m_room.SendStartPickUp();
                     }
                     else
                     {
                         this.m_room.SendCancelPickUp();
                     }
                 }
             }
         }
         RoomMgr.WaitingRoom.SendUpdateRoom(this.m_room);
     }
     else
     {
         this.m_room.SendPlayerState();
     }
 }
示例#9
0
    IEnumerator _CoTryDownloadOnly(string uuid, VoidFuncVoid cb_ok, VoidFuncVoid cb_error)
    {
        string name = uuid;
        //load from local file cache
        bool   save_file_ok = true;
        var    time         = Utils.GetTimestampMiliseconds();
        string json         = Serializable.LoadFromFileEx(name + ".json");

        if (string.IsNullOrEmpty(json))
        {
#if UNITY_EDITOR
            Debug.Log(" missing map file cache  start download with www " + name);
#endif
            if (this._running_task.Contains(uuid))
            {
            }
            else
            {
                this._running_task.Add(uuid);
            }
            int try_times = 3;
            while (try_times > 0)
            {
                var www = new WWW(Serializable.GetDownloadWWWUrl(name));
                yield return(www);

#if UNITY_EDITOR
                Debug.Log(www.url + "  " + www.text);
#else
                //  Debug.Log(www.url);
#endif
                if (Serializable.Map.IsMapJson(www.text))
                {
                    save_file_ok = Serializable.SaveToFile(name + ".json", www.text);
                    json         = www.text;;
                    break;
                }
                else
                {
                    if (www.text.IndexOf("Document not found") > 0 && www.text.Length < 150)
                    {
                        Debug.LogError("MapHttpTask Fatal error:This Map HasNot exist in web server " + name + " url=" + www.url);
                        try_times = -1;
                        break;
                    }
                    //error
                    try_times--;
                    continue;
                }
            }
            if (this._running_task.Contains(uuid))
            {
                this._running_task.Remove(uuid);
            }
        }
        if (Serializable.Map.IsMapJson(json) == false || !save_file_ok)
        {
            BattleServer.TryDisconnected();
            if (cb_error != null)
            {
                cb_error();
            }
        }
        else
        {
            if (cb_ok != null)
            {
                cb_ok();
            }
        }
        time = (Utils.GetTimestampMiliseconds() - time);
#if UNITY_EDITOR
        if (time > 2000)
        {
            Debug.LogError("  MapHttpTask.AddDownloadTask load   " + name + ".json time =" + time + "  ms");
        }
        else
        {
            Debug.Log("  MapHttpTask.AddDownloadTask load   " + name + ".json time =" + time + "  ms");
        }
#endif
    }
示例#10
0
    public static IEnumerator AddDownloadTask(string uuid)
    {
        string name = uuid;
        //load from local file cache
        bool   save_file_ok = true;
        var    time         = Utils.GetTimestampMiliseconds();
        string json         = Serializable.LoadFromFileEx(name + ".json");

        if (string.IsNullOrEmpty(json))
        {
#if UNITY_EDITOR
            Debug.Log(" missing map file cache  start download with www " + name);
#endif
            int try_times = 3;
            while (try_times > 0)
            {
                var www = new WWW(Serializable.GetDownloadWWWUrl(name));
                yield return(www);

#if UNITY_EDITOR
                Debug.Log(www.url + "  " + www.text);
#else
                Debug.Log(www.url);
#endif
                if (Serializable.Map.IsMapJson(www.text))
                {
                    save_file_ok = Serializable.SaveToFile(name + ".json", www.text);
                    json         = www.text;;
                    break;
                }
                else
                {
                    if (www.text.IndexOf("Document not found") > 0 && www.text.Length < 150)
                    {
                        Debug.LogError("MapHttpTask Fatal error:This Map HasNot exist in web server " + name + " url=" + www.url);
                        try_times = -1;
                        break;
                    }
                    //error
                    try_times--;
                    continue;
                }
            }
        }
        if (Serializable.Map.IsMapJson(json) == false || !save_file_ok)
        {
            BattleServer.TryDisconnected();
            if (UICommonDialog.ins != null)
            {
                UICommonDialog.ins.ShowOKCancle("地图下载失败 [error " + uuid + "]", () =>
                {
                    SceneMgr.LoadLevel("GameLogin");
                }, () =>
                {
                    SceneMgr.LoadLevel("GameLogin");
                });
            }
        }
        time = (Utils.GetTimestampMiliseconds() - time);
#if UNITY_EDITOR
        if (time > 2000)
        {
            Debug.LogError("  MapHttpTask.AddDownloadTask load   " + name + ".json time =" + time + "  ms");
        }
        else
        {
            Debug.Log("  MapHttpTask.AddDownloadTask load   " + name + ".json time =" + time + "  ms");
        }
#endif
    }
示例#11
0
 public static void CancelPickup(BattleServer server, BaseRoom room)
 {
     RoomMgr.AddAction(new CancelPickupAction(server, room));
 }
示例#12
0
        /// <summary>
        /// 请不要直接调用,使用RoomMgr.ExitRoom
        /// </summary>
        /// <param name="player"></param>
        public bool RemovePlayerUnsafe(GamePlayer player, bool isKick)
        {
            int index = -1;

            lock (m_places)
            {
                for (int i = 0; i < 10; i++)
                {
                    if (m_places[i] == player)
                    {
                        m_places[i]      = null;
                        m_playerState[i] = 0;
                        m_placesState[i] = -1;
                        m_playerCount--;
                        index = i;
                        break;
                    }
                }
            }

            if (index != -1)
            {
                UpdatePosUnsafe(index, false, -1, -100);
                player.CurrentRoom = null;
                player.TempBag.ClearBag();
                GSPacketIn pkg = player.Out.SendRoomPlayerRemove(player);
                SendToAll(pkg);

                //发送踢人信息
                if (isKick)
                {
                    player.Out.SendMessage(eMessageType.ChatERROR, LanguageMgr.GetTranslation("Game.Server.SceneGames.KickRoom"));
                }

                //从新挑选房主
                bool isChangeHost = false;
                if (m_host == player)
                {
                    if (m_playerCount > 0)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            if (m_places[i] != null)
                            {
                                SetHost(m_places[i]);
                                isChangeHost = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        m_host = null;
                    }
                }

                //游戏中移除人物
                if (IsPlaying)
                {
                    if (m_game != null)
                    {
                        //如果关卡中,房主退出,重置新房主的ready状态
                        if (isChangeHost && m_game is PVEGame)
                        {
                            PVEGame pveGame = m_game as PVEGame;
                            foreach (Player p in pveGame.Players.Values)
                            {
                                if (p.PlayerDetail == m_host)
                                {
                                    p.Ready = false;
                                }
                            }
                        }
                        m_game.RemovePlayer(player, isKick);
                    }
                    if (BattleServer != null)
                    {
                        if (m_game != null)
                        {
                            BattleServer.Server.SendPlayerDisconnet(Game.Id, player.GamePlayerId, RoomId);
                            if (PlayerCount == 0)
                            {
                                BattleServer.RemoveRoom(this);
                            }
                        }
                        else
                        {
                            SendMessage(eMessageType.ChatERROR, LanguageMgr.GetTranslation("Game.Server.SceneGames.PairUp.Failed"));
                            RoomMgr.AddAction(new CancelPickupAction(BattleServer, this));
                            BattleServer.RemoveRoom(this);
                            IsPlaying = false;
                        }
                    }
                }
                else
                {
                    UpdateGameStyle();
                    if (isChangeHost)
                    {
                        //if (RoomType == eRoomType.Dungeon)
                        //{
                        //    HardLevel = eHardLevel.Normal;
                        //}
                        //else
                        //{
                        //    HardLevel = eHardLevel.Simple;
                        //}
                        foreach (GamePlayer gp in GetPlayers())
                        {
                            gp.Out.SendRoomChange(this);
                        }
                    }
                }
            }
            return(index != -1);
        }
示例#13
0
 public void Execute()
 {
     if (this.m_room.CanStart())
     {
         List <GamePlayer> players = this.m_room.GetPlayers();
         if (this.m_room.RoomType == eRoomType.Freedom)
         {
             List <IGamePlayer> list  = new List <IGamePlayer>();
             List <IGamePlayer> list2 = new List <IGamePlayer>();
             foreach (GamePlayer current in players)
             {
                 if (current != null)
                 {
                     if (current.CurrentRoomTeam == 1)
                     {
                         list.Add(current);
                     }
                     else
                     {
                         list2.Add(current);
                     }
                 }
             }
             BaseGame game = GameMgr.StartPVPGame(this.m_room.RoomId, list, list2, this.m_room.MapId, this.m_room.RoomType, this.m_room.GameType, (int)this.m_room.TimeMode);
             this.StartGame(game);
         }
         else
         {
             if (this.m_room.RoomType == eRoomType.Dungeon || this.m_room.RoomType == eRoomType.Freshman || this.m_room.RoomType == eRoomType.Lanbyrinth || this.m_room.RoomType == eRoomType.ConsortiaBoss || this.m_room.RoomType == eRoomType.AcademyDungeon || this.m_room.RoomType == eRoomType.FightLib || this.m_room.RoomType == eRoomType.WordBoss)
             {
                 List <IGamePlayer> list3 = new List <IGamePlayer>();
                 foreach (GamePlayer current2 in players)
                 {
                     if (current2 != null)
                     {
                         list3.Add(current2);
                     }
                 }
                 this.UpdatePveRoomTimeMode();
                 BaseGame game2 = GameMgr.StartPVEGame(this.m_room.RoomId, list3, this.m_room.MapId, this.m_room.RoomType, this.m_room.GameType, (int)this.m_room.TimeMode, this.m_room.HardLevel, this.m_room.LevelLimits);
                 this.StartGame(game2);
             }
             else
             {
                 if (this.m_room.RoomType == eRoomType.Match)
                 {
                     this.m_room.UpdateAvgLevel();
                     BattleServer battleServer = BattleMgr.AddRoom(this.m_room);
                     if (battleServer != null)
                     {
                         this.m_room.BattleServer = battleServer;
                         this.m_room.IsPlaying    = true;
                         this.m_room.SendStartPickUp();
                     }
                     else
                     {
                         GSPacketIn pkg = this.m_room.Host.Out.SendMessage(eMessageType.ChatERROR, "Game đã bắt đầu!");
                         this.m_room.SendToAll(pkg, this.m_room.Host);
                         this.m_room.SendCancelPickUp();
                     }
                 }
             }
         }
         RoomMgr.WaitingRoom.SendUpdateRoom(this.m_room);
     }
 }