Skip to content

Commit

Permalink
Merge pull request #959 from arieshi255/actions-fixup
Browse files Browse the repository at this point in the history
[3.x] WIP: Cleanup of initial action implementation
  • Loading branch information
SapphireMordred authored Jun 21, 2024
2 parents 7bfd953 + 2965d8a commit 52dfd3a
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion deps/datReader/Exd/Structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ namespace Excel
uint8_t HideCastBar : 1;
uint8_t IsTargetLine : 1;

int8_t unknown : 8;
int8_t unknown;
};

/* 75653 */
Expand Down
7 changes: 1 addition & 6 deletions src/scripts/statuseffect/StatusEffectDefiance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/tools/action_parse/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct StatusModifier
struct StatusEntry
{
uint16_t id;
int32_t duration;
uint32_t duration;
uint32_t flag;
std::vector< StatusModifier > modifiers;
};
Expand Down
16 changes: 7 additions & 9 deletions src/world/Action/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -620,25 +618,25 @@ 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 )
{
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 );
}
}

// 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 )
{
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 )
if( !actor->getStatusEffectMap().empty() )
actor->onActionHostile( m_pSource );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/world/Action/ActionLut.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 2 additions & 2 deletions src/world/Action/ActionResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/world/Action/ActionResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
4 changes: 2 additions & 2 deletions src/world/Action/ActionResultBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/world/Action/ActionResultBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
18 changes: 18 additions & 0 deletions src/world/Actor/Chara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); )
Expand Down
2 changes: 2 additions & 0 deletions src/world/Actor/Chara.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/world/StatusEffect/StatusEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/world/StatusEffect/StatusEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down

0 comments on commit 52dfd3a

Please sign in to comment.