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(
" void onTalk( uint32_t eventId, Entity::Player& player, uint64_t actorId ) override\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"
);
@ -43,6 +44,12 @@ const std::string onEmoteStr(
" }\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 )
{
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"
"// and move it to the correct folder in <root>/scripts/native/\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( "_" ) );
@ -83,7 +96,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
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" );
seqStr += " enum Sequence : uint8_t\n {\n";
seqStr += " enum Sequence :\n uint8_t\n {\n";
for( auto& entry : additionalList )
{
if( entry.find( "OnScene" ) != std::string::npos )
@ -99,10 +112,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"
@ -137,6 +150,7 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
}
seqStr += " };\n";
std::string rewards;
std::string reward;
rewards.reserve( 0xFFF );
rewards += " // Quest rewards \n";
rewards += ( pQuestData->expFactor != 0 ) ? " static constexpr auto RewardExpFactor = " +
@ -168,60 +182,83 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
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++ )
{
rewards += std::to_string( pQuestData->itemReward0.at( ca ) );
if( ca != pQuestData->itemReward0.size() - 1 )
if ( pQuestData->itemReward0.at( ca ) != 0 )
{
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++ )
{
rewards += std::to_string( pQuestData->itemCountReward0.at( ca ) );
if( ca != pQuestData->itemCountReward0.size() - 1 )
if ( pQuestData->itemCountReward0.at( ca ) != 0 )
{
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[] = { ";
for( size_t ca = 0; ca < pQuestData->itemReward1.size(); ca++ )
std::size_t cc = 0;
for (size_t ca = 0; ca < pQuestData->itemReward1.size(); ca++)
{
rewards += std::to_string( pQuestData->itemReward1.at( ca ) );
if( ca != pQuestData->itemReward1.size() - 1 )
if (pQuestData->itemReward1.at(ca) != 0)
{
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++ )
{
rewards += std::to_string( pQuestData->itemCountReward1.at( ca ) );
if( ca != pQuestData->itemCountReward1.size() - 1 )
if (pQuestData->itemCountReward1.at( ca ) != 0)
{
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;
@ -285,34 +322,36 @@ createScript( std::shared_ptr< Sapphire::Data::Quest >& pQuestData, std::set< st
scriptEntry += onEmoteStr;
}
for( auto enemy : enemy_ids )
if(hasEnemies)
{
scriptEntry += std::string(
" void onMobKill_" + std::to_string( enemy ) + "( Entity::Player& player )\n"
" {\n"
" }\n\n"
);
scriptEntry += onEnemystr;
}
std::string constructor;
constructor += std::string(
" private:\n"
"private:\n"
" // Basic quest information \n" );
constructor += questVarStr + "\n";
constructor += seqStr + "\n";
constructor += rewards + "\n";
constructor += sentities + "\n";
constructor += " public:\n";
constructor += " " + className + "() : EventScript" + "( " + std::to_string( questId ) + " ){}; \n";
constructor += " ~" + className + "(){}; \n";
constructor += "public:\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(
"class " + className + " : public EventScript\n"
"class " + className + " : \n"
" public Sapphire::ScriptAPI::EventScript\n"
"{\n" +
constructor +
"\n" +
scriptEntry +
" private:\n" +
"private:\n" +
sceneStr +
"};\n\n"
);
@ -332,7 +371,7 @@ 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( "F:/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack" );
if( argc > 1 )
datLocation = std::string( argv[ 1 ] );
if( argc > 2 )
@ -362,7 +401,7 @@ int main( int argc, char** argv )
uint32_t i = 0;
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 );
if( questInfo->name.empty() || questInfo->id.empty() )
@ -407,7 +446,7 @@ int main( int argc, char** argv )
"generated/" + questInfo->id + ".lua";
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;
}
}