/
scriptmanager.cpp
111 lines (92 loc) · 2.7 KB
/
scriptmanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2023 The Forgotten Server Authors. All rights reserved.
// Use of this source code is governed by the GPL-2.0 License that can be found in the LICENSE file.
#include "otpch.h"
#include "scriptmanager.h"
#include "actions.h"
#include "chat.h"
#include "events.h"
#include "globalevent.h"
#include "movement.h"
#include "script.h"
#include "spells.h"
#include "talkaction.h"
#include "weapons.h"
Actions* g_actions = nullptr;
CreatureEvents* g_creatureEvents = nullptr;
Chat* g_chat = nullptr;
Events* g_events = nullptr;
GlobalEvents* g_globalEvents = nullptr;
Spells* g_spells = nullptr;
TalkActions* g_talkActions = nullptr;
MoveEvents* g_moveEvents = nullptr;
Weapons* g_weapons = nullptr;
Scripts* g_scripts = nullptr;
extern LuaEnvironment g_luaEnvironment;
ScriptingManager::~ScriptingManager()
{
delete g_events;
delete g_weapons;
delete g_spells;
delete g_actions;
delete g_talkActions;
delete g_moveEvents;
delete g_chat;
delete g_creatureEvents;
delete g_globalEvents;
delete g_scripts;
}
bool ScriptingManager::loadScriptSystems()
{
if (g_luaEnvironment.loadFile("data/global.lua") == -1) {
std::cout << "[Warning - ScriptingManager::loadScriptSystems] Can not load data/global.lua" << std::endl;
}
g_scripts = new Scripts();
std::cout << ">> Loading lua libs" << std::endl;
if (!g_scripts->loadScripts("scripts/lib", true, false)) {
std::cout << "> ERROR: Unable to load lua libs!" << std::endl;
return false;
}
g_chat = new Chat();
g_weapons = new Weapons();
if (!g_weapons->loadFromXml()) {
std::cout << "> ERROR: Unable to load weapons!" << std::endl;
return false;
}
g_weapons->loadDefaults();
g_spells = new Spells();
if (!g_spells->loadFromXml()) {
std::cout << "> ERROR: Unable to load spells!" << std::endl;
return false;
}
g_actions = new Actions();
if (!g_actions->loadFromXml()) {
std::cout << "> ERROR: Unable to load actions!" << std::endl;
return false;
}
g_talkActions = new TalkActions();
if (!g_talkActions->loadFromXml()) {
std::cout << "> ERROR: Unable to load talk actions!" << std::endl;
return false;
}
g_moveEvents = new MoveEvents();
if (!g_moveEvents->loadFromXml()) {
std::cout << "> ERROR: Unable to load move events!" << std::endl;
return false;
}
g_creatureEvents = new CreatureEvents();
if (!g_creatureEvents->loadFromXml()) {
std::cout << "> ERROR: Unable to load creature events!" << std::endl;
return false;
}
g_globalEvents = new GlobalEvents();
if (!g_globalEvents->loadFromXml()) {
std::cout << "> ERROR: Unable to load global events!" << std::endl;
return false;
}
g_events = new Events();
if (!g_events->load()) {
std::cout << "> ERROR: Unable to load events!" << std::endl;
return false;
}
return true;
}