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>
This commit is contained in:
Aaron Kimbrell
2026-10-01 07:55:55 -05:00
parent 50bfa623ca
commit 7a0dba22a5
33 changed files with 166 additions and 91 deletions

View File

@@ -1,4 +1,5 @@
#include "SwitchComponent.h"
#include "ObjectMessages.h"
#include "EntityManager.h"
#include "eTriggerEventType.h"
#include "RenderComponent.h"
@@ -8,6 +9,7 @@
std::vector<SwitchComponent*> SwitchComponent::petSwitches;
SwitchComponent::SwitchComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
RegisterMsg(&SwitchComponent::OnRequestUse);
m_Active = false;
m_ResetTime = m_Parent->GetVarAs<int32_t>(u"switch_reset_time");
@@ -34,7 +36,7 @@ void SwitchComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitial
outBitStream.Write(m_Active);
}
void SwitchComponent::OnUse(Entity* originator) {
void SwitchComponent::EnterIfResponding(Entity* originator) {
const auto* const destroyableComponent = originator->GetComponent<DestroyableComponent>();
if (!destroyableComponent) return;
for (const auto faction : m_FactionsToRespondTo) {
@@ -45,6 +47,12 @@ void SwitchComponent::OnUse(Entity* originator) {
}
}
bool SwitchComponent::OnRequestUse(GameMessages::RequestUseEvent& event) {
if (event.msg.IsMissionChoice()) return false;
EnterIfResponding(event.user);
return true;
}
void SwitchComponent::SetActive(bool active) {
m_Active = active;