1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 06:27:45 +00:00

General cleanup and improvements of quest_parser

This commit is contained in:
mordred 2019-03-18 15:51:04 +01:00
parent 877b8153c2
commit c59b1df53b
6 changed files with 111 additions and 72 deletions

View file

@ -34,8 +34,6 @@ namespace Sapphire
m_pConfig = std::make_shared< ConfigMgr >();
}
ServerLobby::~ServerLobby( void ) = default;
LobbySessionPtr ServerLobby::getSession( char* sessionId )
{
return g_restConnector.getSession( sessionId );

View file

@ -34,7 +34,7 @@ namespace Sapphire
public:
ServerLobby( const std::string& configPath );
~ServerLobby( void );
~ServerLobby( void ) = default;
void run( int32_t argc, char* argv[] );

View file

@ -67,8 +67,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
std::string header(
"// This is an automatically generated C++ script template\n"
"// Content needs to be added by hand to make it function\n"
"// In order for this script to be loaded, change its extension to .cpp\n"
"// and move it to the correct folder in <root>/scripts/native/\n"
"// In order for this script to be loaded, move it to the correct folder in <root>/scripts/\n"
"\n"
"#include <ScriptObject.h>\n\n"
);
@ -99,10 +98,10 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
sceneName +
"( Entity::Player& player )\n"
" {\n"
" player.eventPlay( this->getId(), " +
" player.playScene( getId(), " +
sceneId +
", 0,\n"
" [&]( Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2, uint16_t param3 )\n"
" [ & ]( Entity::Player& player, const Event::SceneResult& result )\n"
" {\n"
" });\n"
" }\n\n"
@ -170,7 +169,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
if( !pQuestData->itemReward0.empty() )
{
rewards += " static constexpr auto RewardItem[] = { ";
rewards += " static constexpr auto RewardItem = { ";
for( size_t ca = 0; ca < pQuestData->itemReward0.size(); ca++ )
{
rewards += std::to_string( pQuestData->itemReward0.at( ca ) );
@ -184,7 +183,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
if( !pQuestData->itemReward0.empty() )
{
rewards += " static constexpr auto RewardItemCount[] = { ";
rewards += " static constexpr auto RewardItemCount = { ";
for( size_t ca = 0; ca < pQuestData->itemCountReward0.size(); ca++ )
{
rewards += std::to_string( pQuestData->itemCountReward0.at( ca ) );
@ -198,7 +197,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
if( !pQuestData->itemReward1.empty() )
{
rewards += " static constexpr auto RewardItemOptional[] = { ";
rewards += " static constexpr auto RewardItemOptional = { ";
for( size_t ca = 0; ca < pQuestData->itemReward1.size(); ca++ )
{
rewards += std::to_string( pQuestData->itemReward1.at( ca ) );
@ -212,7 +211,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
if( !pQuestData->itemCountReward1.empty() )
{
rewards += " static constexpr auto RewardItemOptionalCount[] = { ";
rewards += " static constexpr auto RewardItemOptionalCount = { ";
for( size_t ca = 0; ca < pQuestData->itemCountReward1.size(); ca++ )
{
rewards += std::to_string( pQuestData->itemCountReward1.at( ca ) );
@ -227,9 +226,13 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
bool hasERange = false;
bool hasEmote = false;
bool hasEnemies = false;
bool hasActions = false;
std::vector< uint32_t > enemy_ids;
std::vector< std::string > action_names;
std::vector< uint32_t > action_ids;
std::vector< std::string > script_entities;
std::string sentities = " // Entities found in the script data of the quest\n";
std::vector< std::string > enemy_strings;
for( size_t ca = 0; ca < pQuestData->scriptInstruction.size(); ca++ )
{
@ -245,8 +248,21 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
{
hasEnemies = true;
enemy_ids.push_back( pQuestData->scriptArg.at( ca ) );
enemy_strings.push_back( pQuestData->scriptInstruction.at( ca ) );
}
if( ( ( pQuestData->scriptInstruction.at( ca ).find( "ACTION0" ) != std::string::npos ) ||
( pQuestData->scriptInstruction.at( ca ).find( "ACTION1" ) != std::string::npos ) ||
( pQuestData->scriptInstruction.at( ca ).find( "ACTION2" ) != std::string::npos ) ) &&
pQuestData->scriptInstruction.at( ca ).find( "_ACTION" ) == std::string::npos &&
pQuestData->scriptInstruction.at( ca ).find( "EVENT" ) == std::string::npos )
{
hasActions = true;
action_ids.push_back( pQuestData->scriptArg.at( ca ) );
action_names.push_back( pQuestData->scriptInstruction.at( ca ) );
}
if( !pQuestData->scriptInstruction.at( ca ).empty() )
script_entities.push_back(
pQuestData->scriptInstruction.at( ca ) + " = " + std::to_string( pQuestData->scriptArg.at( ca ) ) );
@ -269,6 +285,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
additional += "// Start NPC: " + std::to_string( pQuestData->eNpcResidentStart ) + "\n";
additional += "// End NPC: " + std::to_string( pQuestData->eNpcResidentEnd ) + "\n\n";
std::string actionEntry;
std::string scriptEntry;
scriptEntry.reserve( 0xFFFF );
scriptEntry += " //////////////////////////////////////////////////////////////////////\n // Event Handlers\n";
@ -285,15 +302,38 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
scriptEntry += onEmoteStr;
}
for( auto enemy : enemy_ids )
{
if( !enemy_ids.empty() )
scriptEntry += std::string(
" void onMobKill_" + std::to_string( enemy ) + "( Entity::Player& player )\n"
" void onBNpcKill( uint32_t npcId, Entity::Player& player )\n"
" {\n"
" }\n\n"
);
" switch( npcId )\n"
" {\n" );
for( auto enemy : enemy_strings )
{
scriptEntry += " case " + enemy + ": { break; }\n";
}
if( !enemy_ids.empty() )
scriptEntry += std::string( " }\n"
" }\n" );
if( !action_ids.empty() )
actionEntry += std::string(
" void onEObjHit( uint32_t npcId, Entity::Player& player, uin32_t actionId )\n"
" {\n"
" switch( actionId )\n"
" {\n" );
for( auto action : action_names )
{
actionEntry += " case " + action + ": { break; }\n";
}
if( !action_ids.empty() )
actionEntry += std::string( " }\n"
" }\n" );
std::string constructor;
constructor += std::string(
" private:\n"
@ -303,15 +343,17 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
constructor += rewards + "\n";
constructor += sentities + "\n";
constructor += " public:\n";
constructor += " " + className + "() : EventScript" + "( " + std::to_string( questId ) + " ){}; \n";
constructor += " ~" + className + "(){}; \n";
constructor += " " + className + "() : Sapphire::ScriptAPI::EventScript" + "( " + std::to_string( questId ) + " ){}; \n";
constructor += " ~" + className + "() = default; \n";
std::string classString(
"class " + className + " : public EventScript\n"
"class " + className + " : public Sapphire::ScriptAPI::EventScript\n"
"{\n" +
constructor +
"\n" +
scriptEntry +
"\n" +
actionEntry +
" private:\n" +
sceneStr +
"};\n\nEXPOSE_SCRIPT( " + className + " );"
@ -332,7 +374,9 @@ int main( int argc, char** argv )
bool unluac = false;
// std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" );
//std::string datLocation( "C:/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack" );
std::string datLocation( "C:/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack" );
//std::string datLocation( "C:/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack" );
std::string datLocation( "/home/mordred/sqpack" );
if( argc > 1 )
datLocation = std::string( argv[ 1 ] );
if( argc > 2 )

View file

@ -18,8 +18,6 @@
#define GetRelatCoord( Coord, CellCoord ) ((_maxX-Coord)-CellCoord*_cellSize)
namespace Sapphire {
class Zone;
template< class T >
class CellHandler
{

View file

@ -48,6 +48,7 @@ namespace Sapphire
Common::Weather m_currentWeather;
Common::Weather m_weatherOverride;
std::map< uint8_t, int32_t > m_weatherRateMap;
int64_t m_lastMobUpdate;
@ -55,8 +56,6 @@ namespace Sapphire
std::shared_ptr< Data::TerritoryType > m_territoryTypeInfo;
std::map< uint8_t, int32_t > m_weatherRateMap;
uint32_t m_nextEObjId;
uint32_t m_nextActorId;
FrameworkPtr m_pFw;