mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-16 00:35:27 +00:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user