2 * Copyright (C) 2005-2010 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
23 #include "SharedDefines.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__ )
35 // from `gameobject_template`
49 union // different GO types have different data field
51 //0 GAMEOBJECT_TYPE_DOOR
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_MILISECONDS (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
62 //1 GAMEOBJECT_TYPE_BUTTON
66 uint32 lockId
; //1 -> Lock.dbc
67 uint32 autoCloseTime
; //2 secs till autoclose = autoCloseTime / IN_MILISECONDS (previous was 0x10000)
68 uint32 linkedTrapId
; //3
69 uint32 noDamageImmune
; //4 isBattlegroundObject
71 uint32 openTextID
; //6 can be used to replace castBarCaption?
72 uint32 closeTextID
; //7
75 //2 GAMEOBJECT_TYPE_QUESTGIVER
78 uint32 lockId
; //0 -> Lock.dbc
80 uint32 pageMaterial
; //2
82 uint32 customAnim
; //4
83 uint32 noDamageImmune
; //5
84 uint32 openTextID
; //6 can be used to replace castBarCaption?
86 uint32 allowMounted
; //8
89 //3 GAMEOBJECT_TYPE_CHEST
92 uint32 lockId
; //0 -> Lock.dbc
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
103 uint32 leaveLoot
; //11
104 uint32 notInCombat
; //12
106 uint32 openTextID
; //14 can be used to replace castBarCaption?
107 uint32 groupLootRules
; //15
108 uint32 floatingTooltip
; //16
110 //4 GAMEOBJECT_TYPE_BINDER - empty
111 //5 GAMEOBJECT_TYPE_GENERIC
114 uint32 floatingTooltip
; //0
115 uint32 highlight
; //1
116 uint32 serverOnly
; //2
118 uint32 floatOnWater
; //4
121 //6 GAMEOBJECT_TYPE_TRAP
124 uint32 lockId
; //0 -> Lock.dbc
126 uint32 radius
; //2 radius for trap activation
128 uint32 charges
; //4 need respawn (if > 0)
129 uint32 cooldown
; //5 time in secs
130 uint32 autoCloseTime
; //6 secs till autoclose = autoCloseTime / IN_MILISECONDS (previous was 0x10000)
131 uint32 startDelay
; //7
132 uint32 serverOnly
; //8
133 uint32 stealthed
; //9
135 uint32 stealthAffected
; //11
136 uint32 openTextID
; //12 can be used to replace castBarCaption?
137 uint32 closeTextID
; //13
138 uint32 ignoreTotems
; //14
140 //7 GAMEOBJECT_TYPE_CHAIR
145 uint32 onlyCreatorUse
; //2
146 uint32 triggeredEvent
; //3
148 //8 GAMEOBJECT_TYPE_SPELL_FOCUS
153 uint32 linkedTrapId
; //2
154 uint32 serverOnly
; //3
157 uint32 floatingTooltip
; //6
159 //9 GAMEOBJECT_TYPE_TEXT
164 uint32 pageMaterial
; //2
165 uint32 allowMounted
; //3
167 //10 GAMEOBJECT_TYPE_GOOBER
170 uint32 lockId
; //0 -> Lock.dbc
173 uint32 autoCloseTime
; //3 secs till autoclose = autoCloseTime / IN_MILISECONDS (previous was 0x10000)
174 uint32 customAnim
; //4
175 uint32 consumable
; //5
179 uint32 pageMaterial
; //9
181 uint32 noDamageImmune
; //11
182 uint32 linkedTrapId
; //12
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
192 //11 GAMEOBJECT_TYPE_TRANSPORT
196 uint32 startOpen
; //1
197 uint32 autoCloseTime
; //2 secs till autoclose = autoCloseTime / IN_MILISECONDS (previous was 0x10000)
198 uint32 pause1EventID
; //3
199 uint32 pause2EventID
; //4
201 //12 GAMEOBJECT_TYPE_AREADAMAGE
206 uint32 damageMin
; //2
207 uint32 damageMax
; //3
208 uint32 damageSchool
; //4
209 uint32 autoCloseTime
; //5 secs till autoclose = autoCloseTime / IN_MILISECONDS (previous was 0x10000)
210 uint32 openTextID
; //6
211 uint32 closeTextID
; //7
213 //13 GAMEOBJECT_TYPE_CAMERA
216 uint32 lockId
; //0 -> Lock.dbc
217 uint32 cinematicId
; //1
219 uint32 openTextID
; //3 can be used to replace castBarCaption?
221 //14 GAMEOBJECT_TYPE_MAPOBJECT - empty
222 //15 GAMEOBJECT_TYPE_MO_TRANSPORT
225 uint32 taxiPathId
; //0
226 uint32 moveSpeed
; //1
227 uint32 accelRate
; //2
228 uint32 startEventID
; //3
229 uint32 stopEventID
; //4
230 uint32 transportPhysics
; //5
232 uint32 worldState1
; //7
234 //16 GAMEOBJECT_TYPE_DUELFLAG - empty
235 //17 GAMEOBJECT_TYPE_FISHINGNODE - empty
236 //18 GAMEOBJECT_TYPE_SUMMONING_RITUAL
239 uint32 reqParticipants
; //0
241 uint32 animSpell
; //2
242 uint32 ritualPersistent
; //3
243 uint32 casterTargetSpell
; //4
244 uint32 casterTargetSpellTargets
; //5
245 uint32 castersGrouped
; //6
246 uint32 ritualNoTargetCheck
; //7
248 //19 GAMEOBJECT_TYPE_MAILBOX - empty
249 //20 GAMEOBJECT_TYPE_DONOTUSE - empty
250 //21 GAMEOBJECT_TYPE_GUARDPOST
253 uint32 creatureID
; //0
256 //22 GAMEOBJECT_TYPE_SPELLCASTER
261 uint32 partyOnly
; //2
262 uint32 allowMounted
; //3
265 //23 GAMEOBJECT_TYPE_MEETINGSTONE
272 //24 GAMEOBJECT_TYPE_FLAGSTAND
276 uint32 pickupSpell
; //1
278 uint32 returnAura
; //3
279 uint32 returnSpell
; //4
280 uint32 noDamageImmune
; //5
281 uint32 openTextID
; //6
284 //25 GAMEOBJECT_TYPE_FISHINGHOLE // not implemented yet
287 uint32 radius
; //0 how close bobber must land for sending loot
289 uint32 minSuccessOpens
; //2
290 uint32 maxSuccessOpens
; //3
291 uint32 lockId
; //4 -> Lock.dbc; possibly 1628 for all?
293 //26 GAMEOBJECT_TYPE_FLAGDROP
298 uint32 pickupSpell
; //2
299 uint32 noDamageImmune
; //3
300 uint32 openTextID
; //4
302 //27 GAMEOBJECT_TYPE_MINI_GAME
307 //29 GAMEOBJECT_TYPE_CAPTURE_POINT
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
329 uint32 highlight
; //19
330 uint32 startingValue
; //20
331 uint32 unidirectional
; //21
333 //30 GAMEOBJECT_TYPE_AURA_GENERATOR
336 uint32 startOpen
; //0
339 uint32 conditionID1
; //3
341 uint32 conditionID2
; //5
342 uint32 serverOnly
; //6
344 //31 GAMEOBJECT_TYPE_DUNGEON_DIFFICULTY
348 uint32 difficulty
; //1
350 //32 GAMEOBJECT_TYPE_BARBER_CHAIR
353 uint32 chairheight
; //0
354 uint32 heightOffset
; //1
356 //33 GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING
359 uint32 intactNumHits
; //0
360 uint32 creditProxyCreature
; //1
362 uint32 intactEvent
; //3
364 uint32 damagedNumHits
; //5
368 uint32 damagedEvent
; //9
373 uint32 destroyedEvent
; //14
375 uint32 debuildingTimeSecs
; //16
377 uint32 destructibleData
; //18
378 uint32 rebuildingEvent
; //19
381 uint32 damageEvent
; //22
383 } destructibleBuilding
;
384 //34 GAMEOBJECT_TYPE_GUILDBANK - empty
385 //35 GAMEOBJECT_TYPE_TRAPDOOR
388 uint32 whenToPause
; // 0
389 uint32 startOpen
; // 1
390 uint32 autoClose
; // 2
393 // not use for specific field access (only for output with loop by all filed), also this determinate max union size
402 bool IsDespawnAtAction() const
406 case GAMEOBJECT_TYPE_CHEST
: return chest
.consumable
;
407 case GAMEOBJECT_TYPE_GOOBER
: return goober
.consumable
;
408 default: return false;
412 uint32
GetLockId() const
416 case GAMEOBJECT_TYPE_DOOR
: return door
.lockId
;
417 case GAMEOBJECT_TYPE_BUTTON
: return button
.lockId
;
418 case GAMEOBJECT_TYPE_QUESTGIVER
: return questgiver
.lockId
;
419 case GAMEOBJECT_TYPE_CHEST
: return chest
.lockId
;
420 case GAMEOBJECT_TYPE_TRAP
: return trap
.lockId
;
421 case GAMEOBJECT_TYPE_GOOBER
: return goober
.lockId
;
422 case GAMEOBJECT_TYPE_AREADAMAGE
: return areadamage
.lockId
;
423 case GAMEOBJECT_TYPE_CAMERA
: return camera
.lockId
;
424 case GAMEOBJECT_TYPE_FLAGSTAND
: return flagstand
.lockId
;
425 case GAMEOBJECT_TYPE_FISHINGHOLE
:return fishinghole
.lockId
;
426 case GAMEOBJECT_TYPE_FLAGDROP
: return flagdrop
.lockId
;
431 bool GetDespawnPossibility() const // despawn at targeting of cast?
435 case GAMEOBJECT_TYPE_DOOR
: return door
.noDamageImmune
;
436 case GAMEOBJECT_TYPE_BUTTON
: return button
.noDamageImmune
;
437 case GAMEOBJECT_TYPE_QUESTGIVER
: return questgiver
.noDamageImmune
;
438 case GAMEOBJECT_TYPE_GOOBER
: return goober
.noDamageImmune
;
439 case GAMEOBJECT_TYPE_FLAGSTAND
: return flagstand
.noDamageImmune
;
440 case GAMEOBJECT_TYPE_FLAGDROP
: return flagdrop
.noDamageImmune
;
441 default: return true;
445 uint32
GetCharges() const // despawn at uses amount
449 case GAMEOBJECT_TYPE_TRAP
: return trap
.charges
;
450 case GAMEOBJECT_TYPE_GUARDPOST
: return guardpost
.charges
;
451 case GAMEOBJECT_TYPE_SPELLCASTER
: return spellcaster
.charges
;
456 uint32
GetLinkedGameObjectEntry() const
460 case GAMEOBJECT_TYPE_BUTTON
: return button
.linkedTrapId
;
461 case GAMEOBJECT_TYPE_CHEST
: return chest
.linkedTrapId
;
462 case GAMEOBJECT_TYPE_SPELL_FOCUS
: return spellFocus
.linkedTrapId
;
463 case GAMEOBJECT_TYPE_GOOBER
: return goober
.linkedTrapId
;
468 uint32
GetAutoCloseTime() const
470 uint32 autoCloseTime
= 0;
473 case GAMEOBJECT_TYPE_DOOR
: autoCloseTime
= door
.autoCloseTime
; break;
474 case GAMEOBJECT_TYPE_BUTTON
: autoCloseTime
= button
.autoCloseTime
; break;
475 case GAMEOBJECT_TYPE_TRAP
: autoCloseTime
= trap
.autoCloseTime
; break;
476 case GAMEOBJECT_TYPE_GOOBER
: autoCloseTime
= goober
.autoCloseTime
; break;
477 case GAMEOBJECT_TYPE_TRANSPORT
: autoCloseTime
= transport
.autoCloseTime
; break;
478 case GAMEOBJECT_TYPE_AREADAMAGE
: autoCloseTime
= areadamage
.autoCloseTime
; break;
481 return autoCloseTime
/ IN_MILISECONDS
; // prior to 3.0.3, conversion was / 0x10000;
484 uint32
GetLootId() const
488 case GAMEOBJECT_TYPE_CHEST
: return chest
.lootId
;
489 case GAMEOBJECT_TYPE_FISHINGHOLE
: return fishinghole
.lootId
;
494 uint32
GetGossipMenuId() const
498 case GAMEOBJECT_TYPE_QUESTGIVER
: return questgiver
.gossipID
;
499 case GAMEOBJECT_TYPE_GOOBER
: return goober
.gossipID
;
505 // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
506 #if defined( __GNUC__ )
512 struct GameObjectLocale
514 std::vector
<std::string
> Name
;
515 std::vector
<std::string
> CastBarCaption
;
518 // client side GO show states
521 GO_STATE_ACTIVE
= 0, // show in world as used and not reset (closed door open)
522 GO_STATE_READY
= 1, // show in world as ready (closed door close)
523 GO_STATE_ACTIVE_ALTERNATIVE
= 2 // show in world as used in alt way and not reset (closed door open by cannon fire)
526 #define MAX_GO_STATE 3
529 struct GameObjectData
531 uint32 id
; // entry in gamobject_template
548 // For containers: [GO_NOT_READY]->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED->GO_READY -> ...
549 // For bobber: GO_NOT_READY ->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED-><deleted>
550 // For door(closed):[GO_NOT_READY]->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED->GO_READY(close) -> ...
551 // For door(open): [GO_NOT_READY]->GO_READY (open) ->GO_ACTIVATED (close)->GO_JUST_DEACTIVATED->GO_READY(open) -> ...
555 GO_READY
, // can be ready but despawned, and then not possible activate until spawn
562 // 5 sec for bobber catch
563 #define FISHING_BOBBER_READY_TIME 5
565 class MANGOS_DLL_SPEC GameObject
: public WorldObject
568 explicit GameObject();
572 void RemoveFromWorld();
574 bool Create(uint32 guidlow
, uint32 name_id
, Map
*map
, uint32 phaseMask
, float x
, float y
, float z
, float ang
, float rotation0
, float rotation1
, float rotation2
, float rotation3
, uint32 animprogress
, GOState go_state
);
575 void Update(uint32 p_time
);
576 GameObjectInfo
const* GetGOInfo() const;
578 bool IsTransport() const;
580 uint32
GetDBTableGUIDLow() const { return m_DBTableGuid
; }
582 void UpdateRotationFields(float rotation2
= 0.0f
, float rotation3
= 0.0f
);
584 void Say(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterSay(textId
,language
,TargetGuid
); }
585 void Yell(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterYell(textId
,language
,TargetGuid
); }
586 void TextEmote(int32 textId
, uint64 TargetGuid
) { MonsterTextEmote(textId
,TargetGuid
); }
587 void Whisper(int32 textId
, uint64 receiver
) { MonsterWhisper(textId
,receiver
); }
588 void YellToZone(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterYellToZone(textId
,language
,TargetGuid
); }
590 // overwrite WorldObject function for proper name localization
591 const char* GetNameForLocaleIdx(int32 locale_idx
) const;
594 void SaveToDB(uint32 mapid
, uint8 spawnMask
, uint32 phaseMask
);
595 bool LoadFromDB(uint32 guid
, Map
*map
);
598 void SetOwnerGUID(uint64 owner
)
600 m_spawnedByDefault
= false; // all object with owner is despawned after delay
601 SetUInt64Value(OBJECT_FIELD_CREATED_BY
, owner
);
603 uint64
GetOwnerGUID() const { return GetUInt64Value(OBJECT_FIELD_CREATED_BY
); }
604 Unit
* GetOwner() const;
606 void SetSpellId(uint32 id
)
608 m_spawnedByDefault
= false; // all summoned object is despawned after delay
611 uint32
GetSpellId() const { return m_spellId
;}
613 time_t GetRespawnTime() const { return m_respawnTime
; }
614 time_t GetRespawnTimeEx() const
616 time_t now
= time(NULL
);
617 if(m_respawnTime
> now
)
618 return m_respawnTime
;
623 void SetRespawnTime(int32 respawn
)
625 m_respawnTime
= respawn
> 0 ? time(NULL
) + respawn
: 0;
626 m_respawnDelayTime
= respawn
> 0 ? respawn
: 0;
629 bool isSpawned() const
631 return m_respawnDelayTime
== 0 ||
632 (m_respawnTime
> 0 && !m_spawnedByDefault
) ||
633 (m_respawnTime
== 0 && m_spawnedByDefault
);
635 bool isSpawnedByDefault() const { return m_spawnedByDefault
; }
636 uint32
GetRespawnDelay() const { return m_respawnDelayTime
; }
639 void getFishLoot(Loot
*loot
, Player
* loot_owner
);
640 GameobjectTypes
GetGoType() const { return GameobjectTypes(GetByteValue(GAMEOBJECT_BYTES_1
, 1)); }
641 void SetGoType(GameobjectTypes type
) { SetByteValue(GAMEOBJECT_BYTES_1
, 1, type
); }
642 GOState
GetGoState() const { return GOState(GetByteValue(GAMEOBJECT_BYTES_1
, 0)); }
643 void SetGoState(GOState state
) { SetByteValue(GAMEOBJECT_BYTES_1
, 0, state
); }
644 uint8
GetGoArtKit() const { return GetByteValue(GAMEOBJECT_BYTES_1
, 2); }
645 void SetGoArtKit(uint8 artkit
) { SetByteValue(GAMEOBJECT_BYTES_1
, 2, artkit
); }
646 uint8
GetGoAnimProgress() const { return GetByteValue(GAMEOBJECT_BYTES_1
, 3); }
647 void SetGoAnimProgress(uint8 animprogress
) { SetByteValue(GAMEOBJECT_BYTES_1
, 3, animprogress
); }
649 void Use(Unit
* user
);
651 LootState
getLootState() const { return m_lootState
; }
652 void SetLootState(LootState s
) { m_lootState
= s
; }
654 void AddToSkillupList(uint32 PlayerGuidLow
) { m_SkillupList
.push_back(PlayerGuidLow
); }
655 bool IsInSkillupList(uint32 PlayerGuidLow
) const
657 for (std::list
<uint32
>::const_iterator i
= m_SkillupList
.begin(); i
!= m_SkillupList
.end(); ++i
)
658 if (*i
== PlayerGuidLow
) return true;
661 void ClearSkillupList() { m_SkillupList
.clear(); }
663 void AddUniqueUse(Player
* player
);
664 void AddUse() { ++m_usetimes
; }
666 uint32
GetUseCount() const { return m_usetimes
; }
667 uint32
GetUniqueUseCount() const { return m_unique_users
.size(); }
669 void SaveRespawnTime();
673 bool hasQuest(uint32 quest_id
) const;
674 bool hasInvolvedQuest(uint32 quest_id
) const;
675 bool ActivateToQuest(Player
*pTarget
) const;
676 void UseDoorOrButton(uint32 time_to_restore
= 0, bool alternative
= false);
677 // 0 = use `gameobject`.`spawntimesecs`
678 void ResetDoorOrButton();
681 void SummonLinkedTrapIfAny();
682 void TriggeringLinkedGameObject( uint32 trapEntry
, Unit
* target
);
684 bool isVisibleForInState(Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const;
686 GameObject
* LookupFishingHoleAround(float range
);
688 GridReference
<GameObject
> &GetGridRef() { return m_gridRef
; }
690 bool isActiveObject() const { return false; }
691 uint64
GetRotation() const { return m_rotation
; }
694 time_t m_respawnTime
; // (secs) time of next respawn (or despawn if GO have owner()),
695 uint32 m_respawnDelayTime
; // (secs) if 0 then current GO state no dependent from timer
696 LootState m_lootState
;
697 bool m_spawnedByDefault
;
698 time_t m_cooldownTime
; // used as internal reaction delay time store (not state change reaction).
699 // For traps this: spell casting cooldown, for doors/buttons: reset time.
700 std::list
<uint32
> m_SkillupList
;
702 std::set
<uint32
> m_unique_users
;
705 uint32 m_DBTableGuid
; ///< For new or temporary gameobjects is 0 for saved it is lowguid
706 GameObjectInfo
const* m_goInfo
;
709 void SwitchDoorOrButton(bool activate
, bool alternative
= false);
711 GridReference
<GameObject
> m_gridRef
;