2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
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 "MotionMaster.h"
26 #include "MovementGenerator.h"
27 #include "ItemPrototype.h"
29 #include "Database/DatabaseEnv.h"
39 #define UNIT_MOVEMENT_INTERPOLATE_INTERVAL 300
40 #define MAX_CREATURE_WAYPOINTS 16
41 #define MAX_CREATURE_ITEMS 128
45 GOSSIP_OPTION_NONE
= 0, //UNIT_NPC_FLAG_NONE = 0,
46 GOSSIP_OPTION_GOSSIP
= 1, //UNIT_NPC_FLAG_GOSSIP = 1,
47 GOSSIP_OPTION_QUESTGIVER
= 2, //UNIT_NPC_FLAG_QUESTGIVER = 2,
48 GOSSIP_OPTION_VENDOR
= 3, //UNIT_NPC_FLAG_VENDOR = 4,
49 GOSSIP_OPTION_TAXIVENDOR
= 4, //UNIT_NPC_FLAG_TAXIVENDOR = 8,
50 GOSSIP_OPTION_TRAINER
= 5, //UNIT_NPC_FLAG_TRAINER = 16,
51 GOSSIP_OPTION_SPIRITHEALER
= 6, //UNIT_NPC_FLAG_SPIRITHEALER = 32,
52 GOSSIP_OPTION_GUARD
= 7, //UNIT_NPC_FLAG_GUARD = 64,
53 GOSSIP_OPTION_INNKEEPER
= 8, //UNIT_NPC_FLAG_INNKEEPER = 128,
54 GOSSIP_OPTION_BANKER
= 9, //UNIT_NPC_FLAG_BANKER = 256,
55 GOSSIP_OPTION_PETITIONER
= 10, //UNIT_NPC_FLAG_PETITIONER = 512,
56 GOSSIP_OPTION_TABARDVENDOR
= 11, //UNIT_NPC_FLAG_TABARDVENDOR = 1024,
57 GOSSIP_OPTION_BATTLEFIELD
= 12, //UNIT_NPC_FLAG_BATTLEFIELDPERSON = 2048,
58 GOSSIP_OPTION_AUCTIONEER
= 13, //UNIT_NPC_FLAG_AUCTIONEER = 4096,
59 GOSSIP_OPTION_STABLEPET
= 14, //UNIT_NPC_FLAG_STABLE = 8192,
60 GOSSIP_OPTION_ARMORER
= 15, //UNIT_NPC_FLAG_ARMORER = 16384,
61 GOSSIP_OPTION_UNLEARNTALENTS
= 16 //UNIT_NPC_FLAG_TRAINER (bonus option for GOSSIP_OPTION_TRAINER)
66 GOSSIP_GUARD_BANK
= 32,
67 GOSSIP_GUARD_RIDE
= 33,
68 GOSSIP_GUARD_GUILD
= 34,
69 GOSSIP_GUARD_INN
= 35,
70 GOSSIP_GUARD_MAIL
= 36,
71 GOSSIP_GUARD_AUCTION
= 37,
72 GOSSIP_GUARD_WEAPON
= 38,
73 GOSSIP_GUARD_STABLE
= 39,
74 GOSSIP_GUARD_BATTLE
= 40,
75 GOSSIP_GUARD_SPELLTRAINER
= 41,
76 GOSSIP_GUARD_SKILLTRAINER
= 42
79 enum Gossip_Guard_Spell
81 GOSSIP_GUARD_SPELL_WARRIOR
= 64,
82 GOSSIP_GUARD_SPELL_PALADIN
= 65,
83 GOSSIP_GUARD_SPELL_HUNTER
= 66,
84 GOSSIP_GUARD_SPELL_ROGUE
= 67,
85 GOSSIP_GUARD_SPELL_PRIEST
= 68,
86 GOSSIP_GUARD_SPELL_UNKNOWN1
= 69,
87 GOSSIP_GUARD_SPELL_SHAMAN
= 70,
88 GOSSIP_GUARD_SPELL_MAGE
= 71,
89 GOSSIP_GUARD_SPELL_WARLOCK
= 72,
90 GOSSIP_GUARD_SPELL_UNKNOWN2
= 73,
91 GOSSIP_GUARD_SPELL_DRUID
= 74
94 enum Gossip_Guard_Skill
96 GOSSIP_GUARD_SKILL_ALCHEMY
= 80,
97 GOSSIP_GUARD_SKILL_BLACKSMITH
= 81,
98 GOSSIP_GUARD_SKILL_COOKING
= 82,
99 GOSSIP_GUARD_SKILL_ENCHANT
= 83,
100 GOSSIP_GUARD_SKILL_FIRSTAID
= 84,
101 GOSSIP_GUARD_SKILL_FISHING
= 85,
102 GOSSIP_GUARD_SKILL_HERBALISM
= 86,
103 GOSSIP_GUARD_SKILL_LEATHER
= 87,
104 GOSSIP_GUARD_SKILL_MINING
= 88,
105 GOSSIP_GUARD_SKILL_SKINNING
= 89,
106 GOSSIP_GUARD_SKILL_TAILORING
= 90,
107 GOSSIP_GUARD_SKILL_ENGINERING
= 91
135 uint32 reqskillvalue
;
139 // Only GCC 4.1.0 and later support #pragma pack(push,1) syntax
140 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
167 uint32 baseattacktime
;
168 uint32 rangeattacktime
;
174 float bounding_radius
;
176 uint32 trainer_spell
;
181 uint32 rangedattackpower
;
186 uint32 equipmodel
[3];
205 char const* ScriptName
;
207 uint32
randomDisplayID() const;
210 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
230 // max different by z coordinate for creature aggro reaction
231 #define CREATURE_Z_ATTACK_RANGE 3
233 class MANGOS_DLL_SPEC Creature
: public Unit
236 MotionMaster i_motionMaster
;
243 typedef std::list
<TrainerSpell
*> SpellsList
;
245 bool Create (uint32 guidlow
, uint32 mapid
, float x
, float y
, float z
, float ang
, uint32 Entry
);
246 bool CreateFromProto(uint32 guidlow
,uint32 Entry
);
247 void SelectLevel(const CreatureInfo
*cinfo
);
249 virtual void Update( uint32 time
);
250 inline void GetRespawnCoord(float &x
, float &y
, float &z
) const { x
= respawn_cord
[0]; y
= respawn_cord
[1]; z
= respawn_cord
[2]; }
251 inline void GetRespawnDist(float &d
) const { d
= m_respawnradius
; }
253 bool isTamed() const { return m_isTamed
; }
255 void SetTamed(bool isTamed
) { m_isTamed
= isTamed
; }
257 void GivePetXP(uint32 xp
);
259 bool isPet() const { return m_isPet
; }
260 bool isTotem() const { return m_isTotem
; }
261 bool isCivilian() const { return GetCreatureInfo()->civilian
!= 0; }
262 bool isCanSwimOrFly() const;
263 bool isCanWalkOrFly() const;
264 bool isCanTrainingOf(Player
* player
, bool msg
) const;
265 bool isCanTrainingAndResetTalentsOf(Player
* pPlayer
) const;
269 uint32 rank
= GetCreatureInfo()->rank
;
270 return rank
!= CREATURE_ELITE_NORMAL
&& rank
!= CREATURE_ELITE_RARE
;
273 void AIM_Update(const uint32
&);
274 void AIM_Initialize(void);
275 MotionMaster
* operator->(void) { return &i_motionMaster
; }
277 void AI_SendMoveToPacket(float x
, float y
, float z
, uint32 time
, bool run
, bool WalkBack
);
278 inline CreatureAI
&AI(void) { return *i_AI
; }
280 inline void setMoveRandomFlag(bool f
) { m_moveRandom
= f
; }
281 inline void setMoveRunFlag(bool f
) { m_moveRun
= f
; }
282 inline bool getMoveRandomFlag() { return m_moveRandom
; }
283 inline bool getMoveRunFlag() { return m_moveRun
; }
284 inline bool IsStopped(void) const { return !(hasUnitState(UNIT_STAT_MOVING
)); }
285 inline void StopMoving(void)
287 clearUnitState(UNIT_STAT_MOVING
);
288 AI_SendMoveToPacket(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, false);
291 uint32
GetBlockValue() const //dunno mob block value
293 return getLevel()/2 + 1;
296 /*********************************************************/
297 /*** VENDOR SYSTEM ***/
298 /*********************************************************/
300 uint8
GetItemCount() const { return itemcount
; }
301 uint32
GetItemId( uint32 slot
) const { return item_list
[slot
].id
; }
302 uint32
GetItemCount( uint32 slot
) const { return item_list
[slot
].count
; }
303 uint32
GetMaxItemCount( uint32 slot
) const { return item_list
[slot
].maxcount
; }
304 uint32
GetItemIncrTime( uint32 slot
) const { return item_list
[slot
].incrtime
; }
305 uint32
GetItemLastIncr( uint32 slot
) const { return item_list
[slot
].lastincr
; }
306 void SetItemCount( uint32 slot
, uint32 count
) { item_list
[slot
].count
= count
; }
307 void SetItemLastIncr( uint32 slot
, uint32 ptime
) { item_list
[slot
].lastincr
= ptime
; }
308 void AddItem( uint32 item
, uint32 maxcount
, uint32 ptime
)
310 item_list
[itemcount
].id
= item
;
311 item_list
[itemcount
].count
= maxcount
;
312 item_list
[itemcount
].maxcount
= maxcount
;
313 item_list
[itemcount
].incrtime
= ptime
;
314 item_list
[itemcount
].lastincr
= (uint32
)time(NULL
);
318 CreatureInfo
const *GetCreatureInfo() const;
320 void CreateTrainerSpells();
321 uint32
GetTrainerSpellsSize() const { return m_tspells
.size(); }
322 std::list
<TrainerSpell
*>::iterator
GetTspellsBegin(){ return m_tspells
.begin(); }
323 std::list
<TrainerSpell
*>::iterator
GetTspellsEnd(){ return m_tspells
.end(); }
325 uint32
getDialogStatus(Player
*pPlayer
, uint32 defstatus
);
327 void prepareGossipMenu( Player
*pPlayer
,uint32 gossipid
);
328 void sendPreparedGossip( Player
* player
);
329 void OnGossipSelect(Player
* player
, uint32 option
);
330 void OnPoiSelect(Player
* player
, GossipOption
*gossip
);
332 uint32
GetGossipTextId(uint32 action
, uint32 zoneid
);
333 uint32
GetNpcTextId();
334 void LoadGossipOptions();
335 std::string
GetGossipTitle(uint8 type
, uint32 id
);
336 GossipOption
* GetGossipOption( uint32 id
);
337 uint32
GetGossipCount( uint32 gossipid
);
338 void addGossipOption(GossipOption
*gso
) { m_goptions
.push_back(gso
); }
340 inline void setEmoteState(uint8 emote
) { m_emoteState
= emote
; };
342 void setDeathState(DeathState s
); // overwrite virtual Unit::setDeathState
344 void Say(char const* text
, uint32 language
);
345 void MonsterSay(char const *text
, uint32 language
, uint64 targetGUID
);
347 bool LoadFromDB(uint32 guid
, QueryResult
*result
= NULL
);
348 virtual void SaveToDB(); // overwrited in Pet
349 virtual void DeleteFromDB(); // overwrited in Pet
352 bool lootForPickPocketed
;
354 void generateMoneyLoot();
355 Player
*GetLootRecipient() const;
356 void SetLootRecipient (Player
*player
);
358 SpellEntry
*reachWithSpellAttack(Unit
*pVictim
);
359 SpellEntry
*reachWithSpellCure(Unit
*pVictim
);
361 uint32 m_spells
[CREATURE_MAX_SPELLS
];
363 float GetAttackDistance(Unit
*pl
) const;
364 uint32
getloyalty(){ return ((GetUInt32Value(UNIT_FIELD_BYTES_1
) >> 8) & 0xFF);};
365 uint32
getUsedTrainPoint(){ return (GetUInt32Value(UNIT_TRAINING_POINTS
) & 0xFFFF);};
366 void GivePetLevel(uint32 level
);
368 void CallAssistence();
369 void SetNoCallAssistence(bool val
) { m_AlreadyCallAssistence
= val
; }
371 MovementGeneratorType
GetDefaultMovementType() const { return m_defaultMovementType
; }
372 void SetDefaultMovementType(MovementGeneratorType mgt
) { m_defaultMovementType
= mgt
; }
374 // for use only in LoadHelper, Map::Add Map::CreatureCellRelocation
375 Cell
const& GetCurrentCell() const { return m_currentCell
; }
376 void SetCurrentCell(Cell
const& cell
) { m_currentCell
= cell
; }
378 bool IsVisibleInGridForPlayer(Player
* pl
) const;
382 void _LoadMovement();
383 void _RealtimeSetCreatureInfo();
385 float _GetHealthMod(int32 Rank
);
386 float _GetDamageMod(int32 Rank
);
389 uint64 m_lootRecipient
;
392 uint32 m_deathTimer
; // timer for death or corpse disappearance
393 uint32 m_respawnTimer
; // timer for respawn to happen
394 uint32 m_respawnDelay
; // delay between corpse disappearance and respawning
395 uint32 m_corpseDelay
; // delay between death and corpse disappearance
396 float m_respawnradius
;
397 CreatureItem item_list
[MAX_CREATURE_ITEMS
];
400 SpellsList m_tspells
;
404 std::list
<GossipOption
*> m_goptions
;
406 float respawn_cord
[3];
412 bool m_isPet
; // set only in Pet::Pet
413 bool m_isTotem
; // set only in Totem::Totem
415 void RegenerateMana();
416 void RegenerateHealth();
418 MovementGeneratorType m_defaultMovementType
;
419 Cell m_currentCell
; // store current cell where creature listed
420 bool m_AlreadyCallAssistence
;