From bce4fb1492261fd35977ceb3afd19bf35c08c8a1 Mon Sep 17 00:00:00 2001 From: otsffs <141402668+otsffs@users.noreply.github.com> Date: Sat, 31 Aug 2024 17:26:36 +0800 Subject: [PATCH] Enemies regain health based on difficulty after killing a player --- Code/client/Games/Skyrim/Actor.cpp | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Code/client/Games/Skyrim/Actor.cpp b/Code/client/Games/Skyrim/Actor.cpp index ad6207a01..ce8ab344c 100644 --- a/Code/client/Games/Skyrim/Actor.cpp +++ b/Code/client/Games/Skyrim/Actor.cpp @@ -642,6 +642,39 @@ bool TP_MAKE_THISCALL(HookDamageActor, Actor, float aDamage, Actor* apHitter, bo } World::Get().GetRunner().Trigger(HealthChangeEvent(apThis->formID, -realDamage)); + + if(apHitter) + { + // Heal the attacker if they are not a player and they kill the local player + const auto* pExHitter = apHitter->GetExtension(); + if(!pExHitter->IsPlayer() && wouldKill) + { + spdlog::debug("Heals enemies who killed the player"); + // Get max health + float maxHealth = apHitter->GetActorPermanentValue(ActorValueInfo::kHealth); + // Difficulty range is 0-5 + uint32_t difficulty = World::Get().GetServerSettings().Difficulty; + float percentage = difficulty*0.15f; + // Restore 20% of max health to the attacker + float recoveryHealth = maxHealth*0.2f; + // Legendary difficulty + if(difficulty == 5) + recoveryHealth = maxHealth; + // Remaining health of the attacker + float remainingHealth = apHitter->GetActorValue(ActorValueInfo::kHealth); + if(remainingHealth > 0) + { + // Restore health lost based on a proportion + float lostHealth = (maxHealth-remainingHealth)*percentage; + // Final restored value + recoveryHealth = lostHealth > recoveryHealth ? lostHealth : recoveryHealth; + World::Get().GetRunner().Trigger(HealthChangeEvent(apHitter->formID, recoveryHealth)); + // Set the local value + float newHealth = apHitter->GetActorValue(ActorValueInfo::kHealth) + recoveryHealth; + apHitter->ForceActorValue(ActorValueOwner::ForceMode::DAMAGE, ActorValueInfo::kHealth, newHealth); + } + } + } return TiltedPhoques::ThisCall(RealDamageActor, apThis, aDamage, apHitter, aKillMove); } else if (pExHittee->IsRemotePlayer())