Updated Copyright year to 2013
[getmangos.git] / src / game / GameObject.h
blob459eb794fff672976a6f65ba929c9ed3e3cc3f69
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOSSERVER_GAMEOBJECT_H
20 #define MANGOSSERVER_GAMEOBJECT_H
22 #include "Common.h"
23 #include "SharedDefines.h"
24 #include "Object.h"
25 #include "LootMgr.h"
26 #include "Database/DatabaseEnv.h"
28 // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform
29 #if defined( __GNUC__ )
30 #pragma pack(1)
31 #else
32 #pragma pack(push,1)
33 #endif
35 // from `gameobject_template`
36 struct GameObjectInfo
38 uint32 id;
39 uint32 type;
40 uint32 displayId;
41 char* name;
42 char* IconName;
43 char* castBarCaption;
44 char* unk1;
45 uint32 faction;
46 uint32 flags;
47 float size;
48 uint32 questItems[6];
49 union // different GO types have different data field
51 //0 GAMEOBJECT_TYPE_DOOR
52 struct
54 uint32 startOpen; //0 used client side to determine GO_ACTIVATED means open/closed
55 uint32 lockId; //1 -> Lock.dbc
56 uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / IN_MILLISECONDS (previous was 0x10000)
57 uint32 noDamageImmune; //3 break opening whenever you recieve damage?
58 uint32 openTextID; //4 can be used to replace castBarCaption?
59 uint32 closeTextID; //5
60 uint32 ignoredByPathing; //6
61 } door;
62 //1 GAMEOBJECT_TYPE_BUTTON
63 struct
65 uint32 startOpen; //0
66 uint32 lockId; //1 -> Lock.dbc
67 uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / IN_MILLISECONDS (previous was 0x10000)
68 uint32 linkedTrapId; //3
69 uint32 noDamageImmune; //4 isBattlegroundObject
70 uint32 large; //5
71 uint32 openTextID; //6 can be used to replace castBarCaption?
72 uint32 closeTextID; //7
73 uint32 losOK; //8
74 } button;
75 //2 GAMEOBJECT_TYPE_QUESTGIVER
76 struct
78 uint32 lockId; //0 -> Lock.dbc
79 uint32 questList; //1
80 uint32 pageMaterial; //2
81 uint32 gossipID; //3
82 uint32 customAnim; //4
83 uint32 noDamageImmune; //5
84 uint32 openTextID; //6 can be used to replace castBarCaption?
85 uint32 losOK; //7
86 uint32 allowMounted; //8
87 uint32 large; //9
88 } questgiver;
89 //3 GAMEOBJECT_TYPE_CHEST
90 struct
92 uint32 lockId; //0 -> Lock.dbc
93 uint32 lootId; //1
94 uint32 chestRestockTime; //2
95 uint32 consumable; //3
96 uint32 minSuccessOpens; //4
97 uint32 maxSuccessOpens; //5
98 uint32 eventId; //6 lootedEvent
99 uint32 linkedTrapId; //7
100 uint32 questId; //8 not used currently but store quest required for GO activation for player
101 uint32 level; //9
102 uint32 losOK; //10
103 uint32 leaveLoot; //11
104 uint32 notInCombat; //12
105 uint32 logLoot; //13
106 uint32 openTextID; //14 can be used to replace castBarCaption?
107 uint32 groupLootRules; //15
108 uint32 floatingTooltip; //16
109 } chest;
110 //4 GAMEOBJECT_TYPE_BINDER - empty
111 //5 GAMEOBJECT_TYPE_GENERIC
112 struct
114 uint32 floatingTooltip; //0
115 uint32 highlight; //1
116 uint32 serverOnly; //2
117 uint32 large; //3
118 uint32 floatOnWater; //4
119 uint32 questID; //5
120 } _generic;
121 //6 GAMEOBJECT_TYPE_TRAP
122 struct
124 uint32 lockId; //0 -> Lock.dbc
125 uint32 level; //1
126 uint32 radius; //2 radius for trap activation
127 uint32 spellId; //3
128 uint32 charges; //4 need respawn (if > 0)
129 uint32 cooldown; //5 time in secs
130 uint32 autoCloseTime; //6 secs till autoclose = autoCloseTime / IN_MILLISECONDS (previous was 0x10000)
131 uint32 startDelay; //7
132 uint32 serverOnly; //8
133 uint32 stealthed; //9
134 uint32 large; //10
135 uint32 stealthAffected; //11
136 uint32 openTextID; //12 can be used to replace castBarCaption?
137 uint32 closeTextID; //13
138 uint32 ignoreTotems; //14
139 } trap;
140 //7 GAMEOBJECT_TYPE_CHAIR
141 struct
143 uint32 slots; //0
144 uint32 height; //1
145 uint32 onlyCreatorUse; //2
146 uint32 triggeredEvent; //3
147 } chair;
148 //8 GAMEOBJECT_TYPE_SPELL_FOCUS
149 struct
151 uint32 focusId; //0
152 uint32 dist; //1
153 uint32 linkedTrapId; //2
154 uint32 serverOnly; //3
155 uint32 questID; //4
156 uint32 large; //5
157 uint32 floatingTooltip; //6
158 } spellFocus;
159 //9 GAMEOBJECT_TYPE_TEXT
160 struct
162 uint32 pageID; //0
163 uint32 language; //1
164 uint32 pageMaterial; //2
165 uint32 allowMounted; //3
166 } text;
167 //10 GAMEOBJECT_TYPE_GOOBER
168 struct
170 uint32 lockId; //0 -> Lock.dbc
171 uint32 questId; //1
172 uint32 eventId; //2
173 uint32 autoCloseTime; //3 secs till autoclose = autoCloseTime / IN_MILLISECONDS (previous was 0x10000)
174 uint32 customAnim; //4
175 uint32 consumable; //5
176 uint32 cooldown; //6
177 uint32 pageId; //7
178 uint32 language; //8
179 uint32 pageMaterial; //9
180 uint32 spellId; //10
181 uint32 noDamageImmune; //11
182 uint32 linkedTrapId; //12
183 uint32 large; //13
184 uint32 openTextID; //14 can be used to replace castBarCaption?
185 uint32 closeTextID; //15
186 uint32 losOK; //16 isBattlegroundObject
187 uint32 allowMounted; //17
188 uint32 floatingTooltip; //18
189 uint32 gossipID; //19
190 uint32 WorldStateSetsState; //20
191 } goober;
192 //11 GAMEOBJECT_TYPE_TRANSPORT
193 struct
195 uint32 pause; //0
196 uint32 startOpen; //1
197 uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / IN_MILLISECONDS (previous was 0x10000)
198 uint32 pause1EventID; //3
199 uint32 pause2EventID; //4
200 } transport;
201 //12 GAMEOBJECT_TYPE_AREADAMAGE
202 struct
204 uint32 lockId; //0
205 uint32 radius; //1
206 uint32 damageMin; //2
207 uint32 damageMax; //3
208 uint32 damageSchool; //4
209 uint32 autoCloseTime; //5 secs till autoclose = autoCloseTime / IN_MILLISECONDS (previous was 0x10000)
210 uint32 openTextID; //6
211 uint32 closeTextID; //7
212 } areadamage;
213 //13 GAMEOBJECT_TYPE_CAMERA
214 struct
216 uint32 lockId; //0 -> Lock.dbc
217 uint32 cinematicId; //1
218 uint32 eventID; //2
219 uint32 openTextID; //3 can be used to replace castBarCaption?
220 } camera;
221 //14 GAMEOBJECT_TYPE_MAPOBJECT - empty
222 //15 GAMEOBJECT_TYPE_MO_TRANSPORT
223 struct
225 uint32 taxiPathId; //0
226 uint32 moveSpeed; //1
227 uint32 accelRate; //2
228 uint32 startEventID; //3
229 uint32 stopEventID; //4
230 uint32 transportPhysics; //5
231 uint32 mapID; //6
232 uint32 worldState1; //7
233 } moTransport;
234 //16 GAMEOBJECT_TYPE_DUELFLAG - empty
235 //17 GAMEOBJECT_TYPE_FISHINGNODE - empty
236 //18 GAMEOBJECT_TYPE_SUMMONING_RITUAL
237 struct
239 uint32 reqParticipants; //0
240 uint32 spellId; //1
241 uint32 animSpell; //2
242 uint32 ritualPersistent; //3
243 uint32 casterTargetSpell; //4
244 uint32 casterTargetSpellTargets; //5
245 uint32 castersGrouped; //6
246 uint32 ritualNoTargetCheck; //7
247 } summoningRitual;
248 //19 GAMEOBJECT_TYPE_MAILBOX - empty
249 //20 GAMEOBJECT_TYPE_DONOTUSE - empty
250 //21 GAMEOBJECT_TYPE_GUARDPOST
251 struct
253 uint32 creatureID; //0
254 uint32 charges; //1
255 } guardpost;
256 //22 GAMEOBJECT_TYPE_SPELLCASTER
257 struct
259 uint32 spellId; //0
260 uint32 charges; //1
261 uint32 partyOnly; //2
262 uint32 allowMounted; //3
263 uint32 large; //4
264 } spellcaster;
265 //23 GAMEOBJECT_TYPE_MEETINGSTONE
266 struct
268 uint32 minLevel; //0
269 uint32 maxLevel; //1
270 uint32 areaID; //2
271 } meetingstone;
272 //24 GAMEOBJECT_TYPE_FLAGSTAND
273 struct
275 uint32 lockId; //0
276 uint32 pickupSpell; //1
277 uint32 radius; //2
278 uint32 returnAura; //3
279 uint32 returnSpell; //4
280 uint32 noDamageImmune; //5
281 uint32 openTextID; //6
282 uint32 losOK; //7
283 } flagstand;
284 //25 GAMEOBJECT_TYPE_FISHINGHOLE
285 struct
287 uint32 radius; //0 how close bobber must land for sending loot
288 uint32 lootId; //1
289 uint32 minSuccessOpens; //2
290 uint32 maxSuccessOpens; //3
291 uint32 lockId; //4 -> Lock.dbc; possibly 1628 for all?
292 } fishinghole;
293 //26 GAMEOBJECT_TYPE_FLAGDROP
294 struct
296 uint32 lockId; //0
297 uint32 eventID; //1
298 uint32 pickupSpell; //2
299 uint32 noDamageImmune; //3
300 uint32 openTextID; //4
301 } flagdrop;
302 //27 GAMEOBJECT_TYPE_MINI_GAME
303 struct
305 uint32 gameType; //0
306 } miniGame;
307 //29 GAMEOBJECT_TYPE_CAPTURE_POINT
308 struct
310 uint32 radius; //0
311 uint32 spell; //1
312 uint32 worldState1; //2
313 uint32 worldState2; //3
314 uint32 winEventID1; //4
315 uint32 winEventID2; //5
316 uint32 contestedEventID1; //6
317 uint32 contestedEventID2; //7
318 uint32 progressEventID1; //8
319 uint32 progressEventID2; //9
320 uint32 neutralEventID1; //10
321 uint32 neutralEventID2; //11
322 uint32 neutralPercent; //12
323 uint32 worldState3; //13
324 uint32 minSuperiority; //14
325 uint32 maxSuperiority; //15
326 uint32 minTime; //16
327 uint32 maxTime; //17
328 uint32 large; //18
329 uint32 highlight; //19
330 uint32 startingValue; //20
331 uint32 unidirectional; //21
332 } capturePoint;
333 //30 GAMEOBJECT_TYPE_AURA_GENERATOR
334 struct
336 uint32 startOpen; //0
337 uint32 radius; //1
338 uint32 auraID1; //2
339 uint32 conditionID1; //3
340 uint32 auraID2; //4
341 uint32 conditionID2; //5
342 uint32 serverOnly; //6
343 } auraGenerator;
344 //31 GAMEOBJECT_TYPE_DUNGEON_DIFFICULTY
345 struct
347 uint32 mapID; //0
348 uint32 difficulty; //1
349 } dungeonDifficulty;
350 //32 GAMEOBJECT_TYPE_BARBER_CHAIR
351 struct
353 uint32 chairheight; //0
354 uint32 heightOffset; //1
355 } barberChair;
356 //33 GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING
357 struct
359 uint32 intactNumHits; //0
360 uint32 creditProxyCreature; //1
361 uint32 empty1; //2
362 uint32 intactEvent; //3
363 uint32 empty2; //4
364 uint32 damagedNumHits; //5
365 uint32 empty3; //6
366 uint32 empty4; //7
367 uint32 empty5; //8
368 uint32 damagedEvent; //9
369 uint32 empty6; //10
370 uint32 empty7; //11
371 uint32 empty8; //12
372 uint32 empty9; //13
373 uint32 destroyedEvent; //14
374 uint32 empty10; //15
375 uint32 debuildingTimeSecs; //16
376 uint32 empty11; //17
377 uint32 destructibleData; //18
378 uint32 rebuildingEvent; //19
379 uint32 empty12; //20
380 uint32 empty13; //21
381 uint32 damageEvent; //22
382 uint32 empty14; //23
383 } destructibleBuilding;
384 //34 GAMEOBJECT_TYPE_GUILDBANK - empty
385 //35 GAMEOBJECT_TYPE_TRAPDOOR
386 struct
388 uint32 whenToPause; // 0
389 uint32 startOpen; // 1
390 uint32 autoClose; // 2
391 } trapDoor;
393 // not use for specific field access (only for output with loop by all filed), also this determinate max union size
394 struct
396 uint32 data[32];
397 } raw;
400 uint32 unk2;
401 uint32 MinMoneyLoot;
402 uint32 MaxMoneyLoot;
403 uint32 ScriptId;
405 // helpers
406 bool IsDespawnAtAction() const
408 switch (type)
410 case GAMEOBJECT_TYPE_CHEST: return chest.consumable;
411 case GAMEOBJECT_TYPE_GOOBER: return goober.consumable;
412 default: return false;
416 uint32 GetLockId() const
418 switch (type)
420 case GAMEOBJECT_TYPE_DOOR: return door.lockId;
421 case GAMEOBJECT_TYPE_BUTTON: return button.lockId;
422 case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.lockId;
423 case GAMEOBJECT_TYPE_CHEST: return chest.lockId;
424 case GAMEOBJECT_TYPE_TRAP: return trap.lockId;
425 case GAMEOBJECT_TYPE_GOOBER: return goober.lockId;
426 case GAMEOBJECT_TYPE_AREADAMAGE: return areadamage.lockId;
427 case GAMEOBJECT_TYPE_CAMERA: return camera.lockId;
428 case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.lockId;
429 case GAMEOBJECT_TYPE_FISHINGHOLE: return fishinghole.lockId;
430 case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.lockId;
431 default: return 0;
435 bool GetDespawnPossibility() const // despawn at targeting of cast?
437 switch (type)
439 case GAMEOBJECT_TYPE_DOOR: return door.noDamageImmune;
440 case GAMEOBJECT_TYPE_BUTTON: return button.noDamageImmune;
441 case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.noDamageImmune;
442 case GAMEOBJECT_TYPE_GOOBER: return goober.noDamageImmune;
443 case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.noDamageImmune;
444 case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.noDamageImmune;
445 default: return true;
449 uint32 GetCharges() const // despawn at uses amount
451 switch (type)
453 case GAMEOBJECT_TYPE_TRAP: return trap.charges;
454 case GAMEOBJECT_TYPE_GUARDPOST: return guardpost.charges;
455 case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.charges;
456 default: return 0;
460 uint32 GetCooldown() const // not triggering at detection target or use until coolodwn expire
462 switch (type)
464 case GAMEOBJECT_TYPE_TRAP: return trap.cooldown;
465 case GAMEOBJECT_TYPE_GOOBER: return goober.cooldown;
466 default: return 0;
470 uint32 GetLinkedGameObjectEntry() const
472 switch (type)
474 case GAMEOBJECT_TYPE_BUTTON: return button.linkedTrapId;
475 case GAMEOBJECT_TYPE_CHEST: return chest.linkedTrapId;
476 case GAMEOBJECT_TYPE_SPELL_FOCUS: return spellFocus.linkedTrapId;
477 case GAMEOBJECT_TYPE_GOOBER: return goober.linkedTrapId;
478 default: return 0;
482 uint32 GetAutoCloseTime() const
484 uint32 autoCloseTime = 0;
485 switch (type)
487 case GAMEOBJECT_TYPE_DOOR: autoCloseTime = door.autoCloseTime; break;
488 case GAMEOBJECT_TYPE_BUTTON: autoCloseTime = button.autoCloseTime; break;
489 case GAMEOBJECT_TYPE_TRAP: autoCloseTime = trap.autoCloseTime; break;
490 case GAMEOBJECT_TYPE_GOOBER: autoCloseTime = goober.autoCloseTime; break;
491 case GAMEOBJECT_TYPE_TRANSPORT: autoCloseTime = transport.autoCloseTime; break;
492 case GAMEOBJECT_TYPE_AREADAMAGE: autoCloseTime = areadamage.autoCloseTime; break;
493 default: break;
495 return autoCloseTime / IN_MILLISECONDS; // prior to 3.0.3, conversion was / 0x10000;
498 uint32 GetLootId() const
500 switch (type)
502 case GAMEOBJECT_TYPE_CHEST: return chest.lootId;
503 case GAMEOBJECT_TYPE_FISHINGHOLE: return fishinghole.lootId;
504 default: return 0;
508 uint32 GetGossipMenuId() const
510 switch (type)
512 case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.gossipID;
513 case GAMEOBJECT_TYPE_GOOBER: return goober.gossipID;
514 default: return 0;
518 uint32 GetEventScriptId() const
520 switch (type)
522 case GAMEOBJECT_TYPE_GOOBER: return goober.eventId;
523 case GAMEOBJECT_TYPE_CHEST: return chest.eventId;
524 case GAMEOBJECT_TYPE_CAMERA: return camera.eventID;
525 default: return 0;
530 // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
531 #if defined( __GNUC__ )
532 #pragma pack()
533 #else
534 #pragma pack(pop)
535 #endif
537 struct GameObjectLocale
539 std::vector<std::string> Name;
540 std::vector<std::string> CastBarCaption;
543 // client side GO show states
544 enum GOState
546 GO_STATE_ACTIVE = 0, // show in world as used and not reset (closed door open)
547 GO_STATE_READY = 1, // show in world as ready (closed door close)
548 GO_STATE_ACTIVE_ALTERNATIVE = 2 // show in world as used in alt way and not reset (closed door open by cannon fire)
551 #define MAX_GO_STATE 3
553 struct QuaternionData
555 float x, y, z, w;
557 QuaternionData() : x(0.f), y(0.f), z(0.f), w(0.f) {}
558 QuaternionData(float X, float Y, float Z, float W) : x(X), y(Y), z(Z), w(W) {}
560 bool isUnit() const { return fabs(x * x + y * y + z * z + w * w - 1.f) < 1e-5;}
563 // from `gameobject`
564 struct GameObjectData
566 uint32 id; // entry in gamobject_template
567 uint16 mapid;
568 uint16 phaseMask;
569 float posX;
570 float posY;
571 float posZ;
572 float orientation;
573 QuaternionData rotation;
574 int32 spawntimesecs;
575 uint32 animprogress;
576 GOState go_state;
577 uint8 spawnMask;
580 // from `gameobject_addon`
581 struct GameObjectDataAddon
583 uint32 guid;
584 QuaternionData path_rotation;
587 // For containers: [GO_NOT_READY]->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED->GO_READY -> ...
588 // For bobber: GO_NOT_READY ->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED-><deleted>
589 // For door(closed):[GO_NOT_READY]->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED->GO_READY(close) -> ...
590 // For door(open): [GO_NOT_READY]->GO_READY (open) ->GO_ACTIVATED (close)->GO_JUST_DEACTIVATED->GO_READY(open) -> ...
591 enum LootState
593 GO_NOT_READY = 0,
594 GO_READY, // can be ready but despawned, and then not possible activate until spawn
595 GO_ACTIVATED,
596 GO_JUST_DEACTIVATED
599 enum CapturePointState
601 CAPTURE_STATE_NEUTRAL = 0,
602 CAPTURE_STATE_PROGRESS_ALLIANCE,
603 CAPTURE_STATE_PROGRESS_HORDE,
604 CAPTURE_STATE_CONTEST_ALLIANCE,
605 CAPTURE_STATE_CONTEST_HORDE,
606 CAPTURE_STATE_WIN_ALLIANCE,
607 CAPTURE_STATE_WIN_HORDE
610 enum CapturePointSlider
612 CAPTURE_SLIDER_ALLIANCE = 100, // full alliance
613 CAPTURE_SLIDER_HORDE = 0, // full horde
614 CAPTURE_SLIDER_MIDDLE = 50 // middle
617 class Unit;
618 struct GameObjectDisplayInfoEntry;
620 // 5 sec for bobber catch
621 #define FISHING_BOBBER_READY_TIME 5
623 #define GO_ANIMPROGRESS_DEFAULT 0xFF
625 class MANGOS_DLL_SPEC GameObject : public WorldObject
627 public:
628 explicit GameObject();
629 ~GameObject();
631 void AddToWorld() override;
632 void RemoveFromWorld() override;
634 bool Create(uint32 guidlow, uint32 name_id, Map* map, uint32 phaseMask, float x, float y, float z, float ang,
635 QuaternionData rotation = QuaternionData(), uint8 animprogress = GO_ANIMPROGRESS_DEFAULT, GOState go_state = GO_STATE_READY);
636 void Update(uint32 update_diff, uint32 p_time) override;
637 GameObjectInfo const* GetGOInfo() const;
639 bool IsTransport() const;
641 bool HasStaticDBSpawnData() const; // listed in `gameobject` table and have fixed in DB guid
643 // z_rot, y_rot, x_rot - rotation angles around z, y and x axes
644 void SetWorldRotationAngles(float z_rot, float y_rot, float x_rot);
645 void SetWorldRotation(float qx, float qy, float qz, float qw);
646 void SetTransportPathRotation(QuaternionData rotation); // transforms(rotates) transport's path
647 int64 GetPackedWorldRotation() const { return m_packedRotation; }
649 // overwrite WorldObject function for proper name localization
650 const char* GetNameForLocaleIdx(int32 locale_idx) const override;
652 void SaveToDB();
653 void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
654 bool LoadFromDB(uint32 guid, Map* map);
655 void DeleteFromDB();
657 void SetOwnerGuid(ObjectGuid ownerGuid)
659 m_spawnedByDefault = false; // all object with owner is despawned after delay
660 SetGuidValue(OBJECT_FIELD_CREATED_BY, ownerGuid);
662 ObjectGuid const& GetOwnerGuid() const { return GetGuidValue(OBJECT_FIELD_CREATED_BY); }
663 Unit* GetOwner() const;
665 void SetSpellId(uint32 id)
667 m_spawnedByDefault = false; // all summoned object is despawned after delay
668 m_spellId = id;
670 uint32 GetSpellId() const { return m_spellId;}
672 time_t GetRespawnTime() const { return m_respawnTime; }
673 time_t GetRespawnTimeEx() const
675 time_t now = time(NULL);
676 if (m_respawnTime > now)
677 return m_respawnTime;
678 else
679 return now;
682 void SetRespawnTime(time_t respawn)
684 m_respawnTime = respawn > 0 ? time(NULL) + respawn : 0;
685 m_respawnDelayTime = respawn > 0 ? uint32(respawn) : 0;
687 void Respawn();
688 bool isSpawned() const
690 return m_respawnDelayTime == 0 ||
691 (m_respawnTime > 0 && !m_spawnedByDefault) ||
692 (m_respawnTime == 0 && m_spawnedByDefault);
694 bool isSpawnedByDefault() const { return m_spawnedByDefault; }
695 uint32 GetRespawnDelay() const { return m_respawnDelayTime; }
696 void Refresh();
697 void Delete();
699 // Functions spawn/remove gameobject with DB guid in all loaded map copies (if point grid loaded in map)
700 static void AddToRemoveListInMaps(uint32 db_guid, GameObjectData const* data);
701 static void SpawnInMaps(uint32 db_guid, GameObjectData const* data);
703 GameobjectTypes GetGoType() const { return GameobjectTypes(GetByteValue(GAMEOBJECT_BYTES_1, 1)); }
704 void SetGoType(GameobjectTypes type) { SetByteValue(GAMEOBJECT_BYTES_1, 1, type); }
705 GOState GetGoState() const { return GOState(GetByteValue(GAMEOBJECT_BYTES_1, 0)); }
706 void SetGoState(GOState state) { SetByteValue(GAMEOBJECT_BYTES_1, 0, state); }
707 uint8 GetGoArtKit() const { return GetByteValue(GAMEOBJECT_BYTES_1, 2); }
708 void SetGoArtKit(uint8 artkit) { SetByteValue(GAMEOBJECT_BYTES_1, 2, artkit); }
709 uint8 GetGoAnimProgress() const { return GetByteValue(GAMEOBJECT_BYTES_1, 3); }
710 void SetGoAnimProgress(uint8 animprogress) { SetByteValue(GAMEOBJECT_BYTES_1, 3, animprogress); }
711 uint32 GetDisplayId() const { return GetUInt32Value(GAMEOBJECT_DISPLAYID); }
712 void SetDisplayId(uint32 modelId);
714 float GetObjectBoundingRadius() const override; // overwrite WorldObject version
716 void Use(Unit* user);
718 LootState getLootState() const { return m_lootState; }
719 void SetLootState(LootState s) { m_lootState = s; }
721 void AddToSkillupList(Player* player);
722 bool IsInSkillupList(Player* player) const;
723 void ClearSkillupList() { m_SkillupSet.clear(); }
724 void ClearAllUsesData()
726 ClearSkillupList();
727 m_useTimes = 0;
728 m_firstUser.Clear();
729 m_UniqueUsers.clear();
732 void AddUniqueUse(Player* player);
733 void AddUse() { ++m_useTimes; }
735 uint32 GetUseCount() const { return m_useTimes; }
736 uint32 GetUniqueUseCount() const { return m_UniqueUsers.size(); }
738 void SaveRespawnTime() override;
740 // Loot System
741 Loot loot;
742 void getFishLoot(Loot* loot, Player* loot_owner);
743 void StartGroupLoot(Group* group, uint32 timer) override;
745 ObjectGuid GetLootRecipientGuid() const { return m_lootRecipientGuid; }
746 uint32 GetLootGroupRecipientId() const { return m_lootGroupRecipientId; }
747 Player* GetLootRecipient() const; // use group cases as prefered
748 Group* GetGroupLootRecipient() const;
749 bool HasLootRecipient() const { return m_lootGroupRecipientId || !m_lootRecipientGuid.IsEmpty(); }
750 bool IsGroupLootRecipient() const { return m_lootGroupRecipientId; }
751 void SetLootRecipient(Unit* pUnit);
752 Player* GetOriginalLootRecipient() const; // ignore group changes/etc, not for looting
754 bool HasQuest(uint32 quest_id) const override;
755 bool HasInvolvedQuest(uint32 quest_id) const override;
756 bool ActivateToQuest(Player* pTarget) const;
757 void UseDoorOrButton(uint32 time_to_restore = 0, bool alternative = false);
758 // 0 = use `gameobject`.`spawntimesecs`
759 void ResetDoorOrButton();
761 bool IsHostileTo(Unit const* unit) const override;
762 bool IsFriendlyTo(Unit const* unit) const override;
764 void SummonLinkedTrapIfAny();
765 void TriggerLinkedGameObject(Unit* target);
767 bool isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const override;
769 GameObject* LookupFishingHoleAround(float range);
771 void SetCapturePointSlider(float value);
772 float GetCapturePointSlider() const { return m_captureSlider; }
774 GridReference<GameObject>& GetGridRef() { return m_gridRef; }
776 protected:
777 uint32 m_spellId;
778 time_t m_respawnTime; // (secs) time of next respawn (or despawn if GO have owner()),
779 uint32 m_respawnDelayTime; // (secs) if 0 then current GO state no dependent from timer
780 LootState m_lootState;
781 bool m_spawnedByDefault;
782 time_t m_cooldownTime; // used as internal reaction delay time store (not state change reaction).
783 // For traps/goober this: spell casting cooldown, for doors/buttons: reset time.
785 uint32 m_captureTimer; // (msecs) timer used for capture points
786 float m_captureSlider; // capture point slider value in range of [0..100]
787 CapturePointState m_captureState;
789 GuidSet m_SkillupSet; // players that already have skill-up at GO use
791 uint32 m_useTimes; // amount uses/charges triggered
793 // collected only for GAMEOBJECT_TYPE_SUMMONING_RITUAL
794 ObjectGuid m_firstUser; // first GO user, in most used cases owner, but in some cases no, for example non-summoned multi-use GAMEOBJECT_TYPE_SUMMONING_RITUAL
795 GuidSet m_UniqueUsers; // all players who use item, some items activated after specific amount unique uses
797 GameObjectInfo const* m_goInfo;
798 GameObjectDisplayInfoEntry const* m_displayInfo;
799 int64 m_packedRotation;
800 QuaternionData m_worldRotation;
802 // Loot System
803 uint32 m_groupLootTimer; // (msecs)timer used for group loot
804 uint32 m_groupLootId; // used to find group which is looting
805 void StopGroupLoot() override;
806 ObjectGuid m_lootRecipientGuid; // player who will have rights for looting if m_lootGroupRecipient==0 or group disbanded
807 uint32 m_lootGroupRecipientId; // group who will have rights for looting if set and exist
809 private:
810 void SwitchDoorOrButton(bool activate, bool alternative = false);
811 void TickCapturePoint();
813 GridReference<GameObject> m_gridRef;
815 #endif