From 8012d0d7b74ce6df5470382735d2eab2cbffed6e Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 8 Sep 2018 05:29:49 +0300 Subject: [PATCH] [General] Include hit position in PlayerAttack and ActorAttack packets --- apps/openmw/mwclass/creature.cpp | 5 +++-- apps/openmw/mwclass/npc.cpp | 5 +++-- apps/openmw/mwmp/MechanicsHelper.cpp | 16 +++++++++++++--- apps/openmw/mwmp/MechanicsHelper.hpp | 1 + components/openmw-mp/Base/BaseStructs.hpp | 3 +++ .../Packets/Actor/PacketActorAttack.cpp | 7 +++++++ .../Packets/Player/PacketPlayerAttack.cpp | 7 +++++++ 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 02401d890..db844bf17 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -300,14 +300,15 @@ namespace MWClass /* Start of tes3mp addition - If the attacker is a LocalPlayer or LocalActor, get their Attack and - assign data for its target + If the attacker is a LocalPlayer or LocalActor, get their Attack to assign its + hit position and target */ mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(ptr); if (localAttack) { localAttack->success = true; + localAttack->hitPosition = MechanicsHelper::getPositionFromVector(hitPosition); MechanicsHelper::assignAttackTarget(localAttack, victim); } /* diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 4024f1d06..505ce7878 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -628,14 +628,15 @@ namespace MWClass /* Start of tes3mp addition - If the attacker is a LocalPlayer or LocalActor, get their Attack and - assign data for its target + If the attacker is a LocalPlayer or LocalActor, get their Attack to assign its + hit position and target */ mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(ptr); if (localAttack) { localAttack->success = true; + localAttack->hitPosition = MechanicsHelper::getPositionFromVector(hitPosition); MechanicsHelper::assignAttackTarget(localAttack, victim); } /* diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index 9118effaa..3c58b5bbb 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -31,6 +31,16 @@ osg::Vec3f MechanicsHelper::getLinearInterpolation(osg::Vec3f start, osg::Vec3f return (start + osg::componentMultiply(position, (end - start))); } +ESM::Position MechanicsHelper::getPositionFromVector(osg::Vec3f vector) +{ + ESM::Position position; + position.pos[0] = vector.x(); + position.pos[1] = vector.y(); + position.pos[2] = vector.z(); + + return position; +} + // Inspired by similar code in mwclass\creaturelevlist.cpp void MechanicsHelper::spawnLeveledCreatures(MWWorld::CellStore* cellStore) { @@ -263,19 +273,19 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) if (attack.applyWeaponEnchantment) { MWMechanics::CastSpell cast(attacker, victim, false); - cast.mHitPosition = osg::Vec3f(); + cast.mHitPosition = attack.hitPosition.asVec3(); cast.cast(weapon, false); } if (attack.applyProjectileEnchantment) { MWMechanics::CastSpell cast(attacker, victim, false); - cast.mHitPosition = osg::Vec3f(); + cast.mHitPosition = attack.hitPosition.asVec3(); cast.cast(projectile, false); } } - victim.getClass().onHit(victim, attack.damage, healthdmg, weapon, attacker, osg::Vec3f(), + victim.getClass().onHit(victim, attack.damage, healthdmg, weapon, attacker, attack.hitPosition.asVec3(), attack.success); } } diff --git a/apps/openmw/mwmp/MechanicsHelper.hpp b/apps/openmw/mwmp/MechanicsHelper.hpp index d2e5edf1d..fd1c50a1c 100644 --- a/apps/openmw/mwmp/MechanicsHelper.hpp +++ b/apps/openmw/mwmp/MechanicsHelper.hpp @@ -11,6 +11,7 @@ namespace MechanicsHelper { osg::Vec3f getLinearInterpolation(osg::Vec3f start, osg::Vec3f end, float percent); + ESM::Position getPositionFromVector(osg::Vec3f vector); void spawnLeveledCreatures(MWWorld::CellStore* cellStore); diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 8baa29fe0..cf809f4a7 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -3,6 +3,7 @@ #include +#include #include #include @@ -76,6 +77,8 @@ namespace mwmp std::string spellId; // id of spell (e.g. "fireball") std::string itemId; + ESM::Position hitPosition; + float damage; bool success; diff --git a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp index 289fdbc50..2e0daa1a6 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp @@ -31,6 +31,13 @@ void PacketActorAttack::Actor(BaseActor &actor, bool send) RW(actor.attack.pressed, send); RW(actor.attack.success, send); + if (actor.attack.success) + { + RW(actor.attack.hitPosition.pos[0], send); + RW(actor.attack.hitPosition.pos[1], send); + RW(actor.attack.hitPosition.pos[2], send); + } + if (actor.attack.type == mwmp::Attack::MELEE) { RW(actor.attack.damage, send); diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp index 7c5d4aaa6..bd7144fe0 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp @@ -32,6 +32,13 @@ void PacketPlayerAttack::Packet(RakNet::BitStream *bs, bool send) RW(player->attack.pressed, send); RW(player->attack.success, send); + if (player->attack.success) + { + RW(player->attack.hitPosition.pos[0], send); + RW(player->attack.hitPosition.pos[1], send); + RW(player->attack.hitPosition.pos[2], send); + } + if (player->attack.type == mwmp::Attack::MELEE) { RW(player->attack.damage, send);