forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuildHooks.cpp
More file actions
218 lines (186 loc) · 5.5 KB
/
GuildHooks.cpp
File metadata and controls
218 lines (186 loc) · 5.5 KB
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
/*
* Copyright (C) 2010 - 2024 Eluna Lua Engine <https://elunaluaengine.github.io/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#include "Hooks.h"
#include "HookHelpers.h"
#include "LuaEngine.h"
#include "BindingMap.h"
#include "ElunaTemplate.h"
using namespace Hooks;
#define START_HOOK(EVENT) \
auto key = EventKey<GuildEvents>(EVENT);\
if (!GuildEventBindings->HasBindingsFor(key))\
return;
void Eluna::OnAddMember(Guild* guild, Player* player, uint32 plRank)
{
START_HOOK(GUILD_EVENT_ON_ADD_MEMBER);
HookPush(guild);
HookPush(player);
HookPush(plRank);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding)
{
START_HOOK(GUILD_EVENT_ON_REMOVE_MEMBER);
HookPush(guild);
HookPush(player);
HookPush(isDisbanding);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnMOTDChanged(Guild* guild, const std::string& newMotd)
{
START_HOOK(GUILD_EVENT_ON_MOTD_CHANGE);
HookPush(guild);
HookPush(newMotd);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnInfoChanged(Guild* guild, const std::string& newInfo)
{
START_HOOK(GUILD_EVENT_ON_INFO_CHANGE);
HookPush(guild);
HookPush(newInfo);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnCreate(Guild* guild, Player* leader, const std::string& name)
{
START_HOOK(GUILD_EVENT_ON_CREATE);
HookPush(guild);
HookPush(leader);
HookPush(name);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnDisband(Guild* guild)
{
START_HOOK(GUILD_EVENT_ON_DISBAND);
HookPush(guild);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair)
{
START_HOOK(GUILD_EVENT_ON_MONEY_WITHDRAW);
HookPush(guild);
HookPush(player);
HookPush(amount);
HookPush(isRepair); // isRepair not a part of Mangos, implement?
int amountIndex = lua_gettop(L) - 1;
int n = SetupStack(GuildEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
amount = CHECKVAL<uint32>(r);
// Update the stack for subsequent calls.
ReplaceArgument(amount, amountIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
#ifdef CATA
void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint64& amount, bool isRepair)
{
START_HOOK(GUILD_EVENT_ON_MONEY_WITHDRAW);
HookPush(guild);
HookPush(player);
HookPush(amount);
HookPush(isRepair); // isRepair not a part of Mangos, implement?
int amountIndex = lua_gettop(L) - 1;
int n = SetupStack(GuildEventBindings, key, 4);
while (n > 0)
{
int r = CallOneFunction(n--, 4, 1);
if (lua_isnumber(L, r))
{
amount = CHECKVAL<uint32>(r);
// Update the stack for subsequent calls.
ReplaceArgument(amount, amountIndex);
}
lua_pop(L, 1);
}
CleanUpStack(4);
}
#endif
void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount)
{
START_HOOK(GUILD_EVENT_ON_MONEY_DEPOSIT);
HookPush(guild);
HookPush(player);
HookPush(amount);
int amountIndex = lua_gettop(L);
int n = SetupStack(GuildEventBindings, key, 3);
while (n > 0)
{
int r = CallOneFunction(n--, 3, 1);
if (lua_isnumber(L, r))
{
amount = CHECKVAL<uint32>(r);
// Update the stack for subsequent calls.
ReplaceArgument(amount, amountIndex);
}
lua_pop(L, 1);
}
CleanUpStack(3);
}
#ifdef CATA
void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint64& amount)
{
START_HOOK(GUILD_EVENT_ON_MONEY_DEPOSIT);
HookPush(guild);
HookPush(player);
HookPush(amount);
int amountIndex = lua_gettop(L);
int n = SetupStack(GuildEventBindings, key, 3);
while (n > 0)
{
int r = CallOneFunction(n--, 3, 1);
if (lua_isnumber(L, r))
{
amount = CHECKVAL<uint32>(r);
// Update the stack for subsequent calls.
ReplaceArgument(amount, amountIndex);
}
lua_pop(L, 1);
}
CleanUpStack(3);
}
#endif
void Eluna::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId,
bool isDestBank, uint8 destContainer, uint8 destSlotId)
{
START_HOOK(GUILD_EVENT_ON_ITEM_MOVE);
HookPush(guild);
HookPush(player);
HookPush(pItem);
HookPush(isSrcBank);
HookPush(srcContainer);
HookPush(srcSlotId);
HookPush(isDestBank);
HookPush(destContainer);
HookPush(destSlotId);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank)
{
START_HOOK(GUILD_EVENT_ON_EVENT);
HookPush(guild);
HookPush(eventType);
HookPush(playerGuid1);
HookPush(playerGuid2);
HookPush(newRank);
CallAllFunctions(GuildEventBindings, key);
}
void Eluna::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId)
{
START_HOOK(GUILD_EVENT_ON_BANK_EVENT);
HookPush(guild);
HookPush(eventType);
HookPush(tabId);
HookPush(playerGuid);
HookPush(itemOrMoney);
HookPush(itemStackCount);
HookPush(destTabId);
CallAllFunctions(GuildEventBindings, key);
}