1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

[Client] Add MechanicsHelper method to get actorId of an mwmp::Target

Also clean up MechanicsHelper::getPlayerPtr() slightly.
This commit is contained in:
David Cernat 2021-07-21 14:57:55 +02:00
parent a78a88ed6d
commit 4492a7a768
2 changed files with 42 additions and 2 deletions

View file

@ -143,13 +143,52 @@ Cast *MechanicsHelper::getDedicatedCast(const MWWorld::Ptr& ptr)
MWWorld::Ptr MechanicsHelper::getPlayerPtr(const Target& target)
{
if (target.guid == mwmp::Main::get().getLocalPlayer()->guid)
{
return MWMechanics::getPlayer();
else if (PlayerList::getPlayer(target.guid) != nullptr)
return PlayerList::getPlayer(target.guid)->getPtr();
}
else
{
mwmp::DedicatedPlayer* dedicatedPlayer = mwmp::PlayerList::getPlayer(target.guid);
if (dedicatedPlayer != nullptr)
{
return dedicatedPlayer->getPtr();
}
}
return nullptr;
}
unsigned int MechanicsHelper::getActorId(const mwmp::Target& target)
{
int actorId = -1;
MWWorld::Ptr targetPtr;
if (target.isPlayer)
{
targetPtr = getPlayerPtr(target);
}
else
{
auto controller = mwmp::Main::get().getCellController();
if (controller->isLocalActor(target.refNum, target.mpNum))
{
targetPtr = controller->getLocalActor(target.refNum, target.mpNum)->getPtr();
}
else if (controller->isDedicatedActor(target.refNum, target.mpNum))
{
targetPtr = controller->getDedicatedActor(target.refNum, target.mpNum)->getPtr();
}
}
if (targetPtr)
{
actorId = targetPtr.getClass().getCreatureStats(targetPtr).getActorId();
}
return actorId;
}
mwmp::Item MechanicsHelper::getItem(const MWWorld::Ptr& itemPtr, int count)
{
mwmp::Item item;

View file

@ -24,6 +24,7 @@ namespace MechanicsHelper
mwmp::Cast *getDedicatedCast(const MWWorld::Ptr& ptr);
MWWorld::Ptr getPlayerPtr(const mwmp::Target& target);
unsigned int getActorId(const mwmp::Target& target);
mwmp::Item getItem(const MWWorld::Ptr& itemPtr, int count);
mwmp::Target getTarget(const MWWorld::Ptr& ptr);