2 * Copyright (C) 2005-2009 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`
47 union // different GO types have different data field
49 //0 GAMEOBJECT_TYPE_DOOR
52 uint32 startOpen
; //0 used client side to determine GO_ACTIVATED means open/closed
53 uint32 lockId
; //1 -> Lock.dbc
54 uint32 autoCloseTime
; //2 secs till autoclose = autoCloseTime / 0x10000
55 uint32 noDamageImmune
; //3 break opening whenever you recieve damage?
56 uint32 openTextID
; //4 can be used to replace castBarCaption?
57 uint32 closeTextID
; //5
59 //1 GAMEOBJECT_TYPE_BUTTON
63 uint32 lockId
; //1 -> Lock.dbc
64 uint32 autoCloseTime
; //2 secs till autoclose = autoCloseTime / 0x10000
65 uint32 linkedTrap
; //3
66 uint32 noDamageImmune
; //4 isBattlegroundObject
68 uint32 openTextID
; //6 can be used to replace castBarCaption?
69 uint32 closeTextID
; //7
72 //2 GAMEOBJECT_TYPE_QUESTGIVER
75 uint32 lockId
; //0 -> Lock.dbc
77 uint32 pageMaterial
; //2
79 uint32 customAnim
; //4
80 uint32 noDamageImmune
; //5
81 uint32 openTextID
; //6 can be used to replace castBarCaption?
83 uint32 allowMounted
; //8
86 //3 GAMEOBJECT_TYPE_CHEST
89 uint32 lockId
; //0 -> Lock.dbc
91 uint32 chestRestockTime
; //2
92 uint32 consumable
; //3
93 uint32 minSuccessOpens
; //4
94 uint32 maxSuccessOpens
; //5
95 uint32 eventId
; //6 lootedEvent
96 uint32 linkedTrapId
; //7
97 uint32 questId
; //8 not used currently but store quest required for GO activation for player
100 uint32 leaveLoot
; //11
101 uint32 notInCombat
; //12
103 uint32 openTextID
; //14 can be used to replace castBarCaption?
104 uint32 groupLootRules
; //15
106 //4 GAMEOBJECT_TYPE_BINDER - empty
107 //5 GAMEOBJECT_TYPE_GENERIC
110 uint32 floatingTooltip
; //0
111 uint32 highlight
; //1
112 uint32 serverOnly
; //2
114 uint32 floatOnWater
; //4
117 //6 GAMEOBJECT_TYPE_TRAP
120 uint32 lockId
; //0 -> Lock.dbc
122 uint32 radius
; //2 radius for trap activation
124 uint32 charges
; //4 need respawn (if > 0)
125 uint32 cooldown
; //5 time in secs
126 uint32 autoCloseTime
; //6
127 uint32 startDelay
; //7
128 uint32 serverOnly
; //8
129 uint32 stealthed
; //9
131 uint32 stealthAffected
; //11
132 uint32 openTextID
; //12 can be used to replace castBarCaption?
133 uint32 closeTextID
; //13
135 //7 GAMEOBJECT_TYPE_CHAIR
140 uint32 onlyCreatorUse
; //2
142 //8 GAMEOBJECT_TYPE_SPELL_FOCUS
147 uint32 linkedTrapId
; //2
148 uint32 serverOnly
; //3
152 //9 GAMEOBJECT_TYPE_TEXT
157 uint32 pageMaterial
; //2
158 uint32 allowMounted
; //3
160 //10 GAMEOBJECT_TYPE_GOOBER
163 uint32 lockId
; //0 -> Lock.dbc
166 uint32 autoCloseTime
; //3
167 uint32 customAnim
; //4
168 uint32 consumable
; //5
172 uint32 pageMaterial
; //9
174 uint32 noDamageImmune
; //11
175 uint32 linkedTrapId
; //12
177 uint32 openTextID
; //14 can be used to replace castBarCaption?
178 uint32 closeTextID
; //15
179 uint32 losOK
; //16 isBattlegroundObject
180 uint32 allowMounted
; //17
182 //11 GAMEOBJECT_TYPE_TRANSPORT
186 uint32 startOpen
; //1
187 uint32 autoCloseTime
; //2 secs till autoclose = autoCloseTime / 0x10000
189 //12 GAMEOBJECT_TYPE_AREADAMAGE
194 uint32 damageMin
; //2
195 uint32 damageMax
; //3
196 uint32 damageSchool
; //4
197 uint32 autoCloseTime
; //5 secs till autoclose = autoCloseTime / 0x10000
198 uint32 openTextID
; //6
199 uint32 closeTextID
; //7
201 //13 GAMEOBJECT_TYPE_CAMERA
204 uint32 lockId
; //0 -> Lock.dbc
205 uint32 cinematicId
; //1
207 uint32 openTextID
; //3 can be used to replace castBarCaption?
209 //14 GAMEOBJECT_TYPE_MAPOBJECT - empty
210 //15 GAMEOBJECT_TYPE_MO_TRANSPORT
213 uint32 taxiPathId
; //0
214 uint32 moveSpeed
; //1
215 uint32 accelRate
; //2
216 uint32 startEventID
; //3
217 uint32 stopEventID
; //4
218 uint32 transportPhysics
; //5
221 //16 GAMEOBJECT_TYPE_DUELFLAG - empty
222 //17 GAMEOBJECT_TYPE_FISHINGNODE
228 //18 GAMEOBJECT_TYPE_SUMMONING_RITUAL
231 uint32 reqParticipants
; //0
233 uint32 animSpell
; //2
234 uint32 ritualPersistent
; //3
235 uint32 casterTargetSpell
; //4
236 uint32 casterTargetSpellTargets
; //5
237 uint32 castersGrouped
; //6
238 uint32 ritualNoTargetCheck
; //7
240 //19 GAMEOBJECT_TYPE_MAILBOX - empty
241 //20 GAMEOBJECT_TYPE_AUCTIONHOUSE
244 uint32 actionHouseID
; //0
246 //21 GAMEOBJECT_TYPE_GUARDPOST
249 uint32 creatureID
; //0
252 //22 GAMEOBJECT_TYPE_SPELLCASTER
257 uint32 partyOnly
; //2
259 //23 GAMEOBJECT_TYPE_MEETINGSTONE
266 //24 GAMEOBJECT_TYPE_FLAGSTAND
270 uint32 pickupSpell
; //1
272 uint32 returnAura
; //3
273 uint32 returnSpell
; //4
274 uint32 noDamageImmune
; //5
275 uint32 openTextID
; //6
278 //25 GAMEOBJECT_TYPE_FISHINGHOLE // not implemented yet
281 uint32 radius
; //0 how close bobber must land for sending loot
283 uint32 minSuccessOpens
; //2
284 uint32 maxSuccessOpens
; //3
285 uint32 lockId
; //4 -> Lock.dbc; possibly 1628 for all?
287 //26 GAMEOBJECT_TYPE_FLAGDROP
292 uint32 pickupSpell
; //2
293 uint32 noDamageImmune
; //3
294 uint32 openTextID
; //4
296 //27 GAMEOBJECT_TYPE_MINI_GAME
301 //29 GAMEOBJECT_TYPE_CAPTURE_POINT
306 uint32 worldState1
; //2
307 uint32 worldstate2
; //3
308 uint32 winEventID1
; //4
309 uint32 winEventID2
; //5
310 uint32 contestedEventID1
; //6
311 uint32 contestedEventID2
; //7
312 uint32 progressEventID1
; //8
313 uint32 progressEventID2
; //9
314 uint32 neutralEventID1
; //10
315 uint32 neutralEventID2
; //11
316 uint32 neutralPercent
; //12
317 uint32 worldstate3
; //13
318 uint32 minSuperiority
; //14
319 uint32 maxSuperiority
; //15
323 uint32 highlight
; //19
325 //30 GAMEOBJECT_TYPE_AURA_GENERATOR
328 uint32 startOpen
; //0
331 uint32 conditionID1
; //3
333 uint32 conditionID2
; //5
334 uint32 serverOnly
; //6
336 //31 GAMEOBJECT_TYPE_DUNGEON_DIFFICULTY
340 uint32 difficulty
; //1
342 //32 GAMEOBJECT_TYPE_BARBER_CHAIR
345 uint32 chairheight
; //0
346 uint32 heightOffset
; //1
348 //33 GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING
351 uint32 dmgPctState1
; //0
352 uint32 dmgPctState2
; //1
353 uint32 state1Name
; //2
354 uint32 state2Name
; //3
355 } destructibleBuilding
;
356 //34 GAMEOBJECT_TYPE_GUILDBANK - empty
357 //35 GAMEOBJECT_TYPE_TRAPDOOR
360 uint32 whenToPause
; // 0
361 uint32 startOpen
; // 1
362 uint32 autoClose
; // 2
365 // not use for specific field access (only for output with loop by all filed), also this determinate max union size
374 // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
375 #if defined( __GNUC__ )
381 struct GameObjectLocale
383 std::vector
<std::string
> Name
;
384 std::vector
<std::string
> CastBarCaption
;
387 // client side GO show states
390 GO_STATE_ACTIVE
= 0, // show in world as used and not reset (closed door open)
391 GO_STATE_READY
= 1, // show in world as ready (closed door close)
392 GO_STATE_ACTIVE_ALTERNATIVE
= 2 // show in world as used in alt way and not reset (closed door open by cannon fire)
395 #define MAX_GO_STATE 3
398 struct GameObjectData
400 uint32 id
; // entry in gamobject_template
417 // For containers: [GO_NOT_READY]->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED->GO_READY -> ...
418 // For bobber: GO_NOT_READY ->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED-><deleted>
419 // For door(closed):[GO_NOT_READY]->GO_READY (close)->GO_ACTIVATED (open) ->GO_JUST_DEACTIVATED->GO_READY(close) -> ...
420 // For door(open): [GO_NOT_READY]->GO_READY (open) ->GO_ACTIVATED (close)->GO_JUST_DEACTIVATED->GO_READY(open) -> ...
424 GO_READY
, // can be ready but despawned, and then not possible activate until spawn
431 // 5 sec for bobber catch
432 #define FISHING_BOBBER_READY_TIME 5
434 class MANGOS_DLL_SPEC GameObject
: public WorldObject
437 explicit GameObject();
441 void RemoveFromWorld();
443 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
);
444 void Update(uint32 p_time
);
445 GameObjectInfo
const* GetGOInfo() const;
447 bool IsTransport() const;
449 void SetOwnerGUID(uint64 owner
)
451 m_spawnedByDefault
= false; // all object with owner is despawned after delay
452 SetUInt64Value(OBJECT_FIELD_CREATED_BY
, owner
);
454 uint64
GetOwnerGUID() const { return GetUInt64Value(OBJECT_FIELD_CREATED_BY
); }
455 Unit
* GetOwner() const;
457 uint32
GetDBTableGUIDLow() const { return m_DBTableGuid
; }
459 void UpdateRotationFields(float rotation2
= 0.0f
, float rotation3
= 0.0f
);
461 void Say(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterSay(textId
,language
,TargetGuid
); }
462 void Yell(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterYell(textId
,language
,TargetGuid
); }
463 void TextEmote(int32 textId
, uint64 TargetGuid
) { MonsterTextEmote(textId
,TargetGuid
); }
464 void Whisper(int32 textId
, uint64 receiver
) { MonsterWhisper(textId
,receiver
); }
465 void YellToZone(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterYellToZone(textId
,language
,TargetGuid
); }
467 // overwrite WorldObject function for proper name localization
468 const char* GetNameForLocaleIdx(int32 locale_idx
) const;
471 void SaveToDB(uint32 mapid
, uint8 spawnMask
, uint32 phaseMask
);
472 bool LoadFromDB(uint32 guid
, Map
*map
);
474 static uint32
GetLootId(GameObjectInfo
const* info
);
475 uint32
GetLootId() const { return GetLootId(GetGOInfo()); }
476 uint32
GetLockId() const
480 case GAMEOBJECT_TYPE_DOOR
: return GetGOInfo()->door
.lockId
;
481 case GAMEOBJECT_TYPE_BUTTON
: return GetGOInfo()->button
.lockId
;
482 case GAMEOBJECT_TYPE_QUESTGIVER
: return GetGOInfo()->questgiver
.lockId
;
483 case GAMEOBJECT_TYPE_CHEST
: return GetGOInfo()->chest
.lockId
;
484 case GAMEOBJECT_TYPE_TRAP
: return GetGOInfo()->trap
.lockId
;
485 case GAMEOBJECT_TYPE_GOOBER
: return GetGOInfo()->goober
.lockId
;
486 case GAMEOBJECT_TYPE_AREADAMAGE
: return GetGOInfo()->areadamage
.lockId
;
487 case GAMEOBJECT_TYPE_CAMERA
: return GetGOInfo()->camera
.lockId
;
488 case GAMEOBJECT_TYPE_FLAGSTAND
: return GetGOInfo()->flagstand
.lockId
;
489 case GAMEOBJECT_TYPE_FISHINGHOLE
:return GetGOInfo()->fishinghole
.lockId
;
490 case GAMEOBJECT_TYPE_FLAGDROP
: return GetGOInfo()->flagdrop
.lockId
;
495 bool GetDespawnPossibility() const
499 case GAMEOBJECT_TYPE_DOOR
: return GetGOInfo()->door
.noDamageImmune
;
500 case GAMEOBJECT_TYPE_BUTTON
: return GetGOInfo()->button
.noDamageImmune
;
501 case GAMEOBJECT_TYPE_QUESTGIVER
: return GetGOInfo()->questgiver
.noDamageImmune
;
502 case GAMEOBJECT_TYPE_GOOBER
: return GetGOInfo()->goober
.noDamageImmune
;
503 case GAMEOBJECT_TYPE_FLAGSTAND
: return GetGOInfo()->flagstand
.noDamageImmune
;
504 case GAMEOBJECT_TYPE_FLAGDROP
: return GetGOInfo()->flagdrop
.noDamageImmune
;
505 default: return true;
509 time_t GetRespawnTime() const { return m_respawnTime
; }
510 time_t GetRespawnTimeEx() const
512 time_t now
= time(NULL
);
513 if(m_respawnTime
> now
)
514 return m_respawnTime
;
519 void SetRespawnTime(int32 respawn
)
521 m_respawnTime
= respawn
> 0 ? time(NULL
) + respawn
: 0;
522 m_respawnDelayTime
= respawn
> 0 ? respawn
: 0;
525 bool isSpawned() const
527 return m_respawnDelayTime
== 0 ||
528 (m_respawnTime
> 0 && !m_spawnedByDefault
) ||
529 (m_respawnTime
== 0 && m_spawnedByDefault
);
531 bool isSpawnedByDefault() const { return m_spawnedByDefault
; }
532 uint32
GetRespawnDelay() const { return m_respawnDelayTime
; }
535 void SetSpellId(uint32 id
) { m_spellId
= id
;}
536 uint32
GetSpellId() const { return m_spellId
;}
537 void getFishLoot(Loot
*loot
, Player
* loot_owner
);
538 GameobjectTypes
GetGoType() const { return GameobjectTypes(GetByteValue(GAMEOBJECT_BYTES_1
, 1)); }
539 void SetGoType(GameobjectTypes type
) { SetByteValue(GAMEOBJECT_BYTES_1
, 1, type
); }
540 GOState
GetGoState() const { return GOState(GetByteValue(GAMEOBJECT_BYTES_1
, 0)); }
541 void SetGoState(GOState state
) { SetByteValue(GAMEOBJECT_BYTES_1
, 0, state
); }
542 uint8
GetGoArtKit() const { return GetByteValue(GAMEOBJECT_BYTES_1
, 2); }
543 void SetGoArtKit(uint8 artkit
) { SetByteValue(GAMEOBJECT_BYTES_1
, 2, artkit
); }
544 uint8
GetGoAnimProgress() const { return GetByteValue(GAMEOBJECT_BYTES_1
, 3); }
545 void SetGoAnimProgress(uint8 animprogress
) { SetByteValue(GAMEOBJECT_BYTES_1
, 3, animprogress
); }
547 void Use(Unit
* user
);
549 LootState
getLootState() const { return m_lootState
; }
550 void SetLootState(LootState s
) { m_lootState
= s
; }
552 void AddToSkillupList(uint32 PlayerGuidLow
) { m_SkillupList
.push_back(PlayerGuidLow
); }
553 bool IsInSkillupList(uint32 PlayerGuidLow
) const
555 for (std::list
<uint32
>::const_iterator i
= m_SkillupList
.begin(); i
!= m_SkillupList
.end(); ++i
)
556 if (*i
== PlayerGuidLow
) return true;
559 void ClearSkillupList() { m_SkillupList
.clear(); }
561 void AddUniqueUse(Player
* player
);
562 void AddUse() { ++m_usetimes
; }
564 uint32
GetUseCount() const { return m_usetimes
; }
565 uint32
GetUniqueUseCount() const { return m_unique_users
.size(); }
567 void SaveRespawnTime();
571 bool hasQuest(uint32 quest_id
) const;
572 bool hasInvolvedQuest(uint32 quest_id
) const;
573 bool ActivateToQuest(Player
*pTarget
) const;
574 void UseDoorOrButton(uint32 time_to_restore
= 0, bool alternative
= false);
575 // 0 = use `gameobject`.`spawntimesecs`
576 void ResetDoorOrButton();
577 // 0 = use `gameobject`.`spawntimesecs`
579 uint32
GetLinkedGameObjectEntry() const
583 case GAMEOBJECT_TYPE_CHEST
: return GetGOInfo()->chest
.linkedTrapId
;
584 case GAMEOBJECT_TYPE_SPELL_FOCUS
: return GetGOInfo()->spellFocus
.linkedTrapId
;
585 case GAMEOBJECT_TYPE_GOOBER
: return GetGOInfo()->goober
.linkedTrapId
;
590 uint32
GetAutoCloseTime() const
592 uint32 autoCloseTime
= 0;
595 case GAMEOBJECT_TYPE_DOOR
: autoCloseTime
= GetGOInfo()->door
.autoCloseTime
; break;
596 case GAMEOBJECT_TYPE_BUTTON
: autoCloseTime
= GetGOInfo()->button
.autoCloseTime
; break;
597 case GAMEOBJECT_TYPE_TRAP
: autoCloseTime
= GetGOInfo()->trap
.autoCloseTime
; break;
598 case GAMEOBJECT_TYPE_GOOBER
: autoCloseTime
= GetGOInfo()->goober
.autoCloseTime
; break;
599 case GAMEOBJECT_TYPE_TRANSPORT
: autoCloseTime
= GetGOInfo()->transport
.autoCloseTime
; break;
600 case GAMEOBJECT_TYPE_AREADAMAGE
: autoCloseTime
= GetGOInfo()->areadamage
.autoCloseTime
; break;
603 return autoCloseTime
/ 0x10000;
606 void TriggeringLinkedGameObject( uint32 trapEntry
, Unit
* target
);
608 bool isVisibleForInState(Player
const* u
, bool inVisibleList
) const;
610 GameObject
* LookupFishingHoleAround(float range
);
612 GridReference
<GameObject
> &GetGridRef() { return m_gridRef
; }
614 bool isActiveObject() const { return false; }
616 uint32 m_charges
; // Spell charges for GAMEOBJECT_TYPE_SPELLCASTER (22)
618 time_t m_respawnTime
; // (secs) time of next respawn (or despawn if GO have owner()),
619 uint32 m_respawnDelayTime
; // (secs) if 0 then current GO state no dependent from timer
620 LootState m_lootState
;
621 bool m_spawnedByDefault
;
622 time_t m_cooldownTime
; // used as internal reaction delay time store (not state change reaction).
623 // For traps this: spell casting cooldown, for doors/buttons: reset time.
624 std::list
<uint32
> m_SkillupList
;
626 std::set
<uint32
> m_unique_users
;
629 uint32 m_DBTableGuid
; ///< For new or temporary gameobjects is 0 for saved it is lowguid
630 GameObjectInfo
const* m_goInfo
;
632 void SwitchDoorOrButton(bool activate
, bool alternative
= false);
634 GridReference
<GameObject
> m_gridRef
;