diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index dcf379859..2941836d7 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -42,6 +42,7 @@ DedicatedActor::DedicatedActor() hasPositionData = false; hasStatsDynamicData = false; + hasReceivedInitialEquipment = false; hasChangedCell = true; attack.pressed = false; @@ -195,14 +196,16 @@ void DedicatedActor::setEquipment() if (packetRefId.empty() || equal) continue; - if (hasItem(packetRefId, packetCharge)) - equipItem(packetRefId, packetCharge); - else + if (!hasItem(packetRefId, packetCharge)) { ptr.getClass().getContainerStore(ptr).add(packetRefId, count, ptr); - equipItem(packetRefId, packetCharge); } + + // Equip items silently if this is the first time equipment is being set for this character + equipItem(packetRefId, packetCharge, !hasReceivedInitialEquipment); } + + hasReceivedInitialEquipment = true; } void DedicatedActor::setAi() @@ -344,14 +347,14 @@ bool DedicatedActor::hasItem(std::string itemId, int charge) return false; } -void DedicatedActor::equipItem(std::string itemId, int charge) +void DedicatedActor::equipItem(std::string itemId, int charge, bool noSound) { for (const auto &itemPtr : ptr.getClass().getInventoryStore(ptr)) { if (::Misc::StringUtils::ciEqual(itemPtr.getCellRef().getRefId(), itemId) && itemPtr.getCellRef().getCharge() == charge) { std::shared_ptr action = itemPtr.getClass().use(itemPtr); - action->execute(ptr); + action->execute(ptr, noSound); break; } } diff --git a/apps/openmw/mwmp/DedicatedActor.hpp b/apps/openmw/mwmp/DedicatedActor.hpp index 8824b4347..a3420ed7b 100644 --- a/apps/openmw/mwmp/DedicatedActor.hpp +++ b/apps/openmw/mwmp/DedicatedActor.hpp @@ -27,7 +27,7 @@ namespace mwmp void playSound(); bool hasItem(std::string itemId, int charge); - void equipItem(std::string itemId, int charge); + void equipItem(std::string itemId, int charge, bool noSound = false); MWWorld::Ptr getPtr(); void setPtr(const MWWorld::Ptr& newPtr); @@ -35,6 +35,7 @@ namespace mwmp private: MWWorld::Ptr ptr; + bool hasReceivedInitialEquipment; bool hasChangedCell; }; } diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index 4f10a27f6..3901bedc9 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -63,6 +63,7 @@ DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid) npc.mId = ""; previousRace = npc.mRace; + hasReceivedInitialEquipment = false; hasFinishedInitialTeleportation = false; } @@ -306,12 +307,14 @@ void DedicatedPlayer::setEquipment() // Go no further if the player is disguised as a creature if (!ptr.getClass().hasInventoryStore(ptr)) return; + bool equippedSomething = false; + MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore(ptr); for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot) { MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); - const string &packetItemId = equipmentItems[slot].refId; + const string &packetRefId = equipmentItems[slot].refId; std::string ptrItemId = ""; bool equal = false; @@ -319,7 +322,7 @@ void DedicatedPlayer::setEquipment() { ptrItemId = it->getCellRef().getRefId(); - if (!Misc::StringUtils::ciEqual(ptrItemId, packetItemId)) // if other item is now equipped + if (!Misc::StringUtils::ciEqual(ptrItemId, packetRefId)) // if other item is now equipped { MWWorld::ContainerStore &store = ptr.getClass().getContainerStore(ptr); @@ -327,7 +330,7 @@ void DedicatedPlayer::setEquipment() // have just run out but still need to be kept briefly so they can be used in attacks about to be released bool shouldRemove = true; - if (attack.type == mwmp::Attack::RANGED && packetItemId.empty() && !attack.pressed) + if (attack.type == mwmp::Attack::RANGED && packetRefId.empty() && !attack.pressed) { if (slot == MWWorld::InventoryStore::Slot_CarriedRight && Misc::StringUtils::ciEqual(ptrItemId, attack.rangedWeaponId)) shouldRemove = false; @@ -336,28 +339,27 @@ void DedicatedPlayer::setEquipment() } if (shouldRemove) + { store.remove(ptrItemId, store.count(ptrItemId), ptr); + } } else equal = true; } - if (packetItemId.empty() || equal) + if (packetRefId.empty() || equal) continue; const int count = equipmentItems[slot].count; - ptr.getClass().getContainerStore(ptr).add(packetItemId, count, ptr); - - for (const auto &itemPtr : invStore) - { - if (::Misc::StringUtils::ciEqual(itemPtr.getCellRef().getRefId(), packetItemId)) // equip item - { - std::shared_ptr action = itemPtr.getClass().use(itemPtr); - action->execute(ptr); - break; - } - } + ptr.getClass().getContainerStore(ptr).add(packetRefId, count, ptr); + // Equip items silently if this is the first time equipment is being set for this character + equipItem(packetRefId, !hasReceivedInitialEquipment); + equippedSomething = true; } + + // Only track the initial equipment as received if at least one item has been equipped + if (equippedSomething) + hasReceivedInitialEquipment = true; } void DedicatedPlayer::setCell() @@ -469,6 +471,19 @@ void DedicatedPlayer::playSpeech() winMgr->messageBox(MWBase::Environment::get().getDialogueManager()->getVoiceCaption(sound), MWGui::ShowInDialogueMode_Never); } +void DedicatedPlayer::equipItem(std::string itemId, bool noSound) +{ + for (const auto& itemPtr : ptr.getClass().getInventoryStore(ptr)) + { + if (::Misc::StringUtils::ciEqual(itemPtr.getCellRef().getRefId(), itemId)) + { + std::shared_ptr action = itemPtr.getClass().use(itemPtr); + action->execute(ptr, noSound); + break; + } + } +} + void DedicatedPlayer::createReference(const std::string& recId) { MWBase::World *world = MWBase::Environment::get().getWorld(); diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index 4b6b2b715..0abf26090 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -48,6 +48,8 @@ namespace mwmp void playAnimation(); void playSpeech(); + void equipItem(std::string itemId, bool noSound = false); + void createReference(const std::string& recId); void deleteReference(); @@ -75,6 +77,7 @@ namespace mwmp std::string creatureRecordId; + bool hasReceivedInitialEquipment; bool hasFinishedInitialTeleportation; bool isLevitationPurged; };