public static int ZhanDuiRoleSignUp(int serverId, int gameType, int zhanDuiID, long zhanLi = 1L, int groupIndex = 1)
        {
            int result = 1;
            Lazy <KF5v5PiPeiTeam> lazy = new Lazy <KF5v5PiPeiTeam>(() => new KF5v5PiPeiTeam
            {
                TeamID        = zhanDuiID,
                GroupIndex    = groupIndex,
                ServerID      = serverId,
                ZhanDouLi     = zhanLi,
                StateEndTicks = TimeUtil.NOW()
            });
            KF5v5PiPeiTeam piPeiTeam = TianTi5v5Service.PiPeiDict.GetOrAdd(zhanDuiID, (int x) => lazy.Value);
            int            oldGameId = 0;

            lock (piPeiTeam)
            {
                oldGameId               = piPeiTeam.GameId;
                piPeiTeam.GameId        = 0;
                piPeiTeam.State         = 1;
                piPeiTeam.ServerID      = serverId;
                piPeiTeam.ZhanDouLi     = zhanLi;
                piPeiTeam.GroupIndex    = groupIndex;
                piPeiTeam.StateEndTicks = Global.NowTime.Ticks;
                int rndSecs = Global.GetRandomNumber(0, 10);
                LogManager.WriteLog(LogTypes.Info, string.Format("组队竞技战队随机延时,zhanduiid={0}, duanwei={1},time={2}", zhanDuiID, groupIndex, rndSecs), null, true);
            }
            if (oldGameId > 0)
            {
                TianTi5v5Service.RemoveRoleFromFuBen(oldGameId, zhanDuiID);
            }
            return(result);
        }
Exemple #2
0
        public int SignUp_ZorkBattle(int zhanduiID, int serverID)
        {
            int result = 0;

            try
            {
                lock (this.Mutex)
                {
                    DateTime now = TimeUtil.NowDateTime();
                    if (!this.CheckOpenState(now))
                    {
                        result = -11004;
                        return(result);
                    }
                    if (this.StateMachine.GetCurrState() != Zork5v5StateMachine.StateType.SignUp && this.StateMachine.GetCurrState() != Zork5v5StateMachine.StateType.RankAnalyse)
                    {
                        result = -2001;
                        return(result);
                    }
                    TianTi5v5ZhanDuiData zhanduiData = TianTi5v5Service.GetZhanDuiData(zhanduiID);
                    if (null == zhanduiData)
                    {
                        result = -5;
                        return(result);
                    }
                    if (this.PiPeiDict.ContainsKey(zhanduiID))
                    {
                        result = -5;
                        return(result);
                    }
                    KF5v5PiPeiTeam pipeiTeam = new KF5v5PiPeiTeam
                    {
                        TeamID      = zhanduiID,
                        ServerID    = serverID,
                        GroupIndex  = this.CalDuanWeiByJiFen(zhanduiData.ZorkJiFen),
                        ZhanDouLi   = zhanduiData.ZhanDouLi,
                        ZorkJiFen   = zhanduiData.ZorkJiFen,
                        ZhanDuiName = KuaFuServerManager.FormatName(zhanduiData.ZoneID, zhanduiData.ZhanDuiName)
                    };
                    this.PiPeiDict[zhanduiID] = pipeiTeam;
                    LogManager.WriteLog(LogTypes.Analysis, string.Format("Zork::比赛报名 SeasonID:{0} Round:{1} ZhanDuiID:{2}", this.CurrentSeasonID, this.CurrentRound, zhanduiID), null, true);
                }
                return(result);
            }
            catch (Exception ex)
            {
                result = -11;
                LogManager.WriteLog(LogTypes.Error, "Zork5v5Service.SignUp_ZorkBattle failed!", ex, true);
            }
            return(result);
        }
Exemple #3
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 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);
        }