2 * Copyright (C) 2005-2008 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_CREATURE_H
20 #define MANGOSSERVER_CREATURE_H
24 #include "UpdateMask.h"
25 #include "ItemPrototype.h"
27 #include "Database/DatabaseEnv.h"
39 GOSSIP_OPTION_NONE
= 0, //UNIT_NPC_FLAG_NONE = 0,
40 GOSSIP_OPTION_GOSSIP
= 1, //UNIT_NPC_FLAG_GOSSIP = 1,
41 GOSSIP_OPTION_QUESTGIVER
= 2, //UNIT_NPC_FLAG_QUESTGIVER = 2,
42 GOSSIP_OPTION_VENDOR
= 3, //UNIT_NPC_FLAG_VENDOR = 4,
43 GOSSIP_OPTION_TAXIVENDOR
= 4, //UNIT_NPC_FLAG_TAXIVENDOR = 8,
44 GOSSIP_OPTION_TRAINER
= 5, //UNIT_NPC_FLAG_TRAINER = 16,
45 GOSSIP_OPTION_SPIRITHEALER
= 6, //UNIT_NPC_FLAG_SPIRITHEALER = 32,
46 GOSSIP_OPTION_SPIRITGUIDE
= 7, //UNIT_NPC_FLAG_SPIRITGUIDE = 64,
47 GOSSIP_OPTION_INNKEEPER
= 8, //UNIT_NPC_FLAG_INNKEEPER = 128,
48 GOSSIP_OPTION_BANKER
= 9, //UNIT_NPC_FLAG_BANKER = 256,
49 GOSSIP_OPTION_PETITIONER
= 10, //UNIT_NPC_FLAG_PETITIONER = 512,
50 GOSSIP_OPTION_TABARDDESIGNER
= 11, //UNIT_NPC_FLAG_TABARDDESIGNER = 1024,
51 GOSSIP_OPTION_BATTLEFIELD
= 12, //UNIT_NPC_FLAG_BATTLEFIELDPERSON = 2048,
52 GOSSIP_OPTION_AUCTIONEER
= 13, //UNIT_NPC_FLAG_AUCTIONEER = 4096,
53 GOSSIP_OPTION_STABLEPET
= 14, //UNIT_NPC_FLAG_STABLE = 8192,
54 GOSSIP_OPTION_ARMORER
= 15, //UNIT_NPC_FLAG_ARMORER = 16384,
55 GOSSIP_OPTION_UNLEARNTALENTS
= 16, //UNIT_NPC_FLAG_TRAINER (bonus option for GOSSIP_OPTION_TRAINER)
56 GOSSIP_OPTION_UNLEARNPETSKILLS
= 17 //UNIT_NPC_FLAG_TRAINER (bonus option for GOSSIP_OPTION_TRAINER)
61 GOSSIP_GUARD_BANK
= 32,
62 GOSSIP_GUARD_RIDE
= 33,
63 GOSSIP_GUARD_GUILD
= 34,
64 GOSSIP_GUARD_INN
= 35,
65 GOSSIP_GUARD_MAIL
= 36,
66 GOSSIP_GUARD_AUCTION
= 37,
67 GOSSIP_GUARD_WEAPON
= 38,
68 GOSSIP_GUARD_STABLE
= 39,
69 GOSSIP_GUARD_BATTLE
= 40,
70 GOSSIP_GUARD_SPELLTRAINER
= 41,
71 GOSSIP_GUARD_SKILLTRAINER
= 42
74 enum Gossip_Guard_Spell
76 GOSSIP_GUARD_SPELL_WARRIOR
= 64,
77 GOSSIP_GUARD_SPELL_PALADIN
= 65,
78 GOSSIP_GUARD_SPELL_HUNTER
= 66,
79 GOSSIP_GUARD_SPELL_ROGUE
= 67,
80 GOSSIP_GUARD_SPELL_PRIEST
= 68,
81 GOSSIP_GUARD_SPELL_UNKNOWN1
= 69,
82 GOSSIP_GUARD_SPELL_SHAMAN
= 70,
83 GOSSIP_GUARD_SPELL_MAGE
= 71,
84 GOSSIP_GUARD_SPELL_WARLOCK
= 72,
85 GOSSIP_GUARD_SPELL_UNKNOWN2
= 73,
86 GOSSIP_GUARD_SPELL_DRUID
= 74
89 enum Gossip_Guard_Skill
91 GOSSIP_GUARD_SKILL_ALCHEMY
= 80,
92 GOSSIP_GUARD_SKILL_BLACKSMITH
= 81,
93 GOSSIP_GUARD_SKILL_COOKING
= 82,
94 GOSSIP_GUARD_SKILL_ENCHANT
= 83,
95 GOSSIP_GUARD_SKILL_FIRSTAID
= 84,
96 GOSSIP_GUARD_SKILL_FISHING
= 85,
97 GOSSIP_GUARD_SKILL_HERBALISM
= 86,
98 GOSSIP_GUARD_SKILL_LEATHER
= 87,
99 GOSSIP_GUARD_SKILL_MINING
= 88,
100 GOSSIP_GUARD_SKILL_SKINNING
= 89,
101 GOSSIP_GUARD_SKILL_TAILORING
= 90,
102 GOSSIP_GUARD_SKILL_ENGINERING
= 91
114 std::string OptionText
;
118 enum CreatureFlagsExtra
120 CREATURE_FLAG_EXTRA_INSTANCE_BIND
= 0x00000001, // creature kill bind instance with killer and killer's group
121 CREATURE_FLAG_EXTRA_CIVILIAN
= 0x00000002, // not aggro (ignore faction/reputation hostility)
122 CREATURE_FLAG_EXTRA_NO_PARRY
= 0x00000004, // creature can't parry
123 CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN
= 0x00000008, // creature can't counter-attack at parry
124 CREATURE_FLAG_EXTRA_NO_BLOCK
= 0x00000010, // creature can't block
125 CREATURE_FLAG_EXTRA_NO_CRUSH
= 0x00000020, // creature can't do crush attacks
126 CREATURE_FLAG_EXTRA_NO_XP_AT_KILL
= 0x00000040, // creature kill not provide XP
127 CREATURE_FLAG_EXTRA_INVISIBLE
= 0x00000080, // creature is always invisible for player (mostly trigger creatures)
130 // 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
131 #if defined( __GNUC__ )
137 // from `creature_template` table
166 uint32 baseattacktime
;
167 uint32 rangeattacktime
;
168 uint32 unit_flags
; // enum UnitFlags mask values
170 uint32 family
; // enum CreatureFamily values for type==CREATURE_TYPE_BEAST, or 0 in another cases
172 uint32 trainer_spell
;
177 uint32 rangedattackpower
;
178 uint32 type
; // enum CreatureType values
179 uint32 type_flags
; // enum CreatureTypeFlags mask values
181 uint32 pickpocketLootId
;
193 uint32 PetSpellDataId
;
202 uint32 MechanicImmuneMask
;
207 SkillType
GetRequiredLootSkill() const
209 if(type_flags
& CREATURE_TYPEFLAGS_HERBLOOT
)
210 return SKILL_HERBALISM
;
211 else if(type_flags
& CREATURE_TYPEFLAGS_MININGLOOT
)
214 return SKILL_SKINNING
; // normal case
217 bool isTameable() const
219 return type
== CREATURE_TYPE_BEAST
&& family
!= 0 && (type_flags
& CREATURE_TYPEFLAGS_TAMEABLE
);
223 struct CreatureLocale
225 std::vector
<std::string
> Name
;
226 std::vector
<std::string
> SubName
;
229 struct NpcOptionLocale
231 std::vector
<std::string
> OptionText
;
232 std::vector
<std::string
> BoxText
;
238 uint32 equipentry
[3];
241 // from `creature` table
244 uint32 id
; // entry in creature_template
252 uint32 spawntimesecs
;
254 uint32 currentwaypoint
;
262 struct CreatureDataAddonAura
268 // from `creature_addon` table
269 struct CreatureDataAddon
278 CreatureDataAddonAura
const* auras
; // loaded as char* "spell1 eff1 spell2 eff2 ... "
281 struct CreatureModelInfo
284 float bounding_radius
;
287 uint32 modelid_other_gender
;
290 enum InhabitTypeValues
295 INHABIT_ANYWHERE
= INHABIT_GROUND
| INHABIT_WATER
| INHABIT_AIR
298 // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
299 #if defined( __GNUC__ )
308 VendorItem(uint32 _item
, uint32 _maxcount
, uint32 _incrtime
, uint32 _ExtendedCost
)
309 : item(_item
), maxcount(_maxcount
), incrtime(_incrtime
), ExtendedCost(_ExtendedCost
) {}
312 uint32 maxcount
; // 0 for infinity item amount
313 uint32 incrtime
; // time for restore items amount if maxcount != 0
316 typedef std::vector
<VendorItem
*> VendorItemList
;
318 struct VendorItemData
320 VendorItemList m_items
;
322 VendorItem
* GetItem(uint32 slot
) const
324 if(slot
>=m_items
.size()) return NULL
;
325 return m_items
[slot
];
327 bool Empty() const { return m_items
.empty(); }
328 uint8
GetItemCount() const { return m_items
.size(); }
329 void AddItem( uint32 item
, uint32 maxcount
, uint32 ptime
, uint32 ExtendedCost
)
331 m_items
.push_back(new VendorItem(item
, maxcount
, ptime
, ExtendedCost
));
333 bool RemoveItem( uint32 item_id
);
334 VendorItem
const* FindItem(uint32 item_id
) const;
335 size_t FindItemSlot(uint32 item_id
) const;
339 for (VendorItemList::iterator itr
= m_items
.begin(); itr
!= m_items
.end(); ++itr
)
344 struct VendorItemCount
346 explicit VendorItemCount(uint32 _item
, uint32 _count
)
347 : itemId(_item
), count(_count
), lastIncrementTime(time(NULL
)) {}
351 time_t lastIncrementTime
;
354 typedef std::list
<VendorItemCount
> VendorItemCounts
;
361 uint32 reqskillvalue
;
365 typedef std::vector
<TrainerSpell
*> TrainerSpellList
;
367 struct TrainerSpellData
369 TrainerSpellData() : trainerType(0) {}
371 TrainerSpellList spellList
;
372 uint32 trainerType
; // trainer type based at trainer spells, can be different from creature_template value.
373 // req. for correct show non-prof. trainers like weaponmaster, allowed values 0 and 2.
376 TrainerSpell
const* Find(uint32 spell_id
) const;
379 typedef std::list
<GossipOption
> GossipOptionList
;
381 typedef std::map
<uint32
,time_t> CreatureSpellCooldowns
;
383 // max different by z coordinate for creature aggro reaction
384 #define CREATURE_Z_ATTACK_RANGE 3
386 #define MAX_VENDOR_ITEMS 255 // Limitation in item count field size in SMSG_LIST_INVENTORY
388 class MANGOS_DLL_SPEC Creature
: public Unit
398 void RemoveFromWorld();
400 bool Create (uint32 guidlow
, Map
*map
, uint32 Entry
, uint32 team
, const CreatureData
*data
= NULL
);
401 bool LoadCreaturesAddon(bool reload
= false);
402 void SelectLevel(const CreatureInfo
*cinfo
);
403 void LoadEquipment(uint32 equip_entry
, bool force
=false);
405 uint32
GetDBTableGUIDLow() const { return m_DBTableGuid
; }
406 char const* GetSubName() const { return GetCreatureInfo()->SubName
; }
408 void Update( uint32 time
); // overwrited Unit::Update
409 void GetRespawnCoord(float &x
, float &y
, float &z
, float* ori
= NULL
, float* dist
=NULL
) const;
410 uint32
GetEquipmentId() const { return m_equipmentId
; }
412 bool isPet() const { return m_isPet
; }
413 bool isVehicle() const { return m_isVehicle
; }
414 void SetCorpseDelay(uint32 delay
) { m_corpseDelay
= delay
; }
415 bool isTotem() const { return m_isTotem
; }
416 bool isRacialLeader() const { return GetCreatureInfo()->RacialLeader
; }
417 bool isCivilian() const { return GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_CIVILIAN
; }
418 bool canWalk() const { return GetCreatureInfo()->InhabitType
& INHABIT_GROUND
; }
419 bool canSwim() const { return GetCreatureInfo()->InhabitType
& INHABIT_WATER
; }
420 bool canFly() const { return GetCreatureInfo()->InhabitType
& INHABIT_AIR
; }
421 ///// TODO RENAME THIS!!!!!
422 bool isCanTrainingOf(Player
* player
, bool msg
) const;
423 bool isCanIneractWithBattleMaster(Player
* player
, bool msg
) const;
424 bool isCanTrainingAndResetTalentsOf(Player
* pPlayer
) const;
425 bool IsOutOfThreatArea(Unit
* pVictim
) const;
426 bool IsImmunedToSpell(SpellEntry
const* spellInfo
, bool useCharges
= false);
427 // redefine Unit::IsImmunedToSpell
428 bool IsImmunedToSpellEffect(uint32 effect
, uint32 mechanic
) const;
429 // redefine Unit::IsImmunedToSpellEffect
435 uint32 rank
= GetCreatureInfo()->rank
;
436 return rank
!= CREATURE_ELITE_NORMAL
&& rank
!= CREATURE_ELITE_RARE
;
439 bool isWorldBoss() const
444 return GetCreatureInfo()->rank
== CREATURE_ELITE_WORLDBOSS
;
447 uint32
getLevelForTarget(Unit
const* target
) const; // overwrite Unit::getLevelForTarget for boss level support
449 bool IsInEvadeMode() const;
451 bool AIM_Initialize();
453 void AI_SendMoveToPacket(float x
, float y
, float z
, uint32 time
, uint32 MovementFlags
, uint8 type
);
454 CreatureAI
* AI() { return i_AI
; }
456 uint32
GetShieldBlockValue() const //dunno mob block value
458 return (getLevel()/2 + uint32(GetStat(STAT_STRENGTH
)/20));
461 SpellSchoolMask
GetMeleeDamageSchoolMask() const { return m_meleeDamageSchoolMask
; }
462 void SetMeleeDamageSchool(SpellSchools school
) { m_meleeDamageSchoolMask
= SpellSchoolMask(1 << school
); }
464 void _AddCreatureSpellCooldown(uint32 spell_id
, time_t end_time
);
465 void _AddCreatureCategoryCooldown(uint32 category
, time_t apply_time
);
466 void AddCreatureSpellCooldown(uint32 spellid
);
467 bool HasSpellCooldown(uint32 spell_id
) const;
468 bool HasCategoryCooldown(uint32 spell_id
) const;
470 bool HasSpell(uint32 spellID
) const;
472 bool UpdateEntry(uint32 entry
, uint32 team
=ALLIANCE
, const CreatureData
* data
=NULL
);
473 bool UpdateStats(Stats stat
);
474 bool UpdateAllStats();
475 void UpdateResistances(uint32 school
);
477 void UpdateMaxHealth();
478 void UpdateMaxPower(Powers power
);
479 void UpdateAttackPowerAndDamage(bool ranged
= false);
480 void UpdateDamagePhysical(WeaponAttackType attType
);
481 uint32
GetCurrentEquipmentId() { return m_equipmentId
; }
482 float GetSpellDamageMod(int32 Rank
);
484 VendorItemData
const* GetVendorItems() const;
485 uint32
GetVendorItemCurrentCount(VendorItem
const* vItem
);
486 uint32
UpdateVendorItemCurrentCount(VendorItem
const* vItem
, uint32 used_count
);
488 TrainerSpellData
const* GetTrainerSpells() const;
490 CreatureInfo
const *GetCreatureInfo() const { return m_creatureInfo
; }
491 CreatureDataAddon
const* GetCreatureAddon() const;
493 std::string
GetScriptName();
494 uint32
GetScriptId();
496 void prepareGossipMenu( Player
*pPlayer
, uint32 gossipid
= 0 );
497 void sendPreparedGossip( Player
* player
);
498 void OnGossipSelect(Player
* player
, uint32 option
);
499 void OnPoiSelect(Player
* player
, GossipOption
const *gossip
);
501 uint32
GetGossipTextId(uint32 action
, uint32 zoneid
);
502 uint32
GetNpcTextId();
503 void LoadGossipOptions();
504 GossipOption
const* GetGossipOption( uint32 id
) const;
505 void addGossipOption(GossipOption
const& gso
) { m_goptions
.push_back(gso
); }
507 void setEmoteState(uint8 emote
) { m_emoteState
= emote
; };
508 void Say(const char* text
, uint32 language
, uint64 TargetGuid
) { MonsterSay(text
,language
,TargetGuid
); }
509 void Yell(const char* text
, uint32 language
, uint64 TargetGuid
) { MonsterYell(text
,language
,TargetGuid
); }
510 void TextEmote(const char* text
, uint64 TargetGuid
, bool IsBossEmote
= false) { MonsterTextEmote(text
,TargetGuid
,IsBossEmote
); }
511 void Whisper(const char* text
, uint64 receiver
, bool IsBossWhisper
= false) { MonsterWhisper(text
,receiver
,IsBossWhisper
); }
512 void Say(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterSay(textId
,language
,TargetGuid
); }
513 void Yell(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterYell(textId
,language
,TargetGuid
); }
514 void TextEmote(int32 textId
, uint64 TargetGuid
, bool IsBossEmote
= false) { MonsterTextEmote(textId
,TargetGuid
,IsBossEmote
); }
515 void Whisper(int32 textId
, uint64 receiver
, bool IsBossWhisper
= false) { MonsterWhisper(textId
,receiver
,IsBossWhisper
); }
517 // overwrite WorldObject function for proper name localization
518 const char* GetNameForLocaleIdx(int32 locale_idx
) const;
520 void setDeathState(DeathState s
); // overwrite virtual Unit::setDeathState
522 bool LoadFromDB(uint32 guid
, Map
*map
);
525 virtual void SaveToDB(uint32 mapid
, uint8 spawnMask
);
526 virtual void DeleteFromDB(); // overwrited in Pet
529 bool lootForPickPocketed
;
531 Player
*GetLootRecipient() const;
532 bool hasLootRecipient() const { return m_lootRecipient
!=0; }
534 void SetLootRecipient (Unit
* unit
);
535 void AllLootRemovedFromCorpse();
537 SpellEntry
const *reachWithSpellAttack(Unit
*pVictim
);
538 SpellEntry
const *reachWithSpellCure(Unit
*pVictim
);
540 uint32 m_spells
[CREATURE_MAX_SPELLS
];
541 CreatureSpellCooldowns m_CreatureSpellCooldowns
;
542 CreatureSpellCooldowns m_CreatureCategoryCooldowns
;
543 uint32 m_GlobalCooldown
;
545 float GetAttackDistance(Unit
const* pl
) const;
547 void CallAssistence();
548 void SetNoCallAssistence(bool val
) { m_AlreadyCallAssistence
= val
; }
550 MovementGeneratorType
GetDefaultMovementType() const { return m_defaultMovementType
; }
551 void SetDefaultMovementType(MovementGeneratorType mgt
) { m_defaultMovementType
= mgt
; }
553 // for use only in LoadHelper, Map::Add Map::CreatureCellRelocation
554 Cell
const& GetCurrentCell() const { return m_currentCell
; }
555 void SetCurrentCell(Cell
const& cell
) { m_currentCell
= cell
; }
557 bool IsVisibleInGridForPlayer(Player
* pl
) const;
561 time_t const& GetRespawnTime() const { return m_respawnTime
; }
562 time_t GetRespawnTimeEx() const;
563 void SetRespawnTime(uint32 respawn
) { m_respawnTime
= respawn
? time(NULL
) + respawn
: 0; }
565 void SaveRespawnTime();
567 uint32
GetRespawnDelay() const { return m_respawnDelay
; }
568 void SetRespawnDelay(uint32 delay
) { m_respawnDelay
= delay
; }
570 float GetRespawnRadius() const { return m_respawnradius
; }
571 void SetRespawnRadius(float dist
) { m_respawnradius
= dist
; }
573 uint32 m_groupLootTimer
; // (msecs)timer used for group loot
574 uint64 lootingGroupLeaderGUID
; // used to find group which is looting corpse
576 void SendZoneUnderAttackMessage(Player
* attacker
);
578 bool hasQuest(uint32 quest_id
) const;
579 bool hasInvolvedQuest(uint32 quest_id
) const;
581 GridReference
<Creature
> &GetGridRef() { return m_gridRef
; }
582 bool isRegeneratingHealth() { return m_regenHealth
; }
583 virtual uint8
GetPetAutoSpellSize() const { return CREATURE_MAX_SPELLS
; }
584 virtual uint32
GetPetAutoSpellOnPos(uint8 pos
) const
586 if (pos
>= CREATURE_MAX_SPELLS
|| m_charmInfo
->GetCharmSpell(pos
)->active
!= ACT_ENABLED
)
589 return m_charmInfo
->GetCharmSpell(pos
)->spellId
;
592 void SetCombatStartPosition(float x
, float y
, float z
) { CombatStartX
= x
; CombatStartY
= y
; CombatStartZ
= z
; }
593 void GetCombatStartPosition(float &x
, float &y
, float &z
) { x
= CombatStartX
; y
= CombatStartY
; z
= CombatStartZ
; }
595 uint32
GetGlobalCooldown() const { return m_GlobalCooldown
; }
598 bool CreateFromProto(uint32 guidlow
,uint32 Entry
,uint32 team
, const CreatureData
*data
= NULL
);
599 bool InitEntry(uint32 entry
, uint32 team
=ALLIANCE
, const CreatureData
* data
=NULL
);
602 VendorItemCounts m_vendorItemCounts
;
604 void _RealtimeSetCreatureInfo();
606 static float _GetHealthMod(int32 Rank
);
607 static float _GetDamageMod(int32 Rank
);
610 uint64 m_lootRecipient
;
613 uint32 m_deathTimer
; // (msecs)timer for death or corpse disappearance
614 time_t m_respawnTime
; // (secs) time of next respawn
615 uint32 m_respawnDelay
; // (secs) delay between corpse disappearance and respawning
616 uint32 m_corpseDelay
; // (secs) delay between death and corpse disappearance
617 float m_respawnradius
;
619 bool m_gossipOptionLoaded
;
620 GossipOptionList m_goptions
;
623 bool m_isPet
; // set only in Pet::Pet
624 bool m_isVehicle
; // set only in Vehicle::Vehicle
625 bool m_isTotem
; // set only in Totem::Totem
626 void RegenerateMana();
627 void RegenerateHealth();
629 MovementGeneratorType m_defaultMovementType
;
630 Cell m_currentCell
; // store current cell where creature listed
631 uint32 m_DBTableGuid
; ///< For new or temporary creatures is 0 for saved it is lowguid
632 uint32 m_equipmentId
;
634 bool m_AlreadyCallAssistence
;
637 bool m_isDeadByDefault
;
639 SpellSchoolMask m_meleeDamageSchoolMask
;
640 uint32 m_originalEntry
;
646 GridReference
<Creature
> m_gridRef
;
647 CreatureInfo
const* m_creatureInfo
; // in heroic mode can different from ObjMgr::GetCreatureTemplate(GetEntry())