mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-28 15:17:46 +00:00
add EncounterFight, EncounterState; add example ifritnormal;
This commit is contained in:
parent
c3107b8d53
commit
f8b0cfb05b
2 changed files with 203 additions and 0 deletions
72
src/world/Encounter/EncounterFight.h
Normal file
72
src/world/Encounter/EncounterFight.h
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include <memory>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
#include <Territory/InstanceContent.h>
|
||||
#include <Logging/Logger.h>
|
||||
#include <Actor/BNpc.h>
|
||||
|
||||
namespace Sapphire
|
||||
{
|
||||
class EncounterState
|
||||
{
|
||||
public:
|
||||
using EncounterStatePtr = std::shared_ptr< EncounterState >;
|
||||
using StateStack = std::stack< EncounterStatePtr >;
|
||||
using StateStackPtr = std::shared_ptr< StateStack >;
|
||||
|
||||
protected:
|
||||
bool m_bShouldFinish{ false };
|
||||
StateStackPtr m_stateStack;
|
||||
std::shared_ptr< EncounterFight > m_pEncounter;
|
||||
|
||||
public:
|
||||
EncounterState( std::shared_ptr< EncounterFight > pEncounter ) :
|
||||
m_pEncounter( pEncounter )
|
||||
{
|
||||
};
|
||||
|
||||
virtual ~EncounterState() = default;
|
||||
bool shouldFinish() { return m_bShouldFinish; };
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void update( double deltaTime ) = 0;
|
||||
|
||||
virtual void finish() = 0;
|
||||
};
|
||||
|
||||
enum class EncounterFightStatus
|
||||
{
|
||||
IDLE,
|
||||
ACTIVE,
|
||||
FAIL,
|
||||
SUCCESS
|
||||
};
|
||||
|
||||
class EncounterFight : public std::enable_shared_from_this< EncounterFight >
|
||||
{
|
||||
public:
|
||||
EncounterFight( InstanceContentPtr pInstance ) :
|
||||
m_pInstance( pInstance )
|
||||
{
|
||||
};
|
||||
virtual ~EncounterFight() = default;
|
||||
|
||||
virtual void init() = 0;
|
||||
virtual void start() = 0;
|
||||
virtual void update( double deltaTime ) = 0;
|
||||
virtual void reset() = 0;
|
||||
|
||||
virtual void addState( EncounterState::EncounterStatePtr pState, bool initState = true ) = 0;
|
||||
virtual void addBNpc( Entity::BNpcPtr pBNpc ) = 0;
|
||||
virtual Entity::BNpcPtr getBNpc( uint32_t layoutId ) = 0;
|
||||
|
||||
virtual EncounterFightStatus getEncounterFightStatus() const = 0;
|
||||
|
||||
protected:
|
||||
EncounterState::StateStackPtr m_stateStack;
|
||||
std::set< Entity::PlayerPtr > m_playerList;
|
||||
std::unordered_map< uint32_t, Entity::BNpcPtr > m_bnpcs;
|
||||
InstanceContentPtr m_pInstance;
|
||||
EncounterFightStatus m_status;
|
||||
};
|
||||
}
|
131
src/world/Encounter/InstanceContent/IfritNormal.cpp
Normal file
131
src/world/Encounter/InstanceContent/IfritNormal.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
#include <Encounter/EncounterFight.h>
|
||||
|
||||
namespace Sapphire
|
||||
{
|
||||
class IfritNormalData
|
||||
{
|
||||
public:
|
||||
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 <blink>EUNUCH ONLY</blink>" );
|
||||
}
|
||||
|
||||
void update( double deltaTime ) override
|
||||
{
|
||||
auto pIfrit = m_pEncounter->getBNpc( IfritNormalData::IFRIT );
|
||||
}
|
||||
|
||||
void finish() override
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class IfritStateTwo : public EncounterState
|
||||
{
|
||||
public:
|
||||
IfritStateTwo( EncounterFightPtr pEncounter ) : EncounterState( pEncounter )
|
||||
{
|
||||
}
|
||||
|
||||
void init() override
|
||||
{
|
||||
Logger::info( "ifrit FAN CLUB GEOcities <blink>EUNUCH ONLY</blink>" );
|
||||
}
|
||||
|
||||
void update( double deltaTime ) override
|
||||
{
|
||||
auto pIfrit = m_pEncounter->getBNpc( IfritNormalData::IFRIT );
|
||||
}
|
||||
|
||||
void finish() override
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class IfritEncounterFight : public EncounterFight
|
||||
{
|
||||
public:
|
||||
IfritEncounterFight( InstanceContentPtr pInstance ) : EncounterFight( pInstance )
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void init() override
|
||||
{
|
||||
m_stateStack = std::make_shared< EncounterState::StateStack >();
|
||||
|
||||
// todo: i don't like this
|
||||
auto boss = m_pInstance->createBNpcFromLayoutId( IfritNormalData::IFRIT, 13884, Common::BNpcType::Enemy );
|
||||
addBNpc( boss );
|
||||
|
||||
//instance.sendForward();
|
||||
/*
|
||||
auto ifritStateTwo = std::make_shared< IfritStateTwo >( m_stateStack );
|
||||
m_stateStack->push( ifritStateTwo );*/
|
||||
}
|
||||
|
||||
void addState( EncounterState::EncounterStatePtr pState, bool initState = true ) override
|
||||
{
|
||||
m_stateStack->push( pState );
|
||||
if( initState )
|
||||
pState->init();
|
||||
}
|
||||
|
||||
void start() override
|
||||
{
|
||||
auto ifritInitState = std::make_shared< IfritStateOne >( shared_from_this() );
|
||||
addState( ifritInitState );
|
||||
}
|
||||
|
||||
void update( double deltaTime ) override
|
||||
{
|
||||
if( m_stateStack; !m_stateStack->empty() )
|
||||
{
|
||||
if( m_stateStack->top()->shouldFinish() )
|
||||
{
|
||||
m_stateStack->top()->finish();
|
||||
m_stateStack->pop();
|
||||
}
|
||||
|
||||
m_stateStack->top()->update( deltaTime );
|
||||
}
|
||||
}
|
||||
|
||||
void reset() override
|
||||
{
|
||||
auto boss = m_pInstance->getActiveBNpcByLayoutId( IfritNormalData::IFRIT );
|
||||
m_pInstance->removeActor( boss );
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
EncounterFightStatus getEncounterFightStatus() const override
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
|
||||
void addBNpc( Entity::BNpcPtr pBNpc ) override
|
||||
{
|
||||
m_bnpcs[ pBNpc->getLayoutId() ] = pBNpc;
|
||||
}
|
||||
|
||||
Entity::BNpcPtr getBNpc( uint32_t layoutId ) override
|
||||
{
|
||||
auto bnpc = m_bnpcs.find( layoutId );
|
||||
if( bnpc != std::end( m_bnpcs ) )
|
||||
return bnpc->second;
|
||||
}
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue