예제 #1
0
        /// <summary>
        /// 跨服初始化游戏
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public bool KuaFuInitGame(GameClient client)
        {
            long gameId = Global.GetClientKuaFuServerLoginData(client).GameId;

            lock (Mutex)
            {
                CoupleArenaFuBenData fubenData = null;
                if (!GameId2FuBenData.TryGetValue(gameId, out fubenData))
                {
                    fubenData = TianTiClient.getInstance().GetFuBenData(gameId);
                    if (fubenData != null)
                    {
                        if (fubenData.FuBenSeq == 0)
                        {
                            fubenData.FuBenSeq = GameCoreInterface.getinstance().GetNewFuBenSeqId();
                        }
                        GameId2FuBenData.Add(gameId, fubenData);
                    }
                }

                if (fubenData == null)
                {
                    return(false);
                }
                if (fubenData.KfServerId != GameCoreInterface.getinstance().GetLocalServerId())
                {
                    return(false);
                }

                KuaFuFuBenRoleData roleData = null;
                if (fubenData.RoleList == null ||
                    (roleData = fubenData.RoleList.Find(_r => _r.RoleId == client.ClientData.RoleID)) == null)
                {
                    return(false);
                }

                client.ClientData.MapCode         = WarCfg.MapCode;
                client.ClientData.BattleWhichSide = roleData.Side;
                int _posx = 0, _posy = 0;
                if (!GetBirthPoint(client.ClientData.MapCode, client.ClientData.BattleWhichSide,
                                   out _posx, out _posy))
                {
                    LogManager.WriteLog(LogTypes.Error,
                                        string.Format("找不到出生点mapcode={0},side={1}", client.ClientData.MapCode, client.ClientData.BattleWhichSide));
                    return(false);
                }

                client.ClientData.PosX = _posx;
                client.ClientData.PosY = _posy;
                Global.GetClientKuaFuServerLoginData(client).FuBenSeqId = fubenData.FuBenSeq;
                client.ClientData.FuBenSeqID = fubenData.FuBenSeq;
            }

            return(true);
        }
예제 #2
0
        private bool CanAddFuBenRole(TianTiFuBenData tianTiFuBenData, KuaFuRoleData kuaFuRoleData)
        {
            if (tianTiFuBenData.RoleDict.Count == 0)
            {
                return(true);
            }

            KuaFuFuBenRoleData existRole = tianTiFuBenData.RoleDict.Values.FirstOrDefault();
            long rolePairKey             = MakeRolePairKey(kuaFuRoleData.RoleId, existRole.RoleId);

            int fightCount;

            lock (RolePairFightCountDict)
            {
                if (!RolePairFightCountDict.TryGetValue(rolePairKey, out fightCount) || fightCount < Persistence.MaxRolePairFightCount)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        private bool CanAddFuBenRole(TianTiFuBenData tianTiFuBenData, KuaFuRoleData kuaFuRoleData)
        {
            bool result;

            if (tianTiFuBenData.RoleDict.Count == 0)
            {
                result = true;
            }
            else
            {
                KuaFuFuBenRoleData existRole = tianTiFuBenData.RoleDict.Values.FirstOrDefault <KuaFuFuBenRoleData>();
                long rolePairKey             = this.MakeRolePairKey(kuaFuRoleData.RoleId, existRole.RoleId);
                lock (this.RolePairFightCountDict)
                {
                    int fightCount;
                    if (!this.RolePairFightCountDict.TryGetValue(rolePairKey, out fightCount) || fightCount < this.Persistence.MaxRolePairFightCount)
                    {
                        return(true);
                    }
                }
                result = false;
            }
            return(result);
        }
예제 #4
0
        private bool AssignGameFuben(KuaFuRoleData kuaFuRoleData, RangeKey range, DateTime now)
        {
            DateTime           stateEndTime       = now.AddSeconds((double)this.EnterGameSecs);
            TianTiFuBenData    tianTiFuBenData    = null;
            KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData
            {
                ServerId = kuaFuRoleData.ServerId,
                RoleId   = kuaFuRoleData.RoleId
            };
            List <KuaFuRoleData> updateRoleDataList = new List <KuaFuRoleData>();

            if (!this.ProcessTianTiFuBenDataDict.TryGetValue(range, out tianTiFuBenData))
            {
                tianTiFuBenData = new TianTiFuBenData();
                this.ProcessTianTiFuBenDataDict.Add(range, tianTiFuBenData);
            }
            else if (!this.CanAddFuBenRole(tianTiFuBenData, kuaFuRoleData))
            {
                return(true);
            }
            int  roleCount = tianTiFuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData);
            bool result;

            if (roleCount < Consts.TianTiRoleCountTotal)
            {
                result = true;
            }
            else
            {
                try
                {
                    int  kfSrvId       = 0;
                    int  gameId        = this.Persistence.GetNextGameId();
                    bool createSuccess = ClientAgentManager.Instance().AssginKfFuben(this.GameType, (long)gameId, roleCount, out kfSrvId);
                    if (createSuccess)
                    {
                        tianTiFuBenData.ServerId = kfSrvId;
                        tianTiFuBenData.GameId   = gameId;
                        tianTiFuBenData.EndTime  = Global.NowTime.AddMinutes(8.0);
                        this.AddGameFuBen(tianTiFuBenData);
                        this.Persistence.LogCreateTianTiFuBen(tianTiFuBenData.GameId, tianTiFuBenData.ServerId, 0, roleCount);
                        foreach (KuaFuFuBenRoleData role in tianTiFuBenData.RoleDict.Values)
                        {
                            KuaFuRoleKey  key = KuaFuRoleKey.Get(role.ServerId, role.RoleId);
                            KuaFuRoleData kuaFuRoleDataTemp;
                            if (this.RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleDataTemp))
                            {
                                kuaFuRoleDataTemp.UpdateStateTime(tianTiFuBenData.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                            }
                        }
                        tianTiFuBenData.State = GameFuBenState.Start;
                        this.NotifyFuBenRoleEnterGame(tianTiFuBenData);
                        this.ProcessTianTiFuBenDataDict.Remove(range);
                        return(true);
                    }
                    return(false);
                }
                catch (Exception ex)
                {
                    LogManager.WriteExceptionUseCache(ex.ToString());
                }
                result = false;
            }
            return(result);
        }
예제 #5
0
        private void MS_PrepareGame_Update(DateTime now, int param)
        {
            ZorkBattleSceneInfo   matchConfig    = this.SceneDataDict.Values.FirstOrDefault <ZorkBattleSceneInfo>();
            List <KF5v5PiPeiTeam> SignUpTeamList = this.PiPeiDict.Values.ToList <KF5v5PiPeiTeam>();

            if (SignUpTeamList.Count < matchConfig.MaxEnterNum - 1)
            {
                this.StateMachine.SetCurrState(Zork5v5StateMachine.StateType.NotifyEnter, now, param);
                LogManager.WriteLog(LogTypes.Analysis, string.Format("Zork::MS_PrepareGame_Update To:{0} SeasonID:{1} Round:{2}", Zork5v5StateMachine.StateType.NotifyEnter, this.CurrentSeasonID, this.CurrentRound), null, true);
            }
            else
            {
                List <KF5v5PiPeiTeam> TeamStandByList = new List <KF5v5PiPeiTeam>(SignUpTeamList);
                if (TeamStandByList.Count > 0)
                {
                    Random r = new Random((int)now.Ticks);
                    int    i = 0;
                    while (TeamStandByList.Count > 0 && i < TeamStandByList.Count * 2)
                    {
                        int            idx  = r.Next(0, TeamStandByList.Count);
                        int            idx2 = r.Next(0, TeamStandByList.Count);
                        KF5v5PiPeiTeam tmp  = TeamStandByList[idx];
                        TeamStandByList[idx]  = TeamStandByList[idx2];
                        TeamStandByList[idx2] = tmp;
                        i++;
                    }
                }
                int currIdx = 0;
                for (int i = 0; i < TeamStandByList.Count / matchConfig.MaxEnterNum; i++)
                {
                    int zhanduiCount = 0;
                    int side         = 0;
                    KuaFu5v5FuBenData ZorkFuBenData = new KuaFu5v5FuBenData();
                    for (int teamIdx = currIdx; teamIdx < currIdx + matchConfig.MaxEnterNum; teamIdx++)
                    {
                        KF5v5PiPeiTeam team = TeamStandByList[teamIdx];
                        if (ZorkFuBenData.AddZhanDuiWithName(team.TeamID, team.ZhanDuiName, ref zhanduiCount, ref side))
                        {
                            TianTi5v5ZhanDuiData teamData = TianTi5v5Service.GetZhanDuiData(team.TeamID);
                            if (null != teamData)
                            {
                                foreach (TianTi5v5ZhanDuiRoleData role in teamData.teamerList)
                                {
                                    KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData
                                    {
                                        ServerId = team.ServerID,
                                        RoleId   = role.RoleID,
                                        Side     = side
                                    };
                                    ZorkFuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, team.TeamID);
                                }
                            }
                        }
                    }
                    currIdx += matchConfig.MaxEnterNum;
                    this.AssginKfFuben(ZorkFuBenData);
                }
                if (currIdx > 0)
                {
                    TeamStandByList.RemoveRange(0, currIdx);
                }
                if (TeamStandByList.Count >= matchConfig.MaxEnterNum - 1)
                {
                    int zhanduiCount = 0;
                    int side         = 0;
                    KuaFu5v5FuBenData ZorkFuBenData = new KuaFu5v5FuBenData();
                    for (int i = 0; i < TeamStandByList.Count; i++)
                    {
                        KF5v5PiPeiTeam team = TeamStandByList[i];
                        if (ZorkFuBenData.AddZhanDuiWithName(team.TeamID, team.ZhanDuiName, ref zhanduiCount, ref side))
                        {
                            TianTi5v5ZhanDuiData teamData = TianTi5v5Service.GetZhanDuiData(team.TeamID);
                            if (null != teamData)
                            {
                                foreach (TianTi5v5ZhanDuiRoleData role in teamData.teamerList)
                                {
                                    KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData
                                    {
                                        ServerId = team.ServerID,
                                        RoleId   = role.RoleID,
                                        Side     = side
                                    };
                                    ZorkFuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, team.TeamID);
                                }
                            }
                        }
                    }
                    this.AssginKfFuben(ZorkFuBenData);
                }
                else if (TeamStandByList.Count > 0)
                {
                    foreach (KF5v5PiPeiTeam item in TeamStandByList)
                    {
                        this.BybZhanDuiIDSet.Add(item.TeamID);
                    }
                    string zhanduiIdArray = string.Join <int>("|", this.BybZhanDuiIDSet.ToArray <int>());
                    LogManager.WriteLog(LogTypes.Analysis, string.Format("Zork::轮空 SeasonID:{0} Round:{1} zhanduiId:{2} ", this.CurrentSeasonID, this.CurrentRound, zhanduiIdArray), null, true);
                }
                this.StateMachine.SetCurrState(Zork5v5StateMachine.StateType.NotifyEnter, now, param);
                LogManager.WriteLog(LogTypes.Analysis, string.Format("Zork::MS_PrepareGame_Update To:{0} SeasonID:{1} Round:{2}", Zork5v5StateMachine.StateType.NotifyEnter, this.CurrentSeasonID, this.CurrentRound), null, true);
            }
        }
예제 #6
0
        public static bool AssignGameFuben(KF5v5PiPeiTeam kuaFuRoleData, RangeKey range, DateTime now)
        {
            int      roleCount    = 0;
            DateTime stateEndTime = now.AddSeconds((double)TianTi5v5Service.EnterGameSecs);
            List <KuaFuFuBenRoleData> updateRoleDataList = new List <KuaFuFuBenRoleData>();
            KuaFu5v5FuBenData         KuaFu5v5FuBenData  = new KuaFu5v5FuBenData();
            int            side = 0;
            int            removeZhanDuiIDFromPiPeiList = 0;
            KF5v5PiPeiTeam team = kuaFuRoleData;

            if (Consts.TianTiRoleCountTotal > 1)
            {
                foreach (Tuple <KF5v5PiPeiTeam, int, int, int> z in TianTi5v5Service.ProcessPiPeiList)
                {
                    if (z.Item2 >= range.Left && z.Item2 <= range.Right)
                    {
                        if (kuaFuRoleData.GroupIndex >= z.Item3 && kuaFuRoleData.GroupIndex <= z.Item4)
                        {
                            if (TianTi5v5Service.CanAddFuBenRole(kuaFuRoleData.TeamID, z.Item1.TeamID))
                            {
                                removeZhanDuiIDFromPiPeiList = z.Item1.TeamID;
                                team = z.Item1;
                                if (KuaFu5v5FuBenData.AddZhanDui(team.TeamID, ref roleCount, ref side))
                                {
                                    TianTi5v5ZhanDuiData teamData;
                                    if (TianTi5v5Service.ZhanDuiDict.TryGetValue(team.TeamID, out teamData))
                                    {
                                        foreach (TianTi5v5ZhanDuiRoleData role in teamData.teamerList)
                                        {
                                            KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData
                                            {
                                                ServerId = team.ServerID,
                                                RoleId   = role.RoleID,
                                                Side     = side
                                            };
                                            KuaFu5v5FuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, team.TeamID);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (removeZhanDuiIDFromPiPeiList == 0)
                {
                    TianTi5v5Service.ProcessPiPeiList.Add(new Tuple <KF5v5PiPeiTeam, int, int, int>(kuaFuRoleData, kuaFuRoleData.GroupIndex, range.Left, range.Right));
                    return(true);
                }
                TianTi5v5Service.ProcessPiPeiList.RemoveAll((Tuple <KF5v5PiPeiTeam, int, int, int> x) => x.Item1.TeamID == removeZhanDuiIDFromPiPeiList);
                TianTi5v5Service.ProcessPiPeiList.RemoveAll((Tuple <KF5v5PiPeiTeam, int, int, int> x) => x.Item1.TeamID == kuaFuRoleData.TeamID);
            }
            team = kuaFuRoleData;
            if (KuaFu5v5FuBenData.AddZhanDui(team.TeamID, ref roleCount, ref side))
            {
                TianTi5v5ZhanDuiData teamData;
                if (TianTi5v5Service.ZhanDuiDict.TryGetValue(team.TeamID, out teamData))
                {
                    foreach (TianTi5v5ZhanDuiRoleData role in teamData.teamerList)
                    {
                        KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData
                        {
                            ServerId = team.ServerID,
                            RoleId   = role.RoleID,
                            Side     = side
                        };
                        KuaFu5v5FuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, team.TeamID);
                    }
                }
            }
            try
            {
                int  kfSrvId       = 0;
                int  gameId        = TianTi5v5Service.Persistence.GetNextGameId();
                bool createSuccess = ClientAgentManager.Instance().AssginKfFuben(TianTi5v5Service.GameType, (long)gameId, roleCount, out kfSrvId);
                if (createSuccess)
                {
                    KuaFu5v5FuBenData.ServerId  = kfSrvId;
                    KuaFu5v5FuBenData.GameId    = gameId;
                    KuaFu5v5FuBenData.GameType  = (int)TianTi5v5Service.GameType;
                    KuaFu5v5FuBenData.EndTime   = Global.NowTime.AddMinutes(8.0);
                    KuaFu5v5FuBenData.LoginInfo = KuaFuServerManager.GetKuaFuLoginInfo(kuaFuRoleData.ServerID, kfSrvId);
                    TianTi5v5Service.AddGameFuBen(KuaFu5v5FuBenData);
                    TianTi5v5Service.Persistence.LogCreateTianTiFuBen(KuaFu5v5FuBenData.GameId, KuaFu5v5FuBenData.ServerId, 0, roleCount);
                    foreach (int zhanDuiID in KuaFu5v5FuBenData.ZhanDuiDict.Keys)
                    {
                        KF5v5PiPeiTeam kuaFuRoleDataTemp;
                        if (TianTi5v5Service.PiPeiDict.TryGetValue(zhanDuiID, out kuaFuRoleDataTemp))
                        {
                            kuaFuRoleDataTemp.State         = 3;
                            kuaFuRoleDataTemp.StateEndTicks = stateEndTime.Ticks;
                            kuaFuRoleDataTemp.GameId        = KuaFu5v5FuBenData.GameId;
                        }
                    }
                    KuaFu5v5FuBenData.State = GameFuBenState.Start;
                    TianTi5v5Service.NotifyFuBenRoleEnterGame(KuaFu5v5FuBenData);
                    TianTi5v5Service.AddRolePairFightCount(KuaFu5v5FuBenData);
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }
            return(false);
        }
예제 #7
0
        private bool AssignGameFuben(KuaFuRoleData kuaFuRoleData, long waitSecs1, long waitSecs2, DateTime now)
        {
            int      roleCount    = 0;
            DateTime stateEndTime = now.AddSeconds((double)this.EnterGameSecs);
            HuanYingSiYuanFuBenData selectFuben        = null;
            KuaFuFuBenRoleData      kuaFuFuBenRoleData = new KuaFuFuBenRoleData
            {
                ServerId  = kuaFuRoleData.ServerId,
                RoleId    = kuaFuRoleData.RoleId,
                ZhanDouLi = kuaFuRoleData.GameData.ZhanDouLi
            };

            try
            {
                foreach (HuanYingSiYuanFuBenData tmpFuben in this.ShotOfRolesFuBenDataDict.Values)
                {
                    if (tmpFuben.CanRemove())
                    {
                        this.RemoveGameFuBen(tmpFuben);
                    }
                    else if (tmpFuben.CanEnter(kuaFuRoleData.GroupIndex, waitSecs1, waitSecs2))
                    {
                        if (ClientAgentManager.Instance().IsAgentAlive(tmpFuben.ServerId))
                        {
                            roleCount = tmpFuben.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, new GameFuBenRoleCountChanged(this.GameFuBenRoleCountChangedHandler));
                            if (roleCount > 0)
                            {
                                selectFuben = tmpFuben;
                                break;
                            }
                        }
                    }
                }
                if (null == selectFuben)
                {
                    int gameId  = this.Persistence.GetNextGameId();
                    int kfSrvId = 0;
                    if (ClientAgentManager.Instance().AssginKfFuben(this.GameType, (long)gameId, 1, out kfSrvId))
                    {
                        selectFuben            = new HuanYingSiYuanFuBenData();
                        selectFuben.ServerId   = kfSrvId;
                        selectFuben.GameId     = gameId;
                        selectFuben.GroupIndex = kuaFuRoleData.GroupIndex;
                        selectFuben.EndTime    = Global.NowTime.AddMinutes(15.0);
                        this.AddGameFuBen(selectFuben);
                        roleCount = selectFuben.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, new GameFuBenRoleCountChanged(this.GameFuBenRoleCountChangedHandler));
                        this.Persistence.LogCreateHysyFuben(gameId, kfSrvId, 0, 1);
                    }
                }
                if (selectFuben != null && roleCount > 0)
                {
                    if (roleCount == 1)
                    {
                        selectFuben.EndTime = now;
                    }
                    if (selectFuben.State == GameFuBenState.Wait)
                    {
                        if (roleCount == Consts.HuanYingSiYuanRoleCountTotal)
                        {
                            List <KuaFuFuBenRoleData> roleList = selectFuben.SortFuBenRoleList();
                            foreach (KuaFuFuBenRoleData role in roleList)
                            {
                                KuaFuRoleKey  key = KuaFuRoleKey.Get(role.ServerId, role.RoleId);
                                KuaFuRoleData kuaFuRoleDataTemp;
                                if (this.RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleDataTemp))
                                {
                                    kuaFuRoleDataTemp.UpdateStateTime(selectFuben.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                                }
                            }
                            selectFuben.State = GameFuBenState.Start;
                            this.NotifyFuBenRoleEnterGame(selectFuben);
                        }
                        else
                        {
                            kuaFuRoleData.UpdateStateTime(selectFuben.GameId, KuaFuRoleStates.SignUpWaiting, kuaFuRoleData.StateEndTicks);
                            this.NotifyFuBenRoleCount(selectFuben);
                        }
                    }
                    else if (selectFuben.State == GameFuBenState.Start)
                    {
                        kuaFuRoleData.UpdateStateTime(selectFuben.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                        this.NotifyFuBenRoleEnterGame(selectFuben);
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }
            return(false);
        }
예제 #8
0
        private bool AssignGameFuben(KuaFuRoleData kuaFuRoleData, RangeKey range, DateTime now)
        {
            int             roleCount       = 0;
            DateTime        stateEndTime    = now.AddSeconds(EnterGameSecs);
            TianTiFuBenData tianTiFuBenData = null;

            KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData()
            {
                ServerId = kuaFuRoleData.ServerId,
                RoleId   = kuaFuRoleData.RoleId,
            };

            List <KuaFuRoleData> updateRoleDataList = new List <KuaFuRoleData>();

            if (!ProcessTianTiFuBenDataDict.TryGetValue(range, out tianTiFuBenData))
            {
                tianTiFuBenData = new TianTiFuBenData();
                ProcessTianTiFuBenDataDict.Add(range, tianTiFuBenData);
            }
            else if (!CanAddFuBenRole(tianTiFuBenData, kuaFuRoleData))
            {
                return(true);
            }

            roleCount = tianTiFuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData);
            if (roleCount < Consts.TianTiRoleCountTotal)
            {
                return(true);
            }

            try
            {
                int  kfSrvId       = 0;
                int  gameId        = Persistence.GetNextGameId();
                bool createSuccess = ClientAgentManager.Instance().AssginKfFuben(GameType, gameId, roleCount, out kfSrvId);
                if (createSuccess)
                {
                    tianTiFuBenData.ServerId = kfSrvId;
                    tianTiFuBenData.GameId   = gameId;
                    tianTiFuBenData.EndTime  = Global.NowTime.AddMinutes(Consts.TianTiGameFuBenMaxExistMinutes);
                    AddGameFuBen(tianTiFuBenData);

                    Persistence.LogCreateTianTiFuBen(tianTiFuBenData.GameId, tianTiFuBenData.ServerId, 0, roleCount);

                    foreach (var role in tianTiFuBenData.RoleDict.Values)
                    {
                        KuaFuRoleData kuaFuRoleDataTemp;
                        KuaFuRoleKey  key = KuaFuRoleKey.Get(role.ServerId, role.RoleId);
                        if (RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleDataTemp))
                        {
                            kuaFuRoleDataTemp.UpdateStateTime(tianTiFuBenData.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                        }
                    }

                    tianTiFuBenData.State = GameFuBenState.Start;
                    NotifyFuBenRoleEnterGame(tianTiFuBenData);

                    ProcessTianTiFuBenDataDict.Remove(range);
                }
                else
                {
                    //如果分配失败,则返回false,本轮不在尝试分配
                    return(false);
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(false);
        }
예제 #9
0
        private bool AssignGameFuben(KuaFuRoleData kuaFuRoleData, ServerLoadContext context, long waitSecs1, long waitSecs2, DateTime now)
        {
            int                     roleCount               = 0;
            DateTime                stateEndTime            = now.AddSeconds(EnterGameSecs);
            HuanYingSiYuanAgent     huanYingSiYuanAgent     = null;
            HuanYingSiYuanFuBenData huanYingSiYuanFuBenData = null;
            IKuaFuClient            kuaFuClient             = null;

            KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData()
            {
                ServerId  = kuaFuRoleData.ServerId,
                RoleId    = kuaFuRoleData.RoleId,
                ZhanDouLi = HuanYingSiYuanGameData.GetZhanDouLi(kuaFuRoleData.GameData),
            };

            List <KuaFuRoleData> updateRoleDataList = new List <KuaFuRoleData>();

            try
            {
                //先检测是否有需要补充人的队伍
                foreach (var fuBenData in ShotOfRolesFuBenDataDict.Values)
                {
                    //分组编号要相等
                    if (fuBenData.CanRemove())
                    {
                        RemoveGameFuBen(fuBenData);
                    }
                    else if (fuBenData.CanEnter(kuaFuRoleData.GroupIndex, waitSecs1, waitSecs2))
                    {
                        if (ServerId2KuaFuClientAgent.TryGetValue(fuBenData.ServerId, out huanYingSiYuanAgent) && huanYingSiYuanAgent.IsAlive)
                        {
                            roleCount = fuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, GameFuBenRoleCountChangedHandler);
                            if (roleCount > 0)
                            {
                                huanYingSiYuanFuBenData = fuBenData;
                                break;
                            }
                        }
                    }
                }

                if (null == huanYingSiYuanFuBenData)
                {
                    //按负载状态在一个跨服活动服务器上分配一个新的游戏副本,并加入
                    LinkedListNode <KuaFuServerGameConfig> node = context.IdelActiveServerQueue.First;
                    int count = context.IdelActiveServerQueue.Count;
                    for (int i = 0; i < count && node != null; i++)
                    {
                        KuaFuServerGameConfig srv = node.Value;
                        LinkedListNode <KuaFuServerGameConfig> next = node.Next;

                        if (ServerId2KuaFuClientAgent.TryGetValue(srv.ServerId, out huanYingSiYuanAgent) && huanYingSiYuanAgent.IsAlive)
                        {
                            int serverLoad = huanYingSiYuanAgent.GetAliveGameFuBenCount();
                            if (serverLoad < srv.Capacity && serverLoad <= context.ServerLoadAvg)
                            {
                                try
                                {
                                    huanYingSiYuanFuBenData = Persistence.CreateHysyGameFuBen(huanYingSiYuanAgent, kuaFuRoleData.GroupIndex, 1);
                                    if (huanYingSiYuanFuBenData != null)
                                    {
                                        AddGameFuBen(huanYingSiYuanFuBenData, huanYingSiYuanAgent);
                                        roleCount = huanYingSiYuanFuBenData.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, GameFuBenRoleCountChangedHandler);
                                        if (roleCount > 0)
                                        {
                                            context.AlivedGameFuBenCount++;
                                            context.CalcServerLoadAvg();
                                            break;
                                        }
                                    }
                                }
                                catch (System.Exception ex)
                                {
                                    huanYingSiYuanAgent.MaxActiveTicks = 0;
                                }
                            }
                            else
                            {
                                context.IdelActiveServerQueue.Remove(node);
                                if (serverLoad < srv.Capacity)
                                {
                                    context.IdelActiveServerQueue.AddLast(node);
                                }
                            }
                        }

                        node = next;
                    }
                }

                if (huanYingSiYuanFuBenData != null && roleCount > 0)
                {
                    if (roleCount == 1)
                    {
                        huanYingSiYuanFuBenData.EndTime = now; //第一个人进入时,重置副本创建时间
                    }

                    if (huanYingSiYuanFuBenData.State == GameFuBenState.Wait)
                    {
                        if (roleCount == Consts.HuanYingSiYuanRoleCountTotal)
                        {
                            List <KuaFuFuBenRoleData> roleList = huanYingSiYuanFuBenData.SortFuBenRoleList();
                            foreach (var role in roleList)
                            {
                                KuaFuRoleData kuaFuRoleDataTemp;
                                KuaFuRoleKey  key = KuaFuRoleKey.Get(role.ServerId, role.RoleId);
                                if (RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleDataTemp))
                                {
                                    kuaFuRoleDataTemp.UpdateStateTime(huanYingSiYuanFuBenData.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                                }
                            }

                            huanYingSiYuanFuBenData.State = GameFuBenState.Start;
                            NotifyFuBenRoleEnterGame(huanYingSiYuanFuBenData);
                        }
                        else
                        {
                            kuaFuRoleData.UpdateStateTime(huanYingSiYuanFuBenData.GameId, KuaFuRoleStates.SignUpWaiting, kuaFuRoleData.StateEndTicks);
                            NotifyFuBenRoleCount(huanYingSiYuanFuBenData);
                        }
                    }
                    else if (huanYingSiYuanFuBenData.State == GameFuBenState.Start)
                    {
                        kuaFuRoleData.UpdateStateTime(huanYingSiYuanFuBenData.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                        NotifyFuBenRoleEnterGame(huanYingSiYuanFuBenData);
                    }
                }
                else
                {
                    //如果分配失败,则返回false,本轮不在尝试分配
                    return(false);
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(false);
        }
예제 #10
0
        private bool AssignGameFuben(KuaFuRoleData kuaFuRoleData, long waitSecs1, long waitSecs2, DateTime now)
        {
            int      roleCount    = 0;
            DateTime stateEndTime = now.AddSeconds(EnterGameSecs);
            HuanYingSiYuanFuBenData selectFuben = null;

            KuaFuFuBenRoleData kuaFuFuBenRoleData = new KuaFuFuBenRoleData()
            {
                ServerId  = kuaFuRoleData.ServerId,
                RoleId    = kuaFuRoleData.RoleId,
                ZhanDouLi = HuanYingSiYuanGameData.GetZhanDouLi(kuaFuRoleData.GameData),
            };

            try
            {
                //先检测是否有需要补充人的队伍
                foreach (var tmpFuben in ShotOfRolesFuBenDataDict.Values)
                {
                    //分组编号要相等
                    if (tmpFuben.CanRemove())
                    {
                        RemoveGameFuBen(tmpFuben);
                    }
                    else if (tmpFuben.CanEnter(kuaFuRoleData.GroupIndex, waitSecs1, waitSecs2))
                    {
                        if (ClientAgentManager.Instance().IsAgentAlive(tmpFuben.ServerId))
                        {
                            roleCount = tmpFuben.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, GameFuBenRoleCountChangedHandler);
                            if (roleCount > 0)
                            {
                                selectFuben = tmpFuben;
                                break;
                            }
                        }
                    }
                }

                if (null == selectFuben)
                {
                    int gameId  = Persistence.GetNextGameId();
                    int kfSrvId = 0;
                    if (ClientAgentManager.Instance().AssginKfFuben(GameType, gameId, 1, out kfSrvId))
                    {
                        selectFuben            = new HuanYingSiYuanFuBenData();
                        selectFuben.ServerId   = kfSrvId;
                        selectFuben.GameId     = gameId;
                        selectFuben.GroupIndex = kuaFuRoleData.GroupIndex;
                        selectFuben.EndTime    = Global.NowTime.AddMinutes(Consts.HuanYingSiYuanGameFuBenMaxExistMinutes);
                        AddGameFuBen(selectFuben);
                        roleCount = selectFuben.AddKuaFuFuBenRoleData(kuaFuFuBenRoleData, GameFuBenRoleCountChangedHandler);
                        Persistence.LogCreateHysyFuben(gameId, kfSrvId, 0, 1);
                    }
                }

                if (selectFuben != null && roleCount > 0)
                {
                    if (roleCount == 1)
                    {
                        selectFuben.EndTime = now; //第一个人进入时,重置副本创建时间
                    }

                    if (selectFuben.State == GameFuBenState.Wait)
                    {
                        if (roleCount == Consts.HuanYingSiYuanRoleCountTotal)
                        {
                            List <KuaFuFuBenRoleData> roleList = selectFuben.SortFuBenRoleList();
                            foreach (var role in roleList)
                            {
                                KuaFuRoleData kuaFuRoleDataTemp;
                                KuaFuRoleKey  key = KuaFuRoleKey.Get(role.ServerId, role.RoleId);
                                if (RoleIdKuaFuRoleDataDict.TryGetValue(key, out kuaFuRoleDataTemp))
                                {
                                    kuaFuRoleDataTemp.UpdateStateTime(selectFuben.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                                }
                            }

                            selectFuben.State = GameFuBenState.Start;
                            NotifyFuBenRoleEnterGame(selectFuben);
                        }
                        else
                        {
                            kuaFuRoleData.UpdateStateTime(selectFuben.GameId, KuaFuRoleStates.SignUpWaiting, kuaFuRoleData.StateEndTicks);
                            NotifyFuBenRoleCount(selectFuben);
                        }
                    }
                    else if (selectFuben.State == GameFuBenState.Start)
                    {
                        kuaFuRoleData.UpdateStateTime(selectFuben.GameId, KuaFuRoleStates.NotifyEnterGame, stateEndTime.Ticks);
                        NotifyFuBenRoleEnterGame(selectFuben);
                    }
                }
                else
                {
                    //如果分配失败,则返回false,本轮不在尝试分配
                    return(false);
                }

                return(true);
            }
            catch (System.Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(false);
        }