forked from teamnwah/openmw-tes3coop
[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.
This commit is contained in:
parent
7281f9fc42
commit
b5f46ada73
5 changed files with 56 additions and 5 deletions
|
@ -1413,7 +1413,12 @@ namespace MWMechanics
|
|||
MechanicsHelper::resetAttack(localAttack);
|
||||
localAttack->type = MechanicsHelper::isUsingRangedWeapon(player) ? mwmp::Attack::RANGED : mwmp::Attack::MELEE;
|
||||
localAttack->pressed = state;
|
||||
localAttack->shouldSend = true;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,16 @@
|
|||
#include <components/resource/resourcesystem.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/environment.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
|
@ -92,6 +102,33 @@ void WeaponAnimation::attachArrow(MWWorld::Ptr actor)
|
|||
|
||||
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::ContainerStoreIterator weapon = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
||||
if (weapon == inv.end())
|
||||
|
|
|
@ -81,6 +81,7 @@ namespace mwmp
|
|||
ESM::Position hitPosition;
|
||||
|
||||
float damage;
|
||||
float attackStrength;
|
||||
|
||||
bool success;
|
||||
bool block;
|
||||
|
|
|
@ -43,9 +43,13 @@ void PacketActorAttack::Actor(BaseActor &actor, bool send)
|
|||
RW(actor.attack.damage, send);
|
||||
RW(actor.attack.block, send);
|
||||
RW(actor.attack.knockdown, send);
|
||||
|
||||
RW(actor.attack.applyWeaponEnchantment, send);
|
||||
RW(actor.attack.applyProjectileEnchantment, send);
|
||||
|
||||
if (actor.attack.type == mwmp::Attack::RANGED)
|
||||
{
|
||||
RW(actor.attack.applyProjectileEnchantment, send);
|
||||
RW(actor.attack.attackStrength, send);
|
||||
}
|
||||
|
||||
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.block, send);
|
||||
RW(player->attack.knockdown, send);
|
||||
|
||||
RW(player->attack.applyWeaponEnchantment, send);
|
||||
RW(player->attack.applyProjectileEnchantment, send);
|
||||
|
||||
if (player->attack.type == mwmp::Attack::RANGED)
|
||||
{
|
||||
RW(player->attack.applyProjectileEnchantment, send);
|
||||
RW(player->attack.attackStrength, send);
|
||||
}
|
||||
|
||||
if (player->attack.success || player->attack.applyWeaponEnchantment || player->attack.applyProjectileEnchantment)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue