diff --git a/Assets/Scripts/Game/EnemyMotor.cs b/Assets/Scripts/Game/EnemyMotor.cs index 528c1c67be..43728d5b6d 100644 --- a/Assets/Scripts/Game/EnemyMotor.cs +++ b/Assets/Scripts/Game/EnemyMotor.cs @@ -11,6 +11,7 @@ using UnityEngine; using DaggerfallWorkshop.Game.Entity; +using DaggerfallWorkshop.Game.Formulas; using DaggerfallWorkshop.Game.MagicAndEffects; using System.Collections.Generic; using DaggerfallWorkshop.Utility; @@ -32,6 +33,7 @@ public class EnemyMotor : MonoBehaviour #region Member Variables public float OpenDoorDistance = 2f; // Maximum distance to open door + public float fallingDamageThreshold = 5.0f; const float attackSpeedDivisor = 2f; // How much to slow down during attack animations float stopDistance = 1.7f; // Used to prevent orbiting const float doorCrouchingHeight = 1.65f; // How low enemies dive to pass thru doors @@ -1383,10 +1385,6 @@ void UpdateToIdleOrMoveAnim() void ApplyFallDamage() { - // Assuming the same formula is used for the player and enemies - const float fallingDamageThreshold = 5.0f; - const float HPPerMetre = 5f; - if (controller.isGrounded) { // did enemy just land? @@ -1395,18 +1393,22 @@ void ApplyFallDamage() float fallDistance = LastGroundedY - transform.position.y; if (fallDistance > fallingDamageThreshold) { - int damage = (int)(HPPerMetre * (fallDistance - fallingDamageThreshold)); - - EnemyEntity enemyEntity = entityBehaviour.Entity as EnemyEntity; - enemyEntity.DecreaseHealth(damage); + // Assuming the same formula is used for the player and enemies + int damage = FormulaHelper.CalculateFallDamage(entityBehaviour.Entity, fallingDamageThreshold, fallDistance); - if (entityBlood) + if (damage > 0) { - // Like in classic, falling enemies bleed at the center. It must hurt the center of mass ;) - entityBlood.ShowBloodSplash(0, transform.position); - } + EnemyEntity enemyEntity = entityBehaviour.Entity as EnemyEntity; + enemyEntity.DecreaseHealth(damage); - DaggerfallUI.Instance.DaggerfallAudioSource.PlayClipAtPoint((int)SoundClips.FallDamage, FindGroundPosition()); + if (entityBlood) + { + // Like in classic, falling enemies bleed at the center. It must hurt the center of mass ;) + entityBlood.ShowBloodSplash(0, transform.position); + } + + DaggerfallUI.Instance.DaggerfallAudioSource.PlayClipAtPoint((int)SoundClips.FallDamage, FindGroundPosition()); + } } } diff --git a/Assets/Scripts/Game/Formulas/FormulaHelper.cs b/Assets/Scripts/Game/Formulas/FormulaHelper.cs index cfac198788..1cf13c96b0 100644 --- a/Assets/Scripts/Game/Formulas/FormulaHelper.cs +++ b/Assets/Scripts/Game/Formulas/FormulaHelper.cs @@ -427,6 +427,19 @@ public static VampireClans GetVampireClan(int regionIndex) return VampireClans.Lyrezi; } + public static int CalculateFallDamage(DaggerfallEntity entity, float threshold, float distance) + { + Func del; + if (TryGetOverride("CalculateFallDamage", out del)) + return del(entity, threshold, distance); + + float HPPerMetre = 5; + + int damage = (int)(HPPerMetre * (distance - threshold)); + + return damage; + } + #endregion #region Combat & Damage diff --git a/Assets/Scripts/Game/PlayerHealth.cs b/Assets/Scripts/Game/PlayerHealth.cs index 042b1198cc..f227e8327b 100644 --- a/Assets/Scripts/Game/PlayerHealth.cs +++ b/Assets/Scripts/Game/PlayerHealth.cs @@ -1,4 +1,4 @@ -// Project: Daggerfall Unity +// Project: Daggerfall Unity // Copyright: Copyright (C) 2009-2023 Daggerfall Workshop // Web Site: http://www.dfworkshop.net // License: MIT License (http://www.opensource.org/licenses/mit-license.php) @@ -12,6 +12,7 @@ using UnityEngine; using System.Collections; using DaggerfallWorkshop.Game.Entity; +using DaggerfallWorkshop.Game.Formulas; namespace DaggerfallWorkshop.Game { @@ -48,13 +49,12 @@ void RemoveHealth(int amount) /// void ApplyPlayerFallDamage(float fallDistance) { - const float threshold = 5f; - const float HPPerMetre = 5f; - if (entityBehaviour) { - int damage = (int)(HPPerMetre * (fallDistance - threshold)); - RemoveHealth(damage); + int damage = FormulaHelper.CalculateFallDamage(entityBehaviour.Entity,GameManager.Instance.AcrobatMotor.fallingDamageThreshold,fallDistance); + + if (damage > 0) + RemoveHealth(damage); } } }