From 3f8d94b030009bd935e3eaf0e630ec2ab3fdef2b Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 3 Apr 2018 10:27:02 +0300 Subject: [PATCH] [General] Synchronize strike enchantments in combat --- apps/openmw/mwclass/creature.cpp | 16 +++++++++++++++- apps/openmw/mwclass/npc.cpp | 16 +++++++++++++++- apps/openmw/mwmp/MechanicsHelper.cpp | 9 +++++++++ components/openmw-mp/Base/BaseStructs.hpp | 1 + .../Packets/Actor/PacketActorAttack.cpp | 1 + .../Packets/Player/PacketPlayerAttack.cpp | 2 ++ 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 6d198b261..6189a535d 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -307,6 +307,7 @@ namespace MWClass if (localAttack) { localAttack->success = true; + localAttack->usesStrikeEnchantment = false; MechanicsHelper::assignAttackTarget(localAttack, victim); } /* @@ -373,7 +374,20 @@ namespace MWClass } // Apply "On hit" enchanted weapons - MWMechanics::applyOnStrikeEnchantment(ptr, victim, weapon, hitPosition); + + /* + Start of tes3mp change (minor) + + Track whether the strike enchantment is successful for attacks by the + LocalPlayer or LocalActors + */ + bool appliedEnchantment = MWMechanics::applyOnStrikeEnchantment(ptr, victim, weapon, hitPosition); + + if (localAttack) + localAttack->usesStrikeEnchantment = appliedEnchantment; + /* + End of tes3mp change (minor) + */ } else if (isBipedal(ptr)) { diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index fbf6c6357..c2d610cc3 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -634,6 +634,7 @@ namespace MWClass if (localAttack) { localAttack->success = true; + localAttack->usesStrikeEnchantment = false; MechanicsHelper::assignAttackTarget(localAttack, victim); } /* @@ -706,7 +707,20 @@ namespace MWClass damage *= store.find("fCombatKODamageMult")->getFloat(); // Apply "On hit" enchanted weapons - MWMechanics::applyOnStrikeEnchantment(ptr, victim, weapon, hitPosition); + + /* + Start of tes3mp change (minor) + + Track whether the strike enchantment is successful for attacks by the + LocalPlayer or LocalActors + */ + bool appliedEnchantment = MWMechanics::applyOnStrikeEnchantment(ptr, victim, weapon, hitPosition); + + if (localAttack) + localAttack->usesStrikeEnchantment = appliedEnchantment; + /* + End of tes3mp change (minor) + */ MWMechanics::applyElementalShields(ptr, victim); diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index e0ecb0478..f61509386 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -195,8 +195,17 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) } } else + { MWMechanics::blockMeleeAttack(attacker, victim, weapon, attack.damage, 1); + if (attack.usesStrikeEnchantment) + { + MWMechanics::CastSpell cast(attacker, victim, false); + cast.mHitPosition = osg::Vec3f(); + cast.cast(weapon, false); + } + } + victim.getClass().onHit(victim, attack.damage, healthdmg, weapon, attacker, osg::Vec3f(), attack.success); } diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 798323c91..2d3dda43a 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -53,6 +53,7 @@ namespace mwmp bool pressed; bool instant; bool knockdown; + bool usesStrikeEnchantment; bool shouldSend; }; diff --git a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp index 4ca89cdf9..57a43b8a4 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorAttack.cpp @@ -25,4 +25,5 @@ void PacketActorAttack::Actor(BaseActor &actor, bool send) RW(actor.attack.block, send); RW(actor.attack.instant, send); + RW(actor.attack.usesStrikeEnchantment, send); } diff --git a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp index bde2c9d0c..a8ad72496 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerAttack.cpp @@ -29,4 +29,6 @@ void PacketPlayerAttack::Packet(RakNet::BitStream *bs, bool send) RW(player->attack.pressed, send); RW(player->attack.knockdown, send); RW(player->attack.block, send); + + RW(player->attack.usesStrikeEnchantment, send); }