Skip to content

Commit

Permalink
feat: pay and clear crime fines on death
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 24, 2022
1 parent a02b88f commit e6f47dd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Code/client/Games/Skyrim/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct Actor : TESObjectREFR
virtual void sub_B8();
virtual void sub_B9();
virtual void sub_BA();
virtual void sub_BB();
virtual void PayFine(TESFaction* apFaction, bool aGoToJail, bool aRemoveStolenItems);
virtual void sub_BC();
virtual void sub_BD();
virtual void sub_BE();
Expand Down
22 changes: 21 additions & 1 deletion Code/client/Games/Skyrim/PlayerCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void PlayerCharacter::AddSkillExperience(int32_t aSkill, float aExperience) noex
spdlog::debug("Added {} experience to skill {}", deltaExperience, aSkill);
}

void PlayerCharacter::RespawnPlayer() noexcept
NiPoint3 PlayerCharacter::RespawnPlayer() noexcept
{
// Make bleedout state recoverable
SetNoBleedoutRecovery(false);
Expand Down Expand Up @@ -91,6 +91,26 @@ void PlayerCharacter::RespawnPlayer() noexcept

// Make bleedout state unrecoverable again for when the player goes down the next time
SetNoBleedoutRecovery(true);

return pos;
}

void PlayerCharacter::PayCrimeGoldToAllFactions() noexcept
{
// Yes, yes, this isn't great, but there's no "pay fines everywhere" function
TiltedPhoques::Vector<uint32_t> crimeFactionIds{ 0x28170, 0x267E3, 0x29DB0, 0x2816D, 0x2816e, 0x2816C, 0x2816B, 0x267EA, 0x2816F, 0x4018279 };

for (uint32_t crimeFactionId : crimeFactionIds)
{
TESFaction* pCrimeFaction = Cast<TESFaction>(TESForm::GetById(crimeFactionId));
if (!pCrimeFaction)
{
spdlog::error("This isn't a crime faction! {:X}", crimeFactionId);
continue;
}

PayFine(pCrimeFaction, false, false);
}
}

char TP_MAKE_THISCALL(HookPickUpObject, PlayerCharacter, TESObjectREFR* apObject, int32_t aCount, bool aUnk1, bool aUnk2)
Expand Down
4 changes: 3 additions & 1 deletion Code/client/Games/Skyrim/PlayerCharacter.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ struct PlayerCharacter : Actor
return (*pSkills)->skills[aSkill].xp;
}

void RespawnPlayer() noexcept;
NiPoint3 RespawnPlayer() noexcept;

void PayCrimeGoldToAllFactions() noexcept;

struct Objective
{
Expand Down
7 changes: 5 additions & 2 deletions Code/client/Services/Generic/PlayerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ PlayerService::PlayerService(World& aWorld, entt::dispatcher& aDispatcher, Trans

bool knockdownStart = false;
double knockdownTimer = 0.0;
NiPoint3 newPosition{};

bool godmodeStart = false;
double godmodeTimer = 0.0;
Expand Down Expand Up @@ -151,13 +152,15 @@ void PlayerService::RunRespawnUpdates(const double acDeltaTime) noexcept
// just by setting its health back to max. Therefore, put it to 0.
if (pPlayer->GetActorValue(ActorValueInfo::kHealth) > 0.f)
pPlayer->ForceActorValue(ActorValueOwner::ForceMode::DAMAGE, ActorValueInfo::kHealth, 0);

pPlayer->PayCrimeGoldToAllFactions();
}

m_respawnTimer -= acDeltaTime;

if (m_respawnTimer <= 0.0)
{
pPlayer->RespawnPlayer();
newPosition = pPlayer->RespawnPlayer();

knockdownTimer = 1.0;
knockdownStart = true;
Expand All @@ -176,7 +179,7 @@ void PlayerService::RunPostDeathUpdates(const double acDeltaTime) noexcept
if (knockdownStart)
{
knockdownTimer -= acDeltaTime;
if (knockdownTimer <= 0.0)
if (PlayerCharacter::Get()->position == newPosition)
{
PlayerCharacter::SetGodMode(true);
godmodeStart = true;
Expand Down

0 comments on commit e6f47dd

Please sign in to comment.