public void TakeDamage(ActorHitInfo data) { if (MetaState.Instance.SessionFlags.Contains("GodMode") || GameState.Instance.PlayerFlags.Contains(PlayerFlags.Invulnerable) || IsDying) { return; } CharacterModel playerModel = GameState.Instance.PlayerRpgState; //damage model is very stupid right now, we will make it better later var(dt, dr) = playerModel.GetDamageThresholdAndResistance(data.DamageType); float damageTaken = RpgValues.DamageTaken(data.Damage, data.DamagePierce, dt, dr); if (data.HitLocation == (int)ActorBodyPart.Head) { damageTaken *= 2.0f; } else if (data.HitLocation == (int)ActorBodyPart.LeftArm || data.HitLocation == (int)ActorBodyPart.LeftLeg || data.HitLocation == (int)ActorBodyPart.RightArm || data.HitLocation == (int)ActorBodyPart.RightLeg) { damageTaken *= 0.75f; } if (damageTaken > 0) { if (PainSound != null && !PainSound.isPlaying) { PainSound.Play(); } } playerModel.Health -= damageTaken; }
public void TakeDamage(ActorHitInfo data) { if (MetaState.Instance.SessionFlags.Contains("GodMode") || GameState.Instance.PlayerFlags.Contains(PlayerFlags.Invulnerable) || IsDying) { return; } if (!data.HarmFriendly) { string hitFaction = data.OriginatorFaction; if (!string.IsNullOrEmpty(hitFaction)) { FactionRelationStatus relation = FactionModel.GetRelation(hitFaction, PredefinedFaction.Player.ToString()); //this looks backwards but it's because we're checking if the Bullet is-friendly-to the Actor if (relation == FactionRelationStatus.Friendly) { return; //no friendly fire } } } if (DamageHandler != null) { var hitOut = DamageHandler(data); if (hitOut.HasValue) { data = hitOut.Value; } else { return; } } CharacterModel playerModel = GameState.Instance.PlayerRpgState; var(damageToShields, damageToArmor, damageToCharacter) = RpgValues.DamageRatio(data.Damage, data.DamagePierce, playerModel); float oldShields = playerModel.Shields; playerModel.Shields -= damageToShields; if (oldShields > 0 && playerModel.Shields <= 0) { MessageInterface.PushToBus(new QdmsFlagMessage("PlayerShieldsLost")); ShieldComponent.Ref()?.SignalLostShields(); } var(dt, dr) = playerModel.GetDamageThresholdAndResistance(data.DamageType); float damageTaken = RpgValues.DamageTaken(damageToArmor, damageToCharacter, dt, dr); if (data.HitLocation == (int)ActorBodyPart.Head) { damageTaken *= 2.0f; } else if (data.HitLocation == (int)ActorBodyPart.LeftArm || data.HitLocation == (int)ActorBodyPart.LeftLeg || data.HitLocation == (int)ActorBodyPart.RightArm || data.HitLocation == (int)ActorBodyPart.RightLeg) { damageTaken *= 0.75f; } playerModel.Health -= damageTaken; if (damageTaken > PainSoundThreshold) { if (PainSound != null && !PainSound.isPlaying) { PainSound.Play(); } } if (damageToShields > 0 || damageTaken > 0) { ShieldComponent.Ref()?.SignalTookDamage(damageToShields, damageTaken); var damageValues = new Dictionary <string, object>() { { "DamageTaken", damageTaken }, { "DamageToShields", damageToShields }, { "DamageToArmor", damageToArmor }, { "DamageToCharacter", damageToCharacter } }; MessageInterface.PushToBus(new QdmsKeyValueMessage(damageValues, "PlayerTookDamage")); } }
public void TakeDamage(ActorHitInfo data) { //damage model is very stupid right now, we will make it better later float dt = data.DamageType < DamageThreshold.Length ? DamageThreshold[(int)data.DamageType] : 0f; float dr = data.DamageType < DamageThreshold.Length ? DamageResistance[(int)data.DamageType] : 0f; float damageTaken = RpgValues.DamageTaken(data.Damage, data.DamagePierce, dt, dr); if (data.HitLocation == (int)ActorBodyPart.Head) { damageTaken *= 2.0f; } else if (data.HitLocation == (int)ActorBodyPart.LeftArm || data.HitLocation == (int)ActorBodyPart.LeftLeg || data.HitLocation == (int)ActorBodyPart.RightArm || data.HitLocation == (int)ActorBodyPart.RightLeg) { damageTaken *= 0.75f; } damageTaken *= (1f / ConfigState.Instance.GetGameplayConfig().Difficulty.ActorStrength); if (!Invincible) { Health -= damageTaken; } /* * if(!string.IsNullOrEmpty(data.HitPuff)) * { * Debug.Log($"Spawning hitpuff \"{data.HitPuff}\" at {data.HitCoords}"); * Vector3 hitCoords = data.HitCoords.HasValue ? data.HitCoords.Value : transform.position; * WorldUtils.SpawnEffect(data.HitPuff, hitCoords, transform.eulerAngles, null); * } * else if(!string.IsNullOrEmpty(DefaultHitPuff)) * { * Vector3 hitCoords = data.HitCoords.HasValue ? data.HitCoords.Value : transform.position; * WorldUtils.SpawnEffect(DefaultHitPuff, hitCoords, transform.eulerAngles, null); * } */ //we no longer spawn hitpuffs here if (CurrentAiState == ActorAiState.Dead) //abort if we're already dead { return; } bool didTakePain = UnityEngine.Random.Range(0f, 1f) < PainChance; if (Defensive && data.Originator != null && data.Originator != this) { FactionRelationStatus relation = FactionRelationStatus.Neutral; if (data.Originator is PlayerController) { relation = FactionModel.GetRelation(Faction, "Player"); } else if (data.Originator is ActorController) { relation = FactionModel.GetRelation(Faction, ((ActorController)data.Originator).Faction); } if (relation != FactionRelationStatus.Friendly || Infighting) { Target = data.Originator.transform; BeenHit = true; if (DisableInteractionOnHit && InteractionComponent != null) { InteractionComponent.InteractionDisabledByHit = true; } if (FeelPain && didTakePain) { EnterState(ActorAiState.Hurting); } else { EnterState(ActorAiState.Chasing); } } else { EnterState(ActorAiState.Hurting); } } else if (FeelPain && didTakePain) { EnterState(ActorAiState.Hurting); } }
public void TakeDamage(ActorHitInfo data) { if (!data.HarmFriendly) { string hitFaction = data.OriginatorFaction; if (!string.IsNullOrEmpty(hitFaction)) { FactionRelationStatus relation = FactionModel.GetRelation(hitFaction, Faction); //this looks backwards but it's because we're checking if the Bullet is-friendly-to the Actor if (relation == FactionRelationStatus.Friendly) { return; //no friendly fire } } } //damage model is very stupid right now, we will make it better later float dt = data.DamageType < DamageThreshold.Length ? DamageThreshold[(int)data.DamageType] : 0f; float dr = data.DamageType < DamageThreshold.Length ? DamageResistance[(int)data.DamageType] : 0f; float damageTaken = RpgValues.DamageTaken(data.Damage, data.DamagePierce, dt, dr); if (data.HitLocation == (int)ActorBodyPart.Head) { damageTaken *= 2.0f; } else if (data.HitLocation == (int)ActorBodyPart.LeftArm || data.HitLocation == (int)ActorBodyPart.LeftLeg || data.HitLocation == (int)ActorBodyPart.RightArm || data.HitLocation == (int)ActorBodyPart.RightLeg) { damageTaken *= 0.75f; } damageTaken *= (1f / ConfigState.Instance.GetGameplayConfig().Difficulty.ActorStrength); if (!Invincible) { Health -= damageTaken; } if (CurrentAiState == ActorAiState.Dead) //abort if we're already dead { return; } bool didTakePain = UnityEngine.Random.Range(0f, 1f) < PainChance; //shouldn't this be weighted by damage? if (Defensive && data.Originator != null && data.Originator != this) { FactionRelationStatus relation = FactionRelationStatus.Neutral; if (data.Originator is PlayerController) { relation = FactionModel.GetRelation(Faction, "Player"); } else if (data.Originator is ActorController) { relation = FactionModel.GetRelation(Faction, ((ActorController)data.Originator).Faction); } if (relation != FactionRelationStatus.Friendly || Infighting) { Target = data.Originator.transform; BeenHit = true; if (DisableInteractionOnHit && InteractionComponent != null) { InteractionComponent.InteractionDisabledByHit = true; } if (FeelPain && didTakePain) { if (CurrentAiState != ActorAiState.Hurting) { EnterState(ActorAiState.Hurting); } else { EnterState(ActorAiState.Chasing); } } } else if (CurrentAiState != ActorAiState.Hurting) { EnterState(ActorAiState.Hurting); } } else if (FeelPain && didTakePain && CurrentAiState != ActorAiState.Hurting) { EnterState(ActorAiState.Hurting); } }
public void TakeDamage(ActorHitInfo data) { LastHit = null; LastHitDamage = 0; if (!data.HarmFriendly) { string hitFaction = data.OriginatorFaction; if (!string.IsNullOrEmpty(hitFaction)) { FactionRelationStatus relation = GameState.Instance.FactionState.GetRelation(hitFaction, Faction); //this looks backwards but it's because we're checking if the Bullet is-friendly-to the Actor if (relation == FactionRelationStatus.Friendly) { return; //no friendly fire } } } ActorDamageHandlerResult?damageHandlerResult = null; if (DamageHandler != null) { damageHandlerResult = DamageHandler(data); if (damageHandlerResult.Value.HitInfo.HasValue) { data = damageHandlerResult.Value.HitInfo.Value; } else { return; } } LastHit = data; float damageTaken; if (damageHandlerResult?.DamageTaken != null) { damageTaken = damageHandlerResult.Value.DamageTaken.Value; } else { //new way of doing dr/dt float dt = 0, dr = 0; foreach (var dNode in DamageResistances) { if ((int)dNode.DamageType == data.DamageType) { dt = dNode.DamageThreshold; dr = dNode.DamageResistance; } } damageTaken = RpgValues.DamageTaken(data, dt, dr); if (!data.HitFlags.HasFlag(BuiltinHitFlags.IgnoreHitLocation)) { if (data.HitLocation == (int)ActorBodyPart.Head) { damageTaken *= 2.0f; //do we want more flexibility here? } else if (data.HitLocation == (int)ActorBodyPart.LeftArm || data.HitLocation == (int)ActorBodyPart.LeftLeg || data.HitLocation == (int)ActorBodyPart.RightArm || data.HitLocation == (int)ActorBodyPart.RightLeg) { damageTaken *= 0.75f; } } damageTaken *= (1f / ConfigState.Instance.GetGameplayConfig().Difficulty.ActorStrength); } if (!Invincible) { LastHitDamage = damageTaken; Health -= damageTaken; } //handle extreme death if (damageHandlerResult?.ExtremeDeath != null) { WasExtremeDeath = damageHandlerResult.Value.ExtremeDeath.Value; } else { if (data.HitFlags.HasFlag(BuiltinHitFlags.AlwaysExtremeDeath)) { WasExtremeDeath = true; } else if (data.HitFlags.HasFlag(BuiltinHitFlags.NeverExtremeDeath)) { WasExtremeDeath = false; } else { if (ExtremeDeathThreshold > 0) { //interpret as -(maxhealth * threshold) WasExtremeDeath = Health < (-(MaxHealth * ExtremeDeathThreshold)); } else if (ExtremeDeathThreshold < 0) { //interpret as absolute value WasExtremeDeath = Health < ExtremeDeathThreshold; } else { //ExtremeDeathThreshold == 0, no extreme death WasExtremeDeath = false; } } } //TODO do we force into death state here? //TODO consider moving this, but probably wait until we start thinking about abuse of corpses if (CurrentAiState == ActorAiState.Dead) //abort if we're already dead { return; } bool didTakePain; if (damageHandlerResult?.TookPain != null) { didTakePain = damageHandlerResult.Value.TookPain.Value; } else { float derivedPainChance = PainChance; if (PainGuaranteeThreshold != 0) { float damageForMaxPain = Mathf.Abs(PainGuaranteeRelative ? (PainGuaranteeThreshold * MaxHealth) : PainGuaranteeThreshold); derivedPainChance = MathUtils.ScaleRange(damageTaken, 0, damageForMaxPain, PainChance, 1); } derivedPainChance = Mathf.Min(derivedPainChance, PainMaxChance); didTakePain = (data.HitFlags.HasFlag(BuiltinHitFlags.AlwaysPain) || UnityEngine.Random.Range(0f, 1f) < derivedPainChance) && !data.HitFlags.HasFlag(BuiltinHitFlags.NoPain); //TODO shouldn't this be weighted by damage? } if (Defensive && data.Originator != null && data.Originator != this && !data.HitFlags.HasFlag(BuiltinHitFlags.NeverAlert)) { FactionRelationStatus relation = FactionRelationStatus.Neutral; if (data.Originator is PlayerController) { relation = GameState.Instance.FactionState.GetRelation(Faction, "Player"); } else if (data.Originator is ActorController) { relation = GameState.Instance.FactionState.GetRelation(Faction, ((ActorController)data.Originator).Faction); } if (relation != FactionRelationStatus.Friendly || Infighting) { Target = data.Originator.transform; BeenHit = true; if (DisableInteractionOnHit && InteractionComponent != null) { InteractionComponent.InteractionDisabledByHit = true; } if (FeelPain && didTakePain && CurrentAiState != ActorAiState.ScriptedAction && CurrentAiState != ActorAiState.ScriptedMoveTo) { if (PainStateAllowRestart || CurrentAiState != ActorAiState.Hurting) { EnterState(ActorAiState.Hurting); } } else if (CurrentAiState != ActorAiState.Chasing && CurrentAiState != ActorAiState.Attacking && CurrentAiState != ActorAiState.ScriptedAction && CurrentAiState != ActorAiState.ScriptedMoveTo) { EnterState(ActorAiState.Chasing); } } else if ((PainStateAllowRestart || CurrentAiState != ActorAiState.Hurting) && FeelPain && CurrentAiState != ActorAiState.ScriptedAction && CurrentAiState != ActorAiState.ScriptedMoveTo) { EnterState(ActorAiState.Hurting); } } else if (FeelPain && didTakePain && (PainStateAllowRestart || CurrentAiState != ActorAiState.Hurting) && CurrentAiState != ActorAiState.ScriptedAction && CurrentAiState != ActorAiState.ScriptedMoveTo) { EnterState(ActorAiState.Hurting); } }