public static void RemoveGameFuBen(KuaFu5v5FuBenData KuaFu5v5FuBenData)
        {
            int gameId = KuaFu5v5FuBenData.GameId;
            KuaFu5v5FuBenData KuaFu5v5FuBenDataTemp;

            if (TianTi5v5Service.FuBenDataDict.TryRemove(gameId, out KuaFu5v5FuBenDataTemp))
            {
                KuaFu5v5FuBenDataTemp.State = GameFuBenState.End;
            }
            ClientAgentManager.Instance().RemoveKfFuben(TianTi5v5Service.GameType, KuaFu5v5FuBenData.ServerId, (long)KuaFu5v5FuBenData.GameId);
            lock (KuaFu5v5FuBenData)
            {
                foreach (KeyValuePair <int, int> kv in KuaFu5v5FuBenData.ZhanDuiDict)
                {
                    KF5v5PiPeiTeam team;
                    if (TianTi5v5Service.PiPeiDict.TryGetValue(kv.Key, out team))
                    {
                        if (team.GameId == gameId && team.State >= 3)
                        {
                            team.State = 0;
                        }
                    }
                }
            }
        }
 public static void NotifyFuBenRoleEnterGame(KuaFu5v5FuBenData fuBenData)
 {
     try
     {
         lock (fuBenData)
         {
             List <int> serverIDs = new List <int>();
             foreach (KuaFuFuBenRoleData role in fuBenData.RoleDict.Values)
             {
                 if (!serverIDs.Contains(role.ServerId))
                 {
                     serverIDs.Add(role.ServerId);
                     AsyncDataItem evItem = new AsyncDataItem(KuaFuEventTypes.KuaFu5v5UpdateAndNotifyEnterGame, new object[]
                     {
                         fuBenData
                     });
                     ClientAgentManager.Instance().PostAsyncEvent(role.ServerId, TianTi5v5Service.ChannelGameType, evItem);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
        public static void AddRolePairFightCount(KuaFu5v5FuBenData KuaFu5v5FuBenData)
        {
            int roleId  = 0;
            int roleId2 = 0;

            if (KuaFu5v5FuBenData.ZhanDuiDict.Count >= 2)
            {
                foreach (int id in KuaFu5v5FuBenData.ZhanDuiDict.Keys)
                {
                    if (roleId == 0)
                    {
                        roleId = id;
                    }
                    else
                    {
                        roleId2 = id;
                    }
                }
                long rolePairKey = ListExt.MakeRolePairKey(roleId, roleId2);
                lock (TianTi5v5Service.RolePairFightCountDict)
                {
                    int fightCount;
                    if (!TianTi5v5Service.RolePairFightCountDict.TryGetValue(rolePairKey, out fightCount))
                    {
                        TianTi5v5Service.RolePairFightCountDict[rolePairKey] = 1;
                    }
                    else
                    {
                        TianTi5v5Service.RolePairFightCountDict[rolePairKey] = fightCount + 1;
                    }
                }
            }
        }
Exemple #4
0
 private void HandleUnCompleteFuBenData()
 {
     foreach (KeyValuePair <int, KuaFu5v5FuBenData> fubenItem in this.FuBenDataDict)
     {
         KuaFu5v5FuBenData fubenData = fubenItem.Value;
         ClientAgentManager.Instance().RemoveKfFuben(this.GameType, fubenData.ServerId, (long)fubenData.GameId);
     }
     this.FuBenDataDict.Clear();
     this.ZhanDuiIDVsGameIDDict.Clear();
 }
        public static KuaFu5v5FuBenData ZhanDuiGetFuBenData(int gameId)
        {
            KuaFu5v5FuBenData kuaFuFuBenData = null;
            KuaFu5v5FuBenData result;

            if (TianTi5v5Service.FuBenDataDict.TryGetValue(gameId, out kuaFuFuBenData) && kuaFuFuBenData.State < GameFuBenState.End)
            {
                result = kuaFuFuBenData;
            }
            else
            {
                result = null;
            }
            return(result);
        }
Exemple #6
0
        public KuaFu5v5FuBenData GetFuBenDataByGameId_ZorkBattle(int gameid)
        {
            KuaFu5v5FuBenData fuBenData = null;

            try
            {
                lock (this.Mutex)
                {
                    this.FuBenDataDict.TryGetValue(gameid, out fuBenData);
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Error, "Zork5v5Service.GetFuBenDataByGameId_ZorkBattle failed!", ex, true);
            }
            return(fuBenData);
        }
Exemple #7
0
        private void AssginKfFuben(KuaFu5v5FuBenData fubenData)
        {
            int toServerId = 0;
            int gameId     = 0;

            gameId = TianTiPersistence.Instance.GetNextGameId();
            int roleNum = fubenData.ZhanDuiDict.Count * 5;

            if (ClientAgentManager.Instance().AssginKfFuben(this.GameType, (long)gameId, roleNum, out toServerId))
            {
                fubenData.ServerId         = toServerId;
                fubenData.GameId           = gameId;
                fubenData.GameType         = (int)this.GameType;
                fubenData.LoginInfo        = KuaFuServerManager.GetKuaFuLoginInfo(0, toServerId);
                this.FuBenDataDict[gameId] = fubenData;
                foreach (int zhanDuiID in fubenData.ZhanDuiDict.Keys)
                {
                    this.ZhanDuiIDVsGameIDDict[zhanDuiID] = gameId;
                    KF5v5PiPeiTeam kuaFuRoleDataTemp;
                    if (this.PiPeiDict.TryGetValue(zhanDuiID, out kuaFuRoleDataTemp))
                    {
                        kuaFuRoleDataTemp.GameId = fubenData.GameId;
                    }
                }
                string zhanduiIdArray = string.Join <int>("|", fubenData.ZhanDuiDict.Keys.ToArray <int>());
                LogManager.WriteLog(LogTypes.Analysis, string.Format("Zork::分组 SeasonID:{0} gameId:{1} zhanduiId:{2} Round:{3}", new object[]
                {
                    this.CurrentSeasonID,
                    gameId,
                    zhanduiIdArray,
                    this.CurrentRound
                }), null, true);
            }
            else
            {
                string zhanduiIdArray = string.Join <int>("|", fubenData.ZhanDuiDict.Keys.ToArray <int>());
                LogManager.WriteLog(LogTypes.Analysis, string.Format("Zork::分配游戏服务器失败 SeasonID:{0} gameId:{1} zhanduiId:{2} Round:{3}", new object[]
                {
                    this.CurrentSeasonID,
                    gameId,
                    zhanduiIdArray,
                    this.CurrentRound
                }), null, true);
            }
        }
Exemple #8
0
        private void MS_NotifyEnter_Update(DateTime now, int param)
        {
            ZorkBattleSceneInfo matchConfig = this.SceneDataDict.Values.FirstOrDefault <ZorkBattleSceneInfo>();

            Zork5v5StateMachine.StateType GameState = Zork5v5StateMachine.StateType.None;
            for (int i = 0; i < matchConfig.TimePoints.Count - 1; i += 2)
            {
                if (now.DayOfWeek == (DayOfWeek)matchConfig.TimePoints[i].Days)
                {
                    int RoundSeconds  = matchConfig.BattleSignSecs + matchConfig.PrepareSecs + matchConfig.FightingSecs + matchConfig.ClearRolesSecs;
                    int MatchPerRound = (int)(matchConfig.SecondsOfDay[i + 1] - matchConfig.SecondsOfDay[i]) / RoundSeconds;
                    for (int matchloop = 0; matchloop < MatchPerRound; matchloop++)
                    {
                        int signSeconds  = (int)matchConfig.SecondsOfDay[i] + RoundSeconds * matchloop;
                        int startSeconds = signSeconds + matchConfig.BattleSignSecs;
                        int endSeconds   = startSeconds + RoundSeconds - matchConfig.BattleSignSecs;
                        if ((double)startSeconds <= now.TimeOfDay.TotalSeconds && now.TimeOfDay.TotalSeconds < (double)endSeconds)
                        {
                            GameState = Zork5v5StateMachine.StateType.GameStart;
                        }
                    }
                }
            }
            if (GameState == Zork5v5StateMachine.StateType.GameStart)
            {
                foreach (KuaFu5v5FuBenData item in this.FuBenDataDict.Values)
                {
                    KuaFu5v5FuBenData SyncData = item;
                    ClientAgentManager.Instance().BroadCastAsyncEvent(this.EvItemGameType, new AsyncDataItem(KuaFuEventTypes.Zork5v5NtfEnter, new object[]
                    {
                        SyncData
                    }), 0);
                }
                this.StateMachine.SetCurrState(GameState, now, param);
                LogManager.WriteLog(LogTypes.Analysis, string.Format("Zork::MS_NotifyEnter_Update To:{0} SeasonID:{1} Round:{2}", GameState, this.CurrentSeasonID, this.CurrentRound), null, true);
            }
        }
Exemple #9
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);
            }
        }
 public static void AddGameFuBen(KuaFu5v5FuBenData KuaFu5v5FuBenData)
 {
     TianTi5v5Service.FuBenDataDict[KuaFu5v5FuBenData.GameId] = KuaFu5v5FuBenData;
 }
        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);
        }