diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index c7dcb7182..9693ff481 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -94,6 +94,49 @@ MWWorld::Ptr MechanicsHelper::getPlayerPtr(const Target& target) return nullptr; } +mwmp::Target MechanicsHelper::getTarget(const MWWorld::Ptr& ptr) +{ + mwmp::Target target; + + if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) + { + target.isPlayer = true; + target.guid = mwmp::Main::get().getLocalPlayer()->guid; + } + else if (mwmp::PlayerList::isDedicatedPlayer(ptr)) + { + target.isPlayer = true; + target.guid = mwmp::PlayerList::getPlayer(ptr)->guid; + } + else + { + MWWorld::CellRef *ptrRef = &ptr.getCellRef(); + + target.isPlayer = false; + target.refId = ptrRef->getRefId(); + target.refNumIndex = ptrRef->getRefNum().mIndex; + target.mpNum = ptrRef->getMpNum(); + } + + return target; +} + +void MechanicsHelper::clearTarget(mwmp::Target& target) +{ + target.isPlayer = false; + target.refId.clear(); + target.refNumIndex = -1; + target.mpNum = -1; +} + +bool MechanicsHelper::isEmptyTarget(const mwmp::Target& target) +{ + if (target.isPlayer == false && target.refId.empty()) + return true; + + return false; +} + void MechanicsHelper::assignAttackTarget(Attack* attack, const MWWorld::Ptr& target) { if (target == MWBase::Environment::get().getWorld()->getPlayerPtr()) diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp index b707c13fc..86c6024bf 100644 --- a/apps/openmw/mwmp/MechanicsHelper.hpp +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -17,6 +17,10 @@ namespace MechanicsHelper MWWorld::Ptr getPlayerPtr(const mwmp::Target& target); + mwmp::Target getTarget(const MWWorld::Ptr& ptr); + void clearTarget(mwmp::Target& target); + bool isEmptyTarget(const mwmp::Target& target); + void assignAttackTarget(mwmp::Attack* attack, const MWWorld::Ptr& target); void resetAttack(mwmp::Attack* attack);