diff --git a/dGame/dComponents/MultiZoneEntranceComponent.cpp b/dGame/dComponents/MultiZoneEntranceComponent.cpp index 29091e19..9f823282 100644 --- a/dGame/dComponents/MultiZoneEntranceComponent.cpp +++ b/dGame/dComponents/MultiZoneEntranceComponent.cpp @@ -1,32 +1,32 @@ #include "MultiZoneEntranceComponent.h" + #include "RocketLaunchpadControlComponent.h" #include "InventoryComponent.h" #include "CharacterComponent.h" +#include "GameMessages.h" -MultiZoneEntranceComponent::MultiZoneEntranceComponent(Entity* parent) : Component(parent) { - m_ParentEntity = parent; +void MultiZoneEntranceComponent::LoadConfigData() { std::string zoneString = GeneralUtils::UTF16ToWTF8(m_ParentEntity->GetVar(u"MultiZoneIDs")); - std::stringstream ss(zoneString); - for (int i; ss >> i;) { - m_LUPWorlds.push_back(i); - if (ss.peek() == ';') - ss.ignore(); + const auto zoneSplitStr = GeneralUtils::SplitString(zoneString, ';'); + for (const auto& zone : zoneSplitStr) { + uint32_t mapId; + if (GeneralUtils::TryParse(zone, mapId)) m_LUPWorlds.push_back(mapId); } } -MultiZoneEntranceComponent::~MultiZoneEntranceComponent() {} - void MultiZoneEntranceComponent::OnUse(Entity* originator) { - auto* rocket = originator->GetComponent()->RocketEquip(originator); + auto* characterComponent = originator->GetComponent(); + if (!characterComponent) return; + auto* rocket = characterComponent->RocketEquip(originator); if (!rocket) return; - // the LUP world menu is just the property menu, the client knows how to handle it + // The LUP world menu is just the property menu, the client handles this in flash GameMessages::SendPropertyEntranceBegin(m_ParentEntity->GetObjectID(), m_ParentEntity->GetSystemAddress()); } -void MultiZoneEntranceComponent::OnSelectWorld(Entity* originator, uint32_t index) { +void MultiZoneEntranceComponent::OnSelectWorld(Entity* originator, const uint32_t index) const { auto* rocketLaunchpadControlComponent = m_ParentEntity->GetComponent(); - if (!rocketLaunchpadControlComponent) return; + if (!rocketLaunchpadControlComponent || index >= m_LUPWorlds.size()) return; rocketLaunchpadControlComponent->Launch(originator, m_LUPWorlds[index], 0); } diff --git a/dGame/dComponents/MultiZoneEntranceComponent.h b/dGame/dComponents/MultiZoneEntranceComponent.h index 7f6c5ca0..2b0013a5 100644 --- a/dGame/dComponents/MultiZoneEntranceComponent.h +++ b/dGame/dComponents/MultiZoneEntranceComponent.h @@ -1,15 +1,13 @@ #pragma once #include "Entity.h" -#include "GameMessages.h" #include "Component.h" #include "eReplicaComponentType.h" /** * Component that handles the LUP/WBL rocket launchpad that can be interacted with to travel to WBL worlds. - * */ -class MultiZoneEntranceComponent : public Component { +class MultiZoneEntranceComponent final : public Component { public: inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MULTI_ZONE_ENTRANCE; @@ -17,8 +15,9 @@ public: * Constructor for this component, builds the m_LUPWorlds vector * @param parent parent that contains this component */ - MultiZoneEntranceComponent(Entity* parent); - ~MultiZoneEntranceComponent() override; + MultiZoneEntranceComponent(Entity* parent) : Component(parent) {}; + + void LoadConfigData() override; /** * Handles an OnUse event from some entity, preparing it for launch to some other world @@ -31,10 +30,10 @@ public: * @param originator the entity that triggered the event * @param index index of the world that was selected */ - void OnSelectWorld(Entity* originator, uint32_t index); + void OnSelectWorld(Entity* originator, const uint32_t index) const; private: /** * vector of the LUP World Zone IDs, built from CDServer's LUPZoneIDs table */ - std::vector m_LUPWorlds{}; + std::vector m_LUPWorlds; };