-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #916 from hkAlice/bs-stuff
[3.x - EncounterFight] add prototype encounterfight, encounterstate, ifrit normal;
- Loading branch information
Showing
12 changed files
with
405 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#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; | ||
uint64_t m_startTime{ 0 }; | ||
|
||
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( uint64_t 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( uint64_t deltaTime ) = 0; | ||
virtual void reset() = 0; | ||
|
||
virtual void addState( EncounterState::EncounterStatePtr pState, bool initState = true ) = 0; | ||
virtual void addBNpc( Entity::BNpcPtr pBNpc ) = 0; | ||
virtual void removeBNpc( uint32_t layoutId ) = 0; | ||
virtual Entity::BNpcPtr getBNpc( uint32_t layoutId ) = 0; | ||
|
||
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; | ||
InstanceContentPtr m_pInstance; | ||
EncounterFightStatus m_status{ EncounterFightStatus::IDLE }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
#include <Encounter/EncounterFight.h> | ||
|
||
namespace Sapphire | ||
{ | ||
class IfritNormalData | ||
{ | ||
public: | ||
static constexpr int IFRIT = 4126276; | ||
static constexpr int HELLFIRE = 0; | ||
}; | ||
|
||
class IfritStateTwo : public EncounterState | ||
{ | ||
public: | ||
IfritStateTwo( EncounterFightPtr pEncounter ) : EncounterState( pEncounter ) | ||
{ | ||
} | ||
|
||
void init() override | ||
{ | ||
Logger::info( "stage 2 init" ); | ||
} | ||
|
||
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( "stage 1 init" ); | ||
} | ||
|
||
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 > 12000 ) | ||
{ | ||
pIfrit->hateListGetHighest()->die(); | ||
} | ||
} | ||
|
||
void finish() override | ||
{ | ||
|
||
} | ||
}; | ||
|
||
class IfritEncounterFight : public EncounterFight | ||
{ | ||
public: | ||
IfritEncounterFight( InstanceContentPtr pInstance ) : EncounterFight( pInstance ) | ||
{ | ||
|
||
}; | ||
|
||
void init() override | ||
{ | ||
m_status = EncounterFightStatus::IDLE; | ||
m_startTime = 0; | ||
|
||
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 ); | ||
|
||
m_status = EncounterFightStatus::ACTIVE; | ||
} | ||
|
||
void update( uint64_t deltaTime ) override | ||
{ | ||
// todo: better way to start fights here.. | ||
|
||
auto ifrit = getBNpc( IfritNormalData::IFRIT ); | ||
|
||
if( ifrit; ifrit->hateListGetHighestValue() != 0 && m_status == EncounterFightStatus::IDLE ) | ||
{ | ||
m_startTime = deltaTime; | ||
start(); | ||
} | ||
|
||
if( m_status == EncounterFightStatus::ACTIVE && ifrit && !ifrit->hateListGetHighest()->isAlive() ) | ||
{ | ||
m_status = EncounterFightStatus::FAIL; | ||
} | ||
|
||
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 ); | ||
if( boss ) | ||
{ | ||
removeBNpc( 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; | ||
|
||
return nullptr; | ||
} | ||
|
||
void removeBNpc( uint32_t layoutId ) override | ||
{ | ||
m_bnpcs.erase( layoutId ); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,6 +290,5 @@ namespace Sapphire::ScriptAPI | |
uint16_t param1, uint16_t param2 ) | ||
{ | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.