forked from otland/forgottenserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovement.h
172 lines (139 loc) · 5.14 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
/**
* The Forgotten Server - a free and open-source MMORPG server emulator
* Copyright (C) 2016 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"
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;
struct MoveEventList {
std::list<MoveEvent*> moveEvent[MOVE_EVENT_LAST];
};
typedef std::map<uint16_t, bool> VocEquipMap;
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, const Position& fromPos, MoveEvent_t eventType);
uint32_t onPlayerEquip(Player* player, Item* item, slots_t slot, bool isCheck);
uint32_t onPlayerDeEquip(Player* player, Item* item, slots_t slot);
uint32_t onItemMove(Item* item, Tile* tile, bool isAdd);
MoveEvent* getEvent(Item* item, MoveEvent_t eventType);
protected:
typedef std::map<int32_t, MoveEventList> MoveListMap;
void clearMap(MoveListMap& map);
typedef std::map<Position, MoveEventList> MovePosListMap;
void clear() final;
LuaScriptInterface& getScriptInterface() final;
std::string getScriptBaseName() const final;
Event* getEvent(const std::string& nodeName) final;
bool registerEvent(Event* event, const pugi::xml_node& node) final;
void registerItemID(int32_t itemId, MoveEvent_t eventType);
void registerActionID(int32_t actionId, MoveEvent_t eventType);
void registerUniqueID(int32_t uniqueId, MoveEvent_t eventType);
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;
};
typedef uint32_t (StepFunction)(Creature* creature, Item* item, const Position& pos, const Position& fromPos);
typedef uint32_t (MoveFunction)(Item* item, Item* tileItem, const Position& pos);
typedef uint32_t (EquipFunction)(MoveEvent* moveEvent, Player* player, Item* item, slots_t slot, bool boolean);
class MoveEvent final : public Event
{
public:
explicit MoveEvent(LuaScriptInterface* interface);
explicit MoveEvent(const MoveEvent* copy);
MoveEvent_t getEventType() const;
void setEventType(MoveEvent_t type);
bool configureEvent(const pugi::xml_node& node) final;
bool loadFunction(const pugi::xml_attribute& attr) final;
uint32_t fireStepEvent(Creature* creature, Item* item, const Position& pos, const Position& fromPos);
uint32_t fireAddRemItem(Item* item, Item* tileItem, const Position& pos);
uint32_t fireEquip(Player* player, Item* item, slots_t slot, bool boolean);
uint32_t getSlot() const {
return slot;
}
//scripting
bool executeStep(Creature* creature, Item* item, const Position& pos, const Position& fromPos);
bool executeEquip(Player* player, Item* item, slots_t slot);
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;
}
uint32_t getWieldInfo() const {
return wieldInfo;
}
const VocEquipMap& getVocEquipMap() const {
return vocEquipMap;
}
protected:
std::string getScriptEventName() const final;
static StepFunction StepInField;
static StepFunction StepOutField;
static MoveFunction AddItemField;
static MoveFunction RemoveItemField;
static EquipFunction EquipItem;
static EquipFunction DeEquipItem;
MoveEvent_t eventType;
StepFunction* stepFunction;
MoveFunction* moveFunction;
EquipFunction* equipFunction;
uint32_t slot;
//onEquip information
uint32_t reqLevel;
uint32_t reqMagLevel;
bool premium;
std::string vocationString;
uint32_t wieldInfo;
VocEquipMap vocEquipMap;
};
#endif