From 68ee64902dfbcc600643b22ff96b1507c5900ff5 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 13 Apr 2018 16:16:43 +0300 Subject: [PATCH] [Client] Track & use previous race & creatureRefId for DedicatedPlayers --- apps/openmw/mwmp/DedicatedPlayer.cpp | 88 +++++++++++++++------------- apps/openmw/mwmp/DedicatedPlayer.hpp | 4 +- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 5b26e63ab..10c3f8770 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -60,6 +60,7 @@ DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid) MWBase::World *world = MWBase::Environment::get().getWorld(); npc = *world->getPlayerPtr().get()->mBase; npc.mId = "Dedicated Player"; + previousRace = npc.mRace; } DedicatedPlayer::~DedicatedPlayer() { @@ -142,8 +143,6 @@ void DedicatedPlayer::move(float dt) void DedicatedPlayer::setBaseInfo() { - static std::string previousRace; - // Use the previous race if the new one doesn't exist if (!RecordHelper::doesRaceExist(npc.mRace)) npc.mRace = previousRace; @@ -175,56 +174,61 @@ void DedicatedPlayer::setShapeshift() if (reference) isNpc = ptr.getTypeName() == typeid(ESM::NPC).name(); - if (!creatureRefId.empty() && RecordHelper::doesCreatureExist(creatureRefId)) + if (creatureRefId != previousCreatureRefId) { - if (isNpc) + if (!creatureRefId.empty() && RecordHelper::doesCreatureExist(creatureRefId)) { - deleteReference(); - } + if (isNpc) + { + deleteReference(); + } - const ESM::Creature *tmpCreature = world->getStore().get().search(creatureRefId); - creature = *tmpCreature; - creature.mScript = ""; - if (!displayCreatureName) - creature.mName = npc.mName; - LOG_APPEND(Log::LOG_INFO, "- %s is disguised as %s", npc.mName.c_str(), creatureRefId.c_str()); + const ESM::Creature *tmpCreature = world->getStore().get().search(creatureRefId); + creature = *tmpCreature; + creature.mScript = ""; + if (!displayCreatureName) + creature.mName = npc.mName; + LOG_APPEND(Log::LOG_INFO, "- %s is disguised as %s", npc.mName.c_str(), creatureRefId.c_str()); - // Is this our first time creating a creature record id for this player? If so, keep it around - // and reuse it - if (creatureRecordId.empty()) - { - creature.mId = "Dedicated Player"; - creature.mId = creatureRecordId = RecordHelper::createCreatureRecord(creature); - LOG_APPEND(Log::LOG_INFO, "- Creating new creature record %s", creatureRecordId.c_str()); - } - else - { - creature.mId = creatureRecordId; - RecordHelper::updateCreatureRecord(creature); - } + // Is this our first time creating a creature record id for this player? If so, keep it around + // and reuse it + if (creatureRecordId.empty()) + { + creature.mId = "Dedicated Player"; + creature.mId = creatureRecordId = RecordHelper::createCreatureRecord(creature); + LOG_APPEND(Log::LOG_INFO, "- Creating new creature record %s", creatureRecordId.c_str()); + } + else + { + creature.mId = creatureRecordId; + RecordHelper::updateCreatureRecord(creature); + } - if (!reference) - { - LOG_APPEND(Log::LOG_INFO, "- Creating reference for %s", creature.mId.c_str()); - createReference(creature.mId); + if (!reference) + { + LOG_APPEND(Log::LOG_INFO, "- Creating reference for %s", creature.mId.c_str()); + createReference(creature.mId); + } + else + { + reloadPtr(); + } } - else + // This player was already a creature, but the new creature refId was empty or + // invalid, so we'll turn this player into their NPC self again as a result + else if (!isNpc) { + if (reference) + { + deleteReference(); + } + + RecordHelper::updateNpcRecord(npc); + createReference(npc.mId); reloadPtr(); } - } - // This player was already a creature, but the new creature refId was empty or - // invalid, so we'll turn this player into their NPC self again as a result - else if (!isNpc) - { - if (reference) - { - deleteReference(); - } - RecordHelper::updateNpcRecord(npc); - createReference(npc.mId); - reloadPtr(); + previousCreatureRefId = creatureRefId; } if (ptr.getTypeName() == typeid(ESM::NPC).name()) diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index aefa08b76..f77585477 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -71,7 +71,9 @@ namespace mwmp ESM::CustomMarker marker; bool markerEnabled; - std::string npcRecordId; + std::string previousRace; + std::string previousCreatureRefId; + std::string creatureRecordId; }; }