private DamageListForServer GetServerDamageList(WorldBoss _this, List <ulong> players, ulong lastPlayer = 0) { var ret = new DamageListForServer(); var retData = ret.Data; var topPlayers = ret.TopPlayers; for (int i = 0, imax = _this.DamageList.Count > 5 ? 5 : _this.DamageList.Count; i < imax; ++i) { topPlayers.Add(_this.DamageList[i]); } foreach (var playerId in players) { retData.Add(_this.PlayerDamages[playerId]); } retData.Sort(_this.DuComparer); ret.TotalDamage = _this.TotalDamage; ret.LastPlayer = lastPlayer; return(ret); }
private IEnumerator SendDamageListCoroutine(Coroutine co) { var damageList = mBoss.CollectDamageList(); var hpOld = mBoss.Attr.GetDataValue(eAttributeType.HpNow); //把新进来的人加入damageList var datas = damageList.Data; foreach (var player in NewPlayers.Values) { var unit = datas.Find(d => d.CharacterId == player.ObjId); if (unit != null) { unit.Name = player.GetName(); } else { unit = new DamageUnit(); unit.CharacterId = player.ObjId; unit.Name = player.GetName(); datas.Add(unit); } } NewPlayers.Clear(); var notifyMsg = SceneServer.Instance.ActivityAgent.NotifyDamageList(0, ServerId, Guid, damageList); yield return(notifyMsg.SendAndWaitUntilDone(co)); if (notifyMsg.State != MessageState.Reply || notifyMsg.ErrorCode != (int)ErrorCodes.OK) { Logger.Error("NotifyDamageList failed in GetDamageListCoroutine()!!!"); //如果失败了,重试一次 if (++nSendDamageListFailedCount < 1) { yield return(SceneServer.Instance.ServerControl.Wait(co, TimeSpan.FromMilliseconds(20))); SendLastDamageList(); } else { nSendDamageListFailedCount = 0; } yield break; } mDamageList = notifyMsg.Response; //此场景中所有人的伤害列表 var damageDatas = mDamageList.Data; //整场战斗的前五名 var topPlayers = mDamageList.TopPlayers; //通知客户端刷新伤害列表 PushActionToAllPlayer(player => { var myDamageList = new DamageList(); myDamageList.TopPlayers.AddRange(topPlayers); var myUnit = damageDatas.Find(d => d.CharacterId == player.ObjId); if (myUnit == null) { return; } myDamageList.Data.Add(myUnit); myDamageList.NpcMaxHp = BossMaxHp; player.Proxy.NotifyDamageList(myDamageList); }); //修正boss血量 var hpNow = BossMaxHp - mDamageList.TotalDamage; mBoss.Attr.SetDataValue(eAttributeType.HpNow, hpNow); if (hpNow > hpOld) { PushActionToAllPlayer(player => { player.Proxy.NotifyBattleReminder(27, Utils.WrapDictionaryId(6018), 1); }); } //给最后一击的玩家发奖励 if (mDamageList.LastPlayer != 0) { SendLastHitReward(mDamageList.LastPlayer); } }