From 32c3db4c4bf690de4e6a4794ebab6140c80a9055 Mon Sep 17 00:00:00 2001 From: RedRoryOTheGlen Date: Wed, 1 Jul 2026 17:14:41 +0800 Subject: [PATCH 1/2] Changed fall damage handling to work off of a formula that can be overridden by mods. --- Assets/Scripts/Game/Formulas/FormulaHelper.cs | 14 ++++++++++++++ Assets/Scripts/Game/PlayerHealth.cs | 12 ++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Game/Formulas/FormulaHelper.cs b/Assets/Scripts/Game/Formulas/FormulaHelper.cs index cfac198788..3e1e3593d1 100644 --- a/Assets/Scripts/Game/Formulas/FormulaHelper.cs +++ b/Assets/Scripts/Game/Formulas/FormulaHelper.cs @@ -427,6 +427,20 @@ public static VampireClans GetVampireClan(int regionIndex) return VampireClans.Lyrezi; } + public static int CalculateFallDamage(float distance) + { + Func del; + if (TryGetOverride("CalculateFallDamage", out del)) + return del(distance); + + float threshold = GameManager.Instance.AcrobatMotor.fallingDamageThreshold; + 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..7f09de2278 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(fallDistance); + + if (damage > 0) + RemoveHealth(damage); } } } From 878fb8b69547fc847a158d1bc3aa4ec9f1e97849 Mon Sep 17 00:00:00 2001 From: RedRoryOTheGlen Date: Thu, 2 Jul 2026 08:50:13 +0800 Subject: [PATCH 2/2] Enemies can now also have their falling damage threshold modified and use the same formula as players for calculating fall damage. --- Assets/Scripts/Game/EnemyMotor.cs | 28 ++++++++++--------- Assets/Scripts/Game/Formulas/FormulaHelper.cs | 7 ++--- Assets/Scripts/Game/PlayerHealth.cs | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) 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 3e1e3593d1..1cf13c96b0 100644 --- a/Assets/Scripts/Game/Formulas/FormulaHelper.cs +++ b/Assets/Scripts/Game/Formulas/FormulaHelper.cs @@ -427,13 +427,12 @@ public static VampireClans GetVampireClan(int regionIndex) return VampireClans.Lyrezi; } - public static int CalculateFallDamage(float distance) + public static int CalculateFallDamage(DaggerfallEntity entity, float threshold, float distance) { - Func del; + Func del; if (TryGetOverride("CalculateFallDamage", out del)) - return del(distance); + return del(entity, threshold, distance); - float threshold = GameManager.Instance.AcrobatMotor.fallingDamageThreshold; float HPPerMetre = 5; int damage = (int)(HPPerMetre * (distance - threshold)); diff --git a/Assets/Scripts/Game/PlayerHealth.cs b/Assets/Scripts/Game/PlayerHealth.cs index 7f09de2278..f227e8327b 100644 --- a/Assets/Scripts/Game/PlayerHealth.cs +++ b/Assets/Scripts/Game/PlayerHealth.cs @@ -51,7 +51,7 @@ void ApplyPlayerFallDamage(float fallDistance) { if (entityBehaviour) { - int damage = FormulaHelper.CalculateFallDamage(fallDistance); + int damage = FormulaHelper.CalculateFallDamage(entityBehaviour.Entity,GameManager.Instance.AcrobatMotor.fallingDamageThreshold,fallDistance); if (damage > 0) RemoveHealth(damage);