Files
DarkflameServer/dGame/dComponents/MultiZoneEntranceComponent.cpp
Aaron Kimbrell 7a0dba22a5 refactor(component): use is a RequestUse message handler
Components no longer have a virtual OnUse; each component that reacts to a
use registers a RequestUse handler, like the client's components. The entity
runs the INTERACT trigger and the script, then delivers a RequestUseEvent
(carrying the user) to the handlers. The mission choice of a multi-interact
use goes only to the mission offer, as before. Switches keep a direct
EnterIfResponding for touches and pets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 07:55:55 -05:00

44 lines
1.7 KiB
C++

#include "MultiZoneEntranceComponent.h"
#include "ObjectMessages.h"
#include "PropertyMessages.h"
#include "RocketLaunchpadControlComponent.h"
#include "InventoryComponent.h"
#include "CharacterComponent.h"
MultiZoneEntranceComponent::MultiZoneEntranceComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
RegisterMsg(&MultiZoneEntranceComponent::OnRequestUse);
m_Parent = parent;
std::string zoneString = GeneralUtils::UTF16ToWTF8(m_Parent->GetVar<std::u16string>(u"MultiZoneIDs"));
std::stringstream ss(zoneString);
for (int i; ss >> i;) {
m_LUPWorlds.push_back(i);
if (ss.peek() == ';')
ss.ignore();
}
}
MultiZoneEntranceComponent::~MultiZoneEntranceComponent() {}
bool MultiZoneEntranceComponent::OnRequestUse(GameMessages::RequestUseEvent& event) {
if (event.msg.IsMissionChoice()) return false;
auto* const originator = event.user;
auto* const characterComponent = originator->GetComponent<CharacterComponent>();
if (!characterComponent) return true;
auto* rocket = characterComponent->RocketEquip(originator);
if (!rocket) return true;
// the LUP world menu is just the property menu, the client knows how to handle it
GameMessages::PropertyEntranceBegin msg;
msg.target = m_Parent->GetObjectID();
msg.Send(originator->GetSystemAddress());
return true;
}
void MultiZoneEntranceComponent::OnSelectWorld(Entity* originator, uint32_t index) {
auto* rocketLaunchpadControlComponent = m_Parent->GetComponent<RocketLaunchpadControlComponent>();
if (!rocketLaunchpadControlComponent || index >= m_LUPWorlds.size()) return;
rocketLaunchpadControlComponent->Launch(originator, m_LUPWorlds[index], 0, static_cast<int32_t>(index));
}