MultiZoneEntranceComponent pass

This commit is contained in:
David Markowitz 2023-07-09 20:52:48 -07:00
parent d2a7e147cc
commit 7ca9e59ef2
2 changed files with 19 additions and 20 deletions

View File

@ -1,32 +1,32 @@
#include "MultiZoneEntranceComponent.h" #include "MultiZoneEntranceComponent.h"
#include "RocketLaunchpadControlComponent.h" #include "RocketLaunchpadControlComponent.h"
#include "InventoryComponent.h" #include "InventoryComponent.h"
#include "CharacterComponent.h" #include "CharacterComponent.h"
#include "GameMessages.h"
MultiZoneEntranceComponent::MultiZoneEntranceComponent(Entity* parent) : Component(parent) { void MultiZoneEntranceComponent::LoadConfigData() {
m_ParentEntity = parent;
std::string zoneString = GeneralUtils::UTF16ToWTF8(m_ParentEntity->GetVar<std::u16string>(u"MultiZoneIDs")); std::string zoneString = GeneralUtils::UTF16ToWTF8(m_ParentEntity->GetVar<std::u16string>(u"MultiZoneIDs"));
std::stringstream ss(zoneString); const auto zoneSplitStr = GeneralUtils::SplitString(zoneString, ';');
for (int i; ss >> i;) { for (const auto& zone : zoneSplitStr) {
m_LUPWorlds.push_back(i); uint32_t mapId;
if (ss.peek() == ';') if (GeneralUtils::TryParse(zone, mapId)) m_LUPWorlds.push_back(mapId);
ss.ignore();
} }
} }
MultiZoneEntranceComponent::~MultiZoneEntranceComponent() {}
void MultiZoneEntranceComponent::OnUse(Entity* originator) { void MultiZoneEntranceComponent::OnUse(Entity* originator) {
auto* rocket = originator->GetComponent<CharacterComponent>()->RocketEquip(originator); auto* characterComponent = originator->GetComponent<CharacterComponent>();
if (!characterComponent) return;
auto* rocket = characterComponent->RocketEquip(originator);
if (!rocket) return; 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()); 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<RocketLaunchpadControlComponent>(); auto* rocketLaunchpadControlComponent = m_ParentEntity->GetComponent<RocketLaunchpadControlComponent>();
if (!rocketLaunchpadControlComponent) return; if (!rocketLaunchpadControlComponent || index >= m_LUPWorlds.size()) return;
rocketLaunchpadControlComponent->Launch(originator, m_LUPWorlds[index], 0); rocketLaunchpadControlComponent->Launch(originator, m_LUPWorlds[index], 0);
} }

View File

@ -1,15 +1,13 @@
#pragma once #pragma once
#include "Entity.h" #include "Entity.h"
#include "GameMessages.h"
#include "Component.h" #include "Component.h"
#include "eReplicaComponentType.h" #include "eReplicaComponentType.h"
/** /**
* Component that handles the LUP/WBL rocket launchpad that can be interacted with to travel to WBL worlds. * 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: public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MULTI_ZONE_ENTRANCE; inline static const eReplicaComponentType ComponentType = eReplicaComponentType::MULTI_ZONE_ENTRANCE;
@ -17,8 +15,9 @@ public:
* Constructor for this component, builds the m_LUPWorlds vector * Constructor for this component, builds the m_LUPWorlds vector
* @param parent parent that contains this component * @param parent parent that contains this component
*/ */
MultiZoneEntranceComponent(Entity* parent); MultiZoneEntranceComponent(Entity* parent) : Component(parent) {};
~MultiZoneEntranceComponent() override;
void LoadConfigData() override;
/** /**
* Handles an OnUse event from some entity, preparing it for launch to some other world * 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 originator the entity that triggered the event
* @param index index of the world that was selected * @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: private:
/** /**
* vector of the LUP World Zone IDs, built from CDServer's LUPZoneIDs table * vector of the LUP World Zone IDs, built from CDServer's LUPZoneIDs table
*/ */
std::vector<LWOMAPID> m_LUPWorlds{}; std::vector<LWOMAPID> m_LUPWorlds;
}; };