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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
28 #include "GossipDef.h"
33 #include "MapManager.h"
34 #include "CreatureAI.h"
35 #include "CreatureAISelector.h"
37 #include "SpellAuras.h"
38 #include "WaypointMovementGenerator.h"
39 #include "InstanceData.h"
40 #include "BattleGroundMgr.h"
42 #include "GridNotifiers.h"
43 #include "GridNotifiersImpl.h"
46 // apply implementation of the singletons
47 #include "Policies/SingletonImp.h"
49 void TrainerSpellData::Clear()
51 for (TrainerSpellList::iterator itr
= spellList
.begin(); itr
!= spellList
.end(); ++itr
)
56 TrainerSpell
const* TrainerSpellData::Find(uint32 spell_id
) const
58 for(TrainerSpellList::const_iterator itr
= spellList
.begin(); itr
!= spellList
.end(); ++itr
)
59 if((*itr
)->spell
== spell_id
)
65 bool VendorItemData::RemoveItem( uint32 item_id
)
67 for(VendorItemList::iterator i
= m_items
.begin(); i
!= m_items
.end(); ++i
)
69 if((*i
)->item
==item_id
)
78 size_t VendorItemData::FindItemSlot(uint32 item_id
) const
80 for(size_t i
= 0; i
< m_items
.size(); ++i
)
81 if(m_items
[i
]->item
==item_id
)
83 return m_items
.size();
86 VendorItem
const* VendorItemData::FindItem(uint32 item_id
) const
88 for(VendorItemList::const_iterator i
= m_items
.begin(); i
!= m_items
.end(); ++i
)
89 if((*i
)->item
==item_id
)
94 bool AssistDelayEvent::Execute(uint64
/*e_time*/, uint32
/*p_time*/)
96 Unit
* victim
= Unit::GetUnit(m_owner
, m_victim
);
99 while (!m_assistants
.empty())
101 Creature
* assistant
= (Creature
*)Unit::GetUnit(m_owner
, *m_assistants
.begin());
102 m_assistants
.pop_front();
104 if (assistant
&& assistant
->CanAssistTo(&m_owner
, victim
))
106 assistant
->SetNoCallAssistance(true);
108 assistant
->AI()->AttackStart(victim
);
115 Creature::Creature() :
117 lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0),
118 m_lootMoney(0), m_lootRecipient(0),
119 m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f
),
120 m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false), m_isVehicle(false),
121 m_defaultMovementType(IDLE_MOTION_TYPE
), m_equipmentId(0),
122 m_AlreadyCallAssistance(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false),
123 m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL
),m_creatureInfo(NULL
), m_DBTableGuid(0)
126 m_valuesCount
= UNIT_END
;
128 for(int i
=0; i
<4; ++i
)
131 m_CreatureSpellCooldowns
.clear();
132 m_CreatureCategoryCooldowns
.clear();
133 m_GlobalCooldown
= 0;
134 m_unit_movement_flags
= MOVEMENTFLAG_WALK_MODE
;
137 Creature::~Creature()
139 CleanupsBeforeDelete();
141 m_vendorItemCounts
.clear();
147 void Creature::AddToWorld()
149 ///- Register the creature for guid lookup
150 if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this);
154 void Creature::RemoveFromWorld()
156 ///- Remove the creature from the accessor
157 if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this);
158 Unit::RemoveFromWorld();
161 void Creature::RemoveCorpse()
163 if( getDeathState()!=CORPSE
&& !m_isDeadByDefault
|| getDeathState()!=ALIVE
&& m_isDeadByDefault
)
168 ObjectAccessor::UpdateObjectVisibility(this);
170 m_respawnTime
= time(NULL
) + m_respawnDelay
;
173 GetRespawnCoord(x
, y
, z
, &o
);
174 GetMap()->CreatureRelocation(this,x
,y
,z
,o
);
178 * change the entry of creature until respawn
180 bool Creature::InitEntry(uint32 Entry
, uint32 team
, const CreatureData
*data
)
182 CreatureInfo
const *normalInfo
= objmgr
.GetCreatureTemplate(Entry
);
185 sLog
.outErrorDb("Creature::UpdateEntry creature entry %u does not exist.", Entry
);
189 // get heroic mode entry
190 uint32 actualEntry
= Entry
;
191 CreatureInfo
const *cinfo
= normalInfo
;
192 if(normalInfo
->HeroicEntry
)
194 Map
*map
= MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
195 if(map
&& map
->IsHeroic())
197 cinfo
= objmgr
.GetCreatureTemplate(normalInfo
->HeroicEntry
);
200 sLog
.outErrorDb("Creature::UpdateEntry creature heroic entry %u does not exist.", actualEntry
);
206 SetEntry(Entry
); // normal entry always
207 m_creatureInfo
= cinfo
; // map mode related always
209 if (cinfo
->DisplayID_A
== 0 || cinfo
->DisplayID_H
== 0) // Cancel load if no model defined
211 sLog
.outErrorDb("Creature (Entry: %u) has no model defined for Horde or Alliance in table `creature_template`, can't load. ",Entry
);
215 uint32 display_id
= objmgr
.ChooseDisplayId(team
, GetCreatureInfo(), data
);
216 CreatureModelInfo
const *minfo
= objmgr
.GetCreatureModelRandomGender(display_id
);
219 sLog
.outErrorDb("Creature (Entry: %u) has model %u not found in table `creature_model_info`, can't load. ", Entry
, display_id
);
223 display_id
= minfo
->modelid
; // it can be different (for another gender)
225 SetDisplayId(display_id
);
226 SetNativeDisplayId(display_id
);
227 SetByteValue(UNIT_FIELD_BYTES_0
, 2, minfo
->gender
);
229 // Load creature equipment
230 if(!data
|| data
->equipmentId
== 0)
231 { // use default from the template
232 LoadEquipment(cinfo
->equipmentId
);
234 else if(data
&& data
->equipmentId
!= -1)
235 { // override, -1 means no equipment
236 LoadEquipment(data
->equipmentId
);
239 SetName(normalInfo
->Name
); // at normal entry always
241 SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
,minfo
->bounding_radius
);
242 SetFloatValue(UNIT_FIELD_COMBATREACH
,minfo
->combat_reach
);
244 SetFloatValue(UNIT_MOD_CAST_SPEED
, 1.0f
);
246 SetSpeed(MOVE_WALK
, cinfo
->speed
);
247 SetSpeed(MOVE_RUN
, cinfo
->speed
);
248 SetSpeed(MOVE_SWIM
, cinfo
->speed
);
250 SetFloatValue(OBJECT_FIELD_SCALE_X
, cinfo
->scale
);
252 // checked at loading
253 m_defaultMovementType
= MovementGeneratorType(cinfo
->MovementType
);
254 if(!m_respawnradius
&& m_defaultMovementType
==RANDOM_MOTION_TYPE
)
255 m_defaultMovementType
= IDLE_MOTION_TYPE
;
260 bool Creature::UpdateEntry(uint32 Entry
, uint32 team
, const CreatureData
*data
)
262 if(!InitEntry(Entry
,team
,data
))
265 m_regenHealth
= GetCreatureInfo()->RegenHealth
;
267 // creatures always have melee weapon ready if any
268 SetByteValue(UNIT_FIELD_BYTES_2
, 0, SHEATH_STATE_MELEE
);
270 SelectLevel(GetCreatureInfo());
272 SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
, GetCreatureInfo()->faction_H
);
274 SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE
, GetCreatureInfo()->faction_A
);
276 SetUInt32Value(UNIT_NPC_FLAGS
,GetCreatureInfo()->npcflag
);
278 SetAttackTime(BASE_ATTACK
, GetCreatureInfo()->baseattacktime
);
279 SetAttackTime(OFF_ATTACK
, GetCreatureInfo()->baseattacktime
);
280 SetAttackTime(RANGED_ATTACK
,GetCreatureInfo()->rangeattacktime
);
282 SetUInt32Value(UNIT_FIELD_FLAGS
,GetCreatureInfo()->unit_flags
);
283 SetUInt32Value(UNIT_DYNAMIC_FLAGS
,GetCreatureInfo()->dynamicflags
);
285 SetModifierValue(UNIT_MOD_ARMOR
, BASE_VALUE
, float(GetCreatureInfo()->armor
));
286 SetModifierValue(UNIT_MOD_RESISTANCE_HOLY
, BASE_VALUE
, float(GetCreatureInfo()->resistance1
));
287 SetModifierValue(UNIT_MOD_RESISTANCE_FIRE
, BASE_VALUE
, float(GetCreatureInfo()->resistance2
));
288 SetModifierValue(UNIT_MOD_RESISTANCE_NATURE
, BASE_VALUE
, float(GetCreatureInfo()->resistance3
));
289 SetModifierValue(UNIT_MOD_RESISTANCE_FROST
, BASE_VALUE
, float(GetCreatureInfo()->resistance4
));
290 SetModifierValue(UNIT_MOD_RESISTANCE_SHADOW
, BASE_VALUE
, float(GetCreatureInfo()->resistance5
));
291 SetModifierValue(UNIT_MOD_RESISTANCE_ARCANE
, BASE_VALUE
, float(GetCreatureInfo()->resistance6
));
293 SetCanModifyStats(true);
296 FactionTemplateEntry
const* factionTemplate
= sFactionTemplateStore
.LookupEntry(GetCreatureInfo()->faction_A
);
297 if (factionTemplate
) // check and error show at loading templates
299 FactionEntry
const* factionEntry
= sFactionStore
.LookupEntry(factionTemplate
->faction
);
301 if( !(GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_CIVILIAN
) &&
302 (factionEntry
->team
== ALLIANCE
|| factionEntry
->team
== HORDE
) )
306 for(int i
=0; i
< CREATURE_MAX_SPELLS
; ++i
)
307 m_spells
[i
] = GetCreatureInfo()->spells
[i
];
312 void Creature::Update(uint32 diff
)
314 if(m_GlobalCooldown
<= diff
)
315 m_GlobalCooldown
= 0;
317 m_GlobalCooldown
-= diff
;
319 switch( m_deathState
)
322 // Don't must be called, see Creature::setDeathState JUST_ALIVED -> ALIVE promoting.
323 sLog
.outError("Creature (GUIDLow: %u Entry: %u ) in wrong state: JUST_ALIVED (4)",GetGUIDLow(),GetEntry());
326 // Don't must be called, see Creature::setDeathState JUST_DIED -> CORPSE promoting.
327 sLog
.outError("Creature (GUIDLow: %u Entry: %u ) in wrong state: JUST_DEAD (1)",GetGUIDLow(),GetEntry());
331 if( m_respawnTime
<= time(NULL
) )
333 DEBUG_LOG("Respawning...");
335 lootForPickPocketed
= false;
338 if(m_originalEntry
!= GetEntry())
339 UpdateEntry(m_originalEntry
);
341 CreatureInfo
const *cinfo
= GetCreatureInfo();
344 SetUInt32Value(UNIT_DYNAMIC_FLAGS
, 0);
345 if (m_isDeadByDefault
)
347 setDeathState(JUST_DIED
);
349 i_motionMaster
.Clear();
350 clearUnitState(UNIT_STAT_ALL_STATE
);
351 LoadCreaturesAddon(true);
354 setDeathState( JUST_ALIVED
);
356 //Call AI respawn virtual function
357 i_AI
->JustRespawned();
365 if (m_isDeadByDefault
)
368 if( m_deathTimer
<= diff
)
371 DEBUG_LOG("Removing corpse... %u ", GetEntry());
375 m_deathTimer
-= diff
;
376 if (m_groupLootTimer
&& lootingGroupLeaderGUID
)
378 if(diff
<= m_groupLootTimer
)
380 m_groupLootTimer
-= diff
;
384 Group
* group
= objmgr
.GetGroupByLeader(lootingGroupLeaderGUID
);
387 m_groupLootTimer
= 0;
388 lootingGroupLeaderGUID
= 0;
397 if (m_isDeadByDefault
)
399 if( m_deathTimer
<= diff
)
402 DEBUG_LOG("Removing alive corpse... %u ", GetEntry());
406 m_deathTimer
-= diff
;
410 Unit::Update( diff
);
412 // creature can be dead after Unit::Update call
413 // CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly)
419 // do not allow the AI to be changed during update
421 i_AI
->UpdateAI(diff
);
425 // creature can be dead after UpdateAI call
426 // CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly)
431 if(diff
>= m_regenTimer
)
434 m_regenTimer
-= diff
;
436 if (m_regenTimer
!= 0)
439 if (!isInCombat() || IsPolymorphed())
450 setDeathState(JUST_DIED
);
457 void Creature::RegenerateMana()
459 uint32 curValue
= GetPower(POWER_MANA
);
460 uint32 maxValue
= GetMaxPower(POWER_MANA
);
462 if (curValue
>= maxValue
)
467 // Combat and any controlled creature
468 if (isInCombat() || GetCharmerOrOwnerGUID())
470 if(!IsUnderLastManaUseEffect())
472 float ManaIncreaseRate
= sWorld
.getRate(RATE_POWER_MANA
);
473 float Spirit
= GetStat(STAT_SPIRIT
);
475 addvalue
= uint32((Spirit
/5.0f
+ 17.0f
) * ManaIncreaseRate
);
479 addvalue
= maxValue
/3;
481 ModifyPower(POWER_MANA
, addvalue
);
484 void Creature::RegenerateHealth()
486 if (!isRegeneratingHealth())
489 uint32 curValue
= GetHealth();
490 uint32 maxValue
= GetMaxHealth();
492 if (curValue
>= maxValue
)
497 // Not only pet, but any controlled creature
498 if(GetCharmerOrOwnerGUID())
500 float HealthIncreaseRate
= sWorld
.getRate(RATE_HEALTH
);
501 float Spirit
= GetStat(STAT_SPIRIT
);
503 if( GetPower(POWER_MANA
) > 0 )
504 addvalue
= uint32(Spirit
* 0.25 * HealthIncreaseRate
);
506 addvalue
= uint32(Spirit
* 0.80 * HealthIncreaseRate
);
509 addvalue
= maxValue
/3;
511 ModifyHealth(addvalue
);
514 bool Creature::AIM_Initialize()
516 // make sure nothing can change the AI during AI update
519 sLog
.outDebug("AIM_Initialize: failed to init, locked.");
523 CreatureAI
* oldAI
= i_AI
;
524 i_motionMaster
.Initialize();
525 i_AI
= FactorySelector::selectAI(this);
531 bool Creature::Create (uint32 guidlow
, Map
*map
, uint32 phaseMask
, uint32 Entry
, uint32 team
, const CreatureData
*data
)
533 SetMapId(map
->GetId());
534 SetInstanceId(map
->GetInstanceId());
535 SetPhaseMask(phaseMask
,false);
537 //oX = x; oY = y; dX = x; dY = y; m_moveTime = 0; m_startMove = 0;
538 const bool bResult
= CreateFromProto(guidlow
, Entry
, team
, data
);
542 switch (GetCreatureInfo()->rank
)
544 case CREATURE_ELITE_RARE
:
545 m_corpseDelay
= sWorld
.getConfig(CONFIG_CORPSE_DECAY_RARE
);
547 case CREATURE_ELITE_ELITE
:
548 m_corpseDelay
= sWorld
.getConfig(CONFIG_CORPSE_DECAY_ELITE
);
550 case CREATURE_ELITE_RAREELITE
:
551 m_corpseDelay
= sWorld
.getConfig(CONFIG_CORPSE_DECAY_RAREELITE
);
553 case CREATURE_ELITE_WORLDBOSS
:
554 m_corpseDelay
= sWorld
.getConfig(CONFIG_CORPSE_DECAY_WORLDBOSS
);
557 m_corpseDelay
= sWorld
.getConfig(CONFIG_CORPSE_DECAY_NORMAL
);
560 LoadCreaturesAddon();
566 bool Creature::isCanTrainingOf(Player
* pPlayer
, bool msg
) const
571 TrainerSpellData
const* trainer_spells
= GetTrainerSpells();
573 if(!trainer_spells
|| trainer_spells
->spellList
.empty())
575 sLog
.outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_TRAINER but have empty trainer spell list.",
576 GetGUIDLow(),GetEntry());
580 switch(GetCreatureInfo()->trainer_type
)
582 case TRAINER_TYPE_CLASS
:
583 if(pPlayer
->getClass()!=GetCreatureInfo()->classNum
)
587 pPlayer
->PlayerTalkClass
->ClearMenus();
588 switch(GetCreatureInfo()->classNum
)
590 case CLASS_DRUID
: pPlayer
->PlayerTalkClass
->SendGossipMenu( 4913,GetGUID()); break;
591 case CLASS_HUNTER
: pPlayer
->PlayerTalkClass
->SendGossipMenu(10090,GetGUID()); break;
592 case CLASS_MAGE
: pPlayer
->PlayerTalkClass
->SendGossipMenu( 328,GetGUID()); break;
593 case CLASS_PALADIN
:pPlayer
->PlayerTalkClass
->SendGossipMenu( 1635,GetGUID()); break;
594 case CLASS_PRIEST
: pPlayer
->PlayerTalkClass
->SendGossipMenu( 4436,GetGUID()); break;
595 case CLASS_ROGUE
: pPlayer
->PlayerTalkClass
->SendGossipMenu( 4797,GetGUID()); break;
596 case CLASS_SHAMAN
: pPlayer
->PlayerTalkClass
->SendGossipMenu( 5003,GetGUID()); break;
597 case CLASS_WARLOCK
:pPlayer
->PlayerTalkClass
->SendGossipMenu( 5836,GetGUID()); break;
598 case CLASS_WARRIOR
:pPlayer
->PlayerTalkClass
->SendGossipMenu( 4985,GetGUID()); break;
604 case TRAINER_TYPE_PETS
:
605 if(pPlayer
->getClass()!=CLASS_HUNTER
)
607 pPlayer
->PlayerTalkClass
->ClearMenus();
608 pPlayer
->PlayerTalkClass
->SendGossipMenu(3620,GetGUID());
612 case TRAINER_TYPE_MOUNTS
:
613 if(GetCreatureInfo()->race
&& pPlayer
->getRace() != GetCreatureInfo()->race
)
617 pPlayer
->PlayerTalkClass
->ClearMenus();
618 switch(GetCreatureInfo()->classNum
)
620 case RACE_DWARF
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5865,GetGUID()); break;
621 case RACE_GNOME
: pPlayer
->PlayerTalkClass
->SendGossipMenu(4881,GetGUID()); break;
622 case RACE_HUMAN
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5861,GetGUID()); break;
623 case RACE_NIGHTELF
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5862,GetGUID()); break;
624 case RACE_ORC
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5863,GetGUID()); break;
625 case RACE_TAUREN
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5864,GetGUID()); break;
626 case RACE_TROLL
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5816,GetGUID()); break;
627 case RACE_UNDEAD_PLAYER
:pPlayer
->PlayerTalkClass
->SendGossipMenu( 624,GetGUID()); break;
628 case RACE_BLOODELF
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5862,GetGUID()); break;
629 case RACE_DRAENEI
: pPlayer
->PlayerTalkClass
->SendGossipMenu(5864,GetGUID()); break;
635 case TRAINER_TYPE_TRADESKILLS
:
636 if(GetCreatureInfo()->trainer_spell
&& !pPlayer
->HasSpell(GetCreatureInfo()->trainer_spell
))
640 pPlayer
->PlayerTalkClass
->ClearMenus();
641 pPlayer
->PlayerTalkClass
->SendGossipMenu(11031,GetGUID());
647 return false; // checked and error output at creature_template loading
652 bool Creature::isCanInteractWithBattleMaster(Player
* pPlayer
, bool msg
) const
654 if(!isBattleMaster())
657 BattleGroundTypeId bgTypeId
= sBattleGroundMgr
.GetBattleMasterBG(GetEntry());
659 return pPlayer
->GetBGAccessByLevel(bgTypeId
);
661 if(!pPlayer
->GetBGAccessByLevel(bgTypeId
))
663 pPlayer
->PlayerTalkClass
->ClearMenus();
666 case BATTLEGROUND_AV
: pPlayer
->PlayerTalkClass
->SendGossipMenu(7616,GetGUID()); break;
667 case BATTLEGROUND_WS
: pPlayer
->PlayerTalkClass
->SendGossipMenu(7599,GetGUID()); break;
668 case BATTLEGROUND_AB
: pPlayer
->PlayerTalkClass
->SendGossipMenu(7642,GetGUID()); break;
669 case BATTLEGROUND_EY
:
670 case BATTLEGROUND_NA
:
671 case BATTLEGROUND_BE
:
672 case BATTLEGROUND_AA
:
673 case BATTLEGROUND_RL
:
674 case BATTLEGROUND_SA
:
675 case BATTLEGROUND_DS
:
676 case BATTLEGROUND_RV
: pPlayer
->PlayerTalkClass
->SendGossipMenu(10024,GetGUID()); break;
684 bool Creature::isCanTrainingAndResetTalentsOf(Player
* pPlayer
) const
686 return pPlayer
->getLevel() >= 10
687 && GetCreatureInfo()->trainer_type
== TRAINER_TYPE_CLASS
688 && pPlayer
->getClass() == GetCreatureInfo()->classNum
;
691 void Creature::prepareGossipMenu( Player
*pPlayer
,uint32 gossipid
)
693 PlayerMenu
* pm
=pPlayer
->PlayerTalkClass
;
696 // lazy loading single time at use
699 for( GossipOptionList::iterator i
= m_goptions
.begin( ); i
!= m_goptions
.end( ); ++i
)
701 GossipOption
* gso
=&*i
;
702 if(gso
->GossipId
== gossipid
)
704 bool cantalking
=true;
707 uint32 textid
=GetNpcTextId();
708 GossipText
* gossiptext
=objmgr
.GetGossipText(textid
);
716 case GOSSIP_OPTION_QUESTGIVER
:
717 pPlayer
->PrepareQuestMenu(GetGUID());
718 //if (pm->GetQuestMenu()->MenuItemCount() == 0)
720 //pm->GetQuestMenu()->ClearMenu();
722 case GOSSIP_OPTION_ARMORER
:
723 cantalking
=false; // added in special mode
725 case GOSSIP_OPTION_SPIRITHEALER
:
726 if( !pPlayer
->isDead() )
729 case GOSSIP_OPTION_VENDOR
:
731 VendorItemData
const* vItems
= GetVendorItems();
732 if(!vItems
|| vItems
->Empty())
734 sLog
.outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_VENDOR but have empty trading item list.",
735 GetGUIDLow(),GetEntry());
740 case GOSSIP_OPTION_TRAINER
:
741 if(!isCanTrainingOf(pPlayer
,false))
744 case GOSSIP_OPTION_UNLEARNTALENTS
:
745 if(!isCanTrainingAndResetTalentsOf(pPlayer
))
748 case GOSSIP_OPTION_UNLEARNPETSKILLS
:
749 if(!pPlayer
->GetPet() || pPlayer
->GetPet()->getPetType() != HUNTER_PET
|| pPlayer
->GetPet()->m_spells
.size() <= 1 || GetCreatureInfo()->trainer_type
!= TRAINER_TYPE_PETS
|| GetCreatureInfo()->classNum
!= CLASS_HUNTER
)
752 case GOSSIP_OPTION_TAXIVENDOR
:
753 if ( pPlayer
->GetSession()->SendLearnNewTaxiNode(this) )
756 case GOSSIP_OPTION_BATTLEFIELD
:
757 if(!isCanInteractWithBattleMaster(pPlayer
,false))
760 case GOSSIP_OPTION_SPIRITGUIDE
:
761 case GOSSIP_OPTION_INNKEEPER
:
762 case GOSSIP_OPTION_BANKER
:
763 case GOSSIP_OPTION_PETITIONER
:
764 case GOSSIP_OPTION_STABLEPET
:
765 case GOSSIP_OPTION_TABARDDESIGNER
:
766 case GOSSIP_OPTION_AUCTIONEER
:
769 sLog
.outErrorDb("Creature %u (entry: %u) have unknown gossip option %u",GetDBTableGUIDLow(),GetEntry(),gso
->Action
);
774 //note for future dev: should have database fields for BoxMessage & BoxMoney
775 if(!gso
->OptionText
.empty() && cantalking
)
777 std::string OptionText
= gso
->OptionText
;
778 std::string BoxText
= gso
->BoxText
;
779 int loc_idx
= pPlayer
->GetSession()->GetSessionDbLocaleIndex();
782 NpcOptionLocale
const *no
= objmgr
.GetNpcOptionLocale(gso
->Id
);
785 if (no
->OptionText
.size() > loc_idx
&& !no
->OptionText
[loc_idx
].empty())
786 OptionText
=no
->OptionText
[loc_idx
];
787 if (no
->BoxText
.size() > loc_idx
&& !no
->BoxText
[loc_idx
].empty())
788 BoxText
=no
->BoxText
[loc_idx
];
791 pm
->GetGossipMenu().AddMenuItem((uint8
)gso
->Icon
,OptionText
, gossipid
,gso
->Action
,BoxText
,gso
->BoxMoney
,gso
->Coded
);
796 ///some gossips aren't handled in normal way ... so we need to do it this way .. TODO: handle it in normal way ;-)
799 if(HasFlag(UNIT_NPC_FLAGS
,UNIT_NPC_FLAG_TRAINER
))
801 isCanTrainingOf(pPlayer
,true); // output error message if need
803 if(HasFlag(UNIT_NPC_FLAGS
,UNIT_NPC_FLAG_BATTLEMASTER
))
805 isCanInteractWithBattleMaster(pPlayer
,true); // output error message if need
810 void Creature::sendPreparedGossip(Player
* player
)
815 // in case no gossip flag and quest menu not empty, open quest menu (client expect gossip menu with this flag)
816 if (!HasFlag(UNIT_NPC_FLAGS
,UNIT_NPC_FLAG_GOSSIP
) && !player
->PlayerTalkClass
->GetQuestMenu().Empty())
818 player
->SendPreparedQuest(GetGUID());
822 // in case non empty gossip menu (that not included quests list size) show it
823 // (quest entries from quest menu will be included in list)
824 player
->PlayerTalkClass
->SendGossipMenu(GetNpcTextId(), GetGUID());
827 void Creature::OnGossipSelect(Player
* player
, uint32 option
)
829 GossipMenu
& gossipmenu
= player
->PlayerTalkClass
->GetGossipMenu();
831 if(option
>= gossipmenu
.MenuItemCount())
834 uint32 action
=gossipmenu
.GetItem(option
).m_gAction
;
835 uint32 zoneid
=GetZoneId();
836 uint64 guid
=GetGUID();
838 GossipOption
const *gossip
=GetGossipOption( action
);
842 gossip
=GetGossipOption( action
);
847 switch (gossip
->Action
)
849 case GOSSIP_OPTION_GOSSIP
:
851 uint32 textid
= GetGossipTextId(action
, zoneid
);
853 textid
=GetNpcTextId();
855 player
->PlayerTalkClass
->CloseGossip();
856 player
->PlayerTalkClass
->SendTalking(textid
);
859 case GOSSIP_OPTION_SPIRITHEALER
:
860 if (player
->isDead())
861 CastSpell(this,17251,true,NULL
,NULL
,player
->GetGUID());
863 case GOSSIP_OPTION_QUESTGIVER
:
864 player
->PrepareQuestMenu( guid
);
865 player
->SendPreparedQuest( guid
);
867 case GOSSIP_OPTION_VENDOR
:
868 case GOSSIP_OPTION_ARMORER
:
869 player
->GetSession()->SendListInventory(guid
);
871 case GOSSIP_OPTION_STABLEPET
:
872 player
->GetSession()->SendStablePet(guid
);
874 case GOSSIP_OPTION_TRAINER
:
875 player
->GetSession()->SendTrainerList(guid
);
877 case GOSSIP_OPTION_UNLEARNTALENTS
:
878 player
->PlayerTalkClass
->CloseGossip();
879 player
->SendTalentWipeConfirm(guid
);
881 case GOSSIP_OPTION_UNLEARNPETSKILLS
:
882 player
->PlayerTalkClass
->CloseGossip();
883 player
->SendPetSkillWipeConfirm();
885 case GOSSIP_OPTION_TAXIVENDOR
:
886 player
->GetSession()->SendTaxiMenu(this);
888 case GOSSIP_OPTION_INNKEEPER
:
889 player
->PlayerTalkClass
->CloseGossip();
890 player
->SetBindPoint( guid
);
892 case GOSSIP_OPTION_BANKER
:
893 player
->GetSession()->SendShowBank( guid
);
895 case GOSSIP_OPTION_PETITIONER
:
896 player
->PlayerTalkClass
->CloseGossip();
897 player
->GetSession()->SendPetitionShowList( guid
);
899 case GOSSIP_OPTION_TABARDDESIGNER
:
900 player
->PlayerTalkClass
->CloseGossip();
901 player
->GetSession()->SendTabardVendorActivate( guid
);
903 case GOSSIP_OPTION_AUCTIONEER
:
904 player
->GetSession()->SendAuctionHello( guid
, this );
906 case GOSSIP_OPTION_SPIRITGUIDE
:
907 case GOSSIP_GUARD_SPELLTRAINER
:
908 case GOSSIP_GUARD_SKILLTRAINER
:
909 prepareGossipMenu( player
,gossip
->Id
);
910 sendPreparedGossip( player
);
912 case GOSSIP_OPTION_BATTLEFIELD
:
914 BattleGroundTypeId bgTypeId
= sBattleGroundMgr
.GetBattleMasterBG(GetEntry());
915 player
->GetSession()->SendBattlegGroundList( GetGUID(), bgTypeId
);
919 OnPoiSelect( player
, gossip
);
925 void Creature::OnPoiSelect(Player
* player
, GossipOption
const *gossip
)
927 if(gossip
->GossipId
==GOSSIP_GUARD_SPELLTRAINER
|| gossip
->GossipId
==GOSSIP_GUARD_SKILLTRAINER
)
929 Poi_Icon icon
= ICON_POI_0
;
930 //need add more case.
931 switch(gossip
->Action
)
933 case GOSSIP_GUARD_BANK
:
936 case GOSSIP_GUARD_RIDE
:
937 icon
=ICON_POI_RWHORSE
;
939 case GOSSIP_GUARD_GUILD
:
940 icon
=ICON_POI_BLUETOWER
;
946 uint32 textid
= GetGossipTextId( gossip
->Action
, GetZoneId() );
947 player
->PlayerTalkClass
->SendTalking(textid
);
948 // std::string areaname= gossip->OptionText;
949 // how this could worked player->PlayerTalkClass->SendPointOfInterest( x, y, icon, 2, 15, areaname.c_str() );
953 uint32
Creature::GetGossipTextId(uint32 action
, uint32 zoneid
)
955 QueryResult
*result
= WorldDatabase
.PQuery("SELECT textid FROM npc_gossip_textid WHERE action = '%u' AND zoneid ='%u'", action
, zoneid
);
960 Field
*fields
= result
->Fetch();
961 uint32 id
= fields
[0].GetUInt32();
968 uint32
Creature::GetNpcTextId()
971 return DEFAULT_GOSSIP_MESSAGE
;
973 if(uint32 pos
= objmgr
.GetNpcGossip(m_DBTableGuid
))
976 return DEFAULT_GOSSIP_MESSAGE
;
979 GossipOption
const* Creature::GetGossipOption( uint32 id
) const
981 for( GossipOptionList::const_iterator i
= m_goptions
.begin( ); i
!= m_goptions
.end( ); ++i
)
989 void Creature::LoadGossipOptions()
991 if(m_gossipOptionLoaded
)
994 uint32 npcflags
=GetUInt32Value(UNIT_NPC_FLAGS
);
996 CacheNpcOptionList
const& noList
= objmgr
.GetNpcOptions ();
997 for (CacheNpcOptionList::const_iterator i
= noList
.begin (); i
!= noList
.end (); ++i
)
998 if(i
->NpcFlag
& npcflags
)
1001 m_gossipOptionLoaded
= true;
1004 void Creature::AI_SendMoveToPacket(float x
, float y
, float z
, uint32 time
, uint32 MovementFlags
, uint8 type
)
1006 /* uint32 timeElap = getMSTime();
1007 if ((timeElap - m_startMove) < m_moveTime)
1009 oX = (dX - oX) * ( (timeElap - m_startMove) / m_moveTime );
1010 oY = (dY - oY) * ( (timeElap - m_startMove) / m_moveTime );
1020 m_orientation = atan2((oY - dY), (oX - dX));
1022 m_startMove = getMSTime();
1023 m_moveTime = time;*/
1024 SendMonsterMove(x
, y
, z
, type
, MovementFlags
, time
);
1027 Player
*Creature::GetLootRecipient() const
1029 if (!m_lootRecipient
) return NULL
;
1030 else return ObjectAccessor::FindPlayer(m_lootRecipient
);
1033 void Creature::SetLootRecipient(Unit
*unit
)
1035 // set the player whose group should receive the right
1036 // to loot the creature after it dies
1037 // should be set to NULL after the loot disappears
1041 m_lootRecipient
= 0;
1042 RemoveFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_OTHER_TAGGER
);
1046 Player
* player
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself();
1047 if(!player
) // normal creature, no player involved
1050 m_lootRecipient
= player
->GetGUID();
1051 SetFlag(UNIT_DYNAMIC_FLAGS
, UNIT_DYNFLAG_OTHER_TAGGER
);
1054 void Creature::SaveToDB()
1056 // this should only be used when the creature has already been loaded
1057 // preferably after adding to map, because mapid may not be valid otherwise
1058 CreatureData
const *data
= objmgr
.GetCreatureData(m_DBTableGuid
);
1061 sLog
.outError("Creature::SaveToDB failed, cannot get creature data!");
1065 SaveToDB(GetMapId(), data
->spawnMask
,GetPhaseMask());
1068 void Creature::SaveToDB(uint32 mapid
, uint8 spawnMask
, uint32 phaseMask
)
1070 // update in loaded data
1072 m_DBTableGuid
= GetGUIDLow();
1073 CreatureData
& data
= objmgr
.NewOrExistCreatureData(m_DBTableGuid
);
1075 uint32 displayId
= GetNativeDisplayId();
1077 // check if it's a custom model and if not, use 0 for displayId
1078 CreatureInfo
const *cinfo
= GetCreatureInfo();
1081 if(displayId
!= cinfo
->DisplayID_A
&& displayId
!= cinfo
->DisplayID_H
)
1083 CreatureModelInfo
const *minfo
= objmgr
.GetCreatureModelInfo(cinfo
->DisplayID_A
);
1084 if(!minfo
|| displayId
!= minfo
->modelid_other_gender
)
1086 minfo
= objmgr
.GetCreatureModelInfo(cinfo
->DisplayID_H
);
1087 if(minfo
&& displayId
== minfo
->modelid_other_gender
)
1097 // data->guid = guid don't must be update at save
1098 data
.id
= GetEntry();
1100 data
.phaseMask
= phaseMask
;
1101 data
.displayid
= displayId
;
1102 data
.equipmentId
= GetEquipmentId();
1103 data
.posX
= GetPositionX();
1104 data
.posY
= GetPositionY();
1105 data
.posZ
= GetPositionZ();
1106 data
.orientation
= GetOrientation();
1107 data
.spawntimesecs
= m_respawnDelay
;
1108 // prevent add data integrity problems
1109 data
.spawndist
= GetDefaultMovementType()==IDLE_MOTION_TYPE
? 0 : m_respawnradius
;
1110 data
.currentwaypoint
= 0;
1111 data
.curhealth
= GetHealth();
1112 data
.curmana
= GetPower(POWER_MANA
);
1113 data
.is_dead
= m_isDeadByDefault
;
1114 // prevent add data integrity problems
1115 data
.movementType
= !m_respawnradius
&& GetDefaultMovementType()==RANDOM_MOTION_TYPE
1116 ? IDLE_MOTION_TYPE
: GetDefaultMovementType();
1117 data
.spawnMask
= spawnMask
;
1120 WorldDatabase
.BeginTransaction();
1122 WorldDatabase
.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid
);
1124 std::ostringstream ss
;
1125 ss
<< "INSERT INTO creature VALUES ("
1126 << m_DBTableGuid
<< ","
1127 << GetEntry() << ","
1129 << (uint32
)spawnMask
<< ","
1130 << (uint32
)GetPhaseMask() << ","
1132 << GetEquipmentId() <<","
1133 << GetPositionX() << ","
1134 << GetPositionY() << ","
1135 << GetPositionZ() << ","
1136 << GetOrientation() << ","
1137 << m_respawnDelay
<< "," //respawn time
1138 << (float) m_respawnradius
<< "," //spawn distance (float)
1139 << (uint32
) (0) << "," //currentwaypoint
1140 << GetHealth() << "," //curhealth
1141 << GetPower(POWER_MANA
) << "," //curmana
1142 << (m_isDeadByDefault
? 1 : 0) << "," //is_dead
1143 << GetDefaultMovementType() << ")"; //default movement generator type
1145 WorldDatabase
.PExecuteLog( ss
.str( ).c_str( ) );
1147 WorldDatabase
.CommitTransaction();
1150 void Creature::SelectLevel(const CreatureInfo
*cinfo
)
1152 uint32 rank
= isPet()? 0 : cinfo
->rank
;
1155 uint32 minlevel
= std::min(cinfo
->maxlevel
, cinfo
->minlevel
);
1156 uint32 maxlevel
= std::max(cinfo
->maxlevel
, cinfo
->minlevel
);
1157 uint32 level
= minlevel
== maxlevel
? minlevel
: urand(minlevel
, maxlevel
);
1160 float rellevel
= maxlevel
== minlevel
? 0 : (float(level
- minlevel
))/(maxlevel
- minlevel
);
1163 float healthmod
= _GetHealthMod(rank
);
1165 uint32 minhealth
= std::min(cinfo
->maxhealth
, cinfo
->minhealth
);
1166 uint32 maxhealth
= std::max(cinfo
->maxhealth
, cinfo
->minhealth
);
1167 uint32 health
= uint32(healthmod
* (minhealth
+ uint32(rellevel
*(maxhealth
- minhealth
))));
1169 SetCreateHealth(health
);
1170 SetMaxHealth(health
);
1174 uint32 minmana
= std::min(cinfo
->maxmana
, cinfo
->minmana
);
1175 uint32 maxmana
= std::max(cinfo
->maxmana
, cinfo
->minmana
);
1176 uint32 mana
= minmana
+ uint32(rellevel
*(maxmana
- minmana
));
1178 SetCreateMana(mana
);
1179 SetMaxPower(POWER_MANA
, mana
); //MAX Mana
1180 SetPower(POWER_MANA
, mana
);
1182 SetModifierValue(UNIT_MOD_HEALTH
, BASE_VALUE
, health
);
1183 SetModifierValue(UNIT_MOD_MANA
, BASE_VALUE
, mana
);
1186 float damagemod
= _GetDamageMod(rank
);
1188 SetBaseWeaponDamage(BASE_ATTACK
, MINDAMAGE
, cinfo
->mindmg
* damagemod
);
1189 SetBaseWeaponDamage(BASE_ATTACK
, MAXDAMAGE
, cinfo
->maxdmg
* damagemod
);
1191 SetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE
,cinfo
->minrangedmg
* damagemod
);
1192 SetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE
,cinfo
->maxrangedmg
* damagemod
);
1194 SetModifierValue(UNIT_MOD_ATTACK_POWER
, BASE_VALUE
, cinfo
->attackpower
* damagemod
);
1197 float Creature::_GetHealthMod(int32 Rank
)
1199 switch (Rank
) // define rates for each elite rank
1201 case CREATURE_ELITE_NORMAL
:
1202 return sWorld
.getRate(RATE_CREATURE_NORMAL_HP
);
1203 case CREATURE_ELITE_ELITE
:
1204 return sWorld
.getRate(RATE_CREATURE_ELITE_ELITE_HP
);
1205 case CREATURE_ELITE_RAREELITE
:
1206 return sWorld
.getRate(RATE_CREATURE_ELITE_RAREELITE_HP
);
1207 case CREATURE_ELITE_WORLDBOSS
:
1208 return sWorld
.getRate(RATE_CREATURE_ELITE_WORLDBOSS_HP
);
1209 case CREATURE_ELITE_RARE
:
1210 return sWorld
.getRate(RATE_CREATURE_ELITE_RARE_HP
);
1212 return sWorld
.getRate(RATE_CREATURE_ELITE_ELITE_HP
);
1216 float Creature::_GetDamageMod(int32 Rank
)
1218 switch (Rank
) // define rates for each elite rank
1220 case CREATURE_ELITE_NORMAL
:
1221 return sWorld
.getRate(RATE_CREATURE_NORMAL_DAMAGE
);
1222 case CREATURE_ELITE_ELITE
:
1223 return sWorld
.getRate(RATE_CREATURE_ELITE_ELITE_DAMAGE
);
1224 case CREATURE_ELITE_RAREELITE
:
1225 return sWorld
.getRate(RATE_CREATURE_ELITE_RAREELITE_DAMAGE
);
1226 case CREATURE_ELITE_WORLDBOSS
:
1227 return sWorld
.getRate(RATE_CREATURE_ELITE_WORLDBOSS_DAMAGE
);
1228 case CREATURE_ELITE_RARE
:
1229 return sWorld
.getRate(RATE_CREATURE_ELITE_RARE_DAMAGE
);
1231 return sWorld
.getRate(RATE_CREATURE_ELITE_ELITE_DAMAGE
);
1235 float Creature::GetSpellDamageMod(int32 Rank
)
1237 switch (Rank
) // define rates for each elite rank
1239 case CREATURE_ELITE_NORMAL
:
1240 return sWorld
.getRate(RATE_CREATURE_NORMAL_SPELLDAMAGE
);
1241 case CREATURE_ELITE_ELITE
:
1242 return sWorld
.getRate(RATE_CREATURE_ELITE_ELITE_SPELLDAMAGE
);
1243 case CREATURE_ELITE_RAREELITE
:
1244 return sWorld
.getRate(RATE_CREATURE_ELITE_RAREELITE_SPELLDAMAGE
);
1245 case CREATURE_ELITE_WORLDBOSS
:
1246 return sWorld
.getRate(RATE_CREATURE_ELITE_WORLDBOSS_SPELLDAMAGE
);
1247 case CREATURE_ELITE_RARE
:
1248 return sWorld
.getRate(RATE_CREATURE_ELITE_RARE_SPELLDAMAGE
);
1250 return sWorld
.getRate(RATE_CREATURE_ELITE_ELITE_SPELLDAMAGE
);
1254 bool Creature::CreateFromProto(uint32 guidlow
, uint32 Entry
, uint32 team
, const CreatureData
*data
)
1256 CreatureInfo
const *cinfo
= objmgr
.GetCreatureTemplate(Entry
);
1259 sLog
.outErrorDb("Error: creature entry %u does not exist.", Entry
);
1262 m_originalEntry
= Entry
;
1264 Object::_Create(guidlow
, Entry
, HIGHGUID_UNIT
);
1266 if(!UpdateEntry(Entry
, team
, data
))
1269 //Notify the map's instance data.
1270 //Only works if you create the object in it, not if it is moves to that map.
1271 //Normally non-players do not teleport to other maps.
1272 Map
*map
= MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
1273 if(map
&& map
->IsDungeon() && ((InstanceMap
*)map
)->GetInstanceData())
1275 ((InstanceMap
*)map
)->GetInstanceData()->OnCreatureCreate(this, Entry
);
1281 bool Creature::LoadFromDB(uint32 guid
, Map
*map
)
1283 CreatureData
const* data
= objmgr
.GetCreatureData(guid
);
1287 sLog
.outErrorDb("Creature (GUID: %u) not found in table `creature`, can't load. ",guid
);
1291 m_DBTableGuid
= guid
;
1292 if (map
->GetInstanceId() != 0) guid
= objmgr
.GenerateLowGuid(HIGHGUID_UNIT
);
1295 if(!Create(guid
,map
,data
->phaseMask
,data
->id
,team
,data
))
1298 Relocate(data
->posX
,data
->posY
,data
->posZ
,data
->orientation
);
1300 if(!IsPositionValid())
1302 sLog
.outError("ERROR: Creature (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",GetGUIDLow(),GetEntry(),GetPositionX(),GetPositionY());
1306 m_respawnradius
= data
->spawndist
;
1308 m_respawnDelay
= data
->spawntimesecs
;
1309 m_isDeadByDefault
= data
->is_dead
;
1310 m_deathState
= m_isDeadByDefault
? DEAD
: ALIVE
;
1312 m_respawnTime
= objmgr
.GetCreatureRespawnTime(m_DBTableGuid
,GetInstanceId());
1313 if(m_respawnTime
> time(NULL
)) // not ready to respawn
1315 m_deathState
= DEAD
;
1318 float tz
= GetMap()->GetHeight(data
->posX
,data
->posY
,data
->posZ
,false);
1319 if(data
->posZ
- tz
> 0.1)
1320 Relocate(data
->posX
,data
->posY
,tz
);
1323 else if(m_respawnTime
) // respawn time set but expired
1326 objmgr
.SaveCreatureRespawnTime(m_DBTableGuid
,GetInstanceId(),0);
1329 uint32 curhealth
= data
->curhealth
;
1332 curhealth
= uint32(curhealth
*_GetHealthMod(GetCreatureInfo()->rank
));
1337 SetHealth(m_deathState
== ALIVE
? curhealth
: 0);
1338 SetPower(POWER_MANA
,data
->curmana
);
1340 SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool
));
1342 // checked at creature_template loading
1343 m_defaultMovementType
= MovementGeneratorType(data
->movementType
);
1349 void Creature::LoadEquipment(uint32 equip_entry
, bool force
)
1351 if(equip_entry
== 0)
1355 for (uint8 i
= 0; i
< 3; i
++)
1356 SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID
+ i
, 0);
1362 EquipmentInfo
const *einfo
= objmgr
.GetEquipmentInfo(equip_entry
);
1366 m_equipmentId
= equip_entry
;
1367 for (uint8 i
= 0; i
< 3; i
++)
1368 SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID
+ i
, einfo
->equipentry
[i
]);
1371 bool Creature::hasQuest(uint32 quest_id
) const
1373 QuestRelations
const& qr
= objmgr
.mCreatureQuestRelations
;
1374 for(QuestRelations::const_iterator itr
= qr
.lower_bound(GetEntry()); itr
!= qr
.upper_bound(GetEntry()); ++itr
)
1376 if(itr
->second
==quest_id
)
1382 bool Creature::hasInvolvedQuest(uint32 quest_id
) const
1384 QuestRelations
const& qr
= objmgr
.mCreatureQuestInvolvedRelations
;
1385 for(QuestRelations::const_iterator itr
= qr
.lower_bound(GetEntry()); itr
!= qr
.upper_bound(GetEntry()); ++itr
)
1387 if(itr
->second
==quest_id
)
1393 void Creature::DeleteFromDB()
1397 sLog
.outDebug("Trying to delete not saved creature!");
1401 objmgr
.SaveCreatureRespawnTime(m_DBTableGuid
,GetInstanceId(),0);
1402 objmgr
.DeleteCreatureData(m_DBTableGuid
);
1404 WorldDatabase
.BeginTransaction();
1405 WorldDatabase
.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid
);
1406 WorldDatabase
.PExecuteLog("DELETE FROM creature_addon WHERE guid = '%u'", m_DBTableGuid
);
1407 WorldDatabase
.PExecuteLog("DELETE FROM creature_movement WHERE id = '%u'", m_DBTableGuid
);
1408 WorldDatabase
.PExecuteLog("DELETE FROM game_event_creature WHERE guid = '%u'", m_DBTableGuid
);
1409 WorldDatabase
.PExecuteLog("DELETE FROM game_event_model_equip WHERE guid = '%u'", m_DBTableGuid
);
1410 WorldDatabase
.CommitTransaction();
1413 float Creature::GetAttackDistance(Unit
const* pl
) const
1415 float aggroRate
= sWorld
.getRate(RATE_CREATURE_AGGRO
);
1419 int32 playerlevel
= pl
->getLevelForTarget(this);
1420 int32 creaturelevel
= getLevelForTarget(pl
);
1422 int32 leveldif
= playerlevel
- creaturelevel
;
1424 // "The maximum Aggro Radius has a cap of 25 levels under. Example: A level 30 char has the same Aggro Radius of a level 5 char on a level 60 mob."
1425 if ( leveldif
< - 25)
1428 // "The aggro radius of a mob having the same level as the player is roughly 20 yards"
1429 float RetDistance
= 20;
1431 // "Aggro Radius varies with level difference at a rate of roughly 1 yard/level"
1432 // radius grow if playlevel < creaturelevel
1433 RetDistance
-= (float)leveldif
;
1435 if(creaturelevel
+5 <= sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
))
1437 // detect range auras
1438 RetDistance
+= GetTotalAuraModifier(SPELL_AURA_MOD_DETECT_RANGE
);
1440 // detected range auras
1441 RetDistance
+= pl
->GetTotalAuraModifier(SPELL_AURA_MOD_DETECTED_RANGE
);
1444 // "Minimum Aggro Radius for a mob seems to be combat range (5 yards)"
1448 return (RetDistance
*aggroRate
);
1451 void Creature::setDeathState(DeathState s
)
1453 if((s
== JUST_DIED
&& !m_isDeadByDefault
)||(s
== JUST_ALIVED
&& m_isDeadByDefault
))
1455 m_deathTimer
= m_corpseDelay
*1000;
1457 // always save boss respawn time at death to prevent crash cheating
1458 if(sWorld
.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY
) || isWorldBoss())
1461 if (canFly() && FallGround())
1467 Unit::setDeathState(s
);
1471 SetUInt64Value (UNIT_FIELD_TARGET
,0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
1472 SetUInt32Value(UNIT_NPC_FLAGS
, 0);
1474 if(!isPet() && GetCreatureInfo()->SkinLootId
)
1475 if ( LootTemplates_Skinning
.HaveLootFor(GetCreatureInfo()->SkinLootId
) )
1476 SetFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
);
1478 if (canFly() && FallGround())
1481 Unit::setDeathState(CORPSE
);
1483 if(s
== JUST_ALIVED
)
1485 SetHealth(GetMaxHealth());
1486 SetLootRecipient(NULL
);
1487 Unit::setDeathState(ALIVE
);
1488 CreatureInfo
const *cinfo
= GetCreatureInfo();
1489 SetUInt32Value(UNIT_DYNAMIC_FLAGS
, 0);
1490 RemoveFlag (UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
);
1491 AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE
);
1492 SetUInt32Value(UNIT_NPC_FLAGS
, cinfo
->npcflag
);
1493 clearUnitState(UNIT_STAT_ALL_STATE
);
1494 i_motionMaster
.Clear();
1495 SetMeleeDamageSchool(SpellSchools(cinfo
->dmgschool
));
1496 LoadCreaturesAddon(true);
1500 bool Creature::FallGround()
1502 // Let's abort after we called this function one time
1503 if (getDeathState() == DEAD_FALLING
)
1506 // Let's do with no vmap because no way to get far distance with vmap high call
1507 float tz
= GetMap()->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), false);
1509 // Abort too if the ground is very near
1510 if (fabs(GetPositionZ() - tz
) < 0.1f
)
1513 Unit::setDeathState(DEAD_FALLING
);
1514 GetMotionMaster()->MovePoint(0, GetPositionX(), GetPositionY(), tz
);
1515 Relocate(GetPositionX(), GetPositionY(), tz
);
1519 void Creature::Respawn()
1523 // forced recreate creature object at clients
1524 UnitVisibility currentVis
= GetVisibility();
1525 SetVisibility(VISIBILITY_RESPAWN
);
1526 ObjectAccessor::UpdateObjectVisibility(this);
1527 SetVisibility(currentVis
); // restore visibility state
1528 ObjectAccessor::UpdateObjectVisibility(this);
1530 if(getDeathState()==DEAD
)
1533 objmgr
.SaveCreatureRespawnTime(m_DBTableGuid
,GetInstanceId(),0);
1534 m_respawnTime
= time(NULL
); // respawn at next tick
1538 bool Creature::IsImmunedToSpell(SpellEntry
const* spellInfo
)
1543 if (GetCreatureInfo()->MechanicImmuneMask
& (1 << (spellInfo
->Mechanic
- 1)))
1546 return Unit::IsImmunedToSpell(spellInfo
);
1549 bool Creature::IsImmunedToSpellEffect(SpellEntry
const* spellInfo
, uint32 index
) const
1551 if (GetCreatureInfo()->MechanicImmuneMask
& (1 << (spellInfo
->EffectMechanic
[index
] - 1)))
1554 return Unit::IsImmunedToSpellEffect(spellInfo
, index
);
1557 SpellEntry
const *Creature::reachWithSpellAttack(Unit
*pVictim
)
1562 for(uint32 i
=0; i
< CREATURE_MAX_SPELLS
; i
++)
1566 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(m_spells
[i
] );
1569 sLog
.outError("WORLD: unknown spell id %i\n", m_spells
[i
]);
1573 bool bcontinue
= true;
1574 for(uint32 j
=0;j
<3;j
++)
1576 if( (spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
) ||
1577 (spellInfo
->Effect
[j
] == SPELL_EFFECT_INSTAKILL
) ||
1578 (spellInfo
->Effect
[j
] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
) ||
1579 (spellInfo
->Effect
[j
] == SPELL_EFFECT_HEALTH_LEECH
)
1586 if(bcontinue
) continue;
1588 if(spellInfo
->manaCost
> GetPower(POWER_MANA
))
1590 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(spellInfo
->rangeIndex
);
1591 float range
= GetSpellMaxRange(srange
);
1592 float minrange
= GetSpellMinRange(srange
);
1593 float dist
= GetDistance(pVictim
);
1594 //if(!isInFront( pVictim, range ) && spellInfo->AttributesEx )
1596 if( dist
> range
|| dist
< minrange
)
1598 if(spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
&& HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_SILENCED
))
1600 if(spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
&& HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
))
1607 SpellEntry
const *Creature::reachWithSpellCure(Unit
*pVictim
)
1612 for(uint32 i
=0; i
< CREATURE_MAX_SPELLS
; i
++)
1616 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(m_spells
[i
] );
1619 sLog
.outError("WORLD: unknown spell id %i\n", m_spells
[i
]);
1623 bool bcontinue
= true;
1624 for(uint32 j
=0;j
<3;j
++)
1626 if( (spellInfo
->Effect
[j
] == SPELL_EFFECT_HEAL
) )
1632 if(bcontinue
) continue;
1634 if(spellInfo
->manaCost
> GetPower(POWER_MANA
))
1636 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(spellInfo
->rangeIndex
);
1637 float range
= GetSpellMaxRange(srange
);
1638 float minrange
= GetSpellMinRange(srange
);
1639 float dist
= GetDistance(pVictim
);
1640 //if(!isInFront( pVictim, range ) && spellInfo->AttributesEx )
1642 if( dist
> range
|| dist
< minrange
)
1644 if(spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
&& HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_SILENCED
))
1646 if(spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
&& HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
))
1653 bool Creature::IsVisibleInGridForPlayer(Player
* pl
) const
1655 // gamemaster in GM mode see all, including ghosts
1656 if(pl
->isGameMaster())
1659 // Live player (or with not release body see live creatures or death creatures with corpse disappearing time > 0
1660 if(pl
->isAlive() || pl
->GetDeathTimer() > 0)
1662 if(GetCreatureInfo()->flags_extra
& CREATURE_FLAG_EXTRA_INVISIBLE
)
1664 return isAlive() || m_deathTimer
> 0 || m_isDeadByDefault
&& m_deathState
==CORPSE
;
1667 // Dead player see live creatures near own corpse
1670 Corpse
*corpse
= pl
->GetCorpse();
1673 // 20 - aggro distance for same level, 25 - max additional distance if player level less that creature level
1674 if(corpse
->IsWithinDistInMap(this,(20+25)*sWorld
.getRate(RATE_CREATURE_AGGRO
)))
1679 // Dead player see Spirit Healer or Spirit Guide
1680 if(isSpiritService())
1683 // and not see any other
1687 void Creature::CallAssistance()
1689 if( !m_AlreadyCallAssistance
&& getVictim() && !isPet() && !isCharmed())
1691 SetNoCallAssistance(true);
1693 float radius
= sWorld
.getConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS
);
1696 std::list
<Creature
*> assistList
;
1699 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
1701 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1704 MaNGOS::AnyAssistCreatureInRangeCheck
u_check(this, getVictim(), radius
);
1705 MaNGOS::CreatureListSearcher
<MaNGOS::AnyAssistCreatureInRangeCheck
> searcher(this, assistList
, u_check
);
1707 TypeContainerVisitor
<MaNGOS::CreatureListSearcher
<MaNGOS::AnyAssistCreatureInRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
1709 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1710 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *GetMap());
1713 if (!assistList
.empty())
1715 AssistDelayEvent
*e
= new AssistDelayEvent(getVictim()->GetGUID(), *this);
1716 while (!assistList
.empty())
1718 // Pushing guids because in delay can happen some creature gets despawned => invalid pointer
1719 e
->AddAssistant((*assistList
.begin())->GetGUID());
1720 assistList
.pop_front();
1722 m_Events
.AddEvent(e
, m_Events
.CalculateTime(sWorld
.getConfig(CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY
)));
1728 bool Creature::CanAssistTo(const Unit
* u
, const Unit
* enemy
) const
1730 // we don't need help from zombies :)
1734 // skip fighting creature
1738 // only from same creature faction
1739 if(getFaction() != u
->getFaction() )
1742 // only free creature
1743 if( GetCharmerOrOwnerGUID() )
1746 // skip non hostile to caster enemy creatures
1747 if( !IsHostileTo(enemy
) )
1753 void Creature::SaveRespawnTime()
1755 if(isPet() || !m_DBTableGuid
)
1758 if(m_respawnTime
> time(NULL
)) // dead (no corpse)
1759 objmgr
.SaveCreatureRespawnTime(m_DBTableGuid
,GetInstanceId(),m_respawnTime
);
1760 else if(m_deathTimer
> 0) // dead (corpse)
1761 objmgr
.SaveCreatureRespawnTime(m_DBTableGuid
,GetInstanceId(),time(NULL
)+m_respawnDelay
+m_deathTimer
/1000);
1764 bool Creature::IsOutOfThreatArea(Unit
* pVictim
) const
1769 if(!pVictim
->IsInMap(this))
1772 if(!pVictim
->isTargetableForAttack())
1775 if(!pVictim
->isInAccessablePlaceFor(this))
1778 if(sMapStore
.LookupEntry(GetMapId())->IsDungeon())
1781 float length
= pVictim
->GetDistance(CombatStartX
,CombatStartY
,CombatStartZ
);
1782 float AttackDist
= GetAttackDistance(pVictim
);
1783 uint32 ThreatRadius
= sWorld
.getConfig(CONFIG_THREAT_RADIUS
);
1785 //Use AttackDistance in distance check if threat radius is lower. This prevents creature bounce in and out of combat every update tick.
1786 return ( length
> (ThreatRadius
> AttackDist
? ThreatRadius
: AttackDist
));
1789 CreatureDataAddon
const* Creature::GetCreatureAddon() const
1793 if(CreatureDataAddon
const* addon
= ObjectMgr::GetCreatureAddon(m_DBTableGuid
))
1797 // dependent from heroic mode entry
1798 return ObjectMgr::GetCreatureTemplateAddon(GetCreatureInfo()->Entry
);
1801 //creature_addon table
1802 bool Creature::LoadCreaturesAddon(bool reload
)
1804 CreatureDataAddon
const *cainfo
= GetCreatureAddon();
1808 if (cainfo
->mount
!= 0)
1809 Mount(cainfo
->mount
);
1811 if (cainfo
->bytes0
!= 0)
1812 SetUInt32Value(UNIT_FIELD_BYTES_0
, cainfo
->bytes0
);
1814 if (cainfo
->bytes1
!= 0)
1815 SetUInt32Value(UNIT_FIELD_BYTES_1
, cainfo
->bytes1
);
1817 if (cainfo
->bytes2
!= 0)
1818 SetUInt32Value(UNIT_FIELD_BYTES_2
, cainfo
->bytes2
);
1820 if (cainfo
->emote
!= 0)
1821 SetUInt32Value(UNIT_NPC_EMOTESTATE
, cainfo
->emote
);
1823 if (cainfo
->move_flags
!= 0)
1824 SetUnitMovementFlags(cainfo
->move_flags
);
1828 for (CreatureDataAddonAura
const* cAura
= cainfo
->auras
; cAura
->spell_id
; ++cAura
)
1830 SpellEntry
const *AdditionalSpellInfo
= sSpellStore
.LookupEntry(cAura
->spell_id
);
1831 if (!AdditionalSpellInfo
)
1833 sLog
.outErrorDb("Creature (GUIDLow: %u Entry: %u ) has wrong spell %u defined in `auras` field.",GetGUIDLow(),GetEntry(),cAura
->spell_id
);
1837 // skip already applied aura
1838 if(HasAura(cAura
->spell_id
,cAura
->effect_idx
))
1841 sLog
.outErrorDb("Creature (GUIDLow: %u Entry: %u ) has duplicate aura (spell %u effect %u) in `auras` field.",GetGUIDLow(),GetEntry(),cAura
->spell_id
,cAura
->effect_idx
);
1846 Aura
* AdditionalAura
= CreateAura(AdditionalSpellInfo
, cAura
->effect_idx
, NULL
, this, this, 0);
1847 AddAura(AdditionalAura
);
1848 sLog
.outDebug("Spell: %u with Aura %u added to creature (GUIDLow: %u Entry: %u )", cAura
->spell_id
, AdditionalSpellInfo
->EffectApplyAuraName
[0],GetGUIDLow(),GetEntry());
1854 /// Send a message to LocalDefense channel for players opposition team in the zone
1855 void Creature::SendZoneUnderAttackMessage(Player
* attacker
)
1857 uint32 enemy_team
= attacker
->GetTeam();
1859 WorldPacket
data(SMSG_ZONE_UNDER_ATTACK
,4);
1860 data
<< (uint32
)GetZoneId();
1861 sWorld
.SendGlobalMessage(&data
,NULL
,(enemy_team
==ALLIANCE
? HORDE
: ALLIANCE
));
1864 void Creature::_AddCreatureSpellCooldown(uint32 spell_id
, time_t end_time
)
1866 m_CreatureSpellCooldowns
[spell_id
] = end_time
;
1869 void Creature::_AddCreatureCategoryCooldown(uint32 category
, time_t apply_time
)
1871 m_CreatureCategoryCooldowns
[category
] = apply_time
;
1874 void Creature::AddCreatureSpellCooldown(uint32 spellid
)
1876 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellid
);
1880 uint32 cooldown
= GetSpellRecoveryTime(spellInfo
);
1882 _AddCreatureSpellCooldown(spellid
, time(NULL
) + cooldown
/1000);
1884 if(spellInfo
->Category
)
1885 _AddCreatureCategoryCooldown(spellInfo
->Category
, time(NULL
));
1887 m_GlobalCooldown
= spellInfo
->StartRecoveryTime
;
1890 bool Creature::HasCategoryCooldown(uint32 spell_id
) const
1892 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spell_id
);
1896 // check global cooldown if spell affected by it
1897 if (spellInfo
->StartRecoveryCategory
> 0 && m_GlobalCooldown
> 0)
1900 CreatureSpellCooldowns::const_iterator itr
= m_CreatureCategoryCooldowns
.find(spellInfo
->Category
);
1901 return(itr
!= m_CreatureCategoryCooldowns
.end() && time_t(itr
->second
+ (spellInfo
->CategoryRecoveryTime
/ 1000)) > time(NULL
));
1904 bool Creature::HasSpellCooldown(uint32 spell_id
) const
1906 CreatureSpellCooldowns::const_iterator itr
= m_CreatureSpellCooldowns
.find(spell_id
);
1907 return (itr
!= m_CreatureSpellCooldowns
.end() && itr
->second
> time(NULL
)) || HasCategoryCooldown(spell_id
);
1910 bool Creature::IsInEvadeMode() const
1912 return !i_motionMaster
.empty() && i_motionMaster
.GetCurrentMovementGeneratorType() == HOME_MOTION_TYPE
;
1915 bool Creature::HasSpell(uint32 spellID
) const
1918 for(i
= 0; i
< CREATURE_MAX_SPELLS
; ++i
)
1919 if(spellID
== m_spells
[i
])
1921 return i
< CREATURE_MAX_SPELLS
; //broke before end of iteration of known spells
1924 time_t Creature::GetRespawnTimeEx() const
1926 time_t now
= time(NULL
);
1927 if(m_respawnTime
> now
) // dead (no corpse)
1928 return m_respawnTime
;
1929 else if(m_deathTimer
> 0) // dead (corpse)
1930 return now
+m_respawnDelay
+m_deathTimer
/1000;
1935 void Creature::GetRespawnCoord( float &x
, float &y
, float &z
, float* ori
, float* dist
) const
1939 if (CreatureData
const* data
= objmgr
.GetCreatureData(GetDBTableGUIDLow()))
1945 *ori
= data
->orientation
;
1947 *dist
= data
->spawndist
;
1957 *ori
= GetOrientation();
1962 void Creature::AllLootRemovedFromCorpse()
1964 if (!HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_SKINNABLE
))
1968 CreatureInfo
const *cinfo
= GetCreatureInfo();
1970 // corpse was not skinnable -> apply corpse looted timer
1971 if (!cinfo
|| !cinfo
->SkinLootId
)
1972 nDeathTimer
= (uint32
)((m_corpseDelay
* 1000) * sWorld
.getRate(RATE_CORPSE_DECAY_LOOTED
));
1973 // corpse skinnable, but without skinning flag, and then skinned, corpse will despawn next update
1977 // update death timer only if looted timer is shorter
1978 if (m_deathTimer
> nDeathTimer
)
1979 m_deathTimer
= nDeathTimer
;
1983 uint32
Creature::getLevelForTarget( Unit
const* target
) const
1986 return Unit::getLevelForTarget(target
);
1988 uint32 level
= target
->getLevel()+sWorld
.getConfig(CONFIG_WORLD_BOSS_LEVEL_DIFF
);
1996 std::string
Creature::GetScriptName()
1998 return objmgr
.GetScriptName(GetScriptId());
2001 uint32
Creature::GetScriptId()
2003 return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptID
;
2006 VendorItemData
const* Creature::GetVendorItems() const
2008 return objmgr
.GetNpcVendorItemList(GetEntry());
2011 uint32
Creature::GetVendorItemCurrentCount(VendorItem
const* vItem
)
2013 if(!vItem
->maxcount
)
2014 return vItem
->maxcount
;
2016 VendorItemCounts::iterator itr
= m_vendorItemCounts
.begin();
2017 for(; itr
!= m_vendorItemCounts
.end(); ++itr
)
2018 if(itr
->itemId
==vItem
->item
)
2021 if(itr
== m_vendorItemCounts
.end())
2022 return vItem
->maxcount
;
2024 VendorItemCount
* vCount
= &*itr
;
2026 time_t ptime
= time(NULL
);
2028 if( vCount
->lastIncrementTime
+ vItem
->incrtime
<= ptime
)
2030 ItemPrototype
const* pProto
= objmgr
.GetItemPrototype(vItem
->item
);
2032 uint32 diff
= uint32((ptime
- vCount
->lastIncrementTime
)/vItem
->incrtime
);
2033 if((vCount
->count
+ diff
* pProto
->BuyCount
) >= vItem
->maxcount
)
2035 m_vendorItemCounts
.erase(itr
);
2036 return vItem
->maxcount
;
2039 vCount
->count
+= diff
* pProto
->BuyCount
;
2040 vCount
->lastIncrementTime
= ptime
;
2043 return vCount
->count
;
2046 uint32
Creature::UpdateVendorItemCurrentCount(VendorItem
const* vItem
, uint32 used_count
)
2048 if(!vItem
->maxcount
)
2051 VendorItemCounts::iterator itr
= m_vendorItemCounts
.begin();
2052 for(; itr
!= m_vendorItemCounts
.end(); ++itr
)
2053 if(itr
->itemId
==vItem
->item
)
2056 if(itr
== m_vendorItemCounts
.end())
2058 uint32 new_count
= vItem
->maxcount
> used_count
? vItem
->maxcount
-used_count
: 0;
2059 m_vendorItemCounts
.push_back(VendorItemCount(vItem
->item
,new_count
));
2063 VendorItemCount
* vCount
= &*itr
;
2065 time_t ptime
= time(NULL
);
2067 if( vCount
->lastIncrementTime
+ vItem
->incrtime
<= ptime
)
2069 ItemPrototype
const* pProto
= objmgr
.GetItemPrototype(vItem
->item
);
2071 uint32 diff
= uint32((ptime
- vCount
->lastIncrementTime
)/vItem
->incrtime
);
2072 if((vCount
->count
+ diff
* pProto
->BuyCount
) < vItem
->maxcount
)
2073 vCount
->count
+= diff
* pProto
->BuyCount
;
2075 vCount
->count
= vItem
->maxcount
;
2078 vCount
->count
= vCount
->count
> used_count
? vCount
->count
-used_count
: 0;
2079 vCount
->lastIncrementTime
= ptime
;
2080 return vCount
->count
;
2083 TrainerSpellData
const* Creature::GetTrainerSpells() const
2085 return objmgr
.GetNpcTrainerSpells(GetEntry());
2088 // overwrite WorldObject function for proper name localization
2089 const char* Creature::GetNameForLocaleIdx(int32 loc_idx
) const
2093 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale(GetEntry());
2096 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty())
2097 return cl
->Name
[loc_idx
].c_str();