2017-04-17 11:37:19 +00:00
|
|
|
#include <components/openmw-mp/Log.hpp>
|
|
|
|
|
2017-04-17 13:09:07 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/combat.hpp"
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/inventorystore.hpp"
|
|
|
|
|
2017-04-17 11:37:19 +00:00
|
|
|
#include "MechanicsHelper.hpp"
|
|
|
|
#include "Main.hpp"
|
2017-04-17 13:09:07 +00:00
|
|
|
#include "LocalPlayer.hpp"
|
|
|
|
#include "DedicatedPlayer.hpp"
|
|
|
|
|
2017-04-17 11:37:19 +00:00
|
|
|
using namespace mwmp;
|
|
|
|
|
|
|
|
mwmp::MechanicsHelper::MechanicsHelper()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mwmp::MechanicsHelper::~MechanicsHelper()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
osg::Vec3f MechanicsHelper::getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent)
|
|
|
|
{
|
|
|
|
osg::Vec3f position(percent, percent, percent);
|
|
|
|
|
|
|
|
return (start + osg::componentMultiply(position, (end - start)));
|
|
|
|
}
|
2017-04-17 13:09:07 +00:00
|
|
|
|
|
|
|
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);
|
2017-04-17 14:24:11 +00:00
|
|
|
attackerStats.getSpells().setSelectedSpell(attack.spellId);
|
2017-04-17 13:09:07 +00:00
|
|
|
|
|
|
|
MWWorld::Ptr victim;
|
|
|
|
|
2017-04-17 15:31:39 +00:00
|
|
|
if (attack.target.guid == mwmp::Main::get().getLocalPlayer()->guid)
|
2017-04-17 13:09:07 +00:00
|
|
|
victim = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
2017-04-17 15:31:39 +00:00
|
|
|
else if (Players::getPlayer(attack.target.guid) != 0)
|
|
|
|
victim = Players::getPlayer(attack.target.guid)->getPtr();
|
2017-04-17 13:09:07 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
2017-04-17 14:24:11 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "SpellId: %s", attack.spellId.c_str());
|
2017-04-17 13:09:07 +00:00
|
|
|
LOG_APPEND(Log::LOG_VERBOSE, " - success: %d", attack.success);
|
|
|
|
}
|
|
|
|
}
|