From 6c4bb8c423b64278d445c375313b9632ba75f4a2 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 27 Jan 2018 19:09:55 +0200 Subject: [PATCH] [Client] Move resurrection code for local player to LocalPlayer --- apps/openmw/mwmp/LocalPlayer.cpp | 39 +++++++++++++++++++ apps/openmw/mwmp/LocalPlayer.hpp | 2 + .../player/ProcessorPlayerResurrect.hpp | 38 +----------------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 02de21c5a..0bfb30675 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -770,6 +770,45 @@ void LocalPlayer::removeSpells() } } +void LocalPlayer::resurrect() +{ + creatureStats.mDead = false; + + MWWorld::Ptr ptrPlayer = getPlayerPtr(); + + if (resurrectType == mwmp::RESURRECT_TYPE::IMPERIAL_SHRINE) + MWBase::Environment::get().getWorld()->teleportToClosestMarker(ptrPlayer, "divinemarker"); + else if (resurrectType == mwmp::RESURRECT_TYPE::TRIBUNAL_TEMPLE) + MWBase::Environment::get().getWorld()->teleportToClosestMarker(ptrPlayer, "templemarker"); + + ptrPlayer.getClass().getCreatureStats(ptrPlayer).resurrect(); + + // The player could have died from a hand-to-hand attack, so reset their fatigue + // as well + if (creatureStats.mDynamic[2].mMod < 1) + creatureStats.mDynamic[2].mMod = 1; + + creatureStats.mDynamic[2].mCurrent = creatureStats.mDynamic[2].mMod; + MWMechanics::DynamicStat fatigue; + fatigue.readState(creatureStats.mDynamic[2]); + ptrPlayer.getClass().getCreatureStats(ptrPlayer).setFatigue(fatigue); + + // If this player had a weapon or spell readied when dying, they will still have it + // readied but be unable to use it unless we clear it here + ptrPlayer.getClass().getNpcStats(ptrPlayer).setDrawState(MWMechanics::DrawState_Nothing); + + // Record that the player has died since the last attempt was made to arrest them, + // used to make guards lenient enough to attempt an arrest again + diedSinceArrestAttempt = true; + + LOG_APPEND(Log::LOG_INFO, "- diedSinceArrestAttempt is now true"); + + Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_RESURRECT)->setPlayer(this); + Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_RESURRECT)->Send(); + + updateStatsDynamic(true); +} + void LocalPlayer::closeInventoryWindows() { if (MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_Container) || diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 41c170c8d..6f1dc9e07 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -47,6 +47,8 @@ namespace mwmp void removeItems(); void removeSpells(); + void resurrect(); + void closeInventoryWindows(); void setDynamicStats(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp index c6e6ab5b3..af14a3cf1 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp @@ -27,43 +27,7 @@ namespace mwmp { LOG_APPEND(Log::LOG_INFO, "- Packet was about me with resurrectType of %i", player->resurrectType); - player->creatureStats.mDead = false; - - MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - - if (player->resurrectType == mwmp::RESURRECT_TYPE::IMPERIAL_SHRINE) - MWBase::Environment::get().getWorld()->teleportToClosestMarker(playerPtr, "divinemarker"); - else if (player->resurrectType == mwmp::RESURRECT_TYPE::TRIBUNAL_TEMPLE) - MWBase::Environment::get().getWorld()->teleportToClosestMarker(playerPtr, "templemarker"); - - playerPtr.getClass().getCreatureStats(playerPtr).resurrect(); - - // The player could have died from a hand-to-hand attack, so reset their fatigue - // as well - if (player->creatureStats.mDynamic[2].mMod < 1) - player->creatureStats.mDynamic[2].mMod = 1; - - player->creatureStats.mDynamic[2].mCurrent = player->creatureStats.mDynamic[2].mMod; - MWMechanics::DynamicStat fatigue; - fatigue.readState(player->creatureStats.mDynamic[2]); - playerPtr.getClass().getCreatureStats(playerPtr).setFatigue(fatigue); - - // If this player had a weapon or spell readied when dying, they will still have it - // readied but be unable to use it unless we clear it here - playerPtr.getClass().getNpcStats(playerPtr).setDrawState(MWMechanics::DrawState_Nothing); - - // Record that the player has died since the last attempt was made to arrest them, - // used to make guards lenient enough to attempt an arrest again - player->diedSinceArrestAttempt = true; - - LOG_APPEND(Log::LOG_INFO, "- diedSinceArrestAttempt is now true"); - - packet.setPlayer(player); - packet.Send(serverAddr); - - static_cast(player)->updateStatsDynamic(true); - Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player); - Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(serverAddr); + static_cast(player)->resurrect(); } else if (player != 0) {