diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 75d8d8b..132a0eb 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -22,6 +22,7 @@ #include "Component.h" #include "ControllablePhysicsComponent.h" #include "RenderComponent.h" +#include "RocketLaunchLupComponent.h" #include "CharacterComponent.h" #include "DestroyableComponent.h" #include "BuffComponent.h" @@ -456,9 +457,10 @@ void Entity::Initialize() else comp = new InventoryComponent(this); m_Components.insert(std::make_pair(COMPONENT_TYPE_INVENTORY, comp)); } - - if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ROCKET_LAUNCH_LUP) > 0) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_ROCKET_LAUNCH_LUP, nullptr)); + // if this component exists, then we initialize it. it's value is always 0 + if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_ROCKET_LAUNCH_LUP, -1) != -1) { + auto comp = new RocketLaunchLupComponent(this); + m_Components.insert(std::make_pair(COMPONENT_TYPE_ROCKET_LAUNCH_LUP, comp)); } /** @@ -495,13 +497,6 @@ void Entity::Initialize() std::string customScriptServer; bool hasCustomServerScript = false; - // Custom script for the LUP teleporter - if (m_TemplateID == 14333) - { - hasCustomServerScript = true; - customScriptServer = "scripts\\02_server\\DLU\\L_SB_LUP_TELEPORT.lua"; - } - const auto customScriptServerName = GetVarAsString(u"custom_script_server"); const auto customScriptClientName = GetVarAsString(u"custom_script_client"); diff --git a/dGame/dComponents/RocketLaunchLupComponent.cpp b/dGame/dComponents/RocketLaunchLupComponent.cpp new file mode 100644 index 0000000..5e5db53 --- /dev/null +++ b/dGame/dComponents/RocketLaunchLupComponent.cpp @@ -0,0 +1,55 @@ +#include "RocketLaunchLupComponent.h" +#include "CDClientDatabase.h" +#include "RocketLaunchpadControlComponent.h" +#include "CharacterComponent.h" +#include "Item.h" + +RocketLaunchLupComponent::RocketLaunchLupComponent(Entity* parent) : Component(parent) { + m_Parent = parent; + + // get the lup worlds from the cdclient + std::string query = "SELECT * FROM LUPZoneIDs;"; + auto results = CDClientDatabase::ExecuteQuery(query); + while (!results.eof()) { + // fallback to 1600 incase there is an issue + m_LUPWorlds.push_back(results.getIntField(0, 1600)); + results.nextRow(); + } + results.finalize(); +} + +RocketLaunchLupComponent::~RocketLaunchLupComponent() { + if (!m_rocket) return; + // when we exit the ui we need to unequip the rocket + m_rocket->UnEquip(); +} + +void RocketLaunchLupComponent::OnUse(Entity* originator) { + // the LUP world menu is just the property menu, the client knows how to handle it + GameMessages::SendPropertyEntranceBegin(m_Parent->GetObjectID(), m_Parent->GetSystemAddress()); + + // get the rocket to "equip" it so we are holding it + // taken from the RocketLaunchControlComponent + auto* inventoryComponent = originator->GetComponent(); + auto* characterComponent = originator->GetComponent(); + + if (!inventoryComponent || !characterComponent) return; + + m_rocket = inventoryComponent->FindItemById(characterComponent->GetLastRocketItemID()); + if (!m_rocket) return; + + m_rocket->Equip(true); +} + +void RocketLaunchLupComponent::OnSelectWorld(Entity* originator, uint32_t index, const SystemAddress& sysAddr) { + if (m_rocket) m_rocket->UnEquip(); + + // Add one to index because the actual LUP worlds start at index 1. + index++; + + auto* rocketLaunchpadControlComponent = m_Parent->GetComponent(); + + if (!rocketLaunchpadControlComponent) return; + + rocketLaunchpadControlComponent->Launch(originator, LWOOBJID_EMPTY, m_LUPWorlds[index], 0); +} diff --git a/dGame/dComponents/RocketLaunchLupComponent.h b/dGame/dComponents/RocketLaunchLupComponent.h new file mode 100644 index 0000000..621a80c --- /dev/null +++ b/dGame/dComponents/RocketLaunchLupComponent.h @@ -0,0 +1,25 @@ +#pragma once + +#include "Entity.h" +#include "GameMessages.h" +#include "Component.h" +#include "Item.h" + +/** + * Component that handles the LUP/WBL rocket launchpad that can be interacted with to travel to WBL worlds. + * + */ +class RocketLaunchLupComponent : public Component { +public: + static const uint32_t ComponentType = eReplicaComponentType::COMPONENT_TYPE_ROCKET_LAUNCH_LUP; + + RocketLaunchLupComponent(Entity* parent); + ~RocketLaunchLupComponent() override; + + void OnUse(Entity* originator) override; + + void OnSelectWorld(Entity* originator, uint32_t index, const SystemAddress& sysAddr); +private: + std::vector m_LUPWorlds {}; + Item* m_rocket = nullptr; +}; diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index e8e8493..7cb8ae8 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -26,6 +26,7 @@ #include "TeamManager.h" #include "ChatPackets.h" #include "GameConfig.h" +#include "RocketLaunchLupComponent.h" #include #include @@ -2726,10 +2727,15 @@ void GameMessages::HandleEnterProperty(RakNet::BitStream* inStream, Entity* enti auto* player = Player::GetPlayer(sysAddr); auto* entranceComponent = entity->GetComponent(); + if (entranceComponent != nullptr) { + entranceComponent->OnEnterProperty(player, index, returnToZone, sysAddr); + return; + } - if (entranceComponent == nullptr) return; - - entranceComponent->OnEnterProperty(player, index, returnToZone, sysAddr); + auto rocketLaunchLupComponent = entity->GetComponent(); + if (rocketLaunchLupComponent) { + rocketLaunchLupComponent->OnSelectWorld(player, index, sysAddr); + } } void GameMessages::HandleSetConsumableItem(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) diff --git a/dScripts/BaseConsoleTeleportServer.cpp b/dScripts/BaseConsoleTeleportServer.cpp index a9cd74e..ef2d00e 100644 --- a/dScripts/BaseConsoleTeleportServer.cpp +++ b/dScripts/BaseConsoleTeleportServer.cpp @@ -19,21 +19,6 @@ void BaseConsoleTeleportServer::BaseOnMessageBoxResponse(Entity* self, Entity* s if (button == 1) { - if (self->GetLOT() == 14333) - { - auto* rocketLaunchComponent = self->GetComponent(); - - if (rocketLaunchComponent == nullptr) - { - return; - } - - const auto& teleportZone = self->GetVar(u"transferZoneID"); - - rocketLaunchComponent->Launch(player, LWOOBJID_EMPTY, std::stoi(GeneralUtils::UTF16ToWTF8(teleportZone))); - - return; - } GameMessages::SendSetStunned(player->GetObjectID(), PUSH, player->GetSystemAddress(), player->GetObjectID(), true, true, true, true, true, true, true diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 5036b11..00a253d 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -203,7 +203,6 @@ #include "NtSleepingGuard.h" // DLU Scripts -#include "SbLupTeleport.h" #include "DLUVanityNPC.h" // AM Scripts @@ -767,8 +766,6 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr script = new NjNyaMissionitems(); //DLU: - else if (scriptName == "scripts\\02_server\\DLU\\L_SB_LUP_TELEPORT.lua") - script = new SbLupTeleport(); else if (scriptName == "scripts\\02_server\\DLU\\DLUVanityNPC.lua") script = new DLUVanityNPC(); diff --git a/dScripts/SbLupTeleport.cpp b/dScripts/SbLupTeleport.cpp deleted file mode 100644 index 2ea9c1f..0000000 --- a/dScripts/SbLupTeleport.cpp +++ /dev/null @@ -1,154 +0,0 @@ -#include "SbLupTeleport.h" -#include "dZoneManager.h" -#include "EntityManager.h" -#include "GeneralUtils.h" -#include "GameMessages.h" - -void SbLupTeleport::OnStartup(Entity* self) -{ - self->SetVar(u"currentZone", (int32_t) dZoneManager::Instance()->GetZoneID().GetMapID()); - self->SetVar(u"choiceZone", m_ChoiceZoneID); - self->SetVar(u"teleportAnim", m_TeleportAnim); - self->SetVar(u"teleportString", m_TeleportString); - self->SetVar(u"spawnPoint", m_SpawnPoint); - - args = {}; - - AMFStringValue* callbackClient = new AMFStringValue(); - callbackClient->SetStringValue(std::to_string(self->GetObjectID())); - args.InsertValue("callbackClient", callbackClient); - - AMFStringValue* strIdentifier = new AMFStringValue(); - strIdentifier->SetStringValue("choiceDoor"); - args.InsertValue("strIdentifier", strIdentifier); - - AMFStringValue* title = new AMFStringValue(); - title->SetStringValue("%[LUP_Starbase3001_Launchpad]"); - args.InsertValue("title", title); - - AMFArrayValue* choiceOptions = new AMFArrayValue(); - - { - AMFArrayValue* nsArgs = new AMFArrayValue(); - - AMFStringValue* image = new AMFStringValue(); - image->SetStringValue("textures/ui/zone_thumnails/Deep_Freeze.dds"); - nsArgs->InsertValue("image", image); - - AMFStringValue* caption = new AMFStringValue(); - caption->SetStringValue("%[ZoneTable_1601_DisplayDescription]"); - nsArgs->InsertValue("caption", caption); - - AMFStringValue* identifier = new AMFStringValue(); - identifier->SetStringValue("zoneID_1601"); - nsArgs->InsertValue("identifier", identifier); - - AMFStringValue* tooltipText = new AMFStringValue(); - tooltipText->SetStringValue("%[ZoneTable_1601_summary]"); - nsArgs->InsertValue("tooltipText", tooltipText); - - choiceOptions->PushBackValue(nsArgs); - } - - { - AMFArrayValue* ntArgs = new AMFArrayValue(); - - AMFStringValue* image = new AMFStringValue(); - image->SetStringValue("textures/ui/zone_thumnails/Robot_City.dds"); - ntArgs->InsertValue("image", image); - - AMFStringValue* caption = new AMFStringValue(); - caption->SetStringValue("%[ZoneTable_1602_DisplayDescription]"); - ntArgs->InsertValue("caption", caption); - - AMFStringValue* identifier = new AMFStringValue(); - identifier->SetStringValue("zoneID_1602"); - ntArgs->InsertValue("identifier", identifier); - - AMFStringValue* tooltipText = new AMFStringValue(); - tooltipText->SetStringValue("%[ZoneTable_1602_summary]"); - ntArgs->InsertValue("tooltipText", tooltipText); - - choiceOptions->PushBackValue(ntArgs); - } - - { - AMFArrayValue* ntArgs = new AMFArrayValue(); - - AMFStringValue* image = new AMFStringValue(); - image->SetStringValue("textures/ui/zone_thumnails/Moon_Base.dds"); - ntArgs->InsertValue("image", image); - - AMFStringValue* caption = new AMFStringValue(); - caption->SetStringValue("%[ZoneTable_1603_DisplayDescription]"); - ntArgs->InsertValue("caption", caption); - - AMFStringValue* identifier = new AMFStringValue(); - identifier->SetStringValue("zoneID_1603"); - ntArgs->InsertValue("identifier", identifier); - - AMFStringValue* tooltipText = new AMFStringValue(); - tooltipText->SetStringValue("%[ZoneTable_1603_summary]"); - ntArgs->InsertValue("tooltipText", tooltipText); - - choiceOptions->PushBackValue(ntArgs); - } - - { - AMFArrayValue* ntArgs = new AMFArrayValue(); - - AMFStringValue* image = new AMFStringValue(); - image->SetStringValue("textures/ui/zone_thumnails/Porto_Bello.dds"); - ntArgs->InsertValue("image", image); - - AMFStringValue* caption = new AMFStringValue(); - caption->SetStringValue("%[ZoneTable_1604_DisplayDescription]"); - ntArgs->InsertValue("caption", caption); - - AMFStringValue* identifier = new AMFStringValue(); - identifier->SetStringValue("zoneID_1604"); - ntArgs->InsertValue("identifier", identifier); - - AMFStringValue* tooltipText = new AMFStringValue(); - tooltipText->SetStringValue("%[ZoneTable_1604_summary]"); - ntArgs->InsertValue("tooltipText", tooltipText); - - choiceOptions->PushBackValue(ntArgs); - } - - args.InsertValue("options", choiceOptions); -} - -void SbLupTeleport::OnUse(Entity* self, Entity* user) -{ - auto* player = user; - - //if (CheckChoice(self, player)) - { - GameMessages::SendUIMessageServerToSingleClient(player, player->GetSystemAddress(), "QueueChoiceBox", &args); - } - /*else - { - BaseOnUse(self, player); - }*/ -} - -void SbLupTeleport::OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) -{ - BaseOnMessageBoxResponse(self, sender, button, identifier, userData); -} - -void SbLupTeleport::OnChoiceBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier) -{ - BaseChoiceBoxRespond(self, sender, button, buttonIdentifier, identifier); -} - -void SbLupTeleport::OnTimerDone(Entity* self, std::string timerName) -{ - BaseOnTimerDone(self, timerName); -} - -void SbLupTeleport::OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, int32_t param3) -{ - BaseOnFireEventServerSide(self, sender, args, param1, param2, param3); -} diff --git a/dScripts/SbLupTeleport.h b/dScripts/SbLupTeleport.h deleted file mode 100644 index f6c868d..0000000 --- a/dScripts/SbLupTeleport.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once -#include "CppScripts.h" -#include "ChooseYourDestinationNsToNt.h" -#include "BaseConsoleTeleportServer.h" -#include "AMFFormat.h" - -class SbLupTeleport : public CppScripts::Script, ChooseYourDestinationNsToNt, BaseConsoleTeleportServer -{ -public: - void OnStartup(Entity* self) override; - void OnUse(Entity* self, Entity* user) override; - void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override; - void OnChoiceBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier) override; - void OnTimerDone(Entity* self, std::string timerName) override; - void OnFireEventServerSide(Entity *self, Entity *sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override; - -private: - int32_t m_ChoiceZoneID = 1600; - std::string m_SpawnPoint = "NS_LW"; - std::u16string m_TeleportAnim = u"lup-teleport"; - std::u16string m_TeleportString = u"UI_TRAVEL_TO_LUP_STATION"; - AMFArrayValue args = {}; -};