private static List <PlayerEntity> OnePlayerHealthDamage(Contexts contexts, IGameRule gameRule, PlayerEntity srcPlayer, PlayerEntity playerEntity, PlayerDamageInfo damage, IDamageInfoCollector damageInfoCollector, bool isTeam) { if (playerEntity.gamePlay.IsDead()) { return(null); } if ((DateTime.Now.Ticks / 10000L) - playerEntity.statisticsData.Statistics.LastHitDownTime <= 1000 && !damage.InstantDeath) { return(null); } float curHp = playerEntity.gamePlay.CurHp; float realDamage = damage.damage; if (gameRule != null) { realDamage = gameRule.HandleDamage(srcPlayer, playerEntity, damage); } if (null != damageInfoCollector) { damageInfoCollector.SetPlayerDamageInfo(srcPlayer, playerEntity, realDamage, (EBodyPart)damage.part); } if (!SharedConfig.IsOffline && !SharedConfig.IsServer) { return(null); } float ret = playerEntity.gamePlay.DecreaseHp(realDamage); _logger.InfoFormat("[hit] after CurrHp :" + playerEntity.gamePlay.CurHp); damage.damage = ret; //玩家状态 List <PlayerEntity> teamList = CheckUpdatePlayerStatus(playerEntity, damage, !isTeam && gameRule != null ? gameRule.Contexts : null); //保存最后伤害来源 StatisticsData statisticsData = playerEntity.statisticsData.Statistics; if (statisticsData.DataCollectSwitch) { if (playerEntity.gamePlay.IsLastLifeState(EPlayerLifeState.Alive)) { statisticsData.IsHited = true; if (null != srcPlayer) { statisticsData.LastHurtKey = srcPlayer.entityKey.Value; } else { statisticsData.LastHurtKey = EntityKey.Default; } statisticsData.LastHurtType = damage.type; statisticsData.LastHurtPart = damage.part; statisticsData.LastHurtWeaponId = damage.weaponId; } //击倒人头 if (statisticsData.IsHited && (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)) { if (gameRule != null) { PlayerEntity lastEntity = gameRule.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; } } } } if (playerEntity.gamePlay.IsHitDown()) { statisticsData.LastHitDownTime = (DateTime.Now.Ticks / 10000L); 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); } if (playerEntity.gamePlay.IsDead()) { //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 && 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.playerInfo.JobAttribute == (int)EJobAttribute.EJob_Hero) { //英雄击杀 feedbackType |= 1 << (int)EUIKillFeedbackType.HeroKO; playerEntity.playerInfo.SpecialFeedbackType = (int)EUIKillFeedbackType.HeroKO; } //武器 WeaponResConfigItem newConfig = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(damage.weaponId); if (null != newConfig) { if (newConfig.SubType == (int)EWeaponSubType.Melee) { feedbackType |= 1 << (int)EUIKillFeedbackType.MeleeWeapon; playerEntity.playerInfo.SpecialFeedbackType = (int)EUIKillFeedbackType.MeleeWeapon; } else if (newConfig.SubType == (int)EWeaponSubType.BurnBomb) { feedbackType |= 1 << (int)EUIKillFeedbackType.Burning; } else if (newConfig.SubType == (int)EWeaponSubType.Grenade) { feedbackType |= 1 << (int)EUIKillFeedbackType.Grenade; } } if (feedbackType == 0) { //普通击杀 feedbackType = 1 << (int)EUIKillFeedbackType.Normal; } damage.KillFeedbackType = feedbackType; } } //数据统计 ProcessDamageStatistics(contexts, gameRule, srcPlayer, playerEntity, damage); } //击杀|击倒 if (null != gameRule && playerEntity.gamePlay.IsDead()) { gameRule.KillPlayer(srcPlayer, playerEntity, damage); } _logger.DebugFormat("change player hp entityId:{0}, health {1}->{2}, state {3}, srcPlayerId:{4}, playerId:{5}, hurtType:{6}, weaponId:{7}", playerEntity.entityKey.Value.EntityId, curHp, playerEntity.gamePlay.CurHp, playerEntity.gamePlay.LifeState, (srcPlayer != null) ? srcPlayer.playerInfo.PlayerId : 0, playerEntity.playerInfo.PlayerId, damage.type, damage.weaponId); return(teamList); }
private static List <PlayerEntity> OnePlayerHealthDamage(Contexts contexts, IGameRule gameRule, PlayerEntity srcPlayer, PlayerEntity playerEntity, PlayerDamageInfo damage, IDamageInfoCollector damageInfoCollector, bool isTeam) { if (playerEntity.gamePlay.IsDead()) { return(null); } float curHp = playerEntity.gamePlay.CurHp; float realDamage = damage.damage; if (gameRule != null) { realDamage = gameRule.HandleDamage(srcPlayer, playerEntity, damage); } if (null != damageInfoCollector) { damageInfoCollector.SetPlayerDamageInfo(srcPlayer, playerEntity, realDamage, (EBodyPart)damage.part); } if (!SharedConfig.IsOffline && !SharedConfig.IsServer) { return(null); } float ret = playerEntity.gamePlay.DecreaseHp(realDamage); damage.damage = ret; //玩家状态 List <PlayerEntity> teamList = CheckUpdatePlayerStatus(playerEntity, damage, !isTeam && gameRule != null ? gameRule.Contexts : null); //保存最后伤害来源 StatisticsData statisticsData = playerEntity.statisticsData.Statistics; if (statisticsData.DataCollectSwitch) { if (playerEntity.gamePlay.IsLastLifeState(EPlayerLifeState.Alive)) { statisticsData.IsHited = true; if (null != srcPlayer) { statisticsData.LastHurtKey = srcPlayer.entityKey.Value; } else { statisticsData.LastHurtKey = EntityKey.Default; } statisticsData.LastHurtType = damage.type; statisticsData.LastHurtPart = damage.part; statisticsData.LastHurtWeaponId = damage.weaponId; } //谁击倒算谁的人头 if (statisticsData.IsHited) { if (gameRule != null) { PlayerEntity lastEntity = gameRule.Contexts.player.GetEntityWithEntityKey(statisticsData.LastHurtKey); if (null != lastEntity) { srcPlayer = lastEntity; } } damage.type = statisticsData.LastHurtType; damage.part = statisticsData.LastHurtPart; damage.weaponId = statisticsData.LastHurtWeaponId; } if (playerEntity.gamePlay.IsDead()) { //UI击杀信息 int killType = 0; if (damage.part == (int)EBodyPart.Head) { killType |= (int)EUIKillType.Crit; } if (playerEntity.gamePlay.IsHitDown()) { killType |= (int)EUIKillType.Hit; } damage.KillType = killType; //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 && 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; } //武器 WeaponResConfigItem newConfig = SingletonManager.Get <WeaponResourceConfigManager>().GetConfigById(damage.weaponId); if (null != newConfig) { if (newConfig.SubType == (int)EWeaponSubType.Melee) { feedbackType |= 1 << (int)EUIKillFeedbackType.MeleeWeapon; } else if (newConfig.SubType == (int)EWeaponSubType.BurnBomb) { feedbackType |= 1 << (int)EUIKillFeedbackType.Burning; } else if (newConfig.SubType == (int)EWeaponSubType.Grenade) { feedbackType |= 1 << (int)EUIKillFeedbackType.Grenade; } } if (feedbackType == 0) { //普通击杀 feedbackType = 1 << (int)EUIKillFeedbackType.Normal; } damage.KillFeedbackType = feedbackType; } } //数据统计 ProcessDamageStatistics(contexts, gameRule, srcPlayer, playerEntity, damage); } //击杀|击倒 if (null != gameRule && playerEntity.gamePlay.IsDead()) { gameRule.KillPlayer(srcPlayer, playerEntity, damage); } _logger.DebugFormat("change player hp entityId:{0}, health {1}->{2}, state {3}, srcPlayerId:{4}, playerId:{5}, hurtType:{6}, weaponId:{7}", playerEntity.entityKey.Value.EntityId, curHp, playerEntity.gamePlay.CurHp, playerEntity.gamePlay.LifeState, (srcPlayer != null) ? srcPlayer.playerInfo.PlayerId : 0, playerEntity.playerInfo.PlayerId, damage.type, damage.weaponId); return(teamList); }
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); }