From 0a70db86860b5bff412bb6ec95c51f53e654ae14 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sun, 7 May 2023 01:43:22 -0700 Subject: [PATCH] Underneath the Sultantree quest + questbattle implementation ManWil005 MSQ. HP values are likely to be wrong --- .../questbattles/UnderneaththeSultantree.cpp | 114 +++++++ src/scripts/quest/ManWil005.cpp | 318 ++++++++++++++++++ 2 files changed, 432 insertions(+) create mode 100644 src/scripts/quest/ManWil005.cpp diff --git a/src/scripts/instances/questbattles/UnderneaththeSultantree.cpp b/src/scripts/instances/questbattles/UnderneaththeSultantree.cpp index f5dc332f..7d4d61a8 100644 --- a/src/scripts/instances/questbattles/UnderneaththeSultantree.cpp +++ b/src/scripts/instances/questbattles/UnderneaththeSultantree.cpp @@ -1,5 +1,8 @@ #include #include +#include +#include +#include using namespace Sapphire; @@ -100,15 +103,126 @@ public: instance.addEObj( "Millioncornseedling", 2001255, 0, 3927161, 4, { -320.576813f, 25.833500f, -527.550171f }, 0.961304f, -0.384837f, 0); } + enum vars + { + SET_1_SPAWNED, + SET_2_SPAWNED, + SUCCESS_CALLED, + }; + + void onPlayerSetup( Sapphire::QuestBattle& instance, Entity::Player& player ) override + { + player.setRot( -71.03f ); + player.setPos( { 198.303f, 14.244f, 538.248f } ); + } void onUpdate( QuestBattle& instance, uint64_t tickCount ) override { + auto pair1Spawnd = instance.getDirectorVar( SET_1_SPAWNED ); + auto pair2Spawnd = instance.getDirectorVar( SET_2_SPAWNED ); + auto successCalled = instance.getDirectorVar( SUCCESS_CALLED ); + + auto boss = instance.getActiveBNpcByLayoutId( INIT_POP_BOSS ); + auto thancred = instance.getActiveBNpcByLayoutId( INIT_P_POP_01 ); + auto pPlayer = instance.getPlayerPtr(); + + uint32_t bossHpPercent = 0; + if( boss ) + bossHpPercent = boss->getHpPercent(); + + if( pPlayer && !pPlayer->isAlive() ) + { + instance.fail(); + return; + } + + if (!thancred) + return; + + if( pair1Spawnd == 0 && bossHpPercent <= 70 ) + { + instance.setDirectorVar( SET_1_SPAWNED, 1 ); + auto a2 = instance.createBNpcFromLayoutId(INIT_POP_01_01, 1440, Common::BNpcType::Enemy); + auto a3 = instance.createBNpcFromLayoutId( INIT_POP_01_02, 1440, Common::BNpcType::Enemy ); + a2->setFlag( Entity::NoDeaggro ); + a3->setFlag( Entity::NoDeaggro ); + + auto pPlayer = instance.getPlayerPtr(); + a2->hateListAdd( pPlayer, 1 ); + a3->hateListAdd( pPlayer, 1 ); + + thancred->hateListAdd( a2, 9999 ); + thancred->hateListAdd( a3, 9999 ); + } + + if( pair2Spawnd == 0 && bossHpPercent <= 40 ) + { + instance.setDirectorVar( SET_2_SPAWNED, 1 ); + auto a2 = instance.createBNpcFromLayoutId( INIT_POP_02_01, 1440, Common::BNpcType::Enemy ); + auto a3 = instance.createBNpcFromLayoutId( INIT_POP_02_02, 1440, Common::BNpcType::Enemy ); + auto a4 = instance.createBNpcFromLayoutId( INIT_POP_02_03, 1440, Common::BNpcType::Enemy ); + auto a5 = instance.createBNpcFromLayoutId( INIT_POP_02_04, 1440, Common::BNpcType::Enemy ); + a2->setFlag( Entity::NoDeaggro ); + a3->setFlag( Entity::NoDeaggro ); + a4->setFlag( Entity::NoDeaggro ); + a5->setFlag( Entity::NoDeaggro ); + + auto pPlayer = instance.getPlayerPtr(); + a2->hateListAdd( pPlayer, 1 ); + a3->hateListAdd( pPlayer, 1 ); + a4->hateListAdd( pPlayer, 1 ); + a5->hateListAdd( pPlayer, 1 ); + + thancred->hateListAdd( a2, 9999 ); + thancred->hateListAdd( a3, 9999 ); + thancred->hateListAdd( a4, 9999 ); + thancred->hateListAdd( a5, 9999 ); + } + + if( instance.getCountEnemyBNpc() == 0 && successCalled == 0 ) + { + instance.setDirectorVar( SUCCESS_CALLED, 1 ); + instance.success(); + return; + } } void onEnterTerritory( QuestBattle& instance, Entity::Player& player, uint32_t eventId, uint16_t param1, uint16_t param2 ) override { + eventMgr().playScene( player, instance.getDirectorId(), 1, + NO_DEFAULT_CAMERA | CONDITION_CUTSCENE | SILENT_ENTER_TERRI_ENV | + HIDE_HOTBAR | SILENT_ENTER_TERRI_BGM | SILENT_ENTER_TERRI_SE | + DISABLE_STEALTH | 0x00100000 | LOCK_HUD | LOCK_HOTBAR | + // todo: wtf is 0x00100000 + DISABLE_CANCEL_EMOTE, [ & ]( Entity::Player& player, const Event::SceneResult& result ) { + player.setOnEnterEventDone( true ); + } ); + } + + void onDutyComplete( QuestBattle& instance, Entity::Player& player ) override + { + auto idx = player.getQuestIndex( instance.getQuestId() ); + if( idx == -1 ) + return; + auto& quest = player.getQuestByIndex( idx ); + quest.setSeq( 2 ); + } + + void onDutyCommence( QuestBattle& instance, Entity::Player& player ) override + { + // TODO: Change to correct HP values + auto boss = instance.createBNpcFromLayoutId( INIT_POP_BOSS, 10571, Common::BNpcType::Enemy ); + auto thancred = instance.createBNpcFromLayoutId( INIT_P_POP_01, 27780, Common::BNpcType::Friendly ); + + boss->setFlag( Entity::NoDeaggro ); + thancred->setFlag( Entity::NoDeaggro ); + + boss->hateListAdd( thancred, 10000 ); + boss->hateListAdd( player.getAsPlayer(), 1 ); + + thancred->hateListAdd( boss, 10000 ); } diff --git a/src/scripts/quest/ManWil005.cpp b/src/scripts/quest/ManWil005.cpp new file mode 100644 index 00000000..75ab8a97 --- /dev/null +++ b/src/scripts/quest/ManWil005.cpp @@ -0,0 +1,318 @@ +// This is an automatically generated C++ script template +// Content needs to be added by hand to make it function +// In order for this script to be loaded, move it to the correct folder in /scripts/ + +#include +#include "Manager/EventMgr.h" +#include +#include + +// Quest Script: ManWil005_00550 +// Quest Name: Underneath the Sultantree +// Quest ID: 66086 +// Start NPC: 1003995 (Papashan) +// End NPC: 1003995 (Papashan) + +using namespace Sapphire; + +class ManWil005 : public Sapphire::ScriptAPI::QuestScript +{ + private: + // Basic quest information + // Quest vars / flags used + // BitFlag8 + // UI8AL + + /// Countable Num: 1 Seq: 1 Event: 1 Listener: 1003996 + /// Countable Num: 1 Seq: 2 Event: 1 Listener: 2001853 + /// Countable Num: 0 Seq: 255 Event: 15 Listener: 5020000 + // Steps in this quest ( 0 is before accepting, + // 1 is first, 255 means ready for turning it in + enum Sequence : uint8_t + { + Seq0 = 0, + Seq1 = 1, + Seq2 = 2, + SeqFinish = 255, + }; + + // Entities found in the script data of the quest + static constexpr auto Actor0 = 1003995; // Papashan ( Pos: 75.338402 2.138110 316.362000 Teri: 141 ) + static constexpr auto Actor1 = 1003996; // Hooded Lalafell ( Pos: 202.662994 14.104900 536.909973 Teri: 141 ) + static constexpr auto Actor2 = 1003997; // ×次女a ( Pos: 76.674599 2.137120 317.433014 Teri: 141 ) + static constexpr auto Actor3 = 1003998; // ×近衛a ( Pos: 77.176598 2.137340 315.631989 Teri: 141 ) + static constexpr auto Actor4 = 1003999; // ×近衛b ( Pos: 77.310501 2.136910 316.973999 Teri: 141 ) + static constexpr auto Actor5 = 1004000; // ×近衛c ( Pos: 78.402603 2.136520 316.269012 Teri: 141 ) + static constexpr auto Actor6 = 1004001; // Lilira ( Pos: 76.643402 2.136930 318.191010 Teri: 141 ) + static constexpr auto Actor20 = 1006171; // Lilira + static constexpr auto Actor30 = 1006167; // 侍女a + static constexpr auto Actor40 = 1006168; // 近衛a + static constexpr auto Actor50 = 1006169; // 近衛b + static constexpr auto Actor60 = 1006170; // 近衛c + static constexpr auto CutScene02 = 141; + static constexpr auto CutScene03 = 56; + static constexpr auto CutScene04 = 142; + static constexpr auto Eobject0 = 2001853; // ( Pos: 202.638000 14.137900 536.905029 Teri: 141 ) + static constexpr auto EventActionSearch = 1; // Interaction + static constexpr auto Questbattle0 = 37; + static constexpr auto Seq0Actor0Lq = 50; // Goblin Thug + static constexpr auto Territorytype0 = 270; + static constexpr auto Territorytype1 = 141; + + public: + ManWil005() : Sapphire::ScriptAPI::QuestScript( 66086 ){}; + ~ManWil005() = default; + + ////////////////////////////////////////////////////////////////////// + // Event Handlers + void onTalk( World::Quest& quest, Entity::Player& player, uint64_t actorId ) override + { + switch( actorId ) + { + case Actor0: + { + if (quest.getSeq() == Seq0) + { + Scene00000( quest, player ); + } + else if (quest.getSeq() == SeqFinish) + { + Scene00006( quest, player ); + } + + break; + } + case Actor1: + { + if( quest.getSeq() == Seq1 ) + Scene00002( quest, player ); + break; + } + case Actor2: + { + break; + } + case Actor3: + { + break; + } + case Actor4: + { + break; + } + case Actor5: + { + break; + } + case Actor6: + { + break; + } + case Actor20: + { + break; + } + case Actor30: + { + break; + } + case Actor40: + { + break; + } + case Actor50: + { + break; + } + case Actor60: + { + break; + } + } + } + + void onEnterTerritory( World::Quest& quest, Entity::Player& player, uint16_t param1, uint16_t param2 ) override + { + if( quest.getSeq() == Seq2 ) + { + Scene00005( quest, player ); + } + } + + + private: + ////////////////////////////////////////////////////////////////////// + // Available Scenes in this quest, not necessarly all are used + ////////////////////////////////////////////////////////////////////// + + void Scene00000( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 0, HIDE_HOTBAR, bindSceneReturn( &ManWil005::Scene00000Return ) ); + } + + void Scene00000Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + if( result.getResult( 0 ) == 1 ) // accept quest + { + Scene00001( quest, player ); + } + + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00001( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 1, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, bindSceneReturn( &ManWil005::Scene00001Return ) ); + } + + void Scene00001Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + quest.setSeq( Seq1 ); + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00002( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 2, NONE, bindSceneReturn( &ManWil005::Scene00002Return ) ); + } + + void Scene00002Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + if( result.getResult( 0 ) == 1 ) + { + auto& pTeriMgr = Common::Service< Sapphire::World::Manager::TerritoryMgr >::ref(); + + eventMgr().eventFinish( player, result.eventId, 0 ); + pTeriMgr.createAndJoinQuestBattle( player, Questbattle0 ); + } + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00003( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 3, NONE, bindSceneReturn( &ManWil005::Scene00003Return ) ); + } + + void Scene00003Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00004( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 4, NONE, bindSceneReturn( &ManWil005::Scene00004Return ) ); + } + + void Scene00004Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00005( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 5, NO_DEFAULT_CAMERA | CONDITION_CUTSCENE | SILENT_ENTER_TERRI_ENV | HIDE_HOTBAR | SILENT_ENTER_TERRI_BGM | SILENT_ENTER_TERRI_SE | DISABLE_STEALTH | 0x00100000 | LOCK_HUD | LOCK_HOTBAR | + // todo: wtf is 0x00100000 + DISABLE_CANCEL_EMOTE, + bindSceneReturn( &ManWil005::Scene00005Return ) ); + } + + void Scene00005Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + quest.setSeq( SeqFinish ); + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00006( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 6, FADE_OUT | HIDE_HOTBAR | CONDITION_CUTSCENE | HIDE_UI, bindSceneReturn( &ManWil005::Scene00006Return ) ); + } + + void Scene00006Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + if( result.getResult( 0 ) == 1 ) + { + player.finishQuest( getId(), result.getResult( 1 ) ); + } + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00007( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 7, NONE, bindSceneReturn( &ManWil005::Scene00007Return ) ); + } + + void Scene00007Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00008( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 8, NONE, bindSceneReturn( &ManWil005::Scene00008Return ) ); + } + + void Scene00008Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00009( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 9, NONE, bindSceneReturn( &ManWil005::Scene00009Return ) ); + } + + void Scene00009Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00010( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 10, NONE, bindSceneReturn( &ManWil005::Scene00010Return ) ); + } + + void Scene00010Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + + } + + ////////////////////////////////////////////////////////////////////// + + void Scene00011( World::Quest& quest, Entity::Player& player ) + { + eventMgr().playQuestScene( player, getId(), 11, NONE, bindSceneReturn( &ManWil005::Scene00011Return ) ); + } + + void Scene00011Return( World::Quest& quest, Entity::Player& player, const Event::SceneResult& result ) + { + + + } + +}; + +EXPOSE_SCRIPT( ManWil005 ); \ No newline at end of file