From c3375ba86f3c29c4d856ecb2c09b555d4ea277fd Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 19 Apr 2017 11:05:13 +0300 Subject: [PATCH] [Client] Add MechanicsHelper::assignAttackTarget() --- apps/openmw/mwmp/MechanicsHelper.cpp | 19 ++++++++++++++++++- apps/openmw/mwmp/MechanicsHelper.hpp | 4 +++- .../player/ProcessorPlayerAttack.hpp | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index 0602b728e..ca1be954c 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -54,7 +54,24 @@ Attack *MechanicsHelper::getDedicatedAttack(const MWWorld::Ptr& ptr) return NULL; } -void MechanicsHelper::processAttack(const MWWorld::Ptr& attacker, Attack attack) +void MechanicsHelper::assignAttackTarget(Attack* attack, const MWWorld::Ptr& target) +{ + if (mwmp::PlayerList::isDedicatedPlayer(target)) + { + attack->target.guid = mwmp::PlayerList::getPlayer(target)->guid; + attack->target.refId.clear(); + } + else + { + MWWorld::CellRef *targetRef = &target.getCellRef(); + + attack->target.refId = targetRef->getRefId(); + attack->target.refNumIndex = targetRef->getRefNum().mIndex; + attack->target.mpNum = targetRef->getMpNum(); + } +} + +void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) { if (attack.pressed == false) { diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp index 13475f159..63aa94ecc 100644 --- a/apps/openmw/mwmp/MechanicsHelper.hpp +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -19,7 +19,9 @@ namespace mwmp Attack *getLocalAttack(const MWWorld::Ptr& ptr); Attack *getDedicatedAttack(const MWWorld::Ptr& ptr); - void processAttack(const MWWorld::Ptr& attacker, Attack attack); + void assignAttackTarget(Attack* attack, const MWWorld::Ptr& target); + + void processAttack(Attack attack, const MWWorld::Ptr& attacker); }; } diff --git a/apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp b/apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp index 5503aac96..7ee4aca22 100644 --- a/apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp +++ b/apps/openmw/mwmp/processors/player/ProcessorPlayerAttack.hpp @@ -27,7 +27,7 @@ namespace mwmp virtual void Do(PlayerPacket &packet, BasePlayer *player) { - Main::get().getMechanicsHelper()->processAttack(static_cast(player)->getPtr(), player->attack); + Main::get().getMechanicsHelper()->processAttack(player->attack, static_cast(player)->getPtr()); } }; }