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

Also clean up MechanicsHelper::getPlayerPtr() slightly.
pull/593/head
David Cernat 4 years ago
parent a78a88ed6d
commit 4492a7a768

@ -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;

@ -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);

Loading…
Cancel
Save