-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreatureevent.h
135 lines (114 loc) · 4.33 KB
/
creatureevent.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
/**
* 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_CREATUREEVENT_H_73FCAF4608CB41399D53C919316646A9
#define FS_CREATUREEVENT_H_73FCAF4608CB41399D53C919316646A9
#include "luascript.h"
#include "baseevents.h"
#include "enums.h"
class CreatureEvent;
using CreatureEvent_ptr = std::unique_ptr<CreatureEvent>;
enum CreatureEventType_t {
CREATURE_EVENT_NONE,
CREATURE_EVENT_LOGIN,
CREATURE_EVENT_LOGOUT,
CREATURE_EVENT_THINK,
CREATURE_EVENT_PREPAREDEATH,
CREATURE_EVENT_DEATH,
CREATURE_EVENT_KILL,
CREATURE_EVENT_ADVANCE,
CREATURE_EVENT_MODALWINDOW,
CREATURE_EVENT_TEXTEDIT,
CREATURE_EVENT_HEALTHCHANGE,
CREATURE_EVENT_MANACHANGE,
CREATURE_EVENT_EXTENDED_OPCODE, // otclient additional network opcodes
CREATURE_EVENT_ONPROGRESS,
};
class CreatureEvent final : public Event
{
public:
explicit CreatureEvent(LuaScriptInterface* interface);
bool configureEvent(const pugi::xml_node& node) override;
CreatureEventType_t getEventType() const {
return type;
}
void setEventType(CreatureEventType_t eventType) {
type = eventType;
}
const std::string& getName() const {
return eventName;
}
void setName(const std::string& name) {
eventName = name;
}
bool isLoaded() const {
return loaded;
}
void setLoaded(bool b) {
loaded = b;
}
void clearEvent();
void copyEvent(CreatureEvent* creatureEvent);
//scripting
bool executeOnLogin(Player* player) const;
bool executeOnLogout(Player* player) const;
bool executeOnThink(Creature* creature, uint32_t interval);
bool executeOnPrepareDeath(Creature* creature, Creature* killer);
bool executeOnDeath(Creature* creature, Item* corpse, Creature* killer, Creature* mostDamageKiller, bool lastHitUnjustified, bool mostDamageUnjustified);
void executeOnKill(Creature* creature, Creature* target);
bool executeAdvance(Player* player, skills_t, uint32_t, uint32_t);
void executeModalWindow(Player* player, uint32_t modalWindowId, uint8_t buttonId, uint8_t choiceId);
bool executeProgress(Player* player, skills_t skill, uint64_t tries);
bool executeTextEdit(Player* player, Item* item, const std::string& text);
void executeHealthChange(Creature* creature, Creature* attacker, CombatDamage& damage);
void executeManaChange(Creature* creature, Creature* attacker, CombatDamage& damage);
void executeExtendedOpcode(Player* player, uint8_t opcode, const std::string& buffer);
//
private:
std::string getScriptEventName() const override;
std::string eventName;
CreatureEventType_t type;
bool loaded;
};
class CreatureEvents final : public BaseEvents
{
public:
CreatureEvents();
// non-copyable
CreatureEvents(const CreatureEvents&) = delete;
CreatureEvents& operator=(const CreatureEvents&) = delete;
// global events
bool playerLogin(Player* player) const;
bool playerLogout(Player* player) const;
bool playerAdvance(Player* player, skills_t, uint32_t, uint32_t);
bool playerProgress(Player* player, skills_t skill, uint64_t tries);
CreatureEvent* getEventByName(const std::string& name, bool forceLoaded = true);
bool registerLuaEvent(CreatureEvent* event);
void clear(bool fromLua) override final;
void removeInvalidEvents();
private:
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;
//creature events
using CreatureEventMap = std::map<std::string, CreatureEvent>;
CreatureEventMap creatureEvents;
LuaScriptInterface scriptInterface;
};
#endif