From 73dea494c4b628ea5d8154a49a97908167563507 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 9 Apr 2018 19:21:19 +0300 Subject: [PATCH] [General] Allow changes from PlayerBaseInfo without player stat reset --- apps/openmw/mwmp/LocalPlayer.cpp | 41 +++++++++++++++---- apps/openmw/mwmp/LocalPlayer.hpp | 2 +- .../player/ProcessorPlayerBaseInfo.hpp | 4 +- components/openmw-mp/Base/BasePlayer.hpp | 2 + 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 15ffd0707..214821eda 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -440,13 +440,6 @@ void LocalPlayer::updateCell(bool forceUpdate) } } -void LocalPlayer::updateChar() -{ - MWBase::Environment::get().getMechanicsManager()->setPlayerRace(npc.mRace, npc.isMale(), npc.mHead, npc.mHair); - MWBase::Environment::get().getMechanicsManager()->setPlayerBirthsign(birthsign); - MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar(); -} - void LocalPlayer::updateEquipment(bool forceUpdate) { MWWorld::Ptr ptrPlayer = getPlayerPtr(); @@ -838,6 +831,40 @@ void LocalPlayer::closeInventoryWindows() MWBase::Environment::get().getWindowManager()->finishDragDrop(); } +void LocalPlayer::setCharacter() +{ + MWBase::World *world = MWBase::Environment::get().getWorld(); + + // Ignore invalid races + if (world->getStore().get().search(npc.mRace) != 0) + { + MWBase::Environment::get().getWorld()->getPlayer().setBirthSign(birthsign); + + if (resetStats) + MWBase::Environment::get().getMechanicsManager()->setPlayerRace(npc.mRace, npc.isMale(), npc.mHead, npc.mHair); + else + { + ESM::NPC player = *world->getPlayerPtr().get()->mBase; + + player.mRace = npc.mRace; + player.mHead = npc.mHead; + player.mHair = npc.mHair; + player.setIsMale(npc.isMale()); + world->createRecord(player); + + MWBase::Environment::get().getMechanicsManager()->playerLoaded(); + } + + setEquipment(); + + MWBase::Environment::get().getWindowManager()->getInventoryWindow()->rebuildAvatar(); + } + else + { + LOG_APPEND(Log::LOG_INFO, "- Character update was ignored due to invalid race %s", npc.mRace.c_str()); + } +} + void LocalPlayer::setDynamicStats() { MWBase::World *world = MWBase::Environment::get().getWorld(); diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index bd475977d..44baea429 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -33,7 +33,6 @@ namespace mwmp void updateReputation(bool forceUpdate = false); void updatePosition(bool forceUpdate = false); void updateCell(bool forceUpdate = false); - void updateChar(); void updateEquipment(bool forceUpdate = false); void updateInventory(bool forceUpdate = false); void updateAttack(); @@ -52,6 +51,7 @@ namespace mwmp void closeInventoryWindows(); + void setCharacter(); void setDynamicStats(); void setAttributes(); void setSkills(); diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp index 026a1ca1e..eab9e8182 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerBaseInfo.hpp @@ -32,8 +32,8 @@ namespace mwmp } else { - LOG_APPEND(Log::LOG_INFO, "- Updating LocalPlayer"); - static_cast(player)->updateChar(); + LOG_APPEND(Log::LOG_INFO, "- Setting character for LocalPlayer"); + static_cast(player)->setCharacter(); } } else diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 0544f3fb1..9186a383c 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -225,6 +225,7 @@ namespace mwmp spellbookChanges.action = 0; spellbookChanges.count = 0; displayCreatureName = false; + resetStats = false; } BasePlayer() @@ -285,6 +286,7 @@ namespace mwmp std::string sound; Animation animation; + bool resetStats; float scale; bool isWerewolf;