[General] Synchronize projectile speed for ranged attacks

This is done by including the final attackStrength used for ranged attacks in packets and then applying it in WeaponAnimation::releaseArrow() on other clients.
fix/skillcap
David Cernat 6 years ago
parent 7281f9fc42
commit b5f46ada73

@ -1413,6 +1413,11 @@ namespace MWMechanics
MechanicsHelper::resetAttack(localAttack); MechanicsHelper::resetAttack(localAttack);
localAttack->type = MechanicsHelper::isUsingRangedWeapon(player) ? mwmp::Attack::RANGED : mwmp::Attack::MELEE; localAttack->type = MechanicsHelper::isUsingRangedWeapon(player) ? mwmp::Attack::RANGED : mwmp::Attack::MELEE;
localAttack->pressed = state; localAttack->pressed = state;
// Prepare this attack for sending as long as it's not a ranged attack that's being released,
// because we need to get the final attackStrength for that from WeaponAnimation to have the
// correct projectile speed
if (localAttack->type == mwmp::Attack::MELEE || state)
localAttack->shouldSend = true; localAttack->shouldSend = true;
} }
} }

@ -5,6 +5,16 @@
#include <components/resource/resourcesystem.hpp> #include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp> #include <components/resource/scenemanager.hpp>
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
#include "../mwmp/MechanicsHelper.hpp"
/*
End of tes3mp addition
*/
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
@ -92,6 +102,33 @@ void WeaponAnimation::attachArrow(MWWorld::Ptr actor)
void WeaponAnimation::releaseArrow(MWWorld::Ptr actor, float attackStrength) void WeaponAnimation::releaseArrow(MWWorld::Ptr actor, float attackStrength)
{ {
/*
Start of tes3mp addition
If this is an attack by a LocalPlayer or LocalActor, record its attackStrength and
prepare an attack packet for sending
If it's an attack by a DedicatedPlayer or DedicatedActor, apply the attackStrength
from their latest attack packet
*/
mwmp::Attack *localAttack = MechanicsHelper::getLocalAttack(actor);
if (localAttack)
{
localAttack->attackStrength = attackStrength;
localAttack->shouldSend = true;
}
else
{
mwmp::Attack *dedicatedAttack = MechanicsHelper::getDedicatedAttack(actor);
if (dedicatedAttack)
attackStrength = dedicatedAttack->attackStrength;
}
/*
End of tes3mp addition
*/
MWWorld::InventoryStore& inv = actor.getClass().getInventoryStore(actor); MWWorld::InventoryStore& inv = actor.getClass().getInventoryStore(actor);
MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); MWWorld::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
if (weapon == inv.end()) if (weapon == inv.end())

@ -81,6 +81,7 @@ namespace mwmp
ESM::Position hitPosition; ESM::Position hitPosition;
float damage; float damage;
float attackStrength;
bool success; bool success;
bool block; bool block;

@ -43,9 +43,13 @@ void PacketActorAttack::Actor(BaseActor &actor, bool send)
RW(actor.attack.damage, send); RW(actor.attack.damage, send);
RW(actor.attack.block, send); RW(actor.attack.block, send);
RW(actor.attack.knockdown, send); RW(actor.attack.knockdown, send);
RW(actor.attack.applyWeaponEnchantment, send); RW(actor.attack.applyWeaponEnchantment, send);
if (actor.attack.type == mwmp::Attack::RANGED)
{
RW(actor.attack.applyProjectileEnchantment, send); RW(actor.attack.applyProjectileEnchantment, send);
RW(actor.attack.attackStrength, send);
}
if (actor.attack.success || actor.attack.applyWeaponEnchantment || actor.attack.applyProjectileEnchantment) if (actor.attack.success || actor.attack.applyWeaponEnchantment || actor.attack.applyProjectileEnchantment)
{ {

@ -44,9 +44,13 @@ void PacketPlayerAttack::Packet(RakNet::BitStream *bs, bool send)
RW(player->attack.damage, send); RW(player->attack.damage, send);
RW(player->attack.block, send); RW(player->attack.block, send);
RW(player->attack.knockdown, send); RW(player->attack.knockdown, send);
RW(player->attack.applyWeaponEnchantment, send); RW(player->attack.applyWeaponEnchantment, send);
if (player->attack.type == mwmp::Attack::RANGED)
{
RW(player->attack.applyProjectileEnchantment, send); RW(player->attack.applyProjectileEnchantment, send);
RW(player->attack.attackStrength, send);
}
if (player->attack.success || player->attack.applyWeaponEnchantment || player->attack.applyProjectileEnchantment) if (player->attack.success || player->attack.applyWeaponEnchantment || player->attack.applyProjectileEnchantment)
{ {

Loading…
Cancel
Save