forked from mirror/openmw-tes3mp
[Client] Rework MechanicsHelper::getTarget() to avoid crashes
This commit is contained in:
parent
7f0549fc4f
commit
509882b5f6
1 changed files with 22 additions and 20 deletions
|
@ -97,31 +97,33 @@ MWWorld::Ptr MechanicsHelper::getPlayerPtr(const Target& target)
|
|||
mwmp::Target MechanicsHelper::getTarget(const MWWorld::Ptr& ptr)
|
||||
{
|
||||
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;
|
||||
target.guid = mwmp::PlayerList::getPlayer(ptr)->guid;
|
||||
}
|
||||
else
|
||||
{
|
||||
MWWorld::CellRef *ptrRef = &ptr.getCellRef();
|
||||
|
||||
if (ptrRef)
|
||||
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
|
||||
{
|
||||
target.isPlayer = false;
|
||||
target.refId = ptrRef->getRefId();
|
||||
target.refNumIndex = ptrRef->getRefNum().mIndex;
|
||||
target.mpNum = ptrRef->getMpNum();
|
||||
target.name = ptr.getClass().getName(ptr);
|
||||
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
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue