From 958b220835e53dca744f25a8e441d08349df5fd7 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 1 Jul 2018 00:43:29 +0300 Subject: [PATCH] [General] Send summon duration to server in ObjectSpawn packets --- apps/openmw-mp/Script/Functions/Objects.cpp | 10 +++++++++ apps/openmw-mp/Script/Functions/Objects.hpp | 21 +++++++++++++++++++ apps/openmw/mwmechanics/activespells.cpp | 20 ++++++++++++++++++ apps/openmw/mwmechanics/activespells.hpp | 10 +++++++++ apps/openmw/mwmechanics/summoning.cpp | 6 +++++- apps/openmw/mwmp/ObjectList.cpp | 4 +++- apps/openmw/mwmp/ObjectList.hpp | 2 +- components/openmw-mp/Base/BaseObject.hpp | 1 + .../Packets/Object/PacketObjectSpawn.cpp | 1 + 9 files changed, 72 insertions(+), 3 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Objects.cpp b/apps/openmw-mp/Script/Functions/Objects.cpp index 00f612bcb..8124f1f28 100644 --- a/apps/openmw-mp/Script/Functions/Objects.cpp +++ b/apps/openmw-mp/Script/Functions/Objects.cpp @@ -113,6 +113,11 @@ int ObjectFunctions::GetObjectLockLevel(unsigned int i) noexcept return readObjectList->baseObjects.at(i).lockLevel; } +double ObjectFunctions::GetObjectSummonDuration(unsigned int i) noexcept +{ + return readObjectList->baseObjects.at(i).summonDuration; +} + double ObjectFunctions::GetObjectPosX(unsigned int i) noexcept { return readObjectList->baseObjects.at(i).position.pos[0]; @@ -248,6 +253,11 @@ void ObjectFunctions::SetObjectLockLevel(int lockLevel) noexcept tempObject.lockLevel = lockLevel; } +void ObjectFunctions::SetObjectSummonDuration(float summonDuration) noexcept +{ + tempObject.summonDuration = summonDuration; +} + void ObjectFunctions::SetObjectDisarmState(bool disarmState) noexcept { tempObject.isDisarmed = disarmState; diff --git a/apps/openmw-mp/Script/Functions/Objects.hpp b/apps/openmw-mp/Script/Functions/Objects.hpp index ded7d5004..d844fcce8 100644 --- a/apps/openmw-mp/Script/Functions/Objects.hpp +++ b/apps/openmw-mp/Script/Functions/Objects.hpp @@ -24,6 +24,7 @@ {"GetObjectState", ObjectFunctions::GetObjectState},\ {"GetObjectDoorState", ObjectFunctions::GetObjectDoorState},\ {"GetObjectLockLevel", ObjectFunctions::GetObjectLockLevel},\ + {"GetObjectSummonDuration", ObjectFunctions::GetObjectSummonDuration},\ {"GetObjectPosX", ObjectFunctions::GetObjectPosX},\ {"GetObjectPosY", ObjectFunctions::GetObjectPosY},\ {"GetObjectPosZ", ObjectFunctions::GetObjectPosZ},\ @@ -55,6 +56,7 @@ {"SetObjectState", ObjectFunctions::SetObjectState},\ {"SetObjectLockLevel", ObjectFunctions::SetObjectLockLevel},\ {"SetObjectDisarmState", ObjectFunctions::SetObjectDisarmState},\ + {"SetObjectSummonDuration", ObjectFunctions::SetObjectSummonDuration},\ {"SetObjectMasterState", ObjectFunctions::SetObjectMasterState},\ {"SetObjectPosition", ObjectFunctions::SetObjectPosition},\ {"SetObjectRotation", ObjectFunctions::SetObjectRotation},\ @@ -250,6 +252,17 @@ public: */ static int GetObjectLockLevel(unsigned int i) noexcept; + /** + * \brief Get the summon duration of the object at a certain index in the read object list's object + * changes. + * + * Note: Returns -1 if indefinite. + * + * \param i The index of the object. + * \return The summon duration. + */ + static double GetObjectSummonDuration(unsigned int i) noexcept; + /** * \brief Get the X position of the object at a certain index in the read object list's object * changes. @@ -509,6 +522,14 @@ public: */ static void SetObjectLockLevel(int lockLevel) noexcept; + /** + * \brief Set the summon duration of the temporary object stored on the server. + * + * \param summonDuration The summon duration. + * \return void + */ + static void SetObjectSummonDuration(float summonDuration) noexcept; + /** * \brief Set the disarm state of the temporary object stored on the server. * diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 9d8fe60c3..620053c69 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -319,6 +319,26 @@ namespace MWMechanics End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it easy to get an effect's duration + */ + float ActiveSpells::getEffectDuration(short effectId) + { + for (TContainer::iterator it = mSpells.begin(); it != mSpells.end(); ++it) + { + for (std::vector::iterator effectIt = it->second.mEffects.begin(); + effectIt != it->second.mEffects.end();) + { + return effectIt->mDuration; + } + } + } + /* + End of tes3mp addition + */ + void ActiveSpells::clear() { mSpells.clear(); diff --git a/apps/openmw/mwmechanics/activespells.hpp b/apps/openmw/mwmechanics/activespells.hpp index 7f4c8ea3f..a9c3a2761 100644 --- a/apps/openmw/mwmechanics/activespells.hpp +++ b/apps/openmw/mwmechanics/activespells.hpp @@ -104,6 +104,16 @@ namespace MWMechanics End of tes3mp addition */ + /* + Start of tes3mp addition + + Make it easy to get an effect's duration + */ + float getEffectDuration(short effectId); + /* + End of tes3mp addition + */ + /// Remove all spells void clear(); diff --git a/apps/openmw/mwmechanics/summoning.cpp b/apps/openmw/mwmechanics/summoning.cpp index 0657b25ce..e2bc813ff 100644 --- a/apps/openmw/mwmechanics/summoning.cpp +++ b/apps/openmw/mwmechanics/summoning.cpp @@ -8,6 +8,7 @@ Include additional headers for multiplayer purposes */ #include +#include "../mwmechanics/creaturestats.hpp" #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" #include "../mwmp/CellController.hpp" @@ -107,7 +108,10 @@ namespace MWMechanics { mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); objectList->reset(); - objectList->addObjectSpawn(placed, mActor); + + MWMechanics::CreatureStats *actorCreatureStats = &mActor.getClass().getCreatureStats(mActor); + + objectList->addObjectSpawn(placed, mActor, actorCreatureStats->getActiveSpells().getEffectDuration(it->first)); objectList->sendObjectSpawn(); } diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp index d323818d1..ee7187870 100644 --- a/apps/openmw/mwmp/ObjectList.cpp +++ b/apps/openmw/mwmp/ObjectList.cpp @@ -839,6 +839,7 @@ void ObjectList::addObjectSpawn(const MWWorld::Ptr& ptr) baseObject.refId = ptr.getCellRef().getRefId(); baseObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; baseObject.mpNum = 0; + baseObject.summonDuration = -1; baseObject.hasMaster = false; // Make sure we send the RefData position instead of the CellRef one, because that's what @@ -848,7 +849,7 @@ void ObjectList::addObjectSpawn(const MWWorld::Ptr& ptr) addObject(baseObject); } -void ObjectList::addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& master) +void ObjectList::addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& master, float duration) { cell = *ptr.getCell()->getCell(); @@ -856,6 +857,7 @@ void ObjectList::addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& mas baseObject.refId = ptr.getCellRef().getRefId(); baseObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; baseObject.mpNum = 0; + baseObject.summonDuration = duration; baseObject.hasMaster = true; diff --git a/apps/openmw/mwmp/ObjectList.hpp b/apps/openmw/mwmp/ObjectList.hpp index abbdbac96..af8f50dd3 100644 --- a/apps/openmw/mwmp/ObjectList.hpp +++ b/apps/openmw/mwmp/ObjectList.hpp @@ -51,7 +51,7 @@ namespace mwmp void addObjectPlace(const MWWorld::Ptr& ptr, bool droppedByPlayer = false); void addObjectSpawn(const MWWorld::Ptr& ptr); - void addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& master); + void addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& master, float spawnDuration); void addObjectDelete(const MWWorld::Ptr& ptr); void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel); void addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed); diff --git a/components/openmw-mp/Base/BaseObject.hpp b/components/openmw-mp/Base/BaseObject.hpp index 349b1af3f..c40a7f132 100644 --- a/components/openmw-mp/Base/BaseObject.hpp +++ b/components/openmw-mp/Base/BaseObject.hpp @@ -57,6 +57,7 @@ namespace mwmp bool isDisarmed; bool droppedByPlayer; + float summonDuration; Target master; bool hasMaster; diff --git a/components/openmw-mp/Packets/Object/PacketObjectSpawn.cpp b/components/openmw-mp/Packets/Object/PacketObjectSpawn.cpp index 0b5de8111..8ce99788f 100644 --- a/components/openmw-mp/Packets/Object/PacketObjectSpawn.cpp +++ b/components/openmw-mp/Packets/Object/PacketObjectSpawn.cpp @@ -13,6 +13,7 @@ void PacketObjectSpawn::Object(BaseObject &baseObject, bool send) { ObjectPacket::Object(baseObject, send); RW(baseObject.position, send); + RW(baseObject.summonDuration, send); RW(baseObject.hasMaster, send);