Пример #1
0
        public LadderMatchEntityResponse GetMatch(Guid managerId, Guid matchId)
        {
            var match = MemcachedFactory.LadderMatchClient.Get <LadderMatchEntity>(matchId);

            if (match == null)
            {
                match = LadderMatchMgr.GetById(matchId);
                if (match == null)
                {
                    return(ResponseHelper.InvalidParameter <LadderMatchEntityResponse>());
                }
            }

            var response = ResponseHelper.CreateSuccess <LadderMatchEntityResponse>();

            response.Data        = match;
            response.Data.PopMsg = MemcachedFactory.MatchPopClient.Get <List <PopMessageEntity> >(managerId);
            if (response.Data.PopMsg != null)
            {
                MemcachedFactory.MatchPopClient.Delete(managerId);
            }
            return(response);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="matchData"></param>
        /// <param name="laddermatch"></param>
        private void Fight(BaseMatchData matchData, LadderMatchEntity laddermatch)
        {
            try
            {
                if (laddermatch.HomeIsBot && laddermatch.AwayIsBot)
                {
                    laddermatch.HomeScore = 0;
                    laddermatch.AwayScore = 0;
                    laddermatch.Status    = (int)EnumLadderStatus.End;

                    //保存比赛
                    LadderMatchMgr.Insert(laddermatch);
                    return;
                }
                else
                {
                    MatchCore.CreateMatch(matchData);
                    ////测试用 ------------
                    //matchData.ErrorCode = (int)MessageCode.Success;
                    //matchData.Home.Score = 5;
                    //matchData.Away.Score = 2;

                    if (matchData.ErrorCode == (int)MessageCode.Success)
                    {
                        laddermatch.HomeScore = matchData.Home.Score;
                        laddermatch.AwayScore = matchData.Away.Score;
                        laddermatch.Status    = (int)EnumLadderStatus.End;
                        CalPrizePoint(laddermatch);

                        int returnCode = -1;
                        //保存比赛
                        LadderMatchMgr.SaveMatch(laddermatch.LadderId, laddermatch.HomeId, laddermatch.AwayId,
                                                 laddermatch.HomeName, laddermatch.AwayName,
                                                 laddermatch.HomeLadderScore, laddermatch.AwayLadderScore, laddermatch.HomeScore,
                                                 laddermatch.AwayScore, laddermatch.HomeCoin, laddermatch.AwayCoin, laddermatch.HomeExp,
                                                 laddermatch.AwayExp,
                                                 laddermatch.HomeIsBot, laddermatch.AwayIsBot, laddermatch.GroupIndex,
                                                 laddermatch.PrizeHomeScore, laddermatch.PrizeAwayScore,
                                                 laddermatch.RowTime, laddermatch.Idx, ref returnCode);

                        if (!laddermatch.HomeIsBot)
                        {
                            AddManagerData(laddermatch.HomeId, laddermatch.HomeExp, laddermatch.HomeCoin, 0,
                                           EnumCoinChargeSourceType.Ladder, laddermatch.Idx.ToString() + "_home");
                        }
                        if (!laddermatch.AwayIsBot)
                        {
                            AddManagerData(laddermatch.AwayId, laddermatch.AwayExp, laddermatch.AwayCoin, 0,
                                           EnumCoinChargeSourceType.Ladder, laddermatch.Idx.ToString() + "_away");
                        }
                        int homeWinType = (int)CalWinType(laddermatch.HomeScore, laddermatch.AwayScore);
                        int awayWinType = (int)CalWinType(laddermatch.AwayScore, laddermatch.HomeScore);

                        if (!laddermatch.HomeIsBot && homeWinType == (int)EnumWinType.Win)  //胜场活动
                        {
                            ActivityExThread.Instance.LadderDayPrize(laddermatch.HomeId);
                        }
                        if (!laddermatch.AwayIsBot && awayWinType == (int)EnumWinType.Win)  //胜场活动
                        {
                            ActivityExThread.Instance.LadderDayPrize(laddermatch.AwayId);
                        }
                        if (!laddermatch.HomeIsBot)
                        {
                            var homepop = TaskHandler.Instance.LadderFight(laddermatch.HomeId, homeWinType);
                            if (homepop != null)
                            {
                                MemcachedFactory.MatchPopClient.Set(laddermatch.HomeId, homepop);
                            }

                            MatchCore.SaveMatchStat(laddermatch.HomeId, EnumMatchType.Ladder, laddermatch.HomeScore,
                                                    laddermatch.AwayScore, laddermatch.HomeScore);
                            //ActivityExThread.Instance.Ladder(laddermatch.HomeId, laddermatch.HomeLadderScore + laddermatch.PrizeHomeScore, homeWinType);
                            //Games.NBall.Core.Guild.GuildMessage.Instance().LadderActive(laddermatch.HomeId);
                            //ActiveCore.Instance.AddActive(laddermatch.HomeId, EnumActiveType.Ladder, 1);

                            //记录成就相关数据
                            AchievementTaskCore.Instance.UpdateLadderGoals(laddermatch.HomeId, laddermatch.HomeScore,
                                                                           (EnumWinType)homeWinType, laddermatch.HomeLadderScore + laddermatch.PrizeHomeScore);

                            if (laddermatch.HomeIsHook)
                            {
                                LadderThread.Instance.UpdateHookScore(laddermatch.HomeId, laddermatch.PrizeHomeScore,
                                                                      laddermatch.HomeScore > laddermatch.AwayScore, laddermatch.HomeScore,
                                                                      laddermatch.AwayScore, laddermatch.HomeName, laddermatch.AwayName,
                                                                      laddermatch.HomeCoin);
                            }
                        }
                        if (!laddermatch.AwayIsBot)
                        {
                            var awaypop = TaskHandler.Instance.LadderFight(laddermatch.AwayId, awayWinType);
                            if (awaypop != null)
                            {
                                MemcachedFactory.MatchPopClient.Set(laddermatch.AwayId, awaypop);
                            }
                            MatchCore.SaveMatchStat(laddermatch.AwayId, EnumMatchType.Ladder, laddermatch.AwayScore,
                                                    laddermatch.HomeScore, laddermatch.AwayScore);
                            //ActivityExThread.Instance.Ladder(laddermatch.AwayId, laddermatch.AwayLadderScore + laddermatch.PrizeAwayScore, awayWinType);
                            //Games.NBall.Core.Guild.GuildMessage.Instance().LadderActive(laddermatch.AwayId);
                            //ActiveCore.Instance.AddActive(laddermatch.AwayId, EnumActiveType.Ladder, 1);

                            //记录成就相关数据
                            AchievementTaskCore.Instance.UpdateLadderGoals(laddermatch.AwayId, laddermatch.AwayScore,
                                                                           (EnumWinType)awayWinType, laddermatch.AwayLadderScore + laddermatch.PrizeAwayScore);
                            if (laddermatch.AwayIsHook)
                            {
                                LadderThread.Instance.UpdateHookScore(laddermatch.AwayId, laddermatch.PrizeAwayScore,
                                                                      laddermatch.AwayScore < laddermatch.HomeScore, laddermatch.HomeScore,
                                                                      laddermatch.AwayScore, laddermatch.HomeName, laddermatch.AwayName,
                                                                      laddermatch.AwayCoin);
                            }
                        }
                        if (!laddermatch.HomeIsBot)
                        {
                            var manager = ManagerCore.Instance.GetManager(laddermatch.HomeId);
                            if (manager != null)
                            {
                                int cd = LadderCore.Instance.LadderNotVipMatchCD;
                                if (manager.VipLevel > 0)
                                {
                                    cd = LadderCore.Instance.LadderVipMatchCD;
                                }
                                if (!LadderCore.Instance._ManagerMatchCD.ContainsKey(laddermatch.HomeId)) //加cd
                                {
                                    LadderCore.Instance._ManagerMatchCD.TryAdd(laddermatch.HomeId,
                                                                               DateTime.Now.AddSeconds(cd));
                                }
                                else
                                {
                                    LadderCore.Instance._ManagerMatchCD[laddermatch.HomeId] = DateTime.Now.AddSeconds(cd);
                                }
                            }
                        }
                        if (!laddermatch.AwayIsBot)
                        {
                            var manager = ManagerCore.Instance.GetManager(laddermatch.AwayId);
                            if (manager != null)
                            {
                                int cd = LadderCore.Instance.LadderNotVipMatchCD;
                                if (manager.VipLevel > 0)
                                {
                                    cd = LadderCore.Instance.LadderVipMatchCD;
                                }
                                if (!LadderCore.Instance._ManagerMatchCD.ContainsKey(laddermatch.AwayId)) //加cd
                                {
                                    LadderCore.Instance._ManagerMatchCD.TryAdd(laddermatch.AwayId,
                                                                               DateTime.Now.AddSeconds(cd));
                                }
                                else
                                {
                                    LadderCore.Instance._ManagerMatchCD[laddermatch.AwayId] = DateTime.Now.AddSeconds(cd);
                                }
                            }
                        }
                    }
                    MemcachedFactory.LadderMatchClient.Set <LadderMatchEntity>(laddermatch.Idx, laddermatch);
                }
                matchData   = null;
                laddermatch = null;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("天梯比赛", ex);
            }
            if (laddermatch != null)
            {
                MemcachedFactory.LadderMatchClient.Delete(laddermatch.Idx);
                var match = LadderMatchMgr.GetById(laddermatch.Idx);
                MemcachedFactory.LadderMatchClient.Set(laddermatch.Idx, match);
            }
        }