Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enemies regain health based on difficulty after killing a player #707

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
33 changes: 33 additions & 0 deletions Code/client/Games/Skyrim/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Loading