/// <summary> /// 获取阵型,计算阵型等级,和球员位置,技能 /// </summary> /// <param name="arenaTeammemberFrame"></param> /// <returns></returns> public static NbSolutionEntity GetArenaSolution(ArenaTeammemberFrame arenaTeammemberFrame) { var cacheKey = arenaTeammemberFrame.ArenaType.ToString() + arenaTeammemberFrame.ManagerId.ToString(); var entity = MemcachedFactory.ArenaSolutionClient.Get <NbSolutionEntity>(cacheKey); if (entity == null) { entity = NbSolutionMgr.GetById(arenaTeammemberFrame.ManagerId, arenaTeammemberFrame.ZoneName); if (entity == null) { return(null); } entity.FormationId = arenaTeammemberFrame.SolutionId; var formationData = new FormationDataListEntity(entity.FormationData); entity.FormationLevel = formationData.GetLevel(entity.FormationId); var formationDetails = CacheFactory.FormationCache.GetFormationDetail(entity.FormationId); var playerIdList = arenaTeammemberFrame.PlayerList; var skillList = arenaTeammemberFrame.SkillList; entity.PlayerDic = new Dictionary <int, SolutionPlayerEntity>(playerIdList.Count); for (int i = 0; i < playerIdList.Count; i++) { if (playerIdList[i] == 0) { continue; } entity.PlayerDic.Add(playerIdList[i], MatchDataUtil.BuildSolutionPlayer(playerIdList, formationDetails, playerIdList[i], skillList[i])); } entity.PlayerString = arenaTeammemberFrame.PlayerString; entity.SkillString = arenaTeammemberFrame.SkillString; MemcachedFactory.ArenaSolutionClient.Set(cacheKey, entity); } return(entity); }
public static Match_FightManagerinfo GetFightinfoArena(ArenaTeammemberFrame arenaFrame, bool isBot, DTOBuffMemberView buffView = null, string siteId = "") { if (arenaFrame == null) { return(null); } var manager = GetManager(arenaFrame.ManagerId, false, false, siteId); if (manager == null) { return(null); } if (buffView == null) { return(null); } arenaFrame.Kpi = buffView.Kpi; var solution = GetArenaSolution(arenaFrame); if (solution == null) { return(null); } string name = isBot ? _botName : manager.Name; // int coachId = GetCoachId(manager.Idx, siteId); return(GetFightinfoArena(arenaFrame, name, solution.FormationId, manager.Level, manager.Logo, 0, buffView, siteId)); }
public static List <TeammemberEntity> GetRawMembersArena(Guid managerId, ArenaTeammemberFrame arenaFrame, bool syncFlag = true, string siteId = "") { try { var clientKey = arenaFrame.ArenaType.ToString() + managerId.ToString(); List <TeammemberEntity> list = null; if (syncFlag) { list = MemcachedFactory.ArenaTeammembersClient.Get <List <TeammemberEntity> >(clientKey); } if (null != list && list.Count > 0) { return(list); } list = arenaFrame.GetTeammebmerList(); if (syncFlag && list.Count > 0) { MemcachedFactory.ArenaTeammembersClient.Set(clientKey, list); } return(list); } catch (Exception ex) { SystemlogMgr.Error("GetRawMembers", string.Format("mid:{0},arenaType:{1}", managerId, (int)arenaFrame.ArenaType), ex); throw ex; } }
public static List <NBSolutionTeammember> GetArenaSolutionTeammembers(ArenaTeammemberFrame arenaTeammemberFrame, bool onlyMain = false, bool withHire = true, string siteId = "") { var buffView = ArenaBuffDataCore.Instance().GetMembers(arenaTeammemberFrame.ManagerId, arenaTeammemberFrame, true, arenaTeammemberFrame.ZoneName); if (buffView == null) { return(null); } return(GetArenaSolutionTeammembers(arenaTeammemberFrame, buffView, onlyMain, withHire, arenaTeammemberFrame.ZoneName)); }
/// <summary> /// 获取阵型数据 /// </summary> /// <param name="managerId"></param> /// <param name="zoneName"></param> /// <returns></returns> public NBSolutionInfoResponse SolutionAndTeammemberResponse(Guid managerId, string zoneName) { try { var arenaFrame = new ArenaTeammemberFrame(managerId, (EnumArenaType)this.ArenaType, zoneName); var solution = MatchDataHelper.GetArenaSolutionInfo(arenaFrame); if (solution == null) { return(ResponseHelper.InvalidParameter <NBSolutionInfoResponse>()); } var response = ResponseHelper.CreateSuccess <NBSolutionInfoResponse>(); response.Data = solution; response.Data.Kpi = arenaFrame.Kpi; return(response); } catch (Exception ex) { SystemlogMgr.Error("竞技场获取阵容", ex); return(ResponseHelper.InvalidParameter <NBSolutionInfoResponse>()); } }
static Match_FightManagerinfo GetFightinfoArena(ArenaTeammemberFrame arenaFrame, string name, int formationId, int level, string logo, int coachId, DTOBuffMemberView buffView, string siteId = "", bool isNpc = false) { if (buffView == null || arenaFrame == null) { return(null); } var managerinfo = new Match_FightManagerinfo(); managerinfo.FormationId = formationId; managerinfo.Level = level; managerinfo.Logo = logo; managerinfo.ManagerId = arenaFrame.ManagerId; managerinfo.Name = name; managerinfo.CoachId = coachId; managerinfo.Teammembers = GetArenaSolutionTeammembers(arenaFrame, buffView, true, true, siteId, isNpc); managerinfo.Kpi = buffView.Kpi; managerinfo.KpiReady = buffView.KpiReady; return(managerinfo); }
public static NBSolutionInfo GetArenaSolutionInfo(ArenaTeammemberFrame arenaTeammemberFrame) { var solution = GetArenaSolution(arenaTeammemberFrame); if (solution == null) { return(null); } //var manager = GetManager(managerId); //if (manager == null) // return null; var solutionInfo = new NBSolutionInfo(); solutionInfo.FormationId = solution.FormationId; solutionInfo.PlayerString = solution.PlayerString; //solutionInfo.ClothId = BuffPoolCore.Instance().GetManagerClothId(managerId, null); //if (!arenaTeammemberFrame.PlayerList.Exists(r => r == 0)) solutionInfo.Teammembers = GetArenaSolutionTeammembers(arenaTeammemberFrame); //else return(solutionInfo); }
int doRebuildKpi(Guid managerId, int arenaType) { try { var arenaFrame = new ArenaTeammemberFrame(managerId, (EnumArenaType)arenaType); var buffView = ArenaBuffDataCore.Instance().RebuildMembers(managerId, arenaFrame); if (buffView != null) { if (buffView.Kpi > 0) { arenaFrame.Kpi = buffView.Kpi; arenaFrame.Save(); } return(buffView.Kpi); } return(-1); } catch (Exception ex) { SystemlogMgr.Error("doRebuildKpi", ex); return(-1); } }
//public Match_FightinfoResponse GetCrowdFightInfo(Guid matchId, Guid managerId) //{ // var match = MemcachedFactory.CrowdMatchClient.Get<CrowdMatchEntity>(matchId); // if (match == null) // return ResponseHelper.InvalidParameter<Match_FightinfoResponse>(); // if (managerId == match.HomeId) // { // return GetFightInfo(managerId, match.AwayId); // } // else if (managerId == match.AwayId) // { // return GetFightInfo(managerId, match.HomeId); // } // else // { // return ResponseHelper.InvalidParameter<Match_FightinfoResponse>(); // } //} /// <summary> /// 获取竞技场对阵 /// </summary> /// <param name="matchId"></param> /// <returns></returns> public Match_FightinfoResponse GetArenaFightInfo(Guid matchId) { var matchData = MemcachedFactory.ArenaMatchClient.Get <BaseMatchData>(matchId); if (matchData == null) { return(ResponseHelper.Create <Match_FightinfoResponse>(MessageCode.NbParameterError)); } DicNpcEntity homeNpc = null; DicNpcEntity awayNpc = null; ArenaTeammemberFrame homeFrame = null; ArenaTeammemberFrame awayFrame = null; if (matchData.Home.IsNpc) { homeNpc = CacheFactory.NpcdicCache.GetNpc(matchData.Home.ManagerId); } else { homeFrame = new ArenaTeammemberFrame(matchData.Home.ManagerId, (EnumArenaType)matchData.Home.ArenaType, matchData.Home.ZoneName); } if (matchData.Away.IsNpc) { awayNpc = CacheFactory.NpcdicCache.GetNpc(matchData.Away.ManagerId); } else { awayFrame = new ArenaTeammemberFrame(matchData.Away.ManagerId, (EnumArenaType)matchData.Away.ArenaType, matchData.Away.ZoneName); } DTOBuffMemberView homeView, awayView; ArenaBuffDataCore.Instance().GetMembers(out homeView, out awayView, matchData.Home.ZoneName, matchData.Home.ManagerId, matchData.Home.IsNpc, matchData.Away.ZoneName, matchData.Away.ManagerId, homeFrame, awayFrame, matchData.Away.IsNpc, true, false); Match_FightManagerinfo home, away; if (matchData.Home.IsNpc) { home = MatchDataHelper.GetFightinfo(homeNpc, homeView); } else { home = MatchDataHelper.GetFightinfoArena(homeFrame, false, homeView, matchData.Home.ZoneName); } if (matchData.Away.IsNpc) { away = MatchDataHelper.GetFightinfo(awayNpc, awayView); } else { away = MatchDataHelper.GetFightinfoArena(awayFrame, false, awayView, matchData.Away.ZoneName); } if (home == null || away == null) { return(ResponseHelper.Create <Match_FightinfoResponse>(MessageCode.NbParameterError)); } var response = ResponseHelper.CreateSuccess <Match_FightinfoResponse>(); response.Data = new Match_Fightinfo(); response.Data.Home = home; response.Data.Away = away; return(response); }
/// <summary> /// 刷新对手 /// </summary> /// <param name="managerId">经理id</param> /// <param name="danGrading">段位</param> /// <param name="matchOpponent">打过的对手</param> /// <returns></returns> private ArenaOpponent RefreshOpponent(Guid managerId, int danGrading, List <Guid> matchOpponent) { var result = new ArenaOpponent(); var opponentList = new List <OpponentEntity>(); var resultList = new List <Guid>(); for (int i = 1; i < 4; i++) //选3个对手 { var key = CacheFactory.ArenaCache.GetKey(danGrading, i); //获取key if (!_OpponentDic.ContainsKey(key)) { return(null); } var list = new List <ArenaManagerinfoEntity>(); //循环添加。避免操作list影响对手池 foreach (var item in _OpponentDic[key]) { list.Add(item); } int index = 0; while (index < 10 && list.Count > 0) //循环10次排除重复 { var listIndex = RandomHelper.GetInt32WithoutMax(0, list.Count); var info = list[listIndex]; //随机一个对手 list.RemoveAt(listIndex); //移除随机过的项 if (managerId == info.ManagerId) //排除自己 { continue; } if (!resultList.Exists(r => r == info.ManagerId)) //结果里面已经包含了该对手 { if (matchOpponent != null && matchOpponent.Count < 5 && matchOpponent.Exists(r => r == info.ManagerId)) //打过比赛的对手里面已经包含了该对手 { index++; continue; } var entity = new OpponentEntity(); entity.OpponentManagerId = info.ManagerId; entity.OpponentZoneName = info.SiteId; if (info.IsNpc) { entity.OpponentKpi = info.Kpi; entity.OpponentName = info.ManagerName; } else { entity.OpponentName = info.ZoneName + "." + info.ManagerName; var arenaFrame = new ArenaTeammemberFrame(entity.OpponentManagerId, (EnumArenaType)this.ArenaType, entity.OpponentZoneName); entity.OpponentKpi = arenaFrame.Kpi; } entity.IsNpc = info.IsNpc; entity.OpponentLogo = info.Logo; entity.OpponentIntegral = info.Integral; entity.OpponentDanGrading = info.DanGrading; resultList.Add(entity.OpponentManagerId); opponentList.Add(entity); break; } index++; } if (index >= 10 || list.Count == 0) { return(null); } } CheckOpponent(ref opponentList); result.OpponentList = opponentList; result.MatchOpponent = matchOpponent; return(result); }
/// <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); }
public static Dictionary <Guid, TeammemberEntity> GetDicRawMembers4ViewArena(Guid managerId, ArenaTeammemberFrame arenaTeammemberFrame, DTOBuffMemberView buffView, string siteId = "") { Dictionary <Guid, TeammemberEntity> dicMembers = buffView.RawMembers; if (null == dicMembers || dicMembers.Count == 0) { var members = GetRawMembersArena(managerId, arenaTeammemberFrame, true, siteId); if (null == members) { return(null); } dicMembers = members.ToDictionary(i => i.Idx, i => i); } return(dicMembers); }
static List <NBSolutionTeammember> GetArenaSolutionTeammembers(ArenaTeammemberFrame arenaTeammemberFrame, DTOBuffMemberView buffView, bool onlyMain = false, bool withHire = true, string siteId = "", bool isNpc = false) { List <NBSolutionTeammember> list = new List <NBSolutionTeammember>(); if (isNpc) { foreach (var buffMember in buffView.BuffMembers.Values) { if (!onlyMain || buffMember.IsMain) { var entity = new NBSolutionTeammember(); entity.Idx = buffMember.Tid; entity.Kpi = buffMember.Kpi; entity.Level = buffMember.Level; entity.PlayerId = buffMember.Pid; entity.Position = buffMember.PPos; entity.Strength = buffMember.Strength; entity.IsMain = buffMember.IsMain; list.Add(entity); } } } else { if (buffView == null || buffView.BuffMembers == null) { return(list); } var dicMembers = GetDicRawMembers4ViewArena(arenaTeammemberFrame.ManagerId, arenaTeammemberFrame, buffView, siteId); TeammemberEntity member = null; foreach (var buffMember in buffView.BuffMembers.Values) { if (!onlyMain || buffMember.IsMain) { if (dicMembers.TryGetValue(buffMember.Tid, out member)) { if (!withHire && member.IsHirePlayer) { continue; } } var entity = new NBSolutionTeammember(); entity.Idx = buffMember.Tid; entity.Kpi = buffMember.Kpi; entity.Level = buffMember.Level; entity.PlayerId = buffMember.Pid; entity.Position = buffMember.PPos; entity.Strength = buffMember.Strength; entity.IsMain = buffMember.IsMain; if (null != member) { entity.IsCopyed = member.IsCopyed; entity.IsInherited = member.IsInherited; entity.ArousalLv = member.ArousalLv; } list.Add(entity); } } arenaTeammemberFrame.Kpi = buffView.Kpi; } return(list); }
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); }
static ManagerInput CreateTransferManagerArena(MatchManagerInfo managerInfo, DTOBuffMemberView buffView, bool isGuide, ArenaTeammemberFrame arenaFrame, string siteId = "") { if (null == buffView) { return(null); } var manager = MatchDataHelper.GetManager(managerInfo.ManagerId, false, false, siteId); var solution = MatchDataHelper.GetArenaSolution(arenaFrame); string name = managerInfo.IsBot ? _botName : manager.Name; managerInfo.Name = name; var dstData = new ManagerInput(); dstData.Mid = managerInfo.ManagerId; dstData.Name = name; dstData.Logo = manager.Logo.ToString(); dstData.FormId = solution.FormationId; dstData.FormLv = solution.FormationLevel; dstData.ClothId = buffView.ClothId; dstData.Skills = buffView.LiveSkillList; dstData.SubSkills = buffView.SubSkills; if (null != buffView.MatchPropList) { dstData.PropList = new List <PropInput>(); foreach (var item in buffView.MatchPropList) { dstData.PropList.Add(new PropInput(item.Point, item.Percent, item.BuffId)); } } if (null != buffView.MatchBoostList) { dstData.BoostList = new List <BoostInput>(); foreach (var item in buffView.MatchBoostList) { dstData.BoostList.Add(new BoostInput(item.BoostType, item.Point, item.Percent, item.BuffId)); } } BuildManagerData(dstData, buffView, manager.VipLevel, managerInfo.BuffScale, isGuide); return(dstData); }
public static ManagerInput BuildTransferManagerArena(MatchManagerInfo managerInfo, ArenaTeammemberFrame arenaFrame, bool isGuide = false, DTOBuffMemberView buffView = null, string siteId = "") { try { if (managerInfo.IsNpc) { return(GetTransferNpc(managerInfo)); } if (null == buffView) { buffView = ArenaBuffDataCore.Instance().GetMembers(managerInfo.ManagerId, arenaFrame, true, siteId); } return(CreateTransferManagerArena(managerInfo, buffView, isGuide, arenaFrame, siteId)); } catch (Exception ex) { SystemlogMgr.Error("BuildTransferManager", ex); throw; } }