public override void DoAction(IEventArgs args) { IParable unit = args.GetUnit("report"); if (null != unit && unit is SimpleParable) { SimpleParable sp = (SimpleParable)unit; GameOverPlayer goPlayer = (GameOverPlayer)sp.GetFieldObject(0); Dictionary <long, GameOverPlayer> goPlayerList = (Dictionary <long, GameOverPlayer>)sp.GetFieldObject(1); Dictionary <long, IPlayerInfo> playerInfoList = new Dictionary <long, IPlayerInfo>(); Dictionary <long, IPlayerInfo> leavedInfoList = new Dictionary <long, IPlayerInfo>(); Dictionary <long, IPlayerInfo> infoList = (Dictionary <long, IPlayerInfo>)sp.GetFieldObject(2); Dictionary <long, IPlayerInfo> leftList = (Dictionary <long, IPlayerInfo>)sp.GetFieldObject(3); int TeamCapacity = (int)sp.GetFieldObject(4); Logger.InfoFormat("reporting player {0}, totoal player {1}, left player {2}", goPlayer.Id, infoList.Count, leftList.Count); RankType rankType = (RankType)ranktype; IPlayerInfo playerInfo; playerInfoList.TryGetValue(goPlayer.Id, out playerInfo); if (null == playerInfo) { Logger.InfoFormat("no IPlayerInfo of player {0}", goPlayer.Id); return; } //移除缺少数据的玩家 IPlayerInfo availablePlayer; List <long> keys = infoList.Keys.ToList(); foreach (long key in keys) { infoList.TryGetValue(key, out availablePlayer); if (availablePlayer == null || availablePlayer.StatisticsData == null) { Logger.InfoFormat("player {0} info not available", key); continue; } playerInfoList.Add(key, availablePlayer); } keys = leftList.Keys.ToList(); foreach (long key in keys) { leftList.TryGetValue(key, out availablePlayer); if (availablePlayer == null || availablePlayer.StatisticsData == null) { Logger.InfoFormat("left player {0} info not available", key); continue; } leavedInfoList.Add(key, availablePlayer); } //逃跑玩家为所有游戏中的玩家的最后一名 if (playerInfo.StatisticsData.IsRunaway) { playerInfo.StatisticsData.Rank = playerInfoList.Count; } //编辑器传来的数据 if (!string.IsNullOrEmpty(fields)) { string[] items = fields.Split(','); foreach (var item in items) { string[] vs = item.Split('='); if (vs.Length > 1) { goPlayer.Statistics[int.Parse(vs[0])] = args.GetInt(vs[1]); } else { Logger.ErrorFormat("字符串解析错误,请检查模式编辑器: {0}", fields); } } } //团战模式填入两项人数参数 if (rankType == RankType.Group) { int playerCountRate = 0; int teamCountRate = 0; foreach (IPlayerInfo ipi in playerInfoList.Values) { if (ipi.StatisticsData.GameJoinTime > 0 && args.Rule.ServerTime - ipi.StatisticsData.GameJoinTime >= 180000L) { playerCountRate++; } if (ipi.Camp == playerInfo.Camp) { teamCountRate++; } Logger.InfoFormat("player id {0} camp {1} game join time {2} played time {3}", ipi.PlayerId, ipi.Camp, ipi.StatisticsData.GameJoinTime, args.Rule.ServerTime - ipi.StatisticsData.GameJoinTime); } Logger.InfoFormat("game total player count {0} report send {1}", playerInfoList.Count, issend); goPlayer.Statistics[(int)EStatisticsID.ModePlayerCount] = teamCountRate; goPlayer.Statistics[(int)EStatisticsID.SectionPlayerCount] = playerCountRate; } if (issend) { switch (rankType) { case RankType.Group: if (!playerInfo.StatisticsData.IsRunaway) { List <IPlayerInfo> playerSortList = playerInfoList.Values.ToList(); GroupRank(playerSortList, playerInfo, TeamCapacity > 1); } break; case RankType.Survival: int modeId = args.GameContext.session.commonSession.RoomInfo.ModeId; if (modeId != GameRules.SoloSurvival && modeId != GameRules.LadderSoloSurvival && modeId != GameRules.AbyssSoloSurvival) { SurvivalRank(playerInfoList.Values.ToList().Union(leavedInfoList.Values.ToList()).ToList(), goPlayerList, args, playerInfo); } break; default: break; } goPlayer.Statistics[(int)EStatisticsID.Rank] = playerInfo.StatisticsData.Rank; goPlayer.Statistics[(int)EStatisticsID.RankAce] = playerInfo.StatisticsData.Rank == 1 ? 1 : 0; goPlayer.Statistics[(int)EStatisticsID.RankTen] = playerInfo.StatisticsData.Rank <= 10 ? 1 : 0; } else { //不算逃跑的离开玩家的数据保存,否则丢弃数据 if (!playerInfo.StatisticsData.IsRunaway && rankType == RankType.Survival) { GameOverPlayer savedGoPlayer = goPlayer.Clone(); if (goPlayerList.ContainsKey(savedGoPlayer.Id)) { Logger.ErrorFormat("房间GameOverPlayer列表中出现重复ID {0}", savedGoPlayer.Id); } else { goPlayerList.Add(savedGoPlayer.Id, savedGoPlayer); } } //不报告的情况下,将GameOverPlayer ID设为0 goPlayer.Id = 0L; } } }
//private List<PlayerEntity> _playerList = new List<PlayerEntity>(); public override void DoAction(IEventArgs args) { IParable unit = args.GetUnit("report"); if (null != unit && unit is SimpleParable) { SimpleParable sp = (SimpleParable)unit; GameOverPlayer goPlayer = (GameOverPlayer)sp.GetFieldObject(0); Dictionary <long, GameOverPlayer> goPlayerList = (Dictionary <long, GameOverPlayer>)sp.GetFieldObject(1); Dictionary <long, IPlayerInfo> playerInfoList = (Dictionary <long, IPlayerInfo>)sp.GetFieldObject(2); Dictionary <long, IPlayerInfo> leavedInfoList = (Dictionary <long, IPlayerInfo>)sp.GetFieldObject(3); RankType rankType = (RankType)ranktype; IPlayerInfo playerInfo; playerInfoList.TryGetValue(goPlayer.Id, out playerInfo); if (null == playerInfo) { return; } //逃跑玩家为所有游戏中的玩家的最后一名 if (playerInfo.StatisticsData.IsRunaway) { playerInfo.StatisticsData.Rank = playerInfoList.Count; } //编辑器传来的数据 string[] items = fields.Split(','); foreach (var item in items) { string[] vs = item.Split('='); if (vs.Length > 1) { goPlayer.Statistics[int.Parse(vs[0])] = args.GetInt(vs[1]); } else { Logger.ErrorFormat("字符串解析错误,请检查模式编辑器: {0}", fields); } } //团战模式填入两项人数参数 if (rankType == RankType.Group) { int playerCountRate = 0; int teamCountRate = 0; foreach (IPlayerInfo ipi in playerInfoList.Values) { if (ipi.StatisticsData.GameTime >= 3 * 60 * 1000) { playerCountRate++; } if (ipi.Camp == playerInfo.Camp) { teamCountRate++; } } foreach (IPlayerInfo ipi in leavedInfoList.Values) { if (ipi.StatisticsData.GameTime >= 3 * 60 * 1000) { playerCountRate++; } } goPlayer.Statistics[(int)EStatisticsID.ModePlayerCount] = teamCountRate; goPlayer.Statistics[(int)EStatisticsID.SectionPlayerCount] = playerCountRate; } if (issend) { switch (rankType) { case RankType.Group: if (!playerInfo.StatisticsData.IsRunaway) { List <IPlayerInfo> playerSortList = playerInfoList.Values.ToList(); GroupRank(playerSortList); } break; case RankType.Survival: if (args.GameContext.session.commonSession.RoomInfo.ModeId != GameRules.SoloSurvival) { SurvivalRank(playerInfoList.Values.ToList().Union(leavedInfoList.Values.ToList()).ToList(), goPlayerList); Logger.InfoFormat("组队吃鸡模式对玩家进行了排名"); } break; default: break; } goPlayer.Statistics[(int)EStatisticsID.Rank] = playerInfo.StatisticsData.Rank; goPlayer.Statistics[(int)EStatisticsID.RankAce] = playerInfo.StatisticsData.Rank == 1 ? 1 : 0; goPlayer.Statistics[(int)EStatisticsID.RankTen] = playerInfo.StatisticsData.Rank <= 10 ? 1 : 0; } else { //不算逃跑的离开玩家的数据保存,否则丢弃数据 if (!playerInfo.StatisticsData.IsRunaway && rankType == RankType.Survival) { GameOverPlayer savedGoPlayer = goPlayer.Clone(); if (goPlayerList.ContainsKey(savedGoPlayer.Id)) { Logger.ErrorFormat("房间GameOverPlayer列表中出现重复ID {0}", savedGoPlayer.Id); } else { goPlayerList.Add(savedGoPlayer.Id, savedGoPlayer); } } //不报告的情况下,将GameOverPlayer ID设为0 goPlayer.Id = 0L; } Logger.InfoFormat("Player {0} reported, Rank {1}", goPlayer.Id, goPlayer.Statistics[1]); } }