Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions Assets/Scripts/Game/EnemyMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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?
Expand All @@ -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());
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions Assets/Scripts/Game/Formulas/FormulaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,19 @@ public static VampireClans GetVampireClan(int regionIndex)
return VampireClans.Lyrezi;
}

public static int CalculateFallDamage(DaggerfallEntity entity, float threshold, float distance)
{
Func<DaggerfallEntity, float, float, int> 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
Expand Down
12 changes: 6 additions & 6 deletions Assets/Scripts/Game/PlayerHealth.cs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -12,6 +12,7 @@
using UnityEngine;
using System.Collections;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Formulas;

namespace DaggerfallWorkshop.Game
{
Expand Down Expand Up @@ -48,13 +49,12 @@ void RemoveHealth(int amount)
/// </summary>
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);
}
}
}
Expand Down