mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-16 16:55: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:
@@ -1565,7 +1565,7 @@ void Entity::OnCollisionPhantom(const LWOOBJID otherEntity) {
|
||||
|
||||
SwitchComponent* const switchComp = GetComponent<SwitchComponent>();
|
||||
if (switchComp) {
|
||||
switchComp->OnUse(other);
|
||||
switchComp->EnterIfResponding(other);
|
||||
}
|
||||
|
||||
TriggerEvent(eTriggerEventType::ENTER, other);
|
||||
@@ -1635,16 +1635,21 @@ void Entity::OnEmoteReceived(const int32_t emote, Entity* target) {
|
||||
GetScript()->OnEmoteReceived(this, emote, target);
|
||||
}
|
||||
|
||||
void Entity::OnUse(Entity* originator) {
|
||||
TriggerEvent(eTriggerEventType::INTERACT, originator);
|
||||
|
||||
GetScript()->OnUse(this, originator);
|
||||
|
||||
for (const auto& component : m_Components | std::views::values) {
|
||||
if (!component) continue;
|
||||
|
||||
component->OnUse(originator);
|
||||
void Entity::RequestUse(const GameMessages::RequestUse& msg, Entity& user) {
|
||||
if (!msg.IsMissionChoice()) {
|
||||
TriggerEvent(eTriggerEventType::INTERACT, &user);
|
||||
GetScript()->OnUse(this, &user);
|
||||
}
|
||||
|
||||
GameMessages::RequestUseEvent event(msg, user);
|
||||
HandleMsg(event);
|
||||
}
|
||||
|
||||
void Entity::OnUse(Entity* originator) {
|
||||
GameMessages::RequestUse msg;
|
||||
msg.target = originator->GetObjectID();
|
||||
msg.object = m_ObjectID;
|
||||
RequestUse(msg, *originator);
|
||||
}
|
||||
|
||||
void Entity::OnHitOrHealResult(Entity* attacker, int32_t damage) {
|
||||
|
||||
Reference in New Issue
Block a user