[37] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[37] | 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[161] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[37] | 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[161] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[37] | 19 | */ |
---|
| 20 | |
---|
| 21 | #include "Common.h" |
---|
| 22 | #include "Database/DatabaseEnv.h" |
---|
| 23 | #include "WorldPacket.h" |
---|
| 24 | #include "WorldSession.h" |
---|
| 25 | #include "World.h" |
---|
| 26 | #include "ObjectMgr.h" |
---|
| 27 | #include "SpellMgr.h" |
---|
| 28 | #include "Creature.h" |
---|
| 29 | #include "QuestDef.h" |
---|
| 30 | #include "GossipDef.h" |
---|
| 31 | #include "Player.h" |
---|
| 32 | #include "Opcodes.h" |
---|
| 33 | #include "Log.h" |
---|
| 34 | #include "LootMgr.h" |
---|
| 35 | #include "MapManager.h" |
---|
| 36 | #include "CreatureAI.h" |
---|
| 37 | #include "CreatureAISelector.h" |
---|
| 38 | #include "Formulas.h" |
---|
| 39 | #include "SpellAuras.h" |
---|
| 40 | #include "WaypointMovementGenerator.h" |
---|
| 41 | #include "InstanceData.h" |
---|
| 42 | #include "BattleGround.h" |
---|
| 43 | #include "Util.h" |
---|
| 44 | #include "GridNotifiers.h" |
---|
| 45 | #include "GridNotifiersImpl.h" |
---|
| 46 | #include "CellImpl.h" |
---|
[44] | 47 | #include "OutdoorPvPMgr.h" |
---|
| 48 | #include "GameEvent.h" |
---|
[174] | 49 | #include "PossessedAI.h" |
---|
[37] | 50 | // apply implementation of the singletons |
---|
| 51 | #include "Policies/SingletonImp.h" |
---|
| 52 | |
---|
| 53 | void TrainerSpellData::Clear() |
---|
| 54 | { |
---|
| 55 | for (TrainerSpellList::iterator itr = spellList.begin(); itr != spellList.end(); ++itr) |
---|
| 56 | delete (*itr); |
---|
| 57 | spellList.empty(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const |
---|
| 61 | { |
---|
| 62 | for(TrainerSpellList::const_iterator itr = spellList.begin(); itr != spellList.end(); ++itr) |
---|
| 63 | if((*itr)->spell == spell_id) |
---|
| 64 | return *itr; |
---|
| 65 | |
---|
| 66 | return NULL; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | bool VendorItemData::RemoveItem( uint32 item_id ) |
---|
| 70 | { |
---|
| 71 | for(VendorItemList::iterator i = m_items.begin(); i != m_items.end(); ++i ) |
---|
| 72 | { |
---|
| 73 | if((*i)->item==item_id) |
---|
| 74 | { |
---|
| 75 | m_items.erase(i); |
---|
| 76 | return true; |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | return false; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | size_t VendorItemData::FindItemSlot(uint32 item_id) const |
---|
| 83 | { |
---|
| 84 | for(size_t i = 0; i < m_items.size(); ++i ) |
---|
| 85 | if(m_items[i]->item==item_id) |
---|
| 86 | return i; |
---|
| 87 | return m_items.size(); |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | VendorItem const* VendorItemData::FindItem(uint32 item_id) const |
---|
| 91 | { |
---|
| 92 | for(VendorItemList::const_iterator i = m_items.begin(); i != m_items.end(); ++i ) |
---|
| 93 | if((*i)->item==item_id) |
---|
| 94 | return *i; |
---|
| 95 | return NULL; |
---|
| 96 | } |
---|
| 97 | |
---|
[123] | 98 | uint32 CreatureInfo::GetRandomValidModelId() const |
---|
| 99 | { |
---|
| 100 | uint32 c = 0; |
---|
| 101 | uint32 modelIDs[4]; |
---|
| 102 | |
---|
| 103 | if (Modelid1) modelIDs[c++] = Modelid1; |
---|
| 104 | if (Modelid2) modelIDs[c++] = Modelid2; |
---|
| 105 | if (Modelid3) modelIDs[c++] = Modelid3; |
---|
| 106 | if (Modelid4) modelIDs[c++] = Modelid4; |
---|
| 107 | |
---|
| 108 | return ((c>0) ? modelIDs[urand(0,c-1)] : 0); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | uint32 CreatureInfo::GetFirstValidModelId() const |
---|
| 112 | { |
---|
| 113 | if(Modelid1) return Modelid1; |
---|
| 114 | if(Modelid2) return Modelid2; |
---|
| 115 | if(Modelid3) return Modelid3; |
---|
| 116 | if(Modelid4) return Modelid4; |
---|
| 117 | return 0; |
---|
| 118 | } |
---|
| 119 | |
---|
[37] | 120 | Creature::Creature() : |
---|
[174] | 121 | Unit(), i_AI(NULL), i_AI_possessed(NULL), |
---|
[37] | 122 | lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0), |
---|
| 123 | m_lootMoney(0), m_lootRecipient(0), |
---|
| 124 | m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f), |
---|
[161] | 125 | m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false), |
---|
[37] | 126 | m_regenTimer(2000), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0), |
---|
| 127 | m_AlreadyCallAssistence(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), |
---|
| 128 | m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),m_creatureInfo(NULL), m_DBTableGuid(0) |
---|
| 129 | { |
---|
| 130 | m_valuesCount = UNIT_END; |
---|
| 131 | |
---|
| 132 | for(int i =0; i<4; ++i) |
---|
| 133 | m_spells[i] = 0; |
---|
| 134 | |
---|
| 135 | m_CreatureSpellCooldowns.clear(); |
---|
| 136 | m_CreatureCategoryCooldowns.clear(); |
---|
| 137 | m_GlobalCooldown = 0; |
---|
| 138 | m_unit_movement_flags = MOVEMENTFLAG_WALK_MODE; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | Creature::~Creature() |
---|
| 142 | { |
---|
| 143 | CleanupsBeforeDelete(); |
---|
| 144 | |
---|
| 145 | m_vendorItemCounts.clear(); |
---|
| 146 | |
---|
| 147 | delete i_AI; |
---|
| 148 | i_AI = NULL; |
---|
[174] | 149 | |
---|
| 150 | DeletePossessedAI(); |
---|
[37] | 151 | } |
---|
| 152 | |
---|
| 153 | void Creature::AddToWorld() |
---|
| 154 | { |
---|
| 155 | ///- Register the creature for guid lookup |
---|
| 156 | if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); |
---|
| 157 | Unit::AddToWorld(); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | void Creature::RemoveFromWorld() |
---|
| 161 | { |
---|
| 162 | ///- Remove the creature from the accessor |
---|
| 163 | if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); |
---|
| 164 | Unit::RemoveFromWorld(); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | void Creature::RemoveCorpse() |
---|
| 168 | { |
---|
| 169 | if( getDeathState()!=CORPSE && !m_isDeadByDefault || getDeathState()!=ALIVE && m_isDeadByDefault ) |
---|
| 170 | return; |
---|
| 171 | |
---|
| 172 | m_deathTimer = 0; |
---|
| 173 | setDeathState(DEAD); |
---|
| 174 | ObjectAccessor::UpdateObjectVisibility(this); |
---|
| 175 | loot.clear(); |
---|
| 176 | m_respawnTime = time(NULL) + m_respawnDelay; |
---|
| 177 | |
---|
| 178 | float x,y,z,o; |
---|
| 179 | GetRespawnCoord(x, y, z, &o); |
---|
| 180 | MapManager::Instance().GetMap(GetMapId(), this)->CreatureRelocation(this,x,y,z,o); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | /** |
---|
| 184 | * change the entry of creature until respawn |
---|
| 185 | */ |
---|
| 186 | bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data ) |
---|
| 187 | { |
---|
| 188 | CreatureInfo const *normalInfo = objmgr.GetCreatureTemplate(Entry); |
---|
| 189 | if(!normalInfo) |
---|
| 190 | { |
---|
| 191 | sLog.outErrorDb("Creature::UpdateEntry creature entry %u does not exist.", Entry); |
---|
| 192 | return false; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | // get heroic mode entry |
---|
| 196 | uint32 actualEntry = Entry; |
---|
| 197 | CreatureInfo const *cinfo = normalInfo; |
---|
| 198 | if(normalInfo->HeroicEntry) |
---|
| 199 | { |
---|
| 200 | Map *map = MapManager::Instance().FindMap(GetMapId(), GetInstanceId()); |
---|
| 201 | if(map && map->IsHeroic()) |
---|
| 202 | { |
---|
| 203 | cinfo = objmgr.GetCreatureTemplate(normalInfo->HeroicEntry); |
---|
| 204 | if(!cinfo) |
---|
| 205 | { |
---|
| 206 | sLog.outErrorDb("Creature::UpdateEntry creature heroic entry %u does not exist.", actualEntry); |
---|
| 207 | return false; |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | SetUInt32Value(OBJECT_FIELD_ENTRY, Entry); // normal entry always |
---|
| 213 | m_creatureInfo = cinfo; // map mode related always |
---|
| 214 | |
---|
[123] | 215 | // Cancel load if no model defined |
---|
| 216 | if (!(cinfo->GetFirstValidModelId())) |
---|
[37] | 217 | { |
---|
[123] | 218 | sLog.outErrorDb("Creature (Entry: %u) has no model defined in table `creature_template`, can't load. ",Entry); |
---|
[37] | 219 | return false; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | uint32 display_id = objmgr.ChooseDisplayId(team, GetCreatureInfo(), data); |
---|
| 223 | CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(display_id); |
---|
| 224 | if (!minfo) |
---|
| 225 | { |
---|
| 226 | sLog.outErrorDb("Creature (Entry: %u) has model %u not found in table `creature_model_info`, can't load. ", Entry, display_id); |
---|
| 227 | return false; |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | display_id = minfo->modelid; // it can be different (for another gender) |
---|
| 231 | |
---|
| 232 | SetDisplayId(display_id); |
---|
| 233 | SetNativeDisplayId(display_id); |
---|
| 234 | SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender); |
---|
| 235 | |
---|
| 236 | // Load creature equipment |
---|
| 237 | if(!data || data->equipmentId == 0) |
---|
| 238 | { // use default from the template |
---|
| 239 | LoadEquipment(cinfo->equipmentId); |
---|
| 240 | } |
---|
| 241 | else if(data && data->equipmentId != -1) |
---|
| 242 | { // override, -1 means no equipment |
---|
| 243 | LoadEquipment(data->equipmentId); |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | SetName(normalInfo->Name); // at normal entry always |
---|
| 247 | |
---|
| 248 | SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS,minfo->bounding_radius); |
---|
| 249 | SetFloatValue(UNIT_FIELD_COMBATREACH,minfo->combat_reach ); |
---|
| 250 | |
---|
| 251 | SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f); |
---|
| 252 | |
---|
| 253 | SetSpeed(MOVE_WALK, cinfo->speed ); |
---|
| 254 | SetSpeed(MOVE_RUN, cinfo->speed ); |
---|
| 255 | SetSpeed(MOVE_SWIM, cinfo->speed ); |
---|
| 256 | |
---|
| 257 | SetFloatValue(OBJECT_FIELD_SCALE_X, cinfo->scale); |
---|
| 258 | |
---|
| 259 | // checked at loading |
---|
| 260 | m_defaultMovementType = MovementGeneratorType(cinfo->MovementType); |
---|
| 261 | if(!m_respawnradius && m_defaultMovementType==RANDOM_MOTION_TYPE) |
---|
| 262 | m_defaultMovementType = IDLE_MOTION_TYPE; |
---|
| 263 | |
---|
| 264 | return true; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data ) |
---|
| 268 | { |
---|
| 269 | if(!InitEntry(Entry,team,data)) |
---|
| 270 | return false; |
---|
| 271 | |
---|
| 272 | m_regenHealth = GetCreatureInfo()->RegenHealth; |
---|
| 273 | |
---|
| 274 | // creatures always have melee weapon ready if any |
---|
| 275 | SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); |
---|
| 276 | SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_AURAS ); |
---|
| 277 | |
---|
| 278 | SelectLevel(GetCreatureInfo()); |
---|
| 279 | if (team == HORDE) |
---|
| 280 | SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, GetCreatureInfo()->faction_H); |
---|
| 281 | else |
---|
| 282 | SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, GetCreatureInfo()->faction_A); |
---|
| 283 | |
---|
[44] | 284 | if(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_WORLDEVENT) |
---|
| 285 | SetUInt32Value(UNIT_NPC_FLAGS,GetCreatureInfo()->npcflag | gameeventmgr.GetNPCFlag(this)); |
---|
| 286 | else |
---|
| 287 | SetUInt32Value(UNIT_NPC_FLAGS,GetCreatureInfo()->npcflag); |
---|
[37] | 288 | |
---|
| 289 | SetAttackTime(BASE_ATTACK, GetCreatureInfo()->baseattacktime); |
---|
| 290 | SetAttackTime(OFF_ATTACK, GetCreatureInfo()->baseattacktime); |
---|
| 291 | SetAttackTime(RANGED_ATTACK,GetCreatureInfo()->rangeattacktime); |
---|
| 292 | |
---|
[168] | 293 | SetUInt32Value(UNIT_FIELD_FLAGS,GetCreatureInfo()->unit_flags); |
---|
[37] | 294 | SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags); |
---|
| 295 | |
---|
| 296 | SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor)); |
---|
| 297 | SetModifierValue(UNIT_MOD_RESISTANCE_HOLY, BASE_VALUE, float(GetCreatureInfo()->resistance1)); |
---|
| 298 | SetModifierValue(UNIT_MOD_RESISTANCE_FIRE, BASE_VALUE, float(GetCreatureInfo()->resistance2)); |
---|
| 299 | SetModifierValue(UNIT_MOD_RESISTANCE_NATURE, BASE_VALUE, float(GetCreatureInfo()->resistance3)); |
---|
| 300 | SetModifierValue(UNIT_MOD_RESISTANCE_FROST, BASE_VALUE, float(GetCreatureInfo()->resistance4)); |
---|
| 301 | SetModifierValue(UNIT_MOD_RESISTANCE_SHADOW, BASE_VALUE, float(GetCreatureInfo()->resistance5)); |
---|
| 302 | SetModifierValue(UNIT_MOD_RESISTANCE_ARCANE, BASE_VALUE, float(GetCreatureInfo()->resistance6)); |
---|
| 303 | |
---|
| 304 | SetCanModifyStats(true); |
---|
| 305 | UpdateAllStats(); |
---|
| 306 | |
---|
| 307 | FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(GetCreatureInfo()->faction_A); |
---|
| 308 | if (factionTemplate) // check and error show at loading templates |
---|
| 309 | { |
---|
| 310 | FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionTemplate->faction); |
---|
| 311 | if (factionEntry) |
---|
| 312 | if( !(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN) && |
---|
| 313 | (factionEntry->team == ALLIANCE || factionEntry->team == HORDE) ) |
---|
| 314 | SetPvP(true); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | m_spells[0] = GetCreatureInfo()->spell1; |
---|
| 318 | m_spells[1] = GetCreatureInfo()->spell2; |
---|
| 319 | m_spells[2] = GetCreatureInfo()->spell3; |
---|
| 320 | m_spells[3] = GetCreatureInfo()->spell4; |
---|
| 321 | |
---|
| 322 | return true; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | void Creature::Update(uint32 diff) |
---|
| 326 | { |
---|
| 327 | if(m_GlobalCooldown <= diff) |
---|
| 328 | m_GlobalCooldown = 0; |
---|
| 329 | else |
---|
| 330 | m_GlobalCooldown -= diff; |
---|
| 331 | |
---|
| 332 | switch( m_deathState ) |
---|
| 333 | { |
---|
| 334 | case JUST_ALIVED: |
---|
| 335 | // Dont must be called, see Creature::setDeathState JUST_ALIVED -> ALIVE promoting. |
---|
| 336 | sLog.outError("Creature (GUIDLow: %u Entry: %u ) in wrong state: JUST_ALIVED (4)",GetGUIDLow(),GetEntry()); |
---|
| 337 | break; |
---|
| 338 | case JUST_DIED: |
---|
| 339 | // Dont must be called, see Creature::setDeathState JUST_DIED -> CORPSE promoting. |
---|
| 340 | sLog.outError("Creature (GUIDLow: %u Entry: %u ) in wrong state: JUST_DEAD (1)",GetGUIDLow(),GetEntry()); |
---|
| 341 | break; |
---|
| 342 | case DEAD: |
---|
| 343 | { |
---|
| 344 | if( m_respawnTime <= time(NULL) ) |
---|
| 345 | { |
---|
| 346 | DEBUG_LOG("Respawning..."); |
---|
| 347 | m_respawnTime = 0; |
---|
| 348 | lootForPickPocketed = false; |
---|
| 349 | lootForBody = false; |
---|
| 350 | |
---|
| 351 | if(m_originalEntry != GetUInt32Value(OBJECT_FIELD_ENTRY)) |
---|
| 352 | UpdateEntry(m_originalEntry); |
---|
| 353 | |
---|
| 354 | CreatureInfo const *cinfo = GetCreatureInfo(); |
---|
| 355 | |
---|
| 356 | SelectLevel(cinfo); |
---|
| 357 | SetUInt32Value(UNIT_DYNAMIC_FLAGS, 0); |
---|
| 358 | if (m_isDeadByDefault) |
---|
| 359 | { |
---|
| 360 | setDeathState(JUST_DIED); |
---|
| 361 | SetHealth(0); |
---|
| 362 | i_motionMaster.Clear(); |
---|
| 363 | clearUnitState(UNIT_STAT_ALL_STATE); |
---|
| 364 | LoadCreaturesAddon(true); |
---|
| 365 | } |
---|
| 366 | else |
---|
| 367 | setDeathState( JUST_ALIVED ); |
---|
| 368 | |
---|
| 369 | //Call AI respawn virtual function |
---|
[174] | 370 | AI()->JustRespawned(); |
---|
[37] | 371 | |
---|
| 372 | MapManager::Instance().GetMap(GetMapId(), this)->Add(this); |
---|
| 373 | } |
---|
| 374 | break; |
---|
| 375 | } |
---|
| 376 | case CORPSE: |
---|
| 377 | { |
---|
| 378 | if (m_isDeadByDefault) |
---|
| 379 | break; |
---|
| 380 | |
---|
| 381 | if( m_deathTimer <= diff ) |
---|
| 382 | { |
---|
| 383 | RemoveCorpse(); |
---|
| 384 | DEBUG_LOG("Removing corpse... %u ", GetUInt32Value(OBJECT_FIELD_ENTRY)); |
---|
| 385 | } |
---|
| 386 | else |
---|
| 387 | { |
---|
| 388 | m_deathTimer -= diff; |
---|
| 389 | if (m_groupLootTimer && lootingGroupLeaderGUID) |
---|
| 390 | { |
---|
| 391 | if(diff <= m_groupLootTimer) |
---|
| 392 | { |
---|
| 393 | m_groupLootTimer -= diff; |
---|
| 394 | } |
---|
| 395 | else |
---|
| 396 | { |
---|
| 397 | Group* group = objmgr.GetGroupByLeader(lootingGroupLeaderGUID); |
---|
| 398 | if (group) |
---|
| 399 | group->EndRoll(); |
---|
| 400 | m_groupLootTimer = 0; |
---|
| 401 | lootingGroupLeaderGUID = 0; |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | break; |
---|
| 407 | } |
---|
| 408 | case ALIVE: |
---|
| 409 | { |
---|
| 410 | if (m_isDeadByDefault) |
---|
| 411 | { |
---|
| 412 | if( m_deathTimer <= diff ) |
---|
| 413 | { |
---|
| 414 | RemoveCorpse(); |
---|
| 415 | DEBUG_LOG("Removing alive corpse... %u ", GetUInt32Value(OBJECT_FIELD_ENTRY)); |
---|
| 416 | } |
---|
| 417 | else |
---|
| 418 | { |
---|
| 419 | m_deathTimer -= diff; |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | Unit::Update( diff ); |
---|
| 424 | |
---|
| 425 | // creature can be dead after Unit::Update call |
---|
| 426 | // CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly) |
---|
| 427 | if(!isAlive()) |
---|
| 428 | break; |
---|
| 429 | |
---|
| 430 | if(!IsInEvadeMode()) |
---|
| 431 | { |
---|
| 432 | // do not allow the AI to be changed during update |
---|
| 433 | m_AI_locked = true; |
---|
[174] | 434 | AI()->UpdateAI(diff); |
---|
[37] | 435 | m_AI_locked = false; |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | // creature can be dead after UpdateAI call |
---|
| 439 | // CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly) |
---|
| 440 | if(!isAlive()) |
---|
| 441 | break; |
---|
| 442 | if(m_regenTimer > 0) |
---|
| 443 | { |
---|
| 444 | if(diff >= m_regenTimer) |
---|
| 445 | m_regenTimer = 0; |
---|
| 446 | else |
---|
| 447 | m_regenTimer -= diff; |
---|
| 448 | } |
---|
| 449 | if (m_regenTimer != 0) |
---|
| 450 | break; |
---|
| 451 | |
---|
| 452 | if (!isInCombat() || IsPolymorphed()) |
---|
| 453 | RegenerateHealth(); |
---|
| 454 | |
---|
| 455 | RegenerateMana(); |
---|
| 456 | |
---|
| 457 | m_regenTimer = 2000; |
---|
| 458 | break; |
---|
| 459 | } |
---|
| 460 | default: |
---|
| 461 | break; |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | void Creature::RegenerateMana() |
---|
| 466 | { |
---|
| 467 | uint32 curValue = GetPower(POWER_MANA); |
---|
| 468 | uint32 maxValue = GetMaxPower(POWER_MANA); |
---|
| 469 | |
---|
| 470 | if (curValue >= maxValue) |
---|
| 471 | return; |
---|
| 472 | |
---|
| 473 | uint32 addvalue = 0; |
---|
| 474 | |
---|
| 475 | // Combat and any controlled creature |
---|
| 476 | if (isInCombat() || GetCharmerOrOwnerGUID()) |
---|
| 477 | { |
---|
| 478 | if(!IsUnderLastManaUseEffect()) |
---|
| 479 | { |
---|
| 480 | float ManaIncreaseRate = sWorld.getRate(RATE_POWER_MANA); |
---|
| 481 | float Spirit = GetStat(STAT_SPIRIT); |
---|
| 482 | |
---|
| 483 | addvalue = uint32((Spirit/5.0f + 17.0f) * ManaIncreaseRate); |
---|
| 484 | } |
---|
| 485 | } |
---|
| 486 | else |
---|
| 487 | addvalue = maxValue/3; |
---|
| 488 | |
---|
| 489 | ModifyPower(POWER_MANA, addvalue); |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | void Creature::RegenerateHealth() |
---|
| 493 | { |
---|
| 494 | if (!isRegeneratingHealth()) |
---|
| 495 | return; |
---|
| 496 | |
---|
| 497 | uint32 curValue = GetHealth(); |
---|
| 498 | uint32 maxValue = GetMaxHealth(); |
---|
| 499 | |
---|
| 500 | if (curValue >= maxValue) |
---|
| 501 | return; |
---|
| 502 | |
---|
| 503 | uint32 addvalue = 0; |
---|
| 504 | |
---|
| 505 | // Not only pet, but any controelled creature |
---|
| 506 | if(GetCharmerOrOwnerGUID()) |
---|
| 507 | { |
---|
| 508 | float HealthIncreaseRate = sWorld.getRate(RATE_HEALTH); |
---|
| 509 | float Spirit = GetStat(STAT_SPIRIT); |
---|
| 510 | |
---|
| 511 | if( GetPower(POWER_MANA) > 0 ) |
---|
| 512 | addvalue = uint32(Spirit * 0.25 * HealthIncreaseRate); |
---|
| 513 | else |
---|
| 514 | addvalue = uint32(Spirit * 0.80 * HealthIncreaseRate); |
---|
| 515 | } |
---|
| 516 | else |
---|
| 517 | addvalue = maxValue/3; |
---|
| 518 | |
---|
| 519 | ModifyHealth(addvalue); |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | bool Creature::AIM_Initialize() |
---|
| 523 | { |
---|
| 524 | // make sure nothing can change the AI during AI update |
---|
| 525 | if(m_AI_locked) |
---|
| 526 | { |
---|
| 527 | sLog.outDebug("AIM_Initialize: failed to init, locked."); |
---|
| 528 | return false; |
---|
| 529 | } |
---|
| 530 | |
---|
[174] | 531 | // don't allow AI switch when possessed |
---|
| 532 | if (isPossessed()) |
---|
| 533 | return false; |
---|
| 534 | |
---|
[37] | 535 | CreatureAI * oldAI = i_AI; |
---|
| 536 | i_motionMaster.Initialize(); |
---|
| 537 | i_AI = FactorySelector::selectAI(this); |
---|
| 538 | if (oldAI) |
---|
| 539 | delete oldAI; |
---|
| 540 | return true; |
---|
| 541 | } |
---|
| 542 | |
---|
[174] | 543 | void Creature::InitPossessedAI() |
---|
| 544 | { |
---|
| 545 | if (!isPossessed()) return; |
---|
| 546 | |
---|
| 547 | if (!i_AI_possessed) |
---|
| 548 | i_AI_possessed = new PossessedAI(*this); |
---|
| 549 | |
---|
| 550 | // Signal the old AI that it's been disabled |
---|
| 551 | i_AI->OnPossess(true); |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | void Creature::DeletePossessedAI() |
---|
| 555 | { |
---|
| 556 | if (!i_AI_possessed) return; |
---|
| 557 | |
---|
| 558 | delete i_AI_possessed; |
---|
| 559 | i_AI_possessed = NULL; |
---|
| 560 | |
---|
| 561 | // Signal the old AI that it's been re-enabled |
---|
| 562 | i_AI->OnPossess(false); |
---|
| 563 | } |
---|
| 564 | |
---|
[37] | 565 | bool Creature::Create (uint32 guidlow, Map *map, uint32 Entry, uint32 team, const CreatureData *data) |
---|
| 566 | { |
---|
| 567 | SetMapId(map->GetId()); |
---|
| 568 | SetInstanceId(map->GetInstanceId()); |
---|
| 569 | |
---|
| 570 | //oX = x; oY = y; dX = x; dY = y; m_moveTime = 0; m_startMove = 0; |
---|
| 571 | const bool bResult = CreateFromProto(guidlow, Entry, team, data); |
---|
| 572 | |
---|
| 573 | if (bResult) |
---|
| 574 | { |
---|
| 575 | switch (GetCreatureInfo()->rank) |
---|
| 576 | { |
---|
| 577 | case CREATURE_ELITE_RARE: |
---|
| 578 | m_corpseDelay = sWorld.getConfig(CONFIG_CORPSE_DECAY_RARE); |
---|
| 579 | break; |
---|
| 580 | case CREATURE_ELITE_ELITE: |
---|
| 581 | m_corpseDelay = sWorld.getConfig(CONFIG_CORPSE_DECAY_ELITE); |
---|
| 582 | break; |
---|
| 583 | case CREATURE_ELITE_RAREELITE: |
---|
| 584 | m_corpseDelay = sWorld.getConfig(CONFIG_CORPSE_DECAY_RAREELITE); |
---|
| 585 | break; |
---|
| 586 | case CREATURE_ELITE_WORLDBOSS: |
---|
| 587 | m_corpseDelay = sWorld.getConfig(CONFIG_CORPSE_DECAY_WORLDBOSS); |
---|
| 588 | break; |
---|
| 589 | default: |
---|
| 590 | m_corpseDelay = sWorld.getConfig(CONFIG_CORPSE_DECAY_NORMAL); |
---|
| 591 | break; |
---|
| 592 | } |
---|
| 593 | LoadCreaturesAddon(); |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | return bResult; |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | bool Creature::isCanTrainingOf(Player* pPlayer, bool msg) const |
---|
| 600 | { |
---|
| 601 | if(!isTrainer()) |
---|
| 602 | return false; |
---|
| 603 | |
---|
| 604 | TrainerSpellData const* trainer_spells = GetTrainerSpells(); |
---|
| 605 | |
---|
| 606 | if(!trainer_spells || trainer_spells->spellList.empty()) |
---|
| 607 | { |
---|
| 608 | sLog.outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_TRAINER but have empty trainer spell list.", |
---|
| 609 | GetGUIDLow(),GetEntry()); |
---|
| 610 | return false; |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | switch(GetCreatureInfo()->trainer_type) |
---|
| 614 | { |
---|
| 615 | case TRAINER_TYPE_CLASS: |
---|
| 616 | if(pPlayer->getClass()!=GetCreatureInfo()->classNum) |
---|
| 617 | { |
---|
| 618 | if(msg) |
---|
| 619 | { |
---|
| 620 | pPlayer->PlayerTalkClass->ClearMenus(); |
---|
| 621 | switch(GetCreatureInfo()->classNum) |
---|
| 622 | { |
---|
| 623 | case CLASS_DRUID: pPlayer->PlayerTalkClass->SendGossipMenu( 4913,GetGUID()); break; |
---|
| 624 | case CLASS_HUNTER: pPlayer->PlayerTalkClass->SendGossipMenu(10090,GetGUID()); break; |
---|
| 625 | case CLASS_MAGE: pPlayer->PlayerTalkClass->SendGossipMenu( 328,GetGUID()); break; |
---|
| 626 | case CLASS_PALADIN:pPlayer->PlayerTalkClass->SendGossipMenu( 1635,GetGUID()); break; |
---|
| 627 | case CLASS_PRIEST: pPlayer->PlayerTalkClass->SendGossipMenu( 4436,GetGUID()); break; |
---|
| 628 | case CLASS_ROGUE: pPlayer->PlayerTalkClass->SendGossipMenu( 4797,GetGUID()); break; |
---|
| 629 | case CLASS_SHAMAN: pPlayer->PlayerTalkClass->SendGossipMenu( 5003,GetGUID()); break; |
---|
| 630 | case CLASS_WARLOCK:pPlayer->PlayerTalkClass->SendGossipMenu( 5836,GetGUID()); break; |
---|
| 631 | case CLASS_WARRIOR:pPlayer->PlayerTalkClass->SendGossipMenu( 4985,GetGUID()); break; |
---|
| 632 | } |
---|
| 633 | } |
---|
| 634 | return false; |
---|
| 635 | } |
---|
| 636 | break; |
---|
| 637 | case TRAINER_TYPE_PETS: |
---|
| 638 | if(pPlayer->getClass()!=CLASS_HUNTER) |
---|
| 639 | { |
---|
| 640 | pPlayer->PlayerTalkClass->ClearMenus(); |
---|
| 641 | pPlayer->PlayerTalkClass->SendGossipMenu(3620,GetGUID()); |
---|
| 642 | return false; |
---|
| 643 | } |
---|
| 644 | break; |
---|
| 645 | case TRAINER_TYPE_MOUNTS: |
---|
| 646 | if(GetCreatureInfo()->race && pPlayer->getRace() != GetCreatureInfo()->race) |
---|
| 647 | { |
---|
| 648 | if(msg) |
---|
| 649 | { |
---|
| 650 | pPlayer->PlayerTalkClass->ClearMenus(); |
---|
| 651 | switch(GetCreatureInfo()->classNum) |
---|
| 652 | { |
---|
| 653 | case RACE_DWARF: pPlayer->PlayerTalkClass->SendGossipMenu(5865,GetGUID()); break; |
---|
| 654 | case RACE_GNOME: pPlayer->PlayerTalkClass->SendGossipMenu(4881,GetGUID()); break; |
---|
| 655 | case RACE_HUMAN: pPlayer->PlayerTalkClass->SendGossipMenu(5861,GetGUID()); break; |
---|
| 656 | case RACE_NIGHTELF: pPlayer->PlayerTalkClass->SendGossipMenu(5862,GetGUID()); break; |
---|
| 657 | case RACE_ORC: pPlayer->PlayerTalkClass->SendGossipMenu(5863,GetGUID()); break; |
---|
| 658 | case RACE_TAUREN: pPlayer->PlayerTalkClass->SendGossipMenu(5864,GetGUID()); break; |
---|
| 659 | case RACE_TROLL: pPlayer->PlayerTalkClass->SendGossipMenu(5816,GetGUID()); break; |
---|
| 660 | case RACE_UNDEAD_PLAYER:pPlayer->PlayerTalkClass->SendGossipMenu( 624,GetGUID()); break; |
---|
| 661 | case RACE_BLOODELF: pPlayer->PlayerTalkClass->SendGossipMenu(5862,GetGUID()); break; |
---|
| 662 | case RACE_DRAENEI: pPlayer->PlayerTalkClass->SendGossipMenu(5864,GetGUID()); break; |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | return false; |
---|
| 666 | } |
---|
| 667 | break; |
---|
| 668 | case TRAINER_TYPE_TRADESKILLS: |
---|
| 669 | if(GetCreatureInfo()->trainer_spell && !pPlayer->HasSpell(GetCreatureInfo()->trainer_spell)) |
---|
| 670 | { |
---|
| 671 | if(msg) |
---|
| 672 | { |
---|
| 673 | pPlayer->PlayerTalkClass->ClearMenus(); |
---|
| 674 | pPlayer->PlayerTalkClass->SendGossipMenu(11031,GetGUID()); |
---|
| 675 | } |
---|
| 676 | return false; |
---|
| 677 | } |
---|
| 678 | break; |
---|
| 679 | default: |
---|
| 680 | return false; // checked and error output at creature_template loading |
---|
| 681 | } |
---|
| 682 | return true; |
---|
| 683 | } |
---|
| 684 | |
---|
| 685 | bool Creature::isCanIneractWithBattleMaster(Player* pPlayer, bool msg) const |
---|
| 686 | { |
---|
| 687 | if(!isBattleMaster()) |
---|
| 688 | return false; |
---|
| 689 | |
---|
| 690 | uint32 bgTypeId = objmgr.GetBattleMasterBG(GetEntry()); |
---|
| 691 | if(!msg) |
---|
| 692 | return pPlayer->GetBGAccessByLevel(bgTypeId); |
---|
| 693 | |
---|
| 694 | if(!pPlayer->GetBGAccessByLevel(bgTypeId)) |
---|
| 695 | { |
---|
| 696 | pPlayer->PlayerTalkClass->ClearMenus(); |
---|
| 697 | switch(bgTypeId) |
---|
| 698 | { |
---|
| 699 | case BATTLEGROUND_AV: pPlayer->PlayerTalkClass->SendGossipMenu(7616,GetGUID()); break; |
---|
| 700 | case BATTLEGROUND_WS: pPlayer->PlayerTalkClass->SendGossipMenu(7599,GetGUID()); break; |
---|
| 701 | case BATTLEGROUND_AB: pPlayer->PlayerTalkClass->SendGossipMenu(7642,GetGUID()); break; |
---|
| 702 | case BATTLEGROUND_EY: |
---|
| 703 | case BATTLEGROUND_NA: |
---|
| 704 | case BATTLEGROUND_BE: |
---|
| 705 | case BATTLEGROUND_AA: |
---|
| 706 | case BATTLEGROUND_RL: pPlayer->PlayerTalkClass->SendGossipMenu(10024,GetGUID()); break; |
---|
| 707 | break; |
---|
| 708 | } |
---|
| 709 | return false; |
---|
| 710 | } |
---|
| 711 | return true; |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | bool Creature::isCanTrainingAndResetTalentsOf(Player* pPlayer) const |
---|
| 715 | { |
---|
| 716 | return pPlayer->getLevel() >= 10 |
---|
| 717 | && GetCreatureInfo()->trainer_type == TRAINER_TYPE_CLASS |
---|
| 718 | && pPlayer->getClass() == GetCreatureInfo()->classNum; |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | void Creature::prepareGossipMenu( Player *pPlayer,uint32 gossipid ) |
---|
| 722 | { |
---|
| 723 | PlayerMenu* pm=pPlayer->PlayerTalkClass; |
---|
| 724 | pm->ClearMenus(); |
---|
| 725 | |
---|
| 726 | // lazy loading single time at use |
---|
| 727 | LoadGossipOptions(); |
---|
| 728 | |
---|
| 729 | for( GossipOptionList::iterator i = m_goptions.begin( ); i != m_goptions.end( ); i++ ) |
---|
| 730 | { |
---|
[168] | 731 | GossipOption* gso=&*i; |
---|
[37] | 732 | if(gso->GossipId == gossipid) |
---|
| 733 | { |
---|
| 734 | bool cantalking=true; |
---|
| 735 | if(gso->Id==1) |
---|
| 736 | { |
---|
| 737 | uint32 textid=GetNpcTextId(); |
---|
| 738 | GossipText * gossiptext=objmgr.GetGossipText(textid); |
---|
| 739 | if(!gossiptext) |
---|
| 740 | cantalking=false; |
---|
| 741 | } |
---|
| 742 | else |
---|
| 743 | { |
---|
| 744 | switch (gso->Action) |
---|
| 745 | { |
---|
| 746 | case GOSSIP_OPTION_QUESTGIVER: |
---|
| 747 | pPlayer->PrepareQuestMenu(GetGUID()); |
---|
| 748 | //if (pm->GetQuestMenu()->MenuItemCount() == 0) |
---|
| 749 | cantalking=false; |
---|
| 750 | //pm->GetQuestMenu()->ClearMenu(); |
---|
| 751 | break; |
---|
| 752 | case GOSSIP_OPTION_ARMORER: |
---|
| 753 | cantalking=false; // added in special mode |
---|
| 754 | break; |
---|
| 755 | case GOSSIP_OPTION_SPIRITHEALER: |
---|
| 756 | if( !pPlayer->isDead() ) |
---|
| 757 | cantalking=false; |
---|
| 758 | break; |
---|
| 759 | case GOSSIP_OPTION_VENDOR: |
---|
| 760 | { |
---|
| 761 | VendorItemData const* vItems = GetVendorItems(); |
---|
| 762 | if(!vItems || vItems->Empty()) |
---|
| 763 | { |
---|
| 764 | sLog.outErrorDb("Creature %u (Entry: %u) have UNIT_NPC_FLAG_VENDOR but have empty trading item list.", |
---|
| 765 | GetGUIDLow(),GetEntry()); |
---|
| 766 | cantalking=false; |
---|
| 767 | } |
---|
| 768 | break; |
---|
| 769 | } |
---|
| 770 | case GOSSIP_OPTION_TRAINER: |
---|
| 771 | if(!isCanTrainingOf(pPlayer,false)) |
---|
| 772 | cantalking=false; |
---|
| 773 | break; |
---|
| 774 | case GOSSIP_OPTION_UNLEARNTALENTS: |
---|
| 775 | if(!isCanTrainingAndResetTalentsOf(pPlayer)) |
---|
| 776 | cantalking=false; |
---|
| 777 | break; |
---|
| 778 | case GOSSIP_OPTION_UNLEARNPETSKILLS: |
---|
| 779 | if(!pPlayer->GetPet() || pPlayer->GetPet()->getPetType() != HUNTER_PET || pPlayer->GetPet()->m_spells.size() <= 1 || GetCreatureInfo()->trainer_type != TRAINER_TYPE_PETS || GetCreatureInfo()->classNum != CLASS_HUNTER) |
---|
| 780 | cantalking=false; |
---|
| 781 | break; |
---|
| 782 | case GOSSIP_OPTION_TAXIVENDOR: |
---|
| 783 | if ( pPlayer->GetSession()->SendLearnNewTaxiNode(this) ) |
---|
| 784 | return; |
---|
| 785 | break; |
---|
| 786 | case GOSSIP_OPTION_BATTLEFIELD: |
---|
| 787 | if(!isCanIneractWithBattleMaster(pPlayer,false)) |
---|
| 788 | cantalking=false; |
---|
| 789 | break; |
---|
| 790 | case GOSSIP_OPTION_SPIRITGUIDE: |
---|
| 791 | case GOSSIP_OPTION_INNKEEPER: |
---|
| 792 | case GOSSIP_OPTION_BANKER: |
---|
| 793 | case GOSSIP_OPTION_PETITIONER: |
---|
| 794 | case GOSSIP_OPTION_STABLEPET: |
---|
| 795 | case GOSSIP_OPTION_TABARDDESIGNER: |
---|
| 796 | case GOSSIP_OPTION_AUCTIONEER: |
---|
| 797 | break; // no checks |
---|
[44] | 798 | case GOSSIP_OPTION_OUTDOORPVP: |
---|
| 799 | if ( !sOutdoorPvPMgr.CanTalkTo(pPlayer,this,(*gso)) ) |
---|
| 800 | cantalking = false; |
---|
| 801 | break; |
---|
[37] | 802 | default: |
---|
[168] | 803 | sLog.outErrorDb("Creature %u (entry: %u) have unknown gossip option %u",GetDBTableGUIDLow(),GetEntry(),gso->Action); |
---|
[37] | 804 | break; |
---|
| 805 | } |
---|
| 806 | } |
---|
| 807 | |
---|
[168] | 808 | //note for future dev: should have database fields for BoxMessage & BoxMoney |
---|
| 809 | if(!gso->OptionText.empty() && cantalking) |
---|
| 810 | { |
---|
| 811 | std::string OptionText = gso->OptionText; |
---|
| 812 | std::string BoxText = gso->BoxText; |
---|
| 813 | int loc_idx = pPlayer->GetSession()->GetSessionDbLocaleIndex(); |
---|
| 814 | if (loc_idx >= 0) |
---|
| 815 | { |
---|
| 816 | NpcOptionLocale const *no = objmgr.GetNpcOptionLocale(gso->Id); |
---|
| 817 | if (no) |
---|
| 818 | { |
---|
| 819 | if (no->OptionText.size() > loc_idx && !no->OptionText[loc_idx].empty()) |
---|
| 820 | OptionText=no->OptionText[loc_idx]; |
---|
| 821 | if (no->BoxText.size() > loc_idx && !no->BoxText[loc_idx].empty()) |
---|
| 822 | BoxText=no->BoxText[loc_idx]; |
---|
| 823 | } |
---|
| 824 | } |
---|
| 825 | pm->GetGossipMenu().AddMenuItem((uint8)gso->Icon,OptionText, gossipid,gso->Action,BoxText,gso->BoxMoney,gso->Coded); |
---|
[37] | 826 | } |
---|
| 827 | } |
---|
| 828 | } |
---|
| 829 | |
---|
| 830 | ///some gossips aren't handled in normal way ... so we need to do it this way .. TODO: handle it in normal way ;-) |
---|
| 831 | if(pm->Empty()) |
---|
| 832 | { |
---|
| 833 | if(HasFlag(UNIT_NPC_FLAGS,UNIT_NPC_FLAG_TRAINER)) |
---|
| 834 | { |
---|
| 835 | isCanTrainingOf(pPlayer,true); // output error message if need |
---|
| 836 | } |
---|
| 837 | if(HasFlag(UNIT_NPC_FLAGS,UNIT_NPC_FLAG_BATTLEMASTER)) |
---|
| 838 | { |
---|
| 839 | isCanIneractWithBattleMaster(pPlayer,true); // output error message if need |
---|
| 840 | } |
---|
| 841 | } |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | void Creature::sendPreparedGossip(Player* player) |
---|
| 845 | { |
---|
| 846 | if(!player) |
---|
| 847 | return; |
---|
| 848 | |
---|
| 849 | GossipMenu& gossipmenu = player->PlayerTalkClass->GetGossipMenu(); |
---|
| 850 | |
---|
[44] | 851 | if(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_WORLDEVENT) // if world event npc then |
---|
| 852 | gameeventmgr.HandleWorldEventGossip(player, this); // update world state with progress |
---|
| 853 | |
---|
[37] | 854 | // in case empty gossip menu open quest menu if any |
---|
| 855 | if (gossipmenu.Empty() && GetNpcTextId() == 0) |
---|
| 856 | { |
---|
| 857 | player->SendPreparedQuest(GetGUID()); |
---|
| 858 | return; |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | // in case non empty gossip menu (that not included quests list size) show it |
---|
| 862 | // (quest entries from quest menu wiill be included in list) |
---|
| 863 | player->PlayerTalkClass->SendGossipMenu(GetNpcTextId(), GetGUID()); |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | void Creature::OnGossipSelect(Player* player, uint32 option) |
---|
| 867 | { |
---|
| 868 | GossipMenu& gossipmenu = player->PlayerTalkClass->GetGossipMenu(); |
---|
| 869 | |
---|
| 870 | if(option >= gossipmenu.MenuItemCount()) |
---|
| 871 | return; |
---|
| 872 | |
---|
| 873 | uint32 action=gossipmenu.GetItem(option).m_gAction; |
---|
| 874 | uint32 zoneid=GetZoneId(); |
---|
| 875 | uint64 guid=GetGUID(); |
---|
[161] | 876 | |
---|
[37] | 877 | GossipOption const *gossip=GetGossipOption( action ); |
---|
| 878 | if(!gossip) |
---|
| 879 | { |
---|
| 880 | zoneid=0; |
---|
| 881 | gossip=GetGossipOption( action ); |
---|
| 882 | if(!gossip) |
---|
| 883 | return; |
---|
| 884 | } |
---|
| 885 | |
---|
| 886 | switch (gossip->Action) |
---|
| 887 | { |
---|
| 888 | case GOSSIP_OPTION_GOSSIP: |
---|
[173] | 889 | { |
---|
| 890 | uint32 textid = GetGossipTextId(action, zoneid); |
---|
| 891 | if (textid == 0) |
---|
| 892 | textid=GetNpcTextId(); |
---|
| 893 | |
---|
[37] | 894 | player->PlayerTalkClass->CloseGossip(); |
---|
[161] | 895 | player->PlayerTalkClass->SendTalking(textid); |
---|
[37] | 896 | break; |
---|
[173] | 897 | } |
---|
[44] | 898 | case GOSSIP_OPTION_OUTDOORPVP: |
---|
| 899 | sOutdoorPvPMgr.HandleGossipOption(player, GetGUID(), option); |
---|
| 900 | break; |
---|
[37] | 901 | case GOSSIP_OPTION_SPIRITHEALER: |
---|
[161] | 902 | if (player->isDead()) |
---|
[37] | 903 | CastSpell(this,17251,true,NULL,NULL,player->GetGUID()); |
---|
| 904 | break; |
---|
| 905 | case GOSSIP_OPTION_QUESTGIVER: |
---|
| 906 | player->PrepareQuestMenu( guid ); |
---|
| 907 | player->SendPreparedQuest( guid ); |
---|
| 908 | break; |
---|
| 909 | case GOSSIP_OPTION_VENDOR: |
---|
| 910 | case GOSSIP_OPTION_ARMORER: |
---|
| 911 | player->GetSession()->SendListInventory(guid); |
---|
| 912 | break; |
---|
| 913 | case GOSSIP_OPTION_STABLEPET: |
---|
| 914 | player->GetSession()->SendStablePet(guid); |
---|
| 915 | break; |
---|
| 916 | case GOSSIP_OPTION_TRAINER: |
---|
| 917 | player->GetSession()->SendTrainerList(guid); |
---|
| 918 | break; |
---|
| 919 | case GOSSIP_OPTION_UNLEARNTALENTS: |
---|
| 920 | player->PlayerTalkClass->CloseGossip(); |
---|
| 921 | player->SendTalentWipeConfirm(guid); |
---|
| 922 | break; |
---|
| 923 | case GOSSIP_OPTION_UNLEARNPETSKILLS: |
---|
| 924 | player->PlayerTalkClass->CloseGossip(); |
---|
| 925 | player->SendPetSkillWipeConfirm(); |
---|
| 926 | break; |
---|
| 927 | case GOSSIP_OPTION_TAXIVENDOR: |
---|
| 928 | player->GetSession()->SendTaxiMenu(this); |
---|
| 929 | break; |
---|
| 930 | case GOSSIP_OPTION_INNKEEPER: |
---|
| 931 | player->PlayerTalkClass->CloseGossip(); |
---|
| 932 | player->SetBindPoint( guid ); |
---|
| 933 | break; |
---|
| 934 | case GOSSIP_OPTION_BANKER: |
---|
| 935 | player->GetSession()->SendShowBank( guid ); |
---|
| 936 | break; |
---|
| 937 | case GOSSIP_OPTION_PETITIONER: |
---|
| 938 | player->PlayerTalkClass->CloseGossip(); |
---|
| 939 | player->GetSession()->SendPetitionShowList( guid ); |
---|
| 940 | break; |
---|
| 941 | case GOSSIP_OPTION_TABARDDESIGNER: |
---|
| 942 | player->PlayerTalkClass->CloseGossip(); |
---|
| 943 | player->GetSession()->SendTabardVendorActivate( guid ); |
---|
| 944 | break; |
---|
| 945 | case GOSSIP_OPTION_AUCTIONEER: |
---|
| 946 | player->GetSession()->SendAuctionHello( guid, this ); |
---|
| 947 | break; |
---|
| 948 | case GOSSIP_OPTION_SPIRITGUIDE: |
---|
| 949 | case GOSSIP_GUARD_SPELLTRAINER: |
---|
| 950 | case GOSSIP_GUARD_SKILLTRAINER: |
---|
| 951 | prepareGossipMenu( player,gossip->Id ); |
---|
| 952 | sendPreparedGossip( player ); |
---|
| 953 | break; |
---|
| 954 | case GOSSIP_OPTION_BATTLEFIELD: |
---|
| 955 | { |
---|
| 956 | uint32 bgTypeId = objmgr.GetBattleMasterBG(GetEntry()); |
---|
| 957 | player->GetSession()->SendBattlegGroundList( GetGUID(), bgTypeId ); |
---|
| 958 | break; |
---|
| 959 | } |
---|
| 960 | default: |
---|
| 961 | OnPoiSelect( player, gossip ); |
---|
| 962 | break; |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | void Creature::OnPoiSelect(Player* player, GossipOption const *gossip) |
---|
| 968 | { |
---|
| 969 | if(gossip->GossipId==GOSSIP_GUARD_SPELLTRAINER || gossip->GossipId==GOSSIP_GUARD_SKILLTRAINER) |
---|
| 970 | { |
---|
| 971 | //float x,y; |
---|
| 972 | //bool findnpc=false; |
---|
| 973 | Poi_Icon icon = ICON_POI_0; |
---|
| 974 | //QueryResult *result; |
---|
| 975 | //Field *fields; |
---|
| 976 | uint32 mapid=GetMapId(); |
---|
| 977 | Map const* map=MapManager::Instance().GetBaseMap( mapid ); |
---|
| 978 | uint16 areaflag=map->GetAreaFlag(GetPositionX(),GetPositionY()); |
---|
| 979 | uint32 zoneid=Map::GetZoneId(areaflag,mapid); |
---|
[168] | 980 | std::string areaname= gossip->OptionText; |
---|
[37] | 981 | /* |
---|
| 982 | uint16 pflag; |
---|
| 983 | |
---|
| 984 | // use the action relate to creaturetemplate.trainer_type ? |
---|
| 985 | result= WorldDatabase.PQuery("SELECT creature.position_x,creature.position_y FROM creature,creature_template WHERE creature.map = '%u' AND creature.id = creature_template.entry AND creature_template.trainer_type = '%u'", mapid, gossip->Action ); |
---|
| 986 | if(!result) |
---|
| 987 | return; |
---|
| 988 | do |
---|
| 989 | { |
---|
| 990 | fields = result->Fetch(); |
---|
| 991 | x=fields[0].GetFloat(); |
---|
| 992 | y=fields[1].GetFloat(); |
---|
| 993 | pflag=map->GetAreaFlag(GetPositionX(),GetPositionY()); |
---|
| 994 | if(pflag==areaflag) |
---|
| 995 | { |
---|
| 996 | findnpc=true; |
---|
| 997 | break; |
---|
| 998 | } |
---|
| 999 | }while(result->NextRow()); |
---|
| 1000 | |
---|
| 1001 | delete result; |
---|
| 1002 | |
---|
| 1003 | if(!findnpc) |
---|
| 1004 | { |
---|
| 1005 | player->PlayerTalkClass->SendTalking( "$NSorry", "Here no this person."); |
---|
| 1006 | return; |
---|
| 1007 | }*/ |
---|
| 1008 | |
---|
| 1009 | //need add more case. |
---|
| 1010 | switch(gossip->Action) |
---|
| 1011 | { |
---|
| 1012 | case GOSSIP_GUARD_BANK: |
---|
| 1013 | icon=ICON_POI_HOUSE; |
---|
| 1014 | break; |
---|
| 1015 | case GOSSIP_GUARD_RIDE: |
---|
| 1016 | icon=ICON_POI_RWHORSE; |
---|
| 1017 | break; |
---|
| 1018 | case GOSSIP_GUARD_GUILD: |
---|
| 1019 | icon=ICON_POI_BLUETOWER; |
---|
| 1020 | break; |
---|
| 1021 | default: |
---|
| 1022 | icon=ICON_POI_TOWER; |
---|
| 1023 | break; |
---|
| 1024 | } |
---|
| 1025 | uint32 textid=GetGossipTextId( gossip->Action, zoneid ); |
---|
| 1026 | player->PlayerTalkClass->SendTalking( textid ); |
---|
| 1027 | // how this could worked player->PlayerTalkClass->SendPointOfInterest( x, y, icon, 2, 15, areaname.c_str() ); |
---|
| 1028 | } |
---|
| 1029 | } |
---|
| 1030 | |
---|
| 1031 | uint32 Creature::GetGossipTextId(uint32 action, uint32 zoneid) |
---|
| 1032 | { |
---|
| 1033 | QueryResult *result= WorldDatabase.PQuery("SELECT textid FROM npc_gossip_textid WHERE action = '%u' AND zoneid ='%u'", action, zoneid ); |
---|
| 1034 | |
---|
| 1035 | if(!result) |
---|
| 1036 | return 0; |
---|
| 1037 | |
---|
| 1038 | Field *fields = result->Fetch(); |
---|
| 1039 | uint32 id = fields[0].GetUInt32(); |
---|
| 1040 | |
---|
| 1041 | delete result; |
---|
| 1042 | |
---|
| 1043 | return id; |
---|
| 1044 | } |
---|
| 1045 | |
---|
| 1046 | uint32 Creature::GetNpcTextId() |
---|
| 1047 | { |
---|
[44] | 1048 | // don't cache / use cache in case it's a world event announcer |
---|
| 1049 | if(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_WORLDEVENT) |
---|
| 1050 | if(uint32 textid = gameeventmgr.GetNpcTextId(m_DBTableGuid)) |
---|
| 1051 | return textid; |
---|
| 1052 | |
---|
[37] | 1053 | if (!m_DBTableGuid) |
---|
| 1054 | return DEFAULT_GOSSIP_MESSAGE; |
---|
| 1055 | |
---|
| 1056 | if(uint32 pos = objmgr.GetNpcGossip(m_DBTableGuid)) |
---|
| 1057 | return pos; |
---|
| 1058 | |
---|
| 1059 | return DEFAULT_GOSSIP_MESSAGE; |
---|
| 1060 | } |
---|
| 1061 | |
---|
| 1062 | GossipOption const* Creature::GetGossipOption( uint32 id ) const |
---|
| 1063 | { |
---|
| 1064 | for( GossipOptionList::const_iterator i = m_goptions.begin( ); i != m_goptions.end( ); i++ ) |
---|
| 1065 | { |
---|
| 1066 | if(i->Action==id ) |
---|
| 1067 | return &*i; |
---|
| 1068 | } |
---|
| 1069 | return NULL; |
---|
| 1070 | } |
---|
| 1071 | |
---|
[44] | 1072 | void Creature::ResetGossipOptions() |
---|
| 1073 | { |
---|
| 1074 | m_gossipOptionLoaded = false; |
---|
| 1075 | m_goptions.clear(); |
---|
| 1076 | } |
---|
| 1077 | |
---|
[37] | 1078 | void Creature::LoadGossipOptions() |
---|
| 1079 | { |
---|
| 1080 | if(m_gossipOptionLoaded) |
---|
| 1081 | return; |
---|
| 1082 | |
---|
| 1083 | uint32 npcflags=GetUInt32Value(UNIT_NPC_FLAGS); |
---|
| 1084 | |
---|
[168] | 1085 | CacheNpcOptionList const& noList = objmgr.GetNpcOptions (); |
---|
| 1086 | for (CacheNpcOptionList::const_iterator i = noList.begin (); i != noList.end (); ++i) |
---|
| 1087 | if(i->NpcFlag & npcflags) |
---|
| 1088 | addGossipOption(*i); |
---|
[37] | 1089 | |
---|
| 1090 | m_gossipOptionLoaded = true; |
---|
| 1091 | } |
---|
| 1092 | |
---|
| 1093 | void Creature::AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type) |
---|
| 1094 | { |
---|
| 1095 | /* uint32 timeElap = getMSTime(); |
---|
| 1096 | if ((timeElap - m_startMove) < m_moveTime) |
---|
| 1097 | { |
---|
| 1098 | oX = (dX - oX) * ( (timeElap - m_startMove) / m_moveTime ); |
---|
| 1099 | oY = (dY - oY) * ( (timeElap - m_startMove) / m_moveTime ); |
---|
| 1100 | } |
---|
| 1101 | else |
---|
| 1102 | { |
---|
| 1103 | oX = dX; |
---|
| 1104 | oY = dY; |
---|
| 1105 | } |
---|
| 1106 | |
---|
| 1107 | dX = x; |
---|
| 1108 | dY = y; |
---|
| 1109 | m_orientation = atan2((oY - dY), (oX - dX)); |
---|
| 1110 | |
---|
| 1111 | m_startMove = getMSTime(); |
---|
| 1112 | m_moveTime = time;*/ |
---|
| 1113 | SendMonsterMove(x, y, z, type, MovementFlags, time); |
---|
| 1114 | } |
---|
| 1115 | |
---|
| 1116 | Player *Creature::GetLootRecipient() const |
---|
| 1117 | { |
---|
| 1118 | if (!m_lootRecipient) return NULL; |
---|
| 1119 | else return ObjectAccessor::FindPlayer(m_lootRecipient); |
---|
| 1120 | } |
---|
| 1121 | |
---|
| 1122 | void Creature::SetLootRecipient(Unit *unit) |
---|
| 1123 | { |
---|
| 1124 | // set the player whose group should receive the right |
---|
| 1125 | // to loot the creature after it dies |
---|
| 1126 | // should be set to NULL after the loot disappears |
---|
| 1127 | |
---|
| 1128 | if (!unit) |
---|
| 1129 | { |
---|
| 1130 | m_lootRecipient = 0; |
---|
| 1131 | RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_OTHER_TAGGER); |
---|
| 1132 | return; |
---|
| 1133 | } |
---|
| 1134 | |
---|
| 1135 | Player* player = unit->GetCharmerOrOwnerPlayerOrPlayerItself(); |
---|
| 1136 | if(!player) // normal creature, no player involved |
---|
| 1137 | return; |
---|
| 1138 | |
---|
| 1139 | m_lootRecipient = player->GetGUID(); |
---|
| 1140 | SetFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_OTHER_TAGGER); |
---|
| 1141 | } |
---|
| 1142 | |
---|
| 1143 | void Creature::SaveToDB() |
---|
| 1144 | { |
---|
| 1145 | // this should only be used when the creature has already been loaded |
---|
| 1146 | // perferably after adding to map, because mapid may not be valid otherwise |
---|
| 1147 | CreatureData const *data = objmgr.GetCreatureData(m_DBTableGuid); |
---|
| 1148 | if(!data) |
---|
| 1149 | { |
---|
| 1150 | sLog.outError("Creature::SaveToDB failed, cannot get creature data!"); |
---|
| 1151 | return; |
---|
| 1152 | } |
---|
| 1153 | |
---|
| 1154 | SaveToDB(GetMapId(), data->spawnMask); |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | void Creature::SaveToDB(uint32 mapid, uint8 spawnMask) |
---|
| 1158 | { |
---|
| 1159 | // update in loaded data |
---|
| 1160 | if (!m_DBTableGuid) |
---|
| 1161 | m_DBTableGuid = GetGUIDLow(); |
---|
| 1162 | CreatureData& data = objmgr.NewOrExistCreatureData(m_DBTableGuid); |
---|
| 1163 | |
---|
| 1164 | uint32 displayId = GetNativeDisplayId(); |
---|
| 1165 | |
---|
| 1166 | // check if it's a custom model and if not, use 0 for displayId |
---|
| 1167 | CreatureInfo const *cinfo = GetCreatureInfo(); |
---|
| 1168 | if(cinfo) |
---|
| 1169 | { |
---|
[123] | 1170 | if(displayId == cinfo->Modelid1 || displayId == cinfo->Modelid2 || |
---|
| 1171 | displayId == cinfo->Modelid3 || displayId == cinfo->Modelid4) displayId = 0; |
---|
[37] | 1172 | } |
---|
| 1173 | |
---|
| 1174 | // data->guid = guid don't must be update at save |
---|
| 1175 | data.id = GetEntry(); |
---|
| 1176 | data.mapid = mapid; |
---|
| 1177 | data.displayid = displayId; |
---|
| 1178 | data.equipmentId = GetEquipmentId(); |
---|
| 1179 | data.posX = GetPositionX(); |
---|
| 1180 | data.posY = GetPositionY(); |
---|
| 1181 | data.posZ = GetPositionZ(); |
---|
| 1182 | data.orientation = GetOrientation(); |
---|
| 1183 | data.spawntimesecs = m_respawnDelay; |
---|
| 1184 | // prevent add data integrity problems |
---|
| 1185 | data.spawndist = GetDefaultMovementType()==IDLE_MOTION_TYPE ? 0 : m_respawnradius; |
---|
| 1186 | data.currentwaypoint = 0; |
---|
| 1187 | data.curhealth = GetHealth(); |
---|
| 1188 | data.curmana = GetPower(POWER_MANA); |
---|
| 1189 | data.is_dead = m_isDeadByDefault; |
---|
| 1190 | // prevent add data integrity problems |
---|
| 1191 | data.movementType = !m_respawnradius && GetDefaultMovementType()==RANDOM_MOTION_TYPE |
---|
| 1192 | ? IDLE_MOTION_TYPE : GetDefaultMovementType(); |
---|
| 1193 | data.spawnMask = spawnMask; |
---|
| 1194 | |
---|
| 1195 | // updated in DB |
---|
| 1196 | WorldDatabase.BeginTransaction(); |
---|
| 1197 | |
---|
| 1198 | WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid); |
---|
| 1199 | |
---|
| 1200 | std::ostringstream ss; |
---|
| 1201 | ss << "INSERT INTO creature VALUES (" |
---|
| 1202 | << m_DBTableGuid << "," |
---|
| 1203 | << GetEntry() << "," |
---|
| 1204 | << mapid <<"," |
---|
| 1205 | << (uint32)spawnMask << "," |
---|
| 1206 | << displayId <<"," |
---|
| 1207 | << GetEquipmentId() <<"," |
---|
| 1208 | << GetPositionX() << "," |
---|
| 1209 | << GetPositionY() << "," |
---|
| 1210 | << GetPositionZ() << "," |
---|
| 1211 | << GetOrientation() << "," |
---|
| 1212 | << m_respawnDelay << "," //respawn time |
---|
| 1213 | << (float) m_respawnradius << "," //spawn distance (float) |
---|
| 1214 | << (uint32) (0) << "," //currentwaypoint |
---|
| 1215 | << GetHealth() << "," //curhealth |
---|
| 1216 | << GetPower(POWER_MANA) << "," //curmana |
---|
| 1217 | << (m_isDeadByDefault ? 1 : 0) << "," //is_dead |
---|
| 1218 | << GetDefaultMovementType() << ")"; //default movement generator type |
---|
| 1219 | |
---|
| 1220 | WorldDatabase.PExecuteLog( ss.str( ).c_str( ) ); |
---|
| 1221 | |
---|
| 1222 | WorldDatabase.CommitTransaction(); |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | void Creature::SelectLevel(const CreatureInfo *cinfo) |
---|
| 1226 | { |
---|
| 1227 | uint32 rank = isPet()? 0 : cinfo->rank; |
---|
| 1228 | |
---|
| 1229 | // level |
---|
| 1230 | uint32 minlevel = std::min(cinfo->maxlevel, cinfo->minlevel); |
---|
| 1231 | uint32 maxlevel = std::max(cinfo->maxlevel, cinfo->minlevel); |
---|
| 1232 | uint32 level = minlevel == maxlevel ? minlevel : urand(minlevel, maxlevel); |
---|
| 1233 | SetLevel(level); |
---|
| 1234 | |
---|
| 1235 | float rellevel = maxlevel == minlevel ? 0 : (float(level - minlevel))/(maxlevel - minlevel); |
---|
| 1236 | |
---|
| 1237 | // health |
---|
| 1238 | float healthmod = _GetHealthMod(rank); |
---|
| 1239 | |
---|
| 1240 | uint32 minhealth = std::min(cinfo->maxhealth, cinfo->minhealth); |
---|
| 1241 | uint32 maxhealth = std::max(cinfo->maxhealth, cinfo->minhealth); |
---|
| 1242 | uint32 health = uint32(healthmod * (minhealth + uint32(rellevel*(maxhealth - minhealth)))); |
---|
| 1243 | |
---|
| 1244 | SetCreateHealth(health); |
---|
| 1245 | SetMaxHealth(health); |
---|
| 1246 | SetHealth(health); |
---|
| 1247 | |
---|
| 1248 | // mana |
---|
| 1249 | uint32 minmana = std::min(cinfo->maxmana, cinfo->minmana); |
---|
| 1250 | uint32 maxmana = std::max(cinfo->maxmana, cinfo->minmana); |
---|
| 1251 | uint32 mana = minmana + uint32(rellevel*(maxmana - minmana)); |
---|
| 1252 | |
---|
| 1253 | SetCreateMana(mana); |
---|
| 1254 | SetMaxPower(POWER_MANA, mana); //MAX Mana |
---|
| 1255 | SetPower(POWER_MANA, mana); |
---|
| 1256 | |
---|
| 1257 | SetModifierValue(UNIT_MOD_HEALTH, BASE_VALUE, health); |
---|
| 1258 | SetModifierValue(UNIT_MOD_MANA, BASE_VALUE, mana); |
---|
| 1259 | |
---|
| 1260 | // damage |
---|
| 1261 | float damagemod = _GetDamageMod(rank); |
---|
| 1262 | |
---|
| 1263 | SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, cinfo->mindmg * damagemod); |
---|
| 1264 | SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, cinfo->maxdmg * damagemod); |
---|
[136] | 1265 | SetBaseWeaponDamage(OFF_ATTACK, MINDAMAGE, cinfo->mindmg * damagemod); |
---|
| 1266 | SetBaseWeaponDamage(OFF_ATTACK, MAXDAMAGE, cinfo->maxdmg * damagemod); |
---|
| 1267 | SetBaseWeaponDamage(RANGED_ATTACK, MINDAMAGE, cinfo->minrangedmg * damagemod); |
---|
| 1268 | SetBaseWeaponDamage(RANGED_ATTACK, MAXDAMAGE, cinfo->maxrangedmg * damagemod); |
---|
[37] | 1269 | |
---|
| 1270 | SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, cinfo->attackpower * damagemod); |
---|
[136] | 1271 | SetModifierValue(UNIT_MOD_ATTACK_POWER_RANGED, BASE_VALUE, cinfo->rangedattackpower * damagemod); |
---|
[37] | 1272 | } |
---|
| 1273 | |
---|
| 1274 | float Creature::_GetHealthMod(int32 Rank) |
---|
| 1275 | { |
---|
| 1276 | switch (Rank) // define rates for each elite rank |
---|
| 1277 | { |
---|
| 1278 | case CREATURE_ELITE_NORMAL: |
---|
| 1279 | return sWorld.getRate(RATE_CREATURE_NORMAL_HP); |
---|
| 1280 | case CREATURE_ELITE_ELITE: |
---|
| 1281 | return sWorld.getRate(RATE_CREATURE_ELITE_ELITE_HP); |
---|
| 1282 | case CREATURE_ELITE_RAREELITE: |
---|
| 1283 | return sWorld.getRate(RATE_CREATURE_ELITE_RAREELITE_HP); |
---|
| 1284 | case CREATURE_ELITE_WORLDBOSS: |
---|
| 1285 | return sWorld.getRate(RATE_CREATURE_ELITE_WORLDBOSS_HP); |
---|
| 1286 | case CREATURE_ELITE_RARE: |
---|
| 1287 | return sWorld.getRate(RATE_CREATURE_ELITE_RARE_HP); |
---|
| 1288 | default: |
---|
| 1289 | return sWorld.getRate(RATE_CREATURE_ELITE_ELITE_HP); |
---|
| 1290 | } |
---|
| 1291 | } |
---|
| 1292 | |
---|
| 1293 | float Creature::_GetDamageMod(int32 Rank) |
---|
| 1294 | { |
---|
| 1295 | switch (Rank) // define rates for each elite rank |
---|
| 1296 | { |
---|
| 1297 | case CREATURE_ELITE_NORMAL: |
---|
| 1298 | return sWorld.getRate(RATE_CREATURE_NORMAL_DAMAGE); |
---|
| 1299 | case CREATURE_ELITE_ELITE: |
---|
| 1300 | return sWorld.getRate(RATE_CREATURE_ELITE_ELITE_DAMAGE); |
---|
| 1301 | case CREATURE_ELITE_RAREELITE: |
---|
| 1302 | return sWorld.getRate(RATE_CREATURE_ELITE_RAREELITE_DAMAGE); |
---|
| 1303 | case CREATURE_ELITE_WORLDBOSS: |
---|
| 1304 | return sWorld.getRate(RATE_CREATURE_ELITE_WORLDBOSS_DAMAGE); |
---|
| 1305 | case CREATURE_ELITE_RARE: |
---|
| 1306 | return sWorld.getRate(RATE_CREATURE_ELITE_RARE_DAMAGE); |
---|
| 1307 | default: |
---|
| 1308 | return sWorld.getRate(RATE_CREATURE_ELITE_ELITE_DAMAGE); |
---|
| 1309 | } |
---|
| 1310 | } |
---|
| 1311 | |
---|
| 1312 | float Creature::GetSpellDamageMod(int32 Rank) |
---|
| 1313 | { |
---|
| 1314 | switch (Rank) // define rates for each elite rank |
---|
| 1315 | { |
---|
| 1316 | case CREATURE_ELITE_NORMAL: |
---|
| 1317 | return sWorld.getRate(RATE_CREATURE_NORMAL_SPELLDAMAGE); |
---|
| 1318 | case CREATURE_ELITE_ELITE: |
---|
| 1319 | return sWorld.getRate(RATE_CREATURE_ELITE_ELITE_SPELLDAMAGE); |
---|
| 1320 | case CREATURE_ELITE_RAREELITE: |
---|
| 1321 | return sWorld.getRate(RATE_CREATURE_ELITE_RAREELITE_SPELLDAMAGE); |
---|
| 1322 | case CREATURE_ELITE_WORLDBOSS: |
---|
| 1323 | return sWorld.getRate(RATE_CREATURE_ELITE_WORLDBOSS_SPELLDAMAGE); |
---|
| 1324 | case CREATURE_ELITE_RARE: |
---|
| 1325 | return sWorld.getRate(RATE_CREATURE_ELITE_RARE_SPELLDAMAGE); |
---|
| 1326 | default: |
---|
| 1327 | return sWorld.getRate(RATE_CREATURE_ELITE_ELITE_SPELLDAMAGE); |
---|
| 1328 | } |
---|
| 1329 | } |
---|
| 1330 | |
---|
| 1331 | bool Creature::CreateFromProto(uint32 guidlow, uint32 Entry, uint32 team, const CreatureData *data) |
---|
| 1332 | { |
---|
| 1333 | CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(Entry); |
---|
| 1334 | if(!cinfo) |
---|
| 1335 | { |
---|
| 1336 | sLog.outErrorDb("Error: creature entry %u does not exist.", Entry); |
---|
| 1337 | return false; |
---|
| 1338 | } |
---|
| 1339 | m_originalEntry = Entry; |
---|
| 1340 | |
---|
| 1341 | Object::_Create(guidlow, Entry, HIGHGUID_UNIT); |
---|
| 1342 | |
---|
| 1343 | if(!UpdateEntry(Entry, team, data)) |
---|
| 1344 | return false; |
---|
| 1345 | |
---|
| 1346 | //Notify the map's instance data. |
---|
| 1347 | //Only works if you create the object in it, not if it is moves to that map. |
---|
| 1348 | //Normally non-players do not teleport to other maps. |
---|
| 1349 | Map *map = MapManager::Instance().FindMap(GetMapId(), GetInstanceId()); |
---|
| 1350 | if(map && map->IsDungeon() && ((InstanceMap*)map)->GetInstanceData()) |
---|
| 1351 | { |
---|
| 1352 | ((InstanceMap*)map)->GetInstanceData()->OnCreatureCreate(this, Entry); |
---|
| 1353 | } |
---|
| 1354 | |
---|
| 1355 | return true; |
---|
| 1356 | } |
---|
| 1357 | |
---|
| 1358 | bool Creature::LoadFromDB(uint32 guid, Map *map) |
---|
| 1359 | { |
---|
| 1360 | CreatureData const* data = objmgr.GetCreatureData(guid); |
---|
| 1361 | |
---|
| 1362 | if(!data) |
---|
| 1363 | { |
---|
| 1364 | sLog.outErrorDb("Creature (GUID: %u) not found in table `creature`, can't load. ",guid); |
---|
| 1365 | return false; |
---|
| 1366 | } |
---|
| 1367 | |
---|
| 1368 | m_DBTableGuid = guid; |
---|
| 1369 | if (map->GetInstanceId() != 0) guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT); |
---|
| 1370 | |
---|
| 1371 | uint16 team = 0; |
---|
| 1372 | if(!Create(guid,map,data->id,team,data)) |
---|
| 1373 | return false; |
---|
| 1374 | |
---|
| 1375 | Relocate(data->posX,data->posY,data->posZ,data->orientation); |
---|
| 1376 | |
---|
| 1377 | if(!IsPositionValid()) |
---|
| 1378 | { |
---|
| 1379 | sLog.outError("ERROR: Creature (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)",GetGUIDLow(),GetEntry(),GetPositionX(),GetPositionY()); |
---|
| 1380 | return false; |
---|
| 1381 | } |
---|
| 1382 | |
---|
| 1383 | m_respawnradius = data->spawndist; |
---|
| 1384 | |
---|
| 1385 | m_respawnDelay = data->spawntimesecs; |
---|
| 1386 | m_isDeadByDefault = data->is_dead; |
---|
| 1387 | m_deathState = m_isDeadByDefault ? DEAD : ALIVE; |
---|
| 1388 | |
---|
| 1389 | m_respawnTime = objmgr.GetCreatureRespawnTime(m_DBTableGuid,GetInstanceId()); |
---|
| 1390 | if(m_respawnTime > time(NULL)) // not ready to respawn |
---|
| 1391 | m_deathState = DEAD; |
---|
| 1392 | else if(m_respawnTime) // respawn time set but expired |
---|
| 1393 | { |
---|
| 1394 | m_respawnTime = 0; |
---|
| 1395 | objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0); |
---|
| 1396 | } |
---|
| 1397 | |
---|
| 1398 | uint32 curhealth = data->curhealth; |
---|
| 1399 | if(curhealth) |
---|
| 1400 | { |
---|
| 1401 | curhealth = uint32(curhealth*_GetHealthMod(GetCreatureInfo()->rank)); |
---|
| 1402 | if(curhealth < 1) |
---|
| 1403 | curhealth = 1; |
---|
| 1404 | } |
---|
| 1405 | |
---|
| 1406 | SetHealth(m_deathState == ALIVE ? curhealth : 0); |
---|
| 1407 | SetPower(POWER_MANA,data->curmana); |
---|
| 1408 | |
---|
| 1409 | SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool)); |
---|
| 1410 | |
---|
| 1411 | // checked at creature_template loading |
---|
| 1412 | m_defaultMovementType = MovementGeneratorType(data->movementType); |
---|
| 1413 | |
---|
| 1414 | AIM_Initialize(); |
---|
| 1415 | return true; |
---|
| 1416 | } |
---|
| 1417 | |
---|
| 1418 | void Creature::LoadEquipment(uint32 equip_entry, bool force) |
---|
| 1419 | { |
---|
| 1420 | if(equip_entry == 0) |
---|
| 1421 | { |
---|
| 1422 | if (force) |
---|
| 1423 | { |
---|
[161] | 1424 | for (uint8 i = 0; i < 3; i++) |
---|
[37] | 1425 | { |
---|
| 1426 | SetUInt32Value( UNIT_VIRTUAL_ITEM_SLOT_DISPLAY + i, 0); |
---|
| 1427 | SetUInt32Value( UNIT_VIRTUAL_ITEM_INFO + (i * 2), 0); |
---|
| 1428 | SetUInt32Value( UNIT_VIRTUAL_ITEM_INFO + (i * 2) + 1, 0); |
---|
| 1429 | } |
---|
| 1430 | m_equipmentId = 0; |
---|
| 1431 | } |
---|
| 1432 | return; |
---|
| 1433 | } |
---|
| 1434 | |
---|
| 1435 | EquipmentInfo const *einfo = objmgr.GetEquipmentInfo(equip_entry); |
---|
| 1436 | if (!einfo) |
---|
| 1437 | return; |
---|
| 1438 | |
---|
| 1439 | m_equipmentId = equip_entry; |
---|
[161] | 1440 | for (uint8 i = 0; i < 3; i++) |
---|
[37] | 1441 | { |
---|
| 1442 | SetUInt32Value( UNIT_VIRTUAL_ITEM_SLOT_DISPLAY + i, einfo->equipmodel[i]); |
---|
| 1443 | SetUInt32Value( UNIT_VIRTUAL_ITEM_INFO + (i * 2), einfo->equipinfo[i]); |
---|
| 1444 | SetUInt32Value( UNIT_VIRTUAL_ITEM_INFO + (i * 2) + 1, einfo->equipslot[i]); |
---|
| 1445 | } |
---|
| 1446 | } |
---|
| 1447 | |
---|
| 1448 | bool Creature::hasQuest(uint32 quest_id) const |
---|
| 1449 | { |
---|
| 1450 | QuestRelations const& qr = objmgr.mCreatureQuestRelations; |
---|
| 1451 | for(QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr) |
---|
| 1452 | { |
---|
| 1453 | if(itr->second==quest_id) |
---|
| 1454 | return true; |
---|
| 1455 | } |
---|
| 1456 | return false; |
---|
| 1457 | } |
---|
| 1458 | |
---|
| 1459 | bool Creature::hasInvolvedQuest(uint32 quest_id) const |
---|
| 1460 | { |
---|
| 1461 | QuestRelations const& qr = objmgr.mCreatureQuestInvolvedRelations; |
---|
| 1462 | for(QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr) |
---|
| 1463 | { |
---|
| 1464 | if(itr->second==quest_id) |
---|
| 1465 | return true; |
---|
| 1466 | } |
---|
| 1467 | return false; |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | void Creature::DeleteFromDB() |
---|
| 1471 | { |
---|
| 1472 | if (!m_DBTableGuid) |
---|
| 1473 | { |
---|
| 1474 | sLog.outDebug("Trying to delete not saved creature!"); |
---|
| 1475 | return; |
---|
| 1476 | } |
---|
| 1477 | |
---|
| 1478 | objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0); |
---|
| 1479 | objmgr.DeleteCreatureData(m_DBTableGuid); |
---|
| 1480 | |
---|
| 1481 | WorldDatabase.BeginTransaction(); |
---|
| 1482 | WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", m_DBTableGuid); |
---|
| 1483 | WorldDatabase.PExecuteLog("DELETE FROM creature_addon WHERE guid = '%u'", m_DBTableGuid); |
---|
| 1484 | WorldDatabase.PExecuteLog("DELETE FROM creature_movement WHERE id = '%u'", m_DBTableGuid); |
---|
| 1485 | WorldDatabase.PExecuteLog("DELETE FROM game_event_creature WHERE guid = '%u'", m_DBTableGuid); |
---|
| 1486 | WorldDatabase.PExecuteLog("DELETE FROM game_event_model_equip WHERE guid = '%u'", m_DBTableGuid); |
---|
| 1487 | WorldDatabase.CommitTransaction(); |
---|
| 1488 | } |
---|
| 1489 | |
---|
| 1490 | float Creature::GetAttackDistance(Unit const* pl) const |
---|
| 1491 | { |
---|
| 1492 | float aggroRate = sWorld.getRate(RATE_CREATURE_AGGRO); |
---|
| 1493 | if(aggroRate==0) |
---|
| 1494 | return 0.0f; |
---|
| 1495 | |
---|
| 1496 | int32 playerlevel = pl->getLevelForTarget(this); |
---|
| 1497 | int32 creaturelevel = getLevelForTarget(pl); |
---|
| 1498 | |
---|
| 1499 | int32 leveldif = playerlevel - creaturelevel; |
---|
| 1500 | |
---|
| 1501 | // "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." |
---|
| 1502 | if ( leveldif < - 25) |
---|
| 1503 | leveldif = -25; |
---|
| 1504 | |
---|
| 1505 | // "The aggro radius of a mob having the same level as the player is roughly 20 yards" |
---|
| 1506 | float RetDistance = 20; |
---|
| 1507 | |
---|
| 1508 | // "Aggro Radius varries with level difference at a rate of roughly 1 yard/level" |
---|
| 1509 | // radius grow if playlevel < creaturelevel |
---|
| 1510 | RetDistance -= (float)leveldif; |
---|
| 1511 | |
---|
| 1512 | if(creaturelevel+5 <= sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) |
---|
| 1513 | { |
---|
| 1514 | // detect range auras |
---|
| 1515 | RetDistance += GetTotalAuraModifier(SPELL_AURA_MOD_DETECT_RANGE); |
---|
| 1516 | |
---|
| 1517 | // detected range auras |
---|
| 1518 | RetDistance += pl->GetTotalAuraModifier(SPELL_AURA_MOD_DETECTED_RANGE); |
---|
| 1519 | } |
---|
| 1520 | |
---|
| 1521 | // "Minimum Aggro Radius for a mob seems to be combat range (5 yards)" |
---|
| 1522 | if(RetDistance < 5) |
---|
| 1523 | RetDistance = 5; |
---|
| 1524 | |
---|
| 1525 | return (RetDistance*aggroRate); |
---|
| 1526 | } |
---|
| 1527 | |
---|
| 1528 | void Creature::setDeathState(DeathState s) |
---|
| 1529 | { |
---|
| 1530 | if((s == JUST_DIED && !m_isDeadByDefault)||(s == JUST_ALIVED && m_isDeadByDefault)) |
---|
| 1531 | { |
---|
| 1532 | m_deathTimer = m_corpseDelay*1000; |
---|
| 1533 | |
---|
| 1534 | // always save boss respawn time at death to prevent crash cheating |
---|
| 1535 | if(sWorld.getConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATLY) || isWorldBoss()) |
---|
| 1536 | SaveRespawnTime(); |
---|
| 1537 | |
---|
| 1538 | if(!IsStopped()) |
---|
| 1539 | StopMoving(); |
---|
| 1540 | } |
---|
| 1541 | Unit::setDeathState(s); |
---|
| 1542 | |
---|
| 1543 | if(s == JUST_DIED) |
---|
| 1544 | { |
---|
| 1545 | SetUInt64Value (UNIT_FIELD_TARGET,0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState) |
---|
| 1546 | SetUInt32Value(UNIT_NPC_FLAGS, 0); |
---|
| 1547 | |
---|
| 1548 | if(!isPet() && GetCreatureInfo()->SkinLootId) |
---|
| 1549 | if ( LootTemplates_Skinning.HaveLootFor(GetCreatureInfo()->SkinLootId) ) |
---|
| 1550 | SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); |
---|
| 1551 | |
---|
| 1552 | Unit::setDeathState(CORPSE); |
---|
| 1553 | } |
---|
| 1554 | if(s == JUST_ALIVED) |
---|
| 1555 | { |
---|
| 1556 | SetHealth(GetMaxHealth()); |
---|
| 1557 | SetLootRecipient(NULL); |
---|
| 1558 | Unit::setDeathState(ALIVE); |
---|
| 1559 | CreatureInfo const *cinfo = GetCreatureInfo(); |
---|
| 1560 | SetUInt32Value(UNIT_DYNAMIC_FLAGS, 0); |
---|
| 1561 | RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); |
---|
| 1562 | AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); |
---|
| 1563 | SetUInt32Value(UNIT_NPC_FLAGS, cinfo->npcflag); |
---|
| 1564 | clearUnitState(UNIT_STAT_ALL_STATE); |
---|
| 1565 | i_motionMaster.Clear(); |
---|
| 1566 | SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool)); |
---|
| 1567 | LoadCreaturesAddon(true); |
---|
| 1568 | } |
---|
| 1569 | } |
---|
| 1570 | |
---|
| 1571 | void Creature::Respawn() |
---|
| 1572 | { |
---|
| 1573 | RemoveCorpse(); |
---|
| 1574 | |
---|
| 1575 | // forced recreate creature object at clients |
---|
| 1576 | UnitVisibility currentVis = GetVisibility(); |
---|
| 1577 | SetVisibility(VISIBILITY_RESPAWN); |
---|
| 1578 | ObjectAccessor::UpdateObjectVisibility(this); |
---|
| 1579 | SetVisibility(currentVis); // restore visibility state |
---|
| 1580 | ObjectAccessor::UpdateObjectVisibility(this); |
---|
| 1581 | |
---|
| 1582 | if(getDeathState()==DEAD) |
---|
| 1583 | { |
---|
| 1584 | if (m_DBTableGuid) |
---|
| 1585 | objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),0); |
---|
| 1586 | m_respawnTime = time(NULL); // respawn at next tick |
---|
| 1587 | } |
---|
| 1588 | } |
---|
| 1589 | |
---|
| 1590 | bool Creature::IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges) |
---|
| 1591 | { |
---|
| 1592 | if (!spellInfo) |
---|
| 1593 | return false; |
---|
| 1594 | |
---|
| 1595 | if (GetCreatureInfo()->MechanicImmuneMask & (1 << (spellInfo->Mechanic - 1))) |
---|
| 1596 | return true; |
---|
| 1597 | |
---|
| 1598 | return Unit::IsImmunedToSpell(spellInfo, useCharges); |
---|
| 1599 | } |
---|
| 1600 | |
---|
| 1601 | bool Creature::IsImmunedToSpellEffect(uint32 effect, uint32 mechanic) const |
---|
| 1602 | { |
---|
| 1603 | if (GetCreatureInfo()->MechanicImmuneMask & (1 << (mechanic-1))) |
---|
| 1604 | return true; |
---|
| 1605 | |
---|
| 1606 | return Unit::IsImmunedToSpellEffect(effect, mechanic); |
---|
| 1607 | } |
---|
| 1608 | |
---|
| 1609 | SpellEntry const *Creature::reachWithSpellAttack(Unit *pVictim) |
---|
| 1610 | { |
---|
| 1611 | if(!pVictim) |
---|
| 1612 | return NULL; |
---|
| 1613 | |
---|
| 1614 | for(uint32 i=0; i < CREATURE_MAX_SPELLS; i++) |
---|
| 1615 | { |
---|
| 1616 | if(!m_spells[i]) |
---|
| 1617 | continue; |
---|
| 1618 | SpellEntry const *spellInfo = sSpellStore.LookupEntry(m_spells[i] ); |
---|
| 1619 | if(!spellInfo) |
---|
| 1620 | { |
---|
| 1621 | sLog.outError("WORLD: unknown spell id %i\n", m_spells[i]); |
---|
| 1622 | continue; |
---|
| 1623 | } |
---|
| 1624 | |
---|
| 1625 | bool bcontinue = true; |
---|
| 1626 | for(uint32 j=0;j<3;j++) |
---|
| 1627 | { |
---|
| 1628 | if( (spellInfo->Effect[j] == SPELL_EFFECT_SCHOOL_DAMAGE ) || |
---|
| 1629 | (spellInfo->Effect[j] == SPELL_EFFECT_INSTAKILL) || |
---|
| 1630 | (spellInfo->Effect[j] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE) || |
---|
| 1631 | (spellInfo->Effect[j] == SPELL_EFFECT_HEALTH_LEECH ) |
---|
| 1632 | ) |
---|
| 1633 | { |
---|
| 1634 | bcontinue = false; |
---|
| 1635 | break; |
---|
| 1636 | } |
---|
| 1637 | } |
---|
| 1638 | if(bcontinue) continue; |
---|
| 1639 | |
---|
| 1640 | if(spellInfo->manaCost > GetPower(POWER_MANA)) |
---|
| 1641 | continue; |
---|
| 1642 | SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(spellInfo->rangeIndex); |
---|
| 1643 | float range = GetSpellMaxRange(srange); |
---|
| 1644 | float minrange = GetSpellMinRange(srange); |
---|
| 1645 | float dist = GetDistance(pVictim); |
---|
| 1646 | //if(!isInFront( pVictim, range ) && spellInfo->AttributesEx ) |
---|
| 1647 | // continue; |
---|
| 1648 | if( dist > range || dist < minrange ) |
---|
| 1649 | continue; |
---|
| 1650 | if(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED)) |
---|
| 1651 | continue; |
---|
| 1652 | return spellInfo; |
---|
| 1653 | } |
---|
| 1654 | return NULL; |
---|
| 1655 | } |
---|
| 1656 | |
---|
| 1657 | SpellEntry const *Creature::reachWithSpellCure(Unit *pVictim) |
---|
| 1658 | { |
---|
| 1659 | if(!pVictim) |
---|
| 1660 | return NULL; |
---|
| 1661 | |
---|
| 1662 | for(uint32 i=0; i < CREATURE_MAX_SPELLS; i++) |
---|
| 1663 | { |
---|
| 1664 | if(!m_spells[i]) |
---|
| 1665 | continue; |
---|
| 1666 | SpellEntry const *spellInfo = sSpellStore.LookupEntry(m_spells[i] ); |
---|
| 1667 | if(!spellInfo) |
---|
| 1668 | { |
---|
| 1669 | sLog.outError("WORLD: unknown spell id %i\n", m_spells[i]); |
---|
| 1670 | continue; |
---|
| 1671 | } |
---|
| 1672 | |
---|
| 1673 | bool bcontinue = true; |
---|
| 1674 | for(uint32 j=0;j<3;j++) |
---|
| 1675 | { |
---|
| 1676 | if( (spellInfo->Effect[j] == SPELL_EFFECT_HEAL ) ) |
---|
| 1677 | { |
---|
| 1678 | bcontinue = false; |
---|
| 1679 | break; |
---|
| 1680 | } |
---|
| 1681 | } |
---|
| 1682 | if(bcontinue) continue; |
---|
| 1683 | |
---|
| 1684 | if(spellInfo->manaCost > GetPower(POWER_MANA)) |
---|
| 1685 | continue; |
---|
| 1686 | SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(spellInfo->rangeIndex); |
---|
| 1687 | float range = GetSpellMaxRange(srange); |
---|
| 1688 | float minrange = GetSpellMinRange(srange); |
---|
| 1689 | float dist = GetDistance(pVictim); |
---|
| 1690 | //if(!isInFront( pVictim, range ) && spellInfo->AttributesEx ) |
---|
| 1691 | // continue; |
---|
| 1692 | if( dist > range || dist < minrange ) |
---|
| 1693 | continue; |
---|
| 1694 | if(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED)) |
---|
| 1695 | continue; |
---|
| 1696 | return spellInfo; |
---|
| 1697 | } |
---|
| 1698 | return NULL; |
---|
| 1699 | } |
---|
| 1700 | |
---|
| 1701 | bool Creature::IsVisibleInGridForPlayer(Player* pl) const |
---|
| 1702 | { |
---|
| 1703 | // gamemaster in GM mode see all, including ghosts |
---|
| 1704 | if(pl->isGameMaster()) |
---|
| 1705 | return true; |
---|
| 1706 | |
---|
| 1707 | // Live player (or with not release body see live creatures or death creatures with corpse disappearing time > 0 |
---|
| 1708 | if(pl->isAlive() || pl->GetDeathTimer() > 0) |
---|
| 1709 | { |
---|
| 1710 | if( GetEntry() == VISUAL_WAYPOINT && !pl->isGameMaster() ) |
---|
| 1711 | return false; |
---|
| 1712 | return isAlive() || m_deathTimer > 0 || m_isDeadByDefault && m_deathState==CORPSE; |
---|
| 1713 | } |
---|
| 1714 | |
---|
| 1715 | // Dead player see live creatures near own corpse |
---|
| 1716 | if(isAlive()) |
---|
| 1717 | { |
---|
| 1718 | Corpse *corpse = pl->GetCorpse(); |
---|
| 1719 | if(corpse) |
---|
| 1720 | { |
---|
| 1721 | // 20 - aggro distance for same level, 25 - max additional distance if player level less that creature level |
---|
| 1722 | if(corpse->IsWithinDistInMap(this,(20+25)*sWorld.getRate(RATE_CREATURE_AGGRO))) |
---|
| 1723 | return true; |
---|
| 1724 | } |
---|
| 1725 | } |
---|
| 1726 | |
---|
| 1727 | // Dead player see Spirit Healer or Spirit Guide |
---|
| 1728 | if(isSpiritService()) |
---|
| 1729 | return true; |
---|
| 1730 | |
---|
| 1731 | // and not see any other |
---|
| 1732 | return false; |
---|
| 1733 | } |
---|
| 1734 | |
---|
| 1735 | void Creature::DoFleeToGetAssistance(float radius) // Optional parameter |
---|
| 1736 | { |
---|
| 1737 | if (!getVictim()) |
---|
| 1738 | return; |
---|
| 1739 | |
---|
| 1740 | Creature* pCreature = NULL; |
---|
| 1741 | |
---|
[44] | 1742 | CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); |
---|
[37] | 1743 | Cell cell(p); |
---|
| 1744 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
| 1745 | cell.SetNoCreate(); |
---|
| 1746 | |
---|
[44] | 1747 | Trinity::NearestAssistCreatureInCreatureRangeCheck u_check(this,getVictim(),radius); |
---|
| 1748 | Trinity::CreatureLastSearcher<Trinity::NearestAssistCreatureInCreatureRangeCheck> searcher(pCreature, u_check); |
---|
[37] | 1749 | |
---|
[44] | 1750 | TypeContainerVisitor<Trinity::CreatureLastSearcher<Trinity::NearestAssistCreatureInCreatureRangeCheck>, GridTypeMapContainer > grid_creature_searcher(searcher); |
---|
[37] | 1751 | |
---|
| 1752 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
| 1753 | cell_lock->Visit(cell_lock, grid_creature_searcher, *(GetMap())); |
---|
| 1754 | |
---|
| 1755 | if(!GetMotionMaster()->empty() && (GetMotionMaster()->GetCurrentMovementGeneratorType() != POINT_MOTION_TYPE)) |
---|
| 1756 | GetMotionMaster()->Clear(false); |
---|
| 1757 | if(pCreature == NULL) |
---|
| 1758 | { |
---|
| 1759 | GetMotionMaster()->MoveIdle(); |
---|
| 1760 | GetMotionMaster()->MoveFleeing(getVictim()); |
---|
| 1761 | } |
---|
| 1762 | else |
---|
| 1763 | { |
---|
| 1764 | GetMotionMaster()->MoveIdle(); |
---|
| 1765 | GetMotionMaster()->MovePoint(0,pCreature->GetPositionX(),pCreature->GetPositionY(),pCreature->GetPositionZ()); |
---|
| 1766 | } |
---|
| 1767 | } |
---|
| 1768 | |
---|
| 1769 | void Creature::CallAssistence() |
---|
| 1770 | { |
---|
| 1771 | if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed()) |
---|
| 1772 | { |
---|
| 1773 | SetNoCallAssistence(true); |
---|
| 1774 | |
---|
| 1775 | float radius = sWorld.getConfig(CONFIG_CREATURE_FAMILY_ASSISTEMCE_RADIUS); |
---|
| 1776 | if(radius > 0) |
---|
| 1777 | { |
---|
| 1778 | std::list<Creature*> assistList; |
---|
| 1779 | |
---|
| 1780 | { |
---|
[44] | 1781 | CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); |
---|
[37] | 1782 | Cell cell(p); |
---|
| 1783 | cell.data.Part.reserved = ALL_DISTRICT; |
---|
| 1784 | cell.SetNoCreate(); |
---|
| 1785 | |
---|
[44] | 1786 | Trinity::AnyAssistCreatureInRangeCheck u_check(this, getVictim(), radius); |
---|
| 1787 | Trinity::CreatureListSearcher<Trinity::AnyAssistCreatureInRangeCheck> searcher(assistList, u_check); |
---|
[37] | 1788 | |
---|
[44] | 1789 | TypeContainerVisitor<Trinity::CreatureListSearcher<Trinity::AnyAssistCreatureInRangeCheck>, GridTypeMapContainer > grid_creature_searcher(searcher); |
---|
[37] | 1790 | |
---|
| 1791 | CellLock<GridReadGuard> cell_lock(cell, p); |
---|
| 1792 | cell_lock->Visit(cell_lock, grid_creature_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); |
---|
| 1793 | } |
---|
| 1794 | |
---|
| 1795 | for(std::list<Creature*>::iterator iter = assistList.begin(); iter != assistList.end(); ++iter) |
---|
| 1796 | { |
---|
| 1797 | (*iter)->SetNoCallAssistence(true); |
---|
| 1798 | if((*iter)->AI()) |
---|
| 1799 | (*iter)->AI()->AttackStart(getVictim()); |
---|
| 1800 | } |
---|
| 1801 | } |
---|
| 1802 | } |
---|
| 1803 | } |
---|
| 1804 | |
---|
| 1805 | void Creature::SaveRespawnTime() |
---|
| 1806 | { |
---|
| 1807 | if(isPet() || !m_DBTableGuid) |
---|
| 1808 | return; |
---|
| 1809 | |
---|
| 1810 | if(m_respawnTime > time(NULL)) // dead (no corpse) |
---|
| 1811 | objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),m_respawnTime); |
---|
| 1812 | else if(m_deathTimer > 0) // dead (corpse) |
---|
| 1813 | objmgr.SaveCreatureRespawnTime(m_DBTableGuid,GetInstanceId(),time(NULL)+m_respawnDelay+m_deathTimer/1000); |
---|
| 1814 | } |
---|
| 1815 | |
---|
| 1816 | bool Creature::IsOutOfThreatArea(Unit* pVictim) const |
---|
| 1817 | { |
---|
| 1818 | if(!pVictim) |
---|
| 1819 | return true; |
---|
| 1820 | |
---|
| 1821 | if(!pVictim->IsInMap(this)) |
---|
| 1822 | return true; |
---|
| 1823 | |
---|
| 1824 | if(!pVictim->isTargetableForAttack()) |
---|
| 1825 | return true; |
---|
| 1826 | |
---|
| 1827 | if(!pVictim->isInAccessablePlaceFor(this)) |
---|
| 1828 | return true; |
---|
| 1829 | |
---|
| 1830 | if(sMapStore.LookupEntry(GetMapId())->Instanceable()) |
---|
| 1831 | return false; |
---|
| 1832 | |
---|
| 1833 | float length = pVictim->GetDistance(CombatStartX,CombatStartY,CombatStartZ); |
---|
| 1834 | float AttackDist = GetAttackDistance(pVictim); |
---|
| 1835 | uint32 ThreatRadius = sWorld.getConfig(CONFIG_THREAT_RADIUS); |
---|
| 1836 | |
---|
| 1837 | //Use AttackDistance in distance check if threat radius is lower. This prevents creature bounce in and ouf of combat every update tick. |
---|
| 1838 | return ( length > (ThreatRadius > AttackDist ? ThreatRadius : AttackDist)); |
---|
| 1839 | } |
---|
| 1840 | |
---|
| 1841 | CreatureDataAddon const* Creature::GetCreatureAddon() const |
---|
| 1842 | { |
---|
| 1843 | if (m_DBTableGuid) |
---|
| 1844 | { |
---|
| 1845 | if(CreatureDataAddon const* addon = ObjectMgr::GetCreatureAddon(m_DBTableGuid)) |
---|
| 1846 | return addon; |
---|
| 1847 | } |
---|
| 1848 | |
---|
| 1849 | // dependent from heroic mode entry |
---|
| 1850 | return ObjectMgr::GetCreatureTemplateAddon(GetCreatureInfo()->Entry); |
---|
| 1851 | } |
---|
| 1852 | |
---|
| 1853 | //creature_addon table |
---|
| 1854 | bool Creature::LoadCreaturesAddon(bool reload) |
---|
| 1855 | { |
---|
| 1856 | CreatureDataAddon const *cainfo = GetCreatureAddon(); |
---|
| 1857 | if(!cainfo) |
---|
| 1858 | return false; |
---|
| 1859 | |
---|
| 1860 | if (cainfo->mount != 0) |
---|
| 1861 | Mount(cainfo->mount); |
---|
| 1862 | |
---|
| 1863 | if (cainfo->bytes0 != 0) |
---|
| 1864 | SetUInt32Value(UNIT_FIELD_BYTES_0, cainfo->bytes0); |
---|
| 1865 | |
---|
| 1866 | if (cainfo->bytes1 != 0) |
---|
| 1867 | SetUInt32Value(UNIT_FIELD_BYTES_1, cainfo->bytes1); |
---|
| 1868 | |
---|
| 1869 | if (cainfo->bytes2 != 0) |
---|
| 1870 | SetUInt32Value(UNIT_FIELD_BYTES_2, cainfo->bytes2); |
---|
| 1871 | |
---|
| 1872 | if (cainfo->emote != 0) |
---|
| 1873 | SetUInt32Value(UNIT_NPC_EMOTESTATE, cainfo->emote); |
---|
| 1874 | |
---|
| 1875 | if (cainfo->move_flags != 0) |
---|
| 1876 | SetUnitMovementFlags(cainfo->move_flags); |
---|
| 1877 | |
---|
| 1878 | if(cainfo->auras) |
---|
| 1879 | { |
---|
| 1880 | for (CreatureDataAddonAura const* cAura = cainfo->auras; cAura->spell_id; ++cAura) |
---|
| 1881 | { |
---|
| 1882 | SpellEntry const *AdditionalSpellInfo = sSpellStore.LookupEntry(cAura->spell_id); |
---|
| 1883 | if (!AdditionalSpellInfo) |
---|
| 1884 | { |
---|
| 1885 | sLog.outErrorDb("Creature (GUIDLow: %u Entry: %u ) has wrong spell %u defined in `auras` field.",GetGUIDLow(),GetEntry(),cAura->spell_id); |
---|
| 1886 | continue; |
---|
| 1887 | } |
---|
| 1888 | |
---|
| 1889 | // skip already applied aura |
---|
| 1890 | if(HasAura(cAura->spell_id,cAura->effect_idx)) |
---|
| 1891 | { |
---|
| 1892 | if(!reload) |
---|
| 1893 | 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); |
---|
| 1894 | |
---|
| 1895 | continue; |
---|
| 1896 | } |
---|
| 1897 | |
---|
| 1898 | Aura* AdditionalAura = CreateAura(AdditionalSpellInfo, cAura->effect_idx, NULL, this, this, 0); |
---|
| 1899 | AddAura(AdditionalAura); |
---|
| 1900 | sLog.outDebug("Spell: %u with Aura %u added to creature (GUIDLow: %u Entry: %u )", cAura->spell_id, AdditionalSpellInfo->EffectApplyAuraName[0],GetGUIDLow(),GetEntry()); |
---|
| 1901 | } |
---|
| 1902 | } |
---|
| 1903 | return true; |
---|
| 1904 | } |
---|
| 1905 | |
---|
| 1906 | /// Send a message to LocalDefense channel for players oposition team in the zone |
---|
| 1907 | void Creature::SendZoneUnderAttackMessage(Player* attacker) |
---|
| 1908 | { |
---|
| 1909 | uint32 enemy_team = attacker->GetTeam(); |
---|
| 1910 | |
---|
| 1911 | WorldPacket data(SMSG_ZONE_UNDER_ATTACK,4); |
---|
| 1912 | data << (uint32)GetZoneId(); |
---|
| 1913 | sWorld.SendGlobalMessage(&data,NULL,(enemy_team==ALLIANCE ? HORDE : ALLIANCE)); |
---|
| 1914 | } |
---|
| 1915 | |
---|
| 1916 | void Creature::_AddCreatureSpellCooldown(uint32 spell_id, time_t end_time) |
---|
| 1917 | { |
---|
| 1918 | m_CreatureSpellCooldowns[spell_id] = end_time; |
---|
| 1919 | } |
---|
| 1920 | |
---|
| 1921 | void Creature::_AddCreatureCategoryCooldown(uint32 category, time_t apply_time) |
---|
| 1922 | { |
---|
| 1923 | m_CreatureCategoryCooldowns[category] = apply_time; |
---|
| 1924 | } |
---|
| 1925 | |
---|
| 1926 | void Creature::AddCreatureSpellCooldown(uint32 spellid) |
---|
| 1927 | { |
---|
| 1928 | SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid); |
---|
| 1929 | if(!spellInfo) |
---|
| 1930 | return; |
---|
| 1931 | |
---|
| 1932 | uint32 cooldown = GetSpellRecoveryTime(spellInfo); |
---|
| 1933 | if(cooldown) |
---|
| 1934 | _AddCreatureSpellCooldown(spellid, time(NULL) + cooldown/1000); |
---|
| 1935 | |
---|
| 1936 | if(spellInfo->Category) |
---|
| 1937 | _AddCreatureCategoryCooldown(spellInfo->Category, time(NULL)); |
---|
| 1938 | |
---|
| 1939 | m_GlobalCooldown = spellInfo->StartRecoveryTime; |
---|
| 1940 | } |
---|
| 1941 | |
---|
| 1942 | bool Creature::HasCategoryCooldown(uint32 spell_id) const |
---|
| 1943 | { |
---|
| 1944 | SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id); |
---|
| 1945 | if(!spellInfo) |
---|
| 1946 | return false; |
---|
| 1947 | |
---|
| 1948 | // check global cooldown if spell affected by it |
---|
| 1949 | if (spellInfo->StartRecoveryCategory > 0 && m_GlobalCooldown > 0) |
---|
| 1950 | return true; |
---|
| 1951 | |
---|
| 1952 | CreatureSpellCooldowns::const_iterator itr = m_CreatureCategoryCooldowns.find(spellInfo->Category); |
---|
| 1953 | return(itr != m_CreatureCategoryCooldowns.end() && time_t(itr->second + (spellInfo->CategoryRecoveryTime / 1000)) > time(NULL)); |
---|
| 1954 | } |
---|
| 1955 | |
---|
| 1956 | bool Creature::HasSpellCooldown(uint32 spell_id) const |
---|
| 1957 | { |
---|
| 1958 | CreatureSpellCooldowns::const_iterator itr = m_CreatureSpellCooldowns.find(spell_id); |
---|
| 1959 | return (itr != m_CreatureSpellCooldowns.end() && itr->second > time(NULL)) || HasCategoryCooldown(spell_id); |
---|
| 1960 | } |
---|
| 1961 | |
---|
| 1962 | bool Creature::IsInEvadeMode() const |
---|
| 1963 | { |
---|
| 1964 | return !i_motionMaster.empty() && i_motionMaster.GetCurrentMovementGeneratorType() == HOME_MOTION_TYPE; |
---|
| 1965 | } |
---|
| 1966 | |
---|
| 1967 | bool Creature::HasSpell(uint32 spellID) const |
---|
| 1968 | { |
---|
| 1969 | uint8 i; |
---|
| 1970 | for(i = 0; i < CREATURE_MAX_SPELLS; ++i) |
---|
| 1971 | if(spellID == m_spells[i]) |
---|
| 1972 | break; |
---|
| 1973 | return i < CREATURE_MAX_SPELLS; //broke before end of iteration of known spells |
---|
| 1974 | } |
---|
| 1975 | |
---|
| 1976 | time_t Creature::GetRespawnTimeEx() const |
---|
| 1977 | { |
---|
| 1978 | time_t now = time(NULL); |
---|
| 1979 | if(m_respawnTime > now) // dead (no corpse) |
---|
| 1980 | return m_respawnTime; |
---|
| 1981 | else if(m_deathTimer > 0) // dead (corpse) |
---|
| 1982 | return now+m_respawnDelay+m_deathTimer/1000; |
---|
| 1983 | else |
---|
| 1984 | return now; |
---|
| 1985 | } |
---|
| 1986 | |
---|
| 1987 | void Creature::GetRespawnCoord( float &x, float &y, float &z, float* ori, float* dist ) const |
---|
| 1988 | { |
---|
| 1989 | if (m_DBTableGuid) |
---|
| 1990 | { |
---|
| 1991 | if (CreatureData const* data = objmgr.GetCreatureData(GetDBTableGUIDLow())) |
---|
| 1992 | { |
---|
| 1993 | x = data->posX; |
---|
| 1994 | y = data->posY; |
---|
| 1995 | z = data->posZ; |
---|
| 1996 | if(ori) |
---|
| 1997 | *ori = data->orientation; |
---|
| 1998 | if(dist) |
---|
| 1999 | *dist = data->spawndist; |
---|
| 2000 | |
---|
| 2001 | return; |
---|
| 2002 | } |
---|
| 2003 | } |
---|
| 2004 | |
---|
| 2005 | x = GetPositionX(); |
---|
| 2006 | y = GetPositionY(); |
---|
| 2007 | z = GetPositionZ(); |
---|
| 2008 | if(ori) |
---|
| 2009 | *ori = GetOrientation(); |
---|
| 2010 | if(dist) |
---|
| 2011 | *dist = 0; |
---|
| 2012 | } |
---|
| 2013 | |
---|
| 2014 | void Creature::AllLootRemovedFromCorpse() |
---|
| 2015 | { |
---|
| 2016 | if (!HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE)) |
---|
| 2017 | { |
---|
| 2018 | uint32 nDeathTimer; |
---|
| 2019 | |
---|
| 2020 | CreatureInfo const *cinfo = GetCreatureInfo(); |
---|
| 2021 | |
---|
| 2022 | // corpse was not skinnable -> apply corpse looted timer |
---|
| 2023 | if (!cinfo || !cinfo->SkinLootId) |
---|
| 2024 | nDeathTimer = (uint32)((m_corpseDelay * 1000) * sWorld.getRate(RATE_CORPSE_DECAY_LOOTED)); |
---|
| 2025 | // corpse skinnable, but without skinning flag, and then skinned, corpse will despawn next update |
---|
| 2026 | else |
---|
| 2027 | nDeathTimer = 0; |
---|
| 2028 | |
---|
| 2029 | // update death timer only if looted timer is shorter |
---|
| 2030 | if (m_deathTimer > nDeathTimer) |
---|
| 2031 | m_deathTimer = nDeathTimer; |
---|
| 2032 | } |
---|
| 2033 | } |
---|
| 2034 | |
---|
| 2035 | uint32 Creature::getLevelForTarget( Unit const* target ) const |
---|
| 2036 | { |
---|
| 2037 | if(!isWorldBoss()) |
---|
| 2038 | return Unit::getLevelForTarget(target); |
---|
| 2039 | |
---|
| 2040 | uint32 level = target->getLevel()+sWorld.getConfig(CONFIG_WORLD_BOSS_LEVEL_DIFF); |
---|
| 2041 | if(level < 1) |
---|
| 2042 | return 1; |
---|
| 2043 | if(level > 255) |
---|
| 2044 | return 255; |
---|
| 2045 | return level; |
---|
| 2046 | } |
---|
| 2047 | |
---|
| 2048 | char const* Creature::GetScriptName() const |
---|
| 2049 | { |
---|
| 2050 | return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptName; |
---|
| 2051 | } |
---|
| 2052 | |
---|
| 2053 | VendorItemData const* Creature::GetVendorItems() const |
---|
| 2054 | { |
---|
| 2055 | return objmgr.GetNpcVendorItemList(GetEntry()); |
---|
| 2056 | } |
---|
| 2057 | |
---|
| 2058 | uint32 Creature::GetVendorItemCurrentCount(VendorItem const* vItem) |
---|
| 2059 | { |
---|
| 2060 | if(!vItem->maxcount) |
---|
| 2061 | return vItem->maxcount; |
---|
| 2062 | |
---|
| 2063 | VendorItemCounts::iterator itr = m_vendorItemCounts.begin(); |
---|
| 2064 | for(; itr != m_vendorItemCounts.end(); ++itr) |
---|
| 2065 | if(itr->itemId==vItem->item) |
---|
| 2066 | break; |
---|
| 2067 | |
---|
| 2068 | if(itr == m_vendorItemCounts.end()) |
---|
| 2069 | return vItem->maxcount; |
---|
| 2070 | |
---|
| 2071 | VendorItemCount* vCount = &*itr; |
---|
| 2072 | |
---|
| 2073 | time_t ptime = time(NULL); |
---|
| 2074 | |
---|
| 2075 | if( vCount->lastIncrementTime + vItem->incrtime <= ptime ) |
---|
| 2076 | { |
---|
| 2077 | ItemPrototype const* pProto = objmgr.GetItemPrototype(vItem->item); |
---|
| 2078 | |
---|
| 2079 | uint32 diff = uint32((ptime - vCount->lastIncrementTime)/vItem->incrtime); |
---|
| 2080 | if((vCount->count + diff * pProto->BuyCount) >= vItem->maxcount ) |
---|
| 2081 | { |
---|
[161] | 2082 | m_vendorItemCounts.erase(itr); |
---|
[37] | 2083 | return vItem->maxcount; |
---|
| 2084 | } |
---|
| 2085 | |
---|
| 2086 | vCount->count += diff * pProto->BuyCount; |
---|
| 2087 | vCount->lastIncrementTime = ptime; |
---|
| 2088 | } |
---|
| 2089 | |
---|
| 2090 | return vCount->count; |
---|
| 2091 | } |
---|
| 2092 | |
---|
| 2093 | uint32 Creature::UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 used_count) |
---|
| 2094 | { |
---|
| 2095 | if(!vItem->maxcount) |
---|
| 2096 | return 0; |
---|
| 2097 | |
---|
| 2098 | VendorItemCounts::iterator itr = m_vendorItemCounts.begin(); |
---|
| 2099 | for(; itr != m_vendorItemCounts.end(); ++itr) |
---|
| 2100 | if(itr->itemId==vItem->item) |
---|
| 2101 | break; |
---|
| 2102 | |
---|
| 2103 | if(itr == m_vendorItemCounts.end()) |
---|
| 2104 | { |
---|
| 2105 | uint32 new_count = vItem->maxcount > used_count ? vItem->maxcount-used_count : 0; |
---|
| 2106 | m_vendorItemCounts.push_back(VendorItemCount(vItem->item,new_count)); |
---|
| 2107 | return new_count; |
---|
| 2108 | } |
---|
| 2109 | |
---|
| 2110 | VendorItemCount* vCount = &*itr; |
---|
| 2111 | |
---|
| 2112 | time_t ptime = time(NULL); |
---|
| 2113 | |
---|
| 2114 | if( vCount->lastIncrementTime + vItem->incrtime <= ptime ) |
---|
| 2115 | { |
---|
| 2116 | ItemPrototype const* pProto = objmgr.GetItemPrototype(vItem->item); |
---|
| 2117 | |
---|
| 2118 | uint32 diff = uint32((ptime - vCount->lastIncrementTime)/vItem->incrtime); |
---|
| 2119 | if((vCount->count + diff * pProto->BuyCount) < vItem->maxcount ) |
---|
| 2120 | vCount->count += diff * pProto->BuyCount; |
---|
| 2121 | else |
---|
| 2122 | vCount->count = vItem->maxcount; |
---|
| 2123 | } |
---|
| 2124 | |
---|
| 2125 | vCount->count = vCount->count > used_count ? vCount->count-used_count : 0; |
---|
| 2126 | vCount->lastIncrementTime = ptime; |
---|
| 2127 | return vCount->count; |
---|
| 2128 | } |
---|
| 2129 | |
---|
| 2130 | TrainerSpellData const* Creature::GetTrainerSpells() const |
---|
| 2131 | { |
---|
| 2132 | return objmgr.GetNpcTrainerSpells(GetEntry()); |
---|
| 2133 | } |
---|