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 1/2] 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()) From 574d07740b6024f8a764dbd3f2dad390b78bd363 Mon Sep 17 00:00:00 2001 From: otsffs <141402668+otsffs@users.noreply.github.com> Date: Sat, 31 Aug 2024 18:34:24 +0800 Subject: [PATCH 2/2] Formatted code --- Code/client/Games/Skyrim/Actor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/client/Games/Skyrim/Actor.cpp b/Code/client/Games/Skyrim/Actor.cpp index ce8ab344c..30301b86d 100644 --- a/Code/client/Games/Skyrim/Actor.cpp +++ b/Code/client/Games/Skyrim/Actor.cpp @@ -654,9 +654,9 @@ bool TP_MAKE_THISCALL(HookDamageActor, Actor, float aDamage, Actor* apHitter, bo float maxHealth = apHitter->GetActorPermanentValue(ActorValueInfo::kHealth); // Difficulty range is 0-5 uint32_t difficulty = World::Get().GetServerSettings().Difficulty; - float percentage = difficulty*0.15f; + float percentage = difficulty * 0.15f; // Restore 20% of max health to the attacker - float recoveryHealth = maxHealth*0.2f; + float recoveryHealth = maxHealth * 0.2f; // Legendary difficulty if(difficulty == 5) recoveryHealth = maxHealth; @@ -665,7 +665,7 @@ bool TP_MAKE_THISCALL(HookDamageActor, Actor, float aDamage, Actor* apHitter, bo if(remainingHealth > 0) { // Restore health lost based on a proportion - float lostHealth = (maxHealth-remainingHealth)*percentage; + float lostHealth = (maxHealth - remainingHealth) * percentage; // Final restored value recoveryHealth = lostHealth > recoveryHealth ? lostHealth : recoveryHealth; World::Get().GetRunner().Trigger(HealthChangeEvent(apHitter->formID, recoveryHealth));