forked from ElunaLuaEngine/Eluna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGameObjectMethods.h
346 lines (314 loc) · 8.73 KB
/
GameObjectMethods.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
* This program is free software licensed under GPL version 3
* Please see the included DOCS/LICENSE.md for more information
*/
#ifndef GAMEOBJECTMETHODS_H
#define GAMEOBJECTMETHODS_H
/***
* Inherits all methods from: [Object], [WorldObject]
*/
namespace LuaGameObject
{
/**
* Returns 'true' if the [GameObject] can give the specified [Quest]
*
* @param uint32 questId : quest entry Id to check
* @return bool hasQuest
*/
int HasQuest(lua_State* L, GameObject* go)
{
uint32 questId = Eluna::CHECKVAL<uint32>(L, 2);
#if defined TRINITY || AZEROTHCORE
Eluna::Push(L, go->hasQuest(questId));
#else
Eluna::Push(L, go->HasQuest(questId));
#endif
return 1;
}
/**
* Returns 'true' if the [GameObject] is spawned
*
* @return bool isSpawned
*/
int IsSpawned(lua_State* L, GameObject* go)
{
#ifdef CMANGOS
Eluna::Push(L, go->IsSpawned());
#else
Eluna::Push(L, go->isSpawned());
#endif
return 1;
}
/**
* Returns 'true' if the [GameObject] is a transport
*
* @return bool isTransport
*/
int IsTransport(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->IsTransport());
return 1;
}
/**
* Returns 'true' if the [GameObject] is active
*
* @return bool isActive
*/
int IsActive(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->isActiveObject());
return 1;
}
/*int IsDestructible(lua_State* L, GameObject* go) // TODO: Implementation core side
{
Eluna::Push(L, go->IsDestructibleBuilding());
return 1;
}*/
/**
* Returns display ID of the [GameObject]
*
* @return uint32 displayId
*/
int GetDisplayId(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->GetDisplayId());
return 1;
}
/**
* Returns the state of a [GameObject]
* Below are client side [GOState]s off of 3.3.5a
*
* <pre>
* enum GOState
* {
* GO_STATE_ACTIVE = 0, // show in world as used and not reset (closed door open)
* GO_STATE_READY = 1, // show in world as ready (closed door close)
* GO_STATE_ACTIVE_ALTERNATIVE = 2 // show in world as used in alt way and not reset (closed door open by cannon fire)
* };
* </pre>
*
* @return [GOState] goState
*/
int GetGoState(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->GetGoState());
return 1;
}
/**
* Returns the [LootState] of a [GameObject]
* Below are [LootState]s off of 3.3.5a
*
* <pre>
* enum LootState
* {
* GO_NOT_READY = 0,
* GO_READY, // can be ready but despawned, and then not possible activate until spawn
* GO_ACTIVATED,
* GO_JUST_DEACTIVATED
* };
* </pre>
*
* @return [LootState] lootState
*/
int GetLootState(lua_State* L, GameObject* go)
{
#ifdef CMANGOS
Eluna::Push(L, go->GetLootState());
#else
Eluna::Push(L, go->getLootState());
#endif
return 1;
}
/**
* Returns the [Player] that can loot the [GameObject]
*
* Not the original looter and may be nil.
*
* @return [Player] player
*/
int GetLootRecipient(lua_State* L, GameObject* go)
{
Eluna::Push(L, go->GetLootRecipient());
return 1;
}
/**
* Returns the [Group] that can loot the [GameObject]
*
* Not the original looter and may be nil.
*
* @return [Group] group
*/
int GetLootRecipientGroup(lua_State* L, GameObject* go)
{
#if defined TRINITY || AZEROTHCORE
Eluna::Push(L, go->GetLootRecipientGroup());
#else
Eluna::Push(L, go->GetGroupLootRecipient());
#endif
return 1;
}
/**
* Returns the guid of the [GameObject] that is used as the ID in the database
*
* @return uint32 dbguid
*/
int GetDBTableGUIDLow(lua_State* L, GameObject* go)
{
#if defined(TRINITY) || defined(AZEROTHCORE)
Eluna::Push(L, go->GetSpawnId());
#else
// on mangos based this is same as lowguid
Eluna::Push(L, go->GetGUIDLow());
#endif
return 1;
}
/**
* Sets the state of a [GameObject]
*
* <pre>
* enum GOState
* {
* GO_STATE_ACTIVE = 0, // show in world as used and not reset (closed door open)
* GO_STATE_READY = 1, // show in world as ready (closed door close)
* GO_STATE_ACTIVE_ALTERNATIVE = 2 // show in world as used in alt way and not reset (closed door open by cannon fire)
* };
* </pre>
*
* @param [GOState] state : all available go states can be seen above
*/
int SetGoState(lua_State* L, GameObject* go)
{
uint32 state = Eluna::CHECKVAL<uint32>(L, 2, 0);
if (state == 0)
go->SetGoState(GO_STATE_ACTIVE);
else if (state == 1)
go->SetGoState(GO_STATE_READY);
else if (state == 2)
{
#ifdef TRINITY
go->SetGoState(GO_STATE_DESTROYED);
#else
go->SetGoState(GO_STATE_ACTIVE_ALTERNATIVE);
#endif
}
return 0;
}
/**
* Sets the [LootState] of a [GameObject]
* Below are [LootState]s off of 3.3.5a
*
* <pre>
* enum LootState
* {
* GO_NOT_READY = 0,
* GO_READY, // can be ready but despawned, and then not possible activate until spawn
* GO_ACTIVATED,
* GO_JUST_DEACTIVATED
* };
* </pre>
*
* @param [LootState] state : all available loot states can be seen above
*/
int SetLootState(lua_State* L, GameObject* go)
{
uint32 state = Eluna::CHECKVAL<uint32>(L, 2, 0);
if (state == 0)
go->SetLootState(GO_NOT_READY);
else if (state == 1)
go->SetLootState(GO_READY);
else if (state == 2)
go->SetLootState(GO_ACTIVATED);
else if (state == 3)
go->SetLootState(GO_JUST_DEACTIVATED);
return 0;
}
/**
* Saves [GameObject] to the database
*
*/
int SaveToDB(lua_State* /*L*/, GameObject* go)
{
go->SaveToDB();
return 0;
}
/**
* Removes [GameObject] from the world
*
* The object is no longer reachable after this and it is not respawned.
*
* @param bool deleteFromDB : if true, it will delete the [GameObject] from the database
*/
int RemoveFromWorld(lua_State* L, GameObject* go)
{
bool deldb = Eluna::CHECKVAL<bool>(L, 2, false);
// cs_gobject.cpp copy paste
#if defined TRINITY || AZEROTHCORE
ObjectGuid ownerGuid = go->GetOwnerGUID();
#else
ObjectGuid ownerGuid = go->GetOwnerGuid();
#endif
if (ownerGuid)
{
Unit* owner = eObjectAccessor()GetUnit(*go, ownerGuid);
if (!owner || !ownerGuid.IsPlayer())
return 0;
owner->RemoveGameObject(go, false);
}
if (deldb)
{
#ifdef TRINITY
GameObject::DeleteFromDB(go->GetSpawnId());
#else
go->DeleteFromDB();
#endif
}
go->SetRespawnTime(0);
go->Delete();
Eluna::CHECKOBJ<ElunaObject>(L, 1)->Invalidate();
return 0;
}
/**
* Activates a door or a button/lever
*
* @param uint32 delay = 0 : cooldown time in seconds to restore the [GameObject] back to normal. 0 for infinite duration
*/
int UseDoorOrButton(lua_State* L, GameObject* go)
{
uint32 delay = Eluna::CHECKVAL<uint32>(L, 2, 0);
go->UseDoorOrButton(delay);
return 0;
}
/**
* Despawns a [GameObject]
*
* The gameobject may be automatically respawned by the core
*/
int Despawn(lua_State* /*L*/, GameObject* go)
{
go->SetLootState(GO_JUST_DEACTIVATED);
return 0;
}
/**
* Respawns a [GameObject]
*/
int Respawn(lua_State* /*L*/, GameObject* go)
{
go->Respawn();
return 0;
}
/**
* Sets the respawn or despawn time for the gameobject.
*
* Respawn time is also used as despawn time depending on gameobject settings
*
* @param int32 delay = 0 : cooldown time in seconds to respawn or despawn the object. 0 means never
*/
int SetRespawnTime(lua_State* L, GameObject* go)
{
int32 respawn = Eluna::CHECKVAL<int32>(L, 2);
go->SetRespawnTime(respawn);
return 0;
}
};
#endif