[Client] Rework MechanicsHelper::getTarget() to avoid crashes

0.6.3
David Cernat 7 years ago
parent 7f0549fc4f
commit 509882b5f6

@ -97,31 +97,33 @@ MWWorld::Ptr MechanicsHelper::getPlayerPtr(const Target& target)
mwmp::Target MechanicsHelper::getTarget(const MWWorld::Ptr& ptr) mwmp::Target MechanicsHelper::getTarget(const MWWorld::Ptr& ptr)
{ {
mwmp::Target target; mwmp::Target target;
clearTarget(target);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) if (ptr != nullptr)
{
target.isPlayer = true;
target.guid = mwmp::Main::get().getLocalPlayer()->guid;
}
else if (mwmp::PlayerList::isDedicatedPlayer(ptr))
{ {
target.isPlayer = true; if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
target.guid = mwmp::PlayerList::getPlayer(ptr)->guid;
}
else
{
MWWorld::CellRef *ptrRef = &ptr.getCellRef();
if (ptrRef)
{ {
target.isPlayer = false; target.isPlayer = true;
target.refId = ptrRef->getRefId(); target.guid = mwmp::Main::get().getLocalPlayer()->guid;
target.refNumIndex = ptrRef->getRefNum().mIndex; }
target.mpNum = ptrRef->getMpNum(); else if (mwmp::PlayerList::isDedicatedPlayer(ptr))
target.name = ptr.getClass().getName(ptr); {
target.isPlayer = true;
target.guid = mwmp::PlayerList::getPlayer(ptr)->guid;
} }
else else
clearTarget(target); {
MWWorld::CellRef *ptrRef = &ptr.getCellRef();
if (ptrRef)
{
target.isPlayer = false;
target.refId = ptrRef->getRefId();
target.refNumIndex = ptrRef->getRefNum().mIndex;
target.mpNum = ptrRef->getMpNum();
target.name = ptr.getClass().getName(ptr);
}
}
} }
return target; return target;

Loading…
Cancel
Save