private static List <PlayerEntity> CheckUpdatePlayerStatus(PlayerEntity player, PlayerDamageInfo damage, Contexts contexts) { GamePlayComponent gamePlay = player.gamePlay; if (gamePlay.IsLifeState(EPlayerLifeState.Alive)) { if (gamePlay.CurHp <= 0) { //存活队友 int aliveCount = 0; //存活队伍 HashSet <long> aliveTeams = new HashSet <long>(); if (null != contexts) { foreach (PlayerEntity other in contexts.player.GetEntities()) { if (other.hasPlayerInfo && other != player && other.gamePlay.IsLifeState(EPlayerLifeState.Alive)) { aliveTeams.Add(other.playerInfo.TeamId); if (other.playerInfo.TeamId == player.playerInfo.TeamId) { aliveCount++; } } } } if (damage.type == (int)EUIDeadType.Drown || /*|| damage.type == (int) EUIDeadType.VehicleBomb*/ player.stateInterface.State.GetCurrentPostureState() == PostureInConfig.Swim || player.stateInterface.State.GetCurrentPostureState() == PostureInConfig.Dive) { //直接死亡 gamePlay.ChangeLifeState(EPlayerLifeState.Dead, player.time.ClientTime); } else if (aliveCount == 0) { //自己 gamePlay.ChangeLifeState(EPlayerLifeState.Dead, player.time.ClientTime); //全队阵亡 if (null != contexts) { List <PlayerEntity> teamList = new List <PlayerEntity>(); foreach (PlayerEntity other in contexts.player.GetEntities()) { if (other.hasPlayerInfo && other != player && other.playerInfo.TeamId == player.playerInfo.TeamId && other.gamePlay.IsLifeState(EPlayerLifeState.Dying)) { teamList.Add(other); } } return(teamList); } } else if (GetTeamCapacity(contexts) > 1 && aliveTeams.Count > 1) { //受伤状态 gamePlay.ChangeLifeState(EPlayerLifeState.Dying, player.time.ClientTime); } else { gamePlay.ChangeLifeState(EPlayerLifeState.Dead, player.time.ClientTime); } } } else if (gamePlay.IsLifeState(EPlayerLifeState.Dying)) { if (gamePlay.InHurtedHp <= 0) { gamePlay.ChangeLifeState(EPlayerLifeState.Dead, player.time.ClientTime); } else { int aliveCount = 0; if (null != contexts) { foreach (PlayerEntity other in contexts.player.GetEntities()) { if (other.hasPlayerInfo && other != player && other.gamePlay.IsLifeState(EPlayerLifeState.Alive) && other.playerInfo.TeamId == player.playerInfo.TeamId) { aliveCount++; } } } if (aliveCount == 0) { gamePlay.ChangeLifeState(EPlayerLifeState.Dead, player.time.ClientTime); } } } return(null); }
private static List <PlayerEntity> OnePlayerHealthDamage(Contexts contexts, IGameRule gameRule, PlayerEntity srcPlayer, PlayerEntity playerEntity, PlayerDamageInfo damage, bool isTeam) { GamePlayComponent gamePlay = playerEntity.gamePlay; if (gamePlay.IsDead()) { return(null); } float realDamage = gameRule == null ? damage.damage : gameRule.HandleDamage(srcPlayer, playerEntity, damage); WeaponResConfigItem weaponConfig = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(damage.weaponId); if (srcPlayer != null) { try { //受伤梯形标记 if (SharedConfig.IsServer) { if (damage.type == (int)EUIDeadType.Weapon || damage.type == (int)EUIDeadType.Unarmed) { if (weaponConfig != null && weaponConfig.SubType != (int)EWeaponSubType.Grenade) { BulletStatisticsUtil.SetPlayerDamageInfoS(srcPlayer, playerEntity, realDamage, (EBodyPart)damage.part); } } } else { BulletStatisticsUtil.SetPlayerDamageInfoC(srcPlayer, playerEntity, realDamage, (EBodyPart)damage.part); } } catch (Exception e) { _logger.Error("受伤梯形标记", e); } } if (!SharedConfig.IsOffline && !SharedConfig.IsServer) { return(null); } if (!playerEntity.hasStatisticsData) { return(null); } StatisticsData statisticsData = playerEntity.statisticsData.Statistics; var now = gameRule == null ? playerEntity.time.ClientTime : gameRule.ServerTime; if (now - statisticsData.LastHitDownTime <= 1000 && !damage.InstantDeath) { return(null); } damage.damage = gamePlay.DecreaseHp(realDamage); //玩家状态 List <PlayerEntity> teamList = CheckUpdatePlayerStatus(playerEntity, damage, isTeam ? null : contexts, (int)now); //保存最后伤害来源 if (statisticsData.DataCollectSwitch) { try { if (gamePlay.IsLastLifeState(EPlayerLifeState.Alive)) { //statisticsData.IsHited = true; statisticsData.LastHurtKey = null != srcPlayer ? srcPlayer.entityKey.Value : EntityKey.Default; statisticsData.LastHurtType = damage.type; statisticsData.LastHurtPart = damage.part; statisticsData.LastHurtWeaponId = damage.weaponId; } //击倒人头 if ((gamePlay.IsLifeState(EPlayerLifeState.Dying) || gamePlay.IsDead()) && (damage.type == (int)EUIDeadType.NoHelp || damage.type == (int)EUIDeadType.Poison || damage.type == (int)EUIDeadType.Bomb || damage.type == (int)EUIDeadType.Drown || damage.type == (int)EUIDeadType.Bombing || damage.type == (int)EUIDeadType.Fall)) { PlayerEntity lastEntity = contexts.player.GetEntityWithEntityKey(statisticsData.LastHurtKey); if (null != lastEntity) { srcPlayer = lastEntity; if (srcPlayer.playerInfo.TeamId == playerEntity.playerInfo.TeamId) { damage.type = statisticsData.LastHurtType; damage.part = statisticsData.LastHurtPart; damage.weaponId = statisticsData.LastHurtWeaponId; } else { damage.type = (int)EUIDeadType.NoHelp; } } } } catch (Exception e) { _logger.Error("计算玩家战报信息失败", e); } if (gamePlay.IsHitDown()) { try { statisticsData.LastHitDownTime = now; SimpleProto message = FreePool.Allocate(); message.Key = FreeMessageConstant.ScoreInfo; int feedbackType = 0; message.Ks.Add(3); message.Bs.Add(true); if (null != srcPlayer) { if (srcPlayer.playerInfo.TeamId != playerEntity.playerInfo.TeamId) { feedbackType |= 1 << (int)EUIKillFeedbackType.Hit; } message.Ss.Add(srcPlayer.playerInfo.PlayerName); message.Ds.Add(srcPlayer.playerInfo.TeamId); message.Ins.Add(damage.weaponId); } else { message.Ss.Add(""); message.Ds.Add(-1); message.Ins.Add(0); } message.Ins.Add((int)EUIKillType.Hit); message.Ins.Add(feedbackType); message.Ss.Add(playerEntity.playerInfo.PlayerName); message.Ds.Add(playerEntity.playerInfo.TeamId); message.Ins.Add(damage.type); SendMessageAction.sender.SendMessage(contexts.session.commonSession.FreeArgs as IEventArgs, message, 4, string.Empty); } catch (Exception e) { _logger.Error("计算玩家ScoreInfo信息失败", e); } } if (gamePlay.IsDead()) { try { //UI击杀信息 int killType = 0; if (damage.part == (int)EBodyPart.Head) { killType |= (int)EUIKillType.Crit; } damage.KillType = killType; playerEntity.playerInfo.SpecialFeedbackType = 0; //UI击杀反馈 if (null != srcPlayer && srcPlayer.playerInfo.TeamId != playerEntity.playerInfo.TeamId) { int feedbackType = 0; if (damage.part == (int)EBodyPart.Head) { //爆头 feedbackType |= 1 << (int)EUIKillFeedbackType.CritKill; } if (damage.IsOverWall) { //穿墙击杀 feedbackType |= 1 << (int)EUIKillFeedbackType.ThroughWall; } if (SharedConfig.IsServer && null != gameRule && contexts.session.serverSessionObjects.DeathOrder == 0 && srcPlayer.playerInfo.TeamId != playerEntity.playerInfo.TeamId) { //一血 feedbackType |= 1 << (int)EUIKillFeedbackType.FirstBlood; } if (playerEntity.playerInfo.PlayerId == srcPlayer.statisticsData.Statistics.RevengeKillerId) { //复仇 feedbackType |= 1 << (int)EUIKillFeedbackType.Revenge; srcPlayer.statisticsData.Statistics.RevengeKillerId = 0L; } if (srcPlayer.gamePlay.JobAttribute == (int)EJobAttribute.EJob_Hero) { //英雄击杀 feedbackType |= 1 << (int)EUIKillFeedbackType.HeroKO; playerEntity.playerInfo.SpecialFeedbackType = (int)EUIKillFeedbackType.HeroKO; } //武器 if (null != weaponConfig) { switch ((EWeaponSubType)weaponConfig.SubType) { case EWeaponSubType.Melee: feedbackType |= 1 << (int)EUIKillFeedbackType.MeleeWeapon; playerEntity.playerInfo.SpecialFeedbackType = (int)EUIKillFeedbackType.MeleeWeapon; break; case EWeaponSubType.BurnBomb: feedbackType |= 1 << (int)EUIKillFeedbackType.Burning; break; case EWeaponSubType.Grenade: feedbackType |= 1 << (int)EUIKillFeedbackType.Grenade; break; default: break; } } if (feedbackType == 0) { //普通击杀 feedbackType = 1 << (int)EUIKillFeedbackType.Normal; } damage.KillFeedbackType = feedbackType; } } catch (Exception e) { _logger.Error("计算玩家战报信息失败", e); } } //数据统计 ProcessDamageStatistics(contexts, gameRule, srcPlayer, playerEntity, damage); } //击杀|击倒 if (gamePlay.IsDead()) { gameRule.KillPlayer(srcPlayer, playerEntity, damage); try { if (damage.HitPoint != Vector3.zero && damage.HitDirection != Vector3.zero && playerEntity.hasRagDoll) { playerEntity.ragDoll.ForceAtPosition = Vector3.zero; switch (damage.type) { case (int)EUIDeadType.Weapon: var config = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(damage.weaponId); if (weaponConfig.Type == (int)EWeaponType_Config.ThrowWeapon) { playerEntity.ragDoll.RigidBodyTransformName = "Bip01 Spine1"; playerEntity.ragDoll.Impulse = (damage.HitDirection.normalized + new Vector3(0, 1.732f)).normalized * config.S_Ragdoll.RagdollForce * DamageFactor(realDamage); } else { foreach (var pair in Joint2BodyPart) { if (pair.Value == (EBodyPart)damage.part) { playerEntity.ragDoll.RigidBodyTransformName = pair.Key.Substring(0, pair.Key.LastIndexOf("_")); break; } } playerEntity.ragDoll.Impulse = damage.HitDirection.normalized * config.S_Ragdoll.RagdollForce * DamageFactor(realDamage); } break; default: var explosionConfig = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(46); playerEntity.ragDoll.RigidBodyTransformName = "Bip01 Spine1"; playerEntity.ragDoll.Impulse = (damage.HitDirection.normalized + new Vector3(0, 1.732f)).normalized * explosionConfig.S_Ragdoll.RagdollForce * DamageFactor(realDamage); break; } } } catch (Exception e) { _logger.Error("计算玩家死亡ragdoll运动信息失败", e); } } //_logger.DebugFormat("change player hp entityId:{0}, health {1}->{2}, state {3}, srcPlayerId:{4}, playerId:{5}, hurtType:{6}, weaponId:{7}", // playerEntity.entityKey.Value.EntityId, playerEntity.gamePlay.CurHp, playerEntity.gamePlay.CurHp, playerEntity.gamePlay.LifeState, (srcPlayer != null) ? srcPlayer.playerInfo.PlayerId : 0, playerEntity.playerInfo.PlayerId, damage.type, damage.weaponId); return(teamList); }