2828#include < Games/Overrides.h>
2929#include < Games/References.h>
3030#include < AI/AIProcess.h>
31+ #include < EquipManager.h>
3132
3233PlayerService::PlayerService (World& aWorld, entt::dispatcher& aDispatcher, TransportService& aTransport) noexcept
3334 : m_world(aWorld), m_dispatcher(aDispatcher), m_transport(aTransport)
@@ -45,17 +46,6 @@ PlayerService::PlayerService(World& aWorld, entt::dispatcher& aDispatcher, Trans
4546 m_partyLeftConnection = aDispatcher.sink <PartyLeftEvent>().connect <&PlayerService::OnPartyLeftEvent>(this );
4647}
4748
48- namespace
49- {
50- bool isDeathSystemEnabled = true ;
51-
52- bool knockdownStart = false ;
53- double knockdownTimer = 0.0 ;
54-
55- bool godmodeStart = false ;
56- double godmodeTimer = 0.0 ;
57- }
58-
5949void PlayerService::OnUpdate (const UpdateEvent& acEvent) noexcept
6050{
6151 RunRespawnUpdates (acEvent.Delta );
@@ -227,14 +217,20 @@ void PlayerService::OnPartyLeftEvent(const PartyLeftEvent& acEvent) noexcept
227217// TODO: ft (verify)
228218void PlayerService::RunRespawnUpdates (const double acDeltaTime) noexcept
229219{
230- if (!isDeathSystemEnabled )
220+ if (!m_isDeathSystemEnabled )
231221 return ;
232222
233223 static bool s_startTimer = false ;
234224
235225 PlayerCharacter* pPlayer = PlayerCharacter::Get ();
236226 if (!pPlayer->actorState .IsBleedingOut ())
237227 {
228+ #if TP_SKYRIM64
229+ m_cachedMainSpellId = pPlayer->magicItems [0 ] ? pPlayer->magicItems [0 ]->formID : 0 ;
230+ m_cachedSecondarySpellId = pPlayer->magicItems [1 ] ? pPlayer->magicItems [1 ]->formID : 0 ;
231+ m_cachedPowerId = pPlayer->equippedShout ? pPlayer->equippedShout ->formID : 0 ;
232+ #endif
233+
238234 s_startTimer = false ;
239235 return ;
240236 }
@@ -259,51 +255,64 @@ void PlayerService::RunRespawnUpdates(const double acDeltaTime) noexcept
259255 {
260256 pPlayer->RespawnPlayer ();
261257
262- knockdownTimer = 1.5 ;
263- knockdownStart = true ;
258+ m_knockdownTimer = 1.5 ;
259+ m_knockdownStart = true ;
264260
265261 m_transport.Send (PlayerRespawnRequest ());
266262
267263 s_startTimer = false ;
264+
265+ #if TP_SKYRIM64
266+ auto * pEquipManager = EquipManager::Get ();
267+ TESForm* pSpell = TESForm::GetById (m_cachedMainSpellId);
268+ if (pSpell)
269+ pEquipManager->EquipSpell (pPlayer, pSpell, 0 );
270+ pSpell = TESForm::GetById (m_cachedSecondarySpellId);
271+ if (pSpell)
272+ pEquipManager->EquipSpell (pPlayer, pSpell, 1 );
273+ pSpell = TESForm::GetById (m_cachedPowerId);
274+ if (pSpell)
275+ pEquipManager->EquipShout (pPlayer, pSpell);
276+ #endif
268277 }
269278}
270279
271280// TODO: ft (verify)
272281// Doesn't seem to respawn quite yet
273282void PlayerService::RunPostDeathUpdates (const double acDeltaTime) noexcept
274283{
275- if (!isDeathSystemEnabled )
284+ if (!m_isDeathSystemEnabled )
276285 return ;
277286
278287 // If a player dies in ragdoll, it gets stuck.
279288 // This code ragdolls the player again upon respawning.
280289 // It also makes the player invincible for 5 seconds.
281- if (knockdownStart )
290+ if (m_knockdownStart )
282291 {
283- knockdownTimer -= acDeltaTime;
284- if (knockdownTimer <= 0.0 )
292+ m_knockdownTimer -= acDeltaTime;
293+ if (m_knockdownTimer <= 0.0 )
285294 {
286295 PlayerCharacter::SetGodMode (true );
287- godmodeStart = true ;
288- godmodeTimer = 10.0 ;
296+ m_godmodeStart = true ;
297+ m_godmodeTimer = 10.0 ;
289298
290299 PlayerCharacter* pPlayer = PlayerCharacter::Get ();
291300 pPlayer->currentProcess ->KnockExplosion (pPlayer, &pPlayer->position , 0 .f );
292301
293302 FadeOutGame (false , true , 0 .5f , true , 2 .f );
294303
295- knockdownStart = false ;
304+ m_knockdownStart = false ;
296305 }
297306 }
298307
299- if (godmodeStart )
308+ if (m_godmodeStart )
300309 {
301- godmodeTimer -= acDeltaTime;
302- if (godmodeTimer <= 0.0 )
310+ m_godmodeTimer -= acDeltaTime;
311+ if (m_godmodeTimer <= 0.0 )
303312 {
304313 PlayerCharacter::SetGodMode (false );
305314
306- godmodeStart = false ;
315+ m_godmodeStart = false ;
307316 }
308317 }
309318}
@@ -343,9 +352,9 @@ void PlayerService::RunLevelUpdates() const noexcept
343352 }
344353}
345354
346- void PlayerService::ToggleDeathSystem (bool aSet) const noexcept
355+ void PlayerService::ToggleDeathSystem (bool aSet) noexcept
347356{
348- isDeathSystemEnabled = aSet;
357+ m_isDeathSystemEnabled = aSet;
349358
350359 PlayerCharacter::Get ()->SetPlayerRespawnMode (aSet);
351360}
0 commit comments