diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index 9c87e8c9b..9082fea3a 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -86,13 +86,10 @@ Attack *MechanicsHelper::getDedicatedAttack(const MWWorld::Ptr& ptr) MWWorld::Ptr MechanicsHelper::getPlayerPtr(const Target& target) { - if (target.refId.empty()) - { - if (target.guid == mwmp::Main::get().getLocalPlayer()->guid) - return MWBase::Environment::get().getWorld()->getPlayerPtr(); - else if (PlayerList::getPlayer(target.guid) != nullptr) - return PlayerList::getPlayer(target.guid)->getPtr(); - } + if (target.guid == mwmp::Main::get().getLocalPlayer()->guid) + return MWBase::Environment::get().getWorld()->getPlayerPtr(); + else if (PlayerList::getPlayer(target.guid) != nullptr) + return PlayerList::getPlayer(target.guid)->getPtr(); return nullptr; } @@ -101,18 +98,19 @@ void MechanicsHelper::assignAttackTarget(Attack* attack, const MWWorld::Ptr& tar { if (target == MWBase::Environment::get().getWorld()->getPlayerPtr()) { + attack->target.isPlayer = true; attack->target.guid = mwmp::Main::get().getLocalPlayer()->guid; - attack->target.refId.clear(); } else if (mwmp::PlayerList::isDedicatedPlayer(target)) { + attack->target.isPlayer = true; attack->target.guid = mwmp::PlayerList::getPlayer(target)->guid; - attack->target.refId.clear(); } else { MWWorld::CellRef *targetRef = &target.getCellRef(); + attack->target.isPlayer = false; attack->target.refId = targetRef->getRefId(); attack->target.refNumIndex = targetRef->getRefNum().mIndex; attack->target.mpNum = targetRef->getMpNum(); @@ -128,6 +126,8 @@ void MechanicsHelper::resetAttack(Attack* attack) attack->applyProjectileEnchantment = false; attack->target.guid = RakNet::RakNetGUID(); attack->target.refId.clear(); + attack->target.refNumIndex = 0; + attack->target.mpNum = 0; } bool MechanicsHelper::getSpellSuccess(std::string spellId, const MWWorld::Ptr& caster) @@ -152,7 +152,7 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) MWWorld::Ptr victim; - if (attack.target.refId.empty()) + if (attack.target.isPlayer) { if (attack.target.guid == mwmp::Main::get().getLocalPlayer()->guid) victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 5e5ad23b0..03afd6317 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -338,7 +338,7 @@ void WorldEvent::spawnObjects(MWWorld::CellStore* cellStore) { MWWorld::Ptr masterPtr; - if (worldObject.master.refId.empty()) + if (worldObject.master.isPlayer) masterPtr = MechanicsHelper::getPlayerPtr(worldObject.master); else masterPtr = cellStore->searchExact(worldObject.master.refNumIndex, worldObject.master.mpNum); @@ -828,18 +828,19 @@ void WorldEvent::addObjectSpawn(const MWWorld::Ptr& ptr, const MWWorld::Ptr& mas if (master == MWBase::Environment::get().getWorld()->getPlayerPtr()) { + worldObject.master.isPlayer = true; worldObject.master.guid = mwmp::Main::get().getLocalPlayer()->guid; - worldObject.master.refId.clear(); } else if (mwmp::PlayerList::isDedicatedPlayer(master)) { + worldObject.master.isPlayer = true; worldObject.master.guid = mwmp::PlayerList::getPlayer(master)->guid; - worldObject.master.refId.clear(); } else { MWWorld::CellRef *masterRef = &master.getCellRef(); + worldObject.master.isPlayer = false; worldObject.master.refId = masterRef->getRefId(); worldObject.master.refNumIndex = masterRef->getRefNum().mIndex; worldObject.master.mpNum = masterRef->getMpNum(); diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 0b83766f0..03fa30082 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -22,6 +22,8 @@ namespace mwmp struct Target { + bool isPlayer; + std::string refId; int refNumIndex; int mpNum; diff --git a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp index 44e8d43b0..324f7fb84 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp @@ -11,9 +11,18 @@ PacketActorAttack::PacketActorAttack(RakNet::RakPeerInterface *peer) : ActorPack void PacketActorAttack::Actor(BaseActor &actor, bool send) { - RW(actor.attack.target.refNumIndex, send); - RW(actor.attack.target.mpNum, send); - RW(actor.attack.target.guid, send); + RW(actor.attack.target.isPlayer, send); + + if (actor.attack.target.isPlayer) + { + RW(actor.attack.target.guid, send); + } + else + { + RW(actor.attack.target.refId, send, 1); + RW(actor.attack.target.refNumIndex, send); + RW(actor.attack.target.mpNum, send); + } RW(actor.attack.spellId, send); RW(actor.attack.type, send); diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp index 75a6f4323..71dbf9881 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp @@ -16,10 +16,18 @@ void PacketPlayerAttack::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - RW(player->attack.target.refId, send, 1); - RW(player->attack.target.refNumIndex, send); - RW(player->attack.target.mpNum, send); - RW(player->attack.target.guid, send); + RW(player->attack.target.isPlayer, send); + + if (player->attack.target.isPlayer) + { + RW(player->attack.target.guid, send); + } + else + { + RW(player->attack.target.refId, send, 1); + RW(player->attack.target.refNumIndex, send); + RW(player->attack.target.mpNum, send); + } RW(player->attack.spellId, send, 1); RW(player->attack.type, send); diff --git a/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp b/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp index 3716679d7..6d26990f3 100644 --- a/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectSpawn.cpp @@ -18,8 +18,17 @@ void PacketObjectSpawn::Object(WorldObject &worldObject, bool send) if (worldObject.hasMaster) { - RW(worldObject.master.refNumIndex, send); - RW(worldObject.master.mpNum, send); - RW(worldObject.master.guid, send); + RW(worldObject.master.isPlayer, send); + + if (worldObject.master.isPlayer) + { + RW(worldObject.master.guid, send); + } + else + { + RW(worldObject.master.refId, send, 1); + RW(worldObject.master.refNumIndex, send); + RW(worldObject.master.mpNum, send); + } } }