diff --git a/src/common/Network/CommonActorControl.h b/src/common/Network/CommonActorControl.h index 2c971c47..e6e36a3f 100644 --- a/src/common/Network/CommonActorControl.h +++ b/src/common/Network/CommonActorControl.h @@ -548,6 +548,7 @@ namespace Sapphire::Network::ActorControl REQUEST_SALVAGE_SUCCESS_RATE = 0x1B2, MOBHUNT_RECEIPT_ORDER = 0x1B3, MOBHUNT_BREAK_ORDER = 0x1B4, + DYE_ITEM = 0x1B5, EMOTE = 0x1F4, EMOTE_WITH_WARP = 0x1F5, EMOTE_CANCEL = 0x1F6, diff --git a/src/common/Network/PacketDef/Zone/ServerZoneDef.h b/src/common/Network/PacketDef/Zone/ServerZoneDef.h index 585b74db..fe9b938c 100644 --- a/src/common/Network/PacketDef/Zone/ServerZoneDef.h +++ b/src/common/Network/PacketDef/Zone/ServerZoneDef.h @@ -1145,6 +1145,12 @@ namespace Sapphire::Network::Packets::WorldPackets::Server ZoneProtoDownNormalItem item; }; + struct FFXIVIpcUpdateItem : FFXIVIpcBasePacket< UpdateItem > + { + uint32_t contextId; + ZoneProtoDownNormalItem item; + }; + struct FFXIVIpcItemSize : FFXIVIpcBasePacket< ItemSize > { uint32_t contextId; diff --git a/src/scripts/quest/subquest/goldsaucer/SubGsc001.cpp b/src/scripts/quest/subquest/goldsaucer/SubGsc001.cpp new file mode 100644 index 00000000..47a31eb4 --- /dev/null +++ b/src/scripts/quest/subquest/goldsaucer/SubGsc001.cpp @@ -0,0 +1,218 @@ +// FFXIVTheMovie.ParserV3.10 +// param used: +//ACTOR1 = dummy1 +//SCENE_2 = dummy1 +//SCENE_5 = ELYENORA +#include +#include +#include +#include "Manager/TerritoryMgr.h" +#include "Manager/EventMgr.h" +#include "Territory/Territory.h" + +using namespace Sapphire; + +class SubGsc001 : public Sapphire::ScriptAPI::QuestScript +{ +public: + SubGsc001() : Sapphire::ScriptAPI::QuestScript( 65970 ){}; + ~SubGsc001() = default; + + //SEQ_0, 2 entries + //SEQ_255, 3 entries + + //ACTOR0 = 1011565 + //ACTOR1 = 1011566 + //ACTOR2 = 1004433 + //BGM0 = 250 + //ITEM0 = 2001555 + //NCUT0 = 769 + //NCUT1 = 770 + //POPRANGE0 = 5654039 + //SCREENIMAGE0 = 272 + + static constexpr auto EVENT_ON_TALK = 0; + static constexpr auto EVENT_ON_EMOTE = 1; + static constexpr auto EVENT_ON_BNPC_KILL = 2; + static constexpr auto EVENT_ON_WITHIN_RANGE = 3; + static constexpr auto EVENT_ON_ENTER_TERRITORY = 4; + static constexpr auto EVENT_ON_EVENT_ITEM = 5; + static constexpr auto EVENT_ON_EOBJ_HIT = 6; + static constexpr auto EVENT_ON_SAY = 7; + +private: + void onProgress( World::Quest& quest, Entity::Player& player, uint32_t type, uint64_t param1, uint32_t param2, uint32_t param3 ) + { + switch( quest.getSeq() ) + { + case 0: + { + if( param1 == 1011565 ) // ACTOR0 = TRADER00434 + { + if( quest.getUI8AL() != 1 ) + { + Scene00000( quest, player ); // Scene00000: Normal(QuestOffer), id=unknown + // +Callback Scene00001: Normal(Talk, QuestAccept, TargetCanMove), id=TRADER00434 + } + break; + } + if( param1 == 1011566 ) // ACTOR1 = dummy1 + { + Scene00002( quest, player ); // Scene00002: Empty(None), id=dummy1 + break; + } + break; + } + //seq 255 event item ITEM0 = UI8BH max stack 1 + case 255: + { + if( param1 == 1004433 ) // ACTOR2 = ELYENORA + { + Scene00003( quest, player ); // Scene00003: NpcTrade(Talk, TargetCanMove), id=unknown + // +Callback Scene00004: Normal(Talk, YesNo, TargetCanMove, CanCancel), id=ELYENORA + // +Callback Scene00005: Normal(CutScene, FadeIn, QuestReward, QuestComplete, AutoFadeIn), id=ELYENORA + break; + } + if( param1 == 1011565 ) // ACTOR0 = TRADER00434 + { + Scene00006( quest, player ); // Scene00006: Normal(Talk, TargetCanMove), id=TRADER00434 + break; + } + if( param1 == 1011566 ) // ACTOR1 = unknown + { + Scene00007( quest, player ); // Scene00007: Empty(None), id=unknown + break; + } + break; + } + default: + { + playerMgr().sendUrgent( player, "Sequence {} not defined.", quest.getSeq() ); + break; + } + } + } + +public: + void onTalk( World::Quest& quest, Entity::Player& player, uint64_t actorId ) override + { + onProgress( quest, player, EVENT_ON_TALK, actorId, 0, 0 ); + } + + void onEmote( World::Quest& quest, uint64_t actorId, uint32_t emoteId, Sapphire::Entity::Player& player ) override + { + playerMgr().sendDebug( player, "emote: {}", emoteId ); + onProgress( quest, player, EVENT_ON_EMOTE, actorId, 0, emoteId ); + } + + void onWithinRange( World::Quest& quest, Sapphire::Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) override + { + onProgress( quest, player, EVENT_ON_WITHIN_RANGE, static_cast< uint64_t >( param1 ), 0, 0 ); + } + + void onEnterTerritory( World::Quest& quest, Sapphire::Entity::Player& player, uint16_t param1, uint16_t param2 ) override + { + onProgress( quest, player, EVENT_ON_ENTER_TERRITORY, static_cast< uint64_t >( param1 ), static_cast< uint32_t >( param2 ), 0 ); + } + void onEventItem( World::Quest& quest, Sapphire::Entity::Player& player, uint64_t actorId ) override + { + onProgress( quest, player, EVENT_ON_EVENT_ITEM, actorId, 0, 0 ); + } + void onEObjHit( World::Quest& quest, Sapphire::Entity::Player& player, uint64_t actorId, uint32_t actionId ) override + { + onProgress( quest, player, EVENT_ON_EOBJ_HIT, actorId, actionId, 0 ); + } + void onSay( World::Quest& quest, Sapphire::Entity::Player& player, uint64_t actorId, uint32_t sayId ) override + { + onProgress( quest, player, EVENT_ON_SAY, actorId, sayId, 0 ); + } + +private: + void checkProgressSeq0( World::Quest& quest, Entity::Player& player ) + { + quest.setSeq( 255 ); + quest.setUI8BH( 1 ); + } + + void Scene00000( World::Quest& quest, Entity::Player& player ) //SEQ_0: ACTOR0, UI8AL = 1, Flag8(1)=True + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00000: Normal(QuestOffer), id=unknown" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + if( result.numOfResults > 0 && result.getResult( 0 ) == 1 ) + { + Scene00001( quest, player ); + } + }; + eventMgr().playQuestScene( player, getId(), 0, HIDE_HOTBAR, callback ); + } + void Scene00001( World::Quest& quest, Entity::Player& player ) //SEQ_0: ACTOR0, UI8AL = 1, Flag8(1)=True + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00001: Normal(Talk, QuestAccept, TargetCanMove), id=TRADER00434" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + checkProgressSeq0( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 1, HIDE_HOTBAR, callback ); + } + + void Scene00002( World::Quest& quest, Entity::Player& player ) //SEQ_0: ACTOR1, , + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00002: Empty(None), id=dummy1" ); + } + + void Scene00003( World::Quest& quest, Entity::Player& player ) //SEQ_255: ACTOR2, , + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00003: NpcTrade(Talk, TargetCanMove), id=unknown" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + if( result.numOfResults > 0 && result.getResult( 0 ) == 1 ) + { + Scene00004( quest, player ); + } + }; + eventMgr().playQuestScene( player, getId(), 3, HIDE_HOTBAR, callback ); + } + void Scene00004( World::Quest& quest, Entity::Player& player ) //SEQ_255: ACTOR2, , + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00004: Normal(Talk, YesNo, TargetCanMove, CanCancel), id=ELYENORA" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + if( result.errorCode == 0 || ( result.numOfResults > 0 && result.getResult( 0 ) == 1 ) ) + { + Scene00005( quest, player ); + } + }; + eventMgr().playQuestScene( player, getId(), 4, HIDE_HOTBAR, callback ); + } + void Scene00005( World::Quest& quest, Entity::Player& player ) //SEQ_255: ACTOR2, , + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00005: Normal(CutScene, FadeIn, QuestReward, QuestComplete, AutoFadeIn), id=ELYENORA" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + if( result.numOfResults > 0 && result.getResult( 0 ) == 1 ) + { + player.finishQuest( getId(), result.getResult( 1 ) ); + eventMgr().eventFinish( player, result.eventId, 1 ); + warpMgr().requestMoveTerritory( player, Common::WarpType::WARP_TYPE_NORMAL, teriMgr().getZoneByTerritoryTypeId( 144 )->getGuId(), { -34.5, 0.64, 100 }, -1.58 ); + } + }; + eventMgr().playQuestScene( player, getId(), 5, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, callback ); + } + + void Scene00006( World::Quest& quest, Entity::Player& player ) //SEQ_255: ACTOR0, , + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00006: Normal(Talk, TargetCanMove), id=TRADER00434" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + }; + eventMgr().playQuestScene( player, getId(), 6, HIDE_HOTBAR, callback ); + } + + void Scene00007( World::Quest& quest, Entity::Player& player ) //SEQ_255: ACTOR1, , + { + playerMgr().sendDebug( player, "SubGsc001:65970 calling Scene00007: Empty(None), id=unknown" ); + } +}; + +EXPOSE_SCRIPT( SubGsc001 ); diff --git a/src/scripts/quest/subquest/goldsaucer/SubGsc002.cpp b/src/scripts/quest/subquest/goldsaucer/SubGsc002.cpp new file mode 100644 index 00000000..e56c22c4 --- /dev/null +++ b/src/scripts/quest/subquest/goldsaucer/SubGsc002.cpp @@ -0,0 +1,296 @@ +// FFXIVTheMovie.ParserV3.10 +#include +#include +#include +#include "Manager/TerritoryMgr.h" +#include "Manager/EventMgr.h" + +using namespace Sapphire; + +class SubGsc002 : public Sapphire::ScriptAPI::QuestScript +{ +public: + SubGsc002() : Sapphire::ScriptAPI::QuestScript( 65971 ){}; + ~SubGsc002() = default; + + //SEQ_0, 1 entries + //SEQ_1, 2 entries + //SEQ_2, 1 entries + //SEQ_3, 1 entries + //SEQ_4, 1 entries + //SEQ_5, 1 entries + //SEQ_6, 1 entries + //SEQ_255, 1 entries + + //ACTOR0 = 1011022 + //ACTOR1 = 1010448 + //ACTOR2 = 1011038 + //ACTOR3 = 1010478 + //ACTOR4 = 1011080 + //ACTOR5 = 1011079 + //ACTOR6 = 1011084 + //BGM0 = 250 + //LOCACTIONTIMELINE001 = 1072 + //LOCCHECKQUEST001 = 66996 + //LOCCHECKQUEST002 = 65625 + //LOCCHECKQUEST003 = 65964 + //LOCENPC001 = 1011586 + //LOCLEVELENPC001 = 5581118 + //LOCLEVELENPC002 = 5581208 + //LOCLEVELENPC003 = 5584143 + //LOCLEVELENPC004 = 5653245 + //LOCLEVELENPC005 = 5581064 + + static constexpr auto EVENT_ON_TALK = 0; + static constexpr auto EVENT_ON_EMOTE = 1; + static constexpr auto EVENT_ON_BNPC_KILL = 2; + static constexpr auto EVENT_ON_WITHIN_RANGE = 3; + static constexpr auto EVENT_ON_ENTER_TERRITORY = 4; + static constexpr auto EVENT_ON_EVENT_ITEM = 5; + static constexpr auto EVENT_ON_EOBJ_HIT = 6; + static constexpr auto EVENT_ON_SAY = 7; + +private: + void onProgress( World::Quest& quest, Entity::Player& player, uint32_t type, uint64_t param1, uint32_t param2, uint32_t param3 ) + { + switch( quest.getSeq() ) + { + case 0: + { + if( type != EVENT_ON_BNPC_KILL ) Scene00000( quest, player ); // Scene00000: Normal(QuestOffer, TargetCanMove), id=unknown + // +Callback Scene00001: Normal(Talk, QuestAccept, TargetCanMove), id=RECEPTIONIDT00434 + break; + } + case 1: + { + if( param1 == 1010448 ) // ACTOR1 = INFORMATION00435 + { + if( quest.getUI8AL() != 1 ) + { + Scene00002( quest, player ); // Scene00002: Normal(Talk, FadeIn, TargetCanMove, ENpcBind), id=INFORMATION00435 + } + break; + } + if( param1 == 1011022 ) // ACTOR0 = RECEPTIONIDT00434 + { + Scene00003( quest, player ); // Scene00003: Normal(Talk, TargetCanMove), id=RECEPTIONIDT00434 + break; + } + break; + } + case 2: + { + if( type != EVENT_ON_BNPC_KILL ) Scene00004( quest, player ); // Scene00004: Normal(Talk, TargetCanMove), id=EXCHANGE00435 + break; + } + case 3: + { + if( type != EVENT_ON_BNPC_KILL ) Scene00005( quest, player ); // Scene00005: Normal(Talk, FadeIn, TargetCanMove, ENpcBind), id=CARDSHOP00435 + break; + } + case 4: + { + if( type != EVENT_ON_BNPC_KILL ) Scene00006( quest, player ); // Scene00006: Normal(Talk, FadeIn, TargetCanMove, ENpcBind), id=GATENPCA00435 + break; + } + case 5: + { + if( type != EVENT_ON_BNPC_KILL ) Scene00007( quest, player ); // Scene00007: Normal(Talk, FadeIn, TargetCanMove), id=BUNNY00435 + break; + } + case 6: + { + if( type != EVENT_ON_BNPC_KILL ) Scene00008( quest, player ); // Scene00008: Normal(Talk, FadeIn, TargetCanMove), id=GATENPCB00435 + break; + } + case 255: + { + if( type != EVENT_ON_BNPC_KILL ) Scene00009( quest, player ); // Scene00009: Normal(Talk, FadeIn, QuestReward, QuestComplete, TargetCanMove), id=INFORMATION00435 + break; + } + default: + { + playerMgr().sendUrgent( player, "Sequence {} not defined.", quest.getSeq() ); + break; + } + } + } + +public: + void onTalk( World::Quest& quest, Entity::Player& player, uint64_t actorId ) override + { + onProgress( quest, player, EVENT_ON_TALK, actorId, 0, 0 ); + } + + void onEmote( World::Quest& quest, uint64_t actorId, uint32_t emoteId, Sapphire::Entity::Player& player ) override + { + playerMgr().sendDebug( player, "emote: {}", emoteId ); + onProgress( quest, player, EVENT_ON_EMOTE, actorId, 0, emoteId ); + } + + void onWithinRange( World::Quest& quest, Sapphire::Entity::Player& player, uint32_t eventId, uint32_t param1, float x, float y, float z ) override + { + onProgress( quest, player, EVENT_ON_WITHIN_RANGE, static_cast< uint64_t >( param1 ), 0, 0 ); + } + + void onEnterTerritory( World::Quest& quest, Sapphire::Entity::Player& player, uint16_t param1, uint16_t param2 ) override + { + onProgress( quest, player, EVENT_ON_ENTER_TERRITORY, static_cast< uint64_t >( param1 ), static_cast< uint32_t >( param2 ), 0 ); + } + void onEventItem( World::Quest& quest, Sapphire::Entity::Player& player, uint64_t actorId ) override + { + onProgress( quest, player, EVENT_ON_EVENT_ITEM, actorId, 0, 0 ); + } + void onEObjHit( World::Quest& quest, Sapphire::Entity::Player& player, uint64_t actorId, uint32_t actionId ) override + { + onProgress( quest, player, EVENT_ON_EOBJ_HIT, actorId, actionId, 0 ); + } + void onSay( World::Quest& quest, Sapphire::Entity::Player& player, uint64_t actorId, uint32_t sayId ) override + { + onProgress( quest, player, EVENT_ON_SAY, actorId, sayId, 0 ); + } + +private: + void checkProgressSeq0( World::Quest& quest, Entity::Player& player ) + { + quest.setSeq( 1 ); + } + void checkProgressSeq1( World::Quest& quest, Entity::Player& player ) + { + if( quest.getUI8AL() == 1 ) + { + quest.setUI8AL( 0 ); + quest.setBitFlag8( 1, false ); + quest.setSeq( 2 ); + } + } + void checkProgressSeq2( World::Quest& quest, Entity::Player& player ) + { + quest.setSeq( 3 ); + } + void checkProgressSeq3( World::Quest& quest, Entity::Player& player ) + { + quest.setSeq( 4 ); + } + void checkProgressSeq4( World::Quest& quest, Entity::Player& player ) + { + quest.setSeq( 5 ); + } + void checkProgressSeq5( World::Quest& quest, Entity::Player& player ) + { + quest.setSeq( 6 ); + } + void checkProgressSeq6( World::Quest& quest, Entity::Player& player ) + { + quest.setSeq( 255 ); + } + + void Scene00000( World::Quest& quest, Entity::Player& player ) //SEQ_0: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00000: Normal(QuestOffer, TargetCanMove), id=unknown" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + if( result.numOfResults > 0 && result.getResult( 0 ) == 1 ) + { + Scene00001( quest, player ); + } + }; + eventMgr().playQuestScene( player, getId(), 0, HIDE_HOTBAR, callback ); + } + void Scene00001( World::Quest& quest, Entity::Player& player ) //SEQ_0: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00001: Normal(Talk, QuestAccept, TargetCanMove), id=RECEPTIONIDT00434" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + checkProgressSeq0( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 1, HIDE_HOTBAR, callback ); + } + + void Scene00002( World::Quest& quest, Entity::Player& player ) //SEQ_1: ACTOR1, UI8AL = 1, Flag8(1)=True(Todo:0) + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00002: Normal(Talk, FadeIn, TargetCanMove, ENpcBind), id=INFORMATION00435" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + quest.setUI8AL( 1 ); + quest.setBitFlag8( 1, true ); + eventMgr().sendEventNotice( player, getId(), 0, 0, 0, 0 ); + checkProgressSeq1( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 2, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, callback ); + } + + void Scene00003( World::Quest& quest, Entity::Player& player ) //SEQ_1: ACTOR0, , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00003: Normal(Talk, TargetCanMove), id=RECEPTIONIDT00434" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + }; + eventMgr().playQuestScene( player, getId(), 3, HIDE_HOTBAR, callback ); + } + + void Scene00004( World::Quest& quest, Entity::Player& player ) //SEQ_2: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00004: Normal(Talk, TargetCanMove), id=EXCHANGE00435" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + checkProgressSeq2( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 4, HIDE_HOTBAR, callback ); + } + + void Scene00005( World::Quest& quest, Entity::Player& player ) //SEQ_3: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00005: Normal(Talk, FadeIn, TargetCanMove, ENpcBind), id=CARDSHOP00435" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + checkProgressSeq3( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 5, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, callback ); + } + + void Scene00006( World::Quest& quest, Entity::Player& player ) //SEQ_4: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00006: Normal(Talk, FadeIn, TargetCanMove, ENpcBind), id=GATENPCA00435" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + checkProgressSeq4( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 6, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, callback ); + } + + void Scene00007( World::Quest& quest, Entity::Player& player ) //SEQ_5: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00007: Normal(Talk, FadeIn, TargetCanMove), id=BUNNY00435" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + checkProgressSeq5( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 7, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, callback ); + } + + void Scene00008( World::Quest& quest, Entity::Player& player ) //SEQ_6: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00008: Normal(Talk, FadeIn, TargetCanMove), id=GATENPCB00435" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + checkProgressSeq6( quest, player ); + }; + eventMgr().playQuestScene( player, getId(), 8, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, callback ); + } + + void Scene00009( World::Quest& quest, Entity::Player& player ) //SEQ_255: , , + { + playerMgr().sendDebug( player, "SubGsc002:65971 calling Scene00009: Normal(Talk, FadeIn, QuestReward, QuestComplete, TargetCanMove), id=INFORMATION00435" ); + auto callback = [ & ]( World::Quest& quest, Entity::Player& player , const Event::SceneResult& result ) + { + if( result.numOfResults > 0 && result.getResult( 0 ) == 1 ) + { + player.finishQuest( getId(), result.getResult( 1 ) ); + } + }; + eventMgr().playQuestScene( player, getId(), 9, FADE_OUT | CONDITION_CUTSCENE | HIDE_UI, callback ); + } +}; + +EXPOSE_SCRIPT( SubGsc002 ); diff --git a/src/world/Action/ItemManipulationAction.cpp b/src/world/Action/ItemManipulationAction.cpp new file mode 100644 index 00000000..ac2004c9 --- /dev/null +++ b/src/world/Action/ItemManipulationAction.cpp @@ -0,0 +1,70 @@ +#include "ItemManipulationAction.h" + +#include + +#include "Script/ScriptMgr.h" + +#include "Actor/Player.h" +#include "Actor/BNpc.h" + +#include + +#include +#include "WorldServer.h" + +using namespace Sapphire; +using namespace Sapphire::World::Action; +using namespace Sapphire::Network::Packets::WorldPackets::Server; + +ItemManipulationAction::ItemManipulationAction( Entity::CharaPtr source, uint32_t actionId, uint16_t sequence, + std::shared_ptr< Excel::ExcelStruct< Excel::Action > > actionData, uint32_t delayTime ) : + m_delayTimeMs( delayTime ) +{ + m_id = actionId; + m_pSource = std::move( source ); + m_actionData = std::move( actionData ); + m_sequence = sequence; +} + +void ItemManipulationAction::start() +{ + assert( m_pSource ); + m_startTime = Common::Util::getTimeMs(); + + onStart(); + + execute(); +} + +void ItemManipulationAction::execute() +{ + assert( m_pSource ); + + m_effectBuilder->buildAndSendPackets( m_hitActors ); +} + +void ItemManipulationAction::onFinish() +{ + auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref(); + + // send execute event to action script + scriptMgr.onExecute( *this ); +} + +bool ItemManipulationAction::update() +{ + // action has not been started yet + if( m_startTime == 0 ) + return false; + + uint64_t tickCount = Common::Util::getTimeMs(); + uint32_t delayTime = m_delayTimeMs; + + if( std::difftime( static_cast< time_t >( tickCount ), static_cast< time_t >( m_startTime ) ) > delayTime ) + { + onFinish(); + return true; + } + + return false; +} \ No newline at end of file diff --git a/src/world/Action/ItemManipulationAction.h b/src/world/Action/ItemManipulationAction.h new file mode 100644 index 00000000..d43f79c4 --- /dev/null +++ b/src/world/Action/ItemManipulationAction.h @@ -0,0 +1,26 @@ +#pragma once + +#include "Action.h" +#include + +namespace Sapphire::World::Action +{ + class ItemManipulationAction : public Action + { + public: + ItemManipulationAction( Entity::CharaPtr source, uint32_t actionId, uint16_t sequence, + std::shared_ptr< Excel::ExcelStruct< Excel::Action > > actionData, uint32_t delayTime ); + virtual ~ItemManipulationAction() = default; + + void start() override; + + void execute() override; + + bool update() override; + + private: + void onFinish(); + + uint32_t m_delayTimeMs{}; + }; +} \ No newline at end of file diff --git a/src/world/Actor/Player.cpp b/src/world/Actor/Player.cpp index 4147b2d5..b64d6384 100644 --- a/src/world/Actor/Player.cpp +++ b/src/world/Actor/Player.cpp @@ -1493,13 +1493,19 @@ void Player::dyeItemFromDyeingInfo() if( !itemToDye || !dyeToUse ) return; - uint32_t stainColorID = dyeToUse->getAdditionalData(); - itemToDye->setStain( stainColorID ); + if( !removeItem( dyeToUse->getId() ) ) + return; - // TODO: subtract/remove dye used + uint32_t stainColorID = dyeToUse->getAdditionalData(); + bool shouldDye = stainColorID != 0; + bool invalidateGearSet = stainColorID != itemToDye->getStain(); + itemToDye->setStain( stainColorID ); insertInventoryItem( static_cast< Sapphire::Common::InventoryType >( itemToDyeContainer ), static_cast< uint16_t >( itemToDyeSlot ), itemToDye ); writeItem( itemToDye ); + + auto dyePkt = makeActorControlSelf( getId(), DyeMsg, itemToDye->getId(), shouldDye, invalidateGearSet ); + queuePacket( dyePkt ); } void Player::resetObjSpawnIndex() diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index 9bf2e4c9..41f0a5d4 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -723,6 +723,8 @@ namespace Sapphire::Entity ItemPtr addItem( uint32_t catalogId, uint32_t quantity = 1, bool isHq = false, bool slient = false, bool canMerge = true ); + bool removeItem( uint32_t catalogId, uint32_t quantity = 1, bool isHq = false ); + void moveItem( uint16_t fromInventoryId, uint16_t fromSlotId, uint16_t toInventoryId, uint16_t toSlot ); void swapItem( uint16_t fromInventoryId, uint16_t fromSlotId, uint16_t toInventoryId, uint16_t toSlot ); diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index ad0e7aed..a48515d8 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -700,6 +700,54 @@ Sapphire::ItemPtr Sapphire::Entity::Player::addItem( uint32_t catalogId, uint32_ return item; } +bool Sapphire::Entity::Player::removeItem( uint32_t catalogId, uint32_t quantity, bool isHq ) +{ + std::vector< uint16_t > bags = { Bag0, Bag1, Bag2, Bag3 }; + + for( auto bag : bags ) + { + auto storage = m_storageMap[ bag ]; + + for( uint16_t slot = 0; slot < storage->getMaxSize(); slot++ ) + { + if( quantity == 0 ) + break; + + auto item = storage->getItem( slot ); + + // remove any matching items + if( item && item->getId() == catalogId ) + { + uint32_t count = item->getStackSize(); + uint32_t maxStack = item->getMaxStackSize(); + + // check slot is same quality + if( item->isHq() != isHq ) + continue; + + // update stack + int32_t newStackSize = count - quantity; + if( newStackSize <= 0 ) + { + quantity = std::abs( newStackSize ); + discardItem( bag, slot ); + } + else + { + quantity = 0; + item->setStackSize( newStackSize ); + + insertInventoryItem( static_cast< Sapphire::Common::InventoryType >( bag ), slot, item ); + + writeItem( item ); + } + } + } + } + + return quantity == 0; +} + void Sapphire::Entity::Player::moveItem( uint16_t fromInventoryId, uint16_t fromSlotId, uint16_t toInventoryId, uint16_t toSlot ) { diff --git a/src/world/ForwardsZone.h b/src/world/ForwardsZone.h index 941995fe..adedecbe 100644 --- a/src/world/ForwardsZone.h +++ b/src/world/ForwardsZone.h @@ -87,6 +87,7 @@ TYPE_FORWARD( EventAction ); TYPE_FORWARD( ItemAction ); TYPE_FORWARD( EventItemAction ); TYPE_FORWARD( MountAction ); +TYPE_FORWARD( ItemManipulationAction ); TYPE_FORWARD( EffectBuilder ); TYPE_FORWARD( EffectResult ); diff --git a/src/world/Manager/ActionMgr.cpp b/src/world/Manager/ActionMgr.cpp index c0e00e6f..98d6777e 100644 --- a/src/world/Manager/ActionMgr.cpp +++ b/src/world/Manager/ActionMgr.cpp @@ -6,6 +6,7 @@ #include "Action/ItemAction.h" #include "Action/EventItemAction.h" #include "Action/MountAction.h" +#include "Action/ItemManipulationAction.h" #include "Script/ScriptMgr.h" #include "Actor/Player.h" @@ -45,6 +46,19 @@ void ActionMgr::handlePlacedPlayerAction( Entity::Player& player, uint32_t actio bootstrapAction( player, action, actionData ); } +void ActionMgr::handleItemManipulationAction( Entity::Player& player, uint32_t actionId, + Excel::ExcelStructPtr< Excel::Action > actionData, uint16_t sequence ) +{ + auto action = Action::make_ItemManipulationAction( player.getAsPlayer(), actionId, sequence, actionData, 2500 ); // todo: maybe the delay can be retrieved from data + + player.setCurrentAction( action ); + + if( !action->init() ) + return; + + action->start(); +} + void ActionMgr::handleTargetedPlayerAction( Entity::Player& player, uint32_t actionId, Excel::ExcelStructPtr< Excel::Action > actionData, uint64_t targetId, uint16_t sequence ) { diff --git a/src/world/Manager/ActionMgr.h b/src/world/Manager/ActionMgr.h index dbccd264..5a6de33d 100644 --- a/src/world/Manager/ActionMgr.h +++ b/src/world/Manager/ActionMgr.h @@ -22,6 +22,9 @@ namespace Sapphire::World::Manager bool cacheActionLut(); + void handleItemManipulationAction( Entity::Player& player, uint32_t actionId, + Excel::ExcelStructPtr< Excel::Action > actionData, uint16_t sequence ); + void handleTargetedPlayerAction( Entity::Player& player, uint32_t actionId, std::shared_ptr< Excel::ExcelStruct< Excel::Action > > actionData, uint64_t targetId, uint16_t sequence ); void handlePlacedPlayerAction( Entity::Player& player, uint32_t actionId, diff --git a/src/world/Network/Handlers/ActionHandler.cpp b/src/world/Network/Handlers/ActionHandler.cpp index 963404ad..cc573787 100644 --- a/src/world/Network/Handlers/ActionHandler.cpp +++ b/src/world/Network/Handlers/ActionHandler.cpp @@ -47,7 +47,12 @@ void Sapphire::Network::GameConnection::actionRequest( const Packets::FFXIVARR_P if( !action ) return; - actionMgr.handleTargetedPlayerAction( player, actionId, action, targetId, sequence ); + auto category = static_cast< Common::ActionCategory >( action->data().Category ); + + if( category == Common::ActionCategory::ItemManipulation ) + actionMgr.handleItemManipulationAction( player, actionId, action, sequence ); + else + actionMgr.handleTargetedPlayerAction( player, actionId, action, targetId, sequence ); break; } diff --git a/src/world/Network/Handlers/InventoryHandler.cpp b/src/world/Network/Handlers/InventoryHandler.cpp index 2cd3f5a8..954761a1 100644 --- a/src/world/Network/Handlers/InventoryHandler.cpp +++ b/src/world/Network/Handlers/InventoryHandler.cpp @@ -26,7 +26,7 @@ void Sapphire::Network::GameConnection::itemOperation( const Packets::FFXIVARR_P const auto packet = ZoneChannelPacket< FFXIVIpcClientInventoryItemOperation >( inPacket ); const auto operationType = packet.data().OperationType; - const auto splitCount = packet.data().SrcStack; + const auto splitCount = packet.data().DstStack; const auto fromSlot = packet.data().SrcContainerIndex; const auto fromContainer = packet.data().SrcStorageId; diff --git a/src/world/Network/Handlers/PacketCommandHandler.cpp b/src/world/Network/Handlers/PacketCommandHandler.cpp index b006850e..289bf668 100644 --- a/src/world/Network/Handlers/PacketCommandHandler.cpp +++ b/src/world/Network/Handlers/PacketCommandHandler.cpp @@ -182,6 +182,8 @@ const char* packetCommandToString( uint16_t commandId ) return "MOBHUNT_RECEIPT_ORDER"; case MOBHUNT_BREAK_ORDER: return "MOBHUNT_BREAK_ORDER"; + case DYE_ITEM: + return "DYE_ITEM"; case EMOTE: return "EMOTE"; case EMOTE_WITH_WARP: @@ -624,7 +626,7 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_ player.teleportQuery( static_cast< uint16_t >( param11 ) ); break; } - /* case PacketCommand::DyeItem: // Dye item + case PacketCommand::DYE_ITEM: // Dye item { // param11 = item to dye container // param12 = item to dye slot @@ -632,7 +634,7 @@ void Sapphire::Network::GameConnection::commandHandler( const Packets::FFXIVARR_ // param4 = dye bag slot player.setDyeingInfo( param11, param12, param2, param4 ); break; - }*/ + } case PacketCommand::DIRECTOR_INIT_RETURN: // Director init finish { pZone->onInitDirector( player ); diff --git a/src/world/Network/PacketWrappers/UpdateInventorySlotPacket.h b/src/world/Network/PacketWrappers/UpdateInventorySlotPacket.h index c80c7fb0..3b843113 100644 --- a/src/world/Network/PacketWrappers/UpdateInventorySlotPacket.h +++ b/src/world/Network/PacketWrappers/UpdateInventorySlotPacket.h @@ -11,17 +11,17 @@ namespace Sapphire::Network::Packets::WorldPackets::Server /** * @brief The update inventory-slot packet. */ - class UpdateInventorySlotPacket : public ZoneChannelPacket< FFXIVIpcNormalItem > + class UpdateInventorySlotPacket : public ZoneChannelPacket< FFXIVIpcUpdateItem > { public: UpdateInventorySlotPacket( uint32_t playerId, uint16_t slot, uint16_t storageId, const Item& item, uint32_t contextId ) : - ZoneChannelPacket< FFXIVIpcNormalItem >( playerId, playerId ) + ZoneChannelPacket< FFXIVIpcUpdateItem >( playerId, playerId ) { initialize( slot, storageId, item, contextId ); }; UpdateInventorySlotPacket( uint32_t playerId, uint16_t slot, uint16_t storageId, uint32_t contextId ) : - ZoneChannelPacket< FFXIVIpcNormalItem >( playerId, playerId ) + ZoneChannelPacket< FFXIVIpcUpdateItem >( playerId, playerId ) { initialize( slot, storageId, contextId ); }; @@ -37,6 +37,7 @@ namespace Sapphire::Network::Packets::WorldPackets::Server m_data.item.flags = static_cast< uint8_t >( item.isHq() ? 1 : 0 ); m_data.item.refine = item.getSpiritbond(); m_data.item.stain = static_cast< uint8_t >( item.getStain() ); + m_data.item.durability = item.getDurability(); m_data.item.signatureId = 0; };