1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 08:27:46 +00:00

add encounter to instancecontent; basic status handling;

This commit is contained in:
Alice Ogeda 2023-03-08 14:15:13 -03:00
parent 5217a474a5
commit e3a140da40
4 changed files with 54 additions and 5 deletions

View file

@ -58,6 +58,7 @@ namespace Sapphire
virtual void addState( EncounterState::EncounterStatePtr pState, bool initState = true ) = 0; virtual void addState( EncounterState::EncounterStatePtr pState, bool initState = true ) = 0;
virtual void addBNpc( Entity::BNpcPtr pBNpc ) = 0; virtual void addBNpc( Entity::BNpcPtr pBNpc ) = 0;
virtual void removeBNpc( uint32_t layoutId ) = 0;
virtual Entity::BNpcPtr getBNpc( uint32_t layoutId ) = 0; virtual Entity::BNpcPtr getBNpc( uint32_t layoutId ) = 0;
virtual EncounterFightStatus getEncounterFightStatus() const = 0; virtual EncounterFightStatus getEncounterFightStatus() const = 0;

View file

@ -95,6 +95,20 @@ namespace Sapphire
void update( double deltaTime ) override void update( double deltaTime ) override
{ {
// todo: better way to start fights here..
auto ifrit = getBNpc( IfritNormalData::IFRIT );
if( ifrit; ifrit->hateListGetHighestValue() != 0 && m_status == EncounterFightStatus::IDLE )
{
start();
}
if( m_status == EncounterFightStatus::ACTIVE && ifrit && !ifrit->hateListGetHighest()->isAlive() )
{
m_status = EncounterFightStatus::FAIL;
}
if( m_stateStack; !m_stateStack->empty() ) if( m_stateStack; !m_stateStack->empty() )
{ {
if( m_stateStack->top()->shouldFinish() ) if( m_stateStack->top()->shouldFinish() )
@ -110,7 +124,13 @@ namespace Sapphire
void reset() override void reset() override
{ {
auto boss = m_pInstance->getActiveBNpcByLayoutId( IfritNormalData::IFRIT ); auto boss = m_pInstance->getActiveBNpcByLayoutId( IfritNormalData::IFRIT );
m_pInstance->removeActor( boss ); if( boss )
{
removeBNpc( IfritNormalData::IFRIT );
m_pInstance->removeActor( boss );
}
init(); init();
} }
@ -131,5 +151,10 @@ namespace Sapphire
if( bnpc != std::end( m_bnpcs ) ) if( bnpc != std::end( m_bnpcs ) )
return bnpc->second; return bnpc->second;
} }
void removeBNpc( uint32_t layoutId ) override
{
m_bnpcs.erase( layoutId );
}
}; };
} }

View file

@ -28,6 +28,8 @@
#include "InstanceContent.h" #include "InstanceContent.h"
#include "InstanceObjectCache.h" #include "InstanceObjectCache.h"
#include <Encounter/InstanceContent/IfritNormal.h>
using namespace Sapphire::Common; using namespace Sapphire::Common;
using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets;
@ -67,6 +69,11 @@ bool Sapphire::InstanceContent::init()
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref(); auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
scriptMgr.onInstanceInit( *this ); scriptMgr.onInstanceInit( *this );
// todo: every fight is now ifrit
m_pEncounter = std::make_shared< IfritEncounterFight >( std::dynamic_pointer_cast< InstanceContent, Territory >( shared_from_this() ) );
m_pEncounter->init();
return true; return true;
} }
@ -137,10 +144,10 @@ void Sapphire::InstanceContent::onUpdate( uint64_t tickCount )
if( it == m_playerMap.end() ) if( it == m_playerMap.end() )
return; return;
auto player = it->second; auto pPlayer = it->second;
if( !player->isLoadingComplete() || if( !pPlayer->isLoadingComplete() ||
!player->isDirectorInitialized() || !pPlayer->isDirectorInitialized() ||
player->hasCondition( PlayerCondition::WatchingCutscene ) ) pPlayer->hasCondition( PlayerCondition::WatchingCutscene ) )
return; return;
} }
@ -158,12 +165,20 @@ void Sapphire::InstanceContent::onUpdate( uint64_t tickCount )
if( m_pEntranceEObj ) if( m_pEntranceEObj )
m_pEntranceEObj->setPermissionInvisibility( 1 ); m_pEntranceEObj->setPermissionInvisibility( 1 );
m_state = DutyInProgress; m_state = DutyInProgress;
// todo: also yucky, should be init
m_pEncounter->reset();
break; break;
} }
case DutyReset: case DutyReset:
{
// todo: revive players if trial/enclosed raid arena, add reset timer
m_instanceCommenceTime = 0;
m_state = Created;
break; break;
}
case DutyInProgress: case DutyInProgress:
{ {
@ -178,6 +193,9 @@ void Sapphire::InstanceContent::onUpdate( uint64_t tickCount )
m_instanceTerminate = true; m_instanceTerminate = true;
updateBNpcs( tickCount ); updateBNpcs( tickCount );
if( m_pEncounter->getEncounterFightStatus() == EncounterFightStatus::FAIL )
m_state = DutyReset;
break; break;
} }
@ -215,6 +233,8 @@ void Sapphire::InstanceContent::onUpdate( uint64_t tickCount )
auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref(); auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref();
scriptMgr.onInstanceUpdate( *this, tickCount ); scriptMgr.onInstanceUpdate( *this, tickCount );
m_pEncounter->update( tickCount );
m_lastUpdate = tickCount; m_lastUpdate = tickCount;
} }

View file

@ -5,6 +5,7 @@
#include "Event/Director.h" #include "Event/Director.h"
#include "Forwards.h" #include "Forwards.h"
#include <Exd/Structs.h> #include <Exd/Structs.h>
#include <memory>
namespace Sapphire namespace Sapphire
{ {
@ -214,6 +215,8 @@ namespace Sapphire
// the players which are bound to the instance, regardless of inside or offline // the players which are bound to the instance, regardless of inside or offline
std::set< uint32_t > m_boundPlayerIds; std::set< uint32_t > m_boundPlayerIds;
EncounterFightPtr m_pEncounter;
}; };
} }