1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-06-29 18:07:45 +00:00

First revision of quest_parse

This commit is contained in:
Dantestyle 2019-01-06 01:00:35 +01:00
parent df412bba66
commit 40743986c3

View file

@ -27,7 +27,8 @@ using namespace Sapphire;
const std::string onTalkStr( const std::string onTalkStr(
" void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override\n" " void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override\n"
" {\n" " {\n"
" auto actor = Event::mapEventActorToRealActor( actorId );\n" " auto pEventMgr = m_framework->get< World::Manager::EventMgr >();\n"
" auto actor = pEventMgr->mapEventActorToRealActor( static_cast<uint32_t>( actorId ) );\n"
" }\n\n" " }\n\n"
); );
@ -43,6 +44,12 @@ const std::string onEmoteStr(
" }\n\n" " }\n\n"
); );
const std::string onEnemystr(
" void onNpcKill( uint32_t npcId, Entity::Player& player ) override\n"
" {\n"
" }\n\n"
);
std::string titleCase( const std::string& str ) std::string titleCase( const std::string& str )
{ {
if( str.empty() ) if( str.empty() )
@ -70,7 +77,13 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
"// In order for this script to be loaded, change its extension to .cpp\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" "// and move it to the correct folder in <root>/scripts/native/\n"
"\n" "\n"
"#include <ScriptObject.h>\n\n" "#include <Actor/Player.h>\n"
"#include <Manager/EventMgr.h>\n"
"#include <ScriptObject.h>\n"
"#include <Framework.h>\n"
"\n"
"using namespace Sapphire;\n"
"\n"
); );
std::size_t splitPos( pQuestData->id.find( "_" ) ); std::size_t splitPos( pQuestData->id.find( "_" ) );
@ -80,10 +93,10 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
" //////////////////////////////////////////////////////////////////////\n // Available Scenes in this quest, not necessarly all are used\n" ); " //////////////////////////////////////////////////////////////////////\n // Available Scenes in this quest, not necessarly all are used\n" );
std::string seqStr; std::string seqStr;
seqStr.reserve( 0xFFF ); seqStr.reserve( 0xFFF );
seqStr += ( " // Steps in this quest ( 0 is before accepting, \n // 1 is first, 255 means ready for turning it in\n" ); seqStr += ( " // Steps in this quest ( 0 is before accepting, \n // 1 is first, 255 means ready for turning it in\n" );
std::string questVarStr( " // Quest vars / flags used\n" ); std::string questVarStr( " // Quest vars / flags used\n" );
seqStr += " enum Sequence : uint8_t\n {\n"; seqStr += " enum Sequence :\n uint8_t\n {\n";
for( auto& entry : additionalList ) for( auto& entry : additionalList )
{ {
if( entry.find( "OnScene" ) != std::string::npos ) if( entry.find( "OnScene" ) != std::string::npos )
@ -99,25 +112,25 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
sceneName + sceneName +
"( Entity::Player& player )\n" "( Entity::Player& player )\n"
" {\n" " {\n"
" player.eventPlay( this->getId(), " + " player.playScene( getId(), " +
sceneId + sceneId +
", 0,\n" ", 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"
" }\n\n" " }\n\n"
); );
} }
else if( entry.find( "Flag" ) != std::string::npos || else if( entry.find( "Flag" ) != std::string::npos ||
entry.find( "QuestUI" ) != std::string::npos ) entry.find( "QuestUI" ) != std::string::npos )
{ {
questVarStr += " // " + entry + "\n"; questVarStr += " // " + entry + "\n";
} }
else if( entry.find( "SEQ" ) != std::string::npos ) else if( entry.find( "SEQ" ) != std::string::npos )
{ {
if( entry.find( "SEQ_FINISH" ) != std::string::npos ) if( entry.find( "SEQ_FINISH" ) != std::string::npos )
{ {
seqStr += " SeqFinish = 255,\n"; seqStr += " SeqFinish = 255,\n";
} }
else if( entry.find( "SEQ_OFFER" ) != std::string::npos ) else if( entry.find( "SEQ_OFFER" ) != std::string::npos )
{ {
@ -131,97 +144,121 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
}), seqName.end()); }), seqName.end());
std::string seqId = entry.substr( 4 ); std::string seqId = entry.substr( 4 );
seqStr += " " + seqName + " = " + seqId + ",\n"; seqStr += " " + seqName + " = " + seqId + ",\n";
} }
} }
} }
seqStr += " };\n"; seqStr += " };\n";
std::string rewards; std::string rewards;
std::string reward;
rewards.reserve( 0xFFF ); rewards.reserve( 0xFFF );
rewards += " // Quest rewards \n"; rewards += " // Quest rewards \n";
rewards += ( pQuestData->expFactor != 0 ) ? " static constexpr auto RewardExpFactor = " + rewards += ( pQuestData->expFactor != 0 ) ? " static constexpr auto RewardExpFactor = " +
std::to_string( pQuestData->expFactor ) + ";\n" : ""; std::to_string( pQuestData->expFactor ) + ";\n" : "";
rewards += ( pQuestData->gilReward != 0 ) ? " static constexpr auto RewardGil = " + rewards += ( pQuestData->gilReward != 0 ) ? " static constexpr auto RewardGil = " +
std::to_string( pQuestData->gilReward ) + ";\n" : ""; std::to_string( pQuestData->gilReward ) + ";\n" : "";
rewards += ( pQuestData->emoteReward != 0 ) ? " static constexpr auto RewardEmote = " + rewards += ( pQuestData->emoteReward != 0 ) ? " static constexpr auto RewardEmote = " +
std::to_string( pQuestData->emoteReward ) + ";\n" : ""; std::to_string( pQuestData->emoteReward ) + ";\n" : "";
rewards += ( pQuestData->actionReward != 0 ) ? " static constexpr auto RewardAction = " + rewards += ( pQuestData->actionReward != 0 ) ? " static constexpr auto RewardAction = " +
std::to_string( pQuestData->actionReward ) + ";\n" : ""; std::to_string( pQuestData->actionReward ) + ";\n" : "";
rewards += ( pQuestData->generalActionReward[ 0 ] != 0 ) ? " static constexpr auto RewardGeneralAction1 = " + rewards += ( pQuestData->generalActionReward[ 0 ] != 0 ) ? " static constexpr auto RewardGeneralAction1 = " +
std::to_string( pQuestData->generalActionReward[ 0 ] ) + std::to_string( pQuestData->generalActionReward[ 0 ] ) +
";\n" : ""; ";\n" : "";
rewards += ( pQuestData->generalActionReward[ 1 ] != 0 ) ? " static constexpr auto RewardGeneralAction2 = " + rewards += ( pQuestData->generalActionReward[ 1 ] != 0 ) ? " static constexpr auto RewardGeneralAction2 = " +
std::to_string( pQuestData->generalActionReward[ 1 ] ) + std::to_string( pQuestData->generalActionReward[ 1 ] ) +
";\n" : ""; ";\n" : "";
rewards += ( pQuestData->gCSeals != 0 ) ? " static constexpr auto RewardGCSeals = " + rewards += ( pQuestData->gCSeals != 0 ) ? " static constexpr auto RewardGCSeals = " +
std::to_string( pQuestData->gCSeals ) + ";\n" : ""; std::to_string( pQuestData->gCSeals ) + ";\n" : "";
rewards += ( pQuestData->otherReward != 0 ) ? " static constexpr auto RewardOther = " + rewards += ( pQuestData->otherReward != 0 ) ? " static constexpr auto RewardOther = " +
std::to_string( pQuestData->otherReward ) + ";\n" : ""; std::to_string( pQuestData->otherReward ) + ";\n" : "";
rewards += ( pQuestData->reputationReward != 0 ) ? " static constexpr auto RewardReputation = " + rewards += ( pQuestData->reputationReward != 0 ) ? " static constexpr auto RewardReputation = " +
std::to_string( pQuestData->reputationReward ) + ";\n" : ""; std::to_string( pQuestData->reputationReward ) + ";\n" : "";
rewards += ( pQuestData->tomestoneReward != 0 ) ? " static constexpr auto RewardTomeType = " + rewards += ( pQuestData->tomestoneReward != 0 ) ? " static constexpr auto RewardTomeType = " +
std::to_string( pQuestData->tomestoneReward ) + ";\n" : ""; std::to_string( pQuestData->tomestoneReward ) + ";\n" : "";
rewards += ( pQuestData->tomestoneCountReward != 0 ) ? " static constexpr auto RewardTomeCount = " + rewards += ( pQuestData->tomestoneCountReward != 0 ) ? " static constexpr auto RewardTomeCount = " +
std::to_string( pQuestData->tomestoneCountReward ) + ";\n" std::to_string( pQuestData->tomestoneCountReward ) + ";\n"
: ""; : "";
rewards += ( pQuestData->instanceContentUnlock != 0 ) ? " static constexpr auto InstancedContentUnlock = " + rewards += ( pQuestData->instanceContentUnlock != 0 ) ? " static constexpr auto InstancedContentUnlock = " +
std::to_string( pQuestData->instanceContentUnlock ) + ";\n" std::to_string( pQuestData->instanceContentUnlock ) + ";\n"
: ""; : "";
if( !pQuestData->itemReward0.empty() ) if( !pQuestData->itemReward0.at(0) == 0 )
{ {
rewards += " static constexpr auto RewardItem[] = { "; std::size_t cc = 0;
for( size_t ca = 0; ca < pQuestData->itemReward0.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->itemReward0.size(); ca++ )
{ {
rewards += std::to_string( pQuestData->itemReward0.at( ca ) ); if ( pQuestData->itemReward0.at( ca ) != 0 )
if( ca != pQuestData->itemReward0.size() - 1 )
{ {
rewards += ", "; reward += std::to_string( pQuestData->itemReward0.at( ca ) );
if ( pQuestData->itemReward0.at( ca + 1 ) != 0 )
{
reward += ", ";
}
cc++;
} }
} }
rewards += " };\n"; rewards += " static constexpr auto RewardItem["+ std::to_string(cc) + "] = { "+ reward +" };\n";
reward.clear();
} }
if( !pQuestData->itemReward0.empty() ) if( !pQuestData->itemReward0.at(0) == 0 )
{ {
rewards += " static constexpr auto RewardItemCount[] = { "; std::size_t cc = 0;
for( size_t ca = 0; ca < pQuestData->itemCountReward0.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->itemCountReward0.size(); ca++ )
{ {
rewards += std::to_string( pQuestData->itemCountReward0.at( ca ) ); if ( pQuestData->itemCountReward0.at( ca ) != 0 )
if( ca != pQuestData->itemCountReward0.size() - 1 )
{ {
rewards += ", "; reward += std::to_string( pQuestData->itemCountReward0.at( ca ) );
if ( pQuestData->itemCountReward0.at( ca + 1 ) != 0 )
{
reward += ", ";
}
cc++;
} }
} }
rewards += " };\n"; rewards += " static constexpr auto RewardItemCount["+ std::to_string(cc) +"] = { "+ reward +" };\n";
reward.clear();
} }
if( !pQuestData->itemReward1.empty() ) if (!pQuestData->itemReward1.at(0) == 0 )
{ {
rewards += " static constexpr auto RewardItemOptional[] = { "; std::size_t cc = 0;
for( size_t ca = 0; ca < pQuestData->itemReward1.size(); ca++ ) for (size_t ca = 0; ca < pQuestData->itemReward1.size(); ca++)
{ {
rewards += std::to_string( pQuestData->itemReward1.at( ca ) ); if (pQuestData->itemReward1.at(ca) != 0)
if( ca != pQuestData->itemReward1.size() - 1 )
{ {
rewards += ", "; reward += std::to_string(pQuestData->itemReward1.at(ca));
if (pQuestData->itemReward1.at(ca+1) != 0)
{
reward += ", ";
}
else break;
cc++;
} }
} }
rewards += " };\n"; rewards += " static constexpr auto RewardItemOptional[" + std::to_string(cc) + "] = { " + reward + " };\n";
reward.clear();
} }
if( !pQuestData->itemCountReward1.empty() ) if( !pQuestData->itemReward1.at(0) == 0 )
{ {
rewards += " static constexpr auto RewardItemOptionalCount[] = { "; std::size_t cc = 0;
for( size_t ca = 0; ca < pQuestData->itemCountReward1.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->itemCountReward1.size(); ca++ )
{ {
rewards += std::to_string( pQuestData->itemCountReward1.at( ca ) ); if (pQuestData->itemCountReward1.at( ca ) != 0)
if( ca != pQuestData->itemCountReward1.size() - 1 )
{ {
rewards += ", "; reward += std::to_string( pQuestData->itemCountReward1.at( ca ) );
if (pQuestData->itemCountReward1.at(ca+1) != 0)
{
reward += ", ";
}
else break;
cc++;
} }
} }
rewards += " };\n"; rewards += " static constexpr auto RewardItemOptionalCount["+ std::to_string(cc) + "] = { "+ reward + " };\n";
reward.clear();
} }
bool hasERange = false; bool hasERange = false;
@ -229,7 +266,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
bool hasEnemies = false; bool hasEnemies = false;
std::vector< uint32_t > enemy_ids; std::vector< uint32_t > enemy_ids;
std::vector< std::string > script_entities; std::vector< std::string > script_entities;
std::string sentities = " // Entities found in the script data of the quest\n"; std::string sentities = " // Entities found in the script data of the quest\n";
for( size_t ca = 0; ca < pQuestData->scriptInstruction.size(); ca++ ) for( size_t ca = 0; ca < pQuestData->scriptInstruction.size(); ca++ )
{ {
@ -260,7 +297,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
return c == '_'; return c == '_';
}), name.end()); }), name.end());
sentities += " static constexpr auto " + name + ";\n"; sentities += " static constexpr auto " + name + ";\n";
} }
std::string additional = "// Quest Script: " + pQuestData->id + "\n"; std::string additional = "// Quest Script: " + pQuestData->id + "\n";
@ -285,34 +322,36 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
scriptEntry += onEmoteStr; scriptEntry += onEmoteStr;
} }
for( auto enemy : enemy_ids ) if(hasEnemies)
{ {
scriptEntry += std::string( scriptEntry += onEnemystr;
" void onMobKill_" + std::to_string( enemy ) + "( Entity::Player& player )\n"
" {\n"
" }\n\n"
);
} }
std::string constructor; std::string constructor;
constructor += std::string( constructor += std::string(
" private:\n" "private:\n"
" // Basic quest information \n" ); " // Basic quest information \n" );
constructor += questVarStr + "\n"; constructor += questVarStr + "\n";
constructor += seqStr + "\n"; constructor += seqStr + "\n";
constructor += rewards + "\n"; constructor += rewards + "\n";
constructor += sentities + "\n"; constructor += sentities + "\n";
constructor += " public:\n"; constructor += "public:\n";
constructor += " " + className + "() : EventScript" + "( " + std::to_string( questId ) + " ){}; \n"; constructor += " " + className + "() :\n";
constructor += " ~" + className + "(){}; \n"; constructor += " Sapphire::ScriptAPI::EventScript ( " + std::to_string( questId ) + " )\n";
constructor += " {\n";
constructor += " };\n\n";
constructor += " ~" + className + "()\n";
constructor += " {\n";
constructor += " };\n";
std::string classString( std::string classString(
"class " + className + " : public EventScript\n" "class " + className + " : \n"
"{\n" + " public Sapphire::ScriptAPI::EventScript\n"
"{\n" +
constructor + constructor +
"\n" + "\n" +
scriptEntry + scriptEntry +
" private:\n" + "private:\n" +
sceneStr + sceneStr +
"};\n\n" "};\n\n"
); );
@ -332,7 +371,7 @@ int main( int argc, char** argv )
bool unluac = false; bool unluac = false;
// std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" ); // 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:/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( "F:/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack" );
if( argc > 1 ) if( argc > 1 )
datLocation = std::string( argv[ 1 ] ); datLocation = std::string( argv[ 1 ] );
if( argc > 2 ) if( argc > 2 )
@ -362,7 +401,7 @@ int main( int argc, char** argv )
uint32_t i = 0; uint32_t i = 0;
for( const auto& row : rows ) for( const auto& row : rows )
{ {
Logger::info( "Generating {0}", row ); Logger::info( "Generating " + std::to_string( row ) );
auto questInfo = g_exdDataGen.get< Sapphire::Data::Quest >( row ); auto questInfo = g_exdDataGen.get< Sapphire::Data::Quest >( row );
if( questInfo->name.empty() || questInfo->id.empty() ) if( questInfo->name.empty() || questInfo->id.empty() )
@ -407,7 +446,7 @@ int main( int argc, char** argv )
"generated/" + questInfo->id + ".lua"; "generated/" + questInfo->id + ".lua";
if( system( command.c_str() ) == -1 ) if( system( command.c_str() ) == -1 )
{ {
Logger::error( "Error executing java command:\n {0}\nerrno: {1}", command, std::strerror( errno ) ); Logger::error( "Error executing java command:\n" + command + "\nerrno: " + std::strerror( errno ) );
return errno; return errno;
} }
} }