forked from celguar/mangos-eluna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectMethods.h
464 lines (429 loc) · 13 KB
/
ObjectMethods.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/*
* 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 OBJECTMETHODS_H
#define OBJECTMETHODS_H
/***
* A basic game object (either an [Item] or a [WorldObject]).
*
* Objects in MaNGOS/Trinity are stored an a giant block of "values".
* Subclasses of Object, like [WorldObject], extend the block with more data specific to that subclass.
* Further subclasses, like [Player], extend it even further.
*
* A detailed map of all the fields in this data block can be found in the UpdateFields.h file of your emulator
* (it varies depending on the expansion supported).
*
* The GetValue methods in this class (e.g. [Object:GetInt32Value]) provide low-level access to the data block.
* Other methods, like [Object:HasFlag] and [Object:GetScale], merely wrap the GetValue methods and provide a simpler interface.
*
* Inherits all methods from: none
*/
namespace LuaObject
{
/**
* Returns `true` if the specified flag is set, otherwise `false`.
*
* @param uint16 index : the index of the flags data in the [Object]
* @param uint32 flag : the flag to check for in the flags data
* @return bool hasFlag
*/
int HasFlag(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint32 flag = Eluna::CHECKVAL<uint32>(L, 3);
Eluna::Push(L, obj->HasFlag(index, flag));
return 1;
}
/**
* Returns `true` if the [Object] has been added to its [Map], otherwise `false`.
*
* @return bool inWorld
*/
int IsInWorld(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->IsInWorld());
return 1;
}
/**
* Returns the data at the specified index, casted to a signed 32-bit integer.
*
* @param uint16 index
* @return int32 value
*/
int GetInt32Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
Eluna::Push(L, obj->GetInt32Value(index));
return 1;
}
/**
* Returns the data at the specified index, casted to a unsigned 32-bit integer.
*
* @param uint16 index
* @return uint32 value
*/
int GetUInt32Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
Eluna::Push(L, obj->GetUInt32Value(index));
return 1;
}
/**
* Returns the data at the specified index, casted to a single-precision floating point value.
*
* @param uint16 index
* @return float value
*/
int GetFloatValue(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
Eluna::Push(L, obj->GetFloatValue(index));
return 1;
}
/**
* Returns the data at the specified index and offset, casted to an unsigned 8-bit integer.
*
* E.g. if you want the second byte at index 10, you would pass in 1 as the offset.
*
* @param uint16 index
* @param uint8 offset : should be 0, 1, 2, or 3
* @return uint8 value
*/
int GetByteValue(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3);
Eluna::Push(L, obj->GetByteValue(index, offset));
return 1;
}
/**
* Returns the data at the specified index and offset, casted to a signed 16-bit integer.
*
* E.g. if you want the second half-word at index 10, you would pass in 1 as the offset.
*
* @param uint16 index
* @param uint8 offset : should be 0 or 1
* @return uint16 value
*/
int GetUInt16Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3);
Eluna::Push(L, obj->GetUInt16Value(index, offset));
return 1;
}
/**
* Returns the scale/size of the [Object].
*
* This affects the size of a [WorldObject] in-game, but [Item]s don't have a "scale".
*
* @return float scale
*/
int GetScale(lua_State* L, Object* obj)
{
#ifndef AZEROTHCORE
Eluna::Push(L, obj->GetObjectScale());
#else
Eluna::Push(L, obj->GetFloatValue(OBJECT_FIELD_SCALE_X));
#endif
return 1;
}
/**
* Returns the entry of the [Object].
*
* [Player]s do not have an "entry".
*
* @return uint32 entry
*/
int GetEntry(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->GetEntry());
return 1;
}
/**
* Returns the GUID of the [Object].
*
* GUID is an unique identifier for the object.
*
* However on MaNGOS and cMangos creatures and gameobjects inside different maps can share
* the same GUID but not on the same map.
*
* On TrinityCore this value is unique across all maps
*
* @return ObjectGuid guid
*/
int GetGUID(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->GET_GUID());
return 1;
}
/**
* Returns the low-part of the [Object]'s GUID.
*
* On TrinityCore all low GUIDs are different for all objects of the same type.
* For example creatures in instances are assigned new GUIDs when the Map is created.
*
* On MaNGOS and cMaNGOS low GUIDs are unique only on the same map.
* For example creatures in instances use the same low GUID assigned for that spawn in the database.
* This is why to identify a creature you have to know the instanceId and low GUID. See [Map:GetIntstanceId]
*
* @return uint32 guidLow
*/
int GetGUIDLow(lua_State* L, Object* obj)
{
#if defined TRINITY || AZEROTHCORE
Eluna::Push(L, obj->GetGUID().GetCounter());
#else
Eluna::Push(L, obj->GetGUIDLow());
#endif
return 1;
}
/**
* Returns the TypeId of the [Object].
*
* enum TypeID
* {
* TYPEID_OBJECT = 0,
* TYPEID_ITEM = 1,
* TYPEID_CONTAINER = 2,
* TYPEID_UNIT = 3,
* TYPEID_PLAYER = 4,
* TYPEID_GAMEOBJECT = 5,
* TYPEID_DYNAMICOBJECT = 6,
* TYPEID_CORPSE = 7
* };
*
* @return uint8 typeID
*/
int GetTypeId(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->GetTypeId());
return 1;
}
/**
* Returns the data at the specified index, casted to an unsigned 64-bit integer.
*
* @param uint16 index
* @return uint64 value
*/
int GetUInt64Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
Eluna::Push(L, obj->GetUInt64Value(index));
return 1;
}
/**
* Sets the specified flag in the data value at the specified index.
*
* If the flag was already set, it remains set.
*
* To remove a flag, use [Object:RemoveFlag].
*
* @param uint16 index
* @param uint32 value
*/
int SetFlag(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint32 flag = Eluna::CHECKVAL<uint32>(L, 3);
obj->SetFlag(index, flag);
return 0;
}
/**
* Sets the data at the specified index to the given value, converted to a signed 32-bit integer.
*
* @param uint16 index
* @param int32 value
*/
int SetInt32Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
int32 value = Eluna::CHECKVAL<int32>(L, 3);
obj->SetInt32Value(index, value);
return 0;
}
/**
* Sets the data at the specified index to the given value, converted to an unsigned 32-bit integer.
*
* @param uint16 index
* @param uint32 value
*/
int SetUInt32Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint32 value = Eluna::CHECKVAL<uint32>(L, 3);
obj->SetUInt32Value(index, value);
return 0;
}
/**
* Sets the data at the specified index to the given value, converted to an unsigned 32-bit integer.
*
* @param uint16 index
* @param uint32 value
*/
int UpdateUInt32Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint32 value = Eluna::CHECKVAL<uint32>(L, 3);
obj->UpdateUInt32Value(index, value);
return 0;
}
/**
* Sets the data at the specified index to the given value, converted to a single-precision floating point value.
*
* @param uint16 index
* @param float value
*/
int SetFloatValue(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
float value = Eluna::CHECKVAL<float>(L, 3);
obj->SetFloatValue(index, value);
return 0;
}
/**
* Sets the data at the specified index and offset to the given value, converted to an unsigned 8-bit integer.
*
* @param uint16 index
* @param uint8 offset : should be 0, 1, 2, or 3
* @param uint8 value
*/
int SetByteValue(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3);
uint8 value = Eluna::CHECKVAL<uint8>(L, 4);
obj->SetByteValue(index, offset, value);
return 0;
}
/**
* Sets the data at the specified index to the given value, converted to an unsigned 16-bit integer.
*
* @param uint16 index
* @param uint8 offset : should be 0 or 1
* @param uint16 value
*/
int SetUInt16Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3);
uint16 value = Eluna::CHECKVAL<uint16>(L, 4);
obj->SetUInt16Value(index, offset, value);
return 0;
}
/**
* Sets the data at the specified index to the given value, converted to a signed 16-bit integer.
*
* @param uint16 index
* @param uint8 offset : should be 0 or 1
* @param int16 value
*/
int SetInt16Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint8 offset = Eluna::CHECKVAL<uint8>(L, 3);
int16 value = Eluna::CHECKVAL<int16>(L, 4);
obj->SetInt16Value(index, offset, value);
return 0;
}
/**
* Sets the [Object]'s scale/size to the given value.
*
* @param float scale
*/
int SetScale(lua_State* L, Object* obj)
{
float size = Eluna::CHECKVAL<float>(L, 2);
obj->SetObjectScale(size);
return 0;
}
/**
* Sets the data at the specified index to the given value, converted to an unsigned 64-bit integer.
*
* @param uint16 index
* @param uint64 value
*/
int SetUInt64Value(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint64 value = Eluna::CHECKVAL<uint64>(L, 3);
obj->SetUInt64Value(index, value);
return 0;
}
/**
* Removes a flag from the value at the specified index.
*
* @param uint16 index
* @param uint32 flag
*/
int RemoveFlag(lua_State* L, Object* obj)
{
uint16 index = Eluna::CHECKVAL<uint16>(L, 2);
uint32 flag = Eluna::CHECKVAL<uint32>(L, 3);
obj->RemoveFlag(index, flag);
return 0;
}
/**
* Attempts to convert the [Object] to a [Corpse].
*
* If the [Object] is not a [Corpse], returns `nil`.
*
* @return [Corpse] corpse : the [Object] as a [Corpse], or `nil`
*/
int ToCorpse(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->ToCorpse());
return 1;
}
/**
* Attempts to convert the [Object] to a [GameObject].
*
* If the [Object] is not a [GameObject], returns `nil`.
*
* @return [GameObject] gameObject : the [Object] as a [GameObject], or `nil`
*/
int ToGameObject(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->ToGameObject());
return 1;
}
/**
* Attempts to convert the [Object] to a [Unit].
*
* If the [Object] is not a [Unit], returns `nil`.
*
* @return [Unit] unit : the [Object] as a [Unit], or `nil`
*/
int ToUnit(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->ToUnit());
return 1;
}
/**
* Attempts to convert the [Object] to a [Creature].
*
* If the [Object] is not a [Creature], returns `nil`.
*
* @return [Creature] creature : the [Object] as a [Creature], or `nil`
*/
int ToCreature(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->ToCreature());
return 1;
}
/**
* Attempts to convert the [Object] to a [Player].
*
* If the [Object] is not a [Player], returns `nil`.
*
* @return [Player] player : the [Object] as a [Player], or `nil`
*/
int ToPlayer(lua_State* L, Object* obj)
{
Eluna::Push(L, obj->ToPlayer());
return 1;
}
};
#endif