1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 14:07:46 +00:00

More groundwork for questbattles

This commit is contained in:
Mordred 2019-03-31 11:27:11 +02:00
parent 1b86b87503
commit d55ae2c8c0
9 changed files with 239 additions and 179 deletions

View file

@ -102,12 +102,12 @@ uint32_t Sapphire::Entity::EventObject::getHousingLink() const
return m_housingLink;
}
void Sapphire::Entity::EventObject::setParentInstance( Sapphire::InstanceContentPtr instance )
void Sapphire::Entity::EventObject::setParentInstance( Sapphire::ZonePtr instance )
{
m_parentInstance = instance;
}
Sapphire::InstanceContentPtr Sapphire::Entity::EventObject::getParentInstance() const
Sapphire::ZonePtr Sapphire::Entity::EventObject::getParentInstance() const
{
return m_parentInstance;
}

View file

@ -13,7 +13,7 @@ namespace Sapphire::Entity
Common::FFXIVARR_POSITION3 pos, float rotation, const std::string& givenName = "none" );
using OnTalkEventHandler = std::function< void( Entity::Player&, Entity::EventObjectPtr,
InstanceContentPtr, uint64_t ) >;
ZonePtr, uint64_t ) >;
uint32_t getGimmickId() const;
@ -35,9 +35,9 @@ namespace Sapphire::Entity
const std::string& getName() const;
InstanceContentPtr getParentInstance() const;
ZonePtr getParentInstance() const;
void setParentInstance( InstanceContentPtr instance );
void setParentInstance( ZonePtr instance );
void spawn( PlayerPtr pTarget ) override;
@ -56,7 +56,7 @@ namespace Sapphire::Entity
uint8_t m_state;
float m_scale;
std::string m_name;
InstanceContentPtr m_parentInstance;
ZonePtr m_parentInstance;
OnTalkEventHandler m_onTalkEventHandler;

View file

@ -5,6 +5,7 @@
#include "Territory/Zone.h"
#include "Territory/InstanceContent.h"
#include "Territory/QuestBattle.h"
#include "Actor/Player.h"
#include "Actor/EventObject.h"
#include "ServerMgr.h"
@ -461,6 +462,44 @@ bool Sapphire::Scripting::ScriptMgr::onInstanceEnterTerritory( InstanceContentPt
return false;
}
bool Sapphire::Scripting::ScriptMgr::onInstanceInit( QuestBattlePtr instance )
{
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestBattleScript >( instance->getDirectorId() );
if( script )
{
script->onInit( *instance );
return true;
}
return false;
}
bool Sapphire::Scripting::ScriptMgr::onInstanceUpdate( QuestBattlePtr instance, uint32_t currTime )
{
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestBattleScript >( instance->getDirectorId() );
if( script )
{
script->onUpdate( *instance, currTime );
return true;
}
return false;
}
bool Sapphire::Scripting::ScriptMgr::onInstanceEnterTerritory( QuestBattlePtr instance, Entity::Player& player,
uint32_t eventId, uint16_t param1, uint16_t param2 )
{
auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestBattleScript >( instance->getDirectorId() );
if( script )
{
script->onEnterTerritory( *instance, player, eventId, param1, param2 );
return true;
}
return false;
}
Sapphire::Scripting::NativeScriptMgr& Sapphire::Scripting::ScriptMgr::getNativeScriptHandler()
{
return *m_nativeScriptMgr;

View file

@ -100,6 +100,13 @@ namespace Sapphire::Scripting
onInstanceEnterTerritory( InstanceContentPtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1,
uint16_t param2 );
bool onInstanceInit( QuestBattlePtr instance );
bool onInstanceUpdate( QuestBattlePtr instance, uint32_t currTime );
bool onInstanceEnterTerritory( QuestBattlePtr instance, Entity::Player& player, uint32_t eventId, uint16_t param1,
uint16_t param2 );
bool loadDir( const std::string& dirname, std::set< std::string >& files, const std::string& ext );
NativeScriptMgr& getNativeScriptHandler();

View file

@ -5,116 +5,119 @@
#include "Event/Director.h"
#include "Forwards.h"
namespace Sapphire {
namespace Data {
struct InstanceContent;
}
class InstanceContent : public Event::Director, public Zone
namespace Sapphire::Data
{
public:
enum InstanceContentState
struct InstanceContent;
}
namespace Sapphire
{
class InstanceContent : public Event::Director, public Zone
{
Created,
DutyReset,
DutyInProgress,
DutyFinished
public:
enum InstanceContentState
{
Created,
DutyReset,
DutyInProgress,
DutyFinished
};
InstanceContent( std::shared_ptr< Sapphire::Data::InstanceContent > pInstanceConfiguration,
uint16_t territoryType,
uint32_t guId,
const std::string& internalName,
const std::string& contentName,
uint32_t instanceContentId,
FrameworkPtr pFw );
virtual ~InstanceContent();
bool init() override;
void onBeforePlayerZoneIn( Entity::Player& player ) override;
void onPlayerZoneIn( Entity::Player& player ) override;
void onLeaveTerritory( Entity::Player& player ) override;
void onFinishLoading( Entity::Player& player ) override;
void onInitDirector( Entity::Player& player ) override;
void onDirectorSync( Entity::Player& player ) override;
void onUpdate( uint32_t currTime ) override;
void onTalk( Entity::Player& player, uint32_t eventId, uint64_t actorId );
void onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override;
void onRegisterEObj( Entity::EventObjectPtr object ) override;
void setVar( uint8_t index, uint8_t value );
void setSequence( uint8_t value );
void setBranch( uint8_t value );
void startQte();
void startEventCutscene();
void endEventCutscene();
void clearDirector( Entity::Player& player );
/*! set the current bgm index (inside bgm.exd) */
void setCurrentBGM( uint16_t bgmId );
/*! set the current bgm for a specific player */
void setPlayerBGM( Entity::Player& player, uint16_t bgmId );
/*! get the currently playing bgm index */
uint16_t getCurrentBGM() const;
bool hasPlayerPreviouslySpawned( Entity::Player& player ) const;
InstanceContentState getState() const;
std::shared_ptr< Sapphire::Data::InstanceContent > getInstanceConfiguration() const;
uint32_t getInstanceContentId() const;
Entity::EventObjectPtr getEObjByName( const std::string& name );
/*! binds a player to the instance */
bool bindPlayer( uint32_t playerId );
/*! removes bind of player from the instance */
void unbindPlayer( uint32_t playerId );
/*! return true if the player is bound to the instance */
bool isPlayerBound( uint32_t playerId ) const;
/*! number of milliseconds after all players are ready for the instance to commence (spawn circle removed) */
const uint32_t instanceStartDelay = 1250;
private:
std::shared_ptr< Sapphire::Data::InstanceContent > m_instanceConfiguration;
uint32_t m_instanceContentId;
InstanceContentState m_state;
uint16_t m_currentBgm;
int64_t m_instanceExpireTime;
uint64_t m_instanceCommenceTime;
Entity::EventObjectPtr m_pEntranceEObj;
std::map< std::string, Entity::EventObjectPtr > m_eventObjectMap;
std::unordered_map< uint32_t, Entity::EventObjectPtr > m_eventIdToObjectMap;
std::set< uint32_t > m_spawnedPlayers;
// the players which are bound to the instance, regardless of inside or offline
std::set< uint32_t > m_boundPlayerIds;
};
InstanceContent( std::shared_ptr< Sapphire::Data::InstanceContent > pInstanceConfiguration,
uint16_t territoryType,
uint32_t guId,
const std::string& internalName,
const std::string& contentName,
uint32_t instanceContentId,
FrameworkPtr pFw );
virtual ~InstanceContent();
bool init() override;
void onBeforePlayerZoneIn( Entity::Player& player ) override;
void onPlayerZoneIn( Entity::Player& player ) override;
void onLeaveTerritory( Entity::Player& player ) override;
void onFinishLoading( Entity::Player& player ) override;
void onInitDirector( Entity::Player& player ) override;
void onDirectorSync( Entity::Player& player ) override;
void onUpdate( uint32_t currTime ) override;
void onTalk( Entity::Player& player, uint32_t eventId, uint64_t actorId );
void onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override;
void onRegisterEObj( Entity::EventObjectPtr object ) override;
void setVar( uint8_t index, uint8_t value );
void setSequence( uint8_t value );
void setBranch( uint8_t value );
void startQte();
void startEventCutscene();
void endEventCutscene();
void clearDirector( Entity::Player& player );
/*! set the current bgm index (inside bgm.exd) */
void setCurrentBGM( uint16_t bgmId );
/*! set the current bgm for a specific player */
void setPlayerBGM( Entity::Player& player, uint16_t bgmId );
/*! get the currently playing bgm index */
uint16_t getCurrentBGM() const;
bool hasPlayerPreviouslySpawned( Entity::Player& player ) const;
InstanceContentState getState() const;
std::shared_ptr< Sapphire::Data::InstanceContent > getInstanceConfiguration() const;
uint32_t getInstanceContentId() const;
Entity::EventObjectPtr getEObjByName( const std::string& name );
/*! binds a player to the instance */
bool bindPlayer( uint32_t playerId );
/*! removes bind of player from the instance */
void unbindPlayer( uint32_t playerId );
/*! return true if the player is bound to the instance */
bool isPlayerBound( uint32_t playerId ) const;
/*! number of milliseconds after all players are ready for the instance to commence (spawn circle removed) */
const uint32_t instanceStartDelay = 1250;
private:
std::shared_ptr< Sapphire::Data::InstanceContent > m_instanceConfiguration;
uint32_t m_instanceContentId;
InstanceContentState m_state;
uint16_t m_currentBgm;
int64_t m_instanceExpireTime;
uint64_t m_instanceCommenceTime;
Entity::EventObjectPtr m_pEntranceEObj;
std::map< std::string, Entity::EventObjectPtr > m_eventObjectMap;
std::unordered_map< uint32_t, Entity::EventObjectPtr > m_eventIdToObjectMap;
std::set< uint32_t > m_spawnedPlayers;
// the players which are bound to the instance, regardless of inside or offline
std::set< uint32_t > m_boundPlayerIds;
};
}
#endif //SAPPHIRE_INSTANCECONTENT_H

View file

@ -48,7 +48,7 @@ Sapphire::QuestBattle::QuestBattle( std::shared_ptr< Sapphire::Data::QuestBattle
bool Sapphire::QuestBattle::init()
{
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
pScriptMgr->onInstanceInit( getAsInstanceContent() );
pScriptMgr->onInstanceInit( getAsQuestBattle() );
return true;
}
@ -152,7 +152,7 @@ void Sapphire::QuestBattle::onUpdate( uint32_t currTime )
}
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
pScriptMgr->onInstanceUpdate( getAsInstanceContent(), currTime );
pScriptMgr->onInstanceUpdate( getAsQuestBattle(), currTime );
}
void Sapphire::QuestBattle::onFinishLoading( Entity::Player& player )
@ -348,8 +348,8 @@ void Sapphire::QuestBattle::onTalk( Sapphire::Entity::Player& player, uint32_t e
if( it == m_eventIdToObjectMap.end() )
return;
if( auto onTalk = it->second->getOnTalkHandler() )
onTalk( player, it->second, getAsInstanceContent(), actorId );
if( auto onTalkHandler = it->second->getOnTalkHandler() )
onTalkHandler( player, it->second, getAsQuestBattle(), actorId );
else
player.sendDebug( "No onTalk handler found for interactable eobj with EObjID#{0}, eventId#{1} ",
it->second->getObjectId(), eventId );
@ -359,7 +359,7 @@ void
Sapphire::QuestBattle::onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 )
{
auto pScriptMgr = m_pFw->get< Scripting::ScriptMgr >();
pScriptMgr->onInstanceEnterTerritory( getAsInstanceContent(), player, eventId, param1, param2 );
pScriptMgr->onInstanceEnterTerritory( getAsQuestBattle(), player, eventId, param1, param2 );
// TODO: this may or may not be correct for questbattles
player.directorPlayScene( getDirectorId(), 1, NO_DEFAULT_CAMERA | CONDITION_CUTSCENE | SILENT_ENTER_TERRI_ENV |

View file

@ -5,104 +5,107 @@
#include "Event/Director.h"
#include "Forwards.h"
namespace Sapphire {
namespace Data {
namespace Sapphire::Data
{
struct QuestBattle;
}
class QuestBattle : public Event::Director, public Zone
namespace Sapphire
{
public:
QuestBattle( std::shared_ptr< Sapphire::Data::QuestBattle > pBattleDetails,
uint16_t territoryType,
uint32_t guId,
const std::string& internalName,
const std::string& contentName,
uint32_t questBattleId,
FrameworkPtr pFw );
class QuestBattle : public Event::Director, public Zone
{
public:
QuestBattle( std::shared_ptr< Sapphire::Data::QuestBattle > pBattleDetails,
uint16_t territoryType,
uint32_t guId,
const std::string& internalName,
const std::string& contentName,
uint32_t questBattleId,
FrameworkPtr pFw );
virtual ~QuestBattle();
virtual ~QuestBattle();
bool init() override;
bool init() override;
void onBeforePlayerZoneIn( Entity::Player& player ) override;
void onBeforePlayerZoneIn( Entity::Player& player ) override;
void onPlayerZoneIn( Entity::Player& player ) override;
void onPlayerZoneIn( Entity::Player& player ) override;
void onLeaveTerritory( Entity::Player& player ) override;
void onLeaveTerritory( Entity::Player& player ) override;
void onFinishLoading( Entity::Player& player ) override;
void onFinishLoading( Entity::Player& player ) override;
void onInitDirector( Entity::Player& player ) override;
void onInitDirector( Entity::Player& player ) override;
void onDirectorSync( Entity::Player& player ) override;
void onDirectorSync( Entity::Player& player ) override;
void onUpdate( uint32_t currTime ) override;
void onUpdate( uint32_t currTime ) override;
void onTalk( Entity::Player& player, uint32_t eventId, uint64_t actorId );
void onTalk( Entity::Player& player, uint32_t eventId, uint64_t actorId );
void onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override;
void onEnterTerritory( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override;
void onRegisterEObj( Entity::EventObjectPtr object ) override;
void onRegisterEObj( Entity::EventObjectPtr object ) override;
void setVar( uint8_t index, uint8_t value );
void setVar( uint8_t index, uint8_t value );
void setSequence( uint8_t value );
void setSequence( uint8_t value );
void setBranch( uint8_t value );
void setBranch( uint8_t value );
void startQte();
void startQte();
void startEventCutscene();
void startEventCutscene();
void endEventCutscene();
void endEventCutscene();
void clearDirector( Entity::Player& player );
void clearDirector( Entity::Player& player );
/*! set the current bgm index (inside bgm.exd) */
void setCurrentBGM( uint16_t bgmId );
/*! set the current bgm index (inside bgm.exd) */
void setCurrentBGM( uint16_t bgmId );
/*! set the current bgm for a specific player */
void setPlayerBGM( Entity::Player& player, uint16_t bgmId );
/*! set the current bgm for a specific player */
void setPlayerBGM( Entity::Player& player, uint16_t bgmId );
/*! get the currently playing bgm index */
uint16_t getCurrentBGM() const;
/*! get the currently playing bgm index */
uint16_t getCurrentBGM() const;
Event::Director::DirectorState getState() const;
Event::Director::DirectorState getState() const;
std::shared_ptr< Sapphire::Data::QuestBattle > getQuestBattleDetails() const;
std::shared_ptr< Sapphire::Data::QuestBattle > getQuestBattleDetails() const;
uint32_t getQuestBattleId() const;
uint32_t getQuestBattleId() const;
Entity::EventObjectPtr getEObjByName( const std::string& name );
Entity::EventObjectPtr getEObjByName( const std::string& name );
/*! binds a player to the instance */
bool bindPlayer( uint32_t playerId );
/*! binds a player to the instance */
bool bindPlayer( uint32_t playerId );
/*! removes bind of player from the instance */
void unbindPlayer( uint32_t playerId );
/*! removes bind of player from the instance */
void unbindPlayer( uint32_t playerId );
/*! return true if the player is bound to the instance */
bool isPlayerBound( uint32_t playerId ) const;
/*! return true if the player is bound to the instance */
bool isPlayerBound( uint32_t playerId ) const;
/*! number of milliseconds after all players are ready for the instance to commence (spawn circle removed) */
const uint32_t instanceStartDelay = 1250;
/*! number of milliseconds after all players are ready for the instance to commence (spawn circle removed) */
const uint32_t instanceStartDelay = 1250;
private:
std::shared_ptr< Sapphire::Data::QuestBattle > m_pBattleDetails;
uint32_t m_questBattleId;
Event::Director::DirectorState m_state;
uint16_t m_currentBgm;
private:
std::shared_ptr< Sapphire::Data::QuestBattle > m_pBattleDetails;
uint32_t m_questBattleId;
Event::Director::DirectorState m_state;
uint16_t m_currentBgm;
int64_t m_instanceExpireTime;
uint64_t m_instanceCommenceTime;
int64_t m_instanceExpireTime;
uint64_t m_instanceCommenceTime;
std::map< std::string, Entity::EventObjectPtr > m_eventObjectMap;
std::unordered_map< uint32_t, Entity::EventObjectPtr > m_eventIdToObjectMap;
std::set< uint32_t > m_spawnedPlayers;
std::map< std::string, Entity::EventObjectPtr > m_eventObjectMap;
std::unordered_map< uint32_t, Entity::EventObjectPtr > m_eventIdToObjectMap;
std::set< uint32_t > m_spawnedPlayers;
// the players which are bound to the instance, regardless of inside or offline
std::set< uint32_t > m_boundPlayerIds;
};
// the players which are bound to the instance, regardless of inside or offline
std::set< uint32_t > m_boundPlayerIds;
};
}
#endif

View file

@ -17,6 +17,7 @@
#include "Zone.h"
#include "InstanceContent.h"
#include "QuestBattle.h"
#include "Manager/TerritoryMgr.h"
#include "Session.h"
@ -749,6 +750,11 @@ Sapphire::InstanceContentPtr Sapphire::Zone::getAsInstanceContent()
return std::dynamic_pointer_cast< InstanceContent, Zone >( shared_from_this() );
}
Sapphire::QuestBattlePtr Sapphire::Zone::getAsQuestBattle()
{
return std::dynamic_pointer_cast< QuestBattle, Zone >( shared_from_this() );
}
uint32_t Sapphire::Zone::getNextEObjId()
{
return ++m_nextEObjId;

View file

@ -161,6 +161,8 @@ namespace Sapphire
InstanceContentPtr getAsInstanceContent();
QuestBattlePtr getAsQuestBattle();
void updateSpawnPoints();
uint32_t getNextEffectSequence();