From 3c4b1c87f9150c967223dff506a6a526da861dcf Mon Sep 17 00:00:00 2001 From: Vsevolod Kremianskii Date: Sun, 15 Nov 2020 20:36:43 +0700 Subject: [PATCH] feat: Implement running OnExit trigger scripts --- src/game/blueprint/trigger.cpp | 5 +++++ src/game/blueprint/trigger.h | 2 ++ src/game/object/trigger.cpp | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/src/game/blueprint/trigger.cpp b/src/game/blueprint/trigger.cpp index 4df2106a..1d737d97 100644 --- a/src/game/blueprint/trigger.cpp +++ b/src/game/blueprint/trigger.cpp @@ -35,6 +35,7 @@ void TriggerBlueprint::load(const GffStruct &utt) { boost::to_lower(_tag); _onEnter = utt.getString("ScriptOnEnter"); + _onExit = utt.getString("ScriptOnExit"); } const string &TriggerBlueprint::tag() const { @@ -45,6 +46,10 @@ const string &TriggerBlueprint::onEnter() const { return _onEnter; } +const string &TriggerBlueprint::onExit() const { + return _onExit; +} + } // namespace resource } // namespace reone diff --git a/src/game/blueprint/trigger.h b/src/game/blueprint/trigger.h index 77dc43c5..7d657442 100644 --- a/src/game/blueprint/trigger.h +++ b/src/game/blueprint/trigger.h @@ -33,11 +33,13 @@ public: const std::string &tag() const; const std::string &onEnter() const; + const std::string &onExit() const; private: std::string _resRef; std::string _tag; std::string _onEnter; + std::string _onExit; TriggerBlueprint(const TriggerBlueprint &) = delete; TriggerBlueprint &operator=(const TriggerBlueprint &) = delete; diff --git a/src/game/object/trigger.cpp b/src/game/object/trigger.cpp index 1bd36a62..0c659374 100644 --- a/src/game/object/trigger.cpp +++ b/src/game/object/trigger.cpp @@ -24,6 +24,7 @@ #include "../../resource/resources.h" #include "../blueprint/blueprints.h" +#include "../script/util.h" using namespace std; @@ -77,6 +78,10 @@ void Trigger::update(float dt) { if (isIn(position2d)) continue; tenantsToRemove.insert(tenant); + + if (!_blueprint->onExit().empty()) { + runScript(_blueprint->onExit(), id(), tenant->id(), -1); + } } for (auto &tenant : tenantsToRemove) { _tenants.erase(tenant);