From a650683bae578d5eba77400b517df87b9fdd7646 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 17 Apr 2017 18:31:39 +0300 Subject: [PATCH] [General] Add and use Target struct in mwmp::Attack --- .../processors/player/ProcessorPlayerAttack.hpp | 4 ++-- apps/openmw/mwclass/npc.cpp | 4 ++-- apps/openmw/mwmp/LocalPlayer.cpp | 2 +- apps/openmw/mwmp/MechanicsHelper.cpp | 6 +++--- components/openmw-mp/Base/BaseStructs.hpp | 12 +++++++++++- .../openmw-mp/Packets/Player/PacketPlayerAttack.cpp | 2 +- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/openmw-mp/processors/player/ProcessorPlayerAttack.hpp b/apps/openmw-mp/processors/player/ProcessorPlayerAttack.hpp index e6535b88b..610be3feb 100644 --- a/apps/openmw-mp/processors/player/ProcessorPlayerAttack.hpp +++ b/apps/openmw-mp/processors/player/ProcessorPlayerAttack.hpp @@ -26,7 +26,7 @@ namespace mwmp if (!player.creatureStats.mDead) { - Player *target = Players::getPlayer(player.attack.targetGuid); + Player *target = Players::getPlayer(player.attack.target.guid); if (target == nullptr) target = &player; @@ -46,7 +46,7 @@ namespace mwmp //packet.Send(player, true); player.sendToLoaded(&packet); - playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(player.attack.targetGuid); + playerController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->RequestData(player.attack.target.guid); } } }; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index abd394290..934ad0646 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -629,7 +629,7 @@ namespace MWClass mwmp::Main::get().getLocalPlayer()->attack.success = true; mwmp::DedicatedPlayer *dedicatedPlayer = mwmp::Players::getPlayer(victim); if (dedicatedPlayer != nullptr) - mwmp::Main::get().getLocalPlayer()->attack.targetGuid = dedicatedPlayer->guid; + mwmp::Main::get().getLocalPlayer()->attack.target.guid = dedicatedPlayer->guid; } /* End of tes3mp addition @@ -930,7 +930,7 @@ namespace MWClass { mwmp::Attack *attack = &mwmp::Main::get().getLocalPlayer()->attack; attack->damage = damage; - attack->targetGuid = victimPlayer->guid; + attack->target.guid = victimPlayer->guid; attack->knockdown = getCreatureStats(ptr).getKnockedDown(); mwmp::Main::get().getLocalPlayer()->sendAttack(mwmp::Attack::MELEE); // todo: make this sensitive to different weapon types } diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 0c2f06c67..3ad5e0453 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1195,7 +1195,7 @@ void LocalPlayer::prepareAttack(Attack::TYPE type, bool state) attack.type = type; attack.knockdown = false; attack.block = false; - attack.targetGuid = RakNet::RakNetGUID(); + attack.target.guid = RakNet::RakNetGUID(); getNetworking()->getPlayerPacket(ID_PLAYER_ATTACK)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_ATTACK)->Send(); diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index a26bbeba6..1a3328731 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -48,10 +48,10 @@ void MechanicsHelper::processAttack(const MWWorld::Ptr& attacker, Attack attack) MWWorld::Ptr victim; - if (attack.targetGuid == mwmp::Main::get().getLocalPlayer()->guid) + if (attack.target.guid == mwmp::Main::get().getLocalPlayer()->guid) victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); - else if (Players::getPlayer(attack.targetGuid) != 0) - victim = Players::getPlayer(attack.targetGuid)->getPtr(); + else if (Players::getPlayer(attack.target.guid) != 0) + victim = Players::getPlayer(attack.target.guid)->getPtr(); // Get the weapon used (if hand-to-hand, weapon = inv.end()) if (attackerStats.getDrawState() == MWMechanics::DrawState_Weapon) diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 06b948fbd..acd529b0d 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -5,10 +5,20 @@ namespace mwmp { + struct Target + { + std::string refId; + int refNumIndex; + int mpNum; + + RakNet::RakNetGUID guid; + }; + class Attack { public: - RakNet::RakNetGUID targetGuid; + + Target target; char type; // 0 - melee, 1 - magic, 2 - throwable enum TYPE diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp index eb055cc38..ebaf448ac 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp @@ -16,7 +16,7 @@ void PacketPlayerAttack::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - RW(player->attack.targetGuid, send); + RW(player->attack.target.guid, send); RW(player->attack.spellId, send); RW(player->attack.type, send);