diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index 863c85932..35042f00b 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -1,7 +1,19 @@ #include +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + +#include "../mwmechanics/combat.hpp" +#include "../mwmechanics/npcstats.hpp" + +#include "../mwworld/class.hpp" +#include "../mwworld/inventorystore.hpp" + #include "MechanicsHelper.hpp" #include "Main.hpp" +#include "LocalPlayer.hpp" +#include "DedicatedPlayer.hpp" + using namespace mwmp; mwmp::MechanicsHelper::MechanicsHelper() @@ -20,3 +32,59 @@ osg::Vec3f MechanicsHelper::getLinearInterpolation(osg::Vec3f start, osg::Vec3f return (start + osg::componentMultiply(position, (end - start))); } + +void MechanicsHelper::processAttack(const MWWorld::Ptr& attacker, Attack attack) +{ + if (attack.pressed == 0) + { + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", attack.success ? "true" : "false"); + + if (attack.success == 1) + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", attack.damage); + } + + MWMechanics::CreatureStats &attackerStats = attacker.getClass().getNpcStats(attacker); + attackerStats.getSpells().setSelectedSpell(attack.refId); + + MWWorld::Ptr victim; + + if (attack.target == mwmp::Main::get().getLocalPlayer()->guid) + victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); + else if (Players::getPlayer(attack.target) != 0) + victim = Players::getPlayer(attack.target)->getPtr(); + + // Get the weapon used (if hand-to-hand, weapon = inv.end()) + if (attackerStats.getDrawState() == MWMechanics::DrawState_Weapon) + { + MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker); + MWWorld::ContainerStoreIterator weaponslot = inv.getSlot( + MWWorld::InventoryStore::Slot_CarriedRight); + + MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr()); + if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name()) + weapon = MWWorld::Ptr(); + + if (victim.mRef != 0) + { + bool healthdmg; + if (!weapon.isEmpty()) + healthdmg = true; + else + { + MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); + healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown(); + } + + if (!weapon.isEmpty()) + MWMechanics::blockMeleeAttack(attacker, victim, weapon, attack.damage, 1); + + attacker.getClass().onHit(victim, attack.damage, healthdmg, weapon, attacker, osg::Vec3f(), + attack.success); + } + } + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", attack.refId.c_str()); + LOG_APPEND(Log::LOG_VERBOSE, " - success: %d", attack.success); + } +} diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp index 28522fc8a..72c7a0155 100644 --- a/apps/openmw/mwmp/MechanicsHelper.hpp +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_MECHANICSHELPER_HPP #define OPENMW_MECHANICSHELPER_HPP +#include + #include namespace mwmp @@ -13,6 +15,8 @@ namespace mwmp ~MechanicsHelper(); osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent); + + void processAttack(const MWWorld::Ptr& attacker, Attack attack); }; } diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index e5d3077a6..54c5fb583 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -5,32 +5,38 @@ #include #include #include + +#include +#include +#include +#include + #include +#include -#include "../mwbase/world.hpp" #include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" + +#include "../mwclass/npc.hpp" + +#include "../mwmechanics/combat.hpp" +#include "../mwmechanics/npcstats.hpp" + +#include "../mwstate/statemanagerimp.hpp" #include "../mwworld/cellstore.hpp" #include "../mwworld/esmstore.hpp" #include "../mwworld/inventorystore.hpp" -#include "../mwclass/npc.hpp" -#include "../mwmechanics/npcstats.hpp" -#include "../mwmechanics/combat.hpp" - #include + #include "Networking.hpp" -#include "../mwstate/statemanagerimp.hpp" -#include -#include -#include -#include -#include -#include "DedicatedPlayer.hpp" -#include "LocalPlayer.hpp" +#include "Main.hpp" #include "GUIController.hpp" #include "CellController.hpp" -#include "Main.hpp" +#include "MechanicsHelper.hpp" +#include "LocalPlayer.hpp" +#include "DedicatedPlayer.hpp" using namespace std; using namespace mwmp; @@ -442,59 +448,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) myPacket->setPlayer(pl); myPacket->Packet(&bsIn, false); - //cout << "Player: " << pl->Npc()->mName << " pressed: " << (pl->getAttack()->pressed == 1) << endl; - if (pl->attack.pressed == 0) - { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Attack success: %s", pl->attack.success ? "true" : "false"); - - if (pl->attack.success == 1) - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Damage: %f", pl->attack.damage); - } - - MWMechanics::CreatureStats &stats = pl->getPtr().getClass().getNpcStats(pl->getPtr()); - stats.getSpells().setSelectedSpell(pl->attack.refId); - - MWWorld::Ptr victim; - if (pl->attack.target == getLocalPlayer()->guid) - victim = MWBase::Environment::get().getWorld()->getPlayerPtr(); - else if (Players::getPlayer(pl->attack.target) != 0) - victim = Players::getPlayer(pl->attack.target)->getPtr(); - - MWWorld::Ptr attacker; - attacker = pl->getPtr(); - - // Get the weapon used (if hand-to-hand, weapon = inv.end()) - if (pl->drawState == 1) - { - MWWorld::InventoryStore &inv = attacker.getClass().getInventoryStore(attacker); - MWWorld::ContainerStoreIterator weaponslot = inv.getSlot( - MWWorld::InventoryStore::Slot_CarriedRight); - MWWorld::Ptr weapon = ((weaponslot != inv.end()) ? *weaponslot : MWWorld::Ptr()); - if (!weapon.isEmpty() && weapon.getTypeName() != typeid(ESM::Weapon).name()) - weapon = MWWorld::Ptr(); - - if (victim.mRef != 0) - { - bool healthdmg; - if (!weapon.isEmpty()) - healthdmg = true; - else - { - MWMechanics::CreatureStats &otherstats = victim.getClass().getCreatureStats(victim); - healthdmg = otherstats.isParalyzed() || otherstats.getKnockedDown(); - } - - if (!weapon.isEmpty()) - MWMechanics::blockMeleeAttack(attacker, victim, weapon, pl->attack.damage, 1); - pl->getPtr().getClass().onHit(victim, pl->attack.damage, healthdmg, weapon, attacker, osg::Vec3f(), - pl->attack.success); - } - } - else - { - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", pl->attack.refId.c_str()); - LOG_APPEND(Log::LOG_VERBOSE, " - success: %d", pl->attack.success); - } + Main::get().getMechanicsHelper()->processAttack(pl->getPtr(), pl->attack); } break; }