public CompetitionRun(MatchCore comp, int delay, bool showBoards) { turns = 0; competition = comp; millisDelay = delay; comp.OnEvent += MatchEnd; comp.OnEvent += WriteScoreRounds; comp.OnEvent += WriteHeader; if (showBoards) { comp.OnEvent += ASCIIUpdateShot; comp.OnEvent += ASCIIShipDestroyed; comp.OnEvent += ASCIIUpdateShip; comp.OnEvent += ASCIIUpdateShotHit; comp.OnEvent += MakeASCII; comp.OnEvent += SleepEvent; } if (millisDelay > 0) { comp.OnEvent += WriteTurns; comp.OnEvent += ResetTurns; } }
public MatchCreateResponse Fight(Guid managerId, Guid awayId) { var lastTime = MemcachedFactory.FriendMutexClient.Get <DateTime>(managerId); if (lastTime > DateTime.Now) { return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.FriendMatchWait)); } //好友比赛每天每个好友只能挑战3次, 只有第一次有奖励 var friend = FriendManagerMgr.GetOne(managerId, awayId); if (friend.DayMatchCount >= 3)//每日三次比赛 { return(ResponseHelper.Create <MatchCreateResponse>(MessageCode.FriendMatchOver)); } var matchId = ShareUtil.GenerateComb(); var code = MatchCore.CreateMatchFriendAsyn(matchId, managerId, awayId, friend, MatchCallback); if (code != MessageCode.Success) { return(ResponseHelper.Create <MatchCreateResponse>(code)); } MemcachedFactory.FriendMutexClient.Set(managerId, DateTime.Now.AddSeconds(_friendMatchWaitTime)); return(ResponseHelper.MatchCreateResponse(matchId)); }
public void OneTimeSetUp() { var matchInfo = new MatchInfo { Players = new List <Player> { new Player { IsHost = true, MatchKey = "test", PlayerID = 1, PlayerName = "ばぬし", Position = 0, Wait = false }, new Player { IsHost = false, MatchKey = "test", PlayerID = 2, PlayerName = "ねこ", Position = 0, Wait = false } }, CreatePlayerClosed = true, HostPlayerID = 1, MatchKey = "test", NextPlayerID = 1, Turn = 0 }; _core = new MatchCore(matchInfo); _core.Start(); }
public ResultDisplay(MatchCore comp) { competition = comp; buttonLayout = new VerticalLayout(VerticalLayout.VerticalAlign.Center); buttonLayout.Add(new ButtonControl("Back to Main Menu", ButtonClick)); AddControlLayout(buttonLayout); }
void SaveMatchStat() { try { int matchType = (int)EnumMatchType.Dailycup; foreach (var entity in _matchstatDic.Values) { MatchCore.SaveMatchStat(entity.ManagerId, matchType, entity.Win, entity.Lose, entity.Draw, entity.Goals); } } catch (Exception ex) { SystemlogMgr.Error("DailycupProcess SaveMatchStat", ex); } }
/// <summary> /// Replaces the <see cref="MatchRun.CurrentMatch"/> with a new <see cref="Match"/> with specific indexes /// given for <see cref="Shared.Controller"/>s. /// </summary> /// <param name="idx">The current index of the parameter stream.</param> /// <param name="param">The string of parameters made by the user.</param> public static void Match(int idx, params string[] param) { var playControllers = new List <ControllerSkeleton>(); int strParseInt; while (idx < param.Length && int.TryParse(param[idx++], out strParseInt)) { if (strParseInt < 0 || strParseInt > Input.Controllers.Count) { Console.Write("Invalid controller specified: "); Console.WriteLine(strParseInt); } else { playControllers.Add(Input.Controllers[strParseInt]); } } if (playControllers.Count < 2) { Console.WriteLine("A match must include a minimum of two controllers."); return; } try { var newMatch = new MatchCore(); MatchRun.CurrentMatch = newMatch; if (Configuration.Global.GetValue <bool>("mbc_console_create_events")) { Input.RunCommand("event enable MatchBeginEvent"); Input.RunCommand("event enable MatchEndEvent"); Input.RunCommand("event enable PlayerShotEvent"); Input.RunCommand("event enable PlayerWonEvent"); } Console.WriteLine("Match created with:"); foreach (var controller in playControllers) { newMatch.PlayerCreate(controller); Console.WriteLine(controller); } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Replaces the <see cref="MatchRun.CurrentMatch"/> with a new <see cref="Match"/> with specific indexes /// given for <see cref="Shared.Controller"/>s. /// </summary> /// <param name="idx">The current index of the parameter stream.</param> /// <param name="param">The string of parameters made by the user.</param> public static void Match(int idx, params string[] param) { var playControllers = new List<ControllerSkeleton>(); int strParseInt; while (idx < param.Length && int.TryParse(param[idx++], out strParseInt)) { if (strParseInt < 0 || strParseInt > Input.Controllers.Count) { Console.Write("Invalid controller specified: "); Console.WriteLine(strParseInt); } else { playControllers.Add(Input.Controllers[strParseInt]); } } if (playControllers.Count < 2) { Console.WriteLine("A match must include a minimum of two controllers."); return; } try { var newMatch = new MatchCore(); MatchRun.CurrentMatch = newMatch; if (Configuration.Global.GetValue<bool>("mbc_console_create_events")) { Input.RunCommand("event enable MatchBeginEvent"); Input.RunCommand("event enable MatchEndEvent"); Input.RunCommand("event enable PlayerShotEvent"); Input.RunCommand("event enable PlayerWonEvent"); } Console.WriteLine("Match created with:"); foreach (var controller in playControllers) { newMatch.PlayerCreate(controller); Console.WriteLine(controller); } } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <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); } }
public abstract void Event(MatchCore matchCore, int playerId);
/// <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); } }
/// <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; }
public override void Event(MatchCore matchCore, int playerId) { }
/// <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 override void Event(MatchCore matchCore, int playerId) { matchCore.NextPlayerPrevDice = true; matchCore.NoEnqueue = true; }
/// <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); }
/// <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); }
public override void Event(MatchCore matchCore, int playerId) { matchCore.NoEnqueue = true; }
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); }
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); }
public override void Event(MatchCore matchCore, int playerId) { matchCore.Players[playerId].Position = 0; }
public override void Event(MatchCore matchCore, int playerId) { var(_, secondPosition) = matchCore.ActionSchedule.Skip(1).Select((p, i) => (p, i)).First(t => t.p == playerId); matchCore.ActionSchedule.RemoveAt(secondPosition + 1); }
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); }
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); }