baseevents.h

main 100 lines · 2.5 KB Raw
Alex Alex Commit Server upload 18/10/2026 23:38
1/**
2 * The Forgotten Server - a free and open-source MMORPG server emulator
3 * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifndef FS_BASEEVENTS_H_9994E32C91CE4D95912A5FDD1F41884A
21#define FS_BASEEVENTS_H_9994E32C91CE4D95912A5FDD1F41884A
22
23#include "luascript.h"
24
25class Event;
26using Event_ptr = std::unique_ptr<Event>;
27
28class Event
29{
30 public:
31 explicit Event(LuaScriptInterface* interface);
32 virtual ~Event() = default;
33
34 virtual bool configureEvent(const pugi::xml_node& node) = 0;
35
36 bool checkScript(const std::string& basePath, const std::string& scriptsName, const std::string& scriptFile) const;
37 bool loadScript(const std::string& scriptFile);
38 bool loadCallback();
39 virtual bool loadFunction(const pugi::xml_attribute&, bool) {
40 return false;
41 }
42
43 bool isScripted() const {
44 return scripted;
45 }
46
47 bool scripted = false;
48 bool fromLua = false;
49
50 int32_t getScriptId() {
51 return scriptId;
52 }
53
54 protected:
55 virtual std::string getScriptEventName() const = 0;
56
57 int32_t scriptId = 0;
58 LuaScriptInterface* scriptInterface = nullptr;
59};
60
61class BaseEvents
62{
63 public:
64 constexpr BaseEvents() = default;
65 virtual ~BaseEvents() = default;
66
67 bool loadFromXml();
68 bool reload();
69 bool isLoaded() const {
70 return loaded;
71 }
72 void reInitState(bool fromLua);
73
74 private:
75 virtual LuaScriptInterface& getScriptInterface() = 0;
76 virtual std::string getScriptBaseName() const = 0;
77 virtual Event_ptr getEvent(const std::string& nodeName) = 0;
78 virtual bool registerEvent(Event_ptr event, const pugi::xml_node& node) = 0;
79 virtual void clear(bool) = 0;
80
81 bool loaded = false;
82};
83
84class CallBack
85{
86 public:
87 CallBack() = default;
88
89 bool loadCallBack(LuaScriptInterface* interface, const std::string& name);
90
91 protected:
92 int32_t scriptId = 0;
93 LuaScriptInterface* scriptInterface = nullptr;
94
95 private:
96 bool loaded = false;
97};
98
99#endif
100
Top