From c1589c1f2094ee4b264261c5deda07942336b845 Mon Sep 17 00:00:00 2001 From: Alice Ogeda Date: Wed, 8 Mar 2023 14:36:53 -0300 Subject: [PATCH] add timers and enrage mechanic; --- src/world/Encounter/EncounterFight.h | 6 +- .../Encounter/InstanceContent/IfritNormal.h | 88 +++++++++++++------ 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/world/Encounter/EncounterFight.h b/src/world/Encounter/EncounterFight.h index d50bfe18..d8bd421c 100644 --- a/src/world/Encounter/EncounterFight.h +++ b/src/world/Encounter/EncounterFight.h @@ -18,6 +18,7 @@ namespace Sapphire bool m_bShouldFinish{ false }; StateStackPtr m_stateStack; std::shared_ptr< EncounterFight > m_pEncounter; + uint64_t m_startTime{ 0 }; public: EncounterState( std::shared_ptr< EncounterFight > pEncounter ) : @@ -29,7 +30,7 @@ namespace Sapphire bool shouldFinish() { return m_bShouldFinish; }; virtual void init() = 0; - virtual void update( double deltaTime ) = 0; + virtual void update( uint64_t deltaTime ) = 0; virtual void finish() = 0; }; @@ -53,7 +54,7 @@ namespace Sapphire virtual void init() = 0; virtual void start() = 0; - virtual void update( double deltaTime ) = 0; + virtual void update( uint64_t deltaTime ) = 0; virtual void reset() = 0; virtual void addState( EncounterState::EncounterStatePtr pState, bool initState = true ) = 0; @@ -64,6 +65,7 @@ namespace Sapphire virtual EncounterFightStatus getEncounterFightStatus() const = 0; protected: + uint64_t m_startTime{ 0 }; EncounterState::StateStackPtr m_stateStack; std::set< Entity::PlayerPtr > m_playerList; std::unordered_map< uint32_t, Entity::BNpcPtr > m_bnpcs; diff --git a/src/world/Encounter/InstanceContent/IfritNormal.h b/src/world/Encounter/InstanceContent/IfritNormal.h index a4e12428..9db4adfd 100644 --- a/src/world/Encounter/InstanceContent/IfritNormal.h +++ b/src/world/Encounter/InstanceContent/IfritNormal.h @@ -8,28 +8,6 @@ namespace Sapphire static constexpr int IFRIT = 4126276; static constexpr int HELLFIRE = 0; }; - class IfritStateOne : public EncounterState - { - public: - IfritStateOne( EncounterFightPtr pEncounter ) : EncounterState( pEncounter ) - { - } - - void init() override - { - Logger::info( "ifrit FAN CLUB GEOcities EUNUCH ONLY" ); - } - - void update( double deltaTime ) override - { - auto pIfrit = m_pEncounter->getBNpc( IfritNormalData::IFRIT ); - } - - void finish() override - { - - } - }; class IfritStateTwo : public EncounterState { @@ -43,17 +21,73 @@ namespace Sapphire Logger::info( "ifrit FAN CLUB GEOcities EUNUCH ONLY" ); } - void update( double deltaTime ) override + void update( uint64_t deltaTime ) override { + if( m_startTime == 0 ) + m_startTime = deltaTime; + + auto timeElapsedMs = deltaTime - m_startTime; + auto pIfrit = m_pEncounter->getBNpc( IfritNormalData::IFRIT ); + + pIfrit->setRot( pIfrit->getRot() - .2f ); + pIfrit->sendPositionUpdate(); + + if( timeElapsedMs > 5000 ) + { + m_bShouldFinish = true; + } } void finish() override { + Logger::info( "stage 2 done, going back to stage 1" ); } }; + class IfritStateOne : public EncounterState + { + public: + IfritStateOne( EncounterFightPtr pEncounter ) : EncounterState( pEncounter ) + { + } + + void init() override + { + Logger::info( "ifrit FAN CLUB GEOcities EUNUCH ONLY" ); + } + + void update( uint64_t deltaTime ) override + { + if( m_startTime == 0 ) + m_startTime = deltaTime; + + auto timeElapsedMs = deltaTime - m_startTime; + + auto pIfrit = m_pEncounter->getBNpc( IfritNormalData::IFRIT ); + + pIfrit->setRot( pIfrit->getRot() + .2f ); + pIfrit->sendPositionUpdate(); + + if( timeElapsedMs > 5000 ) + { + auto ifritTwoState = std::make_shared< IfritStateTwo >( m_pEncounter ); + m_pEncounter->addState( ifritTwoState ); + } + + if( timeElapsedMs > 10000 ) + { + pIfrit->hateListGetHighest()->die(); + } + } + + void finish() override + { + + } + }; + class IfritEncounterFight : public EncounterFight { public: @@ -65,6 +99,7 @@ namespace Sapphire void init() override { m_status = EncounterFightStatus::IDLE; + m_startTime = 0; m_stateStack = std::make_shared< EncounterState::StateStack >(); @@ -93,7 +128,7 @@ namespace Sapphire m_status = EncounterFightStatus::ACTIVE; } - void update( double deltaTime ) override + void update( uint64_t deltaTime ) override { // todo: better way to start fights here.. @@ -101,6 +136,7 @@ namespace Sapphire if( ifrit; ifrit->hateListGetHighestValue() != 0 && m_status == EncounterFightStatus::IDLE ) { + m_startTime = deltaTime; start(); } @@ -108,7 +144,7 @@ namespace Sapphire { m_status = EncounterFightStatus::FAIL; } - + if( m_stateStack; !m_stateStack->empty() ) { if( m_stateStack->top()->shouldFinish() ) @@ -150,6 +186,8 @@ namespace Sapphire auto bnpc = m_bnpcs.find( layoutId ); if( bnpc != std::end( m_bnpcs ) ) return bnpc->second; + + return nullptr; } void removeBNpc( uint32_t layoutId ) override