From 06b4a4f97cbdf0f5830ff8ecdf671c9c82aa3e32 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Thu, 28 Nov 2019 10:34:34 +0200 Subject: [PATCH] [Client] Don't tie spellcasting for dedicated players/actors to anim end When Koncord implemented spellcasting, he made it so only the act of initiating a spellcast was synchronized, leaving it to other clients to actually cast a spell for a dedicated player or actor once their spellcasting animation was over. This had led to a lot of desyncs and has always been inconsistent with the handling of attacks, so I've belatedly gone ahead and prevented the end of a spellcasting animation from having any effect for dedicated players and actors, making them cast a spell when an appropriate Cast packet is received from them instead. Additionally, the logged messages in MechanicsHelper's handling of attacking and casting have been moved around slightly. --- apps/openmw/mwmechanics/character.cpp | 7 +++++-- apps/openmw/mwmp/MechanicsHelper.cpp | 13 +++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 8c64d5f3f..5a55f25f5 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1094,8 +1094,11 @@ void CharacterController::handleTextKey(const std::string &groupname, const std: // the same animation for all range types, so there are 3 "release" keys on the same time, one for each range type. && evt.compare(off, len, mAttackType + " release") == 0) { - MWBase::Environment::get().getWorld()->castSpell(mPtr, mCastingManualSpell); - mCastingManualSpell = false; + if (mPtr == getPlayer() || mwmp::Main::get().getCellController()->isLocalActor(mPtr)) + { + MWBase::Environment::get().getWorld()->castSpell(mPtr, mCastingManualSpell); + mCastingManualSpell = false; + } } else if (groupname == "shield" && evt.compare(off, len, "block hit") == 0) diff --git a/apps/openmw/mwmp/MechanicsHelper.cpp b/apps/openmw/mwmp/MechanicsHelper.cpp index 960c64df7..40ee080e9 100644 --- a/apps/openmw/mwmp/MechanicsHelper.cpp +++ b/apps/openmw/mwmp/MechanicsHelper.cpp @@ -273,6 +273,8 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Processing attack from %s of type %i", attacker.getClass().getName(attacker).c_str(), attack.type); + LOG_APPEND(TimedLog::LOG_VERBOSE, "- pressed: %s", attack.pressed ? "true" : "false"); + if (!attack.pressed) { LOG_APPEND(TimedLog::LOG_VERBOSE, "- success: %s", attack.success ? "true" : "false"); @@ -281,8 +283,6 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker) LOG_APPEND(TimedLog::LOG_VERBOSE, "- damage: %f", attack.damage); } - LOG_APPEND(TimedLog::LOG_VERBOSE, "- pressed: %s", attack.pressed ? "true" : "false"); - MWMechanics::CreatureStats &attackerStats = attacker.getClass().getCreatureStats(attacker); MWWorld::Ptr victim; @@ -422,13 +422,13 @@ void MechanicsHelper::processCast(Cast cast, const MWWorld::Ptr& caster) LOG_MESSAGE_SIMPLE(TimedLog::LOG_VERBOSE, "Processing cast from %s of type %i", caster.getClass().getName(caster).c_str(), cast.type); + LOG_APPEND(TimedLog::LOG_VERBOSE, "- pressed: %s", cast.pressed ? "true" : "false"); + if (!cast.pressed) { LOG_APPEND(TimedLog::LOG_VERBOSE, "- success: %s", cast.success ? "true" : "false"); } - LOG_APPEND(TimedLog::LOG_VERBOSE, "- pressed: %s", cast.pressed ? "true" : "false"); - MWMechanics::CreatureStats &casterStats = caster.getClass().getCreatureStats(caster); MWWorld::Ptr victim; @@ -452,11 +452,8 @@ void MechanicsHelper::processCast(Cast cast, const MWWorld::Ptr& caster) { casterStats.getSpells().setSelectedSpell(cast.spellId); - if (cast.instant) - { + if (cast.success) MWBase::Environment::get().getWorld()->castSpell(caster); - cast.instant = false; - } LOG_APPEND(TimedLog::LOG_VERBOSE, "- spellId: %s", cast.spellId.c_str()); }