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_CREATURE_H
20 #define MANGOSSERVER_CREATURE_H
24 #include "UpdateMask.h"
25 #include "ItemPrototype.h"
27 #include "Database/DatabaseEnv.h"
41 GOSSIP_OPTION_NONE
= 0, //UNIT_NPC_FLAG_NONE = 0,
42 GOSSIP_OPTION_GOSSIP
= 1, //UNIT_NPC_FLAG_GOSSIP = 1,
43 GOSSIP_OPTION_QUESTGIVER
= 2, //UNIT_NPC_FLAG_QUESTGIVER = 2,
44 GOSSIP_OPTION_VENDOR
= 3, //UNIT_NPC_FLAG_VENDOR = 4,
45 GOSSIP_OPTION_TAXIVENDOR
= 4, //UNIT_NPC_FLAG_TAXIVENDOR = 8,
46 GOSSIP_OPTION_TRAINER
= 5, //UNIT_NPC_FLAG_TRAINER = 16,
47 GOSSIP_OPTION_SPIRITHEALER
= 6, //UNIT_NPC_FLAG_SPIRITHEALER = 32,
48 GOSSIP_OPTION_SPIRITGUIDE
= 7, //UNIT_NPC_FLAG_SPIRITGUIDE = 64,
49 GOSSIP_OPTION_INNKEEPER
= 8, //UNIT_NPC_FLAG_INNKEEPER = 128,
50 GOSSIP_OPTION_BANKER
= 9, //UNIT_NPC_FLAG_BANKER = 256,
51 GOSSIP_OPTION_PETITIONER
= 10, //UNIT_NPC_FLAG_PETITIONER = 512,
52 GOSSIP_OPTION_TABARDDESIGNER
= 11, //UNIT_NPC_FLAG_TABARDDESIGNER = 1024,
53 GOSSIP_OPTION_BATTLEFIELD
= 12, //UNIT_NPC_FLAG_BATTLEFIELDPERSON = 2048,
54 GOSSIP_OPTION_AUCTIONEER
= 13, //UNIT_NPC_FLAG_AUCTIONEER = 4096,
55 GOSSIP_OPTION_STABLEPET
= 14, //UNIT_NPC_FLAG_STABLE = 8192,
56 GOSSIP_OPTION_ARMORER
= 15, //UNIT_NPC_FLAG_ARMORER = 16384,
57 GOSSIP_OPTION_UNLEARNTALENTS
= 16, //UNIT_NPC_FLAG_TRAINER (bonus option for GOSSIP_OPTION_TRAINER)
58 GOSSIP_OPTION_UNLEARNPETSKILLS
= 17 //UNIT_NPC_FLAG_TRAINER (bonus option for GOSSIP_OPTION_TRAINER)
63 GOSSIP_GUARD_BANK
= 32,
64 GOSSIP_GUARD_RIDE
= 33,
65 GOSSIP_GUARD_GUILD
= 34,
66 GOSSIP_GUARD_INN
= 35,
67 GOSSIP_GUARD_MAIL
= 36,
68 GOSSIP_GUARD_AUCTION
= 37,
69 GOSSIP_GUARD_WEAPON
= 38,
70 GOSSIP_GUARD_STABLE
= 39,
71 GOSSIP_GUARD_BATTLE
= 40,
72 GOSSIP_GUARD_SPELLTRAINER
= 41,
73 GOSSIP_GUARD_SKILLTRAINER
= 42
76 enum Gossip_Guard_Spell
78 GOSSIP_GUARD_SPELL_WARRIOR
= 64,
79 GOSSIP_GUARD_SPELL_PALADIN
= 65,
80 GOSSIP_GUARD_SPELL_HUNTER
= 66,
81 GOSSIP_GUARD_SPELL_ROGUE
= 67,
82 GOSSIP_GUARD_SPELL_PRIEST
= 68,
83 GOSSIP_GUARD_SPELL_UNKNOWN1
= 69,
84 GOSSIP_GUARD_SPELL_SHAMAN
= 70,
85 GOSSIP_GUARD_SPELL_MAGE
= 71,
86 GOSSIP_GUARD_SPELL_WARLOCK
= 72,
87 GOSSIP_GUARD_SPELL_UNKNOWN2
= 73,
88 GOSSIP_GUARD_SPELL_DRUID
= 74
91 enum Gossip_Guard_Skill
93 GOSSIP_GUARD_SKILL_ALCHEMY
= 80,
94 GOSSIP_GUARD_SKILL_BLACKSMITH
= 81,
95 GOSSIP_GUARD_SKILL_COOKING
= 82,
96 GOSSIP_GUARD_SKILL_ENCHANT
= 83,
97 GOSSIP_GUARD_SKILL_FIRSTAID
= 84,
98 GOSSIP_GUARD_SKILL_FISHING
= 85,
99 GOSSIP_GUARD_SKILL_HERBALISM
= 86,
100 GOSSIP_GUARD_SKILL_LEATHER
= 87,
101 GOSSIP_GUARD_SKILL_MINING
= 88,
102 GOSSIP_GUARD_SKILL_SKINNING
= 89,
103 GOSSIP_GUARD_SKILL_TAILORING
= 90,
104 GOSSIP_GUARD_SKILL_ENGINERING
= 91
116 std::string OptionText
;
120 enum CreatureFlagsExtra
122 CREATURE_FLAG_EXTRA_INSTANCE_BIND
= 0x00000001, // creature kill bind instance with killer and killer's group
123 CREATURE_FLAG_EXTRA_CIVILIAN
= 0x00000002, // not aggro (ignore faction/reputation hostility)
124 CREATURE_FLAG_EXTRA_NO_PARRY
= 0x00000004, // creature can't parry
125 CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN
= 0x00000008, // creature can't counter-attack at parry
126 CREATURE_FLAG_EXTRA_NO_BLOCK
= 0x00000010, // creature can't block
127 CREATURE_FLAG_EXTRA_NO_CRUSH
= 0x00000020, // creature can't do crush attacks
128 CREATURE_FLAG_EXTRA_NO_XP_AT_KILL
= 0x00000040, // creature kill not provide XP
129 CREATURE_FLAG_EXTRA_INVISIBLE
= 0x00000080, // creature is always invisible for player (mostly trigger creatures)
132 // 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
133 #if defined( __GNUC__ )
139 // from `creature_template` table
168 uint32 baseattacktime
;
169 uint32 rangeattacktime
;
170 uint32 unit_flags
; // enum UnitFlags mask values
172 uint32 family
; // enum CreatureFamily values for type==CREATURE_TYPE_BEAST, or 0 in another cases
174 uint32 trainer_spell
;
179 uint32 rangedattackpower
;
180 uint32 type
; // enum CreatureType values
181 uint32 type_flags
; // enum CreatureTypeFlags mask values
183 uint32 pickpocketLootId
;
195 uint32 PetSpellDataId
;
204 uint32 MechanicImmuneMask
;
209 SkillType
GetRequiredLootSkill() const
211 if(type_flags
& CREATURE_TYPEFLAGS_HERBLOOT
)
212 return SKILL_HERBALISM
;
213 else if(type_flags
& CREATURE_TYPEFLAGS_MININGLOOT
)
216 return SKILL_SKINNING
; // normal case
219 bool isTameable() const
221 return type
== CREATURE_TYPE_BEAST
&& family
!= 0 && (type_flags
& CREATURE_TYPEFLAGS_TAMEABLE
);
225 struct CreatureLocale
227 std::vector
<std::string
> Name
;
228 std::vector
<std::string
> SubName
;
231 struct NpcOptionLocale
233 std::vector
<std::string
> OptionText
;
234 std::vector
<std::string
> BoxText
;
240 uint32 equipentry
[3];
243 // from `creature` table
246 uint32 id
; // entry in creature_template
254 uint32 spawntimesecs
;
256 uint32 currentwaypoint
;
264 struct CreatureDataAddonAura
270 // from `creature_addon` table
271 struct CreatureDataAddon
280 CreatureDataAddonAura
const* auras
; // loaded as char* "spell1 eff1 spell2 eff2 ... "
283 struct CreatureModelInfo
286 float bounding_radius
;
289 uint32 modelid_other_gender
;
292 enum InhabitTypeValues
297 INHABIT_ANYWHERE
= INHABIT_GROUND
| INHABIT_WATER
| INHABIT_AIR
300 // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform
301 #if defined( __GNUC__ )
310 VendorItem(uint32 _item
, uint32 _maxcount
, uint32 _incrtime
, uint32 _ExtendedCost
)
311 : item(_item
), maxcount(_maxcount
), incrtime(_incrtime
), ExtendedCost(_ExtendedCost
) {}
314 uint32 maxcount
; // 0 for infinity item amount
315 uint32 incrtime
; // time for restore items amount if maxcount != 0
318 typedef std::vector
<VendorItem
*> VendorItemList
;
320 struct VendorItemData
322 VendorItemList m_items
;
324 VendorItem
* GetItem(uint32 slot
) const
326 if(slot
>=m_items
.size()) return NULL
;
327 return m_items
[slot
];
329 bool Empty() const { return m_items
.empty(); }
330 uint8
GetItemCount() const { return m_items
.size(); }
331 void AddItem( uint32 item
, uint32 maxcount
, uint32 ptime
, uint32 ExtendedCost
)
333 m_items
.push_back(new VendorItem(item
, maxcount
, ptime
, ExtendedCost
));
335 bool RemoveItem( uint32 item_id
);
336 VendorItem
const* FindItem(uint32 item_id
) const;
337 size_t FindItemSlot(uint32 item_id
) const;
341 for (VendorItemList::iterator itr
= m_items
.begin(); itr
!= m_items
.end(); ++itr
)
346 struct VendorItemCount
348 explicit VendorItemCount(uint32 _item
, uint32 _count
)
349 : itemId(_item
), count(_count
), lastIncrementTime(time(NULL
)) {}
353 time_t lastIncrementTime
;
356 typedef std::list
<VendorItemCount
> VendorItemCounts
;
363 uint32 reqskillvalue
;
367 typedef std::vector
<TrainerSpell
*> TrainerSpellList
;
369 struct TrainerSpellData
371 TrainerSpellData() : trainerType(0) {}
373 TrainerSpellList spellList
;
374 uint32 trainerType
; // trainer type based at trainer spells, can be different from creature_template value.
375 // req. for correct show non-prof. trainers like weaponmaster, allowed values 0 and 2.
378 TrainerSpell
const* Find(uint32 spell_id
) const;
381 typedef std::list
<GossipOption
> GossipOptionList
;
383 typedef std::map
<uint32
,time_t> CreatureSpellCooldowns
;
385 // max different by z coordinate for creature aggro reaction
386 #define CREATURE_Z_ATTACK_RANGE 3
388 #define MAX_VENDOR_ITEMS 255 // Limitation in item count field size in SMSG_LIST_INVENTORY
390 class MANGOS_DLL_SPEC Creature
: public Unit
400 void RemoveFromWorld();
402 bool Create (uint32 guidlow
, Map
*map
, uint32 Entry
, uint32 team
, const CreatureData
*data
= NULL
);
403 bool LoadCreaturesAddon(bool reload
= false);
404 void SelectLevel(const CreatureInfo
*cinfo
);
405 void LoadEquipment(uint32 equip_entry
, bool force
=false);
407 uint32
GetDBTableGUIDLow() const { return m_DBTableGuid
; }
408 char const* GetSubName() const { return GetCreatureInfo()->SubName
; }
410 void Update( uint32 time
); // overwrited Unit::Update
411 void GetRespawnCoord(float &x
, float &y
, float &z
, float* ori
= NULL
, float* dist
=NULL
) const;
412 uint32
GetEquipmentId() const { return m_equipmentId
; }
414 bool isPet() const { return m_isPet
; }
415 bool isVehicle() const { return m_isVehicle
; }
416 void SetCorpseDelay(uint32 delay
) { m_corpseDelay
= delay
; }
417 bool isTotem() const { return m_isTotem
; }
418 bool isRacialLeader() const { return GetCreatureInfo()->RacialLeader
; }
419 bool isCivilian() const { return GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_CIVILIAN
; }
420 bool canWalk() const { return GetCreatureInfo()->InhabitType
& INHABIT_GROUND
; }
421 bool canSwim() const { return GetCreatureInfo()->InhabitType
& INHABIT_WATER
; }
422 bool canFly() const { return GetCreatureInfo()->InhabitType
& INHABIT_AIR
; }
423 ///// TODO RENAME THIS!!!!!
424 bool isCanTrainingOf(Player
* player
, bool msg
) const;
425 bool isCanIneractWithBattleMaster(Player
* player
, bool msg
) const;
426 bool isCanTrainingAndResetTalentsOf(Player
* pPlayer
) const;
427 bool IsOutOfThreatArea(Unit
* pVictim
) const;
428 bool IsImmunedToSpell(SpellEntry
const* spellInfo
);
429 // redefine Unit::IsImmunedToSpell
430 bool IsImmunedToSpellEffect(uint32 effect
, uint32 mechanic
) const;
431 // redefine Unit::IsImmunedToSpellEffect
437 uint32 rank
= GetCreatureInfo()->rank
;
438 return rank
!= CREATURE_ELITE_NORMAL
&& rank
!= CREATURE_ELITE_RARE
;
441 bool isWorldBoss() const
446 return GetCreatureInfo()->rank
== CREATURE_ELITE_WORLDBOSS
;
449 uint32
getLevelForTarget(Unit
const* target
) const; // overwrite Unit::getLevelForTarget for boss level support
451 bool IsInEvadeMode() const;
453 bool AIM_Initialize();
455 void AI_SendMoveToPacket(float x
, float y
, float z
, uint32 time
, uint32 MovementFlags
, uint8 type
);
456 CreatureAI
* AI() { return i_AI
; }
458 uint32
GetShieldBlockValue() const //dunno mob block value
460 return (getLevel()/2 + uint32(GetStat(STAT_STRENGTH
)/20));
463 SpellSchoolMask
GetMeleeDamageSchoolMask() const { return m_meleeDamageSchoolMask
; }
464 void SetMeleeDamageSchool(SpellSchools school
) { m_meleeDamageSchoolMask
= SpellSchoolMask(1 << school
); }
466 void _AddCreatureSpellCooldown(uint32 spell_id
, time_t end_time
);
467 void _AddCreatureCategoryCooldown(uint32 category
, time_t apply_time
);
468 void AddCreatureSpellCooldown(uint32 spellid
);
469 bool HasSpellCooldown(uint32 spell_id
) const;
470 bool HasCategoryCooldown(uint32 spell_id
) const;
472 bool HasSpell(uint32 spellID
) const;
474 bool UpdateEntry(uint32 entry
, uint32 team
=ALLIANCE
, const CreatureData
* data
=NULL
);
475 bool UpdateStats(Stats stat
);
476 bool UpdateAllStats();
477 void UpdateResistances(uint32 school
);
479 void UpdateMaxHealth();
480 void UpdateMaxPower(Powers power
);
481 void UpdateAttackPowerAndDamage(bool ranged
= false);
482 void UpdateDamagePhysical(WeaponAttackType attType
);
483 uint32
GetCurrentEquipmentId() { return m_equipmentId
; }
484 float GetSpellDamageMod(int32 Rank
);
486 VendorItemData
const* GetVendorItems() const;
487 uint32
GetVendorItemCurrentCount(VendorItem
const* vItem
);
488 uint32
UpdateVendorItemCurrentCount(VendorItem
const* vItem
, uint32 used_count
);
490 TrainerSpellData
const* GetTrainerSpells() const;
492 CreatureInfo
const *GetCreatureInfo() const { return m_creatureInfo
; }
493 CreatureDataAddon
const* GetCreatureAddon() const;
495 std::string
GetScriptName();
496 uint32
GetScriptId();
498 void prepareGossipMenu( Player
*pPlayer
, uint32 gossipid
= 0 );
499 void sendPreparedGossip( Player
* player
);
500 void OnGossipSelect(Player
* player
, uint32 option
);
501 void OnPoiSelect(Player
* player
, GossipOption
const *gossip
);
503 uint32
GetGossipTextId(uint32 action
, uint32 zoneid
);
504 uint32
GetNpcTextId();
505 void LoadGossipOptions();
506 GossipOption
const* GetGossipOption( uint32 id
) const;
507 void addGossipOption(GossipOption
const& gso
) { m_goptions
.push_back(gso
); }
509 void setEmoteState(uint8 emote
) { m_emoteState
= emote
; };
510 void Say(const char* text
, uint32 language
, uint64 TargetGuid
) { MonsterSay(text
,language
,TargetGuid
); }
511 void Yell(const char* text
, uint32 language
, uint64 TargetGuid
) { MonsterYell(text
,language
,TargetGuid
); }
512 void TextEmote(const char* text
, uint64 TargetGuid
, bool IsBossEmote
= false) { MonsterTextEmote(text
,TargetGuid
,IsBossEmote
); }
513 void Whisper(const char* text
, uint64 receiver
, bool IsBossWhisper
= false) { MonsterWhisper(text
,receiver
,IsBossWhisper
); }
514 void Say(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterSay(textId
,language
,TargetGuid
); }
515 void Yell(int32 textId
, uint32 language
, uint64 TargetGuid
) { MonsterYell(textId
,language
,TargetGuid
); }
516 void TextEmote(int32 textId
, uint64 TargetGuid
, bool IsBossEmote
= false) { MonsterTextEmote(textId
,TargetGuid
,IsBossEmote
); }
517 void Whisper(int32 textId
, uint64 receiver
, bool IsBossWhisper
= false) { MonsterWhisper(textId
,receiver
,IsBossWhisper
); }
519 // overwrite WorldObject function for proper name localization
520 const char* GetNameForLocaleIdx(int32 locale_idx
) const;
522 void setDeathState(DeathState s
); // overwrite virtual Unit::setDeathState
525 bool LoadFromDB(uint32 guid
, Map
*map
);
528 virtual void SaveToDB(uint32 mapid
, uint8 spawnMask
);
529 virtual void DeleteFromDB(); // overwrited in Pet
532 bool lootForPickPocketed
;
534 Player
*GetLootRecipient() const;
535 bool hasLootRecipient() const { return m_lootRecipient
!=0; }
537 void SetLootRecipient (Unit
* unit
);
538 void AllLootRemovedFromCorpse();
540 SpellEntry
const *reachWithSpellAttack(Unit
*pVictim
);
541 SpellEntry
const *reachWithSpellCure(Unit
*pVictim
);
543 uint32 m_spells
[CREATURE_MAX_SPELLS
];
544 CreatureSpellCooldowns m_CreatureSpellCooldowns
;
545 CreatureSpellCooldowns m_CreatureCategoryCooldowns
;
546 uint32 m_GlobalCooldown
;
548 float GetAttackDistance(Unit
const* pl
) const;
550 void CallAssistance();
551 void SetNoCallAssistance(bool val
) { m_AlreadyCallAssistance
= val
; }
552 bool CanAssistTo(const Unit
* u
, const Unit
* enemy
) const;
554 MovementGeneratorType
GetDefaultMovementType() const { return m_defaultMovementType
; }
555 void SetDefaultMovementType(MovementGeneratorType mgt
) { m_defaultMovementType
= mgt
; }
557 // for use only in LoadHelper, Map::Add Map::CreatureCellRelocation
558 Cell
const& GetCurrentCell() const { return m_currentCell
; }
559 void SetCurrentCell(Cell
const& cell
) { m_currentCell
= cell
; }
561 bool IsVisibleInGridForPlayer(Player
* pl
) const;
565 time_t const& GetRespawnTime() const { return m_respawnTime
; }
566 time_t GetRespawnTimeEx() const;
567 void SetRespawnTime(uint32 respawn
) { m_respawnTime
= respawn
? time(NULL
) + respawn
: 0; }
569 void SaveRespawnTime();
571 uint32
GetRespawnDelay() const { return m_respawnDelay
; }
572 void SetRespawnDelay(uint32 delay
) { m_respawnDelay
= delay
; }
574 float GetRespawnRadius() const { return m_respawnradius
; }
575 void SetRespawnRadius(float dist
) { m_respawnradius
= dist
; }
577 uint32 m_groupLootTimer
; // (msecs)timer used for group loot
578 uint64 lootingGroupLeaderGUID
; // used to find group which is looting corpse
580 void SendZoneUnderAttackMessage(Player
* attacker
);
582 bool hasQuest(uint32 quest_id
) const;
583 bool hasInvolvedQuest(uint32 quest_id
) const;
585 GridReference
<Creature
> &GetGridRef() { return m_gridRef
; }
586 bool isRegeneratingHealth() { return m_regenHealth
; }
587 virtual uint8
GetPetAutoSpellSize() const { return CREATURE_MAX_SPELLS
; }
588 virtual uint32
GetPetAutoSpellOnPos(uint8 pos
) const
590 if (pos
>= CREATURE_MAX_SPELLS
|| m_charmInfo
->GetCharmSpell(pos
)->active
!= ACT_ENABLED
)
593 return m_charmInfo
->GetCharmSpell(pos
)->spellId
;
596 void SetCombatStartPosition(float x
, float y
, float z
) { CombatStartX
= x
; CombatStartY
= y
; CombatStartZ
= z
; }
597 void GetCombatStartPosition(float &x
, float &y
, float &z
) { x
= CombatStartX
; y
= CombatStartY
; z
= CombatStartZ
; }
599 uint32
GetGlobalCooldown() const { return m_GlobalCooldown
; }
602 bool CreateFromProto(uint32 guidlow
,uint32 Entry
,uint32 team
, const CreatureData
*data
= NULL
);
603 bool InitEntry(uint32 entry
, uint32 team
=ALLIANCE
, const CreatureData
* data
=NULL
);
606 VendorItemCounts m_vendorItemCounts
;
608 void _RealtimeSetCreatureInfo();
610 static float _GetHealthMod(int32 Rank
);
611 static float _GetDamageMod(int32 Rank
);
614 uint64 m_lootRecipient
;
617 uint32 m_deathTimer
; // (msecs)timer for death or corpse disappearance
618 time_t m_respawnTime
; // (secs) time of next respawn
619 uint32 m_respawnDelay
; // (secs) delay between corpse disappearance and respawning
620 uint32 m_corpseDelay
; // (secs) delay between death and corpse disappearance
621 float m_respawnradius
;
623 bool m_gossipOptionLoaded
;
624 GossipOptionList m_goptions
;
627 bool m_isPet
; // set only in Pet::Pet
628 bool m_isVehicle
; // set only in Vehicle::Vehicle
629 bool m_isTotem
; // set only in Totem::Totem
630 void RegenerateMana();
631 void RegenerateHealth();
632 MovementGeneratorType m_defaultMovementType
;
633 Cell m_currentCell
; // store current cell where creature listed
634 uint32 m_DBTableGuid
; ///< For new or temporary creatures is 0 for saved it is lowguid
635 uint32 m_equipmentId
;
637 bool m_AlreadyCallAssistance
;
640 bool m_isDeadByDefault
;
642 SpellSchoolMask m_meleeDamageSchoolMask
;
643 uint32 m_originalEntry
;
649 GridReference
<Creature
> m_gridRef
;
650 CreatureInfo
const* m_creatureInfo
; // in heroic mode can different from ObjMgr::GetCreatureTemplate(GetEntry())
653 class AssistDelayEvent
: public BasicEvent
656 AssistDelayEvent(const uint64
& victim
, Unit
& owner
) : BasicEvent(), m_victim(victim
), m_owner(owner
) { }
658 bool Execute(uint64 e_time
, uint32 p_time
);
659 void AddAssistant(const uint64
& guid
) { m_assistants
.push_back(guid
); }
664 std::list
<uint64
> m_assistants
;