From b4dd70b98e9016d2ea5eb9f0ff09cab0a94f1890 Mon Sep 17 00:00:00 2001 From: Rushi <44952533+Skyliegirl33@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:47:47 +0200 Subject: [PATCH 1/6] Remove unnecessary bit field in exd --- deps/datReader/Exd/Structs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/datReader/Exd/Structs.h b/deps/datReader/Exd/Structs.h index 1d1de7b05..9baf7f185 100644 --- a/deps/datReader/Exd/Structs.h +++ b/deps/datReader/Exd/Structs.h @@ -430,7 +430,7 @@ namespace Excel uint8_t HideCastBar : 1; uint8_t IsTargetLine : 1; - int8_t unknown : 8; + int8_t unknown; }; /* 75653 */ From 241ac491efb48fa150057db47d4fb7dc9cafeb69 Mon Sep 17 00:00:00 2001 From: Rushi <44952533+Skyliegirl33@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:48:32 +0200 Subject: [PATCH 2/6] Avoid copying modifiers to applyStatusEffect --- src/world/Action/Action.cpp | 4 ++-- src/world/Action/ActionResult.cpp | 4 ++-- src/world/Action/ActionResult.h | 4 ++-- src/world/Action/ActionResultBuilder.cpp | 4 ++-- src/world/Action/ActionResultBuilder.h | 4 ++-- src/world/StatusEffect/StatusEffect.cpp | 4 ++-- src/world/StatusEffect/StatusEffect.h | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 8afe58091..28e2267cc 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -624,7 +624,7 @@ void Action::Action::handleStatusEffects() { for( auto& status : m_lutEntry.statuses.caster ) { - pActionBuilder->applyStatusEffectSelf( status.id, status.duration, 0, status.modifiers, status.flag, true ); + pActionBuilder->applyStatusEffectSelf( status.id, status.duration, 0, std::move( status.modifiers ), status.flag, true ); } } @@ -635,7 +635,7 @@ void Action::Action::handleStatusEffects() { for( auto& status : m_lutEntry.statuses.target ) { - pActionBuilder->applyStatusEffect( actor, status.id, status.duration, 0, status.modifiers, status.flag, true ); + pActionBuilder->applyStatusEffect( actor, status.id, status.duration, 0, std::move( status.modifiers ), status.flag, true ); } if( actor->getStatusEffectMap().size() > 0 ) diff --git a/src/world/Action/ActionResult.cpp b/src/world/Action/ActionResult.cpp index 6dcb38912..13b8d99eb 100644 --- a/src/world/Action/ActionResult.cpp +++ b/src/world/Action/ActionResult.cpp @@ -78,7 +78,7 @@ void ActionResult::applyStatusEffect( uint32_t id, int32_t duration, Entity::Cha } void ActionResult::applyStatusEffect( uint32_t id, int32_t duration, Entity::Chara& source, uint8_t param, - std::vector< StatusModifier > modifiers, uint32_t flag, bool shouldOverride ) + const std::vector< StatusModifier >& modifiers, uint32_t flag, bool shouldOverride ) { m_result.Value = static_cast< int16_t >( id ); m_result.Arg2 = param; @@ -101,7 +101,7 @@ void ActionResult::applyStatusEffectSelf( uint32_t id, int32_t duration, uint8_t m_pStatus->setParam( param ); } -void ActionResult::applyStatusEffectSelf( uint32_t id, int32_t duration, uint8_t param, std::vector< World::Action::StatusModifier > modifiers, +void ActionResult::applyStatusEffectSelf( uint32_t id, int32_t duration, uint8_t param, const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, bool shouldOverride ) { m_result.Value = static_cast< int16_t >( id ); diff --git a/src/world/Action/ActionResult.h b/src/world/Action/ActionResult.h index 0e7421ebe..3a10b4abc 100644 --- a/src/world/Action/ActionResult.h +++ b/src/world/Action/ActionResult.h @@ -22,9 +22,9 @@ namespace Sapphire::World::Action void comboSucceed(); void applyStatusEffect( uint32_t id, int32_t duration, Entity::Chara& source, uint8_t param, bool shouldOverride ); void applyStatusEffect( uint32_t id, int32_t duration, Entity::Chara& source, uint8_t param, - std::vector< World::Action::StatusModifier > modifiers, uint32_t flag, bool shouldOverride ); + const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, bool shouldOverride ); void applyStatusEffectSelf( uint32_t id, int32_t duration, uint8_t param, bool shouldOverride ); - void applyStatusEffectSelf( uint32_t id, int32_t duration, uint8_t param, std::vector< World::Action::StatusModifier > modifiers, + void applyStatusEffectSelf( uint32_t id, int32_t duration, uint8_t param, const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, bool shouldOverride ); void mount( uint16_t mountId ); diff --git a/src/world/Action/ActionResultBuilder.cpp b/src/world/Action/ActionResultBuilder.cpp index 6b58f2d0c..cf073683e 100644 --- a/src/world/Action/ActionResultBuilder.cpp +++ b/src/world/Action/ActionResultBuilder.cpp @@ -94,7 +94,7 @@ void ActionResultBuilder::applyStatusEffect( Entity::CharaPtr& target, uint16_t } void ActionResultBuilder::applyStatusEffect( Entity::CharaPtr& target, uint16_t statusId, uint32_t duration, uint8_t param, - std::vector< World::Action::StatusModifier > modifiers, uint32_t flag, bool shouldOverride ) + const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, bool shouldOverride ) { ActionResultPtr nextResult = make_ActionResult( target ); nextResult->applyStatusEffect( statusId, duration, *m_sourceChara, param, modifiers, flag, shouldOverride ); @@ -108,7 +108,7 @@ void ActionResultBuilder::applyStatusEffectSelf( uint16_t statusId, uint32_t dur addResultToActor( m_sourceChara, nextResult ); } -void ActionResultBuilder::applyStatusEffectSelf( uint16_t statusId, uint32_t duration, uint8_t param, std::vector< World::Action::StatusModifier > modifiers, +void ActionResultBuilder::applyStatusEffectSelf( uint16_t statusId, uint32_t duration, uint8_t param, const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, bool shouldOverride ) { ActionResultPtr nextResult = make_ActionResult( m_sourceChara ); diff --git a/src/world/Action/ActionResultBuilder.h b/src/world/Action/ActionResultBuilder.h index 672f509b7..e2e79747a 100644 --- a/src/world/Action/ActionResultBuilder.h +++ b/src/world/Action/ActionResultBuilder.h @@ -28,9 +28,9 @@ namespace Sapphire::World::Action void applyStatusEffect( Entity::CharaPtr& target, uint16_t statusId, uint32_t duration, uint8_t param, bool shouldOverride = false ); void applyStatusEffect( Entity::CharaPtr& target, uint16_t statusId, uint32_t duration, uint8_t param, - std::vector< World::Action::StatusModifier > modifiers, uint32_t flag = 0, bool shouldOverride = false ); + const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag = 0, bool shouldOverride = false ); void applyStatusEffectSelf( uint16_t statusId, uint32_t duration, uint8_t param, bool shouldOverride = false ); - void applyStatusEffectSelf( uint16_t statusId, uint32_t duration, uint8_t param, std::vector< World::Action::StatusModifier > modifiers, + void applyStatusEffectSelf( uint16_t statusId, uint32_t duration, uint8_t param, const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag = 0, bool shouldOverride = false ); void mount( Entity::CharaPtr& target, uint16_t mountId ); diff --git a/src/world/StatusEffect/StatusEffect.cpp b/src/world/StatusEffect/StatusEffect.cpp index bcbee38f9..a9f4171c9 100644 --- a/src/world/StatusEffect/StatusEffect.cpp +++ b/src/world/StatusEffect/StatusEffect.cpp @@ -22,11 +22,11 @@ using namespace Sapphire::Network::Packets; //using namespace Sapphire::Network::Packets::WorldPackets::Server; Sapphire::StatusEffect::StatusEffect::StatusEffect( uint32_t id, Entity::CharaPtr sourceActor, Entity::CharaPtr targetActor, - uint32_t duration,std::vector< World::Action::StatusModifier >& modifiers, + uint32_t duration, const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, uint32_t tickRate ) : StatusEffect( id, sourceActor, targetActor, duration, tickRate ) { - m_statusModifiers = std::move( modifiers ); + m_statusModifiers = modifiers; m_flag = flag; } diff --git a/src/world/StatusEffect/StatusEffect.h b/src/world/StatusEffect/StatusEffect.h index 2bf6865b3..a9a3a2349 100644 --- a/src/world/StatusEffect/StatusEffect.h +++ b/src/world/StatusEffect/StatusEffect.h @@ -12,7 +12,7 @@ class StatusEffect { public: StatusEffect( uint32_t id, Entity::CharaPtr sourceActor, Entity::CharaPtr targetActor, - uint32_t duration, std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, uint32_t tickRate ); + uint32_t duration, const std::vector< World::Action::StatusModifier >& modifiers, uint32_t flag, uint32_t tickRate ); StatusEffect( uint32_t id, Entity::CharaPtr sourceActor, Entity::CharaPtr targetActor, uint32_t duration, uint32_t tickRate ); From d8ffb010a3d0eb0a8ac047a29967e0a228814207 Mon Sep 17 00:00:00 2001 From: Rushi <44952533+Skyliegirl33@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:29:27 +0200 Subject: [PATCH 3/6] Change StatusEntry duration to unsigned int --- src/tools/action_parse/main.cpp | 2 +- src/world/Action/ActionLut.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/action_parse/main.cpp b/src/tools/action_parse/main.cpp index 1abe3045e..1f07de8fa 100644 --- a/src/tools/action_parse/main.cpp +++ b/src/tools/action_parse/main.cpp @@ -40,7 +40,7 @@ struct StatusModifier struct StatusEntry { uint16_t id; - int32_t duration; + uint32_t duration; uint32_t flag; std::vector< StatusModifier > modifiers; }; diff --git a/src/world/Action/ActionLut.h b/src/world/Action/ActionLut.h index 258658547..0b86013ee 100644 --- a/src/world/Action/ActionLut.h +++ b/src/world/Action/ActionLut.h @@ -17,7 +17,7 @@ namespace Sapphire::World::Action struct StatusEntry { uint16_t id; - int32_t duration; + uint32_t duration; uint32_t flag; std::vector< StatusModifier > modifiers; }; From 0ac79362cd2ec9da15ffe34cc064cdea8aeb1198 Mon Sep 17 00:00:00 2001 From: Rushi <44952533+Skyliegirl33@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:31:58 +0200 Subject: [PATCH 4/6] Change size() > 0 checks to !empty() --- src/world/Action/Action.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 28e2267cc..aefb889fd 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -592,15 +592,13 @@ void Action::Action::buildActionResults() } // If we hit an enemy - if( m_hitActors.size() > 0 && getHitChara()->getObjKind() != m_pSource->getObjKind() ) + if( !m_hitActors.empty() && getHitChara()->getObjKind() != m_pSource->getObjKind() ) { m_pSource->removeStatusEffectByFlag( Common::StatusEffectFlag::RemoveOnSuccessfulHit ); } handleJobAction(); - - if( m_lutEntry.statuses.caster.size() > 0 || m_lutEntry.statuses.target.size() > 0 ) - handleStatusEffects(); + handleStatusEffects(); m_actionResultBuilder->sendActionResults( m_hitActors ); @@ -620,7 +618,7 @@ void Action::Action::handleStatusEffects() return; // handle caster statuses - if( m_lutEntry.statuses.caster.size() > 0 ) + if( !m_lutEntry.statuses.caster.empty() ) { for( auto& status : m_lutEntry.statuses.caster ) { @@ -629,7 +627,7 @@ void Action::Action::handleStatusEffects() } // handle hit actor statuses - if( m_lutEntry.statuses.target.size() > 0 && m_hitActors.size() > 0 ) + if( !m_lutEntry.statuses.target.empty() && !m_hitActors.empty() ) { for( auto& actor : m_hitActors ) { @@ -638,7 +636,7 @@ void Action::Action::handleStatusEffects() pActionBuilder->applyStatusEffect( actor, status.id, status.duration, 0, std::move( status.modifiers ), status.flag, true ); } - if( actor->getStatusEffectMap().size() > 0 ) + if( !actor->getStatusEffectMap().empty() ) actor->onActionHostile( m_pSource ); } } From 6b72992b9fb4bfca007131aefdb1943607a4995e Mon Sep 17 00:00:00 2001 From: Rushi <44952533+Skyliegirl33@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:38:30 +0200 Subject: [PATCH 5/6] Change StatusEffect to return const-ref in modifier getters --- src/world/StatusEffect/StatusEffect.cpp | 4 ++-- src/world/StatusEffect/StatusEffect.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/world/StatusEffect/StatusEffect.cpp b/src/world/StatusEffect/StatusEffect.cpp index a9f4171c9..85f5497d8 100644 --- a/src/world/StatusEffect/StatusEffect.cpp +++ b/src/world/StatusEffect/StatusEffect.cpp @@ -109,7 +109,7 @@ uint16_t Sapphire::StatusEffect::StatusEffect::getParam() const return m_param; } -std::unordered_map< Common::ParamModifier, int32_t >& Sapphire::StatusEffect::StatusEffect::getModifiers() +const std::unordered_map< Common::ParamModifier, int32_t >& Sapphire::StatusEffect::StatusEffect::getModifiers() const { return m_modifiers; } @@ -196,7 +196,7 @@ uint32_t Sapphire::StatusEffect::StatusEffect::getFlag() const return m_flag; } -std::vector< World::Action::StatusModifier > Sapphire::StatusEffect::StatusEffect::getStatusModifiers() const +const std::vector< World::Action::StatusModifier >& Sapphire::StatusEffect::StatusEffect::getStatusModifiers() const { return m_statusModifiers; } diff --git a/src/world/StatusEffect/StatusEffect.h b/src/world/StatusEffect/StatusEffect.h index a9a3a2349..f8a24dde9 100644 --- a/src/world/StatusEffect/StatusEffect.h +++ b/src/world/StatusEffect/StatusEffect.h @@ -21,7 +21,7 @@ class StatusEffect void onTick(); - std::unordered_map< Common::ParamModifier, int32_t >& getModifiers(); + const std::unordered_map< Common::ParamModifier, int32_t >& getModifiers() const; void setModifier( Common::ParamModifier paramModifier, int32_t value ); @@ -50,7 +50,7 @@ class StatusEffect uint32_t getFlag() const; - std::vector< World::Action::StatusModifier > getStatusModifiers() const; + const std::vector< World::Action::StatusModifier >& getStatusModifiers() const; void setLastTick( uint64_t lastTick ); From 2965d8a03ad6a72eba3861ebd732daa108156f77 Mon Sep 17 00:00:00 2001 From: Rushi <44952533+Skyliegirl33@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:12:33 +0200 Subject: [PATCH 6/6] Add function to remove multiple statuseffects by id --- .../statuseffect/StatusEffectDefiance.cpp | 7 +------ src/world/Actor/Chara.cpp | 18 ++++++++++++++++++ src/world/Actor/Chara.h | 2 ++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/scripts/statuseffect/StatusEffectDefiance.cpp b/src/scripts/statuseffect/StatusEffectDefiance.cpp index 9f26421af..207ccec01 100644 --- a/src/scripts/statuseffect/StatusEffectDefiance.cpp +++ b/src/scripts/statuseffect/StatusEffectDefiance.cpp @@ -15,12 +15,7 @@ class StatusEffectDefiance : public Sapphire::ScriptAPI::StatusEffectScript void onExpire( Entity::Chara& actor ) override { - actor.removeSingleStatusEffectById( Unchained ); - actor.removeSingleStatusEffectById( Wrath ); - actor.removeSingleStatusEffectById( WrathII ); - actor.removeSingleStatusEffectById( WrathIII ); - actor.removeSingleStatusEffectById( WrathIV ); - actor.removeSingleStatusEffectById( Infuriated ); + actor.removeStatusEffectById( { Unchained, Wrath, WrathII, WrathIII, WrathIV, Infuriated } ); } }; diff --git a/src/world/Actor/Chara.cpp b/src/world/Actor/Chara.cpp index 845f0b1d8..2d6abf28d 100644 --- a/src/world/Actor/Chara.cpp +++ b/src/world/Actor/Chara.cpp @@ -559,6 +559,24 @@ void Chara::removeSingleStatusEffectById( uint32_t id ) } } +void Chara::removeStatusEffectById( std::vector< uint32_t > ids ) +{ + for( auto effectIt = m_statusEffectMap.begin(); effectIt != m_statusEffectMap.end(); ) + { + auto foundStatus = std::find( ids.begin(), ids.end(), effectIt->second->getId() ); + + if( foundStatus != ids.end() ) + { + effectIt = removeStatusEffect( effectIt->first ); + ids.erase( foundStatus ); + } + else + { + ++effectIt; + } + } +} + void Chara::removeStatusEffectByFlag( Common::StatusEffectFlag flag ) { for( auto effectIt = m_statusEffectMap.begin(); effectIt != m_statusEffectMap.end(); ) diff --git a/src/world/Actor/Chara.h b/src/world/Actor/Chara.h index 722f4af37..8ee157de0 100644 --- a/src/world/Actor/Chara.h +++ b/src/world/Actor/Chara.h @@ -114,6 +114,8 @@ namespace Sapphire::Entity void removeSingleStatusEffectById( uint32_t id ); + void removeStatusEffectById( std::vector< uint32_t > ids ); + void removeStatusEffectByFlag( Common::StatusEffectFlag flag ); void updateStatusEffects();