From af49f711cadcd39005b081f69b6740ff4878c658 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 14 Sep 2018 13:21:45 +0300 Subject: [PATCH] [Client] Add isUsingRangedWeapon() method to MechanicsHelper --- apps/openmw/mwmp/MechanicsHelper.cpp | 20 ++++++++++++++++++++ apps/openmw/mwmp/MechanicsHelper.hpp | 2 ++ 2 files changed, 22 insertions(+) diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index afdc7daab..af903657f 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -75,6 +75,26 @@ void MechanicsHelper::spawnLeveledCreatures(MWWorld::CellStore* cellStore) objectList->sendObjectSpawn(); } +bool MechanicsHelper::isUsingRangedWeapon(const MWWorld::Ptr& ptr) +{ + if (ptr.getClass().hasInventoryStore(ptr)) + { + MWWorld::InventoryStore &inventoryStore = ptr.getClass().getInventoryStore(ptr); + MWWorld::ContainerStoreIterator weaponSlot = inventoryStore.getSlot( + MWWorld::InventoryStore::Slot_CarriedRight); + + if (weaponSlot != inventoryStore.end()) + { + const ESM::Weapon* weaponRecord = weaponSlot->get()->mBase; + + if (weaponRecord->mData.mType >= ESM::Weapon::MarksmanBow) + return true; + } + } + + return false; +} + Attack *MechanicsHelper::getLocalAttack(const MWWorld::Ptr& ptr) { if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr()) diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp index fd1c50a1c..6fa490384 100644 --- a/apps/openmw/mwmp/MechanicsHelper.hpp +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -15,6 +15,8 @@ namespace MechanicsHelper void spawnLeveledCreatures(MWWorld::CellStore* cellStore); + bool isUsingRangedWeapon(const MWWorld::Ptr& ptr); + mwmp::Attack *getLocalAttack(const MWWorld::Ptr& ptr); mwmp::Attack *getDedicatedAttack(const MWWorld::Ptr& ptr);