1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-20 18:39:39 +00:00

[Client] Set attackingOrSpell state instantly after Attack/Cast packets

It is no longer necessary to wait for the Actors::update() loop to set dedicated players and actors to their new states.
This commit is contained in:
David Cernat 2019-11-30 15:03:51 +02:00
parent c702eab93c
commit ed7fe859dd
6 changed files with 66 additions and 28 deletions

View file

@ -239,6 +239,16 @@ namespace MWBase
virtual bool isReadyToBlock (const MWWorld::Ptr& ptr) const = 0;
virtual bool isAttackingOrSpell(const MWWorld::Ptr &ptr) const = 0;
/*
Start of tes3mp addition
Make it possible to set the attackingOrSpell state from elsewhere in the code
*/
virtual void setAttackingOrSpell(const MWWorld::Ptr &ptr, bool state) const = 0;
/*
End of tes3mp addition
*/
virtual void castSpell(const MWWorld::Ptr& ptr, const std::string spellId, bool manualSpell) = 0;
virtual void processChangedSettings (const std::set< std::pair<std::string, std::string> >& settings) = 0;

View file

@ -1756,33 +1756,6 @@ namespace MWMechanics
End of tes3mp change (minor)
*/
/*
Start of tes3mp addition
If this actor is a DedicatedPlayer or DedicatedActor, update their mAttackingOrSpell
*/
mwmp::Attack *dedicatedAttack = MechanicsHelper::getDedicatedAttack(iter->first);
if (dedicatedAttack)
{
bool attackingOrSpellState = false;
if (dedicatedAttack->pressed)
attackingOrSpellState = true;
else
{
mwmp::Cast *dedicatedCast = MechanicsHelper::getDedicatedCast(iter->first);
if (dedicatedCast->pressed)
attackingOrSpellState = true;
}
iter->second->getCharacterController()->setAttackingOrSpell(attackingOrSpellState);
}
/*
End of tes3mp addition
*/
/*
Start of tes3mp change (major)
@ -2617,6 +2590,24 @@ namespace MWMechanics
return ctrl->isAttackingOrSpell();
}
/*
Start of tes3mp addition
Make it possible to set the attackingOrSpell state from elsewhere in the code
*/
void Actors::setAttackingOrSpell(const MWWorld::Ptr& ptr, bool state) const
{
PtrActorMap::const_iterator it = mActors.find(ptr);
if (it == mActors.end())
return;
CharacterController* ctrl = it->second->getCharacterController();
ctrl->setAttackingOrSpell(state);
}
/*
End of tes3mp addition
*/
void Actors::fastForwardAi()
{
if (!MWBase::Environment::get().getMechanicsManager()->isAIActive())

View file

@ -204,6 +204,16 @@ namespace MWMechanics
bool isReadyToBlock(const MWWorld::Ptr& ptr) const;
bool isAttackingOrSpell(const MWWorld::Ptr& ptr) const;
/*
Start of tes3mp addition
Make it possible to set the attackingOrSpell state from elsewhere in the code
*/
void setAttackingOrSpell(const MWWorld::Ptr& ptr, bool state) const;
/*
End of tes3mp addition
*/
private:
void updateVisibility (const MWWorld::Ptr& ptr, CharacterController* ctrl);

View file

@ -1928,6 +1928,19 @@ namespace MWMechanics
return mActors.isAttackingOrSpell(ptr);
}
/*
Start of tes3mp addition
Make it possible to set the attackingOrSpell state from elsewhere in the code
*/
void MechanicsManager::setAttackingOrSpell(const MWWorld::Ptr &ptr, bool state) const
{
return mActors.setAttackingOrSpell(ptr, state);
}
/*
End of tes3mp addition
*/
void MechanicsManager::setWerewolf(const MWWorld::Ptr& actor, bool werewolf)
{
MWMechanics::NpcStats& npcStats = actor.getClass().getNpcStats(actor);

View file

@ -213,6 +213,16 @@ namespace MWMechanics
/// Is \a ptr casting spell or using weapon now?
virtual bool isAttackingOrSpell(const MWWorld::Ptr &ptr) const override;
/*
Start of tes3mp addition
Make it possible to set the attackingOrSpell state from elsewhere in the code
*/
virtual void setAttackingOrSpell(const MWWorld::Ptr &ptr, bool state) const override;
/*
End of tes3mp addition
*/
virtual void castSpell(const MWWorld::Ptr& ptr, const std::string spellId, bool manualSpell=false) override;
void processChangedSettings(const Settings::CategorySettingVector& settings) override;

View file

@ -3,6 +3,7 @@
#include <components/misc/rng.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/world.hpp"
#include "../mwmechanics/creaturestats.hpp"
@ -288,7 +289,8 @@ void MechanicsHelper::processAttack(Attack attack, const MWWorld::Ptr& attacker)
LOG_APPEND(TimedLog::LOG_VERBOSE, "- animation: %s", attack.attackAnimation.c_str());
}
MWMechanics::CreatureStats &attackerStats = attacker.getClass().getCreatureStats(attacker);
MWBase::Environment::get().getMechanicsManager()->setAttackingOrSpell(attacker, attack.pressed);
MWWorld::Ptr victim;
if (attack.target.isPlayer)
@ -434,7 +436,9 @@ void MechanicsHelper::processCast(Cast cast, const MWWorld::Ptr& caster)
LOG_APPEND(TimedLog::LOG_VERBOSE, "- success: %s", cast.success ? "true" : "false");
}
MWBase::Environment::get().getMechanicsManager()->setAttackingOrSpell(caster, cast.pressed);
MWMechanics::CreatureStats &casterStats = caster.getClass().getCreatureStats(caster);
MWWorld::Ptr victim;
if (cast.target.isPlayer)