示例#1
0
        public byte[] Exec(BaseMatchData stateObj, MatchInput matchInput)
        {
            MatchReport resultEntity = null;
            var         home         = stateObj.Home.ManagerId;
            var         away         = stateObj.Away.ManagerId;

            int i = 0;

            do
            {
                try
                {
                    byte[] process = null;
                    //固定新手引导首场
                    if (ShareUtil.IsAppRXYC && stateObj.IsGuide && stateObj.MatchType == (int)EnumMatchType.PlayerKill)
                    {
                        process = MatchReportCache.Instance().GetReport();
                    }
                    if (null == process)
                    {
                        process = _matchClient.CreateMatch(matchInput);
                    }
                    if (process != null && process.Length > 10)
                    {
                        resultEntity = NB.Match.Base.Util.IOUtil.BinRead <MatchReport>(process, 0);
                    }
                    if (resultEntity == null)
                    {
                        throw new Exception("the callback MatchStream is empty");
                    }
                    else
                    {
                        if (stateObj.NoDraw && resultEntity.HomeScore == resultEntity.AwayScore)
                        {
                            i++;
                        }
                        else
                        {
                            stateObj.ErrorCode  = (int)MessageCode.Success;
                            stateObj.Home.Score = resultEntity.HomeScore;
                            stateObj.Away.Score = resultEntity.AwayScore;
                            return(process);
                        }
                    }
                }
                catch (Exception ex)
                {
                    i++;

                    if (i >= MATCHRetryTimes)
                    {
                        SystemlogMgr.Error("MatchThread Exec", string.Format("Home:{0},Away:{1},Message:{2},StackTrace:{3}", home, away, ex.Message, ex.StackTrace));
                        //SystemlogMgr.Error("MatchThread Exec", ex);
                        stateObj.ErrorCode = (int)MessageCode.Exception;
                        return(null);
                    }
                }
            }while (i < MATCHRetryTimes);
            return(null);
        }
示例#2
0
        /// <summary>
        /// Runs the arena match.
        /// </summary>
        void RunMatch()
        {
            if (_fightDic == null)
            {
                return;
            }
            foreach (var item in _fightDic.Values)
            {
                var matchHome = new MatchManagerInfo(item.HomeId, item.HomeSiteId, false, item.HomeIsBot);
                var matchAway = new MatchManagerInfo(item.AwayId, item.AwaySiteId, false, item.AwayIsBot);
                var matchData = new BaseMatchData((int)EnumMatchType.CrossLadder, item.Idx, matchHome, matchAway);
                matchData.ErrorCode = (int)MessageCode.MatchWait;

                MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);

                //使用多线程
                _nbThreadPool.Add(() => Fight(matchData, item));
            }

            _nbThreadPool.WaitAll();
            _ladderInfo.Groups  = _fightDic.Count;
            _ladderInfo.RowTime = DateTime.Now;

            _ladderInfo.Season     = CacheFactory.CrossLadderCache.GetCurrentSeasonIndex();
            _ladderInfo.Status     = 2;
            _ladderInfo.UpdateTime = DateTime.Now;

            _ladderInfo.FightList = null;
            _fightDic             = null;

            CrossladderInfoMgr.Insert(_ladderInfo);
            _ladderInfo = null;
        }
示例#3
0
        public static BaseMatchData CreateMatch(EnumMatchType matchType, Guid homeId, Guid awayId)
        {
            var matchId  = ShareUtil.GenerateComb();
            var stateObj = new BaseMatchData((int)matchType, matchId, homeId, awayId);

            MatchThread.Instance.CreateMatch(stateObj);
            return(stateObj);
        }
示例#4
0
 void Handle(BaseMatchData matchData, MatchStateCallback callback, object matchState = null)
 {
     if (null == matchData || matchData.Home == null || matchData.Away == null)
     {
         matchData.ErrorCode = (int)MessageCode.NbParameterError;
         return;
     }
     HandleMatch(matchData, callback, matchState);
 }
示例#5
0
 public MessageCode CreateMatchAsyn(BaseMatchData stateObj, MatchStateCallback callback, object matchState = null)
 {
     if (null == stateObj || stateObj.Home == null || stateObj.Away == null)
     {
         return(MessageCode.MatchStateObjisNull);
     }
     stateObj.ErrorCode = (int)MessageCode.MatchWait;
     stateObj.RowTime   = DateTime.Now;
     MemcachedFactory.MatchClient.Set <BaseMatchData>(stateObj.MatchId, stateObj);
     //_poolMatch.Add(() => Handle(stateObj,callback));
     PushMatch(stateObj, callback, matchState);
     return(MessageCode.Success);
 }
示例#6
0
 public MessageCode Query(Guid battleId, out BaseMatchData matchData)
 {
     matchData = null;
     matchData = MemcachedFactory.MatchClient.Get <BaseMatchData>(battleId.ToString());
     if (null != matchData)
     {
         return((MessageCode)matchData.ErrorCode);
     }
     matchData = Load(battleId);
     if (null == matchData)
     {
         return(MessageCode.MatchMiss);
     }
     matchData.ErrorCode = (int)MessageCode.Success;
     MemcachedFactory.MatchClient.Set <BaseMatchData>(battleId.ToString(), matchData);
     return(MessageCode.Success);
 }
示例#7
0
        void PushMatch(BaseMatchData matchData, MatchStateCallback callback, object matchState = null)
        {
            EnumMatchType castMatchType = EnumMatchType.None;

            switch ((EnumMatchType)matchData.MatchType)
            {
            case EnumMatchType.Tour:
            case EnumMatchType.TourElite:
            case EnumMatchType.WorldChallenge:
                castMatchType = EnumMatchType.Tour;
                break;

            case EnumMatchType.Ladder:
            case EnumMatchType.Dailycup:
            case EnumMatchType.League:
            case EnumMatchType.Champion:
                castMatchType = (EnumMatchType)matchData.MatchType;
                break;

            case EnumMatchType.Crowd:
            case EnumMatchType.CrossCrowd:
            case EnumMatchType.Peak:
            case EnumMatchType.CrossPeak:
            case EnumMatchType.GuildWar:
                castMatchType = EnumMatchType.Crowd;
                break;

            default:
                castMatchType = EnumMatchType.None;
                break;
            }
            NBThreadPool pool = null;

            if (!s_dicMatchPool.TryGetValue(castMatchType, out pool) || null == pool)
            {
                pool = _poolMatch;
            }
            pool.Add(() => Handle(matchData, callback, matchState));
        }
示例#8
0
        /// <summary>
        /// Runs the arena match.
        /// </summary>
        void RunMatch()
        {
            if (_fightDic == null)
            {
                return;
            }
            foreach (var item in _fightDic.Values)
            {
                var matchHome = new MatchManagerInfo(item.HomeId, false, item.HomeIsBot);
                var matchAway = new MatchManagerInfo(item.AwayId, false, item.AwayIsBot);
                if (isGuide)//引导。 必胜
                {
                    matchHome.BuffScale = 200;
                    matchAway.BuffScale = 50;
                }
                var matchData = new BaseMatchData((int)EnumMatchType.Ladder, item.Idx, matchHome, matchAway);
                matchData.ErrorCode = (int)MessageCode.MatchWait;

                MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);

                //使用多线程
                _nbThreadPool.Add(() => Fight(matchData, item));
            }

            _nbThreadPool.WaitAll();
            _ladderInfo.Groups  = _fightDic.Count;
            _ladderInfo.RowTime = DateTime.Now;

            _ladderInfo.Season     = 1;
            _ladderInfo.Status     = 2;
            _ladderInfo.UpdateTime = DateTime.Now;

            _ladderInfo.FightList = null;
            _fightDic             = null;

            LadderInfoMgr.Insert(_ladderInfo);
            _ladderInfo = null;
        }
示例#9
0
        /// <summary>
        /// Runs the arena match.
        /// </summary>
        void RunMatch()
        {
            if (_matchDic == null)
            {
                return;
            }
            try
            {
                Status = EnumLadderStatus.Running;
                foreach (var item in _matchDic.Values)
                {
                    var matchHome = new MatchManagerInfo(item.HomeId, item.HomeSiteId);
                    var matchAway = new MatchManagerInfo(item.AwayId, item.AwaySiteId);
                    var matchData = new BaseMatchData((int)EnumMatchType.CrossCrowd, item.Idx, matchHome, matchAway);
                    matchData.ErrorCode = (int)MessageCode.MatchWait;
                    MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);
                    Fight(matchData, item);
                }

                _matchDic           = null;
                _pairRecord.RowTime = DateTime.Now;
                CrosscrowdPairrecordMgr.Insert(_pairRecord);
                _pairRecord = null;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("CrossCrowdProcess-RunMatch", ex);
            }
            finally
            {
                Status = EnumLadderStatus.End;
                if (_clearFightDicDelegate != null)
                {
                    _clearFightDicDelegate();
                }
            }
        }
示例#10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="matchData"></param>
        /// <param name="crowdMatch"></param>
        void Fight(BaseMatchData matchData, CrosscrowdMatchEntity crowdMatch)
        {
            try
            {
                MatchCore.CreateMatch(matchData);
                if (matchData.ErrorCode == (int)MessageCode.Success)
                {
                    crowdMatch.HomeScore = matchData.Home.Score;
                    crowdMatch.AwayScore = matchData.Away.Score;
                    crowdMatch.HomeName  = matchData.Home.Name;
                    crowdMatch.AwayName  = matchData.Away.Name;
                    crowdMatch.Status    = 0;
                    SavePrize(crowdMatch);
                }
                MemcachedFactory.CrowdMatchClient.Set(crowdMatch.Idx, crowdMatch);

                matchData  = null;
                crowdMatch = null;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("CrossCrowdProcess-Fight", ex);
            }
        }
示例#11
0
 public static MessageCode CreateMatchAsyn(BaseMatchData matchData, MatchThread.MatchCallback callback)
 {
     return(MatchThread.Instance.CreateMatchAsyn(matchData, callback));
 }
示例#12
0
        public static MessageCode CreateMatchAsyn(EnumMatchType matchType, Guid matchId, Guid homeId, Guid awayId, MatchThread.MatchCallback callback)
        {
            var stateObj = new BaseMatchData((int)matchType, matchId, homeId, awayId);

            return(CreateMatchAsyn(stateObj, callback));
        }
示例#13
0
 public static void CreateMatch(BaseMatchData stateObj)
 {
     MatchThread.Instance.CreateMatch(stateObj);
 }
示例#14
0
 public void CreateMatch(BaseMatchData stateObj)
 {
     Handle(stateObj, null);
 }
示例#15
0
        /// <summary>
        /// 打比赛
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="opponentId"></param>
        /// <returns></returns>
        public ArenaFightResponse Fight(Guid managerId, Guid opponentId)
        {
            ArenaFightResponse response = new ArenaFightResponse();

            response.Data = new ArenaFight();
            try
            {
                //还未开始
                if (!IsStart)
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.SeasonNotStart));
                }
                if (IsEnd)
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.SeasonNotStart));
                }
                DateTime date = DateTime.Now;
                var      info = GetArenaInfo(managerId);
                //阵型未组建完成
                if (info == null)
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.TeammemberNotNumber));
                }
                RestoreStamina(info);
                //体力不足
                if (info.Stamina <= 0)
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.StaminaInsufficient));
                }
                var arenaInfo = new ArenaTeammemberFrame(managerId, (EnumArenaType)this.ArenaType, info.SiteId);
                //阵型人数<7
                if (arenaInfo.TeammebmerDic.Count < 7)
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.TeammemberNotNumber));
                }
                info.OpponentList = AnalyseOpponent(info.Opponent);
                //对手列表里找对手
                var opponent = info.OpponentList.OpponentList.Find(r => r.OpponentManagerId == opponentId);
                if (opponent == null)
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.NbParameterError));
                }
                if (!opponent.IsNpc)
                {
                    //对手信息
                    var opponentInfo = new ArenaTeammemberFrame(opponentId, (EnumArenaType)this.ArenaType,
                                                                opponent.OpponentZoneName);
                    //对手信息不完整  刷新
                    if (info.OpponentList == null || info.OpponentList.OpponentList.Count == 0 ||
                        opponentInfo.TeammebmerDic.Count < 7)
                    {
                        List <Guid> matcOpponet = null;
                        if (info.OpponentList != null)
                        {
                            matcOpponet = info.OpponentList.MatchOpponent;
                        }
                        var opponentList = RefreshOpponent(managerId, info.DanGrading, matcOpponet);
                        info.OpponentList = opponentList;
                        info.Opponent     = GenerateString(info.OpponentList);
                        ArenaManagerinfoMgr.Update(info);
                        return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.NbParameterError));
                    }
                }

                var matchHome = new MatchManagerInfo(managerId, info.SiteId, info.ArenaType);
                MatchManagerInfo matchAway = null;
                if (!opponent.IsNpc)
                {
                    matchAway = new MatchManagerInfo(opponent.OpponentManagerId, opponent.OpponentZoneName, info.ArenaType);
                }
                else
                {
                    matchAway = new MatchManagerInfo(opponent.OpponentManagerId, true, info.ArenaType);
                }
                var matchId   = ShareUtil.GenerateComb();
                var matchData = new BaseMatchData((int)EnumMatchType.Arena, matchId, matchHome, matchAway);
                matchData.ErrorCode = (int)MessageCode.MatchWait;
                MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);

                MatchCore.CreateMatch(matchData);
                if (matchData.ErrorCode != (int)MessageCode.Success)
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(matchData.ErrorCode));
                }

                //打比赛   自己为主队
                int homeGoals = matchData.Home.Score;
                int awayGoals = matchData.Away.Score;

                if (info.Stamina == info.MaxStamina)
                {
                    info.StaminaRestoreTime = date;
                }
                info.Stamina--;

                if (info.OpponentList.MatchOpponent == null)
                {
                    info.OpponentList.MatchOpponent = new List <Guid>();
                }
                info.OpponentList.MatchOpponent.Add(opponentId);
                //打完比赛重新刷新对手
                info.OpponentList = RefreshOpponent(managerId, info.DanGrading, info.OpponentList.MatchOpponent);
                info.Opponent     = GenerateString(info.OpponentList);

                if (homeGoals > awayGoals) //胜利了获得对手的积分
                {
                    info.Integral         += opponent.GetIntegral;
                    response.Data.Integral = opponent.GetIntegral;
                    info.UpdateTime        = DateTime.Now;
                }
                //计算段位
                CalculateDanGrading(ref info);
                info.Status = 1;
                response.Data.StaminEntity = RestoreStamina(info, false);
                if (!ArenaManagerinfoMgr.Update(info))
                {
                    return(ResponseHelper.Create <ArenaFightResponse>(MessageCode.NbUpdateFail));
                }
                response.Data.OpponentList = info.OpponentList.OpponentList;
                response.Data.MyIntegral   = info.Integral;
                response.Data.DanGrading   = info.DanGrading;
                //更新排名
                SetRank(managerId, info.Integral);
                response.Data.MyRank  = GetRank(managerId);
                response.Data.MatchId = matchId;
                if (info.DanGrading == 1)
                {
                    response.Data.IsMaxDanGrading = true;
                }
                else
                {
                    var dangradingConfig = CacheFactory.ArenaCache.GetDangrading(info.DanGrading);
                    if (dangradingConfig != null)
                    {
                        response.Data.UpIntegral = dangradingConfig.Integral - info.Integral;
                    }
                }

                MemcachedFactory.ArenaMatchClient.Set <BaseMatchData>(matchId, matchData);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("打比赛", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
示例#16
0
        public static MatchInput BuildTransferMatch(BaseMatchData matchData)
        {
            MatchInput match = new MatchInput();

            match.MatchId   = matchData.MatchId;
            match.MatchType = matchData.MatchType;
            match.TranTime  = 120;
            if (matchData.IsGuide)
            {
                matchData.Home.BuffScale = 400;
                // match.ForceType = EnumForceWinType.HomeWin;
            }
            else if (matchData.NoDraw)
            {
                match.ForceType = EnumForceWinType.NoDraw;
            }
            bool   isHomeNpc  = matchData.Home.IsNpc;
            bool   isAwayNpc  = matchData.Away.IsNpc;
            string homeSiteId = matchData.Home.ZoneName;
            string awaySiteId = matchData.Away.ZoneName;

            if (isHomeNpc || isAwayNpc)
            {
                if (matchData.MatchType == (int)EnumMatchType.Arena)
                {
                    ArenaTeammemberFrame homeFrame = null;
                    ArenaTeammemberFrame awayFrame = null;
                    if (!isHomeNpc)
                    {
                        homeFrame = new ArenaTeammemberFrame(matchData.Home.ManagerId, (EnumArenaType)matchData.Home.ArenaType, homeSiteId);
                    }
                    if (!isAwayNpc)
                    {
                        awayFrame = new ArenaTeammemberFrame(matchData.Away.ManagerId, (EnumArenaType)matchData.Away.ArenaType, awaySiteId);
                    }

                    match.HomeManager = BuildTransferManagerArena(matchData.Home, homeFrame, matchData.IsGuide, null, homeSiteId);
                    match.AwayManager = BuildTransferManagerArena(matchData.Away, awayFrame, false, null, awaySiteId);
                }
                else
                {
                    match.HomeManager = BuildTransferManager(matchData.Home, matchData.IsGuide, null, homeSiteId);
                    match.AwayManager = BuildTransferManager(matchData.Away, false, null, awaySiteId);
                }
                return(match);
            }
            DTOBuffMemberView homeView, awayView;

            if (matchData.MatchType == (int)EnumMatchType.Arena)
            {
                ArenaTeammemberFrame homeFrame = new ArenaTeammemberFrame(matchData.Home.ManagerId, (EnumArenaType)matchData.Home.ArenaType, homeSiteId);
                ArenaTeammemberFrame awayFrame = new ArenaTeammemberFrame(matchData.Away.ManagerId, (EnumArenaType)matchData.Away.ArenaType, awaySiteId);
                ArenaBuffDataCore.Instance().GetMembers(out homeView, out awayView, homeSiteId, matchData.Home.ManagerId, isHomeNpc, awaySiteId,
                                                        matchData.Away.ManagerId, homeFrame, awayFrame, isAwayNpc, true, false);
                match.HomeManager = BuildTransferManagerArena(matchData.Home, homeFrame, matchData.IsGuide, homeView, homeSiteId);
                match.AwayManager = BuildTransferManagerArena(matchData.Away, awayFrame, false, awayView, awaySiteId);
            }
            else
            {
                BuffDataCore.Instance().GetMembers(out homeView, out awayView,
                                                   homeSiteId, matchData.Home.ManagerId, isHomeNpc,
                                                   awaySiteId, matchData.Away.ManagerId, isAwayNpc, true, false);
                match.HomeManager = BuildTransferManager(matchData.Home, matchData.IsGuide, homeView, homeSiteId);
                match.AwayManager = BuildTransferManager(matchData.Away, false, awayView, awaySiteId);
            }
            return(match);
        }
示例#17
0
 public MessageCode CreateMatchAsyn(BaseMatchData stateObj, MatchCallback callback)
 {
     return(CreateMatchAsyn(stateObj, (a, b) => callback(a)));
 }
示例#18
0
        MessageCode SaveMatch(NbManagerEntity manager, NbManagerextraEntity managerex, BaseMatchData pkmatchData,
                              Guid lotteryMatchId, int win, int lose, int draw, int prizeExp, int prizeCoin, int prizeItemCode, string prizeItemString
                              , bool isrevenge, long revengeRecordId, ref long outRevengeRecordId, PlayerkillInfoEntity info, int pointCount)
        {
            if (manager == null)
            {
                return(MessageCode.NbUpdateFail);
            }
            try
            {
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    var messageCode = Tran_SaveMatch(transactionManager.TransactionObject, manager, managerex, pkmatchData,
                                                     lotteryMatchId, win, lose, draw, prizeExp, prizeCoin, prizeItemCode, prizeItemString
                                                     , isrevenge, revengeRecordId, ref outRevengeRecordId, info, pointCount);

                    if (messageCode == ShareUtil.SuccessCode)
                    {
                        transactionManager.Commit();
                    }
                    else
                    {
                        transactionManager.Rollback();
                    }
                    return(messageCode);
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("SavePlayerKillMatch", ex);
                return(MessageCode.Exception);
            }
        }
示例#19
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);
            }
        }
示例#20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="matchData"></param>
        /// <param name="laddermatch"></param>
        void Fight(BaseMatchData matchData, CrossladderMatchEntity laddermatch)
        {
            if (laddermatch.HomeIsBot && laddermatch.AwayIsBot)
            {
                laddermatch.HomeScore = 0;
                laddermatch.AwayScore = 0;
                laddermatch.Status    = (int)EnumLadderStatus.End;

                //保存比赛
                CrossladderMatchMgr.Insert(laddermatch);
                return;
            }
            else
            {
                try
                {
                    MatchCore.CreateMatch(matchData);

                    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;
                        //保存比赛
                        CrossladderMatchMgr.SaveMatch(laddermatch.DomainId, laddermatch.LadderId, laddermatch.HomeId, laddermatch.AwayId, laddermatch.HomeName, laddermatch.AwayName,
                                                      laddermatch.HomeLogo, laddermatch.AwayLogo,
                                                      laddermatch.HomeSiteId, laddermatch.AwaySiteId,
                                                      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)
                        {
                            WebServerHandler.AddManagerData(laddermatch.HomeId, laddermatch.HomeExp, laddermatch.HomeCoin, 0, laddermatch.HomeSiteId);
                            MatchCore.SaveMatchStat(laddermatch.HomeId, EnumMatchType.CrossLadder, laddermatch.HomeScore, laddermatch.AwayScore, laddermatch.HomeScore, laddermatch.HomeSiteId);
                            if (laddermatch.HomeIsHook)
                            {
                                CrossLadderManager.Instance.UpdateHookScore(laddermatch.HomeSiteId, laddermatch.HomeId, laddermatch.PrizeHomeScore,
                                                                            laddermatch.HomeScore > laddermatch.AwayScore, laddermatch.HomeScore,
                                                                            laddermatch.AwayScore, laddermatch.HomeName, laddermatch.AwayName,
                                                                            laddermatch.HomeCoin);
                            }
                        }
                        if (!laddermatch.AwayIsBot)
                        {
                            WebServerHandler.AddManagerData(laddermatch.AwayId, laddermatch.AwayExp, laddermatch.AwayCoin, 0, laddermatch.AwaySiteId);
                            MatchCore.SaveMatchStat(laddermatch.AwayId, EnumMatchType.CrossLadder, laddermatch.AwayScore, laddermatch.HomeScore, laddermatch.AwayScore, laddermatch.AwaySiteId);
                            if (laddermatch.AwayIsHook)
                            {
                                CrossLadderManager.Instance.UpdateHookScore(laddermatch.AwaySiteId, laddermatch.AwayId, laddermatch.PrizeAwayScore,
                                                                            laddermatch.AwayScore < laddermatch.HomeScore, laddermatch.HomeScore,
                                                                            laddermatch.AwayScore, laddermatch.HomeName, laddermatch.AwayName,
                                                                            laddermatch.AwayCoin);
                            }
                        }
                    }
                    MemcachedFactory.LadderMatchClient.Set(laddermatch.Idx, laddermatch);
                }
                catch (Exception ex)
                {
                    SystemlogMgr.Error("CrossLadderProcess-Fight", ex);
                }
            }
            matchData   = null;
            laddermatch = null;
        }
示例#21
0
        /// <summary>
        /// 单场比赛
        /// </summary>
        /// <param name="round"></param>
        /// <param name="homeGuid"></param>
        /// <param name="awayGuid"></param>
        /// <param name="homeId"></param>
        /// <param name="awayId"></param>
        /// <param name="leagueId"></param>
        /// <param name="matchId"></param>
        /// <param name="npcStatus"></param>
        /// <param name="fightMap"></param>
        /// <param name="managerMatch"></param>
        public MessageCode SingleMatch(int round, Guid homeGuid, Guid awayGuid, int homeId, int awayId, int leagueId, Guid matchId, int npcStatus, LeagueFightMapFrame fightMap, ref BaseMatchData managerMatch)
        {
            try
            {
                bool homeIsBot = true;
                bool awayIsBot = true;
                switch (npcStatus)
                {
                case 1:
                    homeIsBot = false;
                    break;

                case 2:
                    awayIsBot = false;
                    break;

                default:
                    matchId = ShareUtil.GenerateComb();
                    break;
                }
                //构建主队
                var matchHome = new MatchManagerInfo(homeGuid, homeIsBot, false);
                ////构建客队
                var matchAway = new MatchManagerInfo(awayGuid, awayIsBot, false);

                ////创建一场比赛
                var matchData = new BaseMatchData((int)EnumMatchType.League, matchId, matchHome, matchAway);
                //比赛数据
                matchData.ErrorCode = (int)MessageCode.MatchWait;
                matchData.RowTime   = DateTime.Now;
                MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);
                if (npcStatus == 0)
                {
                    matchData.ErrorCode  = (int)MessageCode.Success;
                    matchData.Home.Score = CacheFactory.LeagueCache.GetGoalsMap(leagueId, homeId);
                    matchData.Away.Score = CacheFactory.LeagueCache.GetGoalsMap(leagueId, awayId);
                }
                else
                {
                    MatchCore.CreateMatch(matchData);
                    if (matchData.ErrorCode != (int)MessageCode.Success)
                    {
                        return((MessageCode)matchData.ErrorCode);
                    }
                    //测试用 ------------
                    //matchData.ErrorCode = (int)MessageCode.Success;
                    //matchData.Home.Score = 5;
                    //matchData.Away.Score = 2;
                    //-------------------
                    managerMatch = matchData;
                }
                int homeGoals = matchData.Home.Score;
                int awayGoals = matchData.Away.Score;
                SaveMatchScore(leagueId, round, homeId, awayId, homeGoals, awayGoals, fightMap, npcStatus);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("League.Match", ex);
                return(MessageCode.NbParameterError);
            }
            return(MessageCode.Success);
        }
示例#22
0
        /// <summary>
        ///  联赛打比赛
        /// </summary>
        /// <param name="leagueId"></param>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public LeagueFightResultResponse Fight(Guid managerId, int leagueId)
        {
            var manager = ManagerCore.Instance.GetManager(managerId);

            if (manager == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            var managerExtra = ManagerCore.Instance.GetManagerExtra(managerId);

            if (managerExtra == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            if (managerExtra.Stamina < 5)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.LeagueStaminaNotEnough));
            }
            var currectLeague = LeagueManagerrecordMgr.GetManagerMarkInfo(managerId, leagueId);

            if (currectLeague == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            var leagueRecordInfo = LeagueRecordMgr.GetById(currectLeague.LeagueRecordId);

            if (leagueRecordInfo == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            if (leagueRecordInfo.Schedule > currectLeague.MaxWheelNumber)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.LeagueHavePass));
            }
            //扣除行动力
            var code = ManagerCore.Instance.SubStamina(managerExtra, 5, manager.Level, manager.VipLevel);

            if (code != MessageCode.Success)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(code));
            }
            //遍历对阵
            int botStatus = 0;//0=主队和客队都是NPC 1 我是主队 2 我是客队
            var npchome   = Guid.Empty;
            var npcaway   = Guid.Empty;
            var matchId   = ShareUtil.GenerateComb();
            //获取对阵记录
            var fightMap = new LeagueFightMapFrame(managerId);
            //获取对阵
            var           pairList     = CreateFightMap(currectLeague.FightDicId, leagueRecordInfo.Schedule);
            BaseMatchData managerMatch = null;

            foreach (var item in pairList)
            {
                botStatus = 0;
                if (item.HomeId == 0)
                {
                    botStatus = 1;
                    npchome   = managerId;
                    npcaway   = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.AwayId);
                }
                else if (item.AwayId == 0)
                {
                    botStatus = 2;
                    npchome   = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.HomeId);
                    npcaway   = managerId;
                }
                else
                {
                    npchome = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.HomeId);
                    npcaway = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.AwayId);
                }
                SingleMatch(leagueRecordInfo.Schedule, npchome, npcaway, item.HomeId, item.AwayId, leagueRecordInfo.LaegueId, matchId, botStatus, fightMap, ref managerMatch);
            }
            if (managerMatch == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.MatchCreateFail));
            }
            LeagueWincountrecordEntity leagueWincountRecord = null;


            //记录比赛数据
            if (managerMatch.Away.IsBot)
            {
                MatchCore.SaveMatchStat(managerId, EnumMatchType.League, managerMatch.Home.Score, managerMatch.Away.Score, managerMatch.Home.Score);
            }
            else
            {
                MatchCore.SaveMatchStat(managerId, EnumMatchType.League, managerMatch.Away.Score, managerMatch.Home.Score, managerMatch.Away.Score);
            }
            var response = ResponseHelper.CreateSuccess <LeagueFightResultResponse>();

            response.Data = new LeagueFightResult
            {
                HomeGoals = managerMatch.Home.Score,
                AwayGoals = managerMatch.Away.Score,
                PrizeList = new List <LeaguePrizeEntity>()
            };
            int star = 0;

            if (managerMatch.Home.Score > managerMatch.Away.Score)
            {
                if (managerMatch.Home.ManagerId == managerId)
                {
                    star = managerMatch.Home.Score - managerMatch.Away.Score;
                    response.Data.Result = 0;
                }
                else
                {
                    response.Data.Result = 2;
                }
            }

            else if (managerMatch.Home.Score == managerMatch.Away.Score)
            {
                response.Data.Result = 1;
            }
            else
            {
                if (managerMatch.Away.ManagerId == managerId)
                {
                    star = managerMatch.Away.Score - managerMatch.Home.Score;
                    response.Data.Result = 0;
                }
                else
                {
                    response.Data.Result = 2;
                }
            }
            var winType = CalWinType(response.Data.Result);
            LaegueManagerinfoEntity leagueManagerInfo = null;

            if (winType == EnumWinType.Win)
            {
                leagueManagerInfo = LaegueManagerinfoMgr.GetById(managerId);
                if (leagueManagerInfo.DailyWinUpdateTime.Date != DateTime.Now.Date)
                {
                    leagueManagerInfo.DailyWinCount = 1;
                }
                else
                {
                    leagueManagerInfo.DailyWinCount++;
                }
                leagueManagerInfo.DailyWinUpdateTime = DateTime.Now;
            }

            //更新胜场奖励
            star = star > 3 ? 3 : star;
            star = star < 0 ? 0 : star;
            UpdateWincountRecord(managerId, leagueId, star, ref leagueWincountRecord);
            currectLeague.MatchId    = matchId;
            currectLeague.UpdateTime = DateTime.Now;
            var result = MatchConfirm(manager, leagueRecordInfo, currectLeague, leagueManagerInfo, managerMatch, fightMap, managerExtra, leagueWincountRecord);

            if (result.Code != (int)MessageCode.Success)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(result.Code));
            }
            var pop = TaskHandler.Instance.LeagueFight(managerId, (int)winType);

            if (pop != null)
            {
                MemcachedFactory.MatchPopClient.Set(managerId, pop);
            }
            response.Data.StarNumber = star;
            response.Data.Stamina    = managerExtra.Stamina;
            response.Data.PrizeList  = result.Data.PrizeList;
            response.Data.VipExp     = result.Data.VipExp;
            response.Data.MatchId    = managerMatch.MatchId;
            return(response);
        }
示例#23
0
 public static MessageCode CreateMatchAsyn(BaseMatchData matchData, MatchThread.MatchStateCallback callback, object matchState = null)
 {
     return(MatchThread.Instance.CreateMatchAsyn(matchData, callback, matchState));
 }
示例#24
0
        MessageCode Tran_SaveMatch(DbTransaction transaction, NbManagerEntity manager, NbManagerextraEntity managerex, BaseMatchData pkmatchData,
                                   Guid lotteryMatchId, int win, int lose, int draw, int prizeExp, int prizeCoin, int prizeItemCode, string prizeItemString
                                   , bool isrevenge, long revengeRecordId, ref long outRevengeRecordId, PlayerkillInfoEntity info, int prizeItemCount)
        {
            if (prizeCoin > 0 || prizeExp > 0)
            {
                if (!ManagerUtil.SaveManagerData(manager, managerex, transaction))
                {
                    return(MessageCode.NbUpdateFail);
                }
                else
                {
                    ManagerUtil.SaveManagerAfter(manager, managerex, transaction);
                }
                if (!NbManagerextraMgr.Update(managerex, transaction))
                {
                    return(MessageCode.NbUpdateFail);
                }
            }
            PlayerkillInfoMgr.Update(info);
            PlayerkillInfoMgr.SaveFightResult(pkmatchData.Home.ManagerId, manager.Logo, pkmatchData.Away.ManagerId, lotteryMatchId,
                                              win, lose, draw, DateTime.Now,
                                              pkmatchData.MatchId, pkmatchData.Home.Name, pkmatchData.Away.Name,
                                              pkmatchData.Home.Score, pkmatchData.Away.Score, prizeExp, prizeCoin,
                                              prizeItemCode
                                              , prizeItemString, isrevenge, revengeRecordId, prizeItemCount, ref outRevengeRecordId, transaction);

            return(MessageCode.Success);
        }
示例#25
0
        /// <summary>
        /// 确认比赛结果
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="leagueRecordInfo"></param>
        /// <returns></returns>
        public LeaguePrizeResponse MatchConfirm(NbManagerEntity manager, LeagueRecordEntity leagueRecordInfo, LeagueManagerrecordEntity leagueManagerRecord, LaegueManagerinfoEntity lagueManagerInfo, BaseMatchData matchData, LeagueFightMapFrame fightMap, NbManagerextraEntity managerExtra, LeagueWincountrecordEntity leagueWinCount)
        {
            //发放玩家单场比赛奖励---------------------------------------------------
            int winType = 0;

            if (matchData.Home.ManagerId == manager.Idx)         //玩家为主队
            {
                if (matchData.Home.Score > matchData.Away.Score) //主队胜
                {
                    winType = 1;
                }
                else if (matchData.Home.Score == matchData.Away.Score) //平
                {
                    winType = 2;
                }
                else //负
                {
                    winType = 3;
                }
            }
            else //玩家为客队
            {
                if (matchData.Home.Score < matchData.Away.Score)//客队胜
                {
                    winType = 1;
                }
                else if (matchData.Home.Score == matchData.Away.Score) //平
                {
                    winType = 2;
                }
                else//负
                {
                    winType = 3;
                }
            }
            var managerPrizes = LeagueCache.Instance.GetLeaguePrize(leagueRecordInfo.LaegueId, winType);

            int exp   = 0;
            int coin  = 0;
            int score = 0;
            ItemPackageFrame package = null;
            int point  = 0;
            int vipExp = 0;

            SendPrize(managerPrizes, manager, leagueRecordInfo.LaegueId, ref exp, ref coin, ref score, ref package,
                      ref point, ref vipExp);
            ManagerUtil.AddManagerData(manager, exp, coin, 0, EnumCoinChargeSourceType.LeaguePrize, ShareUtil.CreateSequential().ToString());

            if (lagueManagerInfo == null)
            {
                lagueManagerInfo = LaegueManagerinfoMgr.GetById(manager.Idx);
            }
            lagueManagerInfo.SumScore += score;

            leagueManagerRecord.MatchId    = new Guid();
            leagueManagerRecord.UpdateTime = DateTime.Now;
            bool isLastWheel = false;

            leagueManagerRecord.Score += score;
            //本联赛最后一轮
            if (leagueRecordInfo.Schedule >= leagueManagerRecord.MaxWheelNumber)
            {
                isLastWheel = true;
                leagueManagerRecord.IsPass      = true;
                leagueManagerRecord.PassNumber += 1;
            }
            int myRank  = 0;
            int myScore = 0;

            //更新排名
            fightMap.UpdateRankList();
            fightMap.GetRank(ref myRank, ref myScore);

            leagueRecordInfo.Score += score;
            leagueRecordInfo.Rank   = myRank;
            //----------------------------
            leagueRecordInfo.Schedule++;
            leagueRecordInfo.IsSend     = true;
            leagueRecordInfo.UpdateTime = DateTime.Now;
            //本联赛最后一轮,如果是冠军解锁下一轮
            bool isUpdatenextManagerRecord = false;
            LeagueManagerrecordEntity nextManagerRecord = null;

            if (isLastWheel)
            {
                if (leagueRecordInfo.Rank == 1)
                {
                    leagueManagerRecord.LastPrizeLeagueRecordId = leagueManagerRecord.LeagueRecordId;
                    if (leagueRecordInfo.LaegueId != 8)
                    {
                        nextManagerRecord = LeagueManagerrecordMgr.GetManagerMarkInfo(manager.Idx,
                                                                                      leagueRecordInfo.LaegueId + 1);
                        nextManagerRecord.IsLock  = false;
                        isUpdatenextManagerRecord = true;
                    }
                    //记录成就相关数据
                    AchievementTaskCore.Instance.UpdateLeagueScore(manager.Idx, leagueRecordInfo.LaegueId,
                                                                   myScore);
                    TaskHandler.Instance.LeagueChampionScore(manager.Idx);
                }
            }

            using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetConnectionString(EnumDbType.Main)))
            {
                transactionManager.BeginTransaction();
                var messageCode = SaveMatchConfirm(manager, package, leagueRecordInfo,
                                                   nextManagerRecord, leagueManagerRecord, point, isUpdatenextManagerRecord, lagueManagerInfo, fightMap, managerExtra, leagueWinCount, transactionManager.TransactionObject);
                if (messageCode == MessageCode.Success)
                {
                    transactionManager.Commit();
                }
                else
                {
                    transactionManager.Rollback();
                    return(ResponseHelper.Create <LeaguePrizeResponse>(messageCode));
                }
            }
            //奖励结果
            var response = ResponseHelper.CreateSuccess <LeaguePrizeResponse>();

            response.Data = new LeaguePrizes
            {
                PrizeList = new List <LeaguePrizeEntity>()
            };
            foreach (var prize in managerPrizes)
            {
                var entity = new LeaguePrizeEntity();
                entity.PrizeType = prize.PrizeType;
                entity.ItemCode  = prize.ItemCode;
                entity.Count     = prize.Count;
                response.Data.PrizeList.Add(entity);
            }
            response.Data.VipExp = vipExp;
            return(response);
        }
示例#26
0
        void HandleMatch(BaseMatchData matchData, MatchStateCallback callback, object matchState = null)
        {
            MatchInput transferMatchEntity = null;

            try
            {
                transferMatchEntity = MatchTransferUtil.BuildTransferMatch(matchData);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("MatchCore:HandleSingle-TransferMatchDataModel", string.Format("MatchType:{0}", matchData.MatchType), ex);
                matchData.ErrorCode = (int)MessageCode.MatchCreateFail;
                return;
            }

            if (null == transferMatchEntity || null == transferMatchEntity.HomeManager || null == transferMatchEntity.AwayManager)
            {
                matchData.ErrorCode = (int)MessageCode.MatchCreateFail;
            }
            else
            {
                byte[] process = null;
                try
                {
                    if (matchData.Home.ManagerId == new Guid("BC214997-FB0B-41D3-A3AC-A58B00B092D8") || matchData.Away.ManagerId == new Guid("BC214997-FB0B-41D3-A3AC-A58B00B092D8"))
                    {
                        LogHelper.Insert("LeagueMatch Id1 " + matchData.MatchId, LogType.Info);
                    }

                    process = Exec(matchData, transferMatchEntity);
                }
                catch (Exception ex)
                {
                    SystemlogMgr.Error("MatchCore:HandleSingle-Exec", ex);
                }

                if (matchData.ErrorCode == (int)MessageCode.Success && process != null)
                {
                    try
                    {
                        MemcachedFactory.MatchClient.Set <BaseMatchData>(matchData.MatchId, matchData);
                        if (!s_noCacheMatchTypes.ContainsKey((EnumMatchType)matchData.MatchType))
                        {
                            MemcachedFactory.MatchProcessClient.Set <byte[]>(matchData.MatchId, process);
                        }
                        if (s_DbMatchTypes.ContainsKey((EnumMatchType)matchData.MatchType))
                        {
                            MatchDataCore.Instance.SaveProcess(matchData.MatchId, matchData.MatchType, process, matchData.RowTime);
                        }
                        if (callback != null)
                        {
                            matchData.ErrorCode = (int)callback(matchData, matchState);
                            if (matchData.ErrorCode != 0)
                            {
                                LogHelper.Insert(string.Format("match callback fail,matchId:{0},errorCode:{1},home:{2},away:{3}", matchData.MatchId, matchData.ErrorCode, matchData.Home.Name, matchData.Away.Name), LogType.Info);
                            }
                        }
                        //MatchReward
                        if (matchData.ErrorCode == 0 && ShareUtil.IsAppRXYC && CheckRewardMatchType(matchData.MatchType))
                        {
                            Guid   mid  = (matchData.Home.IsNpc || matchData.Home.IsBot) ? matchData.Away.ManagerId : matchData.Home.ManagerId;
                            string key  = string.Concat(mid, ".", matchData.MatchType).ToLower();
                            var    data = new DTOMatchRewardState()
                            {
                                MatchId = matchData.MatchId, Coin = -1, Point = -1
                            };
                            MemcachedFactory.MatchRewardClient.Set(key, data);
                        }
                        return;
                    }
                    catch (Exception ex)
                    {
                        SystemlogMgr.Error("MatchCore:HandleSingle-Save", ex);
                        matchData.ErrorCode = (int)MessageCode.MatchCreateFail;
                    }
                }
                else
                {
                    matchData.ErrorCode = (int)MessageCode.MatchCreateFail;
                }
            }
            MemcachedFactory.MatchClient.Set <BaseMatchData>(matchData.MatchId, matchData);
        }
示例#27
0
        private MatchCreateResponse doFight(Guid managerId, Guid awayId, long revengeRecordId, bool hasTask)
        {
            var info = InnerGetInfo(managerId);

            if (info == null)
            {
                return(ResponseHelper.InvalidParameter <MatchCreateResponse>("info"));
            }
            info.Opponents = SerializationHelper.FromByte <List <PlayerKillOpponentEntity> >(info.OpponentInfo);
            if (info.Opponents == null)
            {
                return(ResponseHelper.InvalidParameter <MatchCreateResponse>("opponents"));
            }
            var awayOpp = info.Opponents.Find(d => d.ManagerId == awayId);

            if (awayOpp == null)
            {
                return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.PlayerKillNoAway));
            }
            if (awayOpp.HasWin)
            {
                return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.PlayerKillWinOver));
            }
            var managerex = ManagerCore.Instance.GetManagerExtra(managerId);
            var manager   = ManagerCore.Instance.GetManager(managerId);

            if (manager == null || managerex == null)
            {
                return(ResponseHelper.Create <MatchCreateResponse>((int)MessageCode.MissManager));
            }
            if (managerex.Stamina < _pkStamina)
            {
                return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.LeagueStaminaNotEnough));
            }
            var matchHome = new MatchManagerInfo(manager.Idx, "", false, 20);
            //构建客队
            var matchAway = new MatchManagerInfo(awayId, false, false);
            //创建一场比赛
            Guid matchId   = ShareUtil.GenerateComb();
            var  matchData = new BaseMatchData((int)EnumMatchType.PlayerKill, matchId, matchHome, matchAway);

            matchData.ErrorCode = (int)MessageCode.MatchWait;
            matchData.HasTask   = hasTask;

            var taskListShow = TaskCore.Instance.GetTaskListShow(managerId);

            if (taskListShow.Tasks.Find(t => t.TaskId == 1001) != null)
            {
                matchData.IsGuide = true;
            }

            MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);
            MatchCore.CreateMatch(matchData);

            if (matchData.ErrorCode == (int)MessageCode.Success)
            {
                MatchCallback(matchData, revengeRecordId, awayOpp, info);
            }
            else
            {
                return(ResponseHelper.Create <MatchCreateResponse>(matchData.ErrorCode));
            }

            var response     = ResponseHelper.MatchCreateResponse(matchId);
            var managerExtra = ManagerCore.Instance.GetManagerExtra(managerId);

            response.Data.Stamina = managerExtra.Stamina;
            return(response);
        }
示例#28
0
        public MessageCode MatchCallback(BaseMatchData matchData, long revengeRecordId, PlayerKillOpponentEntity awayOpp, PlayerkillInfoEntity info)
        {
            var pkmatchData = matchData;

            if (pkmatchData == null || pkmatchData.ErrorCode != (int)MessageCode.Success)
            {
                return(MessageCode.MatchCreateFail);
            }
            bool isrevenge      = false;
            Guid lotteryMatchId = Guid.Empty;

            var winType = ShareUtil.CalWinType(pkmatchData.Home.Score, pkmatchData.Away.Score);

            int win       = 0;
            int lose      = 0;
            int draw      = 0;
            int prizeExp  = 0;
            int prizeCoin = 0;

            if (!isrevenge)
            {
                if (winType == EnumWinType.Win)
                {
                    win = 1;
                }
                if (winType == EnumWinType.Lose)
                {
                    lose = 1;
                }
                if (winType == EnumWinType.Draw)
                {
                    draw = 1;
                }
                var prize = CacheFactory.PlayerKillCache.GetPrize(winType);
                prizeCoin = prize.Coin;
                prizeExp  = prize.Exp;
            }
            int    prizeItemCode   = 0;
            string prizeItemString = "";
            var    manager         = ManagerCore.Instance.GetManager(pkmatchData.Home.ManagerId);
            var    managerex       = ManagerCore.Instance.GetManagerExtra(pkmatchData.Home.ManagerId);

            var subtype = 1;

            if (manager.Level % 10 == 0)
            {
                subtype = manager.Level / 10;
            }
            else
            {
                subtype = manager.Level / 10 + 1;
            }

            int matchTimes = 0;

            PlayerkillInfoMgr.GetMatchTimes(manager.Idx, ref matchTimes);

            //if (winType == EnumWinType.Win)
            //{
            var lotteryEntity = CacheFactory.LotteryCache.LotteryFive(EnumLotteryType.PlayerKill, subtype);
            int pointCount    = 0;

            if (lotteryEntity != null)
            {
                //第一场友谊赛固定获得5钻石
                if (matchTimes == 0)
                {
                    prizeItemCode  = 810001;
                    pointCount     = 5;
                    lotteryMatchId = pkmatchData.MatchId;
                }
                else
                {
                    if (winType == EnumWinType.Win)
                    {
                        prizeItemCode   = lotteryEntity.PrizeItemCode;
                        prizeItemString = lotteryEntity.ItemString;
                        if (prizeItemCode == 810001)
                        {
                            var pointConfig = CacheFactory.PlayerKillCache.GetPointConfig(manager.VipLevel);
                            if (pointConfig != null && (info.DayPoint + pointCount) < pointConfig.TotalPoint)
                            {
                                pointCount = pointConfig.PrizePoint;
                                int point = pointCount;
                                //欧洲杯狂欢
                                ActivityExThread.Instance.EuropeCarnival(5, ref point);
                                info.DayPoint = info.DayPoint + point;
                                info.DayPoint = info.DayPoint > pointConfig.TotalPoint ? pointConfig.TotalPoint : info.DayPoint;
                            }
                            else
                            {
                                prizeItemCode = 910001;
                                pointCount    = 5;
                            }
                        }
                        else if (prizeItemCode == 910001)
                        {
                            prizeItemCode = 910001;
                            pointCount    = 5;
                        }
                        var itemcode = ActivityExThread.Instance.SummerGiftBag(4);
                        if (itemcode > 0)
                        {
                            prizeItemCode = itemcode;
                        }
                        else
                        {
                            itemcode = ActivityExThread.Instance.MidAutumnActivity(4, info.SpecialItemNumber);
                            if (itemcode > 0)
                            {
                                info.SpecialItemNumber++;
                                prizeItemCode = itemcode;
                            }
                        }
                        lotteryMatchId = pkmatchData.MatchId;
                    }
                }
            }
            //}



            //LogHelper.Insert("友谊赛比赛结果处理请求:比赛id"+lotteryMatchId+",ManagerId:" + pkmatchData.Home.ManagerId.ToString() + " ,对手Id:" + pkmatchData.Away.ManagerId.ToString(), LogType.Info);

            double totalPlusRate = 0;
            //是否有vip效果
            var vipRate = CacheFactory.VipdicCache.GetEffectValue(manager.VipLevel, EnumVipEffect.PkOrLeagueExpPlus);

            totalPlusRate += vipRate / 100.00;
            //是否有增加经验的Buff
            var buffExp = BuffPoolCore.Instance().GetBuffValue(manager.Idx, EnumBuffCode.PkMatchExp, true, false);
            NbManagerbuffpoolEntity buffExpEntity = null;

            if (buffExp != null)
            {
                if (buffExp.SrcList != null && buffExp.SrcList.Count > 0)
                {
                    buffExpEntity = NbManagerbuffpoolMgr.GetById(buffExp.SrcList[0].Idx);
                    if (buffExpEntity != null && buffExpEntity.RemainTimes > 0)
                    {
                        totalPlusRate += buffExp.Percent;
                    }
                }
            }
            prizeExp = (int)(prizeExp * (1 + totalPlusRate));

            if (matchData.Home.Score > matchData.Away.Score)
            {
                awayOpp.HasWin    = true;
                info.OpponentInfo = SerializationHelper.ToByte(info.Opponents);
                //PlayerkillInfoMgr.Update(info);
            }

            //欧洲杯狂欢
            ActivityExThread.Instance.EuropeCarnival(1, ref prizeExp);

            LogHelper.Insert(string.Format("revengeId:{0},score1:{1},score2:{2},haswin:{3}", revengeRecordId, matchData.Home.Score, matchData.Away.Score, awayOpp.HasWin), LogType.Info);
            OnlineCore.Instance.CalIndulgePrize(manager, ref prizeExp, ref prizeCoin);
            ManagerUtil.AddManagerData(manager, prizeExp, prizeCoin, 0, EnumCoinChargeSourceType.PlayerKillPrize, pkmatchData.MatchId.ToString());
            long outRevengeRecordId = 0;
            //扣除行动力
            var code = ManagerCore.Instance.SubStamina(managerex, _pkStamina, manager.Level, manager.VipLevel);

            if (code != MessageCode.Success)
            {
                return(code);
            }

            code = SaveMatch(manager, managerex, pkmatchData, lotteryMatchId, win, lose, draw, prizeExp, prizeCoin,
                             prizeItemCode, prizeItemString, isrevenge, revengeRecordId, ref outRevengeRecordId, info, pointCount);
            //统计使用的行动力
            StatisticKpiMgr.UpdateSame(ShareUtil.ZoneId, DateTime.Now.Date, 0, _pkStamina, 0, 0);
            if (code == MessageCode.Success)
            {
                //更新祝福Buff剩余场次数
                if (buffExpEntity != null && buffExpEntity.RemainTimes > 0)
                {
                    buffExpEntity.RemainTimes--;
                    NbManagerbuffpoolMgr.Update(buffExpEntity);
                }
                //记录比赛数据
                MatchCore.SaveMatchStat(pkmatchData.Home.ManagerId, EnumMatchType.PlayerKill, pkmatchData.Home.Score, pkmatchData.Away.Score, pkmatchData.Home.Score);
                //记录成就相关数据
                AchievementTaskCore.Instance.UpdatePkMatchGoals(manager.Idx, pkmatchData.Home.Score);
                TaskHandler.Instance.PkOrFriendMatchCount(manager.Idx);
                var popList = ManagerUtil.SaveManagerAfter(manager, false);
                var taskPop = TaskHandler.Instance.PlayerKillFight(manager.Idx, (int)winType);
                if (matchData.HasTask)
                {
                    //var taskPop = TaskHandler.Instance.PlayerKillFight(manager.Idx, (int)winType);
                    if (taskPop != null && taskPop.Count > 0)
                    {
                        if (popList == null)
                        {
                            popList = taskPop;
                        }
                        else
                        {
                            popList.AddRange(taskPop);
                        }
                    }
                }



                MemcachedFactory.MatchPopClient.Set(matchData.MatchId, popList);
            }
            return(code);
        }
示例#29
0
        public MessageCode MatchCallback(BaseMatchData matchData)
        {
            var fmatchData = (FriendMatchData)matchData;

            if (fmatchData == null || fmatchData.ErrorCode != (int)MessageCode.Success)
            {
                return(MessageCode.MatchCreateFail);
            }
            var  friendRecord = fmatchData.FriendRecord;
            bool isFriend     = friendRecord != null;
            var  coin         = 0;
            int  intimacy     = 0;

            if (isFriend)
            {
                var oldIntimacy = friendRecord.Intimacy;
                AddFriendMatchIntimacy(friendRecord);
                intimacy = friendRecord.Intimacy - oldIntimacy;
                if (friendRecord.DayMatchCount == 1)
                {
                    //第一次比赛有奖励
                    if (fmatchData.Home.Score > fmatchData.Away.Score)
                    {
                        coin = 30;
                    }
                    else if (fmatchData.Home.Score == fmatchData.Away.Score)
                    {
                        coin = 20;
                    }
                    else
                    {
                        coin = 10;
                    }
                }
            }
            var match = new FriendMatchEntity();

            match.Idx       = fmatchData.MatchId;
            match.HomeId    = fmatchData.Home.ManagerId;
            match.HomeName  = fmatchData.Home.Name;
            match.HomeScore = fmatchData.Home.Score;
            match.AwayId    = fmatchData.Away.ManagerId;
            match.AwayName  = fmatchData.Away.Name;
            match.AwayScore = fmatchData.Away.Score;
            match.Intimacy  = intimacy;
            match.IsFriend  = isFriend;
            match.RowTime   = DateTime.Now;
            match.Status    = 0;

            MatchCore.SaveMatchStat(match.HomeId, EnumMatchType.Friend, match.HomeScore, match.AwayScore, match.HomeScore);
            var winType = EnumWinType.Win;

            if (match.HomeScore == match.AwayScore)
            {
                winType = EnumWinType.Draw;
            }
            else if (match.HomeScore < match.AwayScore)
            {
                winType = EnumWinType.Lose;
            }

            using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
            {
                transactionManager.BeginTransaction();
                var trans       = transactionManager.TransactionObject;
                var messageCode = MessageCode.NbUpdateFail;
                do
                {
                    if (isFriend)
                    {
                        if (!FriendManagerMgr.Update(friendRecord, trans))
                        {
                            break;
                        }
                    }
                    if (!FriendMatchMgr.Insert(match, trans))
                    {
                        break;
                    }
                    //记录成就相关数据
                    var mess = AchievementTaskCore.Instance.UpdateFriendMatchComb(match.HomeId, winType, trans);
                    if (mess != MessageCode.Success)
                    {
                        break;
                    }

                    if (coin > 0)
                    {
                        //友谊赛金币奖励
                        var manager = ManagerCore.Instance.GetManager(fmatchData.Home.ManagerId);
                        if (manager != null)
                        {
                            mess = ManagerCore.Instance.AddCoin(manager, coin, EnumCoinChargeSourceType.FriendMatch,
                                                                ShareUtil.GenerateComb().ToString(), trans);
                            if (mess != MessageCode.Success)
                            {
                                break;
                            }
                        }
                    }
                    messageCode = MessageCode.Success;
                } while (false);
                if (messageCode == ShareUtil.SuccessCode)
                {
                    transactionManager.Commit();
                }
                else
                {
                    transactionManager.Rollback();
                }
            }
            return(MessageCode.Success);
        }
示例#30
0
        DailycupMatchEntity Fight(DailycupCompetitorsEntity home, DailycupCompetitorsEntity away, int round)
        {
            DailycupMatchEntity dailycupMatch = new DailycupMatchEntity();

            dailycupMatch.DailyCupId  = _dailycup.Idx;
            dailycupMatch.HomeManager = home.ManagerId;
            dailycupMatch.HomeName    = home.ManagerName;
            dailycupMatch.HomeLogo    = home.Logo;

            dailycupMatch.Idx            = ShareUtil.GenerateComb();
            dailycupMatch.Round          = round;
            dailycupMatch.ChipInCount    = 0;
            dailycupMatch.RowTime        = DateTime.Now;
            dailycupMatch.Status         = 0;
            dailycupMatch.HomeLevel      = home.Level;
            dailycupMatch.HomePower      = home.kpi;
            dailycupMatch.HomeWorldScore = home.WorldScore;
            if (away == null) //轮空
            {
                dailycupMatch.AwayManager = Guid.Empty;
                dailycupMatch.AwayName    = "";
                dailycupMatch.AwayScore   = 0;
                dailycupMatch.HomeScore   = 0;
                dailycupMatch.AwayLogo    = "";
            }
            else
            {
                try
                {
                    home.MaxRound = round;
                    away.MaxRound = round;
                    home.Rank     = _dailycup.Round - round + 1;
                    away.Rank     = _dailycup.Round - round + 1;
                    var matchHome = new MatchManagerInfo(home.ManagerId, false, false);
                    var matchAway = new MatchManagerInfo(away.ManagerId, false, false);
                    var matchData = new BaseMatchData((int)EnumMatchType.Dailycup, dailycupMatch.Idx, matchHome, matchAway);
                    matchData.ErrorCode = (int)MessageCode.MatchWait;
                    matchData.NoDraw    = true;
                    MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);

                    MatchCore.CreateMatch(matchData);
                    ////测试用 ------------
                    //matchData.ErrorCode = (int)MessageCode.Success;
                    //matchData.Home.Score = 5;
                    //matchData.Away.Score = 2;

                    if (matchData.ErrorCode == (int)MessageCode.Success)
                    {
                        dailycupMatch.AwayManager    = away.ManagerId;
                        dailycupMatch.AwayName       = away.ManagerName;
                        dailycupMatch.AwayLevel      = away.Level;
                        dailycupMatch.AwayLogo       = away.Logo;
                        dailycupMatch.AwayPower      = away.kpi;
                        dailycupMatch.AwayWorldScore = away.WorldScore;
                        dailycupMatch.HomeScore      = matchData.Home.Score;
                        dailycupMatch.AwayScore      = matchData.Away.Score;

                        if (matchData.Away.Score > matchData.Home.Score)
                        {
                            away.WinCount++;
                            if (round == _dailycup.Round)
                            {
                                away.Rank = -1;
                            }
                        }
                        else
                        {
                            home.WinCount++;
                            if (round == _dailycup.Round)
                            {
                                home.Rank = -1;
                            }
                        }
                        AddMatchStat(dailycupMatch);
                    }
                    else
                    {
                        dailycupMatch.AwayManager = Guid.Empty;
                        dailycupMatch.AwayName    = "";
                        dailycupMatch.AwayScore   = 0;
                        dailycupMatch.HomeScore   = 0;
                        dailycupMatch.AwayLogo    = "";
                        SystemlogMgr.Error("Create Dailycup", string.Format("round:{0},homeId:{1},awayId:{2},code:{3}", round, home.Idx, away.Idx, matchData.ErrorCode));
                        return(dailycupMatch);
                    }
                }
                catch (Exception ex)
                {
                    SystemlogMgr.Error("Create Dailycup", string.Format("round:{0},homeId:{1},awayId:{2}", round, home.Idx, away.Idx));
                    throw ex;
                }
            }
            return(dailycupMatch);
        }