-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmovement.h
261 lines (224 loc) · 7.44 KB
/
movement.h
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2019 Mark Samman <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef FS_MOVEMENT_H_5E0D2626D4634ACA83AC6509518E5F49
#define FS_MOVEMENT_H_5E0D2626D4634ACA83AC6509518E5F49
#include "baseevents.h"
#include "item.h"
#include "luascript.h"
#include "vocation.h"
extern Vocations g_vocations;
enum MoveEvent_t {
MOVE_EVENT_STEP_IN,
MOVE_EVENT_STEP_OUT,
MOVE_EVENT_EQUIP,
MOVE_EVENT_DEEQUIP,
MOVE_EVENT_ADD_ITEM,
MOVE_EVENT_REMOVE_ITEM,
MOVE_EVENT_ADD_ITEM_ITEMTILE,
MOVE_EVENT_REMOVE_ITEM_ITEMTILE,
MOVE_EVENT_LAST,
MOVE_EVENT_NONE
};
class MoveEvent;
using MoveEvent_ptr = std::unique_ptr<MoveEvent>;
struct MoveEventList {
std::list<MoveEvent> moveEvent[MOVE_EVENT_LAST];
};
using VocEquipMap = std::map<uint16_t, bool>;
class MoveEvents final : public BaseEvents
{
public:
MoveEvents();
~MoveEvents();
// non-copyable
MoveEvents(const MoveEvents&) = delete;
MoveEvents& operator=(const MoveEvents&) = delete;
uint32_t onCreatureMove(Creature* creature, const Tile* tile, MoveEvent_t eventType);
ReturnValue onPlayerEquip(Player* player, Item* item, slots_t slot, bool isCheck);
ReturnValue onPlayerDeEquip(Player* player, Item* item, slots_t slot);
uint32_t onItemMove(Item* item, Tile* tile, bool isAdd);
MoveEvent* getEvent(Item* item, MoveEvent_t eventType);
bool registerLuaEvent(MoveEvent* event);
bool registerLuaFunction(MoveEvent* event);
void clear(bool fromLua) override final;
private:
using MoveListMap = std::map<int32_t, MoveEventList>;
using MovePosListMap = std::map<Position, MoveEventList>;
void clearMap(MoveListMap& map, bool fromLua);
void clearPosMap(MovePosListMap& map, bool fromLua);
LuaScriptInterface& getScriptInterface() override;
std::string getScriptBaseName() const override;
Event_ptr getEvent(const std::string& nodeName) override;
bool registerEvent(Event_ptr event, const pugi::xml_node& node) override;
void addEvent(MoveEvent moveEvent, int32_t id, MoveListMap& map);
void addEvent(MoveEvent moveEvent, const Position& pos, MovePosListMap& map);
MoveEvent* getEvent(const Tile* tile, MoveEvent_t eventType);
MoveEvent* getEvent(Item* item, MoveEvent_t eventType, slots_t slot);
MoveListMap uniqueIdMap;
MoveListMap actionIdMap;
MoveListMap itemIdMap;
MovePosListMap positionMap;
LuaScriptInterface scriptInterface;
};
using StepFunction = std::function<uint32_t(Creature* creature, Item* item, const Position& pos)>;
using MoveFunction = std::function<uint32_t(Item* item, Item* tileItem, const Position& pos)>;
using EquipFunction = std::function<ReturnValue(MoveEvent* moveEvent, Player* player, Item* item, slots_t slot, bool boolean)>;
class MoveEvent final : public Event
{
public:
explicit MoveEvent(LuaScriptInterface* interface);
MoveEvent_t getEventType() const;
void setEventType(MoveEvent_t type);
bool configureEvent(const pugi::xml_node& node) override;
bool loadFunction(const pugi::xml_attribute& attr, bool isScripted) override;
uint32_t fireStepEvent(Creature* creature, Item* item, const Position& pos);
uint32_t fireAddRemItem(Item* item, Item* tileItem, const Position& pos);
ReturnValue fireEquip(Player* player, Item* item, slots_t slot, bool isCheck);
uint32_t getSlot() const {
return slot;
}
//scripting
bool executeStep(Creature* creature, Item* item, const Position& pos);
bool executeEquip(Player* player, Item* item, slots_t slot, bool isCheck);
bool executeAddRemItem(Item* item, Item* tileItem, const Position& pos);
//
//onEquip information
uint32_t getReqLevel() const {
return reqLevel;
}
uint32_t getReqMagLv() const {
return reqMagLevel;
}
bool isPremium() const {
return premium;
}
const std::string& getVocationString() const {
return vocationString;
}
void setVocationString(const std::string& str) {
vocationString = str;
}
uint32_t getWieldInfo() const {
return wieldInfo;
}
const VocEquipMap& getVocEquipMap() const {
return vocEquipMap;
}
void addVocEquipMap(std::string vocName) {
int32_t vocationId = g_vocations.getVocationId(vocName);
if (vocationId != -1) {
vocEquipMap[vocationId] = true;
}
}
bool getTileItem() const {
return tileItem;
}
void setTileItem(bool b) {
tileItem = b;
}
void clearItemIdRange() {
return itemIdRange.clear();
}
const std::vector<uint32_t>& getItemIdRange() const {
return itemIdRange;
}
void addItemId(uint32_t id) {
itemIdRange.emplace_back(id);
}
void clearActionIdRange() {
return actionIdRange.clear();
}
const std::vector<uint32_t>& getActionIdRange() const {
return actionIdRange;
}
void addActionId(uint32_t id) {
actionIdRange.emplace_back(id);
}
void clearUniqueIdRange() {
return uniqueIdRange.clear();
}
const std::vector<uint32_t>& getUniqueIdRange() const {
return uniqueIdRange;
}
void addUniqueId(uint32_t id) {
uniqueIdRange.emplace_back(id);
}
void clearPosList() {
return posList.clear();
}
const std::vector<Position>& getPosList() const {
return posList;
}
void addPosList(Position pos) {
posList.emplace_back(pos);
}
void setSlot(uint32_t s) {
slot = s;
}
uint32_t getRequiredLevel() {
return reqLevel;
}
void setRequiredLevel(uint32_t level) {
reqLevel = level;
}
uint32_t getRequiredMagLevel() {
return reqMagLevel;
}
void setRequiredMagLevel(uint32_t level) {
reqMagLevel = level;
}
bool needPremium() {
return premium;
}
void setNeedPremium(bool b) {
premium = b;
}
uint32_t getWieldInfo() {
return wieldInfo;
}
void setWieldInfo(WieldInfo_t info) {
wieldInfo |= info;
}
static uint32_t StepInField(Creature* creature, Item* item, const Position& pos);
static uint32_t StepOutField(Creature* creature, Item* item, const Position& pos);
static uint32_t AddItemField(Item* item, Item* tileItem, const Position& pos);
static uint32_t RemoveItemField(Item* item, Item* tileItem, const Position& pos);
static ReturnValue EquipItem(MoveEvent* moveEvent, Player* player, Item* item, slots_t slot, bool isCheck);
static ReturnValue DeEquipItem(MoveEvent* moveEvent, Player* player, Item* item, slots_t slot, bool);
MoveEvent_t eventType = MOVE_EVENT_NONE;
StepFunction stepFunction;
MoveFunction moveFunction;
EquipFunction equipFunction;
private:
std::string getScriptEventName() const override;
uint32_t slot = SLOTP_WHEREEVER;
//onEquip information
uint32_t reqLevel = 0;
uint32_t reqMagLevel = 0;
bool premium = false;
std::string vocationString;
uint32_t wieldInfo = 0;
VocEquipMap vocEquipMap;
bool tileItem = false;
std::vector<uint32_t> itemIdRange;
std::vector<uint32_t> actionIdRange;
std::vector<uint32_t> uniqueIdRange;
std::vector<Position> posList;
};
#endif