From 0cd43df30502b2a9d3a04f57dc949dc5763676ff Mon Sep 17 00:00:00 2001 From: Lucy <44952533+Skyliegirl33@users.noreply.github.com> Date: Mon, 6 Mar 2023 23:09:03 +0100 Subject: [PATCH] Add basic generic handler for applying statuseffects --- src/world/Action/Action.cpp | 31 +++++++++++++++++++++++++++++++ src/world/Action/Action.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/world/Action/Action.cpp b/src/world/Action/Action.cpp index 4d435570..0da5b41f 100644 --- a/src/world/Action/Action.cpp +++ b/src/world/Action/Action.cpp @@ -533,6 +533,8 @@ void Action::Action::handleAction() Manager::PlayerMgr::sendDebug( *player, "Hit target: pot: {} (c: {}, f: {}, r: {}), heal pot: {}, mpp: {}", m_lutEntry.potency, m_lutEntry.comboPotency, m_lutEntry.flankPotency, m_lutEntry.rearPotency, m_lutEntry.curePotency, m_lutEntry.restoreMPPercentage ); + if( m_lutEntry.statuses.caster.size() > 0 || m_lutEntry.statuses.target.size() > 0 ) + handleStatusEffects(); } // when aoe, these effects are in the target whatever is hit first @@ -600,6 +602,35 @@ void Action::Action::handleAction() // m_effectBuilder.reset(); } +void Action::Action::handleStatusEffects() +{ + // handle caster statuses + if( m_lutEntry.statuses.caster.size() > 0 ) + { + for( auto& status : m_lutEntry.statuses.caster ) + { + getEffectbuilder()->applyStatusEffect( m_pSource, status.id, 0 ); + m_pSource->addStatusEffectByIdIfNotExist( status.id, status.duration, *m_pSource, status.modifiers ); + } + } + + // handle hit actor statuses + if( m_lutEntry.statuses.target.size() > 0 && m_hitActors.size() > 0 ) + { + for( auto& actor : m_hitActors ) + { + for( auto& status : m_lutEntry.statuses.target ) + { + getEffectbuilder()->applyStatusEffect( actor, status.id, 0 ); + actor->addStatusEffectByIdIfNotExist( status.id, status.duration, *m_pSource, status.modifiers ); + } + + if( actor->getStatusEffectMap().size() > 0 ) + actor->onActionHostile( m_pSource ); + } + } +} + bool Action::Action::preCheck() { if( auto player = m_pSource->getAsPlayer() ) diff --git a/src/world/Action/Action.h b/src/world/Action/Action.h index 49d4cff2..77a139dc 100644 --- a/src/world/Action/Action.h +++ b/src/world/Action/Action.h @@ -107,6 +107,8 @@ namespace Sapphire::World::Action void handleAction(); + void handleStatusEffects(); + /*! * @brief Adds an actor filter to this action. * @param filter The ptr to the ActorFilter to add