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"
38 #define UNIT_MOVEMENT_INTERPOLATE_INTERVAL 300
39 #define MAX_CREATURE_WAYPOINTS 16
40 #define MAX_CREATURE_ITEMS 128
44 GOSSIP_OPTION_NONE
= 0, //UNIT_NPC_FLAG_NONE = 0,
45 GOSSIP_OPTION_GOSSIP
= 1, //UNIT_NPC_FLAG_GOSSIP = 1,
46 GOSSIP_OPTION_QUESTGIVER
= 2, //UNIT_NPC_FLAG_QUESTGIVER = 2,
47 GOSSIP_OPTION_VENDOR
= 3, //UNIT_NPC_FLAG_VENDOR = 4,
48 GOSSIP_OPTION_TAXIVENDOR
= 4, //UNIT_NPC_FLAG_TAXIVENDOR = 8,
49 GOSSIP_OPTION_TRAINER
= 5, //UNIT_NPC_FLAG_TRAINER = 16,
50 GOSSIP_OPTION_SPIRITHEALER
= 6, //UNIT_NPC_FLAG_SPIRITHEALER = 32,
51 GOSSIP_OPTION_GUARD
= 7, //UNIT_NPC_FLAG_GUARD = 64,
52 GOSSIP_OPTION_INNKEEPER
= 8, //UNIT_NPC_FLAG_INNKEEPER = 128,
53 GOSSIP_OPTION_BANKER
= 9, //UNIT_NPC_FLAG_BANKER = 256,
54 GOSSIP_OPTION_PETITIONER
= 10, //UNIT_NPC_FLAG_PETITIONER = 512,
55 GOSSIP_OPTION_TABARDVENDOR
= 11, //UNIT_NPC_FLAG_TABARDVENDOR = 1024,
56 GOSSIP_OPTION_BATTLEFIELD
= 12, //UNIT_NPC_FLAG_BATTLEFIELDPERSON = 2048,
57 GOSSIP_OPTION_AUCTIONEER
= 13, //UNIT_NPC_FLAG_AUCTIONEER = 4096,
58 GOSSIP_OPTION_STABLEPET
= 14, //UNIT_NPC_FLAG_STABLE = 8192,
59 GOSSIP_OPTION_ARMORER
= 15 //UNIT_NPC_FLAG_ARMORER = 16384,
64 GOSSIP_GUARD_BANK
= 32,
65 GOSSIP_GUARD_RIDE
= 33,
66 GOSSIP_GUARD_GUILD
= 34,
67 GOSSIP_GUARD_INN
= 35,
68 GOSSIP_GUARD_MAIL
= 36,
69 GOSSIP_GUARD_AUCTION
= 37,
70 GOSSIP_GUARD_WEAPON
= 38,
71 GOSSIP_GUARD_STABLE
= 39,
72 GOSSIP_GUARD_BATTLE
= 40,
73 GOSSIP_GUARD_SPELLTRAINER
= 41,
74 GOSSIP_GUARD_SKILLTRAINER
= 42
77 enum Gossip_Guard_Spell
79 GOSSIP_GUARD_SPELL_WARRIOR
= 64,
80 GOSSIP_GUARD_SPELL_PALADIN
= 65,
81 GOSSIP_GUARD_SPELL_HUNTER
= 66,
82 GOSSIP_GUARD_SPELL_ROGUE
= 67,
83 GOSSIP_GUARD_SPELL_PRIEST
= 68,
84 GOSSIP_GUARD_SPELL_UNKNOWN1
= 69,
85 GOSSIP_GUARD_SPELL_SHAMAN
= 70,
86 GOSSIP_GUARD_SPELL_MAGE
= 71,
87 GOSSIP_GUARD_SPELL_WARLOCK
= 72,
88 GOSSIP_GUARD_SPELL_UNKNOWN2
= 73,
89 GOSSIP_GUARD_SPELL_DRUID
= 74
92 enum Gossip_Guard_Skill
94 GOSSIP_GUARD_SKILL_ALCHEMY
= 80,
95 GOSSIP_GUARD_SKILL_BLACKSMITH
= 81,
96 GOSSIP_GUARD_SKILL_COOKING
= 82,
97 GOSSIP_GUARD_SKILL_ENCHANT
= 83,
98 GOSSIP_GUARD_SKILL_FIRSTAID
= 84,
99 GOSSIP_GUARD_SKILL_FISHING
= 85,
100 GOSSIP_GUARD_SKILL_HERBALISM
= 86,
101 GOSSIP_GUARD_SKILL_LEATHER
= 87,
102 GOSSIP_GUARD_SKILL_MINING
= 88,
103 GOSSIP_GUARD_SKILL_SKINNING
= 89,
104 GOSSIP_GUARD_SKILL_TAILORING
= 90,
105 GOSSIP_GUARD_SKILL_ENGINERING
= 91
133 uint32 reqskillvalue
;
137 // Only GCC 4.1.0 and later support #pragma pack(push,1) syntax
138 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
164 uint32 baseattacktime
;
165 uint32 rangeattacktime
;
171 float bounding_radius
;
173 uint32 trainer_spell
;
178 uint32 rangedattackpower
;
183 uint32 equipmodel
[3];
202 char const* ScriptName
;
205 #if defined( __GNUC__ ) && (GCC_MAJOR < 4 || GCC_MAJOR == 4 && GCC_MINOR < 1)
225 class MANGOS_DLL_SPEC Creature
: public Unit
228 MotionMaster i_motionMaster
;
235 typedef std::list
<TrainerSpell
*> SpellsList
;
237 bool Create (uint32 guidlow
, uint32 mapid
, float x
, float y
, float z
, float ang
, uint32 Entry
);
238 bool CreateFromProto(uint32 guidlow
,uint32 Entry
);
240 virtual void Update( uint32 time
);
241 inline void GetRespawnCoord(float &x
, float &y
, float &z
) const { x
= respawn_cord
[0]; y
= respawn_cord
[1]; z
= respawn_cord
[2]; }
242 inline void GetRespawnDist(float &d
) const { d
= m_respawnradius
; }
244 bool isTamed() const { return m_isTamed
; }
246 void SetTamed(bool isTamed
) { m_isTamed
= isTamed
; }
248 void GivePetXP(uint32 xp
);
250 bool isPet() const { return m_isPet
; }
251 bool isTotem() const { return m_isTotem
; }
252 bool isCivilian() const { return GetCreatureInfo()->civilian
!= 0; }
253 bool isCanSwimOrFly() const;
254 bool isCanWalkOrFly() const;
255 bool isCanTrainingOf(Player
* player
, bool msg
) const;
259 uint32 rank
= GetCreatureInfo()->rank
;
260 return rank
!= CREATURE_ELITE_NORMAL
&& rank
!= CREATURE_ELITE_RARE
;
265 void AIM_Update(const uint32
&);
266 void AIM_Initialize(void);
267 MotionMaster
* operator->(void) { return &i_motionMaster
; }
269 void AI_SendMoveToPacket(float x
, float y
, float z
, uint32 time
, bool run
, bool WalkBack
);
270 inline CreatureAI
&AI(void) { return *i_AI
; }
272 inline void setMoveRandomFlag(bool f
) { m_moveRandom
= f
; }
273 inline void setMoveRunFlag(bool f
) { m_moveRun
= f
; }
274 inline bool getMoveRandomFlag() { return m_moveRandom
; }
275 inline bool getMoveRunFlag() { return m_moveRun
; }
276 inline bool IsStopped(void) const { return !(hasUnitState(UNIT_STAT_MOVING
)); }
277 inline void StopMoving(void)
279 clearUnitState(UNIT_STAT_MOVING
);
280 AI_SendMoveToPacket(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, false);
283 uint32
GetBlockValue() const //dunno mob block value
285 return getLevel()/2 + 1;
288 /*********************************************************/
289 /*** VENDOR SYSTEM ***/
290 /*********************************************************/
292 uint8
GetItemCount() const { return itemcount
; }
293 uint32
GetItemId( uint32 slot
) const { return item_list
[slot
].id
; }
294 uint32
GetItemCount( uint32 slot
) const { return item_list
[slot
].count
; }
295 uint32
GetMaxItemCount( uint32 slot
) const { return item_list
[slot
].maxcount
; }
296 uint32
GetItemIncrTime( uint32 slot
) const { return item_list
[slot
].incrtime
; }
297 uint32
GetItemLastIncr( uint32 slot
) const { return item_list
[slot
].lastincr
; }
298 void SetItemCount( uint32 slot
, uint32 count
) { item_list
[slot
].count
= count
; }
299 void SetItemLastIncr( uint32 slot
, uint32 ptime
) { item_list
[slot
].lastincr
= ptime
; }
300 void AddItem( uint32 item
, uint32 maxcount
, uint32 ptime
)
302 item_list
[itemcount
].id
= item
;
303 item_list
[itemcount
].count
= maxcount
;
304 item_list
[itemcount
].maxcount
= maxcount
;
305 item_list
[itemcount
].incrtime
= ptime
;
306 item_list
[itemcount
].lastincr
= (uint32
)time(NULL
);
310 CreatureInfo
const *GetCreatureInfo() const;
312 void CreateTrainerSpells();
313 uint32
GetTrainerSpellsSize() const { return m_tspells
.size(); }
314 std::list
<TrainerSpell
*>::iterator
GetTspellsBegin(){ return m_tspells
.begin(); }
315 std::list
<TrainerSpell
*>::iterator
GetTspellsEnd(){ return m_tspells
.end(); }
317 uint32
getDialogStatus(Player
*pPlayer
, uint32 defstatus
);
319 bool hasQuest(uint32 quest_id
);
320 bool hasInvolvedQuest(uint32 quest_id
);
322 void prepareGossipMenu( Player
*pPlayer
,uint32 gossipid
);
323 void sendPreparedGossip( Player
* player
);
324 void OnGossipSelect(Player
* player
, uint32 option
);
325 void OnPoiSelect(Player
* player
, GossipOption
*gossip
);
327 uint32
GetGossipTextId(uint32 action
, uint32 zoneid
);
328 uint32
GetNpcTextId();
329 void LoadGossipOptions();
330 std::string
GetGossipTitle(uint8 type
, uint32 id
);
331 GossipOption
* GetGossipOption( uint32 id
);
332 uint32
GetGossipCount( uint32 gossipid
);
333 void addGossipOption(GossipOption
*gso
) { m_goptions
.push_back(gso
); }
335 void generateMoneyLoot();
338 inline void setEmoteState(uint8 emote
) { m_emoteState
= emote
; };
340 void setDeathState(DeathState s
) // overwrite virtual Unit::setDeathState
344 m_deathTimer
= m_corpseDelay
;
346 if(!IsStopped()) StopMoving();
348 Unit::setDeathState(s
);
351 Unit::setDeathState(CORPSE
);
354 void Say(char const* text
, uint32 language
);
356 bool LoadFromDB(uint32 guid
);
357 virtual void SaveToDB(); // overwrited in Pet
358 virtual void DeleteFromDB(); // overwrited in Pet
361 bool lootForPickPocketed
;
363 bool lootForSkinning
;
365 SpellEntry
*reachWithSpellAttack(Unit
*pVictim
);
366 uint32 m_spells
[CREATURE_MAX_SPELLS
];
368 float GetAttackDistance(Unit
*pl
);
369 uint32
getloyalty(){ return ((GetUInt32Value(UNIT_FIELD_BYTES_1
) >> 8) & 0xFF);};
370 uint32
getUsedTrainPoint(){ return (GetUInt32Value(UNIT_TRAINING_POINTS
) & 0xFFFF);};
371 void GivePetLevel(uint32 level
);
373 MovementGeneratorType
GetDefaultMovementType() const { return m_defaultMovementType
; }
374 void SetDefaultMovementType(MovementGeneratorType mgt
) { m_defaultMovementType
= mgt
; }
376 // for use only in LoadHelper, Map::Add Map::CreatureCellRelocation
377 Cell
const& GetCurrentCell() const { return m_currentCell
; }
378 void SetCurrentCell(Cell
const& cell
) { m_currentCell
= cell
; }
382 void _LoadMovement();
383 void _RealtimeSetCreatureInfo();
388 uint32 m_deathTimer
; // timer for death or corpse disappearance
389 uint32 m_respawnTimer
; // timer for respawn to happen
390 uint32 m_respawnDelay
; // delay between corpse disappearance and respawning
391 uint32 m_corpseDelay
; // delay between death and corpse disappearance
392 float m_respawnradius
;
393 CreatureItem item_list
[MAX_CREATURE_ITEMS
];
396 SpellsList m_tspells
;
400 std::list
<GossipOption
*> m_goptions
;
402 float respawn_cord
[3];
408 bool m_isPet
; // set only in Pet::Pet
409 bool m_isTotem
; // set only in Totem::Totem
411 void RegenerateMana();
412 void RegenerateHealth();
414 MovementGeneratorType m_defaultMovementType
;
415 Cell m_currentCell
; // store current cell where creature listed