From c9c481d63aa2e75cf38b4e1497e9fa30a082d80e Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sat, 27 Jul 2019 13:59:35 +1000 Subject: [PATCH] somewhat basic but working effect result delay --- src/world/Action/EffectBuilder.cpp | 16 +++++++------ src/world/Action/EffectBuilder.h | 10 +-------- src/world/Action/EffectResult.cpp | 36 +++++++++++++++++++++++++++--- src/world/Action/EffectResult.h | 8 +++++-- src/world/Math/CalcStats.cpp | 8 +++---- src/world/Territory/Territory.cpp | 33 ++++++++++++++++++++++++--- src/world/Territory/Territory.h | 6 +++++ 7 files changed, 89 insertions(+), 28 deletions(-) diff --git a/src/world/Action/EffectBuilder.cpp b/src/world/Action/EffectBuilder.cpp index 7b070fc0..7068c01e 100644 --- a/src/world/Action/EffectBuilder.cpp +++ b/src/world/Action/EffectBuilder.cpp @@ -24,11 +24,11 @@ EffectBuilder::EffectBuilder( Entity::CharaPtr source, uint32_t actionId, uint16 } -uint32_t EffectBuilder::getResultDelayMs() +uint64_t EffectBuilder::getResultDelayMs() { // todo: actually figure this retarded shit out - return Common::Util::getTimeMs() + 1000; + return Common::Util::getTimeMs() + 850; } EffectResultPtr EffectBuilder::getResult( Entity::CharaPtr& chara ) @@ -69,11 +69,9 @@ void EffectBuilder::buildAndSendPackets() Logger::debug( "EffectBuilder result: " ); Logger::debug( "Targets afflicted: {}", m_resolvedEffects.size() ); - // test shit - for( auto& effect : m_resolvedEffects ) + for( auto it = m_resolvedEffects.begin(); it != m_resolvedEffects.end(); ) { - auto& result = effect.second; - + auto result = it->second; Logger::debug( " - id: {}", result->getTarget()->getId() ); auto seq = m_sourceChara->getCurrentTerritory()->getNextEffectSequence(); @@ -85,6 +83,10 @@ void EffectBuilder::buildAndSendPackets() effectPacket->addEffect( result->buildEffectEntry() ); m_sourceChara->sendToInRangeSet( effectPacket, true ); - } + // add effect to territory + m_sourceChara->getCurrentTerritory()->addEffectResult( std::move( result ) ); + + it = m_resolvedEffects.erase( it ); + } } \ No newline at end of file diff --git a/src/world/Action/EffectBuilder.h b/src/world/Action/EffectBuilder.h index f8d3bb40..d58bebfe 100644 --- a/src/world/Action/EffectBuilder.h +++ b/src/world/Action/EffectBuilder.h @@ -9,14 +9,6 @@ namespace Sapphire::World::Action class EffectBuilder { public: - enum HitSeverity - { - Normal, - Critical, - DirectHit, - CriticalDirectHit - }; - EffectBuilder( Entity::CharaPtr source, uint32_t actionId, uint16_t sequence ); @@ -32,7 +24,7 @@ namespace Sapphire::World::Action private: EffectResultPtr getResult( Entity::CharaPtr& chara ); - uint32_t getResultDelayMs(); + uint64_t getResultDelayMs(); private: uint32_t m_actionId; diff --git a/src/world/Action/EffectResult.cpp b/src/world/Action/EffectResult.cpp index 710c046d..daf32155 100644 --- a/src/world/Action/EffectResult.cpp +++ b/src/world/Action/EffectResult.cpp @@ -2,15 +2,19 @@ #include +#include "Actor/Chara.h" + using namespace Sapphire; using namespace Sapphire::World::Action; -EffectResult::EffectResult( Entity::CharaPtr target, uint32_t runAfter ) : +EffectResult::EffectResult( Entity::CharaPtr target, uint64_t runAfter ) : m_target( std::move( target ) ), - m_runAfter( runAfter ), + m_delayMs( runAfter ), m_value( 0 ), - m_severity( Common::ActionHitSeverityType::NormalDamage ) + m_severity( Common::ActionHitSeverityType::NormalDamage ), + m_type( Common::ActionEffectType::Nothing ), + m_param( 0 ) { } @@ -25,6 +29,11 @@ uint32_t EffectResult::getValue() const return m_value; } +uint64_t EffectResult::getDelay() +{ + return m_delayMs; +} + void EffectResult::setParam( uint8_t param ) { m_param = param; @@ -57,4 +66,25 @@ Common::EffectEntry EffectResult::buildEffectEntry() const entry.param = m_param; return entry; +} + +void EffectResult::execute() +{ + switch( m_type ) + { + case Common::ActionEffectType::Damage: + { + m_target->takeDamage( m_value ); + break; + } + + case Common::ActionEffectType::Heal: + { + m_target->heal( m_value ); + break; + } + + default: + break; + } } \ No newline at end of file diff --git a/src/world/Action/EffectResult.h b/src/world/Action/EffectResult.h index 083ab273..f1dd8b9c 100644 --- a/src/world/Action/EffectResult.h +++ b/src/world/Action/EffectResult.h @@ -13,7 +13,7 @@ namespace Sapphire::World::Action class EffectResult { public: - explicit EffectResult( Entity::CharaPtr target, uint32_t delayMs ); + explicit EffectResult( Entity::CharaPtr target, uint64_t delayMs ); void damage( uint32_t amount, Common::ActionHitSeverityType severity ); void heal( uint32_t amount, Common::ActionHitSeverityType severity ); @@ -22,12 +22,16 @@ namespace Sapphire::World::Action uint32_t getValue() const; + uint64_t getDelay(); + void setParam( uint8_t param ); Common::EffectEntry buildEffectEntry() const; + void execute(); + private: - uint64_t m_runAfter; + uint64_t m_delayMs; Entity::CharaPtr m_target; diff --git a/src/world/Math/CalcStats.cpp b/src/world/Math/CalcStats.cpp index d6513a14..d9c6d143 100644 --- a/src/world/Math/CalcStats.cpp +++ b/src/world/Math/CalcStats.cpp @@ -462,7 +462,7 @@ float CalcStats::calcAutoAttackDamage( const Sapphire::Entity::Chara& chara ) { Logger::debug( format, pot, aa, ap, det, ten, factor ); } - + // todo: traits factor = std::floor( factor * speed( chara ) ); @@ -494,15 +494,15 @@ float CalcStats::calcActionDamage( const Sapphire::Entity::Chara& chara, uint32_ auto factor = std::floor( pot * wd * ap * det * ten ); - constexpr auto format = "dmg: pot: {} wd: {} ap: {} det: {} ten: {} = {}"; + constexpr auto format = "dmg: pot: {} ({}) wd: {} ({}) ap: {} det: {} ten: {} = {}"; if( auto player = const_cast< Entity::Chara& >( chara ).getAsPlayer() ) { - player->sendDebug( format, pot, wd, ap, det, ten, factor ); + player->sendDebug( format, pot, ptc, wd, wepDmg, ap, det, ten, factor ); } else { - Logger::debug( format, pot, wd, ap, det, ten, factor ); + Logger::debug( format, pot, ptc, wd, wepDmg, ap, det, ten, factor ); } // todo: the rest diff --git a/src/world/Territory/Territory.cpp b/src/world/Territory/Territory.cpp index c725e9bd..d8b1cf17 100644 --- a/src/world/Territory/Territory.cpp +++ b/src/world/Territory/Territory.cpp @@ -31,15 +31,15 @@ #include "Actor/SpawnPoint.h" #include "Actor/BNpcTemplate.h" +#include "Action/EffectResult.h" + #include "Network/GameConnection.h" #include "Script/ScriptMgr.h" -#include "Session.h" #include "ForwardsZone.h" #include "ServerMgr.h" #include "CellHandler.h" -#include "Territory.h" #include "Framework.h" #include "Manager/RNGMgr.h" @@ -486,6 +486,8 @@ bool Sapphire::Territory::update( uint64_t tickCount ) updateSpawnPoints(); + processEffectResults( tickCount ); + if( !m_playerMap.empty() ) m_lastActivityTime = tickCount; @@ -1006,7 +1008,7 @@ Sapphire::Entity::BNpcPtr Sapphire::Entity::BNpcPtr Sapphire::Territory::getActiveBNpcByLevelId( uint32_t levelId ) { - for( auto bnpcIt : m_bNpcMap ) + for( const auto& bnpcIt : m_bNpcMap ) { if( bnpcIt.second->getLevelId() == levelId ) return bnpcIt.second; @@ -1018,3 +1020,28 @@ std::shared_ptr< Sapphire::World::Navi::NaviProvider > Sapphire::Territory::getN { return m_pNaviProvider; } + +void Sapphire::Territory::addEffectResult( Sapphire::World::Action::EffectResultPtr result ) +{ + m_effectResults.emplace_back( std::move( result ) ); +} + +void Sapphire::Territory::processEffectResults( uint64_t tickCount ) + +{ + // todo: move this to generic territory/instance delay wrapper cause it might be useful scheduling other things + for( auto it = m_effectResults.begin(); it != m_effectResults.end(); ) + { + auto effect = *it; + + if( tickCount < effect->getDelay() ) + { + ++it; + continue; + } + + effect->execute(); + + it = m_effectResults.erase( it ); + } +} \ No newline at end of file diff --git a/src/world/Territory/Territory.h b/src/world/Territory/Territory.h index a73e5e53..34258d29 100644 --- a/src/world/Territory/Territory.h +++ b/src/world/Territory/Territory.h @@ -65,6 +65,8 @@ namespace Sapphire uint32_t m_effectCounter; std::shared_ptr< World::Navi::NaviProvider > m_pNaviProvider; + std::vector< World::Action::EffectResultPtr > m_effectResults; + public: Territory(); @@ -174,6 +176,10 @@ namespace Sapphire uint32_t getNextEffectSequence(); std::shared_ptr< World::Navi::NaviProvider > getNaviProvider(); + + void addEffectResult( World::Action::EffectResultPtr result ); + + void processEffectResults( uint64_t tickCount ); }; }