From 9bcb0119e99dcda295db70106c56a51f26fd53fc Mon Sep 17 00:00:00 2001 From: megamage Date: Sun, 16 Nov 2008 16:56:35 -0600 Subject: *Fix Gruul's shatter effect damage. Patch provided by _krz. --HG-- branch : trunk --- src/game/GameObject.cpp | 2 +- src/game/SpellEffects.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index 75a1f9be985..f6f89f482e5 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -1280,7 +1280,7 @@ void GameObject::CastSpell(Unit* target, uint32 spell) else { trigger->setFaction(14); - trigger->CastSpell(target, spell, true); + trigger->CastSpell(target, spell, true, 0, 0, target->GetGUID()); } //trigger->setDeathState(JUST_DIED); //trigger->RemoveCorpse(); diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index f32a89db2b4..2c663e90212 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -333,13 +333,26 @@ void Spell::EffectSchoolDMG(uint32 effect_idx) damage = 200; break; } - // must only affect demons + // must only affect demons (also undead?) case 45072: { - if(unitTarget->GetCreatureType() != CREATURE_TYPE_DEMON) + if(unitTarget->GetCreatureType() != CREATURE_TYPE_DEMON + || unitTarget->GetCreatureType() != CREATURE_TYPE_UNDEAD) return; break; } + // gruul's shatter + case 33671: + { + // don't damage self and only players + if(unitTarget->GetGUID() == m_caster->GetGUID() || unitTarget->GetTypeId() != TYPEID_PLAYER) + return; + + float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[0])); + if(!radius) return; + float distance = m_caster->GetDistance2d(unitTarget); + damage = (distance > radius ) ? 0 : (int32)(m_spellInfo->EffectBasePoints[0]*((radius - distance)/radius)); + }break; } break; } @@ -2637,6 +2650,7 @@ void Spell::EffectPersistentAA(uint32 i) { float radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(m_spellInfo->EffectRadiusIndex[i])); Unit *caster = m_originalCasterGUID ? m_originalCaster : m_caster; + if(!caster) return; if(Player* modOwner = caster->GetSpellModOwner()) modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius); -- cgit v1.2.3 From c95cb1003a949a706949db63a3eaace955459899 Mon Sep 17 00:00:00 2001 From: megamage Date: Sun, 16 Nov 2008 17:42:29 -0600 Subject: *Do not let CC spells interrupt themselves. --HG-- branch : trunk --- src/game/Spell.cpp | 3 +++ src/game/Unit.cpp | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 64e9ba04bcc..da6d67a3c6c 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -996,6 +996,9 @@ void Spell::DoSpellHitOnUnit(Unit *unit, const uint32 effectMask) } unit->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_HITBYSPELL); + //TODO: find a better way to judge CC auras + if(m_spellInfo->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) + unit->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CC); } else { diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index ade913d8c26..a6dae99b7ef 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -3782,7 +3782,6 @@ bool Unit::AddAura(Aura *Aur) if(Aur->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) { m_ccAuras.push_back(Aur); - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CC); } } -- cgit v1.2.3 From 363e526baa95e22bc0cdaabb140a002af0f196c6 Mon Sep 17 00:00:00 2001 From: w12x Date: Mon, 17 Nov 2008 23:39:24 +0100 Subject: Fixed I64FMTD define for non-microsoft compilers. This should fix phased events state not being saved on some systems. --HG-- branch : trunk --- src/shared/Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/shared/Common.h b/src/shared/Common.h index 9bf44b78f16..d5c2eedfc5c 100644 --- a/src/shared/Common.h +++ b/src/shared/Common.h @@ -146,7 +146,7 @@ #define stricmp strcasecmp #define strnicmp strncasecmp #define I64FMT "%016llX" -#define I64FMTD "%llu" +#define I64FMTD "%I64u" #define SI64FMTD "%lld" #endif -- cgit v1.2.3 From 474dc08c465b3360a9f578a0df65bb8d2feb9fcd Mon Sep 17 00:00:00 2001 From: megamage Date: Mon, 17 Nov 2008 17:59:33 -0600 Subject: *Update aura stacking check. By QAston. *Update pet autocast check. By qubix. --HG-- branch : trunk --- src/game/Pet.cpp | 3554 +++---- src/game/Pet.h | 528 +- src/game/SharedDefines.h | 2 +- src/game/SpellMgr.cpp | 4197 ++++---- src/game/SpellMgr.h | 1797 ++-- src/game/Unit.cpp | 21657 +++++++++++++++++++------------------- win/TrinityCore&Script VC80.sln | 302 +- win/TrinityCore&Script VC90.sln | 302 +- 8 files changed, 16179 insertions(+), 16160 deletions(-) (limited to 'src') diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 9bf67fae2c1..e9082221450 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -1,1773 +1,1781 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "Common.h" -#include "Database/DatabaseEnv.h" -#include "Log.h" -#include "WorldSession.h" -#include "WorldPacket.h" -#include "ObjectMgr.h" -#include "SpellMgr.h" -#include "Pet.h" -#include "MapManager.h" -#include "Formulas.h" -#include "SpellAuras.h" -#include "CreatureAI.h" -#include "Unit.h" -#include "Util.h" - -char const* petTypeSuffix[MAX_PET_TYPE] = -{ - "'s Minion", // SUMMON_PET - "'s Pet", // HUNTER_PET - "'s Guardian", // GUARDIAN_PET - "'s Companion" // MINI_PET -}; - -//numbers represent minutes * 100 while happy (you get 100 loyalty points per min while happy) -uint32 const LevelUpLoyalty[6] = -{ - 5500, - 11500, - 17000, - 23500, - 31000, - 39500, -}; - -uint32 const LevelStartLoyalty[6] = -{ - 2000, - 4500, - 7000, - 10000, - 13500, - 17500, -}; - -Pet::Pet(PetType type) : Creature() -{ - m_isPet = true; - m_name = "Pet"; - m_petType = type; - - m_removed = false; - m_regenTimer = 4000; - m_happinessTimer = 7500; - m_loyaltyTimer = 12000; - m_duration = 0; - m_bonusdamage = 0; - - m_loyaltyPoints = 0; - m_TrainingPoints = 0; - m_resetTalentsCost = 0; - m_resetTalentsTime = 0; - - m_auraUpdateMask = 0; - - // pets always have a charminfo, even if they are not actually charmed - CharmInfo* charmInfo = InitCharmInfo(this); - - if(type == MINI_PET) // always passive - charmInfo->SetReactState(REACT_PASSIVE); - else if(type == GUARDIAN_PET) // always aggressive - charmInfo->SetReactState(REACT_AGGRESSIVE); - - m_spells.clear(); - m_Auras.clear(); - m_CreatureSpellCooldowns.clear(); - m_CreatureCategoryCooldowns.clear(); - m_autospells.clear(); - m_declinedname = NULL; - m_isActive = true; -} - -Pet::~Pet() -{ - if(m_uint32Values) // only for fully created Object - { - for (PetSpellMap::iterator i = m_spells.begin(); i != m_spells.end(); ++i) - delete i->second; - ObjectAccessor::Instance().RemoveObject(this); - } - - delete m_declinedname; -} - -void Pet::AddToWorld() -{ - ///- Register the pet for guid lookup - if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); - Unit::AddToWorld(); -} - -void Pet::RemoveFromWorld() -{ - ///- Remove the pet from the accessor - if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); - ///- Don't call the function for Creature, normal mobs + totems go in a different storage - Unit::RemoveFromWorld(); -} - -bool Pet::LoadPetFromDB( Unit* owner, uint32 petentry, uint32 petnumber, bool current ) -{ - uint32 ownerid = owner->GetGUIDLow(); - - QueryResult *result; - - if(petnumber) - // known petnumber entry 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND id = '%u'",ownerid, petnumber); - else if(current) - // current pet (slot 0) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND slot = '0'",ownerid ); - else if(petentry) - // known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets) - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND entry = '%u' AND (slot = '0' OR slot = '3') ",ownerid, petentry ); - else - // any current or other non-stabled pet (for hunter "call pet") - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3') ",ownerid); - - if(!result) - return false; - - Field *fields = result->Fetch(); - - // update for case of current pet "slot = 0" - petentry = fields[1].GetUInt32(); - if(!petentry) - { - delete result; - return false; - } - - uint32 summon_spell_id = fields[21].GetUInt32(); - SpellEntry const* spellInfo = sSpellStore.LookupEntry(summon_spell_id); - - bool is_temporary_summoned = spellInfo && GetSpellDuration(spellInfo) > 0; - - // check temporary summoned pets like mage water elemental - if(current && is_temporary_summoned) - { - delete result; - return false; - } - - Map *map = owner->GetMap(); - uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); - uint32 pet_number = fields[0].GetUInt32(); - if(!Create(guid, map, petentry, pet_number)) - { - delete result; - return false; - } - - float px, py, pz; - owner->GetClosePoint(px, py, pz,GetObjectSize(),PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); - - Relocate(px, py, pz, owner->GetOrientation()); - - if(!IsPositionValid()) - { - sLog.outError("ERROR: Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)", - GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); - delete result; - return false; - } - - setPetType(PetType(fields[22].GetUInt8())); - SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction()); - SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id); - - CreatureInfo const *cinfo = GetCreatureInfo(); - if(cinfo->type == CREATURE_TYPE_CRITTER) - { - AIM_Initialize(); - map->Add((Creature*)this); - delete result; - return true; - } - if(getPetType()==HUNTER_PET || (getPetType()==SUMMON_PET && cinfo->type == CREATURE_TYPE_DEMON && owner->getClass() == CLASS_WARLOCK)) - m_charmInfo->SetPetNumber(pet_number, true); - else - m_charmInfo->SetPetNumber(pet_number, false); - SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID()); - SetDisplayId(fields[3].GetUInt32()); - SetNativeDisplayId(fields[3].GetUInt32()); - uint32 petlevel=fields[4].GetUInt32(); - SetUInt32Value(UNIT_NPC_FLAGS , 0); - SetName(fields[11].GetString()); - - switch(getPetType()) - { - - case SUMMON_PET: - petlevel=owner->getLevel(); - - SetUInt32Value(UNIT_FIELD_BYTES_0,2048); - SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - // this enables popup window (pet dismiss, cancel) - break; - case HUNTER_PET: - SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); - SetByteValue(UNIT_FIELD_BYTES_1, 1, fields[8].GetUInt32()); - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); - SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); - - if(fields[12].GetBool()) - SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED); - else - SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); - - SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - // this enables popup window (pet abandon, cancel) - SetTP(fields[9].GetInt32()); - SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - SetPower( POWER_HAPPINESS,fields[15].GetUInt32()); - setPowerType(POWER_FOCUS); - break; - default: - sLog.outError("Pet have incorrect type (%u) for pet loading.",getPetType()); - } - InitStatsForLevel( petlevel); - SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32()); - SetUInt64Value(UNIT_FIELD_CREATEDBY, owner->GetGUID()); - - m_charmInfo->SetReactState( ReactStates( fields[6].GetUInt8() )); - m_loyaltyPoints = fields[7].GetInt32(); - - uint32 savedhealth = fields[13].GetUInt32(); - uint32 savedmana = fields[14].GetUInt32(); - - // set current pet as current - if(fields[10].GetUInt32() != 0) - { - CharacterDatabase.BeginTransaction(); - CharacterDatabase.PExecute("UPDATE character_pet SET slot = '3' WHERE owner = '%u' AND slot = '0' AND id <> '%u'",ownerid, m_charmInfo->GetPetNumber()); - CharacterDatabase.PExecute("UPDATE character_pet SET slot = '0' WHERE owner = '%u' AND id = '%u'",ownerid, m_charmInfo->GetPetNumber()); - CharacterDatabase.CommitTransaction(); - } - - if(!is_temporary_summoned) - { - // permanent controlled pets store state in DB - Tokens tokens = StrSplit(fields[16].GetString(), " "); - - if(tokens.size() != 20) - { - delete result; - return false; - } - - int index; - Tokens::iterator iter; - for(iter = tokens.begin(), index = 0; index < 10; ++iter, ++index ) - { - m_charmInfo->GetActionBarEntry(index)->Type = atol((*iter).c_str()); - ++iter; - m_charmInfo->GetActionBarEntry(index)->SpellOrAction = atol((*iter).c_str()); - } - - //init teach spells - tokens = StrSplit(fields[17].GetString(), " "); - for (iter = tokens.begin(), index = 0; index < 4; ++iter, ++index) - { - uint32 tmp = atol((*iter).c_str()); - - ++iter; - - if(tmp) - AddTeachSpell(tmp, atol((*iter).c_str())); - else - break; - } - } - - // since last save (in seconds) - uint32 timediff = (time(NULL) - fields[18].GetUInt32()); - - delete result; - - //load spells/cooldowns/auras - SetCanModifyStats(true); - _LoadAuras(timediff); - - //init AB - if(is_temporary_summoned) - { - // Temporary summoned pets always have initial spell list at load - InitPetCreateSpells(); - } - else - { - LearnPetPassives(); - CastPetAuras(current); - } - - if(getPetType() == SUMMON_PET && !current) //all (?) summon pets come with full health when called, but not when they are current - { - SetHealth(GetMaxHealth()); - SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); - } - else - { - SetHealth(savedhealth > GetMaxHealth() ? GetMaxHealth() : savedhealth); - SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana); - } - - AIM_Initialize(); - map->Add((Creature*)this); - - // Spells should be loaded after pet is added to map, because in CanCast is check on it - _LoadSpells(); - _LoadSpellCooldowns(); - - owner->SetPet(this); // in DB stored only full controlled creature - sLog.outDebug("New Pet has guid %u", GetGUIDLow()); - - if(owner->GetTypeId() == TYPEID_PLAYER) - { - ((Player*)owner)->PetSpellInitialize(); - if(((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_PET); - } - - if(owner->GetTypeId() == TYPEID_PLAYER && getPetType() == HUNTER_PET) - { - result = CharacterDatabase.PQuery("SELECT genitive, dative, accusative, instrumental, prepositional FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'",owner->GetGUIDLow(),GetCharmInfo()->GetPetNumber()); - - if(result) - { - if(m_declinedname) - delete m_declinedname; - - m_declinedname = new DeclinedName; - Field *fields = result->Fetch(); - for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) - { - m_declinedname->name[i] = fields[i].GetCppString(); - } - } - } - - return true; -} - -void Pet::SavePetToDB(PetSaveMode mode) -{ - if(!GetEntry()) - return; - - // save only fully controlled creature - if(!isControlled()) - return; - - uint32 curhealth = GetHealth(); - uint32 curmana = GetPower(POWER_MANA); - - switch(mode) - { - case PET_SAVE_IN_STABLE_SLOT_1: - case PET_SAVE_IN_STABLE_SLOT_2: - case PET_SAVE_NOT_IN_SLOT: - { - RemoveAllAuras(); - - //only alive hunter pets get auras saved, the others don't - if(!(getPetType() == HUNTER_PET && isAlive())) - m_Auras.clear(); - } - default: - break; - } - - _SaveSpells(); - _SaveSpellCooldowns(); - _SaveAuras(); - - switch(mode) - { - case PET_SAVE_AS_CURRENT: - case PET_SAVE_IN_STABLE_SLOT_1: - case PET_SAVE_IN_STABLE_SLOT_2: - case PET_SAVE_NOT_IN_SLOT: - { - uint32 loyalty =1; - if(getPetType()!=HUNTER_PET) - loyalty = GetLoyaltyLevel(); - - uint32 owner = GUID_LOPART(GetOwnerGUID()); - std::string name = m_name; - CharacterDatabase.escape_string(name); - CharacterDatabase.BeginTransaction(); - // remove current data - CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND id = '%u'", owner,m_charmInfo->GetPetNumber() ); - - // prevent duplicate using slot (except PET_SAVE_NOT_IN_SLOT) - if(mode!=PET_SAVE_NOT_IN_SLOT) - CharacterDatabase.PExecute("UPDATE character_pet SET slot = 3 WHERE owner = '%u' AND slot = '%u'", owner, uint32(mode) ); - - // prevent existence another hunter pet in PET_SAVE_AS_CURRENT and PET_SAVE_NOT_IN_SLOT - if(getPetType()==HUNTER_PET && (mode==PET_SAVE_AS_CURRENT||mode==PET_SAVE_NOT_IN_SLOT)) - CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3')", owner ); - // save pet - std::ostringstream ss; - ss << "INSERT INTO character_pet ( id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata,TeachSpelldata,savetime,resettalents_cost,resettalents_time,CreatedBySpell,PetType) " - << "VALUES (" - << m_charmInfo->GetPetNumber() << ", " - << GetEntry() << ", " - << owner << ", " - << GetNativeDisplayId() << ", " - << getLevel() << ", " - << GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ", " - << uint32(m_charmInfo->GetReactState()) << ", " - << m_loyaltyPoints << ", " - << GetLoyaltyLevel() << ", " - << m_TrainingPoints << ", " - << uint32(mode) << ", '" - << name.c_str() << "', " - << uint32((GetByteValue(UNIT_FIELD_BYTES_2, 2) == UNIT_RENAME_ALLOWED)?0:1) << ", " - << (curhealth<1?1:curhealth) << ", " - << curmana << ", " - << GetPower(POWER_HAPPINESS) << ", '"; - - for(uint32 i = 0; i < 10; i++) - ss << uint32(m_charmInfo->GetActionBarEntry(i)->Type) << " " << uint32(m_charmInfo->GetActionBarEntry(i)->SpellOrAction) << " "; - ss << "', '"; - - //save spells the pet can teach to it's Master - { - int i = 0; - for(TeachSpellMap::iterator itr = m_teachspells.begin(); i < 4 && itr != m_teachspells.end(); ++i, ++itr) - ss << itr->first << " " << itr->second << " "; - for(; i < 4; ++i) - ss << uint32(0) << " " << uint32(0) << " "; - } - - ss << "', " - << time(NULL) << ", " - << uint32(m_resetTalentsCost) << ", " - << uint64(m_resetTalentsTime) << ", " - << GetUInt32Value(UNIT_CREATED_BY_SPELL) << ", " - << uint32(getPetType()) << ")"; - - CharacterDatabase.Execute( ss.str().c_str() ); - - CharacterDatabase.CommitTransaction(); - break; - } - case PET_SAVE_AS_DELETED: - { - RemoveAllAuras(); - uint32 owner = GUID_LOPART(GetOwnerGUID()); - DeleteFromDB(m_charmInfo->GetPetNumber()); - break; - } - default: - sLog.outError("Unknown pet save/remove mode: %d",mode); - } -} - -void Pet::DeleteFromDB(uint32 guidlow) -{ - CharacterDatabase.PExecute("DELETE FROM character_pet WHERE id = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE id = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", guidlow); -} - -void Pet::setDeathState(DeathState s) // overwrite virtual Creature::setDeathState and Unit::setDeathState -{ - Creature::setDeathState(s); - if(getDeathState()==CORPSE) - { - //remove summoned pet (no corpse) - if(getPetType()==SUMMON_PET) - Remove(PET_SAVE_NOT_IN_SLOT); - // other will despawn at corpse desppawning (Pet::Update code) - else - { - // pet corpse non lootable and non skinnable - SetUInt32Value( UNIT_DYNAMIC_FLAGS, 0x00 ); - RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); - - //lose happiness when died and not in BG/Arena - MapEntry const* mapEntry = sMapStore.LookupEntry(GetMapId()); - if(!mapEntry || (mapEntry->map_type != MAP_ARENA && mapEntry->map_type != MAP_BATTLEGROUND)) - ModifyPower(POWER_HAPPINESS, -HAPPINESS_LEVEL_SIZE); - - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); - } - } - else if(getDeathState()==ALIVE) - { - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); - CastPetAuras(true); - } -} - -void Pet::Update(uint32 diff) -{ - if(m_removed) // pet already removed, just wait in remove queue, no updates - return; - - switch( m_deathState ) - { - case CORPSE: - { - if( m_deathTimer <= diff ) - { - assert(getPetType()!=SUMMON_PET && "Must be already removed."); - Remove(PET_SAVE_NOT_IN_SLOT); //hunters' pets never get removed because of death, NEVER! - return; - } - break; - } - case ALIVE: - { - // unsummon pet that lost owner - Unit* owner = GetOwner(); - if(!owner || (!IsWithinDistInMap(owner, OWNER_MAX_DISTANCE) && !isPossessed()) || isControlled() && !owner->GetPetGUID()) - { - Remove(PET_SAVE_NOT_IN_SLOT, true); - return; - } - - if(isControlled()) - { - if( owner->GetPetGUID() != GetGUID() ) - { - Remove(getPetType()==HUNTER_PET?PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); - return; - } - } - - if(m_duration > 0) - { - if(m_duration > diff) - m_duration -= diff; - else - { - Remove(getPetType() != SUMMON_PET ? PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); - return; - } - } - - if(getPetType() != HUNTER_PET) - break; - - //regenerate Focus - if(m_regenTimer <= diff) - { - RegenerateFocus(); - m_regenTimer = 4000; - } - else - m_regenTimer -= diff; - - if(m_happinessTimer <= diff) - { - LooseHappiness(); - m_happinessTimer = 7500; - } - else - m_happinessTimer -= diff; - - if(m_loyaltyTimer <= diff) - { - TickLoyaltyChange(); - m_loyaltyTimer = 12000; - } - else - m_loyaltyTimer -= diff; - - break; - } - default: - break; - } - Creature::Update(diff); -} - -void Pet::RegenerateFocus() -{ - uint32 curValue = GetPower(POWER_FOCUS); - uint32 maxValue = GetMaxPower(POWER_FOCUS); - - if (curValue >= maxValue) - return; - - float addvalue = 24 * sWorld.getRate(RATE_POWER_FOCUS); - - AuraList const& ModPowerRegenPCTAuras = GetAurasByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT); - for(AuraList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) - if ((*i)->GetModifier()->m_miscvalue == POWER_FOCUS) - addvalue *= ((*i)->GetModifier()->m_amount + 100) / 100.0f; - - ModifyPower(POWER_FOCUS, (int32)addvalue); -} - -void Pet::LooseHappiness() -{ - uint32 curValue = GetPower(POWER_HAPPINESS); - if (curValue <= 0) - return; - int32 addvalue = (140 >> GetLoyaltyLevel()) * 125; //value is 70/35/17/8/4 (per min) * 1000 / 8 (timer 7.5 secs) - if(isInCombat()) //we know in combat happiness fades faster, multiplier guess - addvalue = int32(addvalue * 1.5); - ModifyPower(POWER_HAPPINESS, -addvalue); -} - -void Pet::ModifyLoyalty(int32 addvalue) -{ - uint32 loyaltylevel = GetLoyaltyLevel(); - - if(addvalue > 0) //only gain influenced, not loss - addvalue = int32((float)addvalue * sWorld.getRate(RATE_LOYALTY)); - - if(loyaltylevel >= BEST_FRIEND && (addvalue + m_loyaltyPoints) > int32(GetMaxLoyaltyPoints(loyaltylevel))) - return; - - m_loyaltyPoints += addvalue; - - if(m_loyaltyPoints < 0) - { - if(loyaltylevel > REBELLIOUS) - { - //level down - --loyaltylevel; - SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); - m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); - SetTP(m_TrainingPoints - int32(getLevel())); - } - else - { - m_loyaltyPoints = 0; - Unit* owner = GetOwner(); - if(owner && owner->GetTypeId() == TYPEID_PLAYER) - { - WorldPacket data(SMSG_PET_BROKEN, 0); - ((Player*)owner)->GetSession()->SendPacket(&data); - - //run away - ((Player*)owner)->RemovePet(this,PET_SAVE_AS_DELETED); - } - } - } - //level up - else if(m_loyaltyPoints > int32(GetMaxLoyaltyPoints(loyaltylevel))) - { - ++loyaltylevel; - SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); - m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); - SetTP(m_TrainingPoints + getLevel()); - } -} - -void Pet::TickLoyaltyChange() -{ - int32 addvalue; - - switch(GetHappinessState()) - { - case HAPPY: addvalue = 20; break; - case CONTENT: addvalue = 10; break; - case UNHAPPY: addvalue = -20; break; - default: - return; - } - ModifyLoyalty(addvalue); -} - -void Pet::KillLoyaltyBonus(uint32 level) -{ - if(level > 100) - return; - - //at lower levels gain is faster | the lower loyalty the more loyalty is gained - uint32 bonus = uint32(((100 - level) / 10) + (6 - GetLoyaltyLevel())); - ModifyLoyalty(bonus); -} - -HappinessState Pet::GetHappinessState() -{ - if(GetPower(POWER_HAPPINESS) < HAPPINESS_LEVEL_SIZE) - return UNHAPPY; - else if(GetPower(POWER_HAPPINESS) >= HAPPINESS_LEVEL_SIZE * 2) - return HAPPY; - else - return CONTENT; -} - -void Pet::SetLoyaltyLevel(LoyaltyLevel level) -{ - SetByteValue(UNIT_FIELD_BYTES_1, 1, level); -} - -bool Pet::CanTakeMoreActiveSpells(uint32 spellid) -{ - uint8 activecount = 1; - uint32 chainstartstore[ACTIVE_SPELLS_MAX]; - - if(IsPassiveSpell(spellid)) - return true; - - chainstartstore[0] = spellmgr.GetFirstSpellInChain(spellid); - - for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) - { - if(IsPassiveSpell(itr->first)) - continue; - - uint32 chainstart = spellmgr.GetFirstSpellInChain(itr->first); - - uint8 x; - - for(x = 0; x < activecount; x++) - { - if(chainstart == chainstartstore[x]) - break; - } - - if(x == activecount) //spellchain not yet saved -> add active count - { - ++activecount; - if(activecount > ACTIVE_SPELLS_MAX) - return false; - chainstartstore[x] = chainstart; - } - } - return true; -} - -bool Pet::HasTPForSpell(uint32 spellid) -{ - int32 neededtrainp = GetTPForSpell(spellid); - if((m_TrainingPoints - neededtrainp < 0 || neededtrainp < 0) && neededtrainp != 0) - return false; - return true; -} - -int32 Pet::GetTPForSpell(uint32 spellid) -{ - uint32 basetrainp = 0; - - SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellid); - SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellid); - for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) - { - if(!_spell_idx->second->reqtrainpoints) - return 0; - - basetrainp = _spell_idx->second->reqtrainpoints; - break; - } - - uint32 spenttrainp = 0; - uint32 chainstart = spellmgr.GetFirstSpellInChain(spellid); - - for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) - { - if(itr->second->state == PETSPELL_REMOVED) - continue; - - if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) - { - SkillLineAbilityMap::const_iterator _lower = spellmgr.GetBeginSkillLineAbilityMap(itr->first); - SkillLineAbilityMap::const_iterator _upper = spellmgr.GetEndSkillLineAbilityMap(itr->first); - - for(SkillLineAbilityMap::const_iterator _spell_idx2 = _lower; _spell_idx2 != _upper; ++_spell_idx2) - { - if(_spell_idx2->second->reqtrainpoints > spenttrainp) - { - spenttrainp = _spell_idx2->second->reqtrainpoints; - break; - } - } - } - } - - return int32(basetrainp) - int32(spenttrainp); -} - -uint32 Pet::GetMaxLoyaltyPoints(uint32 level) -{ - return LevelUpLoyalty[level - 1]; -} - -uint32 Pet::GetStartLoyaltyPoints(uint32 level) -{ - return LevelStartLoyalty[level - 1]; -} - -void Pet::SetTP(int32 TP) -{ - m_TrainingPoints = TP; - SetUInt32Value(UNIT_TRAINING_POINTS, (uint32)GetDispTP()); -} - -int32 Pet::GetDispTP() -{ - if(getPetType()!= HUNTER_PET) - return(0); - if(m_TrainingPoints < 0) - return -m_TrainingPoints; - else - return -(m_TrainingPoints + 1); -} - -void Pet::Remove(PetSaveMode mode, bool returnreagent) -{ - Unit* owner = GetOwner(); - - if(owner) - { - if(owner->GetTypeId()==TYPEID_PLAYER) - { - ((Player*)owner)->RemovePet(this,mode,returnreagent); - return; - } - - // only if current pet in slot - if(owner->GetPetGUID()==GetGUID()) - owner->SetPet(0); - } - - CleanupsBeforeDelete(); - AddObjectToRemoveList(); - m_removed = true; -} - -void Pet::GivePetXP(uint32 xp) -{ - if(getPetType() != HUNTER_PET) - return; - - if ( xp < 1 ) - return; - - if(!isAlive()) - return; - - uint32 level = getLevel(); - - // XP to money conversion processed in Player::RewardQuest - if(level >= sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) - return; - - uint32 curXP = GetUInt32Value(UNIT_FIELD_PETEXPERIENCE); - uint32 nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); - uint32 newXP = curXP + xp; - - if(newXP >= nextLvlXP && level+1 > GetOwner()->getLevel()) - { - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, nextLvlXP-1); - return; - } - - while( newXP >= nextLvlXP && level < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL) ) - { - newXP -= nextLvlXP; - - SetLevel( level + 1 ); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(level+1))/4)); - - level = getLevel(); - nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); - GivePetLevel(level); - } - - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, newXP); - - if(getPetType() == HUNTER_PET) - KillLoyaltyBonus(level); -} - -void Pet::GivePetLevel(uint32 level) -{ - if(!level) - return; - - InitStatsForLevel( level); - - SetTP(m_TrainingPoints + (GetLoyaltyLevel() - 1)); -} - -bool Pet::CreateBaseAtCreature(Creature* creature) -{ - if(!creature) - { - sLog.outError("CRITICAL ERROR: NULL pointer parsed into CreateBaseAtCreature()"); - return false; - } - uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); - - sLog.outBasic("SetInstanceID()"); - SetInstanceId(creature->GetInstanceId()); - - sLog.outBasic("Create pet"); - uint32 pet_number = objmgr.GeneratePetNumber(); - if(!Create(guid, creature->GetMap(), creature->GetEntry(), pet_number)) - return false; - - Relocate(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); - - if(!IsPositionValid()) - { - sLog.outError("ERROR: Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)", - GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); - return false; - } - - CreatureInfo const *cinfo = GetCreatureInfo(); - if(!cinfo) - { - sLog.outError("ERROR: CreateBaseAtCreature() failed, creatureInfo is missing!"); - return false; - } - - if(cinfo->type == CREATURE_TYPE_CRITTER) - { - setPetType(MINI_PET); - return true; - } - SetDisplayId(creature->GetDisplayId()); - SetNativeDisplayId(creature->GetNativeDisplayId()); - SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - SetPower( POWER_HAPPINESS,166500); - setPowerType(POWER_FOCUS); - SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,0); - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(creature->getLevel()))/4)); - SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - SetUInt32Value(UNIT_NPC_FLAGS , 0); - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(creature->GetCreatureInfo()->family); - if( char* familyname = cFamily->Name[sWorld.GetDefaultDbcLocale()] ) - SetName(familyname); - else - SetName(creature->GetName()); - - m_loyaltyPoints = 1000; - if(cinfo->type == CREATURE_TYPE_BEAST) - { - SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); - SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); - SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); - - SetUInt32Value(UNIT_MOD_CAST_SPEED, creature->GetUInt32Value(UNIT_MOD_CAST_SPEED) ); - SetLoyaltyLevel(REBELLIOUS); - } - return true; -} - -bool Pet::InitStatsForLevel(uint32 petlevel) -{ - CreatureInfo const *cinfo = GetCreatureInfo(); - assert(cinfo); - - Unit* owner = GetOwner(); - if(!owner) - { - sLog.outError("ERROR: attempt to summon pet (Entry %u) without owner! Attempt terminated.", cinfo->Entry); - return false; - } - - uint32 creature_ID = (getPetType() == HUNTER_PET) ? 1 : cinfo->Entry; - - SetLevel( petlevel); - - SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool)); - - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(petlevel*50)); - - SetAttackTime(BASE_ATTACK, BASE_ATTACK_TIME); - SetAttackTime(OFF_ATTACK, BASE_ATTACK_TIME); - SetAttackTime(RANGED_ATTACK, BASE_ATTACK_TIME); - - SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0); - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family); - if(cFamily && cFamily->minScale > 0.0f) - { - float scale; - if (getLevel() >= cFamily->maxScaleLevel) - scale = cFamily->maxScale; - else if (getLevel() <= cFamily->minScaleLevel) - scale = cFamily->minScale; - else - scale = cFamily->minScale + (getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale); - - SetFloatValue(OBJECT_FIELD_SCALE_X, scale); - } - m_bonusdamage = 0; - - int32 createResistance[MAX_SPELL_SCHOOL] = {0,0,0,0,0,0,0}; - - if(cinfo && getPetType() != HUNTER_PET) - { - createResistance[SPELL_SCHOOL_HOLY] = cinfo->resistance1; - createResistance[SPELL_SCHOOL_FIRE] = cinfo->resistance2; - createResistance[SPELL_SCHOOL_NATURE] = cinfo->resistance3; - createResistance[SPELL_SCHOOL_FROST] = cinfo->resistance4; - createResistance[SPELL_SCHOOL_SHADOW] = cinfo->resistance5; - createResistance[SPELL_SCHOOL_ARCANE] = cinfo->resistance6; - } - - switch(getPetType()) - { - case SUMMON_PET: - { - if(owner->GetTypeId() == TYPEID_PLAYER) - { - switch(owner->getClass()) - { - case CLASS_WARLOCK: - { - - //the damage bonus used for pets is either fire or shadow damage, whatever is higher - uint32 fire = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE); - uint32 shadow = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); - uint32 val = (fire > shadow) ? fire : shadow; - - SetBonusDamage(int32 (val * 0.15f)); - //bonusAP += val * 0.57; - break; - } - case CLASS_MAGE: - { - //40% damage bonus of mage's frost damage - float val = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST) * 0.4; - if(val < 0) - val = 0; - SetBonusDamage( int32(val)); - break; - } - default: - break; - } - } - - SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); - SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); - - //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); - - PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); - if(pInfo) // exist in DB - { - SetCreateHealth(pInfo->health); - SetCreateMana(pInfo->mana); - - if(pInfo->armor > 0) - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); - - for(int stat = 0; stat < MAX_STATS; ++stat) - { - SetCreateStat(Stats(stat),float(pInfo->stats[stat])); - } - } - else // not exist in DB, use some default fake data - { - sLog.outErrorDb("Summoned pet (Entry: %u) not have pet stats data in DB",cinfo->Entry); - - // remove elite bonuses included in DB values - SetCreateHealth(uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); - SetCreateMana( uint32(((float(cinfo->maxmana) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); - - SetCreateStat(STAT_STRENGTH,22); - SetCreateStat(STAT_AGILITY,22); - SetCreateStat(STAT_STAMINA,25); - SetCreateStat(STAT_INTELLECT,28); - SetCreateStat(STAT_SPIRIT,27); - } - break; - } - case HUNTER_PET: - { - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(petlevel))/4)); - - //these formula may not be correct; however, it is designed to be close to what it should be - //this makes dps 0.5 of pets level - SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); - //damage range is then petlevel / 2 - SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); - //damage is increased afterwards as strength and pet scaling modify attack power - - //stored standard pet stats are entry 1 in pet_levelinfo - PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); - if(pInfo) // exist in DB - { - SetCreateHealth(pInfo->health); - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); - //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); - - for( int i = STAT_STRENGTH; i < MAX_STATS; i++) - { - SetCreateStat(Stats(i), float(pInfo->stats[i])); - } - } - else // not exist in DB, use some default fake data - { - sLog.outErrorDb("Hunter pet levelstats missing in DB"); - - // remove elite bonuses included in DB values - SetCreateHealth( uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); - - SetCreateStat(STAT_STRENGTH,22); - SetCreateStat(STAT_AGILITY,22); - SetCreateStat(STAT_STAMINA,25); - SetCreateStat(STAT_INTELLECT,28); - SetCreateStat(STAT_SPIRIT,27); - } - break; - } - case GUARDIAN_PET: - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP,1000); - - SetCreateMana( 28 + 10*petlevel ); - SetCreateHealth( 28 + 30*petlevel ); - - // FIXME: this is wrong formula, possible each guardian pet have own damage formula - //these formula may not be correct; however, it is designed to be close to what it should be - //this makes dps 0.5 of pets level - SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); - //damage range is then petlevel / 2 - SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); - break; - default: - sLog.outError("Pet have incorrect type (%u) for levelup.",getPetType()); break; - } - - for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i) - SetModifierValue(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(createResistance[i]) ); - - UpdateAllStats(); - - SetHealth(GetMaxHealth()); - SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); - - return true; -} - -bool Pet::HaveInDiet(ItemPrototype const* item) const -{ - if (!item->FoodType) - return false; - - CreatureInfo const* cInfo = GetCreatureInfo(); - if(!cInfo) - return false; - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); - if(!cFamily) - return false; - - uint32 diet = cFamily->petFoodMask; - uint32 FoodMask = 1 << (item->FoodType-1); - return diet & FoodMask; -} - -uint32 Pet::GetCurrentFoodBenefitLevel(uint32 itemlevel) -{ - // -5 or greater food level - if(getLevel() <= itemlevel +5) //possible to feed level 60 pet with level 55 level food for full effect - return 35000; - // -10..-6 - else if(getLevel() <= itemlevel + 10) //pure guess, but sounds good - return 17000; - // -14..-11 - else if(getLevel() <= itemlevel + 14) //level 55 food gets green on 70, makes sense to me - return 8000; - // -15 or less - else - return 0; //food too low level -} - -void Pet::_LoadSpellCooldowns() -{ - m_CreatureSpellCooldowns.clear(); - m_CreatureCategoryCooldowns.clear(); - - QueryResult *result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - if(result) - { - time_t curTime = time(NULL); - - WorldPacket data(SMSG_SPELL_COOLDOWN, (8+1+result->GetRowCount()*8)); - data << GetGUID(); - data << uint8(0x0); // flags (0x1, 0x2) - - do - { - Field *fields = result->Fetch(); - - uint32 spell_id = fields[0].GetUInt32(); - time_t db_time = (time_t)fields[1].GetUInt64(); - - if(!sSpellStore.LookupEntry(spell_id)) - { - sLog.outError("Pet %u have unknown spell %u in `pet_spell_cooldown`, skipping.",m_charmInfo->GetPetNumber(),spell_id); - continue; - } - - // skip outdated cooldown - if(db_time <= curTime) - continue; - - data << uint32(spell_id); - data << uint32(uint32(db_time-curTime)*1000); // in m.secs - - _AddCreatureSpellCooldown(spell_id,db_time); - - sLog.outDebug("Pet (Number: %u) spell %u cooldown loaded (%u secs).",m_charmInfo->GetPetNumber(),spell_id,uint32(db_time-curTime)); - } - while( result->NextRow() ); - - delete result; - - if(!m_CreatureSpellCooldowns.empty() && GetOwner()) - { - ((Player*)GetOwner())->GetSession()->SendPacket(&data); - } - } -} - -void Pet::_SaveSpellCooldowns() -{ - CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", m_charmInfo->GetPetNumber()); - - time_t curTime = time(NULL); - - // remove oudated and save active - for(CreatureSpellCooldowns::iterator itr = m_CreatureSpellCooldowns.begin();itr != m_CreatureSpellCooldowns.end();) - { - if(itr->second <= curTime) - m_CreatureSpellCooldowns.erase(itr++); - else - { - CharacterDatabase.PExecute("INSERT INTO pet_spell_cooldown (guid,spell,time) VALUES ('%u', '%u', '" I64FMTD "')", m_charmInfo->GetPetNumber(), itr->first, uint64(itr->second)); - ++itr; - } - } -} - -void Pet::_LoadSpells() -{ - QueryResult *result = CharacterDatabase.PQuery("SELECT spell,slot,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - if(result) - { - do - { - Field *fields = result->Fetch(); - - addSpell(fields[0].GetUInt16(), fields[2].GetUInt16(), PETSPELL_UNCHANGED, fields[1].GetUInt16()); - } - while( result->NextRow() ); - - delete result; - } -} - -void Pet::_SaveSpells() -{ - for (PetSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next) - { - ++next; - if (itr->second->type == PETSPELL_FAMILY) continue; // prevent saving family passives to DB - if (itr->second->state == PETSPELL_REMOVED || itr->second->state == PETSPELL_CHANGED) - CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first); - if (itr->second->state == PETSPELL_NEW || itr->second->state == PETSPELL_CHANGED) - CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,slot,active) VALUES ('%u', '%u', '%u','%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second->slotId,itr->second->active); - - if (itr->second->state == PETSPELL_REMOVED) - _removeSpell(itr->first); - else - itr->second->state = PETSPELL_UNCHANGED; - } -} - -void Pet::_LoadAuras(uint32 timediff) -{ - m_Auras.clear(); - for (int i = 0; i < TOTAL_AURAS; i++) - m_modAuras[i].clear(); - - // all aura related fields - for(int i = UNIT_FIELD_AURA; i <= UNIT_FIELD_AURASTATE; ++i) - SetUInt32Value(i, 0); - - QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - if(result) - { - do - { - Field *fields = result->Fetch(); - uint64 caster_guid = fields[0].GetUInt64(); - uint32 spellid = fields[1].GetUInt32(); - uint32 effindex = fields[2].GetUInt32(); - int32 damage = (int32)fields[3].GetUInt32(); - int32 maxduration = (int32)fields[4].GetUInt32(); - int32 remaintime = (int32)fields[5].GetUInt32(); - int32 remaincharges = (int32)fields[6].GetUInt32(); - - SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid); - if(!spellproto) - { - sLog.outError("Unknown aura (spellid %u, effindex %u), ignore.",spellid,effindex); - continue; - } - - if(effindex >= 3) - { - sLog.outError("Invalid effect index (spellid %u, effindex %u), ignore.",spellid,effindex); - continue; - } - - // negative effects should continue counting down after logout - if (remaintime != -1 && !IsPositiveEffect(spellid, effindex)) - { - if(remaintime <= int32(timediff)) - continue; - - remaintime -= timediff; - } - - // prevent wrong values of remaincharges - if(spellproto->procCharges) - { - if(remaincharges <= 0 || remaincharges > spellproto->procCharges) - remaincharges = spellproto->procCharges; - } - else - remaincharges = -1; - - /// do not load single target auras (unless they were cast by the player) - if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) - continue; - - Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); - - if(!damage) - damage = aura->GetModifier()->m_amount; - aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); - AddAura(aura); - } - while( result->NextRow() ); - - delete result; - } -} - -void Pet::_SaveAuras() -{ - CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - AuraMap const& auras = GetAuras(); - for(AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) - { - // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras. - SpellEntry const *spellInfo = itr->second->GetSpellProto(); - uint8 i; - for (i = 0; i < 3; i++) - if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET ) - break; - - if (i != 3) - continue; - - if(itr->second->IsPassive()) - continue; - - /// do not save single target auras (unless they were cast by the player) - if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)) - continue; - - CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " - "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')", - m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); - } -} - -bool Pet::addSpell(uint16 spell_id, uint16 active, PetSpellState state, uint16 slot_id, PetSpellType type) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id); - if (!spellInfo) - { - // do pet spell book cleanup - if(state == PETSPELL_UNCHANGED) // spell load case - { - sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request, deleting for all pets in `pet_spell`.",spell_id); - CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE spell = '%u'",spell_id); - } - else - sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request.",spell_id); - - return false; - } - - PetSpellMap::iterator itr = m_spells.find(spell_id); - if (itr != m_spells.end()) - { - if (itr->second->state == PETSPELL_REMOVED) - { - delete itr->second; - m_spells.erase(itr); - state = PETSPELL_CHANGED; - } - else if (state == PETSPELL_UNCHANGED && itr->second->state != PETSPELL_UNCHANGED) - { - // can be in case spell loading but learned at some previous spell loading - itr->second->state = PETSPELL_UNCHANGED; - return false; - } - else - return false; - } - - uint32 oldspell_id = 0; - - PetSpell *newspell = new PetSpell; - newspell->state = state; - newspell->type = type; - - if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here - { - if(IsPassiveSpell(spell_id)) - newspell->active = ACT_PASSIVE; - else - newspell->active = ACT_DISABLED; - } - else - newspell->active = active; - - uint32 chainstart = spellmgr.GetFirstSpellInChain(spell_id); - - for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); itr++) - { - if(itr->second->state == PETSPELL_REMOVED) continue; - - if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) - { - slot_id = itr->second->slotId; - newspell->active = itr->second->active; - - if(newspell->active == ACT_ENABLED) - ToggleAutocast(itr->first, false); - - oldspell_id = itr->first; - removeSpell(itr->first); - } - } - - uint16 tmpslot=slot_id; - - if (tmpslot == 0xffff) - { - uint16 maxid = 0; - PetSpellMap::iterator itr; - for (itr = m_spells.begin(); itr != m_spells.end(); ++itr) - { - if(itr->second->state == PETSPELL_REMOVED) continue; - if (itr->second->slotId > maxid) maxid = itr->second->slotId; - } - tmpslot = maxid + 1; - } - - newspell->slotId = tmpslot; - m_spells[spell_id] = newspell; - - if (IsPassiveSpell(spell_id)) - CastSpell(this, spell_id, true); - else if(state == PETSPELL_NEW) - m_charmInfo->AddSpellToAB(oldspell_id, spell_id); - - if(newspell->active == ACT_ENABLED) - ToggleAutocast(spell_id, true); - - return true; -} - -bool Pet::learnSpell(uint16 spell_id) -{ - // prevent duplicated entires in spell book - if (!addSpell(spell_id)) - return false; - - Unit* owner = GetOwner(); - if(owner->GetTypeId()==TYPEID_PLAYER) - ((Player*)owner)->PetSpellInitialize(); - return true; -} - -void Pet::removeSpell(uint16 spell_id) -{ - PetSpellMap::iterator itr = m_spells.find(spell_id); - if (itr == m_spells.end()) - return; - - if(itr->second->state == PETSPELL_REMOVED) - return; - - if(itr->second->state == PETSPELL_NEW) - { - delete itr->second; - m_spells.erase(itr); - } - else - itr->second->state = PETSPELL_REMOVED; - - RemoveAurasDueToSpell(spell_id); -} - -bool Pet::_removeSpell(uint16 spell_id) -{ - PetSpellMap::iterator itr = m_spells.find(spell_id); - if (itr != m_spells.end()) - { - delete itr->second; - m_spells.erase(itr); - return true; - } - return false; -} - -void Pet::InitPetCreateSpells() -{ - m_charmInfo->InitPetActionBar(); - - m_spells.clear(); - int32 usedtrainpoints = 0, petspellid; - PetCreateSpellEntry const* CreateSpells = objmgr.GetPetCreateSpellEntry(GetEntry()); - if(CreateSpells) - { - for(uint8 i = 0; i < 4; i++) - { - if(!CreateSpells->spellid[i]) - break; - - SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(CreateSpells->spellid[i]); - if(!learn_spellproto) - continue; - - if(learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_SPELL || learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_PET_SPELL) - { - petspellid = learn_spellproto->EffectTriggerSpell[0]; - Unit* owner = GetOwner(); - if(owner->GetTypeId() == TYPEID_PLAYER && !((Player*)owner)->HasSpell(learn_spellproto->Id)) - { - if(IsPassiveSpell(petspellid)) //learn passive skills when tamed, not sure if thats right - ((Player*)owner)->learnSpell(learn_spellproto->Id); - else - AddTeachSpell(learn_spellproto->EffectTriggerSpell[0], learn_spellproto->Id); - } - } - else - petspellid = learn_spellproto->Id; - - addSpell(petspellid); - - SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); - SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); - - for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) - { - usedtrainpoints += _spell_idx->second->reqtrainpoints; - break; - } - } - } - - LearnPetPassives(); - - CastPetAuras(false); - - SetTP(-usedtrainpoints); -} - -void Pet::CheckLearning(uint32 spellid) -{ - //charmed case -> prevent crash - if(GetTypeId() == TYPEID_PLAYER || getPetType() != HUNTER_PET) - return; - - Unit* owner = GetOwner(); - - if(m_teachspells.empty() || !owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - TeachSpellMap::iterator itr = m_teachspells.find(spellid); - if(itr == m_teachspells.end()) - return; - - if(urand(0, 100) < 10) - { - ((Player*)owner)->learnSpell(itr->second); - m_teachspells.erase(itr); - } -} - -uint32 Pet::resetTalentsCost() const -{ - uint32 days = (sWorld.GetGameTime() - m_resetTalentsTime)/DAY; - - // The first time reset costs 10 silver; after 1 day cost is reset to 10 silver - if(m_resetTalentsCost < 10*SILVER || days > 0) - return 10*SILVER; - // then 50 silver - else if(m_resetTalentsCost < 50*SILVER) - return 50*SILVER; - // then 1 gold - else if(m_resetTalentsCost < 1*GOLD) - return 1*GOLD; - // then increasing at a rate of 1 gold; cap 10 gold - else - return (m_resetTalentsCost + 1*GOLD > 10*GOLD ? 10*GOLD : m_resetTalentsCost + 1*GOLD); -} - -void Pet::ToggleAutocast(uint32 spellid, bool apply) -{ - if(IsPassiveSpell(spellid)) - return; - - if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid)) - if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER - && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE) - return; - - PetSpellMap::const_iterator itr = m_spells.find((uint16)spellid); - - int i; - - if(apply) - { - for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++); - if (i == m_autospells.size()) - { - m_autospells.push_back(spellid); - itr->second->active = ACT_ENABLED; - itr->second->state = PETSPELL_CHANGED; - } - } - else - { - AutoSpellList::iterator itr2 = m_autospells.begin(); - for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++, itr2++); - if (i < m_autospells.size()) - { - m_autospells.erase(itr2); - itr->second->active = ACT_DISABLED; - itr->second->state = PETSPELL_CHANGED; - } - } -} - -bool Pet::Create(uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number) -{ - SetMapId(map->GetId()); - SetInstanceId(map->GetInstanceId()); - - Object::_Create(guidlow, pet_number, HIGHGUID_PET); - - m_DBTableGuid = guidlow; - m_originalEntry = Entry; - - if(!InitEntry(Entry)) - return false; - - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); - SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); - - if(getPetType() == MINI_PET) // always non-attackable - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); - - return true; -} - -bool Pet::HasSpell(uint32 spell) const -{ - return (m_spells.find(spell) != m_spells.end()); -} - -// Get all passive spells in our skill line -void Pet::LearnPetPassives() -{ - CreatureInfo const* cInfo = GetCreatureInfo(); - if(!cInfo) - return; - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); - if(!cFamily) - return; - - PetFamilySpellsStore::const_iterator petStore = sPetFamilySpellsStore.find(cFamily->ID); - if(petStore != sPetFamilySpellsStore.end()) - { - for(PetFamilySpellsSet::const_iterator petSet = petStore->second.begin(); petSet != petStore->second.end(); ++petSet) - addSpell(*petSet, ACT_DECIDE, PETSPELL_NEW, 0xffff, PETSPELL_FAMILY); - } -} - -void Pet::CastPetAuras(bool current) -{ - Unit* owner = GetOwner(); - if(!owner) - return; - - if(getPetType() != HUNTER_PET && (getPetType() != SUMMON_PET || owner->getClass() != CLASS_WARLOCK)) - return; - - for(PetAuraSet::iterator itr = owner->m_petAuras.begin(); itr != owner->m_petAuras.end(); ) - { - PetAura const* pa = *itr; - ++itr; - - if(!current && pa->IsRemovedOnChangePet()) - owner->RemovePetAura(pa); - else - CastPetAura(pa); - } -} - -void Pet::CastPetAura(PetAura const* aura) -{ - uint16 auraId = aura->GetAura(GetEntry()); - if(!auraId) - return; - - if(auraId == 35696) // Demonic Knowledge - { - int32 basePoints = int32(aura->GetDamage() * (GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)) / 100); - CastCustomSpell(this,auraId,&basePoints, NULL, NULL, true ); - } - else - CastSpell(this, auraId, true); -} +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Common.h" +#include "Database/DatabaseEnv.h" +#include "Log.h" +#include "WorldSession.h" +#include "WorldPacket.h" +#include "ObjectMgr.h" +#include "SpellMgr.h" +#include "Pet.h" +#include "MapManager.h" +#include "Formulas.h" +#include "SpellAuras.h" +#include "CreatureAI.h" +#include "Unit.h" +#include "Util.h" + +char const* petTypeSuffix[MAX_PET_TYPE] = +{ + "'s Minion", // SUMMON_PET + "'s Pet", // HUNTER_PET + "'s Guardian", // GUARDIAN_PET + "'s Companion" // MINI_PET +}; + +//numbers represent minutes * 100 while happy (you get 100 loyalty points per min while happy) +uint32 const LevelUpLoyalty[6] = +{ + 5500, + 11500, + 17000, + 23500, + 31000, + 39500, +}; + +uint32 const LevelStartLoyalty[6] = +{ + 2000, + 4500, + 7000, + 10000, + 13500, + 17500, +}; + +Pet::Pet(PetType type) : Creature() +{ + m_isPet = true; + m_name = "Pet"; + m_petType = type; + + m_removed = false; + m_regenTimer = 4000; + m_happinessTimer = 7500; + m_loyaltyTimer = 12000; + m_duration = 0; + m_bonusdamage = 0; + + m_loyaltyPoints = 0; + m_TrainingPoints = 0; + m_resetTalentsCost = 0; + m_resetTalentsTime = 0; + + m_auraUpdateMask = 0; + + // pets always have a charminfo, even if they are not actually charmed + CharmInfo* charmInfo = InitCharmInfo(this); + + if(type == MINI_PET) // always passive + charmInfo->SetReactState(REACT_PASSIVE); + else if(type == GUARDIAN_PET) // always aggressive + charmInfo->SetReactState(REACT_AGGRESSIVE); + + m_spells.clear(); + m_Auras.clear(); + m_CreatureSpellCooldowns.clear(); + m_CreatureCategoryCooldowns.clear(); + m_autospells.clear(); + m_declinedname = NULL; + m_isActive = true; +} + +Pet::~Pet() +{ + if(m_uint32Values) // only for fully created Object + { + for (PetSpellMap::iterator i = m_spells.begin(); i != m_spells.end(); ++i) + delete i->second; + ObjectAccessor::Instance().RemoveObject(this); + } + + delete m_declinedname; +} + +void Pet::AddToWorld() +{ + ///- Register the pet for guid lookup + if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); + Unit::AddToWorld(); +} + +void Pet::RemoveFromWorld() +{ + ///- Remove the pet from the accessor + if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); + ///- Don't call the function for Creature, normal mobs + totems go in a different storage + Unit::RemoveFromWorld(); +} + +bool Pet::LoadPetFromDB( Unit* owner, uint32 petentry, uint32 petnumber, bool current ) +{ + uint32 ownerid = owner->GetGUIDLow(); + + QueryResult *result; + + if(petnumber) + // known petnumber entry 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND id = '%u'",ownerid, petnumber); + else if(current) + // current pet (slot 0) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND slot = '0'",ownerid ); + else if(petentry) + // known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets) + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND entry = '%u' AND (slot = '0' OR slot = '3') ",ownerid, petentry ); + else + // any current or other non-stabled pet (for hunter "call pet") + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3') ",ownerid); + + if(!result) + return false; + + Field *fields = result->Fetch(); + + // update for case of current pet "slot = 0" + petentry = fields[1].GetUInt32(); + if(!petentry) + { + delete result; + return false; + } + + uint32 summon_spell_id = fields[21].GetUInt32(); + SpellEntry const* spellInfo = sSpellStore.LookupEntry(summon_spell_id); + + bool is_temporary_summoned = spellInfo && GetSpellDuration(spellInfo) > 0; + + // check temporary summoned pets like mage water elemental + if(current && is_temporary_summoned) + { + delete result; + return false; + } + + Map *map = owner->GetMap(); + uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); + uint32 pet_number = fields[0].GetUInt32(); + if(!Create(guid, map, petentry, pet_number)) + { + delete result; + return false; + } + + float px, py, pz; + owner->GetClosePoint(px, py, pz,GetObjectSize(),PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); + + Relocate(px, py, pz, owner->GetOrientation()); + + if(!IsPositionValid()) + { + sLog.outError("ERROR: Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)", + GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); + delete result; + return false; + } + + setPetType(PetType(fields[22].GetUInt8())); + SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction()); + SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id); + + CreatureInfo const *cinfo = GetCreatureInfo(); + if(cinfo->type == CREATURE_TYPE_CRITTER) + { + AIM_Initialize(); + map->Add((Creature*)this); + delete result; + return true; + } + if(getPetType()==HUNTER_PET || (getPetType()==SUMMON_PET && cinfo->type == CREATURE_TYPE_DEMON && owner->getClass() == CLASS_WARLOCK)) + m_charmInfo->SetPetNumber(pet_number, true); + else + m_charmInfo->SetPetNumber(pet_number, false); + SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID()); + SetDisplayId(fields[3].GetUInt32()); + SetNativeDisplayId(fields[3].GetUInt32()); + uint32 petlevel=fields[4].GetUInt32(); + SetUInt32Value(UNIT_NPC_FLAGS , 0); + SetName(fields[11].GetString()); + + switch(getPetType()) + { + + case SUMMON_PET: + petlevel=owner->getLevel(); + + SetUInt32Value(UNIT_FIELD_BYTES_0,2048); + SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); + // this enables popup window (pet dismiss, cancel) + break; + case HUNTER_PET: + SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); + SetByteValue(UNIT_FIELD_BYTES_1, 1, fields[8].GetUInt32()); + SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); + + if(fields[12].GetBool()) + SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED); + else + SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); + + SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); + // this enables popup window (pet abandon, cancel) + SetTP(fields[9].GetInt32()); + SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + SetPower( POWER_HAPPINESS,fields[15].GetUInt32()); + setPowerType(POWER_FOCUS); + break; + default: + sLog.outError("Pet have incorrect type (%u) for pet loading.",getPetType()); + } + InitStatsForLevel( petlevel); + SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32()); + SetUInt64Value(UNIT_FIELD_CREATEDBY, owner->GetGUID()); + + m_charmInfo->SetReactState( ReactStates( fields[6].GetUInt8() )); + m_loyaltyPoints = fields[7].GetInt32(); + + uint32 savedhealth = fields[13].GetUInt32(); + uint32 savedmana = fields[14].GetUInt32(); + + // set current pet as current + if(fields[10].GetUInt32() != 0) + { + CharacterDatabase.BeginTransaction(); + CharacterDatabase.PExecute("UPDATE character_pet SET slot = '3' WHERE owner = '%u' AND slot = '0' AND id <> '%u'",ownerid, m_charmInfo->GetPetNumber()); + CharacterDatabase.PExecute("UPDATE character_pet SET slot = '0' WHERE owner = '%u' AND id = '%u'",ownerid, m_charmInfo->GetPetNumber()); + CharacterDatabase.CommitTransaction(); + } + + if(!is_temporary_summoned) + { + // permanent controlled pets store state in DB + Tokens tokens = StrSplit(fields[16].GetString(), " "); + + if(tokens.size() != 20) + { + delete result; + return false; + } + + int index; + Tokens::iterator iter; + for(iter = tokens.begin(), index = 0; index < 10; ++iter, ++index ) + { + m_charmInfo->GetActionBarEntry(index)->Type = atol((*iter).c_str()); + ++iter; + m_charmInfo->GetActionBarEntry(index)->SpellOrAction = atol((*iter).c_str()); + // patch for old data where some spells have ACT_DECIDE but should have ACT_CAST + // so overwrite old state + SpellEntry const *spellInfo = sSpellStore.LookupEntry(m_charmInfo->GetActionBarEntry(index)->SpellOrAction); + if (spellInfo && spellInfo->AttributesEx & SPELL_ATTR_EX_PET_NOT_AUTOCAST) + m_charmInfo->GetActionBarEntry(index)->Type = ACT_CAST; + } + + //init teach spells + tokens = StrSplit(fields[17].GetString(), " "); + for (iter = tokens.begin(), index = 0; index < 4; ++iter, ++index) + { + uint32 tmp = atol((*iter).c_str()); + + ++iter; + + if(tmp) + AddTeachSpell(tmp, atol((*iter).c_str())); + else + break; + } + } + + // since last save (in seconds) + uint32 timediff = (time(NULL) - fields[18].GetUInt32()); + + delete result; + + //load spells/cooldowns/auras + SetCanModifyStats(true); + _LoadAuras(timediff); + + //init AB + if(is_temporary_summoned) + { + // Temporary summoned pets always have initial spell list at load + InitPetCreateSpells(); + } + else + { + LearnPetPassives(); + CastPetAuras(current); + } + + if(getPetType() == SUMMON_PET && !current) //all (?) summon pets come with full health when called, but not when they are current + { + SetHealth(GetMaxHealth()); + SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); + } + else + { + SetHealth(savedhealth > GetMaxHealth() ? GetMaxHealth() : savedhealth); + SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana); + } + + AIM_Initialize(); + map->Add((Creature*)this); + + // Spells should be loaded after pet is added to map, because in CanCast is check on it + _LoadSpells(); + _LoadSpellCooldowns(); + + owner->SetPet(this); // in DB stored only full controlled creature + sLog.outDebug("New Pet has guid %u", GetGUIDLow()); + + if(owner->GetTypeId() == TYPEID_PLAYER) + { + ((Player*)owner)->PetSpellInitialize(); + if(((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_PET); + } + + if(owner->GetTypeId() == TYPEID_PLAYER && getPetType() == HUNTER_PET) + { + result = CharacterDatabase.PQuery("SELECT genitive, dative, accusative, instrumental, prepositional FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'",owner->GetGUIDLow(),GetCharmInfo()->GetPetNumber()); + + if(result) + { + if(m_declinedname) + delete m_declinedname; + + m_declinedname = new DeclinedName; + Field *fields = result->Fetch(); + for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) + { + m_declinedname->name[i] = fields[i].GetCppString(); + } + } + } + + return true; +} + +void Pet::SavePetToDB(PetSaveMode mode) +{ + if(!GetEntry()) + return; + + // save only fully controlled creature + if(!isControlled()) + return; + + uint32 curhealth = GetHealth(); + uint32 curmana = GetPower(POWER_MANA); + + switch(mode) + { + case PET_SAVE_IN_STABLE_SLOT_1: + case PET_SAVE_IN_STABLE_SLOT_2: + case PET_SAVE_NOT_IN_SLOT: + { + RemoveAllAuras(); + + //only alive hunter pets get auras saved, the others don't + if(!(getPetType() == HUNTER_PET && isAlive())) + m_Auras.clear(); + } + default: + break; + } + + _SaveSpells(); + _SaveSpellCooldowns(); + _SaveAuras(); + + switch(mode) + { + case PET_SAVE_AS_CURRENT: + case PET_SAVE_IN_STABLE_SLOT_1: + case PET_SAVE_IN_STABLE_SLOT_2: + case PET_SAVE_NOT_IN_SLOT: + { + uint32 loyalty =1; + if(getPetType()!=HUNTER_PET) + loyalty = GetLoyaltyLevel(); + + uint32 owner = GUID_LOPART(GetOwnerGUID()); + std::string name = m_name; + CharacterDatabase.escape_string(name); + CharacterDatabase.BeginTransaction(); + // remove current data + CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND id = '%u'", owner,m_charmInfo->GetPetNumber() ); + + // prevent duplicate using slot (except PET_SAVE_NOT_IN_SLOT) + if(mode!=PET_SAVE_NOT_IN_SLOT) + CharacterDatabase.PExecute("UPDATE character_pet SET slot = 3 WHERE owner = '%u' AND slot = '%u'", owner, uint32(mode) ); + + // prevent existence another hunter pet in PET_SAVE_AS_CURRENT and PET_SAVE_NOT_IN_SLOT + if(getPetType()==HUNTER_PET && (mode==PET_SAVE_AS_CURRENT||mode==PET_SAVE_NOT_IN_SLOT)) + CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3')", owner ); + // save pet + std::ostringstream ss; + ss << "INSERT INTO character_pet ( id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata,TeachSpelldata,savetime,resettalents_cost,resettalents_time,CreatedBySpell,PetType) " + << "VALUES (" + << m_charmInfo->GetPetNumber() << ", " + << GetEntry() << ", " + << owner << ", " + << GetNativeDisplayId() << ", " + << getLevel() << ", " + << GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ", " + << uint32(m_charmInfo->GetReactState()) << ", " + << m_loyaltyPoints << ", " + << GetLoyaltyLevel() << ", " + << m_TrainingPoints << ", " + << uint32(mode) << ", '" + << name.c_str() << "', " + << uint32((GetByteValue(UNIT_FIELD_BYTES_2, 2) == UNIT_RENAME_ALLOWED)?0:1) << ", " + << (curhealth<1?1:curhealth) << ", " + << curmana << ", " + << GetPower(POWER_HAPPINESS) << ", '"; + + for(uint32 i = 0; i < 10; i++) + ss << uint32(m_charmInfo->GetActionBarEntry(i)->Type) << " " << uint32(m_charmInfo->GetActionBarEntry(i)->SpellOrAction) << " "; + ss << "', '"; + + //save spells the pet can teach to it's Master + { + int i = 0; + for(TeachSpellMap::iterator itr = m_teachspells.begin(); i < 4 && itr != m_teachspells.end(); ++i, ++itr) + ss << itr->first << " " << itr->second << " "; + for(; i < 4; ++i) + ss << uint32(0) << " " << uint32(0) << " "; + } + + ss << "', " + << time(NULL) << ", " + << uint32(m_resetTalentsCost) << ", " + << uint64(m_resetTalentsTime) << ", " + << GetUInt32Value(UNIT_CREATED_BY_SPELL) << ", " + << uint32(getPetType()) << ")"; + + CharacterDatabase.Execute( ss.str().c_str() ); + + CharacterDatabase.CommitTransaction(); + break; + } + case PET_SAVE_AS_DELETED: + { + RemoveAllAuras(); + uint32 owner = GUID_LOPART(GetOwnerGUID()); + DeleteFromDB(m_charmInfo->GetPetNumber()); + break; + } + default: + sLog.outError("Unknown pet save/remove mode: %d",mode); + } +} + +void Pet::DeleteFromDB(uint32 guidlow) +{ + CharacterDatabase.PExecute("DELETE FROM character_pet WHERE id = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE id = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", guidlow); +} + +void Pet::setDeathState(DeathState s) // overwrite virtual Creature::setDeathState and Unit::setDeathState +{ + Creature::setDeathState(s); + if(getDeathState()==CORPSE) + { + //remove summoned pet (no corpse) + if(getPetType()==SUMMON_PET) + Remove(PET_SAVE_NOT_IN_SLOT); + // other will despawn at corpse desppawning (Pet::Update code) + else + { + // pet corpse non lootable and non skinnable + SetUInt32Value( UNIT_DYNAMIC_FLAGS, 0x00 ); + RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); + + //lose happiness when died and not in BG/Arena + MapEntry const* mapEntry = sMapStore.LookupEntry(GetMapId()); + if(!mapEntry || (mapEntry->map_type != MAP_ARENA && mapEntry->map_type != MAP_BATTLEGROUND)) + ModifyPower(POWER_HAPPINESS, -HAPPINESS_LEVEL_SIZE); + + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); + } + } + else if(getDeathState()==ALIVE) + { + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); + CastPetAuras(true); + } +} + +void Pet::Update(uint32 diff) +{ + if(m_removed) // pet already removed, just wait in remove queue, no updates + return; + + switch( m_deathState ) + { + case CORPSE: + { + if( m_deathTimer <= diff ) + { + assert(getPetType()!=SUMMON_PET && "Must be already removed."); + Remove(PET_SAVE_NOT_IN_SLOT); //hunters' pets never get removed because of death, NEVER! + return; + } + break; + } + case ALIVE: + { + // unsummon pet that lost owner + Unit* owner = GetOwner(); + if(!owner || (!IsWithinDistInMap(owner, OWNER_MAX_DISTANCE) && !isPossessed()) || isControlled() && !owner->GetPetGUID()) + { + Remove(PET_SAVE_NOT_IN_SLOT, true); + return; + } + + if(isControlled()) + { + if( owner->GetPetGUID() != GetGUID() ) + { + Remove(getPetType()==HUNTER_PET?PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); + return; + } + } + + if(m_duration > 0) + { + if(m_duration > diff) + m_duration -= diff; + else + { + Remove(getPetType() != SUMMON_PET ? PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); + return; + } + } + + if(getPetType() != HUNTER_PET) + break; + + //regenerate Focus + if(m_regenTimer <= diff) + { + RegenerateFocus(); + m_regenTimer = 4000; + } + else + m_regenTimer -= diff; + + if(m_happinessTimer <= diff) + { + LooseHappiness(); + m_happinessTimer = 7500; + } + else + m_happinessTimer -= diff; + + if(m_loyaltyTimer <= diff) + { + TickLoyaltyChange(); + m_loyaltyTimer = 12000; + } + else + m_loyaltyTimer -= diff; + + break; + } + default: + break; + } + Creature::Update(diff); +} + +void Pet::RegenerateFocus() +{ + uint32 curValue = GetPower(POWER_FOCUS); + uint32 maxValue = GetMaxPower(POWER_FOCUS); + + if (curValue >= maxValue) + return; + + float addvalue = 24 * sWorld.getRate(RATE_POWER_FOCUS); + + AuraList const& ModPowerRegenPCTAuras = GetAurasByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT); + for(AuraList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) + if ((*i)->GetModifier()->m_miscvalue == POWER_FOCUS) + addvalue *= ((*i)->GetModifier()->m_amount + 100) / 100.0f; + + ModifyPower(POWER_FOCUS, (int32)addvalue); +} + +void Pet::LooseHappiness() +{ + uint32 curValue = GetPower(POWER_HAPPINESS); + if (curValue <= 0) + return; + int32 addvalue = (140 >> GetLoyaltyLevel()) * 125; //value is 70/35/17/8/4 (per min) * 1000 / 8 (timer 7.5 secs) + if(isInCombat()) //we know in combat happiness fades faster, multiplier guess + addvalue = int32(addvalue * 1.5); + ModifyPower(POWER_HAPPINESS, -addvalue); +} + +void Pet::ModifyLoyalty(int32 addvalue) +{ + uint32 loyaltylevel = GetLoyaltyLevel(); + + if(addvalue > 0) //only gain influenced, not loss + addvalue = int32((float)addvalue * sWorld.getRate(RATE_LOYALTY)); + + if(loyaltylevel >= BEST_FRIEND && (addvalue + m_loyaltyPoints) > int32(GetMaxLoyaltyPoints(loyaltylevel))) + return; + + m_loyaltyPoints += addvalue; + + if(m_loyaltyPoints < 0) + { + if(loyaltylevel > REBELLIOUS) + { + //level down + --loyaltylevel; + SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); + m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); + SetTP(m_TrainingPoints - int32(getLevel())); + } + else + { + m_loyaltyPoints = 0; + Unit* owner = GetOwner(); + if(owner && owner->GetTypeId() == TYPEID_PLAYER) + { + WorldPacket data(SMSG_PET_BROKEN, 0); + ((Player*)owner)->GetSession()->SendPacket(&data); + + //run away + ((Player*)owner)->RemovePet(this,PET_SAVE_AS_DELETED); + } + } + } + //level up + else if(m_loyaltyPoints > int32(GetMaxLoyaltyPoints(loyaltylevel))) + { + ++loyaltylevel; + SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); + m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); + SetTP(m_TrainingPoints + getLevel()); + } +} + +void Pet::TickLoyaltyChange() +{ + int32 addvalue; + + switch(GetHappinessState()) + { + case HAPPY: addvalue = 20; break; + case CONTENT: addvalue = 10; break; + case UNHAPPY: addvalue = -20; break; + default: + return; + } + ModifyLoyalty(addvalue); +} + +void Pet::KillLoyaltyBonus(uint32 level) +{ + if(level > 100) + return; + + //at lower levels gain is faster | the lower loyalty the more loyalty is gained + uint32 bonus = uint32(((100 - level) / 10) + (6 - GetLoyaltyLevel())); + ModifyLoyalty(bonus); +} + +HappinessState Pet::GetHappinessState() +{ + if(GetPower(POWER_HAPPINESS) < HAPPINESS_LEVEL_SIZE) + return UNHAPPY; + else if(GetPower(POWER_HAPPINESS) >= HAPPINESS_LEVEL_SIZE * 2) + return HAPPY; + else + return CONTENT; +} + +void Pet::SetLoyaltyLevel(LoyaltyLevel level) +{ + SetByteValue(UNIT_FIELD_BYTES_1, 1, level); +} + +bool Pet::CanTakeMoreActiveSpells(uint32 spellid) +{ + uint8 activecount = 1; + uint32 chainstartstore[ACTIVE_SPELLS_MAX]; + + if(IsPassiveSpell(spellid)) + return true; + + chainstartstore[0] = spellmgr.GetFirstSpellInChain(spellid); + + for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) + { + if(IsPassiveSpell(itr->first)) + continue; + + uint32 chainstart = spellmgr.GetFirstSpellInChain(itr->first); + + uint8 x; + + for(x = 0; x < activecount; x++) + { + if(chainstart == chainstartstore[x]) + break; + } + + if(x == activecount) //spellchain not yet saved -> add active count + { + ++activecount; + if(activecount > ACTIVE_SPELLS_MAX) + return false; + chainstartstore[x] = chainstart; + } + } + return true; +} + +bool Pet::HasTPForSpell(uint32 spellid) +{ + int32 neededtrainp = GetTPForSpell(spellid); + if((m_TrainingPoints - neededtrainp < 0 || neededtrainp < 0) && neededtrainp != 0) + return false; + return true; +} + +int32 Pet::GetTPForSpell(uint32 spellid) +{ + uint32 basetrainp = 0; + + SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellid); + SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellid); + for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) + { + if(!_spell_idx->second->reqtrainpoints) + return 0; + + basetrainp = _spell_idx->second->reqtrainpoints; + break; + } + + uint32 spenttrainp = 0; + uint32 chainstart = spellmgr.GetFirstSpellInChain(spellid); + + for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) + { + if(itr->second->state == PETSPELL_REMOVED) + continue; + + if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) + { + SkillLineAbilityMap::const_iterator _lower = spellmgr.GetBeginSkillLineAbilityMap(itr->first); + SkillLineAbilityMap::const_iterator _upper = spellmgr.GetEndSkillLineAbilityMap(itr->first); + + for(SkillLineAbilityMap::const_iterator _spell_idx2 = _lower; _spell_idx2 != _upper; ++_spell_idx2) + { + if(_spell_idx2->second->reqtrainpoints > spenttrainp) + { + spenttrainp = _spell_idx2->second->reqtrainpoints; + break; + } + } + } + } + + return int32(basetrainp) - int32(spenttrainp); +} + +uint32 Pet::GetMaxLoyaltyPoints(uint32 level) +{ + return LevelUpLoyalty[level - 1]; +} + +uint32 Pet::GetStartLoyaltyPoints(uint32 level) +{ + return LevelStartLoyalty[level - 1]; +} + +void Pet::SetTP(int32 TP) +{ + m_TrainingPoints = TP; + SetUInt32Value(UNIT_TRAINING_POINTS, (uint32)GetDispTP()); +} + +int32 Pet::GetDispTP() +{ + if(getPetType()!= HUNTER_PET) + return(0); + if(m_TrainingPoints < 0) + return -m_TrainingPoints; + else + return -(m_TrainingPoints + 1); +} + +void Pet::Remove(PetSaveMode mode, bool returnreagent) +{ + Unit* owner = GetOwner(); + + if(owner) + { + if(owner->GetTypeId()==TYPEID_PLAYER) + { + ((Player*)owner)->RemovePet(this,mode,returnreagent); + return; + } + + // only if current pet in slot + if(owner->GetPetGUID()==GetGUID()) + owner->SetPet(0); + } + + CleanupsBeforeDelete(); + AddObjectToRemoveList(); + m_removed = true; +} + +void Pet::GivePetXP(uint32 xp) +{ + if(getPetType() != HUNTER_PET) + return; + + if ( xp < 1 ) + return; + + if(!isAlive()) + return; + + uint32 level = getLevel(); + + // XP to money conversion processed in Player::RewardQuest + if(level >= sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) + return; + + uint32 curXP = GetUInt32Value(UNIT_FIELD_PETEXPERIENCE); + uint32 nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); + uint32 newXP = curXP + xp; + + if(newXP >= nextLvlXP && level+1 > GetOwner()->getLevel()) + { + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, nextLvlXP-1); + return; + } + + while( newXP >= nextLvlXP && level < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL) ) + { + newXP -= nextLvlXP; + + SetLevel( level + 1 ); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(level+1))/4)); + + level = getLevel(); + nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); + GivePetLevel(level); + } + + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, newXP); + + if(getPetType() == HUNTER_PET) + KillLoyaltyBonus(level); +} + +void Pet::GivePetLevel(uint32 level) +{ + if(!level) + return; + + InitStatsForLevel( level); + + SetTP(m_TrainingPoints + (GetLoyaltyLevel() - 1)); +} + +bool Pet::CreateBaseAtCreature(Creature* creature) +{ + if(!creature) + { + sLog.outError("CRITICAL ERROR: NULL pointer parsed into CreateBaseAtCreature()"); + return false; + } + uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); + + sLog.outBasic("SetInstanceID()"); + SetInstanceId(creature->GetInstanceId()); + + sLog.outBasic("Create pet"); + uint32 pet_number = objmgr.GeneratePetNumber(); + if(!Create(guid, creature->GetMap(), creature->GetEntry(), pet_number)) + return false; + + Relocate(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); + + if(!IsPositionValid()) + { + sLog.outError("ERROR: Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)", + GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); + return false; + } + + CreatureInfo const *cinfo = GetCreatureInfo(); + if(!cinfo) + { + sLog.outError("ERROR: CreateBaseAtCreature() failed, creatureInfo is missing!"); + return false; + } + + if(cinfo->type == CREATURE_TYPE_CRITTER) + { + setPetType(MINI_PET); + return true; + } + SetDisplayId(creature->GetDisplayId()); + SetNativeDisplayId(creature->GetNativeDisplayId()); + SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + SetPower( POWER_HAPPINESS,166500); + setPowerType(POWER_FOCUS); + SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,0); + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(creature->getLevel()))/4)); + SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); + SetUInt32Value(UNIT_NPC_FLAGS , 0); + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(creature->GetCreatureInfo()->family); + if( char* familyname = cFamily->Name[sWorld.GetDefaultDbcLocale()] ) + SetName(familyname); + else + SetName(creature->GetName()); + + m_loyaltyPoints = 1000; + if(cinfo->type == CREATURE_TYPE_BEAST) + { + SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); + SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); + SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); + + SetUInt32Value(UNIT_MOD_CAST_SPEED, creature->GetUInt32Value(UNIT_MOD_CAST_SPEED) ); + SetLoyaltyLevel(REBELLIOUS); + } + return true; +} + +bool Pet::InitStatsForLevel(uint32 petlevel) +{ + CreatureInfo const *cinfo = GetCreatureInfo(); + assert(cinfo); + + Unit* owner = GetOwner(); + if(!owner) + { + sLog.outError("ERROR: attempt to summon pet (Entry %u) without owner! Attempt terminated.", cinfo->Entry); + return false; + } + + uint32 creature_ID = (getPetType() == HUNTER_PET) ? 1 : cinfo->Entry; + + SetLevel( petlevel); + + SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool)); + + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(petlevel*50)); + + SetAttackTime(BASE_ATTACK, BASE_ATTACK_TIME); + SetAttackTime(OFF_ATTACK, BASE_ATTACK_TIME); + SetAttackTime(RANGED_ATTACK, BASE_ATTACK_TIME); + + SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0); + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family); + if(cFamily && cFamily->minScale > 0.0f) + { + float scale; + if (getLevel() >= cFamily->maxScaleLevel) + scale = cFamily->maxScale; + else if (getLevel() <= cFamily->minScaleLevel) + scale = cFamily->minScale; + else + scale = cFamily->minScale + (getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale); + + SetFloatValue(OBJECT_FIELD_SCALE_X, scale); + } + m_bonusdamage = 0; + + int32 createResistance[MAX_SPELL_SCHOOL] = {0,0,0,0,0,0,0}; + + if(cinfo && getPetType() != HUNTER_PET) + { + createResistance[SPELL_SCHOOL_HOLY] = cinfo->resistance1; + createResistance[SPELL_SCHOOL_FIRE] = cinfo->resistance2; + createResistance[SPELL_SCHOOL_NATURE] = cinfo->resistance3; + createResistance[SPELL_SCHOOL_FROST] = cinfo->resistance4; + createResistance[SPELL_SCHOOL_SHADOW] = cinfo->resistance5; + createResistance[SPELL_SCHOOL_ARCANE] = cinfo->resistance6; + } + + switch(getPetType()) + { + case SUMMON_PET: + { + if(owner->GetTypeId() == TYPEID_PLAYER) + { + switch(owner->getClass()) + { + case CLASS_WARLOCK: + { + + //the damage bonus used for pets is either fire or shadow damage, whatever is higher + uint32 fire = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE); + uint32 shadow = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); + uint32 val = (fire > shadow) ? fire : shadow; + + SetBonusDamage(int32 (val * 0.15f)); + //bonusAP += val * 0.57; + break; + } + case CLASS_MAGE: + { + //40% damage bonus of mage's frost damage + float val = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST) * 0.4; + if(val < 0) + val = 0; + SetBonusDamage( int32(val)); + break; + } + default: + break; + } + } + + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); + + //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); + + PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); + if(pInfo) // exist in DB + { + SetCreateHealth(pInfo->health); + SetCreateMana(pInfo->mana); + + if(pInfo->armor > 0) + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); + + for(int stat = 0; stat < MAX_STATS; ++stat) + { + SetCreateStat(Stats(stat),float(pInfo->stats[stat])); + } + } + else // not exist in DB, use some default fake data + { + sLog.outErrorDb("Summoned pet (Entry: %u) not have pet stats data in DB",cinfo->Entry); + + // remove elite bonuses included in DB values + SetCreateHealth(uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); + SetCreateMana( uint32(((float(cinfo->maxmana) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); + + SetCreateStat(STAT_STRENGTH,22); + SetCreateStat(STAT_AGILITY,22); + SetCreateStat(STAT_STAMINA,25); + SetCreateStat(STAT_INTELLECT,28); + SetCreateStat(STAT_SPIRIT,27); + } + break; + } + case HUNTER_PET: + { + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(petlevel))/4)); + + //these formula may not be correct; however, it is designed to be close to what it should be + //this makes dps 0.5 of pets level + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); + //damage range is then petlevel / 2 + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); + //damage is increased afterwards as strength and pet scaling modify attack power + + //stored standard pet stats are entry 1 in pet_levelinfo + PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); + if(pInfo) // exist in DB + { + SetCreateHealth(pInfo->health); + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); + //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); + + for( int i = STAT_STRENGTH; i < MAX_STATS; i++) + { + SetCreateStat(Stats(i), float(pInfo->stats[i])); + } + } + else // not exist in DB, use some default fake data + { + sLog.outErrorDb("Hunter pet levelstats missing in DB"); + + // remove elite bonuses included in DB values + SetCreateHealth( uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); + + SetCreateStat(STAT_STRENGTH,22); + SetCreateStat(STAT_AGILITY,22); + SetCreateStat(STAT_STAMINA,25); + SetCreateStat(STAT_INTELLECT,28); + SetCreateStat(STAT_SPIRIT,27); + } + break; + } + case GUARDIAN_PET: + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP,1000); + + SetCreateMana( 28 + 10*petlevel ); + SetCreateHealth( 28 + 30*petlevel ); + + // FIXME: this is wrong formula, possible each guardian pet have own damage formula + //these formula may not be correct; however, it is designed to be close to what it should be + //this makes dps 0.5 of pets level + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); + //damage range is then petlevel / 2 + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); + break; + default: + sLog.outError("Pet have incorrect type (%u) for levelup.",getPetType()); break; + } + + for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i) + SetModifierValue(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(createResistance[i]) ); + + UpdateAllStats(); + + SetHealth(GetMaxHealth()); + SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); + + return true; +} + +bool Pet::HaveInDiet(ItemPrototype const* item) const +{ + if (!item->FoodType) + return false; + + CreatureInfo const* cInfo = GetCreatureInfo(); + if(!cInfo) + return false; + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); + if(!cFamily) + return false; + + uint32 diet = cFamily->petFoodMask; + uint32 FoodMask = 1 << (item->FoodType-1); + return diet & FoodMask; +} + +uint32 Pet::GetCurrentFoodBenefitLevel(uint32 itemlevel) +{ + // -5 or greater food level + if(getLevel() <= itemlevel +5) //possible to feed level 60 pet with level 55 level food for full effect + return 35000; + // -10..-6 + else if(getLevel() <= itemlevel + 10) //pure guess, but sounds good + return 17000; + // -14..-11 + else if(getLevel() <= itemlevel + 14) //level 55 food gets green on 70, makes sense to me + return 8000; + // -15 or less + else + return 0; //food too low level +} + +void Pet::_LoadSpellCooldowns() +{ + m_CreatureSpellCooldowns.clear(); + m_CreatureCategoryCooldowns.clear(); + + QueryResult *result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + if(result) + { + time_t curTime = time(NULL); + + WorldPacket data(SMSG_SPELL_COOLDOWN, (8+1+result->GetRowCount()*8)); + data << GetGUID(); + data << uint8(0x0); // flags (0x1, 0x2) + + do + { + Field *fields = result->Fetch(); + + uint32 spell_id = fields[0].GetUInt32(); + time_t db_time = (time_t)fields[1].GetUInt64(); + + if(!sSpellStore.LookupEntry(spell_id)) + { + sLog.outError("Pet %u have unknown spell %u in `pet_spell_cooldown`, skipping.",m_charmInfo->GetPetNumber(),spell_id); + continue; + } + + // skip outdated cooldown + if(db_time <= curTime) + continue; + + data << uint32(spell_id); + data << uint32(uint32(db_time-curTime)*1000); // in m.secs + + _AddCreatureSpellCooldown(spell_id,db_time); + + sLog.outDebug("Pet (Number: %u) spell %u cooldown loaded (%u secs).",m_charmInfo->GetPetNumber(),spell_id,uint32(db_time-curTime)); + } + while( result->NextRow() ); + + delete result; + + if(!m_CreatureSpellCooldowns.empty() && GetOwner()) + { + ((Player*)GetOwner())->GetSession()->SendPacket(&data); + } + } +} + +void Pet::_SaveSpellCooldowns() +{ + CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", m_charmInfo->GetPetNumber()); + + time_t curTime = time(NULL); + + // remove oudated and save active + for(CreatureSpellCooldowns::iterator itr = m_CreatureSpellCooldowns.begin();itr != m_CreatureSpellCooldowns.end();) + { + if(itr->second <= curTime) + m_CreatureSpellCooldowns.erase(itr++); + else + { + CharacterDatabase.PExecute("INSERT INTO pet_spell_cooldown (guid,spell,time) VALUES ('%u', '%u', '" I64FMTD "')", m_charmInfo->GetPetNumber(), itr->first, uint64(itr->second)); + ++itr; + } + } +} + +void Pet::_LoadSpells() +{ + QueryResult *result = CharacterDatabase.PQuery("SELECT spell,slot,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + if(result) + { + do + { + Field *fields = result->Fetch(); + + addSpell(fields[0].GetUInt16(), (ActiveStates)fields[2].GetUInt16(), PETSPELL_UNCHANGED, fields[1].GetUInt16()); + } + while( result->NextRow() ); + + delete result; + } +} + +void Pet::_SaveSpells() +{ + for (PetSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next) + { + ++next; + if (itr->second->type == PETSPELL_FAMILY) continue; // prevent saving family passives to DB + if (itr->second->state == PETSPELL_REMOVED || itr->second->state == PETSPELL_CHANGED) + CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first); + if (itr->second->state == PETSPELL_NEW || itr->second->state == PETSPELL_CHANGED) + CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,slot,active) VALUES ('%u', '%u', '%u','%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second->slotId,itr->second->active); + + if (itr->second->state == PETSPELL_REMOVED) + _removeSpell(itr->first); + else + itr->second->state = PETSPELL_UNCHANGED; + } +} + +void Pet::_LoadAuras(uint32 timediff) +{ + m_Auras.clear(); + for (int i = 0; i < TOTAL_AURAS; i++) + m_modAuras[i].clear(); + + // all aura related fields + for(int i = UNIT_FIELD_AURA; i <= UNIT_FIELD_AURASTATE; ++i) + SetUInt32Value(i, 0); + + QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + if(result) + { + do + { + Field *fields = result->Fetch(); + uint64 caster_guid = fields[0].GetUInt64(); + uint32 spellid = fields[1].GetUInt32(); + uint32 effindex = fields[2].GetUInt32(); + int32 damage = (int32)fields[3].GetUInt32(); + int32 maxduration = (int32)fields[4].GetUInt32(); + int32 remaintime = (int32)fields[5].GetUInt32(); + int32 remaincharges = (int32)fields[6].GetUInt32(); + + SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid); + if(!spellproto) + { + sLog.outError("Unknown aura (spellid %u, effindex %u), ignore.",spellid,effindex); + continue; + } + + if(effindex >= 3) + { + sLog.outError("Invalid effect index (spellid %u, effindex %u), ignore.",spellid,effindex); + continue; + } + + // negative effects should continue counting down after logout + if (remaintime != -1 && !IsPositiveEffect(spellid, effindex)) + { + if(remaintime <= int32(timediff)) + continue; + + remaintime -= timediff; + } + + // prevent wrong values of remaincharges + if(spellproto->procCharges) + { + if(remaincharges <= 0 || remaincharges > spellproto->procCharges) + remaincharges = spellproto->procCharges; + } + else + remaincharges = -1; + + /// do not load single target auras (unless they were cast by the player) + if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) + continue; + + Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); + + if(!damage) + damage = aura->GetModifier()->m_amount; + aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); + AddAura(aura); + } + while( result->NextRow() ); + + delete result; + } +} + +void Pet::_SaveAuras() +{ + CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + AuraMap const& auras = GetAuras(); + for(AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) + { + // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras. + SpellEntry const *spellInfo = itr->second->GetSpellProto(); + uint8 i; + for (i = 0; i < 3; i++) + if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET ) + break; + + if (i != 3) + continue; + + if(itr->second->IsPassive()) + continue; + + /// do not save single target auras (unless they were cast by the player) + if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)) + continue; + + CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " + "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')", + m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); + } +} + +bool Pet::addSpell(uint16 spell_id, ActiveStates active, PetSpellState state, uint16 slot_id, PetSpellType type) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id); + if (!spellInfo) + { + // do pet spell book cleanup + if(state == PETSPELL_UNCHANGED) // spell load case + { + sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request, deleting for all pets in `pet_spell`.",spell_id); + CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE spell = '%u'",spell_id); + } + else + sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request.",spell_id); + + return false; + } + // same spells don't have autocast option + if (spellInfo->AttributesEx & SPELL_ATTR_EX_PET_NOT_AUTOCAST) + active = ACT_CAST; + + PetSpellMap::iterator itr = m_spells.find(spell_id); + if (itr != m_spells.end()) + { + if (itr->second->state == PETSPELL_REMOVED) + { + delete itr->second; + m_spells.erase(itr); + state = PETSPELL_CHANGED; + } + else if (state == PETSPELL_UNCHANGED && itr->second->state != PETSPELL_UNCHANGED) + { + // can be in case spell loading but learned at some previous spell loading + itr->second->state = PETSPELL_UNCHANGED; + return false; + } + else + return false; + } + + uint32 oldspell_id = 0; + + PetSpell *newspell = new PetSpell; + newspell->state = state; + newspell->type = type; + + if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here + { + if(IsPassiveSpell(spell_id)) + newspell->active = ACT_PASSIVE; + else + newspell->active = ACT_DISABLED; + } + else + newspell->active = active; + + uint32 chainstart = spellmgr.GetFirstSpellInChain(spell_id); + + for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); itr++) + { + if(itr->second->state == PETSPELL_REMOVED) continue; + + if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) + { + slot_id = itr->second->slotId; + newspell->active = itr->second->active; + + if(newspell->active == ACT_ENABLED) + ToggleAutocast(itr->first, false); + + oldspell_id = itr->first; + removeSpell(itr->first); + } + } + + uint16 tmpslot=slot_id; + + if (tmpslot == 0xffff) + { + uint16 maxid = 0; + PetSpellMap::iterator itr; + for (itr = m_spells.begin(); itr != m_spells.end(); ++itr) + { + if(itr->second->state == PETSPELL_REMOVED) continue; + if (itr->second->slotId > maxid) maxid = itr->second->slotId; + } + tmpslot = maxid + 1; + } + + newspell->slotId = tmpslot; + m_spells[spell_id] = newspell; + + if (IsPassiveSpell(spell_id)) + CastSpell(this, spell_id, true); + else if(state == PETSPELL_NEW) + m_charmInfo->AddSpellToAB(oldspell_id, spell_id, active); + + if(newspell->active == ACT_ENABLED) + ToggleAutocast(spell_id, true); + + return true; +} + +bool Pet::learnSpell(uint16 spell_id) +{ + // prevent duplicated entires in spell book + if (!addSpell(spell_id)) + return false; + + Unit* owner = GetOwner(); + if(owner->GetTypeId()==TYPEID_PLAYER) + ((Player*)owner)->PetSpellInitialize(); + return true; +} + +void Pet::removeSpell(uint16 spell_id) +{ + PetSpellMap::iterator itr = m_spells.find(spell_id); + if (itr == m_spells.end()) + return; + + if(itr->second->state == PETSPELL_REMOVED) + return; + + if(itr->second->state == PETSPELL_NEW) + { + delete itr->second; + m_spells.erase(itr); + } + else + itr->second->state = PETSPELL_REMOVED; + + RemoveAurasDueToSpell(spell_id); +} + +bool Pet::_removeSpell(uint16 spell_id) +{ + PetSpellMap::iterator itr = m_spells.find(spell_id); + if (itr != m_spells.end()) + { + delete itr->second; + m_spells.erase(itr); + return true; + } + return false; +} + +void Pet::InitPetCreateSpells() +{ + m_charmInfo->InitPetActionBar(); + + m_spells.clear(); + int32 usedtrainpoints = 0, petspellid; + PetCreateSpellEntry const* CreateSpells = objmgr.GetPetCreateSpellEntry(GetEntry()); + if(CreateSpells) + { + for(uint8 i = 0; i < 4; i++) + { + if(!CreateSpells->spellid[i]) + break; + + SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(CreateSpells->spellid[i]); + if(!learn_spellproto) + continue; + + if(learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_SPELL || learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_PET_SPELL) + { + petspellid = learn_spellproto->EffectTriggerSpell[0]; + Unit* owner = GetOwner(); + if(owner->GetTypeId() == TYPEID_PLAYER && !((Player*)owner)->HasSpell(learn_spellproto->Id)) + { + if(IsPassiveSpell(petspellid)) //learn passive skills when tamed, not sure if thats right + ((Player*)owner)->learnSpell(learn_spellproto->Id); + else + AddTeachSpell(learn_spellproto->EffectTriggerSpell[0], learn_spellproto->Id); + } + } + else + petspellid = learn_spellproto->Id; + + addSpell(petspellid); + + SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); + SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); + + for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) + { + usedtrainpoints += _spell_idx->second->reqtrainpoints; + break; + } + } + } + + LearnPetPassives(); + + CastPetAuras(false); + + SetTP(-usedtrainpoints); +} + +void Pet::CheckLearning(uint32 spellid) +{ + //charmed case -> prevent crash + if(GetTypeId() == TYPEID_PLAYER || getPetType() != HUNTER_PET) + return; + + Unit* owner = GetOwner(); + + if(m_teachspells.empty() || !owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + TeachSpellMap::iterator itr = m_teachspells.find(spellid); + if(itr == m_teachspells.end()) + return; + + if(urand(0, 100) < 10) + { + ((Player*)owner)->learnSpell(itr->second); + m_teachspells.erase(itr); + } +} + +uint32 Pet::resetTalentsCost() const +{ + uint32 days = (sWorld.GetGameTime() - m_resetTalentsTime)/DAY; + + // The first time reset costs 10 silver; after 1 day cost is reset to 10 silver + if(m_resetTalentsCost < 10*SILVER || days > 0) + return 10*SILVER; + // then 50 silver + else if(m_resetTalentsCost < 50*SILVER) + return 50*SILVER; + // then 1 gold + else if(m_resetTalentsCost < 1*GOLD) + return 1*GOLD; + // then increasing at a rate of 1 gold; cap 10 gold + else + return (m_resetTalentsCost + 1*GOLD > 10*GOLD ? 10*GOLD : m_resetTalentsCost + 1*GOLD); +} + +void Pet::ToggleAutocast(uint32 spellid, bool apply) +{ + if(IsPassiveSpell(spellid)) + return; + + /*if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid)) + if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER + && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE) + return; */ + + PetSpellMap::const_iterator itr = m_spells.find((uint16)spellid); + + int i; + + if(apply) + { + for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++); + if (i == m_autospells.size()) + { + m_autospells.push_back(spellid); + itr->second->active = ACT_ENABLED; + itr->second->state = PETSPELL_CHANGED; + } + } + else + { + AutoSpellList::iterator itr2 = m_autospells.begin(); + for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++, itr2++); + if (i < m_autospells.size()) + { + m_autospells.erase(itr2); + itr->second->active = ACT_DISABLED; + itr->second->state = PETSPELL_CHANGED; + } + } +} + +bool Pet::Create(uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number) +{ + SetMapId(map->GetId()); + SetInstanceId(map->GetInstanceId()); + + Object::_Create(guidlow, pet_number, HIGHGUID_PET); + + m_DBTableGuid = guidlow; + m_originalEntry = Entry; + + if(!InitEntry(Entry)) + return false; + + SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); + + if(getPetType() == MINI_PET) // always non-attackable + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); + + return true; +} + +bool Pet::HasSpell(uint32 spell) const +{ + return (m_spells.find(spell) != m_spells.end()); +} + +// Get all passive spells in our skill line +void Pet::LearnPetPassives() +{ + CreatureInfo const* cInfo = GetCreatureInfo(); + if(!cInfo) + return; + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); + if(!cFamily) + return; + + PetFamilySpellsStore::const_iterator petStore = sPetFamilySpellsStore.find(cFamily->ID); + if(petStore != sPetFamilySpellsStore.end()) + { + for(PetFamilySpellsSet::const_iterator petSet = petStore->second.begin(); petSet != petStore->second.end(); ++petSet) + addSpell(*petSet, ACT_DECIDE, PETSPELL_NEW, 0xffff, PETSPELL_FAMILY); + } +} + +void Pet::CastPetAuras(bool current) +{ + Unit* owner = GetOwner(); + if(!owner) + return; + + if(getPetType() != HUNTER_PET && (getPetType() != SUMMON_PET || owner->getClass() != CLASS_WARLOCK)) + return; + + for(PetAuraSet::iterator itr = owner->m_petAuras.begin(); itr != owner->m_petAuras.end(); ) + { + PetAura const* pa = *itr; + ++itr; + + if(!current && pa->IsRemovedOnChangePet()) + owner->RemovePetAura(pa); + else + CastPetAura(pa); + } +} + +void Pet::CastPetAura(PetAura const* aura) +{ + uint16 auraId = aura->GetAura(GetEntry()); + if(!auraId) + return; + + if(auraId == 35696) // Demonic Knowledge + { + int32 basePoints = int32(aura->GetDamage() * (GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)) / 100); + CastCustomSpell(this,auraId,&basePoints, NULL, NULL, true ); + } + else + CastSpell(this, auraId, true); +} diff --git a/src/game/Pet.h b/src/game/Pet.h index ea13bd5d0dc..90f7584dd2c 100644 --- a/src/game/Pet.h +++ b/src/game/Pet.h @@ -1,264 +1,264 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITYCORE_PET_H -#define TRINITYCORE_PET_H - -#include "ObjectDefines.h" -#include "Creature.h" -#include "Unit.h" - -enum PetType -{ - SUMMON_PET = 0, - HUNTER_PET = 1, - GUARDIAN_PET = 2, - MINI_PET = 3, - MAX_PET_TYPE = 4 -}; - -extern char const* petTypeSuffix[MAX_PET_TYPE]; - -enum PetSaveMode -{ - PET_SAVE_AS_DELETED =-1, - PET_SAVE_AS_CURRENT = 0, - PET_SAVE_IN_STABLE_SLOT_1 = 1, - PET_SAVE_IN_STABLE_SLOT_2 = 2, - PET_SAVE_NOT_IN_SLOT = 3 -}; - -enum HappinessState -{ - UNHAPPY = 1, - CONTENT = 2, - HAPPY = 3 -}; - -enum LoyaltyLevel -{ - REBELLIOUS = 1, - UNRULY = 2, - SUBMISSIVE = 3, - DEPENDABLE = 4, - FAITHFUL = 5, - BEST_FRIEND = 6 -}; - -enum PetSpellState -{ - PETSPELL_UNCHANGED = 0, - PETSPELL_CHANGED = 1, - PETSPELL_NEW = 2, - PETSPELL_REMOVED = 3 -}; - -enum PetSpellType -{ - PETSPELL_NORMAL = 0, - PETSPELL_FAMILY = 1, -}; - -struct PetSpell -{ - uint16 slotId; - uint16 active; - PetSpellState state : 16; - PetSpellType type : 16; -}; - -enum ActionFeedback -{ - FEEDBACK_NONE = 0, - FEEDBACK_PET_DEAD = 1, - FEEDBACK_NOTHING_TO_ATT = 2, - FEEDBACK_CANT_ATT_TARGET = 3 -}; - -enum PetTalk -{ - PET_TALK_SPECIAL_SPELL = 0, - PET_TALK_ATTACK = 1 -}; - -enum PetNameInvalidReason -{ - PET_NAME_INVALID = 1, - PET_NAME_NO_NAME = 2, - PET_NAME_TOO_SHORT = 3, - PET_NAME_TOO_LONG = 4, - PET_NAME_MIXED_LANGUAGES = 6, - PET_NAME_PROFANE = 7, - PET_NAME_RESERVED = 8, - PET_NAME_THREE_CONSECUTIVE = 11, - PET_NAME_INVALID_SPACE = 12, - PET_NAME_CONSECUTIVE_SPACES = 13, - PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14, - PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15, - PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 -}; - -typedef UNORDERED_MAP PetSpellMap; -typedef std::map TeachSpellMap; -typedef std::vector AutoSpellList; - -#define HAPPINESS_LEVEL_SIZE 333000 - -extern const uint32 LevelUpLoyalty[6]; -extern const uint32 LevelStartLoyalty[6]; - -#define ACTIVE_SPELLS_MAX 4 - -#define OWNER_MAX_DISTANCE 100 - -#define PET_FOLLOW_DIST 1 -#define PET_FOLLOW_ANGLE (M_PI/2) - -class Pet : public Creature -{ - public: - explicit Pet(PetType type = MAX_PET_TYPE); - virtual ~Pet(); - - void AddToWorld(); - void RemoveFromWorld(); - - PetType getPetType() const { return m_petType; } - void setPetType(PetType type) { m_petType = type; } - bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; } - bool isTemporarySummoned() const { return m_duration > 0; } - - bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number); - bool CreateBaseAtCreature( Creature* creature ); - bool LoadPetFromDB( Unit* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false ); - void SavePetToDB(PetSaveMode mode); - void Remove(PetSaveMode mode, bool returnreagent = false); - static void DeleteFromDB(uint32 guidlow); - - void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState - void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update - - uint8 GetPetAutoSpellSize() const { return m_autospells.size(); } - uint32 GetPetAutoSpellOnPos(uint8 pos) const - { - if (pos >= m_autospells.size()) - return 0; - else - return m_autospells[pos]; - } - - void RegenerateFocus(); - void LooseHappiness(); - void TickLoyaltyChange(); - void ModifyLoyalty(int32 addvalue); - HappinessState GetHappinessState(); - uint32 GetMaxLoyaltyPoints(uint32 level); - uint32 GetStartLoyaltyPoints(uint32 level); - void KillLoyaltyBonus(uint32 level); - uint32 GetLoyaltyLevel() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); } - void SetLoyaltyLevel(LoyaltyLevel level); - void GivePetXP(uint32 xp); - void GivePetLevel(uint32 level); - bool InitStatsForLevel(uint32 level); - bool HaveInDiet(ItemPrototype const* item) const; - uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel); - void SetDuration(int32 dur) { m_duration = dur; } - - int32 GetBonusDamage() { return m_bonusdamage; } - void SetBonusDamage(int32 damage) { m_bonusdamage = damage; } - - bool UpdateStats(Stats stat); - bool UpdateAllStats(); - void UpdateResistances(uint32 school); - void UpdateArmor(); - void UpdateMaxHealth(); - void UpdateMaxPower(Powers power); - void UpdateAttackPowerAndDamage(bool ranged = false); - void UpdateDamagePhysical(WeaponAttackType attType); - - bool CanTakeMoreActiveSpells(uint32 SpellIconID); - void ToggleAutocast(uint32 spellid, bool apply); - bool HasTPForSpell(uint32 spellid); - int32 GetTPForSpell(uint32 spellid); - - bool HasSpell(uint32 spell) const; - void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; } - - void LearnPetPassives(); - void CastPetAuras(bool current); - void CastPetAura(PetAura const* aura); - - void _LoadSpellCooldowns(); - void _SaveSpellCooldowns(); - void _LoadAuras(uint32 timediff); - void _SaveAuras(); - void _LoadSpells(); - void _SaveSpells(); - - bool addSpell(uint16 spell_id,uint16 active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, uint16 slot_id=0xffff, PetSpellType type = PETSPELL_NORMAL); - bool learnSpell(uint16 spell_id); - void removeSpell(uint16 spell_id); - bool _removeSpell(uint16 spell_id); - - PetSpellMap m_spells; - TeachSpellMap m_teachspells; - AutoSpellList m_autospells; - - void InitPetCreateSpells(); - void CheckLearning(uint32 spellid); - uint32 resetTalentsCost() const; - - void SetTP(int32 TP); - int32 GetDispTP(); - - int32 m_TrainingPoints; - uint32 m_resetTalentsCost; - time_t m_resetTalentsTime; - - uint64 GetAuraUpdateMask() { return m_auraUpdateMask; } - void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); } - void ResetAuraUpdateMask() { m_auraUpdateMask = 0; } - - DeclinedName const* GetDeclinedNames() const { return m_declinedname; } - - bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved) - protected: - uint32 m_regenTimer; - uint32 m_happinessTimer; - uint32 m_loyaltyTimer; - PetType m_petType; - int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets) - int32 m_loyaltyPoints; - int32 m_bonusdamage; - uint64 m_auraUpdateMask; - - DeclinedName *m_declinedname; - - private: - void SaveToDB(uint32, uint8) // overwrited of Creature::SaveToDB - don't must be called - { - assert(false); - } - void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called - { - assert(false); - } -}; -#endif +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TRINITYCORE_PET_H +#define TRINITYCORE_PET_H + +#include "ObjectDefines.h" +#include "Creature.h" +#include "Unit.h" + +enum PetType +{ + SUMMON_PET = 0, + HUNTER_PET = 1, + GUARDIAN_PET = 2, + MINI_PET = 3, + MAX_PET_TYPE = 4 +}; + +extern char const* petTypeSuffix[MAX_PET_TYPE]; + +enum PetSaveMode +{ + PET_SAVE_AS_DELETED =-1, + PET_SAVE_AS_CURRENT = 0, + PET_SAVE_IN_STABLE_SLOT_1 = 1, + PET_SAVE_IN_STABLE_SLOT_2 = 2, + PET_SAVE_NOT_IN_SLOT = 3 +}; + +enum HappinessState +{ + UNHAPPY = 1, + CONTENT = 2, + HAPPY = 3 +}; + +enum LoyaltyLevel +{ + REBELLIOUS = 1, + UNRULY = 2, + SUBMISSIVE = 3, + DEPENDABLE = 4, + FAITHFUL = 5, + BEST_FRIEND = 6 +}; + +enum PetSpellState +{ + PETSPELL_UNCHANGED = 0, + PETSPELL_CHANGED = 1, + PETSPELL_NEW = 2, + PETSPELL_REMOVED = 3 +}; + +enum PetSpellType +{ + PETSPELL_NORMAL = 0, + PETSPELL_FAMILY = 1, +}; + +struct PetSpell +{ + uint16 slotId; + uint16 active; + PetSpellState state : 16; + PetSpellType type : 16; +}; + +enum ActionFeedback +{ + FEEDBACK_NONE = 0, + FEEDBACK_PET_DEAD = 1, + FEEDBACK_NOTHING_TO_ATT = 2, + FEEDBACK_CANT_ATT_TARGET = 3 +}; + +enum PetTalk +{ + PET_TALK_SPECIAL_SPELL = 0, + PET_TALK_ATTACK = 1 +}; + +enum PetNameInvalidReason +{ + PET_NAME_INVALID = 1, + PET_NAME_NO_NAME = 2, + PET_NAME_TOO_SHORT = 3, + PET_NAME_TOO_LONG = 4, + PET_NAME_MIXED_LANGUAGES = 6, + PET_NAME_PROFANE = 7, + PET_NAME_RESERVED = 8, + PET_NAME_THREE_CONSECUTIVE = 11, + PET_NAME_INVALID_SPACE = 12, + PET_NAME_CONSECUTIVE_SPACES = 13, + PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14, + PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15, + PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 +}; + +typedef UNORDERED_MAP PetSpellMap; +typedef std::map TeachSpellMap; +typedef std::vector AutoSpellList; + +#define HAPPINESS_LEVEL_SIZE 333000 + +extern const uint32 LevelUpLoyalty[6]; +extern const uint32 LevelStartLoyalty[6]; + +#define ACTIVE_SPELLS_MAX 4 + +#define OWNER_MAX_DISTANCE 100 + +#define PET_FOLLOW_DIST 1 +#define PET_FOLLOW_ANGLE (M_PI/2) + +class Pet : public Creature +{ + public: + explicit Pet(PetType type = MAX_PET_TYPE); + virtual ~Pet(); + + void AddToWorld(); + void RemoveFromWorld(); + + PetType getPetType() const { return m_petType; } + void setPetType(PetType type) { m_petType = type; } + bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; } + bool isTemporarySummoned() const { return m_duration > 0; } + + bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number); + bool CreateBaseAtCreature( Creature* creature ); + bool LoadPetFromDB( Unit* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false ); + void SavePetToDB(PetSaveMode mode); + void Remove(PetSaveMode mode, bool returnreagent = false); + static void DeleteFromDB(uint32 guidlow); + + void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState + void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update + + uint8 GetPetAutoSpellSize() const { return m_autospells.size(); } + uint32 GetPetAutoSpellOnPos(uint8 pos) const + { + if (pos >= m_autospells.size()) + return 0; + else + return m_autospells[pos]; + } + + void RegenerateFocus(); + void LooseHappiness(); + void TickLoyaltyChange(); + void ModifyLoyalty(int32 addvalue); + HappinessState GetHappinessState(); + uint32 GetMaxLoyaltyPoints(uint32 level); + uint32 GetStartLoyaltyPoints(uint32 level); + void KillLoyaltyBonus(uint32 level); + uint32 GetLoyaltyLevel() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); } + void SetLoyaltyLevel(LoyaltyLevel level); + void GivePetXP(uint32 xp); + void GivePetLevel(uint32 level); + bool InitStatsForLevel(uint32 level); + bool HaveInDiet(ItemPrototype const* item) const; + uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel); + void SetDuration(int32 dur) { m_duration = dur; } + + int32 GetBonusDamage() { return m_bonusdamage; } + void SetBonusDamage(int32 damage) { m_bonusdamage = damage; } + + bool UpdateStats(Stats stat); + bool UpdateAllStats(); + void UpdateResistances(uint32 school); + void UpdateArmor(); + void UpdateMaxHealth(); + void UpdateMaxPower(Powers power); + void UpdateAttackPowerAndDamage(bool ranged = false); + void UpdateDamagePhysical(WeaponAttackType attType); + + bool CanTakeMoreActiveSpells(uint32 SpellIconID); + void ToggleAutocast(uint32 spellid, bool apply); + bool HasTPForSpell(uint32 spellid); + int32 GetTPForSpell(uint32 spellid); + + bool HasSpell(uint32 spell) const; + void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; } + + void LearnPetPassives(); + void CastPetAuras(bool current); + void CastPetAura(PetAura const* aura); + + void _LoadSpellCooldowns(); + void _SaveSpellCooldowns(); + void _LoadAuras(uint32 timediff); + void _SaveAuras(); + void _LoadSpells(); + void _SaveSpells(); + + bool addSpell(uint16 spell_id, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, uint16 slot_id=0xffff, PetSpellType type = PETSPELL_NORMAL); + bool learnSpell(uint16 spell_id); + void removeSpell(uint16 spell_id); + bool _removeSpell(uint16 spell_id); + + PetSpellMap m_spells; + TeachSpellMap m_teachspells; + AutoSpellList m_autospells; + + void InitPetCreateSpells(); + void CheckLearning(uint32 spellid); + uint32 resetTalentsCost() const; + + void SetTP(int32 TP); + int32 GetDispTP(); + + int32 m_TrainingPoints; + uint32 m_resetTalentsCost; + time_t m_resetTalentsTime; + + uint64 GetAuraUpdateMask() { return m_auraUpdateMask; } + void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); } + void ResetAuraUpdateMask() { m_auraUpdateMask = 0; } + + DeclinedName const* GetDeclinedNames() const { return m_declinedname; } + + bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved) + protected: + uint32 m_regenTimer; + uint32 m_happinessTimer; + uint32 m_loyaltyTimer; + PetType m_petType; + int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets) + int32 m_loyaltyPoints; + int32 m_bonusdamage; + uint64 m_auraUpdateMask; + + DeclinedName *m_declinedname; + + private: + void SaveToDB(uint32, uint8) // overwrited of Creature::SaveToDB - don't must be called + { + assert(false); + } + void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called + { + assert(false); + } +}; +#endif diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h index 481598f71ea..a9c66fa3028 100644 --- a/src/game/SharedDefines.h +++ b/src/game/SharedDefines.h @@ -248,7 +248,7 @@ enum ItemQualities #define SPELL_ATTR_EX_UNK14 0x00004000 // 14 #define SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY 0x00008000 // 15 remove auras on immunity #define SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE 0x00010000 // 16 unaffected by school immunity -#define SPELL_ATTR_EX_UNK17 0x00020000 // 17 +#define SPELL_ATTR_EX_PET_NOT_AUTOCAST 0x00020000 // 17 #define SPELL_ATTR_EX_UNK18 0x00040000 // 18 #define SPELL_ATTR_EX_UNK19 0x00080000 // 19 #define SPELL_ATTR_EX_REQ_COMBO_POINTS1 0x00100000 // 20 Req combo points on target diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 07a0df04450..97bf4b0d109 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -1,2077 +1,2120 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "SpellMgr.h" -#include "ObjectMgr.h" -#include "SpellAuraDefines.h" -#include "ProgressBar.h" -#include "Database/DBCStores.h" -#include "World.h" -#include "Chat.h" -#include "Spell.h" - -SpellMgr::SpellMgr() -{ -} - -SpellMgr::~SpellMgr() -{ -} - -SpellMgr& SpellMgr::Instance() -{ - static SpellMgr spellMgr; - return spellMgr; -} - -int32 GetSpellDuration(SpellEntry const *spellInfo) -{ - if(!spellInfo) - return 0; - SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); - if(!du) - return 0; - return (du->Duration[0] == -1) ? -1 : abs(du->Duration[0]); -} - -int32 GetSpellMaxDuration(SpellEntry const *spellInfo) -{ - if(!spellInfo) - return 0; - SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); - if(!du) - return 0; - return (du->Duration[2] == -1) ? -1 : abs(du->Duration[2]); -} - -uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell) -{ - SpellCastTimesEntry const *spellCastTimeEntry = sSpellCastTimesStore.LookupEntry(spellInfo->CastingTimeIndex); - - // not all spells have cast time index and this is all is pasiive abilities - if(!spellCastTimeEntry) - return 0; - - int32 castTime = spellCastTimeEntry->CastTime; - - if (spell) - { - if(Player* modOwner = spell->GetCaster()->GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CASTING_TIME, castTime, spell); - - if( !(spellInfo->Attributes & (SPELL_ATTR_UNK4|SPELL_ATTR_UNK5)) ) - castTime = int32(castTime * spell->GetCaster()->GetFloatValue(UNIT_MOD_CAST_SPEED)); - else - { - if (spell->IsRangedSpell() && !spell->IsAutoRepeat()) - castTime = int32(castTime * spell->GetCaster()->m_modAttackSpeedPct[RANGED_ATTACK]); - } - } - - if (spellInfo->Attributes & SPELL_ATTR_RANGED && (!spell || !(spell->IsAutoRepeat()))) - castTime += 500; - - return (castTime > 0) ? uint32(castTime) : 0; -} - -bool IsPassiveSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if (!spellInfo) - return false; - return (spellInfo->Attributes & SPELL_ATTR_PASSIVE) != 0; -} - -bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) -{ - SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); - SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - if(!spellInfo_1 || !spellInfo_2) return false; - if(spellInfo_1->Id == spellId_2) return false; - - if (spellInfo_1->Effect[effIndex_1] != spellInfo_2->Effect[effIndex_2] || - spellInfo_1->EffectItemType[effIndex_1] != spellInfo_2->EffectItemType[effIndex_2] || - spellInfo_1->EffectMiscValue[effIndex_1] != spellInfo_2->EffectMiscValue[effIndex_2] || - spellInfo_1->EffectApplyAuraName[effIndex_1] != spellInfo_2->EffectApplyAuraName[effIndex_2]) - return false; - - return true; -} - -int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) -{ - SpellEntry const*spellInfo_1 = sSpellStore.LookupEntry(spellId_1); - SpellEntry const*spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - if(!spellInfo_1 || !spellInfo_2) return 0; - if (spellId_1 == spellId_2) return 0; - - int32 diff = spellInfo_1->EffectBasePoints[effIndex_1] - spellInfo_2->EffectBasePoints[effIndex_2]; - if (spellInfo_1->EffectBasePoints[effIndex_1]+1 < 0 && spellInfo_2->EffectBasePoints[effIndex_2]+1 < 0) return -diff; - else return diff; -} - -SpellSpecific GetSpellSpecific(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return SPELL_NORMAL; - - switch(spellInfo->SpellFamilyName) - { - case SPELLFAMILY_MAGE: - { - // family flags 18(Molten), 25(Frost/Ice), 28(Mage) - if (spellInfo->SpellFamilyFlags & 0x12040000) - return SPELL_MAGE_ARMOR; - - if ((spellInfo->SpellFamilyFlags & 0x1000000) && spellInfo->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) - return SPELL_MAGE_POLYMORPH; - - break; - } - case SPELLFAMILY_WARRIOR: - { - if (spellInfo->SpellFamilyFlags & 0x00008000010000LL) - return SPELL_POSITIVE_SHOUT; - - break; - } - case SPELLFAMILY_WARLOCK: - { - // only warlock curses have this - if (spellInfo->Dispel == DISPEL_CURSE) - return SPELL_CURSE; - - // family flag 37 (only part spells have family name) - if (spellInfo->SpellFamilyFlags & 0x2000000000LL) - return SPELL_WARLOCK_ARMOR; - - //seed of corruption and corruption - if (spellInfo->SpellFamilyFlags & 0x1000000002LL) - return SPELL_WARLOCK_CORRUPTION; - break; - } - case SPELLFAMILY_HUNTER: - { - // only hunter stings have this - if (spellInfo->Dispel == DISPEL_POISON) - return SPELL_STING; - - break; - } - case SPELLFAMILY_PALADIN: - { - if (IsSealSpell(spellInfo)) - return SPELL_SEAL; - - if (spellInfo->SpellFamilyFlags & 0x10000100LL) - return SPELL_BLESSING; - - if ((spellInfo->SpellFamilyFlags & 0x00000820180400LL) && (spellInfo->AttributesEx3 & 0x200)) - return SPELL_JUDGEMENT; - - for (int i = 0; i < 3; i++) - { - // only paladin auras have this - if (spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY) - return SPELL_AURA; - } - break; - } - case SPELLFAMILY_SHAMAN: - { - if (IsElementalShield(spellInfo)) - return SPELL_ELEMENTAL_SHIELD; - - break; - } - - case SPELLFAMILY_POTION: - return spellmgr.GetSpellElixirSpecific(spellInfo->Id); - } - - // only warlock armor/skin have this (in additional to family cases) - if( spellInfo->SpellVisual == 130 && spellInfo->SpellIconID == 89) - { - return SPELL_WARLOCK_ARMOR; - } - - // only hunter aspects have this (but not all aspects in hunter family) - if( spellInfo->activeIconID == 122 && (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NATURE) && - (spellInfo->Attributes & 0x50000) != 0 && (spellInfo->Attributes & 0x9000010) == 0) - { - return SPELL_ASPECT; - } - - for(int i = 0; i < 3; i++) - if( spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && ( - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_CREATURES || - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_RESOURCES || - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_STEALTHED ) ) - return SPELL_TRACKER; - - // elixirs can have different families, but potion most ofc. - if(SpellSpecific sp = spellmgr.GetSpellElixirSpecific(spellInfo->Id)) - return sp; - - return SPELL_NORMAL; -} - -bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2) -{ - switch(spellSpec1) - { - case SPELL_SEAL: - case SPELL_BLESSING: - case SPELL_AURA: - case SPELL_STING: - case SPELL_CURSE: - case SPELL_ASPECT: - case SPELL_TRACKER: - case SPELL_WARLOCK_ARMOR: - case SPELL_MAGE_ARMOR: - case SPELL_ELEMENTAL_SHIELD: - case SPELL_MAGE_POLYMORPH: - case SPELL_POSITIVE_SHOUT: - case SPELL_JUDGEMENT: - case SPELL_WARLOCK_CORRUPTION: - return spellSpec1==spellSpec2; - case SPELL_BATTLE_ELIXIR: - return spellSpec2==SPELL_BATTLE_ELIXIR - || spellSpec2==SPELL_FLASK_ELIXIR; - case SPELL_GUARDIAN_ELIXIR: - return spellSpec2==SPELL_GUARDIAN_ELIXIR - || spellSpec2==SPELL_FLASK_ELIXIR; - case SPELL_FLASK_ELIXIR: - return spellSpec2==SPELL_BATTLE_ELIXIR - || spellSpec2==SPELL_GUARDIAN_ELIXIR - || spellSpec2==SPELL_FLASK_ELIXIR; - default: - return false; - } -} - -bool IsPositiveTarget(uint32 targetA, uint32 targetB) -{ - // non-positive targets - switch(targetA) - { - case TARGET_CHAIN_DAMAGE: - case TARGET_ALL_ENEMY_IN_AREA: - case TARGET_ALL_ENEMY_IN_AREA_INSTANT: - case TARGET_IN_FRONT_OF_CASTER: - case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: - case TARGET_CURRENT_ENEMY_COORDINATES: - case TARGET_SINGLE_ENEMY: - return false; - case TARGET_ALL_AROUND_CASTER: - return (targetB == TARGET_ALL_PARTY || targetB == TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER); - default: - break; - } - if (targetB) - return IsPositiveTarget(targetB, 0); - return true; -} - -bool IsPositiveEffect(uint32 spellId, uint32 effIndex) -{ - SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); - if (!spellproto) return false; - - switch(spellId) - { - case 23333: // BG spell - case 23335: // BG spell - case 34976: // BG spell - return true; - case 28441: // not positive dummy spell - case 37675: // Chaos Blast - return false; - } - - switch(spellproto->Effect[effIndex]) - { - // always positive effects (check before target checks that provided non-positive result in some case for positive effects) - case SPELL_EFFECT_HEAL: - case SPELL_EFFECT_LEARN_SPELL: - case SPELL_EFFECT_SKILL_STEP: - case SPELL_EFFECT_HEAL_PCT: - case SPELL_EFFECT_ENERGIZE_PCT: - return true; - - // non-positive aura use - case SPELL_EFFECT_APPLY_AURA: - case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND: - { - switch(spellproto->EffectApplyAuraName[effIndex]) - { - case SPELL_AURA_DUMMY: - { - // dummy aura can be positive or negative dependent from casted spell - switch(spellproto->Id) - { - case 13139: // net-o-matic special effect - case 23445: // evil twin - case 38637: // Nether Exhaustion (red) - case 38638: // Nether Exhaustion (green) - case 38639: // Nether Exhaustion (blue) - return false; - default: - break; - } - } break; - case SPELL_AURA_MOD_STAT: - case SPELL_AURA_MOD_DAMAGE_DONE: // dependent from bas point sign (negative -> negative) - case SPELL_AURA_MOD_HEALING_DONE: - { - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) - return false; - break; - } - case SPELL_AURA_ADD_TARGET_TRIGGER: - return true; - case SPELL_AURA_PERIODIC_TRIGGER_SPELL: - if(spellId != spellproto->EffectTriggerSpell[effIndex]) - { - uint32 spellTriggeredId = spellproto->EffectTriggerSpell[effIndex]; - SpellEntry const *spellTriggeredProto = sSpellStore.LookupEntry(spellTriggeredId); - - if(spellTriggeredProto) - { - // non-positive targets of main spell return early - for(int i = 0; i < 3; ++i) - { - // if non-positive trigger cast targeted to positive target this main cast is non-positive - // this will place this spell auras as debuffs - if(IsPositiveTarget(spellTriggeredProto->EffectImplicitTargetA[effIndex],spellTriggeredProto->EffectImplicitTargetB[effIndex]) && !IsPositiveEffect(spellTriggeredId,i)) - return false; - } - } - } - break; - case SPELL_AURA_PROC_TRIGGER_SPELL: - // many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example) - break; - case SPELL_AURA_MOD_STUN: //have positive and negative spells, we can't sort its correctly at this moment. - if(effIndex==0 && spellproto->Effect[1]==0 && spellproto->Effect[2]==0) - return false; // but all single stun aura spells is negative - - // Petrification - if(spellproto->Id == 17624) - return false; - break; - case SPELL_AURA_MOD_ROOT: - case SPELL_AURA_MOD_SILENCE: - case SPELL_AURA_GHOST: - case SPELL_AURA_PERIODIC_LEECH: - case SPELL_AURA_MOD_PACIFY_SILENCE: - case SPELL_AURA_MOD_STALKED: - case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: - return false; - case SPELL_AURA_PERIODIC_DAMAGE: // used in positive spells also. - // part of negative spell if casted at self (prevent cancel) - if(spellproto->EffectImplicitTargetA[effIndex] == TARGET_SELF) - return false; - break; - case SPELL_AURA_MOD_DECREASE_SPEED: // used in positive spells also - // part of positive spell if casted at self - if(spellproto->EffectImplicitTargetA[effIndex] != TARGET_SELF) - return false; - // but not this if this first effect (don't found batter check) - if(spellproto->Attributes & 0x4000000 && effIndex==0) - return false; - break; - case SPELL_AURA_TRANSFORM: - // some spells negative - switch(spellproto->Id) - { - case 36897: // Transporter Malfunction (race mutation to horde) - case 36899: // Transporter Malfunction (race mutation to alliance) - return false; - } - break; - case SPELL_AURA_MOD_SCALE: - // some spells negative - switch(spellproto->Id) - { - case 36900: // Soul Split: Evil! - case 36901: // Soul Split: Good - case 36893: // Transporter Malfunction (decrease size case) - case 36895: // Transporter Malfunction (increase size case) - return false; - } - break; - case SPELL_AURA_MECHANIC_IMMUNITY: - { - // non-positive immunities - switch(spellproto->EffectMiscValue[effIndex]) - { - case MECHANIC_BANDAGE: - case MECHANIC_SHIELD: - case MECHANIC_MOUNT: - case MECHANIC_INVULNERABILITY: - return false; - default: - break; - } - } break; - case SPELL_AURA_ADD_FLAT_MODIFIER: // mods - case SPELL_AURA_ADD_PCT_MODIFIER: - { - // non-positive mods - switch(spellproto->EffectMiscValue[effIndex]) - { - case SPELLMOD_COST: // dependent from bas point sign (negative -> positive) - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) > 0) - return false; - break; - default: - break; - } - } break; - case SPELL_AURA_MOD_HEALING_PCT: - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) - return false; - break; - case SPELL_AURA_MOD_SKILL: - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) - return false; - break; - case SPELL_AURA_FORCE_REACTION: - if(spellproto->Id==42792) // Recently Dropped Flag (prevent cancel) - return false; - break; - default: - break; - } - break; - } - default: - break; - } - - // non-positive targets - if(!IsPositiveTarget(spellproto->EffectImplicitTargetA[effIndex],spellproto->EffectImplicitTargetB[effIndex])) - return false; - - // AttributesEx check - if(spellproto->AttributesEx & (1<<7)) - return false; - - // ok, positive - return true; -} - -bool IsPositiveSpell(uint32 spellId) -{ - SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); - if (!spellproto) return false; - - // spells with at least one negative effect are considered negative - // some self-applied spells have negative effects but in self casting case negative check ignored. - for (int i = 0; i < 3; i++) - if (!IsPositiveEffect(spellId, i)) - return false; - return true; -} - -bool IsSingleTargetSpell(SpellEntry const *spellInfo) -{ - // all other single target spells have if it has AttributesEx5 - if ( spellInfo->AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL ) - return true; - - // TODO - need found Judgements rule - switch(GetSpellSpecific(spellInfo->Id)) - { - case SPELL_JUDGEMENT: - return true; - } - - // single target triggered spell. - // Not real client side single target spell, but it' not triggered until prev. aura expired. - // This is allow store it in single target spells list for caster for spell proc checking - if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals)) - return true; - - return false; -} - -bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2) -{ - // TODO - need better check - // Equal icon and spellfamily - if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName && - spellInfo1->SpellIconID == spellInfo2->SpellIconID ) - return true; - - // TODO - need found Judgements rule - SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id); - // spell with single target specific types - switch(spec1) - { - case SPELL_JUDGEMENT: - if(GetSpellSpecific(spellInfo2->Id) == spec1) - return true; - break; - } - - return false; -} - -uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form) -{ - // talents that learn spells can have stance requirements that need ignore - // (this requirement only for client-side stance show in talent description) - if( GetTalentSpellCost(spellInfo->Id) > 0 && - (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) ) - return 0; - - uint32 stanceMask = (form ? 1 << (form - 1) : 0); - - if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance - return SPELL_FAILED_NOT_SHAPESHIFT; - - if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance - return 0; - - bool actAsShifted = false; - if (form > 0) - { - SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form); - if (!shapeInfo) - { - sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form); - return 0; - } - actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells - } - - if(actAsShifted) - { - if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted - return SPELL_FAILED_NOT_SHAPESHIFT; - else if (spellInfo->Stances != 0) // needs other shapeshift - return SPELL_FAILED_ONLY_SHAPESHIFT; - } - else - { - // needs shapeshift - if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0) - return SPELL_FAILED_ONLY_SHAPESHIFT; - } - - return 0; -} - -void SpellMgr::LoadSpellTargetPositions() -{ - mSpellTargetPositions.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 3 4 5 - QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell target coordinates", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - ++count; - - uint32 Spell_ID = fields[0].GetUInt32(); - - SpellTargetPosition st; - - st.target_mapId = fields[1].GetUInt32(); - st.target_X = fields[2].GetFloat(); - st.target_Y = fields[3].GetFloat(); - st.target_Z = fields[4].GetFloat(); - st.target_Orientation = fields[5].GetFloat(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID); - if(!spellInfo) - { - sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID); - continue; - } - - bool found = false; - for(int i = 0; i < 3; ++i) - { - if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES ) - { - found = true; - break; - } - } - if(!found) - { - sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID); - continue; - } - - MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId); - if(!mapEntry) - { - sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId); - continue; - } - - if(st.target_X==0 && st.target_Y==0 && st.target_Z==0) - { - sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID); - continue; - } - - mSpellTargetPositions[Spell_ID] = st; - - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell teleport coordinates", count ); -} - -void SpellMgr::LoadSpellAffects() -{ - mSpellAffectMap.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT entry, effectId, SpellFamilyMask FROM spell_affect"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell affect definitions", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 entry = fields[0].GetUInt16(); - uint8 effectId = fields[1].GetUInt8(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); - - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` does not exist", entry); - continue; - } - - if (effectId >= 3) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have invalid effect index (%u)", entry,effectId); - continue; - } - - if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER ) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have not SPELL_AURA_ADD_FLAT_MODIFIER (%u) or SPELL_AURA_ADD_PCT_MODIFIER (%u) or SPELL_AURA_ADD_TARGET_TRIGGER (%u) for effect index (%u)", entry,SPELL_AURA_ADD_FLAT_MODIFIER,SPELL_AURA_ADD_PCT_MODIFIER,SPELL_AURA_ADD_TARGET_TRIGGER,effectId); - continue; - } - - uint64 spellAffectMask = fields[2].GetUInt64(); - - // Spell.dbc have own data for low part of SpellFamilyMask - if( spellInfo->EffectItemType[effectId]) - { - if(spellInfo->EffectItemType[effectId] == spellAffectMask) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have redundant (same with EffectItemType%d) data for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); - continue; - } - - // 24429 have wrong data in EffectItemType and overwrites by DB, possible bug in client - if(spellInfo->Id!=24429 && spellInfo->EffectItemType[effectId] != spellAffectMask) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have different low part from EffectItemType%d for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); - continue; - } - } - - mSpellAffectMap.insert(SpellAffectMap::value_type((entry<<8) + effectId,spellAffectMask)); - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell affect definitions", count ); - - for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) - { - SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); - if (!spellInfo) - continue; - - for (int effectId = 0; effectId < 3; ++effectId) - { - if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || - (spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER) ) - continue; - - if(spellInfo->EffectItemType[effectId] != 0) - continue; - - if(mSpellAffectMap.find((id<<8) + effectId) != mSpellAffectMap.end()) - continue; - - sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u",id,spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId); - } - } -} - -bool SpellMgr::IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const -{ - // false for spellInfo == NULL - if (!spellInfo) - return false; - - SpellEntry const *affect_spell = sSpellStore.LookupEntry(spellId); - // false for affect_spell == NULL - if (!affect_spell) - return false; - - // False if spellFamily not equal - if (affect_spell->SpellFamilyName != spellInfo->SpellFamilyName) - return false; - - // If familyFlags == 0 - if (!familyFlags) - { - // Get it from spellAffect table - familyFlags = GetSpellAffectMask(spellId,effectId); - // false if familyFlags == 0 - if (!familyFlags) - return false; - } - - // true - if (familyFlags & spellInfo->SpellFamilyFlags) - return true; - - return false; -} - -void SpellMgr::LoadSpellProcEvents() -{ - mSpellProcEventMap.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 3 4 5 6 7 8 - QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, Category, SkillID, SpellFamilyName, SpellFamilyMask, procFlags, ppmRate, cooldown FROM spell_proc_event"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell proc event conditions", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 entry = fields[0].GetUInt16(); - - if (!sSpellStore.LookupEntry(entry)) - { - sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry); - continue; - } - - SpellProcEventEntry spe; - - spe.schoolMask = fields[1].GetUInt32(); - spe.category = fields[2].GetUInt32(); - spe.skillId = fields[3].GetUInt32(); - spe.spellFamilyName = fields[4].GetUInt32(); - spe.spellFamilyMask = fields[5].GetUInt64(); - spe.procFlags = fields[6].GetUInt32(); - spe.ppmRate = fields[7].GetFloat(); - spe.cooldown = fields[8].GetUInt32(); - - mSpellProcEventMap[entry] = spe; - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell proc event conditions", count ); - - /* - // Commented for now, as it still produces many errors (still quite many spells miss spell_proc_event) - for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) - { - SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); - if (!spellInfo) - continue; - - bool found = false; - for (int effectId = 0; effectId < 3; ++effectId) - { - // at this moment check only SPELL_AURA_PROC_TRIGGER_SPELL - if( spellInfo->EffectApplyAuraName[effectId] == SPELL_AURA_PROC_TRIGGER_SPELL ) - { - found = true; - break; - } - } - - if(!found) - continue; - - if(GetSpellProcEvent(id)) - continue; - - sLog.outErrorDb("Spell %u (%s) misses spell_proc_event",id,spellInfo->SpellName[sWorld.GetDBClang()]); - } - */ -} - -bool SpellMgr::IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ) -{ - if((procFlags & spellProcEvent->procFlags) == 0) - return false; - - // Additional checks in case spell cast/hit/crit is the event - // Check (if set) school, category, skill line, spell talent mask - if(spellProcEvent->schoolMask && (!procSpell || (GetSpellSchoolMask(procSpell) & spellProcEvent->schoolMask) == 0)) - return false; - if(spellProcEvent->category && (!procSpell || procSpell->Category != spellProcEvent->category)) - return false; - if(spellProcEvent->skillId) - { - if (!procSpell) - return false; - - SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(procSpell->Id); - SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(procSpell->Id); - - bool found = false; - for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) - { - if(_spell_idx->second->skillId == spellProcEvent->skillId) - { - found = true; - break; - } - } - if (!found) - return false; - } - if(spellProcEvent->spellFamilyName && (!procSpell || spellProcEvent->spellFamilyName != procSpell->SpellFamilyName)) - return false; - if(spellProcEvent->spellFamilyMask && (!procSpell || (spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags) == 0)) - return false; - - return true; -} - -void SpellMgr::LoadSpellElixirs() -{ - mSpellElixirs.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 - QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell elixir definitions", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 entry = fields[0].GetUInt16(); - uint8 mask = fields[1].GetUInt8(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); - - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry); - continue; - } - - mSpellElixirs[entry] = mask; - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell elixir definitions", count ); -} - -void SpellMgr::LoadSpellThreats() -{ - sSpellThreatStore.Free(); // for reload - - sSpellThreatStore.Load(); - - sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount ); - sLog.outString(); -} - -bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const -{ - SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - if(!spellInfo_1 || !spellInfo_2) return false; - if(spellInfo_1->Id == spellId_2) return false; - - return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2); -} - -bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo) -{ - if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH) - return false; - if(IsProfessionSpell(spellInfo->Id)) - return false; - - // All stance spells. if any better way, change it. - for (int i = 0; i < 3; i++) - { - // Paladin aura Spell - if(spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN - && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_PARTY) - return false; - // Druid form Spell - if(spellInfo->SpellFamilyName == SPELLFAMILY_DRUID - && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA - && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) - return false; - // Rogue Stealth - if(spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE - && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA - && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) - return false; - } - return true; -} - -bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const -{ - if(spellId_1 == spellId_2) // auras due to the same spell - return false; - - SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); - SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - - if(!spellInfo_1 || !spellInfo_2) - return false; - - if(spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName) - return false; - - if(!spellInfo_1->SpellFamilyName) // generic spells - { - if(!spellInfo_1->SpellIconID - || spellInfo_1->SpellIconID != spellInfo_2->SpellIconID) - return false; - } - else if (spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags) - return false; - - for(uint32 i = 0; i < 3; ++i) - if(spellInfo_1->Effect[i] != spellInfo_2->Effect[i] - || spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i]) - return false; - - return true; -} - -bool SpellMgr::IsProfessionSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return false; - - if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) - return false; - - uint32 skill = spellInfo->EffectMiscValue[1]; - - return IsProfessionSkill(skill); -} - -bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return false; - - if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) - return false; - - uint32 skill = spellInfo->EffectMiscValue[1]; - - return IsPrimaryProfessionSkill(skill); -} - -bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const -{ - return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1; -} - -SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const -{ - // ignore passive spells - if(IsPassiveSpell(spellInfo->Id)) - return spellInfo; - - bool needRankSelection = false; - for(int i=0;i<3;i++) - { - if( IsPositiveEffect(spellInfo->Id, i) && ( - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY - ) ) - { - needRankSelection = true; - break; - } - } - - // not required - if(!needRankSelection) - return spellInfo; - - for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId)) - { - SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId); - if(!nextSpellInfo) - break; - - // if found appropriate level - if(playerLevel + 10 >= nextSpellInfo->spellLevel) - return nextSpellInfo; - - // one rank less then - } - - // not found - return NULL; -} - -void SpellMgr::LoadSpellChains() -{ - mSpellChains.clear(); // need for reload case - mSpellChainsNext.clear(); // need for reload case - - QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain"); - if(result == NULL) - { - barGoLink bar( 1 ); - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded 0 spell chain records" ); - sLog.outErrorDb("`spell_chains` table is empty!"); - return; - } - - uint32 count = 0; - - barGoLink bar( result->GetRowCount() ); - do - { - bar.step(); - Field *fields = result->Fetch(); - - uint32 spell_id = fields[0].GetUInt32(); - - SpellChainNode node; - node.prev = fields[1].GetUInt32(); - node.first = fields[2].GetUInt32(); - node.rank = fields[3].GetUInt8(); - node.req = fields[4].GetUInt32(); - - if(!sSpellStore.LookupEntry(spell_id)) - { - sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id); - continue; - } - - if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev)) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(!sSpellStore.LookupEntry(node.first)) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell) - if( (spell_id == node.first) != (node.rank <= 1) || - (spell_id == node.first) != (node.prev == 0) || - (node.rank <= 1) != (node.prev == 0) ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(node.req!=0 && !sSpellStore.LookupEntry(node.req)) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - // talents not required data in spell chain for work, but must be checked if present for intergrity - if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id)) - { - if(node.rank!=pos->rank+1) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id)) - { - if(node.first!=talentEntry->RankID[0]) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1]) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(node.req!=talentEntry->DependsOnSpell) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - } - } - - mSpellChains[spell_id] = node; - - if(node.prev) - mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id)); - - if(node.req) - mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id)); - - ++count; - } while( result->NextRow() ); - - // additional integrity checks - for(SpellChainMap::iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i) - { - if(i->second.prev) - { - SpellChainMap::iterator i_prev = mSpellChains.find(i->second.prev); - if(i_prev == mSpellChains.end()) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); - } - else if( i_prev->second.first != i->second.first ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different first spell in chain compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); - } - else if( i_prev->second.rank+1 != i->second.rank ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different rank compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); - } - } - - if(i->second.req) - { - SpellChainMap::iterator i_req = mSpellChains.find(i->second.req); - if(i_req == mSpellChains.end()) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); - } - else if( i_req->second.first == i->second.first ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell from same spell chain (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); - } - else if( i_req->second.req ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell with required spell (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); - } - } - } - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell chain records", count ); -} - -void SpellMgr::LoadSpellLearnSkills() -{ - mSpellLearnSkills.clear(); // need for reload case - - // search auto-learned skills and add its to map also for use in unlearn spells/talents - uint32 dbc_count = 0; - for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) - { - SpellEntry const* entry = sSpellStore.LookupEntry(spell); - - if(!entry) - continue; - - for(int i = 0; i < 3; ++i) - { - if(entry->Effect[i]==SPELL_EFFECT_SKILL) - { - SpellLearnSkillNode dbc_node; - dbc_node.skill = entry->EffectMiscValue[i]; - if ( dbc_node.skill != SKILL_RIDING ) - dbc_node.value = 1; - else - dbc_node.value = (entry->EffectBasePoints[i]+1)*75; - dbc_node.maxvalue = (entry->EffectBasePoints[i]+1)*75; - - SpellLearnSkillNode const* db_node = GetSpellLearnSkill(spell); - - mSpellLearnSkills[spell] = dbc_node; - ++dbc_count; - break; - } - } - } - - sLog.outString(); - sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count ); -} - -void SpellMgr::LoadSpellLearnSpells() -{ - mSpellLearnSpells.clear(); // need for reload case - - QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID FROM spell_learn_spell"); - if(!result) - { - barGoLink bar( 1 ); - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded 0 spell learn spells" ); - sLog.outErrorDb("`spell_learn_spell` table is empty!"); - return; - } - - uint32 count = 0; - - barGoLink bar( result->GetRowCount() ); - do - { - bar.step(); - Field *fields = result->Fetch(); - - uint32 spell_id = fields[0].GetUInt32(); - - SpellLearnSpellNode node; - node.spell = fields[1].GetUInt32(); - node.autoLearned= false; - - if(!sSpellStore.LookupEntry(spell_id)) - { - sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id); - continue; - } - - if(!sSpellStore.LookupEntry(node.spell)) - { - sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell); - continue; - } - - mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node)); - - ++count; - } while( result->NextRow() ); - - delete result; - - // search auto-learned spells and add its to map also for use in unlearn spells/talents - uint32 dbc_count = 0; - for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) - { - SpellEntry const* entry = sSpellStore.LookupEntry(spell); - - if(!entry) - continue; - - for(int i = 0; i < 3; ++i) - { - if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL) - { - SpellLearnSpellNode dbc_node; - dbc_node.spell = entry->EffectTriggerSpell[i]; - dbc_node.autoLearned = true; - - SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell); - SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell); - - bool found = false; - for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr) - { - if(itr->second.spell == dbc_node.spell) - { - sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.", - spell,dbc_node.spell); - found = true; - break; - } - } - - if(!found) // add new spell-spell pair if not found - { - mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node)); - ++dbc_count; - } - } - } - } - - sLog.outString(); - sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count ); -} - -void SpellMgr::LoadSpellScriptTarget() -{ - mSpellScriptTarget.clear(); // need for reload case - - uint32 count = 0; - - QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target"); - - if(!result) - { - barGoLink bar(1); - - bar.step(); - - sLog.outString(); - sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty."); - return; - } - - barGoLink bar(result->GetRowCount()); - - do - { - Field *fields = result->Fetch(); - bar.step(); - - uint32 spellId = fields[0].GetUInt32(); - uint32 type = fields[1].GetUInt32(); - uint32 targetEntry = fields[2].GetUInt32(); - - SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); - - if(!spellProto) - { - sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry); - continue; - } - - /*bool targetfound = false; - for(int i = 0; i <3; ++i) - { - if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT || - spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT || - spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES || - spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES ) - { - targetfound = true; - break; - } - } - if(!targetfound) - { - sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not have any implicit target TARGET_SCRIPT(38) or TARGET_SCRIPT_COORDINATES (46).",spellId,targetEntry); - continue; - }*/ - - if( type >= MAX_SPELL_TARGET_TYPE ) - { - sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry); - continue; - } - - switch(type) - { - case SPELL_TARGET_TYPE_GAMEOBJECT: - { - if( targetEntry==0 ) - break; - - if(!sGOStorage.LookupEntry(targetEntry)) - { - sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry); - continue; - } - break; - } - default: - { - if( targetEntry==0 ) - { - sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type); - continue; - } - if(!sCreatureStorage.LookupEntry(targetEntry)) - { - sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry); - continue; - } - const CreatureInfo* cInfo = sCreatureStorage.LookupEntry(targetEntry); - - if(spellId == 30427 && !cInfo->SkinLootId) - { - sLog.outErrorDb("Table `spell_script_target` has creature %u as a target of spellid 30427, but this creature has no skinlootid. Gas extraction will not work!", cInfo->Entry); - continue; - } - break; - } - } - - mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry))); - - ++count; - } while (result->NextRow()); - - delete result; - - // Check all spells - /* Disabled (lot errors at this moment) - for(uint32 i = 1; i < sSpellStore.nCount; ++i) - { - SpellEntry const * spellInfo = sSpellStore.LookupEntry(i); - if(!spellInfo) - continue; - - bool found = false; - for(int j=0; j<3; ++j) - { - if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT ) - { - SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id); - SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id); - if(lower==upper) - { - sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = %u (TARGET_SCRIPT), but does not have record in `spell_script_target`",spellInfo->Id,TARGET_SCRIPT); - break; // effects of spell - } - } - } - } - */ - - sLog.outString(); - sLog.outString(">> Loaded %u Spell Script Targets", count); -} - -void SpellMgr::LoadSpellPetAuras() -{ - mSpellPetAuraMap.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell pet auras", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 spell = fields[0].GetUInt16(); - uint16 pet = fields[1].GetUInt16(); - uint16 aura = fields[2].GetUInt16(); - - SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell); - if(itr != mSpellPetAuraMap.end()) - { - itr->second.AddAura(pet, aura); - } - else - { - SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell); - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell); - continue; - } - int i = 0; - for(; i < 3; ++i) - if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) || - spellInfo->Effect[i] == SPELL_EFFECT_DUMMY) - break; - - if(i == 3) - { - sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell); - continue; - } - - SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura); - if (!spellInfo2) - { - sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura); - continue; - } - - PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->EffectBasePoints[i] + spellInfo->EffectBaseDice[i]); - mSpellPetAuraMap[spell] = pa; - } - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell pet auras", count ); -} - -// set data in core for now -void SpellMgr::LoadSpellCustomAttr() -{ - SpellEntry *tempSpell; - for(uint32 i = 0; i < GetSpellStore()->GetNumRows(); ++i) - { - tempSpell = (SpellEntry*)GetSpellStore()->LookupEntry(i); - if(!tempSpell) - continue; - - mSpellCustomAttrMap[tempSpell->Id] = 0; - - for(uint32 i = 0; i < 3; ++i) - { - switch(tempSpell->EffectApplyAuraName[i]) - { - case SPELL_AURA_PERIODIC_DAMAGE: - case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: - case SPELL_AURA_PERIODIC_LEECH: - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_DAMAGE; - break; - case SPELL_AURA_PERIODIC_HEAL: - case SPELL_AURA_OBS_MOD_HEALTH: - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_HEAL; - break; - default: - break; - } - } - - if(tempSpell->SpellVisual == 3879) - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_BACK; - - switch(tempSpell->Id) - { - case 26029: // dark glare - case 37433: // spout - case 43140: case 43215: // flame breath - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_LINE; - break; - case 24340: case 26558: case 28884: // Meteor - case 36837: case 38903: case 41276: // Meteor - case 26789: // Shard of the Fallen Star - case 31436: // Malevolent Cleave - case 35181: // Dive Bomb - case 40810: case 43267: case 43268: // Saber Lash - case 42384: // Brutal Swipe - case 45150: // Meteor Slash - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_SHARE_DAMAGE; - break; - case 44978: case 45001: case 45002: // Wild Magic - case 45004: case 45006: case 45010: // Wild Magic - case 31347: // Doom - case 41635: // Prayer of Mending - case 44869: // Spectral Blast - case 45027: // Revitalize - case 45976: // Muru Portal Channel - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; - tempSpell->MaxAffectedTargets = 1; - break; - case 41376: // Spite - case 39992: // Needle Spine - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; - tempSpell->MaxAffectedTargets = 3; - break; - case 8122: case 8124: case 10888: case 10890: // Psychic Scream - tempSpell->Attributes |= SPELL_ATTR_BREAKABLE_BY_DAMAGE; - break; - default: - break; - } - } -} - -void SpellMgr::LoadSpellLinked() -{ - mSpellLinkedMap.clear(); // need for reload case - uint32 count = 0; - - // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell"); - if( !result ) - { - barGoLink bar( 1 ); - bar.step(); - sLog.outString(); - sLog.outString( ">> Loaded %u linked spells", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - int32 trigger = fields[0].GetInt32(); - int32 effect = fields[1].GetInt32(); - int32 type = fields[2].GetInt32(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(trigger)); - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(trigger)); - continue; - } - spellInfo = sSpellStore.LookupEntry(abs(effect)); - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(effect)); - continue; - } - - if(type) //we will find a better way when more types are needed - trigger += 1000000; - mSpellLinkedMap[trigger].push_back(effect); - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u linked spells", count ); -} - -/// Some checks for spells, to prevent adding depricated/broken spells for trainers, spell book, etc -bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg) -{ - // not exist - if(!spellInfo) - return false; - - bool need_check_reagents = false; - - // check effects - for(int i=0; i<3; ++i) - { - switch(spellInfo->Effect[i]) - { - case 0: - continue; - - // craft spell for crafting non-existed item (break client recipes list show) - case SPELL_EFFECT_CREATE_ITEM: - { - if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] )) - { - if(msg) - { - if(pl) - ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); - else - sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); - } - return false; - } - - need_check_reagents = true; - break; - } - case SPELL_EFFECT_LEARN_SPELL: - { - SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[0]); - if( !IsSpellValid(spellInfo2,pl,msg) ) - { - if(msg) - { - if(pl) - ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); - else - sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); - } - return false; - } - break; - } - } - } - - if(need_check_reagents) - { - for(int j = 0; j < 8; ++j) - { - if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] )) - { - if(msg) - { - if(pl) - ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); - else - sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); - } - return false; - } - } - } - - return true; -} - -bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id) -{ - // normal case - if( spellInfo->AreaId && spellInfo->AreaId != zone_id && spellInfo->AreaId != area_id ) - return false; - - // elixirs (all area dependent elixirs have family SPELLFAMILY_POTION, use this for speedup) - if(spellInfo->SpellFamilyName==SPELLFAMILY_POTION) - { - if(uint32 mask = spellmgr.GetSpellElixirMask(spellInfo->Id)) - { - if(mask & ELIXIR_UNSTABLE_MASK) - { - // in the Blade's Edge Mountains Plateaus and Gruul's Lair. - return zone_id ==3522 || map_id==565; - } - if(mask & ELIXIR_SHATTRATH_MASK) - { - // in Tempest Keep, Serpentshrine Cavern, Caverns of Time: Mount Hyjal, Black Temple - // TODO: and the Sunwell Plateau - if(zone_id ==3607 || map_id==534 || map_id==564) - return true; - - MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); - if(!mapEntry) - return false; - - return mapEntry->multimap_id==206; - } - - // elixirs not have another limitations - return true; - } - } - - // special cases zone check (maps checked by multimap common id) - switch(spellInfo->Id) - { - case 41618: - case 41620: - { - MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); - if(!mapEntry) - return false; - - return mapEntry->multimap_id==206; - } - - case 41617: - case 41619: - { - MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); - if(!mapEntry) - return false; - - return mapEntry->multimap_id==207; - } - // Dragonmaw Illusion - case 40216: - case 42016: - { - if ( area_id != 3759 && area_id != 3966 && area_id != 3939 ) - return false; - break; - } - } - - return true; -} - -void SpellMgr::LoadSkillLineAbilityMap() -{ - mSkillLineAbilityMap.clear(); - - uint32 count = 0; - - for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); i++) - { - SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i); - if(!SkillInfo) - continue; - - mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo)); - ++count; - } - - sLog.outString(); - sLog.outString(">> Loaded %u SkillLineAbility MultiMap", count); -} - -DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered) -{ - // Explicit Diminishing Groups - switch(spellproto->SpellFamilyName) - { - case SPELLFAMILY_MAGE: - { - // Polymorph - if ((spellproto->SpellFamilyFlags & 0x00001000000LL) && spellproto->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) - return DIMINISHING_POLYMORPH; - break; - } - case SPELLFAMILY_ROGUE: - { - // Kidney Shot - if (spellproto->SpellFamilyFlags & 0x00000200000LL) - return DIMINISHING_KIDNEYSHOT; - // Blind - else if (spellproto->SpellFamilyFlags & 0x00001000000LL) - return DIMINISHING_BLIND_CYCLONE; - break; - } - case SPELLFAMILY_WARLOCK: - { - // Death Coil - if (spellproto->SpellFamilyFlags & 0x00000080000LL) - return DIMINISHING_DEATHCOIL; - // Fear - else if (spellproto->SpellFamilyFlags & 0x40840000000LL) - return DIMINISHING_WARLOCK_FEAR; - // Curses/etc - else if (spellproto->SpellFamilyFlags & 0x00080000000LL) - return DIMINISHING_LIMITONLY; - break; - } - case SPELLFAMILY_DRUID: - { - // Cyclone - if (spellproto->SpellFamilyFlags & 0x02000000000LL) - return DIMINISHING_BLIND_CYCLONE; - break; - } - case SPELLFAMILY_WARRIOR: - { - // Hamstring - limit duration to 10s in PvP - if (spellproto->SpellFamilyFlags & 0x00000000002LL) - return DIMINISHING_LIMITONLY; - break; - } - default: - break; - } - - // Get by mechanic - for (uint8 i=0;i<3;++i) - { - if (spellproto->Mechanic == MECHANIC_STUN || spellproto->EffectMechanic[i] == MECHANIC_STUN) - return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN; - else if (spellproto->Mechanic == MECHANIC_SLEEP || spellproto->EffectMechanic[i] == MECHANIC_SLEEP) - return DIMINISHING_SLEEP; - else if (spellproto->Mechanic == MECHANIC_ROOT || spellproto->EffectMechanic[i] == MECHANIC_ROOT) - return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT; - else if (spellproto->Mechanic == MECHANIC_FEAR || spellproto->EffectMechanic[i] == MECHANIC_FEAR) - return DIMINISHING_FEAR; - else if (spellproto->Mechanic == MECHANIC_CHARM || spellproto->EffectMechanic[i] == MECHANIC_CHARM) - return DIMINISHING_CHARM; - else if (spellproto->Mechanic == MECHANIC_SILENCE || spellproto->EffectMechanic[i] == MECHANIC_SILENCE) - return DIMINISHING_SILENCE; - else if (spellproto->Mechanic == MECHANIC_DISARM || spellproto->EffectMechanic[i] == MECHANIC_DISARM) - return DIMINISHING_DISARM; - else if (spellproto->Mechanic == MECHANIC_FREEZE || spellproto->EffectMechanic[i] == MECHANIC_FREEZE) - return DIMINISHING_FREEZE; - else if (spellproto->Mechanic == MECHANIC_KNOCKOUT|| spellproto->EffectMechanic[i] == MECHANIC_KNOCKOUT || - spellproto->Mechanic == MECHANIC_SAPPED || spellproto->EffectMechanic[i] == MECHANIC_SAPPED) - return DIMINISHING_KNOCKOUT; - else if (spellproto->Mechanic == MECHANIC_BANISH || spellproto->EffectMechanic[i] == MECHANIC_BANISH) - return DIMINISHING_BANISH; - } - - return DIMINISHING_NONE; -} - -bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group) -{ - switch(group) - { - case DIMINISHING_CONTROL_STUN: - case DIMINISHING_TRIGGER_STUN: - case DIMINISHING_KIDNEYSHOT: - case DIMINISHING_SLEEP: - case DIMINISHING_CONTROL_ROOT: - case DIMINISHING_TRIGGER_ROOT: - case DIMINISHING_FEAR: - case DIMINISHING_WARLOCK_FEAR: - case DIMINISHING_CHARM: - case DIMINISHING_POLYMORPH: - case DIMINISHING_FREEZE: - case DIMINISHING_KNOCKOUT: - case DIMINISHING_BLIND_CYCLONE: - case DIMINISHING_BANISH: - case DIMINISHING_LIMITONLY: - return true; - } - return false; -} - -DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group) -{ - switch(group) - { - case DIMINISHING_BLIND_CYCLONE: - case DIMINISHING_CONTROL_STUN: - case DIMINISHING_TRIGGER_STUN: - case DIMINISHING_KIDNEYSHOT: - return DRTYPE_ALL; - case DIMINISHING_SLEEP: - case DIMINISHING_CONTROL_ROOT: - case DIMINISHING_TRIGGER_ROOT: - case DIMINISHING_FEAR: - case DIMINISHING_CHARM: - case DIMINISHING_POLYMORPH: - case DIMINISHING_SILENCE: - case DIMINISHING_DISARM: - case DIMINISHING_DEATHCOIL: - case DIMINISHING_FREEZE: - case DIMINISHING_BANISH: - case DIMINISHING_WARLOCK_FEAR: - case DIMINISHING_KNOCKOUT: - return DRTYPE_PLAYER; - } - - return DRTYPE_NONE; -} +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "SpellMgr.h" +#include "ObjectMgr.h" +#include "SpellAuraDefines.h" +#include "ProgressBar.h" +#include "Database/DBCStores.h" +#include "World.h" +#include "Chat.h" +#include "Spell.h" + +SpellMgr::SpellMgr() +{ +} + +SpellMgr::~SpellMgr() +{ +} + +SpellMgr& SpellMgr::Instance() +{ + static SpellMgr spellMgr; + return spellMgr; +} + +int32 GetSpellDuration(SpellEntry const *spellInfo) +{ + if(!spellInfo) + return 0; + SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); + if(!du) + return 0; + return (du->Duration[0] == -1) ? -1 : abs(du->Duration[0]); +} + +int32 GetSpellMaxDuration(SpellEntry const *spellInfo) +{ + if(!spellInfo) + return 0; + SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); + if(!du) + return 0; + return (du->Duration[2] == -1) ? -1 : abs(du->Duration[2]); +} + +uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell) +{ + SpellCastTimesEntry const *spellCastTimeEntry = sSpellCastTimesStore.LookupEntry(spellInfo->CastingTimeIndex); + + // not all spells have cast time index and this is all is pasiive abilities + if(!spellCastTimeEntry) + return 0; + + int32 castTime = spellCastTimeEntry->CastTime; + + if (spell) + { + if(Player* modOwner = spell->GetCaster()->GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CASTING_TIME, castTime, spell); + + if( !(spellInfo->Attributes & (SPELL_ATTR_UNK4|SPELL_ATTR_UNK5)) ) + castTime = int32(castTime * spell->GetCaster()->GetFloatValue(UNIT_MOD_CAST_SPEED)); + else + { + if (spell->IsRangedSpell() && !spell->IsAutoRepeat()) + castTime = int32(castTime * spell->GetCaster()->m_modAttackSpeedPct[RANGED_ATTACK]); + } + } + + if (spellInfo->Attributes & SPELL_ATTR_RANGED && (!spell || !(spell->IsAutoRepeat()))) + castTime += 500; + + return (castTime > 0) ? uint32(castTime) : 0; +} + +bool IsPassiveSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if (!spellInfo) + return false; + return (spellInfo->Attributes & SPELL_ATTR_PASSIVE) != 0; +} +/*not used for now so commented out +bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) +{ + SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); + SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + if(!spellInfo_1 || !spellInfo_2) return false; + if(spellInfo_1->Id == spellId_2) return false; + + if (spellInfo_1->Effect[effIndex_1] != spellInfo_2->Effect[effIndex_2] || + spellInfo_1->EffectMiscValue[effIndex_1] != spellInfo_2->EffectMiscValue[effIndex_2] || + spellInfo_1->EffectApplyAuraName[effIndex_1] != spellInfo_2->EffectApplyAuraName[effIndex_2]) + return false; + + return true; +}*/ + +int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) +{ + SpellEntry const*spellInfo_1 = sSpellStore.LookupEntry(spellId_1); + SpellEntry const*spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + if(!spellInfo_1 || !spellInfo_2) return 0; + if (spellId_1 == spellId_2) return 0; + + int32 diff = spellInfo_1->EffectBasePoints[effIndex_1] - spellInfo_2->EffectBasePoints[effIndex_2]; + if (spellInfo_1->EffectBasePoints[effIndex_1]+1 < 0 && spellInfo_2->EffectBasePoints[effIndex_2]+1 < 0) return -diff; + else return diff; +} + +SpellSpecific GetSpellSpecific(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return SPELL_NORMAL; + + switch(spellInfo->SpellFamilyName) + { + case SPELLFAMILY_MAGE: + { + // family flags 18(Molten), 25(Frost/Ice), 28(Mage) + if (spellInfo->SpellFamilyFlags & 0x12040000) + return SPELL_MAGE_ARMOR; + + if ((spellInfo->SpellFamilyFlags & 0x1000000) && spellInfo->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) + return SPELL_MAGE_POLYMORPH; + + break; + } + case SPELLFAMILY_WARRIOR: + { + if (spellInfo->SpellFamilyFlags & 0x00008000010000LL) + return SPELL_POSITIVE_SHOUT; + + break; + } + case SPELLFAMILY_WARLOCK: + { + // only warlock curses have this + if (spellInfo->Dispel == DISPEL_CURSE) + return SPELL_CURSE; + + // family flag 37 (only part spells have family name) + if (spellInfo->SpellFamilyFlags & 0x2000000000LL) + return SPELL_WARLOCK_ARMOR; + + //seed of corruption and corruption + if (spellInfo->SpellFamilyFlags & 0x1000000002LL) + return SPELL_WARLOCK_CORRUPTION; + break; + } + case SPELLFAMILY_HUNTER: + { + // only hunter stings have this + if (spellInfo->Dispel == DISPEL_POISON) + return SPELL_STING; + + break; + } + case SPELLFAMILY_PALADIN: + { + if (IsSealSpell(spellInfo)) + return SPELL_SEAL; + + if (spellInfo->SpellFamilyFlags & 0x10000100LL) + return SPELL_BLESSING; + + if ((spellInfo->SpellFamilyFlags & 0x00000820180400LL) && (spellInfo->AttributesEx3 & 0x200)) + return SPELL_JUDGEMENT; + + for (int i = 0; i < 3; i++) + { + // only paladin auras have this + if (spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY) + return SPELL_AURA; + } + break; + } + case SPELLFAMILY_SHAMAN: + { + if (IsElementalShield(spellInfo)) + return SPELL_ELEMENTAL_SHIELD; + + break; + } + + case SPELLFAMILY_POTION: + return spellmgr.GetSpellElixirSpecific(spellInfo->Id); + } + + // only warlock armor/skin have this (in additional to family cases) + if( spellInfo->SpellVisual == 130 && spellInfo->SpellIconID == 89) + { + return SPELL_WARLOCK_ARMOR; + } + + // only hunter aspects have this (but not all aspects in hunter family) + if( spellInfo->activeIconID == 122 && (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NATURE) && + (spellInfo->Attributes & 0x50000) != 0 && (spellInfo->Attributes & 0x9000010) == 0) + { + return SPELL_ASPECT; + } + + for(int i = 0; i < 3; i++) + if( spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && ( + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_CREATURES || + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_RESOURCES || + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_STEALTHED ) ) + return SPELL_TRACKER; + + // elixirs can have different families, but potion most ofc. + if(SpellSpecific sp = spellmgr.GetSpellElixirSpecific(spellInfo->Id)) + return sp; + + return SPELL_NORMAL; +} + +bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2) +{ + switch(spellSpec1) + { + case SPELL_SEAL: + case SPELL_BLESSING: + case SPELL_AURA: + case SPELL_STING: + case SPELL_CURSE: + case SPELL_ASPECT: + case SPELL_POSITIVE_SHOUT: + case SPELL_JUDGEMENT: + case SPELL_WARLOCK_CORRUPTION: + return spellSpec1==spellSpec2; + default: + return false; + } +} + +bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1,uint32 spellSpec2) +{ + switch(spellSpec1) + { + case SPELL_TRACKER: + case SPELL_WARLOCK_ARMOR: + case SPELL_MAGE_ARMOR: + case SPELL_ELEMENTAL_SHIELD: + case SPELL_MAGE_POLYMORPH: + return spellSpec1==spellSpec2; + case SPELL_BATTLE_ELIXIR: + return spellSpec2==SPELL_BATTLE_ELIXIR + || spellSpec2==SPELL_FLASK_ELIXIR; + case SPELL_GUARDIAN_ELIXIR: + return spellSpec2==SPELL_GUARDIAN_ELIXIR + || spellSpec2==SPELL_FLASK_ELIXIR; + case SPELL_FLASK_ELIXIR: + return spellSpec2==SPELL_BATTLE_ELIXIR + || spellSpec2==SPELL_GUARDIAN_ELIXIR + || spellSpec2==SPELL_FLASK_ELIXIR; + default: + return false; + } +} + +bool IsPositiveTarget(uint32 targetA, uint32 targetB) +{ + // non-positive targets + switch(targetA) + { + case TARGET_CHAIN_DAMAGE: + case TARGET_ALL_ENEMY_IN_AREA: + case TARGET_ALL_ENEMY_IN_AREA_INSTANT: + case TARGET_IN_FRONT_OF_CASTER: + case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: + case TARGET_CURRENT_ENEMY_COORDINATES: + case TARGET_SINGLE_ENEMY: + return false; + case TARGET_ALL_AROUND_CASTER: + return (targetB == TARGET_ALL_PARTY || targetB == TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER); + default: + break; + } + if (targetB) + return IsPositiveTarget(targetB, 0); + return true; +} + +bool IsPositiveEffect(uint32 spellId, uint32 effIndex) +{ + SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); + if (!spellproto) return false; + + switch(spellId) + { + case 23333: // BG spell + case 23335: // BG spell + case 34976: // BG spell + return true; + case 28441: // not positive dummy spell + case 37675: // Chaos Blast + return false; + } + + switch(spellproto->Effect[effIndex]) + { + // always positive effects (check before target checks that provided non-positive result in some case for positive effects) + case SPELL_EFFECT_HEAL: + case SPELL_EFFECT_LEARN_SPELL: + case SPELL_EFFECT_SKILL_STEP: + case SPELL_EFFECT_HEAL_PCT: + case SPELL_EFFECT_ENERGIZE_PCT: + return true; + + // non-positive aura use + case SPELL_EFFECT_APPLY_AURA: + case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND: + { + switch(spellproto->EffectApplyAuraName[effIndex]) + { + case SPELL_AURA_DUMMY: + { + // dummy aura can be positive or negative dependent from casted spell + switch(spellproto->Id) + { + case 13139: // net-o-matic special effect + case 23445: // evil twin + case 38637: // Nether Exhaustion (red) + case 38638: // Nether Exhaustion (green) + case 38639: // Nether Exhaustion (blue) + return false; + default: + break; + } + } break; + case SPELL_AURA_MOD_STAT: + case SPELL_AURA_MOD_DAMAGE_DONE: // dependent from bas point sign (negative -> negative) + case SPELL_AURA_MOD_HEALING_DONE: + { + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) + return false; + break; + } + case SPELL_AURA_ADD_TARGET_TRIGGER: + return true; + case SPELL_AURA_PERIODIC_TRIGGER_SPELL: + if(spellId != spellproto->EffectTriggerSpell[effIndex]) + { + uint32 spellTriggeredId = spellproto->EffectTriggerSpell[effIndex]; + SpellEntry const *spellTriggeredProto = sSpellStore.LookupEntry(spellTriggeredId); + + if(spellTriggeredProto) + { + // non-positive targets of main spell return early + for(int i = 0; i < 3; ++i) + { + // if non-positive trigger cast targeted to positive target this main cast is non-positive + // this will place this spell auras as debuffs + if(IsPositiveTarget(spellTriggeredProto->EffectImplicitTargetA[effIndex],spellTriggeredProto->EffectImplicitTargetB[effIndex]) && !IsPositiveEffect(spellTriggeredId,i)) + return false; + } + } + } + break; + case SPELL_AURA_PROC_TRIGGER_SPELL: + // many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example) + break; + case SPELL_AURA_MOD_STUN: //have positive and negative spells, we can't sort its correctly at this moment. + if(effIndex==0 && spellproto->Effect[1]==0 && spellproto->Effect[2]==0) + return false; // but all single stun aura spells is negative + + // Petrification + if(spellproto->Id == 17624) + return false; + break; + case SPELL_AURA_MOD_ROOT: + case SPELL_AURA_MOD_SILENCE: + case SPELL_AURA_GHOST: + case SPELL_AURA_PERIODIC_LEECH: + case SPELL_AURA_MOD_PACIFY_SILENCE: + case SPELL_AURA_MOD_STALKED: + case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: + return false; + case SPELL_AURA_PERIODIC_DAMAGE: // used in positive spells also. + // part of negative spell if casted at self (prevent cancel) + if(spellproto->EffectImplicitTargetA[effIndex] == TARGET_SELF) + return false; + break; + case SPELL_AURA_MOD_DECREASE_SPEED: // used in positive spells also + // part of positive spell if casted at self + if(spellproto->EffectImplicitTargetA[effIndex] != TARGET_SELF) + return false; + // but not this if this first effect (don't found batter check) + if(spellproto->Attributes & 0x4000000 && effIndex==0) + return false; + break; + case SPELL_AURA_TRANSFORM: + // some spells negative + switch(spellproto->Id) + { + case 36897: // Transporter Malfunction (race mutation to horde) + case 36899: // Transporter Malfunction (race mutation to alliance) + return false; + } + break; + case SPELL_AURA_MOD_SCALE: + // some spells negative + switch(spellproto->Id) + { + case 36900: // Soul Split: Evil! + case 36901: // Soul Split: Good + case 36893: // Transporter Malfunction (decrease size case) + case 36895: // Transporter Malfunction (increase size case) + return false; + } + break; + case SPELL_AURA_MECHANIC_IMMUNITY: + { + // non-positive immunities + switch(spellproto->EffectMiscValue[effIndex]) + { + case MECHANIC_BANDAGE: + case MECHANIC_SHIELD: + case MECHANIC_MOUNT: + case MECHANIC_INVULNERABILITY: + return false; + default: + break; + } + } break; + case SPELL_AURA_ADD_FLAT_MODIFIER: // mods + case SPELL_AURA_ADD_PCT_MODIFIER: + { + // non-positive mods + switch(spellproto->EffectMiscValue[effIndex]) + { + case SPELLMOD_COST: // dependent from bas point sign (negative -> positive) + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) > 0) + return false; + break; + default: + break; + } + } break; + case SPELL_AURA_MOD_HEALING_PCT: + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) + return false; + break; + case SPELL_AURA_MOD_SKILL: + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) + return false; + break; + case SPELL_AURA_FORCE_REACTION: + if(spellproto->Id==42792) // Recently Dropped Flag (prevent cancel) + return false; + break; + default: + break; + } + break; + } + default: + break; + } + + // non-positive targets + if(!IsPositiveTarget(spellproto->EffectImplicitTargetA[effIndex],spellproto->EffectImplicitTargetB[effIndex])) + return false; + + // AttributesEx check + if(spellproto->AttributesEx & (1<<7)) + return false; + + // ok, positive + return true; +} + +bool IsPositiveSpell(uint32 spellId) +{ + SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); + if (!spellproto) return false; + + // spells with at least one negative effect are considered negative + // some self-applied spells have negative effects but in self casting case negative check ignored. + for (int i = 0; i < 3; i++) + if (!IsPositiveEffect(spellId, i)) + return false; + return true; +} + +bool IsSingleTargetSpell(SpellEntry const *spellInfo) +{ + // all other single target spells have if it has AttributesEx5 + if ( spellInfo->AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL ) + return true; + + // TODO - need found Judgements rule + switch(GetSpellSpecific(spellInfo->Id)) + { + case SPELL_JUDGEMENT: + return true; + } + + // single target triggered spell. + // Not real client side single target spell, but it' not triggered until prev. aura expired. + // This is allow store it in single target spells list for caster for spell proc checking + if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals)) + return true; + + return false; +} + +bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2) +{ + // TODO - need better check + // Equal icon and spellfamily + if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName && + spellInfo1->SpellIconID == spellInfo2->SpellIconID ) + return true; + + // TODO - need found Judgements rule + SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id); + // spell with single target specific types + switch(spec1) + { + case SPELL_JUDGEMENT: + if(GetSpellSpecific(spellInfo2->Id) == spec1) + return true; + break; + } + + return false; +} + +uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form) +{ + // talents that learn spells can have stance requirements that need ignore + // (this requirement only for client-side stance show in talent description) + if( GetTalentSpellCost(spellInfo->Id) > 0 && + (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) ) + return 0; + + uint32 stanceMask = (form ? 1 << (form - 1) : 0); + + if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance + return SPELL_FAILED_NOT_SHAPESHIFT; + + if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance + return 0; + + bool actAsShifted = false; + if (form > 0) + { + SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form); + if (!shapeInfo) + { + sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form); + return 0; + } + actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells + } + + if(actAsShifted) + { + if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted + return SPELL_FAILED_NOT_SHAPESHIFT; + else if (spellInfo->Stances != 0) // needs other shapeshift + return SPELL_FAILED_ONLY_SHAPESHIFT; + } + else + { + // needs shapeshift + if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0) + return SPELL_FAILED_ONLY_SHAPESHIFT; + } + + return 0; +} + +void SpellMgr::LoadSpellTargetPositions() +{ + mSpellTargetPositions.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 3 4 5 + QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell target coordinates", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + ++count; + + uint32 Spell_ID = fields[0].GetUInt32(); + + SpellTargetPosition st; + + st.target_mapId = fields[1].GetUInt32(); + st.target_X = fields[2].GetFloat(); + st.target_Y = fields[3].GetFloat(); + st.target_Z = fields[4].GetFloat(); + st.target_Orientation = fields[5].GetFloat(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID); + if(!spellInfo) + { + sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID); + continue; + } + + bool found = false; + for(int i = 0; i < 3; ++i) + { + if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES ) + { + found = true; + break; + } + } + if(!found) + { + sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID); + continue; + } + + MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId); + if(!mapEntry) + { + sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId); + continue; + } + + if(st.target_X==0 && st.target_Y==0 && st.target_Z==0) + { + sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID); + continue; + } + + mSpellTargetPositions[Spell_ID] = st; + + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell teleport coordinates", count ); +} + +void SpellMgr::LoadSpellAffects() +{ + mSpellAffectMap.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 + QueryResult *result = WorldDatabase.Query("SELECT entry, effectId, SpellFamilyMask FROM spell_affect"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell affect definitions", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 entry = fields[0].GetUInt16(); + uint8 effectId = fields[1].GetUInt8(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); + + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` does not exist", entry); + continue; + } + + if (effectId >= 3) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have invalid effect index (%u)", entry,effectId); + continue; + } + + if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER ) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have not SPELL_AURA_ADD_FLAT_MODIFIER (%u) or SPELL_AURA_ADD_PCT_MODIFIER (%u) or SPELL_AURA_ADD_TARGET_TRIGGER (%u) for effect index (%u)", entry,SPELL_AURA_ADD_FLAT_MODIFIER,SPELL_AURA_ADD_PCT_MODIFIER,SPELL_AURA_ADD_TARGET_TRIGGER,effectId); + continue; + } + + uint64 spellAffectMask = fields[2].GetUInt64(); + + // Spell.dbc have own data for low part of SpellFamilyMask + if( spellInfo->EffectItemType[effectId]) + { + if(spellInfo->EffectItemType[effectId] == spellAffectMask) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have redundant (same with EffectItemType%d) data for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); + continue; + } + + // 24429 have wrong data in EffectItemType and overwrites by DB, possible bug in client + if(spellInfo->Id!=24429 && spellInfo->EffectItemType[effectId] != spellAffectMask) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have different low part from EffectItemType%d for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); + continue; + } + } + + mSpellAffectMap.insert(SpellAffectMap::value_type((entry<<8) + effectId,spellAffectMask)); + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell affect definitions", count ); + + for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) + { + SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); + if (!spellInfo) + continue; + + for (int effectId = 0; effectId < 3; ++effectId) + { + if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || + (spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER) ) + continue; + + if(spellInfo->EffectItemType[effectId] != 0) + continue; + + if(mSpellAffectMap.find((id<<8) + effectId) != mSpellAffectMap.end()) + continue; + + sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u",id,spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId); + } + } +} + +bool SpellMgr::IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const +{ + // false for spellInfo == NULL + if (!spellInfo) + return false; + + SpellEntry const *affect_spell = sSpellStore.LookupEntry(spellId); + // false for affect_spell == NULL + if (!affect_spell) + return false; + + // False if spellFamily not equal + if (affect_spell->SpellFamilyName != spellInfo->SpellFamilyName) + return false; + + // If familyFlags == 0 + if (!familyFlags) + { + // Get it from spellAffect table + familyFlags = GetSpellAffectMask(spellId,effectId); + // false if familyFlags == 0 + if (!familyFlags) + return false; + } + + // true + if (familyFlags & spellInfo->SpellFamilyFlags) + return true; + + return false; +} + +void SpellMgr::LoadSpellProcEvents() +{ + mSpellProcEventMap.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 3 4 5 6 7 8 + QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, Category, SkillID, SpellFamilyName, SpellFamilyMask, procFlags, ppmRate, cooldown FROM spell_proc_event"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell proc event conditions", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 entry = fields[0].GetUInt16(); + + if (!sSpellStore.LookupEntry(entry)) + { + sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry); + continue; + } + + SpellProcEventEntry spe; + + spe.schoolMask = fields[1].GetUInt32(); + spe.category = fields[2].GetUInt32(); + spe.skillId = fields[3].GetUInt32(); + spe.spellFamilyName = fields[4].GetUInt32(); + spe.spellFamilyMask = fields[5].GetUInt64(); + spe.procFlags = fields[6].GetUInt32(); + spe.ppmRate = fields[7].GetFloat(); + spe.cooldown = fields[8].GetUInt32(); + + mSpellProcEventMap[entry] = spe; + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell proc event conditions", count ); + + /* + // Commented for now, as it still produces many errors (still quite many spells miss spell_proc_event) + for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) + { + SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); + if (!spellInfo) + continue; + + bool found = false; + for (int effectId = 0; effectId < 3; ++effectId) + { + // at this moment check only SPELL_AURA_PROC_TRIGGER_SPELL + if( spellInfo->EffectApplyAuraName[effectId] == SPELL_AURA_PROC_TRIGGER_SPELL ) + { + found = true; + break; + } + } + + if(!found) + continue; + + if(GetSpellProcEvent(id)) + continue; + + sLog.outErrorDb("Spell %u (%s) misses spell_proc_event",id,spellInfo->SpellName[sWorld.GetDBClang()]); + } + */ +} + +bool SpellMgr::IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ) +{ + if((procFlags & spellProcEvent->procFlags) == 0) + return false; + + // Additional checks in case spell cast/hit/crit is the event + // Check (if set) school, category, skill line, spell talent mask + if(spellProcEvent->schoolMask && (!procSpell || (GetSpellSchoolMask(procSpell) & spellProcEvent->schoolMask) == 0)) + return false; + if(spellProcEvent->category && (!procSpell || procSpell->Category != spellProcEvent->category)) + return false; + if(spellProcEvent->skillId) + { + if (!procSpell) + return false; + + SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(procSpell->Id); + SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(procSpell->Id); + + bool found = false; + for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) + { + if(_spell_idx->second->skillId == spellProcEvent->skillId) + { + found = true; + break; + } + } + if (!found) + return false; + } + if(spellProcEvent->spellFamilyName && (!procSpell || spellProcEvent->spellFamilyName != procSpell->SpellFamilyName)) + return false; + if(spellProcEvent->spellFamilyMask && (!procSpell || (spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags) == 0)) + return false; + + return true; +} + +void SpellMgr::LoadSpellElixirs() +{ + mSpellElixirs.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 + QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell elixir definitions", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 entry = fields[0].GetUInt16(); + uint8 mask = fields[1].GetUInt8(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); + + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry); + continue; + } + + mSpellElixirs[entry] = mask; + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell elixir definitions", count ); +} + +void SpellMgr::LoadSpellThreats() +{ + sSpellThreatStore.Free(); // for reload + + sSpellThreatStore.Load(); + + sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount ); + sLog.outString(); +} + +bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const +{ + SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + if(!spellInfo_1 || !spellInfo_2) return false; + if(spellInfo_1->Id == spellId_2) return false; + + return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2); +} + +bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo) +{ + if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH) + return false; + if(IsProfessionSpell(spellInfo->Id)) + return false; + + // All stance spells. if any better way, change it. + for (int i = 0; i < 3; i++) + { + // Paladin aura Spell + if(spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN + && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_PARTY) + return false; + // Druid form Spell + if(spellInfo->SpellFamilyName == SPELLFAMILY_DRUID + && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA + && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) + return false; + // Rogue Stealth + if(spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE + && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA + && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) + return false; + } + return true; +} + +bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool isFromTheSameCaster ) const +{ + SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); + SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + + if(!spellInfo_1 || !spellInfo_2) + return false; + + SpellSpecific spellId_spec_1 = GetSpellSpecific(spellId_1); + SpellSpecific spellId_spec_2 = GetSpellSpecific(spellId_2); + if (spellId_spec_1 && spellId_spec_2) + if (IsSingleFromSpellSpecificPerTarget(spellId_spec_1,spellId_spec_2) + || (IsSingleFromSpellSpecificPerCaster(spellId_spec_1,spellId_spec_2) && isFromTheSameCaster)) + return true; + + if(spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName) + return false; + + if(!spellInfo_1->SpellFamilyName) // generic spells + { + if(!spellInfo_1->SpellIconID + || spellInfo_1->SpellIconID != spellInfo_2->SpellIconID) + return false; + } + + //if both elixirs are not battle/guardian/potions/flasks then always stack + else if ((spellInfo_1->SpellFamilyName == SPELLFAMILY_POTION) + &&(spellId_spec_1 || spellId_spec_2)) + return false; + + else if (spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags) + return false; + + for(uint32 i = 0; i < 3; ++i) + { + if(spellInfo_1->Effect[i] != spellInfo_2->Effect[i]) + return false; + if (spellInfo_1->EffectApplyAuraName[i] || spellInfo_2->EffectApplyAuraName[i]) + { + if(spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i] + || spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i]) + // need itemtype check? need to find an example + return false; + else if (!isFromTheSameCaster) + switch(spellInfo_1->EffectApplyAuraName[i]) + { + //spells with these auras from different casters will stack + case SPELL_AURA_PERIODIC_DAMAGE: + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_PERIODIC_TRIGGER_SPELL: + case SPELL_AURA_PERIODIC_ENERGIZE: + case SPELL_AURA_PERIODIC_MANA_LEECH: + case SPELL_AURA_PERIODIC_LEECH: + //exception for shaman positive totems with these auras + if ((spellInfo_1->SpellFamilyName != SPELLFAMILY_SHAMAN) + ||(spellInfo_1->Effect[i]!=SPELL_AURA_MOD_INCREASE_ENERGY)) + return false; + default: + break; + } + } + } + return true; +} + +bool SpellMgr::IsProfessionSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return false; + + if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) + return false; + + uint32 skill = spellInfo->EffectMiscValue[1]; + + return IsProfessionSkill(skill); +} + +bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return false; + + if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) + return false; + + uint32 skill = spellInfo->EffectMiscValue[1]; + + return IsPrimaryProfessionSkill(skill); +} + +bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const +{ + return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1; +} + +SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const +{ + // ignore passive spells + if(IsPassiveSpell(spellInfo->Id)) + return spellInfo; + + bool needRankSelection = false; + for(int i=0;i<3;i++) + { + if( IsPositiveEffect(spellInfo->Id, i) && ( + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY + ) ) + { + needRankSelection = true; + break; + } + } + + // not required + if(!needRankSelection) + return spellInfo; + + for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId)) + { + SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId); + if(!nextSpellInfo) + break; + + // if found appropriate level + if(playerLevel + 10 >= nextSpellInfo->spellLevel) + return nextSpellInfo; + + // one rank less then + } + + // not found + return NULL; +} + +void SpellMgr::LoadSpellChains() +{ + mSpellChains.clear(); // need for reload case + mSpellChainsNext.clear(); // need for reload case + + QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain"); + if(result == NULL) + { + barGoLink bar( 1 ); + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded 0 spell chain records" ); + sLog.outErrorDb("`spell_chains` table is empty!"); + return; + } + + uint32 count = 0; + + barGoLink bar( result->GetRowCount() ); + do + { + bar.step(); + Field *fields = result->Fetch(); + + uint32 spell_id = fields[0].GetUInt32(); + + SpellChainNode node; + node.prev = fields[1].GetUInt32(); + node.first = fields[2].GetUInt32(); + node.rank = fields[3].GetUInt8(); + node.req = fields[4].GetUInt32(); + + if(!sSpellStore.LookupEntry(spell_id)) + { + sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id); + continue; + } + + if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev)) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(!sSpellStore.LookupEntry(node.first)) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell) + if( (spell_id == node.first) != (node.rank <= 1) || + (spell_id == node.first) != (node.prev == 0) || + (node.rank <= 1) != (node.prev == 0) ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(node.req!=0 && !sSpellStore.LookupEntry(node.req)) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + // talents not required data in spell chain for work, but must be checked if present for intergrity + if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id)) + { + if(node.rank!=pos->rank+1) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id)) + { + if(node.first!=talentEntry->RankID[0]) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1]) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(node.req!=talentEntry->DependsOnSpell) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + } + } + + mSpellChains[spell_id] = node; + + if(node.prev) + mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id)); + + if(node.req) + mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id)); + + ++count; + } while( result->NextRow() ); + + // additional integrity checks + for(SpellChainMap::iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i) + { + if(i->second.prev) + { + SpellChainMap::iterator i_prev = mSpellChains.find(i->second.prev); + if(i_prev == mSpellChains.end()) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); + } + else if( i_prev->second.first != i->second.first ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different first spell in chain compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); + } + else if( i_prev->second.rank+1 != i->second.rank ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different rank compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); + } + } + + if(i->second.req) + { + SpellChainMap::iterator i_req = mSpellChains.find(i->second.req); + if(i_req == mSpellChains.end()) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); + } + else if( i_req->second.first == i->second.first ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell from same spell chain (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); + } + else if( i_req->second.req ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell with required spell (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); + } + } + } + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell chain records", count ); +} + +void SpellMgr::LoadSpellLearnSkills() +{ + mSpellLearnSkills.clear(); // need for reload case + + // search auto-learned skills and add its to map also for use in unlearn spells/talents + uint32 dbc_count = 0; + for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) + { + SpellEntry const* entry = sSpellStore.LookupEntry(spell); + + if(!entry) + continue; + + for(int i = 0; i < 3; ++i) + { + if(entry->Effect[i]==SPELL_EFFECT_SKILL) + { + SpellLearnSkillNode dbc_node; + dbc_node.skill = entry->EffectMiscValue[i]; + if ( dbc_node.skill != SKILL_RIDING ) + dbc_node.value = 1; + else + dbc_node.value = (entry->EffectBasePoints[i]+1)*75; + dbc_node.maxvalue = (entry->EffectBasePoints[i]+1)*75; + + SpellLearnSkillNode const* db_node = GetSpellLearnSkill(spell); + + mSpellLearnSkills[spell] = dbc_node; + ++dbc_count; + break; + } + } + } + + sLog.outString(); + sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count ); +} + +void SpellMgr::LoadSpellLearnSpells() +{ + mSpellLearnSpells.clear(); // need for reload case + + QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID FROM spell_learn_spell"); + if(!result) + { + barGoLink bar( 1 ); + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded 0 spell learn spells" ); + sLog.outErrorDb("`spell_learn_spell` table is empty!"); + return; + } + + uint32 count = 0; + + barGoLink bar( result->GetRowCount() ); + do + { + bar.step(); + Field *fields = result->Fetch(); + + uint32 spell_id = fields[0].GetUInt32(); + + SpellLearnSpellNode node; + node.spell = fields[1].GetUInt32(); + node.autoLearned= false; + + if(!sSpellStore.LookupEntry(spell_id)) + { + sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id); + continue; + } + + if(!sSpellStore.LookupEntry(node.spell)) + { + sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell); + continue; + } + + mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node)); + + ++count; + } while( result->NextRow() ); + + delete result; + + // search auto-learned spells and add its to map also for use in unlearn spells/talents + uint32 dbc_count = 0; + for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) + { + SpellEntry const* entry = sSpellStore.LookupEntry(spell); + + if(!entry) + continue; + + for(int i = 0; i < 3; ++i) + { + if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL) + { + SpellLearnSpellNode dbc_node; + dbc_node.spell = entry->EffectTriggerSpell[i]; + dbc_node.autoLearned = true; + + SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell); + SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell); + + bool found = false; + for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr) + { + if(itr->second.spell == dbc_node.spell) + { + sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.", + spell,dbc_node.spell); + found = true; + break; + } + } + + if(!found) // add new spell-spell pair if not found + { + mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node)); + ++dbc_count; + } + } + } + } + + sLog.outString(); + sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count ); +} + +void SpellMgr::LoadSpellScriptTarget() +{ + mSpellScriptTarget.clear(); // need for reload case + + uint32 count = 0; + + QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target"); + + if(!result) + { + barGoLink bar(1); + + bar.step(); + + sLog.outString(); + sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty."); + return; + } + + barGoLink bar(result->GetRowCount()); + + do + { + Field *fields = result->Fetch(); + bar.step(); + + uint32 spellId = fields[0].GetUInt32(); + uint32 type = fields[1].GetUInt32(); + uint32 targetEntry = fields[2].GetUInt32(); + + SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); + + if(!spellProto) + { + sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry); + continue; + } + + /*bool targetfound = false; + for(int i = 0; i <3; ++i) + { + if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT || + spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT || + spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES || + spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES ) + { + targetfound = true; + break; + } + } + if(!targetfound) + { + sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not have any implicit target TARGET_SCRIPT(38) or TARGET_SCRIPT_COORDINATES (46).",spellId,targetEntry); + continue; + }*/ + + if( type >= MAX_SPELL_TARGET_TYPE ) + { + sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry); + continue; + } + + switch(type) + { + case SPELL_TARGET_TYPE_GAMEOBJECT: + { + if( targetEntry==0 ) + break; + + if(!sGOStorage.LookupEntry(targetEntry)) + { + sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry); + continue; + } + break; + } + default: + { + if( targetEntry==0 ) + { + sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type); + continue; + } + if(!sCreatureStorage.LookupEntry(targetEntry)) + { + sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry); + continue; + } + const CreatureInfo* cInfo = sCreatureStorage.LookupEntry(targetEntry); + + if(spellId == 30427 && !cInfo->SkinLootId) + { + sLog.outErrorDb("Table `spell_script_target` has creature %u as a target of spellid 30427, but this creature has no skinlootid. Gas extraction will not work!", cInfo->Entry); + continue; + } + break; + } + } + + mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry))); + + ++count; + } while (result->NextRow()); + + delete result; + + // Check all spells + /* Disabled (lot errors at this moment) + for(uint32 i = 1; i < sSpellStore.nCount; ++i) + { + SpellEntry const * spellInfo = sSpellStore.LookupEntry(i); + if(!spellInfo) + continue; + + bool found = false; + for(int j=0; j<3; ++j) + { + if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT ) + { + SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id); + SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id); + if(lower==upper) + { + sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = %u (TARGET_SCRIPT), but does not have record in `spell_script_target`",spellInfo->Id,TARGET_SCRIPT); + break; // effects of spell + } + } + } + } + */ + + sLog.outString(); + sLog.outString(">> Loaded %u Spell Script Targets", count); +} + +void SpellMgr::LoadSpellPetAuras() +{ + mSpellPetAuraMap.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 + QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell pet auras", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 spell = fields[0].GetUInt16(); + uint16 pet = fields[1].GetUInt16(); + uint16 aura = fields[2].GetUInt16(); + + SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell); + if(itr != mSpellPetAuraMap.end()) + { + itr->second.AddAura(pet, aura); + } + else + { + SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell); + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell); + continue; + } + int i = 0; + for(; i < 3; ++i) + if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) || + spellInfo->Effect[i] == SPELL_EFFECT_DUMMY) + break; + + if(i == 3) + { + sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell); + continue; + } + + SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura); + if (!spellInfo2) + { + sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura); + continue; + } + + PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->EffectBasePoints[i] + spellInfo->EffectBaseDice[i]); + mSpellPetAuraMap[spell] = pa; + } + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell pet auras", count ); +} + +// set data in core for now +void SpellMgr::LoadSpellCustomAttr() +{ + SpellEntry *tempSpell; + for(uint32 i = 0; i < GetSpellStore()->GetNumRows(); ++i) + { + tempSpell = (SpellEntry*)GetSpellStore()->LookupEntry(i); + if(!tempSpell) + continue; + + mSpellCustomAttrMap[tempSpell->Id] = 0; + + for(uint32 i = 0; i < 3; ++i) + { + switch(tempSpell->EffectApplyAuraName[i]) + { + case SPELL_AURA_PERIODIC_DAMAGE: + case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: + case SPELL_AURA_PERIODIC_LEECH: + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_DAMAGE; + break; + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_OBS_MOD_HEALTH: + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_HEAL; + break; + default: + break; + } + } + + if(tempSpell->SpellVisual == 3879) + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_BACK; + + switch(tempSpell->Id) + { + case 26029: // dark glare + case 37433: // spout + case 43140: case 43215: // flame breath + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_LINE; + break; + case 24340: case 26558: case 28884: // Meteor + case 36837: case 38903: case 41276: // Meteor + case 26789: // Shard of the Fallen Star + case 31436: // Malevolent Cleave + case 35181: // Dive Bomb + case 40810: case 43267: case 43268: // Saber Lash + case 42384: // Brutal Swipe + case 45150: // Meteor Slash + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_SHARE_DAMAGE; + break; + case 44978: case 45001: case 45002: // Wild Magic + case 45004: case 45006: case 45010: // Wild Magic + case 31347: // Doom + case 41635: // Prayer of Mending + case 44869: // Spectral Blast + case 45027: // Revitalize + case 45976: // Muru Portal Channel + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; + tempSpell->MaxAffectedTargets = 1; + break; + case 41376: // Spite + case 39992: // Needle Spine + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; + tempSpell->MaxAffectedTargets = 3; + break; + case 8122: case 8124: case 10888: case 10890: // Psychic Scream + tempSpell->Attributes |= SPELL_ATTR_BREAKABLE_BY_DAMAGE; + break; + default: + break; + } + } +} + +void SpellMgr::LoadSpellLinked() +{ + mSpellLinkedMap.clear(); // need for reload case + uint32 count = 0; + + // 0 1 2 + QueryResult *result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell"); + if( !result ) + { + barGoLink bar( 1 ); + bar.step(); + sLog.outString(); + sLog.outString( ">> Loaded %u linked spells", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + int32 trigger = fields[0].GetInt32(); + int32 effect = fields[1].GetInt32(); + int32 type = fields[2].GetInt32(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(trigger)); + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(trigger)); + continue; + } + spellInfo = sSpellStore.LookupEntry(abs(effect)); + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(effect)); + continue; + } + + if(type) //we will find a better way when more types are needed + trigger += 1000000; + mSpellLinkedMap[trigger].push_back(effect); + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u linked spells", count ); +} + +/// Some checks for spells, to prevent adding depricated/broken spells for trainers, spell book, etc +bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg) +{ + // not exist + if(!spellInfo) + return false; + + bool need_check_reagents = false; + + // check effects + for(int i=0; i<3; ++i) + { + switch(spellInfo->Effect[i]) + { + case 0: + continue; + + // craft spell for crafting non-existed item (break client recipes list show) + case SPELL_EFFECT_CREATE_ITEM: + { + if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] )) + { + if(msg) + { + if(pl) + ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); + else + sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); + } + return false; + } + + need_check_reagents = true; + break; + } + case SPELL_EFFECT_LEARN_SPELL: + { + SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[0]); + if( !IsSpellValid(spellInfo2,pl,msg) ) + { + if(msg) + { + if(pl) + ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); + else + sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); + } + return false; + } + break; + } + } + } + + if(need_check_reagents) + { + for(int j = 0; j < 8; ++j) + { + if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] )) + { + if(msg) + { + if(pl) + ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); + else + sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); + } + return false; + } + } + } + + return true; +} + +bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id) +{ + // normal case + if( spellInfo->AreaId && spellInfo->AreaId != zone_id && spellInfo->AreaId != area_id ) + return false; + + // elixirs (all area dependent elixirs have family SPELLFAMILY_POTION, use this for speedup) + if(spellInfo->SpellFamilyName==SPELLFAMILY_POTION) + { + if(uint32 mask = spellmgr.GetSpellElixirMask(spellInfo->Id)) + { + if(mask & ELIXIR_UNSTABLE_MASK) + { + // in the Blade's Edge Mountains Plateaus and Gruul's Lair. + return zone_id ==3522 || map_id==565; + } + if(mask & ELIXIR_SHATTRATH_MASK) + { + // in Tempest Keep, Serpentshrine Cavern, Caverns of Time: Mount Hyjal, Black Temple + // TODO: and the Sunwell Plateau + if(zone_id ==3607 || map_id==534 || map_id==564) + return true; + + MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); + if(!mapEntry) + return false; + + return mapEntry->multimap_id==206; + } + + // elixirs not have another limitations + return true; + } + } + + // special cases zone check (maps checked by multimap common id) + switch(spellInfo->Id) + { + case 41618: + case 41620: + { + MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); + if(!mapEntry) + return false; + + return mapEntry->multimap_id==206; + } + + case 41617: + case 41619: + { + MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); + if(!mapEntry) + return false; + + return mapEntry->multimap_id==207; + } + // Dragonmaw Illusion + case 40216: + case 42016: + { + if ( area_id != 3759 && area_id != 3966 && area_id != 3939 ) + return false; + break; + } + } + + return true; +} + +void SpellMgr::LoadSkillLineAbilityMap() +{ + mSkillLineAbilityMap.clear(); + + uint32 count = 0; + + for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); i++) + { + SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i); + if(!SkillInfo) + continue; + + mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo)); + ++count; + } + + sLog.outString(); + sLog.outString(">> Loaded %u SkillLineAbility MultiMap", count); +} + +DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered) +{ + // Explicit Diminishing Groups + switch(spellproto->SpellFamilyName) + { + case SPELLFAMILY_MAGE: + { + // Polymorph + if ((spellproto->SpellFamilyFlags & 0x00001000000LL) && spellproto->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) + return DIMINISHING_POLYMORPH; + break; + } + case SPELLFAMILY_ROGUE: + { + // Kidney Shot + if (spellproto->SpellFamilyFlags & 0x00000200000LL) + return DIMINISHING_KIDNEYSHOT; + // Blind + else if (spellproto->SpellFamilyFlags & 0x00001000000LL) + return DIMINISHING_BLIND_CYCLONE; + break; + } + case SPELLFAMILY_WARLOCK: + { + // Death Coil + if (spellproto->SpellFamilyFlags & 0x00000080000LL) + return DIMINISHING_DEATHCOIL; + // Fear + else if (spellproto->SpellFamilyFlags & 0x40840000000LL) + return DIMINISHING_WARLOCK_FEAR; + // Curses/etc + else if (spellproto->SpellFamilyFlags & 0x00080000000LL) + return DIMINISHING_LIMITONLY; + break; + } + case SPELLFAMILY_DRUID: + { + // Cyclone + if (spellproto->SpellFamilyFlags & 0x02000000000LL) + return DIMINISHING_BLIND_CYCLONE; + break; + } + case SPELLFAMILY_WARRIOR: + { + // Hamstring - limit duration to 10s in PvP + if (spellproto->SpellFamilyFlags & 0x00000000002LL) + return DIMINISHING_LIMITONLY; + break; + } + default: + break; + } + + // Get by mechanic + for (uint8 i=0;i<3;++i) + { + if (spellproto->Mechanic == MECHANIC_STUN || spellproto->EffectMechanic[i] == MECHANIC_STUN) + return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN; + else if (spellproto->Mechanic == MECHANIC_SLEEP || spellproto->EffectMechanic[i] == MECHANIC_SLEEP) + return DIMINISHING_SLEEP; + else if (spellproto->Mechanic == MECHANIC_ROOT || spellproto->EffectMechanic[i] == MECHANIC_ROOT) + return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT; + else if (spellproto->Mechanic == MECHANIC_FEAR || spellproto->EffectMechanic[i] == MECHANIC_FEAR) + return DIMINISHING_FEAR; + else if (spellproto->Mechanic == MECHANIC_CHARM || spellproto->EffectMechanic[i] == MECHANIC_CHARM) + return DIMINISHING_CHARM; + else if (spellproto->Mechanic == MECHANIC_SILENCE || spellproto->EffectMechanic[i] == MECHANIC_SILENCE) + return DIMINISHING_SILENCE; + else if (spellproto->Mechanic == MECHANIC_DISARM || spellproto->EffectMechanic[i] == MECHANIC_DISARM) + return DIMINISHING_DISARM; + else if (spellproto->Mechanic == MECHANIC_FREEZE || spellproto->EffectMechanic[i] == MECHANIC_FREEZE) + return DIMINISHING_FREEZE; + else if (spellproto->Mechanic == MECHANIC_KNOCKOUT|| spellproto->EffectMechanic[i] == MECHANIC_KNOCKOUT || + spellproto->Mechanic == MECHANIC_SAPPED || spellproto->EffectMechanic[i] == MECHANIC_SAPPED) + return DIMINISHING_KNOCKOUT; + else if (spellproto->Mechanic == MECHANIC_BANISH || spellproto->EffectMechanic[i] == MECHANIC_BANISH) + return DIMINISHING_BANISH; + } + + return DIMINISHING_NONE; +} + +bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group) +{ + switch(group) + { + case DIMINISHING_CONTROL_STUN: + case DIMINISHING_TRIGGER_STUN: + case DIMINISHING_KIDNEYSHOT: + case DIMINISHING_SLEEP: + case DIMINISHING_CONTROL_ROOT: + case DIMINISHING_TRIGGER_ROOT: + case DIMINISHING_FEAR: + case DIMINISHING_WARLOCK_FEAR: + case DIMINISHING_CHARM: + case DIMINISHING_POLYMORPH: + case DIMINISHING_FREEZE: + case DIMINISHING_KNOCKOUT: + case DIMINISHING_BLIND_CYCLONE: + case DIMINISHING_BANISH: + case DIMINISHING_LIMITONLY: + return true; + } + return false; +} + +DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group) +{ + switch(group) + { + case DIMINISHING_BLIND_CYCLONE: + case DIMINISHING_CONTROL_STUN: + case DIMINISHING_TRIGGER_STUN: + case DIMINISHING_KIDNEYSHOT: + return DRTYPE_ALL; + case DIMINISHING_SLEEP: + case DIMINISHING_CONTROL_ROOT: + case DIMINISHING_TRIGGER_ROOT: + case DIMINISHING_FEAR: + case DIMINISHING_CHARM: + case DIMINISHING_POLYMORPH: + case DIMINISHING_SILENCE: + case DIMINISHING_DISARM: + case DIMINISHING_DEATHCOIL: + case DIMINISHING_FREEZE: + case DIMINISHING_BANISH: + case DIMINISHING_WARLOCK_FEAR: + case DIMINISHING_KNOCKOUT: + return DRTYPE_PLAYER; + } + + return DRTYPE_NONE; +} diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index 7de9c54c6cb..e86a394af9d 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -1,898 +1,899 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _SPELLMGR_H -#define _SPELLMGR_H - -// For static or at-server-startup loaded spell data -// For more high level function for sSpellStore data - -#include "SharedDefines.h" -#include "Database/DBCStructure.h" -#include "Database/SQLStorage.h" - -#include "Utilities/UnorderedMap.h" -#include - -class Player; -class Spell; - -extern SQLStorage sSpellThreatStore; - -enum SpellFailedReason -{ - SPELL_FAILED_AFFECTING_COMBAT = 0x00, - SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 0x01, - SPELL_FAILED_ALREADY_AT_FULL_MANA = 0x02, - SPELL_FAILED_ALREADY_AT_FULL_POWER = 0x03, - SPELL_FAILED_ALREADY_BEING_TAMED = 0x04, - SPELL_FAILED_ALREADY_HAVE_CHARM = 0x05, - SPELL_FAILED_ALREADY_HAVE_SUMMON = 0x06, - SPELL_FAILED_ALREADY_OPEN = 0x07, - SPELL_FAILED_AURA_BOUNCED = 0x08, - SPELL_FAILED_AUTOTRACK_INTERRUPTED = 0x09, - SPELL_FAILED_BAD_IMPLICIT_TARGETS = 0x0A, - SPELL_FAILED_BAD_TARGETS = 0x0B, - SPELL_FAILED_CANT_BE_CHARMED = 0x0C, - SPELL_FAILED_CANT_BE_DISENCHANTED = 0x0D, - SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL = 0x0E, - SPELL_FAILED_CANT_BE_PROSPECTED = 0x0F, - SPELL_FAILED_CANT_CAST_ON_TAPPED = 0x10, - SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE = 0x11, - SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED = 0x12, - SPELL_FAILED_CANT_STEALTH = 0x13, - SPELL_FAILED_CASTER_AURASTATE = 0x14, - SPELL_FAILED_CASTER_DEAD = 0x15, - SPELL_FAILED_CHARMED = 0x16, - SPELL_FAILED_CHEST_IN_USE = 0x17, - SPELL_FAILED_CONFUSED = 0x18, - SPELL_FAILED_DONT_REPORT = 0x19, - SPELL_FAILED_EQUIPPED_ITEM = 0x1A, - SPELL_FAILED_EQUIPPED_ITEM_CLASS = 0x1B, - SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND = 0x1C, - SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND = 0x1D, - SPELL_FAILED_ERROR = 0x1E, - SPELL_FAILED_FIZZLE = 0x1F, - SPELL_FAILED_FLEEING = 0x20, - SPELL_FAILED_FOOD_LOWLEVEL = 0x21, - SPELL_FAILED_HIGHLEVEL = 0x22, - SPELL_FAILED_HUNGER_SATIATED = 0x23, - SPELL_FAILED_IMMUNE = 0x24, - SPELL_FAILED_INTERRUPTED = 0x25, - SPELL_FAILED_INTERRUPTED_COMBAT = 0x26, - SPELL_FAILED_ITEM_ALREADY_ENCHANTED = 0x27, - SPELL_FAILED_ITEM_GONE = 0x28, - SPELL_FAILED_ITEM_NOT_FOUND = 0x29, - SPELL_FAILED_ITEM_NOT_READY = 0x2A, - SPELL_FAILED_LEVEL_REQUIREMENT = 0x2B, - SPELL_FAILED_LINE_OF_SIGHT = 0x2C, - SPELL_FAILED_LOWLEVEL = 0x2D, - SPELL_FAILED_LOW_CASTLEVEL = 0x2E, - SPELL_FAILED_MAINHAND_EMPTY = 0x2F, - SPELL_FAILED_MOVING = 0x30, - SPELL_FAILED_NEED_AMMO = 0x31, - SPELL_FAILED_NEED_AMMO_POUCH = 0x32, - SPELL_FAILED_NEED_EXOTIC_AMMO = 0x33, - SPELL_FAILED_NOPATH = 0x34, - SPELL_FAILED_NOT_BEHIND = 0x35, - SPELL_FAILED_NOT_FISHABLE = 0x36, - SPELL_FAILED_NOT_FLYING = 0x37, - SPELL_FAILED_NOT_HERE = 0x38, - SPELL_FAILED_NOT_INFRONT = 0x39, - SPELL_FAILED_NOT_IN_CONTROL = 0x3A, - SPELL_FAILED_NOT_KNOWN = 0x3B, - SPELL_FAILED_NOT_MOUNTED = 0x3C, - SPELL_FAILED_NOT_ON_TAXI = 0x3D, - SPELL_FAILED_NOT_ON_TRANSPORT = 0x3E, - SPELL_FAILED_NOT_READY = 0x3F, - SPELL_FAILED_NOT_SHAPESHIFT = 0x40, - SPELL_FAILED_NOT_STANDING = 0x41, - SPELL_FAILED_NOT_TRADEABLE = 0x42, - SPELL_FAILED_NOT_TRADING = 0x43, - SPELL_FAILED_NOT_UNSHEATHED = 0x44, - SPELL_FAILED_NOT_WHILE_GHOST = 0x45, - SPELL_FAILED_NO_AMMO = 0x46, - SPELL_FAILED_NO_CHARGES_REMAIN = 0x47, - SPELL_FAILED_NO_CHAMPION = 0x48, - SPELL_FAILED_NO_COMBO_POINTS = 0x49, - SPELL_FAILED_NO_DUELING = 0x4A, - SPELL_FAILED_NO_ENDURANCE = 0x4B, - SPELL_FAILED_NO_FISH = 0x4C, - SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED = 0x4D, - SPELL_FAILED_NO_MOUNTS_ALLOWED = 0x4E, - SPELL_FAILED_NO_PET = 0x4F, - SPELL_FAILED_NO_POWER = 0x50, - SPELL_FAILED_NOTHING_TO_DISPEL = 0x51, - SPELL_FAILED_NOTHING_TO_STEAL = 0x52, - SPELL_FAILED_ONLY_ABOVEWATER = 0x53, - SPELL_FAILED_ONLY_DAYTIME = 0x54, - SPELL_FAILED_ONLY_INDOORS = 0x55, - SPELL_FAILED_ONLY_MOUNTED = 0x56, - SPELL_FAILED_ONLY_NIGHTTIME = 0x57, - SPELL_FAILED_ONLY_OUTDOORS = 0x58, - SPELL_FAILED_ONLY_SHAPESHIFT = 0x59, - SPELL_FAILED_ONLY_STEALTHED = 0x5A, - SPELL_FAILED_ONLY_UNDERWATER = 0x5B, - SPELL_FAILED_OUT_OF_RANGE = 0x5C, - SPELL_FAILED_PACIFIED = 0x5D, - SPELL_FAILED_POSSESSED = 0x5E, - SPELL_FAILED_REAGENTS = 0x5F, - SPELL_FAILED_REQUIRES_AREA = 0x60, - SPELL_FAILED_REQUIRES_SPELL_FOCUS = 0x61, - SPELL_FAILED_ROOTED = 0x62, - SPELL_FAILED_SILENCED = 0x63, - SPELL_FAILED_SPELL_IN_PROGRESS = 0x64, - SPELL_FAILED_SPELL_LEARNED = 0x65, - SPELL_FAILED_SPELL_UNAVAILABLE = 0x66, - SPELL_FAILED_STUNNED = 0x67, - SPELL_FAILED_TARGETS_DEAD = 0x68, - SPELL_FAILED_TARGET_AFFECTING_COMBAT = 0x69, - SPELL_FAILED_TARGET_AURASTATE = 0x6A, - SPELL_FAILED_TARGET_DUELING = 0x6B, - SPELL_FAILED_TARGET_ENEMY = 0x6C, - SPELL_FAILED_TARGET_ENRAGED = 0x6D, - SPELL_FAILED_TARGET_FRIENDLY = 0x6E, - SPELL_FAILED_TARGET_IN_COMBAT = 0x6F, - SPELL_FAILED_TARGET_IS_PLAYER = 0x70, - SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED = 0x71, - SPELL_FAILED_TARGET_NOT_DEAD = 0x72, - SPELL_FAILED_TARGET_NOT_IN_PARTY = 0x73, - SPELL_FAILED_TARGET_NOT_LOOTED = 0x74, - SPELL_FAILED_TARGET_NOT_PLAYER = 0x75, - SPELL_FAILED_TARGET_NO_POCKETS = 0x76, - SPELL_FAILED_TARGET_NO_WEAPONS = 0x77, - SPELL_FAILED_TARGET_UNSKINNABLE = 0x78, - SPELL_FAILED_THIRST_SATIATED = 0x79, - SPELL_FAILED_TOO_CLOSE = 0x7A, - SPELL_FAILED_TOO_MANY_OF_ITEM = 0x7B, - SPELL_FAILED_TOTEM_CATEGORY = 0x7C, - SPELL_FAILED_TOTEMS = 0x7D, - SPELL_FAILED_TRAINING_POINTS = 0x7E, - SPELL_FAILED_TRY_AGAIN = 0x7F, - SPELL_FAILED_UNIT_NOT_BEHIND = 0x80, - SPELL_FAILED_UNIT_NOT_INFRONT = 0x81, - SPELL_FAILED_WRONG_PET_FOOD = 0x82, - SPELL_FAILED_NOT_WHILE_FATIGUED = 0x83, - SPELL_FAILED_TARGET_NOT_IN_INSTANCE = 0x84, - SPELL_FAILED_NOT_WHILE_TRADING = 0x85, - SPELL_FAILED_TARGET_NOT_IN_RAID = 0x86, - SPELL_FAILED_DISENCHANT_WHILE_LOOTING = 0x87, - SPELL_FAILED_PROSPECT_WHILE_LOOTING = 0x88, - SPELL_FAILED_PROSPECT_NEED_MORE = 0x89, - SPELL_FAILED_TARGET_FREEFORALL = 0x8A, - SPELL_FAILED_NO_EDIBLE_CORPSES = 0x8B, - SPELL_FAILED_ONLY_BATTLEGROUNDS = 0x8C, - SPELL_FAILED_TARGET_NOT_GHOST = 0x8D, - SPELL_FAILED_TOO_MANY_SKILLS = 0x8E, - SPELL_FAILED_TRANSFORM_UNUSABLE = 0x8F, - SPELL_FAILED_WRONG_WEATHER = 0x90, - SPELL_FAILED_DAMAGE_IMMUNE = 0x91, - SPELL_FAILED_PREVENTED_BY_MECHANIC = 0x92, - SPELL_FAILED_PLAY_TIME = 0x93, - SPELL_FAILED_REPUTATION = 0x94, - SPELL_FAILED_MIN_SKILL = 0x95, - SPELL_FAILED_NOT_IN_ARENA = 0x96, - SPELL_FAILED_NOT_ON_SHAPESHIFT = 0x97, - SPELL_FAILED_NOT_ON_STEALTHED = 0x98, - SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE = 0x99, - SPELL_FAILED_NOT_ON_MOUNTED = 0x9A, - SPELL_FAILED_TOO_SHALLOW = 0x9B, - SPELL_FAILED_TARGET_NOT_IN_SANCTUARY = 0x9C, - SPELL_FAILED_TARGET_IS_TRIVIAL = 0x9D, - SPELL_FAILED_BM_OR_INVISGOD = 0x9E, - SPELL_FAILED_EXPERT_RIDING_REQUIREMENT = 0x9F, - SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT = 0xA0, - SPELL_FAILED_NOT_IDLE = 0xA1, - SPELL_FAILED_NOT_INACTIVE = 0xA2, - SPELL_FAILED_PARTIAL_PLAYTIME = 0xA3, - SPELL_FAILED_NO_PLAYTIME = 0xA4, - SPELL_FAILED_NOT_IN_BATTLEGROUND = 0xA5, - SPELL_FAILED_ONLY_IN_ARENA = 0xA6, - SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 0xA7, - SPELL_FAILED_UNKNOWN = 0xA8, -}; - -enum SpellFamilyNames -{ - SPELLFAMILY_GENERIC = 0, - SPELLFAMILY_UNK1 = 1, // events, holidays - // 2 - unused - SPELLFAMILY_MAGE = 3, - SPELLFAMILY_WARRIOR = 4, - SPELLFAMILY_WARLOCK = 5, - SPELLFAMILY_PRIEST = 6, - SPELLFAMILY_DRUID = 7, - SPELLFAMILY_ROGUE = 8, - SPELLFAMILY_HUNTER = 9, - SPELLFAMILY_PALADIN = 10, - SPELLFAMILY_SHAMAN = 11, - SPELLFAMILY_UNK2 = 12, - SPELLFAMILY_POTION = 13 -}; - -enum SpellDisableTypes -{ - SPELL_DISABLE_PLAYER = 1, - SPELL_DISABLE_CREATURE = 2 -}; - -//Some SpellFamilyFlags -#define SPELLFAMILYFLAG_ROGUE_VANISH 0x000000800LL -#define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL -#define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL -#define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL -#define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL -#define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL -#define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL - -// Spell clasification -enum SpellSpecific -{ - SPELL_NORMAL = 0, - SPELL_SEAL = 1, - SPELL_BLESSING = 2, - SPELL_AURA = 3, - SPELL_STING = 4, - SPELL_CURSE = 5, - SPELL_ASPECT = 6, - SPELL_TRACKER = 7, - SPELL_WARLOCK_ARMOR = 8, - SPELL_MAGE_ARMOR = 9, - SPELL_ELEMENTAL_SHIELD = 10, - SPELL_MAGE_POLYMORPH = 11, - SPELL_POSITIVE_SHOUT = 12, - SPELL_JUDGEMENT = 13, - SPELL_BATTLE_ELIXIR = 14, - SPELL_GUARDIAN_ELIXIR = 15, - SPELL_FLASK_ELIXIR = 16, - SPELL_WARLOCK_CORRUPTION= 17 -}; - -SpellSpecific GetSpellSpecific(uint32 spellId); - -// Different spell properties -inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); } -uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL); -inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); } -inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); } -inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; } -int32 GetSpellDuration(SpellEntry const *spellInfo); -int32 GetSpellMaxDuration(SpellEntry const *spellInfo); - -inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect) -{ - for(int i= 0; i < 3; ++i) - if(spellInfo->Effect[i]==effect) - return true; - return false; -} - -bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); - -inline bool IsSealSpell(SpellEntry const *spellInfo) -{ - //Collection of all the seal family flags. No other paladin spell has any of those. - return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && - ( spellInfo->SpellFamilyFlags & 0x4000A000200LL ); -} - -inline bool IsElementalShield(SpellEntry const *spellInfo) -{ - // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus - return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552; -} - -int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); -bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2); -bool IsPassiveSpell(uint32 spellId); - -inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo) -{ - switch(spellInfo->Id) - { - case 40214: // Dragonmaw Illusion - case 35480: case 35481: case 35482: // Human Illusion - case 35483: case 39824: // Human Illusion - return true; - } - - return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT; -} - -inline bool IsNonCombatSpell(SpellEntry const *spellInfo) -{ - return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0; -} - -bool IsPositiveSpell(uint32 spellId); -bool IsPositiveEffect(uint32 spellId, uint32 effIndex); -bool IsPositiveTarget(uint32 targetA, uint32 targetB); - -bool IsSingleTargetSpell(SpellEntry const *spellInfo); -bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2); - -bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id); - -inline bool IsAreaEffectTarget( Targets target ) -{ - switch (target ) - { - case TARGET_AREAEFFECT_CUSTOM: - case TARGET_ALL_ENEMY_IN_AREA: - case TARGET_ALL_ENEMY_IN_AREA_INSTANT: - case TARGET_ALL_PARTY_AROUND_CASTER: - case TARGET_ALL_AROUND_CASTER: - case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: - case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER: - case TARGET_ALL_PARTY: - case TARGET_ALL_PARTY_AROUND_CASTER_2: - case TARGET_AREAEFFECT_PARTY: - case TARGET_AREAEFFECT_CUSTOM_2: - case TARGET_AREAEFFECT_PARTY_AND_CLASS: - case TARGET_IN_FRONT_OF_CASTER: - case TARGET_ALL_FRIENDLY_UNITS_IN_AREA: - return true; - default: - break; - } - return false; -} - -inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo) -{ - if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0]))) - return true; - if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1]))) - return true; - if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2]))) - return true; - return false; -} - -inline bool IsAreaAuraEffect(uint32 effect) -{ - if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY || - effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND || - effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY || - effect == SPELL_EFFECT_APPLY_AREA_AURA_PET || - effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER) - return true; - return false; -} - -inline bool IsDispelSpell(SpellEntry const *spellInfo) -{ - if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL || - spellInfo->Effect[1] == SPELL_EFFECT_DISPEL || - spellInfo->Effect[2] == SPELL_EFFECT_DISPEL ) - return true; - return false; -} -inline bool isSpellBreakStealth(SpellEntry const* spellInfo) -{ - return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH); -} - -uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form); - -inline bool IsChanneledSpell(SpellEntry const* spellInfo) -{ - return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2)); -} - -inline bool NeedsComboPoints(SpellEntry const* spellInfo) -{ - return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2)); -} - -inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo) -{ - return SpellSchoolMask(spellInfo->SchoolMask); -} - -inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect) -{ - uint32 mask = 0; - if (spellInfo->Mechanic) - mask |= 1<Mechanic; - if (spellInfo->EffectMechanic[effect]) - mask |= 1<EffectMechanic[effect]; - return mask; -} - -inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect) -{ - if (spellInfo->EffectMechanic[effect]) - return Mechanics(spellInfo->EffectMechanic[effect]); - if (spellInfo->Mechanic) - return Mechanics(spellInfo->Mechanic); - return MECHANIC_NONE; -} - -inline uint32 GetDispellMask(DispelType dispel) -{ - // If dispel all - if (dispel == DISPEL_ALL) - return DISPEL_ALL_MASK; - else - return (1 << dispel); -} - -// Diminishing Returns interaction with spells -DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered); -bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group); -DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group); - -// Spell affects related declarations (accessed using SpellMgr functions) -typedef std::map SpellAffectMap; - -// Spell proc event related declarations (accessed using SpellMgr functions) -enum ProcFlags -{ - PROC_FLAG_NONE = 0x00000000, // None - PROC_FLAG_HIT_MELEE = 0x00000001, // On melee hit - PROC_FLAG_STRUCK_MELEE = 0x00000002, // On being struck melee - PROC_FLAG_KILL_XP_GIVER = 0x00000004, // On kill target giving XP or honor - PROC_FLAG_SPECIAL_DROP = 0x00000008, // - PROC_FLAG_DODGE = 0x00000010, // On dodge melee attack - PROC_FLAG_PARRY = 0x00000020, // On parry melee attack - PROC_FLAG_BLOCK = 0x00000040, // On block attack - PROC_FLAG_TOUCH = 0x00000080, // On being touched (for bombs, probably?) - PROC_FLAG_TARGET_LOW_HEALTH = 0x00000100, // On deal damage to enemy with 20% or less health - PROC_FLAG_LOW_HEALTH = 0x00000200, // On health dropped below 20% - PROC_FLAG_STRUCK_RANGED = 0x00000400, // On being struck ranged - PROC_FLAG_HIT_SPECIAL = 0x00000800, // (!)Removed, may be reassigned in future - PROC_FLAG_CRIT_MELEE = 0x00001000, // On crit melee - PROC_FLAG_STRUCK_CRIT_MELEE = 0x00002000, // On being critically struck in melee - PROC_FLAG_CAST_SPELL = 0x00004000, // On cast spell - PROC_FLAG_TAKE_DAMAGE = 0x00008000, // On take damage - PROC_FLAG_CRIT_SPELL = 0x00010000, // On crit spell - PROC_FLAG_HIT_SPELL = 0x00020000, // On hit spell - PROC_FLAG_STRUCK_CRIT_SPELL = 0x00040000, // On being critically struck by a spell - PROC_FLAG_HIT_RANGED = 0x00080000, // On getting ranged hit - PROC_FLAG_STRUCK_SPELL = 0x00100000, // On being struck by a spell - PROC_FLAG_TRAP = 0x00200000, // On trap activation (?) - PROC_FLAG_CRIT_RANGED = 0x00400000, // On getting ranged crit - PROC_FLAG_STRUCK_CRIT_RANGED = 0x00800000, // On being critically struck by a ranged attack - PROC_FLAG_RESIST_SPELL = 0x01000000, // On resist enemy spell - PROC_FLAG_TARGET_RESISTS = 0x02000000, // On enemy resisted spell - PROC_FLAG_TARGET_DODGE_OR_PARRY = 0x04000000, // On enemy dodges/parries - PROC_FLAG_HEAL = 0x08000000, // On heal - PROC_FLAG_CRIT_HEAL = 0x10000000, // On critical healing effect - PROC_FLAG_HEALED = 0x20000000, // On healing - PROC_FLAG_TARGET_BLOCK = 0x40000000, // On enemy blocks - PROC_FLAG_MISS = 0x80000000 // On miss melee attack -}; - -struct SpellProcEventEntry -{ - uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2 - uint32 category; // if nonzero - match proc condition based on candidate spell's category - uint32 skillId; // if nonzero - for matching proc condition based on candidate spell's skillId from SkillLineAbility.dbc (Shadow Bolt = Destruction) - uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value - uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do) - uint32 procFlags; // bitmask for matching proc event - float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc - uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_ -}; - -typedef UNORDERED_MAP SpellProcEventMap; - -#define ELIXIR_BATTLE_MASK 0x1 -#define ELIXIR_GUARDIAN_MASK 0x2 -#define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK) -#define ELIXIR_UNSTABLE_MASK 0x4 -#define ELIXIR_SHATTRATH_MASK 0x8 - -typedef std::map SpellElixirMap; - -// Spell script target related declarations (accessed using SpellMgr functions) -enum SpellTargetType -{ - SPELL_TARGET_TYPE_GAMEOBJECT = 0, - SPELL_TARGET_TYPE_CREATURE = 1, - SPELL_TARGET_TYPE_DEAD = 2 -}; - -#define MAX_SPELL_TARGET_TYPE 3 - -struct SpellTargetEntry -{ - SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {} - SpellTargetType type; - uint32 targetEntry; -}; - -typedef std::multimap SpellScriptTarget; - -// coordinates for spells (accessed using SpellMgr functions) -struct SpellTargetPosition -{ - uint32 target_mapId; - float target_X; - float target_Y; - float target_Z; - float target_Orientation; -}; - -typedef UNORDERED_MAP SpellTargetPositionMap; - -// Spell pet auras -class PetAura -{ - public: - PetAura() - { - auras.clear(); - } - - PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) : - removeOnChangePet(_removeOnChangePet), damage(_damage) - { - auras[petEntry] = aura; - } - - uint16 GetAura(uint16 petEntry) const - { - std::map::const_iterator itr = auras.find(petEntry); - if(itr != auras.end()) - return itr->second; - else - { - std::map::const_iterator itr = auras.find(0); - if(itr != auras.end()) - return itr->second; - else - return 0; - } - } - - void AddAura(uint16 petEntry, uint16 aura) - { - auras[petEntry] = aura; - } - - bool IsRemovedOnChangePet() const - { - return removeOnChangePet; - } - - int32 GetDamage() const - { - return damage; - } - - private: - std::map auras; - bool removeOnChangePet; - int32 damage; -}; -typedef std::map SpellPetAuraMap; - -// Spell rank chain (accessed using SpellMgr functions) -struct SpellChainNode -{ - uint32 prev; - uint32 first; - uint32 req; - uint8 rank; -}; - -typedef UNORDERED_MAP SpellChainMap; -typedef std::multimap SpellChainMapNext; - -// Spell learning properties (accessed using SpellMgr functions) -struct SpellLearnSkillNode -{ - uint32 skill; - uint32 value; // 0 - max skill value for player level - uint32 maxvalue; // 0 - max skill value for player level -}; - -typedef std::map SpellLearnSkillMap; - -struct SpellLearnSpellNode -{ - uint32 spell; - bool autoLearned; -}; - -typedef std::multimap SpellLearnSpellMap; - -typedef std::multimap SkillLineAbilityMap; - -inline bool IsPrimaryProfessionSkill(uint32 skill) -{ - SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill); - if(!pSkill) - return false; - - if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION) - return false; - - return true; -} - -inline bool IsProfessionSkill(uint32 skill) -{ - return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID; -} - -#define SPELL_ATTR_CU_PLAYERS_ONLY 0x00000001 -#define SPELL_ATTR_CU_CONE_BACK 0x00000002 -#define SPELL_ATTR_CU_CONE_LINE 0x00000004 -#define SPELL_ATTR_CU_SHARE_DAMAGE 0x00000008 -#define SPELL_ATTR_CU_EFFECT_HEAL 0x00000010 -#define SPELL_ATTR_CU_EFFECT_DAMAGE 0x00000020 - -typedef std::map SpellCustomAttrMap; - -typedef std::map > SpellLinkedMap; - -class SpellMgr -{ - // Constructors - public: - SpellMgr(); - ~SpellMgr(); - - // Accessors (const or static functions) - public: - // Spell affects - uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const - { - SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId); - if( itr != mSpellAffectMap.end( ) ) - return itr->second; - return 0; - } - - bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const; - - SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; } - - uint32 GetSpellElixirMask(uint32 spellid) const - { - SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid); - if(itr==mSpellElixirs.end()) - return 0x0; - - return itr->second; - } - - SpellSpecific GetSpellElixirSpecific(uint32 spellid) const - { - uint32 mask = GetSpellElixirMask(spellid); - if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK) - return SPELL_FLASK_ELIXIR; - else if(mask & ELIXIR_BATTLE_MASK) - return SPELL_BATTLE_ELIXIR; - else if(mask & ELIXIR_GUARDIAN_MASK) - return SPELL_GUARDIAN_ELIXIR; - else - return SPELL_NORMAL; - } - - // Spell proc events - SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const - { - SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId); - if( itr != mSpellProcEventMap.end( ) ) - return &itr->second; - return NULL; - } - - static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ); - - // Spell target coordinates - SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const - { - SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id ); - if( itr != mSpellTargetPositions.end( ) ) - return &itr->second; - return NULL; - } - - // Spell ranks chains - SpellChainNode const* GetSpellChainNode(uint32 spell_id) const - { - SpellChainMap::const_iterator itr = mSpellChains.find(spell_id); - if(itr == mSpellChains.end()) - return NULL; - - return &itr->second; - } - - uint32 GetFirstSpellInChain(uint32 spell_id) const - { - if(SpellChainNode const* node = GetSpellChainNode(spell_id)) - return node->first; - - return spell_id; - } - - uint32 GetPrevSpellInChain(uint32 spell_id) const - { - if(SpellChainNode const* node = GetSpellChainNode(spell_id)) - return node->prev; - - return 0; - } - - SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; } - - // Note: not use rank for compare to spell ranks: spell chains isn't linear order - // Use IsHighRankOfSpell instead - uint8 GetSpellRank(uint32 spell_id) const - { - if(SpellChainNode const* node = GetSpellChainNode(spell_id)) - return node->rank; - - return 0; - } - - uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const - { - SpellChainMap::const_iterator itr = mSpellChains.find(spell1); - - uint32 rank2 = GetSpellRank(spell2); - - // not ordered correctly by rank value - if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2) - return false; - - // check present in same rank chain - for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev)) - if(itr->second.prev==spell2) - return true; - - return false; - } - - bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const; - static bool canStackSpellRanks(SpellEntry const *spellInfo); - bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const; - - SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const; - - // Spell learning - SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const - { - SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id); - if(itr != mSpellLearnSkills.end()) - return &itr->second; - else - return NULL; - } - - bool IsSpellLearnSpell(uint32 spell_id) const - { - return mSpellLearnSpells.count(spell_id)!=0; - } - - SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const - { - return mSpellLearnSpells.lower_bound(spell_id); - } - - SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const - { - return mSpellLearnSpells.upper_bound(spell_id); - } - - bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const - { - SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1); - SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1); - for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i) - if(i->second.spell==spell_id2) - return true; - return false; - } - - static bool IsProfessionSpell(uint32 spellId); - static bool IsPrimaryProfessionSpell(uint32 spellId); - bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const; - - // Spell script targets - SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const - { - return mSpellScriptTarget.lower_bound(spell_id); - } - - SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const - { - return mSpellScriptTarget.upper_bound(spell_id); - } - - // Spell correctess for client using - static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true); - - SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const - { - return mSkillLineAbilityMap.lower_bound(spell_id); - } - - SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const - { - return mSkillLineAbilityMap.upper_bound(spell_id); - } - - PetAura const* GetPetAura(uint16 spell_id) - { - SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id); - if(itr != mSpellPetAuraMap.end()) - return &itr->second; - else - return NULL; - } - - uint32 GetSpellCustomAttr(uint32 spell_id) const - { - SpellCustomAttrMap::const_iterator itr = mSpellCustomAttrMap.find(spell_id); - if(itr != mSpellCustomAttrMap.end()) - return itr->second; - else - return 0; - } - - const std::vector *GetSpellLinked(int32 spell_id) const - { - SpellLinkedMap::const_iterator itr = mSpellLinkedMap.find(spell_id); - return itr != mSpellLinkedMap.end() ? &(itr->second) : NULL; - } - - // Modifiers - public: - static SpellMgr& Instance(); - - // Loading data at server startup - void LoadSpellChains(); - void LoadSpellLearnSkills(); - void LoadSpellLearnSpells(); - void LoadSpellScriptTarget(); - void LoadSpellAffects(); - void LoadSpellElixirs(); - void LoadSpellProcEvents(); - void LoadSpellTargetPositions(); - void LoadSpellThreats(); - void LoadSkillLineAbilityMap(); - void LoadSpellPetAuras(); - void LoadSpellCustomAttr(); - void LoadSpellLinked(); - - private: - SpellScriptTarget mSpellScriptTarget; - SpellChainMap mSpellChains; - SpellChainMapNext mSpellChainsNext; - SpellLearnSkillMap mSpellLearnSkills; - SpellLearnSpellMap mSpellLearnSpells; - SpellTargetPositionMap mSpellTargetPositions; - SpellAffectMap mSpellAffectMap; - SpellElixirMap mSpellElixirs; - SpellProcEventMap mSpellProcEventMap; - SkillLineAbilityMap mSkillLineAbilityMap; - SpellPetAuraMap mSpellPetAuraMap; - SpellCustomAttrMap mSpellCustomAttrMap; - SpellLinkedMap mSpellLinkedMap; -}; - -#define spellmgr SpellMgr::Instance() -#endif +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _SPELLMGR_H +#define _SPELLMGR_H + +// For static or at-server-startup loaded spell data +// For more high level function for sSpellStore data + +#include "SharedDefines.h" +#include "Database/DBCStructure.h" +#include "Database/SQLStorage.h" + +#include "Utilities/UnorderedMap.h" +#include + +class Player; +class Spell; + +extern SQLStorage sSpellThreatStore; + +enum SpellFailedReason +{ + SPELL_FAILED_AFFECTING_COMBAT = 0x00, + SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 0x01, + SPELL_FAILED_ALREADY_AT_FULL_MANA = 0x02, + SPELL_FAILED_ALREADY_AT_FULL_POWER = 0x03, + SPELL_FAILED_ALREADY_BEING_TAMED = 0x04, + SPELL_FAILED_ALREADY_HAVE_CHARM = 0x05, + SPELL_FAILED_ALREADY_HAVE_SUMMON = 0x06, + SPELL_FAILED_ALREADY_OPEN = 0x07, + SPELL_FAILED_AURA_BOUNCED = 0x08, + SPELL_FAILED_AUTOTRACK_INTERRUPTED = 0x09, + SPELL_FAILED_BAD_IMPLICIT_TARGETS = 0x0A, + SPELL_FAILED_BAD_TARGETS = 0x0B, + SPELL_FAILED_CANT_BE_CHARMED = 0x0C, + SPELL_FAILED_CANT_BE_DISENCHANTED = 0x0D, + SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL = 0x0E, + SPELL_FAILED_CANT_BE_PROSPECTED = 0x0F, + SPELL_FAILED_CANT_CAST_ON_TAPPED = 0x10, + SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE = 0x11, + SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED = 0x12, + SPELL_FAILED_CANT_STEALTH = 0x13, + SPELL_FAILED_CASTER_AURASTATE = 0x14, + SPELL_FAILED_CASTER_DEAD = 0x15, + SPELL_FAILED_CHARMED = 0x16, + SPELL_FAILED_CHEST_IN_USE = 0x17, + SPELL_FAILED_CONFUSED = 0x18, + SPELL_FAILED_DONT_REPORT = 0x19, + SPELL_FAILED_EQUIPPED_ITEM = 0x1A, + SPELL_FAILED_EQUIPPED_ITEM_CLASS = 0x1B, + SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND = 0x1C, + SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND = 0x1D, + SPELL_FAILED_ERROR = 0x1E, + SPELL_FAILED_FIZZLE = 0x1F, + SPELL_FAILED_FLEEING = 0x20, + SPELL_FAILED_FOOD_LOWLEVEL = 0x21, + SPELL_FAILED_HIGHLEVEL = 0x22, + SPELL_FAILED_HUNGER_SATIATED = 0x23, + SPELL_FAILED_IMMUNE = 0x24, + SPELL_FAILED_INTERRUPTED = 0x25, + SPELL_FAILED_INTERRUPTED_COMBAT = 0x26, + SPELL_FAILED_ITEM_ALREADY_ENCHANTED = 0x27, + SPELL_FAILED_ITEM_GONE = 0x28, + SPELL_FAILED_ITEM_NOT_FOUND = 0x29, + SPELL_FAILED_ITEM_NOT_READY = 0x2A, + SPELL_FAILED_LEVEL_REQUIREMENT = 0x2B, + SPELL_FAILED_LINE_OF_SIGHT = 0x2C, + SPELL_FAILED_LOWLEVEL = 0x2D, + SPELL_FAILED_LOW_CASTLEVEL = 0x2E, + SPELL_FAILED_MAINHAND_EMPTY = 0x2F, + SPELL_FAILED_MOVING = 0x30, + SPELL_FAILED_NEED_AMMO = 0x31, + SPELL_FAILED_NEED_AMMO_POUCH = 0x32, + SPELL_FAILED_NEED_EXOTIC_AMMO = 0x33, + SPELL_FAILED_NOPATH = 0x34, + SPELL_FAILED_NOT_BEHIND = 0x35, + SPELL_FAILED_NOT_FISHABLE = 0x36, + SPELL_FAILED_NOT_FLYING = 0x37, + SPELL_FAILED_NOT_HERE = 0x38, + SPELL_FAILED_NOT_INFRONT = 0x39, + SPELL_FAILED_NOT_IN_CONTROL = 0x3A, + SPELL_FAILED_NOT_KNOWN = 0x3B, + SPELL_FAILED_NOT_MOUNTED = 0x3C, + SPELL_FAILED_NOT_ON_TAXI = 0x3D, + SPELL_FAILED_NOT_ON_TRANSPORT = 0x3E, + SPELL_FAILED_NOT_READY = 0x3F, + SPELL_FAILED_NOT_SHAPESHIFT = 0x40, + SPELL_FAILED_NOT_STANDING = 0x41, + SPELL_FAILED_NOT_TRADEABLE = 0x42, + SPELL_FAILED_NOT_TRADING = 0x43, + SPELL_FAILED_NOT_UNSHEATHED = 0x44, + SPELL_FAILED_NOT_WHILE_GHOST = 0x45, + SPELL_FAILED_NO_AMMO = 0x46, + SPELL_FAILED_NO_CHARGES_REMAIN = 0x47, + SPELL_FAILED_NO_CHAMPION = 0x48, + SPELL_FAILED_NO_COMBO_POINTS = 0x49, + SPELL_FAILED_NO_DUELING = 0x4A, + SPELL_FAILED_NO_ENDURANCE = 0x4B, + SPELL_FAILED_NO_FISH = 0x4C, + SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED = 0x4D, + SPELL_FAILED_NO_MOUNTS_ALLOWED = 0x4E, + SPELL_FAILED_NO_PET = 0x4F, + SPELL_FAILED_NO_POWER = 0x50, + SPELL_FAILED_NOTHING_TO_DISPEL = 0x51, + SPELL_FAILED_NOTHING_TO_STEAL = 0x52, + SPELL_FAILED_ONLY_ABOVEWATER = 0x53, + SPELL_FAILED_ONLY_DAYTIME = 0x54, + SPELL_FAILED_ONLY_INDOORS = 0x55, + SPELL_FAILED_ONLY_MOUNTED = 0x56, + SPELL_FAILED_ONLY_NIGHTTIME = 0x57, + SPELL_FAILED_ONLY_OUTDOORS = 0x58, + SPELL_FAILED_ONLY_SHAPESHIFT = 0x59, + SPELL_FAILED_ONLY_STEALTHED = 0x5A, + SPELL_FAILED_ONLY_UNDERWATER = 0x5B, + SPELL_FAILED_OUT_OF_RANGE = 0x5C, + SPELL_FAILED_PACIFIED = 0x5D, + SPELL_FAILED_POSSESSED = 0x5E, + SPELL_FAILED_REAGENTS = 0x5F, + SPELL_FAILED_REQUIRES_AREA = 0x60, + SPELL_FAILED_REQUIRES_SPELL_FOCUS = 0x61, + SPELL_FAILED_ROOTED = 0x62, + SPELL_FAILED_SILENCED = 0x63, + SPELL_FAILED_SPELL_IN_PROGRESS = 0x64, + SPELL_FAILED_SPELL_LEARNED = 0x65, + SPELL_FAILED_SPELL_UNAVAILABLE = 0x66, + SPELL_FAILED_STUNNED = 0x67, + SPELL_FAILED_TARGETS_DEAD = 0x68, + SPELL_FAILED_TARGET_AFFECTING_COMBAT = 0x69, + SPELL_FAILED_TARGET_AURASTATE = 0x6A, + SPELL_FAILED_TARGET_DUELING = 0x6B, + SPELL_FAILED_TARGET_ENEMY = 0x6C, + SPELL_FAILED_TARGET_ENRAGED = 0x6D, + SPELL_FAILED_TARGET_FRIENDLY = 0x6E, + SPELL_FAILED_TARGET_IN_COMBAT = 0x6F, + SPELL_FAILED_TARGET_IS_PLAYER = 0x70, + SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED = 0x71, + SPELL_FAILED_TARGET_NOT_DEAD = 0x72, + SPELL_FAILED_TARGET_NOT_IN_PARTY = 0x73, + SPELL_FAILED_TARGET_NOT_LOOTED = 0x74, + SPELL_FAILED_TARGET_NOT_PLAYER = 0x75, + SPELL_FAILED_TARGET_NO_POCKETS = 0x76, + SPELL_FAILED_TARGET_NO_WEAPONS = 0x77, + SPELL_FAILED_TARGET_UNSKINNABLE = 0x78, + SPELL_FAILED_THIRST_SATIATED = 0x79, + SPELL_FAILED_TOO_CLOSE = 0x7A, + SPELL_FAILED_TOO_MANY_OF_ITEM = 0x7B, + SPELL_FAILED_TOTEM_CATEGORY = 0x7C, + SPELL_FAILED_TOTEMS = 0x7D, + SPELL_FAILED_TRAINING_POINTS = 0x7E, + SPELL_FAILED_TRY_AGAIN = 0x7F, + SPELL_FAILED_UNIT_NOT_BEHIND = 0x80, + SPELL_FAILED_UNIT_NOT_INFRONT = 0x81, + SPELL_FAILED_WRONG_PET_FOOD = 0x82, + SPELL_FAILED_NOT_WHILE_FATIGUED = 0x83, + SPELL_FAILED_TARGET_NOT_IN_INSTANCE = 0x84, + SPELL_FAILED_NOT_WHILE_TRADING = 0x85, + SPELL_FAILED_TARGET_NOT_IN_RAID = 0x86, + SPELL_FAILED_DISENCHANT_WHILE_LOOTING = 0x87, + SPELL_FAILED_PROSPECT_WHILE_LOOTING = 0x88, + SPELL_FAILED_PROSPECT_NEED_MORE = 0x89, + SPELL_FAILED_TARGET_FREEFORALL = 0x8A, + SPELL_FAILED_NO_EDIBLE_CORPSES = 0x8B, + SPELL_FAILED_ONLY_BATTLEGROUNDS = 0x8C, + SPELL_FAILED_TARGET_NOT_GHOST = 0x8D, + SPELL_FAILED_TOO_MANY_SKILLS = 0x8E, + SPELL_FAILED_TRANSFORM_UNUSABLE = 0x8F, + SPELL_FAILED_WRONG_WEATHER = 0x90, + SPELL_FAILED_DAMAGE_IMMUNE = 0x91, + SPELL_FAILED_PREVENTED_BY_MECHANIC = 0x92, + SPELL_FAILED_PLAY_TIME = 0x93, + SPELL_FAILED_REPUTATION = 0x94, + SPELL_FAILED_MIN_SKILL = 0x95, + SPELL_FAILED_NOT_IN_ARENA = 0x96, + SPELL_FAILED_NOT_ON_SHAPESHIFT = 0x97, + SPELL_FAILED_NOT_ON_STEALTHED = 0x98, + SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE = 0x99, + SPELL_FAILED_NOT_ON_MOUNTED = 0x9A, + SPELL_FAILED_TOO_SHALLOW = 0x9B, + SPELL_FAILED_TARGET_NOT_IN_SANCTUARY = 0x9C, + SPELL_FAILED_TARGET_IS_TRIVIAL = 0x9D, + SPELL_FAILED_BM_OR_INVISGOD = 0x9E, + SPELL_FAILED_EXPERT_RIDING_REQUIREMENT = 0x9F, + SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT = 0xA0, + SPELL_FAILED_NOT_IDLE = 0xA1, + SPELL_FAILED_NOT_INACTIVE = 0xA2, + SPELL_FAILED_PARTIAL_PLAYTIME = 0xA3, + SPELL_FAILED_NO_PLAYTIME = 0xA4, + SPELL_FAILED_NOT_IN_BATTLEGROUND = 0xA5, + SPELL_FAILED_ONLY_IN_ARENA = 0xA6, + SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 0xA7, + SPELL_FAILED_UNKNOWN = 0xA8, +}; + +enum SpellFamilyNames +{ + SPELLFAMILY_GENERIC = 0, + SPELLFAMILY_UNK1 = 1, // events, holidays + // 2 - unused + SPELLFAMILY_MAGE = 3, + SPELLFAMILY_WARRIOR = 4, + SPELLFAMILY_WARLOCK = 5, + SPELLFAMILY_PRIEST = 6, + SPELLFAMILY_DRUID = 7, + SPELLFAMILY_ROGUE = 8, + SPELLFAMILY_HUNTER = 9, + SPELLFAMILY_PALADIN = 10, + SPELLFAMILY_SHAMAN = 11, + SPELLFAMILY_UNK2 = 12, + SPELLFAMILY_POTION = 13 +}; + +enum SpellDisableTypes +{ + SPELL_DISABLE_PLAYER = 1, + SPELL_DISABLE_CREATURE = 2 +}; + +//Some SpellFamilyFlags +#define SPELLFAMILYFLAG_ROGUE_VANISH 0x000000800LL +#define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL +#define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL +#define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL +#define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL +#define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL +#define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL + +// Spell clasification +enum SpellSpecific +{ + SPELL_NORMAL = 0, + SPELL_SEAL = 1, + SPELL_BLESSING = 2, + SPELL_AURA = 3, + SPELL_STING = 4, + SPELL_CURSE = 5, + SPELL_ASPECT = 6, + SPELL_TRACKER = 7, + SPELL_WARLOCK_ARMOR = 8, + SPELL_MAGE_ARMOR = 9, + SPELL_ELEMENTAL_SHIELD = 10, + SPELL_MAGE_POLYMORPH = 11, + SPELL_POSITIVE_SHOUT = 12, + SPELL_JUDGEMENT = 13, + SPELL_BATTLE_ELIXIR = 14, + SPELL_GUARDIAN_ELIXIR = 15, + SPELL_FLASK_ELIXIR = 16, + SPELL_WARLOCK_CORRUPTION= 17 +}; + +SpellSpecific GetSpellSpecific(uint32 spellId); + +// Different spell properties +inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); } +uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL); +inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); } +inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); } +inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; } +int32 GetSpellDuration(SpellEntry const *spellInfo); +int32 GetSpellMaxDuration(SpellEntry const *spellInfo); + +inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect) +{ + for(int i= 0; i < 3; ++i) + if(spellInfo->Effect[i]==effect) + return true; + return false; +} + +//bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); + +inline bool IsSealSpell(SpellEntry const *spellInfo) +{ + //Collection of all the seal family flags. No other paladin spell has any of those. + return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && + ( spellInfo->SpellFamilyFlags & 0x4000A000200LL ); +} + +inline bool IsElementalShield(SpellEntry const *spellInfo) +{ + // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus + return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552; +} + +int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); +bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2); +bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1,uint32 spellSpec2); +bool IsPassiveSpell(uint32 spellId); + +inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo) +{ + switch(spellInfo->Id) + { + case 40214: // Dragonmaw Illusion + case 35480: case 35481: case 35482: // Human Illusion + case 35483: case 39824: // Human Illusion + return true; + } + + return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT; +} + +inline bool IsNonCombatSpell(SpellEntry const *spellInfo) +{ + return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0; +} + +bool IsPositiveSpell(uint32 spellId); +bool IsPositiveEffect(uint32 spellId, uint32 effIndex); +bool IsPositiveTarget(uint32 targetA, uint32 targetB); + +bool IsSingleTargetSpell(SpellEntry const *spellInfo); +bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2); + +bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id); + +inline bool IsAreaEffectTarget( Targets target ) +{ + switch (target ) + { + case TARGET_AREAEFFECT_CUSTOM: + case TARGET_ALL_ENEMY_IN_AREA: + case TARGET_ALL_ENEMY_IN_AREA_INSTANT: + case TARGET_ALL_PARTY_AROUND_CASTER: + case TARGET_ALL_AROUND_CASTER: + case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: + case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER: + case TARGET_ALL_PARTY: + case TARGET_ALL_PARTY_AROUND_CASTER_2: + case TARGET_AREAEFFECT_PARTY: + case TARGET_AREAEFFECT_CUSTOM_2: + case TARGET_AREAEFFECT_PARTY_AND_CLASS: + case TARGET_IN_FRONT_OF_CASTER: + case TARGET_ALL_FRIENDLY_UNITS_IN_AREA: + return true; + default: + break; + } + return false; +} + +inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo) +{ + if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0]))) + return true; + if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1]))) + return true; + if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2]))) + return true; + return false; +} + +inline bool IsAreaAuraEffect(uint32 effect) +{ + if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY || + effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND || + effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY || + effect == SPELL_EFFECT_APPLY_AREA_AURA_PET || + effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER) + return true; + return false; +} + +inline bool IsDispelSpell(SpellEntry const *spellInfo) +{ + if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL || + spellInfo->Effect[1] == SPELL_EFFECT_DISPEL || + spellInfo->Effect[2] == SPELL_EFFECT_DISPEL ) + return true; + return false; +} +inline bool isSpellBreakStealth(SpellEntry const* spellInfo) +{ + return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH); +} + +uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form); + +inline bool IsChanneledSpell(SpellEntry const* spellInfo) +{ + return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2)); +} + +inline bool NeedsComboPoints(SpellEntry const* spellInfo) +{ + return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2)); +} + +inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo) +{ + return SpellSchoolMask(spellInfo->SchoolMask); +} + +inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect) +{ + uint32 mask = 0; + if (spellInfo->Mechanic) + mask |= 1<Mechanic; + if (spellInfo->EffectMechanic[effect]) + mask |= 1<EffectMechanic[effect]; + return mask; +} + +inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect) +{ + if (spellInfo->EffectMechanic[effect]) + return Mechanics(spellInfo->EffectMechanic[effect]); + if (spellInfo->Mechanic) + return Mechanics(spellInfo->Mechanic); + return MECHANIC_NONE; +} + +inline uint32 GetDispellMask(DispelType dispel) +{ + // If dispel all + if (dispel == DISPEL_ALL) + return DISPEL_ALL_MASK; + else + return (1 << dispel); +} + +// Diminishing Returns interaction with spells +DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered); +bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group); +DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group); + +// Spell affects related declarations (accessed using SpellMgr functions) +typedef std::map SpellAffectMap; + +// Spell proc event related declarations (accessed using SpellMgr functions) +enum ProcFlags +{ + PROC_FLAG_NONE = 0x00000000, // None + PROC_FLAG_HIT_MELEE = 0x00000001, // On melee hit + PROC_FLAG_STRUCK_MELEE = 0x00000002, // On being struck melee + PROC_FLAG_KILL_XP_GIVER = 0x00000004, // On kill target giving XP or honor + PROC_FLAG_SPECIAL_DROP = 0x00000008, // + PROC_FLAG_DODGE = 0x00000010, // On dodge melee attack + PROC_FLAG_PARRY = 0x00000020, // On parry melee attack + PROC_FLAG_BLOCK = 0x00000040, // On block attack + PROC_FLAG_TOUCH = 0x00000080, // On being touched (for bombs, probably?) + PROC_FLAG_TARGET_LOW_HEALTH = 0x00000100, // On deal damage to enemy with 20% or less health + PROC_FLAG_LOW_HEALTH = 0x00000200, // On health dropped below 20% + PROC_FLAG_STRUCK_RANGED = 0x00000400, // On being struck ranged + PROC_FLAG_HIT_SPECIAL = 0x00000800, // (!)Removed, may be reassigned in future + PROC_FLAG_CRIT_MELEE = 0x00001000, // On crit melee + PROC_FLAG_STRUCK_CRIT_MELEE = 0x00002000, // On being critically struck in melee + PROC_FLAG_CAST_SPELL = 0x00004000, // On cast spell + PROC_FLAG_TAKE_DAMAGE = 0x00008000, // On take damage + PROC_FLAG_CRIT_SPELL = 0x00010000, // On crit spell + PROC_FLAG_HIT_SPELL = 0x00020000, // On hit spell + PROC_FLAG_STRUCK_CRIT_SPELL = 0x00040000, // On being critically struck by a spell + PROC_FLAG_HIT_RANGED = 0x00080000, // On getting ranged hit + PROC_FLAG_STRUCK_SPELL = 0x00100000, // On being struck by a spell + PROC_FLAG_TRAP = 0x00200000, // On trap activation (?) + PROC_FLAG_CRIT_RANGED = 0x00400000, // On getting ranged crit + PROC_FLAG_STRUCK_CRIT_RANGED = 0x00800000, // On being critically struck by a ranged attack + PROC_FLAG_RESIST_SPELL = 0x01000000, // On resist enemy spell + PROC_FLAG_TARGET_RESISTS = 0x02000000, // On enemy resisted spell + PROC_FLAG_TARGET_DODGE_OR_PARRY = 0x04000000, // On enemy dodges/parries + PROC_FLAG_HEAL = 0x08000000, // On heal + PROC_FLAG_CRIT_HEAL = 0x10000000, // On critical healing effect + PROC_FLAG_HEALED = 0x20000000, // On healing + PROC_FLAG_TARGET_BLOCK = 0x40000000, // On enemy blocks + PROC_FLAG_MISS = 0x80000000 // On miss melee attack +}; + +struct SpellProcEventEntry +{ + uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2 + uint32 category; // if nonzero - match proc condition based on candidate spell's category + uint32 skillId; // if nonzero - for matching proc condition based on candidate spell's skillId from SkillLineAbility.dbc (Shadow Bolt = Destruction) + uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value + uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do) + uint32 procFlags; // bitmask for matching proc event + float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc + uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_ +}; + +typedef UNORDERED_MAP SpellProcEventMap; + +#define ELIXIR_BATTLE_MASK 0x1 +#define ELIXIR_GUARDIAN_MASK 0x2 +#define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK) +#define ELIXIR_UNSTABLE_MASK 0x4 +#define ELIXIR_SHATTRATH_MASK 0x8 + +typedef std::map SpellElixirMap; + +// Spell script target related declarations (accessed using SpellMgr functions) +enum SpellTargetType +{ + SPELL_TARGET_TYPE_GAMEOBJECT = 0, + SPELL_TARGET_TYPE_CREATURE = 1, + SPELL_TARGET_TYPE_DEAD = 2 +}; + +#define MAX_SPELL_TARGET_TYPE 3 + +struct SpellTargetEntry +{ + SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {} + SpellTargetType type; + uint32 targetEntry; +}; + +typedef std::multimap SpellScriptTarget; + +// coordinates for spells (accessed using SpellMgr functions) +struct SpellTargetPosition +{ + uint32 target_mapId; + float target_X; + float target_Y; + float target_Z; + float target_Orientation; +}; + +typedef UNORDERED_MAP SpellTargetPositionMap; + +// Spell pet auras +class PetAura +{ + public: + PetAura() + { + auras.clear(); + } + + PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) : + removeOnChangePet(_removeOnChangePet), damage(_damage) + { + auras[petEntry] = aura; + } + + uint16 GetAura(uint16 petEntry) const + { + std::map::const_iterator itr = auras.find(petEntry); + if(itr != auras.end()) + return itr->second; + else + { + std::map::const_iterator itr = auras.find(0); + if(itr != auras.end()) + return itr->second; + else + return 0; + } + } + + void AddAura(uint16 petEntry, uint16 aura) + { + auras[petEntry] = aura; + } + + bool IsRemovedOnChangePet() const + { + return removeOnChangePet; + } + + int32 GetDamage() const + { + return damage; + } + + private: + std::map auras; + bool removeOnChangePet; + int32 damage; +}; +typedef std::map SpellPetAuraMap; + +// Spell rank chain (accessed using SpellMgr functions) +struct SpellChainNode +{ + uint32 prev; + uint32 first; + uint32 req; + uint8 rank; +}; + +typedef UNORDERED_MAP SpellChainMap; +typedef std::multimap SpellChainMapNext; + +// Spell learning properties (accessed using SpellMgr functions) +struct SpellLearnSkillNode +{ + uint32 skill; + uint32 value; // 0 - max skill value for player level + uint32 maxvalue; // 0 - max skill value for player level +}; + +typedef std::map SpellLearnSkillMap; + +struct SpellLearnSpellNode +{ + uint32 spell; + bool autoLearned; +}; + +typedef std::multimap SpellLearnSpellMap; + +typedef std::multimap SkillLineAbilityMap; + +inline bool IsPrimaryProfessionSkill(uint32 skill) +{ + SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill); + if(!pSkill) + return false; + + if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION) + return false; + + return true; +} + +inline bool IsProfessionSkill(uint32 skill) +{ + return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID; +} + +#define SPELL_ATTR_CU_PLAYERS_ONLY 0x00000001 +#define SPELL_ATTR_CU_CONE_BACK 0x00000002 +#define SPELL_ATTR_CU_CONE_LINE 0x00000004 +#define SPELL_ATTR_CU_SHARE_DAMAGE 0x00000008 +#define SPELL_ATTR_CU_EFFECT_HEAL 0x00000010 +#define SPELL_ATTR_CU_EFFECT_DAMAGE 0x00000020 + +typedef std::map SpellCustomAttrMap; + +typedef std::map > SpellLinkedMap; + +class SpellMgr +{ + // Constructors + public: + SpellMgr(); + ~SpellMgr(); + + // Accessors (const or static functions) + public: + // Spell affects + uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const + { + SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId); + if( itr != mSpellAffectMap.end( ) ) + return itr->second; + return 0; + } + + bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const; + + SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; } + + uint32 GetSpellElixirMask(uint32 spellid) const + { + SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid); + if(itr==mSpellElixirs.end()) + return 0x0; + + return itr->second; + } + + SpellSpecific GetSpellElixirSpecific(uint32 spellid) const + { + uint32 mask = GetSpellElixirMask(spellid); + if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK) + return SPELL_FLASK_ELIXIR; + else if(mask & ELIXIR_BATTLE_MASK) + return SPELL_BATTLE_ELIXIR; + else if(mask & ELIXIR_GUARDIAN_MASK) + return SPELL_GUARDIAN_ELIXIR; + else + return SPELL_NORMAL; + } + + // Spell proc events + SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const + { + SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId); + if( itr != mSpellProcEventMap.end( ) ) + return &itr->second; + return NULL; + } + + static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ); + + // Spell target coordinates + SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const + { + SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id ); + if( itr != mSpellTargetPositions.end( ) ) + return &itr->second; + return NULL; + } + + // Spell ranks chains + SpellChainNode const* GetSpellChainNode(uint32 spell_id) const + { + SpellChainMap::const_iterator itr = mSpellChains.find(spell_id); + if(itr == mSpellChains.end()) + return NULL; + + return &itr->second; + } + + uint32 GetFirstSpellInChain(uint32 spell_id) const + { + if(SpellChainNode const* node = GetSpellChainNode(spell_id)) + return node->first; + + return spell_id; + } + + uint32 GetPrevSpellInChain(uint32 spell_id) const + { + if(SpellChainNode const* node = GetSpellChainNode(spell_id)) + return node->prev; + + return 0; + } + + SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; } + + // Note: not use rank for compare to spell ranks: spell chains isn't linear order + // Use IsHighRankOfSpell instead + uint8 GetSpellRank(uint32 spell_id) const + { + if(SpellChainNode const* node = GetSpellChainNode(spell_id)) + return node->rank; + + return 0; + } + + uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const + { + SpellChainMap::const_iterator itr = mSpellChains.find(spell1); + + uint32 rank2 = GetSpellRank(spell2); + + // not ordered correctly by rank value + if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2) + return false; + + // check present in same rank chain + for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev)) + if(itr->second.prev==spell2) + return true; + + return false; + } + + bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const; + static bool canStackSpellRanks(SpellEntry const *spellInfo); + bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool isFromTheSameCaster ) const; + + SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const; + + // Spell learning + SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const + { + SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id); + if(itr != mSpellLearnSkills.end()) + return &itr->second; + else + return NULL; + } + + bool IsSpellLearnSpell(uint32 spell_id) const + { + return mSpellLearnSpells.count(spell_id)!=0; + } + + SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const + { + return mSpellLearnSpells.lower_bound(spell_id); + } + + SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const + { + return mSpellLearnSpells.upper_bound(spell_id); + } + + bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const + { + SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1); + SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1); + for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i) + if(i->second.spell==spell_id2) + return true; + return false; + } + + static bool IsProfessionSpell(uint32 spellId); + static bool IsPrimaryProfessionSpell(uint32 spellId); + bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const; + + // Spell script targets + SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const + { + return mSpellScriptTarget.lower_bound(spell_id); + } + + SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const + { + return mSpellScriptTarget.upper_bound(spell_id); + } + + // Spell correctess for client using + static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true); + + SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const + { + return mSkillLineAbilityMap.lower_bound(spell_id); + } + + SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const + { + return mSkillLineAbilityMap.upper_bound(spell_id); + } + + PetAura const* GetPetAura(uint16 spell_id) + { + SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id); + if(itr != mSpellPetAuraMap.end()) + return &itr->second; + else + return NULL; + } + + uint32 GetSpellCustomAttr(uint32 spell_id) const + { + SpellCustomAttrMap::const_iterator itr = mSpellCustomAttrMap.find(spell_id); + if(itr != mSpellCustomAttrMap.end()) + return itr->second; + else + return 0; + } + + const std::vector *GetSpellLinked(int32 spell_id) const + { + SpellLinkedMap::const_iterator itr = mSpellLinkedMap.find(spell_id); + return itr != mSpellLinkedMap.end() ? &(itr->second) : NULL; + } + + // Modifiers + public: + static SpellMgr& Instance(); + + // Loading data at server startup + void LoadSpellChains(); + void LoadSpellLearnSkills(); + void LoadSpellLearnSpells(); + void LoadSpellScriptTarget(); + void LoadSpellAffects(); + void LoadSpellElixirs(); + void LoadSpellProcEvents(); + void LoadSpellTargetPositions(); + void LoadSpellThreats(); + void LoadSkillLineAbilityMap(); + void LoadSpellPetAuras(); + void LoadSpellCustomAttr(); + void LoadSpellLinked(); + + private: + SpellScriptTarget mSpellScriptTarget; + SpellChainMap mSpellChains; + SpellChainMapNext mSpellChainsNext; + SpellLearnSkillMap mSpellLearnSkills; + SpellLearnSpellMap mSpellLearnSpells; + SpellTargetPositionMap mSpellTargetPositions; + SpellAffectMap mSpellAffectMap; + SpellElixirMap mSpellElixirs; + SpellProcEventMap mSpellProcEventMap; + SkillLineAbilityMap mSkillLineAbilityMap; + SpellPetAuraMap mSpellPetAuraMap; + SpellCustomAttrMap mSpellCustomAttrMap; + SpellLinkedMap mSpellLinkedMap; +}; + +#define spellmgr SpellMgr::Instance() +#endif diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index a6dae99b7ef..22249af36d6 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -1,10845 +1,10812 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "Common.h" -#include "Log.h" -#include "Opcodes.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#include "World.h" -#include "ObjectMgr.h" -#include "SpellMgr.h" -#include "Unit.h" -#include "QuestDef.h" -#include "Player.h" -#include "Creature.h" -#include "Spell.h" -#include "Group.h" -#include "SpellAuras.h" -#include "MapManager.h" -#include "ObjectAccessor.h" -#include "CreatureAI.h" -#include "Formulas.h" -#include "Pet.h" -#include "Util.h" -#include "Totem.h" -#include "BattleGround.h" -#include "OutdoorPvP.h" -#include "InstanceSaveMgr.h" -#include "GridNotifiersImpl.h" -#include "CellImpl.h" -#include "Path.h" - -#include - -float baseMoveSpeed[MAX_MOVE_TYPE] = -{ - 2.5f, // MOVE_WALK - 7.0f, // MOVE_RUN - 1.25f, // MOVE_WALKBACK - 4.722222f, // MOVE_SWIM - 4.5f, // MOVE_SWIMBACK - 3.141594f, // MOVE_TURN - 7.0f, // MOVE_FLY - 4.5f, // MOVE_FLYBACK -}; - -// auraTypes contains attacker auras capable of proc'ing cast auras -static Unit::AuraTypeSet GenerateAttakerProcCastAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_DUMMY); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); - auraTypes.insert(SPELL_AURA_MOD_HASTE); - auraTypes.insert(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - return auraTypes; -} - -// auraTypes contains victim auras capable of proc'ing cast auras -static Unit::AuraTypeSet GenerateVictimProcCastAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_DUMMY); - auraTypes.insert(SPELL_AURA_PRAYER_OF_MENDING); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); - return auraTypes; -} - -// auraTypes contains auras capable of proc effect/damage (but not cast) for attacker -static Unit::AuraTypeSet GenerateAttakerProcEffectAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_MOD_DAMAGE_DONE); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); - auraTypes.insert(SPELL_AURA_MOD_CASTING_SPEED); - auraTypes.insert(SPELL_AURA_MOD_RATING); - return auraTypes; -} - -// auraTypes contains auras capable of proc effect/damage (but not cast) for victim -static Unit::AuraTypeSet GenerateVictimProcEffectAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_MOD_RESISTANCE); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); - auraTypes.insert(SPELL_AURA_MOD_PARRY_PERCENT); - auraTypes.insert(SPELL_AURA_MOD_BLOCK_PERCENT); - auraTypes.insert(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); - return auraTypes; -} - -static Unit::AuraTypeSet attackerProcCastAuraTypes = GenerateAttakerProcCastAuraTypes(); -static Unit::AuraTypeSet attackerProcEffectAuraTypes = GenerateAttakerProcEffectAuraTypes(); - -static Unit::AuraTypeSet victimProcCastAuraTypes = GenerateVictimProcCastAuraTypes(); -static Unit::AuraTypeSet victimProcEffectAuraTypes = GenerateVictimProcEffectAuraTypes(); - -// auraTypes contains auras capable of proc'ing for attacker and victim -static Unit::AuraTypeSet GenerateProcAuraTypes() -{ - Unit::AuraTypeSet auraTypes; - auraTypes.insert(attackerProcCastAuraTypes.begin(),attackerProcCastAuraTypes.end()); - auraTypes.insert(attackerProcEffectAuraTypes.begin(),attackerProcEffectAuraTypes.end()); - auraTypes.insert(victimProcCastAuraTypes.begin(),victimProcCastAuraTypes.end()); - auraTypes.insert(victimProcEffectAuraTypes.begin(),victimProcEffectAuraTypes.end()); - return auraTypes; -} - -static Unit::AuraTypeSet procAuraTypes = GenerateProcAuraTypes(); - -bool IsPassiveStackableSpell( uint32 spellId ) -{ - if(!IsPassiveSpell(spellId)) - return false; - - SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); - if(!spellProto) - return false; - - for(int j = 0; j < 3; ++j) - { - if(std::find(procAuraTypes.begin(),procAuraTypes.end(),spellProto->EffectApplyAuraName[j])!=procAuraTypes.end()) - return false; - } - - return true; -} - -Unit::Unit() -: WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) -{ - m_objectType |= TYPEMASK_UNIT; - m_objectTypeId = TYPEID_UNIT; - // 2.3.2 - 0x70 - m_updateFlag = (UPDATEFLAG_HIGHGUID | UPDATEFLAG_LIVING | UPDATEFLAG_HASPOSITION); - - m_attackTimer[BASE_ATTACK] = 0; - m_attackTimer[OFF_ATTACK] = 0; - m_attackTimer[RANGED_ATTACK] = 0; - m_modAttackSpeedPct[BASE_ATTACK] = 1.0f; - m_modAttackSpeedPct[OFF_ATTACK] = 1.0f; - m_modAttackSpeedPct[RANGED_ATTACK] = 1.0f; - - m_extraAttacks = 0; - m_canDualWield = false; - - m_state = 0; - m_form = FORM_NONE; - m_deathState = ALIVE; - - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - m_currentSpells[i] = NULL; - - m_addDmgOnce = 0; - - for(int i = 0; i < MAX_TOTEM; ++i) - m_TotemSlot[i] = 0; - - m_ObjectSlot[0] = m_ObjectSlot[1] = m_ObjectSlot[2] = m_ObjectSlot[3] = 0; - //m_Aura = NULL; - //m_AurasCheck = 2000; - //m_removeAuraTimer = 4; - //tmpAura = NULL; - waterbreath = false; - - m_Visibility = VISIBILITY_ON; - - m_interruptMask = 0; - m_detectInvisibilityMask = 0; - m_invisibilityMask = 0; - m_transform = 0; - m_ShapeShiftFormSpellId = 0; - m_canModifyStats = false; - - for (int i = 0; i < MAX_SPELL_IMMUNITY; i++) - m_spellImmune[i].clear(); - for (int i = 0; i < UNIT_MOD_END; i++) - { - m_auraModifiersGroup[i][BASE_VALUE] = 0.0f; - m_auraModifiersGroup[i][BASE_PCT] = 1.0f; - m_auraModifiersGroup[i][TOTAL_VALUE] = 0.0f; - m_auraModifiersGroup[i][TOTAL_PCT] = 1.0f; - } - // implement 50% base damage from offhand - m_auraModifiersGroup[UNIT_MOD_DAMAGE_OFFHAND][TOTAL_PCT] = 0.5f; - - for (int i = 0; i < 3; i++) - { - m_weaponDamage[i][MINDAMAGE] = BASE_MINDAMAGE; - m_weaponDamage[i][MAXDAMAGE] = BASE_MAXDAMAGE; - } - for (int i = 0; i < MAX_STATS; i++) - m_createStats[i] = 0.0f; - - m_attacking = NULL; - m_modMeleeHitChance = 0.0f; - m_modRangedHitChance = 0.0f; - m_modSpellHitChance = 0.0f; - m_baseSpellCritChance = 5; - - m_CombatTimer = 0; - m_lastManaUse = 0; - - //m_victimThreat = 0.0f; - for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) - m_threatModifier[i] = 1.0f; - m_isSorted = true; - for (int i = 0; i < MAX_MOVE_TYPE; ++i) - m_speed_rate[i] = 1.0f; - - m_removedAuras = 0; - m_charmInfo = NULL; - m_unit_movement_flags = 0; - m_isPossessed = false; - - // remove aurastates allowing special moves - for(int i=0; i < MAX_REACTIVE; ++i) - m_reactiveTimer[i] = 0; -} - -Unit::~Unit() -{ - // set current spells as deletable - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - { - if (m_currentSpells[i]) - { - m_currentSpells[i]->SetReferencedFromCurrent(false); - m_currentSpells[i] = NULL; - } - } - - RemoveAllGameObjects(); - RemoveAllDynObjects(); - - if(m_charmInfo) delete m_charmInfo; -} - -void Unit::Update( uint32 p_time ) -{ - /*if(p_time > m_AurasCheck) - { - m_AurasCheck = 2000; - _UpdateAura(); - }else - m_AurasCheck -= p_time;*/ - - // WARNING! Order of execution here is important, do not change. - // Spells must be processed with event system BEFORE they go to _UpdateSpells. - // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad. - m_Events.Update( p_time ); - _UpdateSpells( p_time ); - - // update combat timer only for players and pets - if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet() || ((Creature*)this)->isCharmed())) - { - // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away - // targets without stopping half way there and running off. - // These flags are reset after target dies or another command is given. - if( m_HostilRefManager.isEmpty() ) - { - // m_CombatTimer set at aura start and it will be freeze until aura removing - if ( m_CombatTimer <= p_time ) - ClearInCombat(); - else - m_CombatTimer -= p_time; - } - } - - if(!hasUnitState(UNIT_STAT_CASTING)) - { - if(uint32 base_att = getAttackTimer(BASE_ATTACK)) - setAttackTimer(BASE_ATTACK, (p_time >= base_att ? 0 : base_att - p_time) ); - if(uint32 ranged_att = getAttackTimer(RANGED_ATTACK)) - setAttackTimer(RANGED_ATTACK, (p_time >= ranged_att ? 0 : ranged_att - p_time) ); - if(uint32 off_att = getAttackTimer(OFF_ATTACK)) - setAttackTimer(OFF_ATTACK, (p_time >= off_att ? 0 : off_att - p_time) ); - } - - // update abilities available only for fraction of time - UpdateReactives( p_time ); - - ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, GetHealth() < GetMaxHealth()*0.20f); - ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, GetHealth() < GetMaxHealth()*0.35f); - - i_motionMaster.UpdateMotion(p_time); -} - -bool Unit::haveOffhandWeapon() const -{ - if(GetTypeId() == TYPEID_PLAYER) - return ((Player*)this)->GetWeaponForAttack(OFF_ATTACK,true); - else - return m_canDualWield; -} - -void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player* player) -{ - float x, y, z; - if(GetMotionMaster()->GetDestination(x, y, z)) - SendMonsterMoveWithSpeed(x, y, z, GetUnitMovementFlags(), 0, player); -} - -void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime, Player* player) -{ - if (!transitTime) - { - float dx = x - GetPositionX(); - float dy = y - GetPositionY(); - float dz = z - GetPositionZ(); - - float dist = ((dx*dx) + (dy*dy) + (dz*dz)); - if(dist<0) - dist = 0; - else - dist = sqrt(dist); - - double speed = GetSpeed((MovementFlags & MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); - if(speed<=0) - speed = 2.5f; - speed *= 0.001f; - transitTime = static_cast(dist / speed + 0.5); - } - //float orientation = (float)atan2((double)dy, (double)dx); - SendMonsterMove(x, y, z, 0, MovementFlags, transitTime, player); -} - -void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player) -{ - WorldPacket data( SMSG_MONSTER_MOVE, (41 + GetPackGUID().size()) ); - data.append(GetPackGUID()); - - // Point A, starting location - data << GetPositionX() << GetPositionY() << GetPositionZ(); - // unknown field - unrelated to orientation - // seems to increment about 1000 for every 1.7 seconds - // for now, we'll just use mstime - data << getMSTime(); - - data << uint8(type); // unknown - switch(type) - { - case 0: // normal packet - break; - case 1: // stop packet - SendMessageToSet( &data, true ); - return; - case 3: // not used currently - data << uint64(0); // probably target guid - break; - case 4: // not used currently - data << float(0); // probably orientation - break; - } - - //Movement Flags (0x0 = walk, 0x100 = run, 0x200 = fly/swim) - data << uint32(MovementFlags); - - data << Time; // Time in between points - data << uint32(1); // 1 single waypoint - data << NewPosX << NewPosY << NewPosZ; // the single waypoint Point B - - if(player) - player->GetSession()->SendPacket(&data); - else - SendMessageToSet( &data, true ); -} - -void Unit::SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, uint32 MovementFlags) -{ - uint32 traveltime = uint32(path.GetTotalLength(start, end) * 32); - - uint32 pathSize = end-start; - - WorldPacket data( SMSG_MONSTER_MOVE, (GetPackGUID().size()+4+4+4+4+1+4+4+4+pathSize*4*3) ); - data.append(GetPackGUID()); - data << GetPositionX(); - data << GetPositionY(); - data << GetPositionZ(); - - // unknown field - unrelated to orientation - // seems to increment about 1000 for every 1.7 seconds - // for now, we'll just use mstime - data << getMSTime(); - - data << uint8( 0 ); - data << uint32( MovementFlags ); - data << uint32( traveltime ); - data << uint32( pathSize ); - data.append( (char*)path.GetNodes(start), pathSize * 4 * 3 ); - - //WPAssert( data.size() == 37 + pathnodes.Size( ) * 4 * 3 ); - SendMessageToSet(&data, true); -} - -void Unit::resetAttackTimer(WeaponAttackType type) -{ - m_attackTimer[type] = uint32(GetAttackTime(type) * m_modAttackSpeedPct[type]); -} - -bool Unit::canReachWithAttack(Unit *pVictim) const -{ - assert(pVictim); - return IsWithinDistInMap(pVictim, GetCombatReach()); -} - -bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const -{ - if (!obj || !IsInMap(obj)) return false; - - float dx = GetPositionX() - obj->GetPositionX(); - float dy = GetPositionY() - obj->GetPositionY(); - float dz = GetPositionZ() - obj->GetPositionZ(); - float distsq = dx*dx + dy*dy + dz*dz; - //not sure here, or combatreach + combatreach? - float sizefactor = GetCombatReach() + obj->GetCombatReach(); - float maxdist = dist2compare + sizefactor; - - return distsq < maxdist * maxdist; -} - -void Unit::GetRandomContactPoint( const Unit* obj, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const -{ - //assert(GetCombatReach() > 0.1); - float combat_reach = GetCombatReach(); - if(combat_reach < 0.1) - { - sLog.outError("Unit %u (Type: %u) has invalid combat_reach %f",GetGUIDLow(),GetTypeId(),combat_reach); - if(GetTypeId() == TYPEID_UNIT) - sLog.outError("Creature entry %u has invalid combat_reach", ((Creature*)this)->GetEntry()); - combat_reach = 0.5; - } - uint32 attacker_number = getAttackers().size(); - if(attacker_number > 0) --attacker_number; - GetNearPoint(obj,x,y,z,obj->GetCombatReach(), distance2dMin+(distance2dMax-distance2dMin)*rand_norm() - , GetAngle(obj) + (attacker_number ? (M_PI/2 - M_PI * rand_norm()) * (float)attacker_number / combat_reach / 3 : 0)); -} - -void Unit::RemoveSpellsCausingAura(AuraType auraType) -{ - if (auraType >= TOTAL_AURAS) return; - AuraList::iterator iter, next; - for (iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end(); iter = next) - { - next = iter; - ++next; - - if (*iter) - { - RemoveAurasDueToSpell((*iter)->GetId()); - if (!m_modAuras[auraType].empty()) - next = m_modAuras[auraType].begin(); - else - return; - } - } -} - -void Unit::RemoveAurasWithInterruptFlags(uint32 flag) -{ - if(!(m_interruptMask & flag)) - return; - - // interrupt auras - AuraList::iterator iter, next; - for (iter = m_interruptableAuras.begin(); iter != m_interruptableAuras.end(); iter = next) - { - next = iter; - ++next; - - //sLog.outDetail("auraflag:%u flag:%u = %u",(*iter)->GetSpellProto()->AuraInterruptFlags,flag,(*iter)->GetSpellProto()->AuraInterruptFlags & flag); - if(*iter && ((*iter)->GetSpellProto()->AuraInterruptFlags & flag)) - { - RemoveAurasDueToSpell((*iter)->GetId()); - if (!m_interruptableAuras.empty()) - next = m_interruptableAuras.begin(); - else - break; - } - } - - // interrupt channeled spell - if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) - if(spell->getState() == SPELL_STATE_CASTING && (spell->m_spellInfo->ChannelInterruptFlags & flag)) - InterruptNonMeleeSpells(false); -} - -void Unit::UpdateInterruptMask() -{ - m_interruptMask = 0; - for(AuraList::iterator i = m_interruptableAuras.begin(); i != m_interruptableAuras.end(); ++i) - { - if(*i) - m_interruptMask |= (*i)->GetSpellProto()->AuraInterruptFlags; - } - if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) - if(spell->getState() == SPELL_STATE_CASTING) - m_interruptMask |= spell->m_spellInfo->ChannelInterruptFlags; -} - -bool Unit::HasAuraType(AuraType auraType) const -{ - return (!m_modAuras[auraType].empty()); -} - -/* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */ -void Unit::RemoveSpellbyDamageTaken(uint32 damage, uint32 spell) -{ - // The chance to dispel an aura depends on the damage taken with respect to the casters level. - uint32 max_dmg = getLevel() > 8 ? 25 * getLevel() - 150 : 50; - float chance = float(damage) / max_dmg * 100.0f; - - AuraList::iterator i, next; - for(i = m_ccAuras.begin(); i != m_ccAuras.end(); i = next) - { - next = i; - ++next; - - if(*i && (!spell || (*i)->GetId() != spell) && roll_chance_f(chance)) - { - RemoveAurasDueToSpell((*i)->GetId()); - if (!m_ccAuras.empty()) - next = m_ccAuras.begin(); - else - return; - } - } -} - -uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss) -{ - if (!pVictim->isAlive() || pVictim->isInFlight() || pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) - return 0; - - //You don't lose health from damage taken from another player while in a sanctuary - //You still see it in the combat log though - if(pVictim != this && GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) - { - const AreaTableEntry *area = GetAreaEntryByAreaID(pVictim->GetAreaId()); - if(area && area->flags & AREA_FLAG_SANCTUARY) //sanctuary - return 0; - } - - //Script Event damage taken - if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() ) - ((Creature *)pVictim)->AI()->DamageTaken(this, damage); - - if(!damage) //when will zero damage? need interrupt aura? - { - // Rage from physical damage received . - if(cleanDamage && cleanDamage->damage && (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) && pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) - ((Player*)pVictim)->RewardRage(cleanDamage->damage, 0, false); - - return 0; - } - - if(pVictim->GetTypeId() != TYPEID_PLAYER) - { - // no xp,health if type 8 /critters/ - if ( pVictim->GetCreatureType() == CREATURE_TYPE_CRITTER) - { - // critters run away when hit - pVictim->GetMotionMaster()->MoveFleeing(this); - - // allow loot only if has loot_id in creature_template - if(damage >= pVictim->GetHealth()) - { - pVictim->setDeathState(JUST_DIED); - pVictim->SetHealth(0); - - CreatureInfo const* cInfo = ((Creature*)pVictim)->GetCreatureInfo(); - if(cInfo && cInfo->lootid) - pVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); - - // some critters required for quests - if(GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->KilledMonster(pVictim->GetEntry(),pVictim->GetGUID()); - } - else - pVictim->ModifyHealth(- (int32)damage); - - return damage; - } - } - - DEBUG_LOG("DealDamageStart"); - - uint32 health = pVictim->GetHealth(); - sLog.outDetail("deal dmg:%d to health:%d ",damage,health); - - // duel ends when player has 1 or less hp - bool duel_hasEnded = false; - if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->duel && damage >= (health-1)) - { - // prevent kill only if killed in duel and killed by opponent or opponent controlled creature - if(((Player*)pVictim)->duel->opponent==this || ((Player*)pVictim)->duel->opponent->GetGUID() == GetOwnerGUID()) - damage = health-1; - - duel_hasEnded = true; - } - - // Rage from Damage made (only from direct weapon damage) - if( cleanDamage && damagetype==DIRECT_DAMAGE && this != pVictim && GetTypeId() == TYPEID_PLAYER && (getPowerType() == POWER_RAGE)) - { - uint32 weaponSpeedHitFactor; - - switch(cleanDamage->attackType) - { - case BASE_ATTACK: - { - if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 7); - else - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); - - ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); - - break; - } - case OFF_ATTACK: - { - if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); - else - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 1.75f); - - ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); - - break; - } - case RANGED_ATTACK: - break; - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER && GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)pVictim)->InBattleGround()) - { - Player *killer = ((Player*)this); - if(killer != ((Player*)pVictim)) - if(BattleGround *bg = killer->GetBattleGround()) - bg->UpdatePlayerScore(killer, SCORE_DAMAGE_DONE, damage); - } - } - - if (pVictim->GetTypeId() == TYPEID_UNIT && !((Creature*)pVictim)->isPet() && !((Creature*)pVictim)->hasLootRecipient()) - ((Creature*)pVictim)->SetLootRecipient(this); - if (health <= damage) - { - DEBUG_LOG("DealDamage: victim just died"); - - // find player: owner of controlled `this` or `this` itself maybe - Player *player = GetCharmerOrOwnerPlayerOrPlayerItself(); - - if(pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->GetLootRecipient()) - player = ((Creature*)pVictim)->GetLootRecipient(); - // Reward player, his pets, and group/raid members - // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop) - if(player && player!=pVictim) - if(player->RewardPlayerAndGroupAtKill(pVictim)) - player->ProcDamageAndSpell(pVictim,PROC_FLAG_KILL_XP_GIVER,PROC_FLAG_NONE); - - DEBUG_LOG("DealDamageAttackStop"); - - // stop combat - pVictim->CombatStop(); - pVictim->getHostilRefManager().deleteReferences(); - - // stop movement - pVictim->StopMoving(); - - bool damageFromSpiritOfRedemtionTalent = spellProto && spellProto->Id == 27795; - - // if talent known but not triggered (check priest class for speedup check) - Aura* spiritOfRedemtionTalentReady = NULL; - if( !damageFromSpiritOfRedemtionTalent && // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION - pVictim->GetTypeId()==TYPEID_PLAYER && pVictim->getClass()==CLASS_PRIEST ) - { - AuraList const& vDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); ++itr) - { - if((*itr)->GetSpellProto()->SpellIconID==1654) - { - spiritOfRedemtionTalentReady = *itr; - break; - } - } - } - - DEBUG_LOG("SET JUST_DIED"); - if(!spiritOfRedemtionTalentReady) - pVictim->setDeathState(JUST_DIED); - - // outdoor pvp things, do these after setting the death state, else the player activity notify won't work... doh... - // handle player kill only if not suicide (spirit of redemption for example) - if(GetTypeId() == TYPEID_PLAYER && this != pVictim) - { - if(OutdoorPvP * pvp = ((Player*)this)->GetOutdoorPvP()) - { - pvp->HandleKill((Player*)this,pVictim); - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - if(OutdoorPvP * pvp = ((Player*)pVictim)->GetOutdoorPvP()) - { - pvp->HandlePlayerActivityChanged((Player*)pVictim); - } - } - - DEBUG_LOG("DealDamageHealth1"); - - if(spiritOfRedemtionTalentReady) - { - // save value before aura remove - uint32 ressSpellId = pVictim->GetUInt32Value(PLAYER_SELF_RES_SPELL); - if(!ressSpellId) - ressSpellId = ((Player*)pVictim)->GetResurrectionSpellId(); - - //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers) - pVictim->RemoveAllAurasOnDeath(); - - // restore for use at real death - pVictim->SetUInt32Value(PLAYER_SELF_RES_SPELL,ressSpellId); - - // FORM_SPIRITOFREDEMPTION and related auras - pVictim->CastSpell(pVictim,27827,true,NULL,spiritOfRedemtionTalentReady); - } - else - pVictim->SetHealth(0); - - // remember victim PvP death for corpse type and corpse reclaim delay - // at original death (not at SpiritOfRedemtionTalent timeout) - if( pVictim->GetTypeId()==TYPEID_PLAYER && !damageFromSpiritOfRedemtionTalent ) - ((Player*)pVictim)->SetPvPDeath(player!=NULL); - - // 10% durability loss on death - // clean InHateListOf - if (pVictim->GetTypeId() == TYPEID_PLAYER) - { - // only if not player and not controlled by player pet. And not at BG - if (durabilityLoss && !player && !((Player*)pVictim)->InBattleGround()) - { - DEBUG_LOG("We are dead, loosing 10 percents durability"); - ((Player*)pVictim)->DurabilityLossAll(0.10f,false); - // durability lost message - WorldPacket data(SMSG_DURABILITY_DAMAGE_DEATH, 0); - ((Player*)pVictim)->GetSession()->SendPacket(&data); - } - // Call KilledUnit for creatures - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) - ((Creature*)this)->AI()->KilledUnit(pVictim); - } - else // creature died - { - DEBUG_LOG("DealDamageNotPlayer"); - Creature *cVictim = (Creature*)pVictim; - - if(!cVictim->isPet()) - { - cVictim->DeleteThreatList(); - cVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); - } - - // Call KilledUnit for creatures, this needs to be called after the lootable flag is set - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) - ((Creature*)this)->AI()->KilledUnit(pVictim); - - // Call creature just died function - if (cVictim->AI()) - cVictim->AI()->JustDied(this); - - // Dungeon specific stuff, only applies to players killing creatures - if(cVictim->GetInstanceId()) - { - Map *m = cVictim->GetMap(); - Player *creditedPlayer = GetCharmerOrOwnerPlayerOrPlayerItself(); - // TODO: do instance binding anyway if the charmer/owner is offline - - if(m->IsDungeon() && creditedPlayer) - { - if(m->IsRaid() || m->IsHeroic()) - { - if(cVictim->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND) - ((InstanceMap *)m)->PermBindAllPlayers(creditedPlayer); - } - else - { - // the reset time is set but not added to the scheduler - // until the players leave the instance - time_t resettime = cVictim->GetRespawnTimeEx() + 2 * HOUR; - if(InstanceSave *save = sInstanceSaveManager.GetInstanceSave(cVictim->GetInstanceId())) - if(save->GetResetTime() < resettime) save->SetResetTime(resettime); - } - } - } - } - - // last damage from non duel opponent or opponent controlled creature - if(duel_hasEnded) - { - assert(pVictim->GetTypeId()==TYPEID_PLAYER); - Player *he = (Player*)pVictim; - - assert(he->duel); - - he->duel->opponent->CombatStopWithPets(true); - he->CombatStopWithPets(true); - - he->DuelComplete(DUEL_INTERUPTED); - } - - // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill) - if(pVictim->GetTypeId() == TYPEID_PLAYER && (((Player*)pVictim)->InBattleGround())) - { - Player *killed = ((Player*)pVictim); - Player *killer = NULL; - if(GetTypeId() == TYPEID_PLAYER) - killer = ((Player*)this); - else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) - { - Unit *owner = GetOwner(); - if(owner && owner->GetTypeId() == TYPEID_PLAYER) - killer = ((Player*)owner); - } - - if(killer) - if(BattleGround *bg = killed->GetBattleGround()) - bg->HandleKillPlayer(killed, killer); // drop flags and etc - } - } - else // if (health <= damage) - { - DEBUG_LOG("DealDamageAlive"); - - pVictim->ModifyHealth(- (int32)damage); - - // Check if health is below 20% (apply damage before to prevent case when after ProcDamageAndSpell health < damage - if(pVictim->GetHealth()*5 < pVictim->GetMaxHealth()) - { - uint32 procVictim = PROC_FLAG_NONE; - - // if just dropped below 20% (for CheatDeath) - if((pVictim->GetHealth()+damage)*5 > pVictim->GetMaxHealth()) - procVictim = PROC_FLAG_LOW_HEALTH; - - ProcDamageAndSpell(pVictim,PROC_FLAG_TARGET_LOW_HEALTH,procVictim); - } - - if(damagetype != DOT) - { - if(getVictim()) - { - // if have target and damage pVictim just call AI reaction - if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI()) - ((Creature*)pVictim)->AI()->AttackedBy(this); - } - else - { - // if not have main target then attack state with target (including AI call) - //start melee attacks only after melee hit - Attack(pVictim,(damagetype == DIRECT_DAMAGE)); - } - } - - if(damagetype == DIRECT_DAMAGE|| damagetype == SPELL_DIRECT_DAMAGE) - pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE); - - if (pVictim->GetTypeId() != TYPEID_PLAYER) - { - if(spellProto && IsDamageToThreatSpell(spellProto)) - pVictim->AddThreat(this, damage*2, damageSchoolMask, spellProto); - else - pVictim->AddThreat(this, damage, damageSchoolMask, spellProto); - } - else // victim is a player - { - // Rage from damage received - if(this != pVictim && pVictim->getPowerType() == POWER_RAGE) - { - uint32 rage_damage = damage + (cleanDamage ? cleanDamage->damage : 0); - ((Player*)pVictim)->RewardRage(rage_damage, 0, false); - } - - // random durability for items (HIT TAKEN) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) - { - EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(slot); - } - } - - if(GetTypeId()==TYPEID_PLAYER) - { - // random durability for items (HIT DONE) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) - { - EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); - ((Player*)this)->DurabilityPointLossForEquipSlot(slot); - } - } - - if (damagetype != NODAMAGE && damage)// && pVictim->GetTypeId() == TYPEID_PLAYER) - { - //if (se->procFlags & (1<<3)) - pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DAMAGE); - pVictim->RemoveSpellbyDamageTaken(damage, spellProto ? spellProto->Id : 0); - - if(pVictim != this && pVictim->GetTypeId() == TYPEID_PLAYER) // does not support creature push_back - { - if(damagetype != DOT) - { - if(Spell* spell = pVictim->m_currentSpells[CURRENT_GENERIC_SPELL]) - { - if(spell->getState() == SPELL_STATE_PREPARING) - { - uint32 interruptFlags = spell->m_spellInfo->InterruptFlags; - if(interruptFlags & SPELL_INTERRUPT_FLAG_DAMAGE) - pVictim->InterruptNonMeleeSpells(false); - else if(interruptFlags & SPELL_INTERRUPT_FLAG_PUSH_BACK) - spell->Delayed(); - } - } - } - - if(Spell* spell = pVictim->m_currentSpells[CURRENT_CHANNELED_SPELL]) - { - if(spell->getState() == SPELL_STATE_CASTING) - { - uint32 channelInterruptFlags = spell->m_spellInfo->ChannelInterruptFlags; - if( channelInterruptFlags & CHANNEL_FLAG_DELAY ) - spell->DelayedChannel(); - } - } - } - } - - // last damage from duel opponent - if(duel_hasEnded) - { - assert(pVictim->GetTypeId()==TYPEID_PLAYER); - Player *he = (Player*)pVictim; - - assert(he->duel); - - he->SetHealth(1); - - he->duel->opponent->CombatStopWithPets(true); - he->CombatStopWithPets(true); - - he->CastSpell(he, 7267, true); // beg - he->DuelComplete(DUEL_WON); - } - } - - DEBUG_LOG("DealDamageEnd returned %d damage", damage); - - return damage; -} - -void Unit::CastStop(uint32 except_spellid) -{ - for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) - if (m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id!=except_spellid) - InterruptSpell(i,false); -} - -void Unit::CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); - - if(!spellInfo) - { - sLog.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - CastSpell(Victim,spellInfo,triggered,castItem,triggeredByAura, originalCaster); -} - -void Unit::CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - assert(Victim); - if(!spellInfo) - { - sLog.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - if (castItem) - DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); - - if(!originalCaster && triggeredByAura) - originalCaster = triggeredByAura->GetCasterGUID(); - - Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); - - SpellCastTargets targets; - targets.setUnitTarget( Victim ); - targets.setDestination( Victim->GetPositionX(), Victim->GetPositionY(), Victim->GetPositionZ(), false); - spell->m_CastItem = castItem; - spell->prepare(&targets, triggeredByAura); -} - -void Unit::CastCustomSpell(Unit* Victim,uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); - - if(!spellInfo) - { - sLog.outError("CastCustomSpell: unknown spell id %i\n", spellId); - return; - } - - CastCustomSpell(Victim,spellInfo,bp0,bp1,bp2,triggered,castItem,triggeredByAura, originalCaster); -} - -void Unit::CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - if(!spellInfo) - { - sLog.outError("CastCustomSpell: unknown spell"); - return; - } - - if (castItem) - DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); - - if(!originalCaster && triggeredByAura) - originalCaster = triggeredByAura->GetCasterGUID(); - - Spell *spell = new Spell(this, spellInfo, triggered, originalCaster); - - if(bp0) - spell->m_currentBasePoints[0] = *bp0-int32(spellInfo->EffectBaseDice[0]); - - if(bp1) - spell->m_currentBasePoints[1] = *bp1-int32(spellInfo->EffectBaseDice[1]); - - if(bp2) - spell->m_currentBasePoints[2] = *bp2-int32(spellInfo->EffectBaseDice[2]); - - SpellCastTargets targets; - targets.setUnitTarget( Victim ); - spell->m_CastItem = castItem; - spell->prepare(&targets, triggeredByAura); -} - -// used for scripting -void Unit::CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); - - if(!spellInfo) - { - sLog.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - CastSpell(x, y, z,spellInfo,triggered,castItem,triggeredByAura, originalCaster); -} - -// used for scripting -void Unit::CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - if(!spellInfo) - { - sLog.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - if (castItem) - DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); - - if(!originalCaster && triggeredByAura) - originalCaster = triggeredByAura->GetCasterGUID(); - - Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); - - SpellCastTargets targets; - targets.setDestination(x, y, z); - spell->m_CastItem = castItem; - spell->prepare(&targets, triggeredByAura); -} - -void Unit::DealFlatDamage(Unit *pVictim, SpellEntry const *spellInfo, uint32 *damage, CleanDamage *cleanDamage, bool *crit, bool isTriggeredSpell) -{ - // TODO this in only generic way, check for exceptions - DEBUG_LOG("DealFlatDamage (BEFORE) >> DMG:%u", *damage); - - // Per-damage class calculation - switch (spellInfo->DmgClass) - { - // Melee and Ranged Spells - case SPELL_DAMAGE_CLASS_RANGED: - case SPELL_DAMAGE_CLASS_MELEE: - { - // Calculate physical outcome - MeleeHitOutcome outcome = RollPhysicalOutcomeAgainst(pVictim, BASE_ATTACK, spellInfo); - - //Used to store the Hit Outcome - cleanDamage->hitOutCome = outcome; - - // Return miss/evade first (sends miss message) - switch(outcome) - { - case MELEE_HIT_EVADE: - { - SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_EVADES,0); - *damage = 0; - return; - } - case MELEE_HIT_MISS: - { - SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_NORMAL,0); - *damage = 0; - - if(GetTypeId()== TYPEID_PLAYER) - ((Player*)this)->UpdateWeaponSkill(BASE_ATTACK); - - CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,MELEE_HIT_MISS,spellInfo,isTriggeredSpell); - return; - } - } - - // Hitinfo, Victimstate - uint32 hitInfo = HITINFO_NORMALSWING; - VictimState victimState = VICTIMSTATE_NORMAL; - - // Physical Damage - if ( GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NORMAL ) - { - uint32 modDamage=*damage; - - // apply spellmod to Done damage - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_DAMAGE, *damage); - - //Calculate armor mitigation - uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); - - // random durability for main hand weapon (ABSORB) - if(damageAfterArmor < *damage) - if(pVictim->GetTypeId() == TYPEID_PLAYER) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); - - cleanDamage->damage += *damage - damageAfterArmor; - *damage = damageAfterArmor; - } - // Magical Damage - else - { - // Calculate damage bonus - *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); - } - - // Classify outcome - switch (outcome) - { - case MELEE_HIT_BLOCK_CRIT: - case MELEE_HIT_CRIT: - { - uint32 bonusDmg = *damage; - - // Apply crit_damage bonus - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRIT_DAMAGE_BONUS, bonusDmg); - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - bonusDmg = uint32(bonusDmg * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); - - *damage += bonusDmg; - - // Resilience - reduce crit damage - if (pVictim->GetTypeId()==TYPEID_PLAYER) - { - uint32 resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); - cleanDamage->damage += resilienceReduction; - *damage -= resilienceReduction; - } - - *crit = true; - hitInfo |= HITINFO_CRITICALHIT; - - ModifyAuraState(AURA_STATE_CRIT, true); - StartReactiveTimer( REACTIVE_CRIT ); - - if(getClass()==CLASS_HUNTER) - { - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); - StartReactiveTimer( REACTIVE_HUNTER_CRIT ); - } - - if ( outcome == MELEE_HIT_BLOCK_CRIT ) - { - uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); - if (blocked_amount >= *damage) - { - hitInfo |= HITINFO_SWINGNOHITSOUND; - victimState = VICTIMSTATE_BLOCKS; - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - } - else - { - // To Help Calculate Rage - cleanDamage->damage += blocked_amount; - *damage = *damage - blocked_amount; - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - } - break; - } - case MELEE_HIT_PARRY: - { - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - victimState = VICTIMSTATE_PARRY; - - // Counter-attack ( explained in Unit::DoAttackDamage() ) - if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN) ) - { - // Get attack timers - float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); - float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); - - // Reduce attack time - if (pVictim->haveOffhandWeapon() && offtime < basetime) - { - float percent20 = pVictim->GetAttackTime(OFF_ATTACK) * 0.20; - float percent60 = 3 * percent20; - if(offtime > percent20 && offtime <= percent60) - { - pVictim->setAttackTimer(OFF_ATTACK, uint32(percent20)); - } - else if(offtime > percent60) - { - offtime -= 2 * percent20; - pVictim->setAttackTimer(OFF_ATTACK, uint32(offtime)); - } - } - else - { - float percent20 = pVictim->GetAttackTime(BASE_ATTACK) * 0.20; - float percent60 = 3 * percent20; - if(basetime > percent20 && basetime <= percent60) - { - pVictim->setAttackTimer(BASE_ATTACK, uint32(percent20)); - } - else if(basetime > percent60) - { - basetime -= 2 * percent20; - pVictim->setAttackTimer(BASE_ATTACK, uint32(basetime)); - } - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update victim defense ? - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (PARRY) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); - } - - // Set parry flags - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - // Mongoose bite - set only Counterattack here - if (pVictim->getClass() == CLASS_HUNTER) - { - pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); - pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); - } - else - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - break; - } - case MELEE_HIT_DODGE: - { - if(pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateDefense(); - - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - hitInfo |= HITINFO_SWINGNOHITSOUND; - victimState = VICTIMSTATE_DODGE; - - // Set dodge flags - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - // Overpower - if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) - { - ((Player*)this)->AddComboPoints(pVictim, 1); - StartReactiveTimer( REACTIVE_OVERPOWER ); - } - - // Riposte - if (pVictim->getClass() != CLASS_ROGUE) - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - break; - } - case MELEE_HIT_BLOCK: - { - uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); - if (blocked_amount >= *damage) - { - hitInfo |= HITINFO_SWINGNOHITSOUND; - victimState = VICTIMSTATE_BLOCKS; - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - } - else - { - // To Help Calculate Rage - cleanDamage->damage += blocked_amount; - *damage = *damage - blocked_amount; - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - break; - } - case MELEE_HIT_EVADE: // already processed early - case MELEE_HIT_MISS: // already processed early - case MELEE_HIT_GLANCING: - case MELEE_HIT_CRUSHING: - case MELEE_HIT_NORMAL: - break; - } - - // do all damage=0 cases here - if(*damage == 0) - CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,outcome,spellInfo,isTriggeredSpell); - - break; - } - // Magical Attacks - case SPELL_DAMAGE_CLASS_NONE: - case SPELL_DAMAGE_CLASS_MAGIC: - { - // Calculate damage bonus - *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); - - *crit = isSpellCrit(pVictim, spellInfo, GetSpellSchoolMask(spellInfo), BASE_ATTACK); - if (*crit) - { - *damage = SpellCriticalBonus(spellInfo, *damage, pVictim); - - // Resilience - reduce crit damage - if (pVictim && pVictim->GetTypeId()==TYPEID_PLAYER) - { - uint32 damage_reduction = ((Player *)pVictim)->GetSpellCritDamageReduction(*damage); - if(*damage > damage_reduction) - *damage -= damage_reduction; - else - *damage = 0; - } - - cleanDamage->hitOutCome = MELEE_HIT_CRIT; - } - // spell proc all magic damage==0 case in this function - if(*damage == 0) - { - // Procflags - uint32 procAttacker = PROC_FLAG_HIT_SPELL; - uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); - - ProcDamageAndSpell(pVictim, procAttacker, procVictim, 0, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); - } - - break; - } - } - - // TODO this in only generic way, check for exceptions - DEBUG_LOG("DealFlatDamage (AFTER) >> DMG:%u", *damage); -} - -uint32 Unit::SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell, bool useSpellDamage) -{ - if(!this || !pVictim) - return 0; - if(!this->isAlive() || !pVictim->isAlive()) - return 0; - - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellID); - if(!spellInfo) - return 0; - - CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL); - bool crit = false; - - if (useSpellDamage) - DealFlatDamage(pVictim, spellInfo, &damage, &cleanDamage, &crit, isTriggeredSpell); - - // If we actually dealt some damage (spell proc's for 0 damage (normal and magic) called in DealFlatDamage) - if(damage > 0) - { - // Calculate absorb & resists - uint32 absorb = 0; - uint32 resist = 0; - - CalcAbsorbResist(pVictim,GetSpellSchoolMask(spellInfo), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist); - - //No more damage left, target absorbed and/or resisted all damage - if (damage > absorb + resist) - damage -= absorb + resist; //Remove Absorbed and Resisted from damage actually dealt - else - { - uint32 HitInfo = HITINFO_SWINGNOHITSOUND; - - if (absorb) - HitInfo |= HITINFO_ABSORB; - if (resist) - { - HitInfo |= HITINFO_RESIST; - ProcDamageAndSpell(pVictim, PROC_FLAG_TARGET_RESISTS, PROC_FLAG_RESIST_SPELL, 0, GetSpellSchoolMask(spellInfo), spellInfo,isTriggeredSpell); - } - - //Send resist - SendAttackStateUpdate(HitInfo, pVictim, 1, GetSpellSchoolMask(spellInfo), damage, absorb,resist,VICTIMSTATE_NORMAL,0); - return 0; - } - - // Deal damage done - damage = DealDamage(pVictim, damage, &cleanDamage, SPELL_DIRECT_DAMAGE, GetSpellSchoolMask(spellInfo), spellInfo, true); - - // Send damage log - sLog.outDetail("SpellNonMeleeDamageLog: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u,absorb is %u,resist is %u", - GetGUIDLow(), GetTypeId(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, spellID, absorb,resist); - - // Actual log sent to client - SendSpellNonMeleeDamageLog(pVictim, spellID, damage, GetSpellSchoolMask(spellInfo), absorb, resist, false, 0, crit); - - // Procflags - uint32 procAttacker = PROC_FLAG_HIT_SPELL; - uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); - - if (crit) - { - procAttacker |= PROC_FLAG_CRIT_SPELL; - procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; - } - - ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); - - return damage; - } - else - { - // all spell proc for 0 normal and magic damage called in DealFlatDamage - - //Check for rage - if(cleanDamage.damage) - // Rage from damage received. - if(pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) - ((Player*)pVictim)->RewardRage(cleanDamage.damage, 0, false); - - return 0; - } -} - -void Unit::HandleEmoteCommand(uint32 anim_id) -{ - WorldPacket data( SMSG_EMOTE, 12 ); - data << anim_id << GetGUID(); - WPAssert(data.size() == 12); - - SendMessageToSet(&data, true); -} - -uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage) -{ - uint32 newdamage = 0; - float armor = pVictim->GetArmor(); - // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura - armor += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, SPELL_SCHOOL_MASK_NORMAL); - - if (armor<0.0f) armor=0.0f; - - float tmpvalue = 0.0f; - if(getLevel() <= 59) //Level 1-59 - tmpvalue = armor / (armor + 400.0f + 85.0f * getLevel()); - else if(getLevel() < 70) //Level 60-69 - tmpvalue = armor / (armor - 22167.5f + 467.5f * getLevel()); - else //Level 70+ - tmpvalue = armor / (armor + 10557.5f); - - if(tmpvalue < 0.0f) - tmpvalue = 0.0f; - if(tmpvalue > 0.75f) - tmpvalue = 0.75f; - newdamage = uint32(damage - (damage * tmpvalue)); - - return (newdamage > 1) ? newdamage : 1; -} - -void Unit::CalcAbsorbResist(Unit *pVictim,SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist) -{ - if(!pVictim || !pVictim->isAlive() || !damage) - return; - - // Magic damage, check for resists - if ((schoolMask & SPELL_SCHOOL_MASK_NORMAL)==0) - { - // Get base victim resistance for school - float tmpvalue2 = (float)pVictim->GetResistance(GetFirstSchoolInMask(schoolMask)); - // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura - tmpvalue2 += (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask); - - tmpvalue2 *= (float)(0.15f / getLevel()); - if (tmpvalue2 < 0.0f) - tmpvalue2 = 0.0f; - if (tmpvalue2 > 0.75f) - tmpvalue2 = 0.75f; - uint32 ran = urand(0, 100); - uint32 faq[4] = {24,6,4,6}; - uint8 m = 0; - float Binom = 0.0f; - for (uint8 i = 0; i < 4; i++) - { - Binom += 2400 *( powf(tmpvalue2, i) * powf( (1-tmpvalue2), (4-i)))/faq[i]; - if (ran > Binom ) - ++m; - else - break; - } - if (damagetype == DOT && m == 4) - *resist += uint32(damage - 1); - else - *resist += uint32(damage * m / 4); - if(*resist > damage) - *resist = damage; - } - else - *resist = 0; - - int32 RemainingDamage = damage - *resist; - - // absorb without mana cost - int32 reflectDamage = 0; - Aura* reflectAura = NULL; - AuraList const& vSchoolAbsorb = pVictim->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB); - for(AuraList::const_iterator i = vSchoolAbsorb.begin(), next; i != vSchoolAbsorb.end() && RemainingDamage > 0; i = next) - { - next = i; ++next; - - if (((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - // Cheat Death - if((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_ROGUE && (*i)->GetSpellProto()->SpellIconID == 2109) - { - if (((Player*)pVictim)->HasSpellCooldown(31231)) - continue; - if (pVictim->GetHealth() <= RemainingDamage) - { - int32 chance = (*i)->GetModifier()->m_amount; - if (roll_chance_i(chance)) - { - pVictim->CastSpell(pVictim,31231,true); - ((Player*)pVictim)->AddSpellCooldown(31231,0,time(NULL)+60); - - // with health > 10% lost health until health==10%, in other case no losses - uint32 health10 = pVictim->GetMaxHealth()/10; - RemainingDamage = pVictim->GetHealth() > health10 ? pVictim->GetHealth() - health10 : 0; - } - } - continue; - } - - int32 currentAbsorb; - - //Reflective Shield - if ((pVictim != this) && (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_PRIEST && (*i)->GetSpellProto()->SpellFamilyFlags == 0x1) - { - if(Unit* caster = (*i)->GetCaster()) - { - AuraList const& vOverRideCS = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator k = vOverRideCS.begin(); k != vOverRideCS.end(); ++k) - { - switch((*k)->GetModifier()->m_miscvalue) - { - case 5065: // Rank 1 - case 5064: // Rank 2 - case 5063: // Rank 3 - case 5062: // Rank 4 - case 5061: // Rank 5 - { - if(RemainingDamage >= (*i)->GetModifier()->m_amount) - reflectDamage = (*i)->GetModifier()->m_amount * (*k)->GetModifier()->m_amount/100; - else - reflectDamage = (*k)->GetModifier()->m_amount * RemainingDamage/100; - reflectAura = *i; - - } break; - default: break; - } - - if(reflectDamage) - break; - } - } - } - - if (RemainingDamage >= (*i)->GetModifier()->m_amount) - { - currentAbsorb = (*i)->GetModifier()->m_amount; - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - next = vSchoolAbsorb.begin(); - } - else - { - currentAbsorb = RemainingDamage; - (*i)->GetModifier()->m_amount -= RemainingDamage; - } - - RemainingDamage -= currentAbsorb; - } - // do not cast spells while looping auras; auras can get invalid otherwise - if (reflectDamage) - pVictim->CastCustomSpell(this, 33619, &reflectDamage, NULL, NULL, true, NULL, reflectAura); - - // absorb by mana cost - AuraList const& vManaShield = pVictim->GetAurasByType(SPELL_AURA_MANA_SHIELD); - for(AuraList::const_iterator i = vManaShield.begin(), next; i != vManaShield.end() && RemainingDamage > 0; i = next) - { - next = i; ++next; - - // check damage school mask - if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - int32 currentAbsorb; - if (RemainingDamage >= (*i)->GetModifier()->m_amount) - currentAbsorb = (*i)->GetModifier()->m_amount; - else - currentAbsorb = RemainingDamage; - - float manaMultiplier = (*i)->GetSpellProto()->EffectMultipleValue[(*i)->GetEffIndex()]; - if(Player *modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod((*i)->GetId(), SPELLMOD_MULTIPLE_VALUE, manaMultiplier); - - int32 maxAbsorb = int32(pVictim->GetPower(POWER_MANA) / manaMultiplier); - if (currentAbsorb > maxAbsorb) - currentAbsorb = maxAbsorb; - - (*i)->GetModifier()->m_amount -= currentAbsorb; - if((*i)->GetModifier()->m_amount <= 0) - { - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - next = vManaShield.begin(); - } - - int32 manaReduction = int32(currentAbsorb * manaMultiplier); - pVictim->ApplyPowerMod(POWER_MANA, manaReduction, false); - - RemainingDamage -= currentAbsorb; - } - - // only split damage if not damaging yourself - if(pVictim != this) - { - AuraList const& vSplitDamageFlat = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT); - for(AuraList::const_iterator i = vSplitDamageFlat.begin(), next; i != vSplitDamageFlat.end() && RemainingDamage >= 0; i = next) - { - next = i; ++next; - - // check damage school mask - if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - // Damage can be splitted only if aura has an alive caster - Unit *caster = (*i)->GetCaster(); - if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) - continue; - - int32 currentAbsorb; - if (RemainingDamage >= (*i)->GetModifier()->m_amount) - currentAbsorb = (*i)->GetModifier()->m_amount; - else - currentAbsorb = RemainingDamage; - - RemainingDamage -= currentAbsorb; - - SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, currentAbsorb, schoolMask, 0, 0, false, 0, false); - - CleanDamage cleanDamage = CleanDamage(currentAbsorb, BASE_ATTACK, MELEE_HIT_NORMAL); - DealDamage(caster, currentAbsorb, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); - } - - AuraList const& vSplitDamagePct = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT); - for(AuraList::const_iterator i = vSplitDamagePct.begin(), next; i != vSplitDamagePct.end() && RemainingDamage >= 0; i = next) - { - next = i; ++next; - - // check damage school mask - if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - // Damage can be splitted only if aura has an alive caster - Unit *caster = (*i)->GetCaster(); - if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) - continue; - - int32 splitted = int32(RemainingDamage * (*i)->GetModifier()->m_amount / 100.0f); - - RemainingDamage -= splitted; - - SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, splitted, schoolMask, 0, 0, false, 0, false); - - CleanDamage cleanDamage = CleanDamage(splitted, BASE_ATTACK, MELEE_HIT_NORMAL); - DealDamage(caster, splitted, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); - } - } - - *absorb = damage - RemainingDamage - *resist; -} - -void Unit::DoAttackDamage (Unit *pVictim, uint32 *damage, CleanDamage *cleanDamage, uint32 *blocked_amount, SpellSchoolMask damageSchoolMask, uint32 *hitInfo, VictimState *victimState, uint32 *absorbDamage, uint32 *resistDamage, WeaponAttackType attType, SpellEntry const *spellCasted, bool isTriggeredSpell) -{ - MeleeHitOutcome outcome; - - // If is casted Melee spell, calculate like physical - if(!spellCasted) - outcome = RollMeleeOutcomeAgainst (pVictim, attType); - else - outcome = RollPhysicalOutcomeAgainst (pVictim, attType, spellCasted); - - if(outcome == MELEE_HIT_MISS ||outcome == MELEE_HIT_DODGE ||outcome == MELEE_HIT_BLOCK ||outcome == MELEE_HIT_PARRY) - pVictim->AddThreat(this, 0.0f); - switch(outcome) - { - case MELEE_HIT_EVADE: - { - *hitInfo |= HITINFO_MISS; - *damage = 0; - cleanDamage->damage = 0; - return; - } - case MELEE_HIT_MISS: - { - *hitInfo |= HITINFO_MISS; - *damage = 0; - cleanDamage->damage = 0; - if(GetTypeId()== TYPEID_PLAYER) - ((Player*)this)->UpdateWeaponSkill(attType); - return; - } - } - - /// If this is a creature and it attacks from behind it has a probability to daze it's victim - if( (outcome==MELEE_HIT_CRIT || outcome==MELEE_HIT_CRUSHING || outcome==MELEE_HIT_NORMAL || outcome==MELEE_HIT_GLANCING) && - GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGUID() && !pVictim->HasInArc(M_PI, this) - && pVictim->GetTypeId() == TYPEID_PLAYER) - { - // -probability is between 0% and 40% - // 20% base chance - float Probability = 20; - - //there is a newbie protection, at level 10 just 7% base chance; assuming linear function - if( pVictim->getLevel() < 30 ) - Probability = 0.65f*pVictim->getLevel()+0.5; - - uint32 VictimDefense=pVictim->GetDefenseSkillValue(this); - uint32 AttackerMeleeSkill=GetUnitMeleeSkill(pVictim); - - Probability *= AttackerMeleeSkill/(float)VictimDefense; - - if(Probability > 40.0f) - Probability = 40.0f; - - if(roll_chance_f(Probability)) - CastSpell(pVictim, 1604, true); - } - - //Calculate the damage after armor mitigation if SPELL_SCHOOL_NORMAL - if (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) - { - uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); - - // random durability for main hand weapon (ABSORB) - if(damageAfterArmor < *damage) - if(pVictim->GetTypeId() == TYPEID_PLAYER) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); - - cleanDamage->damage += *damage - damageAfterArmor; - *damage = damageAfterArmor; - } - - if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) - ((Player*)this)->UpdateCombatSkills(pVictim, attType, outcome, false); - - if(GetTypeId() != TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateCombatSkills(this, attType, outcome, true); - - switch (outcome) - { - case MELEE_HIT_BLOCK_CRIT: - case MELEE_HIT_CRIT: - { - //*hitInfo = 0xEA; - // 0xEA - *hitInfo = HITINFO_CRITICALHIT | HITINFO_NORMALSWING2 | 0x8; - - // Crit bonus calc - uint32 crit_bonus; - crit_bonus = *damage; - - // Apply crit_damage bonus for melee spells - if (spellCasted) - { - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellCasted->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - crit_bonus = uint32(crit_bonus * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); - } - - *damage += crit_bonus; - - uint32 resilienceReduction = 0; - - if(attType == RANGED_ATTACK) - { - int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE); - *damage = int32((*damage) * float((100.0f + mod)/100.0f)); - // Resilience - reduce crit damage - if (pVictim->GetTypeId()==TYPEID_PLAYER) - resilienceReduction = ((Player*)pVictim)->GetRangedCritDamageReduction(*damage); - } - else - { - int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE); - mod += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE); - *damage = int32((*damage) * float((100.0f + mod)/100.0f)); - // Resilience - reduce crit damage - if (pVictim->GetTypeId()==TYPEID_PLAYER) - resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); - } - - *damage -= resilienceReduction; - cleanDamage->damage += resilienceReduction; - - if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) - ((Player*)this)->UpdateWeaponSkill(attType); - - ModifyAuraState(AURA_STATE_CRIT, true); - StartReactiveTimer( REACTIVE_CRIT ); - - if(getClass()==CLASS_HUNTER) - { - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); - StartReactiveTimer( REACTIVE_HUNTER_CRIT ); - } - - if ( outcome == MELEE_HIT_BLOCK_CRIT ) - { - *blocked_amount = pVictim->GetShieldBlockValue(); - - if (pVictim->GetUnitBlockChance()) - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); - else - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - //Only set VICTIMSTATE_BLOCK on a full block - if (*blocked_amount >= uint32(*damage)) - { - *victimState = VICTIMSTATE_BLOCKS; - *blocked_amount = uint32(*damage); - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - break; - } - - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL); - break; - } - case MELEE_HIT_PARRY: - { - if(attType == RANGED_ATTACK) //range attack - no parry - { - outcome = MELEE_HIT_NORMAL; - break; - } - - cleanDamage->damage += *damage; - *damage = 0; - *victimState = VICTIMSTATE_PARRY; - - // instant (maybe with small delay) counter attack - { - float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); - float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); - - // after parry nearest next attack time will reduced at %40 from full attack time. - // The delay cannot be reduced to less than 20% of your weapon base swing delay. - if (pVictim->haveOffhandWeapon() && offtime < basetime) - { - float percent20 = pVictim->GetAttackTime(OFF_ATTACK)*0.20; - float percent60 = 3*percent20; - // set to 20% if in range 20%...20+40% of full time - if(offtime > percent20 && offtime <= percent60) - { - pVictim->setAttackTimer(OFF_ATTACK,uint32(percent20)); - } - // decrease at %40 from full time - else if(offtime > percent60) - { - offtime -= 2*percent20; - pVictim->setAttackTimer(OFF_ATTACK,uint32(offtime)); - } - // ELSE not changed - } - else - { - float percent20 = pVictim->GetAttackTime(BASE_ATTACK)*0.20; - float percent60 = 3*percent20; - // set to 20% if in range 20%...20+40% of full time - if(basetime > percent20 && basetime <= percent60) - { - pVictim->setAttackTimer(BASE_ATTACK,uint32(percent20)); - } - // decrease at %40 from full time - else if(basetime > percent60) - { - basetime -= 2*percent20; - pVictim->setAttackTimer(BASE_ATTACK,uint32(basetime)); - } - // ELSE not changed - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update victim defense ? - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (PARRY) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); - } - - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - if (pVictim->getClass() == CLASS_HUNTER) - { - pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); - pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); - } - else - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - - CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - return; - } - case MELEE_HIT_DODGE: - { - if(attType == RANGED_ATTACK) //range attack - no dodge - { - outcome = MELEE_HIT_NORMAL; - break; - } - - cleanDamage->damage += *damage; - *damage = 0; - *victimState = VICTIMSTATE_DODGE; - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateDefense(); - - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - if (pVictim->getClass() != CLASS_ROGUE) // Riposte - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - - // Overpower - if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) - { - ((Player*)this)->AddComboPoints(pVictim, 1); - StartReactiveTimer( REACTIVE_OVERPOWER ); - } - - CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - return; - } - case MELEE_HIT_BLOCK: - { - *blocked_amount = pVictim->GetShieldBlockValue(); - - if (pVictim->GetUnitBlockChance()) - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); - else - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - //Only set VICTIMSTATE_BLOCK on a full block - if (*blocked_amount >= uint32(*damage)) - { - *victimState = VICTIMSTATE_BLOCKS; - *blocked_amount = uint32(*damage); - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - - break; - } - case MELEE_HIT_GLANCING: - { - int32 leveldif = int32(pVictim->getLevel()) - int32(getLevel()); - if (leveldif > 3) leveldif = 3; - *damage *= (1 - leveldif * 0.1f); - cleanDamage->damage = *damage; - *hitInfo |= HITINFO_GLANCING; - break; - } - case MELEE_HIT_CRUSHING: - { - // 150% normal damage - *damage += (*damage / 2); - cleanDamage->damage = *damage; - *hitInfo |= HITINFO_CRUSHING; - // TODO: victimState, victim animation? - break; - } - default: - break; - } - - // apply melee damage bonus and absorb only if base damage not fully blocked to prevent negative damage or damage with full block - if(*victimState != VICTIMSTATE_BLOCKS) - { - MeleeDamageBonus(pVictim, damage,attType,spellCasted); - CalcAbsorbResist(pVictim, damageSchoolMask, DIRECT_DAMAGE, *damage-*blocked_amount, absorbDamage, resistDamage); - } - - if (*absorbDamage) *hitInfo |= HITINFO_ABSORB; - if (*resistDamage) *hitInfo |= HITINFO_RESIST; - - cleanDamage->damage += *blocked_amount; - - if (*damage <= *absorbDamage + *resistDamage + *blocked_amount) - { - //*hitInfo = 0x00010020; - //*hitInfo |= HITINFO_SWINGNOHITSOUND; - //*damageType = 0; - CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - return; - } - - // update at damage Judgement aura duration that applied by attacker at victim - if(*damage) - { - AuraMap const& vAuras = pVictim->GetAuras(); - for(AuraMap::const_iterator itr = vAuras.begin(); itr != vAuras.end(); ++itr) - { - SpellEntry const *spellInfo = (*itr).second->GetSpellProto(); - if( (spellInfo->AttributesEx3 & 0x40000) && spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && - ((*itr).second->GetCasterGUID() == GetGUID() && (!spellCasted || spellCasted->Id == 35395)) ) - { - (*itr).second->SetAuraDuration((*itr).second->GetAuraMaxDuration()); - (*itr).second->UpdateAuraDuration(); - } - } - } - - CastMeleeProcDamageAndSpell(pVictim, (*damage - *absorbDamage - *resistDamage - *blocked_amount), damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - - // victim's damage shield - // yet another hack to fix crashes related to the aura getting removed during iteration - std::set alreadyDone; - uint32 removedAuras = pVictim->m_removedAuras; - AuraList const& vDamageShields = pVictim->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD); - for(AuraList::const_iterator i = vDamageShields.begin(), next = vDamageShields.begin(); i != vDamageShields.end(); i = next) - { - ++next; - if (alreadyDone.find(*i) == alreadyDone.end()) - { - alreadyDone.insert(*i); - pVictim->SpellNonMeleeDamageLog(this, (*i)->GetId(), (*i)->GetModifier()->m_amount, false, false); - if (pVictim->m_removedAuras > removedAuras) - { - removedAuras = pVictim->m_removedAuras; - next = vDamageShields.begin(); - } - } - } -} - -void Unit::AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType, bool extra ) -{ - if(hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING) || HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED) ) - return; - - if (!pVictim->isAlive()) - return; - - if(IsNonMeleeSpellCasted(false)) - return; - - CombatStart(pVictim); - - uint32 hitInfo; - if (attType == BASE_ATTACK) - hitInfo = HITINFO_NORMALSWING2; - else if (attType == OFF_ATTACK) - hitInfo = HITINFO_LEFTSWING; - else - return; // ignore ranged case - - uint32 extraAttacks = m_extraAttacks; - - // melee attack spell casted at main hand attack only - if (attType == BASE_ATTACK && m_currentSpells[CURRENT_MELEE_SPELL]) - { - m_currentSpells[CURRENT_MELEE_SPELL]->cast(); - - // not recent extra attack only at any non extra attack (melee spell case) - if(!extra && extraAttacks) - { - while(m_extraAttacks) - { - AttackerStateUpdate(pVictim, BASE_ATTACK, true); - if(m_extraAttacks > 0) - --m_extraAttacks; - } - } - - return; - } - - VictimState victimState = VICTIMSTATE_NORMAL; - - CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL ); - uint32 blocked_dmg = 0; - uint32 absorbed_dmg = 0; - uint32 resisted_dmg = 0; - - SpellSchoolMask meleeSchoolMask = GetMeleeDamageSchoolMask(); - - if(pVictim->IsImmunedToDamage(meleeSchoolMask,true)) // use charges - { - SendAttackStateUpdate (HITINFO_NORMALSWING, pVictim, 1, meleeSchoolMask, 0, 0, 0, VICTIMSTATE_IS_IMMUNE, 0); - - // not recent extra attack only at any non extra attack (miss case) - if(!extra && extraAttacks) - { - while(m_extraAttacks) - { - AttackerStateUpdate(pVictim, BASE_ATTACK, true); - if(m_extraAttacks > 0) - --m_extraAttacks; - } - } - - return; - } - - uint32 damage = CalculateDamage (attType, false); - - DoAttackDamage (pVictim, &damage, &cleanDamage, &blocked_dmg, meleeSchoolMask, &hitInfo, &victimState, &absorbed_dmg, &resisted_dmg, attType); - - if (hitInfo & HITINFO_MISS) - //send miss - SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); - else - { - //do animation - SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); - - if (damage > (absorbed_dmg + resisted_dmg + blocked_dmg)) - damage -= (absorbed_dmg + resisted_dmg + blocked_dmg); - else - damage = 0; - - DealDamage (pVictim, damage, &cleanDamage, DIRECT_DAMAGE, meleeSchoolMask, NULL, true); - - if(GetTypeId() == TYPEID_PLAYER && pVictim->isAlive()) - { - for(int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; i++) - ((Player*)this)->CastItemCombatSpell(((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0,i),pVictim,attType); - } - } - - if (GetTypeId() == TYPEID_PLAYER) - DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", - GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); - else - DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", - GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); - - // extra attack only at any non extra attack (normal case) - if(!extra && extraAttacks) - { - while(m_extraAttacks) - { - AttackerStateUpdate(pVictim, BASE_ATTACK, true); - if(m_extraAttacks > 0) - --m_extraAttacks; - } - } -} - -MeleeHitOutcome Unit::RollPhysicalOutcomeAgainst (Unit const *pVictim, WeaponAttackType attType, SpellEntry const *spellInfo) -{ - // Miss chance based on melee - float miss_chance = MeleeMissChanceCalc(pVictim, attType); - - // Critical hit chance - float crit_chance = GetUnitCriticalChance(attType, pVictim); - // this is to avoid compiler issue when declaring variables inside if - float block_chance, parry_chance, dodge_chance; - - // cannot be dodged/parried/blocked - if(spellInfo->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) - { - block_chance = 0.0f; - parry_chance = 0.0f; - dodge_chance = 0.0f; - } - else - { - // parry can be avoided only by some abilities - parry_chance = pVictim->GetUnitParryChance(); - // block might be bypassed by it as well - block_chance = pVictim->GetUnitBlockChance(); - // stunned target cannot dodge and this is check in GetUnitDodgeChance() - dodge_chance = pVictim->GetUnitDodgeChance(); - } - - // Only players can have Talent&Spell bonuses - if (GetTypeId() == TYPEID_PLAYER) - { - // Increase from SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL aura - crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, spellInfo->SchoolMask); - - if( dodge_chance != 0.0f ) // if dodge chance is already 0, ignore talents for speed - { - AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); - for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) - { - // can't be dodged rogue finishing move - if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) - { - if(spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) - { - dodge_chance = 0.0f; - break; - } - } - } - } - } - - // Spellmods - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); - - DEBUG_LOG("PHYSICAL OUTCOME: miss %f crit %f dodge %f parry %f block %f",miss_chance,crit_chance,dodge_chance,parry_chance, block_chance); - - return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100),int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), true); -} - -MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(const Unit *pVictim, WeaponAttackType attType) const -{ - // This is only wrapper - - // Miss chance based on melee - float miss_chance = MeleeMissChanceCalc(pVictim, attType); - - // Critical hit chance - float crit_chance = GetUnitCriticalChance(attType, pVictim); - - // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case) - float dodge_chance = pVictim->GetUnitDodgeChance(); - float block_chance = pVictim->GetUnitBlockChance(); - float parry_chance = pVictim->GetUnitParryChance(); - - // Useful if want to specify crit & miss chances for melee, else it could be removed - DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance,crit_chance,dodge_chance,parry_chance,block_chance); - - return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100), int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), false); -} - -MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance, bool SpellCasted ) const -{ - if(pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) - return MELEE_HIT_EVADE; - - int32 attackerMaxSkillValueForLevel = GetMaxSkillValueForLevel(pVictim); - int32 victimMaxSkillValueForLevel = pVictim->GetMaxSkillValueForLevel(this); - - int32 attackerWeaponSkill = GetWeaponSkillValue(attType,pVictim); - int32 victimDefenseSkill = pVictim->GetDefenseSkillValue(this); - - // bonus from skills is 0.04% - int32 skillBonus = 4 * ( attackerWeaponSkill - victimMaxSkillValueForLevel ); - int32 skillBonus2 = 4 * ( attackerMaxSkillValueForLevel - victimDefenseSkill ); - int32 sum = 0, tmp = 0; - int32 roll = urand (0, 10000); - - DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus); - DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d", - roll, miss_chance, dodge_chance, parry_chance, block_chance, crit_chance); - - tmp = miss_chance; - - if (tmp > 0 && roll < (sum += tmp )) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS"); - return MELEE_HIT_MISS; - } - - // always crit against a sitting target (except 0 crit chance) - if( pVictim->GetTypeId() == TYPEID_PLAYER && crit_chance > 0 && !pVictim->IsStandState() ) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)"); - return MELEE_HIT_CRIT; - } - - // Dodge chance - - // only players can't dodge if attacker is behind - if (pVictim->GetTypeId() == TYPEID_PLAYER && !pVictim->HasInArc(M_PI,this)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player."); - } - else - { - // Reduce dodge chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - dodge_chance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); - - // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE - dodge_chance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); - - tmp = dodge_chance; - if ( (tmp > 0) // check if unit _can_ dodge - && ((tmp -= skillBonus) > 0) - && roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum-tmp, sum); - return MELEE_HIT_DODGE; - } - } - - // parry & block chances - - // check if attack comes from behind, nobody can parry or block if attacker is behind - if (!pVictim->HasInArc(M_PI,this)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind."); - } - else - { - // Reduce parry chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - parry_chance-= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); - - if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY) ) - { - int32 tmp = int32(parry_chance); - if ( (tmp > 0) // check if unit _can_ parry - && ((tmp -= skillBonus) > 0) - && (roll < (sum += tmp))) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum-tmp, sum); - return MELEE_HIT_PARRY; - } - } - - if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_BLOCK) ) - { - tmp = block_chance; - if ( (tmp > 0) // check if unit _can_ block - && ((tmp -= skillBonus) > 0) - && (roll < (sum += tmp))) - { - // Critical chance - tmp = crit_chance + skillBonus2; - if ( GetTypeId() == TYPEID_PLAYER && SpellCasted && tmp > 0 ) - { - if ( roll_chance_i(tmp/100)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCKED CRIT"); - return MELEE_HIT_BLOCK_CRIT; - } - } - DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum-tmp, sum); - return MELEE_HIT_BLOCK; - } - } - } - - // Critical chance - tmp = crit_chance + skillBonus2; - - if (tmp > 0 && roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum-tmp, sum); - return MELEE_HIT_CRIT; - } - - // Max 40% chance to score a glancing blow against mobs that are higher level (can do only players and pets and not with ranged weapon) - if( attType != RANGED_ATTACK && !SpellCasted && - (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet()) && - pVictim->GetTypeId() != TYPEID_PLAYER && !((Creature*)pVictim)->isPet() && - getLevel() < pVictim->getLevelForTarget(this) ) - { - // cap possible value (with bonuses > max skill) - int32 skill = attackerWeaponSkill; - int32 maxskill = attackerMaxSkillValueForLevel; - skill = (skill > maxskill) ? maxskill : skill; - - tmp = (10 + (victimDefenseSkill - skill)) * 100; - tmp = tmp > 4000 ? 4000 : tmp; - if (roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum-4000, sum); - return MELEE_HIT_GLANCING; - } - } - - if(GetTypeId()!=TYPEID_PLAYER && !(((Creature*)this)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_CRUSH) && !((Creature*)this)->isPet() ) - { - // mobs can score crushing blows if they're 3 or more levels above victim - // or when their weapon skill is 15 or more above victim's defense skill - tmp = victimDefenseSkill; - int32 tmpmax = victimMaxSkillValueForLevel; - // having defense above your maximum (from items, talents etc.) has no effect - tmp = tmp > tmpmax ? tmpmax : tmp; - // tmp = mob's level * 5 - player's current defense skill - tmp = attackerMaxSkillValueForLevel - tmp; - if(tmp >= 15) - { - // add 2% chance per lacking skill point, min. is 15% - tmp = tmp * 200 - 1500; - if (roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum-tmp, sum); - return MELEE_HIT_CRUSHING; - } - } - } - - DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL"); - return MELEE_HIT_NORMAL; -} - -uint32 Unit::CalculateDamage (WeaponAttackType attType, bool normalized) -{ - float min_damage, max_damage; - - if (normalized && GetTypeId()==TYPEID_PLAYER) - ((Player*)this)->CalculateMinMaxDamage(attType,normalized,min_damage, max_damage); - else - { - switch (attType) - { - case RANGED_ATTACK: - min_damage = GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE); - max_damage = GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE); - break; - case BASE_ATTACK: - min_damage = GetFloatValue(UNIT_FIELD_MINDAMAGE); - max_damage = GetFloatValue(UNIT_FIELD_MAXDAMAGE); - break; - case OFF_ATTACK: - min_damage = GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE); - max_damage = GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE); - break; - // Just for good manner - default: - min_damage = 0.0f; - max_damage = 0.0f; - break; - } - } - - if (min_damage > max_damage) - { - std::swap(min_damage,max_damage); - } - - if(max_damage == 0.0f) - max_damage = 5.0f; - - return urand((uint32)min_damage, (uint32)max_damage); -} - -float Unit::CalculateLevelPenalty(SpellEntry const* spellProto) const -{ - if(spellProto->spellLevel <= 0) - return 1.0f; - - float LvlPenalty = 0.0f; - - if(spellProto->spellLevel < 20) - LvlPenalty = 20.0f - spellProto->spellLevel * 3.75f; - float LvlFactor = (float(spellProto->spellLevel) + 6.0f) / float(getLevel()); - if(LvlFactor > 1.0f) - LvlFactor = 1.0f; - - return (100.0f - LvlPenalty) * LvlFactor / 100.0f; -} - -void Unit::SendAttackStart(Unit* pVictim) -{ - WorldPacket data( SMSG_ATTACKSTART, 16 ); - data << GetGUID(); - data << pVictim->GetGUID(); - - SendMessageToSet(&data, true); - DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" ); -} - -void Unit::SendAttackStop(Unit* victim) -{ - if(!victim) - return; - - WorldPacket data( SMSG_ATTACKSTOP, (4+16) ); // we guess size - data.append(GetPackGUID()); - data.append(victim->GetPackGUID()); // can be 0x00... - data << uint32(0); // can be 0x1 - SendMessageToSet(&data, true); - sLog.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER ? "player" : "creature"), GetGUIDLow(), (victim->GetTypeId()==TYPEID_PLAYER ? "player" : "creature"),victim->GetGUIDLow()); - - /*if(victim->GetTypeId() == TYPEID_UNIT) - ((Creature*)victim)->AI().EnterEvadeMode(this);*/ -} - -/* -// Melee based spells can be miss, parry or dodge on this step -// Crit or block - determined on damage calculation phase! (and can be both in some time) -float Unit::MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell) -{ - // Calculate hit chance (more correct for chance mod) - int32 HitChance; - - // PvP - PvE melee chances - int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; - int32 leveldif = pVictim->getLevelForTarget(this) - getLevelForTarget(pVictim); - if(leveldif < 3) - HitChance = 95 - leveldif; - else - HitChance = 93 - (leveldif - 2) * lchance; - - // Hit chance depends from victim auras - if(attType == RANGED_ATTACK) - HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); - else - HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); - - // Spellmod from SPELLMOD_RESIST_MISS_CHANCE - if(Player *modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, HitChance); - - // Miss = 100 - hit - float miss_chance= 100.0f - HitChance; - - // Bonuses from attacker aura and ratings - if (attType == RANGED_ATTACK) - miss_chance -= m_modRangedHitChance; - else - miss_chance -= m_modMeleeHitChance; - - // bonus from skills is 0.04% - miss_chance -= skillDiff * 0.04f; - - // Limit miss chance from 0 to 60% - if (miss_chance < 0.0f) - return 0.0f; - if (miss_chance > 60.0f) - return 60.0f; - return miss_chance; -} - -// Melee based spells hit result calculations -SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell) -{ - WeaponAttackType attType = BASE_ATTACK; - - if (spell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) - attType = RANGED_ATTACK; - - // bonus from skills is 0.04% per skill Diff - int32 attackerWeaponSkill = int32(GetWeaponSkillValue(attType,pVictim)); - int32 skillDiff = attackerWeaponSkill - int32(pVictim->GetMaxSkillValueForLevel(this)); - int32 fullSkillDiff = attackerWeaponSkill - int32(pVictim->GetDefenseSkillValue(this)); - - uint32 roll = urand (0, 10000); - uint32 missChance = uint32(MeleeSpellMissChance(pVictim, attType, fullSkillDiff, spell)*100.0f); - - // Roll miss - uint32 tmp = missChance; - if (roll < tmp) - return SPELL_MISS_MISS; - - // Same spells cannot be parry/dodge - if (spell->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) - return SPELL_MISS_NONE; - - // Ranged attack can`t miss too - if (attType == RANGED_ATTACK) - return SPELL_MISS_NONE; - - bool attackFromBehind = !pVictim->HasInArc(M_PI,this); - - // Roll dodge - int32 dodgeChance = int32(pVictim->GetUnitDodgeChance()*100.0f) - skillDiff * 4; - // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE - dodgeChance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); - - // Reduce dodge chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - dodgeChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); - if (dodgeChance < 0) - dodgeChance = 0; - - // Can`t dodge from behind in PvP (but its possible in PvE) - if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER && attackFromBehind) - dodgeChance = 0; - - // Rogue talent`s cant be dodged - AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); - for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) - { - if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) // can't be dodged rogue finishing move - { - if(spell->SpellFamilyName==SPELLFAMILY_ROGUE && (spell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) - { - dodgeChance = 0; - break; - } - } - } - - tmp += dodgeChance; - if (roll < tmp) - return SPELL_MISS_DODGE; - - // Roll parry - int32 parryChance = int32(pVictim->GetUnitParryChance()*100.0f) - skillDiff * 4; - // Reduce parry chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - parryChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); - // Can`t parry from behind - if (parryChance < 0 || attackFromBehind) - parryChance = 0; - - tmp += parryChance; - if (roll < tmp) - return SPELL_MISS_PARRY; - - return SPELL_MISS_NONE; -}*/ - -// TODO need use unit spell resistances in calculations -SpellMissInfo Unit::MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell) -{ - // Can`t miss on dead target (on skinning for example) - if (!pVictim->isAlive()) - return SPELL_MISS_NONE; - - SpellSchoolMask schoolMask = GetSpellSchoolMask(spell); - // PvP - PvE spell misschances per leveldif > 2 - int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 7 : 11; - int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); - - // Base hit chance from attacker and victim levels - int32 modHitChance; - if(leveldif < 3) - modHitChance = 96 - leveldif; - else - modHitChance = 94 - (leveldif - 2) * lchance; - - // Spellmod from SPELLMOD_RESIST_MISS_CHANCE - if(Player *modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, modHitChance); - // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras - modHitChance+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT, schoolMask); - // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras - modHitChance+= pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE, schoolMask); - // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura - if (IsAreaOfEffectSpell(spell)) - modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE); - // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST - if (IsDispelSpell(spell)) - modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST); - // Chance resist mechanic (select max value from every mechanic spell effect) - int32 resist_mech = 0; - // Get effects mechanic and chance - for(int eff = 0; eff < 3; ++eff) - { - int32 effect_mech = GetEffectMechanic(spell, eff); - if (effect_mech) - { - int32 temp = pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE, effect_mech); - if (resist_mech < temp) - resist_mech = temp; - } - } - // Apply mod - modHitChance-=resist_mech; - - // Chance resist debuff - modHitChance-=pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE, int32(spell->Dispel)); - - int32 HitChance = modHitChance * 100; - // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings - HitChance += int32(m_modSpellHitChance*100.0f); - - // Decrease hit chance from victim rating bonus - if (pVictim->GetTypeId()==TYPEID_PLAYER) - HitChance -= int32(((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL)*100.0f); - - if (HitChance < 100) HitChance = 100; - if (HitChance > 9900) HitChance = 9900; - - uint32 rand = urand(0,10000); - if (rand > HitChance) - return SPELL_MISS_RESIST; - return SPELL_MISS_NONE; -} - -SpellMissInfo Unit::SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool CanReflect) -{ - // Return evade for units in evade mode - if (pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) - return SPELL_MISS_EVADE; - - // If Spel has this flag cannot be resisted/immuned/etc - if (spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) - return SPELL_MISS_NONE; - - // Check for immune (use charges) - if (pVictim->IsImmunedToSpell(spell,true)) - return SPELL_MISS_IMMUNE; - - // All positive spells can`t miss - // TODO: client not show miss log for this spells - so need find info for this in dbc and use it! - if (IsPositiveSpell(spell->Id) - &&(!IsHostileTo(pVictim))) //prevent from affecting enemy by "positive" spell - return SPELL_MISS_NONE; - - // Check for immune (use charges) - if (pVictim->IsImmunedToDamage(GetSpellSchoolMask(spell),true)) - return SPELL_MISS_IMMUNE; - - // Try victim reflect spell - if (CanReflect) - { - // specialized first - Unit::AuraList const& mReflectSpellsSchool = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL); - for(Unit::AuraList::const_iterator i = mReflectSpellsSchool.begin(); i != mReflectSpellsSchool.end(); ++i) - { - if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spell)) - { - int32 reflectchance = (*i)->GetModifier()->m_amount; - if (reflectchance > 0 && roll_chance_i(reflectchance)) - { - if((*i)->m_procCharges > 0) - { - --(*i)->m_procCharges; - if((*i)->m_procCharges==0) - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - } - return SPELL_MISS_REFLECT; - } - } - } - - // generic reflection - Unit::AuraList const& mReflectSpells = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS); - for(Unit::AuraList::const_iterator i = mReflectSpells.begin(); i != mReflectSpells.end(); ++i) - { - int32 reflectchance = (*i)->GetModifier()->m_amount; - if (reflectchance > 0 && roll_chance_i(reflectchance)) - { - if((*i)->m_procCharges > 0) - { - --(*i)->m_procCharges; - if((*i)->m_procCharges==0) - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - } - return SPELL_MISS_REFLECT; - } - } - } - - // Temporary solution for melee based spells and spells vs SPELL_SCHOOL_NORMAL (hit result calculated after) - for (int i=0;i<3;i++) - { - if (spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE || - spell->Effect[i] == SPELL_EFFECT_WEAPON_PERCENT_DAMAGE || - spell->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG || - spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL) - return SPELL_MISS_NONE; - } - - // TODO need use this code for spell hit result calculation - // now code commented for computability - switch (spell->DmgClass) - { - case SPELL_DAMAGE_CLASS_RANGED: - case SPELL_DAMAGE_CLASS_MELEE: -// return MeleeSpellHitResult(pVictim, spell); - return SPELL_MISS_NONE; - case SPELL_DAMAGE_CLASS_NONE: - return SPELL_MISS_NONE; - case SPELL_DAMAGE_CLASS_MAGIC: - return MagicSpellHitResult(pVictim, spell); - } - return SPELL_MISS_NONE; -} - -float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const -{ - if(!pVictim) - return 0.0f; - - // Base misschance 5% - float misschance = 5.0f; - - // DualWield - Melee spells and physical dmg spells - 5% , white damage 24% - if (haveOffhandWeapon() && attType != RANGED_ATTACK) - { - bool isNormal = false; - for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) - { - if( m_currentSpells[i] && (GetSpellSchoolMask(m_currentSpells[i]->m_spellInfo) & SPELL_SCHOOL_MASK_NORMAL) ) - { - isNormal = true; - break; - } - } - if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL]) - { - misschance = 5.0f; - } - else - { - misschance = 24.0f; - } - } - - // PvP : PvE melee misschances per leveldif > 2 - int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; - - int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); - if(leveldif < 0) - leveldif = 0; - - // Hit chance from attacker based on ratings and auras - float m_modHitChance; - if (attType == RANGED_ATTACK) - m_modHitChance = m_modRangedHitChance; - else - m_modHitChance = m_modMeleeHitChance; - - if(leveldif < 3) - misschance += (leveldif - m_modHitChance); - else - misschance += ((leveldif - 2) * chance - m_modHitChance); - - // Hit chance for victim based on ratings - if (pVictim->GetTypeId()==TYPEID_PLAYER) - { - if (attType == RANGED_ATTACK) - misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED); - else - misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE); - } - - // Modify miss chance by victim auras - if(attType == RANGED_ATTACK) - misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); - else - misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); - - // Modify miss chance from skill difference ( bonus from skills is 0.04% ) - int32 skillBonus = int32(GetWeaponSkillValue(attType,pVictim)) - int32(pVictim->GetDefenseSkillValue(this)); - misschance -= skillBonus * 0.04f; - - // Limit miss chance from 0 to 60% - if ( misschance < 0.0f) - return 0.0f; - if ( misschance > 60.0f) - return 60.0f; - - return misschance; -} - -uint32 Unit::GetDefenseSkillValue(Unit const* target) const -{ - if(GetTypeId() == TYPEID_PLAYER) - { - // in PvP use full skill instead current skill value - uint32 value = (target && target->GetTypeId() == TYPEID_PLAYER) - ? ((Player*)this)->GetMaxSkillValue(SKILL_DEFENSE) - : ((Player*)this)->GetSkillValue(SKILL_DEFENSE); - value += uint32(((Player*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL)); - return value; - } - else - return GetUnitMeleeSkill(target); -} - -float Unit::GetUnitDodgeChance() const -{ - if(hasUnitState(UNIT_STAT_STUNNED)) - return 0.0f; - if( GetTypeId() == TYPEID_PLAYER ) - return GetFloatValue(PLAYER_DODGE_PERCENTAGE); - else - { - if(((Creature const*)this)->isTotem()) - return 0.0f; - else - { - float dodge = 5.0f; - dodge += GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT); - return dodge > 0.0f ? dodge : 0.0f; - } - } -} - -float Unit::GetUnitParryChance() const -{ - if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) - return 0.0f; - - float chance = 0.0f; - - if(GetTypeId() == TYPEID_PLAYER) - { - Player const* player = (Player const*)this; - if(player->CanParry() ) - { - Item *tmpitem = player->GetWeaponForAttack(BASE_ATTACK,true); - if(!tmpitem) - tmpitem = player->GetWeaponForAttack(OFF_ATTACK,true); - - if(tmpitem) - chance = GetFloatValue(PLAYER_PARRY_PERCENTAGE); - } - } - else if(GetTypeId() == TYPEID_UNIT) - { - if(GetCreatureType() == CREATURE_TYPE_HUMANOID) - { - chance = 5.0f; - chance += GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT); - } - } - - return chance > 0.0f ? chance : 0.0f; -} - -float Unit::GetUnitBlockChance() const -{ - if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) - return 0.0f; - - if(GetTypeId() == TYPEID_PLAYER) - { - Player const* player = (Player const*)this; - if(player->CanBlock() ) - { - Item *tmpitem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); - if(tmpitem && !tmpitem->IsBroken() && tmpitem->GetProto()->Block) - return GetFloatValue(PLAYER_BLOCK_PERCENTAGE); - } - // is player but has no block ability or no not broken shield equipped - return 0.0f; - } - else - { - if(((Creature const*)this)->isTotem()) - return 0.0f; - else - { - float block = 5.0f; - block += GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT); - return block > 0.0f ? block : 0.0f; - } - } -} - -float Unit::GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const -{ - float crit; - - if(GetTypeId() == TYPEID_PLAYER) - { - switch(attackType) - { - case BASE_ATTACK: - crit = GetFloatValue( PLAYER_CRIT_PERCENTAGE ); - break; - case OFF_ATTACK: - crit = GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE ); - break; - case RANGED_ATTACK: - crit = GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE ); - break; - // Just for good manner - default: - crit = 0.0f; - break; - } - } - else - { - crit = 5.0f; - crit += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT); - } - - // flat aura mods - if(attackType == RANGED_ATTACK) - crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE); - else - crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE); - - crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); - - // reduce crit chance from Rating for players - if (pVictim->GetTypeId()==TYPEID_PLAYER) - { - if (attackType==RANGED_ATTACK) - crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED); - else - crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE); - } - - if (crit < 0.0f) - crit = 0.0f; - return crit; -} - -uint32 Unit::GetWeaponSkillValue (WeaponAttackType attType, Unit const* target) const -{ - uint32 value = 0; - if(GetTypeId() == TYPEID_PLAYER) - { - Item* item = ((Player*)this)->GetWeaponForAttack(attType,true); - - // feral or unarmed skill only for base attack - if(attType != BASE_ATTACK && !item ) - return 0; - - if(((Player*)this)->IsInFeralForm()) - return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact - - // weapon skill or (unarmed for base attack) - uint32 skill = item ? item->GetSkill() : SKILL_UNARMED; - - // in PvP use full skill instead current skill value - value = (target && target->GetTypeId() == TYPEID_PLAYER) - ? ((Player*)this)->GetMaxSkillValue(skill) - : ((Player*)this)->GetSkillValue(skill); - // Modify value from ratings - value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL)); - switch (attType) - { - case BASE_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND));break; - case OFF_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND));break; - case RANGED_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED));break; - } - } - else - value = GetUnitMeleeSkill(target); - return value; -} - -void Unit::_UpdateSpells( uint32 time ) -{ - if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]) - _UpdateAutoRepeatSpell(); - - // remove finished spells from current pointers - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - { - if (m_currentSpells[i] && m_currentSpells[i]->getState() == SPELL_STATE_FINISHED) - { - m_currentSpells[i]->SetReferencedFromCurrent(false); - m_currentSpells[i] = NULL; // remove pointer - } - } - - // TODO: Find a better way to prevent crash when multiple auras are removed. - m_removedAuras = 0; - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) - if ((*i).second) - (*i).second->SetUpdated(false); - - for (AuraMap::iterator i = m_Auras.begin(), next; i != m_Auras.end(); i = next) - { - next = i; - ++next; - if ((*i).second) - { - // prevent double update - if ((*i).second->IsUpdated()) - continue; - (*i).second->SetUpdated(true); - (*i).second->Update( time ); - // several auras can be deleted due to update - if (m_removedAuras) - { - if (m_Auras.empty()) break; - next = m_Auras.begin(); - m_removedAuras = 0; - } - } - } - - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end();) - { - if ((*i).second) - { - if ( !(*i).second->GetAuraDuration() && !((*i).second->IsPermanent() || ((*i).second->IsPassive())) ) - { - RemoveAura(i); - } - else - { - ++i; - } - } - else - { - ++i; - } - } - - if(!m_gameObj.empty()) - { - std::list::iterator ite1, dnext1; - for (ite1 = m_gameObj.begin(); ite1 != m_gameObj.end(); ite1 = dnext1) - { - dnext1 = ite1; - //(*i)->Update( difftime ); - if( !(*ite1)->isSpawned() ) - { - (*ite1)->SetOwnerGUID(0); - (*ite1)->SetRespawnTime(0); - (*ite1)->Delete(); - dnext1 = m_gameObj.erase(ite1); - } - else - ++dnext1; - } - } -} - -void Unit::_UpdateAutoRepeatSpell() -{ - //check "realtime" interrupts - if ( (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) ) - { - // cancel wand shoot - if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - m_AutoRepeatFirstCast = true; - return; - } - - //apply delay - if ( m_AutoRepeatFirstCast && getAttackTimer(RANGED_ATTACK) < 500 ) - setAttackTimer(RANGED_ATTACK,500); - m_AutoRepeatFirstCast = false; - - //castroutine - if (isAttackReady(RANGED_ATTACK)) - { - // Check if able to cast - if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->CanCast(true)) - { - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - return; - } - - // we want to shoot - Spell* spell = new Spell(this, m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo, true, 0); - spell->prepare(&(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_targets)); - - // all went good, reset attack - resetAttackTimer(RANGED_ATTACK); - } -} - -void Unit::SetCurrentCastedSpell( Spell * pSpell ) -{ - assert(pSpell); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells - - uint32 CSpellType = pSpell->GetCurrentContainer(); - - if (pSpell == m_currentSpells[CSpellType]) return; // avoid breaking self - - // break same type spell if it is not delayed - InterruptSpell(CSpellType,false); - - // special breakage effects: - switch (CSpellType) - { - case CURRENT_GENERIC_SPELL: - { - // generic spells always break channeled not delayed spells - InterruptSpell(CURRENT_CHANNELED_SPELL,false); - - // autorepeat breaking - if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) - { - // break autorepeat if not Auto Shot - if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - m_AutoRepeatFirstCast = true; - } - addUnitState(UNIT_STAT_CASTING); - } break; - - case CURRENT_CHANNELED_SPELL: - { - // channel spells always break generic non-delayed and any channeled spells - InterruptSpell(CURRENT_GENERIC_SPELL,false); - InterruptSpell(CURRENT_CHANNELED_SPELL); - - // it also does break autorepeat if not Auto Shot - if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && - m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351 ) - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - addUnitState(UNIT_STAT_CASTING); - } break; - - case CURRENT_AUTOREPEAT_SPELL: - { - // only Auto Shoot does not break anything - if (pSpell->m_spellInfo->Category == 351) - { - // generic autorepeats break generic non-delayed and channeled non-delayed spells - InterruptSpell(CURRENT_GENERIC_SPELL,false); - InterruptSpell(CURRENT_CHANNELED_SPELL,false); - } - // special action: set first cast flag - m_AutoRepeatFirstCast = true; - } break; - - default: - { - // other spell types don't break anything now - } break; - } - - // current spell (if it is still here) may be safely deleted now - if (m_currentSpells[CSpellType]) - m_currentSpells[CSpellType]->SetReferencedFromCurrent(false); - - // set new current spell - m_currentSpells[CSpellType] = pSpell; - pSpell->SetReferencedFromCurrent(true); -} - -void Unit::InterruptSpell(uint32 spellType, bool withDelayed) -{ - assert(spellType < CURRENT_MAX_SPELL); - - if(m_currentSpells[spellType] && (withDelayed || m_currentSpells[spellType]->getState() != SPELL_STATE_DELAYED) ) - { - // send autorepeat cancel message for autorepeat spells - if (spellType == CURRENT_AUTOREPEAT_SPELL) - { - if(GetTypeId()==TYPEID_PLAYER) - ((Player*)this)->SendAutoRepeatCancel(); - } - - if (m_currentSpells[spellType]->getState() != SPELL_STATE_FINISHED) - m_currentSpells[spellType]->cancel(); - m_currentSpells[spellType]->SetReferencedFromCurrent(false); - m_currentSpells[spellType] = NULL; - } -} - -bool Unit::IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled, bool skipAutorepeat) const -{ - // We don't do loop here to explicitly show that melee spell is excluded. - // Maybe later some special spells will be excluded too. - - // generic spells are casted when they are not finished and not delayed - if ( m_currentSpells[CURRENT_GENERIC_SPELL] && - (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && - (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) - return(true); - - // channeled spells may be delayed, but they are still considered casted - else if ( !skipChanneled && m_currentSpells[CURRENT_CHANNELED_SPELL] && - (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) ) - return(true); - - // autorepeat spells may be finished or delayed, but they are still considered casted - else if ( !skipAutorepeat && m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) - return(true); - - return(false); -} - -void Unit::InterruptNonMeleeSpells(bool withDelayed, uint32 spell_id) -{ - // generic spells are interrupted if they are not finished or delayed - if (m_currentSpells[CURRENT_GENERIC_SPELL] && (!spell_id || m_currentSpells[CURRENT_GENERIC_SPELL]->m_spellInfo->Id==spell_id)) - { - if ( (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && - (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) - m_currentSpells[CURRENT_GENERIC_SPELL]->cancel(); - m_currentSpells[CURRENT_GENERIC_SPELL]->SetReferencedFromCurrent(false); - m_currentSpells[CURRENT_GENERIC_SPELL] = NULL; - } - - // autorepeat spells are interrupted if they are not finished or delayed - if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && (!spell_id || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Id==spell_id)) - { - // send disable autorepeat packet in any case - if(GetTypeId()==TYPEID_PLAYER) - ((Player*)this)->SendAutoRepeatCancel(); - - if ( (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_FINISHED) && - (withDelayed || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_DELAYED) ) - m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->cancel(); - m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->SetReferencedFromCurrent(false); - m_currentSpells[CURRENT_AUTOREPEAT_SPELL] = NULL; - } - - // channeled spells are interrupted if they are not finished, even if they are delayed - if (m_currentSpells[CURRENT_CHANNELED_SPELL] && (!spell_id || m_currentSpells[CURRENT_CHANNELED_SPELL]->m_spellInfo->Id==spell_id)) - { - if (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) - m_currentSpells[CURRENT_CHANNELED_SPELL]->cancel(); - m_currentSpells[CURRENT_CHANNELED_SPELL]->SetReferencedFromCurrent(false); - m_currentSpells[CURRENT_CHANNELED_SPELL] = NULL; - } -} - -Spell* Unit::FindCurrentSpellBySpellId(uint32 spell_id) const -{ - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - if(m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id==spell_id) - return m_currentSpells[i]; - return NULL; -} - -bool Unit::isInFront(Unit const* target, float distance, float arc) const -{ - return IsWithinDistInMap(target, distance) && HasInArc( arc, target ); -} - -void Unit::SetInFront(Unit const* target) -{ - SetOrientation(GetAngle(target)); -} - -bool Unit::isInBack(Unit const* target, float distance, float arc) const -{ - return IsWithinDistInMap(target, distance) && !HasInArc( 2 * M_PI - arc, target ); -} - -bool Unit::isInLine(Unit const* target, float distance) const -{ - if(!HasInArc(M_PI, target) || !IsWithinDistInMap(target, distance)) return false; - float width = (GetObjectSize() / 2 + target->GetObjectSize()) / 2; - float angle = GetAngle(target); - angle -= GetOrientation(); - return abs(sin(angle)) * distance < width; -} - -bool Unit::isInAccessiblePlaceFor(Creature const* c) const -{ - if(IsInWater()) - return c->canSwim(); - else - return c->canWalk() || c->canFly(); -} - -bool Unit::IsInWater() const -{ - return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ()); -} - -bool Unit::IsUnderWater() const -{ - return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ()); -} - -void Unit::DeMorph() -{ - SetDisplayId(GetNativeDisplayId()); -} - -int32 Unit::GetTotalAuraModifier(AuraType auratype) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - modifier += (*i)->GetModifier()->m_amount; - - return modifier; -} - -float Unit::GetTotalAuraMultiplier(AuraType auratype) const -{ - float multiplier = 1.0f; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - multiplier *= (100.0f + (*i)->GetModifier()->m_amount)/100.0f; - - return multiplier; -} - -int32 Unit::GetMaxPositiveAuraModifier(AuraType auratype) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - if ((*i)->GetModifier()->m_amount > modifier) - modifier = (*i)->GetModifier()->m_amount; - - return modifier; -} - -int32 Unit::GetMaxNegativeAuraModifier(AuraType auratype) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - if ((*i)->GetModifier()->m_amount < modifier) - modifier = (*i)->GetModifier()->m_amount; - - return modifier; -} - -int32 Unit::GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask) - modifier += mod->m_amount; - } - return modifier; -} - -float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - float multiplier = 1.0f; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask) - multiplier *= (100.0f + mod->m_amount)/100.0f; - } - return multiplier; -} - -int32 Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask && mod->m_amount > modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -int32 Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask && mod->m_amount < modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -int32 Unit::GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value) - modifier += mod->m_amount; - } - return modifier; -} - -float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const -{ - float multiplier = 1.0f; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value) - multiplier *= (100.0f + mod->m_amount)/100.0f; - } - return multiplier; -} - -int32 Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value && mod->m_amount > modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -int32 Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value && mod->m_amount < modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -bool Unit::AddAura(Aura *Aur) -{ - // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load) - if( !isAlive() && Aur->GetId() != 20584 && Aur->GetId() != 8326 && Aur->GetId() != 2584 && - (GetTypeId()!=TYPEID_PLAYER || !((Player*)this)->GetSession()->PlayerLoading()) ) - { - delete Aur; - return false; - } - - if(Aur->GetTarget() != this) - { - sLog.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)", - Aur->GetId(),Aur->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER?"player":"creature"),GetGUIDLow(), - (Aur->GetTarget()->GetTypeId()==TYPEID_PLAYER?"player":"creature"),Aur->GetTarget()->GetGUIDLow()); - delete Aur; - return false; - } - - SpellEntry const* aurSpellInfo = Aur->GetSpellProto(); - - spellEffectPair spair = spellEffectPair(Aur->GetId(), Aur->GetEffIndex()); - AuraMap::iterator i = m_Auras.find( spair ); - - // take out same spell - if (i != m_Auras.end()) - { - // passive and persistent auras can stack with themselves any number of times - if (!Aur->IsPassive() && !Aur->IsPersistent()) - { - // replace aura if next will > spell StackAmount - if(aurSpellInfo->StackAmount) - { - if(m_Auras.count(spair) >= aurSpellInfo->StackAmount) - RemoveAura(i,AURA_REMOVE_BY_STACK); - } - // if StackAmount==0 not allow auras from same caster - else - { - for(AuraMap::iterator i2 = m_Auras.lower_bound(spair); i2 != m_Auras.upper_bound(spair); ++i2) - { - if(i2->second->GetCasterGUID()==Aur->GetCasterGUID()) - { - // can be only single (this check done at _each_ aura add - RemoveAura(i2,AURA_REMOVE_BY_STACK); - break; - } - - bool stop = false; - switch(aurSpellInfo->EffectApplyAuraName[Aur->GetEffIndex()]) - { - // DoT/HoT/etc - case SPELL_AURA_PERIODIC_DAMAGE: // allow stack - case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: - case SPELL_AURA_PERIODIC_LEECH: - case SPELL_AURA_PERIODIC_HEAL: - case SPELL_AURA_OBS_MOD_HEALTH: - case SPELL_AURA_PERIODIC_MANA_LEECH: - case SPELL_AURA_PERIODIC_ENERGIZE: - case SPELL_AURA_OBS_MOD_MANA: - case SPELL_AURA_POWER_BURN_MANA: - break; - default: // not allow - // can be only single (this check done at _each_ aura add - RemoveAura(i2,AURA_REMOVE_BY_STACK); - stop = true; - break; - } - - if(stop) - break; - } - } - } - } - - // passive auras stack with all (except passive spell proc auras) - if ((!Aur->IsPassive() || !IsPassiveStackableSpell(Aur->GetId())) && - !(Aur->GetId() == 20584 || Aur->GetId() == 8326)) - { - if (!RemoveNoStackAurasDueToAura(Aur)) - { - delete Aur; - return false; // couldn't remove conflicting aura with higher rank - } - } - - // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura) - if (IsSingleTargetSpell(aurSpellInfo) && Aur->GetTarget()) - { - // caster pointer can be deleted in time aura remove, find it by guid at each iteration - for(;;) - { - Unit* caster = Aur->GetCaster(); - if(!caster) // caster deleted and not required adding scAura - break; - - bool restart = false; - AuraList& scAuras = caster->GetSingleCastAuras(); - for(AuraList::iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) - { - if( (*itr)->GetTarget() != Aur->GetTarget() && - IsSingleTargetSpells((*itr)->GetSpellProto(),aurSpellInfo) ) - { - if ((*itr)->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for IsSingleTargetSpell", (*itr)->GetId(), (*itr)->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - (*itr)->GetTarget()->RemoveAura((*itr)->GetId(), (*itr)->GetEffIndex()); - restart = true; - break; - } - } - - if(!restart) - { - // done - scAuras.push_back(Aur); - break; - } - } - } - - // add aura, register in lists and arrays - Aur->_AddAura(); - m_Auras.insert(AuraMap::value_type(spellEffectPair(Aur->GetId(), Aur->GetEffIndex()), Aur)); - if (Aur->GetModifier()->m_auraname < TOTAL_AURAS) - { - m_modAuras[Aur->GetModifier()->m_auraname].push_back(Aur); - if(Aur->GetSpellProto()->AuraInterruptFlags) - { - m_interruptableAuras.push_back(Aur); - AddInterruptMask(Aur->GetSpellProto()->AuraInterruptFlags); - } - if(Aur->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) - { - m_ccAuras.push_back(Aur); - } - } - - Aur->ApplyModifier(true,true); - sLog.outDebug("Aura %u now is in use", Aur->GetModifier()->m_auraname); - return true; -} - -void Unit::RemoveRankAurasDueToSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return; - AuraMap::iterator i,next; - for (i = m_Auras.begin(); i != m_Auras.end(); i = next) - { - next = i; - ++next; - uint32 i_spellId = (*i).second->GetId(); - if((*i).second && i_spellId && i_spellId != spellId) - { - if(spellmgr.IsRankSpellDueToSpell(spellInfo,i_spellId)) - { - RemoveAurasDueToSpell(i_spellId); - - if( m_Auras.empty() ) - break; - else - next = m_Auras.begin(); - } - } - } -} - -bool Unit::RemoveNoStackAurasDueToAura(Aura *Aur) -{ - if (!Aur) - return false; - - SpellEntry const* spellProto = Aur->GetSpellProto(); - if (!spellProto) - return false; - - uint32 spellId = Aur->GetId(); - uint32 effIndex = Aur->GetEffIndex(); - - SpellSpecific spellId_spec = GetSpellSpecific(spellId); - - AuraMap::iterator i,next; - for (i = m_Auras.begin(); i != m_Auras.end(); i = next) - { - next = i; - ++next; - if (!(*i).second) continue; - - SpellEntry const* i_spellProto = (*i).second->GetSpellProto(); - - if (!i_spellProto) - continue; - - uint32 i_spellId = i_spellProto->Id; - - if(IsPassiveSpell(i_spellId)) - { - if(IsPassiveStackableSpell(i_spellId)) - continue; - - // passive non-stackable spells not stackable only with another rank of same spell - if (!spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) - continue; - } - - uint32 i_effIndex = (*i).second->GetEffIndex(); - - if(i_spellId == spellId) continue; - - bool is_triggered_by_spell = false; - // prevent triggered aura of removing aura that triggered it - for(int j = 0; j < 3; ++j) - if (i_spellProto->EffectTriggerSpell[j] == spellProto->Id) - is_triggered_by_spell = true; - if (is_triggered_by_spell) continue; - - for(int j = 0; j < 3; ++j) - { - // prevent remove dummy triggered spells at next effect aura add - switch(spellProto->Effect[j]) // main spell auras added added after triggered spell - { - case SPELL_EFFECT_DUMMY: - switch(spellId) - { - case 5420: if(i_spellId==34123) is_triggered_by_spell = true; break; - } - break; - } - - if(is_triggered_by_spell) - break; - - // prevent remove form main spell by triggered passive spells - switch(i_spellProto->EffectApplyAuraName[j]) // main aura added before triggered spell - { - case SPELL_AURA_MOD_SHAPESHIFT: - switch(i_spellId) - { - case 24858: if(spellId==24905) is_triggered_by_spell = true; break; - case 33891: if(spellId==5420 || spellId==34123) is_triggered_by_spell = true; break; - case 34551: if(spellId==22688) is_triggered_by_spell = true; break; - } - break; - } - } - - if(!is_triggered_by_spell) - { - SpellSpecific i_spellId_spec = GetSpellSpecific(i_spellId); - - bool is_sspc = IsSingleFromSpellSpecificPerCaster(spellId_spec,i_spellId_spec); - - if( is_sspc && Aur->GetCasterGUID() == (*i).second->GetCasterGUID() ) - { - // cannot remove higher rank - if (spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) - if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) - return false; - - // Its a parent aura (create this aura in ApplyModifier) - if ((*i).second->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - RemoveAurasDueToSpell(i_spellId); - - if( m_Auras.empty() ) - break; - else - next = m_Auras.begin(); - } - else if( !is_sspc && spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId) ) - { - // Its a parent aura (create this aura in ApplyModifier) - if ((*i).second->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - RemoveAurasDueToSpell(i_spellId); - - if( m_Auras.empty() ) - break; - else - next = m_Auras.begin(); - } - // Potions stack aura by aura (elixirs/flask already checked) - else if( spellProto->SpellFamilyName == SPELLFAMILY_POTION && i_spellProto->SpellFamilyName == SPELLFAMILY_POTION ) - { - if (IsNoStackAuraDueToAura(spellId, effIndex, i_spellId, i_effIndex)) - { - if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) - return false; // cannot remove higher rank - - // Its a parent aura (create this aura in ApplyModifier) - if ((*i).second->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - RemoveAura(i); - next = i; - } - } - } - } - return true; -} - -void Unit::RemoveAura(uint32 spellId, uint32 effindex, Aura* except) -{ - spellEffectPair spair = spellEffectPair(spellId, effindex); - for(AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) - { - if(iter->second!=except) - { - RemoveAura(iter); - iter = m_Auras.lower_bound(spair); - } - else - ++iter; - } -} - -void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler) -{ - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - Aura *aur = iter->second; - if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) - { - // Custom dispel case - // Unstable Affliction - if (aur->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (aur->GetSpellProto()->SpellFamilyFlags & 0x010000000000LL)) - { - int32 damage = aur->GetModifier()->m_amount*9; - uint64 caster_guid = aur->GetCasterGUID(); - - // Remove aura - RemoveAura(iter, AURA_REMOVE_BY_DISPEL); - - // backfire damage and silence - dispeler->CastCustomSpell(dispeler, 31117, &damage, NULL, NULL, true, NULL, NULL,caster_guid); - - iter = m_Auras.begin(); // iterator can be invalidate at cast if self-dispel - } - else - RemoveAura(iter, AURA_REMOVE_BY_DISPEL); - } - else - ++iter; - } -} - -void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer) -{ - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - Aura *aur = iter->second; - if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) - { - int32 basePoints = aur->GetBasePoints(); - // construct the new aura for the attacker - Aura * new_aur = CreateAura(aur->GetSpellProto(), aur->GetEffIndex(), &basePoints, stealer); - if(!new_aur) - continue; - - // set its duration and maximum duration - // max duration 2 minutes (in msecs) - int32 dur = aur->GetAuraDuration(); - const int32 max_dur = 2*MINUTE*1000; - new_aur->SetAuraMaxDuration( max_dur > dur ? dur : max_dur ); - new_aur->SetAuraDuration( max_dur > dur ? dur : max_dur ); - - // add the new aura to stealer - stealer->AddAura(new_aur); - - // Remove aura as dispel - RemoveAura(iter, AURA_REMOVE_BY_DISPEL); - } - else - ++iter; - } -} - -void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId) -{ - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - if (iter->second->GetId() == spellId) - RemoveAura(iter, AURA_REMOVE_BY_CANCEL); - else - ++iter; - } -} - -void Unit::RemoveAurasWithDispelType( DispelType type ) -{ - // Create dispel mask by dispel type - uint32 dispelMask = GetDispellMask(type); - // Dispel all existing auras vs current dispel type - AuraMap& auras = GetAuras(); - for(AuraMap::iterator itr = auras.begin(); itr != auras.end(); ) - { - SpellEntry const* spell = itr->second->GetSpellProto(); - if( (1<Dispel) & dispelMask ) - { - // Dispel aura - RemoveAurasDueToSpell(spell->Id); - itr = auras.begin(); - } - else - ++itr; - } -} - -void Unit::RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex) -{ - AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); - if(iter != m_Auras.end()) - RemoveAura(iter); -} - -void Unit::RemoveAurasDueToSpell(uint32 spellId, Aura* except) -{ - for (int i = 0; i < 3; ++i) - RemoveAura(spellId,i,except); -} - -void Unit::RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId) -{ - for (int k=0; k < 3; ++k) - { - spellEffectPair spair = spellEffectPair(spellId, k); - for (AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) - { - if (iter->second->GetCastItemGUID() == castItem->GetGUID()) - { - RemoveAura(iter); - iter = m_Auras.upper_bound(spair); // overwrite by more appropriate - } - else - ++iter; - } - } -} - -void Unit::RemoveNotOwnSingleTargetAuras() -{ - // single target auras from other casters - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - if (iter->second->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter->second->GetSpellProto())) - RemoveAura(iter); - else - ++iter; - } - - // single target auras at other targets - AuraList& scAuras = GetSingleCastAuras(); - for (AuraList::iterator iter = scAuras.begin(); iter != scAuras.end(); ) - { - Aura* aura = *iter; - if (aura->GetTarget()!=this) - { - scAuras.erase(iter); // explicitly remove, instead waiting remove in RemoveAura - aura->GetTarget()->RemoveAura(aura->GetId(),aura->GetEffIndex()); - iter = scAuras.begin(); - } - else - ++iter; - } - -} - -void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) -{ - if (IsSingleTargetSpell((*i).second->GetSpellProto())) - { - if(Unit* caster = (*i).second->GetCaster()) - { - AuraList& scAuras = caster->GetSingleCastAuras(); - scAuras.remove((*i).second); - } - else - { - sLog.outError("Couldn't find the caster of the single target aura, may crash later!"); - assert(false); - } - } - - if ((*i).second->GetModifier()->m_auraname < TOTAL_AURAS) - { - m_modAuras[(*i).second->GetModifier()->m_auraname].remove((*i).second); - if((*i).second->GetSpellProto()->AuraInterruptFlags) - { - m_interruptableAuras.remove((*i).second); - UpdateInterruptMask(); - } - if((*i).second->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) - m_ccAuras.remove((*i).second); - } - - // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) - Aura* Aur = i->second; - // Set remove mode - Aur->SetRemoveMode(mode); - // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura - // remove aura from list before to prevent deleting it before - m_Auras.erase(i); - ++m_removedAuras; // internal count used by unit update - - // Status unsummoned at aura remove - Totem* statue = NULL; - if(IsChanneledSpell(Aur->GetSpellProto())) - if(Unit* caster = Aur->GetCaster()) - if(caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->isTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE) - statue = ((Totem*)caster); - - - if(const std::vector *spell_triggered = spellmgr.GetSpellLinked(-(int32)Aur->GetSpellProto()->Id)) - { - for(std::vector::const_iterator i = spell_triggered->begin(); i != spell_triggered->end(); ++i) - { - if(spell_triggered < 0) - RemoveAurasDueToSpell(-(*i)); - else if(Unit* caster = Aur->GetCaster()) - CastSpell(this, *i, true, 0, 0, caster->GetGUID()); - } - } - - sLog.outDebug("Aura %u now is remove mode %d",Aur->GetModifier()->m_auraname, mode); - Aur->ApplyModifier(false,true); - Aur->_RemoveAura(); - delete Aur; - - if(statue) - statue->UnSummon(); - - // only way correctly remove all auras from list - if( m_Auras.empty() ) - i = m_Auras.end(); - else - i = m_Auras.begin(); -} - -void Unit::RemoveAllAuras() -{ - while (!m_Auras.empty()) - { - AuraMap::iterator iter = m_Auras.begin(); - RemoveAura(iter); - } -} - -void Unit::RemoveArenaAuras(bool onleave) -{ - // in join, remove positive buffs, on end, remove negative - // used to remove positive visible auras in arenas - for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) - { - if ( !(iter->second->GetSpellProto()->AttributesEx4 & (1<<21)) // don't remove stances, shadowform, pally/hunter auras - && !iter->second->IsPassive() // don't remove passive auras - && (!(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) || !(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNK8)) // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable) - && (iter->second->IsPositive() ^ onleave)) // remove positive buffs on enter, negative buffs on leave - RemoveAura(iter); - else - ++iter; - } -} - -void Unit::RemoveAllAurasOnDeath() -{ - // used just after dieing to remove all visible auras - // and disable the mods for the passive ones - for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) - { - if (!iter->second->IsPassive() && !iter->second->IsDeathPersistent()) - RemoveAura(iter, AURA_REMOVE_BY_DEATH); - else - ++iter; - } -} - -void Unit::DelayAura(uint32 spellId, uint32 effindex, int32 delaytime) -{ - AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); - if (iter != m_Auras.end()) - { - if (iter->second->GetAuraDuration() < delaytime) - iter->second->SetAuraDuration(0); - else - iter->second->SetAuraDuration(iter->second->GetAuraDuration() - delaytime); - iter->second->UpdateAuraDuration(); - sLog.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter->second->GetModifier()->m_auraname, GetGUIDLow(), iter->second->GetAuraDuration()); - } -} - -void Unit::_RemoveAllAuraMods() -{ - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) - { - (*i).second->ApplyModifier(false); - } -} - -void Unit::_ApplyAllAuraMods() -{ - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) - { - (*i).second->ApplyModifier(true); - } -} - -Aura* Unit::GetAura(uint32 spellId, uint32 effindex) -{ - AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); - if (iter != m_Auras.end()) - return iter->second; - return NULL; -} - -void Unit::AddDynObject(DynamicObject* dynObj) -{ - m_dynObjGUIDs.push_back(dynObj->GetGUID()); -} - -void Unit::RemoveDynObject(uint32 spellid) -{ - if(m_dynObjGUIDs.empty()) - return; - for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(!dynObj) - { - i = m_dynObjGUIDs.erase(i); - } - else if(spellid == 0 || dynObj->GetSpellId() == spellid) - { - dynObj->Delete(); - i = m_dynObjGUIDs.erase(i); - } - else - ++i; - } -} - -void Unit::RemoveAllDynObjects() -{ - while(!m_dynObjGUIDs.empty()) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(dynObj) - dynObj->Delete(); - m_dynObjGUIDs.erase(m_dynObjGUIDs.begin()); - } -} - -DynamicObject * Unit::GetDynObject(uint32 spellId, uint32 effIndex) -{ - for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(!dynObj) - { - i = m_dynObjGUIDs.erase(i); - continue; - } - - if (dynObj->GetSpellId() == spellId && dynObj->GetEffIndex() == effIndex) - return dynObj; - ++i; - } - return NULL; -} - -DynamicObject * Unit::GetDynObject(uint32 spellId) -{ - for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(!dynObj) - { - i = m_dynObjGUIDs.erase(i); - continue; - } - - if (dynObj->GetSpellId() == spellId) - return dynObj; - ++i; - } - return NULL; -} - -void Unit::AddGameObject(GameObject* gameObj) -{ - assert(gameObj && gameObj->GetOwnerGUID()==0); - m_gameObj.push_back(gameObj); - gameObj->SetOwnerGUID(GetGUID()); -} - -void Unit::RemoveGameObject(GameObject* gameObj, bool del) -{ - assert(gameObj && gameObj->GetOwnerGUID()==GetGUID()); - - // GO created by some spell - if ( GetTypeId()==TYPEID_PLAYER && gameObj->GetSpellId() ) - { - SpellEntry const* createBySpell = sSpellStore.LookupEntry(gameObj->GetSpellId()); - // Need activate spell use for owner - if (createBySpell && createBySpell->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) - ((Player*)this)->SendCooldownEvent(createBySpell); - } - gameObj->SetOwnerGUID(0); - m_gameObj.remove(gameObj); - if(del) - { - gameObj->SetRespawnTime(0); - gameObj->Delete(); - } -} - -void Unit::RemoveGameObject(uint32 spellid, bool del) -{ - if(m_gameObj.empty()) - return; - std::list::iterator i, next; - for (i = m_gameObj.begin(); i != m_gameObj.end(); i = next) - { - next = i; - if(spellid == 0 || (*i)->GetSpellId() == spellid) - { - (*i)->SetOwnerGUID(0); - if(del) - { - (*i)->SetRespawnTime(0); - (*i)->Delete(); - } - - next = m_gameObj.erase(i); - } - else - ++next; - } -} - -void Unit::RemoveAllGameObjects() -{ - // remove references to unit - for(std::list::iterator i = m_gameObj.begin(); i != m_gameObj.end();) - { - (*i)->SetOwnerGUID(0); - (*i)->SetRespawnTime(0); - (*i)->Delete(); - i = m_gameObj.erase(i); - } -} - -void Unit::SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID,uint32 Damage, SpellSchoolMask damageSchoolMask,uint32 AbsorbedDamage, uint32 Resist,bool PhysicalDamage, uint32 Blocked, bool CriticalHit) -{ - sLog.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG"); - WorldPacket data(SMSG_SPELLNONMELEEDAMAGELOG, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size - data.append(target->GetPackGUID()); - data.append(GetPackGUID()); - data << uint32(SpellID); - data << uint32(Damage-AbsorbedDamage-Resist-Blocked); - data << uint8(damageSchoolMask); // spell school - data << uint32(AbsorbedDamage); // AbsorbedDamage - data << uint32(Resist); // resist - data << uint8(PhysicalDamage); // if 1, then client show spell name (example: %s's ranged shot hit %s for %u school or %s suffers %u school damage from %s's spell_name - data << uint8(0); // unk isFromAura - data << uint32(Blocked); // blocked - data << uint32(CriticalHit ? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster? - data << uint8(0); // isDebug? - SendMessageToSet( &data, true ); -} - -void Unit::SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo) -{ - WorldPacket data(SMSG_SPELLLOGMISS, (4+8+1+4+8+1)); - data << uint32(spellID); - data << uint64(GetGUID()); - data << uint8(0); // can be 0 or 1 - data << uint32(1); // target count - // for(i = 0; i < target count; ++i) - data << uint64(target->GetGUID()); // target GUID - data << uint8(missInfo); - // end loop - SendMessageToSet(&data, true); -} - -void Unit::SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount) -{ - sLog.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE"); - - WorldPacket data(SMSG_ATTACKERSTATEUPDATE, (16+45)); // we guess size - data << (uint32)HitInfo; - data.append(GetPackGUID()); - data.append(target->GetPackGUID()); - data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); - - data << (uint8)SwingType; // count? - - // for(i = 0; i < SwingType; ++i) - data << (uint32)damageSchoolMask; - data << (float)(Damage-AbsorbDamage-Resist-BlockedAmount); - // still need to double check damage - data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); - data << (uint32)AbsorbDamage; - data << (uint32)Resist; - // end loop - - data << (uint32)TargetState; - - if( AbsorbDamage == 0 ) //also 0x3E8 = 0x3E8, check when that happens - data << (uint32)0; - else - data << (uint32)-1; - - data << (uint32)0; - data << (uint32)BlockedAmount; - - SendMessageToSet( &data, true ); -} - -void Unit::ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const *procSpell, bool isTriggeredSpell, WeaponAttackType attType) -{ - sLog.outDebug("ProcDamageAndSpell: attacker flags are 0x%x, victim flags 0x%x", procAttacker, procVictim); - if(procSpell) - sLog.outDebug("ProcDamageAndSpell: invoked due to spell id %u %s", procSpell->Id, (isTriggeredSpell?"(triggered)":"")); - - // Assign melee/ranged proc flags for magic attacks, that are actually melee/ranged abilities - // not assign for spell proc triggered spell to prevent infinity (or unexpected 2-3 times) melee damage spell proc call with melee damage effect - // That is the question though if it's fully correct - if(procSpell && !isTriggeredSpell) - { - if(procSpell->DmgClass == SPELL_DAMAGE_CLASS_MELEE) - { - if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_MELEE; - if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_MELEE; - if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_MELEE; - if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_MELEE; - attType = BASE_ATTACK; // Melee abilities are assumed to be dealt with mainhand weapon - } - else if (procSpell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) - { - if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_RANGED; - if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_RANGED; - if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_RANGED; - if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_RANGED; - attType = RANGED_ATTACK; - } - } - if(damage && (procVictim & (PROC_FLAG_STRUCK_MELEE|PROC_FLAG_STRUCK_RANGED|PROC_FLAG_STRUCK_SPELL))) - procVictim |= (PROC_FLAG_TAKE_DAMAGE|PROC_FLAG_TOUCH); - - // Not much to do if no flags are set. - if (procAttacker) - { - // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set - ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcEffectAuraTypes,attType, procSpell, damage, damageSchoolMask); - ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcCastAuraTypes,attType, procSpell, damage, damageSchoolMask); - } - - // Now go on with a victim's events'n'auras - // Not much to do if no flags are set or there is no victim - if(pVictim && pVictim->isAlive() && procVictim) - { - // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set - pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcEffectAuraTypes,attType,procSpell, damage, damageSchoolMask); - pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcCastAuraTypes,attType,procSpell, damage, damageSchoolMask); - } -} - -void Unit::CastMeleeProcDamageAndSpell(Unit* pVictim, uint32 damage, SpellSchoolMask damageSchoolMask, WeaponAttackType attType, MeleeHitOutcome outcome, SpellEntry const *spellCasted, bool isTriggeredSpell) -{ - if(!pVictim) - return; - - uint32 procAttacker = PROC_FLAG_NONE; - uint32 procVictim = PROC_FLAG_NONE; - - switch(outcome) - { - case MELEE_HIT_EVADE: - return; - case MELEE_HIT_MISS: - if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_MISS; - } - break; - case MELEE_HIT_BLOCK_CRIT: - case MELEE_HIT_CRIT: - if(spellCasted && attType == BASE_ATTACK) - { - procAttacker |= PROC_FLAG_CRIT_SPELL; - procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; - if ( outcome == MELEE_HIT_BLOCK_CRIT ) - { - procVictim |= PROC_FLAG_BLOCK; - procAttacker |= PROC_FLAG_TARGET_BLOCK; - } - } - else if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; - procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; - } - else - { - procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; - procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; - } - break; - case MELEE_HIT_PARRY: - procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; - procVictim = PROC_FLAG_PARRY; - break; - case MELEE_HIT_BLOCK: - procAttacker = PROC_FLAG_TARGET_BLOCK; - procVictim = PROC_FLAG_BLOCK; - break; - case MELEE_HIT_DODGE: - procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; - procVictim = PROC_FLAG_DODGE; - break; - case MELEE_HIT_CRUSHING: - if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; - procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; - } - else - { - procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; - procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; - } - break; - default: - if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_HIT_MELEE; - procVictim = PROC_FLAG_STRUCK_MELEE; - } - else - { - procAttacker = PROC_FLAG_HIT_RANGED; - procVictim = PROC_FLAG_STRUCK_RANGED; - } - break; - } - - if(damage > 0) - procVictim |= PROC_FLAG_TAKE_DAMAGE; - - if(procAttacker != PROC_FLAG_NONE || procVictim != PROC_FLAG_NONE) - ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, damageSchoolMask, spellCasted, isTriggeredSpell, attType); -} - -bool Unit::HandleHasteAuraProc(Unit *pVictim, SpellEntry const *hasteSpell, uint32 /*effIndex*/, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 /*procFlag*/, uint32 cooldown) -{ - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = 0; - Unit* target = pVictim; - int32 basepoints0 = 0; - - switch(hasteSpell->SpellFamilyName) - { - case SPELLFAMILY_ROGUE: - { - switch(hasteSpell->Id) - { - // Blade Flurry - case 13877: - case 33735: - { - target = SelectNearbyTarget(); - if(!target) - return false; - basepoints0 = damage; - triggered_spell_id = 22482; - break; - } - } - break; - } - } - - // processed charge only counting case - if(!triggered_spell_id) - return true; - - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell->Id,triggered_spell_id); - return false; - } - - // default case - if(!target || target!=this && !target->isAlive()) - return false; - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - if(basepoints0) - CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - else - CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -bool Unit::HandleDummyAuraProc(Unit *pVictim, SpellEntry const *dummySpell, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) -{ - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = 0; - Unit* target = pVictim; - int32 basepoints0 = 0; - - switch(dummySpell->SpellFamilyName) - { - case SPELLFAMILY_GENERIC: - { - switch (dummySpell->Id) - { - // Eye of Eye - case 9799: - case 25988: - { - // prevent damage back from weapon special attacks - if (!procSpell || procSpell->DmgClass != SPELL_DAMAGE_CLASS_MAGIC ) - return false; - - // return damage % to attacker but < 50% own total health - basepoints0 = triggeredByAura->GetModifier()->m_amount*int32(damage)/100; - if(basepoints0 > GetMaxHealth()/2) - basepoints0 = GetMaxHealth()/2; - - triggered_spell_id = 25997; - break; - } - // Sweeping Strikes - case 12328: - case 18765: - case 35429: - { - // prevent chain of triggered spell from same triggered spell - if(procSpell && procSpell->Id==26654) - return false; - - target = SelectNearbyTarget(); - if(!target) - return false; - - triggered_spell_id = 26654; - break; - } - // Unstable Power - case 24658: - { - if (!procSpell || procSpell->Id == 24659) - return false; - // Need remove one 24659 aura - RemoveSingleAuraFromStack(24659, 0); - RemoveSingleAuraFromStack(24659, 1); - return true; - } - // Restless Strength - case 24661: - { - // Need remove one 24662 aura - RemoveSingleAuraFromStack(24662, 0); - return true; - } - // Adaptive Warding (Frostfire Regalia set) - case 28764: - { - if(!procSpell) - return false; - - // find Mage Armor - bool found = false; - AuraList const& mRegenInterupt = GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT); - for(AuraList::const_iterator iter = mRegenInterupt.begin(); iter != mRegenInterupt.end(); ++iter) - { - if(SpellEntry const* iterSpellProto = (*iter)->GetSpellProto()) - { - if(iterSpellProto->SpellFamilyName==SPELLFAMILY_MAGE && (iterSpellProto->SpellFamilyFlags & 0x10000000)) - { - found=true; - break; - } - } - } - if(!found) - return false; - - switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) - { - case SPELL_SCHOOL_NORMAL: - case SPELL_SCHOOL_HOLY: - return false; // ignored - case SPELL_SCHOOL_FIRE: triggered_spell_id = 28765; break; - case SPELL_SCHOOL_NATURE: triggered_spell_id = 28768; break; - case SPELL_SCHOOL_FROST: triggered_spell_id = 28766; break; - case SPELL_SCHOOL_SHADOW: triggered_spell_id = 28769; break; - case SPELL_SCHOOL_ARCANE: triggered_spell_id = 28770; break; - default: - return false; - } - - target = this; - break; - } - // Obsidian Armor (Justice Bearer`s Pauldrons shoulder) - case 27539: - { - if(!procSpell) - return false; - - // not from DoT - bool found = false; - for(int j = 0; j < 3; ++j) - { - if(procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE||procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT) - { - found = true; - break; - } - } - if(found) - return false; - - switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) - { - case SPELL_SCHOOL_NORMAL: - return false; // ignore - case SPELL_SCHOOL_HOLY: triggered_spell_id = 27536; break; - case SPELL_SCHOOL_FIRE: triggered_spell_id = 27533; break; - case SPELL_SCHOOL_NATURE: triggered_spell_id = 27538; break; - case SPELL_SCHOOL_FROST: triggered_spell_id = 27534; break; - case SPELL_SCHOOL_SHADOW: triggered_spell_id = 27535; break; - case SPELL_SCHOOL_ARCANE: triggered_spell_id = 27540; break; - default: - return false; - } - - target = this; - break; - } - // Mana Leech (Passive) (Priest Pet Aura) - case 28305: - { - // Cast on owner - target = GetOwner(); - if(!target) - return false; - - basepoints0 = int32(damage * 2.5f); // manaregen - triggered_spell_id = 34650; - break; - } - // Mark of Malice - case 33493: - { - // Cast finish spell at last charge - if (triggeredByAura->m_procCharges > 1) - return false; - - target = this; - triggered_spell_id = 33494; - break; - } - // Twisted Reflection (boss spell) - case 21063: - triggered_spell_id = 21064; - break; - // Vampiric Aura (boss spell) - case 38196: - { - basepoints0 = 3 * damage; // 300% - if (basepoints0 < 0) - return false; - - triggered_spell_id = 31285; - target = this; - break; - } - // Aura of Madness (Darkmoon Card: Madness trinket) - //===================================================== - // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior) - // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid) - // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid) - // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin) - // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes) - // 41005 Manic: +35 haste (spell, melee and ranged) (All classes) - // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter) - // 41011 Martyr Complex: +35 stamina (All classes) - // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) - // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) - case 39446: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Select class defined buff - switch (getClass()) - { - case CLASS_PALADIN: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 - case CLASS_DRUID: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 - { - uint32 RandomSpell[]={39511,40997,40998,40999,41002,41005,41009,41011,41409}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - case CLASS_ROGUE: // 39511,40997,40998,41002,41005,41011 - case CLASS_WARRIOR: // 39511,40997,40998,41002,41005,41011 - { - uint32 RandomSpell[]={39511,40997,40998,41002,41005,41011}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - case CLASS_PRIEST: // 40999,41002,41005,41009,41011,41406,41409 - case CLASS_SHAMAN: // 40999,41002,41005,41009,41011,41406,41409 - case CLASS_MAGE: // 40999,41002,41005,41009,41011,41406,41409 - case CLASS_WARLOCK: // 40999,41002,41005,41009,41011,41406,41409 - { - uint32 RandomSpell[]={40999,41002,41005,41009,41011,41406,41409}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - case CLASS_HUNTER: // 40997,40999,41002,41005,41009,41011,41406,41409 - { - uint32 RandomSpell[]={40997,40999,41002,41005,41009,41011,41406,41409}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - default: - return false; - } - - target = this; - if (roll_chance_i(10)) - ((Player*)this)->Say("This is Madness!", LANG_UNIVERSAL); - break; - } - /* - // TODO: need find item for aura and triggered spells - // Sunwell Exalted Caster Neck (??? neck) - // cast ??? Light's Wrath if Exalted by Aldor - // cast ??? Arcane Bolt if Exalted by Scryers*/ - case 46569: - return false; // disable for while - /* - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = ??? - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = ??? - break; - } - return false; - }/**/ - // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck) - // cast 45479 Light's Wrath if Exalted by Aldor - // cast 45429 Arcane Bolt if Exalted by Scryers - case 45481: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45479; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = 45429; - break; - } - return false; - } - // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck) - // cast 45480 Light's Strength if Exalted by Aldor - // cast 45428 Arcane Strike if Exalted by Scryers - case 45482: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45480; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = 45428; - break; - } - return false; - } - // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck) - // cast 45431 Arcane Insight if Exalted by Aldor - // cast 45432 Light's Ward if Exalted by Scryers - case 45483: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45432; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45431; - break; - } - return false; - } - // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck) - // cast 45478 Light's Salvation if Exalted by Aldor - // cast 45430 Arcane Surge if Exalted by Scryers - case 45484: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45478; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = 45430; - break; - } - return false; - } - } - break; - } - case SPELLFAMILY_MAGE: - { - // Magic Absorption - if (dummySpell->SpellIconID == 459) // only this spell have SpellIconID == 459 and dummy aura - { - if (getPowerType() != POWER_MANA) - return false; - - // mana reward - basepoints0 = (triggeredByAura->GetModifier()->m_amount * GetMaxPower(POWER_MANA) / 100); - target = this; - triggered_spell_id = 29442; - break; - } - // Master of Elements - if (dummySpell->SpellIconID == 1920) - { - if(!procSpell) - return false; - - // mana cost save - basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; - if( basepoints0 <=0 ) - return false; - - target = this; - triggered_spell_id = 29077; - break; - } - switch(dummySpell->Id) - { - // Ignite - case 11119: - case 11120: - case 12846: - case 12847: - case 12848: - { - switch (dummySpell->Id) - { - case 11119: basepoints0 = int32(0.04f*damage); break; - case 11120: basepoints0 = int32(0.08f*damage); break; - case 12846: basepoints0 = int32(0.12f*damage); break; - case 12847: basepoints0 = int32(0.16f*damage); break; - case 12848: basepoints0 = int32(0.20f*damage); break; - default: - sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell->Id); - return false; - } - - triggered_spell_id = 12654; - break; - } - // Combustion - case 11129: - { - //last charge and crit - if( triggeredByAura->m_procCharges <= 1 && (procFlag & PROC_FLAG_CRIT_SPELL) ) - { - RemoveAurasDueToSpell(28682); //-> remove Combustion auras - return true; // charge counting (will removed) - } - - CastSpell(this, 28682, true, castItem, triggeredByAura); - return(procFlag & PROC_FLAG_CRIT_SPELL);// charge update only at crit hits, no hidden cooldowns - } - } - break; - } - case SPELLFAMILY_WARRIOR: - { - // Retaliation - if(dummySpell->SpellFamilyFlags==0x0000000800000000LL) - { - // check attack comes not from behind - if (!HasInArc(M_PI, pVictim)) - return false; - - triggered_spell_id = 22858; - break; - } - break; - } - case SPELLFAMILY_WARLOCK: - { - // Seed of Corruption - if (dummySpell->SpellFamilyFlags & 0x0000001000000000LL) - { - Modifier* mod = triggeredByAura->GetModifier(); - // if damage is more than need or target die from damage deal finish spell - // FIX ME: not triggered currently at death - if( mod->m_amount <= damage || GetHealth() <= damage ) - { - // remember guid before aura delete - uint64 casterGuid = triggeredByAura->GetCasterGUID(); - - // Remove aura (before cast for prevent infinite loop handlers) - RemoveAurasDueToSpell(triggeredByAura->GetId()); - - // Cast finish spell (triggeredByAura already not exist!) - if(Unit* caster = GetUnit(*this, casterGuid)) - caster->CastSpell(this, 27285, true, castItem); - return true; // no hidden cooldown - } - - // Damage counting - mod->m_amount-=damage; - return true; - } - // Seed of Corruption (Mobs cast) - no die req - if (dummySpell->SpellFamilyFlags == 0x00LL && dummySpell->SpellIconID == 1932) - { - Modifier* mod = triggeredByAura->GetModifier(); - // if damage is more than need deal finish spell - if( mod->m_amount <= damage ) - { - // remember guid before aura delete - uint64 casterGuid = triggeredByAura->GetCasterGUID(); - - // Remove aura (before cast for prevent infinite loop handlers) - RemoveAurasDueToSpell(triggeredByAura->GetId()); - - // Cast finish spell (triggeredByAura already not exist!) - if(Unit* caster = GetUnit(*this, casterGuid)) - caster->CastSpell(this, 32865, true, castItem); - return true; // no hidden cooldown - } - // Damage counting - mod->m_amount-=damage; - return true; - } - switch(dummySpell->Id) - { - // Nightfall - case 18094: - case 18095: - { - target = this; - triggered_spell_id = 17941; - break; - } - //Soul Leech - case 30293: - case 30295: - case 30296: - { - // health - basepoints0 = int32(damage*triggeredByAura->GetModifier()->m_amount/100); - target = this; - triggered_spell_id = 30294; - break; - } - // Shadowflame (Voidheart Raiment set bonus) - case 37377: - { - triggered_spell_id = 37379; - break; - } - // Pet Healing (Corruptor Raiment or Rift Stalker Armor) - case 37381: - { - target = GetPet(); - if(!target) - return false; - - // heal amount - basepoints0 = damage * triggeredByAura->GetModifier()->m_amount/100; - triggered_spell_id = 37382; - break; - } - // Shadowflame Hellfire (Voidheart Raiment set bonus) - case 39437: - { - triggered_spell_id = 37378; - break; - } - } - break; - } - case SPELLFAMILY_PRIEST: - { - // Vampiric Touch - if( dummySpell->SpellFamilyFlags & 0x0000040000000000LL ) - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // pVictim is caster of aura - if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) - return false; - - // energize amount - basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; - pVictim->CastCustomSpell(pVictim,34919,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - return true; // no hidden cooldown - } - switch(dummySpell->Id) - { - // Vampiric Embrace - case 15286: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // pVictim is caster of aura - if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) - return false; - - // heal amount - basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; - pVictim->CastCustomSpell(pVictim,15290,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - return true; // no hidden cooldown - } - // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen) - case 40438: - { - // Shadow Word: Pain - if( procSpell->SpellFamilyFlags & 0x0000000000008000LL ) - triggered_spell_id = 40441; - // Renew - else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) - triggered_spell_id = 40440; - else - return false; - - target = this; - break; - } - // Oracle Healing Bonus ("Garments of the Oracle" set) - case 26169: - { - // heal amount - basepoints0 = int32(damage * 10/100); - target = this; - triggered_spell_id = 26170; - break; - } - // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set - case 39372: - { - if(!procSpell || (GetSpellSchoolMask(procSpell) & (SPELL_SCHOOL_MASK_FROST | SPELL_SCHOOL_MASK_SHADOW))==0 ) - return false; - - // heal amount - basepoints0 = int32(damage * 2 / 100); - target = this; - triggered_spell_id = 39373; - break; - } - // Vestments of Faith (Priest Tier 3) - 4 pieces bonus - case 28809: - { - triggered_spell_id = 28810; - break; - } - } - break; - } - case SPELLFAMILY_DRUID: - { - switch(dummySpell->Id) - { - // Healing Touch (Dreamwalker Raiment set) - case 28719: - { - // mana back - basepoints0 = int32(procSpell->manaCost * 30 / 100); - target = this; - triggered_spell_id = 28742; - break; - } - // Healing Touch Refund (Idol of Longevity trinket) - case 28847: - { - target = this; - triggered_spell_id = 28848; - break; - } - // Mana Restore (Malorne Raiment set / Malorne Regalia set) - case 37288: - case 37295: - { - target = this; - triggered_spell_id = 37238; - break; - } - // Druid Tier 6 Trinket - case 40442: - { - float chance; - - // Starfire - if( procSpell->SpellFamilyFlags & 0x0000000000000004LL ) - { - triggered_spell_id = 40445; - chance = 25.f; - } - // Rejuvenation - else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) - { - triggered_spell_id = 40446; - chance = 25.f; - } - // Mangle (cat/bear) - else if( procSpell->SpellFamilyFlags & 0x0000044000000000LL ) - { - triggered_spell_id = 40452; - chance = 40.f; - } - else - return false; - - if (!roll_chance_f(chance)) - return false; - - target = this; - break; - } - // Maim Interrupt - case 44835: - { - // Deadly Interrupt Effect - triggered_spell_id = 32747; - break; - } - } - break; - } - case SPELLFAMILY_ROGUE: - { - switch(dummySpell->Id) - { - // Deadly Throw Interrupt - case 32748: - { - // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw - if(this == pVictim) - return false; - - triggered_spell_id = 32747; - break; - } - } - // Quick Recovery - if( dummySpell->SpellIconID == 2116 ) - { - if(!procSpell) - return false; - - // only rogue's finishing moves (maybe need additional checks) - if( procSpell->SpellFamilyName!=SPELLFAMILY_ROGUE || - (procSpell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE) == 0) - return false; - - // energy cost save - basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; - if(basepoints0 <= 0) - return false; - - target = this; - triggered_spell_id = 31663; - break; - } - break; - } - case SPELLFAMILY_HUNTER: - { - // Thrill of the Hunt - if ( dummySpell->SpellIconID == 2236 ) - { - if(!procSpell) - return false; - - // mana cost save - basepoints0 = procSpell->manaCost * 40/100; - if(basepoints0 <= 0) - return false; - - target = this; - triggered_spell_id = 34720; - break; - } - break; - } - case SPELLFAMILY_PALADIN: - { - // Seal of Righteousness - melee proc dummy - if (dummySpell->SpellFamilyFlags&0x000000008000000LL && triggeredByAura->GetEffIndex()==0) - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - uint32 spellId; - switch (triggeredByAura->GetId()) - { - case 21084: spellId = 25742; break; // Rank 1 - case 20287: spellId = 25740; break; // Rank 2 - case 20288: spellId = 25739; break; // Rank 3 - case 20289: spellId = 25738; break; // Rank 4 - case 20290: spellId = 25737; break; // Rank 5 - case 20291: spellId = 25736; break; // Rank 6 - case 20292: spellId = 25735; break; // Rank 7 - case 20293: spellId = 25713; break; // Rank 8 - case 27155: spellId = 27156; break; // Rank 9 - default: - sLog.outError("Unit::HandleDummyAuraProc: non handled possibly SoR (Id = %u)", triggeredByAura->GetId()); - return false; - } - Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - float speed = (item ? item->GetProto()->Delay : BASE_ATTACK_TIME)/1000.0f; - - float damageBasePoints; - if(item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) - // two hand weapon - damageBasePoints=1.20f*triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f + 1; - else - // one hand weapon/no weapon - damageBasePoints=0.85f*ceil(triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f) - 1; - - int32 damagePoint = int32(damageBasePoints + 0.03f * (GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE)+GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE))/2.0f) + 1; - - // apply damage bonuses manually - if(damagePoint >= 0) - damagePoint = SpellDamageBonus(pVictim, dummySpell, damagePoint, SPELL_DIRECT_DAMAGE); - - CastCustomSpell(pVictim,spellId,&damagePoint,NULL,NULL,true,NULL, triggeredByAura); - return true; // no hidden cooldown - } - // Seal of Blood do damage trigger - if(dummySpell->SpellFamilyFlags & 0x0000040000000000LL) - { - switch(triggeredByAura->GetEffIndex()) - { - case 0: - // prevent chain triggering - if(procSpell && procSpell->Id==31893 ) - return false; - - triggered_spell_id = 31893; - break; - case 1: - { - // damage - basepoints0 = triggeredByAura->GetModifier()->m_amount * damage / 100; - target = this; - triggered_spell_id = 32221; - break; - } - } - } - - switch(dummySpell->Id) - { - // Holy Power (Redemption Armor set) - case 28789: - { - if(!pVictim) - return false; - - // Set class defined buff - switch (pVictim->getClass()) - { - case CLASS_PALADIN: - case CLASS_PRIEST: - case CLASS_SHAMAN: - case CLASS_DRUID: - triggered_spell_id = 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. - break; - case CLASS_MAGE: - case CLASS_WARLOCK: - triggered_spell_id = 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d. - break; - case CLASS_HUNTER: - case CLASS_ROGUE: - triggered_spell_id = 28791; // Increases the friendly target's attack power by $s1 for $d. - break; - case CLASS_WARRIOR: - triggered_spell_id = 28790; // Increases the friendly target's armor - break; - default: - return false; - } - break; - } - //Seal of Vengeance - case 31801: - { - if(effIndex != 0) // effect 1,2 used by seal unleashing code - return false; - - triggered_spell_id = 31803; - break; - } - // Spiritual Att. - case 31785: - case 33776: - { - // if healed by another unit (pVictim) - if(this == pVictim) - return false; - - // heal amount - basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; - target = this; - triggered_spell_id = 31786; - break; - } - // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal) - case 40470: - { - if( !procSpell ) - return false; - - float chance; - - // Flash of light/Holy light - if( procSpell->SpellFamilyFlags & 0x00000000C0000000LL) - { - triggered_spell_id = 40471; - chance = 15.f; - } - // Judgement - else if( procSpell->SpellFamilyFlags & 0x0000000000800000LL ) - { - triggered_spell_id = 40472; - chance = 50.f; - } - else - return false; - - if (!roll_chance_f(chance)) - return false; - - break; - } - } - break; - } - case SPELLFAMILY_SHAMAN: - { - switch(dummySpell->Id) - { - // Totemic Power (The Earthshatterer set) - case 28823: - { - if( !pVictim ) - return false; - - // Set class defined buff - switch (pVictim->getClass()) - { - case CLASS_PALADIN: - case CLASS_PRIEST: - case CLASS_SHAMAN: - case CLASS_DRUID: - triggered_spell_id = 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. - break; - case CLASS_MAGE: - case CLASS_WARLOCK: - triggered_spell_id = 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d. - break; - case CLASS_HUNTER: - case CLASS_ROGUE: - triggered_spell_id = 28826; // Increases the friendly target's attack power by $s1 for $d. - break; - case CLASS_WARRIOR: - triggered_spell_id = 28827; // Increases the friendly target's armor - break; - default: - return false; - } - break; - } - // Lesser Healing Wave (Totem of Flowing Water Relic) - case 28849: - { - target = this; - triggered_spell_id = 28850; - break; - } - // Windfury Weapon (Passive) 1-5 Ranks - case 33757: - { - if(GetTypeId()!=TYPEID_PLAYER) - return false; - - if(!castItem || !castItem->IsEquipped()) - return false; - - // custom cooldown processing case - if( cooldown && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) - return false; - - uint32 spellId; - switch (castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT))) - { - case 283: spellId = 33757; break; //1 Rank - case 284: spellId = 33756; break; //2 Rank - case 525: spellId = 33755; break; //3 Rank - case 1669:spellId = 33754; break; //4 Rank - case 2636:spellId = 33727; break; //5 Rank - default: - { - sLog.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)", - castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT)),dummySpell->Id); - return false; - } - } - - SpellEntry const* windfurySpellEntry = sSpellStore.LookupEntry(spellId); - if(!windfurySpellEntry) - { - sLog.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId); - return false; - } - - int32 extra_attack_power = CalculateSpellDamage(windfurySpellEntry,0,windfurySpellEntry->EffectBasePoints[0],pVictim); - - // Off-Hand case - if ( castItem->GetSlot() == EQUIPMENT_SLOT_OFFHAND ) - { - // Value gained from additional AP - basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(OFF_ATTACK)/1000/2); - triggered_spell_id = 33750; - } - // Main-Hand case - else - { - // Value gained from additional AP - basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(BASE_ATTACK)/1000); - triggered_spell_id = 25504; - } - - // apply cooldown before cast to prevent processing itself - if( cooldown ) - ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); - - // Attack Twice - for ( uint32 i = 0; i<2; ++i ) - CastCustomSpell(pVictim,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - - return true; - } - // Shaman Tier 6 Trinket - case 40463: - { - if( !procSpell ) - return false; - - float chance; - if (procSpell->SpellFamilyFlags & 0x0000000000000001LL) - { - triggered_spell_id = 40465; // Lightning Bolt - chance = 15.f; - } - else if (procSpell->SpellFamilyFlags & 0x0000000000000080LL) - { - triggered_spell_id = 40465; // Lesser Healing Wave - chance = 10.f; - } - else if (procSpell->SpellFamilyFlags & 0x0000001000000000LL) - { - triggered_spell_id = 40466; // Stormstrike - chance = 50.f; - } - else - return false; - - if (!roll_chance_f(chance)) - return false; - - target = this; - break; - } - } - - // Earth Shield - if(dummySpell->SpellFamilyFlags==0x40000000000LL) - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // heal - basepoints0 = triggeredByAura->GetModifier()->m_amount; - target = this; - triggered_spell_id = 379; - break; - } - // Lightning Overload - if (dummySpell->SpellIconID == 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura - { - if(!procSpell || GetTypeId() != TYPEID_PLAYER || !pVictim ) - return false; - - // custom cooldown processing case - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) - return false; - - uint32 spellId = 0; - // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost - switch (procSpell->Id) - { - // Lightning Bolt - case 403: spellId = 45284; break; // Rank 1 - case 529: spellId = 45286; break; // Rank 2 - case 548: spellId = 45287; break; // Rank 3 - case 915: spellId = 45288; break; // Rank 4 - case 943: spellId = 45289; break; // Rank 5 - case 6041: spellId = 45290; break; // Rank 6 - case 10391: spellId = 45291; break; // Rank 7 - case 10392: spellId = 45292; break; // Rank 8 - case 15207: spellId = 45293; break; // Rank 9 - case 15208: spellId = 45294; break; // Rank 10 - case 25448: spellId = 45295; break; // Rank 11 - case 25449: spellId = 45296; break; // Rank 12 - // Chain Lightning - case 421: spellId = 45297; break; // Rank 1 - case 930: spellId = 45298; break; // Rank 2 - case 2860: spellId = 45299; break; // Rank 3 - case 10605: spellId = 45300; break; // Rank 4 - case 25439: spellId = 45301; break; // Rank 5 - case 25442: spellId = 45302; break; // Rank 6 - default: - sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell->Id); - return false; - } - // No thread generated mod - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_THREAT; - mod->value = -100; - mod->type = SPELLMOD_PCT; - mod->spellId = dummySpell->Id; - mod->effectId = 0; - mod->lastAffected = NULL; - mod->mask = 0x0000000000000003LL; - mod->charges = 0; - ((Player*)this)->AddSpellMod(mod, true); - - // Remove cooldown (Chain Lightning - have Category Recovery time) - if (procSpell->SpellFamilyFlags & 0x0000000000000002LL) - ((Player*)this)->RemoveSpellCooldown(spellId); - - // Hmmm.. in most case spells already set half basepoints but... - // Lightning Bolt (2-10 rank) have full basepoint and half bonus from level - // As on wiki: - // BUG: Rank 2 to 10 (and maybe 11) of Lightning Bolt will proc another Bolt with FULL damage (not halved). This bug is known and will probably be fixed soon. - // So - no add changes :) - CastSpell(pVictim, spellId, true, castItem, triggeredByAura); - - ((Player*)this)->AddSpellMod(mod, false); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); - - return true; - } - break; - } - default: - break; - } - - // processed charge only counting case - if(!triggered_spell_id) - return true; - - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell->Id,triggered_spell_id); - return false; - } - - // default case - if(!target || target!=this && !target->isAlive()) - return false; - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - if(basepoints0) - CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - else - CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const *procSpell, uint32 procFlags,WeaponAttackType attackType, uint32 cooldown) -{ - SpellEntry const* auraSpellInfo = triggeredByAura->GetSpellProto(); - - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = auraSpellInfo->EffectTriggerSpell[triggeredByAura->GetEffIndex()]; - Unit* target = !(procFlags & PROC_FLAG_HEAL) && IsPositiveSpell(triggered_spell_id) ? this : pVictim; - int32 basepoints0 = 0; - - switch(auraSpellInfo->SpellFamilyName) - { - case SPELLFAMILY_GENERIC: - { - switch(auraSpellInfo->Id) - { - // Aegis of Preservation - case 23780: - //Aegis Heal (instead non-existed triggered spell) - triggered_spell_id = 23781; - target = this; - break; - // Elune's Touch (moonkin mana restore) - case 24905: - { - // Elune's Touch (instead non-existed triggered spell) - triggered_spell_id = 33926; - basepoints0 = int32(0.3f * GetTotalAttackPowerValue(BASE_ATTACK)); - target = this; - break; - } - // Enlightenment - case 29601: - { - // only for cast with mana price - if(!procSpell || procSpell->powerType!=POWER_MANA || procSpell->manaCost==0 && procSpell->ManaCostPercentage==0 && procSpell->manaCostPerlevel==0) - return false; - break; // fall through to normal cast - } - // Health Restore - case 33510: - { - // at melee hit call std triggered spell - if(procFlags & PROC_FLAG_HIT_MELEE) - break; // fall through to normal cast - - // Mark of Conquest - else (at range hit) called custom case - triggered_spell_id = 39557; - target = this; - break; - } - // Shaleskin - case 36576: - return true; // nothing to do - // Forgotten Knowledge (Blade of Wizardry) - case 38319: - // only for harmful enemy targeted spell - if(!pVictim || pVictim==this || !procSpell || IsPositiveSpell(procSpell->Id)) - return false; - break; // fall through to normal cast - // Aura of Wrath (Darkmoon Card: Wrath trinket bonus) - case 39442: - { - // proc only at non-crit hits - if(procFlags & (PROC_FLAG_CRIT_MELEE|PROC_FLAG_CRIT_RANGED|PROC_FLAG_CRIT_SPELL)) - return false; - break; // fall through to normal cast - } - // Augment Pain (Timbal's Focusing Crystal trinket bonus) - case 45054: - { - if(!procSpell) - return false; - - //only periodic damage can trigger spell - bool found = false; - for(int j = 0; j < 3; ++j) - { - if( procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE || - procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT || - procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_LEECH ) - { - found = true; - break; - } - } - if(!found) - return false; - - break; // fall through to normal cast - } - // Evasive Maneuvers (Commendation of Kael'thas) - case 45057: - { - // damage taken that reduces below 35% health - // does NOT mean you must have been >= 35% before - if (int32(GetHealth())-int32(damage) >= int32(GetMaxHealth()*0.35f)) - return false; - break; // fall through to normal cast - } - } - - switch(triggered_spell_id) - { - // Setup - case 15250: - { - // applied only for main target - if(!pVictim || pVictim != getVictim()) - return false; - - // continue normal case - break; - } - // Shamanistic Rage triggered spell - case 30824: - basepoints0 = int32(GetTotalAttackPowerValue(BASE_ATTACK)*triggeredByAura->GetModifier()->m_amount/100); - break; - } - break; - } - case SPELLFAMILY_MAGE: - { - switch(auraSpellInfo->SpellIconID) - { - // Blazing Speed - case 2127: - //Blazing Speed (instead non-existed triggered spell) - triggered_spell_id = 31643; - target = this; - break; - } - switch(auraSpellInfo->Id) - { - // Persistent Shield (Scarab Brooch) - case 26467: - basepoints0 = int32(damage * 0.15f); - break; - } - break; - } - case SPELLFAMILY_WARRIOR: - { - //Rampage - if((auraSpellInfo->SpellFamilyFlags & 0x100000) && auraSpellInfo->SpellIconID==2006) - { - //all ranks have effect[0]==AURA (Proc Trigger Spell, non-existed) - //and effect[1]==TriggerSpell - if(auraSpellInfo->Effect[1]!=SPELL_EFFECT_TRIGGER_SPELL) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have wrong effect in RM",triggeredByAura->GetSpellProto()->Id); - return false; - } - triggered_spell_id = auraSpellInfo->EffectTriggerSpell[1]; - break; // fall through to normal cast - } - break; - } - case SPELLFAMILY_WARLOCK: - { - // Pyroclasm - if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000 && auraSpellInfo->SpellIconID==1137) - { - // last case for Hellfire that damage caster also but don't must stun caster - if( pVictim == this ) - return false; - - // custom chance - float chance = 0; - switch (triggeredByAura->GetId()) - { - case 18096: chance = 13.0f; break; - case 18073: chance = 26.0f; break; - } - if (!roll_chance_f(chance)) - return false; - - // Pyroclasm (instead non-existed triggered spell) - triggered_spell_id = 18093; - target = pVictim; - break; - } - // Drain Soul - if(auraSpellInfo->SpellFamilyFlags & 0x0000000000004000) - { - bool found = false; - Unit::AuraList const& mAddFlatModifier = GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER); - for(Unit::AuraList::const_iterator i = mAddFlatModifier.begin(); i != mAddFlatModifier.end(); ++i) - { - //Improved Drain Soul - if ((*i)->GetModifier()->m_miscvalue == SPELLMOD_CHANCE_OF_SUCCESS && (*i)->GetSpellProto()->SpellIconID == 113) - { - int32 value2 = CalculateSpellDamage((*i)->GetSpellProto(),2,(*i)->GetSpellProto()->EffectBasePoints[2],this); - basepoints0 = value2 * GetMaxPower(POWER_MANA) / 100; - - // Drain Soul - triggered_spell_id = 18371; - target = this; - found = true; - break; - } - } - if(!found) - return false; - break; // fall through to normal cast - } - break; - } - case SPELLFAMILY_PRIEST: - { - //Blessed Recovery - if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL && auraSpellInfo->SpellIconID==1875) - { - switch (triggeredByAura->GetSpellProto()->Id) - { - case 27811: triggered_spell_id = 27813; break; - case 27815: triggered_spell_id = 27817; break; - case 27816: triggered_spell_id = 27818; break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR",triggeredByAura->GetSpellProto()->Id); - return false; - } - - int32 heal_amount = damage * triggeredByAura->GetModifier()->m_amount / 100; - basepoints0 = heal_amount/3; - target = this; - break; - } - // Shadowguard - if((auraSpellInfo->SpellFamilyFlags & 0x80000000LL) && auraSpellInfo->SpellVisual==7958) - { - switch(triggeredByAura->GetSpellProto()->Id) - { - case 18137: - triggered_spell_id = 28377; break; // Rank 1 - case 19308: - triggered_spell_id = 28378; break; // Rank 2 - case 19309: - triggered_spell_id = 28379; break; // Rank 3 - case 19310: - triggered_spell_id = 28380; break; // Rank 4 - case 19311: - triggered_spell_id = 28381; break; // Rank 5 - case 19312: - triggered_spell_id = 28382; break; // Rank 6 - case 25477: - triggered_spell_id = 28385; break; // Rank 7 - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in SG",triggeredByAura->GetSpellProto()->Id); - return false; - } - target = pVictim; - break; - } - break; - } - case SPELLFAMILY_DRUID: - { - switch(auraSpellInfo->Id) - { - // Leader of the Pack (triggering Improved Leader of the Pack heal) - case 24932: - { - if (triggeredByAura->GetModifier()->m_amount == 0) - return false; - basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; - triggered_spell_id = 34299; - break; - }; - // Druid Forms Trinket (Druid Tier5 Trinket, triggers different spells per Form) - case 37336: - { - switch(m_form) - { - case FORM_BEAR: - case FORM_DIREBEAR: - triggered_spell_id=37340; break;// Ursine Blessing - case FORM_CAT: - triggered_spell_id=37341; break;// Feline Blessing - case FORM_TREE: - triggered_spell_id=37342; break;// Slyvan Blessing - case FORM_MOONKIN: - triggered_spell_id=37343; break;// Lunar Blessing - case FORM_NONE: - triggered_spell_id=37344; break;// Cenarion Blessing (for caster form, except FORM_MOONKIN) - default: - return false; - } - - target = this; - break; - } - } - break; - } - case SPELLFAMILY_ROGUE: - { - if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000LL) - { - switch(auraSpellInfo->SpellIconID) - { - // Combat Potency - case 2260: - { - // skip non offhand attacks - if(attackType!=OFF_ATTACK) - return false; - break; // fall through to normal cast - } - } - } - break; - } - case SPELLFAMILY_PALADIN: - { - if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL) - { - switch(auraSpellInfo->Id) - { - // Lightning Capacitor - case 37657: - { - // trinket ProcTriggerSpell but for safe checks for player - if(!castItem || !pVictim || !pVictim->isAlive() || GetTypeId()!=TYPEID_PLAYER) - return false; - - if(((Player*)this)->HasSpellCooldown(37657)) - return false; - - // stacking - CastSpell(this, 37658, true, castItem, triggeredByAura); - // 2.5s cooldown before it can stack again, current system allow 1 sec step in cooldown - ((Player*)this)->AddSpellCooldown(37657,0,time(NULL)+(roll_chance_i(50) ? 2 : 3)); - - // counting - uint32 count = 0; - AuraList const& dummyAura = GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator itr = dummyAura.begin(); itr != dummyAura.end(); ++itr) - if((*itr)->GetId()==37658) - ++count; - - // release at 3 aura in stack - if(count <= 2) - return true; // main triggered spell casted anyway - - RemoveAurasDueToSpell(37658); - CastSpell(pVictim, 37661, true, castItem, triggeredByAura); - return true; - } - // Healing Discount - case 37705: - // Healing Trance (instead non-existed triggered spell) - triggered_spell_id = 37706; - target = this; - break; - // HoTs on Heals (Fel Reaver's Piston trinket) - case 38299: - { - // at direct heal effect - if(!procSpell || !IsSpellHaveEffect(procSpell,SPELL_EFFECT_HEAL)) - return false; - - // single proc at time - AuraList const& scAuras = GetSingleCastAuras(); - for(AuraList::const_iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) - if((*itr)->GetId()==triggered_spell_id) - return false; - - // positive cast at victim instead self - target = pVictim; - break; - } - } - switch(auraSpellInfo->SpellIconID) - { - case 241: - { - switch(auraSpellInfo->EffectTriggerSpell[0]) - { - //Illumination - case 18350: - { - if(!procSpell) - return false; - - // procspell is triggered spell but we need mana cost of original casted spell - uint32 originalSpellId = procSpell->Id; - - // Holy Shock - if(procSpell->SpellFamilyName == SPELLFAMILY_PALADIN) - { - if(procSpell->SpellFamilyFlags & 0x0001000000000000LL) - { - switch(procSpell->Id) - { - case 25914: originalSpellId = 20473; break; - case 25913: originalSpellId = 20929; break; - case 25903: originalSpellId = 20930; break; - case 27175: originalSpellId = 27174; break; - case 33074: originalSpellId = 33072; break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell->Id); - return false; - } - } - } - - SpellEntry const *originalSpell = sSpellStore.LookupEntry(originalSpellId); - if(!originalSpell) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId); - return false; - } - - // percent stored in effect 1 (class scripts) base points - int32 percent = auraSpellInfo->EffectBasePoints[1]+1; - - basepoints0 = originalSpell->manaCost*percent/100; - triggered_spell_id = 20272; - target = this; - break; - } - } - break; - } - } - } - if(auraSpellInfo->SpellFamilyFlags & 0x00080000) - { - switch(auraSpellInfo->SpellIconID) - { - //Judgement of Wisdom (overwrite non existing triggered spell call in spell.dbc - case 206: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - uint32 spell = 0; - switch(triggeredByAura->GetSpellProto()->Id) - { - case 20186: - triggered_spell_id = 20268; // Rank 1 - break; - case 20354: - triggered_spell_id = 20352; // Rank 2 - break; - case 20355: - triggered_spell_id = 20353; // Rank 3 - break; - case 27164: - triggered_spell_id = 27165; // Rank 4 - break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoW",triggeredByAura->GetSpellProto()->Id); - return false; - } - - pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); - return true; // no hidden cooldown - } - //Judgement of Light - case 299: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // overwrite non existing triggered spell call in spell.dbc - uint32 spell = 0; - switch(triggeredByAura->GetSpellProto()->Id) - { - case 20185: - triggered_spell_id = 20267; // Rank 1 - break; - case 20344: - triggered_spell_id = 20341; // Rank 2 - break; - case 20345: - triggered_spell_id = 20342; // Rank 3 - break; - case 20346: - triggered_spell_id = 20343; // Rank 4 - break; - case 27162: - triggered_spell_id = 27163; // Rank 5 - break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoL",triggeredByAura->GetSpellProto()->Id); - return false; - } - pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); - return true; // no hidden cooldown - } - } - } - // custom check for proc spell - switch(auraSpellInfo->Id) - { - // Bonus Healing (item spell) - case 40971: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // bonus if health < 50% - if(pVictim->GetHealth() >= pVictim->GetMaxHealth()*triggeredByAura->GetModifier()->m_amount/100) - return false; - - // cast at target positive spell - target = pVictim; - break; - } - } - switch(triggered_spell_id) - { - // Seal of Command - case 20424: - // prevent chain of triggered spell from same triggered spell - if(procSpell && procSpell->Id==20424) - return false; - break; - } - break; - } - case SPELLFAMILY_SHAMAN: - { - if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000) - { - switch(auraSpellInfo->SpellIconID) - { - case 19: - { - switch(auraSpellInfo->Id) - { - case 23551: // Lightning Shield - Tier2: 8 pieces proc shield - { - // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) - triggered_spell_id = 23552; - target = pVictim; - break; - } - case 23552: // Lightning Shield - trigger shield damage - { - // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) - triggered_spell_id = 27635; - target = pVictim; - break; - } - } - break; - } - // Mana Surge (Shaman T1 bonus) - case 87: - { - if(!procSpell) - return false; - - basepoints0 = procSpell->manaCost * 35/100; - triggered_spell_id = 23571; - target = this; - break; - } - //Nature's Guardian - case 2013: - { - if(GetTypeId()!=TYPEID_PLAYER) - return false; - - // damage taken that reduces below 30% health - // does NOT mean you must have been >= 30% before - if (10*(int32(GetHealth())-int32(damage)) >= 3*GetMaxHealth()) - return false; - - triggered_spell_id = 31616; - - // need check cooldown now - if( cooldown && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; - target = this; - if(pVictim && pVictim->isAlive()) - pVictim->getThreatManager().modifyThreatPercent(this,-10); - break; - } - } - } - - // Water Shield (we can't set cooldown for main spell - it's player casted spell - if((auraSpellInfo->SpellFamilyFlags & 0x0000002000000000LL) && auraSpellInfo->SpellVisual==7358) - { - target = this; - break; - } - - // Lightning Shield - if((auraSpellInfo->SpellFamilyFlags & 0x00000400) && auraSpellInfo->SpellVisual==37) - { - // overwrite non existing triggered spell call in spell.dbc - switch(triggeredByAura->GetSpellProto()->Id) - { - case 324: - triggered_spell_id = 26364; break; // Rank 1 - case 325: - triggered_spell_id = 26365; break; // Rank 2 - case 905: - triggered_spell_id = 26366; break; // Rank 3 - case 945: - triggered_spell_id = 26367; break; // Rank 4 - case 8134: - triggered_spell_id = 26369; break; // Rank 5 - case 10431: - triggered_spell_id = 26370; break; // Rank 6 - case 10432: - triggered_spell_id = 26363; break; // Rank 7 - case 25469: - triggered_spell_id = 26371; break; // Rank 8 - case 25472: - triggered_spell_id = 26372; break; // Rank 9 - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield",triggeredByAura->GetSpellProto()->Id); - return false; - } - - target = pVictim; - break; - } - break; - } - } - - // standard non-dummy case - if(!triggered_spell_id) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex()); - return false; - } - - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have not existed EffectTriggered[%d]=%u, not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex(),triggered_spell_id); - return false; - } - - // not allow proc extra attack spell at extra attack - if( m_extraAttacks && IsSpellHaveEffect(triggerEntry,SPELL_EFFECT_ADD_EXTRA_ATTACKS) ) - return false; - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - // default case - if(!target || target!=this && !target->isAlive()) - return false; - - if(basepoints0) - CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - else - CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) -{ - if(!pVictim || !pVictim->isAlive()) - return false; - - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = 0; - - switch(scriptId) - { - case 836: // Improved Blizzard (Rank 1) - { - if (!procSpell || procSpell->SpellVisual!=9487) - return false; - triggered_spell_id = 12484; - break; - } - case 988: // Improved Blizzard (Rank 2) - { - if (!procSpell || procSpell->SpellVisual!=9487) - return false; - triggered_spell_id = 12485; - break; - } - case 989: // Improved Blizzard (Rank 3) - { - if (!procSpell || procSpell->SpellVisual!=9487) - return false; - triggered_spell_id = 12486; - break; - } - case 4086: // Improved Mend Pet (Rank 1) - case 4087: // Improved Mend Pet (Rank 2) - { - int32 chance = triggeredByAura->GetSpellProto()->EffectBasePoints[triggeredByAura->GetEffIndex()]; - if(!roll_chance_i(chance)) - return false; - - triggered_spell_id = 24406; - break; - } - case 4533: // Dreamwalker Raiment 2 pieces bonus - { - // Chance 50% - if (!roll_chance_i(50)) - return false; - - switch (pVictim->getPowerType()) - { - case POWER_MANA: triggered_spell_id = 28722; break; - case POWER_RAGE: triggered_spell_id = 28723; break; - case POWER_ENERGY: triggered_spell_id = 28724; break; - default: - return false; - } - break; - } - case 4537: // Dreamwalker Raiment 6 pieces bonus - triggered_spell_id = 28750; // Blessing of the Claw - break; - case 5497: // Improved Mana Gems (Serpent-Coil Braid) - triggered_spell_id = 37445; // Mana Surge - break; - } - - // not processed - if(!triggered_spell_id) - return false; - - // standard non-dummy case - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id,scriptId); - return false; - } - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - CastSpell(pVictim, triggered_spell_id, true, castItem, triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -void Unit::setPowerType(Powers new_powertype) -{ - SetByteValue(UNIT_FIELD_BYTES_0, 3, new_powertype); - - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE); - } - } - - switch(new_powertype) - { - default: - case POWER_MANA: - break; - case POWER_RAGE: - SetMaxPower(POWER_RAGE,GetCreatePowers(POWER_RAGE)); - SetPower( POWER_RAGE,0); - break; - case POWER_FOCUS: - SetMaxPower(POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); - SetPower( POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); - break; - case POWER_ENERGY: - SetMaxPower(POWER_ENERGY,GetCreatePowers(POWER_ENERGY)); - SetPower( POWER_ENERGY,0); - break; - case POWER_HAPPINESS: - SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - SetPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - break; - } -} - -FactionTemplateEntry const* Unit::getFactionTemplateEntry() const -{ - FactionTemplateEntry const* entry = sFactionTemplateStore.LookupEntry(getFaction()); - if(!entry) - { - static uint64 guid = 0; // prevent repeating spam same faction problem - - if(GetGUID() != guid) - { - if(GetTypeId() == TYPEID_PLAYER) - sLog.outError("Player %s have invalid faction (faction template id) #%u", ((Player*)this)->GetName(), getFaction()); - else - sLog.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature*)this)->GetCreatureInfo()->Entry, getFaction()); - guid = GetGUID(); - } - } - return entry; -} - -bool Unit::IsHostileTo(Unit const* unit) const -{ - // always non-hostile to self - if(unit==this) - return false; - - // always non-hostile to GM in GM mode - if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) - return false; - - // always hostile to enemy - if(getVictim()==unit || unit->getVictim()==this) - return true; - - // test pet/charm masters instead pers/charmeds - Unit const* testerOwner = GetCharmerOrOwner(); - Unit const* targetOwner = unit->GetCharmerOrOwner(); - - // always hostile to owner's enemy - if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) - return true; - - // always hostile to enemy owner - if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) - return true; - - // always hostile to owner of owner's enemy - if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) - return true; - - Unit const* tester = testerOwner ? testerOwner : this; - Unit const* target = targetOwner ? targetOwner : unit; - - // always non-hostile to target with common owner, or to owner/pet - if(tester==target) - return false; - - // special cases (Duel, etc) - if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) - { - Player const* pTester = (Player const*)tester; - Player const* pTarget = (Player const*)target; - - // Duel - if(pTester->duel && pTester->duel->opponent == pTarget && pTester->duel->startTime != 0) - return true; - - // Group - if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) - return false; - - // Sanctuary - if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) - return false; - - // PvP FFA state - if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) - return true; - - //= PvP states - // Green/Blue (can't attack) - if(pTester->GetTeam()==pTarget->GetTeam()) - return false; - - // Red (can attack) if true, Blue/Yellow (can't attack) in another case - return pTester->IsPvP() && pTarget->IsPvP(); - } - - // faction base cases - FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); - FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) - return false; - - if(target->isAttackingPlayer() && tester->IsContestedGuard()) - return true; - - // PvC forced reaction and reputation case - if(tester->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player*)tester)->m_forcedReactions.find(target_faction->faction); - if(forceItr!=((Player*)tester)->m_forcedReactions.end()) - return forceItr->second <= REP_HOSTILE; - - // if faction have reputation then hostile state for tester at 100% dependent from at_war state - if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if(raw_target_faction->reputationListID >=0) - if(FactionState const* factionState = ((Player*)tester)->GetFactionState(raw_target_faction)) - return (factionState->Flags & FACTION_FLAG_AT_WAR); - } - // CvP forced reaction and reputation case - else if(target->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); - if(forceItr!=((Player const*)target)->m_forcedReactions.end()) - return forceItr->second <= REP_HOSTILE; - - // apply reputation state - FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction); - if(raw_tester_faction && raw_tester_faction->reputationListID >=0 ) - return ((Player const*)target)->GetReputationRank(raw_tester_faction) <= REP_HOSTILE; - } - - // common faction based case (CvC,PvC,CvP) - return tester_faction->IsHostileTo(*target_faction); -} - -bool Unit::IsFriendlyTo(Unit const* unit) const -{ - // always friendly to self - if(unit==this) - return true; - - // always friendly to GM in GM mode - if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) - return true; - - // always non-friendly to enemy - if(getVictim()==unit || unit->getVictim()==this) - return false; - - // test pet/charm masters instead pers/charmeds - Unit const* testerOwner = GetCharmerOrOwner(); - Unit const* targetOwner = unit->GetCharmerOrOwner(); - - // always non-friendly to owner's enemy - if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) - return false; - - // always non-friendly to enemy owner - if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) - return false; - - // always non-friendly to owner of owner's enemy - if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) - return false; - - Unit const* tester = testerOwner ? testerOwner : this; - Unit const* target = targetOwner ? targetOwner : unit; - - // always friendly to target with common owner, or to owner/pet - if(tester==target) - return true; - - // special cases (Duel) - if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) - { - Player const* pTester = (Player const*)tester; - Player const* pTarget = (Player const*)target; - - // Duel - if(pTester->duel && pTester->duel->opponent == target && pTester->duel->startTime != 0) - return false; - - // Group - if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) - return true; - - // Sanctuary - if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) - return true; - - // PvP FFA state - if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) - return false; - - //= PvP states - // Green/Blue (non-attackable) - if(pTester->GetTeam()==pTarget->GetTeam()) - return true; - - // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable) - return !pTarget->IsPvP(); - } - - // faction base cases - FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); - FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) - return false; - - if(target->isAttackingPlayer() && tester->IsContestedGuard()) - return false; - - // PvC forced reaction and reputation case - if(tester->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player const*)tester)->m_forcedReactions.find(target_faction->faction); - if(forceItr!=((Player const*)tester)->m_forcedReactions.end()) - return forceItr->second >= REP_FRIENDLY; - - // if faction have reputation then friendly state for tester at 100% dependent from at_war state - if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if(raw_target_faction->reputationListID >=0) - if(FactionState const* FactionState = ((Player*)tester)->GetFactionState(raw_target_faction)) - return !(FactionState->Flags & FACTION_FLAG_AT_WAR); - } - // CvP forced reaction and reputation case - else if(target->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); - if(forceItr!=((Player const*)target)->m_forcedReactions.end()) - return forceItr->second >= REP_FRIENDLY; - - // apply reputation state - if(FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction)) - if(raw_tester_faction->reputationListID >=0 ) - return ((Player const*)target)->GetReputationRank(raw_tester_faction) >= REP_FRIENDLY; - } - - // common faction based case (CvC,PvC,CvP) - return tester_faction->IsFriendlyTo(*target_faction); -} - -bool Unit::IsHostileToPlayers() const -{ - FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); - if(!my_faction) - return false; - - FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); - if(raw_faction && raw_faction->reputationListID >=0 ) - return false; - - return my_faction->IsHostileToPlayers(); -} - -bool Unit::IsNeutralToAll() const -{ - FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); - if(!my_faction) - return true; - - FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); - if(raw_faction && raw_faction->reputationListID >=0 ) - return false; - - return my_faction->IsNeutralToAll(); -} - -bool Unit::Attack(Unit *victim, bool meleeAttack) -{ - if(!victim || victim == this) - return false; - - // dead units can neither attack nor be attacked - if(!isAlive() || !victim->isAlive()) - return false; - - // player cannot attack in mount state - if(GetTypeId()==TYPEID_PLAYER && IsMounted()) - return false; - - // nobody can attack GM in GM-mode - if(victim->GetTypeId()==TYPEID_PLAYER) - { - if(((Player*)victim)->isGameMaster()) - return false; - } - else - { - if(((Creature*)victim)->IsInEvadeMode()) - return false; - } - - // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack) - if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE)) - RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE); - - if (m_attacking) - { - if (m_attacking == victim) - { - // switch to melee attack from ranged/magic - if( meleeAttack && !hasUnitState(UNIT_STAT_MELEE_ATTACKING) ) - { - addUnitState(UNIT_STAT_MELEE_ATTACKING); - SendAttackStart(victim); - return true; - } - return false; - } - AttackStop(); - } - - //Set our target - SetUInt64Value(UNIT_FIELD_TARGET, victim->GetGUID()); - - if(meleeAttack) - addUnitState(UNIT_STAT_MELEE_ATTACKING); - m_attacking = victim; - m_attacking->_addAttacker(this); - - if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->AI()) - ((Creature*)m_attacking)->AI()->AttackedBy(this); - - if(GetTypeId()==TYPEID_UNIT) - { - WorldPacket data(SMSG_AI_REACTION, 12); - data << GetGUID(); - data << uint32(AI_REACTION_AGGRO); // Aggro sound - ((WorldObject*)this)->SendMessageToSet(&data, true); - - ((Creature*)this)->CallAssistence(); - ((Creature*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ()); - } - - // delay offhand weapon attack to next attack time - if(haveOffhandWeapon()) - resetAttackTimer(OFF_ATTACK); - - if(meleeAttack) - SendAttackStart(victim); - - return true; -} - -bool Unit::AttackStop() -{ - if (!m_attacking) - return false; - - Unit* victim = m_attacking; - - m_attacking->_removeAttacker(this); - m_attacking = NULL; - - //Clear our target - SetUInt64Value(UNIT_FIELD_TARGET, 0); - - clearUnitState(UNIT_STAT_MELEE_ATTACKING); - - InterruptSpell(CURRENT_MELEE_SPELL); - - if( GetTypeId()==TYPEID_UNIT ) - { - // reset call assistance - ((Creature*)this)->SetNoCallAssistence(false); - } - - SendAttackStop(victim); - - return true; -} - -void Unit::CombatStop(bool cast) -{ - if(cast& IsNonMeleeSpellCasted(false)) - InterruptNonMeleeSpells(false); - - AttackStop(); - RemoveAllAttackers(); - if( GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel - ClearInCombat(); -} - -void Unit::CombatStopWithPets(bool cast) -{ - CombatStop(cast); - if(Pet* pet = GetPet()) - pet->CombatStop(cast); - if(Unit* charm = GetCharm()) - charm->CombatStop(cast); - if(GetTypeId()==TYPEID_PLAYER) - { - GuardianPetList const& guardians = ((Player*)this)->GetGuardians(); - for(GuardianPetList::const_iterator itr = guardians.begin(); itr != guardians.end(); ++itr) - if(Unit* guardian = Unit::GetUnit(*this,*itr)) - guardian->CombatStop(cast); - } -} - -bool Unit::isAttackingPlayer() const -{ - if(hasUnitState(UNIT_STAT_ATTACK_PLAYER)) - return true; - - Pet* pet = GetPet(); - if(pet && pet->isAttackingPlayer()) - return true; - - Unit* charmed = GetCharm(); - if(charmed && charmed->isAttackingPlayer()) - return true; - - for (int8 i = 0; i < MAX_TOTEM; i++) - { - if(m_TotemSlot[i]) - { - Creature *totem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); - if(totem && totem->isAttackingPlayer()) - return true; - } - } - - return false; -} - -void Unit::RemoveAllAttackers() -{ - while (!m_attackers.empty()) - { - AttackerSet::iterator iter = m_attackers.begin(); - if(!(*iter)->AttackStop()) - { - sLog.outError("WORLD: Unit has an attacker that isn't attacking it!"); - m_attackers.erase(iter); - } - } -} - -void Unit::ModifyAuraState(AuraState flag, bool apply) -{ - if (apply) - { - if (!HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1))) - { - SetFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); - if(GetTypeId() == TYPEID_PLAYER) - { - const PlayerSpellMap& sp_list = ((Player*)this)->GetSpellMap(); - for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) - { - if(itr->second->state == PLAYERSPELL_REMOVED) continue; - SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); - if (!spellInfo || !IsPassiveSpell(itr->first)) continue; - if (spellInfo->CasterAuraState == flag) - CastSpell(this, itr->first, true, NULL); - } - } - } - } - else - { - if (HasFlag(UNIT_FIELD_AURASTATE,1<<(flag-1))) - { - RemoveFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); - Unit::AuraMap& tAuras = GetAuras(); - for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();) - { - SpellEntry const* spellProto = (*itr).second->GetSpellProto(); - if (spellProto->CasterAuraState == flag) - { - // exceptions (applied at state but not removed at state change) - // Rampage - if(spellProto->SpellIconID==2006 && spellProto->SpellFamilyName==SPELLFAMILY_WARRIOR && spellProto->SpellFamilyFlags==0x100000) - { - ++itr; - continue; - } - - RemoveAura(itr); - } - else - ++itr; - } - } - } -} - -Unit *Unit::GetOwner() const -{ - uint64 ownerid = GetOwnerGUID(); - if(!ownerid) - return NULL; - return ObjectAccessor::GetUnit(*this, ownerid); -} - -Unit *Unit::GetCharmer() const -{ - if(uint64 charmerid = GetCharmerGUID()) - return ObjectAccessor::GetUnit(*this, charmerid); - return NULL; -} - -Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() -{ - uint64 guid = GetCharmerOrOwnerGUID(); - if(IS_PLAYER_GUID(guid)) - return ObjectAccessor::GetPlayer(*this, guid); - - return GetTypeId()==TYPEID_PLAYER ? (Player*)this : NULL; -} - -Pet* Unit::GetPet() const -{ - if(uint64 pet_guid = GetPetGUID()) - { - if(Pet* pet = ObjectAccessor::GetPet(pet_guid)) - return pet; - - sLog.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid)); - const_cast(this)->SetPet(0); - } - - return NULL; -} - -Unit* Unit::GetCharm() const -{ - if(uint64 charm_guid = GetCharmGUID()) - { - if(Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid)) - return pet; - - sLog.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid)); - const_cast(this)->SetCharm(0); - } - - return NULL; -} - -void Unit::SetPet(Pet* pet) -{ - SetUInt64Value(UNIT_FIELD_SUMMON,pet ? pet->GetGUID() : 0); - - // FIXME: hack, speed must be set only at follow - if(pet) - for(int i = 0; i < MAX_MOVE_TYPE; ++i) - pet->SetSpeed(UnitMoveType(i),m_speed_rate[i],true); -} - -void Unit::SetCharm(Unit* charmed) -{ - SetUInt64Value(UNIT_FIELD_CHARM,charmed ? charmed->GetGUID() : 0); -} - -void Unit::AddPlayerToVision(Player* plr) -{ - if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) - { - setActive(true); - GetMap()->SwitchGridContainers((Creature*)this, true); - } - m_sharedVision.push_back(plr); - plr->SetFarsightTarget(this); -} - -void Unit::RemovePlayerFromVision(Player* plr) -{ - m_sharedVision.remove(plr); - if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) - { - setActive(false); - GetMap()->SwitchGridContainers((Creature*)this, false); - } - plr->ClearFarsight(); -} - -void Unit::RemoveAllFromVision() -{ - while (!m_sharedVision.empty()) - { - Player* plr = *m_sharedVision.begin(); - m_sharedVision.erase(m_sharedVision.begin()); - plr->ClearFarsight(); - } -} - -void Unit::UncharmSelf() -{ - if (!GetCharmer()) - return; - - RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM); -} - -void Unit::UnpossessSelf(bool attack) -{ - if (!isPossessed() || !GetCharmer()) - return; - - if (GetCharmer()->GetTypeId() == TYPEID_PLAYER) - ((Player*)GetCharmer())->RemovePossess(attack); - else - { - GetCharmer()->SetCharm(0); - SetCharmerGUID(0); - m_isPossessed = false; - } -} - -void Unit::UnsummonAllTotems() -{ - for (int8 i = 0; i < MAX_TOTEM; ++i) - { - if(!m_TotemSlot[i]) - continue; - - Creature *OldTotem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); - if (OldTotem && OldTotem->isTotem()) - ((Totem*)OldTotem)->UnSummon(); - } -} - -void Unit::SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical) -{ - // we guess size - WorldPacket data(SMSG_SPELLHEALLOG, (8+8+4+4+1)); - data.append(pVictim->GetPackGUID()); - data.append(GetPackGUID()); - data << uint32(SpellID); - data << uint32(Damage); - data << uint8(critical ? 1 : 0); - data << uint8(0); // unused in client? - SendMessageToSet(&data, true); -} - -void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype, bool critical) -{ - WorldPacket data(SMSG_SPELLENERGIZELOG, (8+8+4+4+4+1)); - data.append(pVictim->GetPackGUID()); - data.append(GetPackGUID()); - data << uint32(SpellID); - data << uint32(powertype); - data << uint32(Damage); - //data << uint8(critical ? 1 : 0); // removed in 2.4.0 - SendMessageToSet(&data, true); -} - -uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 pdamage, DamageEffectType damagetype) -{ - if(!spellProto || !pVictim || damagetype==DIRECT_DAMAGE ) - return pdamage; - - int32 BonusDamage = 0; - if( GetTypeId()==TYPEID_UNIT ) - { - // Pets just add their bonus damage to their spell damage - // note that their spell damage is just gain of their own auras - if (((Creature*)this)->isPet()) - { - BonusDamage = ((Pet*)this)->GetBonusDamage(); - } - // For totems get damage bonus from owner (statue isn't totem in fact) - else if (((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) - { - if(Unit* owner = GetOwner()) - return owner->SpellDamageBonus(pVictim, spellProto, pdamage, damagetype); - } - } - - // Damage Done - uint32 CastingTime = !IsChanneledSpell(spellProto) ? GetSpellCastTime(spellProto) : GetSpellDuration(spellProto); - - // Taken/Done fixed damage bonus auras - int32 DoneAdvertisedBenefit = SpellBaseDamageBonus(GetSpellSchoolMask(spellProto))+BonusDamage; - int32 TakenAdvertisedBenefit = SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); - - // Damage over Time spells bonus calculation - float DotFactor = 1.0f; - if(damagetype == DOT) - { - int32 DotDuration = GetSpellDuration(spellProto); - // 200% limit - if(DotDuration > 0) - { - if(DotDuration > 30000) DotDuration = 30000; - if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; - int x = 0; - for(int j = 0; j < 3; j++) - { - if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_DAMAGE || - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) - { - x = j; - break; - } - } - int DotTicks = 6; - if(spellProto->EffectAmplitude[x] != 0) - DotTicks = DotDuration / spellProto->EffectAmplitude[x]; - if(DotTicks) - { - DoneAdvertisedBenefit /= DotTicks; - TakenAdvertisedBenefit /= DotTicks; - } - } - } - - // Taken/Done total percent damage auras - float DoneTotalMod = 1.0f; - float TakenTotalMod = 1.0f; - - // ..done - AuraList const& mModDamagePercentDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE); - for(AuraList::const_iterator i = mModDamagePercentDone.begin(); i != mModDamagePercentDone.end(); ++i) - { - if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) && - (*i)->GetSpellProto()->EquippedItemClass == -1 && - // -1 == any item class (not wand then) - (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) - // 0 == any inventory type (not wand then) - { - DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - } - } - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // ..taken - AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); - for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) - if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // .. taken pct: scripted (increases damage of * against targets *) - AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) - { - switch((*i)->GetModifier()->m_miscvalue) - { - //Molten Fury - case 4920: case 4919: - if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT)) - TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; break; - } - } - - // .. taken pct: dummy auras - AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) - { - switch((*i)->GetSpellProto()->SpellIconID) - { - //Cheat Death - case 2109: - if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) ) - { - if(pVictim->GetTypeId() != TYPEID_PLAYER) - continue; - float mod = -((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL)*2*4; - if (mod < (*i)->GetModifier()->m_amount) - mod = (*i)->GetModifier()->m_amount; - TakenTotalMod *= (mod+100.0f)/100.0f; - } - break; - //Mangle - case 2312: - for(int j=0;j<3;j++) - { - if(GetEffectMechanic(spellProto, j)==MECHANIC_BLEED) - { - TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; - break; - } - } - break; - } - } - - // Distribute Damage over multiple effects, reduce by AoE - CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); - - // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing - for(int j = 0; j < 3; ++j) - { - if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || - spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) - { - CastingTime /= 2; - break; - } - } - - switch(spellProto->SpellFamilyName) - { - case SPELLFAMILY_MAGE: - // Ignite - do not modify, it is (8*Rank)% damage of procing Spell - if(spellProto->Id==12654) - { - return pdamage; - } - // Ice Lance - else if((spellProto->SpellFamilyFlags & 0x20000LL) && spellProto->SpellIconID == 186) - { - CastingTime /= 3; // applied 1/3 bonuses in case generic target - if(pVictim->isFrozen()) // and compensate this for frozen target. - TakenTotalMod *= 3.0f; - } - // Pyroblast - 115% of Fire Damage, DoT - 20% of Fire Damage - else if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 184 ) - { - DotFactor = damagetype == DOT ? 0.2f : 1.0f; - CastingTime = damagetype == DOT ? 3500 : 4025; - } - // Fireball - 100% of Fire Damage, DoT - 0% of Fire Damage - else if((spellProto->SpellFamilyFlags & 0x1LL) && spellProto->SpellIconID == 185) - { - CastingTime = 3500; - DotFactor = damagetype == DOT ? 0.0f : 1.0f; - } - // Molten armor - else if (spellProto->SpellFamilyFlags & 0x0000000800000000LL) - { - CastingTime = 0; - } - // Arcane Missiles triggered spell - else if ((spellProto->SpellFamilyFlags & 0x200000LL) && spellProto->SpellIconID == 225) - { - CastingTime = 1000; - } - // Blizzard triggered spell - else if ((spellProto->SpellFamilyFlags & 0x80080LL) && spellProto->SpellIconID == 285) - { - CastingTime = 500; - } - break; - case SPELLFAMILY_WARLOCK: - // Life Tap - if((spellProto->SpellFamilyFlags & 0x40000LL) && spellProto->SpellIconID == 208) - { - CastingTime = 2800; // 80% from +shadow damage - DoneTotalMod = 1.0f; - TakenTotalMod = 1.0f; - } - // Dark Pact - else if((spellProto->SpellFamilyFlags & 0x80000000LL) && spellProto->SpellIconID == 154 && GetPetGUID()) - { - CastingTime = 3360; // 96% from +shadow damage - DoneTotalMod = 1.0f; - TakenTotalMod = 1.0f; - } - // Soul Fire - 115% of Fire Damage - else if((spellProto->SpellFamilyFlags & 0x8000000000LL) && spellProto->SpellIconID == 184) - { - CastingTime = 4025; - } - // Curse of Agony - 120% of Shadow Damage - else if((spellProto->SpellFamilyFlags & 0x0000000400LL) && spellProto->SpellIconID == 544) - { - DotFactor = 1.2f; - } - // Drain Mana - 0% of Shadow Damage - else if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 548) - { - CastingTime = 0; - } - // Drain Soul 214.3% - else if ((spellProto->SpellFamilyFlags & 0x4000LL) && spellProto->SpellIconID == 113 ) - { - CastingTime = 7500; - } - // Hellfire - else if ((spellProto->SpellFamilyFlags & 0x40LL) && spellProto->SpellIconID == 937) - { - CastingTime = damagetype == DOT ? 5000 : 500; // self damage seems to be so - } - // Unstable Affliction - 180% - else if (spellProto->Id == 31117 && spellProto->SpellIconID == 232) - { - CastingTime = 6300; - } - // Corruption 93% - else if ((spellProto->SpellFamilyFlags & 0x2LL) && spellProto->SpellIconID == 313) - { - DotFactor = 0.93f; - } - break; - case SPELLFAMILY_PALADIN: - // Consecration - 95% of Holy Damage - if((spellProto->SpellFamilyFlags & 0x20LL) && spellProto->SpellIconID == 51) - { - DotFactor = 0.95f; - CastingTime = 3500; - } - // Seal of Righteousness - 10.2%/9.8% ( based on weapon type ) of Holy Damage, multiplied by weapon speed - else if((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 25) - { - Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - float wspeed = GetAttackTime(BASE_ATTACK)/1000.0f; - - if( item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) - CastingTime = uint32(wspeed*3500*0.102f); - else - CastingTime = uint32(wspeed*3500*0.098f); - } - // Judgement of Righteousness - 73% - else if ((spellProto->SpellFamilyFlags & 1024) && spellProto->SpellIconID == 25) - { - CastingTime = 2555; - } - // Seal of Vengeance - 17% per Fully Stacked Tick - 5 Applications - else if ((spellProto->SpellFamilyFlags & 0x80000000000LL) && spellProto->SpellIconID == 2292) - { - DotFactor = 0.17f; - CastingTime = 3500; - } - // Holy shield - 5% of Holy Damage - else if ((spellProto->SpellFamilyFlags & 0x4000000000LL) && spellProto->SpellIconID == 453) - { - CastingTime = 175; - } - // Blessing of Sanctuary - 0% - else if ((spellProto->SpellFamilyFlags & 0x10000000LL) && spellProto->SpellIconID == 29) - { - CastingTime = 0; - } - // Seal of Righteousness trigger - already computed for parent spell - else if ( spellProto->SpellFamilyName==SPELLFAMILY_PALADIN && spellProto->SpellIconID==25 && spellProto->AttributesEx4 & 0x00800000LL ) - { - return pdamage; - } - break; - case SPELLFAMILY_SHAMAN: - // totem attack - if (spellProto->SpellFamilyFlags & 0x000040000000LL) - { - if (spellProto->SpellIconID == 33) // Fire Nova totem attack must be 21.4%(untested) - CastingTime = 749; // ignore CastingTime and use as modifier - else if (spellProto->SpellIconID == 680) // Searing Totem attack 8% - CastingTime = 280; // ignore CastingTime and use as modifier - else if (spellProto->SpellIconID == 37) // Magma totem attack must be 6.67%(untested) - CastingTime = 234; // ignore CastingTimePenalty and use as modifier - } - // Lightning Shield (and proc shield from T2 8 pieces bonus ) 33% per charge - else if( (spellProto->SpellFamilyFlags & 0x00000000400LL) || spellProto->Id == 23552) - CastingTime = 1155; // ignore CastingTimePenalty and use as modifier - break; - case SPELLFAMILY_PRIEST: - // Mana Burn - 0% of Shadow Damage - if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 212) - { - CastingTime = 0; - } - // Mind Flay - 59% of Shadow Damage - else if((spellProto->SpellFamilyFlags & 0x800000LL) && spellProto->SpellIconID == 548) - { - CastingTime = 2065; - } - // Holy Fire - 86.71%, DoT - 16.5% - else if ((spellProto->SpellFamilyFlags & 0x100000LL) && spellProto->SpellIconID == 156) - { - DotFactor = damagetype == DOT ? 0.165f : 1.0f; - CastingTime = damagetype == DOT ? 3500 : 3035; - } - // Shadowguard - 28% per charge - else if ((spellProto->SpellFamilyFlags & 0x2000000LL) && spellProto->SpellIconID == 19) - { - CastingTime = 980; - } - // Touch of Weakeness - 10% - else if ((spellProto->SpellFamilyFlags & 0x80000LL) && spellProto->SpellIconID == 1591) - { - CastingTime = 350; - } - // Reflective Shield (back damage) - 0% (other spells fit to check not have damage effects/auras) - else if (spellProto->SpellFamilyFlags == 0 && spellProto->SpellIconID == 566) - { - CastingTime = 0; - } - // Holy Nova - 14% - else if ((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 1874) - { - CastingTime = 500; - } - break; - case SPELLFAMILY_DRUID: - // Hurricane triggered spell - if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 220) - { - CastingTime = 500; - } - break; - case SPELLFAMILY_WARRIOR: - case SPELLFAMILY_HUNTER: - case SPELLFAMILY_ROGUE: - CastingTime = 0; - break; - default: - break; - } - - float LvlPenalty = CalculateLevelPenalty(spellProto); - - // Spellmod SpellDamage - float SpellModSpellDamage = 100.0f; - - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); - - SpellModSpellDamage /= 100.0f; - - float DoneActualBenefit = DoneAdvertisedBenefit * (CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; - float TakenActualBenefit = TakenAdvertisedBenefit; - if(spellProto->SpellFamilyName) - TakenActualBenefit *= (CastingTime / 3500.0f) * DotFactor * LvlPenalty; - - float tmpDamage = (float(pdamage)+DoneActualBenefit)*DoneTotalMod; - - // Add flat bonus from spell damage versus - tmpDamage += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS, creatureTypeMask); - - // apply spellmod to Done damage - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, tmpDamage); - - tmpDamage = (tmpDamage+TakenActualBenefit)*TakenTotalMod; - - if( GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet() ) - tmpDamage *= ((Creature*)this)->GetSpellDamageMod(((Creature*)this)->GetCreatureInfo()->rank); - - return tmpDamage > 0 ? uint32(tmpDamage) : 0; -} - -int32 Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask) -{ - int32 DoneAdvertisedBenefit = 0; - - // ..done - AuraList const& mDamageDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE); - for(AuraList::const_iterator i = mDamageDone.begin();i != mDamageDone.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0 && - (*i)->GetSpellProto()->EquippedItemClass == -1 && - // -1 == any item class (not wand then) - (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) - // 0 == any inventory type (not wand then) - DoneAdvertisedBenefit += (*i)->GetModifier()->m_amount; - - if (GetTypeId() == TYPEID_PLAYER) - { - // Damage bonus from stats - AuraList const& mDamageDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT); - for(AuraList::const_iterator i = mDamageDoneOfStatPercent.begin();i != mDamageDoneOfStatPercent.end(); ++i) - { - if((*i)->GetModifier()->m_miscvalue & schoolMask) - { - SpellEntry const* iSpellProto = (*i)->GetSpellProto(); - uint8 eff = (*i)->GetEffIndex(); - - // stat used dependent from next effect aura SPELL_AURA_MOD_SPELL_HEALING presence and misc value (stat index) - Stats usedStat = STAT_INTELLECT; - if(eff < 2 && iSpellProto->EffectApplyAuraName[eff+1]==SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT) - usedStat = Stats(iSpellProto->EffectMiscValue[eff+1]); - - DoneAdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); - } - } - // ... and attack power - AuraList const& mDamageDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER); - for(AuraList::const_iterator i =mDamageDonebyAP.begin();i != mDamageDonebyAP.end(); ++i) - if ((*i)->GetModifier()->m_miscvalue & schoolMask) - DoneAdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); - - } - return DoneAdvertisedBenefit; -} - -int32 Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) -{ - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - - int32 TakenAdvertisedBenefit = 0; - // ..done (for creature type by mask) in taken - AuraList const& mDamageDoneCreature = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); - for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; - - // ..taken - AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); - for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) - TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; - - return TakenAdvertisedBenefit; -} - -bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType) -{ - // not criting spell - if((spellProto->AttributesEx2 & SPELL_ATTR_EX2_CANT_CRIT)) - return false; - - float crit_chance = 0.0f; - switch(spellProto->DmgClass) - { - case SPELL_DAMAGE_CLASS_NONE: - return false; - case SPELL_DAMAGE_CLASS_MAGIC: - { - if (schoolMask & SPELL_SCHOOL_MASK_NORMAL) - crit_chance = 0.0f; - // For other schools - else if (GetTypeId() == TYPEID_PLAYER) - crit_chance = GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1 + GetFirstSchoolInMask(schoolMask)); - else - { - crit_chance = m_baseSpellCritChance; - crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); - } - // taken - if (pVictim && !IsPositiveSpell(spellProto->Id)) - { - // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE - crit_chance += pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE, schoolMask); - // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE - crit_chance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); - // Modify by player victim resilience - if (pVictim->GetTypeId() == TYPEID_PLAYER) - crit_chance -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL); - // scripted (increase crit chance ... against ... target by x% - if(pVictim->isFrozen()) // Shatter - { - AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) - { - switch((*i)->GetModifier()->m_miscvalue) - { - case 849: crit_chance+= 10.0f; break; //Shatter Rank 1 - case 910: crit_chance+= 20.0f; break; //Shatter Rank 2 - case 911: crit_chance+= 30.0f; break; //Shatter Rank 3 - case 912: crit_chance+= 40.0f; break; //Shatter Rank 4 - case 913: crit_chance+= 50.0f; break; //Shatter Rank 5 - } - } - } - } - break; - } - case SPELL_DAMAGE_CLASS_MELEE: - case SPELL_DAMAGE_CLASS_RANGED: - { - if (pVictim) - { - crit_chance = GetUnitCriticalChance(attackType, pVictim); - crit_chance+= (int32(GetMaxSkillValueForLevel(pVictim)) - int32(pVictim->GetDefenseSkillValue(this))) * 0.04f; - crit_chance+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); - } - break; - } - default: - return false; - } - // percent done - // only players use intelligence for critical chance computations - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); - - crit_chance = crit_chance > 0.0f ? crit_chance : 0.0f; - if (roll_chance_f(crit_chance)) - return true; - return false; -} - -uint32 Unit::SpellCriticalBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim) -{ - // Calculate critical bonus - int32 crit_bonus; - switch(spellProto->DmgClass) - { - case SPELL_DAMAGE_CLASS_MELEE: // for melee based spells is 100% - case SPELL_DAMAGE_CLASS_RANGED: - // TODO: write here full calculation for melee/ranged spells - crit_bonus = damage; - break; - default: - crit_bonus = damage / 2; // for spells is 50% - break; - } - - // adds additional damage to crit_bonus (from talents) - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); - - if(pVictim) - { - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - crit_bonus = int32(crit_bonus * GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS, creatureTypeMask)); - } - - if(crit_bonus > 0) - damage += crit_bonus; - - return damage; -} - -uint32 Unit::SpellHealingBonus(SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, Unit *pVictim) -{ - // For totems get healing bonus from owner (statue isn't totem in fact) - if( GetTypeId()==TYPEID_UNIT && ((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) - if(Unit* owner = GetOwner()) - return owner->SpellHealingBonus(spellProto, healamount, damagetype, pVictim); - - // Healing Done - - // These Spells are doing fixed amount of healing (TODO found less hack-like check) - if (spellProto->Id == 15290 || spellProto->Id == 39373 || - spellProto->Id == 33778 || spellProto->Id == 379 || - spellProto->Id == 38395 || spellProto->Id == 40972) - return healamount; - - int32 AdvertisedBenefit = SpellBaseHealingBonus(GetSpellSchoolMask(spellProto)); - uint32 CastingTime = GetSpellCastTime(spellProto); - - // Healing Taken - AdvertisedBenefit += SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); - - // Blessing of Light dummy effects healing taken from Holy Light and Flash of Light - if (spellProto->SpellFamilyName == SPELLFAMILY_PALADIN && (spellProto->SpellFamilyFlags & 0x00000000C0000000LL)) - { - AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i) - { - if((*i)->GetSpellProto()->SpellVisual == 9180) - { - // Flash of Light - if ((spellProto->SpellFamilyFlags & 0x0000000040000000LL) && (*i)->GetEffIndex() == 1) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - // Holy Light - else if ((spellProto->SpellFamilyFlags & 0x0000000080000000LL) && (*i)->GetEffIndex() == 0) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - } - } - } - - float ActualBenefit = 0.0f; - - if (AdvertisedBenefit != 0) - { - // Healing over Time spells - float DotFactor = 1.0f; - if(damagetype == DOT) - { - int32 DotDuration = GetSpellDuration(spellProto); - if(DotDuration > 0) - { - // 200% limit - if(DotDuration > 30000) DotDuration = 30000; - if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; - int x = 0; - for(int j = 0; j < 3; j++) - { - if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_HEAL || - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) - { - x = j; - break; - } - } - int DotTicks = 6; - if(spellProto->EffectAmplitude[x] != 0) - DotTicks = DotDuration / spellProto->EffectAmplitude[x]; - if(DotTicks) - AdvertisedBenefit /= DotTicks; - } - } - - // distribute healing to all effects, reduce AoE damage - CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); - - // 0% bonus for damage and healing spells for leech spells from healing bonus - for(int j = 0; j < 3; ++j) - { - if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || - spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) - { - CastingTime = 0; - break; - } - } - - // Exception - switch (spellProto->SpellFamilyName) - { - case SPELLFAMILY_SHAMAN: - // Healing stream from totem (add 6% per tick from hill bonus owner) - if (spellProto->SpellFamilyFlags & 0x000000002000LL) - CastingTime = 210; - // Earth Shield 30% per charge - else if (spellProto->SpellFamilyFlags & 0x40000000000LL) - CastingTime = 1050; - break; - case SPELLFAMILY_DRUID: - // Lifebloom - if (spellProto->SpellFamilyFlags & 0x1000000000LL) - { - CastingTime = damagetype == DOT ? 3500 : 1200; - DotFactor = damagetype == DOT ? 0.519f : 1.0f; - } - // Tranquility triggered spell - else if (spellProto->SpellFamilyFlags & 0x80LL) - CastingTime = 667; - // Rejuvenation - else if (spellProto->SpellFamilyFlags & 0x10LL) - DotFactor = 0.845f; - // Regrowth - else if (spellProto->SpellFamilyFlags & 0x40LL) - { - DotFactor = damagetype == DOT ? 0.705f : 1.0f; - CastingTime = damagetype == DOT ? 3500 : 1010; - } - break; - case SPELLFAMILY_PRIEST: - // Holy Nova - 14% - if ((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 1874) - CastingTime = 500; - break; - case SPELLFAMILY_PALADIN: - // Seal and Judgement of Light - if ( spellProto->SpellFamilyFlags & 0x100040000LL ) - CastingTime = 0; - break; - case SPELLFAMILY_WARRIOR: - case SPELLFAMILY_ROGUE: - case SPELLFAMILY_HUNTER: - CastingTime = 0; - break; - } - - float LvlPenalty = CalculateLevelPenalty(spellProto); - - // Spellmod SpellDamage - float SpellModSpellDamage = 100.0f; - - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); - - SpellModSpellDamage /= 100.0f; - - ActualBenefit = (float)AdvertisedBenefit * ((float)CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; - } - - // use float as more appropriate for negative values and percent applying - float heal = healamount + ActualBenefit; - - // TODO: check for ALL/SPELLS type - // Healing done percent - AuraList const& mHealingDonePct = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT); - for(AuraList::const_iterator i = mHealingDonePct.begin();i != mHealingDonePct.end(); ++i) - heal *= (100.0f + (*i)->GetModifier()->m_amount) / 100.0f; - - // apply spellmod to Done amount - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, heal); - - // Healing Wave cast - if (spellProto->SpellFamilyName == SPELLFAMILY_SHAMAN && spellProto->SpellFamilyFlags & 0x0000000000000040LL) - { - // Search for Healing Way on Victim (stack up to 3 time) - int32 pctMod = 0; - Unit::AuraList const& auraDummy = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr!=auraDummy.end(); ++itr) - if((*itr)->GetId() == 29203) - pctMod += (*itr)->GetModifier()->m_amount; - // Apply bonus - if (pctMod) - heal = heal * (100 + pctMod) / 100; - } - - // Healing taken percent - float minval = pVictim->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT); - if(minval) - heal *= (100.0f + minval) / 100.0f; - - float maxval = pVictim->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT); - if(maxval) - heal *= (100.0f + maxval) / 100.0f; - - if (heal < 0) heal = 0; - - return uint32(heal); -} - -int32 Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask) -{ - int32 AdvertisedBenefit = 0; - - AuraList const& mHealingDone = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE); - for(AuraList::const_iterator i = mHealingDone.begin();i != mHealingDone.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - - // Healing bonus of spirit, intellect and strength - if (GetTypeId() == TYPEID_PLAYER) - { - // Healing bonus from stats - AuraList const& mHealingDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT); - for(AuraList::const_iterator i = mHealingDoneOfStatPercent.begin();i != mHealingDoneOfStatPercent.end(); ++i) - { - // stat used dependent from misc value (stat index) - Stats usedStat = Stats((*i)->GetSpellProto()->EffectMiscValue[(*i)->GetEffIndex()]); - AdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); - } - - // ... and attack power - AuraList const& mHealingDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER); - for(AuraList::const_iterator i = mHealingDonebyAP.begin();i != mHealingDonebyAP.end(); ++i) - if ((*i)->GetModifier()->m_miscvalue & schoolMask) - AdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); - } - return AdvertisedBenefit; -} - -int32 Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) -{ - int32 AdvertisedBenefit = 0; - AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_HEALING); - for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - return AdvertisedBenefit; -} - -bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask, bool useCharges) -{ - // no charges dependent checks - SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; - for (SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) - if(itr->type & shoolMask) - return true; - - // charges dependent checks - SpellImmuneList const& damageList = m_spellImmune[IMMUNITY_DAMAGE]; - for (SpellImmuneList::const_iterator itr = damageList.begin(); itr != damageList.end(); ++itr) - { - if(itr->type & shoolMask) - { - if(useCharges) - { - AuraList const& auraDamageImmunity = GetAurasByType(SPELL_AURA_DAMAGE_IMMUNITY); - for(AuraList::const_iterator auraItr = auraDamageImmunity.begin(); auraItr != auraDamageImmunity.end(); ++auraItr) - { - if((*auraItr)->GetId()==itr->spellId) - { - if((*auraItr)->m_procCharges > 0) - { - --(*auraItr)->m_procCharges; - if((*auraItr)->m_procCharges==0) - RemoveAurasDueToSpell(itr->spellId); - } - break; - } - } - } - return true; - } - } - - return false; -} - -bool Unit::IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges) -{ - if (!spellInfo) - return false; - - // no charges first - - //FIX ME this hack: don't get feared if stunned - if (spellInfo->Mechanic == MECHANIC_FEAR ) - { - if ( hasUnitState(UNIT_STAT_STUNNED) ) - return true; - } - - // not have spells with charges currently - SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_DISPEL]; - for(SpellImmuneList::const_iterator itr = dispelList.begin(); itr != dispelList.end(); ++itr) - if(itr->type == spellInfo->Dispel) - return true; - - if( !(spellInfo->AttributesEx & SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE) && (spellInfo->Id != 42292)) // unaffected by school immunity - { - // not have spells with charges currently - SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; - for(SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) - if( !(IsPositiveSpell(itr->spellId) && IsPositiveSpell(spellInfo->Id)) && - (itr->type & GetSpellSchoolMask(spellInfo)) ) - return true; - } - - // charges dependent checks - - SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; - for(SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) - { - if(itr->type == spellInfo->Mechanic) - { - if(useCharges) - { - AuraList const& auraMechImmunity = GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY); - for(AuraList::const_iterator auraItr = auraMechImmunity.begin(); auraItr != auraMechImmunity.end(); ++auraItr) - { - if((*auraItr)->GetId()==itr->spellId) - { - if((*auraItr)->m_procCharges > 0) - { - --(*auraItr)->m_procCharges; - if((*auraItr)->m_procCharges==0) - RemoveAurasDueToSpell(itr->spellId); - } - break; - } - } - } - return true; - } - } - - return false; -} - -bool Unit::IsImmunedToSpellEffect(uint32 effect, uint32 mechanic) const -{ - //If m_immuneToEffect type contain this effect type, IMMUNE effect. - SpellImmuneList const& effectList = m_spellImmune[IMMUNITY_EFFECT]; - for (SpellImmuneList::const_iterator itr = effectList.begin(); itr != effectList.end(); ++itr) - if(itr->type == effect) - return true; - - SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; - for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) - if(itr->type == mechanic) - return true; - - return false; -} - -bool Unit::IsDamageToThreatSpell(SpellEntry const * spellInfo) const -{ - if(!spellInfo) - return false; - - uint32 family = spellInfo->SpellFamilyName; - uint64 flags = spellInfo->SpellFamilyFlags; - - if((family == 5 && flags == 256) || //Searing Pain - (family == 6 && flags == 8192) || //Mind Blast - (family == 11 && flags == 1048576)) //Earth Shock - return true; - - return false; -} - -void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage,WeaponAttackType attType, SpellEntry const *spellProto) -{ - if(!pVictim) - return; - - if(*pdamage == 0) - return; - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - - // Taken/Done fixed damage bonus auras - int32 DoneFlatBenefit = 0; - int32 TakenFlatBenefit = 0; - - // ..done (for creature type by mask) in taken - AuraList const& mDamageDoneCreature = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); - for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - DoneFlatBenefit += (*i)->GetModifier()->m_amount; - - // ..done - // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage - - // ..done (base at attack power for marked target and base at attack power for creature type) - int32 APbonus = 0; - if(attType == RANGED_ATTACK) - { - APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS); - - // ..done (base at attack power and creature type) - AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS); - for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - APbonus += (*i)->GetModifier()->m_amount; - } - else - { - APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS); - - // ..done (base at attack power and creature type) - AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS); - for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - APbonus += (*i)->GetModifier()->m_amount; - } - - if (APbonus!=0) // Can be negative - { - bool normalized = false; - if(spellProto) - { - for (uint8 i = 0; i<3;i++) - { - if (spellProto->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG) - { - normalized = true; - break; - } - } - } - - DoneFlatBenefit += int32(APbonus/14.0f * GetAPMultiplier(attType,normalized)); - } - - // ..taken - AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); - for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) - if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) - TakenFlatBenefit += (*i)->GetModifier()->m_amount; - - if(attType!=RANGED_ATTACK) - TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN); - else - TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN); - - // Done/Taken total percent damage auras - float DoneTotalMod = 1; - float TakenTotalMod = 1; - - // ..done - // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage - // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage - - AuraList const& mDamageDoneVersus = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // ..taken - AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); - for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) - if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // .. taken pct: dummy auras - AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) - { - switch((*i)->GetSpellProto()->SpellIconID) - { - //Cheat Death - case 2109: - if((*i)->GetModifier()->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) - { - if(pVictim->GetTypeId() != TYPEID_PLAYER) - continue; - float mod = ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); - if (mod < (*i)->GetModifier()->m_amount) - mod = (*i)->GetModifier()->m_amount; - TakenTotalMod *= (mod+100.0f)/100.0f; - } - break; - //Mangle - case 2312: - if(spellProto==NULL) - break; - // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG) - if(spellProto->SpellFamilyName==SPELLFAMILY_DRUID && (spellProto->SpellFamilyFlags==0x00008000LL)) - TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; - break; - } - } - - // .. taken pct: class scripts - AuraList const& mclassScritAuras = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator i = mclassScritAuras.begin(); i != mclassScritAuras.end(); ++i) - { - switch((*i)->GetMiscValue()) - { - case 6427: case 6428: // Dirty Deeds - if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT)) - { - Aura* eff0 = GetAura((*i)->GetId(),0); - if(!eff0 || (*i)->GetEffIndex()!=1) - { - sLog.outError("Spell structure of DD (%u) changed.",(*i)->GetId()); - continue; - } - - // effect 0 have expected value but in negative state - TakenTotalMod *= (-eff0->GetModifier()->m_amount+100.0f)/100.0f; - } - break; - } - } - - if(attType != RANGED_ATTACK) - { - AuraList const& mModMeleeDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT); - for(AuraList::const_iterator i = mModMeleeDamageTakenPercent.begin(); i != mModMeleeDamageTakenPercent.end(); ++i) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - } - else - { - AuraList const& mModRangedDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT); - for(AuraList::const_iterator i = mModRangedDamageTakenPercent.begin(); i != mModRangedDamageTakenPercent.end(); ++i) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - } - - float tmpDamage = float(int32(*pdamage) + DoneFlatBenefit) * DoneTotalMod; - - // apply spellmod to Done damage - if(spellProto) - { - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_DAMAGE, tmpDamage); - } - - tmpDamage = (tmpDamage + TakenFlatBenefit)*TakenTotalMod; - - // bonus result can be negative - *pdamage = tmpDamage > 0 ? uint32(tmpDamage) : 0; -} - -void Unit::ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply) -{ - if (apply) - { - for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(), next; itr != m_spellImmune[op].end(); itr = next) - { - next = itr; ++next; - if(itr->type == type) - { - m_spellImmune[op].erase(itr); - next = m_spellImmune[op].begin(); - } - } - SpellImmune Immune; - Immune.spellId = spellId; - Immune.type = type; - m_spellImmune[op].push_back(Immune); - } - else - { - for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(); itr != m_spellImmune[op].end(); ++itr) - { - if(itr->spellId == spellId) - { - m_spellImmune[op].erase(itr); - break; - } - } - } - -} - -void Unit::ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply) -{ - ApplySpellImmune(spellProto->Id,IMMUNITY_DISPEL, type, apply); - - if (apply && spellProto->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY) - RemoveAurasWithDispelType(type); -} - -float Unit::GetWeaponProcChance() const -{ - // normalized proc chance for weapon attack speed - // (odd formula...) - if(isAttackReady(BASE_ATTACK)) - return (GetAttackTime(BASE_ATTACK) * 1.8f / 1000.0f); - else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK)) - return (GetAttackTime(OFF_ATTACK) * 1.6f / 1000.0f); - return 0; -} - -float Unit::GetPPMProcChance(uint32 WeaponSpeed, float PPM) const -{ - // proc per minute chance calculation - if (PPM <= 0) return 0.0f; - uint32 result = uint32((WeaponSpeed * PPM) / 600.0f); // result is chance in percents (probability = Speed_in_sec * (PPM / 60)) - return result; -} - -void Unit::Mount(uint32 mount) -{ - if(!mount) - return; - - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNT); - - SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, mount); - - SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); - - // unsummon pet - if(GetTypeId() == TYPEID_PLAYER) - { - Pet* pet = GetPet(); - if(pet) - { - if(pet->isControlled()) - { - ((Player*)this)->SetTemporaryUnsummonedPetNumber(pet->GetCharmInfo()->GetPetNumber()); - ((Player*)this)->SetOldPetSpell(pet->GetUInt32Value(UNIT_CREATED_BY_SPELL)); - } - - ((Player*)this)->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT); - } - else - ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); - } -} - -void Unit::Unmount() -{ - if(!IsMounted()) - return; - - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED); - - SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0); - RemoveFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); - - // only resummon old pet if the player is already added to a map - // this prevents adding a pet to a not created map which would otherwise cause a crash - // (it could probably happen when logging in after a previous crash) - if(GetTypeId() == TYPEID_PLAYER && IsInWorld() && ((Player*)this)->GetTemporaryUnsummonedPetNumber() && isAlive()) - { - Pet* NewPet = new Pet; - if(!NewPet->LoadPetFromDB(this, 0, ((Player*)this)->GetTemporaryUnsummonedPetNumber(), true)) - delete NewPet; - - ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); - } -} - -void Unit::SetInCombatWith(Unit* enemy) -{ - Unit* eOwner = enemy->GetCharmerOrOwnerOrSelf(); - if(eOwner->IsPvP()) - { - SetInCombatState(true); - return; - } - - //check for duel - if(eOwner->GetTypeId() == TYPEID_PLAYER && ((Player*)eOwner)->duel) - { - Unit const* myOwner = GetCharmerOrOwnerOrSelf(); - if(((Player const*)eOwner)->duel->opponent == myOwner) - { - SetInCombatState(true); - return; - } - } - SetInCombatState(false); -} - -void Unit::CombatStart(Unit* target) -{ - if(!target->IsStandState() && !target->hasUnitState(UNIT_STAT_STUNNED)) - target->SetStandState(PLAYER_STATE_NONE); - - if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER && ((Creature*)target)->AI()) - ((Creature*)target)->AI()->AttackStart(this); - - SetInCombatWith(target); - target->SetInCombatWith(this); - - if(Player* attackedPlayer = target->GetCharmerOrOwnerPlayerOrPlayerItself()) - SetContestedPvP(attackedPlayer); - - if(!isInCombat()) // remove this? - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ATTACK); -} - -void Unit::SetInCombatState(bool PvP) -{ - // only alive units can be in combat - if(!isAlive()) - return; - - if(PvP) - m_CombatTimer = 5000; - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); - - if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); -} - -void Unit::ClearInCombat() -{ - m_CombatTimer = 0; - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); - - if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); - - // Player's state will be cleared in Player::UpdateContestedPvP - if(GetTypeId()!=TYPEID_PLAYER) - clearUnitState(UNIT_STAT_ATTACK_PLAYER); -} - -//TODO: remove this function -bool Unit::isTargetableForAttack() const -{ - return isAttackableByAOE() && !hasUnitState(UNIT_STAT_DIED); -} - -bool Unit::canAttack(Unit const* target) const -{ - assert(target); - - if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) - return false; - - if((m_invisibilityMask || target->m_invisibilityMask) && !canDetectInvisibilityOf(target)) - return false; - - if(target->GetVisibility() == VISIBILITY_GROUP_STEALTH && !canDetectStealthOf(target, GetDistance(target))) - return false; - - return true; -} - -bool Unit::isAttackableByAOE() const -{ - if(!isAlive()) - return false; - - if(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE)) - return false; - - if(GetTypeId()==TYPEID_PLAYER && ((Player *)this)->isGameMaster()) - return false; - - return !isInFlight(); -} - -int32 Unit::ModifyHealth(int32 dVal) -{ - int32 gain = 0; - - if(dVal==0) - return 0; - - int32 curHealth = (int32)GetHealth(); - - int32 val = dVal + curHealth; - if(val <= 0) - { - SetHealth(0); - return -curHealth; - } - - int32 maxHealth = (int32)GetMaxHealth(); - - if(val < maxHealth) - { - SetHealth(val); - gain = val - curHealth; - } - else if(curHealth != maxHealth) - { - SetHealth(maxHealth); - gain = maxHealth - curHealth; - } - - return gain; -} - -int32 Unit::ModifyPower(Powers power, int32 dVal) -{ - int32 gain = 0; - - if(dVal==0) - return 0; - - int32 curPower = (int32)GetPower(power); - - int32 val = dVal + curPower; - if(val <= 0) - { - SetPower(power,0); - return -curPower; - } - - int32 maxPower = (int32)GetMaxPower(power); - - if(val < maxPower) - { - SetPower(power,val); - gain = val - curPower; - } - else if(curPower != maxPower) - { - SetPower(power,maxPower); - gain = maxPower - curPower; - } - - return gain; -} - -bool Unit::isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList) const -{ - if(!u) - return false; - return u->canSeeOrDetect(this, detect, inVisibleList); -} - -bool Unit::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList) const -{ - return true; -} - -bool Unit::canDetectInvisibilityOf(Unit const* u) const -{ - if(m_invisibilityMask & u->m_invisibilityMask) // same group - return true; - AuraList const& auras = GetAurasByType(SPELL_AURA_MOD_STALKED); // Hunter mark - for(AuraList::const_iterator iter = auras.begin(); iter != auras.end(); ++iter) - if((*iter)->GetCasterGUID()==u->GetGUID()) - return true; - - if(uint32 mask = (m_detectInvisibilityMask & u->m_invisibilityMask)) - { - for(uint32 i = 0; i < 10; ++i) - { - if(((1 << i) & mask)==0) - continue; - - // find invisibility level - uint32 invLevel = 0; - Unit::AuraList const& iAuras = u->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY); - for(Unit::AuraList::const_iterator itr = iAuras.begin(); itr != iAuras.end(); ++itr) - if(((*itr)->GetModifier()->m_miscvalue)==i && invLevel < (*itr)->GetModifier()->m_amount) - invLevel = (*itr)->GetModifier()->m_amount; - - // find invisibility detect level - uint32 detectLevel = 0; - if(i==6 && GetTypeId()==TYPEID_PLAYER) // special drunk detection case - { - detectLevel = ((Player*)this)->GetDrunkValue(); - } - else - { - Unit::AuraList const& dAuras = GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION); - for(Unit::AuraList::const_iterator itr = dAuras.begin(); itr != dAuras.end(); ++itr) - if(((*itr)->GetModifier()->m_miscvalue)==i && detectLevel < (*itr)->GetModifier()->m_amount) - detectLevel = (*itr)->GetModifier()->m_amount; - } - - if(invLevel <= detectLevel) - return true; - } - } - - return false; -} - -bool Unit::canDetectStealthOf(Unit const* target, float distance) const -{ - if(hasUnitState(UNIT_STAT_STUNNED)) - return false; - if(distance < 0.24f) //collision - return true; - if(!HasInArc(M_PI, target)) //behind - return false; - if(HasAuraType(SPELL_AURA_DETECT_STEALTH)) - return true; - - //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5) - float visibleDistance = 10.5f - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH) / 100.0f; - //Visible distance is modified by -Level Diff (every level diff = 1.0f in visible distance) - visibleDistance += int32(getLevelForTarget(target)) - int32(target->getLevelForTarget(this)); - //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia) - //based on wowwiki every 5 mod we have 1 more level diff in calculation - visibleDistance += (float)(GetTotalAuraModifier(SPELL_AURA_MOD_DETECT) - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL)) / 5.0f; - - return distance < visibleDistance; -} - -void Unit::SetVisibility(UnitVisibility x) -{ - m_Visibility = x; - - if(IsInWorld()) - { - Map *m = MapManager::Instance().GetMap(GetMapId(), this); - - if(GetTypeId()==TYPEID_PLAYER) - m->PlayerRelocation((Player*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); - else - m->CreatureRelocation((Creature*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); - } -} - -void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) -{ - int32 main_speed_mod = 0; - float stack_bonus = 1.0f; - float non_stack_bonus = 1.0f; - - switch(mtype) - { - case MOVE_WALK: - return; - case MOVE_RUN: - { - if (IsMounted()) // Use on mount auras - { - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED); - stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS); - non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK))/100.0f; - } - else - { - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED); - stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS); - non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK))/100.0f; - } - break; - } - case MOVE_WALKBACK: - return; - case MOVE_SWIM: - { - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED); - break; - } - case MOVE_SWIMBACK: - return; - case MOVE_FLY: - { - if (IsMounted()) // Use on mount auras - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED); - else // Use not mount (shapeshift for example) auras (should stack) - main_speed_mod = GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT); - stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS); - non_stack_bonus = (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK))/100.0f; - break; - } - case MOVE_FLYBACK: - return; - default: - sLog.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype); - return; - } - - float bonus = non_stack_bonus > stack_bonus ? non_stack_bonus : stack_bonus; - // now we ready for speed calculation - float speed = main_speed_mod ? bonus*(100.0f + main_speed_mod)/100.0f : bonus; - - switch(mtype) - { - case MOVE_RUN: - case MOVE_SWIM: - case MOVE_FLY: - { - // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need - // TODO: possible affect only on MOVE_RUN - if(int32 normalization = GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED)) - { - // Use speed from aura - float max_speed = normalization / baseMoveSpeed[mtype]; - if (speed > max_speed) - speed = max_speed; - } - break; - } - default: - break; - } - - // Apply strongest slow aura mod to speed - int32 slow = GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED); - if (slow) - speed *=(100.0f + slow)/100.0f; - SetSpeed(mtype, speed, forced); -} - -float Unit::GetSpeed( UnitMoveType mtype ) const -{ - return m_speed_rate[mtype]*baseMoveSpeed[mtype]; -} - -void Unit::SetSpeed(UnitMoveType mtype, float rate, bool forced) -{ - if (rate < 0) - rate = 0.0f; - - // Update speed only on change - if (m_speed_rate[mtype] == rate) - return; - - m_speed_rate[mtype] = rate; - - propagateSpeedChange(); - - // Send speed change packet only for player - if (GetTypeId()!=TYPEID_PLAYER) - return; - - WorldPacket data; - if(!forced) - { - switch(mtype) - { - case MOVE_WALK: - data.Initialize(MSG_MOVE_SET_WALK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_RUN: - data.Initialize(MSG_MOVE_SET_RUN_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_WALKBACK: - data.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_SWIM: - data.Initialize(MSG_MOVE_SET_SWIM_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_SWIMBACK: - data.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_TURN: - data.Initialize(MSG_MOVE_SET_TURN_RATE, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_FLY: - data.Initialize(MSG_MOVE_SET_FLIGHT_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_FLYBACK: - data.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - default: - sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); - return; - } - - data.append(GetPackGUID()); - data << uint32(0); //movement flags - data << uint8(0); //unk - data << uint32(getMSTime()); - data << float(GetPositionX()); - data << float(GetPositionY()); - data << float(GetPositionZ()); - data << float(GetOrientation()); - data << uint32(0); //flag unk - data << float(GetSpeed(mtype)); - SendMessageToSet( &data, true ); - } - else - { - // register forced speed changes for WorldSession::HandleForceSpeedChangeAck - // and do it only for real sent packets and use run for run/mounted as client expected - ++((Player*)this)->m_forced_speed_changes[mtype]; - switch(mtype) - { - case MOVE_WALK: - data.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE, 16); - break; - case MOVE_RUN: - data.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE, 17); - break; - case MOVE_WALKBACK: - data.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE, 16); - break; - case MOVE_SWIM: - data.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE, 16); - break; - case MOVE_SWIMBACK: - data.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE, 16); - break; - case MOVE_TURN: - data.Initialize(SMSG_FORCE_TURN_RATE_CHANGE, 16); - break; - case MOVE_FLY: - data.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE, 16); - break; - case MOVE_FLYBACK: - data.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE, 16); - break; - default: - sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); - return; - } - data.append(GetPackGUID()); - data << (uint32)0; - if (mtype == MOVE_RUN) - data << uint8(0); // new 2.1.0 - data << float(GetSpeed(mtype)); - SendMessageToSet( &data, true ); - } - if(Pet* pet = GetPet()) - pet->SetSpeed(MOVE_RUN, m_speed_rate[mtype],forced); -} - -void Unit::SetHover(bool on) -{ - if(on) - CastSpell(this,11010,true); - else - RemoveAurasDueToSpell(11010); -} - -void Unit::setDeathState(DeathState s) -{ - if (s != ALIVE && s!= JUST_ALIVED) - { - CombatStop(); - DeleteThreatList(); - ClearComboPointHolders(); // any combo points pointed to unit lost at it death - - if(IsNonMeleeSpellCasted(false)) - InterruptNonMeleeSpells(false); - } - - if (s == JUST_DIED) - { - RemoveAllAurasOnDeath(); - UnsummonAllTotems(); - - // Possessed unit died, restore control to possessor - UnpossessSelf(false); - RemoveAllFromVision(); - - ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, false); - ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, false); - // remove aurastates allowing special moves - ClearAllReactives(); - ClearDiminishings(); - } - else if(s == JUST_ALIVED) - { - RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); // clear skinnable for creature and player (at battleground) - } - - if (m_deathState != ALIVE && s == ALIVE) - { - //_ApplyAllAuraMods(); - } - m_deathState = s; -} - -/*######################################## -######## ######## -######## AGGRO SYSTEM ######## -######## ######## -########################################*/ -bool Unit::CanHaveThreatList() const -{ - // only creatures can have threat list - if( GetTypeId() != TYPEID_UNIT ) - return false; - - // only alive units can have threat list - if( !isAlive() ) - return false; - - // pets and totems can not have threat list - if( ((Creature*)this)->isPet() || ((Creature*)this)->isTotem() ) - return false; - - return true; -} - -//====================================================================== - -float Unit::ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask) -{ - if(!HasAuraType(SPELL_AURA_MOD_THREAT)) - return threat; - - SpellSchools school = GetFirstSchoolInMask(schoolMask); - - return threat * m_threatModifier[school]; -} - -//====================================================================== - -void Unit::AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask, SpellEntry const *threatSpell) -{ - // Only mobs can manage threat lists - if(CanHaveThreatList()) - m_ThreatManager.addThreat(pVictim, threat, schoolMask, threatSpell); -} - -//====================================================================== - -void Unit::DeleteThreatList() -{ - m_ThreatManager.clearReferences(); -} - -//====================================================================== - -void Unit::TauntApply(Unit* taunter) -{ - assert(GetTypeId()== TYPEID_UNIT); - - if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) - return; - - if(!CanHaveThreatList()) - return; - - Unit *target = getVictim(); - if(target && target == taunter) - return; - - SetInFront(taunter); - if (((Creature*)this)->AI()) - ((Creature*)this)->AI()->AttackStart(taunter); - - m_ThreatManager.tauntApply(taunter); -} - -//====================================================================== - -void Unit::TauntFadeOut(Unit *taunter) -{ - assert(GetTypeId()== TYPEID_UNIT); - - if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) - return; - - if(!CanHaveThreatList()) - return; - - Unit *target = getVictim(); - if(!target || target != taunter) - return; - - if(m_ThreatManager.isThreatListEmpty()) - { - if(((Creature*)this)->AI()) - ((Creature*)this)->AI()->EnterEvadeMode(); - return; - } - - m_ThreatManager.tauntFadeOut(taunter); - target = m_ThreatManager.getHostilTarget(); - - if (target && target != taunter) - { - SetInFront(target); - if (((Creature*)this)->AI()) - ((Creature*)this)->AI()->AttackStart(target); - } -} - -//====================================================================== - -bool Unit::SelectHostilTarget() -{ - //function provides main threat functionality - //next-victim-selection algorithm and evade mode are called - //threat list sorting etc. - - assert(GetTypeId()== TYPEID_UNIT); - Unit* target = NULL; - - //This function only useful once AI has been initialized - if (!((Creature*)this)->AI()) - return false; - - if(!m_ThreatManager.isThreatListEmpty()) - { - if(!HasAuraType(SPELL_AURA_MOD_TAUNT)) - { - target = m_ThreatManager.getHostilTarget(); - } - } - - if(target) - { - if(!hasUnitState(UNIT_STAT_STUNNED)) - SetInFront(target); - ((Creature*)this)->AI()->AttackStart(target); - return true; - } - - // no target but something prevent go to evade mode - if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT) ) - return false; - - // last case when creature don't must go to evade mode: - // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list - // for example at owner command to pet attack some far away creature - // Note: creature not have targeted movement generator but have attacker in this case - if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE ) - { - for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr) - { - if( (*itr)->IsInMap(this) && canAttack(*itr) && (*itr)->isInAccessiblePlaceFor((Creature*)this) ) - return false; - } - } - - // enter in evade mode in other case - ((Creature*)this)->AI()->EnterEvadeMode(); - - return false; -} - -//====================================================================== -//====================================================================== -//====================================================================== - -int32 Unit::CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 effBasePoints, Unit const* target) -{ - Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; - - uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; - - int32 level = int32(getLevel()) - int32(spellProto->spellLevel); - if (level > spellProto->maxLevel && spellProto->maxLevel > 0) - level = spellProto->maxLevel; - - float basePointsPerLevel = spellProto->EffectRealPointsPerLevel[effect_index]; - float randomPointsPerLevel = spellProto->EffectDicePerLevel[effect_index]; - int32 basePoints = int32(effBasePoints + level * basePointsPerLevel); - int32 randomPoints = int32(spellProto->EffectDieSides[effect_index] + level * randomPointsPerLevel); - float comboDamage = spellProto->EffectPointsPerComboPoint[effect_index]; - - // prevent random generator from getting confused by spells casted with Unit::CastCustomSpell - int32 randvalue = spellProto->EffectBaseDice[effect_index] >= randomPoints ? spellProto->EffectBaseDice[effect_index]:irand(spellProto->EffectBaseDice[effect_index], randomPoints); - int32 value = basePoints + randvalue; - //random damage - if(comboDamage != 0 && unitPlayer && target && (target->GetGUID() == unitPlayer->GetComboTarget())) - value += (int32)(comboDamage * comboPoints); - - if(Player* modOwner = GetSpellModOwner()) - { - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_ALL_EFFECTS, value); - switch(effect_index) - { - case 0: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT1, value); - break; - case 1: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT2, value); - break; - case 2: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT3, value); - break; - } - } - - if(spellProto->Attributes & SPELL_ATTR_LEVEL_DAMAGE_CALCULATION && spellProto->spellLevel && - spellProto->Effect[effect_index] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE && - spellProto->Effect[effect_index] != SPELL_EFFECT_KNOCK_BACK) - value = int32(value*0.25f*exp(getLevel()*(70-spellProto->spellLevel)/1000.0f)); - - return value; -} - -int32 Unit::CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target) -{ - Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; - - uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; - - int32 minduration = GetSpellDuration(spellProto); - int32 maxduration = GetSpellMaxDuration(spellProto); - - int32 duration; - - if( minduration != -1 && minduration != maxduration ) - duration = minduration + int32((maxduration - minduration) * comboPoints / 5); - else - duration = minduration; - - if (duration > 0) - { - int32 mechanic = GetEffectMechanic(spellProto, effect_index); - // Find total mod value (negative bonus) - int32 durationMod_always = target->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD, mechanic); - // Find max mod (negative bonus) - int32 durationMod_not_stack = target->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK, mechanic); - - int32 durationMod = 0; - // Select strongest negative mod - if (durationMod_always > durationMod_not_stack) - durationMod = durationMod_not_stack; - else - durationMod = durationMod_always; - - if (durationMod != 0) - duration = int32(int64(duration) * (100+durationMod) /100); - - if (duration < 0) duration = 0; - } - - return duration; -} - -DiminishingLevels Unit::GetDiminishing(DiminishingGroup group) -{ - for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) - { - if(i->DRGroup != group) - continue; - - if(!i->hitCount) - return DIMINISHING_LEVEL_1; - - if(!i->hitTime) - return DIMINISHING_LEVEL_1; - - // If last spell was casted more than 15 seconds ago - reset the count. - if(i->stack==0 && getMSTimeDiff(i->hitTime,getMSTime()) > 15000) - { - i->hitCount = DIMINISHING_LEVEL_1; - return DIMINISHING_LEVEL_1; - } - // or else increase the count. - else - { - return DiminishingLevels(i->hitCount); - } - } - return DIMINISHING_LEVEL_1; -} - -void Unit::IncrDiminishing(DiminishingGroup group) -{ - // Checking for existing in the table - bool IsExist = false; - for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) - { - if(i->DRGroup != group) - continue; - - IsExist = true; - if(i->hitCount < DIMINISHING_LEVEL_IMMUNE) - i->hitCount += 1; - - break; - } - - if(!IsExist) - m_Diminishing.push_back(DiminishingReturn(group,getMSTime(),DIMINISHING_LEVEL_2)); -} - -void Unit::ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster,DiminishingLevels Level) -{ - if(duration == -1 || group == DIMINISHING_NONE || caster->IsFriendlyTo(this) ) - return; - - // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0) - if(duration > 10000 && IsDiminishingReturnsGroupDurationLimited(group)) - { - // test pet/charm masters instead pets/charmeds - Unit const* targetOwner = GetCharmerOrOwner(); - Unit const* casterOwner = caster->GetCharmerOrOwner(); - - Unit const* target = targetOwner ? targetOwner : this; - Unit const* source = casterOwner ? casterOwner : caster; - - if(target->GetTypeId() == TYPEID_PLAYER && source->GetTypeId() == TYPEID_PLAYER) - duration = 10000; - } - - float mod = 1.0f; - - // Some diminishings applies to mobs too (for example, Stun) - if((GetDiminishingReturnsGroupType(group) == DRTYPE_PLAYER && GetTypeId() == TYPEID_PLAYER) || GetDiminishingReturnsGroupType(group) == DRTYPE_ALL) - { - DiminishingLevels diminish = Level; - switch(diminish) - { - case DIMINISHING_LEVEL_1: break; - case DIMINISHING_LEVEL_2: mod = 0.5f; break; - case DIMINISHING_LEVEL_3: mod = 0.25f; break; - case DIMINISHING_LEVEL_IMMUNE: mod = 0.0f;break; - default: break; - } - } - - duration = int32(duration * mod); -} - -void Unit::ApplyDiminishingAura( DiminishingGroup group, bool apply ) -{ - // Checking for existing in the table - for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) - { - if(i->DRGroup != group) - continue; - - i->hitTime = getMSTime(); - - if(apply) - i->stack += 1; - else if(i->stack) - i->stack -= 1; - - break; - } -} - -Unit* Unit::GetUnit(WorldObject& object, uint64 guid) -{ - return ObjectAccessor::GetUnit(object,guid); -} - -bool Unit::isVisibleForInState( Player const* u, bool inVisibleList ) const -{ - return isVisibleForOrDetect(u,false,inVisibleList); -} - -uint32 Unit::GetCreatureType() const -{ - if(GetTypeId() == TYPEID_PLAYER) - { - SpellShapeshiftEntry const* ssEntry = sSpellShapeshiftStore.LookupEntry(((Player*)this)->m_form); - if(ssEntry && ssEntry->creatureType > 0) - return ssEntry->creatureType; - else - return CREATURE_TYPE_HUMANOID; - } - else - return ((Creature*)this)->GetCreatureInfo()->type; -} - -/*####################################### -######## ######## -######## STAT SYSTEM ######## -######## ######## -#######################################*/ - -bool Unit::HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply) -{ - if(unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) - { - sLog.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!"); - return false; - } - - float val = 1.0f; - - switch(modifierType) - { - case BASE_VALUE: - case TOTAL_VALUE: - m_auraModifiersGroup[unitMod][modifierType] += apply ? amount : -amount; - break; - case BASE_PCT: - case TOTAL_PCT: - if(amount <= -100.0f) //small hack-fix for -100% modifiers - amount = -200.0f; - - val = (100.0f + amount) / 100.0f; - m_auraModifiersGroup[unitMod][modifierType] *= apply ? val : (1.0f/val); - break; - - default: - break; - } - - if(!CanModifyStats()) - return false; - - switch(unitMod) - { - case UNIT_MOD_STAT_STRENGTH: - case UNIT_MOD_STAT_AGILITY: - case UNIT_MOD_STAT_STAMINA: - case UNIT_MOD_STAT_INTELLECT: - case UNIT_MOD_STAT_SPIRIT: UpdateStats(GetStatByAuraGroup(unitMod)); break; - - case UNIT_MOD_ARMOR: UpdateArmor(); break; - case UNIT_MOD_HEALTH: UpdateMaxHealth(); break; - - case UNIT_MOD_MANA: - case UNIT_MOD_RAGE: - case UNIT_MOD_FOCUS: - case UNIT_MOD_ENERGY: - case UNIT_MOD_HAPPINESS: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod)); break; - - case UNIT_MOD_RESISTANCE_HOLY: - case UNIT_MOD_RESISTANCE_FIRE: - case UNIT_MOD_RESISTANCE_NATURE: - case UNIT_MOD_RESISTANCE_FROST: - case UNIT_MOD_RESISTANCE_SHADOW: - case UNIT_MOD_RESISTANCE_ARCANE: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod)); break; - - case UNIT_MOD_ATTACK_POWER: UpdateAttackPowerAndDamage(); break; - case UNIT_MOD_ATTACK_POWER_RANGED: UpdateAttackPowerAndDamage(true); break; - - case UNIT_MOD_DAMAGE_MAINHAND: UpdateDamagePhysical(BASE_ATTACK); break; - case UNIT_MOD_DAMAGE_OFFHAND: UpdateDamagePhysical(OFF_ATTACK); break; - case UNIT_MOD_DAMAGE_RANGED: UpdateDamagePhysical(RANGED_ATTACK); break; - - default: - break; - } - - return true; -} - -float Unit::GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const -{ - if( unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) - { - sLog.outError("ERROR: trial to access non existed modifier value from UnitMods!"); - return 0.0f; - } - - if(modifierType == TOTAL_PCT && m_auraModifiersGroup[unitMod][modifierType] <= 0.0f) - return 0.0f; - - return m_auraModifiersGroup[unitMod][modifierType]; -} - -float Unit::GetTotalStatValue(Stats stat) const -{ - UnitMods unitMod = UnitMods(UNIT_MOD_STAT_START + stat); - - if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) - return 0.0f; - - // value = ((base_value * base_pct) + total_value) * total_pct - float value = m_auraModifiersGroup[unitMod][BASE_VALUE] + GetCreateStat(stat); - value *= m_auraModifiersGroup[unitMod][BASE_PCT]; - value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; - value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; - - return value; -} - -float Unit::GetTotalAuraModValue(UnitMods unitMod) const -{ - if(unitMod >= UNIT_MOD_END) - { - sLog.outError("ERROR: trial to access non existed UnitMods in GetTotalAuraModValue()!"); - return 0.0f; - } - - if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) - return 0.0f; - - float value = m_auraModifiersGroup[unitMod][BASE_VALUE]; - value *= m_auraModifiersGroup[unitMod][BASE_PCT]; - value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; - value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; - - return value; -} - -SpellSchools Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod) const -{ - SpellSchools school = SPELL_SCHOOL_NORMAL; - - switch(unitMod) - { - case UNIT_MOD_RESISTANCE_HOLY: school = SPELL_SCHOOL_HOLY; break; - case UNIT_MOD_RESISTANCE_FIRE: school = SPELL_SCHOOL_FIRE; break; - case UNIT_MOD_RESISTANCE_NATURE: school = SPELL_SCHOOL_NATURE; break; - case UNIT_MOD_RESISTANCE_FROST: school = SPELL_SCHOOL_FROST; break; - case UNIT_MOD_RESISTANCE_SHADOW: school = SPELL_SCHOOL_SHADOW; break; - case UNIT_MOD_RESISTANCE_ARCANE: school = SPELL_SCHOOL_ARCANE; break; - - default: - break; - } - - return school; -} - -Stats Unit::GetStatByAuraGroup(UnitMods unitMod) const -{ - Stats stat = STAT_STRENGTH; - - switch(unitMod) - { - case UNIT_MOD_STAT_STRENGTH: stat = STAT_STRENGTH; break; - case UNIT_MOD_STAT_AGILITY: stat = STAT_AGILITY; break; - case UNIT_MOD_STAT_STAMINA: stat = STAT_STAMINA; break; - case UNIT_MOD_STAT_INTELLECT: stat = STAT_INTELLECT; break; - case UNIT_MOD_STAT_SPIRIT: stat = STAT_SPIRIT; break; - - default: - break; - } - - return stat; -} - -Powers Unit::GetPowerTypeByAuraGroup(UnitMods unitMod) const -{ - Powers power = POWER_MANA; - - switch(unitMod) - { - case UNIT_MOD_MANA: power = POWER_MANA; break; - case UNIT_MOD_RAGE: power = POWER_RAGE; break; - case UNIT_MOD_FOCUS: power = POWER_FOCUS; break; - case UNIT_MOD_ENERGY: power = POWER_ENERGY; break; - case UNIT_MOD_HAPPINESS: power = POWER_HAPPINESS; break; - - default: - break; - } - - return power; -} - -float Unit::GetTotalAttackPowerValue(WeaponAttackType attType) const -{ - UnitMods unitMod = (attType == RANGED_ATTACK) ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER; - - float val = GetTotalAuraModValue(unitMod); - if(val < 0.0f) - val = 0.0f; - - return val; -} - -float Unit::GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const -{ - if (attType == OFF_ATTACK && !haveOffhandWeapon()) - return 0.0f; - - return m_weaponDamage[attType][type]; -} - -void Unit::SetLevel(uint32 lvl) -{ - SetUInt32Value(UNIT_FIELD_LEVEL, lvl); - - // group update - if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL); -} - -void Unit::SetHealth(uint32 val) -{ - uint32 maxHealth = GetMaxHealth(); - if(maxHealth < val) - val = maxHealth; - - SetUInt32Value(UNIT_FIELD_HEALTH, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP); - } - } -} - -void Unit::SetMaxHealth(uint32 val) -{ - uint32 health = GetHealth(); - SetUInt32Value(UNIT_FIELD_MAXHEALTH, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP); - } - } - - if(val < health) - SetHealth(val); -} - -void Unit::SetPower(Powers power, uint32 val) -{ - uint32 maxPower = GetMaxPower(power); - if(maxPower < val) - val = maxPower; - - SetStatInt32Value(UNIT_FIELD_POWER1 + power, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); - } - - // Update the pet's character sheet with happiness damage bonus - if(pet->getPetType() == HUNTER_PET && power == POWER_HAPPINESS) - { - pet->UpdateDamagePhysical(BASE_ATTACK); - } - } -} - -void Unit::SetMaxPower(Powers power, uint32 val) -{ - uint32 cur_power = GetPower(power); - SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + power, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); - } - } - - if(val < cur_power) - SetPower(power, val); -} - -void Unit::ApplyPowerMod(Powers power, uint32 val, bool apply) -{ - ApplyModUInt32Value(UNIT_FIELD_POWER1+power, val, apply); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); - } - } -} - -void Unit::ApplyMaxPowerMod(Powers power, uint32 val, bool apply) -{ - ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1+power, val, apply); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); - } - } -} - -void Unit::ApplyAuraProcTriggerDamage( Aura* aura, bool apply ) -{ - AuraList& tAuraProcTriggerDamage = m_modAuras[SPELL_AURA_PROC_TRIGGER_DAMAGE]; - if(apply) - tAuraProcTriggerDamage.push_back(aura); - else - tAuraProcTriggerDamage.remove(aura); -} - -uint32 Unit::GetCreatePowers( Powers power ) const -{ - // POWER_FOCUS and POWER_HAPPINESS only have hunter pet - switch(power) - { - case POWER_MANA: return GetCreateMana(); - case POWER_RAGE: return 1000; - case POWER_FOCUS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 100); - case POWER_ENERGY: return 100; - case POWER_HAPPINESS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 1050000); - } - - return 0; -} - -void Unit::AddToWorld() -{ - WorldObject::AddToWorld(); -} - -void Unit::RemoveFromWorld() -{ - // cleanup - if(IsInWorld()) - { - RemoveNotOwnSingleTargetAuras(); - } - - WorldObject::RemoveFromWorld(); -} - -void Unit::CleanupsBeforeDelete() -{ - if(m_uint32Values) // only for fully created object - { - InterruptNonMeleeSpells(true); - m_Events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList - CombatStop(); - ClearComboPointHolders(); - DeleteThreatList(); - getHostilRefManager().setOnlineOfflineState(false); - RemoveAllAuras(); - RemoveAllGameObjects(); - RemoveAllDynObjects(); - GetMotionMaster()->Clear(false); // remove different non-standard movement generators. - - UnpossessSelf(false); - RemoveAllFromVision(); - } - RemoveFromWorld(); -} - - - -CharmInfo* Unit::InitCharmInfo(Unit *charm) -{ - if(!m_charmInfo) - m_charmInfo = new CharmInfo(charm); - return m_charmInfo; -} - -CharmInfo::CharmInfo(Unit* unit) -: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0) -{ - for(int i =0; i<4; ++i) - { - m_charmspells[i].spellId = 0; - m_charmspells[i].active = ACT_DISABLED; - } -} - -void CharmInfo::InitPetActionBar() -{ - // the first 3 SpellOrActions are attack, follow and stay - for(uint32 i = 0; i < 3; i++) - { - PetActionBar[i].Type = ACT_COMMAND; - PetActionBar[i].SpellOrAction = COMMAND_ATTACK - i; - - PetActionBar[i + 7].Type = ACT_REACTION; - PetActionBar[i + 7].SpellOrAction = COMMAND_ATTACK - i; - } - for(uint32 i=0; i < 4; i++) - { - PetActionBar[i + 3].Type = ACT_DISABLED; - PetActionBar[i + 3].SpellOrAction = 0; - } -} - -void CharmInfo::InitEmptyActionBar() -{ - for(uint32 x = 1; x < 10; ++x) - { - PetActionBar[x].Type = ACT_CAST; - PetActionBar[x].SpellOrAction = 0; - } - PetActionBar[0].Type = ACT_COMMAND; - PetActionBar[0].SpellOrAction = COMMAND_ATTACK; -} - -void CharmInfo::InitPossessCreateSpells() -{ - InitEmptyActionBar(); - if(m_unit->GetTypeId() == TYPEID_UNIT) - { - for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) - { - uint32 spellid = ((Creature*)m_unit)->m_spells[i]; - if(IsPassiveSpell(spellid)) - m_unit->CastSpell(m_unit, spellid, true); - else - AddSpellToAB(0, spellid, ACT_CAST); - } - } -} - -void CharmInfo::InitCharmCreateSpells() -{ - if(m_unit->GetTypeId() == TYPEID_PLAYER) //charmed players don't have spells - { - InitEmptyActionBar(); - return; - } - - InitPetActionBar(); - - for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) - { - uint32 spellId = ((Creature*)m_unit)->m_spells[x]; - m_charmspells[x].spellId = spellId; - - if(!spellId) - continue; - - if (IsPassiveSpell(spellId)) - { - m_unit->CastSpell(m_unit, spellId, true); - m_charmspells[x].active = ACT_PASSIVE; - } - else - { - ActiveStates newstate; - bool onlyselfcast = true; - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - - if(!spellInfo) onlyselfcast = false; - for(uint32 i = 0;i<3 && onlyselfcast;++i) //non existent spell will not make any problems as onlyselfcast would be false -> break right away - { - if(spellInfo->EffectImplicitTargetA[i] != TARGET_SELF && spellInfo->EffectImplicitTargetA[i] != 0) - onlyselfcast = false; - } - - if(onlyselfcast || !IsPositiveSpell(spellId)) //only self cast and spells versus enemies are autocastable - newstate = ACT_DISABLED; - else - newstate = ACT_CAST; - - AddSpellToAB(0, spellId, newstate); - } - } -} - -bool CharmInfo::AddSpellToAB(uint32 oldid, uint32 newid, ActiveStates newstate) -{ - for(uint8 i = 0; i < 10; i++) - { - if((PetActionBar[i].Type == ACT_DISABLED || PetActionBar[i].Type == ACT_ENABLED || PetActionBar[i].Type == ACT_CAST) && PetActionBar[i].SpellOrAction == oldid) - { - PetActionBar[i].SpellOrAction = newid; - if(!oldid) - { - if(newstate == ACT_DECIDE) - PetActionBar[i].Type = ACT_DISABLED; - else - PetActionBar[i].Type = newstate; - } - - return true; - } - } - return false; -} - -void CharmInfo::ToggleCreatureAutocast(uint32 spellid, bool apply) -{ - if(IsPassiveSpell(spellid)) - return; - - for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) - { - if(spellid == m_charmspells[x].spellId) - { - m_charmspells[x].active = apply ? ACT_ENABLED : ACT_DISABLED; - } - } -} - -void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow) -{ - m_petnumber = petnumber; - if(statwindow) - m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, m_petnumber); - else - m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0); -} - -bool Unit::isFrozen() const -{ - AuraList const& mRoot = GetAurasByType(SPELL_AURA_MOD_ROOT); - for(AuraList::const_iterator i = mRoot.begin(); i != mRoot.end(); ++i) - if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST) - return true; - return false; -} - -struct ProcTriggeredData -{ - ProcTriggeredData(SpellEntry const * _spellInfo, uint32 _spellParam, Aura* _triggeredByAura, uint32 _cooldown) - : spellInfo(_spellInfo), spellParam(_spellParam), triggeredByAura(_triggeredByAura), - triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura->GetId(),triggeredByAura->GetEffIndex())), - cooldown(_cooldown) - {} - - SpellEntry const * spellInfo; - uint32 spellParam; - Aura* triggeredByAura; - Unit::spellEffectPair triggeredByAura_SpellPair; - uint32 cooldown; -}; - -typedef std::list< ProcTriggeredData > ProcTriggeredList; - -void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, AuraTypeSet const& procAuraTypes, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellSchoolMask damageSchoolMask ) -{ - for(AuraTypeSet::const_iterator aur = procAuraTypes.begin(); aur != procAuraTypes.end(); ++aur) - { - // List of spells (effects) that proceed. Spell prototype and aura-specific value (damage for TRIGGER_DAMAGE) - ProcTriggeredList procTriggered; - - AuraList const& auras = GetAurasByType(*aur); - for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) - { - next = i; ++next; - - SpellEntry const *spellProto = (*i)->GetSpellProto(); - if(!spellProto) - continue; - - SpellProcEventEntry const *spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); - if(!spellProcEvent) - { - // used to prevent spam in log about same non-handled spells - static std::set nonHandledSpellProcSet; - - if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) - { - sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); - nonHandledSpellProcSet.insert(spellProto->Id); - } - - // spell.dbc use totally different flags, that only can create problems if used. - continue; - } - - // Check spellProcEvent data requirements - if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) - continue; - - // Check if current equipment allows aura to proc - if(!isVictim && GetTypeId() == TYPEID_PLAYER ) - { - if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) - { - Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); - - if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) - continue; - } - else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) - { - // Check if player is wearing shield - Item *item = ((Player*)this)->GetShield(true); - if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) - continue; - } - } - - float chance = (float)spellProto->procChance; - - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); - - if(!isVictim && spellProcEvent->ppmRate != 0) - { - uint32 WeaponSpeed = GetAttackTime(attType); - chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); - } - - if(roll_chance_f(chance)) - { - uint32 cooldown = spellProcEvent->cooldown; - - uint32 i_spell_eff = (*i)->GetEffIndex(); - - int32 i_spell_param; - switch(*aur) - { - case SPELL_AURA_PROC_TRIGGER_SPELL: - i_spell_param = procFlag; - break; - case SPELL_AURA_DUMMY: - case SPELL_AURA_PRAYER_OF_MENDING: - case SPELL_AURA_MOD_HASTE: - i_spell_param = i_spell_eff; - break; - case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: - i_spell_param = (*i)->GetModifier()->m_miscvalue; - break; - default: - i_spell_param = (*i)->GetModifier()->m_amount; - break; - } - - procTriggered.push_back( ProcTriggeredData(spellProto,i_spell_param,*i, cooldown) ); - } - } - - // Handle effects proceed this time - for(ProcTriggeredList::iterator i = procTriggered.begin(); i != procTriggered.end(); ++i) - { - // Some auras can be deleted in function called in this loop (except first, ofc) - // Until storing auras in std::multimap to hard check deleting by another way - if(i != procTriggered.begin()) - { - bool found = false; - AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); - AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); - for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) - { - if(itr->second==i->triggeredByAura) - { - found = true; - break; - } - } - - if(!found) - { - sLog.outError("Spell aura %u (id:%u effect:%u) has been deleted before call spell proc event handler",*aur,i->triggeredByAura_SpellPair.first,i->triggeredByAura_SpellPair.second); - sLog.outError("It can be deleted one from early processed auras:"); - for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2) - sLog.outError(" Spell aura %u (id:%u effect:%u)",*aur,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second); - sLog.outError(" "); - continue; - } - } - - // save charges existence before processing to prevent crash at access to deleted triggered aura after - bool triggeredByAuraWithCharges = i->triggeredByAura->m_procCharges > 0; - - bool casted = false; - switch(*aur) - { - case SPELL_AURA_PROC_TRIGGER_SPELL: - { - sLog.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleProcTriggerSpell(pTarget, damage, i->triggeredByAura, procSpell,i->spellParam,attType,i->cooldown); - break; - } - case SPELL_AURA_PROC_TRIGGER_DAMAGE: - { - sLog.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", i->spellParam, i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - uint32 damage = i->spellParam; - SpellNonMeleeDamageLog(pTarget, i->spellInfo->Id, damage, true, true); - casted = true; - break; - } - case SPELL_AURA_DUMMY: - { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleDummyAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); - break; - } - case SPELL_AURA_PRAYER_OF_MENDING: - { - sLog.outDebug("ProcDamageAndSpell(mending): casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - - // aura can be deleted at casts - int32 heal = i->triggeredByAura->GetModifier()->m_amount; - uint64 caster_guid = i->triggeredByAura->GetCasterGUID(); - - // jumps - int32 jumps = i->triggeredByAura->m_procCharges-1; - - // current aura expire - i->triggeredByAura->m_procCharges = 1; // will removed at next charges decrease - - // next target selection - if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) - { - Aura* aura = i->triggeredByAura; - - SpellEntry const* spellProto = aura->GetSpellProto(); - uint32 effIdx = aura->GetEffIndex(); - - float radius; - if (spellProto->EffectRadiusIndex[effIdx]) - radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); - else - radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); - - if(Player* caster = ((Player*)aura->GetCaster())) - { - caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); - - if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) - { - // aura will applied from caster, but spell casted from current aura holder - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_CHARGES; - mod->value = jumps-5; // negative - mod->type = SPELLMOD_FLAT; - mod->spellId = spellProto->Id; - mod->effectId = effIdx; - mod->lastAffected = NULL; - mod->mask = spellProto->SpellFamilyFlags; - mod->charges = 0; - - caster->AddSpellMod(mod, true); - CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,aura,caster->GetGUID()); - caster->AddSpellMod(mod, false); - } - } - } - - // heal - CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); - casted = true; - break; - } - case SPELL_AURA_MOD_HASTE: - { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleHasteAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); - break; - } - case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN: - { - // nothing do, just charges counter - // but count only in case appropriate school damage - casted = i->triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; - break; - } - case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: - { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleOverrideClassScriptAuraProc(pTarget, i->spellParam, damage, i->triggeredByAura, procSpell,i->cooldown); - break; - } - default: - { - // nothing do, just charges counter - casted = true; - break; - } - } - - // Update charge (aura can be removed by triggers) - if(casted && triggeredByAuraWithCharges) - { - // need found aura (can be dropped by triggers) - AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); - AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); - for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) - { - if(itr->second == i->triggeredByAura) - { - if(i->triggeredByAura->m_procCharges > 0) - i->triggeredByAura->m_procCharges -= 1; - - i->triggeredByAura->UpdateAuraCharges(); - break; - } - } - } - } - - // Safely remove auras with zero charges - for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) - { - next = i; ++next; - if((*i)->m_procCharges == 0) - { - RemoveAurasDueToSpell((*i)->GetId()); - next = auras.begin(); - } - } - } -} - -SpellSchoolMask Unit::GetMeleeDamageSchoolMask() const -{ - return SPELL_SCHOOL_MASK_NORMAL; -} - -Player* Unit::GetSpellModOwner() -{ - if(GetTypeId()==TYPEID_PLAYER) - return (Player*)this; - if(((Creature*)this)->isPet() || ((Creature*)this)->isTotem()) - { - Unit* owner = GetOwner(); - if(owner && owner->GetTypeId()==TYPEID_PLAYER) - return (Player*)owner; - } - return NULL; -} - -///----------Pet responses methods----------------- -void Unit::SendPetCastFail(uint32 spellid, uint8 msg) -{ - Unit *owner = GetCharmerOrOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_PET_CAST_FAILED, (4+1)); - data << uint32(spellid); - data << uint8(msg); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetActionFeedback (uint8 msg) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_PET_ACTION_FEEDBACK, 1); - data << uint8(msg); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetTalk (uint32 pettalk) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_PET_ACTION_SOUND, 8+4); - data << uint64(GetGUID()); - data << uint32(pettalk); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetSpellCooldown (uint32 spellid, time_t cooltime) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_SPELL_COOLDOWN, 8+1+4+4); - data << uint64(GetGUID()); - data << uint8(0x0); // flags (0x1, 0x2) - data << uint32(spellid); - data << uint32(cooltime); - - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetClearCooldown (uint32 spellid) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_CLEAR_COOLDOWN, (4+8)); - data << uint32(spellid); - data << uint64(GetGUID()); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetAIReaction(uint64 guid) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_AI_REACTION, 12); - data << uint64(guid) << uint32(00000002); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -///----------End of Pet responses methods---------- - -void Unit::StopMoving() -{ - clearUnitState(UNIT_STAT_MOVING); - - // send explicit stop packet - // rely on vmaps here because for example stormwind is in air - float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); - //if (fabs(GetPositionZ() - z) < 2.0f) - // Relocate(GetPositionX(), GetPositionY(), z); - Relocate(GetPositionX(), GetPositionY(),GetPositionZ()); - - SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0); - - // update position and orientation; - WorldPacket data; - BuildHeartBeatMsg(&data); - SendMessageToSet(&data,false); -} - -void Unit::SetFeared(bool apply, uint64 casterGUID, uint32 spellID) -{ - if( apply ) - { - if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING)) - return; - - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); - - GetMotionMaster()->MovementExpired(false); - CastStop(GetGUID()==casterGUID ? spellID : 0); - - Unit* caster = ObjectAccessor::GetUnit(*this,casterGUID); - - GetMotionMaster()->MoveFleeing(caster); // caster==NULL processed in MoveFleeing - } - else - { - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); - - GetMotionMaster()->MovementExpired(false); - - if( GetTypeId() != TYPEID_PLAYER && isAlive() ) - { - // restore appropriate movement generator - if(getVictim()) - GetMotionMaster()->MoveChase(getVictim()); - else - GetMotionMaster()->Initialize(); - - // attack caster if can - Unit* caster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL); - if(caster && caster != getVictim() && ((Creature*)this)->AI()) - ((Creature*)this)->AI()->AttackStart(caster); - } - } - - if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SetClientControl(this, !apply); -} - -void Unit::SetConfused(bool apply, uint64 casterGUID, uint32 spellID) -{ - if( apply ) - { - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); - - CastStop(GetGUID()==casterGUID ? spellID : 0); - - GetMotionMaster()->MoveConfused(); - } - else - { - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); - - GetMotionMaster()->MovementExpired(false); - - if (GetTypeId() == TYPEID_UNIT) - { - // if in combat restore movement generator - if(getVictim()) - GetMotionMaster()->MoveChase(getVictim()); - } - } - - if(GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SetClientControl(this, !apply); -} - -bool Unit::IsSitState() const -{ - uint8 s = getStandState(); - return s == PLAYER_STATE_SIT_CHAIR || s == PLAYER_STATE_SIT_LOW_CHAIR || - s == PLAYER_STATE_SIT_MEDIUM_CHAIR || s == PLAYER_STATE_SIT_HIGH_CHAIR || - s == PLAYER_STATE_SIT; -} - -bool Unit::IsStandState() const -{ - uint8 s = getStandState(); - return !IsSitState() && s != PLAYER_STATE_SLEEP && s != PLAYER_STATE_KNEEL; -} - -void Unit::SetStandState(uint8 state) -{ - SetByteValue(UNIT_FIELD_BYTES_1, 0, state); - - if (IsStandState()) - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED); - - if(GetTypeId()==TYPEID_PLAYER) - { - WorldPacket data(SMSG_STANDSTATE_UPDATE, 1); - data << (uint8)state; - ((Player*)this)->GetSession()->SendPacket(&data); - } -} - -bool Unit::IsPolymorphed() const -{ - return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH; -} - -void Unit::SetDisplayId(uint32 modelId) -{ - SetUInt32Value(UNIT_FIELD_DISPLAYID, modelId); - - if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(!pet->isControlled()) - return; - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID); - } -} - -void Unit::ClearComboPointHolders() -{ - while(!m_ComboPointHolders.empty()) - { - uint32 lowguid = *m_ComboPointHolders.begin(); - - Player* plr = objmgr.GetPlayer(MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); - if(plr && plr->GetComboTarget()==GetGUID()) // recheck for safe - plr->ClearComboPoints(); // remove also guid from m_ComboPointHolders; - else - m_ComboPointHolders.erase(lowguid); // or remove manually - } -} - -void Unit::ClearAllReactives() -{ - - for(int i=0; i < MAX_REACTIVE; ++i) - m_reactiveTimer[i] = 0; - - if (HasAuraState( AURA_STATE_DEFENSE)) - ModifyAuraState(AURA_STATE_DEFENSE, false); - if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_PARRY)) - ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); - if (HasAuraState( AURA_STATE_CRIT)) - ModifyAuraState(AURA_STATE_CRIT, false); - if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_CRIT_STRIKE) ) - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); - - if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->ClearComboPoints(); -} - -void Unit::UpdateReactives( uint32 p_time ) -{ - for(int i = 0; i < MAX_REACTIVE; ++i) - { - ReactiveType reactive = ReactiveType(i); - - if(!m_reactiveTimer[reactive]) - continue; - - if ( m_reactiveTimer[reactive] <= p_time) - { - m_reactiveTimer[reactive] = 0; - - switch ( reactive ) - { - case REACTIVE_DEFENSE: - if (HasAuraState(AURA_STATE_DEFENSE)) - ModifyAuraState(AURA_STATE_DEFENSE, false); - break; - case REACTIVE_HUNTER_PARRY: - if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_PARRY)) - ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); - break; - case REACTIVE_CRIT: - if (HasAuraState(AURA_STATE_CRIT)) - ModifyAuraState(AURA_STATE_CRIT, false); - break; - case REACTIVE_HUNTER_CRIT: - if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_CRIT_STRIKE) ) - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); - break; - case REACTIVE_OVERPOWER: - if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->ClearComboPoints(); - break; - default: - break; - } - } - else - { - m_reactiveTimer[reactive] -= p_time; - } - } -} - -Unit* Unit::SelectNearbyTarget() const -{ - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); - Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - std::list targets; - - { - Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); - Trinity::UnitListSearcher searcher(targets, u_check); - - TypeContainerVisitor, WorldTypeMapContainer > world_unit_searcher(searcher); - TypeContainerVisitor, GridTypeMapContainer > grid_unit_searcher(searcher); - - CellLock cell_lock(cell, p); - cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); - cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); - } - - // remove current target - if(getVictim()) - targets.remove(getVictim()); - - // remove not LoS targets - for(std::list::iterator tIter = targets.begin(); tIter != targets.end();) - { - if(!IsWithinLOSInMap(*tIter)) - { - std::list::iterator tIter2 = tIter; - ++tIter; - targets.erase(tIter2); - } - else - ++tIter; - } - - // no appropriate targets - if(targets.empty()) - return NULL; - - // select random - uint32 rIdx = urand(0,targets.size()-1); - std::list::const_iterator tcIter = targets.begin(); - for(uint32 i = 0; i < rIdx; ++i) - ++tcIter; - - return *tcIter; -} - -void Unit::ApplyAttackTimePercentMod( WeaponAttackType att,float val, bool apply ) -{ - float remainingTimePct = (float)m_attackTimer[att] / (GetAttackTime(att) * m_modAttackSpeedPct[att]); - if(val > 0) - { - ApplyPercentModFloatVar(m_modAttackSpeedPct[att], val, !apply); - ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val,!apply); - } - else - { - ApplyPercentModFloatVar(m_modAttackSpeedPct[att], -val, apply); - ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,-val,apply); - } - m_attackTimer[att] = uint32(GetAttackTime(att) * m_modAttackSpeedPct[att] * remainingTimePct); -} - -void Unit::ApplyCastTimePercentMod(float val, bool apply ) -{ - if(val > 0) - ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,val,!apply); - else - ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,-val,apply); -} - -uint32 Unit::GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime ) -{ - if (CastingTime > 7000) CastingTime = 7000; - if (CastingTime < 1500) CastingTime = 1500; - - if(damagetype == DOT && !IsChanneledSpell(spellProto)) - CastingTime = 3500; - - int32 overTime = 0; - uint8 effects = 0; - bool DirectDamage = false; - bool AreaEffect = false; - - for ( uint32 i=0; i<3;i++) - { - switch ( spellProto->Effect[i] ) - { - case SPELL_EFFECT_SCHOOL_DAMAGE: - case SPELL_EFFECT_POWER_DRAIN: - case SPELL_EFFECT_HEALTH_LEECH: - case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE: - case SPELL_EFFECT_POWER_BURN: - case SPELL_EFFECT_HEAL: - DirectDamage = true; - break; - case SPELL_EFFECT_APPLY_AURA: - switch ( spellProto->EffectApplyAuraName[i] ) - { - case SPELL_AURA_PERIODIC_DAMAGE: - case SPELL_AURA_PERIODIC_HEAL: - case SPELL_AURA_PERIODIC_LEECH: - if ( GetSpellDuration(spellProto) ) - overTime = GetSpellDuration(spellProto); - break; - default: - // -5% per additional effect - ++effects; - break; - } - default: - break; - } - - if(IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetA[i])) || IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetB[i]))) - AreaEffect = true; - } - - // Combined Spells with Both Over Time and Direct Damage - if ( overTime > 0 && CastingTime > 0 && DirectDamage ) - { - // mainly for DoTs which are 3500 here otherwise - uint32 OriginalCastTime = GetSpellCastTime(spellProto); - if (OriginalCastTime > 7000) OriginalCastTime = 7000; - if (OriginalCastTime < 1500) OriginalCastTime = 1500; - // Portion to Over Time - float PtOT = (overTime / 15000.f) / ((overTime / 15000.f) + (OriginalCastTime / 3500.f)); - - if ( damagetype == DOT ) - CastingTime = uint32(CastingTime * PtOT); - else if ( PtOT < 1.0f ) - CastingTime = uint32(CastingTime * (1 - PtOT)); - else - CastingTime = 0; - } - - // Area Effect Spells receive only half of bonus - if ( AreaEffect ) - CastingTime /= 2; - - // -5% of total per any additional effect - for ( uint8 i=0; i 175 ) - { - CastingTime -= 175; - } - else - { - CastingTime = 0; - break; - } - } - - return CastingTime; -} - -void Unit::UpdateAuraForGroup(uint8 slot) -{ - if(GetTypeId() == TYPEID_PLAYER) - { - Player* player = (Player*)this; - if(player->GetGroup()) - { - player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS); - player->SetAuraUpdateMask(slot); - } - } - else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - { - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS); - pet->SetAuraUpdateMask(slot); - } - } - } -} - -float Unit::GetAPMultiplier(WeaponAttackType attType, bool normalized) -{ - if (!normalized || GetTypeId() != TYPEID_PLAYER) - return float(GetAttackTime(attType))/1000.0f; - - Item *Weapon = ((Player*)this)->GetWeaponForAttack(attType); - if (!Weapon) - return 2.4; // fist attack - - switch (Weapon->GetProto()->InventoryType) - { - case INVTYPE_2HWEAPON: - return 3.3; - case INVTYPE_RANGED: - case INVTYPE_RANGEDRIGHT: - case INVTYPE_THROWN: - return 2.8; - case INVTYPE_WEAPON: - case INVTYPE_WEAPONMAINHAND: - case INVTYPE_WEAPONOFFHAND: - default: - return Weapon->GetProto()->SubClass==ITEM_SUBCLASS_WEAPON_DAGGER ? 1.7 : 2.4; - } -} - -Aura* Unit::GetDummyAura( uint32 spell_id ) const -{ - Unit::AuraList const& mDummy = GetAurasByType(SPELL_AURA_DUMMY); - for(Unit::AuraList::const_iterator itr = mDummy.begin(); itr != mDummy.end(); ++itr) - if ((*itr)->GetId() == spell_id) - return *itr; - - return NULL; -} - -bool Unit::IsUnderLastManaUseEffect() const -{ - return getMSTimeDiff(m_lastManaUse,getMSTime()) < 5000; -} - -void Unit::SetContestedPvP(Player *attackedPlayer) -{ - Player* player = GetCharmerOrOwnerPlayerOrPlayerItself(); - - if(!player || attackedPlayer && (attackedPlayer == player || player->duel && player->duel->opponent == attackedPlayer)) - return; - - player->SetContestedPvPTimer(30000); - if(!player->hasUnitState(UNIT_STAT_ATTACK_PLAYER)) - { - player->addUnitState(UNIT_STAT_ATTACK_PLAYER); - player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP); - // call MoveInLineOfSight for nearby contested guards - SetVisibility(GetVisibility()); - } - if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER)) - { - addUnitState(UNIT_STAT_ATTACK_PLAYER); - // call MoveInLineOfSight for nearby contested guards - SetVisibility(GetVisibility()); - } -} - -void Unit::AddPetAura(PetAura const* petSpell) -{ - m_petAuras.insert(petSpell); - if(Pet* pet = GetPet()) - pet->CastPetAura(petSpell); -} - -void Unit::RemovePetAura(PetAura const* petSpell) -{ - m_petAuras.erase(petSpell); - if(Pet* pet = GetPet()) - pet->RemoveAurasDueToSpell(petSpell->GetAura(pet->GetEntry())); -} - -Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id) -{ - Pet* pet = new Pet(HUNTER_PET); - - if(!pet->CreateBaseAtCreature(creatureTarget)) - { - delete pet; - return NULL; - } - - pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, this->GetGUID()); - pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, this->GetGUID()); - pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,this->getFaction()); - pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id); - - if(!pet->InitStatsForLevel(creatureTarget->getLevel())) - { - sLog.outError("ERROR: Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget->GetEntry()); - delete pet; - return NULL; - } - - pet->GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true); - // this enables pet details window (Shift+P) - pet->AIM_Initialize(); - pet->InitPetCreateSpells(); - pet->SetHealth(pet->GetMaxHealth()); - - return pet; -} +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Common.h" +#include "Log.h" +#include "Opcodes.h" +#include "WorldPacket.h" +#include "WorldSession.h" +#include "World.h" +#include "ObjectMgr.h" +#include "SpellMgr.h" +#include "Unit.h" +#include "QuestDef.h" +#include "Player.h" +#include "Creature.h" +#include "Spell.h" +#include "Group.h" +#include "SpellAuras.h" +#include "MapManager.h" +#include "ObjectAccessor.h" +#include "CreatureAI.h" +#include "Formulas.h" +#include "Pet.h" +#include "Util.h" +#include "Totem.h" +#include "BattleGround.h" +#include "OutdoorPvP.h" +#include "InstanceSaveMgr.h" +#include "GridNotifiersImpl.h" +#include "CellImpl.h" +#include "Path.h" + +#include + +float baseMoveSpeed[MAX_MOVE_TYPE] = +{ + 2.5f, // MOVE_WALK + 7.0f, // MOVE_RUN + 1.25f, // MOVE_WALKBACK + 4.722222f, // MOVE_SWIM + 4.5f, // MOVE_SWIMBACK + 3.141594f, // MOVE_TURN + 7.0f, // MOVE_FLY + 4.5f, // MOVE_FLYBACK +}; + +// auraTypes contains attacker auras capable of proc'ing cast auras +static Unit::AuraTypeSet GenerateAttakerProcCastAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_DUMMY); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); + auraTypes.insert(SPELL_AURA_MOD_HASTE); + auraTypes.insert(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + return auraTypes; +} + +// auraTypes contains victim auras capable of proc'ing cast auras +static Unit::AuraTypeSet GenerateVictimProcCastAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_DUMMY); + auraTypes.insert(SPELL_AURA_PRAYER_OF_MENDING); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); + return auraTypes; +} + +// auraTypes contains auras capable of proc effect/damage (but not cast) for attacker +static Unit::AuraTypeSet GenerateAttakerProcEffectAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_MOD_DAMAGE_DONE); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); + auraTypes.insert(SPELL_AURA_MOD_CASTING_SPEED); + auraTypes.insert(SPELL_AURA_MOD_RATING); + return auraTypes; +} + +// auraTypes contains auras capable of proc effect/damage (but not cast) for victim +static Unit::AuraTypeSet GenerateVictimProcEffectAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_MOD_RESISTANCE); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); + auraTypes.insert(SPELL_AURA_MOD_PARRY_PERCENT); + auraTypes.insert(SPELL_AURA_MOD_BLOCK_PERCENT); + auraTypes.insert(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); + return auraTypes; +} + +static Unit::AuraTypeSet attackerProcCastAuraTypes = GenerateAttakerProcCastAuraTypes(); +static Unit::AuraTypeSet attackerProcEffectAuraTypes = GenerateAttakerProcEffectAuraTypes(); + +static Unit::AuraTypeSet victimProcCastAuraTypes = GenerateVictimProcCastAuraTypes(); +static Unit::AuraTypeSet victimProcEffectAuraTypes = GenerateVictimProcEffectAuraTypes(); + +// auraTypes contains auras capable of proc'ing for attacker and victim +static Unit::AuraTypeSet GenerateProcAuraTypes() +{ + Unit::AuraTypeSet auraTypes; + auraTypes.insert(attackerProcCastAuraTypes.begin(),attackerProcCastAuraTypes.end()); + auraTypes.insert(attackerProcEffectAuraTypes.begin(),attackerProcEffectAuraTypes.end()); + auraTypes.insert(victimProcCastAuraTypes.begin(),victimProcCastAuraTypes.end()); + auraTypes.insert(victimProcEffectAuraTypes.begin(),victimProcEffectAuraTypes.end()); + return auraTypes; +} + +static Unit::AuraTypeSet procAuraTypes = GenerateProcAuraTypes(); + +bool IsPassiveStackableSpell( uint32 spellId ) +{ + if(!IsPassiveSpell(spellId)) + return false; + + SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); + if(!spellProto) + return false; + + for(int j = 0; j < 3; ++j) + { + if(std::find(procAuraTypes.begin(),procAuraTypes.end(),spellProto->EffectApplyAuraName[j])!=procAuraTypes.end()) + return false; + } + + return true; +} + +Unit::Unit() +: WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) +{ + m_objectType |= TYPEMASK_UNIT; + m_objectTypeId = TYPEID_UNIT; + // 2.3.2 - 0x70 + m_updateFlag = (UPDATEFLAG_HIGHGUID | UPDATEFLAG_LIVING | UPDATEFLAG_HASPOSITION); + + m_attackTimer[BASE_ATTACK] = 0; + m_attackTimer[OFF_ATTACK] = 0; + m_attackTimer[RANGED_ATTACK] = 0; + m_modAttackSpeedPct[BASE_ATTACK] = 1.0f; + m_modAttackSpeedPct[OFF_ATTACK] = 1.0f; + m_modAttackSpeedPct[RANGED_ATTACK] = 1.0f; + + m_extraAttacks = 0; + m_canDualWield = false; + + m_state = 0; + m_form = FORM_NONE; + m_deathState = ALIVE; + + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + m_currentSpells[i] = NULL; + + m_addDmgOnce = 0; + + for(int i = 0; i < MAX_TOTEM; ++i) + m_TotemSlot[i] = 0; + + m_ObjectSlot[0] = m_ObjectSlot[1] = m_ObjectSlot[2] = m_ObjectSlot[3] = 0; + //m_Aura = NULL; + //m_AurasCheck = 2000; + //m_removeAuraTimer = 4; + //tmpAura = NULL; + waterbreath = false; + + m_Visibility = VISIBILITY_ON; + + m_interruptMask = 0; + m_detectInvisibilityMask = 0; + m_invisibilityMask = 0; + m_transform = 0; + m_ShapeShiftFormSpellId = 0; + m_canModifyStats = false; + + for (int i = 0; i < MAX_SPELL_IMMUNITY; i++) + m_spellImmune[i].clear(); + for (int i = 0; i < UNIT_MOD_END; i++) + { + m_auraModifiersGroup[i][BASE_VALUE] = 0.0f; + m_auraModifiersGroup[i][BASE_PCT] = 1.0f; + m_auraModifiersGroup[i][TOTAL_VALUE] = 0.0f; + m_auraModifiersGroup[i][TOTAL_PCT] = 1.0f; + } + // implement 50% base damage from offhand + m_auraModifiersGroup[UNIT_MOD_DAMAGE_OFFHAND][TOTAL_PCT] = 0.5f; + + for (int i = 0; i < 3; i++) + { + m_weaponDamage[i][MINDAMAGE] = BASE_MINDAMAGE; + m_weaponDamage[i][MAXDAMAGE] = BASE_MAXDAMAGE; + } + for (int i = 0; i < MAX_STATS; i++) + m_createStats[i] = 0.0f; + + m_attacking = NULL; + m_modMeleeHitChance = 0.0f; + m_modRangedHitChance = 0.0f; + m_modSpellHitChance = 0.0f; + m_baseSpellCritChance = 5; + + m_CombatTimer = 0; + m_lastManaUse = 0; + + //m_victimThreat = 0.0f; + for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) + m_threatModifier[i] = 1.0f; + m_isSorted = true; + for (int i = 0; i < MAX_MOVE_TYPE; ++i) + m_speed_rate[i] = 1.0f; + + m_removedAuras = 0; + m_charmInfo = NULL; + m_unit_movement_flags = 0; + m_isPossessed = false; + + // remove aurastates allowing special moves + for(int i=0; i < MAX_REACTIVE; ++i) + m_reactiveTimer[i] = 0; +} + +Unit::~Unit() +{ + // set current spells as deletable + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + { + if (m_currentSpells[i]) + { + m_currentSpells[i]->SetReferencedFromCurrent(false); + m_currentSpells[i] = NULL; + } + } + + RemoveAllGameObjects(); + RemoveAllDynObjects(); + + if(m_charmInfo) delete m_charmInfo; +} + +void Unit::Update( uint32 p_time ) +{ + /*if(p_time > m_AurasCheck) + { + m_AurasCheck = 2000; + _UpdateAura(); + }else + m_AurasCheck -= p_time;*/ + + // WARNING! Order of execution here is important, do not change. + // Spells must be processed with event system BEFORE they go to _UpdateSpells. + // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad. + m_Events.Update( p_time ); + _UpdateSpells( p_time ); + + // update combat timer only for players and pets + if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet() || ((Creature*)this)->isCharmed())) + { + // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away + // targets without stopping half way there and running off. + // These flags are reset after target dies or another command is given. + if( m_HostilRefManager.isEmpty() ) + { + // m_CombatTimer set at aura start and it will be freeze until aura removing + if ( m_CombatTimer <= p_time ) + ClearInCombat(); + else + m_CombatTimer -= p_time; + } + } + + if(!hasUnitState(UNIT_STAT_CASTING)) + { + if(uint32 base_att = getAttackTimer(BASE_ATTACK)) + setAttackTimer(BASE_ATTACK, (p_time >= base_att ? 0 : base_att - p_time) ); + if(uint32 ranged_att = getAttackTimer(RANGED_ATTACK)) + setAttackTimer(RANGED_ATTACK, (p_time >= ranged_att ? 0 : ranged_att - p_time) ); + if(uint32 off_att = getAttackTimer(OFF_ATTACK)) + setAttackTimer(OFF_ATTACK, (p_time >= off_att ? 0 : off_att - p_time) ); + } + + // update abilities available only for fraction of time + UpdateReactives( p_time ); + + ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, GetHealth() < GetMaxHealth()*0.20f); + ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, GetHealth() < GetMaxHealth()*0.35f); + + i_motionMaster.UpdateMotion(p_time); +} + +bool Unit::haveOffhandWeapon() const +{ + if(GetTypeId() == TYPEID_PLAYER) + return ((Player*)this)->GetWeaponForAttack(OFF_ATTACK,true); + else + return m_canDualWield; +} + +void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player* player) +{ + float x, y, z; + if(GetMotionMaster()->GetDestination(x, y, z)) + SendMonsterMoveWithSpeed(x, y, z, GetUnitMovementFlags(), 0, player); +} + +void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime, Player* player) +{ + if (!transitTime) + { + float dx = x - GetPositionX(); + float dy = y - GetPositionY(); + float dz = z - GetPositionZ(); + + float dist = ((dx*dx) + (dy*dy) + (dz*dz)); + if(dist<0) + dist = 0; + else + dist = sqrt(dist); + + double speed = GetSpeed((MovementFlags & MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); + if(speed<=0) + speed = 2.5f; + speed *= 0.001f; + transitTime = static_cast(dist / speed + 0.5); + } + //float orientation = (float)atan2((double)dy, (double)dx); + SendMonsterMove(x, y, z, 0, MovementFlags, transitTime, player); +} + +void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player) +{ + WorldPacket data( SMSG_MONSTER_MOVE, (41 + GetPackGUID().size()) ); + data.append(GetPackGUID()); + + // Point A, starting location + data << GetPositionX() << GetPositionY() << GetPositionZ(); + // unknown field - unrelated to orientation + // seems to increment about 1000 for every 1.7 seconds + // for now, we'll just use mstime + data << getMSTime(); + + data << uint8(type); // unknown + switch(type) + { + case 0: // normal packet + break; + case 1: // stop packet + SendMessageToSet( &data, true ); + return; + case 3: // not used currently + data << uint64(0); // probably target guid + break; + case 4: // not used currently + data << float(0); // probably orientation + break; + } + + //Movement Flags (0x0 = walk, 0x100 = run, 0x200 = fly/swim) + data << uint32(MovementFlags); + + data << Time; // Time in between points + data << uint32(1); // 1 single waypoint + data << NewPosX << NewPosY << NewPosZ; // the single waypoint Point B + + if(player) + player->GetSession()->SendPacket(&data); + else + SendMessageToSet( &data, true ); +} + +void Unit::SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, uint32 MovementFlags) +{ + uint32 traveltime = uint32(path.GetTotalLength(start, end) * 32); + + uint32 pathSize = end-start; + + WorldPacket data( SMSG_MONSTER_MOVE, (GetPackGUID().size()+4+4+4+4+1+4+4+4+pathSize*4*3) ); + data.append(GetPackGUID()); + data << GetPositionX(); + data << GetPositionY(); + data << GetPositionZ(); + + // unknown field - unrelated to orientation + // seems to increment about 1000 for every 1.7 seconds + // for now, we'll just use mstime + data << getMSTime(); + + data << uint8( 0 ); + data << uint32( MovementFlags ); + data << uint32( traveltime ); + data << uint32( pathSize ); + data.append( (char*)path.GetNodes(start), pathSize * 4 * 3 ); + + //WPAssert( data.size() == 37 + pathnodes.Size( ) * 4 * 3 ); + SendMessageToSet(&data, true); +} + +void Unit::resetAttackTimer(WeaponAttackType type) +{ + m_attackTimer[type] = uint32(GetAttackTime(type) * m_modAttackSpeedPct[type]); +} + +bool Unit::canReachWithAttack(Unit *pVictim) const +{ + assert(pVictim); + return IsWithinDistInMap(pVictim, GetCombatReach()); +} + +bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const +{ + if (!obj || !IsInMap(obj)) return false; + + float dx = GetPositionX() - obj->GetPositionX(); + float dy = GetPositionY() - obj->GetPositionY(); + float dz = GetPositionZ() - obj->GetPositionZ(); + float distsq = dx*dx + dy*dy + dz*dz; + //not sure here, or combatreach + combatreach? + float sizefactor = GetCombatReach() + obj->GetCombatReach(); + float maxdist = dist2compare + sizefactor; + + return distsq < maxdist * maxdist; +} + +void Unit::GetRandomContactPoint( const Unit* obj, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const +{ + //assert(GetCombatReach() > 0.1); + float combat_reach = GetCombatReach(); + if(combat_reach < 0.1) + { + sLog.outError("Unit %u (Type: %u) has invalid combat_reach %f",GetGUIDLow(),GetTypeId(),combat_reach); + if(GetTypeId() == TYPEID_UNIT) + sLog.outError("Creature entry %u has invalid combat_reach", ((Creature*)this)->GetEntry()); + combat_reach = 0.5; + } + uint32 attacker_number = getAttackers().size(); + if(attacker_number > 0) --attacker_number; + GetNearPoint(obj,x,y,z,obj->GetCombatReach(), distance2dMin+(distance2dMax-distance2dMin)*rand_norm() + , GetAngle(obj) + (attacker_number ? (M_PI/2 - M_PI * rand_norm()) * (float)attacker_number / combat_reach / 3 : 0)); +} + +void Unit::RemoveSpellsCausingAura(AuraType auraType) +{ + if (auraType >= TOTAL_AURAS) return; + AuraList::iterator iter, next; + for (iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end(); iter = next) + { + next = iter; + ++next; + + if (*iter) + { + RemoveAurasDueToSpell((*iter)->GetId()); + if (!m_modAuras[auraType].empty()) + next = m_modAuras[auraType].begin(); + else + return; + } + } +} + +void Unit::RemoveAurasWithInterruptFlags(uint32 flag) +{ + if(!(m_interruptMask & flag)) + return; + + // interrupt auras + AuraList::iterator iter, next; + for (iter = m_interruptableAuras.begin(); iter != m_interruptableAuras.end(); iter = next) + { + next = iter; + ++next; + + //sLog.outDetail("auraflag:%u flag:%u = %u",(*iter)->GetSpellProto()->AuraInterruptFlags,flag,(*iter)->GetSpellProto()->AuraInterruptFlags & flag); + if(*iter && ((*iter)->GetSpellProto()->AuraInterruptFlags & flag)) + { + RemoveAurasDueToSpell((*iter)->GetId()); + if (!m_interruptableAuras.empty()) + next = m_interruptableAuras.begin(); + else + break; + } + } + + // interrupt channeled spell + if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) + if(spell->getState() == SPELL_STATE_CASTING && (spell->m_spellInfo->ChannelInterruptFlags & flag)) + InterruptNonMeleeSpells(false); +} + +void Unit::UpdateInterruptMask() +{ + m_interruptMask = 0; + for(AuraList::iterator i = m_interruptableAuras.begin(); i != m_interruptableAuras.end(); ++i) + { + if(*i) + m_interruptMask |= (*i)->GetSpellProto()->AuraInterruptFlags; + } + if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) + if(spell->getState() == SPELL_STATE_CASTING) + m_interruptMask |= spell->m_spellInfo->ChannelInterruptFlags; +} + +bool Unit::HasAuraType(AuraType auraType) const +{ + return (!m_modAuras[auraType].empty()); +} + +/* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */ +void Unit::RemoveSpellbyDamageTaken(uint32 damage, uint32 spell) +{ + // The chance to dispel an aura depends on the damage taken with respect to the casters level. + uint32 max_dmg = getLevel() > 8 ? 25 * getLevel() - 150 : 50; + float chance = float(damage) / max_dmg * 100.0f; + + AuraList::iterator i, next; + for(i = m_ccAuras.begin(); i != m_ccAuras.end(); i = next) + { + next = i; + ++next; + + if(*i && (!spell || (*i)->GetId() != spell) && roll_chance_f(chance)) + { + RemoveAurasDueToSpell((*i)->GetId()); + if (!m_ccAuras.empty()) + next = m_ccAuras.begin(); + else + return; + } + } +} + +uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss) +{ + if (!pVictim->isAlive() || pVictim->isInFlight() || pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) + return 0; + + //You don't lose health from damage taken from another player while in a sanctuary + //You still see it in the combat log though + if(pVictim != this && GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) + { + const AreaTableEntry *area = GetAreaEntryByAreaID(pVictim->GetAreaId()); + if(area && area->flags & AREA_FLAG_SANCTUARY) //sanctuary + return 0; + } + + //Script Event damage taken + if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() ) + ((Creature *)pVictim)->AI()->DamageTaken(this, damage); + + if(!damage) //when will zero damage? need interrupt aura? + { + // Rage from physical damage received . + if(cleanDamage && cleanDamage->damage && (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) && pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) + ((Player*)pVictim)->RewardRage(cleanDamage->damage, 0, false); + + return 0; + } + + if(pVictim->GetTypeId() != TYPEID_PLAYER) + { + // no xp,health if type 8 /critters/ + if ( pVictim->GetCreatureType() == CREATURE_TYPE_CRITTER) + { + // critters run away when hit + pVictim->GetMotionMaster()->MoveFleeing(this); + + // allow loot only if has loot_id in creature_template + if(damage >= pVictim->GetHealth()) + { + pVictim->setDeathState(JUST_DIED); + pVictim->SetHealth(0); + + CreatureInfo const* cInfo = ((Creature*)pVictim)->GetCreatureInfo(); + if(cInfo && cInfo->lootid) + pVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); + + // some critters required for quests + if(GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->KilledMonster(pVictim->GetEntry(),pVictim->GetGUID()); + } + else + pVictim->ModifyHealth(- (int32)damage); + + return damage; + } + } + + DEBUG_LOG("DealDamageStart"); + + uint32 health = pVictim->GetHealth(); + sLog.outDetail("deal dmg:%d to health:%d ",damage,health); + + // duel ends when player has 1 or less hp + bool duel_hasEnded = false; + if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->duel && damage >= (health-1)) + { + // prevent kill only if killed in duel and killed by opponent or opponent controlled creature + if(((Player*)pVictim)->duel->opponent==this || ((Player*)pVictim)->duel->opponent->GetGUID() == GetOwnerGUID()) + damage = health-1; + + duel_hasEnded = true; + } + + // Rage from Damage made (only from direct weapon damage) + if( cleanDamage && damagetype==DIRECT_DAMAGE && this != pVictim && GetTypeId() == TYPEID_PLAYER && (getPowerType() == POWER_RAGE)) + { + uint32 weaponSpeedHitFactor; + + switch(cleanDamage->attackType) + { + case BASE_ATTACK: + { + if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 7); + else + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); + + ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); + + break; + } + case OFF_ATTACK: + { + if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); + else + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 1.75f); + + ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); + + break; + } + case RANGED_ATTACK: + break; + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER && GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)pVictim)->InBattleGround()) + { + Player *killer = ((Player*)this); + if(killer != ((Player*)pVictim)) + if(BattleGround *bg = killer->GetBattleGround()) + bg->UpdatePlayerScore(killer, SCORE_DAMAGE_DONE, damage); + } + } + + if (pVictim->GetTypeId() == TYPEID_UNIT && !((Creature*)pVictim)->isPet() && !((Creature*)pVictim)->hasLootRecipient()) + ((Creature*)pVictim)->SetLootRecipient(this); + if (health <= damage) + { + DEBUG_LOG("DealDamage: victim just died"); + + // find player: owner of controlled `this` or `this` itself maybe + Player *player = GetCharmerOrOwnerPlayerOrPlayerItself(); + + if(pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->GetLootRecipient()) + player = ((Creature*)pVictim)->GetLootRecipient(); + // Reward player, his pets, and group/raid members + // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop) + if(player && player!=pVictim) + if(player->RewardPlayerAndGroupAtKill(pVictim)) + player->ProcDamageAndSpell(pVictim,PROC_FLAG_KILL_XP_GIVER,PROC_FLAG_NONE); + + DEBUG_LOG("DealDamageAttackStop"); + + // stop combat + pVictim->CombatStop(); + pVictim->getHostilRefManager().deleteReferences(); + + // stop movement + pVictim->StopMoving(); + + bool damageFromSpiritOfRedemtionTalent = spellProto && spellProto->Id == 27795; + + // if talent known but not triggered (check priest class for speedup check) + Aura* spiritOfRedemtionTalentReady = NULL; + if( !damageFromSpiritOfRedemtionTalent && // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION + pVictim->GetTypeId()==TYPEID_PLAYER && pVictim->getClass()==CLASS_PRIEST ) + { + AuraList const& vDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); ++itr) + { + if((*itr)->GetSpellProto()->SpellIconID==1654) + { + spiritOfRedemtionTalentReady = *itr; + break; + } + } + } + + DEBUG_LOG("SET JUST_DIED"); + if(!spiritOfRedemtionTalentReady) + pVictim->setDeathState(JUST_DIED); + + // outdoor pvp things, do these after setting the death state, else the player activity notify won't work... doh... + // handle player kill only if not suicide (spirit of redemption for example) + if(GetTypeId() == TYPEID_PLAYER && this != pVictim) + { + if(OutdoorPvP * pvp = ((Player*)this)->GetOutdoorPvP()) + { + pvp->HandleKill((Player*)this,pVictim); + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + if(OutdoorPvP * pvp = ((Player*)pVictim)->GetOutdoorPvP()) + { + pvp->HandlePlayerActivityChanged((Player*)pVictim); + } + } + + DEBUG_LOG("DealDamageHealth1"); + + if(spiritOfRedemtionTalentReady) + { + // save value before aura remove + uint32 ressSpellId = pVictim->GetUInt32Value(PLAYER_SELF_RES_SPELL); + if(!ressSpellId) + ressSpellId = ((Player*)pVictim)->GetResurrectionSpellId(); + + //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers) + pVictim->RemoveAllAurasOnDeath(); + + // restore for use at real death + pVictim->SetUInt32Value(PLAYER_SELF_RES_SPELL,ressSpellId); + + // FORM_SPIRITOFREDEMPTION and related auras + pVictim->CastSpell(pVictim,27827,true,NULL,spiritOfRedemtionTalentReady); + } + else + pVictim->SetHealth(0); + + // remember victim PvP death for corpse type and corpse reclaim delay + // at original death (not at SpiritOfRedemtionTalent timeout) + if( pVictim->GetTypeId()==TYPEID_PLAYER && !damageFromSpiritOfRedemtionTalent ) + ((Player*)pVictim)->SetPvPDeath(player!=NULL); + + // 10% durability loss on death + // clean InHateListOf + if (pVictim->GetTypeId() == TYPEID_PLAYER) + { + // only if not player and not controlled by player pet. And not at BG + if (durabilityLoss && !player && !((Player*)pVictim)->InBattleGround()) + { + DEBUG_LOG("We are dead, loosing 10 percents durability"); + ((Player*)pVictim)->DurabilityLossAll(0.10f,false); + // durability lost message + WorldPacket data(SMSG_DURABILITY_DAMAGE_DEATH, 0); + ((Player*)pVictim)->GetSession()->SendPacket(&data); + } + // Call KilledUnit for creatures + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->KilledUnit(pVictim); + } + else // creature died + { + DEBUG_LOG("DealDamageNotPlayer"); + Creature *cVictim = (Creature*)pVictim; + + if(!cVictim->isPet()) + { + cVictim->DeleteThreatList(); + cVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); + } + + // Call KilledUnit for creatures, this needs to be called after the lootable flag is set + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->KilledUnit(pVictim); + + // Call creature just died function + if (cVictim->AI()) + cVictim->AI()->JustDied(this); + + // Dungeon specific stuff, only applies to players killing creatures + if(cVictim->GetInstanceId()) + { + Map *m = cVictim->GetMap(); + Player *creditedPlayer = GetCharmerOrOwnerPlayerOrPlayerItself(); + // TODO: do instance binding anyway if the charmer/owner is offline + + if(m->IsDungeon() && creditedPlayer) + { + if(m->IsRaid() || m->IsHeroic()) + { + if(cVictim->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND) + ((InstanceMap *)m)->PermBindAllPlayers(creditedPlayer); + } + else + { + // the reset time is set but not added to the scheduler + // until the players leave the instance + time_t resettime = cVictim->GetRespawnTimeEx() + 2 * HOUR; + if(InstanceSave *save = sInstanceSaveManager.GetInstanceSave(cVictim->GetInstanceId())) + if(save->GetResetTime() < resettime) save->SetResetTime(resettime); + } + } + } + } + + // last damage from non duel opponent or opponent controlled creature + if(duel_hasEnded) + { + assert(pVictim->GetTypeId()==TYPEID_PLAYER); + Player *he = (Player*)pVictim; + + assert(he->duel); + + he->duel->opponent->CombatStopWithPets(true); + he->CombatStopWithPets(true); + + he->DuelComplete(DUEL_INTERUPTED); + } + + // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill) + if(pVictim->GetTypeId() == TYPEID_PLAYER && (((Player*)pVictim)->InBattleGround())) + { + Player *killed = ((Player*)pVictim); + Player *killer = NULL; + if(GetTypeId() == TYPEID_PLAYER) + killer = ((Player*)this); + else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) + { + Unit *owner = GetOwner(); + if(owner && owner->GetTypeId() == TYPEID_PLAYER) + killer = ((Player*)owner); + } + + if(killer) + if(BattleGround *bg = killed->GetBattleGround()) + bg->HandleKillPlayer(killed, killer); // drop flags and etc + } + } + else // if (health <= damage) + { + DEBUG_LOG("DealDamageAlive"); + + pVictim->ModifyHealth(- (int32)damage); + + // Check if health is below 20% (apply damage before to prevent case when after ProcDamageAndSpell health < damage + if(pVictim->GetHealth()*5 < pVictim->GetMaxHealth()) + { + uint32 procVictim = PROC_FLAG_NONE; + + // if just dropped below 20% (for CheatDeath) + if((pVictim->GetHealth()+damage)*5 > pVictim->GetMaxHealth()) + procVictim = PROC_FLAG_LOW_HEALTH; + + ProcDamageAndSpell(pVictim,PROC_FLAG_TARGET_LOW_HEALTH,procVictim); + } + + if(damagetype != DOT) + { + if(getVictim()) + { + // if have target and damage pVictim just call AI reaction + if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI()) + ((Creature*)pVictim)->AI()->AttackedBy(this); + } + else + { + // if not have main target then attack state with target (including AI call) + //start melee attacks only after melee hit + Attack(pVictim,(damagetype == DIRECT_DAMAGE)); + } + } + + if(damagetype == DIRECT_DAMAGE|| damagetype == SPELL_DIRECT_DAMAGE) + pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE); + + if (pVictim->GetTypeId() != TYPEID_PLAYER) + { + if(spellProto && IsDamageToThreatSpell(spellProto)) + pVictim->AddThreat(this, damage*2, damageSchoolMask, spellProto); + else + pVictim->AddThreat(this, damage, damageSchoolMask, spellProto); + } + else // victim is a player + { + // Rage from damage received + if(this != pVictim && pVictim->getPowerType() == POWER_RAGE) + { + uint32 rage_damage = damage + (cleanDamage ? cleanDamage->damage : 0); + ((Player*)pVictim)->RewardRage(rage_damage, 0, false); + } + + // random durability for items (HIT TAKEN) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) + { + EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(slot); + } + } + + if(GetTypeId()==TYPEID_PLAYER) + { + // random durability for items (HIT DONE) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) + { + EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); + ((Player*)this)->DurabilityPointLossForEquipSlot(slot); + } + } + + if (damagetype != NODAMAGE && damage)// && pVictim->GetTypeId() == TYPEID_PLAYER) + { + //if (se->procFlags & (1<<3)) + pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DAMAGE); + pVictim->RemoveSpellbyDamageTaken(damage, spellProto ? spellProto->Id : 0); + + if(pVictim != this && pVictim->GetTypeId() == TYPEID_PLAYER) // does not support creature push_back + { + if(damagetype != DOT) + { + if(Spell* spell = pVictim->m_currentSpells[CURRENT_GENERIC_SPELL]) + { + if(spell->getState() == SPELL_STATE_PREPARING) + { + uint32 interruptFlags = spell->m_spellInfo->InterruptFlags; + if(interruptFlags & SPELL_INTERRUPT_FLAG_DAMAGE) + pVictim->InterruptNonMeleeSpells(false); + else if(interruptFlags & SPELL_INTERRUPT_FLAG_PUSH_BACK) + spell->Delayed(); + } + } + } + + if(Spell* spell = pVictim->m_currentSpells[CURRENT_CHANNELED_SPELL]) + { + if(spell->getState() == SPELL_STATE_CASTING) + { + uint32 channelInterruptFlags = spell->m_spellInfo->ChannelInterruptFlags; + if( channelInterruptFlags & CHANNEL_FLAG_DELAY ) + spell->DelayedChannel(); + } + } + } + } + + // last damage from duel opponent + if(duel_hasEnded) + { + assert(pVictim->GetTypeId()==TYPEID_PLAYER); + Player *he = (Player*)pVictim; + + assert(he->duel); + + he->SetHealth(1); + + he->duel->opponent->CombatStopWithPets(true); + he->CombatStopWithPets(true); + + he->CastSpell(he, 7267, true); // beg + he->DuelComplete(DUEL_WON); + } + } + + DEBUG_LOG("DealDamageEnd returned %d damage", damage); + + return damage; +} + +void Unit::CastStop(uint32 except_spellid) +{ + for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) + if (m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id!=except_spellid) + InterruptSpell(i,false); +} + +void Unit::CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); + + if(!spellInfo) + { + sLog.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + CastSpell(Victim,spellInfo,triggered,castItem,triggeredByAura, originalCaster); +} + +void Unit::CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + assert(Victim); + if(!spellInfo) + { + sLog.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + if (castItem) + DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); + + if(!originalCaster && triggeredByAura) + originalCaster = triggeredByAura->GetCasterGUID(); + + Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); + + SpellCastTargets targets; + targets.setUnitTarget( Victim ); + targets.setDestination( Victim->GetPositionX(), Victim->GetPositionY(), Victim->GetPositionZ(), false); + spell->m_CastItem = castItem; + spell->prepare(&targets, triggeredByAura); +} + +void Unit::CastCustomSpell(Unit* Victim,uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); + + if(!spellInfo) + { + sLog.outError("CastCustomSpell: unknown spell id %i\n", spellId); + return; + } + + CastCustomSpell(Victim,spellInfo,bp0,bp1,bp2,triggered,castItem,triggeredByAura, originalCaster); +} + +void Unit::CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + if(!spellInfo) + { + sLog.outError("CastCustomSpell: unknown spell"); + return; + } + + if (castItem) + DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); + + if(!originalCaster && triggeredByAura) + originalCaster = triggeredByAura->GetCasterGUID(); + + Spell *spell = new Spell(this, spellInfo, triggered, originalCaster); + + if(bp0) + spell->m_currentBasePoints[0] = *bp0-int32(spellInfo->EffectBaseDice[0]); + + if(bp1) + spell->m_currentBasePoints[1] = *bp1-int32(spellInfo->EffectBaseDice[1]); + + if(bp2) + spell->m_currentBasePoints[2] = *bp2-int32(spellInfo->EffectBaseDice[2]); + + SpellCastTargets targets; + targets.setUnitTarget( Victim ); + spell->m_CastItem = castItem; + spell->prepare(&targets, triggeredByAura); +} + +// used for scripting +void Unit::CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); + + if(!spellInfo) + { + sLog.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + CastSpell(x, y, z,spellInfo,triggered,castItem,triggeredByAura, originalCaster); +} + +// used for scripting +void Unit::CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + if(!spellInfo) + { + sLog.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + if (castItem) + DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); + + if(!originalCaster && triggeredByAura) + originalCaster = triggeredByAura->GetCasterGUID(); + + Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); + + SpellCastTargets targets; + targets.setDestination(x, y, z); + spell->m_CastItem = castItem; + spell->prepare(&targets, triggeredByAura); +} + +void Unit::DealFlatDamage(Unit *pVictim, SpellEntry const *spellInfo, uint32 *damage, CleanDamage *cleanDamage, bool *crit, bool isTriggeredSpell) +{ + // TODO this in only generic way, check for exceptions + DEBUG_LOG("DealFlatDamage (BEFORE) >> DMG:%u", *damage); + + // Per-damage class calculation + switch (spellInfo->DmgClass) + { + // Melee and Ranged Spells + case SPELL_DAMAGE_CLASS_RANGED: + case SPELL_DAMAGE_CLASS_MELEE: + { + // Calculate physical outcome + MeleeHitOutcome outcome = RollPhysicalOutcomeAgainst(pVictim, BASE_ATTACK, spellInfo); + + //Used to store the Hit Outcome + cleanDamage->hitOutCome = outcome; + + // Return miss/evade first (sends miss message) + switch(outcome) + { + case MELEE_HIT_EVADE: + { + SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_EVADES,0); + *damage = 0; + return; + } + case MELEE_HIT_MISS: + { + SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_NORMAL,0); + *damage = 0; + + if(GetTypeId()== TYPEID_PLAYER) + ((Player*)this)->UpdateWeaponSkill(BASE_ATTACK); + + CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,MELEE_HIT_MISS,spellInfo,isTriggeredSpell); + return; + } + } + + // Hitinfo, Victimstate + uint32 hitInfo = HITINFO_NORMALSWING; + VictimState victimState = VICTIMSTATE_NORMAL; + + // Physical Damage + if ( GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NORMAL ) + { + uint32 modDamage=*damage; + + // apply spellmod to Done damage + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_DAMAGE, *damage); + + //Calculate armor mitigation + uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); + + // random durability for main hand weapon (ABSORB) + if(damageAfterArmor < *damage) + if(pVictim->GetTypeId() == TYPEID_PLAYER) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); + + cleanDamage->damage += *damage - damageAfterArmor; + *damage = damageAfterArmor; + } + // Magical Damage + else + { + // Calculate damage bonus + *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); + } + + // Classify outcome + switch (outcome) + { + case MELEE_HIT_BLOCK_CRIT: + case MELEE_HIT_CRIT: + { + uint32 bonusDmg = *damage; + + // Apply crit_damage bonus + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRIT_DAMAGE_BONUS, bonusDmg); + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + bonusDmg = uint32(bonusDmg * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); + + *damage += bonusDmg; + + // Resilience - reduce crit damage + if (pVictim->GetTypeId()==TYPEID_PLAYER) + { + uint32 resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); + cleanDamage->damage += resilienceReduction; + *damage -= resilienceReduction; + } + + *crit = true; + hitInfo |= HITINFO_CRITICALHIT; + + ModifyAuraState(AURA_STATE_CRIT, true); + StartReactiveTimer( REACTIVE_CRIT ); + + if(getClass()==CLASS_HUNTER) + { + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); + StartReactiveTimer( REACTIVE_HUNTER_CRIT ); + } + + if ( outcome == MELEE_HIT_BLOCK_CRIT ) + { + uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); + if (blocked_amount >= *damage) + { + hitInfo |= HITINFO_SWINGNOHITSOUND; + victimState = VICTIMSTATE_BLOCKS; + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + } + else + { + // To Help Calculate Rage + cleanDamage->damage += blocked_amount; + *damage = *damage - blocked_amount; + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + } + break; + } + case MELEE_HIT_PARRY: + { + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + victimState = VICTIMSTATE_PARRY; + + // Counter-attack ( explained in Unit::DoAttackDamage() ) + if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN) ) + { + // Get attack timers + float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); + float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); + + // Reduce attack time + if (pVictim->haveOffhandWeapon() && offtime < basetime) + { + float percent20 = pVictim->GetAttackTime(OFF_ATTACK) * 0.20; + float percent60 = 3 * percent20; + if(offtime > percent20 && offtime <= percent60) + { + pVictim->setAttackTimer(OFF_ATTACK, uint32(percent20)); + } + else if(offtime > percent60) + { + offtime -= 2 * percent20; + pVictim->setAttackTimer(OFF_ATTACK, uint32(offtime)); + } + } + else + { + float percent20 = pVictim->GetAttackTime(BASE_ATTACK) * 0.20; + float percent60 = 3 * percent20; + if(basetime > percent20 && basetime <= percent60) + { + pVictim->setAttackTimer(BASE_ATTACK, uint32(percent20)); + } + else if(basetime > percent60) + { + basetime -= 2 * percent20; + pVictim->setAttackTimer(BASE_ATTACK, uint32(basetime)); + } + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update victim defense ? + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (PARRY) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); + } + + // Set parry flags + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + // Mongoose bite - set only Counterattack here + if (pVictim->getClass() == CLASS_HUNTER) + { + pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); + pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); + } + else + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + break; + } + case MELEE_HIT_DODGE: + { + if(pVictim->GetTypeId() == TYPEID_PLAYER) + ((Player*)pVictim)->UpdateDefense(); + + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + hitInfo |= HITINFO_SWINGNOHITSOUND; + victimState = VICTIMSTATE_DODGE; + + // Set dodge flags + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + // Overpower + if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) + { + ((Player*)this)->AddComboPoints(pVictim, 1); + StartReactiveTimer( REACTIVE_OVERPOWER ); + } + + // Riposte + if (pVictim->getClass() != CLASS_ROGUE) + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + break; + } + case MELEE_HIT_BLOCK: + { + uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); + if (blocked_amount >= *damage) + { + hitInfo |= HITINFO_SWINGNOHITSOUND; + victimState = VICTIMSTATE_BLOCKS; + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + } + else + { + // To Help Calculate Rage + cleanDamage->damage += blocked_amount; + *damage = *damage - blocked_amount; + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + break; + } + case MELEE_HIT_EVADE: // already processed early + case MELEE_HIT_MISS: // already processed early + case MELEE_HIT_GLANCING: + case MELEE_HIT_CRUSHING: + case MELEE_HIT_NORMAL: + break; + } + + // do all damage=0 cases here + if(*damage == 0) + CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,outcome,spellInfo,isTriggeredSpell); + + break; + } + // Magical Attacks + case SPELL_DAMAGE_CLASS_NONE: + case SPELL_DAMAGE_CLASS_MAGIC: + { + // Calculate damage bonus + *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); + + *crit = isSpellCrit(pVictim, spellInfo, GetSpellSchoolMask(spellInfo), BASE_ATTACK); + if (*crit) + { + *damage = SpellCriticalBonus(spellInfo, *damage, pVictim); + + // Resilience - reduce crit damage + if (pVictim && pVictim->GetTypeId()==TYPEID_PLAYER) + { + uint32 damage_reduction = ((Player *)pVictim)->GetSpellCritDamageReduction(*damage); + if(*damage > damage_reduction) + *damage -= damage_reduction; + else + *damage = 0; + } + + cleanDamage->hitOutCome = MELEE_HIT_CRIT; + } + // spell proc all magic damage==0 case in this function + if(*damage == 0) + { + // Procflags + uint32 procAttacker = PROC_FLAG_HIT_SPELL; + uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); + + ProcDamageAndSpell(pVictim, procAttacker, procVictim, 0, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); + } + + break; + } + } + + // TODO this in only generic way, check for exceptions + DEBUG_LOG("DealFlatDamage (AFTER) >> DMG:%u", *damage); +} + +uint32 Unit::SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell, bool useSpellDamage) +{ + if(!this || !pVictim) + return 0; + if(!this->isAlive() || !pVictim->isAlive()) + return 0; + + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellID); + if(!spellInfo) + return 0; + + CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL); + bool crit = false; + + if (useSpellDamage) + DealFlatDamage(pVictim, spellInfo, &damage, &cleanDamage, &crit, isTriggeredSpell); + + // If we actually dealt some damage (spell proc's for 0 damage (normal and magic) called in DealFlatDamage) + if(damage > 0) + { + // Calculate absorb & resists + uint32 absorb = 0; + uint32 resist = 0; + + CalcAbsorbResist(pVictim,GetSpellSchoolMask(spellInfo), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist); + + //No more damage left, target absorbed and/or resisted all damage + if (damage > absorb + resist) + damage -= absorb + resist; //Remove Absorbed and Resisted from damage actually dealt + else + { + uint32 HitInfo = HITINFO_SWINGNOHITSOUND; + + if (absorb) + HitInfo |= HITINFO_ABSORB; + if (resist) + { + HitInfo |= HITINFO_RESIST; + ProcDamageAndSpell(pVictim, PROC_FLAG_TARGET_RESISTS, PROC_FLAG_RESIST_SPELL, 0, GetSpellSchoolMask(spellInfo), spellInfo,isTriggeredSpell); + } + + //Send resist + SendAttackStateUpdate(HitInfo, pVictim, 1, GetSpellSchoolMask(spellInfo), damage, absorb,resist,VICTIMSTATE_NORMAL,0); + return 0; + } + + // Deal damage done + damage = DealDamage(pVictim, damage, &cleanDamage, SPELL_DIRECT_DAMAGE, GetSpellSchoolMask(spellInfo), spellInfo, true); + + // Send damage log + sLog.outDetail("SpellNonMeleeDamageLog: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u,absorb is %u,resist is %u", + GetGUIDLow(), GetTypeId(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, spellID, absorb,resist); + + // Actual log sent to client + SendSpellNonMeleeDamageLog(pVictim, spellID, damage, GetSpellSchoolMask(spellInfo), absorb, resist, false, 0, crit); + + // Procflags + uint32 procAttacker = PROC_FLAG_HIT_SPELL; + uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); + + if (crit) + { + procAttacker |= PROC_FLAG_CRIT_SPELL; + procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; + } + + ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); + + return damage; + } + else + { + // all spell proc for 0 normal and magic damage called in DealFlatDamage + + //Check for rage + if(cleanDamage.damage) + // Rage from damage received. + if(pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) + ((Player*)pVictim)->RewardRage(cleanDamage.damage, 0, false); + + return 0; + } +} + +void Unit::HandleEmoteCommand(uint32 anim_id) +{ + WorldPacket data( SMSG_EMOTE, 12 ); + data << anim_id << GetGUID(); + WPAssert(data.size() == 12); + + SendMessageToSet(&data, true); +} + +uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage) +{ + uint32 newdamage = 0; + float armor = pVictim->GetArmor(); + // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura + armor += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, SPELL_SCHOOL_MASK_NORMAL); + + if (armor<0.0f) armor=0.0f; + + float tmpvalue = 0.0f; + if(getLevel() <= 59) //Level 1-59 + tmpvalue = armor / (armor + 400.0f + 85.0f * getLevel()); + else if(getLevel() < 70) //Level 60-69 + tmpvalue = armor / (armor - 22167.5f + 467.5f * getLevel()); + else //Level 70+ + tmpvalue = armor / (armor + 10557.5f); + + if(tmpvalue < 0.0f) + tmpvalue = 0.0f; + if(tmpvalue > 0.75f) + tmpvalue = 0.75f; + newdamage = uint32(damage - (damage * tmpvalue)); + + return (newdamage > 1) ? newdamage : 1; +} + +void Unit::CalcAbsorbResist(Unit *pVictim,SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist) +{ + if(!pVictim || !pVictim->isAlive() || !damage) + return; + + // Magic damage, check for resists + if ((schoolMask & SPELL_SCHOOL_MASK_NORMAL)==0) + { + // Get base victim resistance for school + float tmpvalue2 = (float)pVictim->GetResistance(GetFirstSchoolInMask(schoolMask)); + // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura + tmpvalue2 += (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask); + + tmpvalue2 *= (float)(0.15f / getLevel()); + if (tmpvalue2 < 0.0f) + tmpvalue2 = 0.0f; + if (tmpvalue2 > 0.75f) + tmpvalue2 = 0.75f; + uint32 ran = urand(0, 100); + uint32 faq[4] = {24,6,4,6}; + uint8 m = 0; + float Binom = 0.0f; + for (uint8 i = 0; i < 4; i++) + { + Binom += 2400 *( powf(tmpvalue2, i) * powf( (1-tmpvalue2), (4-i)))/faq[i]; + if (ran > Binom ) + ++m; + else + break; + } + if (damagetype == DOT && m == 4) + *resist += uint32(damage - 1); + else + *resist += uint32(damage * m / 4); + if(*resist > damage) + *resist = damage; + } + else + *resist = 0; + + int32 RemainingDamage = damage - *resist; + + // absorb without mana cost + int32 reflectDamage = 0; + Aura* reflectAura = NULL; + AuraList const& vSchoolAbsorb = pVictim->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB); + for(AuraList::const_iterator i = vSchoolAbsorb.begin(), next; i != vSchoolAbsorb.end() && RemainingDamage > 0; i = next) + { + next = i; ++next; + + if (((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + // Cheat Death + if((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_ROGUE && (*i)->GetSpellProto()->SpellIconID == 2109) + { + if (((Player*)pVictim)->HasSpellCooldown(31231)) + continue; + if (pVictim->GetHealth() <= RemainingDamage) + { + int32 chance = (*i)->GetModifier()->m_amount; + if (roll_chance_i(chance)) + { + pVictim->CastSpell(pVictim,31231,true); + ((Player*)pVictim)->AddSpellCooldown(31231,0,time(NULL)+60); + + // with health > 10% lost health until health==10%, in other case no losses + uint32 health10 = pVictim->GetMaxHealth()/10; + RemainingDamage = pVictim->GetHealth() > health10 ? pVictim->GetHealth() - health10 : 0; + } + } + continue; + } + + int32 currentAbsorb; + + //Reflective Shield + if ((pVictim != this) && (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_PRIEST && (*i)->GetSpellProto()->SpellFamilyFlags == 0x1) + { + if(Unit* caster = (*i)->GetCaster()) + { + AuraList const& vOverRideCS = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator k = vOverRideCS.begin(); k != vOverRideCS.end(); ++k) + { + switch((*k)->GetModifier()->m_miscvalue) + { + case 5065: // Rank 1 + case 5064: // Rank 2 + case 5063: // Rank 3 + case 5062: // Rank 4 + case 5061: // Rank 5 + { + if(RemainingDamage >= (*i)->GetModifier()->m_amount) + reflectDamage = (*i)->GetModifier()->m_amount * (*k)->GetModifier()->m_amount/100; + else + reflectDamage = (*k)->GetModifier()->m_amount * RemainingDamage/100; + reflectAura = *i; + + } break; + default: break; + } + + if(reflectDamage) + break; + } + } + } + + if (RemainingDamage >= (*i)->GetModifier()->m_amount) + { + currentAbsorb = (*i)->GetModifier()->m_amount; + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + next = vSchoolAbsorb.begin(); + } + else + { + currentAbsorb = RemainingDamage; + (*i)->GetModifier()->m_amount -= RemainingDamage; + } + + RemainingDamage -= currentAbsorb; + } + // do not cast spells while looping auras; auras can get invalid otherwise + if (reflectDamage) + pVictim->CastCustomSpell(this, 33619, &reflectDamage, NULL, NULL, true, NULL, reflectAura); + + // absorb by mana cost + AuraList const& vManaShield = pVictim->GetAurasByType(SPELL_AURA_MANA_SHIELD); + for(AuraList::const_iterator i = vManaShield.begin(), next; i != vManaShield.end() && RemainingDamage > 0; i = next) + { + next = i; ++next; + + // check damage school mask + if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + int32 currentAbsorb; + if (RemainingDamage >= (*i)->GetModifier()->m_amount) + currentAbsorb = (*i)->GetModifier()->m_amount; + else + currentAbsorb = RemainingDamage; + + float manaMultiplier = (*i)->GetSpellProto()->EffectMultipleValue[(*i)->GetEffIndex()]; + if(Player *modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod((*i)->GetId(), SPELLMOD_MULTIPLE_VALUE, manaMultiplier); + + int32 maxAbsorb = int32(pVictim->GetPower(POWER_MANA) / manaMultiplier); + if (currentAbsorb > maxAbsorb) + currentAbsorb = maxAbsorb; + + (*i)->GetModifier()->m_amount -= currentAbsorb; + if((*i)->GetModifier()->m_amount <= 0) + { + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + next = vManaShield.begin(); + } + + int32 manaReduction = int32(currentAbsorb * manaMultiplier); + pVictim->ApplyPowerMod(POWER_MANA, manaReduction, false); + + RemainingDamage -= currentAbsorb; + } + + // only split damage if not damaging yourself + if(pVictim != this) + { + AuraList const& vSplitDamageFlat = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT); + for(AuraList::const_iterator i = vSplitDamageFlat.begin(), next; i != vSplitDamageFlat.end() && RemainingDamage >= 0; i = next) + { + next = i; ++next; + + // check damage school mask + if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + // Damage can be splitted only if aura has an alive caster + Unit *caster = (*i)->GetCaster(); + if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) + continue; + + int32 currentAbsorb; + if (RemainingDamage >= (*i)->GetModifier()->m_amount) + currentAbsorb = (*i)->GetModifier()->m_amount; + else + currentAbsorb = RemainingDamage; + + RemainingDamage -= currentAbsorb; + + SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, currentAbsorb, schoolMask, 0, 0, false, 0, false); + + CleanDamage cleanDamage = CleanDamage(currentAbsorb, BASE_ATTACK, MELEE_HIT_NORMAL); + DealDamage(caster, currentAbsorb, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); + } + + AuraList const& vSplitDamagePct = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT); + for(AuraList::const_iterator i = vSplitDamagePct.begin(), next; i != vSplitDamagePct.end() && RemainingDamage >= 0; i = next) + { + next = i; ++next; + + // check damage school mask + if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + // Damage can be splitted only if aura has an alive caster + Unit *caster = (*i)->GetCaster(); + if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) + continue; + + int32 splitted = int32(RemainingDamage * (*i)->GetModifier()->m_amount / 100.0f); + + RemainingDamage -= splitted; + + SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, splitted, schoolMask, 0, 0, false, 0, false); + + CleanDamage cleanDamage = CleanDamage(splitted, BASE_ATTACK, MELEE_HIT_NORMAL); + DealDamage(caster, splitted, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); + } + } + + *absorb = damage - RemainingDamage - *resist; +} + +void Unit::DoAttackDamage (Unit *pVictim, uint32 *damage, CleanDamage *cleanDamage, uint32 *blocked_amount, SpellSchoolMask damageSchoolMask, uint32 *hitInfo, VictimState *victimState, uint32 *absorbDamage, uint32 *resistDamage, WeaponAttackType attType, SpellEntry const *spellCasted, bool isTriggeredSpell) +{ + MeleeHitOutcome outcome; + + // If is casted Melee spell, calculate like physical + if(!spellCasted) + outcome = RollMeleeOutcomeAgainst (pVictim, attType); + else + outcome = RollPhysicalOutcomeAgainst (pVictim, attType, spellCasted); + + if(outcome == MELEE_HIT_MISS ||outcome == MELEE_HIT_DODGE ||outcome == MELEE_HIT_BLOCK ||outcome == MELEE_HIT_PARRY) + pVictim->AddThreat(this, 0.0f); + switch(outcome) + { + case MELEE_HIT_EVADE: + { + *hitInfo |= HITINFO_MISS; + *damage = 0; + cleanDamage->damage = 0; + return; + } + case MELEE_HIT_MISS: + { + *hitInfo |= HITINFO_MISS; + *damage = 0; + cleanDamage->damage = 0; + if(GetTypeId()== TYPEID_PLAYER) + ((Player*)this)->UpdateWeaponSkill(attType); + return; + } + } + + /// If this is a creature and it attacks from behind it has a probability to daze it's victim + if( (outcome==MELEE_HIT_CRIT || outcome==MELEE_HIT_CRUSHING || outcome==MELEE_HIT_NORMAL || outcome==MELEE_HIT_GLANCING) && + GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGUID() && !pVictim->HasInArc(M_PI, this) + && pVictim->GetTypeId() == TYPEID_PLAYER) + { + // -probability is between 0% and 40% + // 20% base chance + float Probability = 20; + + //there is a newbie protection, at level 10 just 7% base chance; assuming linear function + if( pVictim->getLevel() < 30 ) + Probability = 0.65f*pVictim->getLevel()+0.5; + + uint32 VictimDefense=pVictim->GetDefenseSkillValue(this); + uint32 AttackerMeleeSkill=GetUnitMeleeSkill(pVictim); + + Probability *= AttackerMeleeSkill/(float)VictimDefense; + + if(Probability > 40.0f) + Probability = 40.0f; + + if(roll_chance_f(Probability)) + CastSpell(pVictim, 1604, true); + } + + //Calculate the damage after armor mitigation if SPELL_SCHOOL_NORMAL + if (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) + { + uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); + + // random durability for main hand weapon (ABSORB) + if(damageAfterArmor < *damage) + if(pVictim->GetTypeId() == TYPEID_PLAYER) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); + + cleanDamage->damage += *damage - damageAfterArmor; + *damage = damageAfterArmor; + } + + if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) + ((Player*)this)->UpdateCombatSkills(pVictim, attType, outcome, false); + + if(GetTypeId() != TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) + ((Player*)pVictim)->UpdateCombatSkills(this, attType, outcome, true); + + switch (outcome) + { + case MELEE_HIT_BLOCK_CRIT: + case MELEE_HIT_CRIT: + { + //*hitInfo = 0xEA; + // 0xEA + *hitInfo = HITINFO_CRITICALHIT | HITINFO_NORMALSWING2 | 0x8; + + // Crit bonus calc + uint32 crit_bonus; + crit_bonus = *damage; + + // Apply crit_damage bonus for melee spells + if (spellCasted) + { + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellCasted->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + crit_bonus = uint32(crit_bonus * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); + } + + *damage += crit_bonus; + + uint32 resilienceReduction = 0; + + if(attType == RANGED_ATTACK) + { + int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE); + *damage = int32((*damage) * float((100.0f + mod)/100.0f)); + // Resilience - reduce crit damage + if (pVictim->GetTypeId()==TYPEID_PLAYER) + resilienceReduction = ((Player*)pVictim)->GetRangedCritDamageReduction(*damage); + } + else + { + int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE); + mod += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE); + *damage = int32((*damage) * float((100.0f + mod)/100.0f)); + // Resilience - reduce crit damage + if (pVictim->GetTypeId()==TYPEID_PLAYER) + resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); + } + + *damage -= resilienceReduction; + cleanDamage->damage += resilienceReduction; + + if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) + ((Player*)this)->UpdateWeaponSkill(attType); + + ModifyAuraState(AURA_STATE_CRIT, true); + StartReactiveTimer( REACTIVE_CRIT ); + + if(getClass()==CLASS_HUNTER) + { + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); + StartReactiveTimer( REACTIVE_HUNTER_CRIT ); + } + + if ( outcome == MELEE_HIT_BLOCK_CRIT ) + { + *blocked_amount = pVictim->GetShieldBlockValue(); + + if (pVictim->GetUnitBlockChance()) + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); + else + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + //Only set VICTIMSTATE_BLOCK on a full block + if (*blocked_amount >= uint32(*damage)) + { + *victimState = VICTIMSTATE_BLOCKS; + *blocked_amount = uint32(*damage); + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + break; + } + + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL); + break; + } + case MELEE_HIT_PARRY: + { + if(attType == RANGED_ATTACK) //range attack - no parry + { + outcome = MELEE_HIT_NORMAL; + break; + } + + cleanDamage->damage += *damage; + *damage = 0; + *victimState = VICTIMSTATE_PARRY; + + // instant (maybe with small delay) counter attack + { + float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); + float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); + + // after parry nearest next attack time will reduced at %40 from full attack time. + // The delay cannot be reduced to less than 20% of your weapon base swing delay. + if (pVictim->haveOffhandWeapon() && offtime < basetime) + { + float percent20 = pVictim->GetAttackTime(OFF_ATTACK)*0.20; + float percent60 = 3*percent20; + // set to 20% if in range 20%...20+40% of full time + if(offtime > percent20 && offtime <= percent60) + { + pVictim->setAttackTimer(OFF_ATTACK,uint32(percent20)); + } + // decrease at %40 from full time + else if(offtime > percent60) + { + offtime -= 2*percent20; + pVictim->setAttackTimer(OFF_ATTACK,uint32(offtime)); + } + // ELSE not changed + } + else + { + float percent20 = pVictim->GetAttackTime(BASE_ATTACK)*0.20; + float percent60 = 3*percent20; + // set to 20% if in range 20%...20+40% of full time + if(basetime > percent20 && basetime <= percent60) + { + pVictim->setAttackTimer(BASE_ATTACK,uint32(percent20)); + } + // decrease at %40 from full time + else if(basetime > percent60) + { + basetime -= 2*percent20; + pVictim->setAttackTimer(BASE_ATTACK,uint32(basetime)); + } + // ELSE not changed + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update victim defense ? + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (PARRY) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); + } + + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + if (pVictim->getClass() == CLASS_HUNTER) + { + pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); + pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); + } + else + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + + CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + return; + } + case MELEE_HIT_DODGE: + { + if(attType == RANGED_ATTACK) //range attack - no dodge + { + outcome = MELEE_HIT_NORMAL; + break; + } + + cleanDamage->damage += *damage; + *damage = 0; + *victimState = VICTIMSTATE_DODGE; + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + ((Player*)pVictim)->UpdateDefense(); + + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + if (pVictim->getClass() != CLASS_ROGUE) // Riposte + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + + // Overpower + if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) + { + ((Player*)this)->AddComboPoints(pVictim, 1); + StartReactiveTimer( REACTIVE_OVERPOWER ); + } + + CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + return; + } + case MELEE_HIT_BLOCK: + { + *blocked_amount = pVictim->GetShieldBlockValue(); + + if (pVictim->GetUnitBlockChance()) + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); + else + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + //Only set VICTIMSTATE_BLOCK on a full block + if (*blocked_amount >= uint32(*damage)) + { + *victimState = VICTIMSTATE_BLOCKS; + *blocked_amount = uint32(*damage); + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + + break; + } + case MELEE_HIT_GLANCING: + { + int32 leveldif = int32(pVictim->getLevel()) - int32(getLevel()); + if (leveldif > 3) leveldif = 3; + *damage *= (1 - leveldif * 0.1f); + cleanDamage->damage = *damage; + *hitInfo |= HITINFO_GLANCING; + break; + } + case MELEE_HIT_CRUSHING: + { + // 150% normal damage + *damage += (*damage / 2); + cleanDamage->damage = *damage; + *hitInfo |= HITINFO_CRUSHING; + // TODO: victimState, victim animation? + break; + } + default: + break; + } + + // apply melee damage bonus and absorb only if base damage not fully blocked to prevent negative damage or damage with full block + if(*victimState != VICTIMSTATE_BLOCKS) + { + MeleeDamageBonus(pVictim, damage,attType,spellCasted); + CalcAbsorbResist(pVictim, damageSchoolMask, DIRECT_DAMAGE, *damage-*blocked_amount, absorbDamage, resistDamage); + } + + if (*absorbDamage) *hitInfo |= HITINFO_ABSORB; + if (*resistDamage) *hitInfo |= HITINFO_RESIST; + + cleanDamage->damage += *blocked_amount; + + if (*damage <= *absorbDamage + *resistDamage + *blocked_amount) + { + //*hitInfo = 0x00010020; + //*hitInfo |= HITINFO_SWINGNOHITSOUND; + //*damageType = 0; + CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + return; + } + + // update at damage Judgement aura duration that applied by attacker at victim + if(*damage) + { + AuraMap const& vAuras = pVictim->GetAuras(); + for(AuraMap::const_iterator itr = vAuras.begin(); itr != vAuras.end(); ++itr) + { + SpellEntry const *spellInfo = (*itr).second->GetSpellProto(); + if( (spellInfo->AttributesEx3 & 0x40000) && spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && + ((*itr).second->GetCasterGUID() == GetGUID() && (!spellCasted || spellCasted->Id == 35395)) ) + { + (*itr).second->SetAuraDuration((*itr).second->GetAuraMaxDuration()); + (*itr).second->UpdateAuraDuration(); + } + } + } + + CastMeleeProcDamageAndSpell(pVictim, (*damage - *absorbDamage - *resistDamage - *blocked_amount), damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + + // victim's damage shield + // yet another hack to fix crashes related to the aura getting removed during iteration + std::set alreadyDone; + uint32 removedAuras = pVictim->m_removedAuras; + AuraList const& vDamageShields = pVictim->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD); + for(AuraList::const_iterator i = vDamageShields.begin(), next = vDamageShields.begin(); i != vDamageShields.end(); i = next) + { + ++next; + if (alreadyDone.find(*i) == alreadyDone.end()) + { + alreadyDone.insert(*i); + pVictim->SpellNonMeleeDamageLog(this, (*i)->GetId(), (*i)->GetModifier()->m_amount, false, false); + if (pVictim->m_removedAuras > removedAuras) + { + removedAuras = pVictim->m_removedAuras; + next = vDamageShields.begin(); + } + } + } +} + +void Unit::AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType, bool extra ) +{ + if(hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING) || HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED) ) + return; + + if (!pVictim->isAlive()) + return; + + if(IsNonMeleeSpellCasted(false)) + return; + + CombatStart(pVictim); + + uint32 hitInfo; + if (attType == BASE_ATTACK) + hitInfo = HITINFO_NORMALSWING2; + else if (attType == OFF_ATTACK) + hitInfo = HITINFO_LEFTSWING; + else + return; // ignore ranged case + + uint32 extraAttacks = m_extraAttacks; + + // melee attack spell casted at main hand attack only + if (attType == BASE_ATTACK && m_currentSpells[CURRENT_MELEE_SPELL]) + { + m_currentSpells[CURRENT_MELEE_SPELL]->cast(); + + // not recent extra attack only at any non extra attack (melee spell case) + if(!extra && extraAttacks) + { + while(m_extraAttacks) + { + AttackerStateUpdate(pVictim, BASE_ATTACK, true); + if(m_extraAttacks > 0) + --m_extraAttacks; + } + } + + return; + } + + VictimState victimState = VICTIMSTATE_NORMAL; + + CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL ); + uint32 blocked_dmg = 0; + uint32 absorbed_dmg = 0; + uint32 resisted_dmg = 0; + + SpellSchoolMask meleeSchoolMask = GetMeleeDamageSchoolMask(); + + if(pVictim->IsImmunedToDamage(meleeSchoolMask,true)) // use charges + { + SendAttackStateUpdate (HITINFO_NORMALSWING, pVictim, 1, meleeSchoolMask, 0, 0, 0, VICTIMSTATE_IS_IMMUNE, 0); + + // not recent extra attack only at any non extra attack (miss case) + if(!extra && extraAttacks) + { + while(m_extraAttacks) + { + AttackerStateUpdate(pVictim, BASE_ATTACK, true); + if(m_extraAttacks > 0) + --m_extraAttacks; + } + } + + return; + } + + uint32 damage = CalculateDamage (attType, false); + + DoAttackDamage (pVictim, &damage, &cleanDamage, &blocked_dmg, meleeSchoolMask, &hitInfo, &victimState, &absorbed_dmg, &resisted_dmg, attType); + + if (hitInfo & HITINFO_MISS) + //send miss + SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); + else + { + //do animation + SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); + + if (damage > (absorbed_dmg + resisted_dmg + blocked_dmg)) + damage -= (absorbed_dmg + resisted_dmg + blocked_dmg); + else + damage = 0; + + DealDamage (pVictim, damage, &cleanDamage, DIRECT_DAMAGE, meleeSchoolMask, NULL, true); + + if(GetTypeId() == TYPEID_PLAYER && pVictim->isAlive()) + { + for(int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; i++) + ((Player*)this)->CastItemCombatSpell(((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0,i),pVictim,attType); + } + } + + if (GetTypeId() == TYPEID_PLAYER) + DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", + GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); + else + DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", + GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); + + // extra attack only at any non extra attack (normal case) + if(!extra && extraAttacks) + { + while(m_extraAttacks) + { + AttackerStateUpdate(pVictim, BASE_ATTACK, true); + if(m_extraAttacks > 0) + --m_extraAttacks; + } + } +} + +MeleeHitOutcome Unit::RollPhysicalOutcomeAgainst (Unit const *pVictim, WeaponAttackType attType, SpellEntry const *spellInfo) +{ + // Miss chance based on melee + float miss_chance = MeleeMissChanceCalc(pVictim, attType); + + // Critical hit chance + float crit_chance = GetUnitCriticalChance(attType, pVictim); + // this is to avoid compiler issue when declaring variables inside if + float block_chance, parry_chance, dodge_chance; + + // cannot be dodged/parried/blocked + if(spellInfo->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) + { + block_chance = 0.0f; + parry_chance = 0.0f; + dodge_chance = 0.0f; + } + else + { + // parry can be avoided only by some abilities + parry_chance = pVictim->GetUnitParryChance(); + // block might be bypassed by it as well + block_chance = pVictim->GetUnitBlockChance(); + // stunned target cannot dodge and this is check in GetUnitDodgeChance() + dodge_chance = pVictim->GetUnitDodgeChance(); + } + + // Only players can have Talent&Spell bonuses + if (GetTypeId() == TYPEID_PLAYER) + { + // Increase from SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL aura + crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, spellInfo->SchoolMask); + + if( dodge_chance != 0.0f ) // if dodge chance is already 0, ignore talents for speed + { + AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); + for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) + { + // can't be dodged rogue finishing move + if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) + { + if(spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) + { + dodge_chance = 0.0f; + break; + } + } + } + } + } + + // Spellmods + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); + + DEBUG_LOG("PHYSICAL OUTCOME: miss %f crit %f dodge %f parry %f block %f",miss_chance,crit_chance,dodge_chance,parry_chance, block_chance); + + return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100),int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), true); +} + +MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(const Unit *pVictim, WeaponAttackType attType) const +{ + // This is only wrapper + + // Miss chance based on melee + float miss_chance = MeleeMissChanceCalc(pVictim, attType); + + // Critical hit chance + float crit_chance = GetUnitCriticalChance(attType, pVictim); + + // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case) + float dodge_chance = pVictim->GetUnitDodgeChance(); + float block_chance = pVictim->GetUnitBlockChance(); + float parry_chance = pVictim->GetUnitParryChance(); + + // Useful if want to specify crit & miss chances for melee, else it could be removed + DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance,crit_chance,dodge_chance,parry_chance,block_chance); + + return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100), int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), false); +} + +MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance, bool SpellCasted ) const +{ + if(pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) + return MELEE_HIT_EVADE; + + int32 attackerMaxSkillValueForLevel = GetMaxSkillValueForLevel(pVictim); + int32 victimMaxSkillValueForLevel = pVictim->GetMaxSkillValueForLevel(this); + + int32 attackerWeaponSkill = GetWeaponSkillValue(attType,pVictim); + int32 victimDefenseSkill = pVictim->GetDefenseSkillValue(this); + + // bonus from skills is 0.04% + int32 skillBonus = 4 * ( attackerWeaponSkill - victimMaxSkillValueForLevel ); + int32 skillBonus2 = 4 * ( attackerMaxSkillValueForLevel - victimDefenseSkill ); + int32 sum = 0, tmp = 0; + int32 roll = urand (0, 10000); + + DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus); + DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d", + roll, miss_chance, dodge_chance, parry_chance, block_chance, crit_chance); + + tmp = miss_chance; + + if (tmp > 0 && roll < (sum += tmp )) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS"); + return MELEE_HIT_MISS; + } + + // always crit against a sitting target (except 0 crit chance) + if( pVictim->GetTypeId() == TYPEID_PLAYER && crit_chance > 0 && !pVictim->IsStandState() ) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)"); + return MELEE_HIT_CRIT; + } + + // Dodge chance + + // only players can't dodge if attacker is behind + if (pVictim->GetTypeId() == TYPEID_PLAYER && !pVictim->HasInArc(M_PI,this)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player."); + } + else + { + // Reduce dodge chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + dodge_chance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); + + // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE + dodge_chance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); + + tmp = dodge_chance; + if ( (tmp > 0) // check if unit _can_ dodge + && ((tmp -= skillBonus) > 0) + && roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum-tmp, sum); + return MELEE_HIT_DODGE; + } + } + + // parry & block chances + + // check if attack comes from behind, nobody can parry or block if attacker is behind + if (!pVictim->HasInArc(M_PI,this)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind."); + } + else + { + // Reduce parry chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + parry_chance-= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); + + if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY) ) + { + int32 tmp = int32(parry_chance); + if ( (tmp > 0) // check if unit _can_ parry + && ((tmp -= skillBonus) > 0) + && (roll < (sum += tmp))) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum-tmp, sum); + return MELEE_HIT_PARRY; + } + } + + if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_BLOCK) ) + { + tmp = block_chance; + if ( (tmp > 0) // check if unit _can_ block + && ((tmp -= skillBonus) > 0) + && (roll < (sum += tmp))) + { + // Critical chance + tmp = crit_chance + skillBonus2; + if ( GetTypeId() == TYPEID_PLAYER && SpellCasted && tmp > 0 ) + { + if ( roll_chance_i(tmp/100)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCKED CRIT"); + return MELEE_HIT_BLOCK_CRIT; + } + } + DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum-tmp, sum); + return MELEE_HIT_BLOCK; + } + } + } + + // Critical chance + tmp = crit_chance + skillBonus2; + + if (tmp > 0 && roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum-tmp, sum); + return MELEE_HIT_CRIT; + } + + // Max 40% chance to score a glancing blow against mobs that are higher level (can do only players and pets and not with ranged weapon) + if( attType != RANGED_ATTACK && !SpellCasted && + (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet()) && + pVictim->GetTypeId() != TYPEID_PLAYER && !((Creature*)pVictim)->isPet() && + getLevel() < pVictim->getLevelForTarget(this) ) + { + // cap possible value (with bonuses > max skill) + int32 skill = attackerWeaponSkill; + int32 maxskill = attackerMaxSkillValueForLevel; + skill = (skill > maxskill) ? maxskill : skill; + + tmp = (10 + (victimDefenseSkill - skill)) * 100; + tmp = tmp > 4000 ? 4000 : tmp; + if (roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum-4000, sum); + return MELEE_HIT_GLANCING; + } + } + + if(GetTypeId()!=TYPEID_PLAYER && !(((Creature*)this)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_CRUSH) && !((Creature*)this)->isPet() ) + { + // mobs can score crushing blows if they're 3 or more levels above victim + // or when their weapon skill is 15 or more above victim's defense skill + tmp = victimDefenseSkill; + int32 tmpmax = victimMaxSkillValueForLevel; + // having defense above your maximum (from items, talents etc.) has no effect + tmp = tmp > tmpmax ? tmpmax : tmp; + // tmp = mob's level * 5 - player's current defense skill + tmp = attackerMaxSkillValueForLevel - tmp; + if(tmp >= 15) + { + // add 2% chance per lacking skill point, min. is 15% + tmp = tmp * 200 - 1500; + if (roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum-tmp, sum); + return MELEE_HIT_CRUSHING; + } + } + } + + DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL"); + return MELEE_HIT_NORMAL; +} + +uint32 Unit::CalculateDamage (WeaponAttackType attType, bool normalized) +{ + float min_damage, max_damage; + + if (normalized && GetTypeId()==TYPEID_PLAYER) + ((Player*)this)->CalculateMinMaxDamage(attType,normalized,min_damage, max_damage); + else + { + switch (attType) + { + case RANGED_ATTACK: + min_damage = GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE); + max_damage = GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE); + break; + case BASE_ATTACK: + min_damage = GetFloatValue(UNIT_FIELD_MINDAMAGE); + max_damage = GetFloatValue(UNIT_FIELD_MAXDAMAGE); + break; + case OFF_ATTACK: + min_damage = GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE); + max_damage = GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE); + break; + // Just for good manner + default: + min_damage = 0.0f; + max_damage = 0.0f; + break; + } + } + + if (min_damage > max_damage) + { + std::swap(min_damage,max_damage); + } + + if(max_damage == 0.0f) + max_damage = 5.0f; + + return urand((uint32)min_damage, (uint32)max_damage); +} + +float Unit::CalculateLevelPenalty(SpellEntry const* spellProto) const +{ + if(spellProto->spellLevel <= 0) + return 1.0f; + + float LvlPenalty = 0.0f; + + if(spellProto->spellLevel < 20) + LvlPenalty = 20.0f - spellProto->spellLevel * 3.75f; + float LvlFactor = (float(spellProto->spellLevel) + 6.0f) / float(getLevel()); + if(LvlFactor > 1.0f) + LvlFactor = 1.0f; + + return (100.0f - LvlPenalty) * LvlFactor / 100.0f; +} + +void Unit::SendAttackStart(Unit* pVictim) +{ + WorldPacket data( SMSG_ATTACKSTART, 16 ); + data << GetGUID(); + data << pVictim->GetGUID(); + + SendMessageToSet(&data, true); + DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" ); +} + +void Unit::SendAttackStop(Unit* victim) +{ + if(!victim) + return; + + WorldPacket data( SMSG_ATTACKSTOP, (4+16) ); // we guess size + data.append(GetPackGUID()); + data.append(victim->GetPackGUID()); // can be 0x00... + data << uint32(0); // can be 0x1 + SendMessageToSet(&data, true); + sLog.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER ? "player" : "creature"), GetGUIDLow(), (victim->GetTypeId()==TYPEID_PLAYER ? "player" : "creature"),victim->GetGUIDLow()); + + /*if(victim->GetTypeId() == TYPEID_UNIT) + ((Creature*)victim)->AI().EnterEvadeMode(this);*/ +} + +/* +// Melee based spells can be miss, parry or dodge on this step +// Crit or block - determined on damage calculation phase! (and can be both in some time) +float Unit::MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell) +{ + // Calculate hit chance (more correct for chance mod) + int32 HitChance; + + // PvP - PvE melee chances + int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; + int32 leveldif = pVictim->getLevelForTarget(this) - getLevelForTarget(pVictim); + if(leveldif < 3) + HitChance = 95 - leveldif; + else + HitChance = 93 - (leveldif - 2) * lchance; + + // Hit chance depends from victim auras + if(attType == RANGED_ATTACK) + HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); + else + HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); + + // Spellmod from SPELLMOD_RESIST_MISS_CHANCE + if(Player *modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, HitChance); + + // Miss = 100 - hit + float miss_chance= 100.0f - HitChance; + + // Bonuses from attacker aura and ratings + if (attType == RANGED_ATTACK) + miss_chance -= m_modRangedHitChance; + else + miss_chance -= m_modMeleeHitChance; + + // bonus from skills is 0.04% + miss_chance -= skillDiff * 0.04f; + + // Limit miss chance from 0 to 60% + if (miss_chance < 0.0f) + return 0.0f; + if (miss_chance > 60.0f) + return 60.0f; + return miss_chance; +} + +// Melee based spells hit result calculations +SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell) +{ + WeaponAttackType attType = BASE_ATTACK; + + if (spell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) + attType = RANGED_ATTACK; + + // bonus from skills is 0.04% per skill Diff + int32 attackerWeaponSkill = int32(GetWeaponSkillValue(attType,pVictim)); + int32 skillDiff = attackerWeaponSkill - int32(pVictim->GetMaxSkillValueForLevel(this)); + int32 fullSkillDiff = attackerWeaponSkill - int32(pVictim->GetDefenseSkillValue(this)); + + uint32 roll = urand (0, 10000); + uint32 missChance = uint32(MeleeSpellMissChance(pVictim, attType, fullSkillDiff, spell)*100.0f); + + // Roll miss + uint32 tmp = missChance; + if (roll < tmp) + return SPELL_MISS_MISS; + + // Same spells cannot be parry/dodge + if (spell->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) + return SPELL_MISS_NONE; + + // Ranged attack can`t miss too + if (attType == RANGED_ATTACK) + return SPELL_MISS_NONE; + + bool attackFromBehind = !pVictim->HasInArc(M_PI,this); + + // Roll dodge + int32 dodgeChance = int32(pVictim->GetUnitDodgeChance()*100.0f) - skillDiff * 4; + // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE + dodgeChance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); + + // Reduce dodge chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + dodgeChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); + if (dodgeChance < 0) + dodgeChance = 0; + + // Can`t dodge from behind in PvP (but its possible in PvE) + if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER && attackFromBehind) + dodgeChance = 0; + + // Rogue talent`s cant be dodged + AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); + for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) + { + if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) // can't be dodged rogue finishing move + { + if(spell->SpellFamilyName==SPELLFAMILY_ROGUE && (spell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) + { + dodgeChance = 0; + break; + } + } + } + + tmp += dodgeChance; + if (roll < tmp) + return SPELL_MISS_DODGE; + + // Roll parry + int32 parryChance = int32(pVictim->GetUnitParryChance()*100.0f) - skillDiff * 4; + // Reduce parry chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + parryChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); + // Can`t parry from behind + if (parryChance < 0 || attackFromBehind) + parryChance = 0; + + tmp += parryChance; + if (roll < tmp) + return SPELL_MISS_PARRY; + + return SPELL_MISS_NONE; +}*/ + +// TODO need use unit spell resistances in calculations +SpellMissInfo Unit::MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell) +{ + // Can`t miss on dead target (on skinning for example) + if (!pVictim->isAlive()) + return SPELL_MISS_NONE; + + SpellSchoolMask schoolMask = GetSpellSchoolMask(spell); + // PvP - PvE spell misschances per leveldif > 2 + int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 7 : 11; + int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); + + // Base hit chance from attacker and victim levels + int32 modHitChance; + if(leveldif < 3) + modHitChance = 96 - leveldif; + else + modHitChance = 94 - (leveldif - 2) * lchance; + + // Spellmod from SPELLMOD_RESIST_MISS_CHANCE + if(Player *modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, modHitChance); + // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras + modHitChance+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT, schoolMask); + // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras + modHitChance+= pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE, schoolMask); + // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura + if (IsAreaOfEffectSpell(spell)) + modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE); + // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST + if (IsDispelSpell(spell)) + modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST); + // Chance resist mechanic (select max value from every mechanic spell effect) + int32 resist_mech = 0; + // Get effects mechanic and chance + for(int eff = 0; eff < 3; ++eff) + { + int32 effect_mech = GetEffectMechanic(spell, eff); + if (effect_mech) + { + int32 temp = pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE, effect_mech); + if (resist_mech < temp) + resist_mech = temp; + } + } + // Apply mod + modHitChance-=resist_mech; + + // Chance resist debuff + modHitChance-=pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE, int32(spell->Dispel)); + + int32 HitChance = modHitChance * 100; + // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings + HitChance += int32(m_modSpellHitChance*100.0f); + + // Decrease hit chance from victim rating bonus + if (pVictim->GetTypeId()==TYPEID_PLAYER) + HitChance -= int32(((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL)*100.0f); + + if (HitChance < 100) HitChance = 100; + if (HitChance > 9900) HitChance = 9900; + + uint32 rand = urand(0,10000); + if (rand > HitChance) + return SPELL_MISS_RESIST; + return SPELL_MISS_NONE; +} + +SpellMissInfo Unit::SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool CanReflect) +{ + // Return evade for units in evade mode + if (pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) + return SPELL_MISS_EVADE; + + // If Spel has this flag cannot be resisted/immuned/etc + if (spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) + return SPELL_MISS_NONE; + + // Check for immune (use charges) + if (pVictim->IsImmunedToSpell(spell,true)) + return SPELL_MISS_IMMUNE; + + // All positive spells can`t miss + // TODO: client not show miss log for this spells - so need find info for this in dbc and use it! + if (IsPositiveSpell(spell->Id) + &&(!IsHostileTo(pVictim))) //prevent from affecting enemy by "positive" spell + return SPELL_MISS_NONE; + + // Check for immune (use charges) + if (pVictim->IsImmunedToDamage(GetSpellSchoolMask(spell),true)) + return SPELL_MISS_IMMUNE; + + // Try victim reflect spell + if (CanReflect) + { + // specialized first + Unit::AuraList const& mReflectSpellsSchool = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL); + for(Unit::AuraList::const_iterator i = mReflectSpellsSchool.begin(); i != mReflectSpellsSchool.end(); ++i) + { + if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spell)) + { + int32 reflectchance = (*i)->GetModifier()->m_amount; + if (reflectchance > 0 && roll_chance_i(reflectchance)) + { + if((*i)->m_procCharges > 0) + { + --(*i)->m_procCharges; + if((*i)->m_procCharges==0) + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + } + return SPELL_MISS_REFLECT; + } + } + } + + // generic reflection + Unit::AuraList const& mReflectSpells = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS); + for(Unit::AuraList::const_iterator i = mReflectSpells.begin(); i != mReflectSpells.end(); ++i) + { + int32 reflectchance = (*i)->GetModifier()->m_amount; + if (reflectchance > 0 && roll_chance_i(reflectchance)) + { + if((*i)->m_procCharges > 0) + { + --(*i)->m_procCharges; + if((*i)->m_procCharges==0) + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + } + return SPELL_MISS_REFLECT; + } + } + } + + // Temporary solution for melee based spells and spells vs SPELL_SCHOOL_NORMAL (hit result calculated after) + for (int i=0;i<3;i++) + { + if (spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE || + spell->Effect[i] == SPELL_EFFECT_WEAPON_PERCENT_DAMAGE || + spell->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG || + spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL) + return SPELL_MISS_NONE; + } + + // TODO need use this code for spell hit result calculation + // now code commented for computability + switch (spell->DmgClass) + { + case SPELL_DAMAGE_CLASS_RANGED: + case SPELL_DAMAGE_CLASS_MELEE: +// return MeleeSpellHitResult(pVictim, spell); + return SPELL_MISS_NONE; + case SPELL_DAMAGE_CLASS_NONE: + return SPELL_MISS_NONE; + case SPELL_DAMAGE_CLASS_MAGIC: + return MagicSpellHitResult(pVictim, spell); + } + return SPELL_MISS_NONE; +} + +float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const +{ + if(!pVictim) + return 0.0f; + + // Base misschance 5% + float misschance = 5.0f; + + // DualWield - Melee spells and physical dmg spells - 5% , white damage 24% + if (haveOffhandWeapon() && attType != RANGED_ATTACK) + { + bool isNormal = false; + for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) + { + if( m_currentSpells[i] && (GetSpellSchoolMask(m_currentSpells[i]->m_spellInfo) & SPELL_SCHOOL_MASK_NORMAL) ) + { + isNormal = true; + break; + } + } + if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL]) + { + misschance = 5.0f; + } + else + { + misschance = 24.0f; + } + } + + // PvP : PvE melee misschances per leveldif > 2 + int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; + + int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); + if(leveldif < 0) + leveldif = 0; + + // Hit chance from attacker based on ratings and auras + float m_modHitChance; + if (attType == RANGED_ATTACK) + m_modHitChance = m_modRangedHitChance; + else + m_modHitChance = m_modMeleeHitChance; + + if(leveldif < 3) + misschance += (leveldif - m_modHitChance); + else + misschance += ((leveldif - 2) * chance - m_modHitChance); + + // Hit chance for victim based on ratings + if (pVictim->GetTypeId()==TYPEID_PLAYER) + { + if (attType == RANGED_ATTACK) + misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED); + else + misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE); + } + + // Modify miss chance by victim auras + if(attType == RANGED_ATTACK) + misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); + else + misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); + + // Modify miss chance from skill difference ( bonus from skills is 0.04% ) + int32 skillBonus = int32(GetWeaponSkillValue(attType,pVictim)) - int32(pVictim->GetDefenseSkillValue(this)); + misschance -= skillBonus * 0.04f; + + // Limit miss chance from 0 to 60% + if ( misschance < 0.0f) + return 0.0f; + if ( misschance > 60.0f) + return 60.0f; + + return misschance; +} + +uint32 Unit::GetDefenseSkillValue(Unit const* target) const +{ + if(GetTypeId() == TYPEID_PLAYER) + { + // in PvP use full skill instead current skill value + uint32 value = (target && target->GetTypeId() == TYPEID_PLAYER) + ? ((Player*)this)->GetMaxSkillValue(SKILL_DEFENSE) + : ((Player*)this)->GetSkillValue(SKILL_DEFENSE); + value += uint32(((Player*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL)); + return value; + } + else + return GetUnitMeleeSkill(target); +} + +float Unit::GetUnitDodgeChance() const +{ + if(hasUnitState(UNIT_STAT_STUNNED)) + return 0.0f; + if( GetTypeId() == TYPEID_PLAYER ) + return GetFloatValue(PLAYER_DODGE_PERCENTAGE); + else + { + if(((Creature const*)this)->isTotem()) + return 0.0f; + else + { + float dodge = 5.0f; + dodge += GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT); + return dodge > 0.0f ? dodge : 0.0f; + } + } +} + +float Unit::GetUnitParryChance() const +{ + if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) + return 0.0f; + + float chance = 0.0f; + + if(GetTypeId() == TYPEID_PLAYER) + { + Player const* player = (Player const*)this; + if(player->CanParry() ) + { + Item *tmpitem = player->GetWeaponForAttack(BASE_ATTACK,true); + if(!tmpitem) + tmpitem = player->GetWeaponForAttack(OFF_ATTACK,true); + + if(tmpitem) + chance = GetFloatValue(PLAYER_PARRY_PERCENTAGE); + } + } + else if(GetTypeId() == TYPEID_UNIT) + { + if(GetCreatureType() == CREATURE_TYPE_HUMANOID) + { + chance = 5.0f; + chance += GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT); + } + } + + return chance > 0.0f ? chance : 0.0f; +} + +float Unit::GetUnitBlockChance() const +{ + if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) + return 0.0f; + + if(GetTypeId() == TYPEID_PLAYER) + { + Player const* player = (Player const*)this; + if(player->CanBlock() ) + { + Item *tmpitem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + if(tmpitem && !tmpitem->IsBroken() && tmpitem->GetProto()->Block) + return GetFloatValue(PLAYER_BLOCK_PERCENTAGE); + } + // is player but has no block ability or no not broken shield equipped + return 0.0f; + } + else + { + if(((Creature const*)this)->isTotem()) + return 0.0f; + else + { + float block = 5.0f; + block += GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT); + return block > 0.0f ? block : 0.0f; + } + } +} + +float Unit::GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const +{ + float crit; + + if(GetTypeId() == TYPEID_PLAYER) + { + switch(attackType) + { + case BASE_ATTACK: + crit = GetFloatValue( PLAYER_CRIT_PERCENTAGE ); + break; + case OFF_ATTACK: + crit = GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE ); + break; + case RANGED_ATTACK: + crit = GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE ); + break; + // Just for good manner + default: + crit = 0.0f; + break; + } + } + else + { + crit = 5.0f; + crit += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT); + } + + // flat aura mods + if(attackType == RANGED_ATTACK) + crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE); + else + crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE); + + crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); + + // reduce crit chance from Rating for players + if (pVictim->GetTypeId()==TYPEID_PLAYER) + { + if (attackType==RANGED_ATTACK) + crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED); + else + crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE); + } + + if (crit < 0.0f) + crit = 0.0f; + return crit; +} + +uint32 Unit::GetWeaponSkillValue (WeaponAttackType attType, Unit const* target) const +{ + uint32 value = 0; + if(GetTypeId() == TYPEID_PLAYER) + { + Item* item = ((Player*)this)->GetWeaponForAttack(attType,true); + + // feral or unarmed skill only for base attack + if(attType != BASE_ATTACK && !item ) + return 0; + + if(((Player*)this)->IsInFeralForm()) + return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact + + // weapon skill or (unarmed for base attack) + uint32 skill = item ? item->GetSkill() : SKILL_UNARMED; + + // in PvP use full skill instead current skill value + value = (target && target->GetTypeId() == TYPEID_PLAYER) + ? ((Player*)this)->GetMaxSkillValue(skill) + : ((Player*)this)->GetSkillValue(skill); + // Modify value from ratings + value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL)); + switch (attType) + { + case BASE_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND));break; + case OFF_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND));break; + case RANGED_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED));break; + } + } + else + value = GetUnitMeleeSkill(target); + return value; +} + +void Unit::_UpdateSpells( uint32 time ) +{ + if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]) + _UpdateAutoRepeatSpell(); + + // remove finished spells from current pointers + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + { + if (m_currentSpells[i] && m_currentSpells[i]->getState() == SPELL_STATE_FINISHED) + { + m_currentSpells[i]->SetReferencedFromCurrent(false); + m_currentSpells[i] = NULL; // remove pointer + } + } + + // TODO: Find a better way to prevent crash when multiple auras are removed. + m_removedAuras = 0; + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) + if ((*i).second) + (*i).second->SetUpdated(false); + + for (AuraMap::iterator i = m_Auras.begin(), next; i != m_Auras.end(); i = next) + { + next = i; + ++next; + if ((*i).second) + { + // prevent double update + if ((*i).second->IsUpdated()) + continue; + (*i).second->SetUpdated(true); + (*i).second->Update( time ); + // several auras can be deleted due to update + if (m_removedAuras) + { + if (m_Auras.empty()) break; + next = m_Auras.begin(); + m_removedAuras = 0; + } + } + } + + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end();) + { + if ((*i).second) + { + if ( !(*i).second->GetAuraDuration() && !((*i).second->IsPermanent() || ((*i).second->IsPassive())) ) + { + RemoveAura(i); + } + else + { + ++i; + } + } + else + { + ++i; + } + } + + if(!m_gameObj.empty()) + { + std::list::iterator ite1, dnext1; + for (ite1 = m_gameObj.begin(); ite1 != m_gameObj.end(); ite1 = dnext1) + { + dnext1 = ite1; + //(*i)->Update( difftime ); + if( !(*ite1)->isSpawned() ) + { + (*ite1)->SetOwnerGUID(0); + (*ite1)->SetRespawnTime(0); + (*ite1)->Delete(); + dnext1 = m_gameObj.erase(ite1); + } + else + ++dnext1; + } + } +} + +void Unit::_UpdateAutoRepeatSpell() +{ + //check "realtime" interrupts + if ( (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) ) + { + // cancel wand shoot + if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + m_AutoRepeatFirstCast = true; + return; + } + + //apply delay + if ( m_AutoRepeatFirstCast && getAttackTimer(RANGED_ATTACK) < 500 ) + setAttackTimer(RANGED_ATTACK,500); + m_AutoRepeatFirstCast = false; + + //castroutine + if (isAttackReady(RANGED_ATTACK)) + { + // Check if able to cast + if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->CanCast(true)) + { + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + return; + } + + // we want to shoot + Spell* spell = new Spell(this, m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo, true, 0); + spell->prepare(&(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_targets)); + + // all went good, reset attack + resetAttackTimer(RANGED_ATTACK); + } +} + +void Unit::SetCurrentCastedSpell( Spell * pSpell ) +{ + assert(pSpell); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells + + uint32 CSpellType = pSpell->GetCurrentContainer(); + + if (pSpell == m_currentSpells[CSpellType]) return; // avoid breaking self + + // break same type spell if it is not delayed + InterruptSpell(CSpellType,false); + + // special breakage effects: + switch (CSpellType) + { + case CURRENT_GENERIC_SPELL: + { + // generic spells always break channeled not delayed spells + InterruptSpell(CURRENT_CHANNELED_SPELL,false); + + // autorepeat breaking + if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) + { + // break autorepeat if not Auto Shot + if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + m_AutoRepeatFirstCast = true; + } + addUnitState(UNIT_STAT_CASTING); + } break; + + case CURRENT_CHANNELED_SPELL: + { + // channel spells always break generic non-delayed and any channeled spells + InterruptSpell(CURRENT_GENERIC_SPELL,false); + InterruptSpell(CURRENT_CHANNELED_SPELL); + + // it also does break autorepeat if not Auto Shot + if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && + m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351 ) + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + addUnitState(UNIT_STAT_CASTING); + } break; + + case CURRENT_AUTOREPEAT_SPELL: + { + // only Auto Shoot does not break anything + if (pSpell->m_spellInfo->Category == 351) + { + // generic autorepeats break generic non-delayed and channeled non-delayed spells + InterruptSpell(CURRENT_GENERIC_SPELL,false); + InterruptSpell(CURRENT_CHANNELED_SPELL,false); + } + // special action: set first cast flag + m_AutoRepeatFirstCast = true; + } break; + + default: + { + // other spell types don't break anything now + } break; + } + + // current spell (if it is still here) may be safely deleted now + if (m_currentSpells[CSpellType]) + m_currentSpells[CSpellType]->SetReferencedFromCurrent(false); + + // set new current spell + m_currentSpells[CSpellType] = pSpell; + pSpell->SetReferencedFromCurrent(true); +} + +void Unit::InterruptSpell(uint32 spellType, bool withDelayed) +{ + assert(spellType < CURRENT_MAX_SPELL); + + if(m_currentSpells[spellType] && (withDelayed || m_currentSpells[spellType]->getState() != SPELL_STATE_DELAYED) ) + { + // send autorepeat cancel message for autorepeat spells + if (spellType == CURRENT_AUTOREPEAT_SPELL) + { + if(GetTypeId()==TYPEID_PLAYER) + ((Player*)this)->SendAutoRepeatCancel(); + } + + if (m_currentSpells[spellType]->getState() != SPELL_STATE_FINISHED) + m_currentSpells[spellType]->cancel(); + m_currentSpells[spellType]->SetReferencedFromCurrent(false); + m_currentSpells[spellType] = NULL; + } +} + +bool Unit::IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled, bool skipAutorepeat) const +{ + // We don't do loop here to explicitly show that melee spell is excluded. + // Maybe later some special spells will be excluded too. + + // generic spells are casted when they are not finished and not delayed + if ( m_currentSpells[CURRENT_GENERIC_SPELL] && + (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && + (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) + return(true); + + // channeled spells may be delayed, but they are still considered casted + else if ( !skipChanneled && m_currentSpells[CURRENT_CHANNELED_SPELL] && + (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) ) + return(true); + + // autorepeat spells may be finished or delayed, but they are still considered casted + else if ( !skipAutorepeat && m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) + return(true); + + return(false); +} + +void Unit::InterruptNonMeleeSpells(bool withDelayed, uint32 spell_id) +{ + // generic spells are interrupted if they are not finished or delayed + if (m_currentSpells[CURRENT_GENERIC_SPELL] && (!spell_id || m_currentSpells[CURRENT_GENERIC_SPELL]->m_spellInfo->Id==spell_id)) + { + if ( (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && + (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) + m_currentSpells[CURRENT_GENERIC_SPELL]->cancel(); + m_currentSpells[CURRENT_GENERIC_SPELL]->SetReferencedFromCurrent(false); + m_currentSpells[CURRENT_GENERIC_SPELL] = NULL; + } + + // autorepeat spells are interrupted if they are not finished or delayed + if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && (!spell_id || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Id==spell_id)) + { + // send disable autorepeat packet in any case + if(GetTypeId()==TYPEID_PLAYER) + ((Player*)this)->SendAutoRepeatCancel(); + + if ( (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_FINISHED) && + (withDelayed || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_DELAYED) ) + m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->cancel(); + m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->SetReferencedFromCurrent(false); + m_currentSpells[CURRENT_AUTOREPEAT_SPELL] = NULL; + } + + // channeled spells are interrupted if they are not finished, even if they are delayed + if (m_currentSpells[CURRENT_CHANNELED_SPELL] && (!spell_id || m_currentSpells[CURRENT_CHANNELED_SPELL]->m_spellInfo->Id==spell_id)) + { + if (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) + m_currentSpells[CURRENT_CHANNELED_SPELL]->cancel(); + m_currentSpells[CURRENT_CHANNELED_SPELL]->SetReferencedFromCurrent(false); + m_currentSpells[CURRENT_CHANNELED_SPELL] = NULL; + } +} + +Spell* Unit::FindCurrentSpellBySpellId(uint32 spell_id) const +{ + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + if(m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id==spell_id) + return m_currentSpells[i]; + return NULL; +} + +bool Unit::isInFront(Unit const* target, float distance, float arc) const +{ + return IsWithinDistInMap(target, distance) && HasInArc( arc, target ); +} + +void Unit::SetInFront(Unit const* target) +{ + SetOrientation(GetAngle(target)); +} + +bool Unit::isInBack(Unit const* target, float distance, float arc) const +{ + return IsWithinDistInMap(target, distance) && !HasInArc( 2 * M_PI - arc, target ); +} + +bool Unit::isInLine(Unit const* target, float distance) const +{ + if(!HasInArc(M_PI, target) || !IsWithinDistInMap(target, distance)) return false; + float width = (GetObjectSize() / 2 + target->GetObjectSize()) / 2; + float angle = GetAngle(target); + angle -= GetOrientation(); + return abs(sin(angle)) * distance < width; +} + +bool Unit::isInAccessiblePlaceFor(Creature const* c) const +{ + if(IsInWater()) + return c->canSwim(); + else + return c->canWalk() || c->canFly(); +} + +bool Unit::IsInWater() const +{ + return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ()); +} + +bool Unit::IsUnderWater() const +{ + return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ()); +} + +void Unit::DeMorph() +{ + SetDisplayId(GetNativeDisplayId()); +} + +int32 Unit::GetTotalAuraModifier(AuraType auratype) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + modifier += (*i)->GetModifier()->m_amount; + + return modifier; +} + +float Unit::GetTotalAuraMultiplier(AuraType auratype) const +{ + float multiplier = 1.0f; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + multiplier *= (100.0f + (*i)->GetModifier()->m_amount)/100.0f; + + return multiplier; +} + +int32 Unit::GetMaxPositiveAuraModifier(AuraType auratype) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + if ((*i)->GetModifier()->m_amount > modifier) + modifier = (*i)->GetModifier()->m_amount; + + return modifier; +} + +int32 Unit::GetMaxNegativeAuraModifier(AuraType auratype) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + if ((*i)->GetModifier()->m_amount < modifier) + modifier = (*i)->GetModifier()->m_amount; + + return modifier; +} + +int32 Unit::GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask) + modifier += mod->m_amount; + } + return modifier; +} + +float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + float multiplier = 1.0f; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask) + multiplier *= (100.0f + mod->m_amount)/100.0f; + } + return multiplier; +} + +int32 Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask && mod->m_amount > modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +int32 Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask && mod->m_amount < modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +int32 Unit::GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value) + modifier += mod->m_amount; + } + return modifier; +} + +float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const +{ + float multiplier = 1.0f; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value) + multiplier *= (100.0f + mod->m_amount)/100.0f; + } + return multiplier; +} + +int32 Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value && mod->m_amount > modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +int32 Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value && mod->m_amount < modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +bool Unit::AddAura(Aura *Aur) +{ + // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load) + if( !isAlive() && Aur->GetId() != 20584 && Aur->GetId() != 8326 && Aur->GetId() != 2584 && + (GetTypeId()!=TYPEID_PLAYER || !((Player*)this)->GetSession()->PlayerLoading()) ) + { + delete Aur; + return false; + } + + if(Aur->GetTarget() != this) + { + sLog.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)", + Aur->GetId(),Aur->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER?"player":"creature"),GetGUIDLow(), + (Aur->GetTarget()->GetTypeId()==TYPEID_PLAYER?"player":"creature"),Aur->GetTarget()->GetGUIDLow()); + delete Aur; + return false; + } + + SpellEntry const* aurSpellInfo = Aur->GetSpellProto(); + + spellEffectPair spair = spellEffectPair(Aur->GetId(), Aur->GetEffIndex()); + AuraMap::iterator i = m_Auras.find( spair ); + + // take out same spell + if (i != m_Auras.end()) + { + // passive and persistent auras can stack with themselves any number of times + if (!Aur->IsPassive() && !Aur->IsPersistent()) + { + // replace aura if next will > spell StackAmount + if(aurSpellInfo->StackAmount) + { + if(m_Auras.count(spair) >= aurSpellInfo->StackAmount) + RemoveAura(i,AURA_REMOVE_BY_STACK); + } + // if StackAmount==0 not allow auras from same caster + else + { + for(AuraMap::iterator i2 = m_Auras.lower_bound(spair); i2 != m_Auras.upper_bound(spair); ++i2) + { + if(i2->second->GetCasterGUID()==Aur->GetCasterGUID()) + { + // can be only single (this check done at _each_ aura add + RemoveAura(i2,AURA_REMOVE_BY_STACK); + break; + } + + bool stop = false; + switch(aurSpellInfo->EffectApplyAuraName[Aur->GetEffIndex()]) + { + // DoT/HoT/etc + case SPELL_AURA_PERIODIC_DAMAGE: // allow stack + case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: + case SPELL_AURA_PERIODIC_LEECH: + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_OBS_MOD_HEALTH: + case SPELL_AURA_PERIODIC_MANA_LEECH: + case SPELL_AURA_PERIODIC_ENERGIZE: + case SPELL_AURA_OBS_MOD_MANA: + case SPELL_AURA_POWER_BURN_MANA: + break; + default: // not allow + // can be only single (this check done at _each_ aura add + RemoveAura(i2,AURA_REMOVE_BY_STACK); + stop = true; + break; + } + + if(stop) + break; + } + } + } + } + + // passive auras stack with all (except passive spell proc auras) + if ((!Aur->IsPassive() || !IsPassiveStackableSpell(Aur->GetId())) && + !(Aur->GetId() == 20584 || Aur->GetId() == 8326)) + { + if (!RemoveNoStackAurasDueToAura(Aur)) + { + delete Aur; + return false; // couldn't remove conflicting aura with higher rank + } + } + + // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura) + if (IsSingleTargetSpell(aurSpellInfo) && Aur->GetTarget()) + { + // caster pointer can be deleted in time aura remove, find it by guid at each iteration + for(;;) + { + Unit* caster = Aur->GetCaster(); + if(!caster) // caster deleted and not required adding scAura + break; + + bool restart = false; + AuraList& scAuras = caster->GetSingleCastAuras(); + for(AuraList::iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) + { + if( (*itr)->GetTarget() != Aur->GetTarget() && + IsSingleTargetSpells((*itr)->GetSpellProto(),aurSpellInfo) ) + { + if ((*itr)->IsInUse()) + { + sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for IsSingleTargetSpell", (*itr)->GetId(), (*itr)->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); + continue; + } + (*itr)->GetTarget()->RemoveAura((*itr)->GetId(), (*itr)->GetEffIndex()); + restart = true; + break; + } + } + + if(!restart) + { + // done + scAuras.push_back(Aur); + break; + } + } + } + + // add aura, register in lists and arrays + Aur->_AddAura(); + m_Auras.insert(AuraMap::value_type(spellEffectPair(Aur->GetId(), Aur->GetEffIndex()), Aur)); + if (Aur->GetModifier()->m_auraname < TOTAL_AURAS) + { + m_modAuras[Aur->GetModifier()->m_auraname].push_back(Aur); + if(Aur->GetSpellProto()->AuraInterruptFlags) + { + m_interruptableAuras.push_back(Aur); + AddInterruptMask(Aur->GetSpellProto()->AuraInterruptFlags); + } + if(Aur->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) + { + m_ccAuras.push_back(Aur); + } + } + + Aur->ApplyModifier(true,true); + sLog.outDebug("Aura %u now is in use", Aur->GetModifier()->m_auraname); + return true; +} + +void Unit::RemoveRankAurasDueToSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return; + AuraMap::iterator i,next; + for (i = m_Auras.begin(); i != m_Auras.end(); i = next) + { + next = i; + ++next; + uint32 i_spellId = (*i).second->GetId(); + if((*i).second && i_spellId && i_spellId != spellId) + { + if(spellmgr.IsRankSpellDueToSpell(spellInfo,i_spellId)) + { + RemoveAurasDueToSpell(i_spellId); + + if( m_Auras.empty() ) + break; + else + next = m_Auras.begin(); + } + } + } +} + +bool Unit::RemoveNoStackAurasDueToAura(Aura *Aur) +{ + if (!Aur) + return false; + + SpellEntry const* spellProto = Aur->GetSpellProto(); + if (!spellProto) + return false; + + uint32 spellId = Aur->GetId(); + uint32 effIndex = Aur->GetEffIndex(); + + SpellSpecific spellId_spec = GetSpellSpecific(spellId); + + AuraMap::iterator i,next; + for (i = m_Auras.begin(); i != m_Auras.end(); i = next) + { + next = i; + ++next; + if (!(*i).second) continue; + + SpellEntry const* i_spellProto = (*i).second->GetSpellProto(); + + if (!i_spellProto) + continue; + + uint32 i_spellId = i_spellProto->Id; + + if(IsPassiveSpell(i_spellId)) + { + if(IsPassiveStackableSpell(i_spellId)) + continue; + + // passive non-stackable spells not stackable only with another rank of same spell + if (!spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) + continue; + } + + uint32 i_effIndex = (*i).second->GetEffIndex(); + + if(i_spellId == spellId) continue; + + bool is_triggered_by_spell = false; + // prevent triggered aura of removing aura that triggered it + for(int j = 0; j < 3; ++j) + if (i_spellProto->EffectTriggerSpell[j] == spellProto->Id) + is_triggered_by_spell = true; + if (is_triggered_by_spell) continue; + + for(int j = 0; j < 3; ++j) + { + // prevent remove dummy triggered spells at next effect aura add + switch(spellProto->Effect[j]) // main spell auras added added after triggered spell + { + case SPELL_EFFECT_DUMMY: + switch(spellId) + { + case 5420: if(i_spellId==34123) is_triggered_by_spell = true; break; + } + break; + } + + if(is_triggered_by_spell) + break; + + // prevent remove form main spell by triggered passive spells + switch(i_spellProto->EffectApplyAuraName[j]) // main aura added before triggered spell + { + case SPELL_AURA_MOD_SHAPESHIFT: + switch(i_spellId) + { + case 24858: if(spellId==24905) is_triggered_by_spell = true; break; + case 33891: if(spellId==5420 || spellId==34123) is_triggered_by_spell = true; break; + case 34551: if(spellId==22688) is_triggered_by_spell = true; break; + } + break; + } + } + + if(!is_triggered_by_spell) + { + bool isFromSameCaster = Aur->GetCasterGUID() == (*i).second->GetCasterGUID(); + if( spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId, isFromSameCaster) ) + { + //some spells should be not removed by lower rank of them + if (!isFromSameCaster + &&(spellProto->Effect[effIndex]==SPELL_AURA_MOD_INCREASE_ENERGY) + &&(spellProto->DurationIndex==21) + &&(spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) + &&(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0)) + return false; + + //Its a parent aura (create this aura in ApplyModifier) + if ((*i).second->IsInUse()) + { + sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); + continue; + } + RemoveAurasDueToSpell(i_spellId); + + if( m_Auras.empty() ) + break; + else + next = m_Auras.begin(); + } + } + } + return true; +} + +void Unit::RemoveAura(uint32 spellId, uint32 effindex, Aura* except) +{ + spellEffectPair spair = spellEffectPair(spellId, effindex); + for(AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) + { + if(iter->second!=except) + { + RemoveAura(iter); + iter = m_Auras.lower_bound(spair); + } + else + ++iter; + } +} + +void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler) +{ + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + Aura *aur = iter->second; + if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) + { + // Custom dispel case + // Unstable Affliction + if (aur->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (aur->GetSpellProto()->SpellFamilyFlags & 0x010000000000LL)) + { + int32 damage = aur->GetModifier()->m_amount*9; + uint64 caster_guid = aur->GetCasterGUID(); + + // Remove aura + RemoveAura(iter, AURA_REMOVE_BY_DISPEL); + + // backfire damage and silence + dispeler->CastCustomSpell(dispeler, 31117, &damage, NULL, NULL, true, NULL, NULL,caster_guid); + + iter = m_Auras.begin(); // iterator can be invalidate at cast if self-dispel + } + else + RemoveAura(iter, AURA_REMOVE_BY_DISPEL); + } + else + ++iter; + } +} + +void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer) +{ + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + Aura *aur = iter->second; + if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) + { + int32 basePoints = aur->GetBasePoints(); + // construct the new aura for the attacker + Aura * new_aur = CreateAura(aur->GetSpellProto(), aur->GetEffIndex(), &basePoints, stealer); + if(!new_aur) + continue; + + // set its duration and maximum duration + // max duration 2 minutes (in msecs) + int32 dur = aur->GetAuraDuration(); + const int32 max_dur = 2*MINUTE*1000; + new_aur->SetAuraMaxDuration( max_dur > dur ? dur : max_dur ); + new_aur->SetAuraDuration( max_dur > dur ? dur : max_dur ); + + // add the new aura to stealer + stealer->AddAura(new_aur); + + // Remove aura as dispel + RemoveAura(iter, AURA_REMOVE_BY_DISPEL); + } + else + ++iter; + } +} + +void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId) +{ + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + if (iter->second->GetId() == spellId) + RemoveAura(iter, AURA_REMOVE_BY_CANCEL); + else + ++iter; + } +} + +void Unit::RemoveAurasWithDispelType( DispelType type ) +{ + // Create dispel mask by dispel type + uint32 dispelMask = GetDispellMask(type); + // Dispel all existing auras vs current dispel type + AuraMap& auras = GetAuras(); + for(AuraMap::iterator itr = auras.begin(); itr != auras.end(); ) + { + SpellEntry const* spell = itr->second->GetSpellProto(); + if( (1<Dispel) & dispelMask ) + { + // Dispel aura + RemoveAurasDueToSpell(spell->Id); + itr = auras.begin(); + } + else + ++itr; + } +} + +void Unit::RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex) +{ + AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); + if(iter != m_Auras.end()) + RemoveAura(iter); +} + +void Unit::RemoveAurasDueToSpell(uint32 spellId, Aura* except) +{ + for (int i = 0; i < 3; ++i) + RemoveAura(spellId,i,except); +} + +void Unit::RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId) +{ + for (int k=0; k < 3; ++k) + { + spellEffectPair spair = spellEffectPair(spellId, k); + for (AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) + { + if (iter->second->GetCastItemGUID() == castItem->GetGUID()) + { + RemoveAura(iter); + iter = m_Auras.upper_bound(spair); // overwrite by more appropriate + } + else + ++iter; + } + } +} + +void Unit::RemoveNotOwnSingleTargetAuras() +{ + // single target auras from other casters + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + if (iter->second->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter->second->GetSpellProto())) + RemoveAura(iter); + else + ++iter; + } + + // single target auras at other targets + AuraList& scAuras = GetSingleCastAuras(); + for (AuraList::iterator iter = scAuras.begin(); iter != scAuras.end(); ) + { + Aura* aura = *iter; + if (aura->GetTarget()!=this) + { + scAuras.erase(iter); // explicitly remove, instead waiting remove in RemoveAura + aura->GetTarget()->RemoveAura(aura->GetId(),aura->GetEffIndex()); + iter = scAuras.begin(); + } + else + ++iter; + } + +} + +void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) +{ + if (IsSingleTargetSpell((*i).second->GetSpellProto())) + { + if(Unit* caster = (*i).second->GetCaster()) + { + AuraList& scAuras = caster->GetSingleCastAuras(); + scAuras.remove((*i).second); + } + else + { + sLog.outError("Couldn't find the caster of the single target aura, may crash later!"); + assert(false); + } + } + + if ((*i).second->GetModifier()->m_auraname < TOTAL_AURAS) + { + m_modAuras[(*i).second->GetModifier()->m_auraname].remove((*i).second); + if((*i).second->GetSpellProto()->AuraInterruptFlags) + { + m_interruptableAuras.remove((*i).second); + UpdateInterruptMask(); + } + if((*i).second->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) + m_ccAuras.remove((*i).second); + } + + // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) + Aura* Aur = i->second; + // Set remove mode + Aur->SetRemoveMode(mode); + // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura + // remove aura from list before to prevent deleting it before + m_Auras.erase(i); + ++m_removedAuras; // internal count used by unit update + + // Status unsummoned at aura remove + Totem* statue = NULL; + if(IsChanneledSpell(Aur->GetSpellProto())) + if(Unit* caster = Aur->GetCaster()) + if(caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->isTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE) + statue = ((Totem*)caster); + + + if(const std::vector *spell_triggered = spellmgr.GetSpellLinked(-(int32)Aur->GetSpellProto()->Id)) + { + for(std::vector::const_iterator i = spell_triggered->begin(); i != spell_triggered->end(); ++i) + { + if(spell_triggered < 0) + RemoveAurasDueToSpell(-(*i)); + else if(Unit* caster = Aur->GetCaster()) + CastSpell(this, *i, true, 0, 0, caster->GetGUID()); + } + } + + sLog.outDebug("Aura %u now is remove mode %d",Aur->GetModifier()->m_auraname, mode); + Aur->ApplyModifier(false,true); + Aur->_RemoveAura(); + delete Aur; + + if(statue) + statue->UnSummon(); + + // only way correctly remove all auras from list + if( m_Auras.empty() ) + i = m_Auras.end(); + else + i = m_Auras.begin(); +} + +void Unit::RemoveAllAuras() +{ + while (!m_Auras.empty()) + { + AuraMap::iterator iter = m_Auras.begin(); + RemoveAura(iter); + } +} + +void Unit::RemoveArenaAuras(bool onleave) +{ + // in join, remove positive buffs, on end, remove negative + // used to remove positive visible auras in arenas + for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) + { + if ( !(iter->second->GetSpellProto()->AttributesEx4 & (1<<21)) // don't remove stances, shadowform, pally/hunter auras + && !iter->second->IsPassive() // don't remove passive auras + && (!(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) || !(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNK8)) // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable) + && (iter->second->IsPositive() ^ onleave)) // remove positive buffs on enter, negative buffs on leave + RemoveAura(iter); + else + ++iter; + } +} + +void Unit::RemoveAllAurasOnDeath() +{ + // used just after dieing to remove all visible auras + // and disable the mods for the passive ones + for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) + { + if (!iter->second->IsPassive() && !iter->second->IsDeathPersistent()) + RemoveAura(iter, AURA_REMOVE_BY_DEATH); + else + ++iter; + } +} + +void Unit::DelayAura(uint32 spellId, uint32 effindex, int32 delaytime) +{ + AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); + if (iter != m_Auras.end()) + { + if (iter->second->GetAuraDuration() < delaytime) + iter->second->SetAuraDuration(0); + else + iter->second->SetAuraDuration(iter->second->GetAuraDuration() - delaytime); + iter->second->UpdateAuraDuration(); + sLog.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter->second->GetModifier()->m_auraname, GetGUIDLow(), iter->second->GetAuraDuration()); + } +} + +void Unit::_RemoveAllAuraMods() +{ + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) + { + (*i).second->ApplyModifier(false); + } +} + +void Unit::_ApplyAllAuraMods() +{ + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) + { + (*i).second->ApplyModifier(true); + } +} + +Aura* Unit::GetAura(uint32 spellId, uint32 effindex) +{ + AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); + if (iter != m_Auras.end()) + return iter->second; + return NULL; +} + +void Unit::AddDynObject(DynamicObject* dynObj) +{ + m_dynObjGUIDs.push_back(dynObj->GetGUID()); +} + +void Unit::RemoveDynObject(uint32 spellid) +{ + if(m_dynObjGUIDs.empty()) + return; + for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(!dynObj) + { + i = m_dynObjGUIDs.erase(i); + } + else if(spellid == 0 || dynObj->GetSpellId() == spellid) + { + dynObj->Delete(); + i = m_dynObjGUIDs.erase(i); + } + else + ++i; + } +} + +void Unit::RemoveAllDynObjects() +{ + while(!m_dynObjGUIDs.empty()) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(dynObj) + dynObj->Delete(); + m_dynObjGUIDs.erase(m_dynObjGUIDs.begin()); + } +} + +DynamicObject * Unit::GetDynObject(uint32 spellId, uint32 effIndex) +{ + for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(!dynObj) + { + i = m_dynObjGUIDs.erase(i); + continue; + } + + if (dynObj->GetSpellId() == spellId && dynObj->GetEffIndex() == effIndex) + return dynObj; + ++i; + } + return NULL; +} + +DynamicObject * Unit::GetDynObject(uint32 spellId) +{ + for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(!dynObj) + { + i = m_dynObjGUIDs.erase(i); + continue; + } + + if (dynObj->GetSpellId() == spellId) + return dynObj; + ++i; + } + return NULL; +} + +void Unit::AddGameObject(GameObject* gameObj) +{ + assert(gameObj && gameObj->GetOwnerGUID()==0); + m_gameObj.push_back(gameObj); + gameObj->SetOwnerGUID(GetGUID()); +} + +void Unit::RemoveGameObject(GameObject* gameObj, bool del) +{ + assert(gameObj && gameObj->GetOwnerGUID()==GetGUID()); + + // GO created by some spell + if ( GetTypeId()==TYPEID_PLAYER && gameObj->GetSpellId() ) + { + SpellEntry const* createBySpell = sSpellStore.LookupEntry(gameObj->GetSpellId()); + // Need activate spell use for owner + if (createBySpell && createBySpell->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) + ((Player*)this)->SendCooldownEvent(createBySpell); + } + gameObj->SetOwnerGUID(0); + m_gameObj.remove(gameObj); + if(del) + { + gameObj->SetRespawnTime(0); + gameObj->Delete(); + } +} + +void Unit::RemoveGameObject(uint32 spellid, bool del) +{ + if(m_gameObj.empty()) + return; + std::list::iterator i, next; + for (i = m_gameObj.begin(); i != m_gameObj.end(); i = next) + { + next = i; + if(spellid == 0 || (*i)->GetSpellId() == spellid) + { + (*i)->SetOwnerGUID(0); + if(del) + { + (*i)->SetRespawnTime(0); + (*i)->Delete(); + } + + next = m_gameObj.erase(i); + } + else + ++next; + } +} + +void Unit::RemoveAllGameObjects() +{ + // remove references to unit + for(std::list::iterator i = m_gameObj.begin(); i != m_gameObj.end();) + { + (*i)->SetOwnerGUID(0); + (*i)->SetRespawnTime(0); + (*i)->Delete(); + i = m_gameObj.erase(i); + } +} + +void Unit::SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID,uint32 Damage, SpellSchoolMask damageSchoolMask,uint32 AbsorbedDamage, uint32 Resist,bool PhysicalDamage, uint32 Blocked, bool CriticalHit) +{ + sLog.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG"); + WorldPacket data(SMSG_SPELLNONMELEEDAMAGELOG, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size + data.append(target->GetPackGUID()); + data.append(GetPackGUID()); + data << uint32(SpellID); + data << uint32(Damage-AbsorbedDamage-Resist-Blocked); + data << uint8(damageSchoolMask); // spell school + data << uint32(AbsorbedDamage); // AbsorbedDamage + data << uint32(Resist); // resist + data << uint8(PhysicalDamage); // if 1, then client show spell name (example: %s's ranged shot hit %s for %u school or %s suffers %u school damage from %s's spell_name + data << uint8(0); // unk isFromAura + data << uint32(Blocked); // blocked + data << uint32(CriticalHit ? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster? + data << uint8(0); // isDebug? + SendMessageToSet( &data, true ); +} + +void Unit::SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo) +{ + WorldPacket data(SMSG_SPELLLOGMISS, (4+8+1+4+8+1)); + data << uint32(spellID); + data << uint64(GetGUID()); + data << uint8(0); // can be 0 or 1 + data << uint32(1); // target count + // for(i = 0; i < target count; ++i) + data << uint64(target->GetGUID()); // target GUID + data << uint8(missInfo); + // end loop + SendMessageToSet(&data, true); +} + +void Unit::SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount) +{ + sLog.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE"); + + WorldPacket data(SMSG_ATTACKERSTATEUPDATE, (16+45)); // we guess size + data << (uint32)HitInfo; + data.append(GetPackGUID()); + data.append(target->GetPackGUID()); + data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); + + data << (uint8)SwingType; // count? + + // for(i = 0; i < SwingType; ++i) + data << (uint32)damageSchoolMask; + data << (float)(Damage-AbsorbDamage-Resist-BlockedAmount); + // still need to double check damage + data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); + data << (uint32)AbsorbDamage; + data << (uint32)Resist; + // end loop + + data << (uint32)TargetState; + + if( AbsorbDamage == 0 ) //also 0x3E8 = 0x3E8, check when that happens + data << (uint32)0; + else + data << (uint32)-1; + + data << (uint32)0; + data << (uint32)BlockedAmount; + + SendMessageToSet( &data, true ); +} + +void Unit::ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const *procSpell, bool isTriggeredSpell, WeaponAttackType attType) +{ + sLog.outDebug("ProcDamageAndSpell: attacker flags are 0x%x, victim flags 0x%x", procAttacker, procVictim); + if(procSpell) + sLog.outDebug("ProcDamageAndSpell: invoked due to spell id %u %s", procSpell->Id, (isTriggeredSpell?"(triggered)":"")); + + // Assign melee/ranged proc flags for magic attacks, that are actually melee/ranged abilities + // not assign for spell proc triggered spell to prevent infinity (or unexpected 2-3 times) melee damage spell proc call with melee damage effect + // That is the question though if it's fully correct + if(procSpell && !isTriggeredSpell) + { + if(procSpell->DmgClass == SPELL_DAMAGE_CLASS_MELEE) + { + if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_MELEE; + if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_MELEE; + if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_MELEE; + if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_MELEE; + attType = BASE_ATTACK; // Melee abilities are assumed to be dealt with mainhand weapon + } + else if (procSpell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) + { + if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_RANGED; + if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_RANGED; + if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_RANGED; + if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_RANGED; + attType = RANGED_ATTACK; + } + } + if(damage && (procVictim & (PROC_FLAG_STRUCK_MELEE|PROC_FLAG_STRUCK_RANGED|PROC_FLAG_STRUCK_SPELL))) + procVictim |= (PROC_FLAG_TAKE_DAMAGE|PROC_FLAG_TOUCH); + + // Not much to do if no flags are set. + if (procAttacker) + { + // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set + ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcEffectAuraTypes,attType, procSpell, damage, damageSchoolMask); + ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcCastAuraTypes,attType, procSpell, damage, damageSchoolMask); + } + + // Now go on with a victim's events'n'auras + // Not much to do if no flags are set or there is no victim + if(pVictim && pVictim->isAlive() && procVictim) + { + // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set + pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcEffectAuraTypes,attType,procSpell, damage, damageSchoolMask); + pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcCastAuraTypes,attType,procSpell, damage, damageSchoolMask); + } +} + +void Unit::CastMeleeProcDamageAndSpell(Unit* pVictim, uint32 damage, SpellSchoolMask damageSchoolMask, WeaponAttackType attType, MeleeHitOutcome outcome, SpellEntry const *spellCasted, bool isTriggeredSpell) +{ + if(!pVictim) + return; + + uint32 procAttacker = PROC_FLAG_NONE; + uint32 procVictim = PROC_FLAG_NONE; + + switch(outcome) + { + case MELEE_HIT_EVADE: + return; + case MELEE_HIT_MISS: + if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_MISS; + } + break; + case MELEE_HIT_BLOCK_CRIT: + case MELEE_HIT_CRIT: + if(spellCasted && attType == BASE_ATTACK) + { + procAttacker |= PROC_FLAG_CRIT_SPELL; + procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; + if ( outcome == MELEE_HIT_BLOCK_CRIT ) + { + procVictim |= PROC_FLAG_BLOCK; + procAttacker |= PROC_FLAG_TARGET_BLOCK; + } + } + else if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; + procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; + } + else + { + procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; + procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; + } + break; + case MELEE_HIT_PARRY: + procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; + procVictim = PROC_FLAG_PARRY; + break; + case MELEE_HIT_BLOCK: + procAttacker = PROC_FLAG_TARGET_BLOCK; + procVictim = PROC_FLAG_BLOCK; + break; + case MELEE_HIT_DODGE: + procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; + procVictim = PROC_FLAG_DODGE; + break; + case MELEE_HIT_CRUSHING: + if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; + procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; + } + else + { + procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; + procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; + } + break; + default: + if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_HIT_MELEE; + procVictim = PROC_FLAG_STRUCK_MELEE; + } + else + { + procAttacker = PROC_FLAG_HIT_RANGED; + procVictim = PROC_FLAG_STRUCK_RANGED; + } + break; + } + + if(damage > 0) + procVictim |= PROC_FLAG_TAKE_DAMAGE; + + if(procAttacker != PROC_FLAG_NONE || procVictim != PROC_FLAG_NONE) + ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, damageSchoolMask, spellCasted, isTriggeredSpell, attType); +} + +bool Unit::HandleHasteAuraProc(Unit *pVictim, SpellEntry const *hasteSpell, uint32 /*effIndex*/, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 /*procFlag*/, uint32 cooldown) +{ + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = 0; + Unit* target = pVictim; + int32 basepoints0 = 0; + + switch(hasteSpell->SpellFamilyName) + { + case SPELLFAMILY_ROGUE: + { + switch(hasteSpell->Id) + { + // Blade Flurry + case 13877: + case 33735: + { + target = SelectNearbyTarget(); + if(!target) + return false; + basepoints0 = damage; + triggered_spell_id = 22482; + break; + } + } + break; + } + } + + // processed charge only counting case + if(!triggered_spell_id) + return true; + + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell->Id,triggered_spell_id); + return false; + } + + // default case + if(!target || target!=this && !target->isAlive()) + return false; + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + if(basepoints0) + CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + else + CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +bool Unit::HandleDummyAuraProc(Unit *pVictim, SpellEntry const *dummySpell, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) +{ + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = 0; + Unit* target = pVictim; + int32 basepoints0 = 0; + + switch(dummySpell->SpellFamilyName) + { + case SPELLFAMILY_GENERIC: + { + switch (dummySpell->Id) + { + // Eye of Eye + case 9799: + case 25988: + { + // prevent damage back from weapon special attacks + if (!procSpell || procSpell->DmgClass != SPELL_DAMAGE_CLASS_MAGIC ) + return false; + + // return damage % to attacker but < 50% own total health + basepoints0 = triggeredByAura->GetModifier()->m_amount*int32(damage)/100; + if(basepoints0 > GetMaxHealth()/2) + basepoints0 = GetMaxHealth()/2; + + triggered_spell_id = 25997; + break; + } + // Sweeping Strikes + case 12328: + case 18765: + case 35429: + { + // prevent chain of triggered spell from same triggered spell + if(procSpell && procSpell->Id==26654) + return false; + + target = SelectNearbyTarget(); + if(!target) + return false; + + triggered_spell_id = 26654; + break; + } + // Unstable Power + case 24658: + { + if (!procSpell || procSpell->Id == 24659) + return false; + // Need remove one 24659 aura + RemoveSingleAuraFromStack(24659, 0); + RemoveSingleAuraFromStack(24659, 1); + return true; + } + // Restless Strength + case 24661: + { + // Need remove one 24662 aura + RemoveSingleAuraFromStack(24662, 0); + return true; + } + // Adaptive Warding (Frostfire Regalia set) + case 28764: + { + if(!procSpell) + return false; + + // find Mage Armor + bool found = false; + AuraList const& mRegenInterupt = GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT); + for(AuraList::const_iterator iter = mRegenInterupt.begin(); iter != mRegenInterupt.end(); ++iter) + { + if(SpellEntry const* iterSpellProto = (*iter)->GetSpellProto()) + { + if(iterSpellProto->SpellFamilyName==SPELLFAMILY_MAGE && (iterSpellProto->SpellFamilyFlags & 0x10000000)) + { + found=true; + break; + } + } + } + if(!found) + return false; + + switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) + { + case SPELL_SCHOOL_NORMAL: + case SPELL_SCHOOL_HOLY: + return false; // ignored + case SPELL_SCHOOL_FIRE: triggered_spell_id = 28765; break; + case SPELL_SCHOOL_NATURE: triggered_spell_id = 28768; break; + case SPELL_SCHOOL_FROST: triggered_spell_id = 28766; break; + case SPELL_SCHOOL_SHADOW: triggered_spell_id = 28769; break; + case SPELL_SCHOOL_ARCANE: triggered_spell_id = 28770; break; + default: + return false; + } + + target = this; + break; + } + // Obsidian Armor (Justice Bearer`s Pauldrons shoulder) + case 27539: + { + if(!procSpell) + return false; + + // not from DoT + bool found = false; + for(int j = 0; j < 3; ++j) + { + if(procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE||procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT) + { + found = true; + break; + } + } + if(found) + return false; + + switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) + { + case SPELL_SCHOOL_NORMAL: + return false; // ignore + case SPELL_SCHOOL_HOLY: triggered_spell_id = 27536; break; + case SPELL_SCHOOL_FIRE: triggered_spell_id = 27533; break; + case SPELL_SCHOOL_NATURE: triggered_spell_id = 27538; break; + case SPELL_SCHOOL_FROST: triggered_spell_id = 27534; break; + case SPELL_SCHOOL_SHADOW: triggered_spell_id = 27535; break; + case SPELL_SCHOOL_ARCANE: triggered_spell_id = 27540; break; + default: + return false; + } + + target = this; + break; + } + // Mana Leech (Passive) (Priest Pet Aura) + case 28305: + { + // Cast on owner + target = GetOwner(); + if(!target) + return false; + + basepoints0 = int32(damage * 2.5f); // manaregen + triggered_spell_id = 34650; + break; + } + // Mark of Malice + case 33493: + { + // Cast finish spell at last charge + if (triggeredByAura->m_procCharges > 1) + return false; + + target = this; + triggered_spell_id = 33494; + break; + } + // Twisted Reflection (boss spell) + case 21063: + triggered_spell_id = 21064; + break; + // Vampiric Aura (boss spell) + case 38196: + { + basepoints0 = 3 * damage; // 300% + if (basepoints0 < 0) + return false; + + triggered_spell_id = 31285; + target = this; + break; + } + // Aura of Madness (Darkmoon Card: Madness trinket) + //===================================================== + // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior) + // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid) + // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid) + // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin) + // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes) + // 41005 Manic: +35 haste (spell, melee and ranged) (All classes) + // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter) + // 41011 Martyr Complex: +35 stamina (All classes) + // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) + // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) + case 39446: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Select class defined buff + switch (getClass()) + { + case CLASS_PALADIN: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 + case CLASS_DRUID: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 + { + uint32 RandomSpell[]={39511,40997,40998,40999,41002,41005,41009,41011,41409}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + case CLASS_ROGUE: // 39511,40997,40998,41002,41005,41011 + case CLASS_WARRIOR: // 39511,40997,40998,41002,41005,41011 + { + uint32 RandomSpell[]={39511,40997,40998,41002,41005,41011}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + case CLASS_PRIEST: // 40999,41002,41005,41009,41011,41406,41409 + case CLASS_SHAMAN: // 40999,41002,41005,41009,41011,41406,41409 + case CLASS_MAGE: // 40999,41002,41005,41009,41011,41406,41409 + case CLASS_WARLOCK: // 40999,41002,41005,41009,41011,41406,41409 + { + uint32 RandomSpell[]={40999,41002,41005,41009,41011,41406,41409}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + case CLASS_HUNTER: // 40997,40999,41002,41005,41009,41011,41406,41409 + { + uint32 RandomSpell[]={40997,40999,41002,41005,41009,41011,41406,41409}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + default: + return false; + } + + target = this; + if (roll_chance_i(10)) + ((Player*)this)->Say("This is Madness!", LANG_UNIVERSAL); + break; + } + /* + // TODO: need find item for aura and triggered spells + // Sunwell Exalted Caster Neck (??? neck) + // cast ??? Light's Wrath if Exalted by Aldor + // cast ??? Arcane Bolt if Exalted by Scryers*/ + case 46569: + return false; // disable for while + /* + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = ??? + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = ??? + break; + } + return false; + }/**/ + // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck) + // cast 45479 Light's Wrath if Exalted by Aldor + // cast 45429 Arcane Bolt if Exalted by Scryers + case 45481: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45479; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = 45429; + break; + } + return false; + } + // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck) + // cast 45480 Light's Strength if Exalted by Aldor + // cast 45428 Arcane Strike if Exalted by Scryers + case 45482: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45480; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = 45428; + break; + } + return false; + } + // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck) + // cast 45431 Arcane Insight if Exalted by Aldor + // cast 45432 Light's Ward if Exalted by Scryers + case 45483: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45432; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45431; + break; + } + return false; + } + // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck) + // cast 45478 Light's Salvation if Exalted by Aldor + // cast 45430 Arcane Surge if Exalted by Scryers + case 45484: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45478; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = 45430; + break; + } + return false; + } + } + break; + } + case SPELLFAMILY_MAGE: + { + // Magic Absorption + if (dummySpell->SpellIconID == 459) // only this spell have SpellIconID == 459 and dummy aura + { + if (getPowerType() != POWER_MANA) + return false; + + // mana reward + basepoints0 = (triggeredByAura->GetModifier()->m_amount * GetMaxPower(POWER_MANA) / 100); + target = this; + triggered_spell_id = 29442; + break; + } + // Master of Elements + if (dummySpell->SpellIconID == 1920) + { + if(!procSpell) + return false; + + // mana cost save + basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; + if( basepoints0 <=0 ) + return false; + + target = this; + triggered_spell_id = 29077; + break; + } + switch(dummySpell->Id) + { + // Ignite + case 11119: + case 11120: + case 12846: + case 12847: + case 12848: + { + switch (dummySpell->Id) + { + case 11119: basepoints0 = int32(0.04f*damage); break; + case 11120: basepoints0 = int32(0.08f*damage); break; + case 12846: basepoints0 = int32(0.12f*damage); break; + case 12847: basepoints0 = int32(0.16f*damage); break; + case 12848: basepoints0 = int32(0.20f*damage); break; + default: + sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell->Id); + return false; + } + + triggered_spell_id = 12654; + break; + } + // Combustion + case 11129: + { + //last charge and crit + if( triggeredByAura->m_procCharges <= 1 && (procFlag & PROC_FLAG_CRIT_SPELL) ) + { + RemoveAurasDueToSpell(28682); //-> remove Combustion auras + return true; // charge counting (will removed) + } + + CastSpell(this, 28682, true, castItem, triggeredByAura); + return(procFlag & PROC_FLAG_CRIT_SPELL);// charge update only at crit hits, no hidden cooldowns + } + } + break; + } + case SPELLFAMILY_WARRIOR: + { + // Retaliation + if(dummySpell->SpellFamilyFlags==0x0000000800000000LL) + { + // check attack comes not from behind + if (!HasInArc(M_PI, pVictim)) + return false; + + triggered_spell_id = 22858; + break; + } + break; + } + case SPELLFAMILY_WARLOCK: + { + // Seed of Corruption + if (dummySpell->SpellFamilyFlags & 0x0000001000000000LL) + { + Modifier* mod = triggeredByAura->GetModifier(); + // if damage is more than need or target die from damage deal finish spell + // FIX ME: not triggered currently at death + if( mod->m_amount <= damage || GetHealth() <= damage ) + { + // remember guid before aura delete + uint64 casterGuid = triggeredByAura->GetCasterGUID(); + + // Remove aura (before cast for prevent infinite loop handlers) + RemoveAurasDueToSpell(triggeredByAura->GetId()); + + // Cast finish spell (triggeredByAura already not exist!) + if(Unit* caster = GetUnit(*this, casterGuid)) + caster->CastSpell(this, 27285, true, castItem); + return true; // no hidden cooldown + } + + // Damage counting + mod->m_amount-=damage; + return true; + } + // Seed of Corruption (Mobs cast) - no die req + if (dummySpell->SpellFamilyFlags == 0x00LL && dummySpell->SpellIconID == 1932) + { + Modifier* mod = triggeredByAura->GetModifier(); + // if damage is more than need deal finish spell + if( mod->m_amount <= damage ) + { + // remember guid before aura delete + uint64 casterGuid = triggeredByAura->GetCasterGUID(); + + // Remove aura (before cast for prevent infinite loop handlers) + RemoveAurasDueToSpell(triggeredByAura->GetId()); + + // Cast finish spell (triggeredByAura already not exist!) + if(Unit* caster = GetUnit(*this, casterGuid)) + caster->CastSpell(this, 32865, true, castItem); + return true; // no hidden cooldown + } + // Damage counting + mod->m_amount-=damage; + return true; + } + switch(dummySpell->Id) + { + // Nightfall + case 18094: + case 18095: + { + target = this; + triggered_spell_id = 17941; + break; + } + //Soul Leech + case 30293: + case 30295: + case 30296: + { + // health + basepoints0 = int32(damage*triggeredByAura->GetModifier()->m_amount/100); + target = this; + triggered_spell_id = 30294; + break; + } + // Shadowflame (Voidheart Raiment set bonus) + case 37377: + { + triggered_spell_id = 37379; + break; + } + // Pet Healing (Corruptor Raiment or Rift Stalker Armor) + case 37381: + { + target = GetPet(); + if(!target) + return false; + + // heal amount + basepoints0 = damage * triggeredByAura->GetModifier()->m_amount/100; + triggered_spell_id = 37382; + break; + } + // Shadowflame Hellfire (Voidheart Raiment set bonus) + case 39437: + { + triggered_spell_id = 37378; + break; + } + } + break; + } + case SPELLFAMILY_PRIEST: + { + // Vampiric Touch + if( dummySpell->SpellFamilyFlags & 0x0000040000000000LL ) + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // pVictim is caster of aura + if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) + return false; + + // energize amount + basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; + pVictim->CastCustomSpell(pVictim,34919,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + return true; // no hidden cooldown + } + switch(dummySpell->Id) + { + // Vampiric Embrace + case 15286: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // pVictim is caster of aura + if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) + return false; + + // heal amount + basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; + pVictim->CastCustomSpell(pVictim,15290,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + return true; // no hidden cooldown + } + // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen) + case 40438: + { + // Shadow Word: Pain + if( procSpell->SpellFamilyFlags & 0x0000000000008000LL ) + triggered_spell_id = 40441; + // Renew + else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) + triggered_spell_id = 40440; + else + return false; + + target = this; + break; + } + // Oracle Healing Bonus ("Garments of the Oracle" set) + case 26169: + { + // heal amount + basepoints0 = int32(damage * 10/100); + target = this; + triggered_spell_id = 26170; + break; + } + // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set + case 39372: + { + if(!procSpell || (GetSpellSchoolMask(procSpell) & (SPELL_SCHOOL_MASK_FROST | SPELL_SCHOOL_MASK_SHADOW))==0 ) + return false; + + // heal amount + basepoints0 = int32(damage * 2 / 100); + target = this; + triggered_spell_id = 39373; + break; + } + // Vestments of Faith (Priest Tier 3) - 4 pieces bonus + case 28809: + { + triggered_spell_id = 28810; + break; + } + } + break; + } + case SPELLFAMILY_DRUID: + { + switch(dummySpell->Id) + { + // Healing Touch (Dreamwalker Raiment set) + case 28719: + { + // mana back + basepoints0 = int32(procSpell->manaCost * 30 / 100); + target = this; + triggered_spell_id = 28742; + break; + } + // Healing Touch Refund (Idol of Longevity trinket) + case 28847: + { + target = this; + triggered_spell_id = 28848; + break; + } + // Mana Restore (Malorne Raiment set / Malorne Regalia set) + case 37288: + case 37295: + { + target = this; + triggered_spell_id = 37238; + break; + } + // Druid Tier 6 Trinket + case 40442: + { + float chance; + + // Starfire + if( procSpell->SpellFamilyFlags & 0x0000000000000004LL ) + { + triggered_spell_id = 40445; + chance = 25.f; + } + // Rejuvenation + else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) + { + triggered_spell_id = 40446; + chance = 25.f; + } + // Mangle (cat/bear) + else if( procSpell->SpellFamilyFlags & 0x0000044000000000LL ) + { + triggered_spell_id = 40452; + chance = 40.f; + } + else + return false; + + if (!roll_chance_f(chance)) + return false; + + target = this; + break; + } + // Maim Interrupt + case 44835: + { + // Deadly Interrupt Effect + triggered_spell_id = 32747; + break; + } + } + break; + } + case SPELLFAMILY_ROGUE: + { + switch(dummySpell->Id) + { + // Deadly Throw Interrupt + case 32748: + { + // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw + if(this == pVictim) + return false; + + triggered_spell_id = 32747; + break; + } + } + // Quick Recovery + if( dummySpell->SpellIconID == 2116 ) + { + if(!procSpell) + return false; + + // only rogue's finishing moves (maybe need additional checks) + if( procSpell->SpellFamilyName!=SPELLFAMILY_ROGUE || + (procSpell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE) == 0) + return false; + + // energy cost save + basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; + if(basepoints0 <= 0) + return false; + + target = this; + triggered_spell_id = 31663; + break; + } + break; + } + case SPELLFAMILY_HUNTER: + { + // Thrill of the Hunt + if ( dummySpell->SpellIconID == 2236 ) + { + if(!procSpell) + return false; + + // mana cost save + basepoints0 = procSpell->manaCost * 40/100; + if(basepoints0 <= 0) + return false; + + target = this; + triggered_spell_id = 34720; + break; + } + break; + } + case SPELLFAMILY_PALADIN: + { + // Seal of Righteousness - melee proc dummy + if (dummySpell->SpellFamilyFlags&0x000000008000000LL && triggeredByAura->GetEffIndex()==0) + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + uint32 spellId; + switch (triggeredByAura->GetId()) + { + case 21084: spellId = 25742; break; // Rank 1 + case 20287: spellId = 25740; break; // Rank 2 + case 20288: spellId = 25739; break; // Rank 3 + case 20289: spellId = 25738; break; // Rank 4 + case 20290: spellId = 25737; break; // Rank 5 + case 20291: spellId = 25736; break; // Rank 6 + case 20292: spellId = 25735; break; // Rank 7 + case 20293: spellId = 25713; break; // Rank 8 + case 27155: spellId = 27156; break; // Rank 9 + default: + sLog.outError("Unit::HandleDummyAuraProc: non handled possibly SoR (Id = %u)", triggeredByAura->GetId()); + return false; + } + Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + float speed = (item ? item->GetProto()->Delay : BASE_ATTACK_TIME)/1000.0f; + + float damageBasePoints; + if(item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) + // two hand weapon + damageBasePoints=1.20f*triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f + 1; + else + // one hand weapon/no weapon + damageBasePoints=0.85f*ceil(triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f) - 1; + + int32 damagePoint = int32(damageBasePoints + 0.03f * (GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE)+GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE))/2.0f) + 1; + + // apply damage bonuses manually + if(damagePoint >= 0) + damagePoint = SpellDamageBonus(pVictim, dummySpell, damagePoint, SPELL_DIRECT_DAMAGE); + + CastCustomSpell(pVictim,spellId,&damagePoint,NULL,NULL,true,NULL, triggeredByAura); + return true; // no hidden cooldown + } + // Seal of Blood do damage trigger + if(dummySpell->SpellFamilyFlags & 0x0000040000000000LL) + { + switch(triggeredByAura->GetEffIndex()) + { + case 0: + // prevent chain triggering + if(procSpell && procSpell->Id==31893 ) + return false; + + triggered_spell_id = 31893; + break; + case 1: + { + // damage + basepoints0 = triggeredByAura->GetModifier()->m_amount * damage / 100; + target = this; + triggered_spell_id = 32221; + break; + } + } + } + + switch(dummySpell->Id) + { + // Holy Power (Redemption Armor set) + case 28789: + { + if(!pVictim) + return false; + + // Set class defined buff + switch (pVictim->getClass()) + { + case CLASS_PALADIN: + case CLASS_PRIEST: + case CLASS_SHAMAN: + case CLASS_DRUID: + triggered_spell_id = 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. + break; + case CLASS_MAGE: + case CLASS_WARLOCK: + triggered_spell_id = 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d. + break; + case CLASS_HUNTER: + case CLASS_ROGUE: + triggered_spell_id = 28791; // Increases the friendly target's attack power by $s1 for $d. + break; + case CLASS_WARRIOR: + triggered_spell_id = 28790; // Increases the friendly target's armor + break; + default: + return false; + } + break; + } + //Seal of Vengeance + case 31801: + { + if(effIndex != 0) // effect 1,2 used by seal unleashing code + return false; + + triggered_spell_id = 31803; + break; + } + // Spiritual Att. + case 31785: + case 33776: + { + // if healed by another unit (pVictim) + if(this == pVictim) + return false; + + // heal amount + basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; + target = this; + triggered_spell_id = 31786; + break; + } + // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal) + case 40470: + { + if( !procSpell ) + return false; + + float chance; + + // Flash of light/Holy light + if( procSpell->SpellFamilyFlags & 0x00000000C0000000LL) + { + triggered_spell_id = 40471; + chance = 15.f; + } + // Judgement + else if( procSpell->SpellFamilyFlags & 0x0000000000800000LL ) + { + triggered_spell_id = 40472; + chance = 50.f; + } + else + return false; + + if (!roll_chance_f(chance)) + return false; + + break; + } + } + break; + } + case SPELLFAMILY_SHAMAN: + { + switch(dummySpell->Id) + { + // Totemic Power (The Earthshatterer set) + case 28823: + { + if( !pVictim ) + return false; + + // Set class defined buff + switch (pVictim->getClass()) + { + case CLASS_PALADIN: + case CLASS_PRIEST: + case CLASS_SHAMAN: + case CLASS_DRUID: + triggered_spell_id = 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. + break; + case CLASS_MAGE: + case CLASS_WARLOCK: + triggered_spell_id = 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d. + break; + case CLASS_HUNTER: + case CLASS_ROGUE: + triggered_spell_id = 28826; // Increases the friendly target's attack power by $s1 for $d. + break; + case CLASS_WARRIOR: + triggered_spell_id = 28827; // Increases the friendly target's armor + break; + default: + return false; + } + break; + } + // Lesser Healing Wave (Totem of Flowing Water Relic) + case 28849: + { + target = this; + triggered_spell_id = 28850; + break; + } + // Windfury Weapon (Passive) 1-5 Ranks + case 33757: + { + if(GetTypeId()!=TYPEID_PLAYER) + return false; + + if(!castItem || !castItem->IsEquipped()) + return false; + + // custom cooldown processing case + if( cooldown && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) + return false; + + uint32 spellId; + switch (castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT))) + { + case 283: spellId = 33757; break; //1 Rank + case 284: spellId = 33756; break; //2 Rank + case 525: spellId = 33755; break; //3 Rank + case 1669:spellId = 33754; break; //4 Rank + case 2636:spellId = 33727; break; //5 Rank + default: + { + sLog.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)", + castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT)),dummySpell->Id); + return false; + } + } + + SpellEntry const* windfurySpellEntry = sSpellStore.LookupEntry(spellId); + if(!windfurySpellEntry) + { + sLog.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId); + return false; + } + + int32 extra_attack_power = CalculateSpellDamage(windfurySpellEntry,0,windfurySpellEntry->EffectBasePoints[0],pVictim); + + // Off-Hand case + if ( castItem->GetSlot() == EQUIPMENT_SLOT_OFFHAND ) + { + // Value gained from additional AP + basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(OFF_ATTACK)/1000/2); + triggered_spell_id = 33750; + } + // Main-Hand case + else + { + // Value gained from additional AP + basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(BASE_ATTACK)/1000); + triggered_spell_id = 25504; + } + + // apply cooldown before cast to prevent processing itself + if( cooldown ) + ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); + + // Attack Twice + for ( uint32 i = 0; i<2; ++i ) + CastCustomSpell(pVictim,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + + return true; + } + // Shaman Tier 6 Trinket + case 40463: + { + if( !procSpell ) + return false; + + float chance; + if (procSpell->SpellFamilyFlags & 0x0000000000000001LL) + { + triggered_spell_id = 40465; // Lightning Bolt + chance = 15.f; + } + else if (procSpell->SpellFamilyFlags & 0x0000000000000080LL) + { + triggered_spell_id = 40465; // Lesser Healing Wave + chance = 10.f; + } + else if (procSpell->SpellFamilyFlags & 0x0000001000000000LL) + { + triggered_spell_id = 40466; // Stormstrike + chance = 50.f; + } + else + return false; + + if (!roll_chance_f(chance)) + return false; + + target = this; + break; + } + } + + // Earth Shield + if(dummySpell->SpellFamilyFlags==0x40000000000LL) + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // heal + basepoints0 = triggeredByAura->GetModifier()->m_amount; + target = this; + triggered_spell_id = 379; + break; + } + // Lightning Overload + if (dummySpell->SpellIconID == 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura + { + if(!procSpell || GetTypeId() != TYPEID_PLAYER || !pVictim ) + return false; + + // custom cooldown processing case + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) + return false; + + uint32 spellId = 0; + // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost + switch (procSpell->Id) + { + // Lightning Bolt + case 403: spellId = 45284; break; // Rank 1 + case 529: spellId = 45286; break; // Rank 2 + case 548: spellId = 45287; break; // Rank 3 + case 915: spellId = 45288; break; // Rank 4 + case 943: spellId = 45289; break; // Rank 5 + case 6041: spellId = 45290; break; // Rank 6 + case 10391: spellId = 45291; break; // Rank 7 + case 10392: spellId = 45292; break; // Rank 8 + case 15207: spellId = 45293; break; // Rank 9 + case 15208: spellId = 45294; break; // Rank 10 + case 25448: spellId = 45295; break; // Rank 11 + case 25449: spellId = 45296; break; // Rank 12 + // Chain Lightning + case 421: spellId = 45297; break; // Rank 1 + case 930: spellId = 45298; break; // Rank 2 + case 2860: spellId = 45299; break; // Rank 3 + case 10605: spellId = 45300; break; // Rank 4 + case 25439: spellId = 45301; break; // Rank 5 + case 25442: spellId = 45302; break; // Rank 6 + default: + sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell->Id); + return false; + } + // No thread generated mod + SpellModifier *mod = new SpellModifier; + mod->op = SPELLMOD_THREAT; + mod->value = -100; + mod->type = SPELLMOD_PCT; + mod->spellId = dummySpell->Id; + mod->effectId = 0; + mod->lastAffected = NULL; + mod->mask = 0x0000000000000003LL; + mod->charges = 0; + ((Player*)this)->AddSpellMod(mod, true); + + // Remove cooldown (Chain Lightning - have Category Recovery time) + if (procSpell->SpellFamilyFlags & 0x0000000000000002LL) + ((Player*)this)->RemoveSpellCooldown(spellId); + + // Hmmm.. in most case spells already set half basepoints but... + // Lightning Bolt (2-10 rank) have full basepoint and half bonus from level + // As on wiki: + // BUG: Rank 2 to 10 (and maybe 11) of Lightning Bolt will proc another Bolt with FULL damage (not halved). This bug is known and will probably be fixed soon. + // So - no add changes :) + CastSpell(pVictim, spellId, true, castItem, triggeredByAura); + + ((Player*)this)->AddSpellMod(mod, false); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); + + return true; + } + break; + } + default: + break; + } + + // processed charge only counting case + if(!triggered_spell_id) + return true; + + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell->Id,triggered_spell_id); + return false; + } + + // default case + if(!target || target!=this && !target->isAlive()) + return false; + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + if(basepoints0) + CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + else + CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const *procSpell, uint32 procFlags,WeaponAttackType attackType, uint32 cooldown) +{ + SpellEntry const* auraSpellInfo = triggeredByAura->GetSpellProto(); + + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = auraSpellInfo->EffectTriggerSpell[triggeredByAura->GetEffIndex()]; + Unit* target = !(procFlags & PROC_FLAG_HEAL) && IsPositiveSpell(triggered_spell_id) ? this : pVictim; + int32 basepoints0 = 0; + + switch(auraSpellInfo->SpellFamilyName) + { + case SPELLFAMILY_GENERIC: + { + switch(auraSpellInfo->Id) + { + // Aegis of Preservation + case 23780: + //Aegis Heal (instead non-existed triggered spell) + triggered_spell_id = 23781; + target = this; + break; + // Elune's Touch (moonkin mana restore) + case 24905: + { + // Elune's Touch (instead non-existed triggered spell) + triggered_spell_id = 33926; + basepoints0 = int32(0.3f * GetTotalAttackPowerValue(BASE_ATTACK)); + target = this; + break; + } + // Enlightenment + case 29601: + { + // only for cast with mana price + if(!procSpell || procSpell->powerType!=POWER_MANA || procSpell->manaCost==0 && procSpell->ManaCostPercentage==0 && procSpell->manaCostPerlevel==0) + return false; + break; // fall through to normal cast + } + // Health Restore + case 33510: + { + // at melee hit call std triggered spell + if(procFlags & PROC_FLAG_HIT_MELEE) + break; // fall through to normal cast + + // Mark of Conquest - else (at range hit) called custom case + triggered_spell_id = 39557; + target = this; + break; + } + // Shaleskin + case 36576: + return true; // nothing to do + // Forgotten Knowledge (Blade of Wizardry) + case 38319: + // only for harmful enemy targeted spell + if(!pVictim || pVictim==this || !procSpell || IsPositiveSpell(procSpell->Id)) + return false; + break; // fall through to normal cast + // Aura of Wrath (Darkmoon Card: Wrath trinket bonus) + case 39442: + { + // proc only at non-crit hits + if(procFlags & (PROC_FLAG_CRIT_MELEE|PROC_FLAG_CRIT_RANGED|PROC_FLAG_CRIT_SPELL)) + return false; + break; // fall through to normal cast + } + // Augment Pain (Timbal's Focusing Crystal trinket bonus) + case 45054: + { + if(!procSpell) + return false; + + //only periodic damage can trigger spell + bool found = false; + for(int j = 0; j < 3; ++j) + { + if( procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE || + procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT || + procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_LEECH ) + { + found = true; + break; + } + } + if(!found) + return false; + + break; // fall through to normal cast + } + // Evasive Maneuvers (Commendation of Kael'thas) + case 45057: + { + // damage taken that reduces below 35% health + // does NOT mean you must have been >= 35% before + if (int32(GetHealth())-int32(damage) >= int32(GetMaxHealth()*0.35f)) + return false; + break; // fall through to normal cast + } + } + + switch(triggered_spell_id) + { + // Setup + case 15250: + { + // applied only for main target + if(!pVictim || pVictim != getVictim()) + return false; + + // continue normal case + break; + } + // Shamanistic Rage triggered spell + case 30824: + basepoints0 = int32(GetTotalAttackPowerValue(BASE_ATTACK)*triggeredByAura->GetModifier()->m_amount/100); + break; + } + break; + } + case SPELLFAMILY_MAGE: + { + switch(auraSpellInfo->SpellIconID) + { + // Blazing Speed + case 2127: + //Blazing Speed (instead non-existed triggered spell) + triggered_spell_id = 31643; + target = this; + break; + } + switch(auraSpellInfo->Id) + { + // Persistent Shield (Scarab Brooch) + case 26467: + basepoints0 = int32(damage * 0.15f); + break; + } + break; + } + case SPELLFAMILY_WARRIOR: + { + //Rampage + if((auraSpellInfo->SpellFamilyFlags & 0x100000) && auraSpellInfo->SpellIconID==2006) + { + //all ranks have effect[0]==AURA (Proc Trigger Spell, non-existed) + //and effect[1]==TriggerSpell + if(auraSpellInfo->Effect[1]!=SPELL_EFFECT_TRIGGER_SPELL) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have wrong effect in RM",triggeredByAura->GetSpellProto()->Id); + return false; + } + triggered_spell_id = auraSpellInfo->EffectTriggerSpell[1]; + break; // fall through to normal cast + } + break; + } + case SPELLFAMILY_WARLOCK: + { + // Pyroclasm + if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000 && auraSpellInfo->SpellIconID==1137) + { + // last case for Hellfire that damage caster also but don't must stun caster + if( pVictim == this ) + return false; + + // custom chance + float chance = 0; + switch (triggeredByAura->GetId()) + { + case 18096: chance = 13.0f; break; + case 18073: chance = 26.0f; break; + } + if (!roll_chance_f(chance)) + return false; + + // Pyroclasm (instead non-existed triggered spell) + triggered_spell_id = 18093; + target = pVictim; + break; + } + // Drain Soul + if(auraSpellInfo->SpellFamilyFlags & 0x0000000000004000) + { + bool found = false; + Unit::AuraList const& mAddFlatModifier = GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER); + for(Unit::AuraList::const_iterator i = mAddFlatModifier.begin(); i != mAddFlatModifier.end(); ++i) + { + //Improved Drain Soul + if ((*i)->GetModifier()->m_miscvalue == SPELLMOD_CHANCE_OF_SUCCESS && (*i)->GetSpellProto()->SpellIconID == 113) + { + int32 value2 = CalculateSpellDamage((*i)->GetSpellProto(),2,(*i)->GetSpellProto()->EffectBasePoints[2],this); + basepoints0 = value2 * GetMaxPower(POWER_MANA) / 100; + + // Drain Soul + triggered_spell_id = 18371; + target = this; + found = true; + break; + } + } + if(!found) + return false; + break; // fall through to normal cast + } + break; + } + case SPELLFAMILY_PRIEST: + { + //Blessed Recovery + if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL && auraSpellInfo->SpellIconID==1875) + { + switch (triggeredByAura->GetSpellProto()->Id) + { + case 27811: triggered_spell_id = 27813; break; + case 27815: triggered_spell_id = 27817; break; + case 27816: triggered_spell_id = 27818; break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR",triggeredByAura->GetSpellProto()->Id); + return false; + } + + int32 heal_amount = damage * triggeredByAura->GetModifier()->m_amount / 100; + basepoints0 = heal_amount/3; + target = this; + break; + } + // Shadowguard + if((auraSpellInfo->SpellFamilyFlags & 0x80000000LL) && auraSpellInfo->SpellVisual==7958) + { + switch(triggeredByAura->GetSpellProto()->Id) + { + case 18137: + triggered_spell_id = 28377; break; // Rank 1 + case 19308: + triggered_spell_id = 28378; break; // Rank 2 + case 19309: + triggered_spell_id = 28379; break; // Rank 3 + case 19310: + triggered_spell_id = 28380; break; // Rank 4 + case 19311: + triggered_spell_id = 28381; break; // Rank 5 + case 19312: + triggered_spell_id = 28382; break; // Rank 6 + case 25477: + triggered_spell_id = 28385; break; // Rank 7 + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in SG",triggeredByAura->GetSpellProto()->Id); + return false; + } + target = pVictim; + break; + } + break; + } + case SPELLFAMILY_DRUID: + { + switch(auraSpellInfo->Id) + { + // Leader of the Pack (triggering Improved Leader of the Pack heal) + case 24932: + { + if (triggeredByAura->GetModifier()->m_amount == 0) + return false; + basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; + triggered_spell_id = 34299; + break; + }; + // Druid Forms Trinket (Druid Tier5 Trinket, triggers different spells per Form) + case 37336: + { + switch(m_form) + { + case FORM_BEAR: + case FORM_DIREBEAR: + triggered_spell_id=37340; break;// Ursine Blessing + case FORM_CAT: + triggered_spell_id=37341; break;// Feline Blessing + case FORM_TREE: + triggered_spell_id=37342; break;// Slyvan Blessing + case FORM_MOONKIN: + triggered_spell_id=37343; break;// Lunar Blessing + case FORM_NONE: + triggered_spell_id=37344; break;// Cenarion Blessing (for caster form, except FORM_MOONKIN) + default: + return false; + } + + target = this; + break; + } + } + break; + } + case SPELLFAMILY_ROGUE: + { + if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000LL) + { + switch(auraSpellInfo->SpellIconID) + { + // Combat Potency + case 2260: + { + // skip non offhand attacks + if(attackType!=OFF_ATTACK) + return false; + break; // fall through to normal cast + } + } + } + break; + } + case SPELLFAMILY_PALADIN: + { + if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL) + { + switch(auraSpellInfo->Id) + { + // Lightning Capacitor + case 37657: + { + // trinket ProcTriggerSpell but for safe checks for player + if(!castItem || !pVictim || !pVictim->isAlive() || GetTypeId()!=TYPEID_PLAYER) + return false; + + if(((Player*)this)->HasSpellCooldown(37657)) + return false; + + // stacking + CastSpell(this, 37658, true, castItem, triggeredByAura); + // 2.5s cooldown before it can stack again, current system allow 1 sec step in cooldown + ((Player*)this)->AddSpellCooldown(37657,0,time(NULL)+(roll_chance_i(50) ? 2 : 3)); + + // counting + uint32 count = 0; + AuraList const& dummyAura = GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator itr = dummyAura.begin(); itr != dummyAura.end(); ++itr) + if((*itr)->GetId()==37658) + ++count; + + // release at 3 aura in stack + if(count <= 2) + return true; // main triggered spell casted anyway + + RemoveAurasDueToSpell(37658); + CastSpell(pVictim, 37661, true, castItem, triggeredByAura); + return true; + } + // Healing Discount + case 37705: + // Healing Trance (instead non-existed triggered spell) + triggered_spell_id = 37706; + target = this; + break; + // HoTs on Heals (Fel Reaver's Piston trinket) + case 38299: + { + // at direct heal effect + if(!procSpell || !IsSpellHaveEffect(procSpell,SPELL_EFFECT_HEAL)) + return false; + + // single proc at time + AuraList const& scAuras = GetSingleCastAuras(); + for(AuraList::const_iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) + if((*itr)->GetId()==triggered_spell_id) + return false; + + // positive cast at victim instead self + target = pVictim; + break; + } + } + switch(auraSpellInfo->SpellIconID) + { + case 241: + { + switch(auraSpellInfo->EffectTriggerSpell[0]) + { + //Illumination + case 18350: + { + if(!procSpell) + return false; + + // procspell is triggered spell but we need mana cost of original casted spell + uint32 originalSpellId = procSpell->Id; + + // Holy Shock + if(procSpell->SpellFamilyName == SPELLFAMILY_PALADIN) + { + if(procSpell->SpellFamilyFlags & 0x0001000000000000LL) + { + switch(procSpell->Id) + { + case 25914: originalSpellId = 20473; break; + case 25913: originalSpellId = 20929; break; + case 25903: originalSpellId = 20930; break; + case 27175: originalSpellId = 27174; break; + case 33074: originalSpellId = 33072; break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell->Id); + return false; + } + } + } + + SpellEntry const *originalSpell = sSpellStore.LookupEntry(originalSpellId); + if(!originalSpell) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId); + return false; + } + + // percent stored in effect 1 (class scripts) base points + int32 percent = auraSpellInfo->EffectBasePoints[1]+1; + + basepoints0 = originalSpell->manaCost*percent/100; + triggered_spell_id = 20272; + target = this; + break; + } + } + break; + } + } + } + if(auraSpellInfo->SpellFamilyFlags & 0x00080000) + { + switch(auraSpellInfo->SpellIconID) + { + //Judgement of Wisdom (overwrite non existing triggered spell call in spell.dbc + case 206: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + uint32 spell = 0; + switch(triggeredByAura->GetSpellProto()->Id) + { + case 20186: + triggered_spell_id = 20268; // Rank 1 + break; + case 20354: + triggered_spell_id = 20352; // Rank 2 + break; + case 20355: + triggered_spell_id = 20353; // Rank 3 + break; + case 27164: + triggered_spell_id = 27165; // Rank 4 + break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoW",triggeredByAura->GetSpellProto()->Id); + return false; + } + + pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); + return true; // no hidden cooldown + } + //Judgement of Light + case 299: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // overwrite non existing triggered spell call in spell.dbc + uint32 spell = 0; + switch(triggeredByAura->GetSpellProto()->Id) + { + case 20185: + triggered_spell_id = 20267; // Rank 1 + break; + case 20344: + triggered_spell_id = 20341; // Rank 2 + break; + case 20345: + triggered_spell_id = 20342; // Rank 3 + break; + case 20346: + triggered_spell_id = 20343; // Rank 4 + break; + case 27162: + triggered_spell_id = 27163; // Rank 5 + break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoL",triggeredByAura->GetSpellProto()->Id); + return false; + } + pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); + return true; // no hidden cooldown + } + } + } + // custom check for proc spell + switch(auraSpellInfo->Id) + { + // Bonus Healing (item spell) + case 40971: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // bonus if health < 50% + if(pVictim->GetHealth() >= pVictim->GetMaxHealth()*triggeredByAura->GetModifier()->m_amount/100) + return false; + + // cast at target positive spell + target = pVictim; + break; + } + } + switch(triggered_spell_id) + { + // Seal of Command + case 20424: + // prevent chain of triggered spell from same triggered spell + if(procSpell && procSpell->Id==20424) + return false; + break; + } + break; + } + case SPELLFAMILY_SHAMAN: + { + if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000) + { + switch(auraSpellInfo->SpellIconID) + { + case 19: + { + switch(auraSpellInfo->Id) + { + case 23551: // Lightning Shield - Tier2: 8 pieces proc shield + { + // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) + triggered_spell_id = 23552; + target = pVictim; + break; + } + case 23552: // Lightning Shield - trigger shield damage + { + // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) + triggered_spell_id = 27635; + target = pVictim; + break; + } + } + break; + } + // Mana Surge (Shaman T1 bonus) + case 87: + { + if(!procSpell) + return false; + + basepoints0 = procSpell->manaCost * 35/100; + triggered_spell_id = 23571; + target = this; + break; + } + //Nature's Guardian + case 2013: + { + if(GetTypeId()!=TYPEID_PLAYER) + return false; + + // damage taken that reduces below 30% health + // does NOT mean you must have been >= 30% before + if (10*(int32(GetHealth())-int32(damage)) >= 3*GetMaxHealth()) + return false; + + triggered_spell_id = 31616; + + // need check cooldown now + if( cooldown && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; + target = this; + if(pVictim && pVictim->isAlive()) + pVictim->getThreatManager().modifyThreatPercent(this,-10); + break; + } + } + } + + // Water Shield (we can't set cooldown for main spell - it's player casted spell + if((auraSpellInfo->SpellFamilyFlags & 0x0000002000000000LL) && auraSpellInfo->SpellVisual==7358) + { + target = this; + break; + } + + // Lightning Shield + if((auraSpellInfo->SpellFamilyFlags & 0x00000400) && auraSpellInfo->SpellVisual==37) + { + // overwrite non existing triggered spell call in spell.dbc + switch(triggeredByAura->GetSpellProto()->Id) + { + case 324: + triggered_spell_id = 26364; break; // Rank 1 + case 325: + triggered_spell_id = 26365; break; // Rank 2 + case 905: + triggered_spell_id = 26366; break; // Rank 3 + case 945: + triggered_spell_id = 26367; break; // Rank 4 + case 8134: + triggered_spell_id = 26369; break; // Rank 5 + case 10431: + triggered_spell_id = 26370; break; // Rank 6 + case 10432: + triggered_spell_id = 26363; break; // Rank 7 + case 25469: + triggered_spell_id = 26371; break; // Rank 8 + case 25472: + triggered_spell_id = 26372; break; // Rank 9 + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield",triggeredByAura->GetSpellProto()->Id); + return false; + } + + target = pVictim; + break; + } + break; + } + } + + // standard non-dummy case + if(!triggered_spell_id) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex()); + return false; + } + + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have not existed EffectTriggered[%d]=%u, not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex(),triggered_spell_id); + return false; + } + + // not allow proc extra attack spell at extra attack + if( m_extraAttacks && IsSpellHaveEffect(triggerEntry,SPELL_EFFECT_ADD_EXTRA_ATTACKS) ) + return false; + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + // default case + if(!target || target!=this && !target->isAlive()) + return false; + + if(basepoints0) + CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + else + CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) +{ + if(!pVictim || !pVictim->isAlive()) + return false; + + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = 0; + + switch(scriptId) + { + case 836: // Improved Blizzard (Rank 1) + { + if (!procSpell || procSpell->SpellVisual!=9487) + return false; + triggered_spell_id = 12484; + break; + } + case 988: // Improved Blizzard (Rank 2) + { + if (!procSpell || procSpell->SpellVisual!=9487) + return false; + triggered_spell_id = 12485; + break; + } + case 989: // Improved Blizzard (Rank 3) + { + if (!procSpell || procSpell->SpellVisual!=9487) + return false; + triggered_spell_id = 12486; + break; + } + case 4086: // Improved Mend Pet (Rank 1) + case 4087: // Improved Mend Pet (Rank 2) + { + int32 chance = triggeredByAura->GetSpellProto()->EffectBasePoints[triggeredByAura->GetEffIndex()]; + if(!roll_chance_i(chance)) + return false; + + triggered_spell_id = 24406; + break; + } + case 4533: // Dreamwalker Raiment 2 pieces bonus + { + // Chance 50% + if (!roll_chance_i(50)) + return false; + + switch (pVictim->getPowerType()) + { + case POWER_MANA: triggered_spell_id = 28722; break; + case POWER_RAGE: triggered_spell_id = 28723; break; + case POWER_ENERGY: triggered_spell_id = 28724; break; + default: + return false; + } + break; + } + case 4537: // Dreamwalker Raiment 6 pieces bonus + triggered_spell_id = 28750; // Blessing of the Claw + break; + case 5497: // Improved Mana Gems (Serpent-Coil Braid) + triggered_spell_id = 37445; // Mana Surge + break; + } + + // not processed + if(!triggered_spell_id) + return false; + + // standard non-dummy case + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id,scriptId); + return false; + } + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + CastSpell(pVictim, triggered_spell_id, true, castItem, triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +void Unit::setPowerType(Powers new_powertype) +{ + SetByteValue(UNIT_FIELD_BYTES_0, 3, new_powertype); + + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE); + } + } + + switch(new_powertype) + { + default: + case POWER_MANA: + break; + case POWER_RAGE: + SetMaxPower(POWER_RAGE,GetCreatePowers(POWER_RAGE)); + SetPower( POWER_RAGE,0); + break; + case POWER_FOCUS: + SetMaxPower(POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); + SetPower( POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); + break; + case POWER_ENERGY: + SetMaxPower(POWER_ENERGY,GetCreatePowers(POWER_ENERGY)); + SetPower( POWER_ENERGY,0); + break; + case POWER_HAPPINESS: + SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + SetPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + break; + } +} + +FactionTemplateEntry const* Unit::getFactionTemplateEntry() const +{ + FactionTemplateEntry const* entry = sFactionTemplateStore.LookupEntry(getFaction()); + if(!entry) + { + static uint64 guid = 0; // prevent repeating spam same faction problem + + if(GetGUID() != guid) + { + if(GetTypeId() == TYPEID_PLAYER) + sLog.outError("Player %s have invalid faction (faction template id) #%u", ((Player*)this)->GetName(), getFaction()); + else + sLog.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature*)this)->GetCreatureInfo()->Entry, getFaction()); + guid = GetGUID(); + } + } + return entry; +} + +bool Unit::IsHostileTo(Unit const* unit) const +{ + // always non-hostile to self + if(unit==this) + return false; + + // always non-hostile to GM in GM mode + if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) + return false; + + // always hostile to enemy + if(getVictim()==unit || unit->getVictim()==this) + return true; + + // test pet/charm masters instead pers/charmeds + Unit const* testerOwner = GetCharmerOrOwner(); + Unit const* targetOwner = unit->GetCharmerOrOwner(); + + // always hostile to owner's enemy + if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) + return true; + + // always hostile to enemy owner + if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) + return true; + + // always hostile to owner of owner's enemy + if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) + return true; + + Unit const* tester = testerOwner ? testerOwner : this; + Unit const* target = targetOwner ? targetOwner : unit; + + // always non-hostile to target with common owner, or to owner/pet + if(tester==target) + return false; + + // special cases (Duel, etc) + if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) + { + Player const* pTester = (Player const*)tester; + Player const* pTarget = (Player const*)target; + + // Duel + if(pTester->duel && pTester->duel->opponent == pTarget && pTester->duel->startTime != 0) + return true; + + // Group + if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) + return false; + + // Sanctuary + if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) + return false; + + // PvP FFA state + if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) + return true; + + //= PvP states + // Green/Blue (can't attack) + if(pTester->GetTeam()==pTarget->GetTeam()) + return false; + + // Red (can attack) if true, Blue/Yellow (can't attack) in another case + return pTester->IsPvP() && pTarget->IsPvP(); + } + + // faction base cases + FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); + FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); + if(!tester_faction || !target_faction) + return false; + + if(target->isAttackingPlayer() && tester->IsContestedGuard()) + return true; + + // PvC forced reaction and reputation case + if(tester->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player*)tester)->m_forcedReactions.find(target_faction->faction); + if(forceItr!=((Player*)tester)->m_forcedReactions.end()) + return forceItr->second <= REP_HOSTILE; + + // if faction have reputation then hostile state for tester at 100% dependent from at_war state + if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) + if(raw_target_faction->reputationListID >=0) + if(FactionState const* factionState = ((Player*)tester)->GetFactionState(raw_target_faction)) + return (factionState->Flags & FACTION_FLAG_AT_WAR); + } + // CvP forced reaction and reputation case + else if(target->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); + if(forceItr!=((Player const*)target)->m_forcedReactions.end()) + return forceItr->second <= REP_HOSTILE; + + // apply reputation state + FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction); + if(raw_tester_faction && raw_tester_faction->reputationListID >=0 ) + return ((Player const*)target)->GetReputationRank(raw_tester_faction) <= REP_HOSTILE; + } + + // common faction based case (CvC,PvC,CvP) + return tester_faction->IsHostileTo(*target_faction); +} + +bool Unit::IsFriendlyTo(Unit const* unit) const +{ + // always friendly to self + if(unit==this) + return true; + + // always friendly to GM in GM mode + if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) + return true; + + // always non-friendly to enemy + if(getVictim()==unit || unit->getVictim()==this) + return false; + + // test pet/charm masters instead pers/charmeds + Unit const* testerOwner = GetCharmerOrOwner(); + Unit const* targetOwner = unit->GetCharmerOrOwner(); + + // always non-friendly to owner's enemy + if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) + return false; + + // always non-friendly to enemy owner + if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) + return false; + + // always non-friendly to owner of owner's enemy + if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) + return false; + + Unit const* tester = testerOwner ? testerOwner : this; + Unit const* target = targetOwner ? targetOwner : unit; + + // always friendly to target with common owner, or to owner/pet + if(tester==target) + return true; + + // special cases (Duel) + if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) + { + Player const* pTester = (Player const*)tester; + Player const* pTarget = (Player const*)target; + + // Duel + if(pTester->duel && pTester->duel->opponent == target && pTester->duel->startTime != 0) + return false; + + // Group + if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) + return true; + + // Sanctuary + if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) + return true; + + // PvP FFA state + if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) + return false; + + //= PvP states + // Green/Blue (non-attackable) + if(pTester->GetTeam()==pTarget->GetTeam()) + return true; + + // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable) + return !pTarget->IsPvP(); + } + + // faction base cases + FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); + FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); + if(!tester_faction || !target_faction) + return false; + + if(target->isAttackingPlayer() && tester->IsContestedGuard()) + return false; + + // PvC forced reaction and reputation case + if(tester->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player const*)tester)->m_forcedReactions.find(target_faction->faction); + if(forceItr!=((Player const*)tester)->m_forcedReactions.end()) + return forceItr->second >= REP_FRIENDLY; + + // if faction have reputation then friendly state for tester at 100% dependent from at_war state + if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) + if(raw_target_faction->reputationListID >=0) + if(FactionState const* FactionState = ((Player*)tester)->GetFactionState(raw_target_faction)) + return !(FactionState->Flags & FACTION_FLAG_AT_WAR); + } + // CvP forced reaction and reputation case + else if(target->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); + if(forceItr!=((Player const*)target)->m_forcedReactions.end()) + return forceItr->second >= REP_FRIENDLY; + + // apply reputation state + if(FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction)) + if(raw_tester_faction->reputationListID >=0 ) + return ((Player const*)target)->GetReputationRank(raw_tester_faction) >= REP_FRIENDLY; + } + + // common faction based case (CvC,PvC,CvP) + return tester_faction->IsFriendlyTo(*target_faction); +} + +bool Unit::IsHostileToPlayers() const +{ + FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); + if(!my_faction) + return false; + + FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); + if(raw_faction && raw_faction->reputationListID >=0 ) + return false; + + return my_faction->IsHostileToPlayers(); +} + +bool Unit::IsNeutralToAll() const +{ + FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); + if(!my_faction) + return true; + + FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); + if(raw_faction && raw_faction->reputationListID >=0 ) + return false; + + return my_faction->IsNeutralToAll(); +} + +bool Unit::Attack(Unit *victim, bool meleeAttack) +{ + if(!victim || victim == this) + return false; + + // dead units can neither attack nor be attacked + if(!isAlive() || !victim->isAlive()) + return false; + + // player cannot attack in mount state + if(GetTypeId()==TYPEID_PLAYER && IsMounted()) + return false; + + // nobody can attack GM in GM-mode + if(victim->GetTypeId()==TYPEID_PLAYER) + { + if(((Player*)victim)->isGameMaster()) + return false; + } + else + { + if(((Creature*)victim)->IsInEvadeMode()) + return false; + } + + // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack) + if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE)) + RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE); + + if (m_attacking) + { + if (m_attacking == victim) + { + // switch to melee attack from ranged/magic + if( meleeAttack && !hasUnitState(UNIT_STAT_MELEE_ATTACKING) ) + { + addUnitState(UNIT_STAT_MELEE_ATTACKING); + SendAttackStart(victim); + return true; + } + return false; + } + AttackStop(); + } + + //Set our target + SetUInt64Value(UNIT_FIELD_TARGET, victim->GetGUID()); + + if(meleeAttack) + addUnitState(UNIT_STAT_MELEE_ATTACKING); + m_attacking = victim; + m_attacking->_addAttacker(this); + + if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->AI()) + ((Creature*)m_attacking)->AI()->AttackedBy(this); + + if(GetTypeId()==TYPEID_UNIT) + { + WorldPacket data(SMSG_AI_REACTION, 12); + data << GetGUID(); + data << uint32(AI_REACTION_AGGRO); // Aggro sound + ((WorldObject*)this)->SendMessageToSet(&data, true); + + ((Creature*)this)->CallAssistence(); + ((Creature*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ()); + } + + // delay offhand weapon attack to next attack time + if(haveOffhandWeapon()) + resetAttackTimer(OFF_ATTACK); + + if(meleeAttack) + SendAttackStart(victim); + + return true; +} + +bool Unit::AttackStop() +{ + if (!m_attacking) + return false; + + Unit* victim = m_attacking; + + m_attacking->_removeAttacker(this); + m_attacking = NULL; + + //Clear our target + SetUInt64Value(UNIT_FIELD_TARGET, 0); + + clearUnitState(UNIT_STAT_MELEE_ATTACKING); + + InterruptSpell(CURRENT_MELEE_SPELL); + + if( GetTypeId()==TYPEID_UNIT ) + { + // reset call assistance + ((Creature*)this)->SetNoCallAssistence(false); + } + + SendAttackStop(victim); + + return true; +} + +void Unit::CombatStop(bool cast) +{ + if(cast& IsNonMeleeSpellCasted(false)) + InterruptNonMeleeSpells(false); + + AttackStop(); + RemoveAllAttackers(); + if( GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel + ClearInCombat(); +} + +void Unit::CombatStopWithPets(bool cast) +{ + CombatStop(cast); + if(Pet* pet = GetPet()) + pet->CombatStop(cast); + if(Unit* charm = GetCharm()) + charm->CombatStop(cast); + if(GetTypeId()==TYPEID_PLAYER) + { + GuardianPetList const& guardians = ((Player*)this)->GetGuardians(); + for(GuardianPetList::const_iterator itr = guardians.begin(); itr != guardians.end(); ++itr) + if(Unit* guardian = Unit::GetUnit(*this,*itr)) + guardian->CombatStop(cast); + } +} + +bool Unit::isAttackingPlayer() const +{ + if(hasUnitState(UNIT_STAT_ATTACK_PLAYER)) + return true; + + Pet* pet = GetPet(); + if(pet && pet->isAttackingPlayer()) + return true; + + Unit* charmed = GetCharm(); + if(charmed && charmed->isAttackingPlayer()) + return true; + + for (int8 i = 0; i < MAX_TOTEM; i++) + { + if(m_TotemSlot[i]) + { + Creature *totem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); + if(totem && totem->isAttackingPlayer()) + return true; + } + } + + return false; +} + +void Unit::RemoveAllAttackers() +{ + while (!m_attackers.empty()) + { + AttackerSet::iterator iter = m_attackers.begin(); + if(!(*iter)->AttackStop()) + { + sLog.outError("WORLD: Unit has an attacker that isn't attacking it!"); + m_attackers.erase(iter); + } + } +} + +void Unit::ModifyAuraState(AuraState flag, bool apply) +{ + if (apply) + { + if (!HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1))) + { + SetFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); + if(GetTypeId() == TYPEID_PLAYER) + { + const PlayerSpellMap& sp_list = ((Player*)this)->GetSpellMap(); + for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) + { + if(itr->second->state == PLAYERSPELL_REMOVED) continue; + SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); + if (!spellInfo || !IsPassiveSpell(itr->first)) continue; + if (spellInfo->CasterAuraState == flag) + CastSpell(this, itr->first, true, NULL); + } + } + } + } + else + { + if (HasFlag(UNIT_FIELD_AURASTATE,1<<(flag-1))) + { + RemoveFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); + Unit::AuraMap& tAuras = GetAuras(); + for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();) + { + SpellEntry const* spellProto = (*itr).second->GetSpellProto(); + if (spellProto->CasterAuraState == flag) + { + // exceptions (applied at state but not removed at state change) + // Rampage + if(spellProto->SpellIconID==2006 && spellProto->SpellFamilyName==SPELLFAMILY_WARRIOR && spellProto->SpellFamilyFlags==0x100000) + { + ++itr; + continue; + } + + RemoveAura(itr); + } + else + ++itr; + } + } + } +} + +Unit *Unit::GetOwner() const +{ + uint64 ownerid = GetOwnerGUID(); + if(!ownerid) + return NULL; + return ObjectAccessor::GetUnit(*this, ownerid); +} + +Unit *Unit::GetCharmer() const +{ + if(uint64 charmerid = GetCharmerGUID()) + return ObjectAccessor::GetUnit(*this, charmerid); + return NULL; +} + +Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() +{ + uint64 guid = GetCharmerOrOwnerGUID(); + if(IS_PLAYER_GUID(guid)) + return ObjectAccessor::GetPlayer(*this, guid); + + return GetTypeId()==TYPEID_PLAYER ? (Player*)this : NULL; +} + +Pet* Unit::GetPet() const +{ + if(uint64 pet_guid = GetPetGUID()) + { + if(Pet* pet = ObjectAccessor::GetPet(pet_guid)) + return pet; + + sLog.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid)); + const_cast(this)->SetPet(0); + } + + return NULL; +} + +Unit* Unit::GetCharm() const +{ + if(uint64 charm_guid = GetCharmGUID()) + { + if(Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid)) + return pet; + + sLog.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid)); + const_cast(this)->SetCharm(0); + } + + return NULL; +} + +void Unit::SetPet(Pet* pet) +{ + SetUInt64Value(UNIT_FIELD_SUMMON,pet ? pet->GetGUID() : 0); + + // FIXME: hack, speed must be set only at follow + if(pet) + for(int i = 0; i < MAX_MOVE_TYPE; ++i) + pet->SetSpeed(UnitMoveType(i),m_speed_rate[i],true); +} + +void Unit::SetCharm(Unit* charmed) +{ + SetUInt64Value(UNIT_FIELD_CHARM,charmed ? charmed->GetGUID() : 0); +} + +void Unit::AddPlayerToVision(Player* plr) +{ + if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) + { + setActive(true); + GetMap()->SwitchGridContainers((Creature*)this, true); + } + m_sharedVision.push_back(plr); + plr->SetFarsightTarget(this); +} + +void Unit::RemovePlayerFromVision(Player* plr) +{ + m_sharedVision.remove(plr); + if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) + { + setActive(false); + GetMap()->SwitchGridContainers((Creature*)this, false); + } + plr->ClearFarsight(); +} + +void Unit::RemoveAllFromVision() +{ + while (!m_sharedVision.empty()) + { + Player* plr = *m_sharedVision.begin(); + m_sharedVision.erase(m_sharedVision.begin()); + plr->ClearFarsight(); + } +} + +void Unit::UncharmSelf() +{ + if (!GetCharmer()) + return; + + RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM); +} + +void Unit::UnpossessSelf(bool attack) +{ + if (!isPossessed() || !GetCharmer()) + return; + + if (GetCharmer()->GetTypeId() == TYPEID_PLAYER) + ((Player*)GetCharmer())->RemovePossess(attack); + else + { + GetCharmer()->SetCharm(0); + SetCharmerGUID(0); + m_isPossessed = false; + } +} + +void Unit::UnsummonAllTotems() +{ + for (int8 i = 0; i < MAX_TOTEM; ++i) + { + if(!m_TotemSlot[i]) + continue; + + Creature *OldTotem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); + if (OldTotem && OldTotem->isTotem()) + ((Totem*)OldTotem)->UnSummon(); + } +} + +void Unit::SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical) +{ + // we guess size + WorldPacket data(SMSG_SPELLHEALLOG, (8+8+4+4+1)); + data.append(pVictim->GetPackGUID()); + data.append(GetPackGUID()); + data << uint32(SpellID); + data << uint32(Damage); + data << uint8(critical ? 1 : 0); + data << uint8(0); // unused in client? + SendMessageToSet(&data, true); +} + +void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype, bool critical) +{ + WorldPacket data(SMSG_SPELLENERGIZELOG, (8+8+4+4+4+1)); + data.append(pVictim->GetPackGUID()); + data.append(GetPackGUID()); + data << uint32(SpellID); + data << uint32(powertype); + data << uint32(Damage); + //data << uint8(critical ? 1 : 0); // removed in 2.4.0 + SendMessageToSet(&data, true); +} + +uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 pdamage, DamageEffectType damagetype) +{ + if(!spellProto || !pVictim || damagetype==DIRECT_DAMAGE ) + return pdamage; + + int32 BonusDamage = 0; + if( GetTypeId()==TYPEID_UNIT ) + { + // Pets just add their bonus damage to their spell damage + // note that their spell damage is just gain of their own auras + if (((Creature*)this)->isPet()) + { + BonusDamage = ((Pet*)this)->GetBonusDamage(); + } + // For totems get damage bonus from owner (statue isn't totem in fact) + else if (((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) + { + if(Unit* owner = GetOwner()) + return owner->SpellDamageBonus(pVictim, spellProto, pdamage, damagetype); + } + } + + // Damage Done + uint32 CastingTime = !IsChanneledSpell(spellProto) ? GetSpellCastTime(spellProto) : GetSpellDuration(spellProto); + + // Taken/Done fixed damage bonus auras + int32 DoneAdvertisedBenefit = SpellBaseDamageBonus(GetSpellSchoolMask(spellProto))+BonusDamage; + int32 TakenAdvertisedBenefit = SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); + + // Damage over Time spells bonus calculation + float DotFactor = 1.0f; + if(damagetype == DOT) + { + int32 DotDuration = GetSpellDuration(spellProto); + // 200% limit + if(DotDuration > 0) + { + if(DotDuration > 30000) DotDuration = 30000; + if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; + int x = 0; + for(int j = 0; j < 3; j++) + { + if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_DAMAGE || + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) + { + x = j; + break; + } + } + int DotTicks = 6; + if(spellProto->EffectAmplitude[x] != 0) + DotTicks = DotDuration / spellProto->EffectAmplitude[x]; + if(DotTicks) + { + DoneAdvertisedBenefit /= DotTicks; + TakenAdvertisedBenefit /= DotTicks; + } + } + } + + // Taken/Done total percent damage auras + float DoneTotalMod = 1.0f; + float TakenTotalMod = 1.0f; + + // ..done + AuraList const& mModDamagePercentDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE); + for(AuraList::const_iterator i = mModDamagePercentDone.begin(); i != mModDamagePercentDone.end(); ++i) + { + if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) && + (*i)->GetSpellProto()->EquippedItemClass == -1 && + // -1 == any item class (not wand then) + (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) + // 0 == any inventory type (not wand then) + { + DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + } + } + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // ..taken + AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); + for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) + if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // .. taken pct: scripted (increases damage of * against targets *) + AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) + { + switch((*i)->GetModifier()->m_miscvalue) + { + //Molten Fury + case 4920: case 4919: + if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT)) + TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; break; + } + } + + // .. taken pct: dummy auras + AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) + { + switch((*i)->GetSpellProto()->SpellIconID) + { + //Cheat Death + case 2109: + if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) ) + { + if(pVictim->GetTypeId() != TYPEID_PLAYER) + continue; + float mod = -((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL)*2*4; + if (mod < (*i)->GetModifier()->m_amount) + mod = (*i)->GetModifier()->m_amount; + TakenTotalMod *= (mod+100.0f)/100.0f; + } + break; + //Mangle + case 2312: + for(int j=0;j<3;j++) + { + if(GetEffectMechanic(spellProto, j)==MECHANIC_BLEED) + { + TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; + break; + } + } + break; + } + } + + // Distribute Damage over multiple effects, reduce by AoE + CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); + + // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing + for(int j = 0; j < 3; ++j) + { + if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || + spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) + { + CastingTime /= 2; + break; + } + } + + switch(spellProto->SpellFamilyName) + { + case SPELLFAMILY_MAGE: + // Ignite - do not modify, it is (8*Rank)% damage of procing Spell + if(spellProto->Id==12654) + { + return pdamage; + } + // Ice Lance + else if((spellProto->SpellFamilyFlags & 0x20000LL) && spellProto->SpellIconID == 186) + { + CastingTime /= 3; // applied 1/3 bonuses in case generic target + if(pVictim->isFrozen()) // and compensate this for frozen target. + TakenTotalMod *= 3.0f; + } + // Pyroblast - 115% of Fire Damage, DoT - 20% of Fire Damage + else if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 184 ) + { + DotFactor = damagetype == DOT ? 0.2f : 1.0f; + CastingTime = damagetype == DOT ? 3500 : 4025; + } + // Fireball - 100% of Fire Damage, DoT - 0% of Fire Damage + else if((spellProto->SpellFamilyFlags & 0x1LL) && spellProto->SpellIconID == 185) + { + CastingTime = 3500; + DotFactor = damagetype == DOT ? 0.0f : 1.0f; + } + // Molten armor + else if (spellProto->SpellFamilyFlags & 0x0000000800000000LL) + { + CastingTime = 0; + } + // Arcane Missiles triggered spell + else if ((spellProto->SpellFamilyFlags & 0x200000LL) && spellProto->SpellIconID == 225) + { + CastingTime = 1000; + } + // Blizzard triggered spell + else if ((spellProto->SpellFamilyFlags & 0x80080LL) && spellProto->SpellIconID == 285) + { + CastingTime = 500; + } + break; + case SPELLFAMILY_WARLOCK: + // Life Tap + if((spellProto->SpellFamilyFlags & 0x40000LL) && spellProto->SpellIconID == 208) + { + CastingTime = 2800; // 80% from +shadow damage + DoneTotalMod = 1.0f; + TakenTotalMod = 1.0f; + } + // Dark Pact + else if((spellProto->SpellFamilyFlags & 0x80000000LL) && spellProto->SpellIconID == 154 && GetPetGUID()) + { + CastingTime = 3360; // 96% from +shadow damage + DoneTotalMod = 1.0f; + TakenTotalMod = 1.0f; + } + // Soul Fire - 115% of Fire Damage + else if((spellProto->SpellFamilyFlags & 0x8000000000LL) && spellProto->SpellIconID == 184) + { + CastingTime = 4025; + } + // Curse of Agony - 120% of Shadow Damage + else if((spellProto->SpellFamilyFlags & 0x0000000400LL) && spellProto->SpellIconID == 544) + { + DotFactor = 1.2f; + } + // Drain Mana - 0% of Shadow Damage + else if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 548) + { + CastingTime = 0; + } + // Drain Soul 214.3% + else if ((spellProto->SpellFamilyFlags & 0x4000LL) && spellProto->SpellIconID == 113 ) + { + CastingTime = 7500; + } + // Hellfire + else if ((spellProto->SpellFamilyFlags & 0x40LL) && spellProto->SpellIconID == 937) + { + CastingTime = damagetype == DOT ? 5000 : 500; // self damage seems to be so + } + // Unstable Affliction - 180% + else if (spellProto->Id == 31117 && spellProto->SpellIconID == 232) + { + CastingTime = 6300; + } + // Corruption 93% + else if ((spellProto->SpellFamilyFlags & 0x2LL) && spellProto->SpellIconID == 313) + { + DotFactor = 0.93f; + } + break; + case SPELLFAMILY_PALADIN: + // Consecration - 95% of Holy Damage + if((spellProto->SpellFamilyFlags & 0x20LL) && spellProto->SpellIconID == 51) + { + DotFactor = 0.95f; + CastingTime = 3500; + } + // Seal of Righteousness - 10.2%/9.8% ( based on weapon type ) of Holy Damage, multiplied by weapon speed + else if((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 25) + { + Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + float wspeed = GetAttackTime(BASE_ATTACK)/1000.0f; + + if( item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) + CastingTime = uint32(wspeed*3500*0.102f); + else + CastingTime = uint32(wspeed*3500*0.098f); + } + // Judgement of Righteousness - 73% + else if ((spellProto->SpellFamilyFlags & 1024) && spellProto->SpellIconID == 25) + { + CastingTime = 2555; + } + // Seal of Vengeance - 17% per Fully Stacked Tick - 5 Applications + else if ((spellProto->SpellFamilyFlags & 0x80000000000LL) && spellProto->SpellIconID == 2292) + { + DotFactor = 0.17f; + CastingTime = 3500; + } + // Holy shield - 5% of Holy Damage + else if ((spellProto->SpellFamilyFlags & 0x4000000000LL) && spellProto->SpellIconID == 453) + { + CastingTime = 175; + } + // Blessing of Sanctuary - 0% + else if ((spellProto->SpellFamilyFlags & 0x10000000LL) && spellProto->SpellIconID == 29) + { + CastingTime = 0; + } + // Seal of Righteousness trigger - already computed for parent spell + else if ( spellProto->SpellFamilyName==SPELLFAMILY_PALADIN && spellProto->SpellIconID==25 && spellProto->AttributesEx4 & 0x00800000LL ) + { + return pdamage; + } + break; + case SPELLFAMILY_SHAMAN: + // totem attack + if (spellProto->SpellFamilyFlags & 0x000040000000LL) + { + if (spellProto->SpellIconID == 33) // Fire Nova totem attack must be 21.4%(untested) + CastingTime = 749; // ignore CastingTime and use as modifier + else if (spellProto->SpellIconID == 680) // Searing Totem attack 8% + CastingTime = 280; // ignore CastingTime and use as modifier + else if (spellProto->SpellIconID == 37) // Magma totem attack must be 6.67%(untested) + CastingTime = 234; // ignore CastingTimePenalty and use as modifier + } + // Lightning Shield (and proc shield from T2 8 pieces bonus ) 33% per charge + else if( (spellProto->SpellFamilyFlags & 0x00000000400LL) || spellProto->Id == 23552) + CastingTime = 1155; // ignore CastingTimePenalty and use as modifier + break; + case SPELLFAMILY_PRIEST: + // Mana Burn - 0% of Shadow Damage + if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 212) + { + CastingTime = 0; + } + // Mind Flay - 59% of Shadow Damage + else if((spellProto->SpellFamilyFlags & 0x800000LL) && spellProto->SpellIconID == 548) + { + CastingTime = 2065; + } + // Holy Fire - 86.71%, DoT - 16.5% + else if ((spellProto->SpellFamilyFlags & 0x100000LL) && spellProto->SpellIconID == 156) + { + DotFactor = damagetype == DOT ? 0.165f : 1.0f; + CastingTime = damagetype == DOT ? 3500 : 3035; + } + // Shadowguard - 28% per charge + else if ((spellProto->SpellFamilyFlags & 0x2000000LL) && spellProto->SpellIconID == 19) + { + CastingTime = 980; + } + // Touch of Weakeness - 10% + else if ((spellProto->SpellFamilyFlags & 0x80000LL) && spellProto->SpellIconID == 1591) + { + CastingTime = 350; + } + // Reflective Shield (back damage) - 0% (other spells fit to check not have damage effects/auras) + else if (spellProto->SpellFamilyFlags == 0 && spellProto->SpellIconID == 566) + { + CastingTime = 0; + } + // Holy Nova - 14% + else if ((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 1874) + { + CastingTime = 500; + } + break; + case SPELLFAMILY_DRUID: + // Hurricane triggered spell + if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 220) + { + CastingTime = 500; + } + break; + case SPELLFAMILY_WARRIOR: + case SPELLFAMILY_HUNTER: + case SPELLFAMILY_ROGUE: + CastingTime = 0; + break; + default: + break; + } + + float LvlPenalty = CalculateLevelPenalty(spellProto); + + // Spellmod SpellDamage + float SpellModSpellDamage = 100.0f; + + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); + + SpellModSpellDamage /= 100.0f; + + float DoneActualBenefit = DoneAdvertisedBenefit * (CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; + float TakenActualBenefit = TakenAdvertisedBenefit; + if(spellProto->SpellFamilyName) + TakenActualBenefit *= (CastingTime / 3500.0f) * DotFactor * LvlPenalty; + + float tmpDamage = (float(pdamage)+DoneActualBenefit)*DoneTotalMod; + + // Add flat bonus from spell damage versus + tmpDamage += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS, creatureTypeMask); + + // apply spellmod to Done damage + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, tmpDamage); + + tmpDamage = (tmpDamage+TakenActualBenefit)*TakenTotalMod; + + if( GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet() ) + tmpDamage *= ((Creature*)this)->GetSpellDamageMod(((Creature*)this)->GetCreatureInfo()->rank); + + return tmpDamage > 0 ? uint32(tmpDamage) : 0; +} + +int32 Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask) +{ + int32 DoneAdvertisedBenefit = 0; + + // ..done + AuraList const& mDamageDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE); + for(AuraList::const_iterator i = mDamageDone.begin();i != mDamageDone.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0 && + (*i)->GetSpellProto()->EquippedItemClass == -1 && + // -1 == any item class (not wand then) + (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) + // 0 == any inventory type (not wand then) + DoneAdvertisedBenefit += (*i)->GetModifier()->m_amount; + + if (GetTypeId() == TYPEID_PLAYER) + { + // Damage bonus from stats + AuraList const& mDamageDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT); + for(AuraList::const_iterator i = mDamageDoneOfStatPercent.begin();i != mDamageDoneOfStatPercent.end(); ++i) + { + if((*i)->GetModifier()->m_miscvalue & schoolMask) + { + SpellEntry const* iSpellProto = (*i)->GetSpellProto(); + uint8 eff = (*i)->GetEffIndex(); + + // stat used dependent from next effect aura SPELL_AURA_MOD_SPELL_HEALING presence and misc value (stat index) + Stats usedStat = STAT_INTELLECT; + if(eff < 2 && iSpellProto->EffectApplyAuraName[eff+1]==SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT) + usedStat = Stats(iSpellProto->EffectMiscValue[eff+1]); + + DoneAdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); + } + } + // ... and attack power + AuraList const& mDamageDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER); + for(AuraList::const_iterator i =mDamageDonebyAP.begin();i != mDamageDonebyAP.end(); ++i) + if ((*i)->GetModifier()->m_miscvalue & schoolMask) + DoneAdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); + + } + return DoneAdvertisedBenefit; +} + +int32 Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) +{ + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + + int32 TakenAdvertisedBenefit = 0; + // ..done (for creature type by mask) in taken + AuraList const& mDamageDoneCreature = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); + for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; + + // ..taken + AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); + for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) + TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; + + return TakenAdvertisedBenefit; +} + +bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType) +{ + // not criting spell + if((spellProto->AttributesEx2 & SPELL_ATTR_EX2_CANT_CRIT)) + return false; + + float crit_chance = 0.0f; + switch(spellProto->DmgClass) + { + case SPELL_DAMAGE_CLASS_NONE: + return false; + case SPELL_DAMAGE_CLASS_MAGIC: + { + if (schoolMask & SPELL_SCHOOL_MASK_NORMAL) + crit_chance = 0.0f; + // For other schools + else if (GetTypeId() == TYPEID_PLAYER) + crit_chance = GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1 + GetFirstSchoolInMask(schoolMask)); + else + { + crit_chance = m_baseSpellCritChance; + crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); + } + // taken + if (pVictim && !IsPositiveSpell(spellProto->Id)) + { + // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE + crit_chance += pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE, schoolMask); + // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE + crit_chance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); + // Modify by player victim resilience + if (pVictim->GetTypeId() == TYPEID_PLAYER) + crit_chance -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL); + // scripted (increase crit chance ... against ... target by x% + if(pVictim->isFrozen()) // Shatter + { + AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) + { + switch((*i)->GetModifier()->m_miscvalue) + { + case 849: crit_chance+= 10.0f; break; //Shatter Rank 1 + case 910: crit_chance+= 20.0f; break; //Shatter Rank 2 + case 911: crit_chance+= 30.0f; break; //Shatter Rank 3 + case 912: crit_chance+= 40.0f; break; //Shatter Rank 4 + case 913: crit_chance+= 50.0f; break; //Shatter Rank 5 + } + } + } + } + break; + } + case SPELL_DAMAGE_CLASS_MELEE: + case SPELL_DAMAGE_CLASS_RANGED: + { + if (pVictim) + { + crit_chance = GetUnitCriticalChance(attackType, pVictim); + crit_chance+= (int32(GetMaxSkillValueForLevel(pVictim)) - int32(pVictim->GetDefenseSkillValue(this))) * 0.04f; + crit_chance+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); + } + break; + } + default: + return false; + } + // percent done + // only players use intelligence for critical chance computations + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); + + crit_chance = crit_chance > 0.0f ? crit_chance : 0.0f; + if (roll_chance_f(crit_chance)) + return true; + return false; +} + +uint32 Unit::SpellCriticalBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim) +{ + // Calculate critical bonus + int32 crit_bonus; + switch(spellProto->DmgClass) + { + case SPELL_DAMAGE_CLASS_MELEE: // for melee based spells is 100% + case SPELL_DAMAGE_CLASS_RANGED: + // TODO: write here full calculation for melee/ranged spells + crit_bonus = damage; + break; + default: + crit_bonus = damage / 2; // for spells is 50% + break; + } + + // adds additional damage to crit_bonus (from talents) + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); + + if(pVictim) + { + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + crit_bonus = int32(crit_bonus * GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS, creatureTypeMask)); + } + + if(crit_bonus > 0) + damage += crit_bonus; + + return damage; +} + +uint32 Unit::SpellHealingBonus(SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, Unit *pVictim) +{ + // For totems get healing bonus from owner (statue isn't totem in fact) + if( GetTypeId()==TYPEID_UNIT && ((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) + if(Unit* owner = GetOwner()) + return owner->SpellHealingBonus(spellProto, healamount, damagetype, pVictim); + + // Healing Done + + // These Spells are doing fixed amount of healing (TODO found less hack-like check) + if (spellProto->Id == 15290 || spellProto->Id == 39373 || + spellProto->Id == 33778 || spellProto->Id == 379 || + spellProto->Id == 38395 || spellProto->Id == 40972) + return healamount; + + int32 AdvertisedBenefit = SpellBaseHealingBonus(GetSpellSchoolMask(spellProto)); + uint32 CastingTime = GetSpellCastTime(spellProto); + + // Healing Taken + AdvertisedBenefit += SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); + + // Blessing of Light dummy effects healing taken from Holy Light and Flash of Light + if (spellProto->SpellFamilyName == SPELLFAMILY_PALADIN && (spellProto->SpellFamilyFlags & 0x00000000C0000000LL)) + { + AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i) + { + if((*i)->GetSpellProto()->SpellVisual == 9180) + { + // Flash of Light + if ((spellProto->SpellFamilyFlags & 0x0000000040000000LL) && (*i)->GetEffIndex() == 1) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + // Holy Light + else if ((spellProto->SpellFamilyFlags & 0x0000000080000000LL) && (*i)->GetEffIndex() == 0) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + } + } + } + + float ActualBenefit = 0.0f; + + if (AdvertisedBenefit != 0) + { + // Healing over Time spells + float DotFactor = 1.0f; + if(damagetype == DOT) + { + int32 DotDuration = GetSpellDuration(spellProto); + if(DotDuration > 0) + { + // 200% limit + if(DotDuration > 30000) DotDuration = 30000; + if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; + int x = 0; + for(int j = 0; j < 3; j++) + { + if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_HEAL || + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) + { + x = j; + break; + } + } + int DotTicks = 6; + if(spellProto->EffectAmplitude[x] != 0) + DotTicks = DotDuration / spellProto->EffectAmplitude[x]; + if(DotTicks) + AdvertisedBenefit /= DotTicks; + } + } + + // distribute healing to all effects, reduce AoE damage + CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); + + // 0% bonus for damage and healing spells for leech spells from healing bonus + for(int j = 0; j < 3; ++j) + { + if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || + spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) + { + CastingTime = 0; + break; + } + } + + // Exception + switch (spellProto->SpellFamilyName) + { + case SPELLFAMILY_SHAMAN: + // Healing stream from totem (add 6% per tick from hill bonus owner) + if (spellProto->SpellFamilyFlags & 0x000000002000LL) + CastingTime = 210; + // Earth Shield 30% per charge + else if (spellProto->SpellFamilyFlags & 0x40000000000LL) + CastingTime = 1050; + break; + case SPELLFAMILY_DRUID: + // Lifebloom + if (spellProto->SpellFamilyFlags & 0x1000000000LL) + { + CastingTime = damagetype == DOT ? 3500 : 1200; + DotFactor = damagetype == DOT ? 0.519f : 1.0f; + } + // Tranquility triggered spell + else if (spellProto->SpellFamilyFlags & 0x80LL) + CastingTime = 667; + // Rejuvenation + else if (spellProto->SpellFamilyFlags & 0x10LL) + DotFactor = 0.845f; + // Regrowth + else if (spellProto->SpellFamilyFlags & 0x40LL) + { + DotFactor = damagetype == DOT ? 0.705f : 1.0f; + CastingTime = damagetype == DOT ? 3500 : 1010; + } + break; + case SPELLFAMILY_PRIEST: + // Holy Nova - 14% + if ((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 1874) + CastingTime = 500; + break; + case SPELLFAMILY_PALADIN: + // Seal and Judgement of Light + if ( spellProto->SpellFamilyFlags & 0x100040000LL ) + CastingTime = 0; + break; + case SPELLFAMILY_WARRIOR: + case SPELLFAMILY_ROGUE: + case SPELLFAMILY_HUNTER: + CastingTime = 0; + break; + } + + float LvlPenalty = CalculateLevelPenalty(spellProto); + + // Spellmod SpellDamage + float SpellModSpellDamage = 100.0f; + + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); + + SpellModSpellDamage /= 100.0f; + + ActualBenefit = (float)AdvertisedBenefit * ((float)CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; + } + + // use float as more appropriate for negative values and percent applying + float heal = healamount + ActualBenefit; + + // TODO: check for ALL/SPELLS type + // Healing done percent + AuraList const& mHealingDonePct = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT); + for(AuraList::const_iterator i = mHealingDonePct.begin();i != mHealingDonePct.end(); ++i) + heal *= (100.0f + (*i)->GetModifier()->m_amount) / 100.0f; + + // apply spellmod to Done amount + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, heal); + + // Healing Wave cast + if (spellProto->SpellFamilyName == SPELLFAMILY_SHAMAN && spellProto->SpellFamilyFlags & 0x0000000000000040LL) + { + // Search for Healing Way on Victim (stack up to 3 time) + int32 pctMod = 0; + Unit::AuraList const& auraDummy = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr!=auraDummy.end(); ++itr) + if((*itr)->GetId() == 29203) + pctMod += (*itr)->GetModifier()->m_amount; + // Apply bonus + if (pctMod) + heal = heal * (100 + pctMod) / 100; + } + + // Healing taken percent + float minval = pVictim->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT); + if(minval) + heal *= (100.0f + minval) / 100.0f; + + float maxval = pVictim->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT); + if(maxval) + heal *= (100.0f + maxval) / 100.0f; + + if (heal < 0) heal = 0; + + return uint32(heal); +} + +int32 Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask) +{ + int32 AdvertisedBenefit = 0; + + AuraList const& mHealingDone = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE); + for(AuraList::const_iterator i = mHealingDone.begin();i != mHealingDone.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + + // Healing bonus of spirit, intellect and strength + if (GetTypeId() == TYPEID_PLAYER) + { + // Healing bonus from stats + AuraList const& mHealingDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT); + for(AuraList::const_iterator i = mHealingDoneOfStatPercent.begin();i != mHealingDoneOfStatPercent.end(); ++i) + { + // stat used dependent from misc value (stat index) + Stats usedStat = Stats((*i)->GetSpellProto()->EffectMiscValue[(*i)->GetEffIndex()]); + AdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); + } + + // ... and attack power + AuraList const& mHealingDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER); + for(AuraList::const_iterator i = mHealingDonebyAP.begin();i != mHealingDonebyAP.end(); ++i) + if ((*i)->GetModifier()->m_miscvalue & schoolMask) + AdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); + } + return AdvertisedBenefit; +} + +int32 Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) +{ + int32 AdvertisedBenefit = 0; + AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_HEALING); + for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + return AdvertisedBenefit; +} + +bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask, bool useCharges) +{ + // no charges dependent checks + SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; + for (SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) + if(itr->type & shoolMask) + return true; + + // charges dependent checks + SpellImmuneList const& damageList = m_spellImmune[IMMUNITY_DAMAGE]; + for (SpellImmuneList::const_iterator itr = damageList.begin(); itr != damageList.end(); ++itr) + { + if(itr->type & shoolMask) + { + if(useCharges) + { + AuraList const& auraDamageImmunity = GetAurasByType(SPELL_AURA_DAMAGE_IMMUNITY); + for(AuraList::const_iterator auraItr = auraDamageImmunity.begin(); auraItr != auraDamageImmunity.end(); ++auraItr) + { + if((*auraItr)->GetId()==itr->spellId) + { + if((*auraItr)->m_procCharges > 0) + { + --(*auraItr)->m_procCharges; + if((*auraItr)->m_procCharges==0) + RemoveAurasDueToSpell(itr->spellId); + } + break; + } + } + } + return true; + } + } + + return false; +} + +bool Unit::IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges) +{ + if (!spellInfo) + return false; + + // no charges first + + //FIX ME this hack: don't get feared if stunned + if (spellInfo->Mechanic == MECHANIC_FEAR ) + { + if ( hasUnitState(UNIT_STAT_STUNNED) ) + return true; + } + + // not have spells with charges currently + SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_DISPEL]; + for(SpellImmuneList::const_iterator itr = dispelList.begin(); itr != dispelList.end(); ++itr) + if(itr->type == spellInfo->Dispel) + return true; + + if( !(spellInfo->AttributesEx & SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE) && (spellInfo->Id != 42292)) // unaffected by school immunity + { + // not have spells with charges currently + SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; + for(SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) + if( !(IsPositiveSpell(itr->spellId) && IsPositiveSpell(spellInfo->Id)) && + (itr->type & GetSpellSchoolMask(spellInfo)) ) + return true; + } + + // charges dependent checks + + SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; + for(SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) + { + if(itr->type == spellInfo->Mechanic) + { + if(useCharges) + { + AuraList const& auraMechImmunity = GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY); + for(AuraList::const_iterator auraItr = auraMechImmunity.begin(); auraItr != auraMechImmunity.end(); ++auraItr) + { + if((*auraItr)->GetId()==itr->spellId) + { + if((*auraItr)->m_procCharges > 0) + { + --(*auraItr)->m_procCharges; + if((*auraItr)->m_procCharges==0) + RemoveAurasDueToSpell(itr->spellId); + } + break; + } + } + } + return true; + } + } + + return false; +} + +bool Unit::IsImmunedToSpellEffect(uint32 effect, uint32 mechanic) const +{ + //If m_immuneToEffect type contain this effect type, IMMUNE effect. + SpellImmuneList const& effectList = m_spellImmune[IMMUNITY_EFFECT]; + for (SpellImmuneList::const_iterator itr = effectList.begin(); itr != effectList.end(); ++itr) + if(itr->type == effect) + return true; + + SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; + for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) + if(itr->type == mechanic) + return true; + + return false; +} + +bool Unit::IsDamageToThreatSpell(SpellEntry const * spellInfo) const +{ + if(!spellInfo) + return false; + + uint32 family = spellInfo->SpellFamilyName; + uint64 flags = spellInfo->SpellFamilyFlags; + + if((family == 5 && flags == 256) || //Searing Pain + (family == 6 && flags == 8192) || //Mind Blast + (family == 11 && flags == 1048576)) //Earth Shock + return true; + + return false; +} + +void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage,WeaponAttackType attType, SpellEntry const *spellProto) +{ + if(!pVictim) + return; + + if(*pdamage == 0) + return; + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + + // Taken/Done fixed damage bonus auras + int32 DoneFlatBenefit = 0; + int32 TakenFlatBenefit = 0; + + // ..done (for creature type by mask) in taken + AuraList const& mDamageDoneCreature = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); + for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + DoneFlatBenefit += (*i)->GetModifier()->m_amount; + + // ..done + // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage + + // ..done (base at attack power for marked target and base at attack power for creature type) + int32 APbonus = 0; + if(attType == RANGED_ATTACK) + { + APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS); + + // ..done (base at attack power and creature type) + AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS); + for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + APbonus += (*i)->GetModifier()->m_amount; + } + else + { + APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS); + + // ..done (base at attack power and creature type) + AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS); + for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + APbonus += (*i)->GetModifier()->m_amount; + } + + if (APbonus!=0) // Can be negative + { + bool normalized = false; + if(spellProto) + { + for (uint8 i = 0; i<3;i++) + { + if (spellProto->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG) + { + normalized = true; + break; + } + } + } + + DoneFlatBenefit += int32(APbonus/14.0f * GetAPMultiplier(attType,normalized)); + } + + // ..taken + AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); + for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) + if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) + TakenFlatBenefit += (*i)->GetModifier()->m_amount; + + if(attType!=RANGED_ATTACK) + TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN); + else + TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN); + + // Done/Taken total percent damage auras + float DoneTotalMod = 1; + float TakenTotalMod = 1; + + // ..done + // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage + // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage + + AuraList const& mDamageDoneVersus = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // ..taken + AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); + for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) + if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // .. taken pct: dummy auras + AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) + { + switch((*i)->GetSpellProto()->SpellIconID) + { + //Cheat Death + case 2109: + if((*i)->GetModifier()->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) + { + if(pVictim->GetTypeId() != TYPEID_PLAYER) + continue; + float mod = ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); + if (mod < (*i)->GetModifier()->m_amount) + mod = (*i)->GetModifier()->m_amount; + TakenTotalMod *= (mod+100.0f)/100.0f; + } + break; + //Mangle + case 2312: + if(spellProto==NULL) + break; + // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG) + if(spellProto->SpellFamilyName==SPELLFAMILY_DRUID && (spellProto->SpellFamilyFlags==0x00008000LL)) + TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; + break; + } + } + + // .. taken pct: class scripts + AuraList const& mclassScritAuras = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator i = mclassScritAuras.begin(); i != mclassScritAuras.end(); ++i) + { + switch((*i)->GetMiscValue()) + { + case 6427: case 6428: // Dirty Deeds + if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT)) + { + Aura* eff0 = GetAura((*i)->GetId(),0); + if(!eff0 || (*i)->GetEffIndex()!=1) + { + sLog.outError("Spell structure of DD (%u) changed.",(*i)->GetId()); + continue; + } + + // effect 0 have expected value but in negative state + TakenTotalMod *= (-eff0->GetModifier()->m_amount+100.0f)/100.0f; + } + break; + } + } + + if(attType != RANGED_ATTACK) + { + AuraList const& mModMeleeDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT); + for(AuraList::const_iterator i = mModMeleeDamageTakenPercent.begin(); i != mModMeleeDamageTakenPercent.end(); ++i) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + } + else + { + AuraList const& mModRangedDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT); + for(AuraList::const_iterator i = mModRangedDamageTakenPercent.begin(); i != mModRangedDamageTakenPercent.end(); ++i) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + } + + float tmpDamage = float(int32(*pdamage) + DoneFlatBenefit) * DoneTotalMod; + + // apply spellmod to Done damage + if(spellProto) + { + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_DAMAGE, tmpDamage); + } + + tmpDamage = (tmpDamage + TakenFlatBenefit)*TakenTotalMod; + + // bonus result can be negative + *pdamage = tmpDamage > 0 ? uint32(tmpDamage) : 0; +} + +void Unit::ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply) +{ + if (apply) + { + for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(), next; itr != m_spellImmune[op].end(); itr = next) + { + next = itr; ++next; + if(itr->type == type) + { + m_spellImmune[op].erase(itr); + next = m_spellImmune[op].begin(); + } + } + SpellImmune Immune; + Immune.spellId = spellId; + Immune.type = type; + m_spellImmune[op].push_back(Immune); + } + else + { + for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(); itr != m_spellImmune[op].end(); ++itr) + { + if(itr->spellId == spellId) + { + m_spellImmune[op].erase(itr); + break; + } + } + } + +} + +void Unit::ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply) +{ + ApplySpellImmune(spellProto->Id,IMMUNITY_DISPEL, type, apply); + + if (apply && spellProto->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY) + RemoveAurasWithDispelType(type); +} + +float Unit::GetWeaponProcChance() const +{ + // normalized proc chance for weapon attack speed + // (odd formula...) + if(isAttackReady(BASE_ATTACK)) + return (GetAttackTime(BASE_ATTACK) * 1.8f / 1000.0f); + else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK)) + return (GetAttackTime(OFF_ATTACK) * 1.6f / 1000.0f); + return 0; +} + +float Unit::GetPPMProcChance(uint32 WeaponSpeed, float PPM) const +{ + // proc per minute chance calculation + if (PPM <= 0) return 0.0f; + uint32 result = uint32((WeaponSpeed * PPM) / 600.0f); // result is chance in percents (probability = Speed_in_sec * (PPM / 60)) + return result; +} + +void Unit::Mount(uint32 mount) +{ + if(!mount) + return; + + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNT); + + SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, mount); + + SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); + + // unsummon pet + if(GetTypeId() == TYPEID_PLAYER) + { + Pet* pet = GetPet(); + if(pet) + { + if(pet->isControlled()) + { + ((Player*)this)->SetTemporaryUnsummonedPetNumber(pet->GetCharmInfo()->GetPetNumber()); + ((Player*)this)->SetOldPetSpell(pet->GetUInt32Value(UNIT_CREATED_BY_SPELL)); + } + + ((Player*)this)->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT); + } + else + ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); + } +} + +void Unit::Unmount() +{ + if(!IsMounted()) + return; + + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED); + + SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0); + RemoveFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); + + // only resummon old pet if the player is already added to a map + // this prevents adding a pet to a not created map which would otherwise cause a crash + // (it could probably happen when logging in after a previous crash) + if(GetTypeId() == TYPEID_PLAYER && IsInWorld() && ((Player*)this)->GetTemporaryUnsummonedPetNumber() && isAlive()) + { + Pet* NewPet = new Pet; + if(!NewPet->LoadPetFromDB(this, 0, ((Player*)this)->GetTemporaryUnsummonedPetNumber(), true)) + delete NewPet; + + ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); + } +} + +void Unit::SetInCombatWith(Unit* enemy) +{ + Unit* eOwner = enemy->GetCharmerOrOwnerOrSelf(); + if(eOwner->IsPvP()) + { + SetInCombatState(true); + return; + } + + //check for duel + if(eOwner->GetTypeId() == TYPEID_PLAYER && ((Player*)eOwner)->duel) + { + Unit const* myOwner = GetCharmerOrOwnerOrSelf(); + if(((Player const*)eOwner)->duel->opponent == myOwner) + { + SetInCombatState(true); + return; + } + } + SetInCombatState(false); +} + +void Unit::CombatStart(Unit* target) +{ + if(!target->IsStandState() && !target->hasUnitState(UNIT_STAT_STUNNED)) + target->SetStandState(PLAYER_STATE_NONE); + + if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER && ((Creature*)target)->AI()) + ((Creature*)target)->AI()->AttackStart(this); + + SetInCombatWith(target); + target->SetInCombatWith(this); + + if(Player* attackedPlayer = target->GetCharmerOrOwnerPlayerOrPlayerItself()) + SetContestedPvP(attackedPlayer); + + if(!isInCombat()) // remove this? + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ATTACK); +} + +void Unit::SetInCombatState(bool PvP) +{ + // only alive units can be in combat + if(!isAlive()) + return; + + if(PvP) + m_CombatTimer = 5000; + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); + + if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); +} + +void Unit::ClearInCombat() +{ + m_CombatTimer = 0; + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); + + if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); + + // Player's state will be cleared in Player::UpdateContestedPvP + if(GetTypeId()!=TYPEID_PLAYER) + clearUnitState(UNIT_STAT_ATTACK_PLAYER); +} + +//TODO: remove this function +bool Unit::isTargetableForAttack() const +{ + return isAttackableByAOE() && !hasUnitState(UNIT_STAT_DIED); +} + +bool Unit::canAttack(Unit const* target) const +{ + assert(target); + + if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) + return false; + + if((m_invisibilityMask || target->m_invisibilityMask) && !canDetectInvisibilityOf(target)) + return false; + + if(target->GetVisibility() == VISIBILITY_GROUP_STEALTH && !canDetectStealthOf(target, GetDistance(target))) + return false; + + return true; +} + +bool Unit::isAttackableByAOE() const +{ + if(!isAlive()) + return false; + + if(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE)) + return false; + + if(GetTypeId()==TYPEID_PLAYER && ((Player *)this)->isGameMaster()) + return false; + + return !isInFlight(); +} + +int32 Unit::ModifyHealth(int32 dVal) +{ + int32 gain = 0; + + if(dVal==0) + return 0; + + int32 curHealth = (int32)GetHealth(); + + int32 val = dVal + curHealth; + if(val <= 0) + { + SetHealth(0); + return -curHealth; + } + + int32 maxHealth = (int32)GetMaxHealth(); + + if(val < maxHealth) + { + SetHealth(val); + gain = val - curHealth; + } + else if(curHealth != maxHealth) + { + SetHealth(maxHealth); + gain = maxHealth - curHealth; + } + + return gain; +} + +int32 Unit::ModifyPower(Powers power, int32 dVal) +{ + int32 gain = 0; + + if(dVal==0) + return 0; + + int32 curPower = (int32)GetPower(power); + + int32 val = dVal + curPower; + if(val <= 0) + { + SetPower(power,0); + return -curPower; + } + + int32 maxPower = (int32)GetMaxPower(power); + + if(val < maxPower) + { + SetPower(power,val); + gain = val - curPower; + } + else if(curPower != maxPower) + { + SetPower(power,maxPower); + gain = maxPower - curPower; + } + + return gain; +} + +bool Unit::isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList) const +{ + if(!u) + return false; + return u->canSeeOrDetect(this, detect, inVisibleList); +} + +bool Unit::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList) const +{ + return true; +} + +bool Unit::canDetectInvisibilityOf(Unit const* u) const +{ + if(m_invisibilityMask & u->m_invisibilityMask) // same group + return true; + AuraList const& auras = GetAurasByType(SPELL_AURA_MOD_STALKED); // Hunter mark + for(AuraList::const_iterator iter = auras.begin(); iter != auras.end(); ++iter) + if((*iter)->GetCasterGUID()==u->GetGUID()) + return true; + + if(uint32 mask = (m_detectInvisibilityMask & u->m_invisibilityMask)) + { + for(uint32 i = 0; i < 10; ++i) + { + if(((1 << i) & mask)==0) + continue; + + // find invisibility level + uint32 invLevel = 0; + Unit::AuraList const& iAuras = u->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY); + for(Unit::AuraList::const_iterator itr = iAuras.begin(); itr != iAuras.end(); ++itr) + if(((*itr)->GetModifier()->m_miscvalue)==i && invLevel < (*itr)->GetModifier()->m_amount) + invLevel = (*itr)->GetModifier()->m_amount; + + // find invisibility detect level + uint32 detectLevel = 0; + if(i==6 && GetTypeId()==TYPEID_PLAYER) // special drunk detection case + { + detectLevel = ((Player*)this)->GetDrunkValue(); + } + else + { + Unit::AuraList const& dAuras = GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION); + for(Unit::AuraList::const_iterator itr = dAuras.begin(); itr != dAuras.end(); ++itr) + if(((*itr)->GetModifier()->m_miscvalue)==i && detectLevel < (*itr)->GetModifier()->m_amount) + detectLevel = (*itr)->GetModifier()->m_amount; + } + + if(invLevel <= detectLevel) + return true; + } + } + + return false; +} + +bool Unit::canDetectStealthOf(Unit const* target, float distance) const +{ + if(hasUnitState(UNIT_STAT_STUNNED)) + return false; + if(distance < 0.24f) //collision + return true; + if(!HasInArc(M_PI, target)) //behind + return false; + if(HasAuraType(SPELL_AURA_DETECT_STEALTH)) + return true; + + //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5) + float visibleDistance = 10.5f - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH) / 100.0f; + //Visible distance is modified by -Level Diff (every level diff = 1.0f in visible distance) + visibleDistance += int32(getLevelForTarget(target)) - int32(target->getLevelForTarget(this)); + //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia) + //based on wowwiki every 5 mod we have 1 more level diff in calculation + visibleDistance += (float)(GetTotalAuraModifier(SPELL_AURA_MOD_DETECT) - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL)) / 5.0f; + + return distance < visibleDistance; +} + +void Unit::SetVisibility(UnitVisibility x) +{ + m_Visibility = x; + + if(IsInWorld()) + { + Map *m = MapManager::Instance().GetMap(GetMapId(), this); + + if(GetTypeId()==TYPEID_PLAYER) + m->PlayerRelocation((Player*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); + else + m->CreatureRelocation((Creature*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); + } +} + +void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) +{ + int32 main_speed_mod = 0; + float stack_bonus = 1.0f; + float non_stack_bonus = 1.0f; + + switch(mtype) + { + case MOVE_WALK: + return; + case MOVE_RUN: + { + if (IsMounted()) // Use on mount auras + { + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED); + stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS); + non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK))/100.0f; + } + else + { + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED); + stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS); + non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK))/100.0f; + } + break; + } + case MOVE_WALKBACK: + return; + case MOVE_SWIM: + { + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED); + break; + } + case MOVE_SWIMBACK: + return; + case MOVE_FLY: + { + if (IsMounted()) // Use on mount auras + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED); + else // Use not mount (shapeshift for example) auras (should stack) + main_speed_mod = GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT); + stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS); + non_stack_bonus = (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK))/100.0f; + break; + } + case MOVE_FLYBACK: + return; + default: + sLog.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype); + return; + } + + float bonus = non_stack_bonus > stack_bonus ? non_stack_bonus : stack_bonus; + // now we ready for speed calculation + float speed = main_speed_mod ? bonus*(100.0f + main_speed_mod)/100.0f : bonus; + + switch(mtype) + { + case MOVE_RUN: + case MOVE_SWIM: + case MOVE_FLY: + { + // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need + // TODO: possible affect only on MOVE_RUN + if(int32 normalization = GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED)) + { + // Use speed from aura + float max_speed = normalization / baseMoveSpeed[mtype]; + if (speed > max_speed) + speed = max_speed; + } + break; + } + default: + break; + } + + // Apply strongest slow aura mod to speed + int32 slow = GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED); + if (slow) + speed *=(100.0f + slow)/100.0f; + SetSpeed(mtype, speed, forced); +} + +float Unit::GetSpeed( UnitMoveType mtype ) const +{ + return m_speed_rate[mtype]*baseMoveSpeed[mtype]; +} + +void Unit::SetSpeed(UnitMoveType mtype, float rate, bool forced) +{ + if (rate < 0) + rate = 0.0f; + + // Update speed only on change + if (m_speed_rate[mtype] == rate) + return; + + m_speed_rate[mtype] = rate; + + propagateSpeedChange(); + + // Send speed change packet only for player + if (GetTypeId()!=TYPEID_PLAYER) + return; + + WorldPacket data; + if(!forced) + { + switch(mtype) + { + case MOVE_WALK: + data.Initialize(MSG_MOVE_SET_WALK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_RUN: + data.Initialize(MSG_MOVE_SET_RUN_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_WALKBACK: + data.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_SWIM: + data.Initialize(MSG_MOVE_SET_SWIM_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_SWIMBACK: + data.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_TURN: + data.Initialize(MSG_MOVE_SET_TURN_RATE, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_FLY: + data.Initialize(MSG_MOVE_SET_FLIGHT_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_FLYBACK: + data.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + default: + sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); + return; + } + + data.append(GetPackGUID()); + data << uint32(0); //movement flags + data << uint8(0); //unk + data << uint32(getMSTime()); + data << float(GetPositionX()); + data << float(GetPositionY()); + data << float(GetPositionZ()); + data << float(GetOrientation()); + data << uint32(0); //flag unk + data << float(GetSpeed(mtype)); + SendMessageToSet( &data, true ); + } + else + { + // register forced speed changes for WorldSession::HandleForceSpeedChangeAck + // and do it only for real sent packets and use run for run/mounted as client expected + ++((Player*)this)->m_forced_speed_changes[mtype]; + switch(mtype) + { + case MOVE_WALK: + data.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE, 16); + break; + case MOVE_RUN: + data.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE, 17); + break; + case MOVE_WALKBACK: + data.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE, 16); + break; + case MOVE_SWIM: + data.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE, 16); + break; + case MOVE_SWIMBACK: + data.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE, 16); + break; + case MOVE_TURN: + data.Initialize(SMSG_FORCE_TURN_RATE_CHANGE, 16); + break; + case MOVE_FLY: + data.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE, 16); + break; + case MOVE_FLYBACK: + data.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE, 16); + break; + default: + sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); + return; + } + data.append(GetPackGUID()); + data << (uint32)0; + if (mtype == MOVE_RUN) + data << uint8(0); // new 2.1.0 + data << float(GetSpeed(mtype)); + SendMessageToSet( &data, true ); + } + if(Pet* pet = GetPet()) + pet->SetSpeed(MOVE_RUN, m_speed_rate[mtype],forced); +} + +void Unit::SetHover(bool on) +{ + if(on) + CastSpell(this,11010,true); + else + RemoveAurasDueToSpell(11010); +} + +void Unit::setDeathState(DeathState s) +{ + if (s != ALIVE && s!= JUST_ALIVED) + { + CombatStop(); + DeleteThreatList(); + ClearComboPointHolders(); // any combo points pointed to unit lost at it death + + if(IsNonMeleeSpellCasted(false)) + InterruptNonMeleeSpells(false); + } + + if (s == JUST_DIED) + { + RemoveAllAurasOnDeath(); + UnsummonAllTotems(); + + // Possessed unit died, restore control to possessor + UnpossessSelf(false); + RemoveAllFromVision(); + + ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, false); + ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, false); + // remove aurastates allowing special moves + ClearAllReactives(); + ClearDiminishings(); + } + else if(s == JUST_ALIVED) + { + RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); // clear skinnable for creature and player (at battleground) + } + + if (m_deathState != ALIVE && s == ALIVE) + { + //_ApplyAllAuraMods(); + } + m_deathState = s; +} + +/*######################################## +######## ######## +######## AGGRO SYSTEM ######## +######## ######## +########################################*/ +bool Unit::CanHaveThreatList() const +{ + // only creatures can have threat list + if( GetTypeId() != TYPEID_UNIT ) + return false; + + // only alive units can have threat list + if( !isAlive() ) + return false; + + // pets and totems can not have threat list + if( ((Creature*)this)->isPet() || ((Creature*)this)->isTotem() ) + return false; + + return true; +} + +//====================================================================== + +float Unit::ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask) +{ + if(!HasAuraType(SPELL_AURA_MOD_THREAT)) + return threat; + + SpellSchools school = GetFirstSchoolInMask(schoolMask); + + return threat * m_threatModifier[school]; +} + +//====================================================================== + +void Unit::AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask, SpellEntry const *threatSpell) +{ + // Only mobs can manage threat lists + if(CanHaveThreatList()) + m_ThreatManager.addThreat(pVictim, threat, schoolMask, threatSpell); +} + +//====================================================================== + +void Unit::DeleteThreatList() +{ + m_ThreatManager.clearReferences(); +} + +//====================================================================== + +void Unit::TauntApply(Unit* taunter) +{ + assert(GetTypeId()== TYPEID_UNIT); + + if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) + return; + + if(!CanHaveThreatList()) + return; + + Unit *target = getVictim(); + if(target && target == taunter) + return; + + SetInFront(taunter); + if (((Creature*)this)->AI()) + ((Creature*)this)->AI()->AttackStart(taunter); + + m_ThreatManager.tauntApply(taunter); +} + +//====================================================================== + +void Unit::TauntFadeOut(Unit *taunter) +{ + assert(GetTypeId()== TYPEID_UNIT); + + if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) + return; + + if(!CanHaveThreatList()) + return; + + Unit *target = getVictim(); + if(!target || target != taunter) + return; + + if(m_ThreatManager.isThreatListEmpty()) + { + if(((Creature*)this)->AI()) + ((Creature*)this)->AI()->EnterEvadeMode(); + return; + } + + m_ThreatManager.tauntFadeOut(taunter); + target = m_ThreatManager.getHostilTarget(); + + if (target && target != taunter) + { + SetInFront(target); + if (((Creature*)this)->AI()) + ((Creature*)this)->AI()->AttackStart(target); + } +} + +//====================================================================== + +bool Unit::SelectHostilTarget() +{ + //function provides main threat functionality + //next-victim-selection algorithm and evade mode are called + //threat list sorting etc. + + assert(GetTypeId()== TYPEID_UNIT); + Unit* target = NULL; + + //This function only useful once AI has been initialized + if (!((Creature*)this)->AI()) + return false; + + if(!m_ThreatManager.isThreatListEmpty()) + { + if(!HasAuraType(SPELL_AURA_MOD_TAUNT)) + { + target = m_ThreatManager.getHostilTarget(); + } + } + + if(target) + { + if(!hasUnitState(UNIT_STAT_STUNNED)) + SetInFront(target); + ((Creature*)this)->AI()->AttackStart(target); + return true; + } + + // no target but something prevent go to evade mode + if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT) ) + return false; + + // last case when creature don't must go to evade mode: + // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list + // for example at owner command to pet attack some far away creature + // Note: creature not have targeted movement generator but have attacker in this case + if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE ) + { + for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr) + { + if( (*itr)->IsInMap(this) && canAttack(*itr) && (*itr)->isInAccessiblePlaceFor((Creature*)this) ) + return false; + } + } + + // enter in evade mode in other case + ((Creature*)this)->AI()->EnterEvadeMode(); + + return false; +} + +//====================================================================== +//====================================================================== +//====================================================================== + +int32 Unit::CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 effBasePoints, Unit const* target) +{ + Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; + + uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; + + int32 level = int32(getLevel()) - int32(spellProto->spellLevel); + if (level > spellProto->maxLevel && spellProto->maxLevel > 0) + level = spellProto->maxLevel; + + float basePointsPerLevel = spellProto->EffectRealPointsPerLevel[effect_index]; + float randomPointsPerLevel = spellProto->EffectDicePerLevel[effect_index]; + int32 basePoints = int32(effBasePoints + level * basePointsPerLevel); + int32 randomPoints = int32(spellProto->EffectDieSides[effect_index] + level * randomPointsPerLevel); + float comboDamage = spellProto->EffectPointsPerComboPoint[effect_index]; + + // prevent random generator from getting confused by spells casted with Unit::CastCustomSpell + int32 randvalue = spellProto->EffectBaseDice[effect_index] >= randomPoints ? spellProto->EffectBaseDice[effect_index]:irand(spellProto->EffectBaseDice[effect_index], randomPoints); + int32 value = basePoints + randvalue; + //random damage + if(comboDamage != 0 && unitPlayer && target && (target->GetGUID() == unitPlayer->GetComboTarget())) + value += (int32)(comboDamage * comboPoints); + + if(Player* modOwner = GetSpellModOwner()) + { + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_ALL_EFFECTS, value); + switch(effect_index) + { + case 0: + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT1, value); + break; + case 1: + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT2, value); + break; + case 2: + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT3, value); + break; + } + } + + if(spellProto->Attributes & SPELL_ATTR_LEVEL_DAMAGE_CALCULATION && spellProto->spellLevel && + spellProto->Effect[effect_index] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE && + spellProto->Effect[effect_index] != SPELL_EFFECT_KNOCK_BACK) + value = int32(value*0.25f*exp(getLevel()*(70-spellProto->spellLevel)/1000.0f)); + + return value; +} + +int32 Unit::CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target) +{ + Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; + + uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; + + int32 minduration = GetSpellDuration(spellProto); + int32 maxduration = GetSpellMaxDuration(spellProto); + + int32 duration; + + if( minduration != -1 && minduration != maxduration ) + duration = minduration + int32((maxduration - minduration) * comboPoints / 5); + else + duration = minduration; + + if (duration > 0) + { + int32 mechanic = GetEffectMechanic(spellProto, effect_index); + // Find total mod value (negative bonus) + int32 durationMod_always = target->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD, mechanic); + // Find max mod (negative bonus) + int32 durationMod_not_stack = target->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK, mechanic); + + int32 durationMod = 0; + // Select strongest negative mod + if (durationMod_always > durationMod_not_stack) + durationMod = durationMod_not_stack; + else + durationMod = durationMod_always; + + if (durationMod != 0) + duration = int32(int64(duration) * (100+durationMod) /100); + + if (duration < 0) duration = 0; + } + + return duration; +} + +DiminishingLevels Unit::GetDiminishing(DiminishingGroup group) +{ + for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) + { + if(i->DRGroup != group) + continue; + + if(!i->hitCount) + return DIMINISHING_LEVEL_1; + + if(!i->hitTime) + return DIMINISHING_LEVEL_1; + + // If last spell was casted more than 15 seconds ago - reset the count. + if(i->stack==0 && getMSTimeDiff(i->hitTime,getMSTime()) > 15000) + { + i->hitCount = DIMINISHING_LEVEL_1; + return DIMINISHING_LEVEL_1; + } + // or else increase the count. + else + { + return DiminishingLevels(i->hitCount); + } + } + return DIMINISHING_LEVEL_1; +} + +void Unit::IncrDiminishing(DiminishingGroup group) +{ + // Checking for existing in the table + bool IsExist = false; + for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) + { + if(i->DRGroup != group) + continue; + + IsExist = true; + if(i->hitCount < DIMINISHING_LEVEL_IMMUNE) + i->hitCount += 1; + + break; + } + + if(!IsExist) + m_Diminishing.push_back(DiminishingReturn(group,getMSTime(),DIMINISHING_LEVEL_2)); +} + +void Unit::ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster,DiminishingLevels Level) +{ + if(duration == -1 || group == DIMINISHING_NONE || caster->IsFriendlyTo(this) ) + return; + + // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0) + if(duration > 10000 && IsDiminishingReturnsGroupDurationLimited(group)) + { + // test pet/charm masters instead pets/charmeds + Unit const* targetOwner = GetCharmerOrOwner(); + Unit const* casterOwner = caster->GetCharmerOrOwner(); + + Unit const* target = targetOwner ? targetOwner : this; + Unit const* source = casterOwner ? casterOwner : caster; + + if(target->GetTypeId() == TYPEID_PLAYER && source->GetTypeId() == TYPEID_PLAYER) + duration = 10000; + } + + float mod = 1.0f; + + // Some diminishings applies to mobs too (for example, Stun) + if((GetDiminishingReturnsGroupType(group) == DRTYPE_PLAYER && GetTypeId() == TYPEID_PLAYER) || GetDiminishingReturnsGroupType(group) == DRTYPE_ALL) + { + DiminishingLevels diminish = Level; + switch(diminish) + { + case DIMINISHING_LEVEL_1: break; + case DIMINISHING_LEVEL_2: mod = 0.5f; break; + case DIMINISHING_LEVEL_3: mod = 0.25f; break; + case DIMINISHING_LEVEL_IMMUNE: mod = 0.0f;break; + default: break; + } + } + + duration = int32(duration * mod); +} + +void Unit::ApplyDiminishingAura( DiminishingGroup group, bool apply ) +{ + // Checking for existing in the table + for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) + { + if(i->DRGroup != group) + continue; + + i->hitTime = getMSTime(); + + if(apply) + i->stack += 1; + else if(i->stack) + i->stack -= 1; + + break; + } +} + +Unit* Unit::GetUnit(WorldObject& object, uint64 guid) +{ + return ObjectAccessor::GetUnit(object,guid); +} + +bool Unit::isVisibleForInState( Player const* u, bool inVisibleList ) const +{ + return isVisibleForOrDetect(u,false,inVisibleList); +} + +uint32 Unit::GetCreatureType() const +{ + if(GetTypeId() == TYPEID_PLAYER) + { + SpellShapeshiftEntry const* ssEntry = sSpellShapeshiftStore.LookupEntry(((Player*)this)->m_form); + if(ssEntry && ssEntry->creatureType > 0) + return ssEntry->creatureType; + else + return CREATURE_TYPE_HUMANOID; + } + else + return ((Creature*)this)->GetCreatureInfo()->type; +} + +/*####################################### +######## ######## +######## STAT SYSTEM ######## +######## ######## +#######################################*/ + +bool Unit::HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply) +{ + if(unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) + { + sLog.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!"); + return false; + } + + float val = 1.0f; + + switch(modifierType) + { + case BASE_VALUE: + case TOTAL_VALUE: + m_auraModifiersGroup[unitMod][modifierType] += apply ? amount : -amount; + break; + case BASE_PCT: + case TOTAL_PCT: + if(amount <= -100.0f) //small hack-fix for -100% modifiers + amount = -200.0f; + + val = (100.0f + amount) / 100.0f; + m_auraModifiersGroup[unitMod][modifierType] *= apply ? val : (1.0f/val); + break; + + default: + break; + } + + if(!CanModifyStats()) + return false; + + switch(unitMod) + { + case UNIT_MOD_STAT_STRENGTH: + case UNIT_MOD_STAT_AGILITY: + case UNIT_MOD_STAT_STAMINA: + case UNIT_MOD_STAT_INTELLECT: + case UNIT_MOD_STAT_SPIRIT: UpdateStats(GetStatByAuraGroup(unitMod)); break; + + case UNIT_MOD_ARMOR: UpdateArmor(); break; + case UNIT_MOD_HEALTH: UpdateMaxHealth(); break; + + case UNIT_MOD_MANA: + case UNIT_MOD_RAGE: + case UNIT_MOD_FOCUS: + case UNIT_MOD_ENERGY: + case UNIT_MOD_HAPPINESS: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod)); break; + + case UNIT_MOD_RESISTANCE_HOLY: + case UNIT_MOD_RESISTANCE_FIRE: + case UNIT_MOD_RESISTANCE_NATURE: + case UNIT_MOD_RESISTANCE_FROST: + case UNIT_MOD_RESISTANCE_SHADOW: + case UNIT_MOD_RESISTANCE_ARCANE: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod)); break; + + case UNIT_MOD_ATTACK_POWER: UpdateAttackPowerAndDamage(); break; + case UNIT_MOD_ATTACK_POWER_RANGED: UpdateAttackPowerAndDamage(true); break; + + case UNIT_MOD_DAMAGE_MAINHAND: UpdateDamagePhysical(BASE_ATTACK); break; + case UNIT_MOD_DAMAGE_OFFHAND: UpdateDamagePhysical(OFF_ATTACK); break; + case UNIT_MOD_DAMAGE_RANGED: UpdateDamagePhysical(RANGED_ATTACK); break; + + default: + break; + } + + return true; +} + +float Unit::GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const +{ + if( unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) + { + sLog.outError("ERROR: trial to access non existed modifier value from UnitMods!"); + return 0.0f; + } + + if(modifierType == TOTAL_PCT && m_auraModifiersGroup[unitMod][modifierType] <= 0.0f) + return 0.0f; + + return m_auraModifiersGroup[unitMod][modifierType]; +} + +float Unit::GetTotalStatValue(Stats stat) const +{ + UnitMods unitMod = UnitMods(UNIT_MOD_STAT_START + stat); + + if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) + return 0.0f; + + // value = ((base_value * base_pct) + total_value) * total_pct + float value = m_auraModifiersGroup[unitMod][BASE_VALUE] + GetCreateStat(stat); + value *= m_auraModifiersGroup[unitMod][BASE_PCT]; + value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; + value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; + + return value; +} + +float Unit::GetTotalAuraModValue(UnitMods unitMod) const +{ + if(unitMod >= UNIT_MOD_END) + { + sLog.outError("ERROR: trial to access non existed UnitMods in GetTotalAuraModValue()!"); + return 0.0f; + } + + if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) + return 0.0f; + + float value = m_auraModifiersGroup[unitMod][BASE_VALUE]; + value *= m_auraModifiersGroup[unitMod][BASE_PCT]; + value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; + value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; + + return value; +} + +SpellSchools Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod) const +{ + SpellSchools school = SPELL_SCHOOL_NORMAL; + + switch(unitMod) + { + case UNIT_MOD_RESISTANCE_HOLY: school = SPELL_SCHOOL_HOLY; break; + case UNIT_MOD_RESISTANCE_FIRE: school = SPELL_SCHOOL_FIRE; break; + case UNIT_MOD_RESISTANCE_NATURE: school = SPELL_SCHOOL_NATURE; break; + case UNIT_MOD_RESISTANCE_FROST: school = SPELL_SCHOOL_FROST; break; + case UNIT_MOD_RESISTANCE_SHADOW: school = SPELL_SCHOOL_SHADOW; break; + case UNIT_MOD_RESISTANCE_ARCANE: school = SPELL_SCHOOL_ARCANE; break; + + default: + break; + } + + return school; +} + +Stats Unit::GetStatByAuraGroup(UnitMods unitMod) const +{ + Stats stat = STAT_STRENGTH; + + switch(unitMod) + { + case UNIT_MOD_STAT_STRENGTH: stat = STAT_STRENGTH; break; + case UNIT_MOD_STAT_AGILITY: stat = STAT_AGILITY; break; + case UNIT_MOD_STAT_STAMINA: stat = STAT_STAMINA; break; + case UNIT_MOD_STAT_INTELLECT: stat = STAT_INTELLECT; break; + case UNIT_MOD_STAT_SPIRIT: stat = STAT_SPIRIT; break; + + default: + break; + } + + return stat; +} + +Powers Unit::GetPowerTypeByAuraGroup(UnitMods unitMod) const +{ + Powers power = POWER_MANA; + + switch(unitMod) + { + case UNIT_MOD_MANA: power = POWER_MANA; break; + case UNIT_MOD_RAGE: power = POWER_RAGE; break; + case UNIT_MOD_FOCUS: power = POWER_FOCUS; break; + case UNIT_MOD_ENERGY: power = POWER_ENERGY; break; + case UNIT_MOD_HAPPINESS: power = POWER_HAPPINESS; break; + + default: + break; + } + + return power; +} + +float Unit::GetTotalAttackPowerValue(WeaponAttackType attType) const +{ + UnitMods unitMod = (attType == RANGED_ATTACK) ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER; + + float val = GetTotalAuraModValue(unitMod); + if(val < 0.0f) + val = 0.0f; + + return val; +} + +float Unit::GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const +{ + if (attType == OFF_ATTACK && !haveOffhandWeapon()) + return 0.0f; + + return m_weaponDamage[attType][type]; +} + +void Unit::SetLevel(uint32 lvl) +{ + SetUInt32Value(UNIT_FIELD_LEVEL, lvl); + + // group update + if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL); +} + +void Unit::SetHealth(uint32 val) +{ + uint32 maxHealth = GetMaxHealth(); + if(maxHealth < val) + val = maxHealth; + + SetUInt32Value(UNIT_FIELD_HEALTH, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP); + } + } +} + +void Unit::SetMaxHealth(uint32 val) +{ + uint32 health = GetHealth(); + SetUInt32Value(UNIT_FIELD_MAXHEALTH, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP); + } + } + + if(val < health) + SetHealth(val); +} + +void Unit::SetPower(Powers power, uint32 val) +{ + uint32 maxPower = GetMaxPower(power); + if(maxPower < val) + val = maxPower; + + SetStatInt32Value(UNIT_FIELD_POWER1 + power, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); + } + + // Update the pet's character sheet with happiness damage bonus + if(pet->getPetType() == HUNTER_PET && power == POWER_HAPPINESS) + { + pet->UpdateDamagePhysical(BASE_ATTACK); + } + } +} + +void Unit::SetMaxPower(Powers power, uint32 val) +{ + uint32 cur_power = GetPower(power); + SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + power, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); + } + } + + if(val < cur_power) + SetPower(power, val); +} + +void Unit::ApplyPowerMod(Powers power, uint32 val, bool apply) +{ + ApplyModUInt32Value(UNIT_FIELD_POWER1+power, val, apply); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); + } + } +} + +void Unit::ApplyMaxPowerMod(Powers power, uint32 val, bool apply) +{ + ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1+power, val, apply); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); + } + } +} + +void Unit::ApplyAuraProcTriggerDamage( Aura* aura, bool apply ) +{ + AuraList& tAuraProcTriggerDamage = m_modAuras[SPELL_AURA_PROC_TRIGGER_DAMAGE]; + if(apply) + tAuraProcTriggerDamage.push_back(aura); + else + tAuraProcTriggerDamage.remove(aura); +} + +uint32 Unit::GetCreatePowers( Powers power ) const +{ + // POWER_FOCUS and POWER_HAPPINESS only have hunter pet + switch(power) + { + case POWER_MANA: return GetCreateMana(); + case POWER_RAGE: return 1000; + case POWER_FOCUS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 100); + case POWER_ENERGY: return 100; + case POWER_HAPPINESS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 1050000); + } + + return 0; +} + +void Unit::AddToWorld() +{ + WorldObject::AddToWorld(); +} + +void Unit::RemoveFromWorld() +{ + // cleanup + if(IsInWorld()) + { + RemoveNotOwnSingleTargetAuras(); + } + + WorldObject::RemoveFromWorld(); +} + +void Unit::CleanupsBeforeDelete() +{ + if(m_uint32Values) // only for fully created object + { + InterruptNonMeleeSpells(true); + m_Events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList + CombatStop(); + ClearComboPointHolders(); + DeleteThreatList(); + getHostilRefManager().setOnlineOfflineState(false); + RemoveAllAuras(); + RemoveAllGameObjects(); + RemoveAllDynObjects(); + GetMotionMaster()->Clear(false); // remove different non-standard movement generators. + + UnpossessSelf(false); + RemoveAllFromVision(); + } + RemoveFromWorld(); +} + + + +CharmInfo* Unit::InitCharmInfo(Unit *charm) +{ + if(!m_charmInfo) + m_charmInfo = new CharmInfo(charm); + return m_charmInfo; +} + +CharmInfo::CharmInfo(Unit* unit) +: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0) +{ + for(int i =0; i<4; ++i) + { + m_charmspells[i].spellId = 0; + m_charmspells[i].active = ACT_DISABLED; + } +} + +void CharmInfo::InitPetActionBar() +{ + // the first 3 SpellOrActions are attack, follow and stay + for(uint32 i = 0; i < 3; i++) + { + PetActionBar[i].Type = ACT_COMMAND; + PetActionBar[i].SpellOrAction = COMMAND_ATTACK - i; + + PetActionBar[i + 7].Type = ACT_REACTION; + PetActionBar[i + 7].SpellOrAction = COMMAND_ATTACK - i; + } + for(uint32 i=0; i < 4; i++) + { + PetActionBar[i + 3].Type = ACT_DISABLED; + PetActionBar[i + 3].SpellOrAction = 0; + } +} + +void CharmInfo::InitEmptyActionBar() +{ + for(uint32 x = 1; x < 10; ++x) + { + PetActionBar[x].Type = ACT_CAST; + PetActionBar[x].SpellOrAction = 0; + } + PetActionBar[0].Type = ACT_COMMAND; + PetActionBar[0].SpellOrAction = COMMAND_ATTACK; +} + +void CharmInfo::InitPossessCreateSpells() +{ + InitEmptyActionBar(); + if(m_unit->GetTypeId() == TYPEID_UNIT) + { + for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) + { + uint32 spellid = ((Creature*)m_unit)->m_spells[i]; + if(IsPassiveSpell(spellid)) + m_unit->CastSpell(m_unit, spellid, true); + else + AddSpellToAB(0, spellid, ACT_CAST); + } + } +} + +void CharmInfo::InitCharmCreateSpells() +{ + if(m_unit->GetTypeId() == TYPEID_PLAYER) //charmed players don't have spells + { + InitEmptyActionBar(); + return; + } + + InitPetActionBar(); + + for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) + { + uint32 spellId = ((Creature*)m_unit)->m_spells[x]; + m_charmspells[x].spellId = spellId; + + if(!spellId) + continue; + + if (IsPassiveSpell(spellId)) + { + m_unit->CastSpell(m_unit, spellId, true); + m_charmspells[x].active = ACT_PASSIVE; + } + else + { + ActiveStates newstate; + bool onlyselfcast = true; + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + + if(!spellInfo) onlyselfcast = false; + for(uint32 i = 0;i<3 && onlyselfcast;++i) //non existent spell will not make any problems as onlyselfcast would be false -> break right away + { + if(spellInfo->EffectImplicitTargetA[i] != TARGET_SELF && spellInfo->EffectImplicitTargetA[i] != 0) + onlyselfcast = false; + } + + if(onlyselfcast || !IsPositiveSpell(spellId)) //only self cast and spells versus enemies are autocastable + newstate = ACT_DISABLED; + else + newstate = ACT_CAST; + + AddSpellToAB(0, spellId, newstate); + } + } +} + +bool CharmInfo::AddSpellToAB(uint32 oldid, uint32 newid, ActiveStates newstate) +{ + for(uint8 i = 0; i < 10; i++) + { + if((PetActionBar[i].Type == ACT_DISABLED || PetActionBar[i].Type == ACT_ENABLED || PetActionBar[i].Type == ACT_CAST) && PetActionBar[i].SpellOrAction == oldid) + { + PetActionBar[i].SpellOrAction = newid; + if(!oldid) + { + if(newstate == ACT_DECIDE) + PetActionBar[i].Type = ACT_DISABLED; + else + PetActionBar[i].Type = newstate; + } + + return true; + } + } + return false; +} + +void CharmInfo::ToggleCreatureAutocast(uint32 spellid, bool apply) +{ + if(IsPassiveSpell(spellid)) + return; + + for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) + { + if(spellid == m_charmspells[x].spellId) + { + m_charmspells[x].active = apply ? ACT_ENABLED : ACT_DISABLED; + } + } +} + +void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow) +{ + m_petnumber = petnumber; + if(statwindow) + m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, m_petnumber); + else + m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0); +} + +bool Unit::isFrozen() const +{ + AuraList const& mRoot = GetAurasByType(SPELL_AURA_MOD_ROOT); + for(AuraList::const_iterator i = mRoot.begin(); i != mRoot.end(); ++i) + if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST) + return true; + return false; +} + +struct ProcTriggeredData +{ + ProcTriggeredData(SpellEntry const * _spellInfo, uint32 _spellParam, Aura* _triggeredByAura, uint32 _cooldown) + : spellInfo(_spellInfo), spellParam(_spellParam), triggeredByAura(_triggeredByAura), + triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura->GetId(),triggeredByAura->GetEffIndex())), + cooldown(_cooldown) + {} + + SpellEntry const * spellInfo; + uint32 spellParam; + Aura* triggeredByAura; + Unit::spellEffectPair triggeredByAura_SpellPair; + uint32 cooldown; +}; + +typedef std::list< ProcTriggeredData > ProcTriggeredList; + +void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, AuraTypeSet const& procAuraTypes, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellSchoolMask damageSchoolMask ) +{ + for(AuraTypeSet::const_iterator aur = procAuraTypes.begin(); aur != procAuraTypes.end(); ++aur) + { + // List of spells (effects) that proceed. Spell prototype and aura-specific value (damage for TRIGGER_DAMAGE) + ProcTriggeredList procTriggered; + + AuraList const& auras = GetAurasByType(*aur); + for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) + { + next = i; ++next; + + SpellEntry const *spellProto = (*i)->GetSpellProto(); + if(!spellProto) + continue; + + SpellProcEventEntry const *spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); + if(!spellProcEvent) + { + // used to prevent spam in log about same non-handled spells + static std::set nonHandledSpellProcSet; + + if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) + { + sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); + nonHandledSpellProcSet.insert(spellProto->Id); + } + + // spell.dbc use totally different flags, that only can create problems if used. + continue; + } + + // Check spellProcEvent data requirements + if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) + continue; + + // Check if current equipment allows aura to proc + if(!isVictim && GetTypeId() == TYPEID_PLAYER ) + { + if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) + { + Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); + + if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) + continue; + } + else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) + { + // Check if player is wearing shield + Item *item = ((Player*)this)->GetShield(true); + if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) + continue; + } + } + + float chance = (float)spellProto->procChance; + + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); + + if(!isVictim && spellProcEvent->ppmRate != 0) + { + uint32 WeaponSpeed = GetAttackTime(attType); + chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); + } + + if(roll_chance_f(chance)) + { + uint32 cooldown = spellProcEvent->cooldown; + + uint32 i_spell_eff = (*i)->GetEffIndex(); + + int32 i_spell_param; + switch(*aur) + { + case SPELL_AURA_PROC_TRIGGER_SPELL: + i_spell_param = procFlag; + break; + case SPELL_AURA_DUMMY: + case SPELL_AURA_PRAYER_OF_MENDING: + case SPELL_AURA_MOD_HASTE: + i_spell_param = i_spell_eff; + break; + case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: + i_spell_param = (*i)->GetModifier()->m_miscvalue; + break; + default: + i_spell_param = (*i)->GetModifier()->m_amount; + break; + } + + procTriggered.push_back( ProcTriggeredData(spellProto,i_spell_param,*i, cooldown) ); + } + } + + // Handle effects proceed this time + for(ProcTriggeredList::iterator i = procTriggered.begin(); i != procTriggered.end(); ++i) + { + // Some auras can be deleted in function called in this loop (except first, ofc) + // Until storing auras in std::multimap to hard check deleting by another way + if(i != procTriggered.begin()) + { + bool found = false; + AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); + AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); + for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) + { + if(itr->second==i->triggeredByAura) + { + found = true; + break; + } + } + + if(!found) + { + sLog.outError("Spell aura %u (id:%u effect:%u) has been deleted before call spell proc event handler",*aur,i->triggeredByAura_SpellPair.first,i->triggeredByAura_SpellPair.second); + sLog.outError("It can be deleted one from early processed auras:"); + for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2) + sLog.outError(" Spell aura %u (id:%u effect:%u)",*aur,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second); + sLog.outError(" "); + continue; + } + } + + // save charges existence before processing to prevent crash at access to deleted triggered aura after + bool triggeredByAuraWithCharges = i->triggeredByAura->m_procCharges > 0; + + bool casted = false; + switch(*aur) + { + case SPELL_AURA_PROC_TRIGGER_SPELL: + { + sLog.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleProcTriggerSpell(pTarget, damage, i->triggeredByAura, procSpell,i->spellParam,attType,i->cooldown); + break; + } + case SPELL_AURA_PROC_TRIGGER_DAMAGE: + { + sLog.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", i->spellParam, i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + uint32 damage = i->spellParam; + SpellNonMeleeDamageLog(pTarget, i->spellInfo->Id, damage, true, true); + casted = true; + break; + } + case SPELL_AURA_DUMMY: + { + sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleDummyAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); + break; + } + case SPELL_AURA_PRAYER_OF_MENDING: + { + sLog.outDebug("ProcDamageAndSpell(mending): casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + + // aura can be deleted at casts + int32 heal = i->triggeredByAura->GetModifier()->m_amount; + uint64 caster_guid = i->triggeredByAura->GetCasterGUID(); + + // jumps + int32 jumps = i->triggeredByAura->m_procCharges-1; + + // current aura expire + i->triggeredByAura->m_procCharges = 1; // will removed at next charges decrease + + // next target selection + if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) + { + Aura* aura = i->triggeredByAura; + + SpellEntry const* spellProto = aura->GetSpellProto(); + uint32 effIdx = aura->GetEffIndex(); + + float radius; + if (spellProto->EffectRadiusIndex[effIdx]) + radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); + else + radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); + + if(Player* caster = ((Player*)aura->GetCaster())) + { + caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); + + if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) + { + // aura will applied from caster, but spell casted from current aura holder + SpellModifier *mod = new SpellModifier; + mod->op = SPELLMOD_CHARGES; + mod->value = jumps-5; // negative + mod->type = SPELLMOD_FLAT; + mod->spellId = spellProto->Id; + mod->effectId = effIdx; + mod->lastAffected = NULL; + mod->mask = spellProto->SpellFamilyFlags; + mod->charges = 0; + + caster->AddSpellMod(mod, true); + CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,aura,caster->GetGUID()); + caster->AddSpellMod(mod, false); + } + } + } + + // heal + CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); + casted = true; + break; + } + case SPELL_AURA_MOD_HASTE: + { + sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleHasteAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); + break; + } + case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN: + { + // nothing do, just charges counter + // but count only in case appropriate school damage + casted = i->triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; + break; + } + case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: + { + sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleOverrideClassScriptAuraProc(pTarget, i->spellParam, damage, i->triggeredByAura, procSpell,i->cooldown); + break; + } + default: + { + // nothing do, just charges counter + casted = true; + break; + } + } + + // Update charge (aura can be removed by triggers) + if(casted && triggeredByAuraWithCharges) + { + // need found aura (can be dropped by triggers) + AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); + AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); + for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) + { + if(itr->second == i->triggeredByAura) + { + if(i->triggeredByAura->m_procCharges > 0) + i->triggeredByAura->m_procCharges -= 1; + + i->triggeredByAura->UpdateAuraCharges(); + break; + } + } + } + } + + // Safely remove auras with zero charges + for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) + { + next = i; ++next; + if((*i)->m_procCharges == 0) + { + RemoveAurasDueToSpell((*i)->GetId()); + next = auras.begin(); + } + } + } +} + +SpellSchoolMask Unit::GetMeleeDamageSchoolMask() const +{ + return SPELL_SCHOOL_MASK_NORMAL; +} + +Player* Unit::GetSpellModOwner() +{ + if(GetTypeId()==TYPEID_PLAYER) + return (Player*)this; + if(((Creature*)this)->isPet() || ((Creature*)this)->isTotem()) + { + Unit* owner = GetOwner(); + if(owner && owner->GetTypeId()==TYPEID_PLAYER) + return (Player*)owner; + } + return NULL; +} + +///----------Pet responses methods----------------- +void Unit::SendPetCastFail(uint32 spellid, uint8 msg) +{ + Unit *owner = GetCharmerOrOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_PET_CAST_FAILED, (4+1)); + data << uint32(spellid); + data << uint8(msg); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetActionFeedback (uint8 msg) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_PET_ACTION_FEEDBACK, 1); + data << uint8(msg); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetTalk (uint32 pettalk) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_PET_ACTION_SOUND, 8+4); + data << uint64(GetGUID()); + data << uint32(pettalk); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetSpellCooldown (uint32 spellid, time_t cooltime) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_SPELL_COOLDOWN, 8+1+4+4); + data << uint64(GetGUID()); + data << uint8(0x0); // flags (0x1, 0x2) + data << uint32(spellid); + data << uint32(cooltime); + + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetClearCooldown (uint32 spellid) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_CLEAR_COOLDOWN, (4+8)); + data << uint32(spellid); + data << uint64(GetGUID()); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetAIReaction(uint64 guid) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_AI_REACTION, 12); + data << uint64(guid) << uint32(00000002); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +///----------End of Pet responses methods---------- + +void Unit::StopMoving() +{ + clearUnitState(UNIT_STAT_MOVING); + + // send explicit stop packet + // rely on vmaps here because for example stormwind is in air + float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); + //if (fabs(GetPositionZ() - z) < 2.0f) + // Relocate(GetPositionX(), GetPositionY(), z); + Relocate(GetPositionX(), GetPositionY(),GetPositionZ()); + + SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0); + + // update position and orientation; + WorldPacket data; + BuildHeartBeatMsg(&data); + SendMessageToSet(&data,false); +} + +void Unit::SetFeared(bool apply, uint64 casterGUID, uint32 spellID) +{ + if( apply ) + { + if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING)) + return; + + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); + + GetMotionMaster()->MovementExpired(false); + CastStop(GetGUID()==casterGUID ? spellID : 0); + + Unit* caster = ObjectAccessor::GetUnit(*this,casterGUID); + + GetMotionMaster()->MoveFleeing(caster); // caster==NULL processed in MoveFleeing + } + else + { + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); + + GetMotionMaster()->MovementExpired(false); + + if( GetTypeId() != TYPEID_PLAYER && isAlive() ) + { + // restore appropriate movement generator + if(getVictim()) + GetMotionMaster()->MoveChase(getVictim()); + else + GetMotionMaster()->Initialize(); + + // attack caster if can + Unit* caster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL); + if(caster && caster != getVictim() && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->AttackStart(caster); + } + } + + if (GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->SetClientControl(this, !apply); +} + +void Unit::SetConfused(bool apply, uint64 casterGUID, uint32 spellID) +{ + if( apply ) + { + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); + + CastStop(GetGUID()==casterGUID ? spellID : 0); + + GetMotionMaster()->MoveConfused(); + } + else + { + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); + + GetMotionMaster()->MovementExpired(false); + + if (GetTypeId() == TYPEID_UNIT) + { + // if in combat restore movement generator + if(getVictim()) + GetMotionMaster()->MoveChase(getVictim()); + } + } + + if(GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->SetClientControl(this, !apply); +} + +bool Unit::IsSitState() const +{ + uint8 s = getStandState(); + return s == PLAYER_STATE_SIT_CHAIR || s == PLAYER_STATE_SIT_LOW_CHAIR || + s == PLAYER_STATE_SIT_MEDIUM_CHAIR || s == PLAYER_STATE_SIT_HIGH_CHAIR || + s == PLAYER_STATE_SIT; +} + +bool Unit::IsStandState() const +{ + uint8 s = getStandState(); + return !IsSitState() && s != PLAYER_STATE_SLEEP && s != PLAYER_STATE_KNEEL; +} + +void Unit::SetStandState(uint8 state) +{ + SetByteValue(UNIT_FIELD_BYTES_1, 0, state); + + if (IsStandState()) + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED); + + if(GetTypeId()==TYPEID_PLAYER) + { + WorldPacket data(SMSG_STANDSTATE_UPDATE, 1); + data << (uint8)state; + ((Player*)this)->GetSession()->SendPacket(&data); + } +} + +bool Unit::IsPolymorphed() const +{ + return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH; +} + +void Unit::SetDisplayId(uint32 modelId) +{ + SetUInt32Value(UNIT_FIELD_DISPLAYID, modelId); + + if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(!pet->isControlled()) + return; + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID); + } +} + +void Unit::ClearComboPointHolders() +{ + while(!m_ComboPointHolders.empty()) + { + uint32 lowguid = *m_ComboPointHolders.begin(); + + Player* plr = objmgr.GetPlayer(MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); + if(plr && plr->GetComboTarget()==GetGUID()) // recheck for safe + plr->ClearComboPoints(); // remove also guid from m_ComboPointHolders; + else + m_ComboPointHolders.erase(lowguid); // or remove manually + } +} + +void Unit::ClearAllReactives() +{ + + for(int i=0; i < MAX_REACTIVE; ++i) + m_reactiveTimer[i] = 0; + + if (HasAuraState( AURA_STATE_DEFENSE)) + ModifyAuraState(AURA_STATE_DEFENSE, false); + if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_PARRY)) + ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); + if (HasAuraState( AURA_STATE_CRIT)) + ModifyAuraState(AURA_STATE_CRIT, false); + if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_CRIT_STRIKE) ) + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); + + if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->ClearComboPoints(); +} + +void Unit::UpdateReactives( uint32 p_time ) +{ + for(int i = 0; i < MAX_REACTIVE; ++i) + { + ReactiveType reactive = ReactiveType(i); + + if(!m_reactiveTimer[reactive]) + continue; + + if ( m_reactiveTimer[reactive] <= p_time) + { + m_reactiveTimer[reactive] = 0; + + switch ( reactive ) + { + case REACTIVE_DEFENSE: + if (HasAuraState(AURA_STATE_DEFENSE)) + ModifyAuraState(AURA_STATE_DEFENSE, false); + break; + case REACTIVE_HUNTER_PARRY: + if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_PARRY)) + ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); + break; + case REACTIVE_CRIT: + if (HasAuraState(AURA_STATE_CRIT)) + ModifyAuraState(AURA_STATE_CRIT, false); + break; + case REACTIVE_HUNTER_CRIT: + if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_CRIT_STRIKE) ) + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); + break; + case REACTIVE_OVERPOWER: + if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->ClearComboPoints(); + break; + default: + break; + } + } + else + { + m_reactiveTimer[reactive] -= p_time; + } + } +} + +Unit* Unit::SelectNearbyTarget() const +{ + CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + std::list targets; + + { + Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); + Trinity::UnitListSearcher searcher(targets, u_check); + + TypeContainerVisitor, WorldTypeMapContainer > world_unit_searcher(searcher); + TypeContainerVisitor, GridTypeMapContainer > grid_unit_searcher(searcher); + + CellLock cell_lock(cell, p); + cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); + cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); + } + + // remove current target + if(getVictim()) + targets.remove(getVictim()); + + // remove not LoS targets + for(std::list::iterator tIter = targets.begin(); tIter != targets.end();) + { + if(!IsWithinLOSInMap(*tIter)) + { + std::list::iterator tIter2 = tIter; + ++tIter; + targets.erase(tIter2); + } + else + ++tIter; + } + + // no appropriate targets + if(targets.empty()) + return NULL; + + // select random + uint32 rIdx = urand(0,targets.size()-1); + std::list::const_iterator tcIter = targets.begin(); + for(uint32 i = 0; i < rIdx; ++i) + ++tcIter; + + return *tcIter; +} + +void Unit::ApplyAttackTimePercentMod( WeaponAttackType att,float val, bool apply ) +{ + float remainingTimePct = (float)m_attackTimer[att] / (GetAttackTime(att) * m_modAttackSpeedPct[att]); + if(val > 0) + { + ApplyPercentModFloatVar(m_modAttackSpeedPct[att], val, !apply); + ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val,!apply); + } + else + { + ApplyPercentModFloatVar(m_modAttackSpeedPct[att], -val, apply); + ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,-val,apply); + } + m_attackTimer[att] = uint32(GetAttackTime(att) * m_modAttackSpeedPct[att] * remainingTimePct); +} + +void Unit::ApplyCastTimePercentMod(float val, bool apply ) +{ + if(val > 0) + ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,val,!apply); + else + ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,-val,apply); +} + +uint32 Unit::GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime ) +{ + if (CastingTime > 7000) CastingTime = 7000; + if (CastingTime < 1500) CastingTime = 1500; + + if(damagetype == DOT && !IsChanneledSpell(spellProto)) + CastingTime = 3500; + + int32 overTime = 0; + uint8 effects = 0; + bool DirectDamage = false; + bool AreaEffect = false; + + for ( uint32 i=0; i<3;i++) + { + switch ( spellProto->Effect[i] ) + { + case SPELL_EFFECT_SCHOOL_DAMAGE: + case SPELL_EFFECT_POWER_DRAIN: + case SPELL_EFFECT_HEALTH_LEECH: + case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE: + case SPELL_EFFECT_POWER_BURN: + case SPELL_EFFECT_HEAL: + DirectDamage = true; + break; + case SPELL_EFFECT_APPLY_AURA: + switch ( spellProto->EffectApplyAuraName[i] ) + { + case SPELL_AURA_PERIODIC_DAMAGE: + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_PERIODIC_LEECH: + if ( GetSpellDuration(spellProto) ) + overTime = GetSpellDuration(spellProto); + break; + default: + // -5% per additional effect + ++effects; + break; + } + default: + break; + } + + if(IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetA[i])) || IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetB[i]))) + AreaEffect = true; + } + + // Combined Spells with Both Over Time and Direct Damage + if ( overTime > 0 && CastingTime > 0 && DirectDamage ) + { + // mainly for DoTs which are 3500 here otherwise + uint32 OriginalCastTime = GetSpellCastTime(spellProto); + if (OriginalCastTime > 7000) OriginalCastTime = 7000; + if (OriginalCastTime < 1500) OriginalCastTime = 1500; + // Portion to Over Time + float PtOT = (overTime / 15000.f) / ((overTime / 15000.f) + (OriginalCastTime / 3500.f)); + + if ( damagetype == DOT ) + CastingTime = uint32(CastingTime * PtOT); + else if ( PtOT < 1.0f ) + CastingTime = uint32(CastingTime * (1 - PtOT)); + else + CastingTime = 0; + } + + // Area Effect Spells receive only half of bonus + if ( AreaEffect ) + CastingTime /= 2; + + // -5% of total per any additional effect + for ( uint8 i=0; i 175 ) + { + CastingTime -= 175; + } + else + { + CastingTime = 0; + break; + } + } + + return CastingTime; +} + +void Unit::UpdateAuraForGroup(uint8 slot) +{ + if(GetTypeId() == TYPEID_PLAYER) + { + Player* player = (Player*)this; + if(player->GetGroup()) + { + player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS); + player->SetAuraUpdateMask(slot); + } + } + else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + { + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS); + pet->SetAuraUpdateMask(slot); + } + } + } +} + +float Unit::GetAPMultiplier(WeaponAttackType attType, bool normalized) +{ + if (!normalized || GetTypeId() != TYPEID_PLAYER) + return float(GetAttackTime(attType))/1000.0f; + + Item *Weapon = ((Player*)this)->GetWeaponForAttack(attType); + if (!Weapon) + return 2.4; // fist attack + + switch (Weapon->GetProto()->InventoryType) + { + case INVTYPE_2HWEAPON: + return 3.3; + case INVTYPE_RANGED: + case INVTYPE_RANGEDRIGHT: + case INVTYPE_THROWN: + return 2.8; + case INVTYPE_WEAPON: + case INVTYPE_WEAPONMAINHAND: + case INVTYPE_WEAPONOFFHAND: + default: + return Weapon->GetProto()->SubClass==ITEM_SUBCLASS_WEAPON_DAGGER ? 1.7 : 2.4; + } +} + +Aura* Unit::GetDummyAura( uint32 spell_id ) const +{ + Unit::AuraList const& mDummy = GetAurasByType(SPELL_AURA_DUMMY); + for(Unit::AuraList::const_iterator itr = mDummy.begin(); itr != mDummy.end(); ++itr) + if ((*itr)->GetId() == spell_id) + return *itr; + + return NULL; +} + +bool Unit::IsUnderLastManaUseEffect() const +{ + return getMSTimeDiff(m_lastManaUse,getMSTime()) < 5000; +} + +void Unit::SetContestedPvP(Player *attackedPlayer) +{ + Player* player = GetCharmerOrOwnerPlayerOrPlayerItself(); + + if(!player || attackedPlayer && (attackedPlayer == player || player->duel && player->duel->opponent == attackedPlayer)) + return; + + player->SetContestedPvPTimer(30000); + if(!player->hasUnitState(UNIT_STAT_ATTACK_PLAYER)) + { + player->addUnitState(UNIT_STAT_ATTACK_PLAYER); + player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP); + // call MoveInLineOfSight for nearby contested guards + SetVisibility(GetVisibility()); + } + if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER)) + { + addUnitState(UNIT_STAT_ATTACK_PLAYER); + // call MoveInLineOfSight for nearby contested guards + SetVisibility(GetVisibility()); + } +} + +void Unit::AddPetAura(PetAura const* petSpell) +{ + m_petAuras.insert(petSpell); + if(Pet* pet = GetPet()) + pet->CastPetAura(petSpell); +} + +void Unit::RemovePetAura(PetAura const* petSpell) +{ + m_petAuras.erase(petSpell); + if(Pet* pet = GetPet()) + pet->RemoveAurasDueToSpell(petSpell->GetAura(pet->GetEntry())); +} + +Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id) +{ + Pet* pet = new Pet(HUNTER_PET); + + if(!pet->CreateBaseAtCreature(creatureTarget)) + { + delete pet; + return NULL; + } + + pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, this->GetGUID()); + pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, this->GetGUID()); + pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,this->getFaction()); + pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id); + + if(!pet->InitStatsForLevel(creatureTarget->getLevel())) + { + sLog.outError("ERROR: Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget->GetEntry()); + delete pet; + return NULL; + } + + pet->GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true); + // this enables pet details window (Shift+P) + pet->AIM_Initialize(); + pet->InitPetCreateSpells(); + pet->SetHealth(pet->GetMaxHealth()); + + return pet; +} diff --git a/win/TrinityCore&Script VC80.sln b/win/TrinityCore&Script VC80.sln index e5f59ada33c..8431a55fb65 100644 --- a/win/TrinityCore&Script VC80.sln +++ b/win/TrinityCore&Script VC80.sln @@ -1,151 +1,151 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC80\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC80\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" - ProjectSection(ProjectDependencies) = postProject - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} - {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} - {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC80\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC80\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC80\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC80\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC80\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC80\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" - ProjectSection(ProjectDependencies) = postProject - {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC80\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityScript", "..\src\bindings\scripts\VC80\80ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" - ProjectSection(ProjectDependencies) = postProject - {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWrappers", "VC80\ACE_vc8.vcproj", "{AD537C9A-FECA-1BAD-6757-8A6348EA12C8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC80\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC80\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" + ProjectSection(ProjectDependencies) = postProject + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} + {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} + {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC80\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC80\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC80\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC80\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC80\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC80\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" + ProjectSection(ProjectDependencies) = postProject + {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC80\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityScript", "..\src\bindings\scripts\VC80\80ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" + ProjectSection(ProjectDependencies) = postProject + {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWrappers", "VC80\ACE_vc8.vcproj", "{AD537C9A-FECA-1BAD-6757-8A6348EA12C8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection +EndGlobal diff --git a/win/TrinityCore&Script VC90.sln b/win/TrinityCore&Script VC90.sln index f320ab3f99f..2e749c005c1 100644 --- a/win/TrinityCore&Script VC90.sln +++ b/win/TrinityCore&Script VC90.sln @@ -1,151 +1,151 @@ -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC90\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC90\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" - ProjectSection(ProjectDependencies) = postProject - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} - {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} - {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC90\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC90\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC90\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC90\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC90\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC90\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" - ProjectSection(ProjectDependencies) = postProject - {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC90\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ScriptsFull", "..\src\bindings\scripts\VC90\90ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" - ProjectSection(ProjectDependencies) = postProject - {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWraper", "VC90\ACE_vc9.vcproj", "{BD537C9A-FECA-1BAD-6757-8A6348EA12C8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC90\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC90\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" + ProjectSection(ProjectDependencies) = postProject + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} + {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} + {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC90\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC90\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC90\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC90\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC90\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC90\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" + ProjectSection(ProjectDependencies) = postProject + {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC90\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ScriptsFull", "..\src\bindings\scripts\VC90\90ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" + ProjectSection(ProjectDependencies) = postProject + {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWraper", "VC90\ACE_vc9.vcproj", "{BD537C9A-FECA-1BAD-6757-8A6348EA12C8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection +EndGlobal -- cgit v1.2.3 From f3c48aa831487031dc25d1ae68be4fd45e880489 Mon Sep 17 00:00:00 2001 From: KingPin Date: Mon, 17 Nov 2008 22:07:21 -0600 Subject: Backed out changeset 835660b317dc --HG-- branch : trunk --- src/game/Pet.cpp | 3554 ++++--- src/game/Pet.h | 528 +- src/game/SharedDefines.h | 2 +- src/game/SpellMgr.cpp | 4197 ++++---- src/game/SpellMgr.h | 1797 ++-- src/game/Unit.cpp | 21657 +++++++++++++++++++------------------- win/TrinityCore&Script VC80.sln | 302 +- win/TrinityCore&Script VC90.sln | 302 +- 8 files changed, 16160 insertions(+), 16179 deletions(-) (limited to 'src') diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index e9082221450..9bf67fae2c1 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -1,1781 +1,1773 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "Common.h" -#include "Database/DatabaseEnv.h" -#include "Log.h" -#include "WorldSession.h" -#include "WorldPacket.h" -#include "ObjectMgr.h" -#include "SpellMgr.h" -#include "Pet.h" -#include "MapManager.h" -#include "Formulas.h" -#include "SpellAuras.h" -#include "CreatureAI.h" -#include "Unit.h" -#include "Util.h" - -char const* petTypeSuffix[MAX_PET_TYPE] = -{ - "'s Minion", // SUMMON_PET - "'s Pet", // HUNTER_PET - "'s Guardian", // GUARDIAN_PET - "'s Companion" // MINI_PET -}; - -//numbers represent minutes * 100 while happy (you get 100 loyalty points per min while happy) -uint32 const LevelUpLoyalty[6] = -{ - 5500, - 11500, - 17000, - 23500, - 31000, - 39500, -}; - -uint32 const LevelStartLoyalty[6] = -{ - 2000, - 4500, - 7000, - 10000, - 13500, - 17500, -}; - -Pet::Pet(PetType type) : Creature() -{ - m_isPet = true; - m_name = "Pet"; - m_petType = type; - - m_removed = false; - m_regenTimer = 4000; - m_happinessTimer = 7500; - m_loyaltyTimer = 12000; - m_duration = 0; - m_bonusdamage = 0; - - m_loyaltyPoints = 0; - m_TrainingPoints = 0; - m_resetTalentsCost = 0; - m_resetTalentsTime = 0; - - m_auraUpdateMask = 0; - - // pets always have a charminfo, even if they are not actually charmed - CharmInfo* charmInfo = InitCharmInfo(this); - - if(type == MINI_PET) // always passive - charmInfo->SetReactState(REACT_PASSIVE); - else if(type == GUARDIAN_PET) // always aggressive - charmInfo->SetReactState(REACT_AGGRESSIVE); - - m_spells.clear(); - m_Auras.clear(); - m_CreatureSpellCooldowns.clear(); - m_CreatureCategoryCooldowns.clear(); - m_autospells.clear(); - m_declinedname = NULL; - m_isActive = true; -} - -Pet::~Pet() -{ - if(m_uint32Values) // only for fully created Object - { - for (PetSpellMap::iterator i = m_spells.begin(); i != m_spells.end(); ++i) - delete i->second; - ObjectAccessor::Instance().RemoveObject(this); - } - - delete m_declinedname; -} - -void Pet::AddToWorld() -{ - ///- Register the pet for guid lookup - if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); - Unit::AddToWorld(); -} - -void Pet::RemoveFromWorld() -{ - ///- Remove the pet from the accessor - if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); - ///- Don't call the function for Creature, normal mobs + totems go in a different storage - Unit::RemoveFromWorld(); -} - -bool Pet::LoadPetFromDB( Unit* owner, uint32 petentry, uint32 petnumber, bool current ) -{ - uint32 ownerid = owner->GetGUIDLow(); - - QueryResult *result; - - if(petnumber) - // known petnumber entry 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND id = '%u'",ownerid, petnumber); - else if(current) - // current pet (slot 0) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND slot = '0'",ownerid ); - else if(petentry) - // known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets) - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND entry = '%u' AND (slot = '0' OR slot = '3') ",ownerid, petentry ); - else - // any current or other non-stabled pet (for hunter "call pet") - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 - result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3') ",ownerid); - - if(!result) - return false; - - Field *fields = result->Fetch(); - - // update for case of current pet "slot = 0" - petentry = fields[1].GetUInt32(); - if(!petentry) - { - delete result; - return false; - } - - uint32 summon_spell_id = fields[21].GetUInt32(); - SpellEntry const* spellInfo = sSpellStore.LookupEntry(summon_spell_id); - - bool is_temporary_summoned = spellInfo && GetSpellDuration(spellInfo) > 0; - - // check temporary summoned pets like mage water elemental - if(current && is_temporary_summoned) - { - delete result; - return false; - } - - Map *map = owner->GetMap(); - uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); - uint32 pet_number = fields[0].GetUInt32(); - if(!Create(guid, map, petentry, pet_number)) - { - delete result; - return false; - } - - float px, py, pz; - owner->GetClosePoint(px, py, pz,GetObjectSize(),PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); - - Relocate(px, py, pz, owner->GetOrientation()); - - if(!IsPositionValid()) - { - sLog.outError("ERROR: Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)", - GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); - delete result; - return false; - } - - setPetType(PetType(fields[22].GetUInt8())); - SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction()); - SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id); - - CreatureInfo const *cinfo = GetCreatureInfo(); - if(cinfo->type == CREATURE_TYPE_CRITTER) - { - AIM_Initialize(); - map->Add((Creature*)this); - delete result; - return true; - } - if(getPetType()==HUNTER_PET || (getPetType()==SUMMON_PET && cinfo->type == CREATURE_TYPE_DEMON && owner->getClass() == CLASS_WARLOCK)) - m_charmInfo->SetPetNumber(pet_number, true); - else - m_charmInfo->SetPetNumber(pet_number, false); - SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID()); - SetDisplayId(fields[3].GetUInt32()); - SetNativeDisplayId(fields[3].GetUInt32()); - uint32 petlevel=fields[4].GetUInt32(); - SetUInt32Value(UNIT_NPC_FLAGS , 0); - SetName(fields[11].GetString()); - - switch(getPetType()) - { - - case SUMMON_PET: - petlevel=owner->getLevel(); - - SetUInt32Value(UNIT_FIELD_BYTES_0,2048); - SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - // this enables popup window (pet dismiss, cancel) - break; - case HUNTER_PET: - SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); - SetByteValue(UNIT_FIELD_BYTES_1, 1, fields[8].GetUInt32()); - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); - SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); - - if(fields[12].GetBool()) - SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED); - else - SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); - - SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - // this enables popup window (pet abandon, cancel) - SetTP(fields[9].GetInt32()); - SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - SetPower( POWER_HAPPINESS,fields[15].GetUInt32()); - setPowerType(POWER_FOCUS); - break; - default: - sLog.outError("Pet have incorrect type (%u) for pet loading.",getPetType()); - } - InitStatsForLevel( petlevel); - SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32()); - SetUInt64Value(UNIT_FIELD_CREATEDBY, owner->GetGUID()); - - m_charmInfo->SetReactState( ReactStates( fields[6].GetUInt8() )); - m_loyaltyPoints = fields[7].GetInt32(); - - uint32 savedhealth = fields[13].GetUInt32(); - uint32 savedmana = fields[14].GetUInt32(); - - // set current pet as current - if(fields[10].GetUInt32() != 0) - { - CharacterDatabase.BeginTransaction(); - CharacterDatabase.PExecute("UPDATE character_pet SET slot = '3' WHERE owner = '%u' AND slot = '0' AND id <> '%u'",ownerid, m_charmInfo->GetPetNumber()); - CharacterDatabase.PExecute("UPDATE character_pet SET slot = '0' WHERE owner = '%u' AND id = '%u'",ownerid, m_charmInfo->GetPetNumber()); - CharacterDatabase.CommitTransaction(); - } - - if(!is_temporary_summoned) - { - // permanent controlled pets store state in DB - Tokens tokens = StrSplit(fields[16].GetString(), " "); - - if(tokens.size() != 20) - { - delete result; - return false; - } - - int index; - Tokens::iterator iter; - for(iter = tokens.begin(), index = 0; index < 10; ++iter, ++index ) - { - m_charmInfo->GetActionBarEntry(index)->Type = atol((*iter).c_str()); - ++iter; - m_charmInfo->GetActionBarEntry(index)->SpellOrAction = atol((*iter).c_str()); - // patch for old data where some spells have ACT_DECIDE but should have ACT_CAST - // so overwrite old state - SpellEntry const *spellInfo = sSpellStore.LookupEntry(m_charmInfo->GetActionBarEntry(index)->SpellOrAction); - if (spellInfo && spellInfo->AttributesEx & SPELL_ATTR_EX_PET_NOT_AUTOCAST) - m_charmInfo->GetActionBarEntry(index)->Type = ACT_CAST; - } - - //init teach spells - tokens = StrSplit(fields[17].GetString(), " "); - for (iter = tokens.begin(), index = 0; index < 4; ++iter, ++index) - { - uint32 tmp = atol((*iter).c_str()); - - ++iter; - - if(tmp) - AddTeachSpell(tmp, atol((*iter).c_str())); - else - break; - } - } - - // since last save (in seconds) - uint32 timediff = (time(NULL) - fields[18].GetUInt32()); - - delete result; - - //load spells/cooldowns/auras - SetCanModifyStats(true); - _LoadAuras(timediff); - - //init AB - if(is_temporary_summoned) - { - // Temporary summoned pets always have initial spell list at load - InitPetCreateSpells(); - } - else - { - LearnPetPassives(); - CastPetAuras(current); - } - - if(getPetType() == SUMMON_PET && !current) //all (?) summon pets come with full health when called, but not when they are current - { - SetHealth(GetMaxHealth()); - SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); - } - else - { - SetHealth(savedhealth > GetMaxHealth() ? GetMaxHealth() : savedhealth); - SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana); - } - - AIM_Initialize(); - map->Add((Creature*)this); - - // Spells should be loaded after pet is added to map, because in CanCast is check on it - _LoadSpells(); - _LoadSpellCooldowns(); - - owner->SetPet(this); // in DB stored only full controlled creature - sLog.outDebug("New Pet has guid %u", GetGUIDLow()); - - if(owner->GetTypeId() == TYPEID_PLAYER) - { - ((Player*)owner)->PetSpellInitialize(); - if(((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_PET); - } - - if(owner->GetTypeId() == TYPEID_PLAYER && getPetType() == HUNTER_PET) - { - result = CharacterDatabase.PQuery("SELECT genitive, dative, accusative, instrumental, prepositional FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'",owner->GetGUIDLow(),GetCharmInfo()->GetPetNumber()); - - if(result) - { - if(m_declinedname) - delete m_declinedname; - - m_declinedname = new DeclinedName; - Field *fields = result->Fetch(); - for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) - { - m_declinedname->name[i] = fields[i].GetCppString(); - } - } - } - - return true; -} - -void Pet::SavePetToDB(PetSaveMode mode) -{ - if(!GetEntry()) - return; - - // save only fully controlled creature - if(!isControlled()) - return; - - uint32 curhealth = GetHealth(); - uint32 curmana = GetPower(POWER_MANA); - - switch(mode) - { - case PET_SAVE_IN_STABLE_SLOT_1: - case PET_SAVE_IN_STABLE_SLOT_2: - case PET_SAVE_NOT_IN_SLOT: - { - RemoveAllAuras(); - - //only alive hunter pets get auras saved, the others don't - if(!(getPetType() == HUNTER_PET && isAlive())) - m_Auras.clear(); - } - default: - break; - } - - _SaveSpells(); - _SaveSpellCooldowns(); - _SaveAuras(); - - switch(mode) - { - case PET_SAVE_AS_CURRENT: - case PET_SAVE_IN_STABLE_SLOT_1: - case PET_SAVE_IN_STABLE_SLOT_2: - case PET_SAVE_NOT_IN_SLOT: - { - uint32 loyalty =1; - if(getPetType()!=HUNTER_PET) - loyalty = GetLoyaltyLevel(); - - uint32 owner = GUID_LOPART(GetOwnerGUID()); - std::string name = m_name; - CharacterDatabase.escape_string(name); - CharacterDatabase.BeginTransaction(); - // remove current data - CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND id = '%u'", owner,m_charmInfo->GetPetNumber() ); - - // prevent duplicate using slot (except PET_SAVE_NOT_IN_SLOT) - if(mode!=PET_SAVE_NOT_IN_SLOT) - CharacterDatabase.PExecute("UPDATE character_pet SET slot = 3 WHERE owner = '%u' AND slot = '%u'", owner, uint32(mode) ); - - // prevent existence another hunter pet in PET_SAVE_AS_CURRENT and PET_SAVE_NOT_IN_SLOT - if(getPetType()==HUNTER_PET && (mode==PET_SAVE_AS_CURRENT||mode==PET_SAVE_NOT_IN_SLOT)) - CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3')", owner ); - // save pet - std::ostringstream ss; - ss << "INSERT INTO character_pet ( id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata,TeachSpelldata,savetime,resettalents_cost,resettalents_time,CreatedBySpell,PetType) " - << "VALUES (" - << m_charmInfo->GetPetNumber() << ", " - << GetEntry() << ", " - << owner << ", " - << GetNativeDisplayId() << ", " - << getLevel() << ", " - << GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ", " - << uint32(m_charmInfo->GetReactState()) << ", " - << m_loyaltyPoints << ", " - << GetLoyaltyLevel() << ", " - << m_TrainingPoints << ", " - << uint32(mode) << ", '" - << name.c_str() << "', " - << uint32((GetByteValue(UNIT_FIELD_BYTES_2, 2) == UNIT_RENAME_ALLOWED)?0:1) << ", " - << (curhealth<1?1:curhealth) << ", " - << curmana << ", " - << GetPower(POWER_HAPPINESS) << ", '"; - - for(uint32 i = 0; i < 10; i++) - ss << uint32(m_charmInfo->GetActionBarEntry(i)->Type) << " " << uint32(m_charmInfo->GetActionBarEntry(i)->SpellOrAction) << " "; - ss << "', '"; - - //save spells the pet can teach to it's Master - { - int i = 0; - for(TeachSpellMap::iterator itr = m_teachspells.begin(); i < 4 && itr != m_teachspells.end(); ++i, ++itr) - ss << itr->first << " " << itr->second << " "; - for(; i < 4; ++i) - ss << uint32(0) << " " << uint32(0) << " "; - } - - ss << "', " - << time(NULL) << ", " - << uint32(m_resetTalentsCost) << ", " - << uint64(m_resetTalentsTime) << ", " - << GetUInt32Value(UNIT_CREATED_BY_SPELL) << ", " - << uint32(getPetType()) << ")"; - - CharacterDatabase.Execute( ss.str().c_str() ); - - CharacterDatabase.CommitTransaction(); - break; - } - case PET_SAVE_AS_DELETED: - { - RemoveAllAuras(); - uint32 owner = GUID_LOPART(GetOwnerGUID()); - DeleteFromDB(m_charmInfo->GetPetNumber()); - break; - } - default: - sLog.outError("Unknown pet save/remove mode: %d",mode); - } -} - -void Pet::DeleteFromDB(uint32 guidlow) -{ - CharacterDatabase.PExecute("DELETE FROM character_pet WHERE id = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE id = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u'", guidlow); - CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", guidlow); -} - -void Pet::setDeathState(DeathState s) // overwrite virtual Creature::setDeathState and Unit::setDeathState -{ - Creature::setDeathState(s); - if(getDeathState()==CORPSE) - { - //remove summoned pet (no corpse) - if(getPetType()==SUMMON_PET) - Remove(PET_SAVE_NOT_IN_SLOT); - // other will despawn at corpse desppawning (Pet::Update code) - else - { - // pet corpse non lootable and non skinnable - SetUInt32Value( UNIT_DYNAMIC_FLAGS, 0x00 ); - RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); - - //lose happiness when died and not in BG/Arena - MapEntry const* mapEntry = sMapStore.LookupEntry(GetMapId()); - if(!mapEntry || (mapEntry->map_type != MAP_ARENA && mapEntry->map_type != MAP_BATTLEGROUND)) - ModifyPower(POWER_HAPPINESS, -HAPPINESS_LEVEL_SIZE); - - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); - } - } - else if(getDeathState()==ALIVE) - { - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); - CastPetAuras(true); - } -} - -void Pet::Update(uint32 diff) -{ - if(m_removed) // pet already removed, just wait in remove queue, no updates - return; - - switch( m_deathState ) - { - case CORPSE: - { - if( m_deathTimer <= diff ) - { - assert(getPetType()!=SUMMON_PET && "Must be already removed."); - Remove(PET_SAVE_NOT_IN_SLOT); //hunters' pets never get removed because of death, NEVER! - return; - } - break; - } - case ALIVE: - { - // unsummon pet that lost owner - Unit* owner = GetOwner(); - if(!owner || (!IsWithinDistInMap(owner, OWNER_MAX_DISTANCE) && !isPossessed()) || isControlled() && !owner->GetPetGUID()) - { - Remove(PET_SAVE_NOT_IN_SLOT, true); - return; - } - - if(isControlled()) - { - if( owner->GetPetGUID() != GetGUID() ) - { - Remove(getPetType()==HUNTER_PET?PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); - return; - } - } - - if(m_duration > 0) - { - if(m_duration > diff) - m_duration -= diff; - else - { - Remove(getPetType() != SUMMON_PET ? PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); - return; - } - } - - if(getPetType() != HUNTER_PET) - break; - - //regenerate Focus - if(m_regenTimer <= diff) - { - RegenerateFocus(); - m_regenTimer = 4000; - } - else - m_regenTimer -= diff; - - if(m_happinessTimer <= diff) - { - LooseHappiness(); - m_happinessTimer = 7500; - } - else - m_happinessTimer -= diff; - - if(m_loyaltyTimer <= diff) - { - TickLoyaltyChange(); - m_loyaltyTimer = 12000; - } - else - m_loyaltyTimer -= diff; - - break; - } - default: - break; - } - Creature::Update(diff); -} - -void Pet::RegenerateFocus() -{ - uint32 curValue = GetPower(POWER_FOCUS); - uint32 maxValue = GetMaxPower(POWER_FOCUS); - - if (curValue >= maxValue) - return; - - float addvalue = 24 * sWorld.getRate(RATE_POWER_FOCUS); - - AuraList const& ModPowerRegenPCTAuras = GetAurasByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT); - for(AuraList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) - if ((*i)->GetModifier()->m_miscvalue == POWER_FOCUS) - addvalue *= ((*i)->GetModifier()->m_amount + 100) / 100.0f; - - ModifyPower(POWER_FOCUS, (int32)addvalue); -} - -void Pet::LooseHappiness() -{ - uint32 curValue = GetPower(POWER_HAPPINESS); - if (curValue <= 0) - return; - int32 addvalue = (140 >> GetLoyaltyLevel()) * 125; //value is 70/35/17/8/4 (per min) * 1000 / 8 (timer 7.5 secs) - if(isInCombat()) //we know in combat happiness fades faster, multiplier guess - addvalue = int32(addvalue * 1.5); - ModifyPower(POWER_HAPPINESS, -addvalue); -} - -void Pet::ModifyLoyalty(int32 addvalue) -{ - uint32 loyaltylevel = GetLoyaltyLevel(); - - if(addvalue > 0) //only gain influenced, not loss - addvalue = int32((float)addvalue * sWorld.getRate(RATE_LOYALTY)); - - if(loyaltylevel >= BEST_FRIEND && (addvalue + m_loyaltyPoints) > int32(GetMaxLoyaltyPoints(loyaltylevel))) - return; - - m_loyaltyPoints += addvalue; - - if(m_loyaltyPoints < 0) - { - if(loyaltylevel > REBELLIOUS) - { - //level down - --loyaltylevel; - SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); - m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); - SetTP(m_TrainingPoints - int32(getLevel())); - } - else - { - m_loyaltyPoints = 0; - Unit* owner = GetOwner(); - if(owner && owner->GetTypeId() == TYPEID_PLAYER) - { - WorldPacket data(SMSG_PET_BROKEN, 0); - ((Player*)owner)->GetSession()->SendPacket(&data); - - //run away - ((Player*)owner)->RemovePet(this,PET_SAVE_AS_DELETED); - } - } - } - //level up - else if(m_loyaltyPoints > int32(GetMaxLoyaltyPoints(loyaltylevel))) - { - ++loyaltylevel; - SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); - m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); - SetTP(m_TrainingPoints + getLevel()); - } -} - -void Pet::TickLoyaltyChange() -{ - int32 addvalue; - - switch(GetHappinessState()) - { - case HAPPY: addvalue = 20; break; - case CONTENT: addvalue = 10; break; - case UNHAPPY: addvalue = -20; break; - default: - return; - } - ModifyLoyalty(addvalue); -} - -void Pet::KillLoyaltyBonus(uint32 level) -{ - if(level > 100) - return; - - //at lower levels gain is faster | the lower loyalty the more loyalty is gained - uint32 bonus = uint32(((100 - level) / 10) + (6 - GetLoyaltyLevel())); - ModifyLoyalty(bonus); -} - -HappinessState Pet::GetHappinessState() -{ - if(GetPower(POWER_HAPPINESS) < HAPPINESS_LEVEL_SIZE) - return UNHAPPY; - else if(GetPower(POWER_HAPPINESS) >= HAPPINESS_LEVEL_SIZE * 2) - return HAPPY; - else - return CONTENT; -} - -void Pet::SetLoyaltyLevel(LoyaltyLevel level) -{ - SetByteValue(UNIT_FIELD_BYTES_1, 1, level); -} - -bool Pet::CanTakeMoreActiveSpells(uint32 spellid) -{ - uint8 activecount = 1; - uint32 chainstartstore[ACTIVE_SPELLS_MAX]; - - if(IsPassiveSpell(spellid)) - return true; - - chainstartstore[0] = spellmgr.GetFirstSpellInChain(spellid); - - for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) - { - if(IsPassiveSpell(itr->first)) - continue; - - uint32 chainstart = spellmgr.GetFirstSpellInChain(itr->first); - - uint8 x; - - for(x = 0; x < activecount; x++) - { - if(chainstart == chainstartstore[x]) - break; - } - - if(x == activecount) //spellchain not yet saved -> add active count - { - ++activecount; - if(activecount > ACTIVE_SPELLS_MAX) - return false; - chainstartstore[x] = chainstart; - } - } - return true; -} - -bool Pet::HasTPForSpell(uint32 spellid) -{ - int32 neededtrainp = GetTPForSpell(spellid); - if((m_TrainingPoints - neededtrainp < 0 || neededtrainp < 0) && neededtrainp != 0) - return false; - return true; -} - -int32 Pet::GetTPForSpell(uint32 spellid) -{ - uint32 basetrainp = 0; - - SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellid); - SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellid); - for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) - { - if(!_spell_idx->second->reqtrainpoints) - return 0; - - basetrainp = _spell_idx->second->reqtrainpoints; - break; - } - - uint32 spenttrainp = 0; - uint32 chainstart = spellmgr.GetFirstSpellInChain(spellid); - - for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) - { - if(itr->second->state == PETSPELL_REMOVED) - continue; - - if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) - { - SkillLineAbilityMap::const_iterator _lower = spellmgr.GetBeginSkillLineAbilityMap(itr->first); - SkillLineAbilityMap::const_iterator _upper = spellmgr.GetEndSkillLineAbilityMap(itr->first); - - for(SkillLineAbilityMap::const_iterator _spell_idx2 = _lower; _spell_idx2 != _upper; ++_spell_idx2) - { - if(_spell_idx2->second->reqtrainpoints > spenttrainp) - { - spenttrainp = _spell_idx2->second->reqtrainpoints; - break; - } - } - } - } - - return int32(basetrainp) - int32(spenttrainp); -} - -uint32 Pet::GetMaxLoyaltyPoints(uint32 level) -{ - return LevelUpLoyalty[level - 1]; -} - -uint32 Pet::GetStartLoyaltyPoints(uint32 level) -{ - return LevelStartLoyalty[level - 1]; -} - -void Pet::SetTP(int32 TP) -{ - m_TrainingPoints = TP; - SetUInt32Value(UNIT_TRAINING_POINTS, (uint32)GetDispTP()); -} - -int32 Pet::GetDispTP() -{ - if(getPetType()!= HUNTER_PET) - return(0); - if(m_TrainingPoints < 0) - return -m_TrainingPoints; - else - return -(m_TrainingPoints + 1); -} - -void Pet::Remove(PetSaveMode mode, bool returnreagent) -{ - Unit* owner = GetOwner(); - - if(owner) - { - if(owner->GetTypeId()==TYPEID_PLAYER) - { - ((Player*)owner)->RemovePet(this,mode,returnreagent); - return; - } - - // only if current pet in slot - if(owner->GetPetGUID()==GetGUID()) - owner->SetPet(0); - } - - CleanupsBeforeDelete(); - AddObjectToRemoveList(); - m_removed = true; -} - -void Pet::GivePetXP(uint32 xp) -{ - if(getPetType() != HUNTER_PET) - return; - - if ( xp < 1 ) - return; - - if(!isAlive()) - return; - - uint32 level = getLevel(); - - // XP to money conversion processed in Player::RewardQuest - if(level >= sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) - return; - - uint32 curXP = GetUInt32Value(UNIT_FIELD_PETEXPERIENCE); - uint32 nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); - uint32 newXP = curXP + xp; - - if(newXP >= nextLvlXP && level+1 > GetOwner()->getLevel()) - { - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, nextLvlXP-1); - return; - } - - while( newXP >= nextLvlXP && level < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL) ) - { - newXP -= nextLvlXP; - - SetLevel( level + 1 ); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(level+1))/4)); - - level = getLevel(); - nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); - GivePetLevel(level); - } - - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, newXP); - - if(getPetType() == HUNTER_PET) - KillLoyaltyBonus(level); -} - -void Pet::GivePetLevel(uint32 level) -{ - if(!level) - return; - - InitStatsForLevel( level); - - SetTP(m_TrainingPoints + (GetLoyaltyLevel() - 1)); -} - -bool Pet::CreateBaseAtCreature(Creature* creature) -{ - if(!creature) - { - sLog.outError("CRITICAL ERROR: NULL pointer parsed into CreateBaseAtCreature()"); - return false; - } - uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); - - sLog.outBasic("SetInstanceID()"); - SetInstanceId(creature->GetInstanceId()); - - sLog.outBasic("Create pet"); - uint32 pet_number = objmgr.GeneratePetNumber(); - if(!Create(guid, creature->GetMap(), creature->GetEntry(), pet_number)) - return false; - - Relocate(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); - - if(!IsPositionValid()) - { - sLog.outError("ERROR: Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)", - GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); - return false; - } - - CreatureInfo const *cinfo = GetCreatureInfo(); - if(!cinfo) - { - sLog.outError("ERROR: CreateBaseAtCreature() failed, creatureInfo is missing!"); - return false; - } - - if(cinfo->type == CREATURE_TYPE_CRITTER) - { - setPetType(MINI_PET); - return true; - } - SetDisplayId(creature->GetDisplayId()); - SetNativeDisplayId(creature->GetNativeDisplayId()); - SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - SetPower( POWER_HAPPINESS,166500); - setPowerType(POWER_FOCUS); - SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,0); - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(creature->getLevel()))/4)); - SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); - SetUInt32Value(UNIT_NPC_FLAGS , 0); - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(creature->GetCreatureInfo()->family); - if( char* familyname = cFamily->Name[sWorld.GetDefaultDbcLocale()] ) - SetName(familyname); - else - SetName(creature->GetName()); - - m_loyaltyPoints = 1000; - if(cinfo->type == CREATURE_TYPE_BEAST) - { - SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); - SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); - SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); - - SetUInt32Value(UNIT_MOD_CAST_SPEED, creature->GetUInt32Value(UNIT_MOD_CAST_SPEED) ); - SetLoyaltyLevel(REBELLIOUS); - } - return true; -} - -bool Pet::InitStatsForLevel(uint32 petlevel) -{ - CreatureInfo const *cinfo = GetCreatureInfo(); - assert(cinfo); - - Unit* owner = GetOwner(); - if(!owner) - { - sLog.outError("ERROR: attempt to summon pet (Entry %u) without owner! Attempt terminated.", cinfo->Entry); - return false; - } - - uint32 creature_ID = (getPetType() == HUNTER_PET) ? 1 : cinfo->Entry; - - SetLevel( petlevel); - - SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool)); - - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(petlevel*50)); - - SetAttackTime(BASE_ATTACK, BASE_ATTACK_TIME); - SetAttackTime(OFF_ATTACK, BASE_ATTACK_TIME); - SetAttackTime(RANGED_ATTACK, BASE_ATTACK_TIME); - - SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0); - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family); - if(cFamily && cFamily->minScale > 0.0f) - { - float scale; - if (getLevel() >= cFamily->maxScaleLevel) - scale = cFamily->maxScale; - else if (getLevel() <= cFamily->minScaleLevel) - scale = cFamily->minScale; - else - scale = cFamily->minScale + (getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale); - - SetFloatValue(OBJECT_FIELD_SCALE_X, scale); - } - m_bonusdamage = 0; - - int32 createResistance[MAX_SPELL_SCHOOL] = {0,0,0,0,0,0,0}; - - if(cinfo && getPetType() != HUNTER_PET) - { - createResistance[SPELL_SCHOOL_HOLY] = cinfo->resistance1; - createResistance[SPELL_SCHOOL_FIRE] = cinfo->resistance2; - createResistance[SPELL_SCHOOL_NATURE] = cinfo->resistance3; - createResistance[SPELL_SCHOOL_FROST] = cinfo->resistance4; - createResistance[SPELL_SCHOOL_SHADOW] = cinfo->resistance5; - createResistance[SPELL_SCHOOL_ARCANE] = cinfo->resistance6; - } - - switch(getPetType()) - { - case SUMMON_PET: - { - if(owner->GetTypeId() == TYPEID_PLAYER) - { - switch(owner->getClass()) - { - case CLASS_WARLOCK: - { - - //the damage bonus used for pets is either fire or shadow damage, whatever is higher - uint32 fire = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE); - uint32 shadow = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); - uint32 val = (fire > shadow) ? fire : shadow; - - SetBonusDamage(int32 (val * 0.15f)); - //bonusAP += val * 0.57; - break; - } - case CLASS_MAGE: - { - //40% damage bonus of mage's frost damage - float val = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST) * 0.4; - if(val < 0) - val = 0; - SetBonusDamage( int32(val)); - break; - } - default: - break; - } - } - - SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); - SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); - - //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); - - PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); - if(pInfo) // exist in DB - { - SetCreateHealth(pInfo->health); - SetCreateMana(pInfo->mana); - - if(pInfo->armor > 0) - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); - - for(int stat = 0; stat < MAX_STATS; ++stat) - { - SetCreateStat(Stats(stat),float(pInfo->stats[stat])); - } - } - else // not exist in DB, use some default fake data - { - sLog.outErrorDb("Summoned pet (Entry: %u) not have pet stats data in DB",cinfo->Entry); - - // remove elite bonuses included in DB values - SetCreateHealth(uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); - SetCreateMana( uint32(((float(cinfo->maxmana) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); - - SetCreateStat(STAT_STRENGTH,22); - SetCreateStat(STAT_AGILITY,22); - SetCreateStat(STAT_STAMINA,25); - SetCreateStat(STAT_INTELLECT,28); - SetCreateStat(STAT_SPIRIT,27); - } - break; - } - case HUNTER_PET: - { - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(petlevel))/4)); - - //these formula may not be correct; however, it is designed to be close to what it should be - //this makes dps 0.5 of pets level - SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); - //damage range is then petlevel / 2 - SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); - //damage is increased afterwards as strength and pet scaling modify attack power - - //stored standard pet stats are entry 1 in pet_levelinfo - PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); - if(pInfo) // exist in DB - { - SetCreateHealth(pInfo->health); - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); - //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); - - for( int i = STAT_STRENGTH; i < MAX_STATS; i++) - { - SetCreateStat(Stats(i), float(pInfo->stats[i])); - } - } - else // not exist in DB, use some default fake data - { - sLog.outErrorDb("Hunter pet levelstats missing in DB"); - - // remove elite bonuses included in DB values - SetCreateHealth( uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); - - SetCreateStat(STAT_STRENGTH,22); - SetCreateStat(STAT_AGILITY,22); - SetCreateStat(STAT_STAMINA,25); - SetCreateStat(STAT_INTELLECT,28); - SetCreateStat(STAT_SPIRIT,27); - } - break; - } - case GUARDIAN_PET: - SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); - SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP,1000); - - SetCreateMana( 28 + 10*petlevel ); - SetCreateHealth( 28 + 30*petlevel ); - - // FIXME: this is wrong formula, possible each guardian pet have own damage formula - //these formula may not be correct; however, it is designed to be close to what it should be - //this makes dps 0.5 of pets level - SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); - //damage range is then petlevel / 2 - SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); - break; - default: - sLog.outError("Pet have incorrect type (%u) for levelup.",getPetType()); break; - } - - for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i) - SetModifierValue(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(createResistance[i]) ); - - UpdateAllStats(); - - SetHealth(GetMaxHealth()); - SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); - - return true; -} - -bool Pet::HaveInDiet(ItemPrototype const* item) const -{ - if (!item->FoodType) - return false; - - CreatureInfo const* cInfo = GetCreatureInfo(); - if(!cInfo) - return false; - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); - if(!cFamily) - return false; - - uint32 diet = cFamily->petFoodMask; - uint32 FoodMask = 1 << (item->FoodType-1); - return diet & FoodMask; -} - -uint32 Pet::GetCurrentFoodBenefitLevel(uint32 itemlevel) -{ - // -5 or greater food level - if(getLevel() <= itemlevel +5) //possible to feed level 60 pet with level 55 level food for full effect - return 35000; - // -10..-6 - else if(getLevel() <= itemlevel + 10) //pure guess, but sounds good - return 17000; - // -14..-11 - else if(getLevel() <= itemlevel + 14) //level 55 food gets green on 70, makes sense to me - return 8000; - // -15 or less - else - return 0; //food too low level -} - -void Pet::_LoadSpellCooldowns() -{ - m_CreatureSpellCooldowns.clear(); - m_CreatureCategoryCooldowns.clear(); - - QueryResult *result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - if(result) - { - time_t curTime = time(NULL); - - WorldPacket data(SMSG_SPELL_COOLDOWN, (8+1+result->GetRowCount()*8)); - data << GetGUID(); - data << uint8(0x0); // flags (0x1, 0x2) - - do - { - Field *fields = result->Fetch(); - - uint32 spell_id = fields[0].GetUInt32(); - time_t db_time = (time_t)fields[1].GetUInt64(); - - if(!sSpellStore.LookupEntry(spell_id)) - { - sLog.outError("Pet %u have unknown spell %u in `pet_spell_cooldown`, skipping.",m_charmInfo->GetPetNumber(),spell_id); - continue; - } - - // skip outdated cooldown - if(db_time <= curTime) - continue; - - data << uint32(spell_id); - data << uint32(uint32(db_time-curTime)*1000); // in m.secs - - _AddCreatureSpellCooldown(spell_id,db_time); - - sLog.outDebug("Pet (Number: %u) spell %u cooldown loaded (%u secs).",m_charmInfo->GetPetNumber(),spell_id,uint32(db_time-curTime)); - } - while( result->NextRow() ); - - delete result; - - if(!m_CreatureSpellCooldowns.empty() && GetOwner()) - { - ((Player*)GetOwner())->GetSession()->SendPacket(&data); - } - } -} - -void Pet::_SaveSpellCooldowns() -{ - CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", m_charmInfo->GetPetNumber()); - - time_t curTime = time(NULL); - - // remove oudated and save active - for(CreatureSpellCooldowns::iterator itr = m_CreatureSpellCooldowns.begin();itr != m_CreatureSpellCooldowns.end();) - { - if(itr->second <= curTime) - m_CreatureSpellCooldowns.erase(itr++); - else - { - CharacterDatabase.PExecute("INSERT INTO pet_spell_cooldown (guid,spell,time) VALUES ('%u', '%u', '" I64FMTD "')", m_charmInfo->GetPetNumber(), itr->first, uint64(itr->second)); - ++itr; - } - } -} - -void Pet::_LoadSpells() -{ - QueryResult *result = CharacterDatabase.PQuery("SELECT spell,slot,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - if(result) - { - do - { - Field *fields = result->Fetch(); - - addSpell(fields[0].GetUInt16(), (ActiveStates)fields[2].GetUInt16(), PETSPELL_UNCHANGED, fields[1].GetUInt16()); - } - while( result->NextRow() ); - - delete result; - } -} - -void Pet::_SaveSpells() -{ - for (PetSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next) - { - ++next; - if (itr->second->type == PETSPELL_FAMILY) continue; // prevent saving family passives to DB - if (itr->second->state == PETSPELL_REMOVED || itr->second->state == PETSPELL_CHANGED) - CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first); - if (itr->second->state == PETSPELL_NEW || itr->second->state == PETSPELL_CHANGED) - CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,slot,active) VALUES ('%u', '%u', '%u','%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second->slotId,itr->second->active); - - if (itr->second->state == PETSPELL_REMOVED) - _removeSpell(itr->first); - else - itr->second->state = PETSPELL_UNCHANGED; - } -} - -void Pet::_LoadAuras(uint32 timediff) -{ - m_Auras.clear(); - for (int i = 0; i < TOTAL_AURAS; i++) - m_modAuras[i].clear(); - - // all aura related fields - for(int i = UNIT_FIELD_AURA; i <= UNIT_FIELD_AURASTATE; ++i) - SetUInt32Value(i, 0); - - QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - if(result) - { - do - { - Field *fields = result->Fetch(); - uint64 caster_guid = fields[0].GetUInt64(); - uint32 spellid = fields[1].GetUInt32(); - uint32 effindex = fields[2].GetUInt32(); - int32 damage = (int32)fields[3].GetUInt32(); - int32 maxduration = (int32)fields[4].GetUInt32(); - int32 remaintime = (int32)fields[5].GetUInt32(); - int32 remaincharges = (int32)fields[6].GetUInt32(); - - SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid); - if(!spellproto) - { - sLog.outError("Unknown aura (spellid %u, effindex %u), ignore.",spellid,effindex); - continue; - } - - if(effindex >= 3) - { - sLog.outError("Invalid effect index (spellid %u, effindex %u), ignore.",spellid,effindex); - continue; - } - - // negative effects should continue counting down after logout - if (remaintime != -1 && !IsPositiveEffect(spellid, effindex)) - { - if(remaintime <= int32(timediff)) - continue; - - remaintime -= timediff; - } - - // prevent wrong values of remaincharges - if(spellproto->procCharges) - { - if(remaincharges <= 0 || remaincharges > spellproto->procCharges) - remaincharges = spellproto->procCharges; - } - else - remaincharges = -1; - - /// do not load single target auras (unless they were cast by the player) - if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) - continue; - - Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); - - if(!damage) - damage = aura->GetModifier()->m_amount; - aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); - AddAura(aura); - } - while( result->NextRow() ); - - delete result; - } -} - -void Pet::_SaveAuras() -{ - CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); - - AuraMap const& auras = GetAuras(); - for(AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) - { - // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras. - SpellEntry const *spellInfo = itr->second->GetSpellProto(); - uint8 i; - for (i = 0; i < 3; i++) - if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET ) - break; - - if (i != 3) - continue; - - if(itr->second->IsPassive()) - continue; - - /// do not save single target auras (unless they were cast by the player) - if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)) - continue; - - CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " - "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')", - m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); - } -} - -bool Pet::addSpell(uint16 spell_id, ActiveStates active, PetSpellState state, uint16 slot_id, PetSpellType type) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id); - if (!spellInfo) - { - // do pet spell book cleanup - if(state == PETSPELL_UNCHANGED) // spell load case - { - sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request, deleting for all pets in `pet_spell`.",spell_id); - CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE spell = '%u'",spell_id); - } - else - sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request.",spell_id); - - return false; - } - // same spells don't have autocast option - if (spellInfo->AttributesEx & SPELL_ATTR_EX_PET_NOT_AUTOCAST) - active = ACT_CAST; - - PetSpellMap::iterator itr = m_spells.find(spell_id); - if (itr != m_spells.end()) - { - if (itr->second->state == PETSPELL_REMOVED) - { - delete itr->second; - m_spells.erase(itr); - state = PETSPELL_CHANGED; - } - else if (state == PETSPELL_UNCHANGED && itr->second->state != PETSPELL_UNCHANGED) - { - // can be in case spell loading but learned at some previous spell loading - itr->second->state = PETSPELL_UNCHANGED; - return false; - } - else - return false; - } - - uint32 oldspell_id = 0; - - PetSpell *newspell = new PetSpell; - newspell->state = state; - newspell->type = type; - - if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here - { - if(IsPassiveSpell(spell_id)) - newspell->active = ACT_PASSIVE; - else - newspell->active = ACT_DISABLED; - } - else - newspell->active = active; - - uint32 chainstart = spellmgr.GetFirstSpellInChain(spell_id); - - for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); itr++) - { - if(itr->second->state == PETSPELL_REMOVED) continue; - - if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) - { - slot_id = itr->second->slotId; - newspell->active = itr->second->active; - - if(newspell->active == ACT_ENABLED) - ToggleAutocast(itr->first, false); - - oldspell_id = itr->first; - removeSpell(itr->first); - } - } - - uint16 tmpslot=slot_id; - - if (tmpslot == 0xffff) - { - uint16 maxid = 0; - PetSpellMap::iterator itr; - for (itr = m_spells.begin(); itr != m_spells.end(); ++itr) - { - if(itr->second->state == PETSPELL_REMOVED) continue; - if (itr->second->slotId > maxid) maxid = itr->second->slotId; - } - tmpslot = maxid + 1; - } - - newspell->slotId = tmpslot; - m_spells[spell_id] = newspell; - - if (IsPassiveSpell(spell_id)) - CastSpell(this, spell_id, true); - else if(state == PETSPELL_NEW) - m_charmInfo->AddSpellToAB(oldspell_id, spell_id, active); - - if(newspell->active == ACT_ENABLED) - ToggleAutocast(spell_id, true); - - return true; -} - -bool Pet::learnSpell(uint16 spell_id) -{ - // prevent duplicated entires in spell book - if (!addSpell(spell_id)) - return false; - - Unit* owner = GetOwner(); - if(owner->GetTypeId()==TYPEID_PLAYER) - ((Player*)owner)->PetSpellInitialize(); - return true; -} - -void Pet::removeSpell(uint16 spell_id) -{ - PetSpellMap::iterator itr = m_spells.find(spell_id); - if (itr == m_spells.end()) - return; - - if(itr->second->state == PETSPELL_REMOVED) - return; - - if(itr->second->state == PETSPELL_NEW) - { - delete itr->second; - m_spells.erase(itr); - } - else - itr->second->state = PETSPELL_REMOVED; - - RemoveAurasDueToSpell(spell_id); -} - -bool Pet::_removeSpell(uint16 spell_id) -{ - PetSpellMap::iterator itr = m_spells.find(spell_id); - if (itr != m_spells.end()) - { - delete itr->second; - m_spells.erase(itr); - return true; - } - return false; -} - -void Pet::InitPetCreateSpells() -{ - m_charmInfo->InitPetActionBar(); - - m_spells.clear(); - int32 usedtrainpoints = 0, petspellid; - PetCreateSpellEntry const* CreateSpells = objmgr.GetPetCreateSpellEntry(GetEntry()); - if(CreateSpells) - { - for(uint8 i = 0; i < 4; i++) - { - if(!CreateSpells->spellid[i]) - break; - - SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(CreateSpells->spellid[i]); - if(!learn_spellproto) - continue; - - if(learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_SPELL || learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_PET_SPELL) - { - petspellid = learn_spellproto->EffectTriggerSpell[0]; - Unit* owner = GetOwner(); - if(owner->GetTypeId() == TYPEID_PLAYER && !((Player*)owner)->HasSpell(learn_spellproto->Id)) - { - if(IsPassiveSpell(petspellid)) //learn passive skills when tamed, not sure if thats right - ((Player*)owner)->learnSpell(learn_spellproto->Id); - else - AddTeachSpell(learn_spellproto->EffectTriggerSpell[0], learn_spellproto->Id); - } - } - else - petspellid = learn_spellproto->Id; - - addSpell(petspellid); - - SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); - SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); - - for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) - { - usedtrainpoints += _spell_idx->second->reqtrainpoints; - break; - } - } - } - - LearnPetPassives(); - - CastPetAuras(false); - - SetTP(-usedtrainpoints); -} - -void Pet::CheckLearning(uint32 spellid) -{ - //charmed case -> prevent crash - if(GetTypeId() == TYPEID_PLAYER || getPetType() != HUNTER_PET) - return; - - Unit* owner = GetOwner(); - - if(m_teachspells.empty() || !owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - TeachSpellMap::iterator itr = m_teachspells.find(spellid); - if(itr == m_teachspells.end()) - return; - - if(urand(0, 100) < 10) - { - ((Player*)owner)->learnSpell(itr->second); - m_teachspells.erase(itr); - } -} - -uint32 Pet::resetTalentsCost() const -{ - uint32 days = (sWorld.GetGameTime() - m_resetTalentsTime)/DAY; - - // The first time reset costs 10 silver; after 1 day cost is reset to 10 silver - if(m_resetTalentsCost < 10*SILVER || days > 0) - return 10*SILVER; - // then 50 silver - else if(m_resetTalentsCost < 50*SILVER) - return 50*SILVER; - // then 1 gold - else if(m_resetTalentsCost < 1*GOLD) - return 1*GOLD; - // then increasing at a rate of 1 gold; cap 10 gold - else - return (m_resetTalentsCost + 1*GOLD > 10*GOLD ? 10*GOLD : m_resetTalentsCost + 1*GOLD); -} - -void Pet::ToggleAutocast(uint32 spellid, bool apply) -{ - if(IsPassiveSpell(spellid)) - return; - - /*if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid)) - if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER - && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE) - return; */ - - PetSpellMap::const_iterator itr = m_spells.find((uint16)spellid); - - int i; - - if(apply) - { - for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++); - if (i == m_autospells.size()) - { - m_autospells.push_back(spellid); - itr->second->active = ACT_ENABLED; - itr->second->state = PETSPELL_CHANGED; - } - } - else - { - AutoSpellList::iterator itr2 = m_autospells.begin(); - for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++, itr2++); - if (i < m_autospells.size()) - { - m_autospells.erase(itr2); - itr->second->active = ACT_DISABLED; - itr->second->state = PETSPELL_CHANGED; - } - } -} - -bool Pet::Create(uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number) -{ - SetMapId(map->GetId()); - SetInstanceId(map->GetInstanceId()); - - Object::_Create(guidlow, pet_number, HIGHGUID_PET); - - m_DBTableGuid = guidlow; - m_originalEntry = Entry; - - if(!InitEntry(Entry)) - return false; - - SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); - SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); - - if(getPetType() == MINI_PET) // always non-attackable - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); - - return true; -} - -bool Pet::HasSpell(uint32 spell) const -{ - return (m_spells.find(spell) != m_spells.end()); -} - -// Get all passive spells in our skill line -void Pet::LearnPetPassives() -{ - CreatureInfo const* cInfo = GetCreatureInfo(); - if(!cInfo) - return; - - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); - if(!cFamily) - return; - - PetFamilySpellsStore::const_iterator petStore = sPetFamilySpellsStore.find(cFamily->ID); - if(petStore != sPetFamilySpellsStore.end()) - { - for(PetFamilySpellsSet::const_iterator petSet = petStore->second.begin(); petSet != petStore->second.end(); ++petSet) - addSpell(*petSet, ACT_DECIDE, PETSPELL_NEW, 0xffff, PETSPELL_FAMILY); - } -} - -void Pet::CastPetAuras(bool current) -{ - Unit* owner = GetOwner(); - if(!owner) - return; - - if(getPetType() != HUNTER_PET && (getPetType() != SUMMON_PET || owner->getClass() != CLASS_WARLOCK)) - return; - - for(PetAuraSet::iterator itr = owner->m_petAuras.begin(); itr != owner->m_petAuras.end(); ) - { - PetAura const* pa = *itr; - ++itr; - - if(!current && pa->IsRemovedOnChangePet()) - owner->RemovePetAura(pa); - else - CastPetAura(pa); - } -} - -void Pet::CastPetAura(PetAura const* aura) -{ - uint16 auraId = aura->GetAura(GetEntry()); - if(!auraId) - return; - - if(auraId == 35696) // Demonic Knowledge - { - int32 basePoints = int32(aura->GetDamage() * (GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)) / 100); - CastCustomSpell(this,auraId,&basePoints, NULL, NULL, true ); - } - else - CastSpell(this, auraId, true); -} +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Common.h" +#include "Database/DatabaseEnv.h" +#include "Log.h" +#include "WorldSession.h" +#include "WorldPacket.h" +#include "ObjectMgr.h" +#include "SpellMgr.h" +#include "Pet.h" +#include "MapManager.h" +#include "Formulas.h" +#include "SpellAuras.h" +#include "CreatureAI.h" +#include "Unit.h" +#include "Util.h" + +char const* petTypeSuffix[MAX_PET_TYPE] = +{ + "'s Minion", // SUMMON_PET + "'s Pet", // HUNTER_PET + "'s Guardian", // GUARDIAN_PET + "'s Companion" // MINI_PET +}; + +//numbers represent minutes * 100 while happy (you get 100 loyalty points per min while happy) +uint32 const LevelUpLoyalty[6] = +{ + 5500, + 11500, + 17000, + 23500, + 31000, + 39500, +}; + +uint32 const LevelStartLoyalty[6] = +{ + 2000, + 4500, + 7000, + 10000, + 13500, + 17500, +}; + +Pet::Pet(PetType type) : Creature() +{ + m_isPet = true; + m_name = "Pet"; + m_petType = type; + + m_removed = false; + m_regenTimer = 4000; + m_happinessTimer = 7500; + m_loyaltyTimer = 12000; + m_duration = 0; + m_bonusdamage = 0; + + m_loyaltyPoints = 0; + m_TrainingPoints = 0; + m_resetTalentsCost = 0; + m_resetTalentsTime = 0; + + m_auraUpdateMask = 0; + + // pets always have a charminfo, even if they are not actually charmed + CharmInfo* charmInfo = InitCharmInfo(this); + + if(type == MINI_PET) // always passive + charmInfo->SetReactState(REACT_PASSIVE); + else if(type == GUARDIAN_PET) // always aggressive + charmInfo->SetReactState(REACT_AGGRESSIVE); + + m_spells.clear(); + m_Auras.clear(); + m_CreatureSpellCooldowns.clear(); + m_CreatureCategoryCooldowns.clear(); + m_autospells.clear(); + m_declinedname = NULL; + m_isActive = true; +} + +Pet::~Pet() +{ + if(m_uint32Values) // only for fully created Object + { + for (PetSpellMap::iterator i = m_spells.begin(); i != m_spells.end(); ++i) + delete i->second; + ObjectAccessor::Instance().RemoveObject(this); + } + + delete m_declinedname; +} + +void Pet::AddToWorld() +{ + ///- Register the pet for guid lookup + if(!IsInWorld()) ObjectAccessor::Instance().AddObject(this); + Unit::AddToWorld(); +} + +void Pet::RemoveFromWorld() +{ + ///- Remove the pet from the accessor + if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); + ///- Don't call the function for Creature, normal mobs + totems go in a different storage + Unit::RemoveFromWorld(); +} + +bool Pet::LoadPetFromDB( Unit* owner, uint32 petentry, uint32 petnumber, bool current ) +{ + uint32 ownerid = owner->GetGUIDLow(); + + QueryResult *result; + + if(petnumber) + // known petnumber entry 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND id = '%u'",ownerid, petnumber); + else if(current) + // current pet (slot 0) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND slot = '0'",ownerid ); + else if(petentry) + // known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets) + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND entry = '%u' AND (slot = '0' OR slot = '3') ",ownerid, petentry ); + else + // any current or other non-stabled pet (for hunter "call pet") + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 + result = CharacterDatabase.PQuery("SELECT id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata, TeachSpelldata, savetime, resettalents_cost, resettalents_time, CreatedBySpell, PetType FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3') ",ownerid); + + if(!result) + return false; + + Field *fields = result->Fetch(); + + // update for case of current pet "slot = 0" + petentry = fields[1].GetUInt32(); + if(!petentry) + { + delete result; + return false; + } + + uint32 summon_spell_id = fields[21].GetUInt32(); + SpellEntry const* spellInfo = sSpellStore.LookupEntry(summon_spell_id); + + bool is_temporary_summoned = spellInfo && GetSpellDuration(spellInfo) > 0; + + // check temporary summoned pets like mage water elemental + if(current && is_temporary_summoned) + { + delete result; + return false; + } + + Map *map = owner->GetMap(); + uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); + uint32 pet_number = fields[0].GetUInt32(); + if(!Create(guid, map, petentry, pet_number)) + { + delete result; + return false; + } + + float px, py, pz; + owner->GetClosePoint(px, py, pz,GetObjectSize(),PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); + + Relocate(px, py, pz, owner->GetOrientation()); + + if(!IsPositionValid()) + { + sLog.outError("ERROR: Pet (guidlow %d, entry %d) not loaded. Suggested coordinates isn't valid (X: %f Y: %f)", + GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); + delete result; + return false; + } + + setPetType(PetType(fields[22].GetUInt8())); + SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,owner->getFaction()); + SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id); + + CreatureInfo const *cinfo = GetCreatureInfo(); + if(cinfo->type == CREATURE_TYPE_CRITTER) + { + AIM_Initialize(); + map->Add((Creature*)this); + delete result; + return true; + } + if(getPetType()==HUNTER_PET || (getPetType()==SUMMON_PET && cinfo->type == CREATURE_TYPE_DEMON && owner->getClass() == CLASS_WARLOCK)) + m_charmInfo->SetPetNumber(pet_number, true); + else + m_charmInfo->SetPetNumber(pet_number, false); + SetUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID()); + SetDisplayId(fields[3].GetUInt32()); + SetNativeDisplayId(fields[3].GetUInt32()); + uint32 petlevel=fields[4].GetUInt32(); + SetUInt32Value(UNIT_NPC_FLAGS , 0); + SetName(fields[11].GetString()); + + switch(getPetType()) + { + + case SUMMON_PET: + petlevel=owner->getLevel(); + + SetUInt32Value(UNIT_FIELD_BYTES_0,2048); + SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); + // this enables popup window (pet dismiss, cancel) + break; + case HUNTER_PET: + SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); + SetByteValue(UNIT_FIELD_BYTES_1, 1, fields[8].GetUInt32()); + SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); + + if(fields[12].GetBool()) + SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_NOT_ALLOWED); + else + SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); + + SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); + // this enables popup window (pet abandon, cancel) + SetTP(fields[9].GetInt32()); + SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + SetPower( POWER_HAPPINESS,fields[15].GetUInt32()); + setPowerType(POWER_FOCUS); + break; + default: + sLog.outError("Pet have incorrect type (%u) for pet loading.",getPetType()); + } + InitStatsForLevel( petlevel); + SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL)); + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32()); + SetUInt64Value(UNIT_FIELD_CREATEDBY, owner->GetGUID()); + + m_charmInfo->SetReactState( ReactStates( fields[6].GetUInt8() )); + m_loyaltyPoints = fields[7].GetInt32(); + + uint32 savedhealth = fields[13].GetUInt32(); + uint32 savedmana = fields[14].GetUInt32(); + + // set current pet as current + if(fields[10].GetUInt32() != 0) + { + CharacterDatabase.BeginTransaction(); + CharacterDatabase.PExecute("UPDATE character_pet SET slot = '3' WHERE owner = '%u' AND slot = '0' AND id <> '%u'",ownerid, m_charmInfo->GetPetNumber()); + CharacterDatabase.PExecute("UPDATE character_pet SET slot = '0' WHERE owner = '%u' AND id = '%u'",ownerid, m_charmInfo->GetPetNumber()); + CharacterDatabase.CommitTransaction(); + } + + if(!is_temporary_summoned) + { + // permanent controlled pets store state in DB + Tokens tokens = StrSplit(fields[16].GetString(), " "); + + if(tokens.size() != 20) + { + delete result; + return false; + } + + int index; + Tokens::iterator iter; + for(iter = tokens.begin(), index = 0; index < 10; ++iter, ++index ) + { + m_charmInfo->GetActionBarEntry(index)->Type = atol((*iter).c_str()); + ++iter; + m_charmInfo->GetActionBarEntry(index)->SpellOrAction = atol((*iter).c_str()); + } + + //init teach spells + tokens = StrSplit(fields[17].GetString(), " "); + for (iter = tokens.begin(), index = 0; index < 4; ++iter, ++index) + { + uint32 tmp = atol((*iter).c_str()); + + ++iter; + + if(tmp) + AddTeachSpell(tmp, atol((*iter).c_str())); + else + break; + } + } + + // since last save (in seconds) + uint32 timediff = (time(NULL) - fields[18].GetUInt32()); + + delete result; + + //load spells/cooldowns/auras + SetCanModifyStats(true); + _LoadAuras(timediff); + + //init AB + if(is_temporary_summoned) + { + // Temporary summoned pets always have initial spell list at load + InitPetCreateSpells(); + } + else + { + LearnPetPassives(); + CastPetAuras(current); + } + + if(getPetType() == SUMMON_PET && !current) //all (?) summon pets come with full health when called, but not when they are current + { + SetHealth(GetMaxHealth()); + SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); + } + else + { + SetHealth(savedhealth > GetMaxHealth() ? GetMaxHealth() : savedhealth); + SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana); + } + + AIM_Initialize(); + map->Add((Creature*)this); + + // Spells should be loaded after pet is added to map, because in CanCast is check on it + _LoadSpells(); + _LoadSpellCooldowns(); + + owner->SetPet(this); // in DB stored only full controlled creature + sLog.outDebug("New Pet has guid %u", GetGUIDLow()); + + if(owner->GetTypeId() == TYPEID_PLAYER) + { + ((Player*)owner)->PetSpellInitialize(); + if(((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_PET); + } + + if(owner->GetTypeId() == TYPEID_PLAYER && getPetType() == HUNTER_PET) + { + result = CharacterDatabase.PQuery("SELECT genitive, dative, accusative, instrumental, prepositional FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'",owner->GetGUIDLow(),GetCharmInfo()->GetPetNumber()); + + if(result) + { + if(m_declinedname) + delete m_declinedname; + + m_declinedname = new DeclinedName; + Field *fields = result->Fetch(); + for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) + { + m_declinedname->name[i] = fields[i].GetCppString(); + } + } + } + + return true; +} + +void Pet::SavePetToDB(PetSaveMode mode) +{ + if(!GetEntry()) + return; + + // save only fully controlled creature + if(!isControlled()) + return; + + uint32 curhealth = GetHealth(); + uint32 curmana = GetPower(POWER_MANA); + + switch(mode) + { + case PET_SAVE_IN_STABLE_SLOT_1: + case PET_SAVE_IN_STABLE_SLOT_2: + case PET_SAVE_NOT_IN_SLOT: + { + RemoveAllAuras(); + + //only alive hunter pets get auras saved, the others don't + if(!(getPetType() == HUNTER_PET && isAlive())) + m_Auras.clear(); + } + default: + break; + } + + _SaveSpells(); + _SaveSpellCooldowns(); + _SaveAuras(); + + switch(mode) + { + case PET_SAVE_AS_CURRENT: + case PET_SAVE_IN_STABLE_SLOT_1: + case PET_SAVE_IN_STABLE_SLOT_2: + case PET_SAVE_NOT_IN_SLOT: + { + uint32 loyalty =1; + if(getPetType()!=HUNTER_PET) + loyalty = GetLoyaltyLevel(); + + uint32 owner = GUID_LOPART(GetOwnerGUID()); + std::string name = m_name; + CharacterDatabase.escape_string(name); + CharacterDatabase.BeginTransaction(); + // remove current data + CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND id = '%u'", owner,m_charmInfo->GetPetNumber() ); + + // prevent duplicate using slot (except PET_SAVE_NOT_IN_SLOT) + if(mode!=PET_SAVE_NOT_IN_SLOT) + CharacterDatabase.PExecute("UPDATE character_pet SET slot = 3 WHERE owner = '%u' AND slot = '%u'", owner, uint32(mode) ); + + // prevent existence another hunter pet in PET_SAVE_AS_CURRENT and PET_SAVE_NOT_IN_SLOT + if(getPetType()==HUNTER_PET && (mode==PET_SAVE_AS_CURRENT||mode==PET_SAVE_NOT_IN_SLOT)) + CharacterDatabase.PExecute("DELETE FROM character_pet WHERE owner = '%u' AND (slot = '0' OR slot = '3')", owner ); + // save pet + std::ostringstream ss; + ss << "INSERT INTO character_pet ( id, entry, owner, modelid, level, exp, Reactstate, loyaltypoints, loyalty, trainpoint, slot, name, renamed, curhealth, curmana, curhappiness, abdata,TeachSpelldata,savetime,resettalents_cost,resettalents_time,CreatedBySpell,PetType) " + << "VALUES (" + << m_charmInfo->GetPetNumber() << ", " + << GetEntry() << ", " + << owner << ", " + << GetNativeDisplayId() << ", " + << getLevel() << ", " + << GetUInt32Value(UNIT_FIELD_PETEXPERIENCE) << ", " + << uint32(m_charmInfo->GetReactState()) << ", " + << m_loyaltyPoints << ", " + << GetLoyaltyLevel() << ", " + << m_TrainingPoints << ", " + << uint32(mode) << ", '" + << name.c_str() << "', " + << uint32((GetByteValue(UNIT_FIELD_BYTES_2, 2) == UNIT_RENAME_ALLOWED)?0:1) << ", " + << (curhealth<1?1:curhealth) << ", " + << curmana << ", " + << GetPower(POWER_HAPPINESS) << ", '"; + + for(uint32 i = 0; i < 10; i++) + ss << uint32(m_charmInfo->GetActionBarEntry(i)->Type) << " " << uint32(m_charmInfo->GetActionBarEntry(i)->SpellOrAction) << " "; + ss << "', '"; + + //save spells the pet can teach to it's Master + { + int i = 0; + for(TeachSpellMap::iterator itr = m_teachspells.begin(); i < 4 && itr != m_teachspells.end(); ++i, ++itr) + ss << itr->first << " " << itr->second << " "; + for(; i < 4; ++i) + ss << uint32(0) << " " << uint32(0) << " "; + } + + ss << "', " + << time(NULL) << ", " + << uint32(m_resetTalentsCost) << ", " + << uint64(m_resetTalentsTime) << ", " + << GetUInt32Value(UNIT_CREATED_BY_SPELL) << ", " + << uint32(getPetType()) << ")"; + + CharacterDatabase.Execute( ss.str().c_str() ); + + CharacterDatabase.CommitTransaction(); + break; + } + case PET_SAVE_AS_DELETED: + { + RemoveAllAuras(); + uint32 owner = GUID_LOPART(GetOwnerGUID()); + DeleteFromDB(m_charmInfo->GetPetNumber()); + break; + } + default: + sLog.outError("Unknown pet save/remove mode: %d",mode); + } +} + +void Pet::DeleteFromDB(uint32 guidlow) +{ + CharacterDatabase.PExecute("DELETE FROM character_pet WHERE id = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE id = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u'", guidlow); + CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", guidlow); +} + +void Pet::setDeathState(DeathState s) // overwrite virtual Creature::setDeathState and Unit::setDeathState +{ + Creature::setDeathState(s); + if(getDeathState()==CORPSE) + { + //remove summoned pet (no corpse) + if(getPetType()==SUMMON_PET) + Remove(PET_SAVE_NOT_IN_SLOT); + // other will despawn at corpse desppawning (Pet::Update code) + else + { + // pet corpse non lootable and non skinnable + SetUInt32Value( UNIT_DYNAMIC_FLAGS, 0x00 ); + RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); + + //lose happiness when died and not in BG/Arena + MapEntry const* mapEntry = sMapStore.LookupEntry(GetMapId()); + if(!mapEntry || (mapEntry->map_type != MAP_ARENA && mapEntry->map_type != MAP_BATTLEGROUND)) + ModifyPower(POWER_HAPPINESS, -HAPPINESS_LEVEL_SIZE); + + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); + } + } + else if(getDeathState()==ALIVE) + { + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_ROTATE); + CastPetAuras(true); + } +} + +void Pet::Update(uint32 diff) +{ + if(m_removed) // pet already removed, just wait in remove queue, no updates + return; + + switch( m_deathState ) + { + case CORPSE: + { + if( m_deathTimer <= diff ) + { + assert(getPetType()!=SUMMON_PET && "Must be already removed."); + Remove(PET_SAVE_NOT_IN_SLOT); //hunters' pets never get removed because of death, NEVER! + return; + } + break; + } + case ALIVE: + { + // unsummon pet that lost owner + Unit* owner = GetOwner(); + if(!owner || (!IsWithinDistInMap(owner, OWNER_MAX_DISTANCE) && !isPossessed()) || isControlled() && !owner->GetPetGUID()) + { + Remove(PET_SAVE_NOT_IN_SLOT, true); + return; + } + + if(isControlled()) + { + if( owner->GetPetGUID() != GetGUID() ) + { + Remove(getPetType()==HUNTER_PET?PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); + return; + } + } + + if(m_duration > 0) + { + if(m_duration > diff) + m_duration -= diff; + else + { + Remove(getPetType() != SUMMON_PET ? PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); + return; + } + } + + if(getPetType() != HUNTER_PET) + break; + + //regenerate Focus + if(m_regenTimer <= diff) + { + RegenerateFocus(); + m_regenTimer = 4000; + } + else + m_regenTimer -= diff; + + if(m_happinessTimer <= diff) + { + LooseHappiness(); + m_happinessTimer = 7500; + } + else + m_happinessTimer -= diff; + + if(m_loyaltyTimer <= diff) + { + TickLoyaltyChange(); + m_loyaltyTimer = 12000; + } + else + m_loyaltyTimer -= diff; + + break; + } + default: + break; + } + Creature::Update(diff); +} + +void Pet::RegenerateFocus() +{ + uint32 curValue = GetPower(POWER_FOCUS); + uint32 maxValue = GetMaxPower(POWER_FOCUS); + + if (curValue >= maxValue) + return; + + float addvalue = 24 * sWorld.getRate(RATE_POWER_FOCUS); + + AuraList const& ModPowerRegenPCTAuras = GetAurasByType(SPELL_AURA_MOD_POWER_REGEN_PERCENT); + for(AuraList::const_iterator i = ModPowerRegenPCTAuras.begin(); i != ModPowerRegenPCTAuras.end(); ++i) + if ((*i)->GetModifier()->m_miscvalue == POWER_FOCUS) + addvalue *= ((*i)->GetModifier()->m_amount + 100) / 100.0f; + + ModifyPower(POWER_FOCUS, (int32)addvalue); +} + +void Pet::LooseHappiness() +{ + uint32 curValue = GetPower(POWER_HAPPINESS); + if (curValue <= 0) + return; + int32 addvalue = (140 >> GetLoyaltyLevel()) * 125; //value is 70/35/17/8/4 (per min) * 1000 / 8 (timer 7.5 secs) + if(isInCombat()) //we know in combat happiness fades faster, multiplier guess + addvalue = int32(addvalue * 1.5); + ModifyPower(POWER_HAPPINESS, -addvalue); +} + +void Pet::ModifyLoyalty(int32 addvalue) +{ + uint32 loyaltylevel = GetLoyaltyLevel(); + + if(addvalue > 0) //only gain influenced, not loss + addvalue = int32((float)addvalue * sWorld.getRate(RATE_LOYALTY)); + + if(loyaltylevel >= BEST_FRIEND && (addvalue + m_loyaltyPoints) > int32(GetMaxLoyaltyPoints(loyaltylevel))) + return; + + m_loyaltyPoints += addvalue; + + if(m_loyaltyPoints < 0) + { + if(loyaltylevel > REBELLIOUS) + { + //level down + --loyaltylevel; + SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); + m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); + SetTP(m_TrainingPoints - int32(getLevel())); + } + else + { + m_loyaltyPoints = 0; + Unit* owner = GetOwner(); + if(owner && owner->GetTypeId() == TYPEID_PLAYER) + { + WorldPacket data(SMSG_PET_BROKEN, 0); + ((Player*)owner)->GetSession()->SendPacket(&data); + + //run away + ((Player*)owner)->RemovePet(this,PET_SAVE_AS_DELETED); + } + } + } + //level up + else if(m_loyaltyPoints > int32(GetMaxLoyaltyPoints(loyaltylevel))) + { + ++loyaltylevel; + SetLoyaltyLevel(LoyaltyLevel(loyaltylevel)); + m_loyaltyPoints = GetStartLoyaltyPoints(loyaltylevel); + SetTP(m_TrainingPoints + getLevel()); + } +} + +void Pet::TickLoyaltyChange() +{ + int32 addvalue; + + switch(GetHappinessState()) + { + case HAPPY: addvalue = 20; break; + case CONTENT: addvalue = 10; break; + case UNHAPPY: addvalue = -20; break; + default: + return; + } + ModifyLoyalty(addvalue); +} + +void Pet::KillLoyaltyBonus(uint32 level) +{ + if(level > 100) + return; + + //at lower levels gain is faster | the lower loyalty the more loyalty is gained + uint32 bonus = uint32(((100 - level) / 10) + (6 - GetLoyaltyLevel())); + ModifyLoyalty(bonus); +} + +HappinessState Pet::GetHappinessState() +{ + if(GetPower(POWER_HAPPINESS) < HAPPINESS_LEVEL_SIZE) + return UNHAPPY; + else if(GetPower(POWER_HAPPINESS) >= HAPPINESS_LEVEL_SIZE * 2) + return HAPPY; + else + return CONTENT; +} + +void Pet::SetLoyaltyLevel(LoyaltyLevel level) +{ + SetByteValue(UNIT_FIELD_BYTES_1, 1, level); +} + +bool Pet::CanTakeMoreActiveSpells(uint32 spellid) +{ + uint8 activecount = 1; + uint32 chainstartstore[ACTIVE_SPELLS_MAX]; + + if(IsPassiveSpell(spellid)) + return true; + + chainstartstore[0] = spellmgr.GetFirstSpellInChain(spellid); + + for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) + { + if(IsPassiveSpell(itr->first)) + continue; + + uint32 chainstart = spellmgr.GetFirstSpellInChain(itr->first); + + uint8 x; + + for(x = 0; x < activecount; x++) + { + if(chainstart == chainstartstore[x]) + break; + } + + if(x == activecount) //spellchain not yet saved -> add active count + { + ++activecount; + if(activecount > ACTIVE_SPELLS_MAX) + return false; + chainstartstore[x] = chainstart; + } + } + return true; +} + +bool Pet::HasTPForSpell(uint32 spellid) +{ + int32 neededtrainp = GetTPForSpell(spellid); + if((m_TrainingPoints - neededtrainp < 0 || neededtrainp < 0) && neededtrainp != 0) + return false; + return true; +} + +int32 Pet::GetTPForSpell(uint32 spellid) +{ + uint32 basetrainp = 0; + + SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(spellid); + SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(spellid); + for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) + { + if(!_spell_idx->second->reqtrainpoints) + return 0; + + basetrainp = _spell_idx->second->reqtrainpoints; + break; + } + + uint32 spenttrainp = 0; + uint32 chainstart = spellmgr.GetFirstSpellInChain(spellid); + + for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr) + { + if(itr->second->state == PETSPELL_REMOVED) + continue; + + if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) + { + SkillLineAbilityMap::const_iterator _lower = spellmgr.GetBeginSkillLineAbilityMap(itr->first); + SkillLineAbilityMap::const_iterator _upper = spellmgr.GetEndSkillLineAbilityMap(itr->first); + + for(SkillLineAbilityMap::const_iterator _spell_idx2 = _lower; _spell_idx2 != _upper; ++_spell_idx2) + { + if(_spell_idx2->second->reqtrainpoints > spenttrainp) + { + spenttrainp = _spell_idx2->second->reqtrainpoints; + break; + } + } + } + } + + return int32(basetrainp) - int32(spenttrainp); +} + +uint32 Pet::GetMaxLoyaltyPoints(uint32 level) +{ + return LevelUpLoyalty[level - 1]; +} + +uint32 Pet::GetStartLoyaltyPoints(uint32 level) +{ + return LevelStartLoyalty[level - 1]; +} + +void Pet::SetTP(int32 TP) +{ + m_TrainingPoints = TP; + SetUInt32Value(UNIT_TRAINING_POINTS, (uint32)GetDispTP()); +} + +int32 Pet::GetDispTP() +{ + if(getPetType()!= HUNTER_PET) + return(0); + if(m_TrainingPoints < 0) + return -m_TrainingPoints; + else + return -(m_TrainingPoints + 1); +} + +void Pet::Remove(PetSaveMode mode, bool returnreagent) +{ + Unit* owner = GetOwner(); + + if(owner) + { + if(owner->GetTypeId()==TYPEID_PLAYER) + { + ((Player*)owner)->RemovePet(this,mode,returnreagent); + return; + } + + // only if current pet in slot + if(owner->GetPetGUID()==GetGUID()) + owner->SetPet(0); + } + + CleanupsBeforeDelete(); + AddObjectToRemoveList(); + m_removed = true; +} + +void Pet::GivePetXP(uint32 xp) +{ + if(getPetType() != HUNTER_PET) + return; + + if ( xp < 1 ) + return; + + if(!isAlive()) + return; + + uint32 level = getLevel(); + + // XP to money conversion processed in Player::RewardQuest + if(level >= sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL)) + return; + + uint32 curXP = GetUInt32Value(UNIT_FIELD_PETEXPERIENCE); + uint32 nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); + uint32 newXP = curXP + xp; + + if(newXP >= nextLvlXP && level+1 > GetOwner()->getLevel()) + { + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, nextLvlXP-1); + return; + } + + while( newXP >= nextLvlXP && level < sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL) ) + { + newXP -= nextLvlXP; + + SetLevel( level + 1 ); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(level+1))/4)); + + level = getLevel(); + nextLvlXP = GetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP); + GivePetLevel(level); + } + + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, newXP); + + if(getPetType() == HUNTER_PET) + KillLoyaltyBonus(level); +} + +void Pet::GivePetLevel(uint32 level) +{ + if(!level) + return; + + InitStatsForLevel( level); + + SetTP(m_TrainingPoints + (GetLoyaltyLevel() - 1)); +} + +bool Pet::CreateBaseAtCreature(Creature* creature) +{ + if(!creature) + { + sLog.outError("CRITICAL ERROR: NULL pointer parsed into CreateBaseAtCreature()"); + return false; + } + uint32 guid=objmgr.GenerateLowGuid(HIGHGUID_PET); + + sLog.outBasic("SetInstanceID()"); + SetInstanceId(creature->GetInstanceId()); + + sLog.outBasic("Create pet"); + uint32 pet_number = objmgr.GeneratePetNumber(); + if(!Create(guid, creature->GetMap(), creature->GetEntry(), pet_number)) + return false; + + Relocate(creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(), creature->GetOrientation()); + + if(!IsPositionValid()) + { + sLog.outError("ERROR: Pet (guidlow %d, entry %d) not created base at creature. Suggested coordinates isn't valid (X: %f Y: %f)", + GetGUIDLow(), GetEntry(), GetPositionX(), GetPositionY()); + return false; + } + + CreatureInfo const *cinfo = GetCreatureInfo(); + if(!cinfo) + { + sLog.outError("ERROR: CreateBaseAtCreature() failed, creatureInfo is missing!"); + return false; + } + + if(cinfo->type == CREATURE_TYPE_CRITTER) + { + setPetType(MINI_PET); + return true; + } + SetDisplayId(creature->GetDisplayId()); + SetNativeDisplayId(creature->GetNativeDisplayId()); + SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + SetPower( POWER_HAPPINESS,166500); + setPowerType(POWER_FOCUS); + SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP,0); + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(creature->getLevel()))/4)); + SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE); + SetUInt32Value(UNIT_NPC_FLAGS , 0); + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(creature->GetCreatureInfo()->family); + if( char* familyname = cFamily->Name[sWorld.GetDefaultDbcLocale()] ) + SetName(familyname); + else + SetName(creature->GetName()); + + m_loyaltyPoints = 1000; + if(cinfo->type == CREATURE_TYPE_BEAST) + { + SetUInt32Value(UNIT_FIELD_BYTES_0, 0x02020100); + SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); + SetByteValue(UNIT_FIELD_BYTES_2, 2, UNIT_RENAME_ALLOWED); + + SetUInt32Value(UNIT_MOD_CAST_SPEED, creature->GetUInt32Value(UNIT_MOD_CAST_SPEED) ); + SetLoyaltyLevel(REBELLIOUS); + } + return true; +} + +bool Pet::InitStatsForLevel(uint32 petlevel) +{ + CreatureInfo const *cinfo = GetCreatureInfo(); + assert(cinfo); + + Unit* owner = GetOwner(); + if(!owner) + { + sLog.outError("ERROR: attempt to summon pet (Entry %u) without owner! Attempt terminated.", cinfo->Entry); + return false; + } + + uint32 creature_ID = (getPetType() == HUNTER_PET) ? 1 : cinfo->Entry; + + SetLevel( petlevel); + + SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool)); + + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(petlevel*50)); + + SetAttackTime(BASE_ATTACK, BASE_ATTACK_TIME); + SetAttackTime(OFF_ATTACK, BASE_ATTACK_TIME); + SetAttackTime(RANGED_ATTACK, BASE_ATTACK_TIME); + + SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0); + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family); + if(cFamily && cFamily->minScale > 0.0f) + { + float scale; + if (getLevel() >= cFamily->maxScaleLevel) + scale = cFamily->maxScale; + else if (getLevel() <= cFamily->minScaleLevel) + scale = cFamily->minScale; + else + scale = cFamily->minScale + (getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale); + + SetFloatValue(OBJECT_FIELD_SCALE_X, scale); + } + m_bonusdamage = 0; + + int32 createResistance[MAX_SPELL_SCHOOL] = {0,0,0,0,0,0,0}; + + if(cinfo && getPetType() != HUNTER_PET) + { + createResistance[SPELL_SCHOOL_HOLY] = cinfo->resistance1; + createResistance[SPELL_SCHOOL_FIRE] = cinfo->resistance2; + createResistance[SPELL_SCHOOL_NATURE] = cinfo->resistance3; + createResistance[SPELL_SCHOOL_FROST] = cinfo->resistance4; + createResistance[SPELL_SCHOOL_SHADOW] = cinfo->resistance5; + createResistance[SPELL_SCHOOL_ARCANE] = cinfo->resistance6; + } + + switch(getPetType()) + { + case SUMMON_PET: + { + if(owner->GetTypeId() == TYPEID_PLAYER) + { + switch(owner->getClass()) + { + case CLASS_WARLOCK: + { + + //the damage bonus used for pets is either fire or shadow damage, whatever is higher + uint32 fire = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE); + uint32 shadow = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); + uint32 val = (fire > shadow) ? fire : shadow; + + SetBonusDamage(int32 (val * 0.15f)); + //bonusAP += val * 0.57; + break; + } + case CLASS_MAGE: + { + //40% damage bonus of mage's frost damage + float val = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST) * 0.4; + if(val < 0) + val = 0; + SetBonusDamage( int32(val)); + break; + } + default: + break; + } + } + + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); + + //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); + + PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); + if(pInfo) // exist in DB + { + SetCreateHealth(pInfo->health); + SetCreateMana(pInfo->mana); + + if(pInfo->armor > 0) + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); + + for(int stat = 0; stat < MAX_STATS; ++stat) + { + SetCreateStat(Stats(stat),float(pInfo->stats[stat])); + } + } + else // not exist in DB, use some default fake data + { + sLog.outErrorDb("Summoned pet (Entry: %u) not have pet stats data in DB",cinfo->Entry); + + // remove elite bonuses included in DB values + SetCreateHealth(uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); + SetCreateMana( uint32(((float(cinfo->maxmana) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); + + SetCreateStat(STAT_STRENGTH,22); + SetCreateStat(STAT_AGILITY,22); + SetCreateStat(STAT_STAMINA,25); + SetCreateStat(STAT_INTELLECT,28); + SetCreateStat(STAT_SPIRIT,27); + } + break; + } + case HUNTER_PET: + { + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, uint32((Trinity::XP::xp_to_level(petlevel))/4)); + + //these formula may not be correct; however, it is designed to be close to what it should be + //this makes dps 0.5 of pets level + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); + //damage range is then petlevel / 2 + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); + //damage is increased afterwards as strength and pet scaling modify attack power + + //stored standard pet stats are entry 1 in pet_levelinfo + PetLevelInfo const* pInfo = objmgr.GetPetLevelInfo(creature_ID, petlevel); + if(pInfo) // exist in DB + { + SetCreateHealth(pInfo->health); + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(pInfo->armor)); + //SetModifierValue(UNIT_MOD_ATTACK_POWER, BASE_VALUE, float(cinfo->attackpower)); + + for( int i = STAT_STRENGTH; i < MAX_STATS; i++) + { + SetCreateStat(Stats(i), float(pInfo->stats[i])); + } + } + else // not exist in DB, use some default fake data + { + sLog.outErrorDb("Hunter pet levelstats missing in DB"); + + // remove elite bonuses included in DB values + SetCreateHealth( uint32(((float(cinfo->maxhealth) / cinfo->maxlevel) / (1 + 2 * cinfo->rank)) * petlevel) ); + + SetCreateStat(STAT_STRENGTH,22); + SetCreateStat(STAT_AGILITY,22); + SetCreateStat(STAT_STAMINA,25); + SetCreateStat(STAT_INTELLECT,28); + SetCreateStat(STAT_SPIRIT,27); + } + break; + } + case GUARDIAN_PET: + SetUInt32Value(UNIT_FIELD_PETEXPERIENCE,0); + SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP,1000); + + SetCreateMana( 28 + 10*petlevel ); + SetCreateHealth( 28 + 30*petlevel ); + + // FIXME: this is wrong formula, possible each guardian pet have own damage formula + //these formula may not be correct; however, it is designed to be close to what it should be + //this makes dps 0.5 of pets level + SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) ); + //damage range is then petlevel / 2 + SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) ); + break; + default: + sLog.outError("Pet have incorrect type (%u) for levelup.",getPetType()); break; + } + + for (int i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i) + SetModifierValue(UnitMods(UNIT_MOD_RESISTANCE_START + i), BASE_VALUE, float(createResistance[i]) ); + + UpdateAllStats(); + + SetHealth(GetMaxHealth()); + SetPower(POWER_MANA, GetMaxPower(POWER_MANA)); + + return true; +} + +bool Pet::HaveInDiet(ItemPrototype const* item) const +{ + if (!item->FoodType) + return false; + + CreatureInfo const* cInfo = GetCreatureInfo(); + if(!cInfo) + return false; + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); + if(!cFamily) + return false; + + uint32 diet = cFamily->petFoodMask; + uint32 FoodMask = 1 << (item->FoodType-1); + return diet & FoodMask; +} + +uint32 Pet::GetCurrentFoodBenefitLevel(uint32 itemlevel) +{ + // -5 or greater food level + if(getLevel() <= itemlevel +5) //possible to feed level 60 pet with level 55 level food for full effect + return 35000; + // -10..-6 + else if(getLevel() <= itemlevel + 10) //pure guess, but sounds good + return 17000; + // -14..-11 + else if(getLevel() <= itemlevel + 14) //level 55 food gets green on 70, makes sense to me + return 8000; + // -15 or less + else + return 0; //food too low level +} + +void Pet::_LoadSpellCooldowns() +{ + m_CreatureSpellCooldowns.clear(); + m_CreatureCategoryCooldowns.clear(); + + QueryResult *result = CharacterDatabase.PQuery("SELECT spell,time FROM pet_spell_cooldown WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + if(result) + { + time_t curTime = time(NULL); + + WorldPacket data(SMSG_SPELL_COOLDOWN, (8+1+result->GetRowCount()*8)); + data << GetGUID(); + data << uint8(0x0); // flags (0x1, 0x2) + + do + { + Field *fields = result->Fetch(); + + uint32 spell_id = fields[0].GetUInt32(); + time_t db_time = (time_t)fields[1].GetUInt64(); + + if(!sSpellStore.LookupEntry(spell_id)) + { + sLog.outError("Pet %u have unknown spell %u in `pet_spell_cooldown`, skipping.",m_charmInfo->GetPetNumber(),spell_id); + continue; + } + + // skip outdated cooldown + if(db_time <= curTime) + continue; + + data << uint32(spell_id); + data << uint32(uint32(db_time-curTime)*1000); // in m.secs + + _AddCreatureSpellCooldown(spell_id,db_time); + + sLog.outDebug("Pet (Number: %u) spell %u cooldown loaded (%u secs).",m_charmInfo->GetPetNumber(),spell_id,uint32(db_time-curTime)); + } + while( result->NextRow() ); + + delete result; + + if(!m_CreatureSpellCooldowns.empty() && GetOwner()) + { + ((Player*)GetOwner())->GetSession()->SendPacket(&data); + } + } +} + +void Pet::_SaveSpellCooldowns() +{ + CharacterDatabase.PExecute("DELETE FROM pet_spell_cooldown WHERE guid = '%u'", m_charmInfo->GetPetNumber()); + + time_t curTime = time(NULL); + + // remove oudated and save active + for(CreatureSpellCooldowns::iterator itr = m_CreatureSpellCooldowns.begin();itr != m_CreatureSpellCooldowns.end();) + { + if(itr->second <= curTime) + m_CreatureSpellCooldowns.erase(itr++); + else + { + CharacterDatabase.PExecute("INSERT INTO pet_spell_cooldown (guid,spell,time) VALUES ('%u', '%u', '" I64FMTD "')", m_charmInfo->GetPetNumber(), itr->first, uint64(itr->second)); + ++itr; + } + } +} + +void Pet::_LoadSpells() +{ + QueryResult *result = CharacterDatabase.PQuery("SELECT spell,slot,active FROM pet_spell WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + if(result) + { + do + { + Field *fields = result->Fetch(); + + addSpell(fields[0].GetUInt16(), fields[2].GetUInt16(), PETSPELL_UNCHANGED, fields[1].GetUInt16()); + } + while( result->NextRow() ); + + delete result; + } +} + +void Pet::_SaveSpells() +{ + for (PetSpellMap::const_iterator itr = m_spells.begin(), next = m_spells.begin(); itr != m_spells.end(); itr = next) + { + ++next; + if (itr->second->type == PETSPELL_FAMILY) continue; // prevent saving family passives to DB + if (itr->second->state == PETSPELL_REMOVED || itr->second->state == PETSPELL_CHANGED) + CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE guid = '%u' and spell = '%u'", m_charmInfo->GetPetNumber(), itr->first); + if (itr->second->state == PETSPELL_NEW || itr->second->state == PETSPELL_CHANGED) + CharacterDatabase.PExecute("INSERT INTO pet_spell (guid,spell,slot,active) VALUES ('%u', '%u', '%u','%u')", m_charmInfo->GetPetNumber(), itr->first, itr->second->slotId,itr->second->active); + + if (itr->second->state == PETSPELL_REMOVED) + _removeSpell(itr->first); + else + itr->second->state = PETSPELL_UNCHANGED; + } +} + +void Pet::_LoadAuras(uint32 timediff) +{ + m_Auras.clear(); + for (int i = 0; i < TOTAL_AURAS; i++) + m_modAuras[i].clear(); + + // all aura related fields + for(int i = UNIT_FIELD_AURA; i <= UNIT_FIELD_AURASTATE; ++i) + SetUInt32Value(i, 0); + + QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + if(result) + { + do + { + Field *fields = result->Fetch(); + uint64 caster_guid = fields[0].GetUInt64(); + uint32 spellid = fields[1].GetUInt32(); + uint32 effindex = fields[2].GetUInt32(); + int32 damage = (int32)fields[3].GetUInt32(); + int32 maxduration = (int32)fields[4].GetUInt32(); + int32 remaintime = (int32)fields[5].GetUInt32(); + int32 remaincharges = (int32)fields[6].GetUInt32(); + + SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid); + if(!spellproto) + { + sLog.outError("Unknown aura (spellid %u, effindex %u), ignore.",spellid,effindex); + continue; + } + + if(effindex >= 3) + { + sLog.outError("Invalid effect index (spellid %u, effindex %u), ignore.",spellid,effindex); + continue; + } + + // negative effects should continue counting down after logout + if (remaintime != -1 && !IsPositiveEffect(spellid, effindex)) + { + if(remaintime <= int32(timediff)) + continue; + + remaintime -= timediff; + } + + // prevent wrong values of remaincharges + if(spellproto->procCharges) + { + if(remaincharges <= 0 || remaincharges > spellproto->procCharges) + remaincharges = spellproto->procCharges; + } + else + remaincharges = -1; + + /// do not load single target auras (unless they were cast by the player) + if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) + continue; + + Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); + + if(!damage) + damage = aura->GetModifier()->m_amount; + aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); + AddAura(aura); + } + while( result->NextRow() ); + + delete result; + } +} + +void Pet::_SaveAuras() +{ + CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + + AuraMap const& auras = GetAuras(); + for(AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) + { + // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras. + SpellEntry const *spellInfo = itr->second->GetSpellProto(); + uint8 i; + for (i = 0; i < 3; i++) + if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET ) + break; + + if (i != 3) + continue; + + if(itr->second->IsPassive()) + continue; + + /// do not save single target auras (unless they were cast by the player) + if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)) + continue; + + CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " + "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')", + m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); + } +} + +bool Pet::addSpell(uint16 spell_id, uint16 active, PetSpellState state, uint16 slot_id, PetSpellType type) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spell_id); + if (!spellInfo) + { + // do pet spell book cleanup + if(state == PETSPELL_UNCHANGED) // spell load case + { + sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request, deleting for all pets in `pet_spell`.",spell_id); + CharacterDatabase.PExecute("DELETE FROM pet_spell WHERE spell = '%u'",spell_id); + } + else + sLog.outError("Pet::addSpell: Non-existed in SpellStore spell #%u request.",spell_id); + + return false; + } + + PetSpellMap::iterator itr = m_spells.find(spell_id); + if (itr != m_spells.end()) + { + if (itr->second->state == PETSPELL_REMOVED) + { + delete itr->second; + m_spells.erase(itr); + state = PETSPELL_CHANGED; + } + else if (state == PETSPELL_UNCHANGED && itr->second->state != PETSPELL_UNCHANGED) + { + // can be in case spell loading but learned at some previous spell loading + itr->second->state = PETSPELL_UNCHANGED; + return false; + } + else + return false; + } + + uint32 oldspell_id = 0; + + PetSpell *newspell = new PetSpell; + newspell->state = state; + newspell->type = type; + + if(active == ACT_DECIDE) //active was not used before, so we save it's autocast/passive state here + { + if(IsPassiveSpell(spell_id)) + newspell->active = ACT_PASSIVE; + else + newspell->active = ACT_DISABLED; + } + else + newspell->active = active; + + uint32 chainstart = spellmgr.GetFirstSpellInChain(spell_id); + + for (PetSpellMap::iterator itr = m_spells.begin(); itr != m_spells.end(); itr++) + { + if(itr->second->state == PETSPELL_REMOVED) continue; + + if(spellmgr.GetFirstSpellInChain(itr->first) == chainstart) + { + slot_id = itr->second->slotId; + newspell->active = itr->second->active; + + if(newspell->active == ACT_ENABLED) + ToggleAutocast(itr->first, false); + + oldspell_id = itr->first; + removeSpell(itr->first); + } + } + + uint16 tmpslot=slot_id; + + if (tmpslot == 0xffff) + { + uint16 maxid = 0; + PetSpellMap::iterator itr; + for (itr = m_spells.begin(); itr != m_spells.end(); ++itr) + { + if(itr->second->state == PETSPELL_REMOVED) continue; + if (itr->second->slotId > maxid) maxid = itr->second->slotId; + } + tmpslot = maxid + 1; + } + + newspell->slotId = tmpslot; + m_spells[spell_id] = newspell; + + if (IsPassiveSpell(spell_id)) + CastSpell(this, spell_id, true); + else if(state == PETSPELL_NEW) + m_charmInfo->AddSpellToAB(oldspell_id, spell_id); + + if(newspell->active == ACT_ENABLED) + ToggleAutocast(spell_id, true); + + return true; +} + +bool Pet::learnSpell(uint16 spell_id) +{ + // prevent duplicated entires in spell book + if (!addSpell(spell_id)) + return false; + + Unit* owner = GetOwner(); + if(owner->GetTypeId()==TYPEID_PLAYER) + ((Player*)owner)->PetSpellInitialize(); + return true; +} + +void Pet::removeSpell(uint16 spell_id) +{ + PetSpellMap::iterator itr = m_spells.find(spell_id); + if (itr == m_spells.end()) + return; + + if(itr->second->state == PETSPELL_REMOVED) + return; + + if(itr->second->state == PETSPELL_NEW) + { + delete itr->second; + m_spells.erase(itr); + } + else + itr->second->state = PETSPELL_REMOVED; + + RemoveAurasDueToSpell(spell_id); +} + +bool Pet::_removeSpell(uint16 spell_id) +{ + PetSpellMap::iterator itr = m_spells.find(spell_id); + if (itr != m_spells.end()) + { + delete itr->second; + m_spells.erase(itr); + return true; + } + return false; +} + +void Pet::InitPetCreateSpells() +{ + m_charmInfo->InitPetActionBar(); + + m_spells.clear(); + int32 usedtrainpoints = 0, petspellid; + PetCreateSpellEntry const* CreateSpells = objmgr.GetPetCreateSpellEntry(GetEntry()); + if(CreateSpells) + { + for(uint8 i = 0; i < 4; i++) + { + if(!CreateSpells->spellid[i]) + break; + + SpellEntry const *learn_spellproto = sSpellStore.LookupEntry(CreateSpells->spellid[i]); + if(!learn_spellproto) + continue; + + if(learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_SPELL || learn_spellproto->Effect[0] == SPELL_EFFECT_LEARN_PET_SPELL) + { + petspellid = learn_spellproto->EffectTriggerSpell[0]; + Unit* owner = GetOwner(); + if(owner->GetTypeId() == TYPEID_PLAYER && !((Player*)owner)->HasSpell(learn_spellproto->Id)) + { + if(IsPassiveSpell(petspellid)) //learn passive skills when tamed, not sure if thats right + ((Player*)owner)->learnSpell(learn_spellproto->Id); + else + AddTeachSpell(learn_spellproto->EffectTriggerSpell[0], learn_spellproto->Id); + } + } + else + petspellid = learn_spellproto->Id; + + addSpell(petspellid); + + SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); + SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(learn_spellproto->EffectTriggerSpell[0]); + + for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) + { + usedtrainpoints += _spell_idx->second->reqtrainpoints; + break; + } + } + } + + LearnPetPassives(); + + CastPetAuras(false); + + SetTP(-usedtrainpoints); +} + +void Pet::CheckLearning(uint32 spellid) +{ + //charmed case -> prevent crash + if(GetTypeId() == TYPEID_PLAYER || getPetType() != HUNTER_PET) + return; + + Unit* owner = GetOwner(); + + if(m_teachspells.empty() || !owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + TeachSpellMap::iterator itr = m_teachspells.find(spellid); + if(itr == m_teachspells.end()) + return; + + if(urand(0, 100) < 10) + { + ((Player*)owner)->learnSpell(itr->second); + m_teachspells.erase(itr); + } +} + +uint32 Pet::resetTalentsCost() const +{ + uint32 days = (sWorld.GetGameTime() - m_resetTalentsTime)/DAY; + + // The first time reset costs 10 silver; after 1 day cost is reset to 10 silver + if(m_resetTalentsCost < 10*SILVER || days > 0) + return 10*SILVER; + // then 50 silver + else if(m_resetTalentsCost < 50*SILVER) + return 50*SILVER; + // then 1 gold + else if(m_resetTalentsCost < 1*GOLD) + return 1*GOLD; + // then increasing at a rate of 1 gold; cap 10 gold + else + return (m_resetTalentsCost + 1*GOLD > 10*GOLD ? 10*GOLD : m_resetTalentsCost + 1*GOLD); +} + +void Pet::ToggleAutocast(uint32 spellid, bool apply) +{ + if(IsPassiveSpell(spellid)) + return; + + if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid)) + if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER + && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE) + return; + + PetSpellMap::const_iterator itr = m_spells.find((uint16)spellid); + + int i; + + if(apply) + { + for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++); + if (i == m_autospells.size()) + { + m_autospells.push_back(spellid); + itr->second->active = ACT_ENABLED; + itr->second->state = PETSPELL_CHANGED; + } + } + else + { + AutoSpellList::iterator itr2 = m_autospells.begin(); + for (i = 0; i < m_autospells.size() && m_autospells[i] != spellid; i++, itr2++); + if (i < m_autospells.size()) + { + m_autospells.erase(itr2); + itr->second->active = ACT_DISABLED; + itr->second->state = PETSPELL_CHANGED; + } + } +} + +bool Pet::Create(uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number) +{ + SetMapId(map->GetId()); + SetInstanceId(map->GetInstanceId()); + + Object::_Create(guidlow, pet_number, HIGHGUID_PET); + + m_DBTableGuid = guidlow; + m_originalEntry = Entry; + + if(!InitEntry(Entry)) + return false; + + SetByteValue(UNIT_FIELD_BYTES_2, 0, SHEATH_STATE_MELEE ); + SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5 ); + + if(getPetType() == MINI_PET) // always non-attackable + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); + + return true; +} + +bool Pet::HasSpell(uint32 spell) const +{ + return (m_spells.find(spell) != m_spells.end()); +} + +// Get all passive spells in our skill line +void Pet::LearnPetPassives() +{ + CreatureInfo const* cInfo = GetCreatureInfo(); + if(!cInfo) + return; + + CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cInfo->family); + if(!cFamily) + return; + + PetFamilySpellsStore::const_iterator petStore = sPetFamilySpellsStore.find(cFamily->ID); + if(petStore != sPetFamilySpellsStore.end()) + { + for(PetFamilySpellsSet::const_iterator petSet = petStore->second.begin(); petSet != petStore->second.end(); ++petSet) + addSpell(*petSet, ACT_DECIDE, PETSPELL_NEW, 0xffff, PETSPELL_FAMILY); + } +} + +void Pet::CastPetAuras(bool current) +{ + Unit* owner = GetOwner(); + if(!owner) + return; + + if(getPetType() != HUNTER_PET && (getPetType() != SUMMON_PET || owner->getClass() != CLASS_WARLOCK)) + return; + + for(PetAuraSet::iterator itr = owner->m_petAuras.begin(); itr != owner->m_petAuras.end(); ) + { + PetAura const* pa = *itr; + ++itr; + + if(!current && pa->IsRemovedOnChangePet()) + owner->RemovePetAura(pa); + else + CastPetAura(pa); + } +} + +void Pet::CastPetAura(PetAura const* aura) +{ + uint16 auraId = aura->GetAura(GetEntry()); + if(!auraId) + return; + + if(auraId == 35696) // Demonic Knowledge + { + int32 basePoints = int32(aura->GetDamage() * (GetStat(STAT_STAMINA) + GetStat(STAT_INTELLECT)) / 100); + CastCustomSpell(this,auraId,&basePoints, NULL, NULL, true ); + } + else + CastSpell(this, auraId, true); +} diff --git a/src/game/Pet.h b/src/game/Pet.h index 90f7584dd2c..ea13bd5d0dc 100644 --- a/src/game/Pet.h +++ b/src/game/Pet.h @@ -1,264 +1,264 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef TRINITYCORE_PET_H -#define TRINITYCORE_PET_H - -#include "ObjectDefines.h" -#include "Creature.h" -#include "Unit.h" - -enum PetType -{ - SUMMON_PET = 0, - HUNTER_PET = 1, - GUARDIAN_PET = 2, - MINI_PET = 3, - MAX_PET_TYPE = 4 -}; - -extern char const* petTypeSuffix[MAX_PET_TYPE]; - -enum PetSaveMode -{ - PET_SAVE_AS_DELETED =-1, - PET_SAVE_AS_CURRENT = 0, - PET_SAVE_IN_STABLE_SLOT_1 = 1, - PET_SAVE_IN_STABLE_SLOT_2 = 2, - PET_SAVE_NOT_IN_SLOT = 3 -}; - -enum HappinessState -{ - UNHAPPY = 1, - CONTENT = 2, - HAPPY = 3 -}; - -enum LoyaltyLevel -{ - REBELLIOUS = 1, - UNRULY = 2, - SUBMISSIVE = 3, - DEPENDABLE = 4, - FAITHFUL = 5, - BEST_FRIEND = 6 -}; - -enum PetSpellState -{ - PETSPELL_UNCHANGED = 0, - PETSPELL_CHANGED = 1, - PETSPELL_NEW = 2, - PETSPELL_REMOVED = 3 -}; - -enum PetSpellType -{ - PETSPELL_NORMAL = 0, - PETSPELL_FAMILY = 1, -}; - -struct PetSpell -{ - uint16 slotId; - uint16 active; - PetSpellState state : 16; - PetSpellType type : 16; -}; - -enum ActionFeedback -{ - FEEDBACK_NONE = 0, - FEEDBACK_PET_DEAD = 1, - FEEDBACK_NOTHING_TO_ATT = 2, - FEEDBACK_CANT_ATT_TARGET = 3 -}; - -enum PetTalk -{ - PET_TALK_SPECIAL_SPELL = 0, - PET_TALK_ATTACK = 1 -}; - -enum PetNameInvalidReason -{ - PET_NAME_INVALID = 1, - PET_NAME_NO_NAME = 2, - PET_NAME_TOO_SHORT = 3, - PET_NAME_TOO_LONG = 4, - PET_NAME_MIXED_LANGUAGES = 6, - PET_NAME_PROFANE = 7, - PET_NAME_RESERVED = 8, - PET_NAME_THREE_CONSECUTIVE = 11, - PET_NAME_INVALID_SPACE = 12, - PET_NAME_CONSECUTIVE_SPACES = 13, - PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14, - PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15, - PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 -}; - -typedef UNORDERED_MAP PetSpellMap; -typedef std::map TeachSpellMap; -typedef std::vector AutoSpellList; - -#define HAPPINESS_LEVEL_SIZE 333000 - -extern const uint32 LevelUpLoyalty[6]; -extern const uint32 LevelStartLoyalty[6]; - -#define ACTIVE_SPELLS_MAX 4 - -#define OWNER_MAX_DISTANCE 100 - -#define PET_FOLLOW_DIST 1 -#define PET_FOLLOW_ANGLE (M_PI/2) - -class Pet : public Creature -{ - public: - explicit Pet(PetType type = MAX_PET_TYPE); - virtual ~Pet(); - - void AddToWorld(); - void RemoveFromWorld(); - - PetType getPetType() const { return m_petType; } - void setPetType(PetType type) { m_petType = type; } - bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; } - bool isTemporarySummoned() const { return m_duration > 0; } - - bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number); - bool CreateBaseAtCreature( Creature* creature ); - bool LoadPetFromDB( Unit* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false ); - void SavePetToDB(PetSaveMode mode); - void Remove(PetSaveMode mode, bool returnreagent = false); - static void DeleteFromDB(uint32 guidlow); - - void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState - void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update - - uint8 GetPetAutoSpellSize() const { return m_autospells.size(); } - uint32 GetPetAutoSpellOnPos(uint8 pos) const - { - if (pos >= m_autospells.size()) - return 0; - else - return m_autospells[pos]; - } - - void RegenerateFocus(); - void LooseHappiness(); - void TickLoyaltyChange(); - void ModifyLoyalty(int32 addvalue); - HappinessState GetHappinessState(); - uint32 GetMaxLoyaltyPoints(uint32 level); - uint32 GetStartLoyaltyPoints(uint32 level); - void KillLoyaltyBonus(uint32 level); - uint32 GetLoyaltyLevel() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); } - void SetLoyaltyLevel(LoyaltyLevel level); - void GivePetXP(uint32 xp); - void GivePetLevel(uint32 level); - bool InitStatsForLevel(uint32 level); - bool HaveInDiet(ItemPrototype const* item) const; - uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel); - void SetDuration(int32 dur) { m_duration = dur; } - - int32 GetBonusDamage() { return m_bonusdamage; } - void SetBonusDamage(int32 damage) { m_bonusdamage = damage; } - - bool UpdateStats(Stats stat); - bool UpdateAllStats(); - void UpdateResistances(uint32 school); - void UpdateArmor(); - void UpdateMaxHealth(); - void UpdateMaxPower(Powers power); - void UpdateAttackPowerAndDamage(bool ranged = false); - void UpdateDamagePhysical(WeaponAttackType attType); - - bool CanTakeMoreActiveSpells(uint32 SpellIconID); - void ToggleAutocast(uint32 spellid, bool apply); - bool HasTPForSpell(uint32 spellid); - int32 GetTPForSpell(uint32 spellid); - - bool HasSpell(uint32 spell) const; - void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; } - - void LearnPetPassives(); - void CastPetAuras(bool current); - void CastPetAura(PetAura const* aura); - - void _LoadSpellCooldowns(); - void _SaveSpellCooldowns(); - void _LoadAuras(uint32 timediff); - void _SaveAuras(); - void _LoadSpells(); - void _SaveSpells(); - - bool addSpell(uint16 spell_id, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, uint16 slot_id=0xffff, PetSpellType type = PETSPELL_NORMAL); - bool learnSpell(uint16 spell_id); - void removeSpell(uint16 spell_id); - bool _removeSpell(uint16 spell_id); - - PetSpellMap m_spells; - TeachSpellMap m_teachspells; - AutoSpellList m_autospells; - - void InitPetCreateSpells(); - void CheckLearning(uint32 spellid); - uint32 resetTalentsCost() const; - - void SetTP(int32 TP); - int32 GetDispTP(); - - int32 m_TrainingPoints; - uint32 m_resetTalentsCost; - time_t m_resetTalentsTime; - - uint64 GetAuraUpdateMask() { return m_auraUpdateMask; } - void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); } - void ResetAuraUpdateMask() { m_auraUpdateMask = 0; } - - DeclinedName const* GetDeclinedNames() const { return m_declinedname; } - - bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved) - protected: - uint32 m_regenTimer; - uint32 m_happinessTimer; - uint32 m_loyaltyTimer; - PetType m_petType; - int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets) - int32 m_loyaltyPoints; - int32 m_bonusdamage; - uint64 m_auraUpdateMask; - - DeclinedName *m_declinedname; - - private: - void SaveToDB(uint32, uint8) // overwrited of Creature::SaveToDB - don't must be called - { - assert(false); - } - void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called - { - assert(false); - } -}; -#endif +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TRINITYCORE_PET_H +#define TRINITYCORE_PET_H + +#include "ObjectDefines.h" +#include "Creature.h" +#include "Unit.h" + +enum PetType +{ + SUMMON_PET = 0, + HUNTER_PET = 1, + GUARDIAN_PET = 2, + MINI_PET = 3, + MAX_PET_TYPE = 4 +}; + +extern char const* petTypeSuffix[MAX_PET_TYPE]; + +enum PetSaveMode +{ + PET_SAVE_AS_DELETED =-1, + PET_SAVE_AS_CURRENT = 0, + PET_SAVE_IN_STABLE_SLOT_1 = 1, + PET_SAVE_IN_STABLE_SLOT_2 = 2, + PET_SAVE_NOT_IN_SLOT = 3 +}; + +enum HappinessState +{ + UNHAPPY = 1, + CONTENT = 2, + HAPPY = 3 +}; + +enum LoyaltyLevel +{ + REBELLIOUS = 1, + UNRULY = 2, + SUBMISSIVE = 3, + DEPENDABLE = 4, + FAITHFUL = 5, + BEST_FRIEND = 6 +}; + +enum PetSpellState +{ + PETSPELL_UNCHANGED = 0, + PETSPELL_CHANGED = 1, + PETSPELL_NEW = 2, + PETSPELL_REMOVED = 3 +}; + +enum PetSpellType +{ + PETSPELL_NORMAL = 0, + PETSPELL_FAMILY = 1, +}; + +struct PetSpell +{ + uint16 slotId; + uint16 active; + PetSpellState state : 16; + PetSpellType type : 16; +}; + +enum ActionFeedback +{ + FEEDBACK_NONE = 0, + FEEDBACK_PET_DEAD = 1, + FEEDBACK_NOTHING_TO_ATT = 2, + FEEDBACK_CANT_ATT_TARGET = 3 +}; + +enum PetTalk +{ + PET_TALK_SPECIAL_SPELL = 0, + PET_TALK_ATTACK = 1 +}; + +enum PetNameInvalidReason +{ + PET_NAME_INVALID = 1, + PET_NAME_NO_NAME = 2, + PET_NAME_TOO_SHORT = 3, + PET_NAME_TOO_LONG = 4, + PET_NAME_MIXED_LANGUAGES = 6, + PET_NAME_PROFANE = 7, + PET_NAME_RESERVED = 8, + PET_NAME_THREE_CONSECUTIVE = 11, + PET_NAME_INVALID_SPACE = 12, + PET_NAME_CONSECUTIVE_SPACES = 13, + PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14, + PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15, + PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 +}; + +typedef UNORDERED_MAP PetSpellMap; +typedef std::map TeachSpellMap; +typedef std::vector AutoSpellList; + +#define HAPPINESS_LEVEL_SIZE 333000 + +extern const uint32 LevelUpLoyalty[6]; +extern const uint32 LevelStartLoyalty[6]; + +#define ACTIVE_SPELLS_MAX 4 + +#define OWNER_MAX_DISTANCE 100 + +#define PET_FOLLOW_DIST 1 +#define PET_FOLLOW_ANGLE (M_PI/2) + +class Pet : public Creature +{ + public: + explicit Pet(PetType type = MAX_PET_TYPE); + virtual ~Pet(); + + void AddToWorld(); + void RemoveFromWorld(); + + PetType getPetType() const { return m_petType; } + void setPetType(PetType type) { m_petType = type; } + bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; } + bool isTemporarySummoned() const { return m_duration > 0; } + + bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number); + bool CreateBaseAtCreature( Creature* creature ); + bool LoadPetFromDB( Unit* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false ); + void SavePetToDB(PetSaveMode mode); + void Remove(PetSaveMode mode, bool returnreagent = false); + static void DeleteFromDB(uint32 guidlow); + + void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState + void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update + + uint8 GetPetAutoSpellSize() const { return m_autospells.size(); } + uint32 GetPetAutoSpellOnPos(uint8 pos) const + { + if (pos >= m_autospells.size()) + return 0; + else + return m_autospells[pos]; + } + + void RegenerateFocus(); + void LooseHappiness(); + void TickLoyaltyChange(); + void ModifyLoyalty(int32 addvalue); + HappinessState GetHappinessState(); + uint32 GetMaxLoyaltyPoints(uint32 level); + uint32 GetStartLoyaltyPoints(uint32 level); + void KillLoyaltyBonus(uint32 level); + uint32 GetLoyaltyLevel() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); } + void SetLoyaltyLevel(LoyaltyLevel level); + void GivePetXP(uint32 xp); + void GivePetLevel(uint32 level); + bool InitStatsForLevel(uint32 level); + bool HaveInDiet(ItemPrototype const* item) const; + uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel); + void SetDuration(int32 dur) { m_duration = dur; } + + int32 GetBonusDamage() { return m_bonusdamage; } + void SetBonusDamage(int32 damage) { m_bonusdamage = damage; } + + bool UpdateStats(Stats stat); + bool UpdateAllStats(); + void UpdateResistances(uint32 school); + void UpdateArmor(); + void UpdateMaxHealth(); + void UpdateMaxPower(Powers power); + void UpdateAttackPowerAndDamage(bool ranged = false); + void UpdateDamagePhysical(WeaponAttackType attType); + + bool CanTakeMoreActiveSpells(uint32 SpellIconID); + void ToggleAutocast(uint32 spellid, bool apply); + bool HasTPForSpell(uint32 spellid); + int32 GetTPForSpell(uint32 spellid); + + bool HasSpell(uint32 spell) const; + void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; } + + void LearnPetPassives(); + void CastPetAuras(bool current); + void CastPetAura(PetAura const* aura); + + void _LoadSpellCooldowns(); + void _SaveSpellCooldowns(); + void _LoadAuras(uint32 timediff); + void _SaveAuras(); + void _LoadSpells(); + void _SaveSpells(); + + bool addSpell(uint16 spell_id,uint16 active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, uint16 slot_id=0xffff, PetSpellType type = PETSPELL_NORMAL); + bool learnSpell(uint16 spell_id); + void removeSpell(uint16 spell_id); + bool _removeSpell(uint16 spell_id); + + PetSpellMap m_spells; + TeachSpellMap m_teachspells; + AutoSpellList m_autospells; + + void InitPetCreateSpells(); + void CheckLearning(uint32 spellid); + uint32 resetTalentsCost() const; + + void SetTP(int32 TP); + int32 GetDispTP(); + + int32 m_TrainingPoints; + uint32 m_resetTalentsCost; + time_t m_resetTalentsTime; + + uint64 GetAuraUpdateMask() { return m_auraUpdateMask; } + void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); } + void ResetAuraUpdateMask() { m_auraUpdateMask = 0; } + + DeclinedName const* GetDeclinedNames() const { return m_declinedname; } + + bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved) + protected: + uint32 m_regenTimer; + uint32 m_happinessTimer; + uint32 m_loyaltyTimer; + PetType m_petType; + int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets) + int32 m_loyaltyPoints; + int32 m_bonusdamage; + uint64 m_auraUpdateMask; + + DeclinedName *m_declinedname; + + private: + void SaveToDB(uint32, uint8) // overwrited of Creature::SaveToDB - don't must be called + { + assert(false); + } + void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called + { + assert(false); + } +}; +#endif diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h index a9c66fa3028..481598f71ea 100644 --- a/src/game/SharedDefines.h +++ b/src/game/SharedDefines.h @@ -248,7 +248,7 @@ enum ItemQualities #define SPELL_ATTR_EX_UNK14 0x00004000 // 14 #define SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY 0x00008000 // 15 remove auras on immunity #define SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE 0x00010000 // 16 unaffected by school immunity -#define SPELL_ATTR_EX_PET_NOT_AUTOCAST 0x00020000 // 17 +#define SPELL_ATTR_EX_UNK17 0x00020000 // 17 #define SPELL_ATTR_EX_UNK18 0x00040000 // 18 #define SPELL_ATTR_EX_UNK19 0x00080000 // 19 #define SPELL_ATTR_EX_REQ_COMBO_POINTS1 0x00100000 // 20 Req combo points on target diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 97bf4b0d109..07a0df04450 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -1,2120 +1,2077 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "SpellMgr.h" -#include "ObjectMgr.h" -#include "SpellAuraDefines.h" -#include "ProgressBar.h" -#include "Database/DBCStores.h" -#include "World.h" -#include "Chat.h" -#include "Spell.h" - -SpellMgr::SpellMgr() -{ -} - -SpellMgr::~SpellMgr() -{ -} - -SpellMgr& SpellMgr::Instance() -{ - static SpellMgr spellMgr; - return spellMgr; -} - -int32 GetSpellDuration(SpellEntry const *spellInfo) -{ - if(!spellInfo) - return 0; - SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); - if(!du) - return 0; - return (du->Duration[0] == -1) ? -1 : abs(du->Duration[0]); -} - -int32 GetSpellMaxDuration(SpellEntry const *spellInfo) -{ - if(!spellInfo) - return 0; - SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); - if(!du) - return 0; - return (du->Duration[2] == -1) ? -1 : abs(du->Duration[2]); -} - -uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell) -{ - SpellCastTimesEntry const *spellCastTimeEntry = sSpellCastTimesStore.LookupEntry(spellInfo->CastingTimeIndex); - - // not all spells have cast time index and this is all is pasiive abilities - if(!spellCastTimeEntry) - return 0; - - int32 castTime = spellCastTimeEntry->CastTime; - - if (spell) - { - if(Player* modOwner = spell->GetCaster()->GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CASTING_TIME, castTime, spell); - - if( !(spellInfo->Attributes & (SPELL_ATTR_UNK4|SPELL_ATTR_UNK5)) ) - castTime = int32(castTime * spell->GetCaster()->GetFloatValue(UNIT_MOD_CAST_SPEED)); - else - { - if (spell->IsRangedSpell() && !spell->IsAutoRepeat()) - castTime = int32(castTime * spell->GetCaster()->m_modAttackSpeedPct[RANGED_ATTACK]); - } - } - - if (spellInfo->Attributes & SPELL_ATTR_RANGED && (!spell || !(spell->IsAutoRepeat()))) - castTime += 500; - - return (castTime > 0) ? uint32(castTime) : 0; -} - -bool IsPassiveSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if (!spellInfo) - return false; - return (spellInfo->Attributes & SPELL_ATTR_PASSIVE) != 0; -} -/*not used for now so commented out -bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) -{ - SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); - SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - if(!spellInfo_1 || !spellInfo_2) return false; - if(spellInfo_1->Id == spellId_2) return false; - - if (spellInfo_1->Effect[effIndex_1] != spellInfo_2->Effect[effIndex_2] || - spellInfo_1->EffectMiscValue[effIndex_1] != spellInfo_2->EffectMiscValue[effIndex_2] || - spellInfo_1->EffectApplyAuraName[effIndex_1] != spellInfo_2->EffectApplyAuraName[effIndex_2]) - return false; - - return true; -}*/ - -int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) -{ - SpellEntry const*spellInfo_1 = sSpellStore.LookupEntry(spellId_1); - SpellEntry const*spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - if(!spellInfo_1 || !spellInfo_2) return 0; - if (spellId_1 == spellId_2) return 0; - - int32 diff = spellInfo_1->EffectBasePoints[effIndex_1] - spellInfo_2->EffectBasePoints[effIndex_2]; - if (spellInfo_1->EffectBasePoints[effIndex_1]+1 < 0 && spellInfo_2->EffectBasePoints[effIndex_2]+1 < 0) return -diff; - else return diff; -} - -SpellSpecific GetSpellSpecific(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return SPELL_NORMAL; - - switch(spellInfo->SpellFamilyName) - { - case SPELLFAMILY_MAGE: - { - // family flags 18(Molten), 25(Frost/Ice), 28(Mage) - if (spellInfo->SpellFamilyFlags & 0x12040000) - return SPELL_MAGE_ARMOR; - - if ((spellInfo->SpellFamilyFlags & 0x1000000) && spellInfo->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) - return SPELL_MAGE_POLYMORPH; - - break; - } - case SPELLFAMILY_WARRIOR: - { - if (spellInfo->SpellFamilyFlags & 0x00008000010000LL) - return SPELL_POSITIVE_SHOUT; - - break; - } - case SPELLFAMILY_WARLOCK: - { - // only warlock curses have this - if (spellInfo->Dispel == DISPEL_CURSE) - return SPELL_CURSE; - - // family flag 37 (only part spells have family name) - if (spellInfo->SpellFamilyFlags & 0x2000000000LL) - return SPELL_WARLOCK_ARMOR; - - //seed of corruption and corruption - if (spellInfo->SpellFamilyFlags & 0x1000000002LL) - return SPELL_WARLOCK_CORRUPTION; - break; - } - case SPELLFAMILY_HUNTER: - { - // only hunter stings have this - if (spellInfo->Dispel == DISPEL_POISON) - return SPELL_STING; - - break; - } - case SPELLFAMILY_PALADIN: - { - if (IsSealSpell(spellInfo)) - return SPELL_SEAL; - - if (spellInfo->SpellFamilyFlags & 0x10000100LL) - return SPELL_BLESSING; - - if ((spellInfo->SpellFamilyFlags & 0x00000820180400LL) && (spellInfo->AttributesEx3 & 0x200)) - return SPELL_JUDGEMENT; - - for (int i = 0; i < 3; i++) - { - // only paladin auras have this - if (spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY) - return SPELL_AURA; - } - break; - } - case SPELLFAMILY_SHAMAN: - { - if (IsElementalShield(spellInfo)) - return SPELL_ELEMENTAL_SHIELD; - - break; - } - - case SPELLFAMILY_POTION: - return spellmgr.GetSpellElixirSpecific(spellInfo->Id); - } - - // only warlock armor/skin have this (in additional to family cases) - if( spellInfo->SpellVisual == 130 && spellInfo->SpellIconID == 89) - { - return SPELL_WARLOCK_ARMOR; - } - - // only hunter aspects have this (but not all aspects in hunter family) - if( spellInfo->activeIconID == 122 && (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NATURE) && - (spellInfo->Attributes & 0x50000) != 0 && (spellInfo->Attributes & 0x9000010) == 0) - { - return SPELL_ASPECT; - } - - for(int i = 0; i < 3; i++) - if( spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && ( - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_CREATURES || - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_RESOURCES || - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_STEALTHED ) ) - return SPELL_TRACKER; - - // elixirs can have different families, but potion most ofc. - if(SpellSpecific sp = spellmgr.GetSpellElixirSpecific(spellInfo->Id)) - return sp; - - return SPELL_NORMAL; -} - -bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2) -{ - switch(spellSpec1) - { - case SPELL_SEAL: - case SPELL_BLESSING: - case SPELL_AURA: - case SPELL_STING: - case SPELL_CURSE: - case SPELL_ASPECT: - case SPELL_POSITIVE_SHOUT: - case SPELL_JUDGEMENT: - case SPELL_WARLOCK_CORRUPTION: - return spellSpec1==spellSpec2; - default: - return false; - } -} - -bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1,uint32 spellSpec2) -{ - switch(spellSpec1) - { - case SPELL_TRACKER: - case SPELL_WARLOCK_ARMOR: - case SPELL_MAGE_ARMOR: - case SPELL_ELEMENTAL_SHIELD: - case SPELL_MAGE_POLYMORPH: - return spellSpec1==spellSpec2; - case SPELL_BATTLE_ELIXIR: - return spellSpec2==SPELL_BATTLE_ELIXIR - || spellSpec2==SPELL_FLASK_ELIXIR; - case SPELL_GUARDIAN_ELIXIR: - return spellSpec2==SPELL_GUARDIAN_ELIXIR - || spellSpec2==SPELL_FLASK_ELIXIR; - case SPELL_FLASK_ELIXIR: - return spellSpec2==SPELL_BATTLE_ELIXIR - || spellSpec2==SPELL_GUARDIAN_ELIXIR - || spellSpec2==SPELL_FLASK_ELIXIR; - default: - return false; - } -} - -bool IsPositiveTarget(uint32 targetA, uint32 targetB) -{ - // non-positive targets - switch(targetA) - { - case TARGET_CHAIN_DAMAGE: - case TARGET_ALL_ENEMY_IN_AREA: - case TARGET_ALL_ENEMY_IN_AREA_INSTANT: - case TARGET_IN_FRONT_OF_CASTER: - case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: - case TARGET_CURRENT_ENEMY_COORDINATES: - case TARGET_SINGLE_ENEMY: - return false; - case TARGET_ALL_AROUND_CASTER: - return (targetB == TARGET_ALL_PARTY || targetB == TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER); - default: - break; - } - if (targetB) - return IsPositiveTarget(targetB, 0); - return true; -} - -bool IsPositiveEffect(uint32 spellId, uint32 effIndex) -{ - SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); - if (!spellproto) return false; - - switch(spellId) - { - case 23333: // BG spell - case 23335: // BG spell - case 34976: // BG spell - return true; - case 28441: // not positive dummy spell - case 37675: // Chaos Blast - return false; - } - - switch(spellproto->Effect[effIndex]) - { - // always positive effects (check before target checks that provided non-positive result in some case for positive effects) - case SPELL_EFFECT_HEAL: - case SPELL_EFFECT_LEARN_SPELL: - case SPELL_EFFECT_SKILL_STEP: - case SPELL_EFFECT_HEAL_PCT: - case SPELL_EFFECT_ENERGIZE_PCT: - return true; - - // non-positive aura use - case SPELL_EFFECT_APPLY_AURA: - case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND: - { - switch(spellproto->EffectApplyAuraName[effIndex]) - { - case SPELL_AURA_DUMMY: - { - // dummy aura can be positive or negative dependent from casted spell - switch(spellproto->Id) - { - case 13139: // net-o-matic special effect - case 23445: // evil twin - case 38637: // Nether Exhaustion (red) - case 38638: // Nether Exhaustion (green) - case 38639: // Nether Exhaustion (blue) - return false; - default: - break; - } - } break; - case SPELL_AURA_MOD_STAT: - case SPELL_AURA_MOD_DAMAGE_DONE: // dependent from bas point sign (negative -> negative) - case SPELL_AURA_MOD_HEALING_DONE: - { - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) - return false; - break; - } - case SPELL_AURA_ADD_TARGET_TRIGGER: - return true; - case SPELL_AURA_PERIODIC_TRIGGER_SPELL: - if(spellId != spellproto->EffectTriggerSpell[effIndex]) - { - uint32 spellTriggeredId = spellproto->EffectTriggerSpell[effIndex]; - SpellEntry const *spellTriggeredProto = sSpellStore.LookupEntry(spellTriggeredId); - - if(spellTriggeredProto) - { - // non-positive targets of main spell return early - for(int i = 0; i < 3; ++i) - { - // if non-positive trigger cast targeted to positive target this main cast is non-positive - // this will place this spell auras as debuffs - if(IsPositiveTarget(spellTriggeredProto->EffectImplicitTargetA[effIndex],spellTriggeredProto->EffectImplicitTargetB[effIndex]) && !IsPositiveEffect(spellTriggeredId,i)) - return false; - } - } - } - break; - case SPELL_AURA_PROC_TRIGGER_SPELL: - // many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example) - break; - case SPELL_AURA_MOD_STUN: //have positive and negative spells, we can't sort its correctly at this moment. - if(effIndex==0 && spellproto->Effect[1]==0 && spellproto->Effect[2]==0) - return false; // but all single stun aura spells is negative - - // Petrification - if(spellproto->Id == 17624) - return false; - break; - case SPELL_AURA_MOD_ROOT: - case SPELL_AURA_MOD_SILENCE: - case SPELL_AURA_GHOST: - case SPELL_AURA_PERIODIC_LEECH: - case SPELL_AURA_MOD_PACIFY_SILENCE: - case SPELL_AURA_MOD_STALKED: - case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: - return false; - case SPELL_AURA_PERIODIC_DAMAGE: // used in positive spells also. - // part of negative spell if casted at self (prevent cancel) - if(spellproto->EffectImplicitTargetA[effIndex] == TARGET_SELF) - return false; - break; - case SPELL_AURA_MOD_DECREASE_SPEED: // used in positive spells also - // part of positive spell if casted at self - if(spellproto->EffectImplicitTargetA[effIndex] != TARGET_SELF) - return false; - // but not this if this first effect (don't found batter check) - if(spellproto->Attributes & 0x4000000 && effIndex==0) - return false; - break; - case SPELL_AURA_TRANSFORM: - // some spells negative - switch(spellproto->Id) - { - case 36897: // Transporter Malfunction (race mutation to horde) - case 36899: // Transporter Malfunction (race mutation to alliance) - return false; - } - break; - case SPELL_AURA_MOD_SCALE: - // some spells negative - switch(spellproto->Id) - { - case 36900: // Soul Split: Evil! - case 36901: // Soul Split: Good - case 36893: // Transporter Malfunction (decrease size case) - case 36895: // Transporter Malfunction (increase size case) - return false; - } - break; - case SPELL_AURA_MECHANIC_IMMUNITY: - { - // non-positive immunities - switch(spellproto->EffectMiscValue[effIndex]) - { - case MECHANIC_BANDAGE: - case MECHANIC_SHIELD: - case MECHANIC_MOUNT: - case MECHANIC_INVULNERABILITY: - return false; - default: - break; - } - } break; - case SPELL_AURA_ADD_FLAT_MODIFIER: // mods - case SPELL_AURA_ADD_PCT_MODIFIER: - { - // non-positive mods - switch(spellproto->EffectMiscValue[effIndex]) - { - case SPELLMOD_COST: // dependent from bas point sign (negative -> positive) - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) > 0) - return false; - break; - default: - break; - } - } break; - case SPELL_AURA_MOD_HEALING_PCT: - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) - return false; - break; - case SPELL_AURA_MOD_SKILL: - if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) - return false; - break; - case SPELL_AURA_FORCE_REACTION: - if(spellproto->Id==42792) // Recently Dropped Flag (prevent cancel) - return false; - break; - default: - break; - } - break; - } - default: - break; - } - - // non-positive targets - if(!IsPositiveTarget(spellproto->EffectImplicitTargetA[effIndex],spellproto->EffectImplicitTargetB[effIndex])) - return false; - - // AttributesEx check - if(spellproto->AttributesEx & (1<<7)) - return false; - - // ok, positive - return true; -} - -bool IsPositiveSpell(uint32 spellId) -{ - SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); - if (!spellproto) return false; - - // spells with at least one negative effect are considered negative - // some self-applied spells have negative effects but in self casting case negative check ignored. - for (int i = 0; i < 3; i++) - if (!IsPositiveEffect(spellId, i)) - return false; - return true; -} - -bool IsSingleTargetSpell(SpellEntry const *spellInfo) -{ - // all other single target spells have if it has AttributesEx5 - if ( spellInfo->AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL ) - return true; - - // TODO - need found Judgements rule - switch(GetSpellSpecific(spellInfo->Id)) - { - case SPELL_JUDGEMENT: - return true; - } - - // single target triggered spell. - // Not real client side single target spell, but it' not triggered until prev. aura expired. - // This is allow store it in single target spells list for caster for spell proc checking - if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals)) - return true; - - return false; -} - -bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2) -{ - // TODO - need better check - // Equal icon and spellfamily - if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName && - spellInfo1->SpellIconID == spellInfo2->SpellIconID ) - return true; - - // TODO - need found Judgements rule - SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id); - // spell with single target specific types - switch(spec1) - { - case SPELL_JUDGEMENT: - if(GetSpellSpecific(spellInfo2->Id) == spec1) - return true; - break; - } - - return false; -} - -uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form) -{ - // talents that learn spells can have stance requirements that need ignore - // (this requirement only for client-side stance show in talent description) - if( GetTalentSpellCost(spellInfo->Id) > 0 && - (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) ) - return 0; - - uint32 stanceMask = (form ? 1 << (form - 1) : 0); - - if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance - return SPELL_FAILED_NOT_SHAPESHIFT; - - if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance - return 0; - - bool actAsShifted = false; - if (form > 0) - { - SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form); - if (!shapeInfo) - { - sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form); - return 0; - } - actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells - } - - if(actAsShifted) - { - if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted - return SPELL_FAILED_NOT_SHAPESHIFT; - else if (spellInfo->Stances != 0) // needs other shapeshift - return SPELL_FAILED_ONLY_SHAPESHIFT; - } - else - { - // needs shapeshift - if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0) - return SPELL_FAILED_ONLY_SHAPESHIFT; - } - - return 0; -} - -void SpellMgr::LoadSpellTargetPositions() -{ - mSpellTargetPositions.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 3 4 5 - QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell target coordinates", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - ++count; - - uint32 Spell_ID = fields[0].GetUInt32(); - - SpellTargetPosition st; - - st.target_mapId = fields[1].GetUInt32(); - st.target_X = fields[2].GetFloat(); - st.target_Y = fields[3].GetFloat(); - st.target_Z = fields[4].GetFloat(); - st.target_Orientation = fields[5].GetFloat(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID); - if(!spellInfo) - { - sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID); - continue; - } - - bool found = false; - for(int i = 0; i < 3; ++i) - { - if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES ) - { - found = true; - break; - } - } - if(!found) - { - sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID); - continue; - } - - MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId); - if(!mapEntry) - { - sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId); - continue; - } - - if(st.target_X==0 && st.target_Y==0 && st.target_Z==0) - { - sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID); - continue; - } - - mSpellTargetPositions[Spell_ID] = st; - - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell teleport coordinates", count ); -} - -void SpellMgr::LoadSpellAffects() -{ - mSpellAffectMap.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT entry, effectId, SpellFamilyMask FROM spell_affect"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell affect definitions", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 entry = fields[0].GetUInt16(); - uint8 effectId = fields[1].GetUInt8(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); - - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` does not exist", entry); - continue; - } - - if (effectId >= 3) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have invalid effect index (%u)", entry,effectId); - continue; - } - - if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER ) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have not SPELL_AURA_ADD_FLAT_MODIFIER (%u) or SPELL_AURA_ADD_PCT_MODIFIER (%u) or SPELL_AURA_ADD_TARGET_TRIGGER (%u) for effect index (%u)", entry,SPELL_AURA_ADD_FLAT_MODIFIER,SPELL_AURA_ADD_PCT_MODIFIER,SPELL_AURA_ADD_TARGET_TRIGGER,effectId); - continue; - } - - uint64 spellAffectMask = fields[2].GetUInt64(); - - // Spell.dbc have own data for low part of SpellFamilyMask - if( spellInfo->EffectItemType[effectId]) - { - if(spellInfo->EffectItemType[effectId] == spellAffectMask) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have redundant (same with EffectItemType%d) data for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); - continue; - } - - // 24429 have wrong data in EffectItemType and overwrites by DB, possible bug in client - if(spellInfo->Id!=24429 && spellInfo->EffectItemType[effectId] != spellAffectMask) - { - sLog.outErrorDb("Spell %u listed in `spell_affect` have different low part from EffectItemType%d for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); - continue; - } - } - - mSpellAffectMap.insert(SpellAffectMap::value_type((entry<<8) + effectId,spellAffectMask)); - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell affect definitions", count ); - - for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) - { - SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); - if (!spellInfo) - continue; - - for (int effectId = 0; effectId < 3; ++effectId) - { - if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || - (spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && - spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER) ) - continue; - - if(spellInfo->EffectItemType[effectId] != 0) - continue; - - if(mSpellAffectMap.find((id<<8) + effectId) != mSpellAffectMap.end()) - continue; - - sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u",id,spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId); - } - } -} - -bool SpellMgr::IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const -{ - // false for spellInfo == NULL - if (!spellInfo) - return false; - - SpellEntry const *affect_spell = sSpellStore.LookupEntry(spellId); - // false for affect_spell == NULL - if (!affect_spell) - return false; - - // False if spellFamily not equal - if (affect_spell->SpellFamilyName != spellInfo->SpellFamilyName) - return false; - - // If familyFlags == 0 - if (!familyFlags) - { - // Get it from spellAffect table - familyFlags = GetSpellAffectMask(spellId,effectId); - // false if familyFlags == 0 - if (!familyFlags) - return false; - } - - // true - if (familyFlags & spellInfo->SpellFamilyFlags) - return true; - - return false; -} - -void SpellMgr::LoadSpellProcEvents() -{ - mSpellProcEventMap.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 3 4 5 6 7 8 - QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, Category, SkillID, SpellFamilyName, SpellFamilyMask, procFlags, ppmRate, cooldown FROM spell_proc_event"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell proc event conditions", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 entry = fields[0].GetUInt16(); - - if (!sSpellStore.LookupEntry(entry)) - { - sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry); - continue; - } - - SpellProcEventEntry spe; - - spe.schoolMask = fields[1].GetUInt32(); - spe.category = fields[2].GetUInt32(); - spe.skillId = fields[3].GetUInt32(); - spe.spellFamilyName = fields[4].GetUInt32(); - spe.spellFamilyMask = fields[5].GetUInt64(); - spe.procFlags = fields[6].GetUInt32(); - spe.ppmRate = fields[7].GetFloat(); - spe.cooldown = fields[8].GetUInt32(); - - mSpellProcEventMap[entry] = spe; - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell proc event conditions", count ); - - /* - // Commented for now, as it still produces many errors (still quite many spells miss spell_proc_event) - for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) - { - SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); - if (!spellInfo) - continue; - - bool found = false; - for (int effectId = 0; effectId < 3; ++effectId) - { - // at this moment check only SPELL_AURA_PROC_TRIGGER_SPELL - if( spellInfo->EffectApplyAuraName[effectId] == SPELL_AURA_PROC_TRIGGER_SPELL ) - { - found = true; - break; - } - } - - if(!found) - continue; - - if(GetSpellProcEvent(id)) - continue; - - sLog.outErrorDb("Spell %u (%s) misses spell_proc_event",id,spellInfo->SpellName[sWorld.GetDBClang()]); - } - */ -} - -bool SpellMgr::IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ) -{ - if((procFlags & spellProcEvent->procFlags) == 0) - return false; - - // Additional checks in case spell cast/hit/crit is the event - // Check (if set) school, category, skill line, spell talent mask - if(spellProcEvent->schoolMask && (!procSpell || (GetSpellSchoolMask(procSpell) & spellProcEvent->schoolMask) == 0)) - return false; - if(spellProcEvent->category && (!procSpell || procSpell->Category != spellProcEvent->category)) - return false; - if(spellProcEvent->skillId) - { - if (!procSpell) - return false; - - SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(procSpell->Id); - SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(procSpell->Id); - - bool found = false; - for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) - { - if(_spell_idx->second->skillId == spellProcEvent->skillId) - { - found = true; - break; - } - } - if (!found) - return false; - } - if(spellProcEvent->spellFamilyName && (!procSpell || spellProcEvent->spellFamilyName != procSpell->SpellFamilyName)) - return false; - if(spellProcEvent->spellFamilyMask && (!procSpell || (spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags) == 0)) - return false; - - return true; -} - -void SpellMgr::LoadSpellElixirs() -{ - mSpellElixirs.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 - QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell elixir definitions", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 entry = fields[0].GetUInt16(); - uint8 mask = fields[1].GetUInt8(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); - - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry); - continue; - } - - mSpellElixirs[entry] = mask; - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell elixir definitions", count ); -} - -void SpellMgr::LoadSpellThreats() -{ - sSpellThreatStore.Free(); // for reload - - sSpellThreatStore.Load(); - - sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount ); - sLog.outString(); -} - -bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const -{ - SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - if(!spellInfo_1 || !spellInfo_2) return false; - if(spellInfo_1->Id == spellId_2) return false; - - return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2); -} - -bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo) -{ - if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH) - return false; - if(IsProfessionSpell(spellInfo->Id)) - return false; - - // All stance spells. if any better way, change it. - for (int i = 0; i < 3; i++) - { - // Paladin aura Spell - if(spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN - && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_PARTY) - return false; - // Druid form Spell - if(spellInfo->SpellFamilyName == SPELLFAMILY_DRUID - && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA - && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) - return false; - // Rogue Stealth - if(spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE - && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA - && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) - return false; - } - return true; -} - -bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool isFromTheSameCaster ) const -{ - SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); - SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); - - if(!spellInfo_1 || !spellInfo_2) - return false; - - SpellSpecific spellId_spec_1 = GetSpellSpecific(spellId_1); - SpellSpecific spellId_spec_2 = GetSpellSpecific(spellId_2); - if (spellId_spec_1 && spellId_spec_2) - if (IsSingleFromSpellSpecificPerTarget(spellId_spec_1,spellId_spec_2) - || (IsSingleFromSpellSpecificPerCaster(spellId_spec_1,spellId_spec_2) && isFromTheSameCaster)) - return true; - - if(spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName) - return false; - - if(!spellInfo_1->SpellFamilyName) // generic spells - { - if(!spellInfo_1->SpellIconID - || spellInfo_1->SpellIconID != spellInfo_2->SpellIconID) - return false; - } - - //if both elixirs are not battle/guardian/potions/flasks then always stack - else if ((spellInfo_1->SpellFamilyName == SPELLFAMILY_POTION) - &&(spellId_spec_1 || spellId_spec_2)) - return false; - - else if (spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags) - return false; - - for(uint32 i = 0; i < 3; ++i) - { - if(spellInfo_1->Effect[i] != spellInfo_2->Effect[i]) - return false; - if (spellInfo_1->EffectApplyAuraName[i] || spellInfo_2->EffectApplyAuraName[i]) - { - if(spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i] - || spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i]) - // need itemtype check? need to find an example - return false; - else if (!isFromTheSameCaster) - switch(spellInfo_1->EffectApplyAuraName[i]) - { - //spells with these auras from different casters will stack - case SPELL_AURA_PERIODIC_DAMAGE: - case SPELL_AURA_PERIODIC_HEAL: - case SPELL_AURA_PERIODIC_TRIGGER_SPELL: - case SPELL_AURA_PERIODIC_ENERGIZE: - case SPELL_AURA_PERIODIC_MANA_LEECH: - case SPELL_AURA_PERIODIC_LEECH: - //exception for shaman positive totems with these auras - if ((spellInfo_1->SpellFamilyName != SPELLFAMILY_SHAMAN) - ||(spellInfo_1->Effect[i]!=SPELL_AURA_MOD_INCREASE_ENERGY)) - return false; - default: - break; - } - } - } - return true; -} - -bool SpellMgr::IsProfessionSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return false; - - if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) - return false; - - uint32 skill = spellInfo->EffectMiscValue[1]; - - return IsProfessionSkill(skill); -} - -bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return false; - - if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) - return false; - - uint32 skill = spellInfo->EffectMiscValue[1]; - - return IsPrimaryProfessionSkill(skill); -} - -bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const -{ - return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1; -} - -SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const -{ - // ignore passive spells - if(IsPassiveSpell(spellInfo->Id)) - return spellInfo; - - bool needRankSelection = false; - for(int i=0;i<3;i++) - { - if( IsPositiveEffect(spellInfo->Id, i) && ( - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY - ) ) - { - needRankSelection = true; - break; - } - } - - // not required - if(!needRankSelection) - return spellInfo; - - for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId)) - { - SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId); - if(!nextSpellInfo) - break; - - // if found appropriate level - if(playerLevel + 10 >= nextSpellInfo->spellLevel) - return nextSpellInfo; - - // one rank less then - } - - // not found - return NULL; -} - -void SpellMgr::LoadSpellChains() -{ - mSpellChains.clear(); // need for reload case - mSpellChainsNext.clear(); // need for reload case - - QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain"); - if(result == NULL) - { - barGoLink bar( 1 ); - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded 0 spell chain records" ); - sLog.outErrorDb("`spell_chains` table is empty!"); - return; - } - - uint32 count = 0; - - barGoLink bar( result->GetRowCount() ); - do - { - bar.step(); - Field *fields = result->Fetch(); - - uint32 spell_id = fields[0].GetUInt32(); - - SpellChainNode node; - node.prev = fields[1].GetUInt32(); - node.first = fields[2].GetUInt32(); - node.rank = fields[3].GetUInt8(); - node.req = fields[4].GetUInt32(); - - if(!sSpellStore.LookupEntry(spell_id)) - { - sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id); - continue; - } - - if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev)) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(!sSpellStore.LookupEntry(node.first)) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell) - if( (spell_id == node.first) != (node.rank <= 1) || - (spell_id == node.first) != (node.prev == 0) || - (node.rank <= 1) != (node.prev == 0) ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(node.req!=0 && !sSpellStore.LookupEntry(node.req)) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - // talents not required data in spell chain for work, but must be checked if present for intergrity - if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id)) - { - if(node.rank!=pos->rank+1) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id)) - { - if(node.first!=talentEntry->RankID[0]) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1]) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - - if(node.req!=talentEntry->DependsOnSpell) - { - sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.", - spell_id,node.prev,node.first,node.rank,node.req); - continue; - } - } - } - - mSpellChains[spell_id] = node; - - if(node.prev) - mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id)); - - if(node.req) - mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id)); - - ++count; - } while( result->NextRow() ); - - // additional integrity checks - for(SpellChainMap::iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i) - { - if(i->second.prev) - { - SpellChainMap::iterator i_prev = mSpellChains.find(i->second.prev); - if(i_prev == mSpellChains.end()) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); - } - else if( i_prev->second.first != i->second.first ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different first spell in chain compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); - } - else if( i_prev->second.rank+1 != i->second.rank ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different rank compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); - } - } - - if(i->second.req) - { - SpellChainMap::iterator i_req = mSpellChains.find(i->second.req); - if(i_req == mSpellChains.end()) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); - } - else if( i_req->second.first == i->second.first ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell from same spell chain (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); - } - else if( i_req->second.req ) - { - sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell with required spell (prev: %u, first: %u, rank: %d, req: %u).", - i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, - i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); - } - } - } - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell chain records", count ); -} - -void SpellMgr::LoadSpellLearnSkills() -{ - mSpellLearnSkills.clear(); // need for reload case - - // search auto-learned skills and add its to map also for use in unlearn spells/talents - uint32 dbc_count = 0; - for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) - { - SpellEntry const* entry = sSpellStore.LookupEntry(spell); - - if(!entry) - continue; - - for(int i = 0; i < 3; ++i) - { - if(entry->Effect[i]==SPELL_EFFECT_SKILL) - { - SpellLearnSkillNode dbc_node; - dbc_node.skill = entry->EffectMiscValue[i]; - if ( dbc_node.skill != SKILL_RIDING ) - dbc_node.value = 1; - else - dbc_node.value = (entry->EffectBasePoints[i]+1)*75; - dbc_node.maxvalue = (entry->EffectBasePoints[i]+1)*75; - - SpellLearnSkillNode const* db_node = GetSpellLearnSkill(spell); - - mSpellLearnSkills[spell] = dbc_node; - ++dbc_count; - break; - } - } - } - - sLog.outString(); - sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count ); -} - -void SpellMgr::LoadSpellLearnSpells() -{ - mSpellLearnSpells.clear(); // need for reload case - - QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID FROM spell_learn_spell"); - if(!result) - { - barGoLink bar( 1 ); - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded 0 spell learn spells" ); - sLog.outErrorDb("`spell_learn_spell` table is empty!"); - return; - } - - uint32 count = 0; - - barGoLink bar( result->GetRowCount() ); - do - { - bar.step(); - Field *fields = result->Fetch(); - - uint32 spell_id = fields[0].GetUInt32(); - - SpellLearnSpellNode node; - node.spell = fields[1].GetUInt32(); - node.autoLearned= false; - - if(!sSpellStore.LookupEntry(spell_id)) - { - sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id); - continue; - } - - if(!sSpellStore.LookupEntry(node.spell)) - { - sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell); - continue; - } - - mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node)); - - ++count; - } while( result->NextRow() ); - - delete result; - - // search auto-learned spells and add its to map also for use in unlearn spells/talents - uint32 dbc_count = 0; - for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) - { - SpellEntry const* entry = sSpellStore.LookupEntry(spell); - - if(!entry) - continue; - - for(int i = 0; i < 3; ++i) - { - if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL) - { - SpellLearnSpellNode dbc_node; - dbc_node.spell = entry->EffectTriggerSpell[i]; - dbc_node.autoLearned = true; - - SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell); - SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell); - - bool found = false; - for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr) - { - if(itr->second.spell == dbc_node.spell) - { - sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.", - spell,dbc_node.spell); - found = true; - break; - } - } - - if(!found) // add new spell-spell pair if not found - { - mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node)); - ++dbc_count; - } - } - } - } - - sLog.outString(); - sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count ); -} - -void SpellMgr::LoadSpellScriptTarget() -{ - mSpellScriptTarget.clear(); // need for reload case - - uint32 count = 0; - - QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target"); - - if(!result) - { - barGoLink bar(1); - - bar.step(); - - sLog.outString(); - sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty."); - return; - } - - barGoLink bar(result->GetRowCount()); - - do - { - Field *fields = result->Fetch(); - bar.step(); - - uint32 spellId = fields[0].GetUInt32(); - uint32 type = fields[1].GetUInt32(); - uint32 targetEntry = fields[2].GetUInt32(); - - SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); - - if(!spellProto) - { - sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry); - continue; - } - - /*bool targetfound = false; - for(int i = 0; i <3; ++i) - { - if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT || - spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT || - spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES || - spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES ) - { - targetfound = true; - break; - } - } - if(!targetfound) - { - sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not have any implicit target TARGET_SCRIPT(38) or TARGET_SCRIPT_COORDINATES (46).",spellId,targetEntry); - continue; - }*/ - - if( type >= MAX_SPELL_TARGET_TYPE ) - { - sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry); - continue; - } - - switch(type) - { - case SPELL_TARGET_TYPE_GAMEOBJECT: - { - if( targetEntry==0 ) - break; - - if(!sGOStorage.LookupEntry(targetEntry)) - { - sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry); - continue; - } - break; - } - default: - { - if( targetEntry==0 ) - { - sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type); - continue; - } - if(!sCreatureStorage.LookupEntry(targetEntry)) - { - sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry); - continue; - } - const CreatureInfo* cInfo = sCreatureStorage.LookupEntry(targetEntry); - - if(spellId == 30427 && !cInfo->SkinLootId) - { - sLog.outErrorDb("Table `spell_script_target` has creature %u as a target of spellid 30427, but this creature has no skinlootid. Gas extraction will not work!", cInfo->Entry); - continue; - } - break; - } - } - - mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry))); - - ++count; - } while (result->NextRow()); - - delete result; - - // Check all spells - /* Disabled (lot errors at this moment) - for(uint32 i = 1; i < sSpellStore.nCount; ++i) - { - SpellEntry const * spellInfo = sSpellStore.LookupEntry(i); - if(!spellInfo) - continue; - - bool found = false; - for(int j=0; j<3; ++j) - { - if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT ) - { - SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id); - SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id); - if(lower==upper) - { - sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = %u (TARGET_SCRIPT), but does not have record in `spell_script_target`",spellInfo->Id,TARGET_SCRIPT); - break; // effects of spell - } - } - } - } - */ - - sLog.outString(); - sLog.outString(">> Loaded %u Spell Script Targets", count); -} - -void SpellMgr::LoadSpellPetAuras() -{ - mSpellPetAuraMap.clear(); // need for reload case - - uint32 count = 0; - - // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras"); - if( !result ) - { - - barGoLink bar( 1 ); - - bar.step(); - - sLog.outString(); - sLog.outString( ">> Loaded %u spell pet auras", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - uint16 spell = fields[0].GetUInt16(); - uint16 pet = fields[1].GetUInt16(); - uint16 aura = fields[2].GetUInt16(); - - SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell); - if(itr != mSpellPetAuraMap.end()) - { - itr->second.AddAura(pet, aura); - } - else - { - SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell); - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell); - continue; - } - int i = 0; - for(; i < 3; ++i) - if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) || - spellInfo->Effect[i] == SPELL_EFFECT_DUMMY) - break; - - if(i == 3) - { - sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell); - continue; - } - - SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura); - if (!spellInfo2) - { - sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura); - continue; - } - - PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->EffectBasePoints[i] + spellInfo->EffectBaseDice[i]); - mSpellPetAuraMap[spell] = pa; - } - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u spell pet auras", count ); -} - -// set data in core for now -void SpellMgr::LoadSpellCustomAttr() -{ - SpellEntry *tempSpell; - for(uint32 i = 0; i < GetSpellStore()->GetNumRows(); ++i) - { - tempSpell = (SpellEntry*)GetSpellStore()->LookupEntry(i); - if(!tempSpell) - continue; - - mSpellCustomAttrMap[tempSpell->Id] = 0; - - for(uint32 i = 0; i < 3; ++i) - { - switch(tempSpell->EffectApplyAuraName[i]) - { - case SPELL_AURA_PERIODIC_DAMAGE: - case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: - case SPELL_AURA_PERIODIC_LEECH: - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_DAMAGE; - break; - case SPELL_AURA_PERIODIC_HEAL: - case SPELL_AURA_OBS_MOD_HEALTH: - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_HEAL; - break; - default: - break; - } - } - - if(tempSpell->SpellVisual == 3879) - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_BACK; - - switch(tempSpell->Id) - { - case 26029: // dark glare - case 37433: // spout - case 43140: case 43215: // flame breath - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_LINE; - break; - case 24340: case 26558: case 28884: // Meteor - case 36837: case 38903: case 41276: // Meteor - case 26789: // Shard of the Fallen Star - case 31436: // Malevolent Cleave - case 35181: // Dive Bomb - case 40810: case 43267: case 43268: // Saber Lash - case 42384: // Brutal Swipe - case 45150: // Meteor Slash - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_SHARE_DAMAGE; - break; - case 44978: case 45001: case 45002: // Wild Magic - case 45004: case 45006: case 45010: // Wild Magic - case 31347: // Doom - case 41635: // Prayer of Mending - case 44869: // Spectral Blast - case 45027: // Revitalize - case 45976: // Muru Portal Channel - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; - tempSpell->MaxAffectedTargets = 1; - break; - case 41376: // Spite - case 39992: // Needle Spine - mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; - tempSpell->MaxAffectedTargets = 3; - break; - case 8122: case 8124: case 10888: case 10890: // Psychic Scream - tempSpell->Attributes |= SPELL_ATTR_BREAKABLE_BY_DAMAGE; - break; - default: - break; - } - } -} - -void SpellMgr::LoadSpellLinked() -{ - mSpellLinkedMap.clear(); // need for reload case - uint32 count = 0; - - // 0 1 2 - QueryResult *result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell"); - if( !result ) - { - barGoLink bar( 1 ); - bar.step(); - sLog.outString(); - sLog.outString( ">> Loaded %u linked spells", count ); - return; - } - - barGoLink bar( result->GetRowCount() ); - - do - { - Field *fields = result->Fetch(); - - bar.step(); - - int32 trigger = fields[0].GetInt32(); - int32 effect = fields[1].GetInt32(); - int32 type = fields[2].GetInt32(); - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(trigger)); - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(trigger)); - continue; - } - spellInfo = sSpellStore.LookupEntry(abs(effect)); - if (!spellInfo) - { - sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(effect)); - continue; - } - - if(type) //we will find a better way when more types are needed - trigger += 1000000; - mSpellLinkedMap[trigger].push_back(effect); - - ++count; - } while( result->NextRow() ); - - delete result; - - sLog.outString(); - sLog.outString( ">> Loaded %u linked spells", count ); -} - -/// Some checks for spells, to prevent adding depricated/broken spells for trainers, spell book, etc -bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg) -{ - // not exist - if(!spellInfo) - return false; - - bool need_check_reagents = false; - - // check effects - for(int i=0; i<3; ++i) - { - switch(spellInfo->Effect[i]) - { - case 0: - continue; - - // craft spell for crafting non-existed item (break client recipes list show) - case SPELL_EFFECT_CREATE_ITEM: - { - if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] )) - { - if(msg) - { - if(pl) - ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); - else - sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); - } - return false; - } - - need_check_reagents = true; - break; - } - case SPELL_EFFECT_LEARN_SPELL: - { - SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[0]); - if( !IsSpellValid(spellInfo2,pl,msg) ) - { - if(msg) - { - if(pl) - ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); - else - sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); - } - return false; - } - break; - } - } - } - - if(need_check_reagents) - { - for(int j = 0; j < 8; ++j) - { - if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] )) - { - if(msg) - { - if(pl) - ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); - else - sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); - } - return false; - } - } - } - - return true; -} - -bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id) -{ - // normal case - if( spellInfo->AreaId && spellInfo->AreaId != zone_id && spellInfo->AreaId != area_id ) - return false; - - // elixirs (all area dependent elixirs have family SPELLFAMILY_POTION, use this for speedup) - if(spellInfo->SpellFamilyName==SPELLFAMILY_POTION) - { - if(uint32 mask = spellmgr.GetSpellElixirMask(spellInfo->Id)) - { - if(mask & ELIXIR_UNSTABLE_MASK) - { - // in the Blade's Edge Mountains Plateaus and Gruul's Lair. - return zone_id ==3522 || map_id==565; - } - if(mask & ELIXIR_SHATTRATH_MASK) - { - // in Tempest Keep, Serpentshrine Cavern, Caverns of Time: Mount Hyjal, Black Temple - // TODO: and the Sunwell Plateau - if(zone_id ==3607 || map_id==534 || map_id==564) - return true; - - MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); - if(!mapEntry) - return false; - - return mapEntry->multimap_id==206; - } - - // elixirs not have another limitations - return true; - } - } - - // special cases zone check (maps checked by multimap common id) - switch(spellInfo->Id) - { - case 41618: - case 41620: - { - MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); - if(!mapEntry) - return false; - - return mapEntry->multimap_id==206; - } - - case 41617: - case 41619: - { - MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); - if(!mapEntry) - return false; - - return mapEntry->multimap_id==207; - } - // Dragonmaw Illusion - case 40216: - case 42016: - { - if ( area_id != 3759 && area_id != 3966 && area_id != 3939 ) - return false; - break; - } - } - - return true; -} - -void SpellMgr::LoadSkillLineAbilityMap() -{ - mSkillLineAbilityMap.clear(); - - uint32 count = 0; - - for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); i++) - { - SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i); - if(!SkillInfo) - continue; - - mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo)); - ++count; - } - - sLog.outString(); - sLog.outString(">> Loaded %u SkillLineAbility MultiMap", count); -} - -DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered) -{ - // Explicit Diminishing Groups - switch(spellproto->SpellFamilyName) - { - case SPELLFAMILY_MAGE: - { - // Polymorph - if ((spellproto->SpellFamilyFlags & 0x00001000000LL) && spellproto->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) - return DIMINISHING_POLYMORPH; - break; - } - case SPELLFAMILY_ROGUE: - { - // Kidney Shot - if (spellproto->SpellFamilyFlags & 0x00000200000LL) - return DIMINISHING_KIDNEYSHOT; - // Blind - else if (spellproto->SpellFamilyFlags & 0x00001000000LL) - return DIMINISHING_BLIND_CYCLONE; - break; - } - case SPELLFAMILY_WARLOCK: - { - // Death Coil - if (spellproto->SpellFamilyFlags & 0x00000080000LL) - return DIMINISHING_DEATHCOIL; - // Fear - else if (spellproto->SpellFamilyFlags & 0x40840000000LL) - return DIMINISHING_WARLOCK_FEAR; - // Curses/etc - else if (spellproto->SpellFamilyFlags & 0x00080000000LL) - return DIMINISHING_LIMITONLY; - break; - } - case SPELLFAMILY_DRUID: - { - // Cyclone - if (spellproto->SpellFamilyFlags & 0x02000000000LL) - return DIMINISHING_BLIND_CYCLONE; - break; - } - case SPELLFAMILY_WARRIOR: - { - // Hamstring - limit duration to 10s in PvP - if (spellproto->SpellFamilyFlags & 0x00000000002LL) - return DIMINISHING_LIMITONLY; - break; - } - default: - break; - } - - // Get by mechanic - for (uint8 i=0;i<3;++i) - { - if (spellproto->Mechanic == MECHANIC_STUN || spellproto->EffectMechanic[i] == MECHANIC_STUN) - return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN; - else if (spellproto->Mechanic == MECHANIC_SLEEP || spellproto->EffectMechanic[i] == MECHANIC_SLEEP) - return DIMINISHING_SLEEP; - else if (spellproto->Mechanic == MECHANIC_ROOT || spellproto->EffectMechanic[i] == MECHANIC_ROOT) - return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT; - else if (spellproto->Mechanic == MECHANIC_FEAR || spellproto->EffectMechanic[i] == MECHANIC_FEAR) - return DIMINISHING_FEAR; - else if (spellproto->Mechanic == MECHANIC_CHARM || spellproto->EffectMechanic[i] == MECHANIC_CHARM) - return DIMINISHING_CHARM; - else if (spellproto->Mechanic == MECHANIC_SILENCE || spellproto->EffectMechanic[i] == MECHANIC_SILENCE) - return DIMINISHING_SILENCE; - else if (spellproto->Mechanic == MECHANIC_DISARM || spellproto->EffectMechanic[i] == MECHANIC_DISARM) - return DIMINISHING_DISARM; - else if (spellproto->Mechanic == MECHANIC_FREEZE || spellproto->EffectMechanic[i] == MECHANIC_FREEZE) - return DIMINISHING_FREEZE; - else if (spellproto->Mechanic == MECHANIC_KNOCKOUT|| spellproto->EffectMechanic[i] == MECHANIC_KNOCKOUT || - spellproto->Mechanic == MECHANIC_SAPPED || spellproto->EffectMechanic[i] == MECHANIC_SAPPED) - return DIMINISHING_KNOCKOUT; - else if (spellproto->Mechanic == MECHANIC_BANISH || spellproto->EffectMechanic[i] == MECHANIC_BANISH) - return DIMINISHING_BANISH; - } - - return DIMINISHING_NONE; -} - -bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group) -{ - switch(group) - { - case DIMINISHING_CONTROL_STUN: - case DIMINISHING_TRIGGER_STUN: - case DIMINISHING_KIDNEYSHOT: - case DIMINISHING_SLEEP: - case DIMINISHING_CONTROL_ROOT: - case DIMINISHING_TRIGGER_ROOT: - case DIMINISHING_FEAR: - case DIMINISHING_WARLOCK_FEAR: - case DIMINISHING_CHARM: - case DIMINISHING_POLYMORPH: - case DIMINISHING_FREEZE: - case DIMINISHING_KNOCKOUT: - case DIMINISHING_BLIND_CYCLONE: - case DIMINISHING_BANISH: - case DIMINISHING_LIMITONLY: - return true; - } - return false; -} - -DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group) -{ - switch(group) - { - case DIMINISHING_BLIND_CYCLONE: - case DIMINISHING_CONTROL_STUN: - case DIMINISHING_TRIGGER_STUN: - case DIMINISHING_KIDNEYSHOT: - return DRTYPE_ALL; - case DIMINISHING_SLEEP: - case DIMINISHING_CONTROL_ROOT: - case DIMINISHING_TRIGGER_ROOT: - case DIMINISHING_FEAR: - case DIMINISHING_CHARM: - case DIMINISHING_POLYMORPH: - case DIMINISHING_SILENCE: - case DIMINISHING_DISARM: - case DIMINISHING_DEATHCOIL: - case DIMINISHING_FREEZE: - case DIMINISHING_BANISH: - case DIMINISHING_WARLOCK_FEAR: - case DIMINISHING_KNOCKOUT: - return DRTYPE_PLAYER; - } - - return DRTYPE_NONE; -} +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "SpellMgr.h" +#include "ObjectMgr.h" +#include "SpellAuraDefines.h" +#include "ProgressBar.h" +#include "Database/DBCStores.h" +#include "World.h" +#include "Chat.h" +#include "Spell.h" + +SpellMgr::SpellMgr() +{ +} + +SpellMgr::~SpellMgr() +{ +} + +SpellMgr& SpellMgr::Instance() +{ + static SpellMgr spellMgr; + return spellMgr; +} + +int32 GetSpellDuration(SpellEntry const *spellInfo) +{ + if(!spellInfo) + return 0; + SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); + if(!du) + return 0; + return (du->Duration[0] == -1) ? -1 : abs(du->Duration[0]); +} + +int32 GetSpellMaxDuration(SpellEntry const *spellInfo) +{ + if(!spellInfo) + return 0; + SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex); + if(!du) + return 0; + return (du->Duration[2] == -1) ? -1 : abs(du->Duration[2]); +} + +uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell) +{ + SpellCastTimesEntry const *spellCastTimeEntry = sSpellCastTimesStore.LookupEntry(spellInfo->CastingTimeIndex); + + // not all spells have cast time index and this is all is pasiive abilities + if(!spellCastTimeEntry) + return 0; + + int32 castTime = spellCastTimeEntry->CastTime; + + if (spell) + { + if(Player* modOwner = spell->GetCaster()->GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CASTING_TIME, castTime, spell); + + if( !(spellInfo->Attributes & (SPELL_ATTR_UNK4|SPELL_ATTR_UNK5)) ) + castTime = int32(castTime * spell->GetCaster()->GetFloatValue(UNIT_MOD_CAST_SPEED)); + else + { + if (spell->IsRangedSpell() && !spell->IsAutoRepeat()) + castTime = int32(castTime * spell->GetCaster()->m_modAttackSpeedPct[RANGED_ATTACK]); + } + } + + if (spellInfo->Attributes & SPELL_ATTR_RANGED && (!spell || !(spell->IsAutoRepeat()))) + castTime += 500; + + return (castTime > 0) ? uint32(castTime) : 0; +} + +bool IsPassiveSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if (!spellInfo) + return false; + return (spellInfo->Attributes & SPELL_ATTR_PASSIVE) != 0; +} + +bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) +{ + SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); + SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + if(!spellInfo_1 || !spellInfo_2) return false; + if(spellInfo_1->Id == spellId_2) return false; + + if (spellInfo_1->Effect[effIndex_1] != spellInfo_2->Effect[effIndex_2] || + spellInfo_1->EffectItemType[effIndex_1] != spellInfo_2->EffectItemType[effIndex_2] || + spellInfo_1->EffectMiscValue[effIndex_1] != spellInfo_2->EffectMiscValue[effIndex_2] || + spellInfo_1->EffectApplyAuraName[effIndex_1] != spellInfo_2->EffectApplyAuraName[effIndex_2]) + return false; + + return true; +} + +int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) +{ + SpellEntry const*spellInfo_1 = sSpellStore.LookupEntry(spellId_1); + SpellEntry const*spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + if(!spellInfo_1 || !spellInfo_2) return 0; + if (spellId_1 == spellId_2) return 0; + + int32 diff = spellInfo_1->EffectBasePoints[effIndex_1] - spellInfo_2->EffectBasePoints[effIndex_2]; + if (spellInfo_1->EffectBasePoints[effIndex_1]+1 < 0 && spellInfo_2->EffectBasePoints[effIndex_2]+1 < 0) return -diff; + else return diff; +} + +SpellSpecific GetSpellSpecific(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return SPELL_NORMAL; + + switch(spellInfo->SpellFamilyName) + { + case SPELLFAMILY_MAGE: + { + // family flags 18(Molten), 25(Frost/Ice), 28(Mage) + if (spellInfo->SpellFamilyFlags & 0x12040000) + return SPELL_MAGE_ARMOR; + + if ((spellInfo->SpellFamilyFlags & 0x1000000) && spellInfo->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) + return SPELL_MAGE_POLYMORPH; + + break; + } + case SPELLFAMILY_WARRIOR: + { + if (spellInfo->SpellFamilyFlags & 0x00008000010000LL) + return SPELL_POSITIVE_SHOUT; + + break; + } + case SPELLFAMILY_WARLOCK: + { + // only warlock curses have this + if (spellInfo->Dispel == DISPEL_CURSE) + return SPELL_CURSE; + + // family flag 37 (only part spells have family name) + if (spellInfo->SpellFamilyFlags & 0x2000000000LL) + return SPELL_WARLOCK_ARMOR; + + //seed of corruption and corruption + if (spellInfo->SpellFamilyFlags & 0x1000000002LL) + return SPELL_WARLOCK_CORRUPTION; + break; + } + case SPELLFAMILY_HUNTER: + { + // only hunter stings have this + if (spellInfo->Dispel == DISPEL_POISON) + return SPELL_STING; + + break; + } + case SPELLFAMILY_PALADIN: + { + if (IsSealSpell(spellInfo)) + return SPELL_SEAL; + + if (spellInfo->SpellFamilyFlags & 0x10000100LL) + return SPELL_BLESSING; + + if ((spellInfo->SpellFamilyFlags & 0x00000820180400LL) && (spellInfo->AttributesEx3 & 0x200)) + return SPELL_JUDGEMENT; + + for (int i = 0; i < 3; i++) + { + // only paladin auras have this + if (spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY) + return SPELL_AURA; + } + break; + } + case SPELLFAMILY_SHAMAN: + { + if (IsElementalShield(spellInfo)) + return SPELL_ELEMENTAL_SHIELD; + + break; + } + + case SPELLFAMILY_POTION: + return spellmgr.GetSpellElixirSpecific(spellInfo->Id); + } + + // only warlock armor/skin have this (in additional to family cases) + if( spellInfo->SpellVisual == 130 && spellInfo->SpellIconID == 89) + { + return SPELL_WARLOCK_ARMOR; + } + + // only hunter aspects have this (but not all aspects in hunter family) + if( spellInfo->activeIconID == 122 && (GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NATURE) && + (spellInfo->Attributes & 0x50000) != 0 && (spellInfo->Attributes & 0x9000010) == 0) + { + return SPELL_ASPECT; + } + + for(int i = 0; i < 3; i++) + if( spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && ( + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_CREATURES || + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_RESOURCES || + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_TRACK_STEALTHED ) ) + return SPELL_TRACKER; + + // elixirs can have different families, but potion most ofc. + if(SpellSpecific sp = spellmgr.GetSpellElixirSpecific(spellInfo->Id)) + return sp; + + return SPELL_NORMAL; +} + +bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2) +{ + switch(spellSpec1) + { + case SPELL_SEAL: + case SPELL_BLESSING: + case SPELL_AURA: + case SPELL_STING: + case SPELL_CURSE: + case SPELL_ASPECT: + case SPELL_TRACKER: + case SPELL_WARLOCK_ARMOR: + case SPELL_MAGE_ARMOR: + case SPELL_ELEMENTAL_SHIELD: + case SPELL_MAGE_POLYMORPH: + case SPELL_POSITIVE_SHOUT: + case SPELL_JUDGEMENT: + case SPELL_WARLOCK_CORRUPTION: + return spellSpec1==spellSpec2; + case SPELL_BATTLE_ELIXIR: + return spellSpec2==SPELL_BATTLE_ELIXIR + || spellSpec2==SPELL_FLASK_ELIXIR; + case SPELL_GUARDIAN_ELIXIR: + return spellSpec2==SPELL_GUARDIAN_ELIXIR + || spellSpec2==SPELL_FLASK_ELIXIR; + case SPELL_FLASK_ELIXIR: + return spellSpec2==SPELL_BATTLE_ELIXIR + || spellSpec2==SPELL_GUARDIAN_ELIXIR + || spellSpec2==SPELL_FLASK_ELIXIR; + default: + return false; + } +} + +bool IsPositiveTarget(uint32 targetA, uint32 targetB) +{ + // non-positive targets + switch(targetA) + { + case TARGET_CHAIN_DAMAGE: + case TARGET_ALL_ENEMY_IN_AREA: + case TARGET_ALL_ENEMY_IN_AREA_INSTANT: + case TARGET_IN_FRONT_OF_CASTER: + case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: + case TARGET_CURRENT_ENEMY_COORDINATES: + case TARGET_SINGLE_ENEMY: + return false; + case TARGET_ALL_AROUND_CASTER: + return (targetB == TARGET_ALL_PARTY || targetB == TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER); + default: + break; + } + if (targetB) + return IsPositiveTarget(targetB, 0); + return true; +} + +bool IsPositiveEffect(uint32 spellId, uint32 effIndex) +{ + SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); + if (!spellproto) return false; + + switch(spellId) + { + case 23333: // BG spell + case 23335: // BG spell + case 34976: // BG spell + return true; + case 28441: // not positive dummy spell + case 37675: // Chaos Blast + return false; + } + + switch(spellproto->Effect[effIndex]) + { + // always positive effects (check before target checks that provided non-positive result in some case for positive effects) + case SPELL_EFFECT_HEAL: + case SPELL_EFFECT_LEARN_SPELL: + case SPELL_EFFECT_SKILL_STEP: + case SPELL_EFFECT_HEAL_PCT: + case SPELL_EFFECT_ENERGIZE_PCT: + return true; + + // non-positive aura use + case SPELL_EFFECT_APPLY_AURA: + case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND: + { + switch(spellproto->EffectApplyAuraName[effIndex]) + { + case SPELL_AURA_DUMMY: + { + // dummy aura can be positive or negative dependent from casted spell + switch(spellproto->Id) + { + case 13139: // net-o-matic special effect + case 23445: // evil twin + case 38637: // Nether Exhaustion (red) + case 38638: // Nether Exhaustion (green) + case 38639: // Nether Exhaustion (blue) + return false; + default: + break; + } + } break; + case SPELL_AURA_MOD_STAT: + case SPELL_AURA_MOD_DAMAGE_DONE: // dependent from bas point sign (negative -> negative) + case SPELL_AURA_MOD_HEALING_DONE: + { + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) + return false; + break; + } + case SPELL_AURA_ADD_TARGET_TRIGGER: + return true; + case SPELL_AURA_PERIODIC_TRIGGER_SPELL: + if(spellId != spellproto->EffectTriggerSpell[effIndex]) + { + uint32 spellTriggeredId = spellproto->EffectTriggerSpell[effIndex]; + SpellEntry const *spellTriggeredProto = sSpellStore.LookupEntry(spellTriggeredId); + + if(spellTriggeredProto) + { + // non-positive targets of main spell return early + for(int i = 0; i < 3; ++i) + { + // if non-positive trigger cast targeted to positive target this main cast is non-positive + // this will place this spell auras as debuffs + if(IsPositiveTarget(spellTriggeredProto->EffectImplicitTargetA[effIndex],spellTriggeredProto->EffectImplicitTargetB[effIndex]) && !IsPositiveEffect(spellTriggeredId,i)) + return false; + } + } + } + break; + case SPELL_AURA_PROC_TRIGGER_SPELL: + // many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example) + break; + case SPELL_AURA_MOD_STUN: //have positive and negative spells, we can't sort its correctly at this moment. + if(effIndex==0 && spellproto->Effect[1]==0 && spellproto->Effect[2]==0) + return false; // but all single stun aura spells is negative + + // Petrification + if(spellproto->Id == 17624) + return false; + break; + case SPELL_AURA_MOD_ROOT: + case SPELL_AURA_MOD_SILENCE: + case SPELL_AURA_GHOST: + case SPELL_AURA_PERIODIC_LEECH: + case SPELL_AURA_MOD_PACIFY_SILENCE: + case SPELL_AURA_MOD_STALKED: + case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: + return false; + case SPELL_AURA_PERIODIC_DAMAGE: // used in positive spells also. + // part of negative spell if casted at self (prevent cancel) + if(spellproto->EffectImplicitTargetA[effIndex] == TARGET_SELF) + return false; + break; + case SPELL_AURA_MOD_DECREASE_SPEED: // used in positive spells also + // part of positive spell if casted at self + if(spellproto->EffectImplicitTargetA[effIndex] != TARGET_SELF) + return false; + // but not this if this first effect (don't found batter check) + if(spellproto->Attributes & 0x4000000 && effIndex==0) + return false; + break; + case SPELL_AURA_TRANSFORM: + // some spells negative + switch(spellproto->Id) + { + case 36897: // Transporter Malfunction (race mutation to horde) + case 36899: // Transporter Malfunction (race mutation to alliance) + return false; + } + break; + case SPELL_AURA_MOD_SCALE: + // some spells negative + switch(spellproto->Id) + { + case 36900: // Soul Split: Evil! + case 36901: // Soul Split: Good + case 36893: // Transporter Malfunction (decrease size case) + case 36895: // Transporter Malfunction (increase size case) + return false; + } + break; + case SPELL_AURA_MECHANIC_IMMUNITY: + { + // non-positive immunities + switch(spellproto->EffectMiscValue[effIndex]) + { + case MECHANIC_BANDAGE: + case MECHANIC_SHIELD: + case MECHANIC_MOUNT: + case MECHANIC_INVULNERABILITY: + return false; + default: + break; + } + } break; + case SPELL_AURA_ADD_FLAT_MODIFIER: // mods + case SPELL_AURA_ADD_PCT_MODIFIER: + { + // non-positive mods + switch(spellproto->EffectMiscValue[effIndex]) + { + case SPELLMOD_COST: // dependent from bas point sign (negative -> positive) + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) > 0) + return false; + break; + default: + break; + } + } break; + case SPELL_AURA_MOD_HEALING_PCT: + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) + return false; + break; + case SPELL_AURA_MOD_SKILL: + if(spellproto->EffectBasePoints[effIndex]+int32(spellproto->EffectBaseDice[effIndex]) < 0) + return false; + break; + case SPELL_AURA_FORCE_REACTION: + if(spellproto->Id==42792) // Recently Dropped Flag (prevent cancel) + return false; + break; + default: + break; + } + break; + } + default: + break; + } + + // non-positive targets + if(!IsPositiveTarget(spellproto->EffectImplicitTargetA[effIndex],spellproto->EffectImplicitTargetB[effIndex])) + return false; + + // AttributesEx check + if(spellproto->AttributesEx & (1<<7)) + return false; + + // ok, positive + return true; +} + +bool IsPositiveSpell(uint32 spellId) +{ + SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId); + if (!spellproto) return false; + + // spells with at least one negative effect are considered negative + // some self-applied spells have negative effects but in self casting case negative check ignored. + for (int i = 0; i < 3; i++) + if (!IsPositiveEffect(spellId, i)) + return false; + return true; +} + +bool IsSingleTargetSpell(SpellEntry const *spellInfo) +{ + // all other single target spells have if it has AttributesEx5 + if ( spellInfo->AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL ) + return true; + + // TODO - need found Judgements rule + switch(GetSpellSpecific(spellInfo->Id)) + { + case SPELL_JUDGEMENT: + return true; + } + + // single target triggered spell. + // Not real client side single target spell, but it' not triggered until prev. aura expired. + // This is allow store it in single target spells list for caster for spell proc checking + if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals)) + return true; + + return false; +} + +bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2) +{ + // TODO - need better check + // Equal icon and spellfamily + if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName && + spellInfo1->SpellIconID == spellInfo2->SpellIconID ) + return true; + + // TODO - need found Judgements rule + SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id); + // spell with single target specific types + switch(spec1) + { + case SPELL_JUDGEMENT: + if(GetSpellSpecific(spellInfo2->Id) == spec1) + return true; + break; + } + + return false; +} + +uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form) +{ + // talents that learn spells can have stance requirements that need ignore + // (this requirement only for client-side stance show in talent description) + if( GetTalentSpellCost(spellInfo->Id) > 0 && + (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) ) + return 0; + + uint32 stanceMask = (form ? 1 << (form - 1) : 0); + + if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance + return SPELL_FAILED_NOT_SHAPESHIFT; + + if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance + return 0; + + bool actAsShifted = false; + if (form > 0) + { + SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form); + if (!shapeInfo) + { + sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form); + return 0; + } + actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells + } + + if(actAsShifted) + { + if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted + return SPELL_FAILED_NOT_SHAPESHIFT; + else if (spellInfo->Stances != 0) // needs other shapeshift + return SPELL_FAILED_ONLY_SHAPESHIFT; + } + else + { + // needs shapeshift + if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0) + return SPELL_FAILED_ONLY_SHAPESHIFT; + } + + return 0; +} + +void SpellMgr::LoadSpellTargetPositions() +{ + mSpellTargetPositions.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 3 4 5 + QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell target coordinates", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + ++count; + + uint32 Spell_ID = fields[0].GetUInt32(); + + SpellTargetPosition st; + + st.target_mapId = fields[1].GetUInt32(); + st.target_X = fields[2].GetFloat(); + st.target_Y = fields[3].GetFloat(); + st.target_Z = fields[4].GetFloat(); + st.target_Orientation = fields[5].GetFloat(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID); + if(!spellInfo) + { + sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID); + continue; + } + + bool found = false; + for(int i = 0; i < 3; ++i) + { + if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES ) + { + found = true; + break; + } + } + if(!found) + { + sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID); + continue; + } + + MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId); + if(!mapEntry) + { + sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId); + continue; + } + + if(st.target_X==0 && st.target_Y==0 && st.target_Z==0) + { + sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID); + continue; + } + + mSpellTargetPositions[Spell_ID] = st; + + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell teleport coordinates", count ); +} + +void SpellMgr::LoadSpellAffects() +{ + mSpellAffectMap.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 + QueryResult *result = WorldDatabase.Query("SELECT entry, effectId, SpellFamilyMask FROM spell_affect"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell affect definitions", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 entry = fields[0].GetUInt16(); + uint8 effectId = fields[1].GetUInt8(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); + + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` does not exist", entry); + continue; + } + + if (effectId >= 3) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have invalid effect index (%u)", entry,effectId); + continue; + } + + if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER ) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have not SPELL_AURA_ADD_FLAT_MODIFIER (%u) or SPELL_AURA_ADD_PCT_MODIFIER (%u) or SPELL_AURA_ADD_TARGET_TRIGGER (%u) for effect index (%u)", entry,SPELL_AURA_ADD_FLAT_MODIFIER,SPELL_AURA_ADD_PCT_MODIFIER,SPELL_AURA_ADD_TARGET_TRIGGER,effectId); + continue; + } + + uint64 spellAffectMask = fields[2].GetUInt64(); + + // Spell.dbc have own data for low part of SpellFamilyMask + if( spellInfo->EffectItemType[effectId]) + { + if(spellInfo->EffectItemType[effectId] == spellAffectMask) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have redundant (same with EffectItemType%d) data for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); + continue; + } + + // 24429 have wrong data in EffectItemType and overwrites by DB, possible bug in client + if(spellInfo->Id!=24429 && spellInfo->EffectItemType[effectId] != spellAffectMask) + { + sLog.outErrorDb("Spell %u listed in `spell_affect` have different low part from EffectItemType%d for effect index (%u) and not needed, skipped.", entry,effectId+1,effectId); + continue; + } + } + + mSpellAffectMap.insert(SpellAffectMap::value_type((entry<<8) + effectId,spellAffectMask)); + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell affect definitions", count ); + + for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) + { + SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); + if (!spellInfo) + continue; + + for (int effectId = 0; effectId < 3; ++effectId) + { + if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || + (spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER && + spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER) ) + continue; + + if(spellInfo->EffectItemType[effectId] != 0) + continue; + + if(mSpellAffectMap.find((id<<8) + effectId) != mSpellAffectMap.end()) + continue; + + sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u",id,spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId); + } + } +} + +bool SpellMgr::IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const +{ + // false for spellInfo == NULL + if (!spellInfo) + return false; + + SpellEntry const *affect_spell = sSpellStore.LookupEntry(spellId); + // false for affect_spell == NULL + if (!affect_spell) + return false; + + // False if spellFamily not equal + if (affect_spell->SpellFamilyName != spellInfo->SpellFamilyName) + return false; + + // If familyFlags == 0 + if (!familyFlags) + { + // Get it from spellAffect table + familyFlags = GetSpellAffectMask(spellId,effectId); + // false if familyFlags == 0 + if (!familyFlags) + return false; + } + + // true + if (familyFlags & spellInfo->SpellFamilyFlags) + return true; + + return false; +} + +void SpellMgr::LoadSpellProcEvents() +{ + mSpellProcEventMap.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 3 4 5 6 7 8 + QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, Category, SkillID, SpellFamilyName, SpellFamilyMask, procFlags, ppmRate, cooldown FROM spell_proc_event"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell proc event conditions", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 entry = fields[0].GetUInt16(); + + if (!sSpellStore.LookupEntry(entry)) + { + sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry); + continue; + } + + SpellProcEventEntry spe; + + spe.schoolMask = fields[1].GetUInt32(); + spe.category = fields[2].GetUInt32(); + spe.skillId = fields[3].GetUInt32(); + spe.spellFamilyName = fields[4].GetUInt32(); + spe.spellFamilyMask = fields[5].GetUInt64(); + spe.procFlags = fields[6].GetUInt32(); + spe.ppmRate = fields[7].GetFloat(); + spe.cooldown = fields[8].GetUInt32(); + + mSpellProcEventMap[entry] = spe; + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell proc event conditions", count ); + + /* + // Commented for now, as it still produces many errors (still quite many spells miss spell_proc_event) + for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id) + { + SpellEntry const* spellInfo = sSpellStore.LookupEntry(id); + if (!spellInfo) + continue; + + bool found = false; + for (int effectId = 0; effectId < 3; ++effectId) + { + // at this moment check only SPELL_AURA_PROC_TRIGGER_SPELL + if( spellInfo->EffectApplyAuraName[effectId] == SPELL_AURA_PROC_TRIGGER_SPELL ) + { + found = true; + break; + } + } + + if(!found) + continue; + + if(GetSpellProcEvent(id)) + continue; + + sLog.outErrorDb("Spell %u (%s) misses spell_proc_event",id,spellInfo->SpellName[sWorld.GetDBClang()]); + } + */ +} + +bool SpellMgr::IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ) +{ + if((procFlags & spellProcEvent->procFlags) == 0) + return false; + + // Additional checks in case spell cast/hit/crit is the event + // Check (if set) school, category, skill line, spell talent mask + if(spellProcEvent->schoolMask && (!procSpell || (GetSpellSchoolMask(procSpell) & spellProcEvent->schoolMask) == 0)) + return false; + if(spellProcEvent->category && (!procSpell || procSpell->Category != spellProcEvent->category)) + return false; + if(spellProcEvent->skillId) + { + if (!procSpell) + return false; + + SkillLineAbilityMap::const_iterator lower = spellmgr.GetBeginSkillLineAbilityMap(procSpell->Id); + SkillLineAbilityMap::const_iterator upper = spellmgr.GetEndSkillLineAbilityMap(procSpell->Id); + + bool found = false; + for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx) + { + if(_spell_idx->second->skillId == spellProcEvent->skillId) + { + found = true; + break; + } + } + if (!found) + return false; + } + if(spellProcEvent->spellFamilyName && (!procSpell || spellProcEvent->spellFamilyName != procSpell->SpellFamilyName)) + return false; + if(spellProcEvent->spellFamilyMask && (!procSpell || (spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags) == 0)) + return false; + + return true; +} + +void SpellMgr::LoadSpellElixirs() +{ + mSpellElixirs.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 + QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell elixir definitions", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 entry = fields[0].GetUInt16(); + uint8 mask = fields[1].GetUInt8(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry); + + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry); + continue; + } + + mSpellElixirs[entry] = mask; + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell elixir definitions", count ); +} + +void SpellMgr::LoadSpellThreats() +{ + sSpellThreatStore.Free(); // for reload + + sSpellThreatStore.Load(); + + sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount ); + sLog.outString(); +} + +bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const +{ + SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + if(!spellInfo_1 || !spellInfo_2) return false; + if(spellInfo_1->Id == spellId_2) return false; + + return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2); +} + +bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo) +{ + if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH) + return false; + if(IsProfessionSpell(spellInfo->Id)) + return false; + + // All stance spells. if any better way, change it. + for (int i = 0; i < 3; i++) + { + // Paladin aura Spell + if(spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN + && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_PARTY) + return false; + // Druid form Spell + if(spellInfo->SpellFamilyName == SPELLFAMILY_DRUID + && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA + && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) + return false; + // Rogue Stealth + if(spellInfo->SpellFamilyName == SPELLFAMILY_ROGUE + && spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA + && spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT) + return false; + } + return true; +} + +bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const +{ + if(spellId_1 == spellId_2) // auras due to the same spell + return false; + + SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); + SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); + + if(!spellInfo_1 || !spellInfo_2) + return false; + + if(spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName) + return false; + + if(!spellInfo_1->SpellFamilyName) // generic spells + { + if(!spellInfo_1->SpellIconID + || spellInfo_1->SpellIconID != spellInfo_2->SpellIconID) + return false; + } + else if (spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags) + return false; + + for(uint32 i = 0; i < 3; ++i) + if(spellInfo_1->Effect[i] != spellInfo_2->Effect[i] + || spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i]) + return false; + + return true; +} + +bool SpellMgr::IsProfessionSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return false; + + if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) + return false; + + uint32 skill = spellInfo->EffectMiscValue[1]; + + return IsProfessionSkill(skill); +} + +bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return false; + + if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL) + return false; + + uint32 skill = spellInfo->EffectMiscValue[1]; + + return IsPrimaryProfessionSkill(skill); +} + +bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const +{ + return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1; +} + +SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const +{ + // ignore passive spells + if(IsPassiveSpell(spellInfo->Id)) + return spellInfo; + + bool needRankSelection = false; + for(int i=0;i<3;i++) + { + if( IsPositiveEffect(spellInfo->Id, i) && ( + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY + ) ) + { + needRankSelection = true; + break; + } + } + + // not required + if(!needRankSelection) + return spellInfo; + + for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId)) + { + SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId); + if(!nextSpellInfo) + break; + + // if found appropriate level + if(playerLevel + 10 >= nextSpellInfo->spellLevel) + return nextSpellInfo; + + // one rank less then + } + + // not found + return NULL; +} + +void SpellMgr::LoadSpellChains() +{ + mSpellChains.clear(); // need for reload case + mSpellChainsNext.clear(); // need for reload case + + QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain"); + if(result == NULL) + { + barGoLink bar( 1 ); + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded 0 spell chain records" ); + sLog.outErrorDb("`spell_chains` table is empty!"); + return; + } + + uint32 count = 0; + + barGoLink bar( result->GetRowCount() ); + do + { + bar.step(); + Field *fields = result->Fetch(); + + uint32 spell_id = fields[0].GetUInt32(); + + SpellChainNode node; + node.prev = fields[1].GetUInt32(); + node.first = fields[2].GetUInt32(); + node.rank = fields[3].GetUInt8(); + node.req = fields[4].GetUInt32(); + + if(!sSpellStore.LookupEntry(spell_id)) + { + sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id); + continue; + } + + if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev)) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(!sSpellStore.LookupEntry(node.first)) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell) + if( (spell_id == node.first) != (node.rank <= 1) || + (spell_id == node.first) != (node.prev == 0) || + (node.rank <= 1) != (node.prev == 0) ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(node.req!=0 && !sSpellStore.LookupEntry(node.req)) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + // talents not required data in spell chain for work, but must be checked if present for intergrity + if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id)) + { + if(node.rank!=pos->rank+1) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id)) + { + if(node.first!=talentEntry->RankID[0]) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1]) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + + if(node.req!=talentEntry->DependsOnSpell) + { + sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.", + spell_id,node.prev,node.first,node.rank,node.req); + continue; + } + } + } + + mSpellChains[spell_id] = node; + + if(node.prev) + mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id)); + + if(node.req) + mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id)); + + ++count; + } while( result->NextRow() ); + + // additional integrity checks + for(SpellChainMap::iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i) + { + if(i->second.prev) + { + SpellChainMap::iterator i_prev = mSpellChains.find(i->second.prev); + if(i_prev == mSpellChains.end()) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); + } + else if( i_prev->second.first != i->second.first ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different first spell in chain compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); + } + else if( i_prev->second.rank+1 != i->second.rank ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different rank compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req); + } + } + + if(i->second.req) + { + SpellChainMap::iterator i_req = mSpellChains.find(i->second.req); + if(i_req == mSpellChains.end()) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req); + } + else if( i_req->second.first == i->second.first ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell from same spell chain (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); + } + else if( i_req->second.req ) + { + sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell with required spell (prev: %u, first: %u, rank: %d, req: %u).", + i->first,i->second.prev,i->second.first,i->second.rank,i->second.req, + i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req); + } + } + } + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell chain records", count ); +} + +void SpellMgr::LoadSpellLearnSkills() +{ + mSpellLearnSkills.clear(); // need for reload case + + // search auto-learned skills and add its to map also for use in unlearn spells/talents + uint32 dbc_count = 0; + for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) + { + SpellEntry const* entry = sSpellStore.LookupEntry(spell); + + if(!entry) + continue; + + for(int i = 0; i < 3; ++i) + { + if(entry->Effect[i]==SPELL_EFFECT_SKILL) + { + SpellLearnSkillNode dbc_node; + dbc_node.skill = entry->EffectMiscValue[i]; + if ( dbc_node.skill != SKILL_RIDING ) + dbc_node.value = 1; + else + dbc_node.value = (entry->EffectBasePoints[i]+1)*75; + dbc_node.maxvalue = (entry->EffectBasePoints[i]+1)*75; + + SpellLearnSkillNode const* db_node = GetSpellLearnSkill(spell); + + mSpellLearnSkills[spell] = dbc_node; + ++dbc_count; + break; + } + } + } + + sLog.outString(); + sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count ); +} + +void SpellMgr::LoadSpellLearnSpells() +{ + mSpellLearnSpells.clear(); // need for reload case + + QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID FROM spell_learn_spell"); + if(!result) + { + barGoLink bar( 1 ); + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded 0 spell learn spells" ); + sLog.outErrorDb("`spell_learn_spell` table is empty!"); + return; + } + + uint32 count = 0; + + barGoLink bar( result->GetRowCount() ); + do + { + bar.step(); + Field *fields = result->Fetch(); + + uint32 spell_id = fields[0].GetUInt32(); + + SpellLearnSpellNode node; + node.spell = fields[1].GetUInt32(); + node.autoLearned= false; + + if(!sSpellStore.LookupEntry(spell_id)) + { + sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id); + continue; + } + + if(!sSpellStore.LookupEntry(node.spell)) + { + sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell); + continue; + } + + mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node)); + + ++count; + } while( result->NextRow() ); + + delete result; + + // search auto-learned spells and add its to map also for use in unlearn spells/talents + uint32 dbc_count = 0; + for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell) + { + SpellEntry const* entry = sSpellStore.LookupEntry(spell); + + if(!entry) + continue; + + for(int i = 0; i < 3; ++i) + { + if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL) + { + SpellLearnSpellNode dbc_node; + dbc_node.spell = entry->EffectTriggerSpell[i]; + dbc_node.autoLearned = true; + + SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell); + SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell); + + bool found = false; + for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr) + { + if(itr->second.spell == dbc_node.spell) + { + sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.", + spell,dbc_node.spell); + found = true; + break; + } + } + + if(!found) // add new spell-spell pair if not found + { + mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node)); + ++dbc_count; + } + } + } + } + + sLog.outString(); + sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count ); +} + +void SpellMgr::LoadSpellScriptTarget() +{ + mSpellScriptTarget.clear(); // need for reload case + + uint32 count = 0; + + QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target"); + + if(!result) + { + barGoLink bar(1); + + bar.step(); + + sLog.outString(); + sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty."); + return; + } + + barGoLink bar(result->GetRowCount()); + + do + { + Field *fields = result->Fetch(); + bar.step(); + + uint32 spellId = fields[0].GetUInt32(); + uint32 type = fields[1].GetUInt32(); + uint32 targetEntry = fields[2].GetUInt32(); + + SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); + + if(!spellProto) + { + sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry); + continue; + } + + /*bool targetfound = false; + for(int i = 0; i <3; ++i) + { + if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT || + spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT || + spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES || + spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES ) + { + targetfound = true; + break; + } + } + if(!targetfound) + { + sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not have any implicit target TARGET_SCRIPT(38) or TARGET_SCRIPT_COORDINATES (46).",spellId,targetEntry); + continue; + }*/ + + if( type >= MAX_SPELL_TARGET_TYPE ) + { + sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry); + continue; + } + + switch(type) + { + case SPELL_TARGET_TYPE_GAMEOBJECT: + { + if( targetEntry==0 ) + break; + + if(!sGOStorage.LookupEntry(targetEntry)) + { + sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry); + continue; + } + break; + } + default: + { + if( targetEntry==0 ) + { + sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type); + continue; + } + if(!sCreatureStorage.LookupEntry(targetEntry)) + { + sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry); + continue; + } + const CreatureInfo* cInfo = sCreatureStorage.LookupEntry(targetEntry); + + if(spellId == 30427 && !cInfo->SkinLootId) + { + sLog.outErrorDb("Table `spell_script_target` has creature %u as a target of spellid 30427, but this creature has no skinlootid. Gas extraction will not work!", cInfo->Entry); + continue; + } + break; + } + } + + mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry))); + + ++count; + } while (result->NextRow()); + + delete result; + + // Check all spells + /* Disabled (lot errors at this moment) + for(uint32 i = 1; i < sSpellStore.nCount; ++i) + { + SpellEntry const * spellInfo = sSpellStore.LookupEntry(i); + if(!spellInfo) + continue; + + bool found = false; + for(int j=0; j<3; ++j) + { + if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT ) + { + SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id); + SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id); + if(lower==upper) + { + sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = %u (TARGET_SCRIPT), but does not have record in `spell_script_target`",spellInfo->Id,TARGET_SCRIPT); + break; // effects of spell + } + } + } + } + */ + + sLog.outString(); + sLog.outString(">> Loaded %u Spell Script Targets", count); +} + +void SpellMgr::LoadSpellPetAuras() +{ + mSpellPetAuraMap.clear(); // need for reload case + + uint32 count = 0; + + // 0 1 2 + QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras"); + if( !result ) + { + + barGoLink bar( 1 ); + + bar.step(); + + sLog.outString(); + sLog.outString( ">> Loaded %u spell pet auras", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + uint16 spell = fields[0].GetUInt16(); + uint16 pet = fields[1].GetUInt16(); + uint16 aura = fields[2].GetUInt16(); + + SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell); + if(itr != mSpellPetAuraMap.end()) + { + itr->second.AddAura(pet, aura); + } + else + { + SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell); + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell); + continue; + } + int i = 0; + for(; i < 3; ++i) + if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA && + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) || + spellInfo->Effect[i] == SPELL_EFFECT_DUMMY) + break; + + if(i == 3) + { + sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell); + continue; + } + + SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura); + if (!spellInfo2) + { + sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura); + continue; + } + + PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->EffectBasePoints[i] + spellInfo->EffectBaseDice[i]); + mSpellPetAuraMap[spell] = pa; + } + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u spell pet auras", count ); +} + +// set data in core for now +void SpellMgr::LoadSpellCustomAttr() +{ + SpellEntry *tempSpell; + for(uint32 i = 0; i < GetSpellStore()->GetNumRows(); ++i) + { + tempSpell = (SpellEntry*)GetSpellStore()->LookupEntry(i); + if(!tempSpell) + continue; + + mSpellCustomAttrMap[tempSpell->Id] = 0; + + for(uint32 i = 0; i < 3; ++i) + { + switch(tempSpell->EffectApplyAuraName[i]) + { + case SPELL_AURA_PERIODIC_DAMAGE: + case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: + case SPELL_AURA_PERIODIC_LEECH: + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_DAMAGE; + break; + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_OBS_MOD_HEALTH: + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_EFFECT_HEAL; + break; + default: + break; + } + } + + if(tempSpell->SpellVisual == 3879) + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_BACK; + + switch(tempSpell->Id) + { + case 26029: // dark glare + case 37433: // spout + case 43140: case 43215: // flame breath + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_CONE_LINE; + break; + case 24340: case 26558: case 28884: // Meteor + case 36837: case 38903: case 41276: // Meteor + case 26789: // Shard of the Fallen Star + case 31436: // Malevolent Cleave + case 35181: // Dive Bomb + case 40810: case 43267: case 43268: // Saber Lash + case 42384: // Brutal Swipe + case 45150: // Meteor Slash + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_SHARE_DAMAGE; + break; + case 44978: case 45001: case 45002: // Wild Magic + case 45004: case 45006: case 45010: // Wild Magic + case 31347: // Doom + case 41635: // Prayer of Mending + case 44869: // Spectral Blast + case 45027: // Revitalize + case 45976: // Muru Portal Channel + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; + tempSpell->MaxAffectedTargets = 1; + break; + case 41376: // Spite + case 39992: // Needle Spine + mSpellCustomAttrMap[tempSpell->Id] |= SPELL_ATTR_CU_PLAYERS_ONLY; + tempSpell->MaxAffectedTargets = 3; + break; + case 8122: case 8124: case 10888: case 10890: // Psychic Scream + tempSpell->Attributes |= SPELL_ATTR_BREAKABLE_BY_DAMAGE; + break; + default: + break; + } + } +} + +void SpellMgr::LoadSpellLinked() +{ + mSpellLinkedMap.clear(); // need for reload case + uint32 count = 0; + + // 0 1 2 + QueryResult *result = WorldDatabase.Query("SELECT spell_trigger, spell_effect, type FROM spell_linked_spell"); + if( !result ) + { + barGoLink bar( 1 ); + bar.step(); + sLog.outString(); + sLog.outString( ">> Loaded %u linked spells", count ); + return; + } + + barGoLink bar( result->GetRowCount() ); + + do + { + Field *fields = result->Fetch(); + + bar.step(); + + int32 trigger = fields[0].GetInt32(); + int32 effect = fields[1].GetInt32(); + int32 type = fields[2].GetInt32(); + + SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(trigger)); + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(trigger)); + continue; + } + spellInfo = sSpellStore.LookupEntry(abs(effect)); + if (!spellInfo) + { + sLog.outErrorDb("Spell %u listed in `spell_linked_spell` does not exist", abs(effect)); + continue; + } + + if(type) //we will find a better way when more types are needed + trigger += 1000000; + mSpellLinkedMap[trigger].push_back(effect); + + ++count; + } while( result->NextRow() ); + + delete result; + + sLog.outString(); + sLog.outString( ">> Loaded %u linked spells", count ); +} + +/// Some checks for spells, to prevent adding depricated/broken spells for trainers, spell book, etc +bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg) +{ + // not exist + if(!spellInfo) + return false; + + bool need_check_reagents = false; + + // check effects + for(int i=0; i<3; ++i) + { + switch(spellInfo->Effect[i]) + { + case 0: + continue; + + // craft spell for crafting non-existed item (break client recipes list show) + case SPELL_EFFECT_CREATE_ITEM: + { + if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] )) + { + if(msg) + { + if(pl) + ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); + else + sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]); + } + return false; + } + + need_check_reagents = true; + break; + } + case SPELL_EFFECT_LEARN_SPELL: + { + SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[0]); + if( !IsSpellValid(spellInfo2,pl,msg) ) + { + if(msg) + { + if(pl) + ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); + else + sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[0]); + } + return false; + } + break; + } + } + } + + if(need_check_reagents) + { + for(int j = 0; j < 8; ++j) + { + if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] )) + { + if(msg) + { + if(pl) + ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); + else + sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]); + } + return false; + } + } + } + + return true; +} + +bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id) +{ + // normal case + if( spellInfo->AreaId && spellInfo->AreaId != zone_id && spellInfo->AreaId != area_id ) + return false; + + // elixirs (all area dependent elixirs have family SPELLFAMILY_POTION, use this for speedup) + if(spellInfo->SpellFamilyName==SPELLFAMILY_POTION) + { + if(uint32 mask = spellmgr.GetSpellElixirMask(spellInfo->Id)) + { + if(mask & ELIXIR_UNSTABLE_MASK) + { + // in the Blade's Edge Mountains Plateaus and Gruul's Lair. + return zone_id ==3522 || map_id==565; + } + if(mask & ELIXIR_SHATTRATH_MASK) + { + // in Tempest Keep, Serpentshrine Cavern, Caverns of Time: Mount Hyjal, Black Temple + // TODO: and the Sunwell Plateau + if(zone_id ==3607 || map_id==534 || map_id==564) + return true; + + MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); + if(!mapEntry) + return false; + + return mapEntry->multimap_id==206; + } + + // elixirs not have another limitations + return true; + } + } + + // special cases zone check (maps checked by multimap common id) + switch(spellInfo->Id) + { + case 41618: + case 41620: + { + MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); + if(!mapEntry) + return false; + + return mapEntry->multimap_id==206; + } + + case 41617: + case 41619: + { + MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); + if(!mapEntry) + return false; + + return mapEntry->multimap_id==207; + } + // Dragonmaw Illusion + case 40216: + case 42016: + { + if ( area_id != 3759 && area_id != 3966 && area_id != 3939 ) + return false; + break; + } + } + + return true; +} + +void SpellMgr::LoadSkillLineAbilityMap() +{ + mSkillLineAbilityMap.clear(); + + uint32 count = 0; + + for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); i++) + { + SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i); + if(!SkillInfo) + continue; + + mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo)); + ++count; + } + + sLog.outString(); + sLog.outString(">> Loaded %u SkillLineAbility MultiMap", count); +} + +DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered) +{ + // Explicit Diminishing Groups + switch(spellproto->SpellFamilyName) + { + case SPELLFAMILY_MAGE: + { + // Polymorph + if ((spellproto->SpellFamilyFlags & 0x00001000000LL) && spellproto->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE) + return DIMINISHING_POLYMORPH; + break; + } + case SPELLFAMILY_ROGUE: + { + // Kidney Shot + if (spellproto->SpellFamilyFlags & 0x00000200000LL) + return DIMINISHING_KIDNEYSHOT; + // Blind + else if (spellproto->SpellFamilyFlags & 0x00001000000LL) + return DIMINISHING_BLIND_CYCLONE; + break; + } + case SPELLFAMILY_WARLOCK: + { + // Death Coil + if (spellproto->SpellFamilyFlags & 0x00000080000LL) + return DIMINISHING_DEATHCOIL; + // Fear + else if (spellproto->SpellFamilyFlags & 0x40840000000LL) + return DIMINISHING_WARLOCK_FEAR; + // Curses/etc + else if (spellproto->SpellFamilyFlags & 0x00080000000LL) + return DIMINISHING_LIMITONLY; + break; + } + case SPELLFAMILY_DRUID: + { + // Cyclone + if (spellproto->SpellFamilyFlags & 0x02000000000LL) + return DIMINISHING_BLIND_CYCLONE; + break; + } + case SPELLFAMILY_WARRIOR: + { + // Hamstring - limit duration to 10s in PvP + if (spellproto->SpellFamilyFlags & 0x00000000002LL) + return DIMINISHING_LIMITONLY; + break; + } + default: + break; + } + + // Get by mechanic + for (uint8 i=0;i<3;++i) + { + if (spellproto->Mechanic == MECHANIC_STUN || spellproto->EffectMechanic[i] == MECHANIC_STUN) + return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN; + else if (spellproto->Mechanic == MECHANIC_SLEEP || spellproto->EffectMechanic[i] == MECHANIC_SLEEP) + return DIMINISHING_SLEEP; + else if (spellproto->Mechanic == MECHANIC_ROOT || spellproto->EffectMechanic[i] == MECHANIC_ROOT) + return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT; + else if (spellproto->Mechanic == MECHANIC_FEAR || spellproto->EffectMechanic[i] == MECHANIC_FEAR) + return DIMINISHING_FEAR; + else if (spellproto->Mechanic == MECHANIC_CHARM || spellproto->EffectMechanic[i] == MECHANIC_CHARM) + return DIMINISHING_CHARM; + else if (spellproto->Mechanic == MECHANIC_SILENCE || spellproto->EffectMechanic[i] == MECHANIC_SILENCE) + return DIMINISHING_SILENCE; + else if (spellproto->Mechanic == MECHANIC_DISARM || spellproto->EffectMechanic[i] == MECHANIC_DISARM) + return DIMINISHING_DISARM; + else if (spellproto->Mechanic == MECHANIC_FREEZE || spellproto->EffectMechanic[i] == MECHANIC_FREEZE) + return DIMINISHING_FREEZE; + else if (spellproto->Mechanic == MECHANIC_KNOCKOUT|| spellproto->EffectMechanic[i] == MECHANIC_KNOCKOUT || + spellproto->Mechanic == MECHANIC_SAPPED || spellproto->EffectMechanic[i] == MECHANIC_SAPPED) + return DIMINISHING_KNOCKOUT; + else if (spellproto->Mechanic == MECHANIC_BANISH || spellproto->EffectMechanic[i] == MECHANIC_BANISH) + return DIMINISHING_BANISH; + } + + return DIMINISHING_NONE; +} + +bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group) +{ + switch(group) + { + case DIMINISHING_CONTROL_STUN: + case DIMINISHING_TRIGGER_STUN: + case DIMINISHING_KIDNEYSHOT: + case DIMINISHING_SLEEP: + case DIMINISHING_CONTROL_ROOT: + case DIMINISHING_TRIGGER_ROOT: + case DIMINISHING_FEAR: + case DIMINISHING_WARLOCK_FEAR: + case DIMINISHING_CHARM: + case DIMINISHING_POLYMORPH: + case DIMINISHING_FREEZE: + case DIMINISHING_KNOCKOUT: + case DIMINISHING_BLIND_CYCLONE: + case DIMINISHING_BANISH: + case DIMINISHING_LIMITONLY: + return true; + } + return false; +} + +DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group) +{ + switch(group) + { + case DIMINISHING_BLIND_CYCLONE: + case DIMINISHING_CONTROL_STUN: + case DIMINISHING_TRIGGER_STUN: + case DIMINISHING_KIDNEYSHOT: + return DRTYPE_ALL; + case DIMINISHING_SLEEP: + case DIMINISHING_CONTROL_ROOT: + case DIMINISHING_TRIGGER_ROOT: + case DIMINISHING_FEAR: + case DIMINISHING_CHARM: + case DIMINISHING_POLYMORPH: + case DIMINISHING_SILENCE: + case DIMINISHING_DISARM: + case DIMINISHING_DEATHCOIL: + case DIMINISHING_FREEZE: + case DIMINISHING_BANISH: + case DIMINISHING_WARLOCK_FEAR: + case DIMINISHING_KNOCKOUT: + return DRTYPE_PLAYER; + } + + return DRTYPE_NONE; +} diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index e86a394af9d..7de9c54c6cb 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -1,899 +1,898 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _SPELLMGR_H -#define _SPELLMGR_H - -// For static or at-server-startup loaded spell data -// For more high level function for sSpellStore data - -#include "SharedDefines.h" -#include "Database/DBCStructure.h" -#include "Database/SQLStorage.h" - -#include "Utilities/UnorderedMap.h" -#include - -class Player; -class Spell; - -extern SQLStorage sSpellThreatStore; - -enum SpellFailedReason -{ - SPELL_FAILED_AFFECTING_COMBAT = 0x00, - SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 0x01, - SPELL_FAILED_ALREADY_AT_FULL_MANA = 0x02, - SPELL_FAILED_ALREADY_AT_FULL_POWER = 0x03, - SPELL_FAILED_ALREADY_BEING_TAMED = 0x04, - SPELL_FAILED_ALREADY_HAVE_CHARM = 0x05, - SPELL_FAILED_ALREADY_HAVE_SUMMON = 0x06, - SPELL_FAILED_ALREADY_OPEN = 0x07, - SPELL_FAILED_AURA_BOUNCED = 0x08, - SPELL_FAILED_AUTOTRACK_INTERRUPTED = 0x09, - SPELL_FAILED_BAD_IMPLICIT_TARGETS = 0x0A, - SPELL_FAILED_BAD_TARGETS = 0x0B, - SPELL_FAILED_CANT_BE_CHARMED = 0x0C, - SPELL_FAILED_CANT_BE_DISENCHANTED = 0x0D, - SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL = 0x0E, - SPELL_FAILED_CANT_BE_PROSPECTED = 0x0F, - SPELL_FAILED_CANT_CAST_ON_TAPPED = 0x10, - SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE = 0x11, - SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED = 0x12, - SPELL_FAILED_CANT_STEALTH = 0x13, - SPELL_FAILED_CASTER_AURASTATE = 0x14, - SPELL_FAILED_CASTER_DEAD = 0x15, - SPELL_FAILED_CHARMED = 0x16, - SPELL_FAILED_CHEST_IN_USE = 0x17, - SPELL_FAILED_CONFUSED = 0x18, - SPELL_FAILED_DONT_REPORT = 0x19, - SPELL_FAILED_EQUIPPED_ITEM = 0x1A, - SPELL_FAILED_EQUIPPED_ITEM_CLASS = 0x1B, - SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND = 0x1C, - SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND = 0x1D, - SPELL_FAILED_ERROR = 0x1E, - SPELL_FAILED_FIZZLE = 0x1F, - SPELL_FAILED_FLEEING = 0x20, - SPELL_FAILED_FOOD_LOWLEVEL = 0x21, - SPELL_FAILED_HIGHLEVEL = 0x22, - SPELL_FAILED_HUNGER_SATIATED = 0x23, - SPELL_FAILED_IMMUNE = 0x24, - SPELL_FAILED_INTERRUPTED = 0x25, - SPELL_FAILED_INTERRUPTED_COMBAT = 0x26, - SPELL_FAILED_ITEM_ALREADY_ENCHANTED = 0x27, - SPELL_FAILED_ITEM_GONE = 0x28, - SPELL_FAILED_ITEM_NOT_FOUND = 0x29, - SPELL_FAILED_ITEM_NOT_READY = 0x2A, - SPELL_FAILED_LEVEL_REQUIREMENT = 0x2B, - SPELL_FAILED_LINE_OF_SIGHT = 0x2C, - SPELL_FAILED_LOWLEVEL = 0x2D, - SPELL_FAILED_LOW_CASTLEVEL = 0x2E, - SPELL_FAILED_MAINHAND_EMPTY = 0x2F, - SPELL_FAILED_MOVING = 0x30, - SPELL_FAILED_NEED_AMMO = 0x31, - SPELL_FAILED_NEED_AMMO_POUCH = 0x32, - SPELL_FAILED_NEED_EXOTIC_AMMO = 0x33, - SPELL_FAILED_NOPATH = 0x34, - SPELL_FAILED_NOT_BEHIND = 0x35, - SPELL_FAILED_NOT_FISHABLE = 0x36, - SPELL_FAILED_NOT_FLYING = 0x37, - SPELL_FAILED_NOT_HERE = 0x38, - SPELL_FAILED_NOT_INFRONT = 0x39, - SPELL_FAILED_NOT_IN_CONTROL = 0x3A, - SPELL_FAILED_NOT_KNOWN = 0x3B, - SPELL_FAILED_NOT_MOUNTED = 0x3C, - SPELL_FAILED_NOT_ON_TAXI = 0x3D, - SPELL_FAILED_NOT_ON_TRANSPORT = 0x3E, - SPELL_FAILED_NOT_READY = 0x3F, - SPELL_FAILED_NOT_SHAPESHIFT = 0x40, - SPELL_FAILED_NOT_STANDING = 0x41, - SPELL_FAILED_NOT_TRADEABLE = 0x42, - SPELL_FAILED_NOT_TRADING = 0x43, - SPELL_FAILED_NOT_UNSHEATHED = 0x44, - SPELL_FAILED_NOT_WHILE_GHOST = 0x45, - SPELL_FAILED_NO_AMMO = 0x46, - SPELL_FAILED_NO_CHARGES_REMAIN = 0x47, - SPELL_FAILED_NO_CHAMPION = 0x48, - SPELL_FAILED_NO_COMBO_POINTS = 0x49, - SPELL_FAILED_NO_DUELING = 0x4A, - SPELL_FAILED_NO_ENDURANCE = 0x4B, - SPELL_FAILED_NO_FISH = 0x4C, - SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED = 0x4D, - SPELL_FAILED_NO_MOUNTS_ALLOWED = 0x4E, - SPELL_FAILED_NO_PET = 0x4F, - SPELL_FAILED_NO_POWER = 0x50, - SPELL_FAILED_NOTHING_TO_DISPEL = 0x51, - SPELL_FAILED_NOTHING_TO_STEAL = 0x52, - SPELL_FAILED_ONLY_ABOVEWATER = 0x53, - SPELL_FAILED_ONLY_DAYTIME = 0x54, - SPELL_FAILED_ONLY_INDOORS = 0x55, - SPELL_FAILED_ONLY_MOUNTED = 0x56, - SPELL_FAILED_ONLY_NIGHTTIME = 0x57, - SPELL_FAILED_ONLY_OUTDOORS = 0x58, - SPELL_FAILED_ONLY_SHAPESHIFT = 0x59, - SPELL_FAILED_ONLY_STEALTHED = 0x5A, - SPELL_FAILED_ONLY_UNDERWATER = 0x5B, - SPELL_FAILED_OUT_OF_RANGE = 0x5C, - SPELL_FAILED_PACIFIED = 0x5D, - SPELL_FAILED_POSSESSED = 0x5E, - SPELL_FAILED_REAGENTS = 0x5F, - SPELL_FAILED_REQUIRES_AREA = 0x60, - SPELL_FAILED_REQUIRES_SPELL_FOCUS = 0x61, - SPELL_FAILED_ROOTED = 0x62, - SPELL_FAILED_SILENCED = 0x63, - SPELL_FAILED_SPELL_IN_PROGRESS = 0x64, - SPELL_FAILED_SPELL_LEARNED = 0x65, - SPELL_FAILED_SPELL_UNAVAILABLE = 0x66, - SPELL_FAILED_STUNNED = 0x67, - SPELL_FAILED_TARGETS_DEAD = 0x68, - SPELL_FAILED_TARGET_AFFECTING_COMBAT = 0x69, - SPELL_FAILED_TARGET_AURASTATE = 0x6A, - SPELL_FAILED_TARGET_DUELING = 0x6B, - SPELL_FAILED_TARGET_ENEMY = 0x6C, - SPELL_FAILED_TARGET_ENRAGED = 0x6D, - SPELL_FAILED_TARGET_FRIENDLY = 0x6E, - SPELL_FAILED_TARGET_IN_COMBAT = 0x6F, - SPELL_FAILED_TARGET_IS_PLAYER = 0x70, - SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED = 0x71, - SPELL_FAILED_TARGET_NOT_DEAD = 0x72, - SPELL_FAILED_TARGET_NOT_IN_PARTY = 0x73, - SPELL_FAILED_TARGET_NOT_LOOTED = 0x74, - SPELL_FAILED_TARGET_NOT_PLAYER = 0x75, - SPELL_FAILED_TARGET_NO_POCKETS = 0x76, - SPELL_FAILED_TARGET_NO_WEAPONS = 0x77, - SPELL_FAILED_TARGET_UNSKINNABLE = 0x78, - SPELL_FAILED_THIRST_SATIATED = 0x79, - SPELL_FAILED_TOO_CLOSE = 0x7A, - SPELL_FAILED_TOO_MANY_OF_ITEM = 0x7B, - SPELL_FAILED_TOTEM_CATEGORY = 0x7C, - SPELL_FAILED_TOTEMS = 0x7D, - SPELL_FAILED_TRAINING_POINTS = 0x7E, - SPELL_FAILED_TRY_AGAIN = 0x7F, - SPELL_FAILED_UNIT_NOT_BEHIND = 0x80, - SPELL_FAILED_UNIT_NOT_INFRONT = 0x81, - SPELL_FAILED_WRONG_PET_FOOD = 0x82, - SPELL_FAILED_NOT_WHILE_FATIGUED = 0x83, - SPELL_FAILED_TARGET_NOT_IN_INSTANCE = 0x84, - SPELL_FAILED_NOT_WHILE_TRADING = 0x85, - SPELL_FAILED_TARGET_NOT_IN_RAID = 0x86, - SPELL_FAILED_DISENCHANT_WHILE_LOOTING = 0x87, - SPELL_FAILED_PROSPECT_WHILE_LOOTING = 0x88, - SPELL_FAILED_PROSPECT_NEED_MORE = 0x89, - SPELL_FAILED_TARGET_FREEFORALL = 0x8A, - SPELL_FAILED_NO_EDIBLE_CORPSES = 0x8B, - SPELL_FAILED_ONLY_BATTLEGROUNDS = 0x8C, - SPELL_FAILED_TARGET_NOT_GHOST = 0x8D, - SPELL_FAILED_TOO_MANY_SKILLS = 0x8E, - SPELL_FAILED_TRANSFORM_UNUSABLE = 0x8F, - SPELL_FAILED_WRONG_WEATHER = 0x90, - SPELL_FAILED_DAMAGE_IMMUNE = 0x91, - SPELL_FAILED_PREVENTED_BY_MECHANIC = 0x92, - SPELL_FAILED_PLAY_TIME = 0x93, - SPELL_FAILED_REPUTATION = 0x94, - SPELL_FAILED_MIN_SKILL = 0x95, - SPELL_FAILED_NOT_IN_ARENA = 0x96, - SPELL_FAILED_NOT_ON_SHAPESHIFT = 0x97, - SPELL_FAILED_NOT_ON_STEALTHED = 0x98, - SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE = 0x99, - SPELL_FAILED_NOT_ON_MOUNTED = 0x9A, - SPELL_FAILED_TOO_SHALLOW = 0x9B, - SPELL_FAILED_TARGET_NOT_IN_SANCTUARY = 0x9C, - SPELL_FAILED_TARGET_IS_TRIVIAL = 0x9D, - SPELL_FAILED_BM_OR_INVISGOD = 0x9E, - SPELL_FAILED_EXPERT_RIDING_REQUIREMENT = 0x9F, - SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT = 0xA0, - SPELL_FAILED_NOT_IDLE = 0xA1, - SPELL_FAILED_NOT_INACTIVE = 0xA2, - SPELL_FAILED_PARTIAL_PLAYTIME = 0xA3, - SPELL_FAILED_NO_PLAYTIME = 0xA4, - SPELL_FAILED_NOT_IN_BATTLEGROUND = 0xA5, - SPELL_FAILED_ONLY_IN_ARENA = 0xA6, - SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 0xA7, - SPELL_FAILED_UNKNOWN = 0xA8, -}; - -enum SpellFamilyNames -{ - SPELLFAMILY_GENERIC = 0, - SPELLFAMILY_UNK1 = 1, // events, holidays - // 2 - unused - SPELLFAMILY_MAGE = 3, - SPELLFAMILY_WARRIOR = 4, - SPELLFAMILY_WARLOCK = 5, - SPELLFAMILY_PRIEST = 6, - SPELLFAMILY_DRUID = 7, - SPELLFAMILY_ROGUE = 8, - SPELLFAMILY_HUNTER = 9, - SPELLFAMILY_PALADIN = 10, - SPELLFAMILY_SHAMAN = 11, - SPELLFAMILY_UNK2 = 12, - SPELLFAMILY_POTION = 13 -}; - -enum SpellDisableTypes -{ - SPELL_DISABLE_PLAYER = 1, - SPELL_DISABLE_CREATURE = 2 -}; - -//Some SpellFamilyFlags -#define SPELLFAMILYFLAG_ROGUE_VANISH 0x000000800LL -#define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL -#define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL -#define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL -#define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL -#define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL -#define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL - -// Spell clasification -enum SpellSpecific -{ - SPELL_NORMAL = 0, - SPELL_SEAL = 1, - SPELL_BLESSING = 2, - SPELL_AURA = 3, - SPELL_STING = 4, - SPELL_CURSE = 5, - SPELL_ASPECT = 6, - SPELL_TRACKER = 7, - SPELL_WARLOCK_ARMOR = 8, - SPELL_MAGE_ARMOR = 9, - SPELL_ELEMENTAL_SHIELD = 10, - SPELL_MAGE_POLYMORPH = 11, - SPELL_POSITIVE_SHOUT = 12, - SPELL_JUDGEMENT = 13, - SPELL_BATTLE_ELIXIR = 14, - SPELL_GUARDIAN_ELIXIR = 15, - SPELL_FLASK_ELIXIR = 16, - SPELL_WARLOCK_CORRUPTION= 17 -}; - -SpellSpecific GetSpellSpecific(uint32 spellId); - -// Different spell properties -inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); } -uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL); -inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); } -inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); } -inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; } -int32 GetSpellDuration(SpellEntry const *spellInfo); -int32 GetSpellMaxDuration(SpellEntry const *spellInfo); - -inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect) -{ - for(int i= 0; i < 3; ++i) - if(spellInfo->Effect[i]==effect) - return true; - return false; -} - -//bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); - -inline bool IsSealSpell(SpellEntry const *spellInfo) -{ - //Collection of all the seal family flags. No other paladin spell has any of those. - return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && - ( spellInfo->SpellFamilyFlags & 0x4000A000200LL ); -} - -inline bool IsElementalShield(SpellEntry const *spellInfo) -{ - // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus - return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552; -} - -int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); -bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2); -bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1,uint32 spellSpec2); -bool IsPassiveSpell(uint32 spellId); - -inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo) -{ - switch(spellInfo->Id) - { - case 40214: // Dragonmaw Illusion - case 35480: case 35481: case 35482: // Human Illusion - case 35483: case 39824: // Human Illusion - return true; - } - - return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT; -} - -inline bool IsNonCombatSpell(SpellEntry const *spellInfo) -{ - return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0; -} - -bool IsPositiveSpell(uint32 spellId); -bool IsPositiveEffect(uint32 spellId, uint32 effIndex); -bool IsPositiveTarget(uint32 targetA, uint32 targetB); - -bool IsSingleTargetSpell(SpellEntry const *spellInfo); -bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2); - -bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id); - -inline bool IsAreaEffectTarget( Targets target ) -{ - switch (target ) - { - case TARGET_AREAEFFECT_CUSTOM: - case TARGET_ALL_ENEMY_IN_AREA: - case TARGET_ALL_ENEMY_IN_AREA_INSTANT: - case TARGET_ALL_PARTY_AROUND_CASTER: - case TARGET_ALL_AROUND_CASTER: - case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: - case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER: - case TARGET_ALL_PARTY: - case TARGET_ALL_PARTY_AROUND_CASTER_2: - case TARGET_AREAEFFECT_PARTY: - case TARGET_AREAEFFECT_CUSTOM_2: - case TARGET_AREAEFFECT_PARTY_AND_CLASS: - case TARGET_IN_FRONT_OF_CASTER: - case TARGET_ALL_FRIENDLY_UNITS_IN_AREA: - return true; - default: - break; - } - return false; -} - -inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo) -{ - if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0]))) - return true; - if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1]))) - return true; - if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2]))) - return true; - return false; -} - -inline bool IsAreaAuraEffect(uint32 effect) -{ - if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY || - effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND || - effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY || - effect == SPELL_EFFECT_APPLY_AREA_AURA_PET || - effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER) - return true; - return false; -} - -inline bool IsDispelSpell(SpellEntry const *spellInfo) -{ - if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL || - spellInfo->Effect[1] == SPELL_EFFECT_DISPEL || - spellInfo->Effect[2] == SPELL_EFFECT_DISPEL ) - return true; - return false; -} -inline bool isSpellBreakStealth(SpellEntry const* spellInfo) -{ - return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH); -} - -uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form); - -inline bool IsChanneledSpell(SpellEntry const* spellInfo) -{ - return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2)); -} - -inline bool NeedsComboPoints(SpellEntry const* spellInfo) -{ - return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2)); -} - -inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo) -{ - return SpellSchoolMask(spellInfo->SchoolMask); -} - -inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect) -{ - uint32 mask = 0; - if (spellInfo->Mechanic) - mask |= 1<Mechanic; - if (spellInfo->EffectMechanic[effect]) - mask |= 1<EffectMechanic[effect]; - return mask; -} - -inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect) -{ - if (spellInfo->EffectMechanic[effect]) - return Mechanics(spellInfo->EffectMechanic[effect]); - if (spellInfo->Mechanic) - return Mechanics(spellInfo->Mechanic); - return MECHANIC_NONE; -} - -inline uint32 GetDispellMask(DispelType dispel) -{ - // If dispel all - if (dispel == DISPEL_ALL) - return DISPEL_ALL_MASK; - else - return (1 << dispel); -} - -// Diminishing Returns interaction with spells -DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered); -bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group); -DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group); - -// Spell affects related declarations (accessed using SpellMgr functions) -typedef std::map SpellAffectMap; - -// Spell proc event related declarations (accessed using SpellMgr functions) -enum ProcFlags -{ - PROC_FLAG_NONE = 0x00000000, // None - PROC_FLAG_HIT_MELEE = 0x00000001, // On melee hit - PROC_FLAG_STRUCK_MELEE = 0x00000002, // On being struck melee - PROC_FLAG_KILL_XP_GIVER = 0x00000004, // On kill target giving XP or honor - PROC_FLAG_SPECIAL_DROP = 0x00000008, // - PROC_FLAG_DODGE = 0x00000010, // On dodge melee attack - PROC_FLAG_PARRY = 0x00000020, // On parry melee attack - PROC_FLAG_BLOCK = 0x00000040, // On block attack - PROC_FLAG_TOUCH = 0x00000080, // On being touched (for bombs, probably?) - PROC_FLAG_TARGET_LOW_HEALTH = 0x00000100, // On deal damage to enemy with 20% or less health - PROC_FLAG_LOW_HEALTH = 0x00000200, // On health dropped below 20% - PROC_FLAG_STRUCK_RANGED = 0x00000400, // On being struck ranged - PROC_FLAG_HIT_SPECIAL = 0x00000800, // (!)Removed, may be reassigned in future - PROC_FLAG_CRIT_MELEE = 0x00001000, // On crit melee - PROC_FLAG_STRUCK_CRIT_MELEE = 0x00002000, // On being critically struck in melee - PROC_FLAG_CAST_SPELL = 0x00004000, // On cast spell - PROC_FLAG_TAKE_DAMAGE = 0x00008000, // On take damage - PROC_FLAG_CRIT_SPELL = 0x00010000, // On crit spell - PROC_FLAG_HIT_SPELL = 0x00020000, // On hit spell - PROC_FLAG_STRUCK_CRIT_SPELL = 0x00040000, // On being critically struck by a spell - PROC_FLAG_HIT_RANGED = 0x00080000, // On getting ranged hit - PROC_FLAG_STRUCK_SPELL = 0x00100000, // On being struck by a spell - PROC_FLAG_TRAP = 0x00200000, // On trap activation (?) - PROC_FLAG_CRIT_RANGED = 0x00400000, // On getting ranged crit - PROC_FLAG_STRUCK_CRIT_RANGED = 0x00800000, // On being critically struck by a ranged attack - PROC_FLAG_RESIST_SPELL = 0x01000000, // On resist enemy spell - PROC_FLAG_TARGET_RESISTS = 0x02000000, // On enemy resisted spell - PROC_FLAG_TARGET_DODGE_OR_PARRY = 0x04000000, // On enemy dodges/parries - PROC_FLAG_HEAL = 0x08000000, // On heal - PROC_FLAG_CRIT_HEAL = 0x10000000, // On critical healing effect - PROC_FLAG_HEALED = 0x20000000, // On healing - PROC_FLAG_TARGET_BLOCK = 0x40000000, // On enemy blocks - PROC_FLAG_MISS = 0x80000000 // On miss melee attack -}; - -struct SpellProcEventEntry -{ - uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2 - uint32 category; // if nonzero - match proc condition based on candidate spell's category - uint32 skillId; // if nonzero - for matching proc condition based on candidate spell's skillId from SkillLineAbility.dbc (Shadow Bolt = Destruction) - uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value - uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do) - uint32 procFlags; // bitmask for matching proc event - float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc - uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_ -}; - -typedef UNORDERED_MAP SpellProcEventMap; - -#define ELIXIR_BATTLE_MASK 0x1 -#define ELIXIR_GUARDIAN_MASK 0x2 -#define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK) -#define ELIXIR_UNSTABLE_MASK 0x4 -#define ELIXIR_SHATTRATH_MASK 0x8 - -typedef std::map SpellElixirMap; - -// Spell script target related declarations (accessed using SpellMgr functions) -enum SpellTargetType -{ - SPELL_TARGET_TYPE_GAMEOBJECT = 0, - SPELL_TARGET_TYPE_CREATURE = 1, - SPELL_TARGET_TYPE_DEAD = 2 -}; - -#define MAX_SPELL_TARGET_TYPE 3 - -struct SpellTargetEntry -{ - SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {} - SpellTargetType type; - uint32 targetEntry; -}; - -typedef std::multimap SpellScriptTarget; - -// coordinates for spells (accessed using SpellMgr functions) -struct SpellTargetPosition -{ - uint32 target_mapId; - float target_X; - float target_Y; - float target_Z; - float target_Orientation; -}; - -typedef UNORDERED_MAP SpellTargetPositionMap; - -// Spell pet auras -class PetAura -{ - public: - PetAura() - { - auras.clear(); - } - - PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) : - removeOnChangePet(_removeOnChangePet), damage(_damage) - { - auras[petEntry] = aura; - } - - uint16 GetAura(uint16 petEntry) const - { - std::map::const_iterator itr = auras.find(petEntry); - if(itr != auras.end()) - return itr->second; - else - { - std::map::const_iterator itr = auras.find(0); - if(itr != auras.end()) - return itr->second; - else - return 0; - } - } - - void AddAura(uint16 petEntry, uint16 aura) - { - auras[petEntry] = aura; - } - - bool IsRemovedOnChangePet() const - { - return removeOnChangePet; - } - - int32 GetDamage() const - { - return damage; - } - - private: - std::map auras; - bool removeOnChangePet; - int32 damage; -}; -typedef std::map SpellPetAuraMap; - -// Spell rank chain (accessed using SpellMgr functions) -struct SpellChainNode -{ - uint32 prev; - uint32 first; - uint32 req; - uint8 rank; -}; - -typedef UNORDERED_MAP SpellChainMap; -typedef std::multimap SpellChainMapNext; - -// Spell learning properties (accessed using SpellMgr functions) -struct SpellLearnSkillNode -{ - uint32 skill; - uint32 value; // 0 - max skill value for player level - uint32 maxvalue; // 0 - max skill value for player level -}; - -typedef std::map SpellLearnSkillMap; - -struct SpellLearnSpellNode -{ - uint32 spell; - bool autoLearned; -}; - -typedef std::multimap SpellLearnSpellMap; - -typedef std::multimap SkillLineAbilityMap; - -inline bool IsPrimaryProfessionSkill(uint32 skill) -{ - SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill); - if(!pSkill) - return false; - - if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION) - return false; - - return true; -} - -inline bool IsProfessionSkill(uint32 skill) -{ - return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID; -} - -#define SPELL_ATTR_CU_PLAYERS_ONLY 0x00000001 -#define SPELL_ATTR_CU_CONE_BACK 0x00000002 -#define SPELL_ATTR_CU_CONE_LINE 0x00000004 -#define SPELL_ATTR_CU_SHARE_DAMAGE 0x00000008 -#define SPELL_ATTR_CU_EFFECT_HEAL 0x00000010 -#define SPELL_ATTR_CU_EFFECT_DAMAGE 0x00000020 - -typedef std::map SpellCustomAttrMap; - -typedef std::map > SpellLinkedMap; - -class SpellMgr -{ - // Constructors - public: - SpellMgr(); - ~SpellMgr(); - - // Accessors (const or static functions) - public: - // Spell affects - uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const - { - SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId); - if( itr != mSpellAffectMap.end( ) ) - return itr->second; - return 0; - } - - bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const; - - SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; } - - uint32 GetSpellElixirMask(uint32 spellid) const - { - SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid); - if(itr==mSpellElixirs.end()) - return 0x0; - - return itr->second; - } - - SpellSpecific GetSpellElixirSpecific(uint32 spellid) const - { - uint32 mask = GetSpellElixirMask(spellid); - if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK) - return SPELL_FLASK_ELIXIR; - else if(mask & ELIXIR_BATTLE_MASK) - return SPELL_BATTLE_ELIXIR; - else if(mask & ELIXIR_GUARDIAN_MASK) - return SPELL_GUARDIAN_ELIXIR; - else - return SPELL_NORMAL; - } - - // Spell proc events - SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const - { - SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId); - if( itr != mSpellProcEventMap.end( ) ) - return &itr->second; - return NULL; - } - - static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ); - - // Spell target coordinates - SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const - { - SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id ); - if( itr != mSpellTargetPositions.end( ) ) - return &itr->second; - return NULL; - } - - // Spell ranks chains - SpellChainNode const* GetSpellChainNode(uint32 spell_id) const - { - SpellChainMap::const_iterator itr = mSpellChains.find(spell_id); - if(itr == mSpellChains.end()) - return NULL; - - return &itr->second; - } - - uint32 GetFirstSpellInChain(uint32 spell_id) const - { - if(SpellChainNode const* node = GetSpellChainNode(spell_id)) - return node->first; - - return spell_id; - } - - uint32 GetPrevSpellInChain(uint32 spell_id) const - { - if(SpellChainNode const* node = GetSpellChainNode(spell_id)) - return node->prev; - - return 0; - } - - SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; } - - // Note: not use rank for compare to spell ranks: spell chains isn't linear order - // Use IsHighRankOfSpell instead - uint8 GetSpellRank(uint32 spell_id) const - { - if(SpellChainNode const* node = GetSpellChainNode(spell_id)) - return node->rank; - - return 0; - } - - uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const - { - SpellChainMap::const_iterator itr = mSpellChains.find(spell1); - - uint32 rank2 = GetSpellRank(spell2); - - // not ordered correctly by rank value - if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2) - return false; - - // check present in same rank chain - for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev)) - if(itr->second.prev==spell2) - return true; - - return false; - } - - bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const; - static bool canStackSpellRanks(SpellEntry const *spellInfo); - bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool isFromTheSameCaster ) const; - - SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const; - - // Spell learning - SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const - { - SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id); - if(itr != mSpellLearnSkills.end()) - return &itr->second; - else - return NULL; - } - - bool IsSpellLearnSpell(uint32 spell_id) const - { - return mSpellLearnSpells.count(spell_id)!=0; - } - - SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const - { - return mSpellLearnSpells.lower_bound(spell_id); - } - - SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const - { - return mSpellLearnSpells.upper_bound(spell_id); - } - - bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const - { - SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1); - SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1); - for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i) - if(i->second.spell==spell_id2) - return true; - return false; - } - - static bool IsProfessionSpell(uint32 spellId); - static bool IsPrimaryProfessionSpell(uint32 spellId); - bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const; - - // Spell script targets - SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const - { - return mSpellScriptTarget.lower_bound(spell_id); - } - - SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const - { - return mSpellScriptTarget.upper_bound(spell_id); - } - - // Spell correctess for client using - static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true); - - SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const - { - return mSkillLineAbilityMap.lower_bound(spell_id); - } - - SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const - { - return mSkillLineAbilityMap.upper_bound(spell_id); - } - - PetAura const* GetPetAura(uint16 spell_id) - { - SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id); - if(itr != mSpellPetAuraMap.end()) - return &itr->second; - else - return NULL; - } - - uint32 GetSpellCustomAttr(uint32 spell_id) const - { - SpellCustomAttrMap::const_iterator itr = mSpellCustomAttrMap.find(spell_id); - if(itr != mSpellCustomAttrMap.end()) - return itr->second; - else - return 0; - } - - const std::vector *GetSpellLinked(int32 spell_id) const - { - SpellLinkedMap::const_iterator itr = mSpellLinkedMap.find(spell_id); - return itr != mSpellLinkedMap.end() ? &(itr->second) : NULL; - } - - // Modifiers - public: - static SpellMgr& Instance(); - - // Loading data at server startup - void LoadSpellChains(); - void LoadSpellLearnSkills(); - void LoadSpellLearnSpells(); - void LoadSpellScriptTarget(); - void LoadSpellAffects(); - void LoadSpellElixirs(); - void LoadSpellProcEvents(); - void LoadSpellTargetPositions(); - void LoadSpellThreats(); - void LoadSkillLineAbilityMap(); - void LoadSpellPetAuras(); - void LoadSpellCustomAttr(); - void LoadSpellLinked(); - - private: - SpellScriptTarget mSpellScriptTarget; - SpellChainMap mSpellChains; - SpellChainMapNext mSpellChainsNext; - SpellLearnSkillMap mSpellLearnSkills; - SpellLearnSpellMap mSpellLearnSpells; - SpellTargetPositionMap mSpellTargetPositions; - SpellAffectMap mSpellAffectMap; - SpellElixirMap mSpellElixirs; - SpellProcEventMap mSpellProcEventMap; - SkillLineAbilityMap mSkillLineAbilityMap; - SpellPetAuraMap mSpellPetAuraMap; - SpellCustomAttrMap mSpellCustomAttrMap; - SpellLinkedMap mSpellLinkedMap; -}; - -#define spellmgr SpellMgr::Instance() -#endif +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _SPELLMGR_H +#define _SPELLMGR_H + +// For static or at-server-startup loaded spell data +// For more high level function for sSpellStore data + +#include "SharedDefines.h" +#include "Database/DBCStructure.h" +#include "Database/SQLStorage.h" + +#include "Utilities/UnorderedMap.h" +#include + +class Player; +class Spell; + +extern SQLStorage sSpellThreatStore; + +enum SpellFailedReason +{ + SPELL_FAILED_AFFECTING_COMBAT = 0x00, + SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 0x01, + SPELL_FAILED_ALREADY_AT_FULL_MANA = 0x02, + SPELL_FAILED_ALREADY_AT_FULL_POWER = 0x03, + SPELL_FAILED_ALREADY_BEING_TAMED = 0x04, + SPELL_FAILED_ALREADY_HAVE_CHARM = 0x05, + SPELL_FAILED_ALREADY_HAVE_SUMMON = 0x06, + SPELL_FAILED_ALREADY_OPEN = 0x07, + SPELL_FAILED_AURA_BOUNCED = 0x08, + SPELL_FAILED_AUTOTRACK_INTERRUPTED = 0x09, + SPELL_FAILED_BAD_IMPLICIT_TARGETS = 0x0A, + SPELL_FAILED_BAD_TARGETS = 0x0B, + SPELL_FAILED_CANT_BE_CHARMED = 0x0C, + SPELL_FAILED_CANT_BE_DISENCHANTED = 0x0D, + SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL = 0x0E, + SPELL_FAILED_CANT_BE_PROSPECTED = 0x0F, + SPELL_FAILED_CANT_CAST_ON_TAPPED = 0x10, + SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE = 0x11, + SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED = 0x12, + SPELL_FAILED_CANT_STEALTH = 0x13, + SPELL_FAILED_CASTER_AURASTATE = 0x14, + SPELL_FAILED_CASTER_DEAD = 0x15, + SPELL_FAILED_CHARMED = 0x16, + SPELL_FAILED_CHEST_IN_USE = 0x17, + SPELL_FAILED_CONFUSED = 0x18, + SPELL_FAILED_DONT_REPORT = 0x19, + SPELL_FAILED_EQUIPPED_ITEM = 0x1A, + SPELL_FAILED_EQUIPPED_ITEM_CLASS = 0x1B, + SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND = 0x1C, + SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND = 0x1D, + SPELL_FAILED_ERROR = 0x1E, + SPELL_FAILED_FIZZLE = 0x1F, + SPELL_FAILED_FLEEING = 0x20, + SPELL_FAILED_FOOD_LOWLEVEL = 0x21, + SPELL_FAILED_HIGHLEVEL = 0x22, + SPELL_FAILED_HUNGER_SATIATED = 0x23, + SPELL_FAILED_IMMUNE = 0x24, + SPELL_FAILED_INTERRUPTED = 0x25, + SPELL_FAILED_INTERRUPTED_COMBAT = 0x26, + SPELL_FAILED_ITEM_ALREADY_ENCHANTED = 0x27, + SPELL_FAILED_ITEM_GONE = 0x28, + SPELL_FAILED_ITEM_NOT_FOUND = 0x29, + SPELL_FAILED_ITEM_NOT_READY = 0x2A, + SPELL_FAILED_LEVEL_REQUIREMENT = 0x2B, + SPELL_FAILED_LINE_OF_SIGHT = 0x2C, + SPELL_FAILED_LOWLEVEL = 0x2D, + SPELL_FAILED_LOW_CASTLEVEL = 0x2E, + SPELL_FAILED_MAINHAND_EMPTY = 0x2F, + SPELL_FAILED_MOVING = 0x30, + SPELL_FAILED_NEED_AMMO = 0x31, + SPELL_FAILED_NEED_AMMO_POUCH = 0x32, + SPELL_FAILED_NEED_EXOTIC_AMMO = 0x33, + SPELL_FAILED_NOPATH = 0x34, + SPELL_FAILED_NOT_BEHIND = 0x35, + SPELL_FAILED_NOT_FISHABLE = 0x36, + SPELL_FAILED_NOT_FLYING = 0x37, + SPELL_FAILED_NOT_HERE = 0x38, + SPELL_FAILED_NOT_INFRONT = 0x39, + SPELL_FAILED_NOT_IN_CONTROL = 0x3A, + SPELL_FAILED_NOT_KNOWN = 0x3B, + SPELL_FAILED_NOT_MOUNTED = 0x3C, + SPELL_FAILED_NOT_ON_TAXI = 0x3D, + SPELL_FAILED_NOT_ON_TRANSPORT = 0x3E, + SPELL_FAILED_NOT_READY = 0x3F, + SPELL_FAILED_NOT_SHAPESHIFT = 0x40, + SPELL_FAILED_NOT_STANDING = 0x41, + SPELL_FAILED_NOT_TRADEABLE = 0x42, + SPELL_FAILED_NOT_TRADING = 0x43, + SPELL_FAILED_NOT_UNSHEATHED = 0x44, + SPELL_FAILED_NOT_WHILE_GHOST = 0x45, + SPELL_FAILED_NO_AMMO = 0x46, + SPELL_FAILED_NO_CHARGES_REMAIN = 0x47, + SPELL_FAILED_NO_CHAMPION = 0x48, + SPELL_FAILED_NO_COMBO_POINTS = 0x49, + SPELL_FAILED_NO_DUELING = 0x4A, + SPELL_FAILED_NO_ENDURANCE = 0x4B, + SPELL_FAILED_NO_FISH = 0x4C, + SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED = 0x4D, + SPELL_FAILED_NO_MOUNTS_ALLOWED = 0x4E, + SPELL_FAILED_NO_PET = 0x4F, + SPELL_FAILED_NO_POWER = 0x50, + SPELL_FAILED_NOTHING_TO_DISPEL = 0x51, + SPELL_FAILED_NOTHING_TO_STEAL = 0x52, + SPELL_FAILED_ONLY_ABOVEWATER = 0x53, + SPELL_FAILED_ONLY_DAYTIME = 0x54, + SPELL_FAILED_ONLY_INDOORS = 0x55, + SPELL_FAILED_ONLY_MOUNTED = 0x56, + SPELL_FAILED_ONLY_NIGHTTIME = 0x57, + SPELL_FAILED_ONLY_OUTDOORS = 0x58, + SPELL_FAILED_ONLY_SHAPESHIFT = 0x59, + SPELL_FAILED_ONLY_STEALTHED = 0x5A, + SPELL_FAILED_ONLY_UNDERWATER = 0x5B, + SPELL_FAILED_OUT_OF_RANGE = 0x5C, + SPELL_FAILED_PACIFIED = 0x5D, + SPELL_FAILED_POSSESSED = 0x5E, + SPELL_FAILED_REAGENTS = 0x5F, + SPELL_FAILED_REQUIRES_AREA = 0x60, + SPELL_FAILED_REQUIRES_SPELL_FOCUS = 0x61, + SPELL_FAILED_ROOTED = 0x62, + SPELL_FAILED_SILENCED = 0x63, + SPELL_FAILED_SPELL_IN_PROGRESS = 0x64, + SPELL_FAILED_SPELL_LEARNED = 0x65, + SPELL_FAILED_SPELL_UNAVAILABLE = 0x66, + SPELL_FAILED_STUNNED = 0x67, + SPELL_FAILED_TARGETS_DEAD = 0x68, + SPELL_FAILED_TARGET_AFFECTING_COMBAT = 0x69, + SPELL_FAILED_TARGET_AURASTATE = 0x6A, + SPELL_FAILED_TARGET_DUELING = 0x6B, + SPELL_FAILED_TARGET_ENEMY = 0x6C, + SPELL_FAILED_TARGET_ENRAGED = 0x6D, + SPELL_FAILED_TARGET_FRIENDLY = 0x6E, + SPELL_FAILED_TARGET_IN_COMBAT = 0x6F, + SPELL_FAILED_TARGET_IS_PLAYER = 0x70, + SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED = 0x71, + SPELL_FAILED_TARGET_NOT_DEAD = 0x72, + SPELL_FAILED_TARGET_NOT_IN_PARTY = 0x73, + SPELL_FAILED_TARGET_NOT_LOOTED = 0x74, + SPELL_FAILED_TARGET_NOT_PLAYER = 0x75, + SPELL_FAILED_TARGET_NO_POCKETS = 0x76, + SPELL_FAILED_TARGET_NO_WEAPONS = 0x77, + SPELL_FAILED_TARGET_UNSKINNABLE = 0x78, + SPELL_FAILED_THIRST_SATIATED = 0x79, + SPELL_FAILED_TOO_CLOSE = 0x7A, + SPELL_FAILED_TOO_MANY_OF_ITEM = 0x7B, + SPELL_FAILED_TOTEM_CATEGORY = 0x7C, + SPELL_FAILED_TOTEMS = 0x7D, + SPELL_FAILED_TRAINING_POINTS = 0x7E, + SPELL_FAILED_TRY_AGAIN = 0x7F, + SPELL_FAILED_UNIT_NOT_BEHIND = 0x80, + SPELL_FAILED_UNIT_NOT_INFRONT = 0x81, + SPELL_FAILED_WRONG_PET_FOOD = 0x82, + SPELL_FAILED_NOT_WHILE_FATIGUED = 0x83, + SPELL_FAILED_TARGET_NOT_IN_INSTANCE = 0x84, + SPELL_FAILED_NOT_WHILE_TRADING = 0x85, + SPELL_FAILED_TARGET_NOT_IN_RAID = 0x86, + SPELL_FAILED_DISENCHANT_WHILE_LOOTING = 0x87, + SPELL_FAILED_PROSPECT_WHILE_LOOTING = 0x88, + SPELL_FAILED_PROSPECT_NEED_MORE = 0x89, + SPELL_FAILED_TARGET_FREEFORALL = 0x8A, + SPELL_FAILED_NO_EDIBLE_CORPSES = 0x8B, + SPELL_FAILED_ONLY_BATTLEGROUNDS = 0x8C, + SPELL_FAILED_TARGET_NOT_GHOST = 0x8D, + SPELL_FAILED_TOO_MANY_SKILLS = 0x8E, + SPELL_FAILED_TRANSFORM_UNUSABLE = 0x8F, + SPELL_FAILED_WRONG_WEATHER = 0x90, + SPELL_FAILED_DAMAGE_IMMUNE = 0x91, + SPELL_FAILED_PREVENTED_BY_MECHANIC = 0x92, + SPELL_FAILED_PLAY_TIME = 0x93, + SPELL_FAILED_REPUTATION = 0x94, + SPELL_FAILED_MIN_SKILL = 0x95, + SPELL_FAILED_NOT_IN_ARENA = 0x96, + SPELL_FAILED_NOT_ON_SHAPESHIFT = 0x97, + SPELL_FAILED_NOT_ON_STEALTHED = 0x98, + SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE = 0x99, + SPELL_FAILED_NOT_ON_MOUNTED = 0x9A, + SPELL_FAILED_TOO_SHALLOW = 0x9B, + SPELL_FAILED_TARGET_NOT_IN_SANCTUARY = 0x9C, + SPELL_FAILED_TARGET_IS_TRIVIAL = 0x9D, + SPELL_FAILED_BM_OR_INVISGOD = 0x9E, + SPELL_FAILED_EXPERT_RIDING_REQUIREMENT = 0x9F, + SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT = 0xA0, + SPELL_FAILED_NOT_IDLE = 0xA1, + SPELL_FAILED_NOT_INACTIVE = 0xA2, + SPELL_FAILED_PARTIAL_PLAYTIME = 0xA3, + SPELL_FAILED_NO_PLAYTIME = 0xA4, + SPELL_FAILED_NOT_IN_BATTLEGROUND = 0xA5, + SPELL_FAILED_ONLY_IN_ARENA = 0xA6, + SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 0xA7, + SPELL_FAILED_UNKNOWN = 0xA8, +}; + +enum SpellFamilyNames +{ + SPELLFAMILY_GENERIC = 0, + SPELLFAMILY_UNK1 = 1, // events, holidays + // 2 - unused + SPELLFAMILY_MAGE = 3, + SPELLFAMILY_WARRIOR = 4, + SPELLFAMILY_WARLOCK = 5, + SPELLFAMILY_PRIEST = 6, + SPELLFAMILY_DRUID = 7, + SPELLFAMILY_ROGUE = 8, + SPELLFAMILY_HUNTER = 9, + SPELLFAMILY_PALADIN = 10, + SPELLFAMILY_SHAMAN = 11, + SPELLFAMILY_UNK2 = 12, + SPELLFAMILY_POTION = 13 +}; + +enum SpellDisableTypes +{ + SPELL_DISABLE_PLAYER = 1, + SPELL_DISABLE_CREATURE = 2 +}; + +//Some SpellFamilyFlags +#define SPELLFAMILYFLAG_ROGUE_VANISH 0x000000800LL +#define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL +#define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL +#define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL +#define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL +#define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL +#define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL + +// Spell clasification +enum SpellSpecific +{ + SPELL_NORMAL = 0, + SPELL_SEAL = 1, + SPELL_BLESSING = 2, + SPELL_AURA = 3, + SPELL_STING = 4, + SPELL_CURSE = 5, + SPELL_ASPECT = 6, + SPELL_TRACKER = 7, + SPELL_WARLOCK_ARMOR = 8, + SPELL_MAGE_ARMOR = 9, + SPELL_ELEMENTAL_SHIELD = 10, + SPELL_MAGE_POLYMORPH = 11, + SPELL_POSITIVE_SHOUT = 12, + SPELL_JUDGEMENT = 13, + SPELL_BATTLE_ELIXIR = 14, + SPELL_GUARDIAN_ELIXIR = 15, + SPELL_FLASK_ELIXIR = 16, + SPELL_WARLOCK_CORRUPTION= 17 +}; + +SpellSpecific GetSpellSpecific(uint32 spellId); + +// Different spell properties +inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); } +uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL); +inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); } +inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); } +inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; } +int32 GetSpellDuration(SpellEntry const *spellInfo); +int32 GetSpellMaxDuration(SpellEntry const *spellInfo); + +inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect) +{ + for(int i= 0; i < 3; ++i) + if(spellInfo->Effect[i]==effect) + return true; + return false; +} + +bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); + +inline bool IsSealSpell(SpellEntry const *spellInfo) +{ + //Collection of all the seal family flags. No other paladin spell has any of those. + return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && + ( spellInfo->SpellFamilyFlags & 0x4000A000200LL ); +} + +inline bool IsElementalShield(SpellEntry const *spellInfo) +{ + // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus + return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552; +} + +int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); +bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2); +bool IsPassiveSpell(uint32 spellId); + +inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo) +{ + switch(spellInfo->Id) + { + case 40214: // Dragonmaw Illusion + case 35480: case 35481: case 35482: // Human Illusion + case 35483: case 39824: // Human Illusion + return true; + } + + return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT; +} + +inline bool IsNonCombatSpell(SpellEntry const *spellInfo) +{ + return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0; +} + +bool IsPositiveSpell(uint32 spellId); +bool IsPositiveEffect(uint32 spellId, uint32 effIndex); +bool IsPositiveTarget(uint32 targetA, uint32 targetB); + +bool IsSingleTargetSpell(SpellEntry const *spellInfo); +bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2); + +bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id); + +inline bool IsAreaEffectTarget( Targets target ) +{ + switch (target ) + { + case TARGET_AREAEFFECT_CUSTOM: + case TARGET_ALL_ENEMY_IN_AREA: + case TARGET_ALL_ENEMY_IN_AREA_INSTANT: + case TARGET_ALL_PARTY_AROUND_CASTER: + case TARGET_ALL_AROUND_CASTER: + case TARGET_ALL_ENEMY_IN_AREA_CHANNELED: + case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER: + case TARGET_ALL_PARTY: + case TARGET_ALL_PARTY_AROUND_CASTER_2: + case TARGET_AREAEFFECT_PARTY: + case TARGET_AREAEFFECT_CUSTOM_2: + case TARGET_AREAEFFECT_PARTY_AND_CLASS: + case TARGET_IN_FRONT_OF_CASTER: + case TARGET_ALL_FRIENDLY_UNITS_IN_AREA: + return true; + default: + break; + } + return false; +} + +inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo) +{ + if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0]))) + return true; + if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1]))) + return true; + if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2]))) + return true; + return false; +} + +inline bool IsAreaAuraEffect(uint32 effect) +{ + if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY || + effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND || + effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY || + effect == SPELL_EFFECT_APPLY_AREA_AURA_PET || + effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER) + return true; + return false; +} + +inline bool IsDispelSpell(SpellEntry const *spellInfo) +{ + if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL || + spellInfo->Effect[1] == SPELL_EFFECT_DISPEL || + spellInfo->Effect[2] == SPELL_EFFECT_DISPEL ) + return true; + return false; +} +inline bool isSpellBreakStealth(SpellEntry const* spellInfo) +{ + return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH); +} + +uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form); + +inline bool IsChanneledSpell(SpellEntry const* spellInfo) +{ + return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2)); +} + +inline bool NeedsComboPoints(SpellEntry const* spellInfo) +{ + return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2)); +} + +inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo) +{ + return SpellSchoolMask(spellInfo->SchoolMask); +} + +inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect) +{ + uint32 mask = 0; + if (spellInfo->Mechanic) + mask |= 1<Mechanic; + if (spellInfo->EffectMechanic[effect]) + mask |= 1<EffectMechanic[effect]; + return mask; +} + +inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect) +{ + if (spellInfo->EffectMechanic[effect]) + return Mechanics(spellInfo->EffectMechanic[effect]); + if (spellInfo->Mechanic) + return Mechanics(spellInfo->Mechanic); + return MECHANIC_NONE; +} + +inline uint32 GetDispellMask(DispelType dispel) +{ + // If dispel all + if (dispel == DISPEL_ALL) + return DISPEL_ALL_MASK; + else + return (1 << dispel); +} + +// Diminishing Returns interaction with spells +DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered); +bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group); +DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group); + +// Spell affects related declarations (accessed using SpellMgr functions) +typedef std::map SpellAffectMap; + +// Spell proc event related declarations (accessed using SpellMgr functions) +enum ProcFlags +{ + PROC_FLAG_NONE = 0x00000000, // None + PROC_FLAG_HIT_MELEE = 0x00000001, // On melee hit + PROC_FLAG_STRUCK_MELEE = 0x00000002, // On being struck melee + PROC_FLAG_KILL_XP_GIVER = 0x00000004, // On kill target giving XP or honor + PROC_FLAG_SPECIAL_DROP = 0x00000008, // + PROC_FLAG_DODGE = 0x00000010, // On dodge melee attack + PROC_FLAG_PARRY = 0x00000020, // On parry melee attack + PROC_FLAG_BLOCK = 0x00000040, // On block attack + PROC_FLAG_TOUCH = 0x00000080, // On being touched (for bombs, probably?) + PROC_FLAG_TARGET_LOW_HEALTH = 0x00000100, // On deal damage to enemy with 20% or less health + PROC_FLAG_LOW_HEALTH = 0x00000200, // On health dropped below 20% + PROC_FLAG_STRUCK_RANGED = 0x00000400, // On being struck ranged + PROC_FLAG_HIT_SPECIAL = 0x00000800, // (!)Removed, may be reassigned in future + PROC_FLAG_CRIT_MELEE = 0x00001000, // On crit melee + PROC_FLAG_STRUCK_CRIT_MELEE = 0x00002000, // On being critically struck in melee + PROC_FLAG_CAST_SPELL = 0x00004000, // On cast spell + PROC_FLAG_TAKE_DAMAGE = 0x00008000, // On take damage + PROC_FLAG_CRIT_SPELL = 0x00010000, // On crit spell + PROC_FLAG_HIT_SPELL = 0x00020000, // On hit spell + PROC_FLAG_STRUCK_CRIT_SPELL = 0x00040000, // On being critically struck by a spell + PROC_FLAG_HIT_RANGED = 0x00080000, // On getting ranged hit + PROC_FLAG_STRUCK_SPELL = 0x00100000, // On being struck by a spell + PROC_FLAG_TRAP = 0x00200000, // On trap activation (?) + PROC_FLAG_CRIT_RANGED = 0x00400000, // On getting ranged crit + PROC_FLAG_STRUCK_CRIT_RANGED = 0x00800000, // On being critically struck by a ranged attack + PROC_FLAG_RESIST_SPELL = 0x01000000, // On resist enemy spell + PROC_FLAG_TARGET_RESISTS = 0x02000000, // On enemy resisted spell + PROC_FLAG_TARGET_DODGE_OR_PARRY = 0x04000000, // On enemy dodges/parries + PROC_FLAG_HEAL = 0x08000000, // On heal + PROC_FLAG_CRIT_HEAL = 0x10000000, // On critical healing effect + PROC_FLAG_HEALED = 0x20000000, // On healing + PROC_FLAG_TARGET_BLOCK = 0x40000000, // On enemy blocks + PROC_FLAG_MISS = 0x80000000 // On miss melee attack +}; + +struct SpellProcEventEntry +{ + uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2 + uint32 category; // if nonzero - match proc condition based on candidate spell's category + uint32 skillId; // if nonzero - for matching proc condition based on candidate spell's skillId from SkillLineAbility.dbc (Shadow Bolt = Destruction) + uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value + uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do) + uint32 procFlags; // bitmask for matching proc event + float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc + uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_ +}; + +typedef UNORDERED_MAP SpellProcEventMap; + +#define ELIXIR_BATTLE_MASK 0x1 +#define ELIXIR_GUARDIAN_MASK 0x2 +#define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK) +#define ELIXIR_UNSTABLE_MASK 0x4 +#define ELIXIR_SHATTRATH_MASK 0x8 + +typedef std::map SpellElixirMap; + +// Spell script target related declarations (accessed using SpellMgr functions) +enum SpellTargetType +{ + SPELL_TARGET_TYPE_GAMEOBJECT = 0, + SPELL_TARGET_TYPE_CREATURE = 1, + SPELL_TARGET_TYPE_DEAD = 2 +}; + +#define MAX_SPELL_TARGET_TYPE 3 + +struct SpellTargetEntry +{ + SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {} + SpellTargetType type; + uint32 targetEntry; +}; + +typedef std::multimap SpellScriptTarget; + +// coordinates for spells (accessed using SpellMgr functions) +struct SpellTargetPosition +{ + uint32 target_mapId; + float target_X; + float target_Y; + float target_Z; + float target_Orientation; +}; + +typedef UNORDERED_MAP SpellTargetPositionMap; + +// Spell pet auras +class PetAura +{ + public: + PetAura() + { + auras.clear(); + } + + PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) : + removeOnChangePet(_removeOnChangePet), damage(_damage) + { + auras[petEntry] = aura; + } + + uint16 GetAura(uint16 petEntry) const + { + std::map::const_iterator itr = auras.find(petEntry); + if(itr != auras.end()) + return itr->second; + else + { + std::map::const_iterator itr = auras.find(0); + if(itr != auras.end()) + return itr->second; + else + return 0; + } + } + + void AddAura(uint16 petEntry, uint16 aura) + { + auras[petEntry] = aura; + } + + bool IsRemovedOnChangePet() const + { + return removeOnChangePet; + } + + int32 GetDamage() const + { + return damage; + } + + private: + std::map auras; + bool removeOnChangePet; + int32 damage; +}; +typedef std::map SpellPetAuraMap; + +// Spell rank chain (accessed using SpellMgr functions) +struct SpellChainNode +{ + uint32 prev; + uint32 first; + uint32 req; + uint8 rank; +}; + +typedef UNORDERED_MAP SpellChainMap; +typedef std::multimap SpellChainMapNext; + +// Spell learning properties (accessed using SpellMgr functions) +struct SpellLearnSkillNode +{ + uint32 skill; + uint32 value; // 0 - max skill value for player level + uint32 maxvalue; // 0 - max skill value for player level +}; + +typedef std::map SpellLearnSkillMap; + +struct SpellLearnSpellNode +{ + uint32 spell; + bool autoLearned; +}; + +typedef std::multimap SpellLearnSpellMap; + +typedef std::multimap SkillLineAbilityMap; + +inline bool IsPrimaryProfessionSkill(uint32 skill) +{ + SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill); + if(!pSkill) + return false; + + if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION) + return false; + + return true; +} + +inline bool IsProfessionSkill(uint32 skill) +{ + return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID; +} + +#define SPELL_ATTR_CU_PLAYERS_ONLY 0x00000001 +#define SPELL_ATTR_CU_CONE_BACK 0x00000002 +#define SPELL_ATTR_CU_CONE_LINE 0x00000004 +#define SPELL_ATTR_CU_SHARE_DAMAGE 0x00000008 +#define SPELL_ATTR_CU_EFFECT_HEAL 0x00000010 +#define SPELL_ATTR_CU_EFFECT_DAMAGE 0x00000020 + +typedef std::map SpellCustomAttrMap; + +typedef std::map > SpellLinkedMap; + +class SpellMgr +{ + // Constructors + public: + SpellMgr(); + ~SpellMgr(); + + // Accessors (const or static functions) + public: + // Spell affects + uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const + { + SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId); + if( itr != mSpellAffectMap.end( ) ) + return itr->second; + return 0; + } + + bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const; + + SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; } + + uint32 GetSpellElixirMask(uint32 spellid) const + { + SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid); + if(itr==mSpellElixirs.end()) + return 0x0; + + return itr->second; + } + + SpellSpecific GetSpellElixirSpecific(uint32 spellid) const + { + uint32 mask = GetSpellElixirMask(spellid); + if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK) + return SPELL_FLASK_ELIXIR; + else if(mask & ELIXIR_BATTLE_MASK) + return SPELL_BATTLE_ELIXIR; + else if(mask & ELIXIR_GUARDIAN_MASK) + return SPELL_GUARDIAN_ELIXIR; + else + return SPELL_NORMAL; + } + + // Spell proc events + SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const + { + SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId); + if( itr != mSpellProcEventMap.end( ) ) + return &itr->second; + return NULL; + } + + static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags ); + + // Spell target coordinates + SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const + { + SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id ); + if( itr != mSpellTargetPositions.end( ) ) + return &itr->second; + return NULL; + } + + // Spell ranks chains + SpellChainNode const* GetSpellChainNode(uint32 spell_id) const + { + SpellChainMap::const_iterator itr = mSpellChains.find(spell_id); + if(itr == mSpellChains.end()) + return NULL; + + return &itr->second; + } + + uint32 GetFirstSpellInChain(uint32 spell_id) const + { + if(SpellChainNode const* node = GetSpellChainNode(spell_id)) + return node->first; + + return spell_id; + } + + uint32 GetPrevSpellInChain(uint32 spell_id) const + { + if(SpellChainNode const* node = GetSpellChainNode(spell_id)) + return node->prev; + + return 0; + } + + SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; } + + // Note: not use rank for compare to spell ranks: spell chains isn't linear order + // Use IsHighRankOfSpell instead + uint8 GetSpellRank(uint32 spell_id) const + { + if(SpellChainNode const* node = GetSpellChainNode(spell_id)) + return node->rank; + + return 0; + } + + uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const + { + SpellChainMap::const_iterator itr = mSpellChains.find(spell1); + + uint32 rank2 = GetSpellRank(spell2); + + // not ordered correctly by rank value + if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2) + return false; + + // check present in same rank chain + for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev)) + if(itr->second.prev==spell2) + return true; + + return false; + } + + bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const; + static bool canStackSpellRanks(SpellEntry const *spellInfo); + bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const; + + SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const; + + // Spell learning + SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const + { + SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id); + if(itr != mSpellLearnSkills.end()) + return &itr->second; + else + return NULL; + } + + bool IsSpellLearnSpell(uint32 spell_id) const + { + return mSpellLearnSpells.count(spell_id)!=0; + } + + SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const + { + return mSpellLearnSpells.lower_bound(spell_id); + } + + SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const + { + return mSpellLearnSpells.upper_bound(spell_id); + } + + bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const + { + SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1); + SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1); + for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i) + if(i->second.spell==spell_id2) + return true; + return false; + } + + static bool IsProfessionSpell(uint32 spellId); + static bool IsPrimaryProfessionSpell(uint32 spellId); + bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const; + + // Spell script targets + SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const + { + return mSpellScriptTarget.lower_bound(spell_id); + } + + SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const + { + return mSpellScriptTarget.upper_bound(spell_id); + } + + // Spell correctess for client using + static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true); + + SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const + { + return mSkillLineAbilityMap.lower_bound(spell_id); + } + + SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const + { + return mSkillLineAbilityMap.upper_bound(spell_id); + } + + PetAura const* GetPetAura(uint16 spell_id) + { + SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id); + if(itr != mSpellPetAuraMap.end()) + return &itr->second; + else + return NULL; + } + + uint32 GetSpellCustomAttr(uint32 spell_id) const + { + SpellCustomAttrMap::const_iterator itr = mSpellCustomAttrMap.find(spell_id); + if(itr != mSpellCustomAttrMap.end()) + return itr->second; + else + return 0; + } + + const std::vector *GetSpellLinked(int32 spell_id) const + { + SpellLinkedMap::const_iterator itr = mSpellLinkedMap.find(spell_id); + return itr != mSpellLinkedMap.end() ? &(itr->second) : NULL; + } + + // Modifiers + public: + static SpellMgr& Instance(); + + // Loading data at server startup + void LoadSpellChains(); + void LoadSpellLearnSkills(); + void LoadSpellLearnSpells(); + void LoadSpellScriptTarget(); + void LoadSpellAffects(); + void LoadSpellElixirs(); + void LoadSpellProcEvents(); + void LoadSpellTargetPositions(); + void LoadSpellThreats(); + void LoadSkillLineAbilityMap(); + void LoadSpellPetAuras(); + void LoadSpellCustomAttr(); + void LoadSpellLinked(); + + private: + SpellScriptTarget mSpellScriptTarget; + SpellChainMap mSpellChains; + SpellChainMapNext mSpellChainsNext; + SpellLearnSkillMap mSpellLearnSkills; + SpellLearnSpellMap mSpellLearnSpells; + SpellTargetPositionMap mSpellTargetPositions; + SpellAffectMap mSpellAffectMap; + SpellElixirMap mSpellElixirs; + SpellProcEventMap mSpellProcEventMap; + SkillLineAbilityMap mSkillLineAbilityMap; + SpellPetAuraMap mSpellPetAuraMap; + SpellCustomAttrMap mSpellCustomAttrMap; + SpellLinkedMap mSpellLinkedMap; +}; + +#define spellmgr SpellMgr::Instance() +#endif diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 22249af36d6..a6dae99b7ef 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -1,10812 +1,10845 @@ -/* - * Copyright (C) 2005-2008 MaNGOS - * - * Copyright (C) 2008 Trinity - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "Common.h" -#include "Log.h" -#include "Opcodes.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#include "World.h" -#include "ObjectMgr.h" -#include "SpellMgr.h" -#include "Unit.h" -#include "QuestDef.h" -#include "Player.h" -#include "Creature.h" -#include "Spell.h" -#include "Group.h" -#include "SpellAuras.h" -#include "MapManager.h" -#include "ObjectAccessor.h" -#include "CreatureAI.h" -#include "Formulas.h" -#include "Pet.h" -#include "Util.h" -#include "Totem.h" -#include "BattleGround.h" -#include "OutdoorPvP.h" -#include "InstanceSaveMgr.h" -#include "GridNotifiersImpl.h" -#include "CellImpl.h" -#include "Path.h" - -#include - -float baseMoveSpeed[MAX_MOVE_TYPE] = -{ - 2.5f, // MOVE_WALK - 7.0f, // MOVE_RUN - 1.25f, // MOVE_WALKBACK - 4.722222f, // MOVE_SWIM - 4.5f, // MOVE_SWIMBACK - 3.141594f, // MOVE_TURN - 7.0f, // MOVE_FLY - 4.5f, // MOVE_FLYBACK -}; - -// auraTypes contains attacker auras capable of proc'ing cast auras -static Unit::AuraTypeSet GenerateAttakerProcCastAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_DUMMY); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); - auraTypes.insert(SPELL_AURA_MOD_HASTE); - auraTypes.insert(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - return auraTypes; -} - -// auraTypes contains victim auras capable of proc'ing cast auras -static Unit::AuraTypeSet GenerateVictimProcCastAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_DUMMY); - auraTypes.insert(SPELL_AURA_PRAYER_OF_MENDING); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); - return auraTypes; -} - -// auraTypes contains auras capable of proc effect/damage (but not cast) for attacker -static Unit::AuraTypeSet GenerateAttakerProcEffectAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_MOD_DAMAGE_DONE); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); - auraTypes.insert(SPELL_AURA_MOD_CASTING_SPEED); - auraTypes.insert(SPELL_AURA_MOD_RATING); - return auraTypes; -} - -// auraTypes contains auras capable of proc effect/damage (but not cast) for victim -static Unit::AuraTypeSet GenerateVictimProcEffectAuraTypes() -{ - static Unit::AuraTypeSet auraTypes; - auraTypes.insert(SPELL_AURA_MOD_RESISTANCE); - auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); - auraTypes.insert(SPELL_AURA_MOD_PARRY_PERCENT); - auraTypes.insert(SPELL_AURA_MOD_BLOCK_PERCENT); - auraTypes.insert(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); - return auraTypes; -} - -static Unit::AuraTypeSet attackerProcCastAuraTypes = GenerateAttakerProcCastAuraTypes(); -static Unit::AuraTypeSet attackerProcEffectAuraTypes = GenerateAttakerProcEffectAuraTypes(); - -static Unit::AuraTypeSet victimProcCastAuraTypes = GenerateVictimProcCastAuraTypes(); -static Unit::AuraTypeSet victimProcEffectAuraTypes = GenerateVictimProcEffectAuraTypes(); - -// auraTypes contains auras capable of proc'ing for attacker and victim -static Unit::AuraTypeSet GenerateProcAuraTypes() -{ - Unit::AuraTypeSet auraTypes; - auraTypes.insert(attackerProcCastAuraTypes.begin(),attackerProcCastAuraTypes.end()); - auraTypes.insert(attackerProcEffectAuraTypes.begin(),attackerProcEffectAuraTypes.end()); - auraTypes.insert(victimProcCastAuraTypes.begin(),victimProcCastAuraTypes.end()); - auraTypes.insert(victimProcEffectAuraTypes.begin(),victimProcEffectAuraTypes.end()); - return auraTypes; -} - -static Unit::AuraTypeSet procAuraTypes = GenerateProcAuraTypes(); - -bool IsPassiveStackableSpell( uint32 spellId ) -{ - if(!IsPassiveSpell(spellId)) - return false; - - SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); - if(!spellProto) - return false; - - for(int j = 0; j < 3; ++j) - { - if(std::find(procAuraTypes.begin(),procAuraTypes.end(),spellProto->EffectApplyAuraName[j])!=procAuraTypes.end()) - return false; - } - - return true; -} - -Unit::Unit() -: WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) -{ - m_objectType |= TYPEMASK_UNIT; - m_objectTypeId = TYPEID_UNIT; - // 2.3.2 - 0x70 - m_updateFlag = (UPDATEFLAG_HIGHGUID | UPDATEFLAG_LIVING | UPDATEFLAG_HASPOSITION); - - m_attackTimer[BASE_ATTACK] = 0; - m_attackTimer[OFF_ATTACK] = 0; - m_attackTimer[RANGED_ATTACK] = 0; - m_modAttackSpeedPct[BASE_ATTACK] = 1.0f; - m_modAttackSpeedPct[OFF_ATTACK] = 1.0f; - m_modAttackSpeedPct[RANGED_ATTACK] = 1.0f; - - m_extraAttacks = 0; - m_canDualWield = false; - - m_state = 0; - m_form = FORM_NONE; - m_deathState = ALIVE; - - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - m_currentSpells[i] = NULL; - - m_addDmgOnce = 0; - - for(int i = 0; i < MAX_TOTEM; ++i) - m_TotemSlot[i] = 0; - - m_ObjectSlot[0] = m_ObjectSlot[1] = m_ObjectSlot[2] = m_ObjectSlot[3] = 0; - //m_Aura = NULL; - //m_AurasCheck = 2000; - //m_removeAuraTimer = 4; - //tmpAura = NULL; - waterbreath = false; - - m_Visibility = VISIBILITY_ON; - - m_interruptMask = 0; - m_detectInvisibilityMask = 0; - m_invisibilityMask = 0; - m_transform = 0; - m_ShapeShiftFormSpellId = 0; - m_canModifyStats = false; - - for (int i = 0; i < MAX_SPELL_IMMUNITY; i++) - m_spellImmune[i].clear(); - for (int i = 0; i < UNIT_MOD_END; i++) - { - m_auraModifiersGroup[i][BASE_VALUE] = 0.0f; - m_auraModifiersGroup[i][BASE_PCT] = 1.0f; - m_auraModifiersGroup[i][TOTAL_VALUE] = 0.0f; - m_auraModifiersGroup[i][TOTAL_PCT] = 1.0f; - } - // implement 50% base damage from offhand - m_auraModifiersGroup[UNIT_MOD_DAMAGE_OFFHAND][TOTAL_PCT] = 0.5f; - - for (int i = 0; i < 3; i++) - { - m_weaponDamage[i][MINDAMAGE] = BASE_MINDAMAGE; - m_weaponDamage[i][MAXDAMAGE] = BASE_MAXDAMAGE; - } - for (int i = 0; i < MAX_STATS; i++) - m_createStats[i] = 0.0f; - - m_attacking = NULL; - m_modMeleeHitChance = 0.0f; - m_modRangedHitChance = 0.0f; - m_modSpellHitChance = 0.0f; - m_baseSpellCritChance = 5; - - m_CombatTimer = 0; - m_lastManaUse = 0; - - //m_victimThreat = 0.0f; - for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) - m_threatModifier[i] = 1.0f; - m_isSorted = true; - for (int i = 0; i < MAX_MOVE_TYPE; ++i) - m_speed_rate[i] = 1.0f; - - m_removedAuras = 0; - m_charmInfo = NULL; - m_unit_movement_flags = 0; - m_isPossessed = false; - - // remove aurastates allowing special moves - for(int i=0; i < MAX_REACTIVE; ++i) - m_reactiveTimer[i] = 0; -} - -Unit::~Unit() -{ - // set current spells as deletable - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - { - if (m_currentSpells[i]) - { - m_currentSpells[i]->SetReferencedFromCurrent(false); - m_currentSpells[i] = NULL; - } - } - - RemoveAllGameObjects(); - RemoveAllDynObjects(); - - if(m_charmInfo) delete m_charmInfo; -} - -void Unit::Update( uint32 p_time ) -{ - /*if(p_time > m_AurasCheck) - { - m_AurasCheck = 2000; - _UpdateAura(); - }else - m_AurasCheck -= p_time;*/ - - // WARNING! Order of execution here is important, do not change. - // Spells must be processed with event system BEFORE they go to _UpdateSpells. - // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad. - m_Events.Update( p_time ); - _UpdateSpells( p_time ); - - // update combat timer only for players and pets - if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet() || ((Creature*)this)->isCharmed())) - { - // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away - // targets without stopping half way there and running off. - // These flags are reset after target dies or another command is given. - if( m_HostilRefManager.isEmpty() ) - { - // m_CombatTimer set at aura start and it will be freeze until aura removing - if ( m_CombatTimer <= p_time ) - ClearInCombat(); - else - m_CombatTimer -= p_time; - } - } - - if(!hasUnitState(UNIT_STAT_CASTING)) - { - if(uint32 base_att = getAttackTimer(BASE_ATTACK)) - setAttackTimer(BASE_ATTACK, (p_time >= base_att ? 0 : base_att - p_time) ); - if(uint32 ranged_att = getAttackTimer(RANGED_ATTACK)) - setAttackTimer(RANGED_ATTACK, (p_time >= ranged_att ? 0 : ranged_att - p_time) ); - if(uint32 off_att = getAttackTimer(OFF_ATTACK)) - setAttackTimer(OFF_ATTACK, (p_time >= off_att ? 0 : off_att - p_time) ); - } - - // update abilities available only for fraction of time - UpdateReactives( p_time ); - - ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, GetHealth() < GetMaxHealth()*0.20f); - ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, GetHealth() < GetMaxHealth()*0.35f); - - i_motionMaster.UpdateMotion(p_time); -} - -bool Unit::haveOffhandWeapon() const -{ - if(GetTypeId() == TYPEID_PLAYER) - return ((Player*)this)->GetWeaponForAttack(OFF_ATTACK,true); - else - return m_canDualWield; -} - -void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player* player) -{ - float x, y, z; - if(GetMotionMaster()->GetDestination(x, y, z)) - SendMonsterMoveWithSpeed(x, y, z, GetUnitMovementFlags(), 0, player); -} - -void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime, Player* player) -{ - if (!transitTime) - { - float dx = x - GetPositionX(); - float dy = y - GetPositionY(); - float dz = z - GetPositionZ(); - - float dist = ((dx*dx) + (dy*dy) + (dz*dz)); - if(dist<0) - dist = 0; - else - dist = sqrt(dist); - - double speed = GetSpeed((MovementFlags & MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); - if(speed<=0) - speed = 2.5f; - speed *= 0.001f; - transitTime = static_cast(dist / speed + 0.5); - } - //float orientation = (float)atan2((double)dy, (double)dx); - SendMonsterMove(x, y, z, 0, MovementFlags, transitTime, player); -} - -void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player) -{ - WorldPacket data( SMSG_MONSTER_MOVE, (41 + GetPackGUID().size()) ); - data.append(GetPackGUID()); - - // Point A, starting location - data << GetPositionX() << GetPositionY() << GetPositionZ(); - // unknown field - unrelated to orientation - // seems to increment about 1000 for every 1.7 seconds - // for now, we'll just use mstime - data << getMSTime(); - - data << uint8(type); // unknown - switch(type) - { - case 0: // normal packet - break; - case 1: // stop packet - SendMessageToSet( &data, true ); - return; - case 3: // not used currently - data << uint64(0); // probably target guid - break; - case 4: // not used currently - data << float(0); // probably orientation - break; - } - - //Movement Flags (0x0 = walk, 0x100 = run, 0x200 = fly/swim) - data << uint32(MovementFlags); - - data << Time; // Time in between points - data << uint32(1); // 1 single waypoint - data << NewPosX << NewPosY << NewPosZ; // the single waypoint Point B - - if(player) - player->GetSession()->SendPacket(&data); - else - SendMessageToSet( &data, true ); -} - -void Unit::SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, uint32 MovementFlags) -{ - uint32 traveltime = uint32(path.GetTotalLength(start, end) * 32); - - uint32 pathSize = end-start; - - WorldPacket data( SMSG_MONSTER_MOVE, (GetPackGUID().size()+4+4+4+4+1+4+4+4+pathSize*4*3) ); - data.append(GetPackGUID()); - data << GetPositionX(); - data << GetPositionY(); - data << GetPositionZ(); - - // unknown field - unrelated to orientation - // seems to increment about 1000 for every 1.7 seconds - // for now, we'll just use mstime - data << getMSTime(); - - data << uint8( 0 ); - data << uint32( MovementFlags ); - data << uint32( traveltime ); - data << uint32( pathSize ); - data.append( (char*)path.GetNodes(start), pathSize * 4 * 3 ); - - //WPAssert( data.size() == 37 + pathnodes.Size( ) * 4 * 3 ); - SendMessageToSet(&data, true); -} - -void Unit::resetAttackTimer(WeaponAttackType type) -{ - m_attackTimer[type] = uint32(GetAttackTime(type) * m_modAttackSpeedPct[type]); -} - -bool Unit::canReachWithAttack(Unit *pVictim) const -{ - assert(pVictim); - return IsWithinDistInMap(pVictim, GetCombatReach()); -} - -bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const -{ - if (!obj || !IsInMap(obj)) return false; - - float dx = GetPositionX() - obj->GetPositionX(); - float dy = GetPositionY() - obj->GetPositionY(); - float dz = GetPositionZ() - obj->GetPositionZ(); - float distsq = dx*dx + dy*dy + dz*dz; - //not sure here, or combatreach + combatreach? - float sizefactor = GetCombatReach() + obj->GetCombatReach(); - float maxdist = dist2compare + sizefactor; - - return distsq < maxdist * maxdist; -} - -void Unit::GetRandomContactPoint( const Unit* obj, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const -{ - //assert(GetCombatReach() > 0.1); - float combat_reach = GetCombatReach(); - if(combat_reach < 0.1) - { - sLog.outError("Unit %u (Type: %u) has invalid combat_reach %f",GetGUIDLow(),GetTypeId(),combat_reach); - if(GetTypeId() == TYPEID_UNIT) - sLog.outError("Creature entry %u has invalid combat_reach", ((Creature*)this)->GetEntry()); - combat_reach = 0.5; - } - uint32 attacker_number = getAttackers().size(); - if(attacker_number > 0) --attacker_number; - GetNearPoint(obj,x,y,z,obj->GetCombatReach(), distance2dMin+(distance2dMax-distance2dMin)*rand_norm() - , GetAngle(obj) + (attacker_number ? (M_PI/2 - M_PI * rand_norm()) * (float)attacker_number / combat_reach / 3 : 0)); -} - -void Unit::RemoveSpellsCausingAura(AuraType auraType) -{ - if (auraType >= TOTAL_AURAS) return; - AuraList::iterator iter, next; - for (iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end(); iter = next) - { - next = iter; - ++next; - - if (*iter) - { - RemoveAurasDueToSpell((*iter)->GetId()); - if (!m_modAuras[auraType].empty()) - next = m_modAuras[auraType].begin(); - else - return; - } - } -} - -void Unit::RemoveAurasWithInterruptFlags(uint32 flag) -{ - if(!(m_interruptMask & flag)) - return; - - // interrupt auras - AuraList::iterator iter, next; - for (iter = m_interruptableAuras.begin(); iter != m_interruptableAuras.end(); iter = next) - { - next = iter; - ++next; - - //sLog.outDetail("auraflag:%u flag:%u = %u",(*iter)->GetSpellProto()->AuraInterruptFlags,flag,(*iter)->GetSpellProto()->AuraInterruptFlags & flag); - if(*iter && ((*iter)->GetSpellProto()->AuraInterruptFlags & flag)) - { - RemoveAurasDueToSpell((*iter)->GetId()); - if (!m_interruptableAuras.empty()) - next = m_interruptableAuras.begin(); - else - break; - } - } - - // interrupt channeled spell - if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) - if(spell->getState() == SPELL_STATE_CASTING && (spell->m_spellInfo->ChannelInterruptFlags & flag)) - InterruptNonMeleeSpells(false); -} - -void Unit::UpdateInterruptMask() -{ - m_interruptMask = 0; - for(AuraList::iterator i = m_interruptableAuras.begin(); i != m_interruptableAuras.end(); ++i) - { - if(*i) - m_interruptMask |= (*i)->GetSpellProto()->AuraInterruptFlags; - } - if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) - if(spell->getState() == SPELL_STATE_CASTING) - m_interruptMask |= spell->m_spellInfo->ChannelInterruptFlags; -} - -bool Unit::HasAuraType(AuraType auraType) const -{ - return (!m_modAuras[auraType].empty()); -} - -/* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */ -void Unit::RemoveSpellbyDamageTaken(uint32 damage, uint32 spell) -{ - // The chance to dispel an aura depends on the damage taken with respect to the casters level. - uint32 max_dmg = getLevel() > 8 ? 25 * getLevel() - 150 : 50; - float chance = float(damage) / max_dmg * 100.0f; - - AuraList::iterator i, next; - for(i = m_ccAuras.begin(); i != m_ccAuras.end(); i = next) - { - next = i; - ++next; - - if(*i && (!spell || (*i)->GetId() != spell) && roll_chance_f(chance)) - { - RemoveAurasDueToSpell((*i)->GetId()); - if (!m_ccAuras.empty()) - next = m_ccAuras.begin(); - else - return; - } - } -} - -uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss) -{ - if (!pVictim->isAlive() || pVictim->isInFlight() || pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) - return 0; - - //You don't lose health from damage taken from another player while in a sanctuary - //You still see it in the combat log though - if(pVictim != this && GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) - { - const AreaTableEntry *area = GetAreaEntryByAreaID(pVictim->GetAreaId()); - if(area && area->flags & AREA_FLAG_SANCTUARY) //sanctuary - return 0; - } - - //Script Event damage taken - if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() ) - ((Creature *)pVictim)->AI()->DamageTaken(this, damage); - - if(!damage) //when will zero damage? need interrupt aura? - { - // Rage from physical damage received . - if(cleanDamage && cleanDamage->damage && (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) && pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) - ((Player*)pVictim)->RewardRage(cleanDamage->damage, 0, false); - - return 0; - } - - if(pVictim->GetTypeId() != TYPEID_PLAYER) - { - // no xp,health if type 8 /critters/ - if ( pVictim->GetCreatureType() == CREATURE_TYPE_CRITTER) - { - // critters run away when hit - pVictim->GetMotionMaster()->MoveFleeing(this); - - // allow loot only if has loot_id in creature_template - if(damage >= pVictim->GetHealth()) - { - pVictim->setDeathState(JUST_DIED); - pVictim->SetHealth(0); - - CreatureInfo const* cInfo = ((Creature*)pVictim)->GetCreatureInfo(); - if(cInfo && cInfo->lootid) - pVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); - - // some critters required for quests - if(GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->KilledMonster(pVictim->GetEntry(),pVictim->GetGUID()); - } - else - pVictim->ModifyHealth(- (int32)damage); - - return damage; - } - } - - DEBUG_LOG("DealDamageStart"); - - uint32 health = pVictim->GetHealth(); - sLog.outDetail("deal dmg:%d to health:%d ",damage,health); - - // duel ends when player has 1 or less hp - bool duel_hasEnded = false; - if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->duel && damage >= (health-1)) - { - // prevent kill only if killed in duel and killed by opponent or opponent controlled creature - if(((Player*)pVictim)->duel->opponent==this || ((Player*)pVictim)->duel->opponent->GetGUID() == GetOwnerGUID()) - damage = health-1; - - duel_hasEnded = true; - } - - // Rage from Damage made (only from direct weapon damage) - if( cleanDamage && damagetype==DIRECT_DAMAGE && this != pVictim && GetTypeId() == TYPEID_PLAYER && (getPowerType() == POWER_RAGE)) - { - uint32 weaponSpeedHitFactor; - - switch(cleanDamage->attackType) - { - case BASE_ATTACK: - { - if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 7); - else - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); - - ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); - - break; - } - case OFF_ATTACK: - { - if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); - else - weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 1.75f); - - ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); - - break; - } - case RANGED_ATTACK: - break; - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER && GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)pVictim)->InBattleGround()) - { - Player *killer = ((Player*)this); - if(killer != ((Player*)pVictim)) - if(BattleGround *bg = killer->GetBattleGround()) - bg->UpdatePlayerScore(killer, SCORE_DAMAGE_DONE, damage); - } - } - - if (pVictim->GetTypeId() == TYPEID_UNIT && !((Creature*)pVictim)->isPet() && !((Creature*)pVictim)->hasLootRecipient()) - ((Creature*)pVictim)->SetLootRecipient(this); - if (health <= damage) - { - DEBUG_LOG("DealDamage: victim just died"); - - // find player: owner of controlled `this` or `this` itself maybe - Player *player = GetCharmerOrOwnerPlayerOrPlayerItself(); - - if(pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->GetLootRecipient()) - player = ((Creature*)pVictim)->GetLootRecipient(); - // Reward player, his pets, and group/raid members - // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop) - if(player && player!=pVictim) - if(player->RewardPlayerAndGroupAtKill(pVictim)) - player->ProcDamageAndSpell(pVictim,PROC_FLAG_KILL_XP_GIVER,PROC_FLAG_NONE); - - DEBUG_LOG("DealDamageAttackStop"); - - // stop combat - pVictim->CombatStop(); - pVictim->getHostilRefManager().deleteReferences(); - - // stop movement - pVictim->StopMoving(); - - bool damageFromSpiritOfRedemtionTalent = spellProto && spellProto->Id == 27795; - - // if talent known but not triggered (check priest class for speedup check) - Aura* spiritOfRedemtionTalentReady = NULL; - if( !damageFromSpiritOfRedemtionTalent && // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION - pVictim->GetTypeId()==TYPEID_PLAYER && pVictim->getClass()==CLASS_PRIEST ) - { - AuraList const& vDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); ++itr) - { - if((*itr)->GetSpellProto()->SpellIconID==1654) - { - spiritOfRedemtionTalentReady = *itr; - break; - } - } - } - - DEBUG_LOG("SET JUST_DIED"); - if(!spiritOfRedemtionTalentReady) - pVictim->setDeathState(JUST_DIED); - - // outdoor pvp things, do these after setting the death state, else the player activity notify won't work... doh... - // handle player kill only if not suicide (spirit of redemption for example) - if(GetTypeId() == TYPEID_PLAYER && this != pVictim) - { - if(OutdoorPvP * pvp = ((Player*)this)->GetOutdoorPvP()) - { - pvp->HandleKill((Player*)this,pVictim); - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - if(OutdoorPvP * pvp = ((Player*)pVictim)->GetOutdoorPvP()) - { - pvp->HandlePlayerActivityChanged((Player*)pVictim); - } - } - - DEBUG_LOG("DealDamageHealth1"); - - if(spiritOfRedemtionTalentReady) - { - // save value before aura remove - uint32 ressSpellId = pVictim->GetUInt32Value(PLAYER_SELF_RES_SPELL); - if(!ressSpellId) - ressSpellId = ((Player*)pVictim)->GetResurrectionSpellId(); - - //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers) - pVictim->RemoveAllAurasOnDeath(); - - // restore for use at real death - pVictim->SetUInt32Value(PLAYER_SELF_RES_SPELL,ressSpellId); - - // FORM_SPIRITOFREDEMPTION and related auras - pVictim->CastSpell(pVictim,27827,true,NULL,spiritOfRedemtionTalentReady); - } - else - pVictim->SetHealth(0); - - // remember victim PvP death for corpse type and corpse reclaim delay - // at original death (not at SpiritOfRedemtionTalent timeout) - if( pVictim->GetTypeId()==TYPEID_PLAYER && !damageFromSpiritOfRedemtionTalent ) - ((Player*)pVictim)->SetPvPDeath(player!=NULL); - - // 10% durability loss on death - // clean InHateListOf - if (pVictim->GetTypeId() == TYPEID_PLAYER) - { - // only if not player and not controlled by player pet. And not at BG - if (durabilityLoss && !player && !((Player*)pVictim)->InBattleGround()) - { - DEBUG_LOG("We are dead, loosing 10 percents durability"); - ((Player*)pVictim)->DurabilityLossAll(0.10f,false); - // durability lost message - WorldPacket data(SMSG_DURABILITY_DAMAGE_DEATH, 0); - ((Player*)pVictim)->GetSession()->SendPacket(&data); - } - // Call KilledUnit for creatures - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) - ((Creature*)this)->AI()->KilledUnit(pVictim); - } - else // creature died - { - DEBUG_LOG("DealDamageNotPlayer"); - Creature *cVictim = (Creature*)pVictim; - - if(!cVictim->isPet()) - { - cVictim->DeleteThreatList(); - cVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); - } - - // Call KilledUnit for creatures, this needs to be called after the lootable flag is set - if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) - ((Creature*)this)->AI()->KilledUnit(pVictim); - - // Call creature just died function - if (cVictim->AI()) - cVictim->AI()->JustDied(this); - - // Dungeon specific stuff, only applies to players killing creatures - if(cVictim->GetInstanceId()) - { - Map *m = cVictim->GetMap(); - Player *creditedPlayer = GetCharmerOrOwnerPlayerOrPlayerItself(); - // TODO: do instance binding anyway if the charmer/owner is offline - - if(m->IsDungeon() && creditedPlayer) - { - if(m->IsRaid() || m->IsHeroic()) - { - if(cVictim->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND) - ((InstanceMap *)m)->PermBindAllPlayers(creditedPlayer); - } - else - { - // the reset time is set but not added to the scheduler - // until the players leave the instance - time_t resettime = cVictim->GetRespawnTimeEx() + 2 * HOUR; - if(InstanceSave *save = sInstanceSaveManager.GetInstanceSave(cVictim->GetInstanceId())) - if(save->GetResetTime() < resettime) save->SetResetTime(resettime); - } - } - } - } - - // last damage from non duel opponent or opponent controlled creature - if(duel_hasEnded) - { - assert(pVictim->GetTypeId()==TYPEID_PLAYER); - Player *he = (Player*)pVictim; - - assert(he->duel); - - he->duel->opponent->CombatStopWithPets(true); - he->CombatStopWithPets(true); - - he->DuelComplete(DUEL_INTERUPTED); - } - - // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill) - if(pVictim->GetTypeId() == TYPEID_PLAYER && (((Player*)pVictim)->InBattleGround())) - { - Player *killed = ((Player*)pVictim); - Player *killer = NULL; - if(GetTypeId() == TYPEID_PLAYER) - killer = ((Player*)this); - else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) - { - Unit *owner = GetOwner(); - if(owner && owner->GetTypeId() == TYPEID_PLAYER) - killer = ((Player*)owner); - } - - if(killer) - if(BattleGround *bg = killed->GetBattleGround()) - bg->HandleKillPlayer(killed, killer); // drop flags and etc - } - } - else // if (health <= damage) - { - DEBUG_LOG("DealDamageAlive"); - - pVictim->ModifyHealth(- (int32)damage); - - // Check if health is below 20% (apply damage before to prevent case when after ProcDamageAndSpell health < damage - if(pVictim->GetHealth()*5 < pVictim->GetMaxHealth()) - { - uint32 procVictim = PROC_FLAG_NONE; - - // if just dropped below 20% (for CheatDeath) - if((pVictim->GetHealth()+damage)*5 > pVictim->GetMaxHealth()) - procVictim = PROC_FLAG_LOW_HEALTH; - - ProcDamageAndSpell(pVictim,PROC_FLAG_TARGET_LOW_HEALTH,procVictim); - } - - if(damagetype != DOT) - { - if(getVictim()) - { - // if have target and damage pVictim just call AI reaction - if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI()) - ((Creature*)pVictim)->AI()->AttackedBy(this); - } - else - { - // if not have main target then attack state with target (including AI call) - //start melee attacks only after melee hit - Attack(pVictim,(damagetype == DIRECT_DAMAGE)); - } - } - - if(damagetype == DIRECT_DAMAGE|| damagetype == SPELL_DIRECT_DAMAGE) - pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE); - - if (pVictim->GetTypeId() != TYPEID_PLAYER) - { - if(spellProto && IsDamageToThreatSpell(spellProto)) - pVictim->AddThreat(this, damage*2, damageSchoolMask, spellProto); - else - pVictim->AddThreat(this, damage, damageSchoolMask, spellProto); - } - else // victim is a player - { - // Rage from damage received - if(this != pVictim && pVictim->getPowerType() == POWER_RAGE) - { - uint32 rage_damage = damage + (cleanDamage ? cleanDamage->damage : 0); - ((Player*)pVictim)->RewardRage(rage_damage, 0, false); - } - - // random durability for items (HIT TAKEN) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) - { - EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(slot); - } - } - - if(GetTypeId()==TYPEID_PLAYER) - { - // random durability for items (HIT DONE) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) - { - EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); - ((Player*)this)->DurabilityPointLossForEquipSlot(slot); - } - } - - if (damagetype != NODAMAGE && damage)// && pVictim->GetTypeId() == TYPEID_PLAYER) - { - //if (se->procFlags & (1<<3)) - pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DAMAGE); - pVictim->RemoveSpellbyDamageTaken(damage, spellProto ? spellProto->Id : 0); - - if(pVictim != this && pVictim->GetTypeId() == TYPEID_PLAYER) // does not support creature push_back - { - if(damagetype != DOT) - { - if(Spell* spell = pVictim->m_currentSpells[CURRENT_GENERIC_SPELL]) - { - if(spell->getState() == SPELL_STATE_PREPARING) - { - uint32 interruptFlags = spell->m_spellInfo->InterruptFlags; - if(interruptFlags & SPELL_INTERRUPT_FLAG_DAMAGE) - pVictim->InterruptNonMeleeSpells(false); - else if(interruptFlags & SPELL_INTERRUPT_FLAG_PUSH_BACK) - spell->Delayed(); - } - } - } - - if(Spell* spell = pVictim->m_currentSpells[CURRENT_CHANNELED_SPELL]) - { - if(spell->getState() == SPELL_STATE_CASTING) - { - uint32 channelInterruptFlags = spell->m_spellInfo->ChannelInterruptFlags; - if( channelInterruptFlags & CHANNEL_FLAG_DELAY ) - spell->DelayedChannel(); - } - } - } - } - - // last damage from duel opponent - if(duel_hasEnded) - { - assert(pVictim->GetTypeId()==TYPEID_PLAYER); - Player *he = (Player*)pVictim; - - assert(he->duel); - - he->SetHealth(1); - - he->duel->opponent->CombatStopWithPets(true); - he->CombatStopWithPets(true); - - he->CastSpell(he, 7267, true); // beg - he->DuelComplete(DUEL_WON); - } - } - - DEBUG_LOG("DealDamageEnd returned %d damage", damage); - - return damage; -} - -void Unit::CastStop(uint32 except_spellid) -{ - for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) - if (m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id!=except_spellid) - InterruptSpell(i,false); -} - -void Unit::CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); - - if(!spellInfo) - { - sLog.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - CastSpell(Victim,spellInfo,triggered,castItem,triggeredByAura, originalCaster); -} - -void Unit::CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - assert(Victim); - if(!spellInfo) - { - sLog.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - if (castItem) - DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); - - if(!originalCaster && triggeredByAura) - originalCaster = triggeredByAura->GetCasterGUID(); - - Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); - - SpellCastTargets targets; - targets.setUnitTarget( Victim ); - targets.setDestination( Victim->GetPositionX(), Victim->GetPositionY(), Victim->GetPositionZ(), false); - spell->m_CastItem = castItem; - spell->prepare(&targets, triggeredByAura); -} - -void Unit::CastCustomSpell(Unit* Victim,uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); - - if(!spellInfo) - { - sLog.outError("CastCustomSpell: unknown spell id %i\n", spellId); - return; - } - - CastCustomSpell(Victim,spellInfo,bp0,bp1,bp2,triggered,castItem,triggeredByAura, originalCaster); -} - -void Unit::CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - if(!spellInfo) - { - sLog.outError("CastCustomSpell: unknown spell"); - return; - } - - if (castItem) - DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); - - if(!originalCaster && triggeredByAura) - originalCaster = triggeredByAura->GetCasterGUID(); - - Spell *spell = new Spell(this, spellInfo, triggered, originalCaster); - - if(bp0) - spell->m_currentBasePoints[0] = *bp0-int32(spellInfo->EffectBaseDice[0]); - - if(bp1) - spell->m_currentBasePoints[1] = *bp1-int32(spellInfo->EffectBaseDice[1]); - - if(bp2) - spell->m_currentBasePoints[2] = *bp2-int32(spellInfo->EffectBaseDice[2]); - - SpellCastTargets targets; - targets.setUnitTarget( Victim ); - spell->m_CastItem = castItem; - spell->prepare(&targets, triggeredByAura); -} - -// used for scripting -void Unit::CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); - - if(!spellInfo) - { - sLog.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - CastSpell(x, y, z,spellInfo,triggered,castItem,triggeredByAura, originalCaster); -} - -// used for scripting -void Unit::CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) -{ - if(!spellInfo) - { - sLog.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); - return; - } - - if (castItem) - DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); - - if(!originalCaster && triggeredByAura) - originalCaster = triggeredByAura->GetCasterGUID(); - - Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); - - SpellCastTargets targets; - targets.setDestination(x, y, z); - spell->m_CastItem = castItem; - spell->prepare(&targets, triggeredByAura); -} - -void Unit::DealFlatDamage(Unit *pVictim, SpellEntry const *spellInfo, uint32 *damage, CleanDamage *cleanDamage, bool *crit, bool isTriggeredSpell) -{ - // TODO this in only generic way, check for exceptions - DEBUG_LOG("DealFlatDamage (BEFORE) >> DMG:%u", *damage); - - // Per-damage class calculation - switch (spellInfo->DmgClass) - { - // Melee and Ranged Spells - case SPELL_DAMAGE_CLASS_RANGED: - case SPELL_DAMAGE_CLASS_MELEE: - { - // Calculate physical outcome - MeleeHitOutcome outcome = RollPhysicalOutcomeAgainst(pVictim, BASE_ATTACK, spellInfo); - - //Used to store the Hit Outcome - cleanDamage->hitOutCome = outcome; - - // Return miss/evade first (sends miss message) - switch(outcome) - { - case MELEE_HIT_EVADE: - { - SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_EVADES,0); - *damage = 0; - return; - } - case MELEE_HIT_MISS: - { - SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_NORMAL,0); - *damage = 0; - - if(GetTypeId()== TYPEID_PLAYER) - ((Player*)this)->UpdateWeaponSkill(BASE_ATTACK); - - CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,MELEE_HIT_MISS,spellInfo,isTriggeredSpell); - return; - } - } - - // Hitinfo, Victimstate - uint32 hitInfo = HITINFO_NORMALSWING; - VictimState victimState = VICTIMSTATE_NORMAL; - - // Physical Damage - if ( GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NORMAL ) - { - uint32 modDamage=*damage; - - // apply spellmod to Done damage - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_DAMAGE, *damage); - - //Calculate armor mitigation - uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); - - // random durability for main hand weapon (ABSORB) - if(damageAfterArmor < *damage) - if(pVictim->GetTypeId() == TYPEID_PLAYER) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); - - cleanDamage->damage += *damage - damageAfterArmor; - *damage = damageAfterArmor; - } - // Magical Damage - else - { - // Calculate damage bonus - *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); - } - - // Classify outcome - switch (outcome) - { - case MELEE_HIT_BLOCK_CRIT: - case MELEE_HIT_CRIT: - { - uint32 bonusDmg = *damage; - - // Apply crit_damage bonus - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRIT_DAMAGE_BONUS, bonusDmg); - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - bonusDmg = uint32(bonusDmg * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); - - *damage += bonusDmg; - - // Resilience - reduce crit damage - if (pVictim->GetTypeId()==TYPEID_PLAYER) - { - uint32 resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); - cleanDamage->damage += resilienceReduction; - *damage -= resilienceReduction; - } - - *crit = true; - hitInfo |= HITINFO_CRITICALHIT; - - ModifyAuraState(AURA_STATE_CRIT, true); - StartReactiveTimer( REACTIVE_CRIT ); - - if(getClass()==CLASS_HUNTER) - { - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); - StartReactiveTimer( REACTIVE_HUNTER_CRIT ); - } - - if ( outcome == MELEE_HIT_BLOCK_CRIT ) - { - uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); - if (blocked_amount >= *damage) - { - hitInfo |= HITINFO_SWINGNOHITSOUND; - victimState = VICTIMSTATE_BLOCKS; - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - } - else - { - // To Help Calculate Rage - cleanDamage->damage += blocked_amount; - *damage = *damage - blocked_amount; - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - } - break; - } - case MELEE_HIT_PARRY: - { - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - victimState = VICTIMSTATE_PARRY; - - // Counter-attack ( explained in Unit::DoAttackDamage() ) - if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN) ) - { - // Get attack timers - float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); - float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); - - // Reduce attack time - if (pVictim->haveOffhandWeapon() && offtime < basetime) - { - float percent20 = pVictim->GetAttackTime(OFF_ATTACK) * 0.20; - float percent60 = 3 * percent20; - if(offtime > percent20 && offtime <= percent60) - { - pVictim->setAttackTimer(OFF_ATTACK, uint32(percent20)); - } - else if(offtime > percent60) - { - offtime -= 2 * percent20; - pVictim->setAttackTimer(OFF_ATTACK, uint32(offtime)); - } - } - else - { - float percent20 = pVictim->GetAttackTime(BASE_ATTACK) * 0.20; - float percent60 = 3 * percent20; - if(basetime > percent20 && basetime <= percent60) - { - pVictim->setAttackTimer(BASE_ATTACK, uint32(percent20)); - } - else if(basetime > percent60) - { - basetime -= 2 * percent20; - pVictim->setAttackTimer(BASE_ATTACK, uint32(basetime)); - } - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update victim defense ? - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (PARRY) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); - } - - // Set parry flags - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - // Mongoose bite - set only Counterattack here - if (pVictim->getClass() == CLASS_HUNTER) - { - pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); - pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); - } - else - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - break; - } - case MELEE_HIT_DODGE: - { - if(pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateDefense(); - - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - hitInfo |= HITINFO_SWINGNOHITSOUND; - victimState = VICTIMSTATE_DODGE; - - // Set dodge flags - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - // Overpower - if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) - { - ((Player*)this)->AddComboPoints(pVictim, 1); - StartReactiveTimer( REACTIVE_OVERPOWER ); - } - - // Riposte - if (pVictim->getClass() != CLASS_ROGUE) - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - break; - } - case MELEE_HIT_BLOCK: - { - uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); - if (blocked_amount >= *damage) - { - hitInfo |= HITINFO_SWINGNOHITSOUND; - victimState = VICTIMSTATE_BLOCKS; - cleanDamage->damage += *damage; // To Help Calculate Rage - *damage = 0; - } - else - { - // To Help Calculate Rage - cleanDamage->damage += blocked_amount; - *damage = *damage - blocked_amount; - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - break; - } - case MELEE_HIT_EVADE: // already processed early - case MELEE_HIT_MISS: // already processed early - case MELEE_HIT_GLANCING: - case MELEE_HIT_CRUSHING: - case MELEE_HIT_NORMAL: - break; - } - - // do all damage=0 cases here - if(*damage == 0) - CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,outcome,spellInfo,isTriggeredSpell); - - break; - } - // Magical Attacks - case SPELL_DAMAGE_CLASS_NONE: - case SPELL_DAMAGE_CLASS_MAGIC: - { - // Calculate damage bonus - *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); - - *crit = isSpellCrit(pVictim, spellInfo, GetSpellSchoolMask(spellInfo), BASE_ATTACK); - if (*crit) - { - *damage = SpellCriticalBonus(spellInfo, *damage, pVictim); - - // Resilience - reduce crit damage - if (pVictim && pVictim->GetTypeId()==TYPEID_PLAYER) - { - uint32 damage_reduction = ((Player *)pVictim)->GetSpellCritDamageReduction(*damage); - if(*damage > damage_reduction) - *damage -= damage_reduction; - else - *damage = 0; - } - - cleanDamage->hitOutCome = MELEE_HIT_CRIT; - } - // spell proc all magic damage==0 case in this function - if(*damage == 0) - { - // Procflags - uint32 procAttacker = PROC_FLAG_HIT_SPELL; - uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); - - ProcDamageAndSpell(pVictim, procAttacker, procVictim, 0, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); - } - - break; - } - } - - // TODO this in only generic way, check for exceptions - DEBUG_LOG("DealFlatDamage (AFTER) >> DMG:%u", *damage); -} - -uint32 Unit::SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell, bool useSpellDamage) -{ - if(!this || !pVictim) - return 0; - if(!this->isAlive() || !pVictim->isAlive()) - return 0; - - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellID); - if(!spellInfo) - return 0; - - CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL); - bool crit = false; - - if (useSpellDamage) - DealFlatDamage(pVictim, spellInfo, &damage, &cleanDamage, &crit, isTriggeredSpell); - - // If we actually dealt some damage (spell proc's for 0 damage (normal and magic) called in DealFlatDamage) - if(damage > 0) - { - // Calculate absorb & resists - uint32 absorb = 0; - uint32 resist = 0; - - CalcAbsorbResist(pVictim,GetSpellSchoolMask(spellInfo), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist); - - //No more damage left, target absorbed and/or resisted all damage - if (damage > absorb + resist) - damage -= absorb + resist; //Remove Absorbed and Resisted from damage actually dealt - else - { - uint32 HitInfo = HITINFO_SWINGNOHITSOUND; - - if (absorb) - HitInfo |= HITINFO_ABSORB; - if (resist) - { - HitInfo |= HITINFO_RESIST; - ProcDamageAndSpell(pVictim, PROC_FLAG_TARGET_RESISTS, PROC_FLAG_RESIST_SPELL, 0, GetSpellSchoolMask(spellInfo), spellInfo,isTriggeredSpell); - } - - //Send resist - SendAttackStateUpdate(HitInfo, pVictim, 1, GetSpellSchoolMask(spellInfo), damage, absorb,resist,VICTIMSTATE_NORMAL,0); - return 0; - } - - // Deal damage done - damage = DealDamage(pVictim, damage, &cleanDamage, SPELL_DIRECT_DAMAGE, GetSpellSchoolMask(spellInfo), spellInfo, true); - - // Send damage log - sLog.outDetail("SpellNonMeleeDamageLog: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u,absorb is %u,resist is %u", - GetGUIDLow(), GetTypeId(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, spellID, absorb,resist); - - // Actual log sent to client - SendSpellNonMeleeDamageLog(pVictim, spellID, damage, GetSpellSchoolMask(spellInfo), absorb, resist, false, 0, crit); - - // Procflags - uint32 procAttacker = PROC_FLAG_HIT_SPELL; - uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); - - if (crit) - { - procAttacker |= PROC_FLAG_CRIT_SPELL; - procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; - } - - ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); - - return damage; - } - else - { - // all spell proc for 0 normal and magic damage called in DealFlatDamage - - //Check for rage - if(cleanDamage.damage) - // Rage from damage received. - if(pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) - ((Player*)pVictim)->RewardRage(cleanDamage.damage, 0, false); - - return 0; - } -} - -void Unit::HandleEmoteCommand(uint32 anim_id) -{ - WorldPacket data( SMSG_EMOTE, 12 ); - data << anim_id << GetGUID(); - WPAssert(data.size() == 12); - - SendMessageToSet(&data, true); -} - -uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage) -{ - uint32 newdamage = 0; - float armor = pVictim->GetArmor(); - // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura - armor += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, SPELL_SCHOOL_MASK_NORMAL); - - if (armor<0.0f) armor=0.0f; - - float tmpvalue = 0.0f; - if(getLevel() <= 59) //Level 1-59 - tmpvalue = armor / (armor + 400.0f + 85.0f * getLevel()); - else if(getLevel() < 70) //Level 60-69 - tmpvalue = armor / (armor - 22167.5f + 467.5f * getLevel()); - else //Level 70+ - tmpvalue = armor / (armor + 10557.5f); - - if(tmpvalue < 0.0f) - tmpvalue = 0.0f; - if(tmpvalue > 0.75f) - tmpvalue = 0.75f; - newdamage = uint32(damage - (damage * tmpvalue)); - - return (newdamage > 1) ? newdamage : 1; -} - -void Unit::CalcAbsorbResist(Unit *pVictim,SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist) -{ - if(!pVictim || !pVictim->isAlive() || !damage) - return; - - // Magic damage, check for resists - if ((schoolMask & SPELL_SCHOOL_MASK_NORMAL)==0) - { - // Get base victim resistance for school - float tmpvalue2 = (float)pVictim->GetResistance(GetFirstSchoolInMask(schoolMask)); - // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura - tmpvalue2 += (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask); - - tmpvalue2 *= (float)(0.15f / getLevel()); - if (tmpvalue2 < 0.0f) - tmpvalue2 = 0.0f; - if (tmpvalue2 > 0.75f) - tmpvalue2 = 0.75f; - uint32 ran = urand(0, 100); - uint32 faq[4] = {24,6,4,6}; - uint8 m = 0; - float Binom = 0.0f; - for (uint8 i = 0; i < 4; i++) - { - Binom += 2400 *( powf(tmpvalue2, i) * powf( (1-tmpvalue2), (4-i)))/faq[i]; - if (ran > Binom ) - ++m; - else - break; - } - if (damagetype == DOT && m == 4) - *resist += uint32(damage - 1); - else - *resist += uint32(damage * m / 4); - if(*resist > damage) - *resist = damage; - } - else - *resist = 0; - - int32 RemainingDamage = damage - *resist; - - // absorb without mana cost - int32 reflectDamage = 0; - Aura* reflectAura = NULL; - AuraList const& vSchoolAbsorb = pVictim->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB); - for(AuraList::const_iterator i = vSchoolAbsorb.begin(), next; i != vSchoolAbsorb.end() && RemainingDamage > 0; i = next) - { - next = i; ++next; - - if (((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - // Cheat Death - if((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_ROGUE && (*i)->GetSpellProto()->SpellIconID == 2109) - { - if (((Player*)pVictim)->HasSpellCooldown(31231)) - continue; - if (pVictim->GetHealth() <= RemainingDamage) - { - int32 chance = (*i)->GetModifier()->m_amount; - if (roll_chance_i(chance)) - { - pVictim->CastSpell(pVictim,31231,true); - ((Player*)pVictim)->AddSpellCooldown(31231,0,time(NULL)+60); - - // with health > 10% lost health until health==10%, in other case no losses - uint32 health10 = pVictim->GetMaxHealth()/10; - RemainingDamage = pVictim->GetHealth() > health10 ? pVictim->GetHealth() - health10 : 0; - } - } - continue; - } - - int32 currentAbsorb; - - //Reflective Shield - if ((pVictim != this) && (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_PRIEST && (*i)->GetSpellProto()->SpellFamilyFlags == 0x1) - { - if(Unit* caster = (*i)->GetCaster()) - { - AuraList const& vOverRideCS = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator k = vOverRideCS.begin(); k != vOverRideCS.end(); ++k) - { - switch((*k)->GetModifier()->m_miscvalue) - { - case 5065: // Rank 1 - case 5064: // Rank 2 - case 5063: // Rank 3 - case 5062: // Rank 4 - case 5061: // Rank 5 - { - if(RemainingDamage >= (*i)->GetModifier()->m_amount) - reflectDamage = (*i)->GetModifier()->m_amount * (*k)->GetModifier()->m_amount/100; - else - reflectDamage = (*k)->GetModifier()->m_amount * RemainingDamage/100; - reflectAura = *i; - - } break; - default: break; - } - - if(reflectDamage) - break; - } - } - } - - if (RemainingDamage >= (*i)->GetModifier()->m_amount) - { - currentAbsorb = (*i)->GetModifier()->m_amount; - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - next = vSchoolAbsorb.begin(); - } - else - { - currentAbsorb = RemainingDamage; - (*i)->GetModifier()->m_amount -= RemainingDamage; - } - - RemainingDamage -= currentAbsorb; - } - // do not cast spells while looping auras; auras can get invalid otherwise - if (reflectDamage) - pVictim->CastCustomSpell(this, 33619, &reflectDamage, NULL, NULL, true, NULL, reflectAura); - - // absorb by mana cost - AuraList const& vManaShield = pVictim->GetAurasByType(SPELL_AURA_MANA_SHIELD); - for(AuraList::const_iterator i = vManaShield.begin(), next; i != vManaShield.end() && RemainingDamage > 0; i = next) - { - next = i; ++next; - - // check damage school mask - if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - int32 currentAbsorb; - if (RemainingDamage >= (*i)->GetModifier()->m_amount) - currentAbsorb = (*i)->GetModifier()->m_amount; - else - currentAbsorb = RemainingDamage; - - float manaMultiplier = (*i)->GetSpellProto()->EffectMultipleValue[(*i)->GetEffIndex()]; - if(Player *modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod((*i)->GetId(), SPELLMOD_MULTIPLE_VALUE, manaMultiplier); - - int32 maxAbsorb = int32(pVictim->GetPower(POWER_MANA) / manaMultiplier); - if (currentAbsorb > maxAbsorb) - currentAbsorb = maxAbsorb; - - (*i)->GetModifier()->m_amount -= currentAbsorb; - if((*i)->GetModifier()->m_amount <= 0) - { - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - next = vManaShield.begin(); - } - - int32 manaReduction = int32(currentAbsorb * manaMultiplier); - pVictim->ApplyPowerMod(POWER_MANA, manaReduction, false); - - RemainingDamage -= currentAbsorb; - } - - // only split damage if not damaging yourself - if(pVictim != this) - { - AuraList const& vSplitDamageFlat = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT); - for(AuraList::const_iterator i = vSplitDamageFlat.begin(), next; i != vSplitDamageFlat.end() && RemainingDamage >= 0; i = next) - { - next = i; ++next; - - // check damage school mask - if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - // Damage can be splitted only if aura has an alive caster - Unit *caster = (*i)->GetCaster(); - if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) - continue; - - int32 currentAbsorb; - if (RemainingDamage >= (*i)->GetModifier()->m_amount) - currentAbsorb = (*i)->GetModifier()->m_amount; - else - currentAbsorb = RemainingDamage; - - RemainingDamage -= currentAbsorb; - - SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, currentAbsorb, schoolMask, 0, 0, false, 0, false); - - CleanDamage cleanDamage = CleanDamage(currentAbsorb, BASE_ATTACK, MELEE_HIT_NORMAL); - DealDamage(caster, currentAbsorb, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); - } - - AuraList const& vSplitDamagePct = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT); - for(AuraList::const_iterator i = vSplitDamagePct.begin(), next; i != vSplitDamagePct.end() && RemainingDamage >= 0; i = next) - { - next = i; ++next; - - // check damage school mask - if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) - continue; - - // Damage can be splitted only if aura has an alive caster - Unit *caster = (*i)->GetCaster(); - if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) - continue; - - int32 splitted = int32(RemainingDamage * (*i)->GetModifier()->m_amount / 100.0f); - - RemainingDamage -= splitted; - - SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, splitted, schoolMask, 0, 0, false, 0, false); - - CleanDamage cleanDamage = CleanDamage(splitted, BASE_ATTACK, MELEE_HIT_NORMAL); - DealDamage(caster, splitted, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); - } - } - - *absorb = damage - RemainingDamage - *resist; -} - -void Unit::DoAttackDamage (Unit *pVictim, uint32 *damage, CleanDamage *cleanDamage, uint32 *blocked_amount, SpellSchoolMask damageSchoolMask, uint32 *hitInfo, VictimState *victimState, uint32 *absorbDamage, uint32 *resistDamage, WeaponAttackType attType, SpellEntry const *spellCasted, bool isTriggeredSpell) -{ - MeleeHitOutcome outcome; - - // If is casted Melee spell, calculate like physical - if(!spellCasted) - outcome = RollMeleeOutcomeAgainst (pVictim, attType); - else - outcome = RollPhysicalOutcomeAgainst (pVictim, attType, spellCasted); - - if(outcome == MELEE_HIT_MISS ||outcome == MELEE_HIT_DODGE ||outcome == MELEE_HIT_BLOCK ||outcome == MELEE_HIT_PARRY) - pVictim->AddThreat(this, 0.0f); - switch(outcome) - { - case MELEE_HIT_EVADE: - { - *hitInfo |= HITINFO_MISS; - *damage = 0; - cleanDamage->damage = 0; - return; - } - case MELEE_HIT_MISS: - { - *hitInfo |= HITINFO_MISS; - *damage = 0; - cleanDamage->damage = 0; - if(GetTypeId()== TYPEID_PLAYER) - ((Player*)this)->UpdateWeaponSkill(attType); - return; - } - } - - /// If this is a creature and it attacks from behind it has a probability to daze it's victim - if( (outcome==MELEE_HIT_CRIT || outcome==MELEE_HIT_CRUSHING || outcome==MELEE_HIT_NORMAL || outcome==MELEE_HIT_GLANCING) && - GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGUID() && !pVictim->HasInArc(M_PI, this) - && pVictim->GetTypeId() == TYPEID_PLAYER) - { - // -probability is between 0% and 40% - // 20% base chance - float Probability = 20; - - //there is a newbie protection, at level 10 just 7% base chance; assuming linear function - if( pVictim->getLevel() < 30 ) - Probability = 0.65f*pVictim->getLevel()+0.5; - - uint32 VictimDefense=pVictim->GetDefenseSkillValue(this); - uint32 AttackerMeleeSkill=GetUnitMeleeSkill(pVictim); - - Probability *= AttackerMeleeSkill/(float)VictimDefense; - - if(Probability > 40.0f) - Probability = 40.0f; - - if(roll_chance_f(Probability)) - CastSpell(pVictim, 1604, true); - } - - //Calculate the damage after armor mitigation if SPELL_SCHOOL_NORMAL - if (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) - { - uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); - - // random durability for main hand weapon (ABSORB) - if(damageAfterArmor < *damage) - if(pVictim->GetTypeId() == TYPEID_PLAYER) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); - - cleanDamage->damage += *damage - damageAfterArmor; - *damage = damageAfterArmor; - } - - if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) - ((Player*)this)->UpdateCombatSkills(pVictim, attType, outcome, false); - - if(GetTypeId() != TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateCombatSkills(this, attType, outcome, true); - - switch (outcome) - { - case MELEE_HIT_BLOCK_CRIT: - case MELEE_HIT_CRIT: - { - //*hitInfo = 0xEA; - // 0xEA - *hitInfo = HITINFO_CRITICALHIT | HITINFO_NORMALSWING2 | 0x8; - - // Crit bonus calc - uint32 crit_bonus; - crit_bonus = *damage; - - // Apply crit_damage bonus for melee spells - if (spellCasted) - { - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellCasted->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - crit_bonus = uint32(crit_bonus * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); - } - - *damage += crit_bonus; - - uint32 resilienceReduction = 0; - - if(attType == RANGED_ATTACK) - { - int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE); - *damage = int32((*damage) * float((100.0f + mod)/100.0f)); - // Resilience - reduce crit damage - if (pVictim->GetTypeId()==TYPEID_PLAYER) - resilienceReduction = ((Player*)pVictim)->GetRangedCritDamageReduction(*damage); - } - else - { - int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE); - mod += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE); - *damage = int32((*damage) * float((100.0f + mod)/100.0f)); - // Resilience - reduce crit damage - if (pVictim->GetTypeId()==TYPEID_PLAYER) - resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); - } - - *damage -= resilienceReduction; - cleanDamage->damage += resilienceReduction; - - if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) - ((Player*)this)->UpdateWeaponSkill(attType); - - ModifyAuraState(AURA_STATE_CRIT, true); - StartReactiveTimer( REACTIVE_CRIT ); - - if(getClass()==CLASS_HUNTER) - { - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); - StartReactiveTimer( REACTIVE_HUNTER_CRIT ); - } - - if ( outcome == MELEE_HIT_BLOCK_CRIT ) - { - *blocked_amount = pVictim->GetShieldBlockValue(); - - if (pVictim->GetUnitBlockChance()) - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); - else - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - //Only set VICTIMSTATE_BLOCK on a full block - if (*blocked_amount >= uint32(*damage)) - { - *victimState = VICTIMSTATE_BLOCKS; - *blocked_amount = uint32(*damage); - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - break; - } - - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL); - break; - } - case MELEE_HIT_PARRY: - { - if(attType == RANGED_ATTACK) //range attack - no parry - { - outcome = MELEE_HIT_NORMAL; - break; - } - - cleanDamage->damage += *damage; - *damage = 0; - *victimState = VICTIMSTATE_PARRY; - - // instant (maybe with small delay) counter attack - { - float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); - float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); - - // after parry nearest next attack time will reduced at %40 from full attack time. - // The delay cannot be reduced to less than 20% of your weapon base swing delay. - if (pVictim->haveOffhandWeapon() && offtime < basetime) - { - float percent20 = pVictim->GetAttackTime(OFF_ATTACK)*0.20; - float percent60 = 3*percent20; - // set to 20% if in range 20%...20+40% of full time - if(offtime > percent20 && offtime <= percent60) - { - pVictim->setAttackTimer(OFF_ATTACK,uint32(percent20)); - } - // decrease at %40 from full time - else if(offtime > percent60) - { - offtime -= 2*percent20; - pVictim->setAttackTimer(OFF_ATTACK,uint32(offtime)); - } - // ELSE not changed - } - else - { - float percent20 = pVictim->GetAttackTime(BASE_ATTACK)*0.20; - float percent60 = 3*percent20; - // set to 20% if in range 20%...20+40% of full time - if(basetime > percent20 && basetime <= percent60) - { - pVictim->setAttackTimer(BASE_ATTACK,uint32(percent20)); - } - // decrease at %40 from full time - else if(basetime > percent60) - { - basetime -= 2*percent20; - pVictim->setAttackTimer(BASE_ATTACK,uint32(basetime)); - } - // ELSE not changed - } - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update victim defense ? - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (PARRY) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); - } - - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - if (pVictim->getClass() == CLASS_HUNTER) - { - pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); - pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); - } - else - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - - CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - return; - } - case MELEE_HIT_DODGE: - { - if(attType == RANGED_ATTACK) //range attack - no dodge - { - outcome = MELEE_HIT_NORMAL; - break; - } - - cleanDamage->damage += *damage; - *damage = 0; - *victimState = VICTIMSTATE_DODGE; - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - ((Player*)pVictim)->UpdateDefense(); - - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - if (pVictim->getClass() != CLASS_ROGUE) // Riposte - { - pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - } - - // Overpower - if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) - { - ((Player*)this)->AddComboPoints(pVictim, 1); - StartReactiveTimer( REACTIVE_OVERPOWER ); - } - - CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - return; - } - case MELEE_HIT_BLOCK: - { - *blocked_amount = pVictim->GetShieldBlockValue(); - - if (pVictim->GetUnitBlockChance()) - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); - else - pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); - - //Only set VICTIMSTATE_BLOCK on a full block - if (*blocked_amount >= uint32(*damage)) - { - *victimState = VICTIMSTATE_BLOCKS; - *blocked_amount = uint32(*damage); - } - - if(pVictim->GetTypeId() == TYPEID_PLAYER) - { - // Update defense - ((Player*)pVictim)->UpdateDefense(); - - // random durability for main hand weapon (BLOCK) - if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) - ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); - } - - pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); - pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); - - break; - } - case MELEE_HIT_GLANCING: - { - int32 leveldif = int32(pVictim->getLevel()) - int32(getLevel()); - if (leveldif > 3) leveldif = 3; - *damage *= (1 - leveldif * 0.1f); - cleanDamage->damage = *damage; - *hitInfo |= HITINFO_GLANCING; - break; - } - case MELEE_HIT_CRUSHING: - { - // 150% normal damage - *damage += (*damage / 2); - cleanDamage->damage = *damage; - *hitInfo |= HITINFO_CRUSHING; - // TODO: victimState, victim animation? - break; - } - default: - break; - } - - // apply melee damage bonus and absorb only if base damage not fully blocked to prevent negative damage or damage with full block - if(*victimState != VICTIMSTATE_BLOCKS) - { - MeleeDamageBonus(pVictim, damage,attType,spellCasted); - CalcAbsorbResist(pVictim, damageSchoolMask, DIRECT_DAMAGE, *damage-*blocked_amount, absorbDamage, resistDamage); - } - - if (*absorbDamage) *hitInfo |= HITINFO_ABSORB; - if (*resistDamage) *hitInfo |= HITINFO_RESIST; - - cleanDamage->damage += *blocked_amount; - - if (*damage <= *absorbDamage + *resistDamage + *blocked_amount) - { - //*hitInfo = 0x00010020; - //*hitInfo |= HITINFO_SWINGNOHITSOUND; - //*damageType = 0; - CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - return; - } - - // update at damage Judgement aura duration that applied by attacker at victim - if(*damage) - { - AuraMap const& vAuras = pVictim->GetAuras(); - for(AuraMap::const_iterator itr = vAuras.begin(); itr != vAuras.end(); ++itr) - { - SpellEntry const *spellInfo = (*itr).second->GetSpellProto(); - if( (spellInfo->AttributesEx3 & 0x40000) && spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && - ((*itr).second->GetCasterGUID() == GetGUID() && (!spellCasted || spellCasted->Id == 35395)) ) - { - (*itr).second->SetAuraDuration((*itr).second->GetAuraMaxDuration()); - (*itr).second->UpdateAuraDuration(); - } - } - } - - CastMeleeProcDamageAndSpell(pVictim, (*damage - *absorbDamage - *resistDamage - *blocked_amount), damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); - - // victim's damage shield - // yet another hack to fix crashes related to the aura getting removed during iteration - std::set alreadyDone; - uint32 removedAuras = pVictim->m_removedAuras; - AuraList const& vDamageShields = pVictim->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD); - for(AuraList::const_iterator i = vDamageShields.begin(), next = vDamageShields.begin(); i != vDamageShields.end(); i = next) - { - ++next; - if (alreadyDone.find(*i) == alreadyDone.end()) - { - alreadyDone.insert(*i); - pVictim->SpellNonMeleeDamageLog(this, (*i)->GetId(), (*i)->GetModifier()->m_amount, false, false); - if (pVictim->m_removedAuras > removedAuras) - { - removedAuras = pVictim->m_removedAuras; - next = vDamageShields.begin(); - } - } - } -} - -void Unit::AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType, bool extra ) -{ - if(hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING) || HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED) ) - return; - - if (!pVictim->isAlive()) - return; - - if(IsNonMeleeSpellCasted(false)) - return; - - CombatStart(pVictim); - - uint32 hitInfo; - if (attType == BASE_ATTACK) - hitInfo = HITINFO_NORMALSWING2; - else if (attType == OFF_ATTACK) - hitInfo = HITINFO_LEFTSWING; - else - return; // ignore ranged case - - uint32 extraAttacks = m_extraAttacks; - - // melee attack spell casted at main hand attack only - if (attType == BASE_ATTACK && m_currentSpells[CURRENT_MELEE_SPELL]) - { - m_currentSpells[CURRENT_MELEE_SPELL]->cast(); - - // not recent extra attack only at any non extra attack (melee spell case) - if(!extra && extraAttacks) - { - while(m_extraAttacks) - { - AttackerStateUpdate(pVictim, BASE_ATTACK, true); - if(m_extraAttacks > 0) - --m_extraAttacks; - } - } - - return; - } - - VictimState victimState = VICTIMSTATE_NORMAL; - - CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL ); - uint32 blocked_dmg = 0; - uint32 absorbed_dmg = 0; - uint32 resisted_dmg = 0; - - SpellSchoolMask meleeSchoolMask = GetMeleeDamageSchoolMask(); - - if(pVictim->IsImmunedToDamage(meleeSchoolMask,true)) // use charges - { - SendAttackStateUpdate (HITINFO_NORMALSWING, pVictim, 1, meleeSchoolMask, 0, 0, 0, VICTIMSTATE_IS_IMMUNE, 0); - - // not recent extra attack only at any non extra attack (miss case) - if(!extra && extraAttacks) - { - while(m_extraAttacks) - { - AttackerStateUpdate(pVictim, BASE_ATTACK, true); - if(m_extraAttacks > 0) - --m_extraAttacks; - } - } - - return; - } - - uint32 damage = CalculateDamage (attType, false); - - DoAttackDamage (pVictim, &damage, &cleanDamage, &blocked_dmg, meleeSchoolMask, &hitInfo, &victimState, &absorbed_dmg, &resisted_dmg, attType); - - if (hitInfo & HITINFO_MISS) - //send miss - SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); - else - { - //do animation - SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); - - if (damage > (absorbed_dmg + resisted_dmg + blocked_dmg)) - damage -= (absorbed_dmg + resisted_dmg + blocked_dmg); - else - damage = 0; - - DealDamage (pVictim, damage, &cleanDamage, DIRECT_DAMAGE, meleeSchoolMask, NULL, true); - - if(GetTypeId() == TYPEID_PLAYER && pVictim->isAlive()) - { - for(int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; i++) - ((Player*)this)->CastItemCombatSpell(((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0,i),pVictim,attType); - } - } - - if (GetTypeId() == TYPEID_PLAYER) - DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", - GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); - else - DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", - GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); - - // extra attack only at any non extra attack (normal case) - if(!extra && extraAttacks) - { - while(m_extraAttacks) - { - AttackerStateUpdate(pVictim, BASE_ATTACK, true); - if(m_extraAttacks > 0) - --m_extraAttacks; - } - } -} - -MeleeHitOutcome Unit::RollPhysicalOutcomeAgainst (Unit const *pVictim, WeaponAttackType attType, SpellEntry const *spellInfo) -{ - // Miss chance based on melee - float miss_chance = MeleeMissChanceCalc(pVictim, attType); - - // Critical hit chance - float crit_chance = GetUnitCriticalChance(attType, pVictim); - // this is to avoid compiler issue when declaring variables inside if - float block_chance, parry_chance, dodge_chance; - - // cannot be dodged/parried/blocked - if(spellInfo->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) - { - block_chance = 0.0f; - parry_chance = 0.0f; - dodge_chance = 0.0f; - } - else - { - // parry can be avoided only by some abilities - parry_chance = pVictim->GetUnitParryChance(); - // block might be bypassed by it as well - block_chance = pVictim->GetUnitBlockChance(); - // stunned target cannot dodge and this is check in GetUnitDodgeChance() - dodge_chance = pVictim->GetUnitDodgeChance(); - } - - // Only players can have Talent&Spell bonuses - if (GetTypeId() == TYPEID_PLAYER) - { - // Increase from SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL aura - crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, spellInfo->SchoolMask); - - if( dodge_chance != 0.0f ) // if dodge chance is already 0, ignore talents for speed - { - AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); - for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) - { - // can't be dodged rogue finishing move - if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) - { - if(spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) - { - dodge_chance = 0.0f; - break; - } - } - } - } - } - - // Spellmods - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); - - DEBUG_LOG("PHYSICAL OUTCOME: miss %f crit %f dodge %f parry %f block %f",miss_chance,crit_chance,dodge_chance,parry_chance, block_chance); - - return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100),int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), true); -} - -MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(const Unit *pVictim, WeaponAttackType attType) const -{ - // This is only wrapper - - // Miss chance based on melee - float miss_chance = MeleeMissChanceCalc(pVictim, attType); - - // Critical hit chance - float crit_chance = GetUnitCriticalChance(attType, pVictim); - - // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case) - float dodge_chance = pVictim->GetUnitDodgeChance(); - float block_chance = pVictim->GetUnitBlockChance(); - float parry_chance = pVictim->GetUnitParryChance(); - - // Useful if want to specify crit & miss chances for melee, else it could be removed - DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance,crit_chance,dodge_chance,parry_chance,block_chance); - - return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100), int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), false); -} - -MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance, bool SpellCasted ) const -{ - if(pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) - return MELEE_HIT_EVADE; - - int32 attackerMaxSkillValueForLevel = GetMaxSkillValueForLevel(pVictim); - int32 victimMaxSkillValueForLevel = pVictim->GetMaxSkillValueForLevel(this); - - int32 attackerWeaponSkill = GetWeaponSkillValue(attType,pVictim); - int32 victimDefenseSkill = pVictim->GetDefenseSkillValue(this); - - // bonus from skills is 0.04% - int32 skillBonus = 4 * ( attackerWeaponSkill - victimMaxSkillValueForLevel ); - int32 skillBonus2 = 4 * ( attackerMaxSkillValueForLevel - victimDefenseSkill ); - int32 sum = 0, tmp = 0; - int32 roll = urand (0, 10000); - - DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus); - DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d", - roll, miss_chance, dodge_chance, parry_chance, block_chance, crit_chance); - - tmp = miss_chance; - - if (tmp > 0 && roll < (sum += tmp )) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS"); - return MELEE_HIT_MISS; - } - - // always crit against a sitting target (except 0 crit chance) - if( pVictim->GetTypeId() == TYPEID_PLAYER && crit_chance > 0 && !pVictim->IsStandState() ) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)"); - return MELEE_HIT_CRIT; - } - - // Dodge chance - - // only players can't dodge if attacker is behind - if (pVictim->GetTypeId() == TYPEID_PLAYER && !pVictim->HasInArc(M_PI,this)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player."); - } - else - { - // Reduce dodge chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - dodge_chance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); - - // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE - dodge_chance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); - - tmp = dodge_chance; - if ( (tmp > 0) // check if unit _can_ dodge - && ((tmp -= skillBonus) > 0) - && roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum-tmp, sum); - return MELEE_HIT_DODGE; - } - } - - // parry & block chances - - // check if attack comes from behind, nobody can parry or block if attacker is behind - if (!pVictim->HasInArc(M_PI,this)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind."); - } - else - { - // Reduce parry chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - parry_chance-= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); - - if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY) ) - { - int32 tmp = int32(parry_chance); - if ( (tmp > 0) // check if unit _can_ parry - && ((tmp -= skillBonus) > 0) - && (roll < (sum += tmp))) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum-tmp, sum); - return MELEE_HIT_PARRY; - } - } - - if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_BLOCK) ) - { - tmp = block_chance; - if ( (tmp > 0) // check if unit _can_ block - && ((tmp -= skillBonus) > 0) - && (roll < (sum += tmp))) - { - // Critical chance - tmp = crit_chance + skillBonus2; - if ( GetTypeId() == TYPEID_PLAYER && SpellCasted && tmp > 0 ) - { - if ( roll_chance_i(tmp/100)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCKED CRIT"); - return MELEE_HIT_BLOCK_CRIT; - } - } - DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum-tmp, sum); - return MELEE_HIT_BLOCK; - } - } - } - - // Critical chance - tmp = crit_chance + skillBonus2; - - if (tmp > 0 && roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum-tmp, sum); - return MELEE_HIT_CRIT; - } - - // Max 40% chance to score a glancing blow against mobs that are higher level (can do only players and pets and not with ranged weapon) - if( attType != RANGED_ATTACK && !SpellCasted && - (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet()) && - pVictim->GetTypeId() != TYPEID_PLAYER && !((Creature*)pVictim)->isPet() && - getLevel() < pVictim->getLevelForTarget(this) ) - { - // cap possible value (with bonuses > max skill) - int32 skill = attackerWeaponSkill; - int32 maxskill = attackerMaxSkillValueForLevel; - skill = (skill > maxskill) ? maxskill : skill; - - tmp = (10 + (victimDefenseSkill - skill)) * 100; - tmp = tmp > 4000 ? 4000 : tmp; - if (roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum-4000, sum); - return MELEE_HIT_GLANCING; - } - } - - if(GetTypeId()!=TYPEID_PLAYER && !(((Creature*)this)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_CRUSH) && !((Creature*)this)->isPet() ) - { - // mobs can score crushing blows if they're 3 or more levels above victim - // or when their weapon skill is 15 or more above victim's defense skill - tmp = victimDefenseSkill; - int32 tmpmax = victimMaxSkillValueForLevel; - // having defense above your maximum (from items, talents etc.) has no effect - tmp = tmp > tmpmax ? tmpmax : tmp; - // tmp = mob's level * 5 - player's current defense skill - tmp = attackerMaxSkillValueForLevel - tmp; - if(tmp >= 15) - { - // add 2% chance per lacking skill point, min. is 15% - tmp = tmp * 200 - 1500; - if (roll < (sum += tmp)) - { - DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum-tmp, sum); - return MELEE_HIT_CRUSHING; - } - } - } - - DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL"); - return MELEE_HIT_NORMAL; -} - -uint32 Unit::CalculateDamage (WeaponAttackType attType, bool normalized) -{ - float min_damage, max_damage; - - if (normalized && GetTypeId()==TYPEID_PLAYER) - ((Player*)this)->CalculateMinMaxDamage(attType,normalized,min_damage, max_damage); - else - { - switch (attType) - { - case RANGED_ATTACK: - min_damage = GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE); - max_damage = GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE); - break; - case BASE_ATTACK: - min_damage = GetFloatValue(UNIT_FIELD_MINDAMAGE); - max_damage = GetFloatValue(UNIT_FIELD_MAXDAMAGE); - break; - case OFF_ATTACK: - min_damage = GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE); - max_damage = GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE); - break; - // Just for good manner - default: - min_damage = 0.0f; - max_damage = 0.0f; - break; - } - } - - if (min_damage > max_damage) - { - std::swap(min_damage,max_damage); - } - - if(max_damage == 0.0f) - max_damage = 5.0f; - - return urand((uint32)min_damage, (uint32)max_damage); -} - -float Unit::CalculateLevelPenalty(SpellEntry const* spellProto) const -{ - if(spellProto->spellLevel <= 0) - return 1.0f; - - float LvlPenalty = 0.0f; - - if(spellProto->spellLevel < 20) - LvlPenalty = 20.0f - spellProto->spellLevel * 3.75f; - float LvlFactor = (float(spellProto->spellLevel) + 6.0f) / float(getLevel()); - if(LvlFactor > 1.0f) - LvlFactor = 1.0f; - - return (100.0f - LvlPenalty) * LvlFactor / 100.0f; -} - -void Unit::SendAttackStart(Unit* pVictim) -{ - WorldPacket data( SMSG_ATTACKSTART, 16 ); - data << GetGUID(); - data << pVictim->GetGUID(); - - SendMessageToSet(&data, true); - DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" ); -} - -void Unit::SendAttackStop(Unit* victim) -{ - if(!victim) - return; - - WorldPacket data( SMSG_ATTACKSTOP, (4+16) ); // we guess size - data.append(GetPackGUID()); - data.append(victim->GetPackGUID()); // can be 0x00... - data << uint32(0); // can be 0x1 - SendMessageToSet(&data, true); - sLog.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER ? "player" : "creature"), GetGUIDLow(), (victim->GetTypeId()==TYPEID_PLAYER ? "player" : "creature"),victim->GetGUIDLow()); - - /*if(victim->GetTypeId() == TYPEID_UNIT) - ((Creature*)victim)->AI().EnterEvadeMode(this);*/ -} - -/* -// Melee based spells can be miss, parry or dodge on this step -// Crit or block - determined on damage calculation phase! (and can be both in some time) -float Unit::MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell) -{ - // Calculate hit chance (more correct for chance mod) - int32 HitChance; - - // PvP - PvE melee chances - int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; - int32 leveldif = pVictim->getLevelForTarget(this) - getLevelForTarget(pVictim); - if(leveldif < 3) - HitChance = 95 - leveldif; - else - HitChance = 93 - (leveldif - 2) * lchance; - - // Hit chance depends from victim auras - if(attType == RANGED_ATTACK) - HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); - else - HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); - - // Spellmod from SPELLMOD_RESIST_MISS_CHANCE - if(Player *modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, HitChance); - - // Miss = 100 - hit - float miss_chance= 100.0f - HitChance; - - // Bonuses from attacker aura and ratings - if (attType == RANGED_ATTACK) - miss_chance -= m_modRangedHitChance; - else - miss_chance -= m_modMeleeHitChance; - - // bonus from skills is 0.04% - miss_chance -= skillDiff * 0.04f; - - // Limit miss chance from 0 to 60% - if (miss_chance < 0.0f) - return 0.0f; - if (miss_chance > 60.0f) - return 60.0f; - return miss_chance; -} - -// Melee based spells hit result calculations -SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell) -{ - WeaponAttackType attType = BASE_ATTACK; - - if (spell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) - attType = RANGED_ATTACK; - - // bonus from skills is 0.04% per skill Diff - int32 attackerWeaponSkill = int32(GetWeaponSkillValue(attType,pVictim)); - int32 skillDiff = attackerWeaponSkill - int32(pVictim->GetMaxSkillValueForLevel(this)); - int32 fullSkillDiff = attackerWeaponSkill - int32(pVictim->GetDefenseSkillValue(this)); - - uint32 roll = urand (0, 10000); - uint32 missChance = uint32(MeleeSpellMissChance(pVictim, attType, fullSkillDiff, spell)*100.0f); - - // Roll miss - uint32 tmp = missChance; - if (roll < tmp) - return SPELL_MISS_MISS; - - // Same spells cannot be parry/dodge - if (spell->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) - return SPELL_MISS_NONE; - - // Ranged attack can`t miss too - if (attType == RANGED_ATTACK) - return SPELL_MISS_NONE; - - bool attackFromBehind = !pVictim->HasInArc(M_PI,this); - - // Roll dodge - int32 dodgeChance = int32(pVictim->GetUnitDodgeChance()*100.0f) - skillDiff * 4; - // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE - dodgeChance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); - - // Reduce dodge chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - dodgeChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); - if (dodgeChance < 0) - dodgeChance = 0; - - // Can`t dodge from behind in PvP (but its possible in PvE) - if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER && attackFromBehind) - dodgeChance = 0; - - // Rogue talent`s cant be dodged - AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); - for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) - { - if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) // can't be dodged rogue finishing move - { - if(spell->SpellFamilyName==SPELLFAMILY_ROGUE && (spell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) - { - dodgeChance = 0; - break; - } - } - } - - tmp += dodgeChance; - if (roll < tmp) - return SPELL_MISS_DODGE; - - // Roll parry - int32 parryChance = int32(pVictim->GetUnitParryChance()*100.0f) - skillDiff * 4; - // Reduce parry chance by attacker expertise rating - if (GetTypeId() == TYPEID_PLAYER) - parryChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); - // Can`t parry from behind - if (parryChance < 0 || attackFromBehind) - parryChance = 0; - - tmp += parryChance; - if (roll < tmp) - return SPELL_MISS_PARRY; - - return SPELL_MISS_NONE; -}*/ - -// TODO need use unit spell resistances in calculations -SpellMissInfo Unit::MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell) -{ - // Can`t miss on dead target (on skinning for example) - if (!pVictim->isAlive()) - return SPELL_MISS_NONE; - - SpellSchoolMask schoolMask = GetSpellSchoolMask(spell); - // PvP - PvE spell misschances per leveldif > 2 - int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 7 : 11; - int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); - - // Base hit chance from attacker and victim levels - int32 modHitChance; - if(leveldif < 3) - modHitChance = 96 - leveldif; - else - modHitChance = 94 - (leveldif - 2) * lchance; - - // Spellmod from SPELLMOD_RESIST_MISS_CHANCE - if(Player *modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, modHitChance); - // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras - modHitChance+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT, schoolMask); - // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras - modHitChance+= pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE, schoolMask); - // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura - if (IsAreaOfEffectSpell(spell)) - modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE); - // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST - if (IsDispelSpell(spell)) - modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST); - // Chance resist mechanic (select max value from every mechanic spell effect) - int32 resist_mech = 0; - // Get effects mechanic and chance - for(int eff = 0; eff < 3; ++eff) - { - int32 effect_mech = GetEffectMechanic(spell, eff); - if (effect_mech) - { - int32 temp = pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE, effect_mech); - if (resist_mech < temp) - resist_mech = temp; - } - } - // Apply mod - modHitChance-=resist_mech; - - // Chance resist debuff - modHitChance-=pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE, int32(spell->Dispel)); - - int32 HitChance = modHitChance * 100; - // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings - HitChance += int32(m_modSpellHitChance*100.0f); - - // Decrease hit chance from victim rating bonus - if (pVictim->GetTypeId()==TYPEID_PLAYER) - HitChance -= int32(((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL)*100.0f); - - if (HitChance < 100) HitChance = 100; - if (HitChance > 9900) HitChance = 9900; - - uint32 rand = urand(0,10000); - if (rand > HitChance) - return SPELL_MISS_RESIST; - return SPELL_MISS_NONE; -} - -SpellMissInfo Unit::SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool CanReflect) -{ - // Return evade for units in evade mode - if (pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) - return SPELL_MISS_EVADE; - - // If Spel has this flag cannot be resisted/immuned/etc - if (spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) - return SPELL_MISS_NONE; - - // Check for immune (use charges) - if (pVictim->IsImmunedToSpell(spell,true)) - return SPELL_MISS_IMMUNE; - - // All positive spells can`t miss - // TODO: client not show miss log for this spells - so need find info for this in dbc and use it! - if (IsPositiveSpell(spell->Id) - &&(!IsHostileTo(pVictim))) //prevent from affecting enemy by "positive" spell - return SPELL_MISS_NONE; - - // Check for immune (use charges) - if (pVictim->IsImmunedToDamage(GetSpellSchoolMask(spell),true)) - return SPELL_MISS_IMMUNE; - - // Try victim reflect spell - if (CanReflect) - { - // specialized first - Unit::AuraList const& mReflectSpellsSchool = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL); - for(Unit::AuraList::const_iterator i = mReflectSpellsSchool.begin(); i != mReflectSpellsSchool.end(); ++i) - { - if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spell)) - { - int32 reflectchance = (*i)->GetModifier()->m_amount; - if (reflectchance > 0 && roll_chance_i(reflectchance)) - { - if((*i)->m_procCharges > 0) - { - --(*i)->m_procCharges; - if((*i)->m_procCharges==0) - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - } - return SPELL_MISS_REFLECT; - } - } - } - - // generic reflection - Unit::AuraList const& mReflectSpells = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS); - for(Unit::AuraList::const_iterator i = mReflectSpells.begin(); i != mReflectSpells.end(); ++i) - { - int32 reflectchance = (*i)->GetModifier()->m_amount; - if (reflectchance > 0 && roll_chance_i(reflectchance)) - { - if((*i)->m_procCharges > 0) - { - --(*i)->m_procCharges; - if((*i)->m_procCharges==0) - pVictim->RemoveAurasDueToSpell((*i)->GetId()); - } - return SPELL_MISS_REFLECT; - } - } - } - - // Temporary solution for melee based spells and spells vs SPELL_SCHOOL_NORMAL (hit result calculated after) - for (int i=0;i<3;i++) - { - if (spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE || - spell->Effect[i] == SPELL_EFFECT_WEAPON_PERCENT_DAMAGE || - spell->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG || - spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL) - return SPELL_MISS_NONE; - } - - // TODO need use this code for spell hit result calculation - // now code commented for computability - switch (spell->DmgClass) - { - case SPELL_DAMAGE_CLASS_RANGED: - case SPELL_DAMAGE_CLASS_MELEE: -// return MeleeSpellHitResult(pVictim, spell); - return SPELL_MISS_NONE; - case SPELL_DAMAGE_CLASS_NONE: - return SPELL_MISS_NONE; - case SPELL_DAMAGE_CLASS_MAGIC: - return MagicSpellHitResult(pVictim, spell); - } - return SPELL_MISS_NONE; -} - -float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const -{ - if(!pVictim) - return 0.0f; - - // Base misschance 5% - float misschance = 5.0f; - - // DualWield - Melee spells and physical dmg spells - 5% , white damage 24% - if (haveOffhandWeapon() && attType != RANGED_ATTACK) - { - bool isNormal = false; - for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) - { - if( m_currentSpells[i] && (GetSpellSchoolMask(m_currentSpells[i]->m_spellInfo) & SPELL_SCHOOL_MASK_NORMAL) ) - { - isNormal = true; - break; - } - } - if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL]) - { - misschance = 5.0f; - } - else - { - misschance = 24.0f; - } - } - - // PvP : PvE melee misschances per leveldif > 2 - int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; - - int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); - if(leveldif < 0) - leveldif = 0; - - // Hit chance from attacker based on ratings and auras - float m_modHitChance; - if (attType == RANGED_ATTACK) - m_modHitChance = m_modRangedHitChance; - else - m_modHitChance = m_modMeleeHitChance; - - if(leveldif < 3) - misschance += (leveldif - m_modHitChance); - else - misschance += ((leveldif - 2) * chance - m_modHitChance); - - // Hit chance for victim based on ratings - if (pVictim->GetTypeId()==TYPEID_PLAYER) - { - if (attType == RANGED_ATTACK) - misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED); - else - misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE); - } - - // Modify miss chance by victim auras - if(attType == RANGED_ATTACK) - misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); - else - misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); - - // Modify miss chance from skill difference ( bonus from skills is 0.04% ) - int32 skillBonus = int32(GetWeaponSkillValue(attType,pVictim)) - int32(pVictim->GetDefenseSkillValue(this)); - misschance -= skillBonus * 0.04f; - - // Limit miss chance from 0 to 60% - if ( misschance < 0.0f) - return 0.0f; - if ( misschance > 60.0f) - return 60.0f; - - return misschance; -} - -uint32 Unit::GetDefenseSkillValue(Unit const* target) const -{ - if(GetTypeId() == TYPEID_PLAYER) - { - // in PvP use full skill instead current skill value - uint32 value = (target && target->GetTypeId() == TYPEID_PLAYER) - ? ((Player*)this)->GetMaxSkillValue(SKILL_DEFENSE) - : ((Player*)this)->GetSkillValue(SKILL_DEFENSE); - value += uint32(((Player*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL)); - return value; - } - else - return GetUnitMeleeSkill(target); -} - -float Unit::GetUnitDodgeChance() const -{ - if(hasUnitState(UNIT_STAT_STUNNED)) - return 0.0f; - if( GetTypeId() == TYPEID_PLAYER ) - return GetFloatValue(PLAYER_DODGE_PERCENTAGE); - else - { - if(((Creature const*)this)->isTotem()) - return 0.0f; - else - { - float dodge = 5.0f; - dodge += GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT); - return dodge > 0.0f ? dodge : 0.0f; - } - } -} - -float Unit::GetUnitParryChance() const -{ - if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) - return 0.0f; - - float chance = 0.0f; - - if(GetTypeId() == TYPEID_PLAYER) - { - Player const* player = (Player const*)this; - if(player->CanParry() ) - { - Item *tmpitem = player->GetWeaponForAttack(BASE_ATTACK,true); - if(!tmpitem) - tmpitem = player->GetWeaponForAttack(OFF_ATTACK,true); - - if(tmpitem) - chance = GetFloatValue(PLAYER_PARRY_PERCENTAGE); - } - } - else if(GetTypeId() == TYPEID_UNIT) - { - if(GetCreatureType() == CREATURE_TYPE_HUMANOID) - { - chance = 5.0f; - chance += GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT); - } - } - - return chance > 0.0f ? chance : 0.0f; -} - -float Unit::GetUnitBlockChance() const -{ - if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) - return 0.0f; - - if(GetTypeId() == TYPEID_PLAYER) - { - Player const* player = (Player const*)this; - if(player->CanBlock() ) - { - Item *tmpitem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); - if(tmpitem && !tmpitem->IsBroken() && tmpitem->GetProto()->Block) - return GetFloatValue(PLAYER_BLOCK_PERCENTAGE); - } - // is player but has no block ability or no not broken shield equipped - return 0.0f; - } - else - { - if(((Creature const*)this)->isTotem()) - return 0.0f; - else - { - float block = 5.0f; - block += GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT); - return block > 0.0f ? block : 0.0f; - } - } -} - -float Unit::GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const -{ - float crit; - - if(GetTypeId() == TYPEID_PLAYER) - { - switch(attackType) - { - case BASE_ATTACK: - crit = GetFloatValue( PLAYER_CRIT_PERCENTAGE ); - break; - case OFF_ATTACK: - crit = GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE ); - break; - case RANGED_ATTACK: - crit = GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE ); - break; - // Just for good manner - default: - crit = 0.0f; - break; - } - } - else - { - crit = 5.0f; - crit += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT); - } - - // flat aura mods - if(attackType == RANGED_ATTACK) - crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE); - else - crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE); - - crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); - - // reduce crit chance from Rating for players - if (pVictim->GetTypeId()==TYPEID_PLAYER) - { - if (attackType==RANGED_ATTACK) - crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED); - else - crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE); - } - - if (crit < 0.0f) - crit = 0.0f; - return crit; -} - -uint32 Unit::GetWeaponSkillValue (WeaponAttackType attType, Unit const* target) const -{ - uint32 value = 0; - if(GetTypeId() == TYPEID_PLAYER) - { - Item* item = ((Player*)this)->GetWeaponForAttack(attType,true); - - // feral or unarmed skill only for base attack - if(attType != BASE_ATTACK && !item ) - return 0; - - if(((Player*)this)->IsInFeralForm()) - return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact - - // weapon skill or (unarmed for base attack) - uint32 skill = item ? item->GetSkill() : SKILL_UNARMED; - - // in PvP use full skill instead current skill value - value = (target && target->GetTypeId() == TYPEID_PLAYER) - ? ((Player*)this)->GetMaxSkillValue(skill) - : ((Player*)this)->GetSkillValue(skill); - // Modify value from ratings - value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL)); - switch (attType) - { - case BASE_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND));break; - case OFF_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND));break; - case RANGED_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED));break; - } - } - else - value = GetUnitMeleeSkill(target); - return value; -} - -void Unit::_UpdateSpells( uint32 time ) -{ - if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]) - _UpdateAutoRepeatSpell(); - - // remove finished spells from current pointers - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - { - if (m_currentSpells[i] && m_currentSpells[i]->getState() == SPELL_STATE_FINISHED) - { - m_currentSpells[i]->SetReferencedFromCurrent(false); - m_currentSpells[i] = NULL; // remove pointer - } - } - - // TODO: Find a better way to prevent crash when multiple auras are removed. - m_removedAuras = 0; - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) - if ((*i).second) - (*i).second->SetUpdated(false); - - for (AuraMap::iterator i = m_Auras.begin(), next; i != m_Auras.end(); i = next) - { - next = i; - ++next; - if ((*i).second) - { - // prevent double update - if ((*i).second->IsUpdated()) - continue; - (*i).second->SetUpdated(true); - (*i).second->Update( time ); - // several auras can be deleted due to update - if (m_removedAuras) - { - if (m_Auras.empty()) break; - next = m_Auras.begin(); - m_removedAuras = 0; - } - } - } - - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end();) - { - if ((*i).second) - { - if ( !(*i).second->GetAuraDuration() && !((*i).second->IsPermanent() || ((*i).second->IsPassive())) ) - { - RemoveAura(i); - } - else - { - ++i; - } - } - else - { - ++i; - } - } - - if(!m_gameObj.empty()) - { - std::list::iterator ite1, dnext1; - for (ite1 = m_gameObj.begin(); ite1 != m_gameObj.end(); ite1 = dnext1) - { - dnext1 = ite1; - //(*i)->Update( difftime ); - if( !(*ite1)->isSpawned() ) - { - (*ite1)->SetOwnerGUID(0); - (*ite1)->SetRespawnTime(0); - (*ite1)->Delete(); - dnext1 = m_gameObj.erase(ite1); - } - else - ++dnext1; - } - } -} - -void Unit::_UpdateAutoRepeatSpell() -{ - //check "realtime" interrupts - if ( (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) ) - { - // cancel wand shoot - if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - m_AutoRepeatFirstCast = true; - return; - } - - //apply delay - if ( m_AutoRepeatFirstCast && getAttackTimer(RANGED_ATTACK) < 500 ) - setAttackTimer(RANGED_ATTACK,500); - m_AutoRepeatFirstCast = false; - - //castroutine - if (isAttackReady(RANGED_ATTACK)) - { - // Check if able to cast - if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->CanCast(true)) - { - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - return; - } - - // we want to shoot - Spell* spell = new Spell(this, m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo, true, 0); - spell->prepare(&(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_targets)); - - // all went good, reset attack - resetAttackTimer(RANGED_ATTACK); - } -} - -void Unit::SetCurrentCastedSpell( Spell * pSpell ) -{ - assert(pSpell); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells - - uint32 CSpellType = pSpell->GetCurrentContainer(); - - if (pSpell == m_currentSpells[CSpellType]) return; // avoid breaking self - - // break same type spell if it is not delayed - InterruptSpell(CSpellType,false); - - // special breakage effects: - switch (CSpellType) - { - case CURRENT_GENERIC_SPELL: - { - // generic spells always break channeled not delayed spells - InterruptSpell(CURRENT_CHANNELED_SPELL,false); - - // autorepeat breaking - if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) - { - // break autorepeat if not Auto Shot - if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - m_AutoRepeatFirstCast = true; - } - addUnitState(UNIT_STAT_CASTING); - } break; - - case CURRENT_CHANNELED_SPELL: - { - // channel spells always break generic non-delayed and any channeled spells - InterruptSpell(CURRENT_GENERIC_SPELL,false); - InterruptSpell(CURRENT_CHANNELED_SPELL); - - // it also does break autorepeat if not Auto Shot - if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && - m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351 ) - InterruptSpell(CURRENT_AUTOREPEAT_SPELL); - addUnitState(UNIT_STAT_CASTING); - } break; - - case CURRENT_AUTOREPEAT_SPELL: - { - // only Auto Shoot does not break anything - if (pSpell->m_spellInfo->Category == 351) - { - // generic autorepeats break generic non-delayed and channeled non-delayed spells - InterruptSpell(CURRENT_GENERIC_SPELL,false); - InterruptSpell(CURRENT_CHANNELED_SPELL,false); - } - // special action: set first cast flag - m_AutoRepeatFirstCast = true; - } break; - - default: - { - // other spell types don't break anything now - } break; - } - - // current spell (if it is still here) may be safely deleted now - if (m_currentSpells[CSpellType]) - m_currentSpells[CSpellType]->SetReferencedFromCurrent(false); - - // set new current spell - m_currentSpells[CSpellType] = pSpell; - pSpell->SetReferencedFromCurrent(true); -} - -void Unit::InterruptSpell(uint32 spellType, bool withDelayed) -{ - assert(spellType < CURRENT_MAX_SPELL); - - if(m_currentSpells[spellType] && (withDelayed || m_currentSpells[spellType]->getState() != SPELL_STATE_DELAYED) ) - { - // send autorepeat cancel message for autorepeat spells - if (spellType == CURRENT_AUTOREPEAT_SPELL) - { - if(GetTypeId()==TYPEID_PLAYER) - ((Player*)this)->SendAutoRepeatCancel(); - } - - if (m_currentSpells[spellType]->getState() != SPELL_STATE_FINISHED) - m_currentSpells[spellType]->cancel(); - m_currentSpells[spellType]->SetReferencedFromCurrent(false); - m_currentSpells[spellType] = NULL; - } -} - -bool Unit::IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled, bool skipAutorepeat) const -{ - // We don't do loop here to explicitly show that melee spell is excluded. - // Maybe later some special spells will be excluded too. - - // generic spells are casted when they are not finished and not delayed - if ( m_currentSpells[CURRENT_GENERIC_SPELL] && - (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && - (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) - return(true); - - // channeled spells may be delayed, but they are still considered casted - else if ( !skipChanneled && m_currentSpells[CURRENT_CHANNELED_SPELL] && - (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) ) - return(true); - - // autorepeat spells may be finished or delayed, but they are still considered casted - else if ( !skipAutorepeat && m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) - return(true); - - return(false); -} - -void Unit::InterruptNonMeleeSpells(bool withDelayed, uint32 spell_id) -{ - // generic spells are interrupted if they are not finished or delayed - if (m_currentSpells[CURRENT_GENERIC_SPELL] && (!spell_id || m_currentSpells[CURRENT_GENERIC_SPELL]->m_spellInfo->Id==spell_id)) - { - if ( (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && - (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) - m_currentSpells[CURRENT_GENERIC_SPELL]->cancel(); - m_currentSpells[CURRENT_GENERIC_SPELL]->SetReferencedFromCurrent(false); - m_currentSpells[CURRENT_GENERIC_SPELL] = NULL; - } - - // autorepeat spells are interrupted if they are not finished or delayed - if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && (!spell_id || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Id==spell_id)) - { - // send disable autorepeat packet in any case - if(GetTypeId()==TYPEID_PLAYER) - ((Player*)this)->SendAutoRepeatCancel(); - - if ( (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_FINISHED) && - (withDelayed || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_DELAYED) ) - m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->cancel(); - m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->SetReferencedFromCurrent(false); - m_currentSpells[CURRENT_AUTOREPEAT_SPELL] = NULL; - } - - // channeled spells are interrupted if they are not finished, even if they are delayed - if (m_currentSpells[CURRENT_CHANNELED_SPELL] && (!spell_id || m_currentSpells[CURRENT_CHANNELED_SPELL]->m_spellInfo->Id==spell_id)) - { - if (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) - m_currentSpells[CURRENT_CHANNELED_SPELL]->cancel(); - m_currentSpells[CURRENT_CHANNELED_SPELL]->SetReferencedFromCurrent(false); - m_currentSpells[CURRENT_CHANNELED_SPELL] = NULL; - } -} - -Spell* Unit::FindCurrentSpellBySpellId(uint32 spell_id) const -{ - for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) - if(m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id==spell_id) - return m_currentSpells[i]; - return NULL; -} - -bool Unit::isInFront(Unit const* target, float distance, float arc) const -{ - return IsWithinDistInMap(target, distance) && HasInArc( arc, target ); -} - -void Unit::SetInFront(Unit const* target) -{ - SetOrientation(GetAngle(target)); -} - -bool Unit::isInBack(Unit const* target, float distance, float arc) const -{ - return IsWithinDistInMap(target, distance) && !HasInArc( 2 * M_PI - arc, target ); -} - -bool Unit::isInLine(Unit const* target, float distance) const -{ - if(!HasInArc(M_PI, target) || !IsWithinDistInMap(target, distance)) return false; - float width = (GetObjectSize() / 2 + target->GetObjectSize()) / 2; - float angle = GetAngle(target); - angle -= GetOrientation(); - return abs(sin(angle)) * distance < width; -} - -bool Unit::isInAccessiblePlaceFor(Creature const* c) const -{ - if(IsInWater()) - return c->canSwim(); - else - return c->canWalk() || c->canFly(); -} - -bool Unit::IsInWater() const -{ - return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ()); -} - -bool Unit::IsUnderWater() const -{ - return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ()); -} - -void Unit::DeMorph() -{ - SetDisplayId(GetNativeDisplayId()); -} - -int32 Unit::GetTotalAuraModifier(AuraType auratype) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - modifier += (*i)->GetModifier()->m_amount; - - return modifier; -} - -float Unit::GetTotalAuraMultiplier(AuraType auratype) const -{ - float multiplier = 1.0f; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - multiplier *= (100.0f + (*i)->GetModifier()->m_amount)/100.0f; - - return multiplier; -} - -int32 Unit::GetMaxPositiveAuraModifier(AuraType auratype) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - if ((*i)->GetModifier()->m_amount > modifier) - modifier = (*i)->GetModifier()->m_amount; - - return modifier; -} - -int32 Unit::GetMaxNegativeAuraModifier(AuraType auratype) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - if ((*i)->GetModifier()->m_amount < modifier) - modifier = (*i)->GetModifier()->m_amount; - - return modifier; -} - -int32 Unit::GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask) - modifier += mod->m_amount; - } - return modifier; -} - -float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - float multiplier = 1.0f; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask) - multiplier *= (100.0f + mod->m_amount)/100.0f; - } - return multiplier; -} - -int32 Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask && mod->m_amount > modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -int32 Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue & misc_mask && mod->m_amount < modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -int32 Unit::GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value) - modifier += mod->m_amount; - } - return modifier; -} - -float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const -{ - float multiplier = 1.0f; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value) - multiplier *= (100.0f + mod->m_amount)/100.0f; - } - return multiplier; -} - -int32 Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value && mod->m_amount > modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -int32 Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const -{ - int32 modifier = 0; - - AuraList const& mTotalAuraList = GetAurasByType(auratype); - for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - if (mod->m_miscvalue == misc_value && mod->m_amount < modifier) - modifier = mod->m_amount; - } - - return modifier; -} - -bool Unit::AddAura(Aura *Aur) -{ - // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load) - if( !isAlive() && Aur->GetId() != 20584 && Aur->GetId() != 8326 && Aur->GetId() != 2584 && - (GetTypeId()!=TYPEID_PLAYER || !((Player*)this)->GetSession()->PlayerLoading()) ) - { - delete Aur; - return false; - } - - if(Aur->GetTarget() != this) - { - sLog.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)", - Aur->GetId(),Aur->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER?"player":"creature"),GetGUIDLow(), - (Aur->GetTarget()->GetTypeId()==TYPEID_PLAYER?"player":"creature"),Aur->GetTarget()->GetGUIDLow()); - delete Aur; - return false; - } - - SpellEntry const* aurSpellInfo = Aur->GetSpellProto(); - - spellEffectPair spair = spellEffectPair(Aur->GetId(), Aur->GetEffIndex()); - AuraMap::iterator i = m_Auras.find( spair ); - - // take out same spell - if (i != m_Auras.end()) - { - // passive and persistent auras can stack with themselves any number of times - if (!Aur->IsPassive() && !Aur->IsPersistent()) - { - // replace aura if next will > spell StackAmount - if(aurSpellInfo->StackAmount) - { - if(m_Auras.count(spair) >= aurSpellInfo->StackAmount) - RemoveAura(i,AURA_REMOVE_BY_STACK); - } - // if StackAmount==0 not allow auras from same caster - else - { - for(AuraMap::iterator i2 = m_Auras.lower_bound(spair); i2 != m_Auras.upper_bound(spair); ++i2) - { - if(i2->second->GetCasterGUID()==Aur->GetCasterGUID()) - { - // can be only single (this check done at _each_ aura add - RemoveAura(i2,AURA_REMOVE_BY_STACK); - break; - } - - bool stop = false; - switch(aurSpellInfo->EffectApplyAuraName[Aur->GetEffIndex()]) - { - // DoT/HoT/etc - case SPELL_AURA_PERIODIC_DAMAGE: // allow stack - case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: - case SPELL_AURA_PERIODIC_LEECH: - case SPELL_AURA_PERIODIC_HEAL: - case SPELL_AURA_OBS_MOD_HEALTH: - case SPELL_AURA_PERIODIC_MANA_LEECH: - case SPELL_AURA_PERIODIC_ENERGIZE: - case SPELL_AURA_OBS_MOD_MANA: - case SPELL_AURA_POWER_BURN_MANA: - break; - default: // not allow - // can be only single (this check done at _each_ aura add - RemoveAura(i2,AURA_REMOVE_BY_STACK); - stop = true; - break; - } - - if(stop) - break; - } - } - } - } - - // passive auras stack with all (except passive spell proc auras) - if ((!Aur->IsPassive() || !IsPassiveStackableSpell(Aur->GetId())) && - !(Aur->GetId() == 20584 || Aur->GetId() == 8326)) - { - if (!RemoveNoStackAurasDueToAura(Aur)) - { - delete Aur; - return false; // couldn't remove conflicting aura with higher rank - } - } - - // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura) - if (IsSingleTargetSpell(aurSpellInfo) && Aur->GetTarget()) - { - // caster pointer can be deleted in time aura remove, find it by guid at each iteration - for(;;) - { - Unit* caster = Aur->GetCaster(); - if(!caster) // caster deleted and not required adding scAura - break; - - bool restart = false; - AuraList& scAuras = caster->GetSingleCastAuras(); - for(AuraList::iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) - { - if( (*itr)->GetTarget() != Aur->GetTarget() && - IsSingleTargetSpells((*itr)->GetSpellProto(),aurSpellInfo) ) - { - if ((*itr)->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for IsSingleTargetSpell", (*itr)->GetId(), (*itr)->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - (*itr)->GetTarget()->RemoveAura((*itr)->GetId(), (*itr)->GetEffIndex()); - restart = true; - break; - } - } - - if(!restart) - { - // done - scAuras.push_back(Aur); - break; - } - } - } - - // add aura, register in lists and arrays - Aur->_AddAura(); - m_Auras.insert(AuraMap::value_type(spellEffectPair(Aur->GetId(), Aur->GetEffIndex()), Aur)); - if (Aur->GetModifier()->m_auraname < TOTAL_AURAS) - { - m_modAuras[Aur->GetModifier()->m_auraname].push_back(Aur); - if(Aur->GetSpellProto()->AuraInterruptFlags) - { - m_interruptableAuras.push_back(Aur); - AddInterruptMask(Aur->GetSpellProto()->AuraInterruptFlags); - } - if(Aur->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) - { - m_ccAuras.push_back(Aur); - } - } - - Aur->ApplyModifier(true,true); - sLog.outDebug("Aura %u now is in use", Aur->GetModifier()->m_auraname); - return true; -} - -void Unit::RemoveRankAurasDueToSpell(uint32 spellId) -{ - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - if(!spellInfo) - return; - AuraMap::iterator i,next; - for (i = m_Auras.begin(); i != m_Auras.end(); i = next) - { - next = i; - ++next; - uint32 i_spellId = (*i).second->GetId(); - if((*i).second && i_spellId && i_spellId != spellId) - { - if(spellmgr.IsRankSpellDueToSpell(spellInfo,i_spellId)) - { - RemoveAurasDueToSpell(i_spellId); - - if( m_Auras.empty() ) - break; - else - next = m_Auras.begin(); - } - } - } -} - -bool Unit::RemoveNoStackAurasDueToAura(Aura *Aur) -{ - if (!Aur) - return false; - - SpellEntry const* spellProto = Aur->GetSpellProto(); - if (!spellProto) - return false; - - uint32 spellId = Aur->GetId(); - uint32 effIndex = Aur->GetEffIndex(); - - SpellSpecific spellId_spec = GetSpellSpecific(spellId); - - AuraMap::iterator i,next; - for (i = m_Auras.begin(); i != m_Auras.end(); i = next) - { - next = i; - ++next; - if (!(*i).second) continue; - - SpellEntry const* i_spellProto = (*i).second->GetSpellProto(); - - if (!i_spellProto) - continue; - - uint32 i_spellId = i_spellProto->Id; - - if(IsPassiveSpell(i_spellId)) - { - if(IsPassiveStackableSpell(i_spellId)) - continue; - - // passive non-stackable spells not stackable only with another rank of same spell - if (!spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) - continue; - } - - uint32 i_effIndex = (*i).second->GetEffIndex(); - - if(i_spellId == spellId) continue; - - bool is_triggered_by_spell = false; - // prevent triggered aura of removing aura that triggered it - for(int j = 0; j < 3; ++j) - if (i_spellProto->EffectTriggerSpell[j] == spellProto->Id) - is_triggered_by_spell = true; - if (is_triggered_by_spell) continue; - - for(int j = 0; j < 3; ++j) - { - // prevent remove dummy triggered spells at next effect aura add - switch(spellProto->Effect[j]) // main spell auras added added after triggered spell - { - case SPELL_EFFECT_DUMMY: - switch(spellId) - { - case 5420: if(i_spellId==34123) is_triggered_by_spell = true; break; - } - break; - } - - if(is_triggered_by_spell) - break; - - // prevent remove form main spell by triggered passive spells - switch(i_spellProto->EffectApplyAuraName[j]) // main aura added before triggered spell - { - case SPELL_AURA_MOD_SHAPESHIFT: - switch(i_spellId) - { - case 24858: if(spellId==24905) is_triggered_by_spell = true; break; - case 33891: if(spellId==5420 || spellId==34123) is_triggered_by_spell = true; break; - case 34551: if(spellId==22688) is_triggered_by_spell = true; break; - } - break; - } - } - - if(!is_triggered_by_spell) - { - bool isFromSameCaster = Aur->GetCasterGUID() == (*i).second->GetCasterGUID(); - if( spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId, isFromSameCaster) ) - { - //some spells should be not removed by lower rank of them - if (!isFromSameCaster - &&(spellProto->Effect[effIndex]==SPELL_AURA_MOD_INCREASE_ENERGY) - &&(spellProto->DurationIndex==21) - &&(spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) - &&(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0)) - return false; - - //Its a parent aura (create this aura in ApplyModifier) - if ((*i).second->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - RemoveAurasDueToSpell(i_spellId); - - if( m_Auras.empty() ) - break; - else - next = m_Auras.begin(); - } - } - } - return true; -} - -void Unit::RemoveAura(uint32 spellId, uint32 effindex, Aura* except) -{ - spellEffectPair spair = spellEffectPair(spellId, effindex); - for(AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) - { - if(iter->second!=except) - { - RemoveAura(iter); - iter = m_Auras.lower_bound(spair); - } - else - ++iter; - } -} - -void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler) -{ - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - Aura *aur = iter->second; - if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) - { - // Custom dispel case - // Unstable Affliction - if (aur->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (aur->GetSpellProto()->SpellFamilyFlags & 0x010000000000LL)) - { - int32 damage = aur->GetModifier()->m_amount*9; - uint64 caster_guid = aur->GetCasterGUID(); - - // Remove aura - RemoveAura(iter, AURA_REMOVE_BY_DISPEL); - - // backfire damage and silence - dispeler->CastCustomSpell(dispeler, 31117, &damage, NULL, NULL, true, NULL, NULL,caster_guid); - - iter = m_Auras.begin(); // iterator can be invalidate at cast if self-dispel - } - else - RemoveAura(iter, AURA_REMOVE_BY_DISPEL); - } - else - ++iter; - } -} - -void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer) -{ - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - Aura *aur = iter->second; - if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) - { - int32 basePoints = aur->GetBasePoints(); - // construct the new aura for the attacker - Aura * new_aur = CreateAura(aur->GetSpellProto(), aur->GetEffIndex(), &basePoints, stealer); - if(!new_aur) - continue; - - // set its duration and maximum duration - // max duration 2 minutes (in msecs) - int32 dur = aur->GetAuraDuration(); - const int32 max_dur = 2*MINUTE*1000; - new_aur->SetAuraMaxDuration( max_dur > dur ? dur : max_dur ); - new_aur->SetAuraDuration( max_dur > dur ? dur : max_dur ); - - // add the new aura to stealer - stealer->AddAura(new_aur); - - // Remove aura as dispel - RemoveAura(iter, AURA_REMOVE_BY_DISPEL); - } - else - ++iter; - } -} - -void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId) -{ - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - if (iter->second->GetId() == spellId) - RemoveAura(iter, AURA_REMOVE_BY_CANCEL); - else - ++iter; - } -} - -void Unit::RemoveAurasWithDispelType( DispelType type ) -{ - // Create dispel mask by dispel type - uint32 dispelMask = GetDispellMask(type); - // Dispel all existing auras vs current dispel type - AuraMap& auras = GetAuras(); - for(AuraMap::iterator itr = auras.begin(); itr != auras.end(); ) - { - SpellEntry const* spell = itr->second->GetSpellProto(); - if( (1<Dispel) & dispelMask ) - { - // Dispel aura - RemoveAurasDueToSpell(spell->Id); - itr = auras.begin(); - } - else - ++itr; - } -} - -void Unit::RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex) -{ - AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); - if(iter != m_Auras.end()) - RemoveAura(iter); -} - -void Unit::RemoveAurasDueToSpell(uint32 spellId, Aura* except) -{ - for (int i = 0; i < 3; ++i) - RemoveAura(spellId,i,except); -} - -void Unit::RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId) -{ - for (int k=0; k < 3; ++k) - { - spellEffectPair spair = spellEffectPair(spellId, k); - for (AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) - { - if (iter->second->GetCastItemGUID() == castItem->GetGUID()) - { - RemoveAura(iter); - iter = m_Auras.upper_bound(spair); // overwrite by more appropriate - } - else - ++iter; - } - } -} - -void Unit::RemoveNotOwnSingleTargetAuras() -{ - // single target auras from other casters - for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) - { - if (iter->second->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter->second->GetSpellProto())) - RemoveAura(iter); - else - ++iter; - } - - // single target auras at other targets - AuraList& scAuras = GetSingleCastAuras(); - for (AuraList::iterator iter = scAuras.begin(); iter != scAuras.end(); ) - { - Aura* aura = *iter; - if (aura->GetTarget()!=this) - { - scAuras.erase(iter); // explicitly remove, instead waiting remove in RemoveAura - aura->GetTarget()->RemoveAura(aura->GetId(),aura->GetEffIndex()); - iter = scAuras.begin(); - } - else - ++iter; - } - -} - -void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) -{ - if (IsSingleTargetSpell((*i).second->GetSpellProto())) - { - if(Unit* caster = (*i).second->GetCaster()) - { - AuraList& scAuras = caster->GetSingleCastAuras(); - scAuras.remove((*i).second); - } - else - { - sLog.outError("Couldn't find the caster of the single target aura, may crash later!"); - assert(false); - } - } - - if ((*i).second->GetModifier()->m_auraname < TOTAL_AURAS) - { - m_modAuras[(*i).second->GetModifier()->m_auraname].remove((*i).second); - if((*i).second->GetSpellProto()->AuraInterruptFlags) - { - m_interruptableAuras.remove((*i).second); - UpdateInterruptMask(); - } - if((*i).second->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) - m_ccAuras.remove((*i).second); - } - - // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) - Aura* Aur = i->second; - // Set remove mode - Aur->SetRemoveMode(mode); - // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura - // remove aura from list before to prevent deleting it before - m_Auras.erase(i); - ++m_removedAuras; // internal count used by unit update - - // Status unsummoned at aura remove - Totem* statue = NULL; - if(IsChanneledSpell(Aur->GetSpellProto())) - if(Unit* caster = Aur->GetCaster()) - if(caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->isTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE) - statue = ((Totem*)caster); - - - if(const std::vector *spell_triggered = spellmgr.GetSpellLinked(-(int32)Aur->GetSpellProto()->Id)) - { - for(std::vector::const_iterator i = spell_triggered->begin(); i != spell_triggered->end(); ++i) - { - if(spell_triggered < 0) - RemoveAurasDueToSpell(-(*i)); - else if(Unit* caster = Aur->GetCaster()) - CastSpell(this, *i, true, 0, 0, caster->GetGUID()); - } - } - - sLog.outDebug("Aura %u now is remove mode %d",Aur->GetModifier()->m_auraname, mode); - Aur->ApplyModifier(false,true); - Aur->_RemoveAura(); - delete Aur; - - if(statue) - statue->UnSummon(); - - // only way correctly remove all auras from list - if( m_Auras.empty() ) - i = m_Auras.end(); - else - i = m_Auras.begin(); -} - -void Unit::RemoveAllAuras() -{ - while (!m_Auras.empty()) - { - AuraMap::iterator iter = m_Auras.begin(); - RemoveAura(iter); - } -} - -void Unit::RemoveArenaAuras(bool onleave) -{ - // in join, remove positive buffs, on end, remove negative - // used to remove positive visible auras in arenas - for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) - { - if ( !(iter->second->GetSpellProto()->AttributesEx4 & (1<<21)) // don't remove stances, shadowform, pally/hunter auras - && !iter->second->IsPassive() // don't remove passive auras - && (!(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) || !(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNK8)) // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable) - && (iter->second->IsPositive() ^ onleave)) // remove positive buffs on enter, negative buffs on leave - RemoveAura(iter); - else - ++iter; - } -} - -void Unit::RemoveAllAurasOnDeath() -{ - // used just after dieing to remove all visible auras - // and disable the mods for the passive ones - for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) - { - if (!iter->second->IsPassive() && !iter->second->IsDeathPersistent()) - RemoveAura(iter, AURA_REMOVE_BY_DEATH); - else - ++iter; - } -} - -void Unit::DelayAura(uint32 spellId, uint32 effindex, int32 delaytime) -{ - AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); - if (iter != m_Auras.end()) - { - if (iter->second->GetAuraDuration() < delaytime) - iter->second->SetAuraDuration(0); - else - iter->second->SetAuraDuration(iter->second->GetAuraDuration() - delaytime); - iter->second->UpdateAuraDuration(); - sLog.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter->second->GetModifier()->m_auraname, GetGUIDLow(), iter->second->GetAuraDuration()); - } -} - -void Unit::_RemoveAllAuraMods() -{ - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) - { - (*i).second->ApplyModifier(false); - } -} - -void Unit::_ApplyAllAuraMods() -{ - for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) - { - (*i).second->ApplyModifier(true); - } -} - -Aura* Unit::GetAura(uint32 spellId, uint32 effindex) -{ - AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); - if (iter != m_Auras.end()) - return iter->second; - return NULL; -} - -void Unit::AddDynObject(DynamicObject* dynObj) -{ - m_dynObjGUIDs.push_back(dynObj->GetGUID()); -} - -void Unit::RemoveDynObject(uint32 spellid) -{ - if(m_dynObjGUIDs.empty()) - return; - for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(!dynObj) - { - i = m_dynObjGUIDs.erase(i); - } - else if(spellid == 0 || dynObj->GetSpellId() == spellid) - { - dynObj->Delete(); - i = m_dynObjGUIDs.erase(i); - } - else - ++i; - } -} - -void Unit::RemoveAllDynObjects() -{ - while(!m_dynObjGUIDs.empty()) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(dynObj) - dynObj->Delete(); - m_dynObjGUIDs.erase(m_dynObjGUIDs.begin()); - } -} - -DynamicObject * Unit::GetDynObject(uint32 spellId, uint32 effIndex) -{ - for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(!dynObj) - { - i = m_dynObjGUIDs.erase(i); - continue; - } - - if (dynObj->GetSpellId() == spellId && dynObj->GetEffIndex() == effIndex) - return dynObj; - ++i; - } - return NULL; -} - -DynamicObject * Unit::GetDynObject(uint32 spellId) -{ - for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) - { - DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); - if(!dynObj) - { - i = m_dynObjGUIDs.erase(i); - continue; - } - - if (dynObj->GetSpellId() == spellId) - return dynObj; - ++i; - } - return NULL; -} - -void Unit::AddGameObject(GameObject* gameObj) -{ - assert(gameObj && gameObj->GetOwnerGUID()==0); - m_gameObj.push_back(gameObj); - gameObj->SetOwnerGUID(GetGUID()); -} - -void Unit::RemoveGameObject(GameObject* gameObj, bool del) -{ - assert(gameObj && gameObj->GetOwnerGUID()==GetGUID()); - - // GO created by some spell - if ( GetTypeId()==TYPEID_PLAYER && gameObj->GetSpellId() ) - { - SpellEntry const* createBySpell = sSpellStore.LookupEntry(gameObj->GetSpellId()); - // Need activate spell use for owner - if (createBySpell && createBySpell->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) - ((Player*)this)->SendCooldownEvent(createBySpell); - } - gameObj->SetOwnerGUID(0); - m_gameObj.remove(gameObj); - if(del) - { - gameObj->SetRespawnTime(0); - gameObj->Delete(); - } -} - -void Unit::RemoveGameObject(uint32 spellid, bool del) -{ - if(m_gameObj.empty()) - return; - std::list::iterator i, next; - for (i = m_gameObj.begin(); i != m_gameObj.end(); i = next) - { - next = i; - if(spellid == 0 || (*i)->GetSpellId() == spellid) - { - (*i)->SetOwnerGUID(0); - if(del) - { - (*i)->SetRespawnTime(0); - (*i)->Delete(); - } - - next = m_gameObj.erase(i); - } - else - ++next; - } -} - -void Unit::RemoveAllGameObjects() -{ - // remove references to unit - for(std::list::iterator i = m_gameObj.begin(); i != m_gameObj.end();) - { - (*i)->SetOwnerGUID(0); - (*i)->SetRespawnTime(0); - (*i)->Delete(); - i = m_gameObj.erase(i); - } -} - -void Unit::SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID,uint32 Damage, SpellSchoolMask damageSchoolMask,uint32 AbsorbedDamage, uint32 Resist,bool PhysicalDamage, uint32 Blocked, bool CriticalHit) -{ - sLog.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG"); - WorldPacket data(SMSG_SPELLNONMELEEDAMAGELOG, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size - data.append(target->GetPackGUID()); - data.append(GetPackGUID()); - data << uint32(SpellID); - data << uint32(Damage-AbsorbedDamage-Resist-Blocked); - data << uint8(damageSchoolMask); // spell school - data << uint32(AbsorbedDamage); // AbsorbedDamage - data << uint32(Resist); // resist - data << uint8(PhysicalDamage); // if 1, then client show spell name (example: %s's ranged shot hit %s for %u school or %s suffers %u school damage from %s's spell_name - data << uint8(0); // unk isFromAura - data << uint32(Blocked); // blocked - data << uint32(CriticalHit ? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster? - data << uint8(0); // isDebug? - SendMessageToSet( &data, true ); -} - -void Unit::SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo) -{ - WorldPacket data(SMSG_SPELLLOGMISS, (4+8+1+4+8+1)); - data << uint32(spellID); - data << uint64(GetGUID()); - data << uint8(0); // can be 0 or 1 - data << uint32(1); // target count - // for(i = 0; i < target count; ++i) - data << uint64(target->GetGUID()); // target GUID - data << uint8(missInfo); - // end loop - SendMessageToSet(&data, true); -} - -void Unit::SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount) -{ - sLog.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE"); - - WorldPacket data(SMSG_ATTACKERSTATEUPDATE, (16+45)); // we guess size - data << (uint32)HitInfo; - data.append(GetPackGUID()); - data.append(target->GetPackGUID()); - data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); - - data << (uint8)SwingType; // count? - - // for(i = 0; i < SwingType; ++i) - data << (uint32)damageSchoolMask; - data << (float)(Damage-AbsorbDamage-Resist-BlockedAmount); - // still need to double check damage - data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); - data << (uint32)AbsorbDamage; - data << (uint32)Resist; - // end loop - - data << (uint32)TargetState; - - if( AbsorbDamage == 0 ) //also 0x3E8 = 0x3E8, check when that happens - data << (uint32)0; - else - data << (uint32)-1; - - data << (uint32)0; - data << (uint32)BlockedAmount; - - SendMessageToSet( &data, true ); -} - -void Unit::ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const *procSpell, bool isTriggeredSpell, WeaponAttackType attType) -{ - sLog.outDebug("ProcDamageAndSpell: attacker flags are 0x%x, victim flags 0x%x", procAttacker, procVictim); - if(procSpell) - sLog.outDebug("ProcDamageAndSpell: invoked due to spell id %u %s", procSpell->Id, (isTriggeredSpell?"(triggered)":"")); - - // Assign melee/ranged proc flags for magic attacks, that are actually melee/ranged abilities - // not assign for spell proc triggered spell to prevent infinity (or unexpected 2-3 times) melee damage spell proc call with melee damage effect - // That is the question though if it's fully correct - if(procSpell && !isTriggeredSpell) - { - if(procSpell->DmgClass == SPELL_DAMAGE_CLASS_MELEE) - { - if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_MELEE; - if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_MELEE; - if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_MELEE; - if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_MELEE; - attType = BASE_ATTACK; // Melee abilities are assumed to be dealt with mainhand weapon - } - else if (procSpell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) - { - if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_RANGED; - if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_RANGED; - if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_RANGED; - if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_RANGED; - attType = RANGED_ATTACK; - } - } - if(damage && (procVictim & (PROC_FLAG_STRUCK_MELEE|PROC_FLAG_STRUCK_RANGED|PROC_FLAG_STRUCK_SPELL))) - procVictim |= (PROC_FLAG_TAKE_DAMAGE|PROC_FLAG_TOUCH); - - // Not much to do if no flags are set. - if (procAttacker) - { - // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set - ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcEffectAuraTypes,attType, procSpell, damage, damageSchoolMask); - ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcCastAuraTypes,attType, procSpell, damage, damageSchoolMask); - } - - // Now go on with a victim's events'n'auras - // Not much to do if no flags are set or there is no victim - if(pVictim && pVictim->isAlive() && procVictim) - { - // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set - pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcEffectAuraTypes,attType,procSpell, damage, damageSchoolMask); - pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcCastAuraTypes,attType,procSpell, damage, damageSchoolMask); - } -} - -void Unit::CastMeleeProcDamageAndSpell(Unit* pVictim, uint32 damage, SpellSchoolMask damageSchoolMask, WeaponAttackType attType, MeleeHitOutcome outcome, SpellEntry const *spellCasted, bool isTriggeredSpell) -{ - if(!pVictim) - return; - - uint32 procAttacker = PROC_FLAG_NONE; - uint32 procVictim = PROC_FLAG_NONE; - - switch(outcome) - { - case MELEE_HIT_EVADE: - return; - case MELEE_HIT_MISS: - if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_MISS; - } - break; - case MELEE_HIT_BLOCK_CRIT: - case MELEE_HIT_CRIT: - if(spellCasted && attType == BASE_ATTACK) - { - procAttacker |= PROC_FLAG_CRIT_SPELL; - procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; - if ( outcome == MELEE_HIT_BLOCK_CRIT ) - { - procVictim |= PROC_FLAG_BLOCK; - procAttacker |= PROC_FLAG_TARGET_BLOCK; - } - } - else if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; - procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; - } - else - { - procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; - procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; - } - break; - case MELEE_HIT_PARRY: - procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; - procVictim = PROC_FLAG_PARRY; - break; - case MELEE_HIT_BLOCK: - procAttacker = PROC_FLAG_TARGET_BLOCK; - procVictim = PROC_FLAG_BLOCK; - break; - case MELEE_HIT_DODGE: - procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; - procVictim = PROC_FLAG_DODGE; - break; - case MELEE_HIT_CRUSHING: - if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; - procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; - } - else - { - procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; - procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; - } - break; - default: - if(attType == BASE_ATTACK || attType == OFF_ATTACK) - { - procAttacker = PROC_FLAG_HIT_MELEE; - procVictim = PROC_FLAG_STRUCK_MELEE; - } - else - { - procAttacker = PROC_FLAG_HIT_RANGED; - procVictim = PROC_FLAG_STRUCK_RANGED; - } - break; - } - - if(damage > 0) - procVictim |= PROC_FLAG_TAKE_DAMAGE; - - if(procAttacker != PROC_FLAG_NONE || procVictim != PROC_FLAG_NONE) - ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, damageSchoolMask, spellCasted, isTriggeredSpell, attType); -} - -bool Unit::HandleHasteAuraProc(Unit *pVictim, SpellEntry const *hasteSpell, uint32 /*effIndex*/, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 /*procFlag*/, uint32 cooldown) -{ - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = 0; - Unit* target = pVictim; - int32 basepoints0 = 0; - - switch(hasteSpell->SpellFamilyName) - { - case SPELLFAMILY_ROGUE: - { - switch(hasteSpell->Id) - { - // Blade Flurry - case 13877: - case 33735: - { - target = SelectNearbyTarget(); - if(!target) - return false; - basepoints0 = damage; - triggered_spell_id = 22482; - break; - } - } - break; - } - } - - // processed charge only counting case - if(!triggered_spell_id) - return true; - - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell->Id,triggered_spell_id); - return false; - } - - // default case - if(!target || target!=this && !target->isAlive()) - return false; - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - if(basepoints0) - CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - else - CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -bool Unit::HandleDummyAuraProc(Unit *pVictim, SpellEntry const *dummySpell, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) -{ - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = 0; - Unit* target = pVictim; - int32 basepoints0 = 0; - - switch(dummySpell->SpellFamilyName) - { - case SPELLFAMILY_GENERIC: - { - switch (dummySpell->Id) - { - // Eye of Eye - case 9799: - case 25988: - { - // prevent damage back from weapon special attacks - if (!procSpell || procSpell->DmgClass != SPELL_DAMAGE_CLASS_MAGIC ) - return false; - - // return damage % to attacker but < 50% own total health - basepoints0 = triggeredByAura->GetModifier()->m_amount*int32(damage)/100; - if(basepoints0 > GetMaxHealth()/2) - basepoints0 = GetMaxHealth()/2; - - triggered_spell_id = 25997; - break; - } - // Sweeping Strikes - case 12328: - case 18765: - case 35429: - { - // prevent chain of triggered spell from same triggered spell - if(procSpell && procSpell->Id==26654) - return false; - - target = SelectNearbyTarget(); - if(!target) - return false; - - triggered_spell_id = 26654; - break; - } - // Unstable Power - case 24658: - { - if (!procSpell || procSpell->Id == 24659) - return false; - // Need remove one 24659 aura - RemoveSingleAuraFromStack(24659, 0); - RemoveSingleAuraFromStack(24659, 1); - return true; - } - // Restless Strength - case 24661: - { - // Need remove one 24662 aura - RemoveSingleAuraFromStack(24662, 0); - return true; - } - // Adaptive Warding (Frostfire Regalia set) - case 28764: - { - if(!procSpell) - return false; - - // find Mage Armor - bool found = false; - AuraList const& mRegenInterupt = GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT); - for(AuraList::const_iterator iter = mRegenInterupt.begin(); iter != mRegenInterupt.end(); ++iter) - { - if(SpellEntry const* iterSpellProto = (*iter)->GetSpellProto()) - { - if(iterSpellProto->SpellFamilyName==SPELLFAMILY_MAGE && (iterSpellProto->SpellFamilyFlags & 0x10000000)) - { - found=true; - break; - } - } - } - if(!found) - return false; - - switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) - { - case SPELL_SCHOOL_NORMAL: - case SPELL_SCHOOL_HOLY: - return false; // ignored - case SPELL_SCHOOL_FIRE: triggered_spell_id = 28765; break; - case SPELL_SCHOOL_NATURE: triggered_spell_id = 28768; break; - case SPELL_SCHOOL_FROST: triggered_spell_id = 28766; break; - case SPELL_SCHOOL_SHADOW: triggered_spell_id = 28769; break; - case SPELL_SCHOOL_ARCANE: triggered_spell_id = 28770; break; - default: - return false; - } - - target = this; - break; - } - // Obsidian Armor (Justice Bearer`s Pauldrons shoulder) - case 27539: - { - if(!procSpell) - return false; - - // not from DoT - bool found = false; - for(int j = 0; j < 3; ++j) - { - if(procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE||procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT) - { - found = true; - break; - } - } - if(found) - return false; - - switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) - { - case SPELL_SCHOOL_NORMAL: - return false; // ignore - case SPELL_SCHOOL_HOLY: triggered_spell_id = 27536; break; - case SPELL_SCHOOL_FIRE: triggered_spell_id = 27533; break; - case SPELL_SCHOOL_NATURE: triggered_spell_id = 27538; break; - case SPELL_SCHOOL_FROST: triggered_spell_id = 27534; break; - case SPELL_SCHOOL_SHADOW: triggered_spell_id = 27535; break; - case SPELL_SCHOOL_ARCANE: triggered_spell_id = 27540; break; - default: - return false; - } - - target = this; - break; - } - // Mana Leech (Passive) (Priest Pet Aura) - case 28305: - { - // Cast on owner - target = GetOwner(); - if(!target) - return false; - - basepoints0 = int32(damage * 2.5f); // manaregen - triggered_spell_id = 34650; - break; - } - // Mark of Malice - case 33493: - { - // Cast finish spell at last charge - if (triggeredByAura->m_procCharges > 1) - return false; - - target = this; - triggered_spell_id = 33494; - break; - } - // Twisted Reflection (boss spell) - case 21063: - triggered_spell_id = 21064; - break; - // Vampiric Aura (boss spell) - case 38196: - { - basepoints0 = 3 * damage; // 300% - if (basepoints0 < 0) - return false; - - triggered_spell_id = 31285; - target = this; - break; - } - // Aura of Madness (Darkmoon Card: Madness trinket) - //===================================================== - // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior) - // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid) - // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid) - // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin) - // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes) - // 41005 Manic: +35 haste (spell, melee and ranged) (All classes) - // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter) - // 41011 Martyr Complex: +35 stamina (All classes) - // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) - // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) - case 39446: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Select class defined buff - switch (getClass()) - { - case CLASS_PALADIN: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 - case CLASS_DRUID: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 - { - uint32 RandomSpell[]={39511,40997,40998,40999,41002,41005,41009,41011,41409}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - case CLASS_ROGUE: // 39511,40997,40998,41002,41005,41011 - case CLASS_WARRIOR: // 39511,40997,40998,41002,41005,41011 - { - uint32 RandomSpell[]={39511,40997,40998,41002,41005,41011}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - case CLASS_PRIEST: // 40999,41002,41005,41009,41011,41406,41409 - case CLASS_SHAMAN: // 40999,41002,41005,41009,41011,41406,41409 - case CLASS_MAGE: // 40999,41002,41005,41009,41011,41406,41409 - case CLASS_WARLOCK: // 40999,41002,41005,41009,41011,41406,41409 - { - uint32 RandomSpell[]={40999,41002,41005,41009,41011,41406,41409}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - case CLASS_HUNTER: // 40997,40999,41002,41005,41009,41011,41406,41409 - { - uint32 RandomSpell[]={40997,40999,41002,41005,41009,41011,41406,41409}; - triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; - break; - } - default: - return false; - } - - target = this; - if (roll_chance_i(10)) - ((Player*)this)->Say("This is Madness!", LANG_UNIVERSAL); - break; - } - /* - // TODO: need find item for aura and triggered spells - // Sunwell Exalted Caster Neck (??? neck) - // cast ??? Light's Wrath if Exalted by Aldor - // cast ??? Arcane Bolt if Exalted by Scryers*/ - case 46569: - return false; // disable for while - /* - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = ??? - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = ??? - break; - } - return false; - }/**/ - // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck) - // cast 45479 Light's Wrath if Exalted by Aldor - // cast 45429 Arcane Bolt if Exalted by Scryers - case 45481: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45479; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = 45429; - break; - } - return false; - } - // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck) - // cast 45480 Light's Strength if Exalted by Aldor - // cast 45428 Arcane Strike if Exalted by Scryers - case 45482: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45480; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = 45428; - break; - } - return false; - } - // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck) - // cast 45431 Arcane Insight if Exalted by Aldor - // cast 45432 Light's Ward if Exalted by Scryers - case 45483: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45432; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45431; - break; - } - return false; - } - // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck) - // cast 45478 Light's Salvation if Exalted by Aldor - // cast 45430 Arcane Surge if Exalted by Scryers - case 45484: - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // Get Aldor reputation rank - if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) - { - target = this; - triggered_spell_id = 45478; - break; - } - // Get Scryers reputation rank - if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) - { - triggered_spell_id = 45430; - break; - } - return false; - } - } - break; - } - case SPELLFAMILY_MAGE: - { - // Magic Absorption - if (dummySpell->SpellIconID == 459) // only this spell have SpellIconID == 459 and dummy aura - { - if (getPowerType() != POWER_MANA) - return false; - - // mana reward - basepoints0 = (triggeredByAura->GetModifier()->m_amount * GetMaxPower(POWER_MANA) / 100); - target = this; - triggered_spell_id = 29442; - break; - } - // Master of Elements - if (dummySpell->SpellIconID == 1920) - { - if(!procSpell) - return false; - - // mana cost save - basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; - if( basepoints0 <=0 ) - return false; - - target = this; - triggered_spell_id = 29077; - break; - } - switch(dummySpell->Id) - { - // Ignite - case 11119: - case 11120: - case 12846: - case 12847: - case 12848: - { - switch (dummySpell->Id) - { - case 11119: basepoints0 = int32(0.04f*damage); break; - case 11120: basepoints0 = int32(0.08f*damage); break; - case 12846: basepoints0 = int32(0.12f*damage); break; - case 12847: basepoints0 = int32(0.16f*damage); break; - case 12848: basepoints0 = int32(0.20f*damage); break; - default: - sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell->Id); - return false; - } - - triggered_spell_id = 12654; - break; - } - // Combustion - case 11129: - { - //last charge and crit - if( triggeredByAura->m_procCharges <= 1 && (procFlag & PROC_FLAG_CRIT_SPELL) ) - { - RemoveAurasDueToSpell(28682); //-> remove Combustion auras - return true; // charge counting (will removed) - } - - CastSpell(this, 28682, true, castItem, triggeredByAura); - return(procFlag & PROC_FLAG_CRIT_SPELL);// charge update only at crit hits, no hidden cooldowns - } - } - break; - } - case SPELLFAMILY_WARRIOR: - { - // Retaliation - if(dummySpell->SpellFamilyFlags==0x0000000800000000LL) - { - // check attack comes not from behind - if (!HasInArc(M_PI, pVictim)) - return false; - - triggered_spell_id = 22858; - break; - } - break; - } - case SPELLFAMILY_WARLOCK: - { - // Seed of Corruption - if (dummySpell->SpellFamilyFlags & 0x0000001000000000LL) - { - Modifier* mod = triggeredByAura->GetModifier(); - // if damage is more than need or target die from damage deal finish spell - // FIX ME: not triggered currently at death - if( mod->m_amount <= damage || GetHealth() <= damage ) - { - // remember guid before aura delete - uint64 casterGuid = triggeredByAura->GetCasterGUID(); - - // Remove aura (before cast for prevent infinite loop handlers) - RemoveAurasDueToSpell(triggeredByAura->GetId()); - - // Cast finish spell (triggeredByAura already not exist!) - if(Unit* caster = GetUnit(*this, casterGuid)) - caster->CastSpell(this, 27285, true, castItem); - return true; // no hidden cooldown - } - - // Damage counting - mod->m_amount-=damage; - return true; - } - // Seed of Corruption (Mobs cast) - no die req - if (dummySpell->SpellFamilyFlags == 0x00LL && dummySpell->SpellIconID == 1932) - { - Modifier* mod = triggeredByAura->GetModifier(); - // if damage is more than need deal finish spell - if( mod->m_amount <= damage ) - { - // remember guid before aura delete - uint64 casterGuid = triggeredByAura->GetCasterGUID(); - - // Remove aura (before cast for prevent infinite loop handlers) - RemoveAurasDueToSpell(triggeredByAura->GetId()); - - // Cast finish spell (triggeredByAura already not exist!) - if(Unit* caster = GetUnit(*this, casterGuid)) - caster->CastSpell(this, 32865, true, castItem); - return true; // no hidden cooldown - } - // Damage counting - mod->m_amount-=damage; - return true; - } - switch(dummySpell->Id) - { - // Nightfall - case 18094: - case 18095: - { - target = this; - triggered_spell_id = 17941; - break; - } - //Soul Leech - case 30293: - case 30295: - case 30296: - { - // health - basepoints0 = int32(damage*triggeredByAura->GetModifier()->m_amount/100); - target = this; - triggered_spell_id = 30294; - break; - } - // Shadowflame (Voidheart Raiment set bonus) - case 37377: - { - triggered_spell_id = 37379; - break; - } - // Pet Healing (Corruptor Raiment or Rift Stalker Armor) - case 37381: - { - target = GetPet(); - if(!target) - return false; - - // heal amount - basepoints0 = damage * triggeredByAura->GetModifier()->m_amount/100; - triggered_spell_id = 37382; - break; - } - // Shadowflame Hellfire (Voidheart Raiment set bonus) - case 39437: - { - triggered_spell_id = 37378; - break; - } - } - break; - } - case SPELLFAMILY_PRIEST: - { - // Vampiric Touch - if( dummySpell->SpellFamilyFlags & 0x0000040000000000LL ) - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // pVictim is caster of aura - if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) - return false; - - // energize amount - basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; - pVictim->CastCustomSpell(pVictim,34919,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - return true; // no hidden cooldown - } - switch(dummySpell->Id) - { - // Vampiric Embrace - case 15286: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // pVictim is caster of aura - if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) - return false; - - // heal amount - basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; - pVictim->CastCustomSpell(pVictim,15290,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - return true; // no hidden cooldown - } - // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen) - case 40438: - { - // Shadow Word: Pain - if( procSpell->SpellFamilyFlags & 0x0000000000008000LL ) - triggered_spell_id = 40441; - // Renew - else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) - triggered_spell_id = 40440; - else - return false; - - target = this; - break; - } - // Oracle Healing Bonus ("Garments of the Oracle" set) - case 26169: - { - // heal amount - basepoints0 = int32(damage * 10/100); - target = this; - triggered_spell_id = 26170; - break; - } - // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set - case 39372: - { - if(!procSpell || (GetSpellSchoolMask(procSpell) & (SPELL_SCHOOL_MASK_FROST | SPELL_SCHOOL_MASK_SHADOW))==0 ) - return false; - - // heal amount - basepoints0 = int32(damage * 2 / 100); - target = this; - triggered_spell_id = 39373; - break; - } - // Vestments of Faith (Priest Tier 3) - 4 pieces bonus - case 28809: - { - triggered_spell_id = 28810; - break; - } - } - break; - } - case SPELLFAMILY_DRUID: - { - switch(dummySpell->Id) - { - // Healing Touch (Dreamwalker Raiment set) - case 28719: - { - // mana back - basepoints0 = int32(procSpell->manaCost * 30 / 100); - target = this; - triggered_spell_id = 28742; - break; - } - // Healing Touch Refund (Idol of Longevity trinket) - case 28847: - { - target = this; - triggered_spell_id = 28848; - break; - } - // Mana Restore (Malorne Raiment set / Malorne Regalia set) - case 37288: - case 37295: - { - target = this; - triggered_spell_id = 37238; - break; - } - // Druid Tier 6 Trinket - case 40442: - { - float chance; - - // Starfire - if( procSpell->SpellFamilyFlags & 0x0000000000000004LL ) - { - triggered_spell_id = 40445; - chance = 25.f; - } - // Rejuvenation - else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) - { - triggered_spell_id = 40446; - chance = 25.f; - } - // Mangle (cat/bear) - else if( procSpell->SpellFamilyFlags & 0x0000044000000000LL ) - { - triggered_spell_id = 40452; - chance = 40.f; - } - else - return false; - - if (!roll_chance_f(chance)) - return false; - - target = this; - break; - } - // Maim Interrupt - case 44835: - { - // Deadly Interrupt Effect - triggered_spell_id = 32747; - break; - } - } - break; - } - case SPELLFAMILY_ROGUE: - { - switch(dummySpell->Id) - { - // Deadly Throw Interrupt - case 32748: - { - // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw - if(this == pVictim) - return false; - - triggered_spell_id = 32747; - break; - } - } - // Quick Recovery - if( dummySpell->SpellIconID == 2116 ) - { - if(!procSpell) - return false; - - // only rogue's finishing moves (maybe need additional checks) - if( procSpell->SpellFamilyName!=SPELLFAMILY_ROGUE || - (procSpell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE) == 0) - return false; - - // energy cost save - basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; - if(basepoints0 <= 0) - return false; - - target = this; - triggered_spell_id = 31663; - break; - } - break; - } - case SPELLFAMILY_HUNTER: - { - // Thrill of the Hunt - if ( dummySpell->SpellIconID == 2236 ) - { - if(!procSpell) - return false; - - // mana cost save - basepoints0 = procSpell->manaCost * 40/100; - if(basepoints0 <= 0) - return false; - - target = this; - triggered_spell_id = 34720; - break; - } - break; - } - case SPELLFAMILY_PALADIN: - { - // Seal of Righteousness - melee proc dummy - if (dummySpell->SpellFamilyFlags&0x000000008000000LL && triggeredByAura->GetEffIndex()==0) - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - uint32 spellId; - switch (triggeredByAura->GetId()) - { - case 21084: spellId = 25742; break; // Rank 1 - case 20287: spellId = 25740; break; // Rank 2 - case 20288: spellId = 25739; break; // Rank 3 - case 20289: spellId = 25738; break; // Rank 4 - case 20290: spellId = 25737; break; // Rank 5 - case 20291: spellId = 25736; break; // Rank 6 - case 20292: spellId = 25735; break; // Rank 7 - case 20293: spellId = 25713; break; // Rank 8 - case 27155: spellId = 27156; break; // Rank 9 - default: - sLog.outError("Unit::HandleDummyAuraProc: non handled possibly SoR (Id = %u)", triggeredByAura->GetId()); - return false; - } - Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - float speed = (item ? item->GetProto()->Delay : BASE_ATTACK_TIME)/1000.0f; - - float damageBasePoints; - if(item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) - // two hand weapon - damageBasePoints=1.20f*triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f + 1; - else - // one hand weapon/no weapon - damageBasePoints=0.85f*ceil(triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f) - 1; - - int32 damagePoint = int32(damageBasePoints + 0.03f * (GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE)+GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE))/2.0f) + 1; - - // apply damage bonuses manually - if(damagePoint >= 0) - damagePoint = SpellDamageBonus(pVictim, dummySpell, damagePoint, SPELL_DIRECT_DAMAGE); - - CastCustomSpell(pVictim,spellId,&damagePoint,NULL,NULL,true,NULL, triggeredByAura); - return true; // no hidden cooldown - } - // Seal of Blood do damage trigger - if(dummySpell->SpellFamilyFlags & 0x0000040000000000LL) - { - switch(triggeredByAura->GetEffIndex()) - { - case 0: - // prevent chain triggering - if(procSpell && procSpell->Id==31893 ) - return false; - - triggered_spell_id = 31893; - break; - case 1: - { - // damage - basepoints0 = triggeredByAura->GetModifier()->m_amount * damage / 100; - target = this; - triggered_spell_id = 32221; - break; - } - } - } - - switch(dummySpell->Id) - { - // Holy Power (Redemption Armor set) - case 28789: - { - if(!pVictim) - return false; - - // Set class defined buff - switch (pVictim->getClass()) - { - case CLASS_PALADIN: - case CLASS_PRIEST: - case CLASS_SHAMAN: - case CLASS_DRUID: - triggered_spell_id = 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. - break; - case CLASS_MAGE: - case CLASS_WARLOCK: - triggered_spell_id = 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d. - break; - case CLASS_HUNTER: - case CLASS_ROGUE: - triggered_spell_id = 28791; // Increases the friendly target's attack power by $s1 for $d. - break; - case CLASS_WARRIOR: - triggered_spell_id = 28790; // Increases the friendly target's armor - break; - default: - return false; - } - break; - } - //Seal of Vengeance - case 31801: - { - if(effIndex != 0) // effect 1,2 used by seal unleashing code - return false; - - triggered_spell_id = 31803; - break; - } - // Spiritual Att. - case 31785: - case 33776: - { - // if healed by another unit (pVictim) - if(this == pVictim) - return false; - - // heal amount - basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; - target = this; - triggered_spell_id = 31786; - break; - } - // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal) - case 40470: - { - if( !procSpell ) - return false; - - float chance; - - // Flash of light/Holy light - if( procSpell->SpellFamilyFlags & 0x00000000C0000000LL) - { - triggered_spell_id = 40471; - chance = 15.f; - } - // Judgement - else if( procSpell->SpellFamilyFlags & 0x0000000000800000LL ) - { - triggered_spell_id = 40472; - chance = 50.f; - } - else - return false; - - if (!roll_chance_f(chance)) - return false; - - break; - } - } - break; - } - case SPELLFAMILY_SHAMAN: - { - switch(dummySpell->Id) - { - // Totemic Power (The Earthshatterer set) - case 28823: - { - if( !pVictim ) - return false; - - // Set class defined buff - switch (pVictim->getClass()) - { - case CLASS_PALADIN: - case CLASS_PRIEST: - case CLASS_SHAMAN: - case CLASS_DRUID: - triggered_spell_id = 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. - break; - case CLASS_MAGE: - case CLASS_WARLOCK: - triggered_spell_id = 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d. - break; - case CLASS_HUNTER: - case CLASS_ROGUE: - triggered_spell_id = 28826; // Increases the friendly target's attack power by $s1 for $d. - break; - case CLASS_WARRIOR: - triggered_spell_id = 28827; // Increases the friendly target's armor - break; - default: - return false; - } - break; - } - // Lesser Healing Wave (Totem of Flowing Water Relic) - case 28849: - { - target = this; - triggered_spell_id = 28850; - break; - } - // Windfury Weapon (Passive) 1-5 Ranks - case 33757: - { - if(GetTypeId()!=TYPEID_PLAYER) - return false; - - if(!castItem || !castItem->IsEquipped()) - return false; - - // custom cooldown processing case - if( cooldown && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) - return false; - - uint32 spellId; - switch (castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT))) - { - case 283: spellId = 33757; break; //1 Rank - case 284: spellId = 33756; break; //2 Rank - case 525: spellId = 33755; break; //3 Rank - case 1669:spellId = 33754; break; //4 Rank - case 2636:spellId = 33727; break; //5 Rank - default: - { - sLog.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)", - castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT)),dummySpell->Id); - return false; - } - } - - SpellEntry const* windfurySpellEntry = sSpellStore.LookupEntry(spellId); - if(!windfurySpellEntry) - { - sLog.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId); - return false; - } - - int32 extra_attack_power = CalculateSpellDamage(windfurySpellEntry,0,windfurySpellEntry->EffectBasePoints[0],pVictim); - - // Off-Hand case - if ( castItem->GetSlot() == EQUIPMENT_SLOT_OFFHAND ) - { - // Value gained from additional AP - basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(OFF_ATTACK)/1000/2); - triggered_spell_id = 33750; - } - // Main-Hand case - else - { - // Value gained from additional AP - basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(BASE_ATTACK)/1000); - triggered_spell_id = 25504; - } - - // apply cooldown before cast to prevent processing itself - if( cooldown ) - ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); - - // Attack Twice - for ( uint32 i = 0; i<2; ++i ) - CastCustomSpell(pVictim,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - - return true; - } - // Shaman Tier 6 Trinket - case 40463: - { - if( !procSpell ) - return false; - - float chance; - if (procSpell->SpellFamilyFlags & 0x0000000000000001LL) - { - triggered_spell_id = 40465; // Lightning Bolt - chance = 15.f; - } - else if (procSpell->SpellFamilyFlags & 0x0000000000000080LL) - { - triggered_spell_id = 40465; // Lesser Healing Wave - chance = 10.f; - } - else if (procSpell->SpellFamilyFlags & 0x0000001000000000LL) - { - triggered_spell_id = 40466; // Stormstrike - chance = 50.f; - } - else - return false; - - if (!roll_chance_f(chance)) - return false; - - target = this; - break; - } - } - - // Earth Shield - if(dummySpell->SpellFamilyFlags==0x40000000000LL) - { - if(GetTypeId() != TYPEID_PLAYER) - return false; - - // heal - basepoints0 = triggeredByAura->GetModifier()->m_amount; - target = this; - triggered_spell_id = 379; - break; - } - // Lightning Overload - if (dummySpell->SpellIconID == 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura - { - if(!procSpell || GetTypeId() != TYPEID_PLAYER || !pVictim ) - return false; - - // custom cooldown processing case - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) - return false; - - uint32 spellId = 0; - // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost - switch (procSpell->Id) - { - // Lightning Bolt - case 403: spellId = 45284; break; // Rank 1 - case 529: spellId = 45286; break; // Rank 2 - case 548: spellId = 45287; break; // Rank 3 - case 915: spellId = 45288; break; // Rank 4 - case 943: spellId = 45289; break; // Rank 5 - case 6041: spellId = 45290; break; // Rank 6 - case 10391: spellId = 45291; break; // Rank 7 - case 10392: spellId = 45292; break; // Rank 8 - case 15207: spellId = 45293; break; // Rank 9 - case 15208: spellId = 45294; break; // Rank 10 - case 25448: spellId = 45295; break; // Rank 11 - case 25449: spellId = 45296; break; // Rank 12 - // Chain Lightning - case 421: spellId = 45297; break; // Rank 1 - case 930: spellId = 45298; break; // Rank 2 - case 2860: spellId = 45299; break; // Rank 3 - case 10605: spellId = 45300; break; // Rank 4 - case 25439: spellId = 45301; break; // Rank 5 - case 25442: spellId = 45302; break; // Rank 6 - default: - sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell->Id); - return false; - } - // No thread generated mod - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_THREAT; - mod->value = -100; - mod->type = SPELLMOD_PCT; - mod->spellId = dummySpell->Id; - mod->effectId = 0; - mod->lastAffected = NULL; - mod->mask = 0x0000000000000003LL; - mod->charges = 0; - ((Player*)this)->AddSpellMod(mod, true); - - // Remove cooldown (Chain Lightning - have Category Recovery time) - if (procSpell->SpellFamilyFlags & 0x0000000000000002LL) - ((Player*)this)->RemoveSpellCooldown(spellId); - - // Hmmm.. in most case spells already set half basepoints but... - // Lightning Bolt (2-10 rank) have full basepoint and half bonus from level - // As on wiki: - // BUG: Rank 2 to 10 (and maybe 11) of Lightning Bolt will proc another Bolt with FULL damage (not halved). This bug is known and will probably be fixed soon. - // So - no add changes :) - CastSpell(pVictim, spellId, true, castItem, triggeredByAura); - - ((Player*)this)->AddSpellMod(mod, false); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); - - return true; - } - break; - } - default: - break; - } - - // processed charge only counting case - if(!triggered_spell_id) - return true; - - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell->Id,triggered_spell_id); - return false; - } - - // default case - if(!target || target!=this && !target->isAlive()) - return false; - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - if(basepoints0) - CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - else - CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const *procSpell, uint32 procFlags,WeaponAttackType attackType, uint32 cooldown) -{ - SpellEntry const* auraSpellInfo = triggeredByAura->GetSpellProto(); - - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = auraSpellInfo->EffectTriggerSpell[triggeredByAura->GetEffIndex()]; - Unit* target = !(procFlags & PROC_FLAG_HEAL) && IsPositiveSpell(triggered_spell_id) ? this : pVictim; - int32 basepoints0 = 0; - - switch(auraSpellInfo->SpellFamilyName) - { - case SPELLFAMILY_GENERIC: - { - switch(auraSpellInfo->Id) - { - // Aegis of Preservation - case 23780: - //Aegis Heal (instead non-existed triggered spell) - triggered_spell_id = 23781; - target = this; - break; - // Elune's Touch (moonkin mana restore) - case 24905: - { - // Elune's Touch (instead non-existed triggered spell) - triggered_spell_id = 33926; - basepoints0 = int32(0.3f * GetTotalAttackPowerValue(BASE_ATTACK)); - target = this; - break; - } - // Enlightenment - case 29601: - { - // only for cast with mana price - if(!procSpell || procSpell->powerType!=POWER_MANA || procSpell->manaCost==0 && procSpell->ManaCostPercentage==0 && procSpell->manaCostPerlevel==0) - return false; - break; // fall through to normal cast - } - // Health Restore - case 33510: - { - // at melee hit call std triggered spell - if(procFlags & PROC_FLAG_HIT_MELEE) - break; // fall through to normal cast - - // Mark of Conquest - else (at range hit) called custom case - triggered_spell_id = 39557; - target = this; - break; - } - // Shaleskin - case 36576: - return true; // nothing to do - // Forgotten Knowledge (Blade of Wizardry) - case 38319: - // only for harmful enemy targeted spell - if(!pVictim || pVictim==this || !procSpell || IsPositiveSpell(procSpell->Id)) - return false; - break; // fall through to normal cast - // Aura of Wrath (Darkmoon Card: Wrath trinket bonus) - case 39442: - { - // proc only at non-crit hits - if(procFlags & (PROC_FLAG_CRIT_MELEE|PROC_FLAG_CRIT_RANGED|PROC_FLAG_CRIT_SPELL)) - return false; - break; // fall through to normal cast - } - // Augment Pain (Timbal's Focusing Crystal trinket bonus) - case 45054: - { - if(!procSpell) - return false; - - //only periodic damage can trigger spell - bool found = false; - for(int j = 0; j < 3; ++j) - { - if( procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE || - procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT || - procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_LEECH ) - { - found = true; - break; - } - } - if(!found) - return false; - - break; // fall through to normal cast - } - // Evasive Maneuvers (Commendation of Kael'thas) - case 45057: - { - // damage taken that reduces below 35% health - // does NOT mean you must have been >= 35% before - if (int32(GetHealth())-int32(damage) >= int32(GetMaxHealth()*0.35f)) - return false; - break; // fall through to normal cast - } - } - - switch(triggered_spell_id) - { - // Setup - case 15250: - { - // applied only for main target - if(!pVictim || pVictim != getVictim()) - return false; - - // continue normal case - break; - } - // Shamanistic Rage triggered spell - case 30824: - basepoints0 = int32(GetTotalAttackPowerValue(BASE_ATTACK)*triggeredByAura->GetModifier()->m_amount/100); - break; - } - break; - } - case SPELLFAMILY_MAGE: - { - switch(auraSpellInfo->SpellIconID) - { - // Blazing Speed - case 2127: - //Blazing Speed (instead non-existed triggered spell) - triggered_spell_id = 31643; - target = this; - break; - } - switch(auraSpellInfo->Id) - { - // Persistent Shield (Scarab Brooch) - case 26467: - basepoints0 = int32(damage * 0.15f); - break; - } - break; - } - case SPELLFAMILY_WARRIOR: - { - //Rampage - if((auraSpellInfo->SpellFamilyFlags & 0x100000) && auraSpellInfo->SpellIconID==2006) - { - //all ranks have effect[0]==AURA (Proc Trigger Spell, non-existed) - //and effect[1]==TriggerSpell - if(auraSpellInfo->Effect[1]!=SPELL_EFFECT_TRIGGER_SPELL) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have wrong effect in RM",triggeredByAura->GetSpellProto()->Id); - return false; - } - triggered_spell_id = auraSpellInfo->EffectTriggerSpell[1]; - break; // fall through to normal cast - } - break; - } - case SPELLFAMILY_WARLOCK: - { - // Pyroclasm - if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000 && auraSpellInfo->SpellIconID==1137) - { - // last case for Hellfire that damage caster also but don't must stun caster - if( pVictim == this ) - return false; - - // custom chance - float chance = 0; - switch (triggeredByAura->GetId()) - { - case 18096: chance = 13.0f; break; - case 18073: chance = 26.0f; break; - } - if (!roll_chance_f(chance)) - return false; - - // Pyroclasm (instead non-existed triggered spell) - triggered_spell_id = 18093; - target = pVictim; - break; - } - // Drain Soul - if(auraSpellInfo->SpellFamilyFlags & 0x0000000000004000) - { - bool found = false; - Unit::AuraList const& mAddFlatModifier = GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER); - for(Unit::AuraList::const_iterator i = mAddFlatModifier.begin(); i != mAddFlatModifier.end(); ++i) - { - //Improved Drain Soul - if ((*i)->GetModifier()->m_miscvalue == SPELLMOD_CHANCE_OF_SUCCESS && (*i)->GetSpellProto()->SpellIconID == 113) - { - int32 value2 = CalculateSpellDamage((*i)->GetSpellProto(),2,(*i)->GetSpellProto()->EffectBasePoints[2],this); - basepoints0 = value2 * GetMaxPower(POWER_MANA) / 100; - - // Drain Soul - triggered_spell_id = 18371; - target = this; - found = true; - break; - } - } - if(!found) - return false; - break; // fall through to normal cast - } - break; - } - case SPELLFAMILY_PRIEST: - { - //Blessed Recovery - if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL && auraSpellInfo->SpellIconID==1875) - { - switch (triggeredByAura->GetSpellProto()->Id) - { - case 27811: triggered_spell_id = 27813; break; - case 27815: triggered_spell_id = 27817; break; - case 27816: triggered_spell_id = 27818; break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR",triggeredByAura->GetSpellProto()->Id); - return false; - } - - int32 heal_amount = damage * triggeredByAura->GetModifier()->m_amount / 100; - basepoints0 = heal_amount/3; - target = this; - break; - } - // Shadowguard - if((auraSpellInfo->SpellFamilyFlags & 0x80000000LL) && auraSpellInfo->SpellVisual==7958) - { - switch(triggeredByAura->GetSpellProto()->Id) - { - case 18137: - triggered_spell_id = 28377; break; // Rank 1 - case 19308: - triggered_spell_id = 28378; break; // Rank 2 - case 19309: - triggered_spell_id = 28379; break; // Rank 3 - case 19310: - triggered_spell_id = 28380; break; // Rank 4 - case 19311: - triggered_spell_id = 28381; break; // Rank 5 - case 19312: - triggered_spell_id = 28382; break; // Rank 6 - case 25477: - triggered_spell_id = 28385; break; // Rank 7 - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in SG",triggeredByAura->GetSpellProto()->Id); - return false; - } - target = pVictim; - break; - } - break; - } - case SPELLFAMILY_DRUID: - { - switch(auraSpellInfo->Id) - { - // Leader of the Pack (triggering Improved Leader of the Pack heal) - case 24932: - { - if (triggeredByAura->GetModifier()->m_amount == 0) - return false; - basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; - triggered_spell_id = 34299; - break; - }; - // Druid Forms Trinket (Druid Tier5 Trinket, triggers different spells per Form) - case 37336: - { - switch(m_form) - { - case FORM_BEAR: - case FORM_DIREBEAR: - triggered_spell_id=37340; break;// Ursine Blessing - case FORM_CAT: - triggered_spell_id=37341; break;// Feline Blessing - case FORM_TREE: - triggered_spell_id=37342; break;// Slyvan Blessing - case FORM_MOONKIN: - triggered_spell_id=37343; break;// Lunar Blessing - case FORM_NONE: - triggered_spell_id=37344; break;// Cenarion Blessing (for caster form, except FORM_MOONKIN) - default: - return false; - } - - target = this; - break; - } - } - break; - } - case SPELLFAMILY_ROGUE: - { - if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000LL) - { - switch(auraSpellInfo->SpellIconID) - { - // Combat Potency - case 2260: - { - // skip non offhand attacks - if(attackType!=OFF_ATTACK) - return false; - break; // fall through to normal cast - } - } - } - break; - } - case SPELLFAMILY_PALADIN: - { - if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL) - { - switch(auraSpellInfo->Id) - { - // Lightning Capacitor - case 37657: - { - // trinket ProcTriggerSpell but for safe checks for player - if(!castItem || !pVictim || !pVictim->isAlive() || GetTypeId()!=TYPEID_PLAYER) - return false; - - if(((Player*)this)->HasSpellCooldown(37657)) - return false; - - // stacking - CastSpell(this, 37658, true, castItem, triggeredByAura); - // 2.5s cooldown before it can stack again, current system allow 1 sec step in cooldown - ((Player*)this)->AddSpellCooldown(37657,0,time(NULL)+(roll_chance_i(50) ? 2 : 3)); - - // counting - uint32 count = 0; - AuraList const& dummyAura = GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator itr = dummyAura.begin(); itr != dummyAura.end(); ++itr) - if((*itr)->GetId()==37658) - ++count; - - // release at 3 aura in stack - if(count <= 2) - return true; // main triggered spell casted anyway - - RemoveAurasDueToSpell(37658); - CastSpell(pVictim, 37661, true, castItem, triggeredByAura); - return true; - } - // Healing Discount - case 37705: - // Healing Trance (instead non-existed triggered spell) - triggered_spell_id = 37706; - target = this; - break; - // HoTs on Heals (Fel Reaver's Piston trinket) - case 38299: - { - // at direct heal effect - if(!procSpell || !IsSpellHaveEffect(procSpell,SPELL_EFFECT_HEAL)) - return false; - - // single proc at time - AuraList const& scAuras = GetSingleCastAuras(); - for(AuraList::const_iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) - if((*itr)->GetId()==triggered_spell_id) - return false; - - // positive cast at victim instead self - target = pVictim; - break; - } - } - switch(auraSpellInfo->SpellIconID) - { - case 241: - { - switch(auraSpellInfo->EffectTriggerSpell[0]) - { - //Illumination - case 18350: - { - if(!procSpell) - return false; - - // procspell is triggered spell but we need mana cost of original casted spell - uint32 originalSpellId = procSpell->Id; - - // Holy Shock - if(procSpell->SpellFamilyName == SPELLFAMILY_PALADIN) - { - if(procSpell->SpellFamilyFlags & 0x0001000000000000LL) - { - switch(procSpell->Id) - { - case 25914: originalSpellId = 20473; break; - case 25913: originalSpellId = 20929; break; - case 25903: originalSpellId = 20930; break; - case 27175: originalSpellId = 27174; break; - case 33074: originalSpellId = 33072; break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell->Id); - return false; - } - } - } - - SpellEntry const *originalSpell = sSpellStore.LookupEntry(originalSpellId); - if(!originalSpell) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId); - return false; - } - - // percent stored in effect 1 (class scripts) base points - int32 percent = auraSpellInfo->EffectBasePoints[1]+1; - - basepoints0 = originalSpell->manaCost*percent/100; - triggered_spell_id = 20272; - target = this; - break; - } - } - break; - } - } - } - if(auraSpellInfo->SpellFamilyFlags & 0x00080000) - { - switch(auraSpellInfo->SpellIconID) - { - //Judgement of Wisdom (overwrite non existing triggered spell call in spell.dbc - case 206: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - uint32 spell = 0; - switch(triggeredByAura->GetSpellProto()->Id) - { - case 20186: - triggered_spell_id = 20268; // Rank 1 - break; - case 20354: - triggered_spell_id = 20352; // Rank 2 - break; - case 20355: - triggered_spell_id = 20353; // Rank 3 - break; - case 27164: - triggered_spell_id = 27165; // Rank 4 - break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoW",triggeredByAura->GetSpellProto()->Id); - return false; - } - - pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); - return true; // no hidden cooldown - } - //Judgement of Light - case 299: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // overwrite non existing triggered spell call in spell.dbc - uint32 spell = 0; - switch(triggeredByAura->GetSpellProto()->Id) - { - case 20185: - triggered_spell_id = 20267; // Rank 1 - break; - case 20344: - triggered_spell_id = 20341; // Rank 2 - break; - case 20345: - triggered_spell_id = 20342; // Rank 3 - break; - case 20346: - triggered_spell_id = 20343; // Rank 4 - break; - case 27162: - triggered_spell_id = 27163; // Rank 5 - break; - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoL",triggeredByAura->GetSpellProto()->Id); - return false; - } - pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); - return true; // no hidden cooldown - } - } - } - // custom check for proc spell - switch(auraSpellInfo->Id) - { - // Bonus Healing (item spell) - case 40971: - { - if(!pVictim || !pVictim->isAlive()) - return false; - - // bonus if health < 50% - if(pVictim->GetHealth() >= pVictim->GetMaxHealth()*triggeredByAura->GetModifier()->m_amount/100) - return false; - - // cast at target positive spell - target = pVictim; - break; - } - } - switch(triggered_spell_id) - { - // Seal of Command - case 20424: - // prevent chain of triggered spell from same triggered spell - if(procSpell && procSpell->Id==20424) - return false; - break; - } - break; - } - case SPELLFAMILY_SHAMAN: - { - if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000) - { - switch(auraSpellInfo->SpellIconID) - { - case 19: - { - switch(auraSpellInfo->Id) - { - case 23551: // Lightning Shield - Tier2: 8 pieces proc shield - { - // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) - triggered_spell_id = 23552; - target = pVictim; - break; - } - case 23552: // Lightning Shield - trigger shield damage - { - // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) - triggered_spell_id = 27635; - target = pVictim; - break; - } - } - break; - } - // Mana Surge (Shaman T1 bonus) - case 87: - { - if(!procSpell) - return false; - - basepoints0 = procSpell->manaCost * 35/100; - triggered_spell_id = 23571; - target = this; - break; - } - //Nature's Guardian - case 2013: - { - if(GetTypeId()!=TYPEID_PLAYER) - return false; - - // damage taken that reduces below 30% health - // does NOT mean you must have been >= 30% before - if (10*(int32(GetHealth())-int32(damage)) >= 3*GetMaxHealth()) - return false; - - triggered_spell_id = 31616; - - // need check cooldown now - if( cooldown && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; - target = this; - if(pVictim && pVictim->isAlive()) - pVictim->getThreatManager().modifyThreatPercent(this,-10); - break; - } - } - } - - // Water Shield (we can't set cooldown for main spell - it's player casted spell - if((auraSpellInfo->SpellFamilyFlags & 0x0000002000000000LL) && auraSpellInfo->SpellVisual==7358) - { - target = this; - break; - } - - // Lightning Shield - if((auraSpellInfo->SpellFamilyFlags & 0x00000400) && auraSpellInfo->SpellVisual==37) - { - // overwrite non existing triggered spell call in spell.dbc - switch(triggeredByAura->GetSpellProto()->Id) - { - case 324: - triggered_spell_id = 26364; break; // Rank 1 - case 325: - triggered_spell_id = 26365; break; // Rank 2 - case 905: - triggered_spell_id = 26366; break; // Rank 3 - case 945: - triggered_spell_id = 26367; break; // Rank 4 - case 8134: - triggered_spell_id = 26369; break; // Rank 5 - case 10431: - triggered_spell_id = 26370; break; // Rank 6 - case 10432: - triggered_spell_id = 26363; break; // Rank 7 - case 25469: - triggered_spell_id = 26371; break; // Rank 8 - case 25472: - triggered_spell_id = 26372; break; // Rank 9 - default: - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield",triggeredByAura->GetSpellProto()->Id); - return false; - } - - target = pVictim; - break; - } - break; - } - } - - // standard non-dummy case - if(!triggered_spell_id) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex()); - return false; - } - - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have not existed EffectTriggered[%d]=%u, not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex(),triggered_spell_id); - return false; - } - - // not allow proc extra attack spell at extra attack - if( m_extraAttacks && IsSpellHaveEffect(triggerEntry,SPELL_EFFECT_ADD_EXTRA_ATTACKS) ) - return false; - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - // default case - if(!target || target!=this && !target->isAlive()) - return false; - - if(basepoints0) - CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); - else - CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) -{ - if(!pVictim || !pVictim->isAlive()) - return false; - - Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER - ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; - - uint32 triggered_spell_id = 0; - - switch(scriptId) - { - case 836: // Improved Blizzard (Rank 1) - { - if (!procSpell || procSpell->SpellVisual!=9487) - return false; - triggered_spell_id = 12484; - break; - } - case 988: // Improved Blizzard (Rank 2) - { - if (!procSpell || procSpell->SpellVisual!=9487) - return false; - triggered_spell_id = 12485; - break; - } - case 989: // Improved Blizzard (Rank 3) - { - if (!procSpell || procSpell->SpellVisual!=9487) - return false; - triggered_spell_id = 12486; - break; - } - case 4086: // Improved Mend Pet (Rank 1) - case 4087: // Improved Mend Pet (Rank 2) - { - int32 chance = triggeredByAura->GetSpellProto()->EffectBasePoints[triggeredByAura->GetEffIndex()]; - if(!roll_chance_i(chance)) - return false; - - triggered_spell_id = 24406; - break; - } - case 4533: // Dreamwalker Raiment 2 pieces bonus - { - // Chance 50% - if (!roll_chance_i(50)) - return false; - - switch (pVictim->getPowerType()) - { - case POWER_MANA: triggered_spell_id = 28722; break; - case POWER_RAGE: triggered_spell_id = 28723; break; - case POWER_ENERGY: triggered_spell_id = 28724; break; - default: - return false; - } - break; - } - case 4537: // Dreamwalker Raiment 6 pieces bonus - triggered_spell_id = 28750; // Blessing of the Claw - break; - case 5497: // Improved Mana Gems (Serpent-Coil Braid) - triggered_spell_id = 37445; // Mana Surge - break; - } - - // not processed - if(!triggered_spell_id) - return false; - - // standard non-dummy case - SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); - - if(!triggerEntry) - { - sLog.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id,scriptId); - return false; - } - - if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) - return false; - - CastSpell(pVictim, triggered_spell_id, true, castItem, triggeredByAura); - - if( cooldown && GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); - - return true; -} - -void Unit::setPowerType(Powers new_powertype) -{ - SetByteValue(UNIT_FIELD_BYTES_0, 3, new_powertype); - - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE); - } - } - - switch(new_powertype) - { - default: - case POWER_MANA: - break; - case POWER_RAGE: - SetMaxPower(POWER_RAGE,GetCreatePowers(POWER_RAGE)); - SetPower( POWER_RAGE,0); - break; - case POWER_FOCUS: - SetMaxPower(POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); - SetPower( POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); - break; - case POWER_ENERGY: - SetMaxPower(POWER_ENERGY,GetCreatePowers(POWER_ENERGY)); - SetPower( POWER_ENERGY,0); - break; - case POWER_HAPPINESS: - SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - SetPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); - break; - } -} - -FactionTemplateEntry const* Unit::getFactionTemplateEntry() const -{ - FactionTemplateEntry const* entry = sFactionTemplateStore.LookupEntry(getFaction()); - if(!entry) - { - static uint64 guid = 0; // prevent repeating spam same faction problem - - if(GetGUID() != guid) - { - if(GetTypeId() == TYPEID_PLAYER) - sLog.outError("Player %s have invalid faction (faction template id) #%u", ((Player*)this)->GetName(), getFaction()); - else - sLog.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature*)this)->GetCreatureInfo()->Entry, getFaction()); - guid = GetGUID(); - } - } - return entry; -} - -bool Unit::IsHostileTo(Unit const* unit) const -{ - // always non-hostile to self - if(unit==this) - return false; - - // always non-hostile to GM in GM mode - if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) - return false; - - // always hostile to enemy - if(getVictim()==unit || unit->getVictim()==this) - return true; - - // test pet/charm masters instead pers/charmeds - Unit const* testerOwner = GetCharmerOrOwner(); - Unit const* targetOwner = unit->GetCharmerOrOwner(); - - // always hostile to owner's enemy - if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) - return true; - - // always hostile to enemy owner - if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) - return true; - - // always hostile to owner of owner's enemy - if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) - return true; - - Unit const* tester = testerOwner ? testerOwner : this; - Unit const* target = targetOwner ? targetOwner : unit; - - // always non-hostile to target with common owner, or to owner/pet - if(tester==target) - return false; - - // special cases (Duel, etc) - if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) - { - Player const* pTester = (Player const*)tester; - Player const* pTarget = (Player const*)target; - - // Duel - if(pTester->duel && pTester->duel->opponent == pTarget && pTester->duel->startTime != 0) - return true; - - // Group - if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) - return false; - - // Sanctuary - if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) - return false; - - // PvP FFA state - if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) - return true; - - //= PvP states - // Green/Blue (can't attack) - if(pTester->GetTeam()==pTarget->GetTeam()) - return false; - - // Red (can attack) if true, Blue/Yellow (can't attack) in another case - return pTester->IsPvP() && pTarget->IsPvP(); - } - - // faction base cases - FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); - FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) - return false; - - if(target->isAttackingPlayer() && tester->IsContestedGuard()) - return true; - - // PvC forced reaction and reputation case - if(tester->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player*)tester)->m_forcedReactions.find(target_faction->faction); - if(forceItr!=((Player*)tester)->m_forcedReactions.end()) - return forceItr->second <= REP_HOSTILE; - - // if faction have reputation then hostile state for tester at 100% dependent from at_war state - if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if(raw_target_faction->reputationListID >=0) - if(FactionState const* factionState = ((Player*)tester)->GetFactionState(raw_target_faction)) - return (factionState->Flags & FACTION_FLAG_AT_WAR); - } - // CvP forced reaction and reputation case - else if(target->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); - if(forceItr!=((Player const*)target)->m_forcedReactions.end()) - return forceItr->second <= REP_HOSTILE; - - // apply reputation state - FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction); - if(raw_tester_faction && raw_tester_faction->reputationListID >=0 ) - return ((Player const*)target)->GetReputationRank(raw_tester_faction) <= REP_HOSTILE; - } - - // common faction based case (CvC,PvC,CvP) - return tester_faction->IsHostileTo(*target_faction); -} - -bool Unit::IsFriendlyTo(Unit const* unit) const -{ - // always friendly to self - if(unit==this) - return true; - - // always friendly to GM in GM mode - if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) - return true; - - // always non-friendly to enemy - if(getVictim()==unit || unit->getVictim()==this) - return false; - - // test pet/charm masters instead pers/charmeds - Unit const* testerOwner = GetCharmerOrOwner(); - Unit const* targetOwner = unit->GetCharmerOrOwner(); - - // always non-friendly to owner's enemy - if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) - return false; - - // always non-friendly to enemy owner - if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) - return false; - - // always non-friendly to owner of owner's enemy - if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) - return false; - - Unit const* tester = testerOwner ? testerOwner : this; - Unit const* target = targetOwner ? targetOwner : unit; - - // always friendly to target with common owner, or to owner/pet - if(tester==target) - return true; - - // special cases (Duel) - if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) - { - Player const* pTester = (Player const*)tester; - Player const* pTarget = (Player const*)target; - - // Duel - if(pTester->duel && pTester->duel->opponent == target && pTester->duel->startTime != 0) - return false; - - // Group - if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) - return true; - - // Sanctuary - if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) - return true; - - // PvP FFA state - if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) - return false; - - //= PvP states - // Green/Blue (non-attackable) - if(pTester->GetTeam()==pTarget->GetTeam()) - return true; - - // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable) - return !pTarget->IsPvP(); - } - - // faction base cases - FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); - FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); - if(!tester_faction || !target_faction) - return false; - - if(target->isAttackingPlayer() && tester->IsContestedGuard()) - return false; - - // PvC forced reaction and reputation case - if(tester->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player const*)tester)->m_forcedReactions.find(target_faction->faction); - if(forceItr!=((Player const*)tester)->m_forcedReactions.end()) - return forceItr->second >= REP_FRIENDLY; - - // if faction have reputation then friendly state for tester at 100% dependent from at_war state - if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) - if(raw_target_faction->reputationListID >=0) - if(FactionState const* FactionState = ((Player*)tester)->GetFactionState(raw_target_faction)) - return !(FactionState->Flags & FACTION_FLAG_AT_WAR); - } - // CvP forced reaction and reputation case - else if(target->GetTypeId()==TYPEID_PLAYER) - { - // forced reaction - ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); - if(forceItr!=((Player const*)target)->m_forcedReactions.end()) - return forceItr->second >= REP_FRIENDLY; - - // apply reputation state - if(FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction)) - if(raw_tester_faction->reputationListID >=0 ) - return ((Player const*)target)->GetReputationRank(raw_tester_faction) >= REP_FRIENDLY; - } - - // common faction based case (CvC,PvC,CvP) - return tester_faction->IsFriendlyTo(*target_faction); -} - -bool Unit::IsHostileToPlayers() const -{ - FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); - if(!my_faction) - return false; - - FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); - if(raw_faction && raw_faction->reputationListID >=0 ) - return false; - - return my_faction->IsHostileToPlayers(); -} - -bool Unit::IsNeutralToAll() const -{ - FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); - if(!my_faction) - return true; - - FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); - if(raw_faction && raw_faction->reputationListID >=0 ) - return false; - - return my_faction->IsNeutralToAll(); -} - -bool Unit::Attack(Unit *victim, bool meleeAttack) -{ - if(!victim || victim == this) - return false; - - // dead units can neither attack nor be attacked - if(!isAlive() || !victim->isAlive()) - return false; - - // player cannot attack in mount state - if(GetTypeId()==TYPEID_PLAYER && IsMounted()) - return false; - - // nobody can attack GM in GM-mode - if(victim->GetTypeId()==TYPEID_PLAYER) - { - if(((Player*)victim)->isGameMaster()) - return false; - } - else - { - if(((Creature*)victim)->IsInEvadeMode()) - return false; - } - - // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack) - if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE)) - RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE); - - if (m_attacking) - { - if (m_attacking == victim) - { - // switch to melee attack from ranged/magic - if( meleeAttack && !hasUnitState(UNIT_STAT_MELEE_ATTACKING) ) - { - addUnitState(UNIT_STAT_MELEE_ATTACKING); - SendAttackStart(victim); - return true; - } - return false; - } - AttackStop(); - } - - //Set our target - SetUInt64Value(UNIT_FIELD_TARGET, victim->GetGUID()); - - if(meleeAttack) - addUnitState(UNIT_STAT_MELEE_ATTACKING); - m_attacking = victim; - m_attacking->_addAttacker(this); - - if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->AI()) - ((Creature*)m_attacking)->AI()->AttackedBy(this); - - if(GetTypeId()==TYPEID_UNIT) - { - WorldPacket data(SMSG_AI_REACTION, 12); - data << GetGUID(); - data << uint32(AI_REACTION_AGGRO); // Aggro sound - ((WorldObject*)this)->SendMessageToSet(&data, true); - - ((Creature*)this)->CallAssistence(); - ((Creature*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ()); - } - - // delay offhand weapon attack to next attack time - if(haveOffhandWeapon()) - resetAttackTimer(OFF_ATTACK); - - if(meleeAttack) - SendAttackStart(victim); - - return true; -} - -bool Unit::AttackStop() -{ - if (!m_attacking) - return false; - - Unit* victim = m_attacking; - - m_attacking->_removeAttacker(this); - m_attacking = NULL; - - //Clear our target - SetUInt64Value(UNIT_FIELD_TARGET, 0); - - clearUnitState(UNIT_STAT_MELEE_ATTACKING); - - InterruptSpell(CURRENT_MELEE_SPELL); - - if( GetTypeId()==TYPEID_UNIT ) - { - // reset call assistance - ((Creature*)this)->SetNoCallAssistence(false); - } - - SendAttackStop(victim); - - return true; -} - -void Unit::CombatStop(bool cast) -{ - if(cast& IsNonMeleeSpellCasted(false)) - InterruptNonMeleeSpells(false); - - AttackStop(); - RemoveAllAttackers(); - if( GetTypeId()==TYPEID_PLAYER ) - ((Player*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel - ClearInCombat(); -} - -void Unit::CombatStopWithPets(bool cast) -{ - CombatStop(cast); - if(Pet* pet = GetPet()) - pet->CombatStop(cast); - if(Unit* charm = GetCharm()) - charm->CombatStop(cast); - if(GetTypeId()==TYPEID_PLAYER) - { - GuardianPetList const& guardians = ((Player*)this)->GetGuardians(); - for(GuardianPetList::const_iterator itr = guardians.begin(); itr != guardians.end(); ++itr) - if(Unit* guardian = Unit::GetUnit(*this,*itr)) - guardian->CombatStop(cast); - } -} - -bool Unit::isAttackingPlayer() const -{ - if(hasUnitState(UNIT_STAT_ATTACK_PLAYER)) - return true; - - Pet* pet = GetPet(); - if(pet && pet->isAttackingPlayer()) - return true; - - Unit* charmed = GetCharm(); - if(charmed && charmed->isAttackingPlayer()) - return true; - - for (int8 i = 0; i < MAX_TOTEM; i++) - { - if(m_TotemSlot[i]) - { - Creature *totem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); - if(totem && totem->isAttackingPlayer()) - return true; - } - } - - return false; -} - -void Unit::RemoveAllAttackers() -{ - while (!m_attackers.empty()) - { - AttackerSet::iterator iter = m_attackers.begin(); - if(!(*iter)->AttackStop()) - { - sLog.outError("WORLD: Unit has an attacker that isn't attacking it!"); - m_attackers.erase(iter); - } - } -} - -void Unit::ModifyAuraState(AuraState flag, bool apply) -{ - if (apply) - { - if (!HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1))) - { - SetFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); - if(GetTypeId() == TYPEID_PLAYER) - { - const PlayerSpellMap& sp_list = ((Player*)this)->GetSpellMap(); - for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) - { - if(itr->second->state == PLAYERSPELL_REMOVED) continue; - SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); - if (!spellInfo || !IsPassiveSpell(itr->first)) continue; - if (spellInfo->CasterAuraState == flag) - CastSpell(this, itr->first, true, NULL); - } - } - } - } - else - { - if (HasFlag(UNIT_FIELD_AURASTATE,1<<(flag-1))) - { - RemoveFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); - Unit::AuraMap& tAuras = GetAuras(); - for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();) - { - SpellEntry const* spellProto = (*itr).second->GetSpellProto(); - if (spellProto->CasterAuraState == flag) - { - // exceptions (applied at state but not removed at state change) - // Rampage - if(spellProto->SpellIconID==2006 && spellProto->SpellFamilyName==SPELLFAMILY_WARRIOR && spellProto->SpellFamilyFlags==0x100000) - { - ++itr; - continue; - } - - RemoveAura(itr); - } - else - ++itr; - } - } - } -} - -Unit *Unit::GetOwner() const -{ - uint64 ownerid = GetOwnerGUID(); - if(!ownerid) - return NULL; - return ObjectAccessor::GetUnit(*this, ownerid); -} - -Unit *Unit::GetCharmer() const -{ - if(uint64 charmerid = GetCharmerGUID()) - return ObjectAccessor::GetUnit(*this, charmerid); - return NULL; -} - -Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() -{ - uint64 guid = GetCharmerOrOwnerGUID(); - if(IS_PLAYER_GUID(guid)) - return ObjectAccessor::GetPlayer(*this, guid); - - return GetTypeId()==TYPEID_PLAYER ? (Player*)this : NULL; -} - -Pet* Unit::GetPet() const -{ - if(uint64 pet_guid = GetPetGUID()) - { - if(Pet* pet = ObjectAccessor::GetPet(pet_guid)) - return pet; - - sLog.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid)); - const_cast(this)->SetPet(0); - } - - return NULL; -} - -Unit* Unit::GetCharm() const -{ - if(uint64 charm_guid = GetCharmGUID()) - { - if(Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid)) - return pet; - - sLog.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid)); - const_cast(this)->SetCharm(0); - } - - return NULL; -} - -void Unit::SetPet(Pet* pet) -{ - SetUInt64Value(UNIT_FIELD_SUMMON,pet ? pet->GetGUID() : 0); - - // FIXME: hack, speed must be set only at follow - if(pet) - for(int i = 0; i < MAX_MOVE_TYPE; ++i) - pet->SetSpeed(UnitMoveType(i),m_speed_rate[i],true); -} - -void Unit::SetCharm(Unit* charmed) -{ - SetUInt64Value(UNIT_FIELD_CHARM,charmed ? charmed->GetGUID() : 0); -} - -void Unit::AddPlayerToVision(Player* plr) -{ - if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) - { - setActive(true); - GetMap()->SwitchGridContainers((Creature*)this, true); - } - m_sharedVision.push_back(plr); - plr->SetFarsightTarget(this); -} - -void Unit::RemovePlayerFromVision(Player* plr) -{ - m_sharedVision.remove(plr); - if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) - { - setActive(false); - GetMap()->SwitchGridContainers((Creature*)this, false); - } - plr->ClearFarsight(); -} - -void Unit::RemoveAllFromVision() -{ - while (!m_sharedVision.empty()) - { - Player* plr = *m_sharedVision.begin(); - m_sharedVision.erase(m_sharedVision.begin()); - plr->ClearFarsight(); - } -} - -void Unit::UncharmSelf() -{ - if (!GetCharmer()) - return; - - RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM); -} - -void Unit::UnpossessSelf(bool attack) -{ - if (!isPossessed() || !GetCharmer()) - return; - - if (GetCharmer()->GetTypeId() == TYPEID_PLAYER) - ((Player*)GetCharmer())->RemovePossess(attack); - else - { - GetCharmer()->SetCharm(0); - SetCharmerGUID(0); - m_isPossessed = false; - } -} - -void Unit::UnsummonAllTotems() -{ - for (int8 i = 0; i < MAX_TOTEM; ++i) - { - if(!m_TotemSlot[i]) - continue; - - Creature *OldTotem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); - if (OldTotem && OldTotem->isTotem()) - ((Totem*)OldTotem)->UnSummon(); - } -} - -void Unit::SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical) -{ - // we guess size - WorldPacket data(SMSG_SPELLHEALLOG, (8+8+4+4+1)); - data.append(pVictim->GetPackGUID()); - data.append(GetPackGUID()); - data << uint32(SpellID); - data << uint32(Damage); - data << uint8(critical ? 1 : 0); - data << uint8(0); // unused in client? - SendMessageToSet(&data, true); -} - -void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype, bool critical) -{ - WorldPacket data(SMSG_SPELLENERGIZELOG, (8+8+4+4+4+1)); - data.append(pVictim->GetPackGUID()); - data.append(GetPackGUID()); - data << uint32(SpellID); - data << uint32(powertype); - data << uint32(Damage); - //data << uint8(critical ? 1 : 0); // removed in 2.4.0 - SendMessageToSet(&data, true); -} - -uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 pdamage, DamageEffectType damagetype) -{ - if(!spellProto || !pVictim || damagetype==DIRECT_DAMAGE ) - return pdamage; - - int32 BonusDamage = 0; - if( GetTypeId()==TYPEID_UNIT ) - { - // Pets just add their bonus damage to their spell damage - // note that their spell damage is just gain of their own auras - if (((Creature*)this)->isPet()) - { - BonusDamage = ((Pet*)this)->GetBonusDamage(); - } - // For totems get damage bonus from owner (statue isn't totem in fact) - else if (((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) - { - if(Unit* owner = GetOwner()) - return owner->SpellDamageBonus(pVictim, spellProto, pdamage, damagetype); - } - } - - // Damage Done - uint32 CastingTime = !IsChanneledSpell(spellProto) ? GetSpellCastTime(spellProto) : GetSpellDuration(spellProto); - - // Taken/Done fixed damage bonus auras - int32 DoneAdvertisedBenefit = SpellBaseDamageBonus(GetSpellSchoolMask(spellProto))+BonusDamage; - int32 TakenAdvertisedBenefit = SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); - - // Damage over Time spells bonus calculation - float DotFactor = 1.0f; - if(damagetype == DOT) - { - int32 DotDuration = GetSpellDuration(spellProto); - // 200% limit - if(DotDuration > 0) - { - if(DotDuration > 30000) DotDuration = 30000; - if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; - int x = 0; - for(int j = 0; j < 3; j++) - { - if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_DAMAGE || - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) - { - x = j; - break; - } - } - int DotTicks = 6; - if(spellProto->EffectAmplitude[x] != 0) - DotTicks = DotDuration / spellProto->EffectAmplitude[x]; - if(DotTicks) - { - DoneAdvertisedBenefit /= DotTicks; - TakenAdvertisedBenefit /= DotTicks; - } - } - } - - // Taken/Done total percent damage auras - float DoneTotalMod = 1.0f; - float TakenTotalMod = 1.0f; - - // ..done - AuraList const& mModDamagePercentDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE); - for(AuraList::const_iterator i = mModDamagePercentDone.begin(); i != mModDamagePercentDone.end(); ++i) - { - if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) && - (*i)->GetSpellProto()->EquippedItemClass == -1 && - // -1 == any item class (not wand then) - (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) - // 0 == any inventory type (not wand then) - { - DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - } - } - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // ..taken - AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); - for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) - if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // .. taken pct: scripted (increases damage of * against targets *) - AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) - { - switch((*i)->GetModifier()->m_miscvalue) - { - //Molten Fury - case 4920: case 4919: - if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT)) - TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; break; - } - } - - // .. taken pct: dummy auras - AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) - { - switch((*i)->GetSpellProto()->SpellIconID) - { - //Cheat Death - case 2109: - if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) ) - { - if(pVictim->GetTypeId() != TYPEID_PLAYER) - continue; - float mod = -((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL)*2*4; - if (mod < (*i)->GetModifier()->m_amount) - mod = (*i)->GetModifier()->m_amount; - TakenTotalMod *= (mod+100.0f)/100.0f; - } - break; - //Mangle - case 2312: - for(int j=0;j<3;j++) - { - if(GetEffectMechanic(spellProto, j)==MECHANIC_BLEED) - { - TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; - break; - } - } - break; - } - } - - // Distribute Damage over multiple effects, reduce by AoE - CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); - - // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing - for(int j = 0; j < 3; ++j) - { - if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || - spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) - { - CastingTime /= 2; - break; - } - } - - switch(spellProto->SpellFamilyName) - { - case SPELLFAMILY_MAGE: - // Ignite - do not modify, it is (8*Rank)% damage of procing Spell - if(spellProto->Id==12654) - { - return pdamage; - } - // Ice Lance - else if((spellProto->SpellFamilyFlags & 0x20000LL) && spellProto->SpellIconID == 186) - { - CastingTime /= 3; // applied 1/3 bonuses in case generic target - if(pVictim->isFrozen()) // and compensate this for frozen target. - TakenTotalMod *= 3.0f; - } - // Pyroblast - 115% of Fire Damage, DoT - 20% of Fire Damage - else if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 184 ) - { - DotFactor = damagetype == DOT ? 0.2f : 1.0f; - CastingTime = damagetype == DOT ? 3500 : 4025; - } - // Fireball - 100% of Fire Damage, DoT - 0% of Fire Damage - else if((spellProto->SpellFamilyFlags & 0x1LL) && spellProto->SpellIconID == 185) - { - CastingTime = 3500; - DotFactor = damagetype == DOT ? 0.0f : 1.0f; - } - // Molten armor - else if (spellProto->SpellFamilyFlags & 0x0000000800000000LL) - { - CastingTime = 0; - } - // Arcane Missiles triggered spell - else if ((spellProto->SpellFamilyFlags & 0x200000LL) && spellProto->SpellIconID == 225) - { - CastingTime = 1000; - } - // Blizzard triggered spell - else if ((spellProto->SpellFamilyFlags & 0x80080LL) && spellProto->SpellIconID == 285) - { - CastingTime = 500; - } - break; - case SPELLFAMILY_WARLOCK: - // Life Tap - if((spellProto->SpellFamilyFlags & 0x40000LL) && spellProto->SpellIconID == 208) - { - CastingTime = 2800; // 80% from +shadow damage - DoneTotalMod = 1.0f; - TakenTotalMod = 1.0f; - } - // Dark Pact - else if((spellProto->SpellFamilyFlags & 0x80000000LL) && spellProto->SpellIconID == 154 && GetPetGUID()) - { - CastingTime = 3360; // 96% from +shadow damage - DoneTotalMod = 1.0f; - TakenTotalMod = 1.0f; - } - // Soul Fire - 115% of Fire Damage - else if((spellProto->SpellFamilyFlags & 0x8000000000LL) && spellProto->SpellIconID == 184) - { - CastingTime = 4025; - } - // Curse of Agony - 120% of Shadow Damage - else if((spellProto->SpellFamilyFlags & 0x0000000400LL) && spellProto->SpellIconID == 544) - { - DotFactor = 1.2f; - } - // Drain Mana - 0% of Shadow Damage - else if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 548) - { - CastingTime = 0; - } - // Drain Soul 214.3% - else if ((spellProto->SpellFamilyFlags & 0x4000LL) && spellProto->SpellIconID == 113 ) - { - CastingTime = 7500; - } - // Hellfire - else if ((spellProto->SpellFamilyFlags & 0x40LL) && spellProto->SpellIconID == 937) - { - CastingTime = damagetype == DOT ? 5000 : 500; // self damage seems to be so - } - // Unstable Affliction - 180% - else if (spellProto->Id == 31117 && spellProto->SpellIconID == 232) - { - CastingTime = 6300; - } - // Corruption 93% - else if ((spellProto->SpellFamilyFlags & 0x2LL) && spellProto->SpellIconID == 313) - { - DotFactor = 0.93f; - } - break; - case SPELLFAMILY_PALADIN: - // Consecration - 95% of Holy Damage - if((spellProto->SpellFamilyFlags & 0x20LL) && spellProto->SpellIconID == 51) - { - DotFactor = 0.95f; - CastingTime = 3500; - } - // Seal of Righteousness - 10.2%/9.8% ( based on weapon type ) of Holy Damage, multiplied by weapon speed - else if((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 25) - { - Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); - float wspeed = GetAttackTime(BASE_ATTACK)/1000.0f; - - if( item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) - CastingTime = uint32(wspeed*3500*0.102f); - else - CastingTime = uint32(wspeed*3500*0.098f); - } - // Judgement of Righteousness - 73% - else if ((spellProto->SpellFamilyFlags & 1024) && spellProto->SpellIconID == 25) - { - CastingTime = 2555; - } - // Seal of Vengeance - 17% per Fully Stacked Tick - 5 Applications - else if ((spellProto->SpellFamilyFlags & 0x80000000000LL) && spellProto->SpellIconID == 2292) - { - DotFactor = 0.17f; - CastingTime = 3500; - } - // Holy shield - 5% of Holy Damage - else if ((spellProto->SpellFamilyFlags & 0x4000000000LL) && spellProto->SpellIconID == 453) - { - CastingTime = 175; - } - // Blessing of Sanctuary - 0% - else if ((spellProto->SpellFamilyFlags & 0x10000000LL) && spellProto->SpellIconID == 29) - { - CastingTime = 0; - } - // Seal of Righteousness trigger - already computed for parent spell - else if ( spellProto->SpellFamilyName==SPELLFAMILY_PALADIN && spellProto->SpellIconID==25 && spellProto->AttributesEx4 & 0x00800000LL ) - { - return pdamage; - } - break; - case SPELLFAMILY_SHAMAN: - // totem attack - if (spellProto->SpellFamilyFlags & 0x000040000000LL) - { - if (spellProto->SpellIconID == 33) // Fire Nova totem attack must be 21.4%(untested) - CastingTime = 749; // ignore CastingTime and use as modifier - else if (spellProto->SpellIconID == 680) // Searing Totem attack 8% - CastingTime = 280; // ignore CastingTime and use as modifier - else if (spellProto->SpellIconID == 37) // Magma totem attack must be 6.67%(untested) - CastingTime = 234; // ignore CastingTimePenalty and use as modifier - } - // Lightning Shield (and proc shield from T2 8 pieces bonus ) 33% per charge - else if( (spellProto->SpellFamilyFlags & 0x00000000400LL) || spellProto->Id == 23552) - CastingTime = 1155; // ignore CastingTimePenalty and use as modifier - break; - case SPELLFAMILY_PRIEST: - // Mana Burn - 0% of Shadow Damage - if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 212) - { - CastingTime = 0; - } - // Mind Flay - 59% of Shadow Damage - else if((spellProto->SpellFamilyFlags & 0x800000LL) && spellProto->SpellIconID == 548) - { - CastingTime = 2065; - } - // Holy Fire - 86.71%, DoT - 16.5% - else if ((spellProto->SpellFamilyFlags & 0x100000LL) && spellProto->SpellIconID == 156) - { - DotFactor = damagetype == DOT ? 0.165f : 1.0f; - CastingTime = damagetype == DOT ? 3500 : 3035; - } - // Shadowguard - 28% per charge - else if ((spellProto->SpellFamilyFlags & 0x2000000LL) && spellProto->SpellIconID == 19) - { - CastingTime = 980; - } - // Touch of Weakeness - 10% - else if ((spellProto->SpellFamilyFlags & 0x80000LL) && spellProto->SpellIconID == 1591) - { - CastingTime = 350; - } - // Reflective Shield (back damage) - 0% (other spells fit to check not have damage effects/auras) - else if (spellProto->SpellFamilyFlags == 0 && spellProto->SpellIconID == 566) - { - CastingTime = 0; - } - // Holy Nova - 14% - else if ((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 1874) - { - CastingTime = 500; - } - break; - case SPELLFAMILY_DRUID: - // Hurricane triggered spell - if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 220) - { - CastingTime = 500; - } - break; - case SPELLFAMILY_WARRIOR: - case SPELLFAMILY_HUNTER: - case SPELLFAMILY_ROGUE: - CastingTime = 0; - break; - default: - break; - } - - float LvlPenalty = CalculateLevelPenalty(spellProto); - - // Spellmod SpellDamage - float SpellModSpellDamage = 100.0f; - - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); - - SpellModSpellDamage /= 100.0f; - - float DoneActualBenefit = DoneAdvertisedBenefit * (CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; - float TakenActualBenefit = TakenAdvertisedBenefit; - if(spellProto->SpellFamilyName) - TakenActualBenefit *= (CastingTime / 3500.0f) * DotFactor * LvlPenalty; - - float tmpDamage = (float(pdamage)+DoneActualBenefit)*DoneTotalMod; - - // Add flat bonus from spell damage versus - tmpDamage += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS, creatureTypeMask); - - // apply spellmod to Done damage - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, tmpDamage); - - tmpDamage = (tmpDamage+TakenActualBenefit)*TakenTotalMod; - - if( GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet() ) - tmpDamage *= ((Creature*)this)->GetSpellDamageMod(((Creature*)this)->GetCreatureInfo()->rank); - - return tmpDamage > 0 ? uint32(tmpDamage) : 0; -} - -int32 Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask) -{ - int32 DoneAdvertisedBenefit = 0; - - // ..done - AuraList const& mDamageDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE); - for(AuraList::const_iterator i = mDamageDone.begin();i != mDamageDone.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0 && - (*i)->GetSpellProto()->EquippedItemClass == -1 && - // -1 == any item class (not wand then) - (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) - // 0 == any inventory type (not wand then) - DoneAdvertisedBenefit += (*i)->GetModifier()->m_amount; - - if (GetTypeId() == TYPEID_PLAYER) - { - // Damage bonus from stats - AuraList const& mDamageDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT); - for(AuraList::const_iterator i = mDamageDoneOfStatPercent.begin();i != mDamageDoneOfStatPercent.end(); ++i) - { - if((*i)->GetModifier()->m_miscvalue & schoolMask) - { - SpellEntry const* iSpellProto = (*i)->GetSpellProto(); - uint8 eff = (*i)->GetEffIndex(); - - // stat used dependent from next effect aura SPELL_AURA_MOD_SPELL_HEALING presence and misc value (stat index) - Stats usedStat = STAT_INTELLECT; - if(eff < 2 && iSpellProto->EffectApplyAuraName[eff+1]==SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT) - usedStat = Stats(iSpellProto->EffectMiscValue[eff+1]); - - DoneAdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); - } - } - // ... and attack power - AuraList const& mDamageDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER); - for(AuraList::const_iterator i =mDamageDonebyAP.begin();i != mDamageDonebyAP.end(); ++i) - if ((*i)->GetModifier()->m_miscvalue & schoolMask) - DoneAdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); - - } - return DoneAdvertisedBenefit; -} - -int32 Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) -{ - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - - int32 TakenAdvertisedBenefit = 0; - // ..done (for creature type by mask) in taken - AuraList const& mDamageDoneCreature = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); - for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; - - // ..taken - AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); - for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) - TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; - - return TakenAdvertisedBenefit; -} - -bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType) -{ - // not criting spell - if((spellProto->AttributesEx2 & SPELL_ATTR_EX2_CANT_CRIT)) - return false; - - float crit_chance = 0.0f; - switch(spellProto->DmgClass) - { - case SPELL_DAMAGE_CLASS_NONE: - return false; - case SPELL_DAMAGE_CLASS_MAGIC: - { - if (schoolMask & SPELL_SCHOOL_MASK_NORMAL) - crit_chance = 0.0f; - // For other schools - else if (GetTypeId() == TYPEID_PLAYER) - crit_chance = GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1 + GetFirstSchoolInMask(schoolMask)); - else - { - crit_chance = m_baseSpellCritChance; - crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); - } - // taken - if (pVictim && !IsPositiveSpell(spellProto->Id)) - { - // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE - crit_chance += pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE, schoolMask); - // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE - crit_chance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); - // Modify by player victim resilience - if (pVictim->GetTypeId() == TYPEID_PLAYER) - crit_chance -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL); - // scripted (increase crit chance ... against ... target by x% - if(pVictim->isFrozen()) // Shatter - { - AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) - { - switch((*i)->GetModifier()->m_miscvalue) - { - case 849: crit_chance+= 10.0f; break; //Shatter Rank 1 - case 910: crit_chance+= 20.0f; break; //Shatter Rank 2 - case 911: crit_chance+= 30.0f; break; //Shatter Rank 3 - case 912: crit_chance+= 40.0f; break; //Shatter Rank 4 - case 913: crit_chance+= 50.0f; break; //Shatter Rank 5 - } - } - } - } - break; - } - case SPELL_DAMAGE_CLASS_MELEE: - case SPELL_DAMAGE_CLASS_RANGED: - { - if (pVictim) - { - crit_chance = GetUnitCriticalChance(attackType, pVictim); - crit_chance+= (int32(GetMaxSkillValueForLevel(pVictim)) - int32(pVictim->GetDefenseSkillValue(this))) * 0.04f; - crit_chance+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); - } - break; - } - default: - return false; - } - // percent done - // only players use intelligence for critical chance computations - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); - - crit_chance = crit_chance > 0.0f ? crit_chance : 0.0f; - if (roll_chance_f(crit_chance)) - return true; - return false; -} - -uint32 Unit::SpellCriticalBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim) -{ - // Calculate critical bonus - int32 crit_bonus; - switch(spellProto->DmgClass) - { - case SPELL_DAMAGE_CLASS_MELEE: // for melee based spells is 100% - case SPELL_DAMAGE_CLASS_RANGED: - // TODO: write here full calculation for melee/ranged spells - crit_bonus = damage; - break; - default: - crit_bonus = damage / 2; // for spells is 50% - break; - } - - // adds additional damage to crit_bonus (from talents) - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); - - if(pVictim) - { - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - crit_bonus = int32(crit_bonus * GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS, creatureTypeMask)); - } - - if(crit_bonus > 0) - damage += crit_bonus; - - return damage; -} - -uint32 Unit::SpellHealingBonus(SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, Unit *pVictim) -{ - // For totems get healing bonus from owner (statue isn't totem in fact) - if( GetTypeId()==TYPEID_UNIT && ((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) - if(Unit* owner = GetOwner()) - return owner->SpellHealingBonus(spellProto, healamount, damagetype, pVictim); - - // Healing Done - - // These Spells are doing fixed amount of healing (TODO found less hack-like check) - if (spellProto->Id == 15290 || spellProto->Id == 39373 || - spellProto->Id == 33778 || spellProto->Id == 379 || - spellProto->Id == 38395 || spellProto->Id == 40972) - return healamount; - - int32 AdvertisedBenefit = SpellBaseHealingBonus(GetSpellSchoolMask(spellProto)); - uint32 CastingTime = GetSpellCastTime(spellProto); - - // Healing Taken - AdvertisedBenefit += SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); - - // Blessing of Light dummy effects healing taken from Holy Light and Flash of Light - if (spellProto->SpellFamilyName == SPELLFAMILY_PALADIN && (spellProto->SpellFamilyFlags & 0x00000000C0000000LL)) - { - AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i) - { - if((*i)->GetSpellProto()->SpellVisual == 9180) - { - // Flash of Light - if ((spellProto->SpellFamilyFlags & 0x0000000040000000LL) && (*i)->GetEffIndex() == 1) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - // Holy Light - else if ((spellProto->SpellFamilyFlags & 0x0000000080000000LL) && (*i)->GetEffIndex() == 0) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - } - } - } - - float ActualBenefit = 0.0f; - - if (AdvertisedBenefit != 0) - { - // Healing over Time spells - float DotFactor = 1.0f; - if(damagetype == DOT) - { - int32 DotDuration = GetSpellDuration(spellProto); - if(DotDuration > 0) - { - // 200% limit - if(DotDuration > 30000) DotDuration = 30000; - if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; - int x = 0; - for(int j = 0; j < 3; j++) - { - if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_HEAL || - spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) - { - x = j; - break; - } - } - int DotTicks = 6; - if(spellProto->EffectAmplitude[x] != 0) - DotTicks = DotDuration / spellProto->EffectAmplitude[x]; - if(DotTicks) - AdvertisedBenefit /= DotTicks; - } - } - - // distribute healing to all effects, reduce AoE damage - CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); - - // 0% bonus for damage and healing spells for leech spells from healing bonus - for(int j = 0; j < 3; ++j) - { - if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || - spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) - { - CastingTime = 0; - break; - } - } - - // Exception - switch (spellProto->SpellFamilyName) - { - case SPELLFAMILY_SHAMAN: - // Healing stream from totem (add 6% per tick from hill bonus owner) - if (spellProto->SpellFamilyFlags & 0x000000002000LL) - CastingTime = 210; - // Earth Shield 30% per charge - else if (spellProto->SpellFamilyFlags & 0x40000000000LL) - CastingTime = 1050; - break; - case SPELLFAMILY_DRUID: - // Lifebloom - if (spellProto->SpellFamilyFlags & 0x1000000000LL) - { - CastingTime = damagetype == DOT ? 3500 : 1200; - DotFactor = damagetype == DOT ? 0.519f : 1.0f; - } - // Tranquility triggered spell - else if (spellProto->SpellFamilyFlags & 0x80LL) - CastingTime = 667; - // Rejuvenation - else if (spellProto->SpellFamilyFlags & 0x10LL) - DotFactor = 0.845f; - // Regrowth - else if (spellProto->SpellFamilyFlags & 0x40LL) - { - DotFactor = damagetype == DOT ? 0.705f : 1.0f; - CastingTime = damagetype == DOT ? 3500 : 1010; - } - break; - case SPELLFAMILY_PRIEST: - // Holy Nova - 14% - if ((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 1874) - CastingTime = 500; - break; - case SPELLFAMILY_PALADIN: - // Seal and Judgement of Light - if ( spellProto->SpellFamilyFlags & 0x100040000LL ) - CastingTime = 0; - break; - case SPELLFAMILY_WARRIOR: - case SPELLFAMILY_ROGUE: - case SPELLFAMILY_HUNTER: - CastingTime = 0; - break; - } - - float LvlPenalty = CalculateLevelPenalty(spellProto); - - // Spellmod SpellDamage - float SpellModSpellDamage = 100.0f; - - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); - - SpellModSpellDamage /= 100.0f; - - ActualBenefit = (float)AdvertisedBenefit * ((float)CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; - } - - // use float as more appropriate for negative values and percent applying - float heal = healamount + ActualBenefit; - - // TODO: check for ALL/SPELLS type - // Healing done percent - AuraList const& mHealingDonePct = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT); - for(AuraList::const_iterator i = mHealingDonePct.begin();i != mHealingDonePct.end(); ++i) - heal *= (100.0f + (*i)->GetModifier()->m_amount) / 100.0f; - - // apply spellmod to Done amount - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, heal); - - // Healing Wave cast - if (spellProto->SpellFamilyName == SPELLFAMILY_SHAMAN && spellProto->SpellFamilyFlags & 0x0000000000000040LL) - { - // Search for Healing Way on Victim (stack up to 3 time) - int32 pctMod = 0; - Unit::AuraList const& auraDummy = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr!=auraDummy.end(); ++itr) - if((*itr)->GetId() == 29203) - pctMod += (*itr)->GetModifier()->m_amount; - // Apply bonus - if (pctMod) - heal = heal * (100 + pctMod) / 100; - } - - // Healing taken percent - float minval = pVictim->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT); - if(minval) - heal *= (100.0f + minval) / 100.0f; - - float maxval = pVictim->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT); - if(maxval) - heal *= (100.0f + maxval) / 100.0f; - - if (heal < 0) heal = 0; - - return uint32(heal); -} - -int32 Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask) -{ - int32 AdvertisedBenefit = 0; - - AuraList const& mHealingDone = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE); - for(AuraList::const_iterator i = mHealingDone.begin();i != mHealingDone.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - - // Healing bonus of spirit, intellect and strength - if (GetTypeId() == TYPEID_PLAYER) - { - // Healing bonus from stats - AuraList const& mHealingDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT); - for(AuraList::const_iterator i = mHealingDoneOfStatPercent.begin();i != mHealingDoneOfStatPercent.end(); ++i) - { - // stat used dependent from misc value (stat index) - Stats usedStat = Stats((*i)->GetSpellProto()->EffectMiscValue[(*i)->GetEffIndex()]); - AdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); - } - - // ... and attack power - AuraList const& mHealingDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER); - for(AuraList::const_iterator i = mHealingDonebyAP.begin();i != mHealingDonebyAP.end(); ++i) - if ((*i)->GetModifier()->m_miscvalue & schoolMask) - AdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); - } - return AdvertisedBenefit; -} - -int32 Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) -{ - int32 AdvertisedBenefit = 0; - AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_HEALING); - for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) - if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) - AdvertisedBenefit += (*i)->GetModifier()->m_amount; - return AdvertisedBenefit; -} - -bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask, bool useCharges) -{ - // no charges dependent checks - SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; - for (SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) - if(itr->type & shoolMask) - return true; - - // charges dependent checks - SpellImmuneList const& damageList = m_spellImmune[IMMUNITY_DAMAGE]; - for (SpellImmuneList::const_iterator itr = damageList.begin(); itr != damageList.end(); ++itr) - { - if(itr->type & shoolMask) - { - if(useCharges) - { - AuraList const& auraDamageImmunity = GetAurasByType(SPELL_AURA_DAMAGE_IMMUNITY); - for(AuraList::const_iterator auraItr = auraDamageImmunity.begin(); auraItr != auraDamageImmunity.end(); ++auraItr) - { - if((*auraItr)->GetId()==itr->spellId) - { - if((*auraItr)->m_procCharges > 0) - { - --(*auraItr)->m_procCharges; - if((*auraItr)->m_procCharges==0) - RemoveAurasDueToSpell(itr->spellId); - } - break; - } - } - } - return true; - } - } - - return false; -} - -bool Unit::IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges) -{ - if (!spellInfo) - return false; - - // no charges first - - //FIX ME this hack: don't get feared if stunned - if (spellInfo->Mechanic == MECHANIC_FEAR ) - { - if ( hasUnitState(UNIT_STAT_STUNNED) ) - return true; - } - - // not have spells with charges currently - SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_DISPEL]; - for(SpellImmuneList::const_iterator itr = dispelList.begin(); itr != dispelList.end(); ++itr) - if(itr->type == spellInfo->Dispel) - return true; - - if( !(spellInfo->AttributesEx & SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE) && (spellInfo->Id != 42292)) // unaffected by school immunity - { - // not have spells with charges currently - SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; - for(SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) - if( !(IsPositiveSpell(itr->spellId) && IsPositiveSpell(spellInfo->Id)) && - (itr->type & GetSpellSchoolMask(spellInfo)) ) - return true; - } - - // charges dependent checks - - SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; - for(SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) - { - if(itr->type == spellInfo->Mechanic) - { - if(useCharges) - { - AuraList const& auraMechImmunity = GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY); - for(AuraList::const_iterator auraItr = auraMechImmunity.begin(); auraItr != auraMechImmunity.end(); ++auraItr) - { - if((*auraItr)->GetId()==itr->spellId) - { - if((*auraItr)->m_procCharges > 0) - { - --(*auraItr)->m_procCharges; - if((*auraItr)->m_procCharges==0) - RemoveAurasDueToSpell(itr->spellId); - } - break; - } - } - } - return true; - } - } - - return false; -} - -bool Unit::IsImmunedToSpellEffect(uint32 effect, uint32 mechanic) const -{ - //If m_immuneToEffect type contain this effect type, IMMUNE effect. - SpellImmuneList const& effectList = m_spellImmune[IMMUNITY_EFFECT]; - for (SpellImmuneList::const_iterator itr = effectList.begin(); itr != effectList.end(); ++itr) - if(itr->type == effect) - return true; - - SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; - for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) - if(itr->type == mechanic) - return true; - - return false; -} - -bool Unit::IsDamageToThreatSpell(SpellEntry const * spellInfo) const -{ - if(!spellInfo) - return false; - - uint32 family = spellInfo->SpellFamilyName; - uint64 flags = spellInfo->SpellFamilyFlags; - - if((family == 5 && flags == 256) || //Searing Pain - (family == 6 && flags == 8192) || //Mind Blast - (family == 11 && flags == 1048576)) //Earth Shock - return true; - - return false; -} - -void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage,WeaponAttackType attType, SpellEntry const *spellProto) -{ - if(!pVictim) - return; - - if(*pdamage == 0) - return; - - uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); - - // Taken/Done fixed damage bonus auras - int32 DoneFlatBenefit = 0; - int32 TakenFlatBenefit = 0; - - // ..done (for creature type by mask) in taken - AuraList const& mDamageDoneCreature = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); - for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - DoneFlatBenefit += (*i)->GetModifier()->m_amount; - - // ..done - // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage - - // ..done (base at attack power for marked target and base at attack power for creature type) - int32 APbonus = 0; - if(attType == RANGED_ATTACK) - { - APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS); - - // ..done (base at attack power and creature type) - AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS); - for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - APbonus += (*i)->GetModifier()->m_amount; - } - else - { - APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS); - - // ..done (base at attack power and creature type) - AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS); - for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - APbonus += (*i)->GetModifier()->m_amount; - } - - if (APbonus!=0) // Can be negative - { - bool normalized = false; - if(spellProto) - { - for (uint8 i = 0; i<3;i++) - { - if (spellProto->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG) - { - normalized = true; - break; - } - } - } - - DoneFlatBenefit += int32(APbonus/14.0f * GetAPMultiplier(attType,normalized)); - } - - // ..taken - AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); - for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) - if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) - TakenFlatBenefit += (*i)->GetModifier()->m_amount; - - if(attType!=RANGED_ATTACK) - TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN); - else - TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN); - - // Done/Taken total percent damage auras - float DoneTotalMod = 1; - float TakenTotalMod = 1; - - // ..done - // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage - // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage - - AuraList const& mDamageDoneVersus = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); - for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) - if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) - DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // ..taken - AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); - for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) - if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - - // .. taken pct: dummy auras - AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); - for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) - { - switch((*i)->GetSpellProto()->SpellIconID) - { - //Cheat Death - case 2109: - if((*i)->GetModifier()->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) - { - if(pVictim->GetTypeId() != TYPEID_PLAYER) - continue; - float mod = ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); - if (mod < (*i)->GetModifier()->m_amount) - mod = (*i)->GetModifier()->m_amount; - TakenTotalMod *= (mod+100.0f)/100.0f; - } - break; - //Mangle - case 2312: - if(spellProto==NULL) - break; - // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG) - if(spellProto->SpellFamilyName==SPELLFAMILY_DRUID && (spellProto->SpellFamilyFlags==0x00008000LL)) - TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; - break; - } - } - - // .. taken pct: class scripts - AuraList const& mclassScritAuras = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(AuraList::const_iterator i = mclassScritAuras.begin(); i != mclassScritAuras.end(); ++i) - { - switch((*i)->GetMiscValue()) - { - case 6427: case 6428: // Dirty Deeds - if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT)) - { - Aura* eff0 = GetAura((*i)->GetId(),0); - if(!eff0 || (*i)->GetEffIndex()!=1) - { - sLog.outError("Spell structure of DD (%u) changed.",(*i)->GetId()); - continue; - } - - // effect 0 have expected value but in negative state - TakenTotalMod *= (-eff0->GetModifier()->m_amount+100.0f)/100.0f; - } - break; - } - } - - if(attType != RANGED_ATTACK) - { - AuraList const& mModMeleeDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT); - for(AuraList::const_iterator i = mModMeleeDamageTakenPercent.begin(); i != mModMeleeDamageTakenPercent.end(); ++i) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - } - else - { - AuraList const& mModRangedDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT); - for(AuraList::const_iterator i = mModRangedDamageTakenPercent.begin(); i != mModRangedDamageTakenPercent.end(); ++i) - TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; - } - - float tmpDamage = float(int32(*pdamage) + DoneFlatBenefit) * DoneTotalMod; - - // apply spellmod to Done damage - if(spellProto) - { - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_DAMAGE, tmpDamage); - } - - tmpDamage = (tmpDamage + TakenFlatBenefit)*TakenTotalMod; - - // bonus result can be negative - *pdamage = tmpDamage > 0 ? uint32(tmpDamage) : 0; -} - -void Unit::ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply) -{ - if (apply) - { - for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(), next; itr != m_spellImmune[op].end(); itr = next) - { - next = itr; ++next; - if(itr->type == type) - { - m_spellImmune[op].erase(itr); - next = m_spellImmune[op].begin(); - } - } - SpellImmune Immune; - Immune.spellId = spellId; - Immune.type = type; - m_spellImmune[op].push_back(Immune); - } - else - { - for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(); itr != m_spellImmune[op].end(); ++itr) - { - if(itr->spellId == spellId) - { - m_spellImmune[op].erase(itr); - break; - } - } - } - -} - -void Unit::ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply) -{ - ApplySpellImmune(spellProto->Id,IMMUNITY_DISPEL, type, apply); - - if (apply && spellProto->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY) - RemoveAurasWithDispelType(type); -} - -float Unit::GetWeaponProcChance() const -{ - // normalized proc chance for weapon attack speed - // (odd formula...) - if(isAttackReady(BASE_ATTACK)) - return (GetAttackTime(BASE_ATTACK) * 1.8f / 1000.0f); - else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK)) - return (GetAttackTime(OFF_ATTACK) * 1.6f / 1000.0f); - return 0; -} - -float Unit::GetPPMProcChance(uint32 WeaponSpeed, float PPM) const -{ - // proc per minute chance calculation - if (PPM <= 0) return 0.0f; - uint32 result = uint32((WeaponSpeed * PPM) / 600.0f); // result is chance in percents (probability = Speed_in_sec * (PPM / 60)) - return result; -} - -void Unit::Mount(uint32 mount) -{ - if(!mount) - return; - - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNT); - - SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, mount); - - SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); - - // unsummon pet - if(GetTypeId() == TYPEID_PLAYER) - { - Pet* pet = GetPet(); - if(pet) - { - if(pet->isControlled()) - { - ((Player*)this)->SetTemporaryUnsummonedPetNumber(pet->GetCharmInfo()->GetPetNumber()); - ((Player*)this)->SetOldPetSpell(pet->GetUInt32Value(UNIT_CREATED_BY_SPELL)); - } - - ((Player*)this)->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT); - } - else - ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); - } -} - -void Unit::Unmount() -{ - if(!IsMounted()) - return; - - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED); - - SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0); - RemoveFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); - - // only resummon old pet if the player is already added to a map - // this prevents adding a pet to a not created map which would otherwise cause a crash - // (it could probably happen when logging in after a previous crash) - if(GetTypeId() == TYPEID_PLAYER && IsInWorld() && ((Player*)this)->GetTemporaryUnsummonedPetNumber() && isAlive()) - { - Pet* NewPet = new Pet; - if(!NewPet->LoadPetFromDB(this, 0, ((Player*)this)->GetTemporaryUnsummonedPetNumber(), true)) - delete NewPet; - - ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); - } -} - -void Unit::SetInCombatWith(Unit* enemy) -{ - Unit* eOwner = enemy->GetCharmerOrOwnerOrSelf(); - if(eOwner->IsPvP()) - { - SetInCombatState(true); - return; - } - - //check for duel - if(eOwner->GetTypeId() == TYPEID_PLAYER && ((Player*)eOwner)->duel) - { - Unit const* myOwner = GetCharmerOrOwnerOrSelf(); - if(((Player const*)eOwner)->duel->opponent == myOwner) - { - SetInCombatState(true); - return; - } - } - SetInCombatState(false); -} - -void Unit::CombatStart(Unit* target) -{ - if(!target->IsStandState() && !target->hasUnitState(UNIT_STAT_STUNNED)) - target->SetStandState(PLAYER_STATE_NONE); - - if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER && ((Creature*)target)->AI()) - ((Creature*)target)->AI()->AttackStart(this); - - SetInCombatWith(target); - target->SetInCombatWith(this); - - if(Player* attackedPlayer = target->GetCharmerOrOwnerPlayerOrPlayerItself()) - SetContestedPvP(attackedPlayer); - - if(!isInCombat()) // remove this? - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ATTACK); -} - -void Unit::SetInCombatState(bool PvP) -{ - // only alive units can be in combat - if(!isAlive()) - return; - - if(PvP) - m_CombatTimer = 5000; - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); - - if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); -} - -void Unit::ClearInCombat() -{ - m_CombatTimer = 0; - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); - - if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); - - // Player's state will be cleared in Player::UpdateContestedPvP - if(GetTypeId()!=TYPEID_PLAYER) - clearUnitState(UNIT_STAT_ATTACK_PLAYER); -} - -//TODO: remove this function -bool Unit::isTargetableForAttack() const -{ - return isAttackableByAOE() && !hasUnitState(UNIT_STAT_DIED); -} - -bool Unit::canAttack(Unit const* target) const -{ - assert(target); - - if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) - return false; - - if((m_invisibilityMask || target->m_invisibilityMask) && !canDetectInvisibilityOf(target)) - return false; - - if(target->GetVisibility() == VISIBILITY_GROUP_STEALTH && !canDetectStealthOf(target, GetDistance(target))) - return false; - - return true; -} - -bool Unit::isAttackableByAOE() const -{ - if(!isAlive()) - return false; - - if(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE)) - return false; - - if(GetTypeId()==TYPEID_PLAYER && ((Player *)this)->isGameMaster()) - return false; - - return !isInFlight(); -} - -int32 Unit::ModifyHealth(int32 dVal) -{ - int32 gain = 0; - - if(dVal==0) - return 0; - - int32 curHealth = (int32)GetHealth(); - - int32 val = dVal + curHealth; - if(val <= 0) - { - SetHealth(0); - return -curHealth; - } - - int32 maxHealth = (int32)GetMaxHealth(); - - if(val < maxHealth) - { - SetHealth(val); - gain = val - curHealth; - } - else if(curHealth != maxHealth) - { - SetHealth(maxHealth); - gain = maxHealth - curHealth; - } - - return gain; -} - -int32 Unit::ModifyPower(Powers power, int32 dVal) -{ - int32 gain = 0; - - if(dVal==0) - return 0; - - int32 curPower = (int32)GetPower(power); - - int32 val = dVal + curPower; - if(val <= 0) - { - SetPower(power,0); - return -curPower; - } - - int32 maxPower = (int32)GetMaxPower(power); - - if(val < maxPower) - { - SetPower(power,val); - gain = val - curPower; - } - else if(curPower != maxPower) - { - SetPower(power,maxPower); - gain = maxPower - curPower; - } - - return gain; -} - -bool Unit::isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList) const -{ - if(!u) - return false; - return u->canSeeOrDetect(this, detect, inVisibleList); -} - -bool Unit::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList) const -{ - return true; -} - -bool Unit::canDetectInvisibilityOf(Unit const* u) const -{ - if(m_invisibilityMask & u->m_invisibilityMask) // same group - return true; - AuraList const& auras = GetAurasByType(SPELL_AURA_MOD_STALKED); // Hunter mark - for(AuraList::const_iterator iter = auras.begin(); iter != auras.end(); ++iter) - if((*iter)->GetCasterGUID()==u->GetGUID()) - return true; - - if(uint32 mask = (m_detectInvisibilityMask & u->m_invisibilityMask)) - { - for(uint32 i = 0; i < 10; ++i) - { - if(((1 << i) & mask)==0) - continue; - - // find invisibility level - uint32 invLevel = 0; - Unit::AuraList const& iAuras = u->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY); - for(Unit::AuraList::const_iterator itr = iAuras.begin(); itr != iAuras.end(); ++itr) - if(((*itr)->GetModifier()->m_miscvalue)==i && invLevel < (*itr)->GetModifier()->m_amount) - invLevel = (*itr)->GetModifier()->m_amount; - - // find invisibility detect level - uint32 detectLevel = 0; - if(i==6 && GetTypeId()==TYPEID_PLAYER) // special drunk detection case - { - detectLevel = ((Player*)this)->GetDrunkValue(); - } - else - { - Unit::AuraList const& dAuras = GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION); - for(Unit::AuraList::const_iterator itr = dAuras.begin(); itr != dAuras.end(); ++itr) - if(((*itr)->GetModifier()->m_miscvalue)==i && detectLevel < (*itr)->GetModifier()->m_amount) - detectLevel = (*itr)->GetModifier()->m_amount; - } - - if(invLevel <= detectLevel) - return true; - } - } - - return false; -} - -bool Unit::canDetectStealthOf(Unit const* target, float distance) const -{ - if(hasUnitState(UNIT_STAT_STUNNED)) - return false; - if(distance < 0.24f) //collision - return true; - if(!HasInArc(M_PI, target)) //behind - return false; - if(HasAuraType(SPELL_AURA_DETECT_STEALTH)) - return true; - - //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5) - float visibleDistance = 10.5f - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH) / 100.0f; - //Visible distance is modified by -Level Diff (every level diff = 1.0f in visible distance) - visibleDistance += int32(getLevelForTarget(target)) - int32(target->getLevelForTarget(this)); - //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia) - //based on wowwiki every 5 mod we have 1 more level diff in calculation - visibleDistance += (float)(GetTotalAuraModifier(SPELL_AURA_MOD_DETECT) - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL)) / 5.0f; - - return distance < visibleDistance; -} - -void Unit::SetVisibility(UnitVisibility x) -{ - m_Visibility = x; - - if(IsInWorld()) - { - Map *m = MapManager::Instance().GetMap(GetMapId(), this); - - if(GetTypeId()==TYPEID_PLAYER) - m->PlayerRelocation((Player*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); - else - m->CreatureRelocation((Creature*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); - } -} - -void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) -{ - int32 main_speed_mod = 0; - float stack_bonus = 1.0f; - float non_stack_bonus = 1.0f; - - switch(mtype) - { - case MOVE_WALK: - return; - case MOVE_RUN: - { - if (IsMounted()) // Use on mount auras - { - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED); - stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS); - non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK))/100.0f; - } - else - { - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED); - stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS); - non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK))/100.0f; - } - break; - } - case MOVE_WALKBACK: - return; - case MOVE_SWIM: - { - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED); - break; - } - case MOVE_SWIMBACK: - return; - case MOVE_FLY: - { - if (IsMounted()) // Use on mount auras - main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED); - else // Use not mount (shapeshift for example) auras (should stack) - main_speed_mod = GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT); - stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS); - non_stack_bonus = (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK))/100.0f; - break; - } - case MOVE_FLYBACK: - return; - default: - sLog.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype); - return; - } - - float bonus = non_stack_bonus > stack_bonus ? non_stack_bonus : stack_bonus; - // now we ready for speed calculation - float speed = main_speed_mod ? bonus*(100.0f + main_speed_mod)/100.0f : bonus; - - switch(mtype) - { - case MOVE_RUN: - case MOVE_SWIM: - case MOVE_FLY: - { - // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need - // TODO: possible affect only on MOVE_RUN - if(int32 normalization = GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED)) - { - // Use speed from aura - float max_speed = normalization / baseMoveSpeed[mtype]; - if (speed > max_speed) - speed = max_speed; - } - break; - } - default: - break; - } - - // Apply strongest slow aura mod to speed - int32 slow = GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED); - if (slow) - speed *=(100.0f + slow)/100.0f; - SetSpeed(mtype, speed, forced); -} - -float Unit::GetSpeed( UnitMoveType mtype ) const -{ - return m_speed_rate[mtype]*baseMoveSpeed[mtype]; -} - -void Unit::SetSpeed(UnitMoveType mtype, float rate, bool forced) -{ - if (rate < 0) - rate = 0.0f; - - // Update speed only on change - if (m_speed_rate[mtype] == rate) - return; - - m_speed_rate[mtype] = rate; - - propagateSpeedChange(); - - // Send speed change packet only for player - if (GetTypeId()!=TYPEID_PLAYER) - return; - - WorldPacket data; - if(!forced) - { - switch(mtype) - { - case MOVE_WALK: - data.Initialize(MSG_MOVE_SET_WALK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_RUN: - data.Initialize(MSG_MOVE_SET_RUN_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_WALKBACK: - data.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_SWIM: - data.Initialize(MSG_MOVE_SET_SWIM_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_SWIMBACK: - data.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_TURN: - data.Initialize(MSG_MOVE_SET_TURN_RATE, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_FLY: - data.Initialize(MSG_MOVE_SET_FLIGHT_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - case MOVE_FLYBACK: - data.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); - break; - default: - sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); - return; - } - - data.append(GetPackGUID()); - data << uint32(0); //movement flags - data << uint8(0); //unk - data << uint32(getMSTime()); - data << float(GetPositionX()); - data << float(GetPositionY()); - data << float(GetPositionZ()); - data << float(GetOrientation()); - data << uint32(0); //flag unk - data << float(GetSpeed(mtype)); - SendMessageToSet( &data, true ); - } - else - { - // register forced speed changes for WorldSession::HandleForceSpeedChangeAck - // and do it only for real sent packets and use run for run/mounted as client expected - ++((Player*)this)->m_forced_speed_changes[mtype]; - switch(mtype) - { - case MOVE_WALK: - data.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE, 16); - break; - case MOVE_RUN: - data.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE, 17); - break; - case MOVE_WALKBACK: - data.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE, 16); - break; - case MOVE_SWIM: - data.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE, 16); - break; - case MOVE_SWIMBACK: - data.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE, 16); - break; - case MOVE_TURN: - data.Initialize(SMSG_FORCE_TURN_RATE_CHANGE, 16); - break; - case MOVE_FLY: - data.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE, 16); - break; - case MOVE_FLYBACK: - data.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE, 16); - break; - default: - sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); - return; - } - data.append(GetPackGUID()); - data << (uint32)0; - if (mtype == MOVE_RUN) - data << uint8(0); // new 2.1.0 - data << float(GetSpeed(mtype)); - SendMessageToSet( &data, true ); - } - if(Pet* pet = GetPet()) - pet->SetSpeed(MOVE_RUN, m_speed_rate[mtype],forced); -} - -void Unit::SetHover(bool on) -{ - if(on) - CastSpell(this,11010,true); - else - RemoveAurasDueToSpell(11010); -} - -void Unit::setDeathState(DeathState s) -{ - if (s != ALIVE && s!= JUST_ALIVED) - { - CombatStop(); - DeleteThreatList(); - ClearComboPointHolders(); // any combo points pointed to unit lost at it death - - if(IsNonMeleeSpellCasted(false)) - InterruptNonMeleeSpells(false); - } - - if (s == JUST_DIED) - { - RemoveAllAurasOnDeath(); - UnsummonAllTotems(); - - // Possessed unit died, restore control to possessor - UnpossessSelf(false); - RemoveAllFromVision(); - - ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, false); - ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, false); - // remove aurastates allowing special moves - ClearAllReactives(); - ClearDiminishings(); - } - else if(s == JUST_ALIVED) - { - RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); // clear skinnable for creature and player (at battleground) - } - - if (m_deathState != ALIVE && s == ALIVE) - { - //_ApplyAllAuraMods(); - } - m_deathState = s; -} - -/*######################################## -######## ######## -######## AGGRO SYSTEM ######## -######## ######## -########################################*/ -bool Unit::CanHaveThreatList() const -{ - // only creatures can have threat list - if( GetTypeId() != TYPEID_UNIT ) - return false; - - // only alive units can have threat list - if( !isAlive() ) - return false; - - // pets and totems can not have threat list - if( ((Creature*)this)->isPet() || ((Creature*)this)->isTotem() ) - return false; - - return true; -} - -//====================================================================== - -float Unit::ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask) -{ - if(!HasAuraType(SPELL_AURA_MOD_THREAT)) - return threat; - - SpellSchools school = GetFirstSchoolInMask(schoolMask); - - return threat * m_threatModifier[school]; -} - -//====================================================================== - -void Unit::AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask, SpellEntry const *threatSpell) -{ - // Only mobs can manage threat lists - if(CanHaveThreatList()) - m_ThreatManager.addThreat(pVictim, threat, schoolMask, threatSpell); -} - -//====================================================================== - -void Unit::DeleteThreatList() -{ - m_ThreatManager.clearReferences(); -} - -//====================================================================== - -void Unit::TauntApply(Unit* taunter) -{ - assert(GetTypeId()== TYPEID_UNIT); - - if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) - return; - - if(!CanHaveThreatList()) - return; - - Unit *target = getVictim(); - if(target && target == taunter) - return; - - SetInFront(taunter); - if (((Creature*)this)->AI()) - ((Creature*)this)->AI()->AttackStart(taunter); - - m_ThreatManager.tauntApply(taunter); -} - -//====================================================================== - -void Unit::TauntFadeOut(Unit *taunter) -{ - assert(GetTypeId()== TYPEID_UNIT); - - if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) - return; - - if(!CanHaveThreatList()) - return; - - Unit *target = getVictim(); - if(!target || target != taunter) - return; - - if(m_ThreatManager.isThreatListEmpty()) - { - if(((Creature*)this)->AI()) - ((Creature*)this)->AI()->EnterEvadeMode(); - return; - } - - m_ThreatManager.tauntFadeOut(taunter); - target = m_ThreatManager.getHostilTarget(); - - if (target && target != taunter) - { - SetInFront(target); - if (((Creature*)this)->AI()) - ((Creature*)this)->AI()->AttackStart(target); - } -} - -//====================================================================== - -bool Unit::SelectHostilTarget() -{ - //function provides main threat functionality - //next-victim-selection algorithm and evade mode are called - //threat list sorting etc. - - assert(GetTypeId()== TYPEID_UNIT); - Unit* target = NULL; - - //This function only useful once AI has been initialized - if (!((Creature*)this)->AI()) - return false; - - if(!m_ThreatManager.isThreatListEmpty()) - { - if(!HasAuraType(SPELL_AURA_MOD_TAUNT)) - { - target = m_ThreatManager.getHostilTarget(); - } - } - - if(target) - { - if(!hasUnitState(UNIT_STAT_STUNNED)) - SetInFront(target); - ((Creature*)this)->AI()->AttackStart(target); - return true; - } - - // no target but something prevent go to evade mode - if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT) ) - return false; - - // last case when creature don't must go to evade mode: - // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list - // for example at owner command to pet attack some far away creature - // Note: creature not have targeted movement generator but have attacker in this case - if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE ) - { - for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr) - { - if( (*itr)->IsInMap(this) && canAttack(*itr) && (*itr)->isInAccessiblePlaceFor((Creature*)this) ) - return false; - } - } - - // enter in evade mode in other case - ((Creature*)this)->AI()->EnterEvadeMode(); - - return false; -} - -//====================================================================== -//====================================================================== -//====================================================================== - -int32 Unit::CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 effBasePoints, Unit const* target) -{ - Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; - - uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; - - int32 level = int32(getLevel()) - int32(spellProto->spellLevel); - if (level > spellProto->maxLevel && spellProto->maxLevel > 0) - level = spellProto->maxLevel; - - float basePointsPerLevel = spellProto->EffectRealPointsPerLevel[effect_index]; - float randomPointsPerLevel = spellProto->EffectDicePerLevel[effect_index]; - int32 basePoints = int32(effBasePoints + level * basePointsPerLevel); - int32 randomPoints = int32(spellProto->EffectDieSides[effect_index] + level * randomPointsPerLevel); - float comboDamage = spellProto->EffectPointsPerComboPoint[effect_index]; - - // prevent random generator from getting confused by spells casted with Unit::CastCustomSpell - int32 randvalue = spellProto->EffectBaseDice[effect_index] >= randomPoints ? spellProto->EffectBaseDice[effect_index]:irand(spellProto->EffectBaseDice[effect_index], randomPoints); - int32 value = basePoints + randvalue; - //random damage - if(comboDamage != 0 && unitPlayer && target && (target->GetGUID() == unitPlayer->GetComboTarget())) - value += (int32)(comboDamage * comboPoints); - - if(Player* modOwner = GetSpellModOwner()) - { - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_ALL_EFFECTS, value); - switch(effect_index) - { - case 0: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT1, value); - break; - case 1: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT2, value); - break; - case 2: - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT3, value); - break; - } - } - - if(spellProto->Attributes & SPELL_ATTR_LEVEL_DAMAGE_CALCULATION && spellProto->spellLevel && - spellProto->Effect[effect_index] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE && - spellProto->Effect[effect_index] != SPELL_EFFECT_KNOCK_BACK) - value = int32(value*0.25f*exp(getLevel()*(70-spellProto->spellLevel)/1000.0f)); - - return value; -} - -int32 Unit::CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target) -{ - Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; - - uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; - - int32 minduration = GetSpellDuration(spellProto); - int32 maxduration = GetSpellMaxDuration(spellProto); - - int32 duration; - - if( minduration != -1 && minduration != maxduration ) - duration = minduration + int32((maxduration - minduration) * comboPoints / 5); - else - duration = minduration; - - if (duration > 0) - { - int32 mechanic = GetEffectMechanic(spellProto, effect_index); - // Find total mod value (negative bonus) - int32 durationMod_always = target->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD, mechanic); - // Find max mod (negative bonus) - int32 durationMod_not_stack = target->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK, mechanic); - - int32 durationMod = 0; - // Select strongest negative mod - if (durationMod_always > durationMod_not_stack) - durationMod = durationMod_not_stack; - else - durationMod = durationMod_always; - - if (durationMod != 0) - duration = int32(int64(duration) * (100+durationMod) /100); - - if (duration < 0) duration = 0; - } - - return duration; -} - -DiminishingLevels Unit::GetDiminishing(DiminishingGroup group) -{ - for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) - { - if(i->DRGroup != group) - continue; - - if(!i->hitCount) - return DIMINISHING_LEVEL_1; - - if(!i->hitTime) - return DIMINISHING_LEVEL_1; - - // If last spell was casted more than 15 seconds ago - reset the count. - if(i->stack==0 && getMSTimeDiff(i->hitTime,getMSTime()) > 15000) - { - i->hitCount = DIMINISHING_LEVEL_1; - return DIMINISHING_LEVEL_1; - } - // or else increase the count. - else - { - return DiminishingLevels(i->hitCount); - } - } - return DIMINISHING_LEVEL_1; -} - -void Unit::IncrDiminishing(DiminishingGroup group) -{ - // Checking for existing in the table - bool IsExist = false; - for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) - { - if(i->DRGroup != group) - continue; - - IsExist = true; - if(i->hitCount < DIMINISHING_LEVEL_IMMUNE) - i->hitCount += 1; - - break; - } - - if(!IsExist) - m_Diminishing.push_back(DiminishingReturn(group,getMSTime(),DIMINISHING_LEVEL_2)); -} - -void Unit::ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster,DiminishingLevels Level) -{ - if(duration == -1 || group == DIMINISHING_NONE || caster->IsFriendlyTo(this) ) - return; - - // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0) - if(duration > 10000 && IsDiminishingReturnsGroupDurationLimited(group)) - { - // test pet/charm masters instead pets/charmeds - Unit const* targetOwner = GetCharmerOrOwner(); - Unit const* casterOwner = caster->GetCharmerOrOwner(); - - Unit const* target = targetOwner ? targetOwner : this; - Unit const* source = casterOwner ? casterOwner : caster; - - if(target->GetTypeId() == TYPEID_PLAYER && source->GetTypeId() == TYPEID_PLAYER) - duration = 10000; - } - - float mod = 1.0f; - - // Some diminishings applies to mobs too (for example, Stun) - if((GetDiminishingReturnsGroupType(group) == DRTYPE_PLAYER && GetTypeId() == TYPEID_PLAYER) || GetDiminishingReturnsGroupType(group) == DRTYPE_ALL) - { - DiminishingLevels diminish = Level; - switch(diminish) - { - case DIMINISHING_LEVEL_1: break; - case DIMINISHING_LEVEL_2: mod = 0.5f; break; - case DIMINISHING_LEVEL_3: mod = 0.25f; break; - case DIMINISHING_LEVEL_IMMUNE: mod = 0.0f;break; - default: break; - } - } - - duration = int32(duration * mod); -} - -void Unit::ApplyDiminishingAura( DiminishingGroup group, bool apply ) -{ - // Checking for existing in the table - for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) - { - if(i->DRGroup != group) - continue; - - i->hitTime = getMSTime(); - - if(apply) - i->stack += 1; - else if(i->stack) - i->stack -= 1; - - break; - } -} - -Unit* Unit::GetUnit(WorldObject& object, uint64 guid) -{ - return ObjectAccessor::GetUnit(object,guid); -} - -bool Unit::isVisibleForInState( Player const* u, bool inVisibleList ) const -{ - return isVisibleForOrDetect(u,false,inVisibleList); -} - -uint32 Unit::GetCreatureType() const -{ - if(GetTypeId() == TYPEID_PLAYER) - { - SpellShapeshiftEntry const* ssEntry = sSpellShapeshiftStore.LookupEntry(((Player*)this)->m_form); - if(ssEntry && ssEntry->creatureType > 0) - return ssEntry->creatureType; - else - return CREATURE_TYPE_HUMANOID; - } - else - return ((Creature*)this)->GetCreatureInfo()->type; -} - -/*####################################### -######## ######## -######## STAT SYSTEM ######## -######## ######## -#######################################*/ - -bool Unit::HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply) -{ - if(unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) - { - sLog.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!"); - return false; - } - - float val = 1.0f; - - switch(modifierType) - { - case BASE_VALUE: - case TOTAL_VALUE: - m_auraModifiersGroup[unitMod][modifierType] += apply ? amount : -amount; - break; - case BASE_PCT: - case TOTAL_PCT: - if(amount <= -100.0f) //small hack-fix for -100% modifiers - amount = -200.0f; - - val = (100.0f + amount) / 100.0f; - m_auraModifiersGroup[unitMod][modifierType] *= apply ? val : (1.0f/val); - break; - - default: - break; - } - - if(!CanModifyStats()) - return false; - - switch(unitMod) - { - case UNIT_MOD_STAT_STRENGTH: - case UNIT_MOD_STAT_AGILITY: - case UNIT_MOD_STAT_STAMINA: - case UNIT_MOD_STAT_INTELLECT: - case UNIT_MOD_STAT_SPIRIT: UpdateStats(GetStatByAuraGroup(unitMod)); break; - - case UNIT_MOD_ARMOR: UpdateArmor(); break; - case UNIT_MOD_HEALTH: UpdateMaxHealth(); break; - - case UNIT_MOD_MANA: - case UNIT_MOD_RAGE: - case UNIT_MOD_FOCUS: - case UNIT_MOD_ENERGY: - case UNIT_MOD_HAPPINESS: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod)); break; - - case UNIT_MOD_RESISTANCE_HOLY: - case UNIT_MOD_RESISTANCE_FIRE: - case UNIT_MOD_RESISTANCE_NATURE: - case UNIT_MOD_RESISTANCE_FROST: - case UNIT_MOD_RESISTANCE_SHADOW: - case UNIT_MOD_RESISTANCE_ARCANE: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod)); break; - - case UNIT_MOD_ATTACK_POWER: UpdateAttackPowerAndDamage(); break; - case UNIT_MOD_ATTACK_POWER_RANGED: UpdateAttackPowerAndDamage(true); break; - - case UNIT_MOD_DAMAGE_MAINHAND: UpdateDamagePhysical(BASE_ATTACK); break; - case UNIT_MOD_DAMAGE_OFFHAND: UpdateDamagePhysical(OFF_ATTACK); break; - case UNIT_MOD_DAMAGE_RANGED: UpdateDamagePhysical(RANGED_ATTACK); break; - - default: - break; - } - - return true; -} - -float Unit::GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const -{ - if( unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) - { - sLog.outError("ERROR: trial to access non existed modifier value from UnitMods!"); - return 0.0f; - } - - if(modifierType == TOTAL_PCT && m_auraModifiersGroup[unitMod][modifierType] <= 0.0f) - return 0.0f; - - return m_auraModifiersGroup[unitMod][modifierType]; -} - -float Unit::GetTotalStatValue(Stats stat) const -{ - UnitMods unitMod = UnitMods(UNIT_MOD_STAT_START + stat); - - if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) - return 0.0f; - - // value = ((base_value * base_pct) + total_value) * total_pct - float value = m_auraModifiersGroup[unitMod][BASE_VALUE] + GetCreateStat(stat); - value *= m_auraModifiersGroup[unitMod][BASE_PCT]; - value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; - value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; - - return value; -} - -float Unit::GetTotalAuraModValue(UnitMods unitMod) const -{ - if(unitMod >= UNIT_MOD_END) - { - sLog.outError("ERROR: trial to access non existed UnitMods in GetTotalAuraModValue()!"); - return 0.0f; - } - - if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) - return 0.0f; - - float value = m_auraModifiersGroup[unitMod][BASE_VALUE]; - value *= m_auraModifiersGroup[unitMod][BASE_PCT]; - value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; - value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; - - return value; -} - -SpellSchools Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod) const -{ - SpellSchools school = SPELL_SCHOOL_NORMAL; - - switch(unitMod) - { - case UNIT_MOD_RESISTANCE_HOLY: school = SPELL_SCHOOL_HOLY; break; - case UNIT_MOD_RESISTANCE_FIRE: school = SPELL_SCHOOL_FIRE; break; - case UNIT_MOD_RESISTANCE_NATURE: school = SPELL_SCHOOL_NATURE; break; - case UNIT_MOD_RESISTANCE_FROST: school = SPELL_SCHOOL_FROST; break; - case UNIT_MOD_RESISTANCE_SHADOW: school = SPELL_SCHOOL_SHADOW; break; - case UNIT_MOD_RESISTANCE_ARCANE: school = SPELL_SCHOOL_ARCANE; break; - - default: - break; - } - - return school; -} - -Stats Unit::GetStatByAuraGroup(UnitMods unitMod) const -{ - Stats stat = STAT_STRENGTH; - - switch(unitMod) - { - case UNIT_MOD_STAT_STRENGTH: stat = STAT_STRENGTH; break; - case UNIT_MOD_STAT_AGILITY: stat = STAT_AGILITY; break; - case UNIT_MOD_STAT_STAMINA: stat = STAT_STAMINA; break; - case UNIT_MOD_STAT_INTELLECT: stat = STAT_INTELLECT; break; - case UNIT_MOD_STAT_SPIRIT: stat = STAT_SPIRIT; break; - - default: - break; - } - - return stat; -} - -Powers Unit::GetPowerTypeByAuraGroup(UnitMods unitMod) const -{ - Powers power = POWER_MANA; - - switch(unitMod) - { - case UNIT_MOD_MANA: power = POWER_MANA; break; - case UNIT_MOD_RAGE: power = POWER_RAGE; break; - case UNIT_MOD_FOCUS: power = POWER_FOCUS; break; - case UNIT_MOD_ENERGY: power = POWER_ENERGY; break; - case UNIT_MOD_HAPPINESS: power = POWER_HAPPINESS; break; - - default: - break; - } - - return power; -} - -float Unit::GetTotalAttackPowerValue(WeaponAttackType attType) const -{ - UnitMods unitMod = (attType == RANGED_ATTACK) ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER; - - float val = GetTotalAuraModValue(unitMod); - if(val < 0.0f) - val = 0.0f; - - return val; -} - -float Unit::GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const -{ - if (attType == OFF_ATTACK && !haveOffhandWeapon()) - return 0.0f; - - return m_weaponDamage[attType][type]; -} - -void Unit::SetLevel(uint32 lvl) -{ - SetUInt32Value(UNIT_FIELD_LEVEL, lvl); - - // group update - if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL); -} - -void Unit::SetHealth(uint32 val) -{ - uint32 maxHealth = GetMaxHealth(); - if(maxHealth < val) - val = maxHealth; - - SetUInt32Value(UNIT_FIELD_HEALTH, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP); - } - } -} - -void Unit::SetMaxHealth(uint32 val) -{ - uint32 health = GetHealth(); - SetUInt32Value(UNIT_FIELD_MAXHEALTH, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP); - } - } - - if(val < health) - SetHealth(val); -} - -void Unit::SetPower(Powers power, uint32 val) -{ - uint32 maxPower = GetMaxPower(power); - if(maxPower < val) - val = maxPower; - - SetStatInt32Value(UNIT_FIELD_POWER1 + power, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); - } - - // Update the pet's character sheet with happiness damage bonus - if(pet->getPetType() == HUNTER_PET && power == POWER_HAPPINESS) - { - pet->UpdateDamagePhysical(BASE_ATTACK); - } - } -} - -void Unit::SetMaxPower(Powers power, uint32 val) -{ - uint32 cur_power = GetPower(power); - SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + power, val); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); - } - } - - if(val < cur_power) - SetPower(power, val); -} - -void Unit::ApplyPowerMod(Powers power, uint32 val, bool apply) -{ - ApplyModUInt32Value(UNIT_FIELD_POWER1+power, val, apply); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); - } - } -} - -void Unit::ApplyMaxPowerMod(Powers power, uint32 val, bool apply) -{ - ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1+power, val, apply); - - // group update - if(GetTypeId() == TYPEID_PLAYER) - { - if(((Player*)this)->GetGroup()) - ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); - } - else if(((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); - } - } -} - -void Unit::ApplyAuraProcTriggerDamage( Aura* aura, bool apply ) -{ - AuraList& tAuraProcTriggerDamage = m_modAuras[SPELL_AURA_PROC_TRIGGER_DAMAGE]; - if(apply) - tAuraProcTriggerDamage.push_back(aura); - else - tAuraProcTriggerDamage.remove(aura); -} - -uint32 Unit::GetCreatePowers( Powers power ) const -{ - // POWER_FOCUS and POWER_HAPPINESS only have hunter pet - switch(power) - { - case POWER_MANA: return GetCreateMana(); - case POWER_RAGE: return 1000; - case POWER_FOCUS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 100); - case POWER_ENERGY: return 100; - case POWER_HAPPINESS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 1050000); - } - - return 0; -} - -void Unit::AddToWorld() -{ - WorldObject::AddToWorld(); -} - -void Unit::RemoveFromWorld() -{ - // cleanup - if(IsInWorld()) - { - RemoveNotOwnSingleTargetAuras(); - } - - WorldObject::RemoveFromWorld(); -} - -void Unit::CleanupsBeforeDelete() -{ - if(m_uint32Values) // only for fully created object - { - InterruptNonMeleeSpells(true); - m_Events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList - CombatStop(); - ClearComboPointHolders(); - DeleteThreatList(); - getHostilRefManager().setOnlineOfflineState(false); - RemoveAllAuras(); - RemoveAllGameObjects(); - RemoveAllDynObjects(); - GetMotionMaster()->Clear(false); // remove different non-standard movement generators. - - UnpossessSelf(false); - RemoveAllFromVision(); - } - RemoveFromWorld(); -} - - - -CharmInfo* Unit::InitCharmInfo(Unit *charm) -{ - if(!m_charmInfo) - m_charmInfo = new CharmInfo(charm); - return m_charmInfo; -} - -CharmInfo::CharmInfo(Unit* unit) -: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0) -{ - for(int i =0; i<4; ++i) - { - m_charmspells[i].spellId = 0; - m_charmspells[i].active = ACT_DISABLED; - } -} - -void CharmInfo::InitPetActionBar() -{ - // the first 3 SpellOrActions are attack, follow and stay - for(uint32 i = 0; i < 3; i++) - { - PetActionBar[i].Type = ACT_COMMAND; - PetActionBar[i].SpellOrAction = COMMAND_ATTACK - i; - - PetActionBar[i + 7].Type = ACT_REACTION; - PetActionBar[i + 7].SpellOrAction = COMMAND_ATTACK - i; - } - for(uint32 i=0; i < 4; i++) - { - PetActionBar[i + 3].Type = ACT_DISABLED; - PetActionBar[i + 3].SpellOrAction = 0; - } -} - -void CharmInfo::InitEmptyActionBar() -{ - for(uint32 x = 1; x < 10; ++x) - { - PetActionBar[x].Type = ACT_CAST; - PetActionBar[x].SpellOrAction = 0; - } - PetActionBar[0].Type = ACT_COMMAND; - PetActionBar[0].SpellOrAction = COMMAND_ATTACK; -} - -void CharmInfo::InitPossessCreateSpells() -{ - InitEmptyActionBar(); - if(m_unit->GetTypeId() == TYPEID_UNIT) - { - for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) - { - uint32 spellid = ((Creature*)m_unit)->m_spells[i]; - if(IsPassiveSpell(spellid)) - m_unit->CastSpell(m_unit, spellid, true); - else - AddSpellToAB(0, spellid, ACT_CAST); - } - } -} - -void CharmInfo::InitCharmCreateSpells() -{ - if(m_unit->GetTypeId() == TYPEID_PLAYER) //charmed players don't have spells - { - InitEmptyActionBar(); - return; - } - - InitPetActionBar(); - - for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) - { - uint32 spellId = ((Creature*)m_unit)->m_spells[x]; - m_charmspells[x].spellId = spellId; - - if(!spellId) - continue; - - if (IsPassiveSpell(spellId)) - { - m_unit->CastSpell(m_unit, spellId, true); - m_charmspells[x].active = ACT_PASSIVE; - } - else - { - ActiveStates newstate; - bool onlyselfcast = true; - SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); - - if(!spellInfo) onlyselfcast = false; - for(uint32 i = 0;i<3 && onlyselfcast;++i) //non existent spell will not make any problems as onlyselfcast would be false -> break right away - { - if(spellInfo->EffectImplicitTargetA[i] != TARGET_SELF && spellInfo->EffectImplicitTargetA[i] != 0) - onlyselfcast = false; - } - - if(onlyselfcast || !IsPositiveSpell(spellId)) //only self cast and spells versus enemies are autocastable - newstate = ACT_DISABLED; - else - newstate = ACT_CAST; - - AddSpellToAB(0, spellId, newstate); - } - } -} - -bool CharmInfo::AddSpellToAB(uint32 oldid, uint32 newid, ActiveStates newstate) -{ - for(uint8 i = 0; i < 10; i++) - { - if((PetActionBar[i].Type == ACT_DISABLED || PetActionBar[i].Type == ACT_ENABLED || PetActionBar[i].Type == ACT_CAST) && PetActionBar[i].SpellOrAction == oldid) - { - PetActionBar[i].SpellOrAction = newid; - if(!oldid) - { - if(newstate == ACT_DECIDE) - PetActionBar[i].Type = ACT_DISABLED; - else - PetActionBar[i].Type = newstate; - } - - return true; - } - } - return false; -} - -void CharmInfo::ToggleCreatureAutocast(uint32 spellid, bool apply) -{ - if(IsPassiveSpell(spellid)) - return; - - for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) - { - if(spellid == m_charmspells[x].spellId) - { - m_charmspells[x].active = apply ? ACT_ENABLED : ACT_DISABLED; - } - } -} - -void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow) -{ - m_petnumber = petnumber; - if(statwindow) - m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, m_petnumber); - else - m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0); -} - -bool Unit::isFrozen() const -{ - AuraList const& mRoot = GetAurasByType(SPELL_AURA_MOD_ROOT); - for(AuraList::const_iterator i = mRoot.begin(); i != mRoot.end(); ++i) - if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST) - return true; - return false; -} - -struct ProcTriggeredData -{ - ProcTriggeredData(SpellEntry const * _spellInfo, uint32 _spellParam, Aura* _triggeredByAura, uint32 _cooldown) - : spellInfo(_spellInfo), spellParam(_spellParam), triggeredByAura(_triggeredByAura), - triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura->GetId(),triggeredByAura->GetEffIndex())), - cooldown(_cooldown) - {} - - SpellEntry const * spellInfo; - uint32 spellParam; - Aura* triggeredByAura; - Unit::spellEffectPair triggeredByAura_SpellPair; - uint32 cooldown; -}; - -typedef std::list< ProcTriggeredData > ProcTriggeredList; - -void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, AuraTypeSet const& procAuraTypes, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellSchoolMask damageSchoolMask ) -{ - for(AuraTypeSet::const_iterator aur = procAuraTypes.begin(); aur != procAuraTypes.end(); ++aur) - { - // List of spells (effects) that proceed. Spell prototype and aura-specific value (damage for TRIGGER_DAMAGE) - ProcTriggeredList procTriggered; - - AuraList const& auras = GetAurasByType(*aur); - for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) - { - next = i; ++next; - - SpellEntry const *spellProto = (*i)->GetSpellProto(); - if(!spellProto) - continue; - - SpellProcEventEntry const *spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); - if(!spellProcEvent) - { - // used to prevent spam in log about same non-handled spells - static std::set nonHandledSpellProcSet; - - if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) - { - sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); - nonHandledSpellProcSet.insert(spellProto->Id); - } - - // spell.dbc use totally different flags, that only can create problems if used. - continue; - } - - // Check spellProcEvent data requirements - if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) - continue; - - // Check if current equipment allows aura to proc - if(!isVictim && GetTypeId() == TYPEID_PLAYER ) - { - if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) - { - Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); - - if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) - continue; - } - else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) - { - // Check if player is wearing shield - Item *item = ((Player*)this)->GetShield(true); - if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) - continue; - } - } - - float chance = (float)spellProto->procChance; - - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); - - if(!isVictim && spellProcEvent->ppmRate != 0) - { - uint32 WeaponSpeed = GetAttackTime(attType); - chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); - } - - if(roll_chance_f(chance)) - { - uint32 cooldown = spellProcEvent->cooldown; - - uint32 i_spell_eff = (*i)->GetEffIndex(); - - int32 i_spell_param; - switch(*aur) - { - case SPELL_AURA_PROC_TRIGGER_SPELL: - i_spell_param = procFlag; - break; - case SPELL_AURA_DUMMY: - case SPELL_AURA_PRAYER_OF_MENDING: - case SPELL_AURA_MOD_HASTE: - i_spell_param = i_spell_eff; - break; - case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: - i_spell_param = (*i)->GetModifier()->m_miscvalue; - break; - default: - i_spell_param = (*i)->GetModifier()->m_amount; - break; - } - - procTriggered.push_back( ProcTriggeredData(spellProto,i_spell_param,*i, cooldown) ); - } - } - - // Handle effects proceed this time - for(ProcTriggeredList::iterator i = procTriggered.begin(); i != procTriggered.end(); ++i) - { - // Some auras can be deleted in function called in this loop (except first, ofc) - // Until storing auras in std::multimap to hard check deleting by another way - if(i != procTriggered.begin()) - { - bool found = false; - AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); - AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); - for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) - { - if(itr->second==i->triggeredByAura) - { - found = true; - break; - } - } - - if(!found) - { - sLog.outError("Spell aura %u (id:%u effect:%u) has been deleted before call spell proc event handler",*aur,i->triggeredByAura_SpellPair.first,i->triggeredByAura_SpellPair.second); - sLog.outError("It can be deleted one from early processed auras:"); - for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2) - sLog.outError(" Spell aura %u (id:%u effect:%u)",*aur,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second); - sLog.outError(" "); - continue; - } - } - - // save charges existence before processing to prevent crash at access to deleted triggered aura after - bool triggeredByAuraWithCharges = i->triggeredByAura->m_procCharges > 0; - - bool casted = false; - switch(*aur) - { - case SPELL_AURA_PROC_TRIGGER_SPELL: - { - sLog.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleProcTriggerSpell(pTarget, damage, i->triggeredByAura, procSpell,i->spellParam,attType,i->cooldown); - break; - } - case SPELL_AURA_PROC_TRIGGER_DAMAGE: - { - sLog.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", i->spellParam, i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - uint32 damage = i->spellParam; - SpellNonMeleeDamageLog(pTarget, i->spellInfo->Id, damage, true, true); - casted = true; - break; - } - case SPELL_AURA_DUMMY: - { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleDummyAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); - break; - } - case SPELL_AURA_PRAYER_OF_MENDING: - { - sLog.outDebug("ProcDamageAndSpell(mending): casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - - // aura can be deleted at casts - int32 heal = i->triggeredByAura->GetModifier()->m_amount; - uint64 caster_guid = i->triggeredByAura->GetCasterGUID(); - - // jumps - int32 jumps = i->triggeredByAura->m_procCharges-1; - - // current aura expire - i->triggeredByAura->m_procCharges = 1; // will removed at next charges decrease - - // next target selection - if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) - { - Aura* aura = i->triggeredByAura; - - SpellEntry const* spellProto = aura->GetSpellProto(); - uint32 effIdx = aura->GetEffIndex(); - - float radius; - if (spellProto->EffectRadiusIndex[effIdx]) - radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); - else - radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); - - if(Player* caster = ((Player*)aura->GetCaster())) - { - caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); - - if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) - { - // aura will applied from caster, but spell casted from current aura holder - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_CHARGES; - mod->value = jumps-5; // negative - mod->type = SPELLMOD_FLAT; - mod->spellId = spellProto->Id; - mod->effectId = effIdx; - mod->lastAffected = NULL; - mod->mask = spellProto->SpellFamilyFlags; - mod->charges = 0; - - caster->AddSpellMod(mod, true); - CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,aura,caster->GetGUID()); - caster->AddSpellMod(mod, false); - } - } - } - - // heal - CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); - casted = true; - break; - } - case SPELL_AURA_MOD_HASTE: - { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleHasteAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); - break; - } - case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN: - { - // nothing do, just charges counter - // but count only in case appropriate school damage - casted = i->triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; - break; - } - case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: - { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleOverrideClassScriptAuraProc(pTarget, i->spellParam, damage, i->triggeredByAura, procSpell,i->cooldown); - break; - } - default: - { - // nothing do, just charges counter - casted = true; - break; - } - } - - // Update charge (aura can be removed by triggers) - if(casted && triggeredByAuraWithCharges) - { - // need found aura (can be dropped by triggers) - AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); - AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); - for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) - { - if(itr->second == i->triggeredByAura) - { - if(i->triggeredByAura->m_procCharges > 0) - i->triggeredByAura->m_procCharges -= 1; - - i->triggeredByAura->UpdateAuraCharges(); - break; - } - } - } - } - - // Safely remove auras with zero charges - for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) - { - next = i; ++next; - if((*i)->m_procCharges == 0) - { - RemoveAurasDueToSpell((*i)->GetId()); - next = auras.begin(); - } - } - } -} - -SpellSchoolMask Unit::GetMeleeDamageSchoolMask() const -{ - return SPELL_SCHOOL_MASK_NORMAL; -} - -Player* Unit::GetSpellModOwner() -{ - if(GetTypeId()==TYPEID_PLAYER) - return (Player*)this; - if(((Creature*)this)->isPet() || ((Creature*)this)->isTotem()) - { - Unit* owner = GetOwner(); - if(owner && owner->GetTypeId()==TYPEID_PLAYER) - return (Player*)owner; - } - return NULL; -} - -///----------Pet responses methods----------------- -void Unit::SendPetCastFail(uint32 spellid, uint8 msg) -{ - Unit *owner = GetCharmerOrOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_PET_CAST_FAILED, (4+1)); - data << uint32(spellid); - data << uint8(msg); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetActionFeedback (uint8 msg) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_PET_ACTION_FEEDBACK, 1); - data << uint8(msg); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetTalk (uint32 pettalk) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_PET_ACTION_SOUND, 8+4); - data << uint64(GetGUID()); - data << uint32(pettalk); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetSpellCooldown (uint32 spellid, time_t cooltime) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_SPELL_COOLDOWN, 8+1+4+4); - data << uint64(GetGUID()); - data << uint8(0x0); // flags (0x1, 0x2) - data << uint32(spellid); - data << uint32(cooltime); - - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetClearCooldown (uint32 spellid) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_CLEAR_COOLDOWN, (4+8)); - data << uint32(spellid); - data << uint64(GetGUID()); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -void Unit::SendPetAIReaction(uint64 guid) -{ - Unit* owner = GetOwner(); - if(!owner || owner->GetTypeId() != TYPEID_PLAYER) - return; - - WorldPacket data(SMSG_AI_REACTION, 12); - data << uint64(guid) << uint32(00000002); - ((Player*)owner)->GetSession()->SendPacket(&data); -} - -///----------End of Pet responses methods---------- - -void Unit::StopMoving() -{ - clearUnitState(UNIT_STAT_MOVING); - - // send explicit stop packet - // rely on vmaps here because for example stormwind is in air - float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); - //if (fabs(GetPositionZ() - z) < 2.0f) - // Relocate(GetPositionX(), GetPositionY(), z); - Relocate(GetPositionX(), GetPositionY(),GetPositionZ()); - - SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0); - - // update position and orientation; - WorldPacket data; - BuildHeartBeatMsg(&data); - SendMessageToSet(&data,false); -} - -void Unit::SetFeared(bool apply, uint64 casterGUID, uint32 spellID) -{ - if( apply ) - { - if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING)) - return; - - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); - - GetMotionMaster()->MovementExpired(false); - CastStop(GetGUID()==casterGUID ? spellID : 0); - - Unit* caster = ObjectAccessor::GetUnit(*this,casterGUID); - - GetMotionMaster()->MoveFleeing(caster); // caster==NULL processed in MoveFleeing - } - else - { - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); - - GetMotionMaster()->MovementExpired(false); - - if( GetTypeId() != TYPEID_PLAYER && isAlive() ) - { - // restore appropriate movement generator - if(getVictim()) - GetMotionMaster()->MoveChase(getVictim()); - else - GetMotionMaster()->Initialize(); - - // attack caster if can - Unit* caster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL); - if(caster && caster != getVictim() && ((Creature*)this)->AI()) - ((Creature*)this)->AI()->AttackStart(caster); - } - } - - if (GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SetClientControl(this, !apply); -} - -void Unit::SetConfused(bool apply, uint64 casterGUID, uint32 spellID) -{ - if( apply ) - { - SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); - - CastStop(GetGUID()==casterGUID ? spellID : 0); - - GetMotionMaster()->MoveConfused(); - } - else - { - RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); - - GetMotionMaster()->MovementExpired(false); - - if (GetTypeId() == TYPEID_UNIT) - { - // if in combat restore movement generator - if(getVictim()) - GetMotionMaster()->MoveChase(getVictim()); - } - } - - if(GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->SetClientControl(this, !apply); -} - -bool Unit::IsSitState() const -{ - uint8 s = getStandState(); - return s == PLAYER_STATE_SIT_CHAIR || s == PLAYER_STATE_SIT_LOW_CHAIR || - s == PLAYER_STATE_SIT_MEDIUM_CHAIR || s == PLAYER_STATE_SIT_HIGH_CHAIR || - s == PLAYER_STATE_SIT; -} - -bool Unit::IsStandState() const -{ - uint8 s = getStandState(); - return !IsSitState() && s != PLAYER_STATE_SLEEP && s != PLAYER_STATE_KNEEL; -} - -void Unit::SetStandState(uint8 state) -{ - SetByteValue(UNIT_FIELD_BYTES_1, 0, state); - - if (IsStandState()) - RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED); - - if(GetTypeId()==TYPEID_PLAYER) - { - WorldPacket data(SMSG_STANDSTATE_UPDATE, 1); - data << (uint8)state; - ((Player*)this)->GetSession()->SendPacket(&data); - } -} - -bool Unit::IsPolymorphed() const -{ - return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH; -} - -void Unit::SetDisplayId(uint32 modelId) -{ - SetUInt32Value(UNIT_FIELD_DISPLAYID, modelId); - - if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(!pet->isControlled()) - return; - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID); - } -} - -void Unit::ClearComboPointHolders() -{ - while(!m_ComboPointHolders.empty()) - { - uint32 lowguid = *m_ComboPointHolders.begin(); - - Player* plr = objmgr.GetPlayer(MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); - if(plr && plr->GetComboTarget()==GetGUID()) // recheck for safe - plr->ClearComboPoints(); // remove also guid from m_ComboPointHolders; - else - m_ComboPointHolders.erase(lowguid); // or remove manually - } -} - -void Unit::ClearAllReactives() -{ - - for(int i=0; i < MAX_REACTIVE; ++i) - m_reactiveTimer[i] = 0; - - if (HasAuraState( AURA_STATE_DEFENSE)) - ModifyAuraState(AURA_STATE_DEFENSE, false); - if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_PARRY)) - ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); - if (HasAuraState( AURA_STATE_CRIT)) - ModifyAuraState(AURA_STATE_CRIT, false); - if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_CRIT_STRIKE) ) - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); - - if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->ClearComboPoints(); -} - -void Unit::UpdateReactives( uint32 p_time ) -{ - for(int i = 0; i < MAX_REACTIVE; ++i) - { - ReactiveType reactive = ReactiveType(i); - - if(!m_reactiveTimer[reactive]) - continue; - - if ( m_reactiveTimer[reactive] <= p_time) - { - m_reactiveTimer[reactive] = 0; - - switch ( reactive ) - { - case REACTIVE_DEFENSE: - if (HasAuraState(AURA_STATE_DEFENSE)) - ModifyAuraState(AURA_STATE_DEFENSE, false); - break; - case REACTIVE_HUNTER_PARRY: - if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_PARRY)) - ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); - break; - case REACTIVE_CRIT: - if (HasAuraState(AURA_STATE_CRIT)) - ModifyAuraState(AURA_STATE_CRIT, false); - break; - case REACTIVE_HUNTER_CRIT: - if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_CRIT_STRIKE) ) - ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); - break; - case REACTIVE_OVERPOWER: - if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) - ((Player*)this)->ClearComboPoints(); - break; - default: - break; - } - } - else - { - m_reactiveTimer[reactive] -= p_time; - } - } -} - -Unit* Unit::SelectNearbyTarget() const -{ - CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); - Cell cell(p); - cell.data.Part.reserved = ALL_DISTRICT; - cell.SetNoCreate(); - - std::list targets; - - { - Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); - Trinity::UnitListSearcher searcher(targets, u_check); - - TypeContainerVisitor, WorldTypeMapContainer > world_unit_searcher(searcher); - TypeContainerVisitor, GridTypeMapContainer > grid_unit_searcher(searcher); - - CellLock cell_lock(cell, p); - cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); - cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); - } - - // remove current target - if(getVictim()) - targets.remove(getVictim()); - - // remove not LoS targets - for(std::list::iterator tIter = targets.begin(); tIter != targets.end();) - { - if(!IsWithinLOSInMap(*tIter)) - { - std::list::iterator tIter2 = tIter; - ++tIter; - targets.erase(tIter2); - } - else - ++tIter; - } - - // no appropriate targets - if(targets.empty()) - return NULL; - - // select random - uint32 rIdx = urand(0,targets.size()-1); - std::list::const_iterator tcIter = targets.begin(); - for(uint32 i = 0; i < rIdx; ++i) - ++tcIter; - - return *tcIter; -} - -void Unit::ApplyAttackTimePercentMod( WeaponAttackType att,float val, bool apply ) -{ - float remainingTimePct = (float)m_attackTimer[att] / (GetAttackTime(att) * m_modAttackSpeedPct[att]); - if(val > 0) - { - ApplyPercentModFloatVar(m_modAttackSpeedPct[att], val, !apply); - ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val,!apply); - } - else - { - ApplyPercentModFloatVar(m_modAttackSpeedPct[att], -val, apply); - ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,-val,apply); - } - m_attackTimer[att] = uint32(GetAttackTime(att) * m_modAttackSpeedPct[att] * remainingTimePct); -} - -void Unit::ApplyCastTimePercentMod(float val, bool apply ) -{ - if(val > 0) - ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,val,!apply); - else - ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,-val,apply); -} - -uint32 Unit::GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime ) -{ - if (CastingTime > 7000) CastingTime = 7000; - if (CastingTime < 1500) CastingTime = 1500; - - if(damagetype == DOT && !IsChanneledSpell(spellProto)) - CastingTime = 3500; - - int32 overTime = 0; - uint8 effects = 0; - bool DirectDamage = false; - bool AreaEffect = false; - - for ( uint32 i=0; i<3;i++) - { - switch ( spellProto->Effect[i] ) - { - case SPELL_EFFECT_SCHOOL_DAMAGE: - case SPELL_EFFECT_POWER_DRAIN: - case SPELL_EFFECT_HEALTH_LEECH: - case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE: - case SPELL_EFFECT_POWER_BURN: - case SPELL_EFFECT_HEAL: - DirectDamage = true; - break; - case SPELL_EFFECT_APPLY_AURA: - switch ( spellProto->EffectApplyAuraName[i] ) - { - case SPELL_AURA_PERIODIC_DAMAGE: - case SPELL_AURA_PERIODIC_HEAL: - case SPELL_AURA_PERIODIC_LEECH: - if ( GetSpellDuration(spellProto) ) - overTime = GetSpellDuration(spellProto); - break; - default: - // -5% per additional effect - ++effects; - break; - } - default: - break; - } - - if(IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetA[i])) || IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetB[i]))) - AreaEffect = true; - } - - // Combined Spells with Both Over Time and Direct Damage - if ( overTime > 0 && CastingTime > 0 && DirectDamage ) - { - // mainly for DoTs which are 3500 here otherwise - uint32 OriginalCastTime = GetSpellCastTime(spellProto); - if (OriginalCastTime > 7000) OriginalCastTime = 7000; - if (OriginalCastTime < 1500) OriginalCastTime = 1500; - // Portion to Over Time - float PtOT = (overTime / 15000.f) / ((overTime / 15000.f) + (OriginalCastTime / 3500.f)); - - if ( damagetype == DOT ) - CastingTime = uint32(CastingTime * PtOT); - else if ( PtOT < 1.0f ) - CastingTime = uint32(CastingTime * (1 - PtOT)); - else - CastingTime = 0; - } - - // Area Effect Spells receive only half of bonus - if ( AreaEffect ) - CastingTime /= 2; - - // -5% of total per any additional effect - for ( uint8 i=0; i 175 ) - { - CastingTime -= 175; - } - else - { - CastingTime = 0; - break; - } - } - - return CastingTime; -} - -void Unit::UpdateAuraForGroup(uint8 slot) -{ - if(GetTypeId() == TYPEID_PLAYER) - { - Player* player = (Player*)this; - if(player->GetGroup()) - { - player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS); - player->SetAuraUpdateMask(slot); - } - } - else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) - { - Pet *pet = ((Pet*)this); - if(pet->isControlled()) - { - Unit *owner = GetOwner(); - if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) - { - ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS); - pet->SetAuraUpdateMask(slot); - } - } - } -} - -float Unit::GetAPMultiplier(WeaponAttackType attType, bool normalized) -{ - if (!normalized || GetTypeId() != TYPEID_PLAYER) - return float(GetAttackTime(attType))/1000.0f; - - Item *Weapon = ((Player*)this)->GetWeaponForAttack(attType); - if (!Weapon) - return 2.4; // fist attack - - switch (Weapon->GetProto()->InventoryType) - { - case INVTYPE_2HWEAPON: - return 3.3; - case INVTYPE_RANGED: - case INVTYPE_RANGEDRIGHT: - case INVTYPE_THROWN: - return 2.8; - case INVTYPE_WEAPON: - case INVTYPE_WEAPONMAINHAND: - case INVTYPE_WEAPONOFFHAND: - default: - return Weapon->GetProto()->SubClass==ITEM_SUBCLASS_WEAPON_DAGGER ? 1.7 : 2.4; - } -} - -Aura* Unit::GetDummyAura( uint32 spell_id ) const -{ - Unit::AuraList const& mDummy = GetAurasByType(SPELL_AURA_DUMMY); - for(Unit::AuraList::const_iterator itr = mDummy.begin(); itr != mDummy.end(); ++itr) - if ((*itr)->GetId() == spell_id) - return *itr; - - return NULL; -} - -bool Unit::IsUnderLastManaUseEffect() const -{ - return getMSTimeDiff(m_lastManaUse,getMSTime()) < 5000; -} - -void Unit::SetContestedPvP(Player *attackedPlayer) -{ - Player* player = GetCharmerOrOwnerPlayerOrPlayerItself(); - - if(!player || attackedPlayer && (attackedPlayer == player || player->duel && player->duel->opponent == attackedPlayer)) - return; - - player->SetContestedPvPTimer(30000); - if(!player->hasUnitState(UNIT_STAT_ATTACK_PLAYER)) - { - player->addUnitState(UNIT_STAT_ATTACK_PLAYER); - player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP); - // call MoveInLineOfSight for nearby contested guards - SetVisibility(GetVisibility()); - } - if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER)) - { - addUnitState(UNIT_STAT_ATTACK_PLAYER); - // call MoveInLineOfSight for nearby contested guards - SetVisibility(GetVisibility()); - } -} - -void Unit::AddPetAura(PetAura const* petSpell) -{ - m_petAuras.insert(petSpell); - if(Pet* pet = GetPet()) - pet->CastPetAura(petSpell); -} - -void Unit::RemovePetAura(PetAura const* petSpell) -{ - m_petAuras.erase(petSpell); - if(Pet* pet = GetPet()) - pet->RemoveAurasDueToSpell(petSpell->GetAura(pet->GetEntry())); -} - -Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id) -{ - Pet* pet = new Pet(HUNTER_PET); - - if(!pet->CreateBaseAtCreature(creatureTarget)) - { - delete pet; - return NULL; - } - - pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, this->GetGUID()); - pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, this->GetGUID()); - pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,this->getFaction()); - pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id); - - if(!pet->InitStatsForLevel(creatureTarget->getLevel())) - { - sLog.outError("ERROR: Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget->GetEntry()); - delete pet; - return NULL; - } - - pet->GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true); - // this enables pet details window (Shift+P) - pet->AIM_Initialize(); - pet->InitPetCreateSpells(); - pet->SetHealth(pet->GetMaxHealth()); - - return pet; -} +/* + * Copyright (C) 2005-2008 MaNGOS + * + * Copyright (C) 2008 Trinity + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "Common.h" +#include "Log.h" +#include "Opcodes.h" +#include "WorldPacket.h" +#include "WorldSession.h" +#include "World.h" +#include "ObjectMgr.h" +#include "SpellMgr.h" +#include "Unit.h" +#include "QuestDef.h" +#include "Player.h" +#include "Creature.h" +#include "Spell.h" +#include "Group.h" +#include "SpellAuras.h" +#include "MapManager.h" +#include "ObjectAccessor.h" +#include "CreatureAI.h" +#include "Formulas.h" +#include "Pet.h" +#include "Util.h" +#include "Totem.h" +#include "BattleGround.h" +#include "OutdoorPvP.h" +#include "InstanceSaveMgr.h" +#include "GridNotifiersImpl.h" +#include "CellImpl.h" +#include "Path.h" + +#include + +float baseMoveSpeed[MAX_MOVE_TYPE] = +{ + 2.5f, // MOVE_WALK + 7.0f, // MOVE_RUN + 1.25f, // MOVE_WALKBACK + 4.722222f, // MOVE_SWIM + 4.5f, // MOVE_SWIMBACK + 3.141594f, // MOVE_TURN + 7.0f, // MOVE_FLY + 4.5f, // MOVE_FLYBACK +}; + +// auraTypes contains attacker auras capable of proc'ing cast auras +static Unit::AuraTypeSet GenerateAttakerProcCastAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_DUMMY); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); + auraTypes.insert(SPELL_AURA_MOD_HASTE); + auraTypes.insert(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + return auraTypes; +} + +// auraTypes contains victim auras capable of proc'ing cast auras +static Unit::AuraTypeSet GenerateVictimProcCastAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_DUMMY); + auraTypes.insert(SPELL_AURA_PRAYER_OF_MENDING); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_SPELL); + return auraTypes; +} + +// auraTypes contains auras capable of proc effect/damage (but not cast) for attacker +static Unit::AuraTypeSet GenerateAttakerProcEffectAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_MOD_DAMAGE_DONE); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); + auraTypes.insert(SPELL_AURA_MOD_CASTING_SPEED); + auraTypes.insert(SPELL_AURA_MOD_RATING); + return auraTypes; +} + +// auraTypes contains auras capable of proc effect/damage (but not cast) for victim +static Unit::AuraTypeSet GenerateVictimProcEffectAuraTypes() +{ + static Unit::AuraTypeSet auraTypes; + auraTypes.insert(SPELL_AURA_MOD_RESISTANCE); + auraTypes.insert(SPELL_AURA_PROC_TRIGGER_DAMAGE); + auraTypes.insert(SPELL_AURA_MOD_PARRY_PERCENT); + auraTypes.insert(SPELL_AURA_MOD_BLOCK_PERCENT); + auraTypes.insert(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); + return auraTypes; +} + +static Unit::AuraTypeSet attackerProcCastAuraTypes = GenerateAttakerProcCastAuraTypes(); +static Unit::AuraTypeSet attackerProcEffectAuraTypes = GenerateAttakerProcEffectAuraTypes(); + +static Unit::AuraTypeSet victimProcCastAuraTypes = GenerateVictimProcCastAuraTypes(); +static Unit::AuraTypeSet victimProcEffectAuraTypes = GenerateVictimProcEffectAuraTypes(); + +// auraTypes contains auras capable of proc'ing for attacker and victim +static Unit::AuraTypeSet GenerateProcAuraTypes() +{ + Unit::AuraTypeSet auraTypes; + auraTypes.insert(attackerProcCastAuraTypes.begin(),attackerProcCastAuraTypes.end()); + auraTypes.insert(attackerProcEffectAuraTypes.begin(),attackerProcEffectAuraTypes.end()); + auraTypes.insert(victimProcCastAuraTypes.begin(),victimProcCastAuraTypes.end()); + auraTypes.insert(victimProcEffectAuraTypes.begin(),victimProcEffectAuraTypes.end()); + return auraTypes; +} + +static Unit::AuraTypeSet procAuraTypes = GenerateProcAuraTypes(); + +bool IsPassiveStackableSpell( uint32 spellId ) +{ + if(!IsPassiveSpell(spellId)) + return false; + + SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId); + if(!spellProto) + return false; + + for(int j = 0; j < 3; ++j) + { + if(std::find(procAuraTypes.begin(),procAuraTypes.end(),spellProto->EffectApplyAuraName[j])!=procAuraTypes.end()) + return false; + } + + return true; +} + +Unit::Unit() +: WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) +{ + m_objectType |= TYPEMASK_UNIT; + m_objectTypeId = TYPEID_UNIT; + // 2.3.2 - 0x70 + m_updateFlag = (UPDATEFLAG_HIGHGUID | UPDATEFLAG_LIVING | UPDATEFLAG_HASPOSITION); + + m_attackTimer[BASE_ATTACK] = 0; + m_attackTimer[OFF_ATTACK] = 0; + m_attackTimer[RANGED_ATTACK] = 0; + m_modAttackSpeedPct[BASE_ATTACK] = 1.0f; + m_modAttackSpeedPct[OFF_ATTACK] = 1.0f; + m_modAttackSpeedPct[RANGED_ATTACK] = 1.0f; + + m_extraAttacks = 0; + m_canDualWield = false; + + m_state = 0; + m_form = FORM_NONE; + m_deathState = ALIVE; + + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + m_currentSpells[i] = NULL; + + m_addDmgOnce = 0; + + for(int i = 0; i < MAX_TOTEM; ++i) + m_TotemSlot[i] = 0; + + m_ObjectSlot[0] = m_ObjectSlot[1] = m_ObjectSlot[2] = m_ObjectSlot[3] = 0; + //m_Aura = NULL; + //m_AurasCheck = 2000; + //m_removeAuraTimer = 4; + //tmpAura = NULL; + waterbreath = false; + + m_Visibility = VISIBILITY_ON; + + m_interruptMask = 0; + m_detectInvisibilityMask = 0; + m_invisibilityMask = 0; + m_transform = 0; + m_ShapeShiftFormSpellId = 0; + m_canModifyStats = false; + + for (int i = 0; i < MAX_SPELL_IMMUNITY; i++) + m_spellImmune[i].clear(); + for (int i = 0; i < UNIT_MOD_END; i++) + { + m_auraModifiersGroup[i][BASE_VALUE] = 0.0f; + m_auraModifiersGroup[i][BASE_PCT] = 1.0f; + m_auraModifiersGroup[i][TOTAL_VALUE] = 0.0f; + m_auraModifiersGroup[i][TOTAL_PCT] = 1.0f; + } + // implement 50% base damage from offhand + m_auraModifiersGroup[UNIT_MOD_DAMAGE_OFFHAND][TOTAL_PCT] = 0.5f; + + for (int i = 0; i < 3; i++) + { + m_weaponDamage[i][MINDAMAGE] = BASE_MINDAMAGE; + m_weaponDamage[i][MAXDAMAGE] = BASE_MAXDAMAGE; + } + for (int i = 0; i < MAX_STATS; i++) + m_createStats[i] = 0.0f; + + m_attacking = NULL; + m_modMeleeHitChance = 0.0f; + m_modRangedHitChance = 0.0f; + m_modSpellHitChance = 0.0f; + m_baseSpellCritChance = 5; + + m_CombatTimer = 0; + m_lastManaUse = 0; + + //m_victimThreat = 0.0f; + for (int i = 0; i < MAX_SPELL_SCHOOL; ++i) + m_threatModifier[i] = 1.0f; + m_isSorted = true; + for (int i = 0; i < MAX_MOVE_TYPE; ++i) + m_speed_rate[i] = 1.0f; + + m_removedAuras = 0; + m_charmInfo = NULL; + m_unit_movement_flags = 0; + m_isPossessed = false; + + // remove aurastates allowing special moves + for(int i=0; i < MAX_REACTIVE; ++i) + m_reactiveTimer[i] = 0; +} + +Unit::~Unit() +{ + // set current spells as deletable + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + { + if (m_currentSpells[i]) + { + m_currentSpells[i]->SetReferencedFromCurrent(false); + m_currentSpells[i] = NULL; + } + } + + RemoveAllGameObjects(); + RemoveAllDynObjects(); + + if(m_charmInfo) delete m_charmInfo; +} + +void Unit::Update( uint32 p_time ) +{ + /*if(p_time > m_AurasCheck) + { + m_AurasCheck = 2000; + _UpdateAura(); + }else + m_AurasCheck -= p_time;*/ + + // WARNING! Order of execution here is important, do not change. + // Spells must be processed with event system BEFORE they go to _UpdateSpells. + // Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad. + m_Events.Update( p_time ); + _UpdateSpells( p_time ); + + // update combat timer only for players and pets + if (isInCombat() && (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet() || ((Creature*)this)->isCharmed())) + { + // Check UNIT_STAT_MELEE_ATTACKING or UNIT_STAT_CHASE (without UNIT_STAT_FOLLOW in this case) so pets can reach far away + // targets without stopping half way there and running off. + // These flags are reset after target dies or another command is given. + if( m_HostilRefManager.isEmpty() ) + { + // m_CombatTimer set at aura start and it will be freeze until aura removing + if ( m_CombatTimer <= p_time ) + ClearInCombat(); + else + m_CombatTimer -= p_time; + } + } + + if(!hasUnitState(UNIT_STAT_CASTING)) + { + if(uint32 base_att = getAttackTimer(BASE_ATTACK)) + setAttackTimer(BASE_ATTACK, (p_time >= base_att ? 0 : base_att - p_time) ); + if(uint32 ranged_att = getAttackTimer(RANGED_ATTACK)) + setAttackTimer(RANGED_ATTACK, (p_time >= ranged_att ? 0 : ranged_att - p_time) ); + if(uint32 off_att = getAttackTimer(OFF_ATTACK)) + setAttackTimer(OFF_ATTACK, (p_time >= off_att ? 0 : off_att - p_time) ); + } + + // update abilities available only for fraction of time + UpdateReactives( p_time ); + + ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, GetHealth() < GetMaxHealth()*0.20f); + ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, GetHealth() < GetMaxHealth()*0.35f); + + i_motionMaster.UpdateMotion(p_time); +} + +bool Unit::haveOffhandWeapon() const +{ + if(GetTypeId() == TYPEID_PLAYER) + return ((Player*)this)->GetWeaponForAttack(OFF_ATTACK,true); + else + return m_canDualWield; +} + +void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player* player) +{ + float x, y, z; + if(GetMotionMaster()->GetDestination(x, y, z)) + SendMonsterMoveWithSpeed(x, y, z, GetUnitMovementFlags(), 0, player); +} + +void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime, Player* player) +{ + if (!transitTime) + { + float dx = x - GetPositionX(); + float dy = y - GetPositionY(); + float dz = z - GetPositionZ(); + + float dist = ((dx*dx) + (dy*dy) + (dz*dz)); + if(dist<0) + dist = 0; + else + dist = sqrt(dist); + + double speed = GetSpeed((MovementFlags & MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN); + if(speed<=0) + speed = 2.5f; + speed *= 0.001f; + transitTime = static_cast(dist / speed + 0.5); + } + //float orientation = (float)atan2((double)dy, (double)dx); + SendMonsterMove(x, y, z, 0, MovementFlags, transitTime, player); +} + +void Unit::SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player) +{ + WorldPacket data( SMSG_MONSTER_MOVE, (41 + GetPackGUID().size()) ); + data.append(GetPackGUID()); + + // Point A, starting location + data << GetPositionX() << GetPositionY() << GetPositionZ(); + // unknown field - unrelated to orientation + // seems to increment about 1000 for every 1.7 seconds + // for now, we'll just use mstime + data << getMSTime(); + + data << uint8(type); // unknown + switch(type) + { + case 0: // normal packet + break; + case 1: // stop packet + SendMessageToSet( &data, true ); + return; + case 3: // not used currently + data << uint64(0); // probably target guid + break; + case 4: // not used currently + data << float(0); // probably orientation + break; + } + + //Movement Flags (0x0 = walk, 0x100 = run, 0x200 = fly/swim) + data << uint32(MovementFlags); + + data << Time; // Time in between points + data << uint32(1); // 1 single waypoint + data << NewPosX << NewPosY << NewPosZ; // the single waypoint Point B + + if(player) + player->GetSession()->SendPacket(&data); + else + SendMessageToSet( &data, true ); +} + +void Unit::SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end, uint32 MovementFlags) +{ + uint32 traveltime = uint32(path.GetTotalLength(start, end) * 32); + + uint32 pathSize = end-start; + + WorldPacket data( SMSG_MONSTER_MOVE, (GetPackGUID().size()+4+4+4+4+1+4+4+4+pathSize*4*3) ); + data.append(GetPackGUID()); + data << GetPositionX(); + data << GetPositionY(); + data << GetPositionZ(); + + // unknown field - unrelated to orientation + // seems to increment about 1000 for every 1.7 seconds + // for now, we'll just use mstime + data << getMSTime(); + + data << uint8( 0 ); + data << uint32( MovementFlags ); + data << uint32( traveltime ); + data << uint32( pathSize ); + data.append( (char*)path.GetNodes(start), pathSize * 4 * 3 ); + + //WPAssert( data.size() == 37 + pathnodes.Size( ) * 4 * 3 ); + SendMessageToSet(&data, true); +} + +void Unit::resetAttackTimer(WeaponAttackType type) +{ + m_attackTimer[type] = uint32(GetAttackTime(type) * m_modAttackSpeedPct[type]); +} + +bool Unit::canReachWithAttack(Unit *pVictim) const +{ + assert(pVictim); + return IsWithinDistInMap(pVictim, GetCombatReach()); +} + +bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const +{ + if (!obj || !IsInMap(obj)) return false; + + float dx = GetPositionX() - obj->GetPositionX(); + float dy = GetPositionY() - obj->GetPositionY(); + float dz = GetPositionZ() - obj->GetPositionZ(); + float distsq = dx*dx + dy*dy + dz*dz; + //not sure here, or combatreach + combatreach? + float sizefactor = GetCombatReach() + obj->GetCombatReach(); + float maxdist = dist2compare + sizefactor; + + return distsq < maxdist * maxdist; +} + +void Unit::GetRandomContactPoint( const Unit* obj, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const +{ + //assert(GetCombatReach() > 0.1); + float combat_reach = GetCombatReach(); + if(combat_reach < 0.1) + { + sLog.outError("Unit %u (Type: %u) has invalid combat_reach %f",GetGUIDLow(),GetTypeId(),combat_reach); + if(GetTypeId() == TYPEID_UNIT) + sLog.outError("Creature entry %u has invalid combat_reach", ((Creature*)this)->GetEntry()); + combat_reach = 0.5; + } + uint32 attacker_number = getAttackers().size(); + if(attacker_number > 0) --attacker_number; + GetNearPoint(obj,x,y,z,obj->GetCombatReach(), distance2dMin+(distance2dMax-distance2dMin)*rand_norm() + , GetAngle(obj) + (attacker_number ? (M_PI/2 - M_PI * rand_norm()) * (float)attacker_number / combat_reach / 3 : 0)); +} + +void Unit::RemoveSpellsCausingAura(AuraType auraType) +{ + if (auraType >= TOTAL_AURAS) return; + AuraList::iterator iter, next; + for (iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end(); iter = next) + { + next = iter; + ++next; + + if (*iter) + { + RemoveAurasDueToSpell((*iter)->GetId()); + if (!m_modAuras[auraType].empty()) + next = m_modAuras[auraType].begin(); + else + return; + } + } +} + +void Unit::RemoveAurasWithInterruptFlags(uint32 flag) +{ + if(!(m_interruptMask & flag)) + return; + + // interrupt auras + AuraList::iterator iter, next; + for (iter = m_interruptableAuras.begin(); iter != m_interruptableAuras.end(); iter = next) + { + next = iter; + ++next; + + //sLog.outDetail("auraflag:%u flag:%u = %u",(*iter)->GetSpellProto()->AuraInterruptFlags,flag,(*iter)->GetSpellProto()->AuraInterruptFlags & flag); + if(*iter && ((*iter)->GetSpellProto()->AuraInterruptFlags & flag)) + { + RemoveAurasDueToSpell((*iter)->GetId()); + if (!m_interruptableAuras.empty()) + next = m_interruptableAuras.begin(); + else + break; + } + } + + // interrupt channeled spell + if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) + if(spell->getState() == SPELL_STATE_CASTING && (spell->m_spellInfo->ChannelInterruptFlags & flag)) + InterruptNonMeleeSpells(false); +} + +void Unit::UpdateInterruptMask() +{ + m_interruptMask = 0; + for(AuraList::iterator i = m_interruptableAuras.begin(); i != m_interruptableAuras.end(); ++i) + { + if(*i) + m_interruptMask |= (*i)->GetSpellProto()->AuraInterruptFlags; + } + if(Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) + if(spell->getState() == SPELL_STATE_CASTING) + m_interruptMask |= spell->m_spellInfo->ChannelInterruptFlags; +} + +bool Unit::HasAuraType(AuraType auraType) const +{ + return (!m_modAuras[auraType].empty()); +} + +/* Called by DealDamage for auras that have a chance to be dispelled on damage taken. */ +void Unit::RemoveSpellbyDamageTaken(uint32 damage, uint32 spell) +{ + // The chance to dispel an aura depends on the damage taken with respect to the casters level. + uint32 max_dmg = getLevel() > 8 ? 25 * getLevel() - 150 : 50; + float chance = float(damage) / max_dmg * 100.0f; + + AuraList::iterator i, next; + for(i = m_ccAuras.begin(); i != m_ccAuras.end(); i = next) + { + next = i; + ++next; + + if(*i && (!spell || (*i)->GetId() != spell) && roll_chance_f(chance)) + { + RemoveAurasDueToSpell((*i)->GetId()); + if (!m_ccAuras.empty()) + next = m_ccAuras.begin(); + else + return; + } + } +} + +uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDamage, DamageEffectType damagetype, SpellSchoolMask damageSchoolMask, SpellEntry const *spellProto, bool durabilityLoss) +{ + if (!pVictim->isAlive() || pVictim->isInFlight() || pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) + return 0; + + //You don't lose health from damage taken from another player while in a sanctuary + //You still see it in the combat log though + if(pVictim != this && GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) + { + const AreaTableEntry *area = GetAreaEntryByAreaID(pVictim->GetAreaId()); + if(area && area->flags & AREA_FLAG_SANCTUARY) //sanctuary + return 0; + } + + //Script Event damage taken + if( pVictim->GetTypeId()== TYPEID_UNIT && ((Creature *)pVictim)->AI() ) + ((Creature *)pVictim)->AI()->DamageTaken(this, damage); + + if(!damage) //when will zero damage? need interrupt aura? + { + // Rage from physical damage received . + if(cleanDamage && cleanDamage->damage && (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) && pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) + ((Player*)pVictim)->RewardRage(cleanDamage->damage, 0, false); + + return 0; + } + + if(pVictim->GetTypeId() != TYPEID_PLAYER) + { + // no xp,health if type 8 /critters/ + if ( pVictim->GetCreatureType() == CREATURE_TYPE_CRITTER) + { + // critters run away when hit + pVictim->GetMotionMaster()->MoveFleeing(this); + + // allow loot only if has loot_id in creature_template + if(damage >= pVictim->GetHealth()) + { + pVictim->setDeathState(JUST_DIED); + pVictim->SetHealth(0); + + CreatureInfo const* cInfo = ((Creature*)pVictim)->GetCreatureInfo(); + if(cInfo && cInfo->lootid) + pVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); + + // some critters required for quests + if(GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->KilledMonster(pVictim->GetEntry(),pVictim->GetGUID()); + } + else + pVictim->ModifyHealth(- (int32)damage); + + return damage; + } + } + + DEBUG_LOG("DealDamageStart"); + + uint32 health = pVictim->GetHealth(); + sLog.outDetail("deal dmg:%d to health:%d ",damage,health); + + // duel ends when player has 1 or less hp + bool duel_hasEnded = false; + if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->duel && damage >= (health-1)) + { + // prevent kill only if killed in duel and killed by opponent or opponent controlled creature + if(((Player*)pVictim)->duel->opponent==this || ((Player*)pVictim)->duel->opponent->GetGUID() == GetOwnerGUID()) + damage = health-1; + + duel_hasEnded = true; + } + + // Rage from Damage made (only from direct weapon damage) + if( cleanDamage && damagetype==DIRECT_DAMAGE && this != pVictim && GetTypeId() == TYPEID_PLAYER && (getPowerType() == POWER_RAGE)) + { + uint32 weaponSpeedHitFactor; + + switch(cleanDamage->attackType) + { + case BASE_ATTACK: + { + if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 7); + else + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); + + ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); + + break; + } + case OFF_ATTACK: + { + if(cleanDamage->hitOutCome == MELEE_HIT_CRIT) + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 3.5f); + else + weaponSpeedHitFactor = uint32(GetAttackTime(cleanDamage->attackType)/1000.0f * 1.75f); + + ((Player*)this)->RewardRage(damage, weaponSpeedHitFactor, true); + + break; + } + case RANGED_ATTACK: + break; + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER && GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)pVictim)->InBattleGround()) + { + Player *killer = ((Player*)this); + if(killer != ((Player*)pVictim)) + if(BattleGround *bg = killer->GetBattleGround()) + bg->UpdatePlayerScore(killer, SCORE_DAMAGE_DONE, damage); + } + } + + if (pVictim->GetTypeId() == TYPEID_UNIT && !((Creature*)pVictim)->isPet() && !((Creature*)pVictim)->hasLootRecipient()) + ((Creature*)pVictim)->SetLootRecipient(this); + if (health <= damage) + { + DEBUG_LOG("DealDamage: victim just died"); + + // find player: owner of controlled `this` or `this` itself maybe + Player *player = GetCharmerOrOwnerPlayerOrPlayerItself(); + + if(pVictim->GetTypeId() == TYPEID_UNIT && ((Creature*)pVictim)->GetLootRecipient()) + player = ((Creature*)pVictim)->GetLootRecipient(); + // Reward player, his pets, and group/raid members + // call kill spell proc event (before real die and combat stop to triggering auras removed at death/combat stop) + if(player && player!=pVictim) + if(player->RewardPlayerAndGroupAtKill(pVictim)) + player->ProcDamageAndSpell(pVictim,PROC_FLAG_KILL_XP_GIVER,PROC_FLAG_NONE); + + DEBUG_LOG("DealDamageAttackStop"); + + // stop combat + pVictim->CombatStop(); + pVictim->getHostilRefManager().deleteReferences(); + + // stop movement + pVictim->StopMoving(); + + bool damageFromSpiritOfRedemtionTalent = spellProto && spellProto->Id == 27795; + + // if talent known but not triggered (check priest class for speedup check) + Aura* spiritOfRedemtionTalentReady = NULL; + if( !damageFromSpiritOfRedemtionTalent && // not called from SPELL_AURA_SPIRIT_OF_REDEMPTION + pVictim->GetTypeId()==TYPEID_PLAYER && pVictim->getClass()==CLASS_PRIEST ) + { + AuraList const& vDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator itr = vDummyAuras.begin(); itr != vDummyAuras.end(); ++itr) + { + if((*itr)->GetSpellProto()->SpellIconID==1654) + { + spiritOfRedemtionTalentReady = *itr; + break; + } + } + } + + DEBUG_LOG("SET JUST_DIED"); + if(!spiritOfRedemtionTalentReady) + pVictim->setDeathState(JUST_DIED); + + // outdoor pvp things, do these after setting the death state, else the player activity notify won't work... doh... + // handle player kill only if not suicide (spirit of redemption for example) + if(GetTypeId() == TYPEID_PLAYER && this != pVictim) + { + if(OutdoorPvP * pvp = ((Player*)this)->GetOutdoorPvP()) + { + pvp->HandleKill((Player*)this,pVictim); + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + if(OutdoorPvP * pvp = ((Player*)pVictim)->GetOutdoorPvP()) + { + pvp->HandlePlayerActivityChanged((Player*)pVictim); + } + } + + DEBUG_LOG("DealDamageHealth1"); + + if(spiritOfRedemtionTalentReady) + { + // save value before aura remove + uint32 ressSpellId = pVictim->GetUInt32Value(PLAYER_SELF_RES_SPELL); + if(!ressSpellId) + ressSpellId = ((Player*)pVictim)->GetResurrectionSpellId(); + + //Remove all expected to remove at death auras (most important negative case like DoT or periodic triggers) + pVictim->RemoveAllAurasOnDeath(); + + // restore for use at real death + pVictim->SetUInt32Value(PLAYER_SELF_RES_SPELL,ressSpellId); + + // FORM_SPIRITOFREDEMPTION and related auras + pVictim->CastSpell(pVictim,27827,true,NULL,spiritOfRedemtionTalentReady); + } + else + pVictim->SetHealth(0); + + // remember victim PvP death for corpse type and corpse reclaim delay + // at original death (not at SpiritOfRedemtionTalent timeout) + if( pVictim->GetTypeId()==TYPEID_PLAYER && !damageFromSpiritOfRedemtionTalent ) + ((Player*)pVictim)->SetPvPDeath(player!=NULL); + + // 10% durability loss on death + // clean InHateListOf + if (pVictim->GetTypeId() == TYPEID_PLAYER) + { + // only if not player and not controlled by player pet. And not at BG + if (durabilityLoss && !player && !((Player*)pVictim)->InBattleGround()) + { + DEBUG_LOG("We are dead, loosing 10 percents durability"); + ((Player*)pVictim)->DurabilityLossAll(0.10f,false); + // durability lost message + WorldPacket data(SMSG_DURABILITY_DAMAGE_DEATH, 0); + ((Player*)pVictim)->GetSession()->SendPacket(&data); + } + // Call KilledUnit for creatures + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->KilledUnit(pVictim); + } + else // creature died + { + DEBUG_LOG("DealDamageNotPlayer"); + Creature *cVictim = (Creature*)pVictim; + + if(!cVictim->isPet()) + { + cVictim->DeleteThreatList(); + cVictim->SetUInt32Value(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE); + } + + // Call KilledUnit for creatures, this needs to be called after the lootable flag is set + if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->KilledUnit(pVictim); + + // Call creature just died function + if (cVictim->AI()) + cVictim->AI()->JustDied(this); + + // Dungeon specific stuff, only applies to players killing creatures + if(cVictim->GetInstanceId()) + { + Map *m = cVictim->GetMap(); + Player *creditedPlayer = GetCharmerOrOwnerPlayerOrPlayerItself(); + // TODO: do instance binding anyway if the charmer/owner is offline + + if(m->IsDungeon() && creditedPlayer) + { + if(m->IsRaid() || m->IsHeroic()) + { + if(cVictim->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND) + ((InstanceMap *)m)->PermBindAllPlayers(creditedPlayer); + } + else + { + // the reset time is set but not added to the scheduler + // until the players leave the instance + time_t resettime = cVictim->GetRespawnTimeEx() + 2 * HOUR; + if(InstanceSave *save = sInstanceSaveManager.GetInstanceSave(cVictim->GetInstanceId())) + if(save->GetResetTime() < resettime) save->SetResetTime(resettime); + } + } + } + } + + // last damage from non duel opponent or opponent controlled creature + if(duel_hasEnded) + { + assert(pVictim->GetTypeId()==TYPEID_PLAYER); + Player *he = (Player*)pVictim; + + assert(he->duel); + + he->duel->opponent->CombatStopWithPets(true); + he->CombatStopWithPets(true); + + he->DuelComplete(DUEL_INTERUPTED); + } + + // battleground things (do this at the end, so the death state flag will be properly set to handle in the bg->handlekill) + if(pVictim->GetTypeId() == TYPEID_PLAYER && (((Player*)pVictim)->InBattleGround())) + { + Player *killed = ((Player*)pVictim); + Player *killer = NULL; + if(GetTypeId() == TYPEID_PLAYER) + killer = ((Player*)this); + else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) + { + Unit *owner = GetOwner(); + if(owner && owner->GetTypeId() == TYPEID_PLAYER) + killer = ((Player*)owner); + } + + if(killer) + if(BattleGround *bg = killed->GetBattleGround()) + bg->HandleKillPlayer(killed, killer); // drop flags and etc + } + } + else // if (health <= damage) + { + DEBUG_LOG("DealDamageAlive"); + + pVictim->ModifyHealth(- (int32)damage); + + // Check if health is below 20% (apply damage before to prevent case when after ProcDamageAndSpell health < damage + if(pVictim->GetHealth()*5 < pVictim->GetMaxHealth()) + { + uint32 procVictim = PROC_FLAG_NONE; + + // if just dropped below 20% (for CheatDeath) + if((pVictim->GetHealth()+damage)*5 > pVictim->GetMaxHealth()) + procVictim = PROC_FLAG_LOW_HEALTH; + + ProcDamageAndSpell(pVictim,PROC_FLAG_TARGET_LOW_HEALTH,procVictim); + } + + if(damagetype != DOT) + { + if(getVictim()) + { + // if have target and damage pVictim just call AI reaction + if(pVictim != getVictim() && pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->AI()) + ((Creature*)pVictim)->AI()->AttackedBy(this); + } + else + { + // if not have main target then attack state with target (including AI call) + //start melee attacks only after melee hit + Attack(pVictim,(damagetype == DIRECT_DAMAGE)); + } + } + + if(damagetype == DIRECT_DAMAGE|| damagetype == SPELL_DIRECT_DAMAGE) + pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DIRECT_DAMAGE); + + if (pVictim->GetTypeId() != TYPEID_PLAYER) + { + if(spellProto && IsDamageToThreatSpell(spellProto)) + pVictim->AddThreat(this, damage*2, damageSchoolMask, spellProto); + else + pVictim->AddThreat(this, damage, damageSchoolMask, spellProto); + } + else // victim is a player + { + // Rage from damage received + if(this != pVictim && pVictim->getPowerType() == POWER_RAGE) + { + uint32 rage_damage = damage + (cleanDamage ? cleanDamage->damage : 0); + ((Player*)pVictim)->RewardRage(rage_damage, 0, false); + } + + // random durability for items (HIT TAKEN) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) + { + EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(slot); + } + } + + if(GetTypeId()==TYPEID_PLAYER) + { + // random durability for items (HIT DONE) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_DAMAGE))) + { + EquipmentSlots slot = EquipmentSlots(urand(0,EQUIPMENT_SLOT_END-1)); + ((Player*)this)->DurabilityPointLossForEquipSlot(slot); + } + } + + if (damagetype != NODAMAGE && damage)// && pVictim->GetTypeId() == TYPEID_PLAYER) + { + //if (se->procFlags & (1<<3)) + pVictim->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_DAMAGE); + pVictim->RemoveSpellbyDamageTaken(damage, spellProto ? spellProto->Id : 0); + + if(pVictim != this && pVictim->GetTypeId() == TYPEID_PLAYER) // does not support creature push_back + { + if(damagetype != DOT) + { + if(Spell* spell = pVictim->m_currentSpells[CURRENT_GENERIC_SPELL]) + { + if(spell->getState() == SPELL_STATE_PREPARING) + { + uint32 interruptFlags = spell->m_spellInfo->InterruptFlags; + if(interruptFlags & SPELL_INTERRUPT_FLAG_DAMAGE) + pVictim->InterruptNonMeleeSpells(false); + else if(interruptFlags & SPELL_INTERRUPT_FLAG_PUSH_BACK) + spell->Delayed(); + } + } + } + + if(Spell* spell = pVictim->m_currentSpells[CURRENT_CHANNELED_SPELL]) + { + if(spell->getState() == SPELL_STATE_CASTING) + { + uint32 channelInterruptFlags = spell->m_spellInfo->ChannelInterruptFlags; + if( channelInterruptFlags & CHANNEL_FLAG_DELAY ) + spell->DelayedChannel(); + } + } + } + } + + // last damage from duel opponent + if(duel_hasEnded) + { + assert(pVictim->GetTypeId()==TYPEID_PLAYER); + Player *he = (Player*)pVictim; + + assert(he->duel); + + he->SetHealth(1); + + he->duel->opponent->CombatStopWithPets(true); + he->CombatStopWithPets(true); + + he->CastSpell(he, 7267, true); // beg + he->DuelComplete(DUEL_WON); + } + } + + DEBUG_LOG("DealDamageEnd returned %d damage", damage); + + return damage; +} + +void Unit::CastStop(uint32 except_spellid) +{ + for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) + if (m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id!=except_spellid) + InterruptSpell(i,false); +} + +void Unit::CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); + + if(!spellInfo) + { + sLog.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + CastSpell(Victim,spellInfo,triggered,castItem,triggeredByAura, originalCaster); +} + +void Unit::CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + assert(Victim); + if(!spellInfo) + { + sLog.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + if (castItem) + DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); + + if(!originalCaster && triggeredByAura) + originalCaster = triggeredByAura->GetCasterGUID(); + + Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); + + SpellCastTargets targets; + targets.setUnitTarget( Victim ); + targets.setDestination( Victim->GetPositionX(), Victim->GetPositionY(), Victim->GetPositionZ(), false); + spell->m_CastItem = castItem; + spell->prepare(&targets, triggeredByAura); +} + +void Unit::CastCustomSpell(Unit* Victim,uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); + + if(!spellInfo) + { + sLog.outError("CastCustomSpell: unknown spell id %i\n", spellId); + return; + } + + CastCustomSpell(Victim,spellInfo,bp0,bp1,bp2,triggered,castItem,triggeredByAura, originalCaster); +} + +void Unit::CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + if(!spellInfo) + { + sLog.outError("CastCustomSpell: unknown spell"); + return; + } + + if (castItem) + DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); + + if(!originalCaster && triggeredByAura) + originalCaster = triggeredByAura->GetCasterGUID(); + + Spell *spell = new Spell(this, spellInfo, triggered, originalCaster); + + if(bp0) + spell->m_currentBasePoints[0] = *bp0-int32(spellInfo->EffectBaseDice[0]); + + if(bp1) + spell->m_currentBasePoints[1] = *bp1-int32(spellInfo->EffectBaseDice[1]); + + if(bp2) + spell->m_currentBasePoints[2] = *bp2-int32(spellInfo->EffectBaseDice[2]); + + SpellCastTargets targets; + targets.setUnitTarget( Victim ); + spell->m_CastItem = castItem; + spell->prepare(&targets, triggeredByAura); +} + +// used for scripting +void Unit::CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId ); + + if(!spellInfo) + { + sLog.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + CastSpell(x, y, z,spellInfo,triggered,castItem,triggeredByAura, originalCaster); +} + +// used for scripting +void Unit::CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) +{ + if(!spellInfo) + { + sLog.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); + return; + } + + if (castItem) + DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); + + if(!originalCaster && triggeredByAura) + originalCaster = triggeredByAura->GetCasterGUID(); + + Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); + + SpellCastTargets targets; + targets.setDestination(x, y, z); + spell->m_CastItem = castItem; + spell->prepare(&targets, triggeredByAura); +} + +void Unit::DealFlatDamage(Unit *pVictim, SpellEntry const *spellInfo, uint32 *damage, CleanDamage *cleanDamage, bool *crit, bool isTriggeredSpell) +{ + // TODO this in only generic way, check for exceptions + DEBUG_LOG("DealFlatDamage (BEFORE) >> DMG:%u", *damage); + + // Per-damage class calculation + switch (spellInfo->DmgClass) + { + // Melee and Ranged Spells + case SPELL_DAMAGE_CLASS_RANGED: + case SPELL_DAMAGE_CLASS_MELEE: + { + // Calculate physical outcome + MeleeHitOutcome outcome = RollPhysicalOutcomeAgainst(pVictim, BASE_ATTACK, spellInfo); + + //Used to store the Hit Outcome + cleanDamage->hitOutCome = outcome; + + // Return miss/evade first (sends miss message) + switch(outcome) + { + case MELEE_HIT_EVADE: + { + SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_EVADES,0); + *damage = 0; + return; + } + case MELEE_HIT_MISS: + { + SendAttackStateUpdate(HITINFO_MISS, pVictim, 1, GetSpellSchoolMask(spellInfo), 0, 0,0,VICTIMSTATE_NORMAL,0); + *damage = 0; + + if(GetTypeId()== TYPEID_PLAYER) + ((Player*)this)->UpdateWeaponSkill(BASE_ATTACK); + + CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,MELEE_HIT_MISS,spellInfo,isTriggeredSpell); + return; + } + } + + // Hitinfo, Victimstate + uint32 hitInfo = HITINFO_NORMALSWING; + VictimState victimState = VICTIMSTATE_NORMAL; + + // Physical Damage + if ( GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NORMAL ) + { + uint32 modDamage=*damage; + + // apply spellmod to Done damage + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_DAMAGE, *damage); + + //Calculate armor mitigation + uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); + + // random durability for main hand weapon (ABSORB) + if(damageAfterArmor < *damage) + if(pVictim->GetTypeId() == TYPEID_PLAYER) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); + + cleanDamage->damage += *damage - damageAfterArmor; + *damage = damageAfterArmor; + } + // Magical Damage + else + { + // Calculate damage bonus + *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); + } + + // Classify outcome + switch (outcome) + { + case MELEE_HIT_BLOCK_CRIT: + case MELEE_HIT_CRIT: + { + uint32 bonusDmg = *damage; + + // Apply crit_damage bonus + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRIT_DAMAGE_BONUS, bonusDmg); + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + bonusDmg = uint32(bonusDmg * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); + + *damage += bonusDmg; + + // Resilience - reduce crit damage + if (pVictim->GetTypeId()==TYPEID_PLAYER) + { + uint32 resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); + cleanDamage->damage += resilienceReduction; + *damage -= resilienceReduction; + } + + *crit = true; + hitInfo |= HITINFO_CRITICALHIT; + + ModifyAuraState(AURA_STATE_CRIT, true); + StartReactiveTimer( REACTIVE_CRIT ); + + if(getClass()==CLASS_HUNTER) + { + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); + StartReactiveTimer( REACTIVE_HUNTER_CRIT ); + } + + if ( outcome == MELEE_HIT_BLOCK_CRIT ) + { + uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); + if (blocked_amount >= *damage) + { + hitInfo |= HITINFO_SWINGNOHITSOUND; + victimState = VICTIMSTATE_BLOCKS; + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + } + else + { + // To Help Calculate Rage + cleanDamage->damage += blocked_amount; + *damage = *damage - blocked_amount; + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + } + break; + } + case MELEE_HIT_PARRY: + { + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + victimState = VICTIMSTATE_PARRY; + + // Counter-attack ( explained in Unit::DoAttackDamage() ) + if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY_HASTEN) ) + { + // Get attack timers + float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); + float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); + + // Reduce attack time + if (pVictim->haveOffhandWeapon() && offtime < basetime) + { + float percent20 = pVictim->GetAttackTime(OFF_ATTACK) * 0.20; + float percent60 = 3 * percent20; + if(offtime > percent20 && offtime <= percent60) + { + pVictim->setAttackTimer(OFF_ATTACK, uint32(percent20)); + } + else if(offtime > percent60) + { + offtime -= 2 * percent20; + pVictim->setAttackTimer(OFF_ATTACK, uint32(offtime)); + } + } + else + { + float percent20 = pVictim->GetAttackTime(BASE_ATTACK) * 0.20; + float percent60 = 3 * percent20; + if(basetime > percent20 && basetime <= percent60) + { + pVictim->setAttackTimer(BASE_ATTACK, uint32(percent20)); + } + else if(basetime > percent60) + { + basetime -= 2 * percent20; + pVictim->setAttackTimer(BASE_ATTACK, uint32(basetime)); + } + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update victim defense ? + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (PARRY) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); + } + + // Set parry flags + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + // Mongoose bite - set only Counterattack here + if (pVictim->getClass() == CLASS_HUNTER) + { + pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); + pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); + } + else + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + break; + } + case MELEE_HIT_DODGE: + { + if(pVictim->GetTypeId() == TYPEID_PLAYER) + ((Player*)pVictim)->UpdateDefense(); + + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + hitInfo |= HITINFO_SWINGNOHITSOUND; + victimState = VICTIMSTATE_DODGE; + + // Set dodge flags + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + // Overpower + if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) + { + ((Player*)this)->AddComboPoints(pVictim, 1); + StartReactiveTimer( REACTIVE_OVERPOWER ); + } + + // Riposte + if (pVictim->getClass() != CLASS_ROGUE) + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + break; + } + case MELEE_HIT_BLOCK: + { + uint32 blocked_amount = uint32(pVictim->GetShieldBlockValue()); + if (blocked_amount >= *damage) + { + hitInfo |= HITINFO_SWINGNOHITSOUND; + victimState = VICTIMSTATE_BLOCKS; + cleanDamage->damage += *damage; // To Help Calculate Rage + *damage = 0; + } + else + { + // To Help Calculate Rage + cleanDamage->damage += blocked_amount; + *damage = *damage - blocked_amount; + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + break; + } + case MELEE_HIT_EVADE: // already processed early + case MELEE_HIT_MISS: // already processed early + case MELEE_HIT_GLANCING: + case MELEE_HIT_CRUSHING: + case MELEE_HIT_NORMAL: + break; + } + + // do all damage=0 cases here + if(*damage == 0) + CastMeleeProcDamageAndSpell(pVictim,0,GetSpellSchoolMask(spellInfo),BASE_ATTACK,outcome,spellInfo,isTriggeredSpell); + + break; + } + // Magical Attacks + case SPELL_DAMAGE_CLASS_NONE: + case SPELL_DAMAGE_CLASS_MAGIC: + { + // Calculate damage bonus + *damage = SpellDamageBonus(pVictim, spellInfo, *damage, SPELL_DIRECT_DAMAGE); + + *crit = isSpellCrit(pVictim, spellInfo, GetSpellSchoolMask(spellInfo), BASE_ATTACK); + if (*crit) + { + *damage = SpellCriticalBonus(spellInfo, *damage, pVictim); + + // Resilience - reduce crit damage + if (pVictim && pVictim->GetTypeId()==TYPEID_PLAYER) + { + uint32 damage_reduction = ((Player *)pVictim)->GetSpellCritDamageReduction(*damage); + if(*damage > damage_reduction) + *damage -= damage_reduction; + else + *damage = 0; + } + + cleanDamage->hitOutCome = MELEE_HIT_CRIT; + } + // spell proc all magic damage==0 case in this function + if(*damage == 0) + { + // Procflags + uint32 procAttacker = PROC_FLAG_HIT_SPELL; + uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); + + ProcDamageAndSpell(pVictim, procAttacker, procVictim, 0, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); + } + + break; + } + } + + // TODO this in only generic way, check for exceptions + DEBUG_LOG("DealFlatDamage (AFTER) >> DMG:%u", *damage); +} + +uint32 Unit::SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell, bool useSpellDamage) +{ + if(!this || !pVictim) + return 0; + if(!this->isAlive() || !pVictim->isAlive()) + return 0; + + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellID); + if(!spellInfo) + return 0; + + CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL); + bool crit = false; + + if (useSpellDamage) + DealFlatDamage(pVictim, spellInfo, &damage, &cleanDamage, &crit, isTriggeredSpell); + + // If we actually dealt some damage (spell proc's for 0 damage (normal and magic) called in DealFlatDamage) + if(damage > 0) + { + // Calculate absorb & resists + uint32 absorb = 0; + uint32 resist = 0; + + CalcAbsorbResist(pVictim,GetSpellSchoolMask(spellInfo), SPELL_DIRECT_DAMAGE, damage, &absorb, &resist); + + //No more damage left, target absorbed and/or resisted all damage + if (damage > absorb + resist) + damage -= absorb + resist; //Remove Absorbed and Resisted from damage actually dealt + else + { + uint32 HitInfo = HITINFO_SWINGNOHITSOUND; + + if (absorb) + HitInfo |= HITINFO_ABSORB; + if (resist) + { + HitInfo |= HITINFO_RESIST; + ProcDamageAndSpell(pVictim, PROC_FLAG_TARGET_RESISTS, PROC_FLAG_RESIST_SPELL, 0, GetSpellSchoolMask(spellInfo), spellInfo,isTriggeredSpell); + } + + //Send resist + SendAttackStateUpdate(HitInfo, pVictim, 1, GetSpellSchoolMask(spellInfo), damage, absorb,resist,VICTIMSTATE_NORMAL,0); + return 0; + } + + // Deal damage done + damage = DealDamage(pVictim, damage, &cleanDamage, SPELL_DIRECT_DAMAGE, GetSpellSchoolMask(spellInfo), spellInfo, true); + + // Send damage log + sLog.outDetail("SpellNonMeleeDamageLog: %u (TypeId: %u) attacked %u (TypeId: %u) for %u dmg inflicted by %u,absorb is %u,resist is %u", + GetGUIDLow(), GetTypeId(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, spellID, absorb,resist); + + // Actual log sent to client + SendSpellNonMeleeDamageLog(pVictim, spellID, damage, GetSpellSchoolMask(spellInfo), absorb, resist, false, 0, crit); + + // Procflags + uint32 procAttacker = PROC_FLAG_HIT_SPELL; + uint32 procVictim = (PROC_FLAG_STRUCK_SPELL|PROC_FLAG_TAKE_DAMAGE); + + if (crit) + { + procAttacker |= PROC_FLAG_CRIT_SPELL; + procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; + } + + ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, GetSpellSchoolMask(spellInfo), spellInfo, isTriggeredSpell); + + return damage; + } + else + { + // all spell proc for 0 normal and magic damage called in DealFlatDamage + + //Check for rage + if(cleanDamage.damage) + // Rage from damage received. + if(pVictim->GetTypeId() == TYPEID_PLAYER && (pVictim->getPowerType() == POWER_RAGE)) + ((Player*)pVictim)->RewardRage(cleanDamage.damage, 0, false); + + return 0; + } +} + +void Unit::HandleEmoteCommand(uint32 anim_id) +{ + WorldPacket data( SMSG_EMOTE, 12 ); + data << anim_id << GetGUID(); + WPAssert(data.size() == 12); + + SendMessageToSet(&data, true); +} + +uint32 Unit::CalcArmorReducedDamage(Unit* pVictim, const uint32 damage) +{ + uint32 newdamage = 0; + float armor = pVictim->GetArmor(); + // Ignore enemy armor by SPELL_AURA_MOD_TARGET_RESISTANCE aura + armor += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, SPELL_SCHOOL_MASK_NORMAL); + + if (armor<0.0f) armor=0.0f; + + float tmpvalue = 0.0f; + if(getLevel() <= 59) //Level 1-59 + tmpvalue = armor / (armor + 400.0f + 85.0f * getLevel()); + else if(getLevel() < 70) //Level 60-69 + tmpvalue = armor / (armor - 22167.5f + 467.5f * getLevel()); + else //Level 70+ + tmpvalue = armor / (armor + 10557.5f); + + if(tmpvalue < 0.0f) + tmpvalue = 0.0f; + if(tmpvalue > 0.75f) + tmpvalue = 0.75f; + newdamage = uint32(damage - (damage * tmpvalue)); + + return (newdamage > 1) ? newdamage : 1; +} + +void Unit::CalcAbsorbResist(Unit *pVictim,SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist) +{ + if(!pVictim || !pVictim->isAlive() || !damage) + return; + + // Magic damage, check for resists + if ((schoolMask & SPELL_SCHOOL_MASK_NORMAL)==0) + { + // Get base victim resistance for school + float tmpvalue2 = (float)pVictim->GetResistance(GetFirstSchoolInMask(schoolMask)); + // Ignore resistance by self SPELL_AURA_MOD_TARGET_RESISTANCE aura + tmpvalue2 += (float)GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask); + + tmpvalue2 *= (float)(0.15f / getLevel()); + if (tmpvalue2 < 0.0f) + tmpvalue2 = 0.0f; + if (tmpvalue2 > 0.75f) + tmpvalue2 = 0.75f; + uint32 ran = urand(0, 100); + uint32 faq[4] = {24,6,4,6}; + uint8 m = 0; + float Binom = 0.0f; + for (uint8 i = 0; i < 4; i++) + { + Binom += 2400 *( powf(tmpvalue2, i) * powf( (1-tmpvalue2), (4-i)))/faq[i]; + if (ran > Binom ) + ++m; + else + break; + } + if (damagetype == DOT && m == 4) + *resist += uint32(damage - 1); + else + *resist += uint32(damage * m / 4); + if(*resist > damage) + *resist = damage; + } + else + *resist = 0; + + int32 RemainingDamage = damage - *resist; + + // absorb without mana cost + int32 reflectDamage = 0; + Aura* reflectAura = NULL; + AuraList const& vSchoolAbsorb = pVictim->GetAurasByType(SPELL_AURA_SCHOOL_ABSORB); + for(AuraList::const_iterator i = vSchoolAbsorb.begin(), next; i != vSchoolAbsorb.end() && RemainingDamage > 0; i = next) + { + next = i; ++next; + + if (((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + // Cheat Death + if((*i)->GetSpellProto()->SpellFamilyName==SPELLFAMILY_ROGUE && (*i)->GetSpellProto()->SpellIconID == 2109) + { + if (((Player*)pVictim)->HasSpellCooldown(31231)) + continue; + if (pVictim->GetHealth() <= RemainingDamage) + { + int32 chance = (*i)->GetModifier()->m_amount; + if (roll_chance_i(chance)) + { + pVictim->CastSpell(pVictim,31231,true); + ((Player*)pVictim)->AddSpellCooldown(31231,0,time(NULL)+60); + + // with health > 10% lost health until health==10%, in other case no losses + uint32 health10 = pVictim->GetMaxHealth()/10; + RemainingDamage = pVictim->GetHealth() > health10 ? pVictim->GetHealth() - health10 : 0; + } + } + continue; + } + + int32 currentAbsorb; + + //Reflective Shield + if ((pVictim != this) && (*i)->GetSpellProto()->SpellFamilyName == SPELLFAMILY_PRIEST && (*i)->GetSpellProto()->SpellFamilyFlags == 0x1) + { + if(Unit* caster = (*i)->GetCaster()) + { + AuraList const& vOverRideCS = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator k = vOverRideCS.begin(); k != vOverRideCS.end(); ++k) + { + switch((*k)->GetModifier()->m_miscvalue) + { + case 5065: // Rank 1 + case 5064: // Rank 2 + case 5063: // Rank 3 + case 5062: // Rank 4 + case 5061: // Rank 5 + { + if(RemainingDamage >= (*i)->GetModifier()->m_amount) + reflectDamage = (*i)->GetModifier()->m_amount * (*k)->GetModifier()->m_amount/100; + else + reflectDamage = (*k)->GetModifier()->m_amount * RemainingDamage/100; + reflectAura = *i; + + } break; + default: break; + } + + if(reflectDamage) + break; + } + } + } + + if (RemainingDamage >= (*i)->GetModifier()->m_amount) + { + currentAbsorb = (*i)->GetModifier()->m_amount; + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + next = vSchoolAbsorb.begin(); + } + else + { + currentAbsorb = RemainingDamage; + (*i)->GetModifier()->m_amount -= RemainingDamage; + } + + RemainingDamage -= currentAbsorb; + } + // do not cast spells while looping auras; auras can get invalid otherwise + if (reflectDamage) + pVictim->CastCustomSpell(this, 33619, &reflectDamage, NULL, NULL, true, NULL, reflectAura); + + // absorb by mana cost + AuraList const& vManaShield = pVictim->GetAurasByType(SPELL_AURA_MANA_SHIELD); + for(AuraList::const_iterator i = vManaShield.begin(), next; i != vManaShield.end() && RemainingDamage > 0; i = next) + { + next = i; ++next; + + // check damage school mask + if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + int32 currentAbsorb; + if (RemainingDamage >= (*i)->GetModifier()->m_amount) + currentAbsorb = (*i)->GetModifier()->m_amount; + else + currentAbsorb = RemainingDamage; + + float manaMultiplier = (*i)->GetSpellProto()->EffectMultipleValue[(*i)->GetEffIndex()]; + if(Player *modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod((*i)->GetId(), SPELLMOD_MULTIPLE_VALUE, manaMultiplier); + + int32 maxAbsorb = int32(pVictim->GetPower(POWER_MANA) / manaMultiplier); + if (currentAbsorb > maxAbsorb) + currentAbsorb = maxAbsorb; + + (*i)->GetModifier()->m_amount -= currentAbsorb; + if((*i)->GetModifier()->m_amount <= 0) + { + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + next = vManaShield.begin(); + } + + int32 manaReduction = int32(currentAbsorb * manaMultiplier); + pVictim->ApplyPowerMod(POWER_MANA, manaReduction, false); + + RemainingDamage -= currentAbsorb; + } + + // only split damage if not damaging yourself + if(pVictim != this) + { + AuraList const& vSplitDamageFlat = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_FLAT); + for(AuraList::const_iterator i = vSplitDamageFlat.begin(), next; i != vSplitDamageFlat.end() && RemainingDamage >= 0; i = next) + { + next = i; ++next; + + // check damage school mask + if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + // Damage can be splitted only if aura has an alive caster + Unit *caster = (*i)->GetCaster(); + if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) + continue; + + int32 currentAbsorb; + if (RemainingDamage >= (*i)->GetModifier()->m_amount) + currentAbsorb = (*i)->GetModifier()->m_amount; + else + currentAbsorb = RemainingDamage; + + RemainingDamage -= currentAbsorb; + + SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, currentAbsorb, schoolMask, 0, 0, false, 0, false); + + CleanDamage cleanDamage = CleanDamage(currentAbsorb, BASE_ATTACK, MELEE_HIT_NORMAL); + DealDamage(caster, currentAbsorb, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); + } + + AuraList const& vSplitDamagePct = pVictim->GetAurasByType(SPELL_AURA_SPLIT_DAMAGE_PCT); + for(AuraList::const_iterator i = vSplitDamagePct.begin(), next; i != vSplitDamagePct.end() && RemainingDamage >= 0; i = next) + { + next = i; ++next; + + // check damage school mask + if(((*i)->GetModifier()->m_miscvalue & schoolMask)==0) + continue; + + // Damage can be splitted only if aura has an alive caster + Unit *caster = (*i)->GetCaster(); + if(!caster || caster == pVictim || !caster->IsInWorld() || !caster->isAlive()) + continue; + + int32 splitted = int32(RemainingDamage * (*i)->GetModifier()->m_amount / 100.0f); + + RemainingDamage -= splitted; + + SendSpellNonMeleeDamageLog(caster, (*i)->GetSpellProto()->Id, splitted, schoolMask, 0, 0, false, 0, false); + + CleanDamage cleanDamage = CleanDamage(splitted, BASE_ATTACK, MELEE_HIT_NORMAL); + DealDamage(caster, splitted, &cleanDamage, DIRECT_DAMAGE, schoolMask, (*i)->GetSpellProto(), false); + } + } + + *absorb = damage - RemainingDamage - *resist; +} + +void Unit::DoAttackDamage (Unit *pVictim, uint32 *damage, CleanDamage *cleanDamage, uint32 *blocked_amount, SpellSchoolMask damageSchoolMask, uint32 *hitInfo, VictimState *victimState, uint32 *absorbDamage, uint32 *resistDamage, WeaponAttackType attType, SpellEntry const *spellCasted, bool isTriggeredSpell) +{ + MeleeHitOutcome outcome; + + // If is casted Melee spell, calculate like physical + if(!spellCasted) + outcome = RollMeleeOutcomeAgainst (pVictim, attType); + else + outcome = RollPhysicalOutcomeAgainst (pVictim, attType, spellCasted); + + if(outcome == MELEE_HIT_MISS ||outcome == MELEE_HIT_DODGE ||outcome == MELEE_HIT_BLOCK ||outcome == MELEE_HIT_PARRY) + pVictim->AddThreat(this, 0.0f); + switch(outcome) + { + case MELEE_HIT_EVADE: + { + *hitInfo |= HITINFO_MISS; + *damage = 0; + cleanDamage->damage = 0; + return; + } + case MELEE_HIT_MISS: + { + *hitInfo |= HITINFO_MISS; + *damage = 0; + cleanDamage->damage = 0; + if(GetTypeId()== TYPEID_PLAYER) + ((Player*)this)->UpdateWeaponSkill(attType); + return; + } + } + + /// If this is a creature and it attacks from behind it has a probability to daze it's victim + if( (outcome==MELEE_HIT_CRIT || outcome==MELEE_HIT_CRUSHING || outcome==MELEE_HIT_NORMAL || outcome==MELEE_HIT_GLANCING) && + GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGUID() && !pVictim->HasInArc(M_PI, this) + && pVictim->GetTypeId() == TYPEID_PLAYER) + { + // -probability is between 0% and 40% + // 20% base chance + float Probability = 20; + + //there is a newbie protection, at level 10 just 7% base chance; assuming linear function + if( pVictim->getLevel() < 30 ) + Probability = 0.65f*pVictim->getLevel()+0.5; + + uint32 VictimDefense=pVictim->GetDefenseSkillValue(this); + uint32 AttackerMeleeSkill=GetUnitMeleeSkill(pVictim); + + Probability *= AttackerMeleeSkill/(float)VictimDefense; + + if(Probability > 40.0f) + Probability = 40.0f; + + if(roll_chance_f(Probability)) + CastSpell(pVictim, 1604, true); + } + + //Calculate the damage after armor mitigation if SPELL_SCHOOL_NORMAL + if (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL) + { + uint32 damageAfterArmor = CalcArmorReducedDamage(pVictim, *damage); + + // random durability for main hand weapon (ABSORB) + if(damageAfterArmor < *damage) + if(pVictim->GetTypeId() == TYPEID_PLAYER) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_ABSORB))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EquipmentSlots(urand(EQUIPMENT_SLOT_START,EQUIPMENT_SLOT_BACK))); + + cleanDamage->damage += *damage - damageAfterArmor; + *damage = damageAfterArmor; + } + + if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) + ((Player*)this)->UpdateCombatSkills(pVictim, attType, outcome, false); + + if(GetTypeId() != TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER) + ((Player*)pVictim)->UpdateCombatSkills(this, attType, outcome, true); + + switch (outcome) + { + case MELEE_HIT_BLOCK_CRIT: + case MELEE_HIT_CRIT: + { + //*hitInfo = 0xEA; + // 0xEA + *hitInfo = HITINFO_CRITICALHIT | HITINFO_NORMALSWING2 | 0x8; + + // Crit bonus calc + uint32 crit_bonus; + crit_bonus = *damage; + + // Apply crit_damage bonus for melee spells + if (spellCasted) + { + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellCasted->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + crit_bonus = uint32(crit_bonus * ((*i)->GetModifier()->m_amount+100.0f)/100.0f); + } + + *damage += crit_bonus; + + uint32 resilienceReduction = 0; + + if(attType == RANGED_ATTACK) + { + int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_DAMAGE); + *damage = int32((*damage) * float((100.0f + mod)/100.0f)); + // Resilience - reduce crit damage + if (pVictim->GetTypeId()==TYPEID_PLAYER) + resilienceReduction = ((Player*)pVictim)->GetRangedCritDamageReduction(*damage); + } + else + { + int32 mod = pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_DAMAGE); + mod += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE); + *damage = int32((*damage) * float((100.0f + mod)/100.0f)); + // Resilience - reduce crit damage + if (pVictim->GetTypeId()==TYPEID_PLAYER) + resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(*damage); + } + + *damage -= resilienceReduction; + cleanDamage->damage += resilienceReduction; + + if(GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() != TYPEID_PLAYER && pVictim->GetCreatureType() != CREATURE_TYPE_CRITTER ) + ((Player*)this)->UpdateWeaponSkill(attType); + + ModifyAuraState(AURA_STATE_CRIT, true); + StartReactiveTimer( REACTIVE_CRIT ); + + if(getClass()==CLASS_HUNTER) + { + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, true); + StartReactiveTimer( REACTIVE_HUNTER_CRIT ); + } + + if ( outcome == MELEE_HIT_BLOCK_CRIT ) + { + *blocked_amount = pVictim->GetShieldBlockValue(); + + if (pVictim->GetUnitBlockChance()) + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); + else + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + //Only set VICTIMSTATE_BLOCK on a full block + if (*blocked_amount >= uint32(*damage)) + { + *victimState = VICTIMSTATE_BLOCKS; + *blocked_amount = uint32(*damage); + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + break; + } + + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_WOUNDCRITICAL); + break; + } + case MELEE_HIT_PARRY: + { + if(attType == RANGED_ATTACK) //range attack - no parry + { + outcome = MELEE_HIT_NORMAL; + break; + } + + cleanDamage->damage += *damage; + *damage = 0; + *victimState = VICTIMSTATE_PARRY; + + // instant (maybe with small delay) counter attack + { + float offtime = float(pVictim->getAttackTimer(OFF_ATTACK)); + float basetime = float(pVictim->getAttackTimer(BASE_ATTACK)); + + // after parry nearest next attack time will reduced at %40 from full attack time. + // The delay cannot be reduced to less than 20% of your weapon base swing delay. + if (pVictim->haveOffhandWeapon() && offtime < basetime) + { + float percent20 = pVictim->GetAttackTime(OFF_ATTACK)*0.20; + float percent60 = 3*percent20; + // set to 20% if in range 20%...20+40% of full time + if(offtime > percent20 && offtime <= percent60) + { + pVictim->setAttackTimer(OFF_ATTACK,uint32(percent20)); + } + // decrease at %40 from full time + else if(offtime > percent60) + { + offtime -= 2*percent20; + pVictim->setAttackTimer(OFF_ATTACK,uint32(offtime)); + } + // ELSE not changed + } + else + { + float percent20 = pVictim->GetAttackTime(BASE_ATTACK)*0.20; + float percent60 = 3*percent20; + // set to 20% if in range 20%...20+40% of full time + if(basetime > percent20 && basetime <= percent60) + { + pVictim->setAttackTimer(BASE_ATTACK,uint32(percent20)); + } + // decrease at %40 from full time + else if(basetime > percent60) + { + basetime -= 2*percent20; + pVictim->setAttackTimer(BASE_ATTACK,uint32(basetime)); + } + // ELSE not changed + } + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update victim defense ? + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (PARRY) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_PARRY))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_MAINHAND); + } + + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + if (pVictim->getClass() == CLASS_HUNTER) + { + pVictim->ModifyAuraState(AURA_STATE_HUNTER_PARRY,true); + pVictim->StartReactiveTimer( REACTIVE_HUNTER_PARRY ); + } + else + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + + CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + return; + } + case MELEE_HIT_DODGE: + { + if(attType == RANGED_ATTACK) //range attack - no dodge + { + outcome = MELEE_HIT_NORMAL; + break; + } + + cleanDamage->damage += *damage; + *damage = 0; + *victimState = VICTIMSTATE_DODGE; + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + ((Player*)pVictim)->UpdateDefense(); + + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + if (pVictim->getClass() != CLASS_ROGUE) // Riposte + { + pVictim->ModifyAuraState(AURA_STATE_DEFENSE, true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + } + + // Overpower + if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_WARRIOR) + { + ((Player*)this)->AddComboPoints(pVictim, 1); + StartReactiveTimer( REACTIVE_OVERPOWER ); + } + + CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + return; + } + case MELEE_HIT_BLOCK: + { + *blocked_amount = pVictim->GetShieldBlockValue(); + + if (pVictim->GetUnitBlockChance()) + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYSHIELD); + else + pVictim->HandleEmoteCommand(EMOTE_ONESHOT_PARRYUNARMED); + + //Only set VICTIMSTATE_BLOCK on a full block + if (*blocked_amount >= uint32(*damage)) + { + *victimState = VICTIMSTATE_BLOCKS; + *blocked_amount = uint32(*damage); + } + + if(pVictim->GetTypeId() == TYPEID_PLAYER) + { + // Update defense + ((Player*)pVictim)->UpdateDefense(); + + // random durability for main hand weapon (BLOCK) + if (roll_chance_f(sWorld.getRate(RATE_DURABILITY_LOSS_BLOCK))) + ((Player*)pVictim)->DurabilityPointLossForEquipSlot(EQUIPMENT_SLOT_OFFHAND); + } + + pVictim->ModifyAuraState(AURA_STATE_DEFENSE,true); + pVictim->StartReactiveTimer( REACTIVE_DEFENSE ); + + break; + } + case MELEE_HIT_GLANCING: + { + int32 leveldif = int32(pVictim->getLevel()) - int32(getLevel()); + if (leveldif > 3) leveldif = 3; + *damage *= (1 - leveldif * 0.1f); + cleanDamage->damage = *damage; + *hitInfo |= HITINFO_GLANCING; + break; + } + case MELEE_HIT_CRUSHING: + { + // 150% normal damage + *damage += (*damage / 2); + cleanDamage->damage = *damage; + *hitInfo |= HITINFO_CRUSHING; + // TODO: victimState, victim animation? + break; + } + default: + break; + } + + // apply melee damage bonus and absorb only if base damage not fully blocked to prevent negative damage or damage with full block + if(*victimState != VICTIMSTATE_BLOCKS) + { + MeleeDamageBonus(pVictim, damage,attType,spellCasted); + CalcAbsorbResist(pVictim, damageSchoolMask, DIRECT_DAMAGE, *damage-*blocked_amount, absorbDamage, resistDamage); + } + + if (*absorbDamage) *hitInfo |= HITINFO_ABSORB; + if (*resistDamage) *hitInfo |= HITINFO_RESIST; + + cleanDamage->damage += *blocked_amount; + + if (*damage <= *absorbDamage + *resistDamage + *blocked_amount) + { + //*hitInfo = 0x00010020; + //*hitInfo |= HITINFO_SWINGNOHITSOUND; + //*damageType = 0; + CastMeleeProcDamageAndSpell(pVictim, 0, damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + return; + } + + // update at damage Judgement aura duration that applied by attacker at victim + if(*damage) + { + AuraMap const& vAuras = pVictim->GetAuras(); + for(AuraMap::const_iterator itr = vAuras.begin(); itr != vAuras.end(); ++itr) + { + SpellEntry const *spellInfo = (*itr).second->GetSpellProto(); + if( (spellInfo->AttributesEx3 & 0x40000) && spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN && + ((*itr).second->GetCasterGUID() == GetGUID() && (!spellCasted || spellCasted->Id == 35395)) ) + { + (*itr).second->SetAuraDuration((*itr).second->GetAuraMaxDuration()); + (*itr).second->UpdateAuraDuration(); + } + } + } + + CastMeleeProcDamageAndSpell(pVictim, (*damage - *absorbDamage - *resistDamage - *blocked_amount), damageSchoolMask, attType, outcome, spellCasted, isTriggeredSpell); + + // victim's damage shield + // yet another hack to fix crashes related to the aura getting removed during iteration + std::set alreadyDone; + uint32 removedAuras = pVictim->m_removedAuras; + AuraList const& vDamageShields = pVictim->GetAurasByType(SPELL_AURA_DAMAGE_SHIELD); + for(AuraList::const_iterator i = vDamageShields.begin(), next = vDamageShields.begin(); i != vDamageShields.end(); i = next) + { + ++next; + if (alreadyDone.find(*i) == alreadyDone.end()) + { + alreadyDone.insert(*i); + pVictim->SpellNonMeleeDamageLog(this, (*i)->GetId(), (*i)->GetModifier()->m_amount, false, false); + if (pVictim->m_removedAuras > removedAuras) + { + removedAuras = pVictim->m_removedAuras; + next = vDamageShields.begin(); + } + } + } +} + +void Unit::AttackerStateUpdate (Unit *pVictim, WeaponAttackType attType, bool extra ) +{ + if(hasUnitState(UNIT_STAT_CONFUSED | UNIT_STAT_STUNNED | UNIT_STAT_FLEEING) || HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED) ) + return; + + if (!pVictim->isAlive()) + return; + + if(IsNonMeleeSpellCasted(false)) + return; + + CombatStart(pVictim); + + uint32 hitInfo; + if (attType == BASE_ATTACK) + hitInfo = HITINFO_NORMALSWING2; + else if (attType == OFF_ATTACK) + hitInfo = HITINFO_LEFTSWING; + else + return; // ignore ranged case + + uint32 extraAttacks = m_extraAttacks; + + // melee attack spell casted at main hand attack only + if (attType == BASE_ATTACK && m_currentSpells[CURRENT_MELEE_SPELL]) + { + m_currentSpells[CURRENT_MELEE_SPELL]->cast(); + + // not recent extra attack only at any non extra attack (melee spell case) + if(!extra && extraAttacks) + { + while(m_extraAttacks) + { + AttackerStateUpdate(pVictim, BASE_ATTACK, true); + if(m_extraAttacks > 0) + --m_extraAttacks; + } + } + + return; + } + + VictimState victimState = VICTIMSTATE_NORMAL; + + CleanDamage cleanDamage = CleanDamage(0, BASE_ATTACK, MELEE_HIT_NORMAL ); + uint32 blocked_dmg = 0; + uint32 absorbed_dmg = 0; + uint32 resisted_dmg = 0; + + SpellSchoolMask meleeSchoolMask = GetMeleeDamageSchoolMask(); + + if(pVictim->IsImmunedToDamage(meleeSchoolMask,true)) // use charges + { + SendAttackStateUpdate (HITINFO_NORMALSWING, pVictim, 1, meleeSchoolMask, 0, 0, 0, VICTIMSTATE_IS_IMMUNE, 0); + + // not recent extra attack only at any non extra attack (miss case) + if(!extra && extraAttacks) + { + while(m_extraAttacks) + { + AttackerStateUpdate(pVictim, BASE_ATTACK, true); + if(m_extraAttacks > 0) + --m_extraAttacks; + } + } + + return; + } + + uint32 damage = CalculateDamage (attType, false); + + DoAttackDamage (pVictim, &damage, &cleanDamage, &blocked_dmg, meleeSchoolMask, &hitInfo, &victimState, &absorbed_dmg, &resisted_dmg, attType); + + if (hitInfo & HITINFO_MISS) + //send miss + SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); + else + { + //do animation + SendAttackStateUpdate (hitInfo, pVictim, 1, meleeSchoolMask, damage, absorbed_dmg, resisted_dmg, victimState, blocked_dmg); + + if (damage > (absorbed_dmg + resisted_dmg + blocked_dmg)) + damage -= (absorbed_dmg + resisted_dmg + blocked_dmg); + else + damage = 0; + + DealDamage (pVictim, damage, &cleanDamage, DIRECT_DAMAGE, meleeSchoolMask, NULL, true); + + if(GetTypeId() == TYPEID_PLAYER && pVictim->isAlive()) + { + for(int i = EQUIPMENT_SLOT_START; i < EQUIPMENT_SLOT_END; i++) + ((Player*)this)->CastItemCombatSpell(((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0,i),pVictim,attType); + } + } + + if (GetTypeId() == TYPEID_PLAYER) + DEBUG_LOG("AttackerStateUpdate: (Player) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", + GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); + else + DEBUG_LOG("AttackerStateUpdate: (NPC) %u attacked %u (TypeId: %u) for %u dmg, absorbed %u, blocked %u, resisted %u.", + GetGUIDLow(), pVictim->GetGUIDLow(), pVictim->GetTypeId(), damage, absorbed_dmg, blocked_dmg, resisted_dmg); + + // extra attack only at any non extra attack (normal case) + if(!extra && extraAttacks) + { + while(m_extraAttacks) + { + AttackerStateUpdate(pVictim, BASE_ATTACK, true); + if(m_extraAttacks > 0) + --m_extraAttacks; + } + } +} + +MeleeHitOutcome Unit::RollPhysicalOutcomeAgainst (Unit const *pVictim, WeaponAttackType attType, SpellEntry const *spellInfo) +{ + // Miss chance based on melee + float miss_chance = MeleeMissChanceCalc(pVictim, attType); + + // Critical hit chance + float crit_chance = GetUnitCriticalChance(attType, pVictim); + // this is to avoid compiler issue when declaring variables inside if + float block_chance, parry_chance, dodge_chance; + + // cannot be dodged/parried/blocked + if(spellInfo->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) + { + block_chance = 0.0f; + parry_chance = 0.0f; + dodge_chance = 0.0f; + } + else + { + // parry can be avoided only by some abilities + parry_chance = pVictim->GetUnitParryChance(); + // block might be bypassed by it as well + block_chance = pVictim->GetUnitBlockChance(); + // stunned target cannot dodge and this is check in GetUnitDodgeChance() + dodge_chance = pVictim->GetUnitDodgeChance(); + } + + // Only players can have Talent&Spell bonuses + if (GetTypeId() == TYPEID_PLAYER) + { + // Increase from SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL aura + crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, spellInfo->SchoolMask); + + if( dodge_chance != 0.0f ) // if dodge chance is already 0, ignore talents for speed + { + AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); + for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) + { + // can't be dodged rogue finishing move + if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) + { + if(spellInfo->SpellFamilyName==SPELLFAMILY_ROGUE && (spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) + { + dodge_chance = 0.0f; + break; + } + } + } + } + } + + // Spellmods + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); + + DEBUG_LOG("PHYSICAL OUTCOME: miss %f crit %f dodge %f parry %f block %f",miss_chance,crit_chance,dodge_chance,parry_chance, block_chance); + + return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100),int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), true); +} + +MeleeHitOutcome Unit::RollMeleeOutcomeAgainst(const Unit *pVictim, WeaponAttackType attType) const +{ + // This is only wrapper + + // Miss chance based on melee + float miss_chance = MeleeMissChanceCalc(pVictim, attType); + + // Critical hit chance + float crit_chance = GetUnitCriticalChance(attType, pVictim); + + // stunned target cannot dodge and this is check in GetUnitDodgeChance() (returned 0 in this case) + float dodge_chance = pVictim->GetUnitDodgeChance(); + float block_chance = pVictim->GetUnitBlockChance(); + float parry_chance = pVictim->GetUnitParryChance(); + + // Useful if want to specify crit & miss chances for melee, else it could be removed + DEBUG_LOG("MELEE OUTCOME: miss %f crit %f dodge %f parry %f block %f", miss_chance,crit_chance,dodge_chance,parry_chance,block_chance); + + return RollMeleeOutcomeAgainst(pVictim, attType, int32(crit_chance*100), int32(miss_chance*100), int32(dodge_chance*100),int32(parry_chance*100),int32(block_chance*100), false); +} + +MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttackType attType, int32 crit_chance, int32 miss_chance, int32 dodge_chance, int32 parry_chance, int32 block_chance, bool SpellCasted ) const +{ + if(pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) + return MELEE_HIT_EVADE; + + int32 attackerMaxSkillValueForLevel = GetMaxSkillValueForLevel(pVictim); + int32 victimMaxSkillValueForLevel = pVictim->GetMaxSkillValueForLevel(this); + + int32 attackerWeaponSkill = GetWeaponSkillValue(attType,pVictim); + int32 victimDefenseSkill = pVictim->GetDefenseSkillValue(this); + + // bonus from skills is 0.04% + int32 skillBonus = 4 * ( attackerWeaponSkill - victimMaxSkillValueForLevel ); + int32 skillBonus2 = 4 * ( attackerMaxSkillValueForLevel - victimDefenseSkill ); + int32 sum = 0, tmp = 0; + int32 roll = urand (0, 10000); + + DEBUG_LOG ("RollMeleeOutcomeAgainst: skill bonus of %d for attacker", skillBonus); + DEBUG_LOG ("RollMeleeOutcomeAgainst: rolled %d, miss %d, dodge %d, parry %d, block %d, crit %d", + roll, miss_chance, dodge_chance, parry_chance, block_chance, crit_chance); + + tmp = miss_chance; + + if (tmp > 0 && roll < (sum += tmp )) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: MISS"); + return MELEE_HIT_MISS; + } + + // always crit against a sitting target (except 0 crit chance) + if( pVictim->GetTypeId() == TYPEID_PLAYER && crit_chance > 0 && !pVictim->IsStandState() ) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT (sitting victim)"); + return MELEE_HIT_CRIT; + } + + // Dodge chance + + // only players can't dodge if attacker is behind + if (pVictim->GetTypeId() == TYPEID_PLAYER && !pVictim->HasInArc(M_PI,this)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind and victim was a player."); + } + else + { + // Reduce dodge chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + dodge_chance -= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); + + // Modify dodge chance by attacker SPELL_AURA_MOD_COMBAT_RESULT_CHANCE + dodge_chance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); + + tmp = dodge_chance; + if ( (tmp > 0) // check if unit _can_ dodge + && ((tmp -= skillBonus) > 0) + && roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: DODGE <%d, %d)", sum-tmp, sum); + return MELEE_HIT_DODGE; + } + } + + // parry & block chances + + // check if attack comes from behind, nobody can parry or block if attacker is behind + if (!pVictim->HasInArc(M_PI,this)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: attack came from behind."); + } + else + { + // Reduce parry chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + parry_chance-= int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType)*100); + + if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_PARRY) ) + { + int32 tmp = int32(parry_chance); + if ( (tmp > 0) // check if unit _can_ parry + && ((tmp -= skillBonus) > 0) + && (roll < (sum += tmp))) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: PARRY <%d, %d)", sum-tmp, sum); + return MELEE_HIT_PARRY; + } + } + + if(pVictim->GetTypeId()==TYPEID_PLAYER || !(((Creature*)pVictim)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_BLOCK) ) + { + tmp = block_chance; + if ( (tmp > 0) // check if unit _can_ block + && ((tmp -= skillBonus) > 0) + && (roll < (sum += tmp))) + { + // Critical chance + tmp = crit_chance + skillBonus2; + if ( GetTypeId() == TYPEID_PLAYER && SpellCasted && tmp > 0 ) + { + if ( roll_chance_i(tmp/100)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCKED CRIT"); + return MELEE_HIT_BLOCK_CRIT; + } + } + DEBUG_LOG ("RollMeleeOutcomeAgainst: BLOCK <%d, %d)", sum-tmp, sum); + return MELEE_HIT_BLOCK; + } + } + } + + // Critical chance + tmp = crit_chance + skillBonus2; + + if (tmp > 0 && roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: CRIT <%d, %d)", sum-tmp, sum); + return MELEE_HIT_CRIT; + } + + // Max 40% chance to score a glancing blow against mobs that are higher level (can do only players and pets and not with ranged weapon) + if( attType != RANGED_ATTACK && !SpellCasted && + (GetTypeId() == TYPEID_PLAYER || ((Creature*)this)->isPet()) && + pVictim->GetTypeId() != TYPEID_PLAYER && !((Creature*)pVictim)->isPet() && + getLevel() < pVictim->getLevelForTarget(this) ) + { + // cap possible value (with bonuses > max skill) + int32 skill = attackerWeaponSkill; + int32 maxskill = attackerMaxSkillValueForLevel; + skill = (skill > maxskill) ? maxskill : skill; + + tmp = (10 + (victimDefenseSkill - skill)) * 100; + tmp = tmp > 4000 ? 4000 : tmp; + if (roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: GLANCING <%d, %d)", sum-4000, sum); + return MELEE_HIT_GLANCING; + } + } + + if(GetTypeId()!=TYPEID_PLAYER && !(((Creature*)this)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_CRUSH) && !((Creature*)this)->isPet() ) + { + // mobs can score crushing blows if they're 3 or more levels above victim + // or when their weapon skill is 15 or more above victim's defense skill + tmp = victimDefenseSkill; + int32 tmpmax = victimMaxSkillValueForLevel; + // having defense above your maximum (from items, talents etc.) has no effect + tmp = tmp > tmpmax ? tmpmax : tmp; + // tmp = mob's level * 5 - player's current defense skill + tmp = attackerMaxSkillValueForLevel - tmp; + if(tmp >= 15) + { + // add 2% chance per lacking skill point, min. is 15% + tmp = tmp * 200 - 1500; + if (roll < (sum += tmp)) + { + DEBUG_LOG ("RollMeleeOutcomeAgainst: CRUSHING <%d, %d)", sum-tmp, sum); + return MELEE_HIT_CRUSHING; + } + } + } + + DEBUG_LOG ("RollMeleeOutcomeAgainst: NORMAL"); + return MELEE_HIT_NORMAL; +} + +uint32 Unit::CalculateDamage (WeaponAttackType attType, bool normalized) +{ + float min_damage, max_damage; + + if (normalized && GetTypeId()==TYPEID_PLAYER) + ((Player*)this)->CalculateMinMaxDamage(attType,normalized,min_damage, max_damage); + else + { + switch (attType) + { + case RANGED_ATTACK: + min_damage = GetFloatValue(UNIT_FIELD_MINRANGEDDAMAGE); + max_damage = GetFloatValue(UNIT_FIELD_MAXRANGEDDAMAGE); + break; + case BASE_ATTACK: + min_damage = GetFloatValue(UNIT_FIELD_MINDAMAGE); + max_damage = GetFloatValue(UNIT_FIELD_MAXDAMAGE); + break; + case OFF_ATTACK: + min_damage = GetFloatValue(UNIT_FIELD_MINOFFHANDDAMAGE); + max_damage = GetFloatValue(UNIT_FIELD_MAXOFFHANDDAMAGE); + break; + // Just for good manner + default: + min_damage = 0.0f; + max_damage = 0.0f; + break; + } + } + + if (min_damage > max_damage) + { + std::swap(min_damage,max_damage); + } + + if(max_damage == 0.0f) + max_damage = 5.0f; + + return urand((uint32)min_damage, (uint32)max_damage); +} + +float Unit::CalculateLevelPenalty(SpellEntry const* spellProto) const +{ + if(spellProto->spellLevel <= 0) + return 1.0f; + + float LvlPenalty = 0.0f; + + if(spellProto->spellLevel < 20) + LvlPenalty = 20.0f - spellProto->spellLevel * 3.75f; + float LvlFactor = (float(spellProto->spellLevel) + 6.0f) / float(getLevel()); + if(LvlFactor > 1.0f) + LvlFactor = 1.0f; + + return (100.0f - LvlPenalty) * LvlFactor / 100.0f; +} + +void Unit::SendAttackStart(Unit* pVictim) +{ + WorldPacket data( SMSG_ATTACKSTART, 16 ); + data << GetGUID(); + data << pVictim->GetGUID(); + + SendMessageToSet(&data, true); + DEBUG_LOG( "WORLD: Sent SMSG_ATTACKSTART" ); +} + +void Unit::SendAttackStop(Unit* victim) +{ + if(!victim) + return; + + WorldPacket data( SMSG_ATTACKSTOP, (4+16) ); // we guess size + data.append(GetPackGUID()); + data.append(victim->GetPackGUID()); // can be 0x00... + data << uint32(0); // can be 0x1 + SendMessageToSet(&data, true); + sLog.outDetail("%s %u stopped attacking %s %u", (GetTypeId()==TYPEID_PLAYER ? "player" : "creature"), GetGUIDLow(), (victim->GetTypeId()==TYPEID_PLAYER ? "player" : "creature"),victim->GetGUIDLow()); + + /*if(victim->GetTypeId() == TYPEID_UNIT) + ((Creature*)victim)->AI().EnterEvadeMode(this);*/ +} + +/* +// Melee based spells can be miss, parry or dodge on this step +// Crit or block - determined on damage calculation phase! (and can be both in some time) +float Unit::MeleeSpellMissChance(Unit *pVictim, WeaponAttackType attType, int32 skillDiff, SpellEntry const *spell) +{ + // Calculate hit chance (more correct for chance mod) + int32 HitChance; + + // PvP - PvE melee chances + int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; + int32 leveldif = pVictim->getLevelForTarget(this) - getLevelForTarget(pVictim); + if(leveldif < 3) + HitChance = 95 - leveldif; + else + HitChance = 93 - (leveldif - 2) * lchance; + + // Hit chance depends from victim auras + if(attType == RANGED_ATTACK) + HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); + else + HitChance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); + + // Spellmod from SPELLMOD_RESIST_MISS_CHANCE + if(Player *modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, HitChance); + + // Miss = 100 - hit + float miss_chance= 100.0f - HitChance; + + // Bonuses from attacker aura and ratings + if (attType == RANGED_ATTACK) + miss_chance -= m_modRangedHitChance; + else + miss_chance -= m_modMeleeHitChance; + + // bonus from skills is 0.04% + miss_chance -= skillDiff * 0.04f; + + // Limit miss chance from 0 to 60% + if (miss_chance < 0.0f) + return 0.0f; + if (miss_chance > 60.0f) + return 60.0f; + return miss_chance; +} + +// Melee based spells hit result calculations +SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell) +{ + WeaponAttackType attType = BASE_ATTACK; + + if (spell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) + attType = RANGED_ATTACK; + + // bonus from skills is 0.04% per skill Diff + int32 attackerWeaponSkill = int32(GetWeaponSkillValue(attType,pVictim)); + int32 skillDiff = attackerWeaponSkill - int32(pVictim->GetMaxSkillValueForLevel(this)); + int32 fullSkillDiff = attackerWeaponSkill - int32(pVictim->GetDefenseSkillValue(this)); + + uint32 roll = urand (0, 10000); + uint32 missChance = uint32(MeleeSpellMissChance(pVictim, attType, fullSkillDiff, spell)*100.0f); + + // Roll miss + uint32 tmp = missChance; + if (roll < tmp) + return SPELL_MISS_MISS; + + // Same spells cannot be parry/dodge + if (spell->Attributes & SPELL_ATTR_IMPOSSIBLE_DODGE_PARRY_BLOCK) + return SPELL_MISS_NONE; + + // Ranged attack can`t miss too + if (attType == RANGED_ATTACK) + return SPELL_MISS_NONE; + + bool attackFromBehind = !pVictim->HasInArc(M_PI,this); + + // Roll dodge + int32 dodgeChance = int32(pVictim->GetUnitDodgeChance()*100.0f) - skillDiff * 4; + // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE + dodgeChance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE); + + // Reduce dodge chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + dodgeChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); + if (dodgeChance < 0) + dodgeChance = 0; + + // Can`t dodge from behind in PvP (but its possible in PvE) + if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER && attackFromBehind) + dodgeChance = 0; + + // Rogue talent`s cant be dodged + AuraList const& mCanNotBeDodge = GetAurasByType(SPELL_AURA_IGNORE_COMBAT_RESULT); + for(AuraList::const_iterator i = mCanNotBeDodge.begin(); i != mCanNotBeDodge.end(); ++i) + { + if((*i)->GetModifier()->m_miscvalue == VICTIMSTATE_DODGE) // can't be dodged rogue finishing move + { + if(spell->SpellFamilyName==SPELLFAMILY_ROGUE && (spell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE)) + { + dodgeChance = 0; + break; + } + } + } + + tmp += dodgeChance; + if (roll < tmp) + return SPELL_MISS_DODGE; + + // Roll parry + int32 parryChance = int32(pVictim->GetUnitParryChance()*100.0f) - skillDiff * 4; + // Reduce parry chance by attacker expertise rating + if (GetTypeId() == TYPEID_PLAYER) + parryChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f); + // Can`t parry from behind + if (parryChance < 0 || attackFromBehind) + parryChance = 0; + + tmp += parryChance; + if (roll < tmp) + return SPELL_MISS_PARRY; + + return SPELL_MISS_NONE; +}*/ + +// TODO need use unit spell resistances in calculations +SpellMissInfo Unit::MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell) +{ + // Can`t miss on dead target (on skinning for example) + if (!pVictim->isAlive()) + return SPELL_MISS_NONE; + + SpellSchoolMask schoolMask = GetSpellSchoolMask(spell); + // PvP - PvE spell misschances per leveldif > 2 + int32 lchance = pVictim->GetTypeId() == TYPEID_PLAYER ? 7 : 11; + int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); + + // Base hit chance from attacker and victim levels + int32 modHitChance; + if(leveldif < 3) + modHitChance = 96 - leveldif; + else + modHitChance = 94 - (leveldif - 2) * lchance; + + // Spellmod from SPELLMOD_RESIST_MISS_CHANCE + if(Player *modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spell->Id, SPELLMOD_RESIST_MISS_CHANCE, modHitChance); + // Increase from attacker SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT auras + modHitChance+=GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT, schoolMask); + // Chance hit from victim SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE auras + modHitChance+= pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_HIT_CHANCE, schoolMask); + // Reduce spell hit chance for Area of effect spells from victim SPELL_AURA_MOD_AOE_AVOIDANCE aura + if (IsAreaOfEffectSpell(spell)) + modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_AOE_AVOIDANCE); + // Reduce spell hit chance for dispel mechanic spells from victim SPELL_AURA_MOD_DISPEL_RESIST + if (IsDispelSpell(spell)) + modHitChance-=pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_DISPEL_RESIST); + // Chance resist mechanic (select max value from every mechanic spell effect) + int32 resist_mech = 0; + // Get effects mechanic and chance + for(int eff = 0; eff < 3; ++eff) + { + int32 effect_mech = GetEffectMechanic(spell, eff); + if (effect_mech) + { + int32 temp = pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE, effect_mech); + if (resist_mech < temp) + resist_mech = temp; + } + } + // Apply mod + modHitChance-=resist_mech; + + // Chance resist debuff + modHitChance-=pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_DEBUFF_RESISTANCE, int32(spell->Dispel)); + + int32 HitChance = modHitChance * 100; + // Increase hit chance from attacker SPELL_AURA_MOD_SPELL_HIT_CHANCE and attacker ratings + HitChance += int32(m_modSpellHitChance*100.0f); + + // Decrease hit chance from victim rating bonus + if (pVictim->GetTypeId()==TYPEID_PLAYER) + HitChance -= int32(((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_SPELL)*100.0f); + + if (HitChance < 100) HitChance = 100; + if (HitChance > 9900) HitChance = 9900; + + uint32 rand = urand(0,10000); + if (rand > HitChance) + return SPELL_MISS_RESIST; + return SPELL_MISS_NONE; +} + +SpellMissInfo Unit::SpellHitResult(Unit *pVictim, SpellEntry const *spell, bool CanReflect) +{ + // Return evade for units in evade mode + if (pVictim->GetTypeId()==TYPEID_UNIT && ((Creature*)pVictim)->IsInEvadeMode()) + return SPELL_MISS_EVADE; + + // If Spel has this flag cannot be resisted/immuned/etc + if (spell->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) + return SPELL_MISS_NONE; + + // Check for immune (use charges) + if (pVictim->IsImmunedToSpell(spell,true)) + return SPELL_MISS_IMMUNE; + + // All positive spells can`t miss + // TODO: client not show miss log for this spells - so need find info for this in dbc and use it! + if (IsPositiveSpell(spell->Id) + &&(!IsHostileTo(pVictim))) //prevent from affecting enemy by "positive" spell + return SPELL_MISS_NONE; + + // Check for immune (use charges) + if (pVictim->IsImmunedToDamage(GetSpellSchoolMask(spell),true)) + return SPELL_MISS_IMMUNE; + + // Try victim reflect spell + if (CanReflect) + { + // specialized first + Unit::AuraList const& mReflectSpellsSchool = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS_SCHOOL); + for(Unit::AuraList::const_iterator i = mReflectSpellsSchool.begin(); i != mReflectSpellsSchool.end(); ++i) + { + if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spell)) + { + int32 reflectchance = (*i)->GetModifier()->m_amount; + if (reflectchance > 0 && roll_chance_i(reflectchance)) + { + if((*i)->m_procCharges > 0) + { + --(*i)->m_procCharges; + if((*i)->m_procCharges==0) + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + } + return SPELL_MISS_REFLECT; + } + } + } + + // generic reflection + Unit::AuraList const& mReflectSpells = pVictim->GetAurasByType(SPELL_AURA_REFLECT_SPELLS); + for(Unit::AuraList::const_iterator i = mReflectSpells.begin(); i != mReflectSpells.end(); ++i) + { + int32 reflectchance = (*i)->GetModifier()->m_amount; + if (reflectchance > 0 && roll_chance_i(reflectchance)) + { + if((*i)->m_procCharges > 0) + { + --(*i)->m_procCharges; + if((*i)->m_procCharges==0) + pVictim->RemoveAurasDueToSpell((*i)->GetId()); + } + return SPELL_MISS_REFLECT; + } + } + } + + // Temporary solution for melee based spells and spells vs SPELL_SCHOOL_NORMAL (hit result calculated after) + for (int i=0;i<3;i++) + { + if (spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE || + spell->Effect[i] == SPELL_EFFECT_WEAPON_PERCENT_DAMAGE || + spell->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG || + spell->Effect[i] == SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL) + return SPELL_MISS_NONE; + } + + // TODO need use this code for spell hit result calculation + // now code commented for computability + switch (spell->DmgClass) + { + case SPELL_DAMAGE_CLASS_RANGED: + case SPELL_DAMAGE_CLASS_MELEE: +// return MeleeSpellHitResult(pVictim, spell); + return SPELL_MISS_NONE; + case SPELL_DAMAGE_CLASS_NONE: + return SPELL_MISS_NONE; + case SPELL_DAMAGE_CLASS_MAGIC: + return MagicSpellHitResult(pVictim, spell); + } + return SPELL_MISS_NONE; +} + +float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const +{ + if(!pVictim) + return 0.0f; + + // Base misschance 5% + float misschance = 5.0f; + + // DualWield - Melee spells and physical dmg spells - 5% , white damage 24% + if (haveOffhandWeapon() && attType != RANGED_ATTACK) + { + bool isNormal = false; + for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; i++) + { + if( m_currentSpells[i] && (GetSpellSchoolMask(m_currentSpells[i]->m_spellInfo) & SPELL_SCHOOL_MASK_NORMAL) ) + { + isNormal = true; + break; + } + } + if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL]) + { + misschance = 5.0f; + } + else + { + misschance = 24.0f; + } + } + + // PvP : PvE melee misschances per leveldif > 2 + int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7; + + int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim)); + if(leveldif < 0) + leveldif = 0; + + // Hit chance from attacker based on ratings and auras + float m_modHitChance; + if (attType == RANGED_ATTACK) + m_modHitChance = m_modRangedHitChance; + else + m_modHitChance = m_modMeleeHitChance; + + if(leveldif < 3) + misschance += (leveldif - m_modHitChance); + else + misschance += ((leveldif - 2) * chance - m_modHitChance); + + // Hit chance for victim based on ratings + if (pVictim->GetTypeId()==TYPEID_PLAYER) + { + if (attType == RANGED_ATTACK) + misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED); + else + misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE); + } + + // Modify miss chance by victim auras + if(attType == RANGED_ATTACK) + misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE); + else + misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE); + + // Modify miss chance from skill difference ( bonus from skills is 0.04% ) + int32 skillBonus = int32(GetWeaponSkillValue(attType,pVictim)) - int32(pVictim->GetDefenseSkillValue(this)); + misschance -= skillBonus * 0.04f; + + // Limit miss chance from 0 to 60% + if ( misschance < 0.0f) + return 0.0f; + if ( misschance > 60.0f) + return 60.0f; + + return misschance; +} + +uint32 Unit::GetDefenseSkillValue(Unit const* target) const +{ + if(GetTypeId() == TYPEID_PLAYER) + { + // in PvP use full skill instead current skill value + uint32 value = (target && target->GetTypeId() == TYPEID_PLAYER) + ? ((Player*)this)->GetMaxSkillValue(SKILL_DEFENSE) + : ((Player*)this)->GetSkillValue(SKILL_DEFENSE); + value += uint32(((Player*)this)->GetRatingBonusValue(CR_DEFENSE_SKILL)); + return value; + } + else + return GetUnitMeleeSkill(target); +} + +float Unit::GetUnitDodgeChance() const +{ + if(hasUnitState(UNIT_STAT_STUNNED)) + return 0.0f; + if( GetTypeId() == TYPEID_PLAYER ) + return GetFloatValue(PLAYER_DODGE_PERCENTAGE); + else + { + if(((Creature const*)this)->isTotem()) + return 0.0f; + else + { + float dodge = 5.0f; + dodge += GetTotalAuraModifier(SPELL_AURA_MOD_DODGE_PERCENT); + return dodge > 0.0f ? dodge : 0.0f; + } + } +} + +float Unit::GetUnitParryChance() const +{ + if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) + return 0.0f; + + float chance = 0.0f; + + if(GetTypeId() == TYPEID_PLAYER) + { + Player const* player = (Player const*)this; + if(player->CanParry() ) + { + Item *tmpitem = player->GetWeaponForAttack(BASE_ATTACK,true); + if(!tmpitem) + tmpitem = player->GetWeaponForAttack(OFF_ATTACK,true); + + if(tmpitem) + chance = GetFloatValue(PLAYER_PARRY_PERCENTAGE); + } + } + else if(GetTypeId() == TYPEID_UNIT) + { + if(GetCreatureType() == CREATURE_TYPE_HUMANOID) + { + chance = 5.0f; + chance += GetTotalAuraModifier(SPELL_AURA_MOD_PARRY_PERCENT); + } + } + + return chance > 0.0f ? chance : 0.0f; +} + +float Unit::GetUnitBlockChance() const +{ + if ( IsNonMeleeSpellCasted(false) || hasUnitState(UNIT_STAT_STUNNED)) + return 0.0f; + + if(GetTypeId() == TYPEID_PLAYER) + { + Player const* player = (Player const*)this; + if(player->CanBlock() ) + { + Item *tmpitem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND); + if(tmpitem && !tmpitem->IsBroken() && tmpitem->GetProto()->Block) + return GetFloatValue(PLAYER_BLOCK_PERCENTAGE); + } + // is player but has no block ability or no not broken shield equipped + return 0.0f; + } + else + { + if(((Creature const*)this)->isTotem()) + return 0.0f; + else + { + float block = 5.0f; + block += GetTotalAuraModifier(SPELL_AURA_MOD_BLOCK_PERCENT); + return block > 0.0f ? block : 0.0f; + } + } +} + +float Unit::GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVictim) const +{ + float crit; + + if(GetTypeId() == TYPEID_PLAYER) + { + switch(attackType) + { + case BASE_ATTACK: + crit = GetFloatValue( PLAYER_CRIT_PERCENTAGE ); + break; + case OFF_ATTACK: + crit = GetFloatValue( PLAYER_OFFHAND_CRIT_PERCENTAGE ); + break; + case RANGED_ATTACK: + crit = GetFloatValue( PLAYER_RANGED_CRIT_PERCENTAGE ); + break; + // Just for good manner + default: + crit = 0.0f; + break; + } + } + else + { + crit = 5.0f; + crit += GetTotalAuraModifier(SPELL_AURA_MOD_CRIT_PERCENT); + } + + // flat aura mods + if(attackType == RANGED_ATTACK) + crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_CRIT_CHANCE); + else + crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_CRIT_CHANCE); + + crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); + + // reduce crit chance from Rating for players + if (pVictim->GetTypeId()==TYPEID_PLAYER) + { + if (attackType==RANGED_ATTACK) + crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED); + else + crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE); + } + + if (crit < 0.0f) + crit = 0.0f; + return crit; +} + +uint32 Unit::GetWeaponSkillValue (WeaponAttackType attType, Unit const* target) const +{ + uint32 value = 0; + if(GetTypeId() == TYPEID_PLAYER) + { + Item* item = ((Player*)this)->GetWeaponForAttack(attType,true); + + // feral or unarmed skill only for base attack + if(attType != BASE_ATTACK && !item ) + return 0; + + if(((Player*)this)->IsInFeralForm()) + return GetMaxSkillValueForLevel(); // always maximized SKILL_FERAL_COMBAT in fact + + // weapon skill or (unarmed for base attack) + uint32 skill = item ? item->GetSkill() : SKILL_UNARMED; + + // in PvP use full skill instead current skill value + value = (target && target->GetTypeId() == TYPEID_PLAYER) + ? ((Player*)this)->GetMaxSkillValue(skill) + : ((Player*)this)->GetSkillValue(skill); + // Modify value from ratings + value += uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL)); + switch (attType) + { + case BASE_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_MAINHAND));break; + case OFF_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_OFFHAND));break; + case RANGED_ATTACK: value+=uint32(((Player*)this)->GetRatingBonusValue(CR_WEAPON_SKILL_RANGED));break; + } + } + else + value = GetUnitMeleeSkill(target); + return value; +} + +void Unit::_UpdateSpells( uint32 time ) +{ + if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]) + _UpdateAutoRepeatSpell(); + + // remove finished spells from current pointers + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + { + if (m_currentSpells[i] && m_currentSpells[i]->getState() == SPELL_STATE_FINISHED) + { + m_currentSpells[i]->SetReferencedFromCurrent(false); + m_currentSpells[i] = NULL; // remove pointer + } + } + + // TODO: Find a better way to prevent crash when multiple auras are removed. + m_removedAuras = 0; + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) + if ((*i).second) + (*i).second->SetUpdated(false); + + for (AuraMap::iterator i = m_Auras.begin(), next; i != m_Auras.end(); i = next) + { + next = i; + ++next; + if ((*i).second) + { + // prevent double update + if ((*i).second->IsUpdated()) + continue; + (*i).second->SetUpdated(true); + (*i).second->Update( time ); + // several auras can be deleted due to update + if (m_removedAuras) + { + if (m_Auras.empty()) break; + next = m_Auras.begin(); + m_removedAuras = 0; + } + } + } + + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end();) + { + if ((*i).second) + { + if ( !(*i).second->GetAuraDuration() && !((*i).second->IsPermanent() || ((*i).second->IsPassive())) ) + { + RemoveAura(i); + } + else + { + ++i; + } + } + else + { + ++i; + } + } + + if(!m_gameObj.empty()) + { + std::list::iterator ite1, dnext1; + for (ite1 = m_gameObj.begin(); ite1 != m_gameObj.end(); ite1 = dnext1) + { + dnext1 = ite1; + //(*i)->Update( difftime ); + if( !(*ite1)->isSpawned() ) + { + (*ite1)->SetOwnerGUID(0); + (*ite1)->SetRespawnTime(0); + (*ite1)->Delete(); + dnext1 = m_gameObj.erase(ite1); + } + else + ++dnext1; + } + } +} + +void Unit::_UpdateAutoRepeatSpell() +{ + //check "realtime" interrupts + if ( (GetTypeId() == TYPEID_PLAYER && ((Player*)this)->isMoving()) || IsNonMeleeSpellCasted(false,false,true) ) + { + // cancel wand shoot + if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + m_AutoRepeatFirstCast = true; + return; + } + + //apply delay + if ( m_AutoRepeatFirstCast && getAttackTimer(RANGED_ATTACK) < 500 ) + setAttackTimer(RANGED_ATTACK,500); + m_AutoRepeatFirstCast = false; + + //castroutine + if (isAttackReady(RANGED_ATTACK)) + { + // Check if able to cast + if(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->CanCast(true)) + { + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + return; + } + + // we want to shoot + Spell* spell = new Spell(this, m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo, true, 0); + spell->prepare(&(m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_targets)); + + // all went good, reset attack + resetAttackTimer(RANGED_ATTACK); + } +} + +void Unit::SetCurrentCastedSpell( Spell * pSpell ) +{ + assert(pSpell); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells + + uint32 CSpellType = pSpell->GetCurrentContainer(); + + if (pSpell == m_currentSpells[CSpellType]) return; // avoid breaking self + + // break same type spell if it is not delayed + InterruptSpell(CSpellType,false); + + // special breakage effects: + switch (CSpellType) + { + case CURRENT_GENERIC_SPELL: + { + // generic spells always break channeled not delayed spells + InterruptSpell(CURRENT_CHANNELED_SPELL,false); + + // autorepeat breaking + if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) + { + // break autorepeat if not Auto Shot + if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351) + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + m_AutoRepeatFirstCast = true; + } + addUnitState(UNIT_STAT_CASTING); + } break; + + case CURRENT_CHANNELED_SPELL: + { + // channel spells always break generic non-delayed and any channeled spells + InterruptSpell(CURRENT_GENERIC_SPELL,false); + InterruptSpell(CURRENT_CHANNELED_SPELL); + + // it also does break autorepeat if not Auto Shot + if ( m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && + m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Category == 351 ) + InterruptSpell(CURRENT_AUTOREPEAT_SPELL); + addUnitState(UNIT_STAT_CASTING); + } break; + + case CURRENT_AUTOREPEAT_SPELL: + { + // only Auto Shoot does not break anything + if (pSpell->m_spellInfo->Category == 351) + { + // generic autorepeats break generic non-delayed and channeled non-delayed spells + InterruptSpell(CURRENT_GENERIC_SPELL,false); + InterruptSpell(CURRENT_CHANNELED_SPELL,false); + } + // special action: set first cast flag + m_AutoRepeatFirstCast = true; + } break; + + default: + { + // other spell types don't break anything now + } break; + } + + // current spell (if it is still here) may be safely deleted now + if (m_currentSpells[CSpellType]) + m_currentSpells[CSpellType]->SetReferencedFromCurrent(false); + + // set new current spell + m_currentSpells[CSpellType] = pSpell; + pSpell->SetReferencedFromCurrent(true); +} + +void Unit::InterruptSpell(uint32 spellType, bool withDelayed) +{ + assert(spellType < CURRENT_MAX_SPELL); + + if(m_currentSpells[spellType] && (withDelayed || m_currentSpells[spellType]->getState() != SPELL_STATE_DELAYED) ) + { + // send autorepeat cancel message for autorepeat spells + if (spellType == CURRENT_AUTOREPEAT_SPELL) + { + if(GetTypeId()==TYPEID_PLAYER) + ((Player*)this)->SendAutoRepeatCancel(); + } + + if (m_currentSpells[spellType]->getState() != SPELL_STATE_FINISHED) + m_currentSpells[spellType]->cancel(); + m_currentSpells[spellType]->SetReferencedFromCurrent(false); + m_currentSpells[spellType] = NULL; + } +} + +bool Unit::IsNonMeleeSpellCasted(bool withDelayed, bool skipChanneled, bool skipAutorepeat) const +{ + // We don't do loop here to explicitly show that melee spell is excluded. + // Maybe later some special spells will be excluded too. + + // generic spells are casted when they are not finished and not delayed + if ( m_currentSpells[CURRENT_GENERIC_SPELL] && + (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && + (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) + return(true); + + // channeled spells may be delayed, but they are still considered casted + else if ( !skipChanneled && m_currentSpells[CURRENT_CHANNELED_SPELL] && + (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) ) + return(true); + + // autorepeat spells may be finished or delayed, but they are still considered casted + else if ( !skipAutorepeat && m_currentSpells[CURRENT_AUTOREPEAT_SPELL] ) + return(true); + + return(false); +} + +void Unit::InterruptNonMeleeSpells(bool withDelayed, uint32 spell_id) +{ + // generic spells are interrupted if they are not finished or delayed + if (m_currentSpells[CURRENT_GENERIC_SPELL] && (!spell_id || m_currentSpells[CURRENT_GENERIC_SPELL]->m_spellInfo->Id==spell_id)) + { + if ( (m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_FINISHED) && + (withDelayed || m_currentSpells[CURRENT_GENERIC_SPELL]->getState() != SPELL_STATE_DELAYED) ) + m_currentSpells[CURRENT_GENERIC_SPELL]->cancel(); + m_currentSpells[CURRENT_GENERIC_SPELL]->SetReferencedFromCurrent(false); + m_currentSpells[CURRENT_GENERIC_SPELL] = NULL; + } + + // autorepeat spells are interrupted if they are not finished or delayed + if (m_currentSpells[CURRENT_AUTOREPEAT_SPELL] && (!spell_id || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->m_spellInfo->Id==spell_id)) + { + // send disable autorepeat packet in any case + if(GetTypeId()==TYPEID_PLAYER) + ((Player*)this)->SendAutoRepeatCancel(); + + if ( (m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_FINISHED) && + (withDelayed || m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->getState() != SPELL_STATE_DELAYED) ) + m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->cancel(); + m_currentSpells[CURRENT_AUTOREPEAT_SPELL]->SetReferencedFromCurrent(false); + m_currentSpells[CURRENT_AUTOREPEAT_SPELL] = NULL; + } + + // channeled spells are interrupted if they are not finished, even if they are delayed + if (m_currentSpells[CURRENT_CHANNELED_SPELL] && (!spell_id || m_currentSpells[CURRENT_CHANNELED_SPELL]->m_spellInfo->Id==spell_id)) + { + if (m_currentSpells[CURRENT_CHANNELED_SPELL]->getState() != SPELL_STATE_FINISHED) + m_currentSpells[CURRENT_CHANNELED_SPELL]->cancel(); + m_currentSpells[CURRENT_CHANNELED_SPELL]->SetReferencedFromCurrent(false); + m_currentSpells[CURRENT_CHANNELED_SPELL] = NULL; + } +} + +Spell* Unit::FindCurrentSpellBySpellId(uint32 spell_id) const +{ + for (uint32 i = 0; i < CURRENT_MAX_SPELL; i++) + if(m_currentSpells[i] && m_currentSpells[i]->m_spellInfo->Id==spell_id) + return m_currentSpells[i]; + return NULL; +} + +bool Unit::isInFront(Unit const* target, float distance, float arc) const +{ + return IsWithinDistInMap(target, distance) && HasInArc( arc, target ); +} + +void Unit::SetInFront(Unit const* target) +{ + SetOrientation(GetAngle(target)); +} + +bool Unit::isInBack(Unit const* target, float distance, float arc) const +{ + return IsWithinDistInMap(target, distance) && !HasInArc( 2 * M_PI - arc, target ); +} + +bool Unit::isInLine(Unit const* target, float distance) const +{ + if(!HasInArc(M_PI, target) || !IsWithinDistInMap(target, distance)) return false; + float width = (GetObjectSize() / 2 + target->GetObjectSize()) / 2; + float angle = GetAngle(target); + angle -= GetOrientation(); + return abs(sin(angle)) * distance < width; +} + +bool Unit::isInAccessiblePlaceFor(Creature const* c) const +{ + if(IsInWater()) + return c->canSwim(); + else + return c->canWalk() || c->canFly(); +} + +bool Unit::IsInWater() const +{ + return MapManager::Instance().GetBaseMap(GetMapId())->IsInWater(GetPositionX(),GetPositionY(), GetPositionZ()); +} + +bool Unit::IsUnderWater() const +{ + return MapManager::Instance().GetBaseMap(GetMapId())->IsUnderWater(GetPositionX(),GetPositionY(),GetPositionZ()); +} + +void Unit::DeMorph() +{ + SetDisplayId(GetNativeDisplayId()); +} + +int32 Unit::GetTotalAuraModifier(AuraType auratype) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + modifier += (*i)->GetModifier()->m_amount; + + return modifier; +} + +float Unit::GetTotalAuraMultiplier(AuraType auratype) const +{ + float multiplier = 1.0f; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + multiplier *= (100.0f + (*i)->GetModifier()->m_amount)/100.0f; + + return multiplier; +} + +int32 Unit::GetMaxPositiveAuraModifier(AuraType auratype) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + if ((*i)->GetModifier()->m_amount > modifier) + modifier = (*i)->GetModifier()->m_amount; + + return modifier; +} + +int32 Unit::GetMaxNegativeAuraModifier(AuraType auratype) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + if ((*i)->GetModifier()->m_amount < modifier) + modifier = (*i)->GetModifier()->m_amount; + + return modifier; +} + +int32 Unit::GetTotalAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask) + modifier += mod->m_amount; + } + return modifier; +} + +float Unit::GetTotalAuraMultiplierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + float multiplier = 1.0f; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask) + multiplier *= (100.0f + mod->m_amount)/100.0f; + } + return multiplier; +} + +int32 Unit::GetMaxPositiveAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask && mod->m_amount > modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +int32 Unit::GetMaxNegativeAuraModifierByMiscMask(AuraType auratype, uint32 misc_mask) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue & misc_mask && mod->m_amount < modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +int32 Unit::GetTotalAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value) + modifier += mod->m_amount; + } + return modifier; +} + +float Unit::GetTotalAuraMultiplierByMiscValue(AuraType auratype, int32 misc_value) const +{ + float multiplier = 1.0f; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value) + multiplier *= (100.0f + mod->m_amount)/100.0f; + } + return multiplier; +} + +int32 Unit::GetMaxPositiveAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value && mod->m_amount > modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +int32 Unit::GetMaxNegativeAuraModifierByMiscValue(AuraType auratype, int32 misc_value) const +{ + int32 modifier = 0; + + AuraList const& mTotalAuraList = GetAurasByType(auratype); + for(AuraList::const_iterator i = mTotalAuraList.begin();i != mTotalAuraList.end(); ++i) + { + Modifier* mod = (*i)->GetModifier(); + if (mod->m_miscvalue == misc_value && mod->m_amount < modifier) + modifier = mod->m_amount; + } + + return modifier; +} + +bool Unit::AddAura(Aura *Aur) +{ + // ghost spell check, allow apply any auras at player loading in ghost mode (will be cleanup after load) + if( !isAlive() && Aur->GetId() != 20584 && Aur->GetId() != 8326 && Aur->GetId() != 2584 && + (GetTypeId()!=TYPEID_PLAYER || !((Player*)this)->GetSession()->PlayerLoading()) ) + { + delete Aur; + return false; + } + + if(Aur->GetTarget() != this) + { + sLog.outError("Aura (spell %u eff %u) add to aura list of %s (lowguid: %u) but Aura target is %s (lowguid: %u)", + Aur->GetId(),Aur->GetEffIndex(),(GetTypeId()==TYPEID_PLAYER?"player":"creature"),GetGUIDLow(), + (Aur->GetTarget()->GetTypeId()==TYPEID_PLAYER?"player":"creature"),Aur->GetTarget()->GetGUIDLow()); + delete Aur; + return false; + } + + SpellEntry const* aurSpellInfo = Aur->GetSpellProto(); + + spellEffectPair spair = spellEffectPair(Aur->GetId(), Aur->GetEffIndex()); + AuraMap::iterator i = m_Auras.find( spair ); + + // take out same spell + if (i != m_Auras.end()) + { + // passive and persistent auras can stack with themselves any number of times + if (!Aur->IsPassive() && !Aur->IsPersistent()) + { + // replace aura if next will > spell StackAmount + if(aurSpellInfo->StackAmount) + { + if(m_Auras.count(spair) >= aurSpellInfo->StackAmount) + RemoveAura(i,AURA_REMOVE_BY_STACK); + } + // if StackAmount==0 not allow auras from same caster + else + { + for(AuraMap::iterator i2 = m_Auras.lower_bound(spair); i2 != m_Auras.upper_bound(spair); ++i2) + { + if(i2->second->GetCasterGUID()==Aur->GetCasterGUID()) + { + // can be only single (this check done at _each_ aura add + RemoveAura(i2,AURA_REMOVE_BY_STACK); + break; + } + + bool stop = false; + switch(aurSpellInfo->EffectApplyAuraName[Aur->GetEffIndex()]) + { + // DoT/HoT/etc + case SPELL_AURA_PERIODIC_DAMAGE: // allow stack + case SPELL_AURA_PERIODIC_DAMAGE_PERCENT: + case SPELL_AURA_PERIODIC_LEECH: + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_OBS_MOD_HEALTH: + case SPELL_AURA_PERIODIC_MANA_LEECH: + case SPELL_AURA_PERIODIC_ENERGIZE: + case SPELL_AURA_OBS_MOD_MANA: + case SPELL_AURA_POWER_BURN_MANA: + break; + default: // not allow + // can be only single (this check done at _each_ aura add + RemoveAura(i2,AURA_REMOVE_BY_STACK); + stop = true; + break; + } + + if(stop) + break; + } + } + } + } + + // passive auras stack with all (except passive spell proc auras) + if ((!Aur->IsPassive() || !IsPassiveStackableSpell(Aur->GetId())) && + !(Aur->GetId() == 20584 || Aur->GetId() == 8326)) + { + if (!RemoveNoStackAurasDueToAura(Aur)) + { + delete Aur; + return false; // couldn't remove conflicting aura with higher rank + } + } + + // update single target auras list (before aura add to aura list, to prevent unexpected remove recently added aura) + if (IsSingleTargetSpell(aurSpellInfo) && Aur->GetTarget()) + { + // caster pointer can be deleted in time aura remove, find it by guid at each iteration + for(;;) + { + Unit* caster = Aur->GetCaster(); + if(!caster) // caster deleted and not required adding scAura + break; + + bool restart = false; + AuraList& scAuras = caster->GetSingleCastAuras(); + for(AuraList::iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) + { + if( (*itr)->GetTarget() != Aur->GetTarget() && + IsSingleTargetSpells((*itr)->GetSpellProto(),aurSpellInfo) ) + { + if ((*itr)->IsInUse()) + { + sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for IsSingleTargetSpell", (*itr)->GetId(), (*itr)->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); + continue; + } + (*itr)->GetTarget()->RemoveAura((*itr)->GetId(), (*itr)->GetEffIndex()); + restart = true; + break; + } + } + + if(!restart) + { + // done + scAuras.push_back(Aur); + break; + } + } + } + + // add aura, register in lists and arrays + Aur->_AddAura(); + m_Auras.insert(AuraMap::value_type(spellEffectPair(Aur->GetId(), Aur->GetEffIndex()), Aur)); + if (Aur->GetModifier()->m_auraname < TOTAL_AURAS) + { + m_modAuras[Aur->GetModifier()->m_auraname].push_back(Aur); + if(Aur->GetSpellProto()->AuraInterruptFlags) + { + m_interruptableAuras.push_back(Aur); + AddInterruptMask(Aur->GetSpellProto()->AuraInterruptFlags); + } + if(Aur->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) + { + m_ccAuras.push_back(Aur); + } + } + + Aur->ApplyModifier(true,true); + sLog.outDebug("Aura %u now is in use", Aur->GetModifier()->m_auraname); + return true; +} + +void Unit::RemoveRankAurasDueToSpell(uint32 spellId) +{ + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + if(!spellInfo) + return; + AuraMap::iterator i,next; + for (i = m_Auras.begin(); i != m_Auras.end(); i = next) + { + next = i; + ++next; + uint32 i_spellId = (*i).second->GetId(); + if((*i).second && i_spellId && i_spellId != spellId) + { + if(spellmgr.IsRankSpellDueToSpell(spellInfo,i_spellId)) + { + RemoveAurasDueToSpell(i_spellId); + + if( m_Auras.empty() ) + break; + else + next = m_Auras.begin(); + } + } + } +} + +bool Unit::RemoveNoStackAurasDueToAura(Aura *Aur) +{ + if (!Aur) + return false; + + SpellEntry const* spellProto = Aur->GetSpellProto(); + if (!spellProto) + return false; + + uint32 spellId = Aur->GetId(); + uint32 effIndex = Aur->GetEffIndex(); + + SpellSpecific spellId_spec = GetSpellSpecific(spellId); + + AuraMap::iterator i,next; + for (i = m_Auras.begin(); i != m_Auras.end(); i = next) + { + next = i; + ++next; + if (!(*i).second) continue; + + SpellEntry const* i_spellProto = (*i).second->GetSpellProto(); + + if (!i_spellProto) + continue; + + uint32 i_spellId = i_spellProto->Id; + + if(IsPassiveSpell(i_spellId)) + { + if(IsPassiveStackableSpell(i_spellId)) + continue; + + // passive non-stackable spells not stackable only with another rank of same spell + if (!spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) + continue; + } + + uint32 i_effIndex = (*i).second->GetEffIndex(); + + if(i_spellId == spellId) continue; + + bool is_triggered_by_spell = false; + // prevent triggered aura of removing aura that triggered it + for(int j = 0; j < 3; ++j) + if (i_spellProto->EffectTriggerSpell[j] == spellProto->Id) + is_triggered_by_spell = true; + if (is_triggered_by_spell) continue; + + for(int j = 0; j < 3; ++j) + { + // prevent remove dummy triggered spells at next effect aura add + switch(spellProto->Effect[j]) // main spell auras added added after triggered spell + { + case SPELL_EFFECT_DUMMY: + switch(spellId) + { + case 5420: if(i_spellId==34123) is_triggered_by_spell = true; break; + } + break; + } + + if(is_triggered_by_spell) + break; + + // prevent remove form main spell by triggered passive spells + switch(i_spellProto->EffectApplyAuraName[j]) // main aura added before triggered spell + { + case SPELL_AURA_MOD_SHAPESHIFT: + switch(i_spellId) + { + case 24858: if(spellId==24905) is_triggered_by_spell = true; break; + case 33891: if(spellId==5420 || spellId==34123) is_triggered_by_spell = true; break; + case 34551: if(spellId==22688) is_triggered_by_spell = true; break; + } + break; + } + } + + if(!is_triggered_by_spell) + { + SpellSpecific i_spellId_spec = GetSpellSpecific(i_spellId); + + bool is_sspc = IsSingleFromSpellSpecificPerCaster(spellId_spec,i_spellId_spec); + + if( is_sspc && Aur->GetCasterGUID() == (*i).second->GetCasterGUID() ) + { + // cannot remove higher rank + if (spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) + if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) + return false; + + // Its a parent aura (create this aura in ApplyModifier) + if ((*i).second->IsInUse()) + { + sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); + continue; + } + RemoveAurasDueToSpell(i_spellId); + + if( m_Auras.empty() ) + break; + else + next = m_Auras.begin(); + } + else if( !is_sspc && spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId) ) + { + // Its a parent aura (create this aura in ApplyModifier) + if ((*i).second->IsInUse()) + { + sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); + continue; + } + RemoveAurasDueToSpell(i_spellId); + + if( m_Auras.empty() ) + break; + else + next = m_Auras.begin(); + } + // Potions stack aura by aura (elixirs/flask already checked) + else if( spellProto->SpellFamilyName == SPELLFAMILY_POTION && i_spellProto->SpellFamilyName == SPELLFAMILY_POTION ) + { + if (IsNoStackAuraDueToAura(spellId, effIndex, i_spellId, i_effIndex)) + { + if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) + return false; // cannot remove higher rank + + // Its a parent aura (create this aura in ApplyModifier) + if ((*i).second->IsInUse()) + { + sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); + continue; + } + RemoveAura(i); + next = i; + } + } + } + } + return true; +} + +void Unit::RemoveAura(uint32 spellId, uint32 effindex, Aura* except) +{ + spellEffectPair spair = spellEffectPair(spellId, effindex); + for(AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) + { + if(iter->second!=except) + { + RemoveAura(iter); + iter = m_Auras.lower_bound(spair); + } + else + ++iter; + } +} + +void Unit::RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler) +{ + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + Aura *aur = iter->second; + if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) + { + // Custom dispel case + // Unstable Affliction + if (aur->GetSpellProto()->SpellFamilyName == SPELLFAMILY_WARLOCK && (aur->GetSpellProto()->SpellFamilyFlags & 0x010000000000LL)) + { + int32 damage = aur->GetModifier()->m_amount*9; + uint64 caster_guid = aur->GetCasterGUID(); + + // Remove aura + RemoveAura(iter, AURA_REMOVE_BY_DISPEL); + + // backfire damage and silence + dispeler->CastCustomSpell(dispeler, 31117, &damage, NULL, NULL, true, NULL, NULL,caster_guid); + + iter = m_Auras.begin(); // iterator can be invalidate at cast if self-dispel + } + else + RemoveAura(iter, AURA_REMOVE_BY_DISPEL); + } + else + ++iter; + } +} + +void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer) +{ + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + Aura *aur = iter->second; + if (aur->GetId() == spellId && aur->GetCasterGUID() == casterGUID) + { + int32 basePoints = aur->GetBasePoints(); + // construct the new aura for the attacker + Aura * new_aur = CreateAura(aur->GetSpellProto(), aur->GetEffIndex(), &basePoints, stealer); + if(!new_aur) + continue; + + // set its duration and maximum duration + // max duration 2 minutes (in msecs) + int32 dur = aur->GetAuraDuration(); + const int32 max_dur = 2*MINUTE*1000; + new_aur->SetAuraMaxDuration( max_dur > dur ? dur : max_dur ); + new_aur->SetAuraDuration( max_dur > dur ? dur : max_dur ); + + // add the new aura to stealer + stealer->AddAura(new_aur); + + // Remove aura as dispel + RemoveAura(iter, AURA_REMOVE_BY_DISPEL); + } + else + ++iter; + } +} + +void Unit::RemoveAurasDueToSpellByCancel(uint32 spellId) +{ + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + if (iter->second->GetId() == spellId) + RemoveAura(iter, AURA_REMOVE_BY_CANCEL); + else + ++iter; + } +} + +void Unit::RemoveAurasWithDispelType( DispelType type ) +{ + // Create dispel mask by dispel type + uint32 dispelMask = GetDispellMask(type); + // Dispel all existing auras vs current dispel type + AuraMap& auras = GetAuras(); + for(AuraMap::iterator itr = auras.begin(); itr != auras.end(); ) + { + SpellEntry const* spell = itr->second->GetSpellProto(); + if( (1<Dispel) & dispelMask ) + { + // Dispel aura + RemoveAurasDueToSpell(spell->Id); + itr = auras.begin(); + } + else + ++itr; + } +} + +void Unit::RemoveSingleAuraFromStack(uint32 spellId, uint32 effindex) +{ + AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); + if(iter != m_Auras.end()) + RemoveAura(iter); +} + +void Unit::RemoveAurasDueToSpell(uint32 spellId, Aura* except) +{ + for (int i = 0; i < 3; ++i) + RemoveAura(spellId,i,except); +} + +void Unit::RemoveAurasDueToItemSpell(Item* castItem,uint32 spellId) +{ + for (int k=0; k < 3; ++k) + { + spellEffectPair spair = spellEffectPair(spellId, k); + for (AuraMap::iterator iter = m_Auras.lower_bound(spair); iter != m_Auras.upper_bound(spair);) + { + if (iter->second->GetCastItemGUID() == castItem->GetGUID()) + { + RemoveAura(iter); + iter = m_Auras.upper_bound(spair); // overwrite by more appropriate + } + else + ++iter; + } + } +} + +void Unit::RemoveNotOwnSingleTargetAuras() +{ + // single target auras from other casters + for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); ) + { + if (iter->second->GetCasterGUID()!=GetGUID() && IsSingleTargetSpell(iter->second->GetSpellProto())) + RemoveAura(iter); + else + ++iter; + } + + // single target auras at other targets + AuraList& scAuras = GetSingleCastAuras(); + for (AuraList::iterator iter = scAuras.begin(); iter != scAuras.end(); ) + { + Aura* aura = *iter; + if (aura->GetTarget()!=this) + { + scAuras.erase(iter); // explicitly remove, instead waiting remove in RemoveAura + aura->GetTarget()->RemoveAura(aura->GetId(),aura->GetEffIndex()); + iter = scAuras.begin(); + } + else + ++iter; + } + +} + +void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) +{ + if (IsSingleTargetSpell((*i).second->GetSpellProto())) + { + if(Unit* caster = (*i).second->GetCaster()) + { + AuraList& scAuras = caster->GetSingleCastAuras(); + scAuras.remove((*i).second); + } + else + { + sLog.outError("Couldn't find the caster of the single target aura, may crash later!"); + assert(false); + } + } + + if ((*i).second->GetModifier()->m_auraname < TOTAL_AURAS) + { + m_modAuras[(*i).second->GetModifier()->m_auraname].remove((*i).second); + if((*i).second->GetSpellProto()->AuraInterruptFlags) + { + m_interruptableAuras.remove((*i).second); + UpdateInterruptMask(); + } + if((*i).second->GetSpellProto()->Attributes & SPELL_ATTR_BREAKABLE_BY_DAMAGE) + m_ccAuras.remove((*i).second); + } + + // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) + Aura* Aur = i->second; + // Set remove mode + Aur->SetRemoveMode(mode); + // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura + // remove aura from list before to prevent deleting it before + m_Auras.erase(i); + ++m_removedAuras; // internal count used by unit update + + // Status unsummoned at aura remove + Totem* statue = NULL; + if(IsChanneledSpell(Aur->GetSpellProto())) + if(Unit* caster = Aur->GetCaster()) + if(caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->isTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE) + statue = ((Totem*)caster); + + + if(const std::vector *spell_triggered = spellmgr.GetSpellLinked(-(int32)Aur->GetSpellProto()->Id)) + { + for(std::vector::const_iterator i = spell_triggered->begin(); i != spell_triggered->end(); ++i) + { + if(spell_triggered < 0) + RemoveAurasDueToSpell(-(*i)); + else if(Unit* caster = Aur->GetCaster()) + CastSpell(this, *i, true, 0, 0, caster->GetGUID()); + } + } + + sLog.outDebug("Aura %u now is remove mode %d",Aur->GetModifier()->m_auraname, mode); + Aur->ApplyModifier(false,true); + Aur->_RemoveAura(); + delete Aur; + + if(statue) + statue->UnSummon(); + + // only way correctly remove all auras from list + if( m_Auras.empty() ) + i = m_Auras.end(); + else + i = m_Auras.begin(); +} + +void Unit::RemoveAllAuras() +{ + while (!m_Auras.empty()) + { + AuraMap::iterator iter = m_Auras.begin(); + RemoveAura(iter); + } +} + +void Unit::RemoveArenaAuras(bool onleave) +{ + // in join, remove positive buffs, on end, remove negative + // used to remove positive visible auras in arenas + for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) + { + if ( !(iter->second->GetSpellProto()->AttributesEx4 & (1<<21)) // don't remove stances, shadowform, pally/hunter auras + && !iter->second->IsPassive() // don't remove passive auras + && (!(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) || !(iter->second->GetSpellProto()->Attributes & SPELL_ATTR_UNK8)) // not unaffected by invulnerability auras or not having that unknown flag (that seemed the most probable) + && (iter->second->IsPositive() ^ onleave)) // remove positive buffs on enter, negative buffs on leave + RemoveAura(iter); + else + ++iter; + } +} + +void Unit::RemoveAllAurasOnDeath() +{ + // used just after dieing to remove all visible auras + // and disable the mods for the passive ones + for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();) + { + if (!iter->second->IsPassive() && !iter->second->IsDeathPersistent()) + RemoveAura(iter, AURA_REMOVE_BY_DEATH); + else + ++iter; + } +} + +void Unit::DelayAura(uint32 spellId, uint32 effindex, int32 delaytime) +{ + AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); + if (iter != m_Auras.end()) + { + if (iter->second->GetAuraDuration() < delaytime) + iter->second->SetAuraDuration(0); + else + iter->second->SetAuraDuration(iter->second->GetAuraDuration() - delaytime); + iter->second->UpdateAuraDuration(); + sLog.outDebug("Aura %u partially interrupted on unit %u, new duration: %u ms",iter->second->GetModifier()->m_auraname, GetGUIDLow(), iter->second->GetAuraDuration()); + } +} + +void Unit::_RemoveAllAuraMods() +{ + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) + { + (*i).second->ApplyModifier(false); + } +} + +void Unit::_ApplyAllAuraMods() +{ + for (AuraMap::iterator i = m_Auras.begin(); i != m_Auras.end(); ++i) + { + (*i).second->ApplyModifier(true); + } +} + +Aura* Unit::GetAura(uint32 spellId, uint32 effindex) +{ + AuraMap::iterator iter = m_Auras.find(spellEffectPair(spellId, effindex)); + if (iter != m_Auras.end()) + return iter->second; + return NULL; +} + +void Unit::AddDynObject(DynamicObject* dynObj) +{ + m_dynObjGUIDs.push_back(dynObj->GetGUID()); +} + +void Unit::RemoveDynObject(uint32 spellid) +{ + if(m_dynObjGUIDs.empty()) + return; + for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(!dynObj) + { + i = m_dynObjGUIDs.erase(i); + } + else if(spellid == 0 || dynObj->GetSpellId() == spellid) + { + dynObj->Delete(); + i = m_dynObjGUIDs.erase(i); + } + else + ++i; + } +} + +void Unit::RemoveAllDynObjects() +{ + while(!m_dynObjGUIDs.empty()) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(dynObj) + dynObj->Delete(); + m_dynObjGUIDs.erase(m_dynObjGUIDs.begin()); + } +} + +DynamicObject * Unit::GetDynObject(uint32 spellId, uint32 effIndex) +{ + for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(!dynObj) + { + i = m_dynObjGUIDs.erase(i); + continue; + } + + if (dynObj->GetSpellId() == spellId && dynObj->GetEffIndex() == effIndex) + return dynObj; + ++i; + } + return NULL; +} + +DynamicObject * Unit::GetDynObject(uint32 spellId) +{ + for (DynObjectGUIDs::iterator i = m_dynObjGUIDs.begin(); i != m_dynObjGUIDs.end();) + { + DynamicObject* dynObj = ObjectAccessor::GetDynamicObject(*this,*m_dynObjGUIDs.begin()); + if(!dynObj) + { + i = m_dynObjGUIDs.erase(i); + continue; + } + + if (dynObj->GetSpellId() == spellId) + return dynObj; + ++i; + } + return NULL; +} + +void Unit::AddGameObject(GameObject* gameObj) +{ + assert(gameObj && gameObj->GetOwnerGUID()==0); + m_gameObj.push_back(gameObj); + gameObj->SetOwnerGUID(GetGUID()); +} + +void Unit::RemoveGameObject(GameObject* gameObj, bool del) +{ + assert(gameObj && gameObj->GetOwnerGUID()==GetGUID()); + + // GO created by some spell + if ( GetTypeId()==TYPEID_PLAYER && gameObj->GetSpellId() ) + { + SpellEntry const* createBySpell = sSpellStore.LookupEntry(gameObj->GetSpellId()); + // Need activate spell use for owner + if (createBySpell && createBySpell->Attributes & SPELL_ATTR_DISABLED_WHILE_ACTIVE) + ((Player*)this)->SendCooldownEvent(createBySpell); + } + gameObj->SetOwnerGUID(0); + m_gameObj.remove(gameObj); + if(del) + { + gameObj->SetRespawnTime(0); + gameObj->Delete(); + } +} + +void Unit::RemoveGameObject(uint32 spellid, bool del) +{ + if(m_gameObj.empty()) + return; + std::list::iterator i, next; + for (i = m_gameObj.begin(); i != m_gameObj.end(); i = next) + { + next = i; + if(spellid == 0 || (*i)->GetSpellId() == spellid) + { + (*i)->SetOwnerGUID(0); + if(del) + { + (*i)->SetRespawnTime(0); + (*i)->Delete(); + } + + next = m_gameObj.erase(i); + } + else + ++next; + } +} + +void Unit::RemoveAllGameObjects() +{ + // remove references to unit + for(std::list::iterator i = m_gameObj.begin(); i != m_gameObj.end();) + { + (*i)->SetOwnerGUID(0); + (*i)->SetRespawnTime(0); + (*i)->Delete(); + i = m_gameObj.erase(i); + } +} + +void Unit::SendSpellNonMeleeDamageLog(Unit *target,uint32 SpellID,uint32 Damage, SpellSchoolMask damageSchoolMask,uint32 AbsorbedDamage, uint32 Resist,bool PhysicalDamage, uint32 Blocked, bool CriticalHit) +{ + sLog.outDebug("Sending: SMSG_SPELLNONMELEEDAMAGELOG"); + WorldPacket data(SMSG_SPELLNONMELEEDAMAGELOG, (16+4+4+1+4+4+1+1+4+4+1)); // we guess size + data.append(target->GetPackGUID()); + data.append(GetPackGUID()); + data << uint32(SpellID); + data << uint32(Damage-AbsorbedDamage-Resist-Blocked); + data << uint8(damageSchoolMask); // spell school + data << uint32(AbsorbedDamage); // AbsorbedDamage + data << uint32(Resist); // resist + data << uint8(PhysicalDamage); // if 1, then client show spell name (example: %s's ranged shot hit %s for %u school or %s suffers %u school damage from %s's spell_name + data << uint8(0); // unk isFromAura + data << uint32(Blocked); // blocked + data << uint32(CriticalHit ? 0x27 : 0x25); // hitType, flags: 0x2 - SPELL_HIT_TYPE_CRIT, 0x10 - replace caster? + data << uint8(0); // isDebug? + SendMessageToSet( &data, true ); +} + +void Unit::SendSpellMiss(Unit *target, uint32 spellID, SpellMissInfo missInfo) +{ + WorldPacket data(SMSG_SPELLLOGMISS, (4+8+1+4+8+1)); + data << uint32(spellID); + data << uint64(GetGUID()); + data << uint8(0); // can be 0 or 1 + data << uint32(1); // target count + // for(i = 0; i < target count; ++i) + data << uint64(target->GetGUID()); // target GUID + data << uint8(missInfo); + // end loop + SendMessageToSet(&data, true); +} + +void Unit::SendAttackStateUpdate(uint32 HitInfo, Unit *target, uint8 SwingType, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, uint32 Resist, VictimState TargetState, uint32 BlockedAmount) +{ + sLog.outDebug("WORLD: Sending SMSG_ATTACKERSTATEUPDATE"); + + WorldPacket data(SMSG_ATTACKERSTATEUPDATE, (16+45)); // we guess size + data << (uint32)HitInfo; + data.append(GetPackGUID()); + data.append(target->GetPackGUID()); + data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); + + data << (uint8)SwingType; // count? + + // for(i = 0; i < SwingType; ++i) + data << (uint32)damageSchoolMask; + data << (float)(Damage-AbsorbDamage-Resist-BlockedAmount); + // still need to double check damage + data << (uint32)(Damage-AbsorbDamage-Resist-BlockedAmount); + data << (uint32)AbsorbDamage; + data << (uint32)Resist; + // end loop + + data << (uint32)TargetState; + + if( AbsorbDamage == 0 ) //also 0x3E8 = 0x3E8, check when that happens + data << (uint32)0; + else + data << (uint32)-1; + + data << (uint32)0; + data << (uint32)BlockedAmount; + + SendMessageToSet( &data, true ); +} + +void Unit::ProcDamageAndSpell(Unit *pVictim, uint32 procAttacker, uint32 procVictim, uint32 damage, SpellSchoolMask damageSchoolMask, SpellEntry const *procSpell, bool isTriggeredSpell, WeaponAttackType attType) +{ + sLog.outDebug("ProcDamageAndSpell: attacker flags are 0x%x, victim flags 0x%x", procAttacker, procVictim); + if(procSpell) + sLog.outDebug("ProcDamageAndSpell: invoked due to spell id %u %s", procSpell->Id, (isTriggeredSpell?"(triggered)":"")); + + // Assign melee/ranged proc flags for magic attacks, that are actually melee/ranged abilities + // not assign for spell proc triggered spell to prevent infinity (or unexpected 2-3 times) melee damage spell proc call with melee damage effect + // That is the question though if it's fully correct + if(procSpell && !isTriggeredSpell) + { + if(procSpell->DmgClass == SPELL_DAMAGE_CLASS_MELEE) + { + if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_MELEE; + if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_MELEE; + if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_MELEE; + if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_MELEE; + attType = BASE_ATTACK; // Melee abilities are assumed to be dealt with mainhand weapon + } + else if (procSpell->DmgClass == SPELL_DAMAGE_CLASS_RANGED) + { + if(procAttacker & PROC_FLAG_HIT_SPELL) procAttacker |= PROC_FLAG_HIT_RANGED; + if(procAttacker & PROC_FLAG_CRIT_SPELL) procAttacker |= PROC_FLAG_CRIT_RANGED; + if(procVictim & PROC_FLAG_STRUCK_SPELL) procVictim |= PROC_FLAG_STRUCK_RANGED; + if(procVictim & PROC_FLAG_STRUCK_CRIT_SPELL) procVictim |= PROC_FLAG_STRUCK_CRIT_RANGED; + attType = RANGED_ATTACK; + } + } + if(damage && (procVictim & (PROC_FLAG_STRUCK_MELEE|PROC_FLAG_STRUCK_RANGED|PROC_FLAG_STRUCK_SPELL))) + procVictim |= (PROC_FLAG_TAKE_DAMAGE|PROC_FLAG_TOUCH); + + // Not much to do if no flags are set. + if (procAttacker) + { + // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set + ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcEffectAuraTypes,attType, procSpell, damage, damageSchoolMask); + ProcDamageAndSpellFor(false,pVictim,procAttacker,attackerProcCastAuraTypes,attType, procSpell, damage, damageSchoolMask); + } + + // Now go on with a victim's events'n'auras + // Not much to do if no flags are set or there is no victim + if(pVictim && pVictim->isAlive() && procVictim) + { + // processing auras that not generate casts at proc event before auras that generate casts to prevent proc aura added at prev. proc aura execute in set + pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcEffectAuraTypes,attType,procSpell, damage, damageSchoolMask); + pVictim->ProcDamageAndSpellFor(true,this,procVictim,victimProcCastAuraTypes,attType,procSpell, damage, damageSchoolMask); + } +} + +void Unit::CastMeleeProcDamageAndSpell(Unit* pVictim, uint32 damage, SpellSchoolMask damageSchoolMask, WeaponAttackType attType, MeleeHitOutcome outcome, SpellEntry const *spellCasted, bool isTriggeredSpell) +{ + if(!pVictim) + return; + + uint32 procAttacker = PROC_FLAG_NONE; + uint32 procVictim = PROC_FLAG_NONE; + + switch(outcome) + { + case MELEE_HIT_EVADE: + return; + case MELEE_HIT_MISS: + if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_MISS; + } + break; + case MELEE_HIT_BLOCK_CRIT: + case MELEE_HIT_CRIT: + if(spellCasted && attType == BASE_ATTACK) + { + procAttacker |= PROC_FLAG_CRIT_SPELL; + procVictim |= PROC_FLAG_STRUCK_CRIT_SPELL; + if ( outcome == MELEE_HIT_BLOCK_CRIT ) + { + procVictim |= PROC_FLAG_BLOCK; + procAttacker |= PROC_FLAG_TARGET_BLOCK; + } + } + else if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; + procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; + } + else + { + procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; + procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; + } + break; + case MELEE_HIT_PARRY: + procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; + procVictim = PROC_FLAG_PARRY; + break; + case MELEE_HIT_BLOCK: + procAttacker = PROC_FLAG_TARGET_BLOCK; + procVictim = PROC_FLAG_BLOCK; + break; + case MELEE_HIT_DODGE: + procAttacker = PROC_FLAG_TARGET_DODGE_OR_PARRY; + procVictim = PROC_FLAG_DODGE; + break; + case MELEE_HIT_CRUSHING: + if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_HIT_MELEE | PROC_FLAG_CRIT_MELEE; + procVictim = PROC_FLAG_STRUCK_MELEE | PROC_FLAG_STRUCK_CRIT_MELEE; + } + else + { + procAttacker = PROC_FLAG_HIT_RANGED | PROC_FLAG_CRIT_RANGED; + procVictim = PROC_FLAG_STRUCK_RANGED | PROC_FLAG_STRUCK_CRIT_RANGED; + } + break; + default: + if(attType == BASE_ATTACK || attType == OFF_ATTACK) + { + procAttacker = PROC_FLAG_HIT_MELEE; + procVictim = PROC_FLAG_STRUCK_MELEE; + } + else + { + procAttacker = PROC_FLAG_HIT_RANGED; + procVictim = PROC_FLAG_STRUCK_RANGED; + } + break; + } + + if(damage > 0) + procVictim |= PROC_FLAG_TAKE_DAMAGE; + + if(procAttacker != PROC_FLAG_NONE || procVictim != PROC_FLAG_NONE) + ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, damageSchoolMask, spellCasted, isTriggeredSpell, attType); +} + +bool Unit::HandleHasteAuraProc(Unit *pVictim, SpellEntry const *hasteSpell, uint32 /*effIndex*/, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 /*procFlag*/, uint32 cooldown) +{ + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = 0; + Unit* target = pVictim; + int32 basepoints0 = 0; + + switch(hasteSpell->SpellFamilyName) + { + case SPELLFAMILY_ROGUE: + { + switch(hasteSpell->Id) + { + // Blade Flurry + case 13877: + case 33735: + { + target = SelectNearbyTarget(); + if(!target) + return false; + basepoints0 = damage; + triggered_spell_id = 22482; + break; + } + } + break; + } + } + + // processed charge only counting case + if(!triggered_spell_id) + return true; + + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleHasteAuraProc: Spell %u have not existed triggered spell %u",hasteSpell->Id,triggered_spell_id); + return false; + } + + // default case + if(!target || target!=this && !target->isAlive()) + return false; + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + if(basepoints0) + CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + else + CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +bool Unit::HandleDummyAuraProc(Unit *pVictim, SpellEntry const *dummySpell, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) +{ + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = 0; + Unit* target = pVictim; + int32 basepoints0 = 0; + + switch(dummySpell->SpellFamilyName) + { + case SPELLFAMILY_GENERIC: + { + switch (dummySpell->Id) + { + // Eye of Eye + case 9799: + case 25988: + { + // prevent damage back from weapon special attacks + if (!procSpell || procSpell->DmgClass != SPELL_DAMAGE_CLASS_MAGIC ) + return false; + + // return damage % to attacker but < 50% own total health + basepoints0 = triggeredByAura->GetModifier()->m_amount*int32(damage)/100; + if(basepoints0 > GetMaxHealth()/2) + basepoints0 = GetMaxHealth()/2; + + triggered_spell_id = 25997; + break; + } + // Sweeping Strikes + case 12328: + case 18765: + case 35429: + { + // prevent chain of triggered spell from same triggered spell + if(procSpell && procSpell->Id==26654) + return false; + + target = SelectNearbyTarget(); + if(!target) + return false; + + triggered_spell_id = 26654; + break; + } + // Unstable Power + case 24658: + { + if (!procSpell || procSpell->Id == 24659) + return false; + // Need remove one 24659 aura + RemoveSingleAuraFromStack(24659, 0); + RemoveSingleAuraFromStack(24659, 1); + return true; + } + // Restless Strength + case 24661: + { + // Need remove one 24662 aura + RemoveSingleAuraFromStack(24662, 0); + return true; + } + // Adaptive Warding (Frostfire Regalia set) + case 28764: + { + if(!procSpell) + return false; + + // find Mage Armor + bool found = false; + AuraList const& mRegenInterupt = GetAurasByType(SPELL_AURA_MOD_MANA_REGEN_INTERRUPT); + for(AuraList::const_iterator iter = mRegenInterupt.begin(); iter != mRegenInterupt.end(); ++iter) + { + if(SpellEntry const* iterSpellProto = (*iter)->GetSpellProto()) + { + if(iterSpellProto->SpellFamilyName==SPELLFAMILY_MAGE && (iterSpellProto->SpellFamilyFlags & 0x10000000)) + { + found=true; + break; + } + } + } + if(!found) + return false; + + switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) + { + case SPELL_SCHOOL_NORMAL: + case SPELL_SCHOOL_HOLY: + return false; // ignored + case SPELL_SCHOOL_FIRE: triggered_spell_id = 28765; break; + case SPELL_SCHOOL_NATURE: triggered_spell_id = 28768; break; + case SPELL_SCHOOL_FROST: triggered_spell_id = 28766; break; + case SPELL_SCHOOL_SHADOW: triggered_spell_id = 28769; break; + case SPELL_SCHOOL_ARCANE: triggered_spell_id = 28770; break; + default: + return false; + } + + target = this; + break; + } + // Obsidian Armor (Justice Bearer`s Pauldrons shoulder) + case 27539: + { + if(!procSpell) + return false; + + // not from DoT + bool found = false; + for(int j = 0; j < 3; ++j) + { + if(procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE||procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT) + { + found = true; + break; + } + } + if(found) + return false; + + switch(GetFirstSchoolInMask(GetSpellSchoolMask(procSpell))) + { + case SPELL_SCHOOL_NORMAL: + return false; // ignore + case SPELL_SCHOOL_HOLY: triggered_spell_id = 27536; break; + case SPELL_SCHOOL_FIRE: triggered_spell_id = 27533; break; + case SPELL_SCHOOL_NATURE: triggered_spell_id = 27538; break; + case SPELL_SCHOOL_FROST: triggered_spell_id = 27534; break; + case SPELL_SCHOOL_SHADOW: triggered_spell_id = 27535; break; + case SPELL_SCHOOL_ARCANE: triggered_spell_id = 27540; break; + default: + return false; + } + + target = this; + break; + } + // Mana Leech (Passive) (Priest Pet Aura) + case 28305: + { + // Cast on owner + target = GetOwner(); + if(!target) + return false; + + basepoints0 = int32(damage * 2.5f); // manaregen + triggered_spell_id = 34650; + break; + } + // Mark of Malice + case 33493: + { + // Cast finish spell at last charge + if (triggeredByAura->m_procCharges > 1) + return false; + + target = this; + triggered_spell_id = 33494; + break; + } + // Twisted Reflection (boss spell) + case 21063: + triggered_spell_id = 21064; + break; + // Vampiric Aura (boss spell) + case 38196: + { + basepoints0 = 3 * damage; // 300% + if (basepoints0 < 0) + return false; + + triggered_spell_id = 31285; + target = this; + break; + } + // Aura of Madness (Darkmoon Card: Madness trinket) + //===================================================== + // 39511 Sociopath: +35 strength (Paladin, Rogue, Druid, Warrior) + // 40997 Delusional: +70 attack power (Rogue, Hunter, Paladin, Warrior, Druid) + // 40998 Kleptomania: +35 agility (Warrior, Rogue, Paladin, Hunter, Druid) + // 40999 Megalomania: +41 damage/healing (Druid, Shaman, Priest, Warlock, Mage, Paladin) + // 41002 Paranoia: +35 spell/melee/ranged crit strike rating (All classes) + // 41005 Manic: +35 haste (spell, melee and ranged) (All classes) + // 41009 Narcissism: +35 intellect (Druid, Shaman, Priest, Warlock, Mage, Paladin, Hunter) + // 41011 Martyr Complex: +35 stamina (All classes) + // 41406 Dementia: Every 5 seconds either gives you +5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) + // 41409 Dementia: Every 5 seconds either gives you -5% damage/healing. (Druid, Shaman, Priest, Warlock, Mage, Paladin) + case 39446: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Select class defined buff + switch (getClass()) + { + case CLASS_PALADIN: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 + case CLASS_DRUID: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 + { + uint32 RandomSpell[]={39511,40997,40998,40999,41002,41005,41009,41011,41409}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + case CLASS_ROGUE: // 39511,40997,40998,41002,41005,41011 + case CLASS_WARRIOR: // 39511,40997,40998,41002,41005,41011 + { + uint32 RandomSpell[]={39511,40997,40998,41002,41005,41011}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + case CLASS_PRIEST: // 40999,41002,41005,41009,41011,41406,41409 + case CLASS_SHAMAN: // 40999,41002,41005,41009,41011,41406,41409 + case CLASS_MAGE: // 40999,41002,41005,41009,41011,41406,41409 + case CLASS_WARLOCK: // 40999,41002,41005,41009,41011,41406,41409 + { + uint32 RandomSpell[]={40999,41002,41005,41009,41011,41406,41409}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + case CLASS_HUNTER: // 40997,40999,41002,41005,41009,41011,41406,41409 + { + uint32 RandomSpell[]={40997,40999,41002,41005,41009,41011,41406,41409}; + triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; + break; + } + default: + return false; + } + + target = this; + if (roll_chance_i(10)) + ((Player*)this)->Say("This is Madness!", LANG_UNIVERSAL); + break; + } + /* + // TODO: need find item for aura and triggered spells + // Sunwell Exalted Caster Neck (??? neck) + // cast ??? Light's Wrath if Exalted by Aldor + // cast ??? Arcane Bolt if Exalted by Scryers*/ + case 46569: + return false; // disable for while + /* + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = ??? + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = ??? + break; + } + return false; + }/**/ + // Sunwell Exalted Caster Neck (Shattered Sun Pendant of Acumen neck) + // cast 45479 Light's Wrath if Exalted by Aldor + // cast 45429 Arcane Bolt if Exalted by Scryers + case 45481: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45479; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = 45429; + break; + } + return false; + } + // Sunwell Exalted Melee Neck (Shattered Sun Pendant of Might neck) + // cast 45480 Light's Strength if Exalted by Aldor + // cast 45428 Arcane Strike if Exalted by Scryers + case 45482: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45480; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = 45428; + break; + } + return false; + } + // Sunwell Exalted Tank Neck (Shattered Sun Pendant of Resolve neck) + // cast 45431 Arcane Insight if Exalted by Aldor + // cast 45432 Light's Ward if Exalted by Scryers + case 45483: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45432; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45431; + break; + } + return false; + } + // Sunwell Exalted Healer Neck (Shattered Sun Pendant of Restoration neck) + // cast 45478 Light's Salvation if Exalted by Aldor + // cast 45430 Arcane Surge if Exalted by Scryers + case 45484: + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // Get Aldor reputation rank + if (((Player *)this)->GetReputationRank(932) == REP_EXALTED) + { + target = this; + triggered_spell_id = 45478; + break; + } + // Get Scryers reputation rank + if (((Player *)this)->GetReputationRank(934) == REP_EXALTED) + { + triggered_spell_id = 45430; + break; + } + return false; + } + } + break; + } + case SPELLFAMILY_MAGE: + { + // Magic Absorption + if (dummySpell->SpellIconID == 459) // only this spell have SpellIconID == 459 and dummy aura + { + if (getPowerType() != POWER_MANA) + return false; + + // mana reward + basepoints0 = (triggeredByAura->GetModifier()->m_amount * GetMaxPower(POWER_MANA) / 100); + target = this; + triggered_spell_id = 29442; + break; + } + // Master of Elements + if (dummySpell->SpellIconID == 1920) + { + if(!procSpell) + return false; + + // mana cost save + basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; + if( basepoints0 <=0 ) + return false; + + target = this; + triggered_spell_id = 29077; + break; + } + switch(dummySpell->Id) + { + // Ignite + case 11119: + case 11120: + case 12846: + case 12847: + case 12848: + { + switch (dummySpell->Id) + { + case 11119: basepoints0 = int32(0.04f*damage); break; + case 11120: basepoints0 = int32(0.08f*damage); break; + case 12846: basepoints0 = int32(0.12f*damage); break; + case 12847: basepoints0 = int32(0.16f*damage); break; + case 12848: basepoints0 = int32(0.20f*damage); break; + default: + sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (IG)",dummySpell->Id); + return false; + } + + triggered_spell_id = 12654; + break; + } + // Combustion + case 11129: + { + //last charge and crit + if( triggeredByAura->m_procCharges <= 1 && (procFlag & PROC_FLAG_CRIT_SPELL) ) + { + RemoveAurasDueToSpell(28682); //-> remove Combustion auras + return true; // charge counting (will removed) + } + + CastSpell(this, 28682, true, castItem, triggeredByAura); + return(procFlag & PROC_FLAG_CRIT_SPELL);// charge update only at crit hits, no hidden cooldowns + } + } + break; + } + case SPELLFAMILY_WARRIOR: + { + // Retaliation + if(dummySpell->SpellFamilyFlags==0x0000000800000000LL) + { + // check attack comes not from behind + if (!HasInArc(M_PI, pVictim)) + return false; + + triggered_spell_id = 22858; + break; + } + break; + } + case SPELLFAMILY_WARLOCK: + { + // Seed of Corruption + if (dummySpell->SpellFamilyFlags & 0x0000001000000000LL) + { + Modifier* mod = triggeredByAura->GetModifier(); + // if damage is more than need or target die from damage deal finish spell + // FIX ME: not triggered currently at death + if( mod->m_amount <= damage || GetHealth() <= damage ) + { + // remember guid before aura delete + uint64 casterGuid = triggeredByAura->GetCasterGUID(); + + // Remove aura (before cast for prevent infinite loop handlers) + RemoveAurasDueToSpell(triggeredByAura->GetId()); + + // Cast finish spell (triggeredByAura already not exist!) + if(Unit* caster = GetUnit(*this, casterGuid)) + caster->CastSpell(this, 27285, true, castItem); + return true; // no hidden cooldown + } + + // Damage counting + mod->m_amount-=damage; + return true; + } + // Seed of Corruption (Mobs cast) - no die req + if (dummySpell->SpellFamilyFlags == 0x00LL && dummySpell->SpellIconID == 1932) + { + Modifier* mod = triggeredByAura->GetModifier(); + // if damage is more than need deal finish spell + if( mod->m_amount <= damage ) + { + // remember guid before aura delete + uint64 casterGuid = triggeredByAura->GetCasterGUID(); + + // Remove aura (before cast for prevent infinite loop handlers) + RemoveAurasDueToSpell(triggeredByAura->GetId()); + + // Cast finish spell (triggeredByAura already not exist!) + if(Unit* caster = GetUnit(*this, casterGuid)) + caster->CastSpell(this, 32865, true, castItem); + return true; // no hidden cooldown + } + // Damage counting + mod->m_amount-=damage; + return true; + } + switch(dummySpell->Id) + { + // Nightfall + case 18094: + case 18095: + { + target = this; + triggered_spell_id = 17941; + break; + } + //Soul Leech + case 30293: + case 30295: + case 30296: + { + // health + basepoints0 = int32(damage*triggeredByAura->GetModifier()->m_amount/100); + target = this; + triggered_spell_id = 30294; + break; + } + // Shadowflame (Voidheart Raiment set bonus) + case 37377: + { + triggered_spell_id = 37379; + break; + } + // Pet Healing (Corruptor Raiment or Rift Stalker Armor) + case 37381: + { + target = GetPet(); + if(!target) + return false; + + // heal amount + basepoints0 = damage * triggeredByAura->GetModifier()->m_amount/100; + triggered_spell_id = 37382; + break; + } + // Shadowflame Hellfire (Voidheart Raiment set bonus) + case 39437: + { + triggered_spell_id = 37378; + break; + } + } + break; + } + case SPELLFAMILY_PRIEST: + { + // Vampiric Touch + if( dummySpell->SpellFamilyFlags & 0x0000040000000000LL ) + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // pVictim is caster of aura + if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) + return false; + + // energize amount + basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; + pVictim->CastCustomSpell(pVictim,34919,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + return true; // no hidden cooldown + } + switch(dummySpell->Id) + { + // Vampiric Embrace + case 15286: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // pVictim is caster of aura + if(triggeredByAura->GetCasterGUID() != pVictim->GetGUID()) + return false; + + // heal amount + basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; + pVictim->CastCustomSpell(pVictim,15290,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + return true; // no hidden cooldown + } + // Priest Tier 6 Trinket (Ashtongue Talisman of Acumen) + case 40438: + { + // Shadow Word: Pain + if( procSpell->SpellFamilyFlags & 0x0000000000008000LL ) + triggered_spell_id = 40441; + // Renew + else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) + triggered_spell_id = 40440; + else + return false; + + target = this; + break; + } + // Oracle Healing Bonus ("Garments of the Oracle" set) + case 26169: + { + // heal amount + basepoints0 = int32(damage * 10/100); + target = this; + triggered_spell_id = 26170; + break; + } + // Frozen Shadoweave (Shadow's Embrace set) warning! its not only priest set + case 39372: + { + if(!procSpell || (GetSpellSchoolMask(procSpell) & (SPELL_SCHOOL_MASK_FROST | SPELL_SCHOOL_MASK_SHADOW))==0 ) + return false; + + // heal amount + basepoints0 = int32(damage * 2 / 100); + target = this; + triggered_spell_id = 39373; + break; + } + // Vestments of Faith (Priest Tier 3) - 4 pieces bonus + case 28809: + { + triggered_spell_id = 28810; + break; + } + } + break; + } + case SPELLFAMILY_DRUID: + { + switch(dummySpell->Id) + { + // Healing Touch (Dreamwalker Raiment set) + case 28719: + { + // mana back + basepoints0 = int32(procSpell->manaCost * 30 / 100); + target = this; + triggered_spell_id = 28742; + break; + } + // Healing Touch Refund (Idol of Longevity trinket) + case 28847: + { + target = this; + triggered_spell_id = 28848; + break; + } + // Mana Restore (Malorne Raiment set / Malorne Regalia set) + case 37288: + case 37295: + { + target = this; + triggered_spell_id = 37238; + break; + } + // Druid Tier 6 Trinket + case 40442: + { + float chance; + + // Starfire + if( procSpell->SpellFamilyFlags & 0x0000000000000004LL ) + { + triggered_spell_id = 40445; + chance = 25.f; + } + // Rejuvenation + else if( procSpell->SpellFamilyFlags & 0x0000000000000010LL ) + { + triggered_spell_id = 40446; + chance = 25.f; + } + // Mangle (cat/bear) + else if( procSpell->SpellFamilyFlags & 0x0000044000000000LL ) + { + triggered_spell_id = 40452; + chance = 40.f; + } + else + return false; + + if (!roll_chance_f(chance)) + return false; + + target = this; + break; + } + // Maim Interrupt + case 44835: + { + // Deadly Interrupt Effect + triggered_spell_id = 32747; + break; + } + } + break; + } + case SPELLFAMILY_ROGUE: + { + switch(dummySpell->Id) + { + // Deadly Throw Interrupt + case 32748: + { + // Prevent cast Deadly Throw Interrupt on self from last effect (apply dummy) of Deadly Throw + if(this == pVictim) + return false; + + triggered_spell_id = 32747; + break; + } + } + // Quick Recovery + if( dummySpell->SpellIconID == 2116 ) + { + if(!procSpell) + return false; + + // only rogue's finishing moves (maybe need additional checks) + if( procSpell->SpellFamilyName!=SPELLFAMILY_ROGUE || + (procSpell->SpellFamilyFlags & SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE) == 0) + return false; + + // energy cost save + basepoints0 = procSpell->manaCost * triggeredByAura->GetModifier()->m_amount/100; + if(basepoints0 <= 0) + return false; + + target = this; + triggered_spell_id = 31663; + break; + } + break; + } + case SPELLFAMILY_HUNTER: + { + // Thrill of the Hunt + if ( dummySpell->SpellIconID == 2236 ) + { + if(!procSpell) + return false; + + // mana cost save + basepoints0 = procSpell->manaCost * 40/100; + if(basepoints0 <= 0) + return false; + + target = this; + triggered_spell_id = 34720; + break; + } + break; + } + case SPELLFAMILY_PALADIN: + { + // Seal of Righteousness - melee proc dummy + if (dummySpell->SpellFamilyFlags&0x000000008000000LL && triggeredByAura->GetEffIndex()==0) + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + uint32 spellId; + switch (triggeredByAura->GetId()) + { + case 21084: spellId = 25742; break; // Rank 1 + case 20287: spellId = 25740; break; // Rank 2 + case 20288: spellId = 25739; break; // Rank 3 + case 20289: spellId = 25738; break; // Rank 4 + case 20290: spellId = 25737; break; // Rank 5 + case 20291: spellId = 25736; break; // Rank 6 + case 20292: spellId = 25735; break; // Rank 7 + case 20293: spellId = 25713; break; // Rank 8 + case 27155: spellId = 27156; break; // Rank 9 + default: + sLog.outError("Unit::HandleDummyAuraProc: non handled possibly SoR (Id = %u)", triggeredByAura->GetId()); + return false; + } + Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + float speed = (item ? item->GetProto()->Delay : BASE_ATTACK_TIME)/1000.0f; + + float damageBasePoints; + if(item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) + // two hand weapon + damageBasePoints=1.20f*triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f + 1; + else + // one hand weapon/no weapon + damageBasePoints=0.85f*ceil(triggeredByAura->GetModifier()->m_amount * 1.2f * 1.03f * speed/100.0f) - 1; + + int32 damagePoint = int32(damageBasePoints + 0.03f * (GetWeaponDamageRange(BASE_ATTACK,MINDAMAGE)+GetWeaponDamageRange(BASE_ATTACK,MAXDAMAGE))/2.0f) + 1; + + // apply damage bonuses manually + if(damagePoint >= 0) + damagePoint = SpellDamageBonus(pVictim, dummySpell, damagePoint, SPELL_DIRECT_DAMAGE); + + CastCustomSpell(pVictim,spellId,&damagePoint,NULL,NULL,true,NULL, triggeredByAura); + return true; // no hidden cooldown + } + // Seal of Blood do damage trigger + if(dummySpell->SpellFamilyFlags & 0x0000040000000000LL) + { + switch(triggeredByAura->GetEffIndex()) + { + case 0: + // prevent chain triggering + if(procSpell && procSpell->Id==31893 ) + return false; + + triggered_spell_id = 31893; + break; + case 1: + { + // damage + basepoints0 = triggeredByAura->GetModifier()->m_amount * damage / 100; + target = this; + triggered_spell_id = 32221; + break; + } + } + } + + switch(dummySpell->Id) + { + // Holy Power (Redemption Armor set) + case 28789: + { + if(!pVictim) + return false; + + // Set class defined buff + switch (pVictim->getClass()) + { + case CLASS_PALADIN: + case CLASS_PRIEST: + case CLASS_SHAMAN: + case CLASS_DRUID: + triggered_spell_id = 28795; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. + break; + case CLASS_MAGE: + case CLASS_WARLOCK: + triggered_spell_id = 28793; // Increases the friendly target's spell damage and healing by up to $s1 for $d. + break; + case CLASS_HUNTER: + case CLASS_ROGUE: + triggered_spell_id = 28791; // Increases the friendly target's attack power by $s1 for $d. + break; + case CLASS_WARRIOR: + triggered_spell_id = 28790; // Increases the friendly target's armor + break; + default: + return false; + } + break; + } + //Seal of Vengeance + case 31801: + { + if(effIndex != 0) // effect 1,2 used by seal unleashing code + return false; + + triggered_spell_id = 31803; + break; + } + // Spiritual Att. + case 31785: + case 33776: + { + // if healed by another unit (pVictim) + if(this == pVictim) + return false; + + // heal amount + basepoints0 = triggeredByAura->GetModifier()->m_amount*damage/100; + target = this; + triggered_spell_id = 31786; + break; + } + // Paladin Tier 6 Trinket (Ashtongue Talisman of Zeal) + case 40470: + { + if( !procSpell ) + return false; + + float chance; + + // Flash of light/Holy light + if( procSpell->SpellFamilyFlags & 0x00000000C0000000LL) + { + triggered_spell_id = 40471; + chance = 15.f; + } + // Judgement + else if( procSpell->SpellFamilyFlags & 0x0000000000800000LL ) + { + triggered_spell_id = 40472; + chance = 50.f; + } + else + return false; + + if (!roll_chance_f(chance)) + return false; + + break; + } + } + break; + } + case SPELLFAMILY_SHAMAN: + { + switch(dummySpell->Id) + { + // Totemic Power (The Earthshatterer set) + case 28823: + { + if( !pVictim ) + return false; + + // Set class defined buff + switch (pVictim->getClass()) + { + case CLASS_PALADIN: + case CLASS_PRIEST: + case CLASS_SHAMAN: + case CLASS_DRUID: + triggered_spell_id = 28824; // Increases the friendly target's mana regeneration by $s1 per 5 sec. for $d. + break; + case CLASS_MAGE: + case CLASS_WARLOCK: + triggered_spell_id = 28825; // Increases the friendly target's spell damage and healing by up to $s1 for $d. + break; + case CLASS_HUNTER: + case CLASS_ROGUE: + triggered_spell_id = 28826; // Increases the friendly target's attack power by $s1 for $d. + break; + case CLASS_WARRIOR: + triggered_spell_id = 28827; // Increases the friendly target's armor + break; + default: + return false; + } + break; + } + // Lesser Healing Wave (Totem of Flowing Water Relic) + case 28849: + { + target = this; + triggered_spell_id = 28850; + break; + } + // Windfury Weapon (Passive) 1-5 Ranks + case 33757: + { + if(GetTypeId()!=TYPEID_PLAYER) + return false; + + if(!castItem || !castItem->IsEquipped()) + return false; + + // custom cooldown processing case + if( cooldown && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) + return false; + + uint32 spellId; + switch (castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT))) + { + case 283: spellId = 33757; break; //1 Rank + case 284: spellId = 33756; break; //2 Rank + case 525: spellId = 33755; break; //3 Rank + case 1669:spellId = 33754; break; //4 Rank + case 2636:spellId = 33727; break; //5 Rank + default: + { + sLog.outError("Unit::HandleDummyAuraProc: non handled item enchantment (rank?) %u for spell id: %u (Windfury)", + castItem->GetEnchantmentId(EnchantmentSlot(TEMP_ENCHANTMENT_SLOT)),dummySpell->Id); + return false; + } + } + + SpellEntry const* windfurySpellEntry = sSpellStore.LookupEntry(spellId); + if(!windfurySpellEntry) + { + sLog.outError("Unit::HandleDummyAuraProc: non existed spell id: %u (Windfury)",spellId); + return false; + } + + int32 extra_attack_power = CalculateSpellDamage(windfurySpellEntry,0,windfurySpellEntry->EffectBasePoints[0],pVictim); + + // Off-Hand case + if ( castItem->GetSlot() == EQUIPMENT_SLOT_OFFHAND ) + { + // Value gained from additional AP + basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(OFF_ATTACK)/1000/2); + triggered_spell_id = 33750; + } + // Main-Hand case + else + { + // Value gained from additional AP + basepoints0 = int32(extra_attack_power/14.0f * GetAttackTime(BASE_ATTACK)/1000); + triggered_spell_id = 25504; + } + + // apply cooldown before cast to prevent processing itself + if( cooldown ) + ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); + + // Attack Twice + for ( uint32 i = 0; i<2; ++i ) + CastCustomSpell(pVictim,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + + return true; + } + // Shaman Tier 6 Trinket + case 40463: + { + if( !procSpell ) + return false; + + float chance; + if (procSpell->SpellFamilyFlags & 0x0000000000000001LL) + { + triggered_spell_id = 40465; // Lightning Bolt + chance = 15.f; + } + else if (procSpell->SpellFamilyFlags & 0x0000000000000080LL) + { + triggered_spell_id = 40465; // Lesser Healing Wave + chance = 10.f; + } + else if (procSpell->SpellFamilyFlags & 0x0000001000000000LL) + { + triggered_spell_id = 40466; // Stormstrike + chance = 50.f; + } + else + return false; + + if (!roll_chance_f(chance)) + return false; + + target = this; + break; + } + } + + // Earth Shield + if(dummySpell->SpellFamilyFlags==0x40000000000LL) + { + if(GetTypeId() != TYPEID_PLAYER) + return false; + + // heal + basepoints0 = triggeredByAura->GetModifier()->m_amount; + target = this; + triggered_spell_id = 379; + break; + } + // Lightning Overload + if (dummySpell->SpellIconID == 2018) // only this spell have SpellFamily Shaman SpellIconID == 2018 and dummy aura + { + if(!procSpell || GetTypeId() != TYPEID_PLAYER || !pVictim ) + return false; + + // custom cooldown processing case + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(dummySpell->Id)) + return false; + + uint32 spellId = 0; + // Every Lightning Bolt and Chain Lightning spell have duplicate vs half damage and zero cost + switch (procSpell->Id) + { + // Lightning Bolt + case 403: spellId = 45284; break; // Rank 1 + case 529: spellId = 45286; break; // Rank 2 + case 548: spellId = 45287; break; // Rank 3 + case 915: spellId = 45288; break; // Rank 4 + case 943: spellId = 45289; break; // Rank 5 + case 6041: spellId = 45290; break; // Rank 6 + case 10391: spellId = 45291; break; // Rank 7 + case 10392: spellId = 45292; break; // Rank 8 + case 15207: spellId = 45293; break; // Rank 9 + case 15208: spellId = 45294; break; // Rank 10 + case 25448: spellId = 45295; break; // Rank 11 + case 25449: spellId = 45296; break; // Rank 12 + // Chain Lightning + case 421: spellId = 45297; break; // Rank 1 + case 930: spellId = 45298; break; // Rank 2 + case 2860: spellId = 45299; break; // Rank 3 + case 10605: spellId = 45300; break; // Rank 4 + case 25439: spellId = 45301; break; // Rank 5 + case 25442: spellId = 45302; break; // Rank 6 + default: + sLog.outError("Unit::HandleDummyAuraProc: non handled spell id: %u (LO)", procSpell->Id); + return false; + } + // No thread generated mod + SpellModifier *mod = new SpellModifier; + mod->op = SPELLMOD_THREAT; + mod->value = -100; + mod->type = SPELLMOD_PCT; + mod->spellId = dummySpell->Id; + mod->effectId = 0; + mod->lastAffected = NULL; + mod->mask = 0x0000000000000003LL; + mod->charges = 0; + ((Player*)this)->AddSpellMod(mod, true); + + // Remove cooldown (Chain Lightning - have Category Recovery time) + if (procSpell->SpellFamilyFlags & 0x0000000000000002LL) + ((Player*)this)->RemoveSpellCooldown(spellId); + + // Hmmm.. in most case spells already set half basepoints but... + // Lightning Bolt (2-10 rank) have full basepoint and half bonus from level + // As on wiki: + // BUG: Rank 2 to 10 (and maybe 11) of Lightning Bolt will proc another Bolt with FULL damage (not halved). This bug is known and will probably be fixed soon. + // So - no add changes :) + CastSpell(pVictim, spellId, true, castItem, triggeredByAura); + + ((Player*)this)->AddSpellMod(mod, false); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(dummySpell->Id,0,time(NULL) + cooldown); + + return true; + } + break; + } + default: + break; + } + + // processed charge only counting case + if(!triggered_spell_id) + return true; + + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleDummyAuraProc: Spell %u have not existed triggered spell %u",dummySpell->Id,triggered_spell_id); + return false; + } + + // default case + if(!target || target!=this && !target->isAlive()) + return false; + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + if(basepoints0) + CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + else + CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const *procSpell, uint32 procFlags,WeaponAttackType attackType, uint32 cooldown) +{ + SpellEntry const* auraSpellInfo = triggeredByAura->GetSpellProto(); + + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = auraSpellInfo->EffectTriggerSpell[triggeredByAura->GetEffIndex()]; + Unit* target = !(procFlags & PROC_FLAG_HEAL) && IsPositiveSpell(triggered_spell_id) ? this : pVictim; + int32 basepoints0 = 0; + + switch(auraSpellInfo->SpellFamilyName) + { + case SPELLFAMILY_GENERIC: + { + switch(auraSpellInfo->Id) + { + // Aegis of Preservation + case 23780: + //Aegis Heal (instead non-existed triggered spell) + triggered_spell_id = 23781; + target = this; + break; + // Elune's Touch (moonkin mana restore) + case 24905: + { + // Elune's Touch (instead non-existed triggered spell) + triggered_spell_id = 33926; + basepoints0 = int32(0.3f * GetTotalAttackPowerValue(BASE_ATTACK)); + target = this; + break; + } + // Enlightenment + case 29601: + { + // only for cast with mana price + if(!procSpell || procSpell->powerType!=POWER_MANA || procSpell->manaCost==0 && procSpell->ManaCostPercentage==0 && procSpell->manaCostPerlevel==0) + return false; + break; // fall through to normal cast + } + // Health Restore + case 33510: + { + // at melee hit call std triggered spell + if(procFlags & PROC_FLAG_HIT_MELEE) + break; // fall through to normal cast + + // Mark of Conquest - else (at range hit) called custom case + triggered_spell_id = 39557; + target = this; + break; + } + // Shaleskin + case 36576: + return true; // nothing to do + // Forgotten Knowledge (Blade of Wizardry) + case 38319: + // only for harmful enemy targeted spell + if(!pVictim || pVictim==this || !procSpell || IsPositiveSpell(procSpell->Id)) + return false; + break; // fall through to normal cast + // Aura of Wrath (Darkmoon Card: Wrath trinket bonus) + case 39442: + { + // proc only at non-crit hits + if(procFlags & (PROC_FLAG_CRIT_MELEE|PROC_FLAG_CRIT_RANGED|PROC_FLAG_CRIT_SPELL)) + return false; + break; // fall through to normal cast + } + // Augment Pain (Timbal's Focusing Crystal trinket bonus) + case 45054: + { + if(!procSpell) + return false; + + //only periodic damage can trigger spell + bool found = false; + for(int j = 0; j < 3; ++j) + { + if( procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE || + procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_DAMAGE_PERCENT || + procSpell->EffectApplyAuraName[j]==SPELL_AURA_PERIODIC_LEECH ) + { + found = true; + break; + } + } + if(!found) + return false; + + break; // fall through to normal cast + } + // Evasive Maneuvers (Commendation of Kael'thas) + case 45057: + { + // damage taken that reduces below 35% health + // does NOT mean you must have been >= 35% before + if (int32(GetHealth())-int32(damage) >= int32(GetMaxHealth()*0.35f)) + return false; + break; // fall through to normal cast + } + } + + switch(triggered_spell_id) + { + // Setup + case 15250: + { + // applied only for main target + if(!pVictim || pVictim != getVictim()) + return false; + + // continue normal case + break; + } + // Shamanistic Rage triggered spell + case 30824: + basepoints0 = int32(GetTotalAttackPowerValue(BASE_ATTACK)*triggeredByAura->GetModifier()->m_amount/100); + break; + } + break; + } + case SPELLFAMILY_MAGE: + { + switch(auraSpellInfo->SpellIconID) + { + // Blazing Speed + case 2127: + //Blazing Speed (instead non-existed triggered spell) + triggered_spell_id = 31643; + target = this; + break; + } + switch(auraSpellInfo->Id) + { + // Persistent Shield (Scarab Brooch) + case 26467: + basepoints0 = int32(damage * 0.15f); + break; + } + break; + } + case SPELLFAMILY_WARRIOR: + { + //Rampage + if((auraSpellInfo->SpellFamilyFlags & 0x100000) && auraSpellInfo->SpellIconID==2006) + { + //all ranks have effect[0]==AURA (Proc Trigger Spell, non-existed) + //and effect[1]==TriggerSpell + if(auraSpellInfo->Effect[1]!=SPELL_EFFECT_TRIGGER_SPELL) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have wrong effect in RM",triggeredByAura->GetSpellProto()->Id); + return false; + } + triggered_spell_id = auraSpellInfo->EffectTriggerSpell[1]; + break; // fall through to normal cast + } + break; + } + case SPELLFAMILY_WARLOCK: + { + // Pyroclasm + if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000 && auraSpellInfo->SpellIconID==1137) + { + // last case for Hellfire that damage caster also but don't must stun caster + if( pVictim == this ) + return false; + + // custom chance + float chance = 0; + switch (triggeredByAura->GetId()) + { + case 18096: chance = 13.0f; break; + case 18073: chance = 26.0f; break; + } + if (!roll_chance_f(chance)) + return false; + + // Pyroclasm (instead non-existed triggered spell) + triggered_spell_id = 18093; + target = pVictim; + break; + } + // Drain Soul + if(auraSpellInfo->SpellFamilyFlags & 0x0000000000004000) + { + bool found = false; + Unit::AuraList const& mAddFlatModifier = GetAurasByType(SPELL_AURA_ADD_FLAT_MODIFIER); + for(Unit::AuraList::const_iterator i = mAddFlatModifier.begin(); i != mAddFlatModifier.end(); ++i) + { + //Improved Drain Soul + if ((*i)->GetModifier()->m_miscvalue == SPELLMOD_CHANCE_OF_SUCCESS && (*i)->GetSpellProto()->SpellIconID == 113) + { + int32 value2 = CalculateSpellDamage((*i)->GetSpellProto(),2,(*i)->GetSpellProto()->EffectBasePoints[2],this); + basepoints0 = value2 * GetMaxPower(POWER_MANA) / 100; + + // Drain Soul + triggered_spell_id = 18371; + target = this; + found = true; + break; + } + } + if(!found) + return false; + break; // fall through to normal cast + } + break; + } + case SPELLFAMILY_PRIEST: + { + //Blessed Recovery + if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL && auraSpellInfo->SpellIconID==1875) + { + switch (triggeredByAura->GetSpellProto()->Id) + { + case 27811: triggered_spell_id = 27813; break; + case 27815: triggered_spell_id = 27817; break; + case 27816: triggered_spell_id = 27818; break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in BR",triggeredByAura->GetSpellProto()->Id); + return false; + } + + int32 heal_amount = damage * triggeredByAura->GetModifier()->m_amount / 100; + basepoints0 = heal_amount/3; + target = this; + break; + } + // Shadowguard + if((auraSpellInfo->SpellFamilyFlags & 0x80000000LL) && auraSpellInfo->SpellVisual==7958) + { + switch(triggeredByAura->GetSpellProto()->Id) + { + case 18137: + triggered_spell_id = 28377; break; // Rank 1 + case 19308: + triggered_spell_id = 28378; break; // Rank 2 + case 19309: + triggered_spell_id = 28379; break; // Rank 3 + case 19310: + triggered_spell_id = 28380; break; // Rank 4 + case 19311: + triggered_spell_id = 28381; break; // Rank 5 + case 19312: + triggered_spell_id = 28382; break; // Rank 6 + case 25477: + triggered_spell_id = 28385; break; // Rank 7 + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in SG",triggeredByAura->GetSpellProto()->Id); + return false; + } + target = pVictim; + break; + } + break; + } + case SPELLFAMILY_DRUID: + { + switch(auraSpellInfo->Id) + { + // Leader of the Pack (triggering Improved Leader of the Pack heal) + case 24932: + { + if (triggeredByAura->GetModifier()->m_amount == 0) + return false; + basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; + triggered_spell_id = 34299; + break; + }; + // Druid Forms Trinket (Druid Tier5 Trinket, triggers different spells per Form) + case 37336: + { + switch(m_form) + { + case FORM_BEAR: + case FORM_DIREBEAR: + triggered_spell_id=37340; break;// Ursine Blessing + case FORM_CAT: + triggered_spell_id=37341; break;// Feline Blessing + case FORM_TREE: + triggered_spell_id=37342; break;// Slyvan Blessing + case FORM_MOONKIN: + triggered_spell_id=37343; break;// Lunar Blessing + case FORM_NONE: + triggered_spell_id=37344; break;// Cenarion Blessing (for caster form, except FORM_MOONKIN) + default: + return false; + } + + target = this; + break; + } + } + break; + } + case SPELLFAMILY_ROGUE: + { + if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000LL) + { + switch(auraSpellInfo->SpellIconID) + { + // Combat Potency + case 2260: + { + // skip non offhand attacks + if(attackType!=OFF_ATTACK) + return false; + break; // fall through to normal cast + } + } + } + break; + } + case SPELLFAMILY_PALADIN: + { + if(auraSpellInfo->SpellFamilyFlags == 0x00000000LL) + { + switch(auraSpellInfo->Id) + { + // Lightning Capacitor + case 37657: + { + // trinket ProcTriggerSpell but for safe checks for player + if(!castItem || !pVictim || !pVictim->isAlive() || GetTypeId()!=TYPEID_PLAYER) + return false; + + if(((Player*)this)->HasSpellCooldown(37657)) + return false; + + // stacking + CastSpell(this, 37658, true, castItem, triggeredByAura); + // 2.5s cooldown before it can stack again, current system allow 1 sec step in cooldown + ((Player*)this)->AddSpellCooldown(37657,0,time(NULL)+(roll_chance_i(50) ? 2 : 3)); + + // counting + uint32 count = 0; + AuraList const& dummyAura = GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator itr = dummyAura.begin(); itr != dummyAura.end(); ++itr) + if((*itr)->GetId()==37658) + ++count; + + // release at 3 aura in stack + if(count <= 2) + return true; // main triggered spell casted anyway + + RemoveAurasDueToSpell(37658); + CastSpell(pVictim, 37661, true, castItem, triggeredByAura); + return true; + } + // Healing Discount + case 37705: + // Healing Trance (instead non-existed triggered spell) + triggered_spell_id = 37706; + target = this; + break; + // HoTs on Heals (Fel Reaver's Piston trinket) + case 38299: + { + // at direct heal effect + if(!procSpell || !IsSpellHaveEffect(procSpell,SPELL_EFFECT_HEAL)) + return false; + + // single proc at time + AuraList const& scAuras = GetSingleCastAuras(); + for(AuraList::const_iterator itr = scAuras.begin(); itr != scAuras.end(); ++itr) + if((*itr)->GetId()==triggered_spell_id) + return false; + + // positive cast at victim instead self + target = pVictim; + break; + } + } + switch(auraSpellInfo->SpellIconID) + { + case 241: + { + switch(auraSpellInfo->EffectTriggerSpell[0]) + { + //Illumination + case 18350: + { + if(!procSpell) + return false; + + // procspell is triggered spell but we need mana cost of original casted spell + uint32 originalSpellId = procSpell->Id; + + // Holy Shock + if(procSpell->SpellFamilyName == SPELLFAMILY_PALADIN) + { + if(procSpell->SpellFamilyFlags & 0x0001000000000000LL) + { + switch(procSpell->Id) + { + case 25914: originalSpellId = 20473; break; + case 25913: originalSpellId = 20929; break; + case 25903: originalSpellId = 20930; break; + case 27175: originalSpellId = 27174; break; + case 33074: originalSpellId = 33072; break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in HShock",procSpell->Id); + return false; + } + } + } + + SpellEntry const *originalSpell = sSpellStore.LookupEntry(originalSpellId); + if(!originalSpell) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u unknown but selected as original in Illu",originalSpellId); + return false; + } + + // percent stored in effect 1 (class scripts) base points + int32 percent = auraSpellInfo->EffectBasePoints[1]+1; + + basepoints0 = originalSpell->manaCost*percent/100; + triggered_spell_id = 20272; + target = this; + break; + } + } + break; + } + } + } + if(auraSpellInfo->SpellFamilyFlags & 0x00080000) + { + switch(auraSpellInfo->SpellIconID) + { + //Judgement of Wisdom (overwrite non existing triggered spell call in spell.dbc + case 206: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + uint32 spell = 0; + switch(triggeredByAura->GetSpellProto()->Id) + { + case 20186: + triggered_spell_id = 20268; // Rank 1 + break; + case 20354: + triggered_spell_id = 20352; // Rank 2 + break; + case 20355: + triggered_spell_id = 20353; // Rank 3 + break; + case 27164: + triggered_spell_id = 27165; // Rank 4 + break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoW",triggeredByAura->GetSpellProto()->Id); + return false; + } + + pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); + return true; // no hidden cooldown + } + //Judgement of Light + case 299: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // overwrite non existing triggered spell call in spell.dbc + uint32 spell = 0; + switch(triggeredByAura->GetSpellProto()->Id) + { + case 20185: + triggered_spell_id = 20267; // Rank 1 + break; + case 20344: + triggered_spell_id = 20341; // Rank 2 + break; + case 20345: + triggered_spell_id = 20342; // Rank 3 + break; + case 20346: + triggered_spell_id = 20343; // Rank 4 + break; + case 27162: + triggered_spell_id = 27163; // Rank 5 + break; + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in JoL",triggeredByAura->GetSpellProto()->Id); + return false; + } + pVictim->CastSpell(pVictim,triggered_spell_id,true,castItem,triggeredByAura,GetGUID()); + return true; // no hidden cooldown + } + } + } + // custom check for proc spell + switch(auraSpellInfo->Id) + { + // Bonus Healing (item spell) + case 40971: + { + if(!pVictim || !pVictim->isAlive()) + return false; + + // bonus if health < 50% + if(pVictim->GetHealth() >= pVictim->GetMaxHealth()*triggeredByAura->GetModifier()->m_amount/100) + return false; + + // cast at target positive spell + target = pVictim; + break; + } + } + switch(triggered_spell_id) + { + // Seal of Command + case 20424: + // prevent chain of triggered spell from same triggered spell + if(procSpell && procSpell->Id==20424) + return false; + break; + } + break; + } + case SPELLFAMILY_SHAMAN: + { + if(auraSpellInfo->SpellFamilyFlags == 0x0000000000000000) + { + switch(auraSpellInfo->SpellIconID) + { + case 19: + { + switch(auraSpellInfo->Id) + { + case 23551: // Lightning Shield - Tier2: 8 pieces proc shield + { + // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) + triggered_spell_id = 23552; + target = pVictim; + break; + } + case 23552: // Lightning Shield - trigger shield damage + { + // Lightning Shield (overwrite non existing triggered spell call in spell.dbc) + triggered_spell_id = 27635; + target = pVictim; + break; + } + } + break; + } + // Mana Surge (Shaman T1 bonus) + case 87: + { + if(!procSpell) + return false; + + basepoints0 = procSpell->manaCost * 35/100; + triggered_spell_id = 23571; + target = this; + break; + } + //Nature's Guardian + case 2013: + { + if(GetTypeId()!=TYPEID_PLAYER) + return false; + + // damage taken that reduces below 30% health + // does NOT mean you must have been >= 30% before + if (10*(int32(GetHealth())-int32(damage)) >= 3*GetMaxHealth()) + return false; + + triggered_spell_id = 31616; + + // need check cooldown now + if( cooldown && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + basepoints0 = triggeredByAura->GetModifier()->m_amount * GetMaxHealth() / 100; + target = this; + if(pVictim && pVictim->isAlive()) + pVictim->getThreatManager().modifyThreatPercent(this,-10); + break; + } + } + } + + // Water Shield (we can't set cooldown for main spell - it's player casted spell + if((auraSpellInfo->SpellFamilyFlags & 0x0000002000000000LL) && auraSpellInfo->SpellVisual==7358) + { + target = this; + break; + } + + // Lightning Shield + if((auraSpellInfo->SpellFamilyFlags & 0x00000400) && auraSpellInfo->SpellVisual==37) + { + // overwrite non existing triggered spell call in spell.dbc + switch(triggeredByAura->GetSpellProto()->Id) + { + case 324: + triggered_spell_id = 26364; break; // Rank 1 + case 325: + triggered_spell_id = 26365; break; // Rank 2 + case 905: + triggered_spell_id = 26366; break; // Rank 3 + case 945: + triggered_spell_id = 26367; break; // Rank 4 + case 8134: + triggered_spell_id = 26369; break; // Rank 5 + case 10431: + triggered_spell_id = 26370; break; // Rank 6 + case 10432: + triggered_spell_id = 26363; break; // Rank 7 + case 25469: + triggered_spell_id = 26371; break; // Rank 8 + case 25472: + triggered_spell_id = 26372; break; // Rank 9 + default: + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u not handled in LShield",triggeredByAura->GetSpellProto()->Id); + return false; + } + + target = pVictim; + break; + } + break; + } + } + + // standard non-dummy case + if(!triggered_spell_id) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have 0 in EffectTriggered[%d], not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex()); + return false; + } + + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleProcTriggerSpell: Spell %u have not existed EffectTriggered[%d]=%u, not handled custom case?",auraSpellInfo->Id,triggeredByAura->GetEffIndex(),triggered_spell_id); + return false; + } + + // not allow proc extra attack spell at extra attack + if( m_extraAttacks && IsSpellHaveEffect(triggerEntry,SPELL_EFFECT_ADD_EXTRA_ATTACKS) ) + return false; + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + // default case + if(!target || target!=this && !target->isAlive()) + return false; + + if(basepoints0) + CastCustomSpell(target,triggered_spell_id,&basepoints0,NULL,NULL,true,castItem,triggeredByAura); + else + CastSpell(target,triggered_spell_id,true,castItem,triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) +{ + if(!pVictim || !pVictim->isAlive()) + return false; + + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER + ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; + + uint32 triggered_spell_id = 0; + + switch(scriptId) + { + case 836: // Improved Blizzard (Rank 1) + { + if (!procSpell || procSpell->SpellVisual!=9487) + return false; + triggered_spell_id = 12484; + break; + } + case 988: // Improved Blizzard (Rank 2) + { + if (!procSpell || procSpell->SpellVisual!=9487) + return false; + triggered_spell_id = 12485; + break; + } + case 989: // Improved Blizzard (Rank 3) + { + if (!procSpell || procSpell->SpellVisual!=9487) + return false; + triggered_spell_id = 12486; + break; + } + case 4086: // Improved Mend Pet (Rank 1) + case 4087: // Improved Mend Pet (Rank 2) + { + int32 chance = triggeredByAura->GetSpellProto()->EffectBasePoints[triggeredByAura->GetEffIndex()]; + if(!roll_chance_i(chance)) + return false; + + triggered_spell_id = 24406; + break; + } + case 4533: // Dreamwalker Raiment 2 pieces bonus + { + // Chance 50% + if (!roll_chance_i(50)) + return false; + + switch (pVictim->getPowerType()) + { + case POWER_MANA: triggered_spell_id = 28722; break; + case POWER_RAGE: triggered_spell_id = 28723; break; + case POWER_ENERGY: triggered_spell_id = 28724; break; + default: + return false; + } + break; + } + case 4537: // Dreamwalker Raiment 6 pieces bonus + triggered_spell_id = 28750; // Blessing of the Claw + break; + case 5497: // Improved Mana Gems (Serpent-Coil Braid) + triggered_spell_id = 37445; // Mana Surge + break; + } + + // not processed + if(!triggered_spell_id) + return false; + + // standard non-dummy case + SpellEntry const* triggerEntry = sSpellStore.LookupEntry(triggered_spell_id); + + if(!triggerEntry) + { + sLog.outError("Unit::HandleOverrideClassScriptAuraProc: Spell %u triggering for class script id %u",triggered_spell_id,scriptId); + return false; + } + + if( cooldown && GetTypeId()==TYPEID_PLAYER && ((Player*)this)->HasSpellCooldown(triggered_spell_id)) + return false; + + CastSpell(pVictim, triggered_spell_id, true, castItem, triggeredByAura); + + if( cooldown && GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->AddSpellCooldown(triggered_spell_id,0,time(NULL) + cooldown); + + return true; +} + +void Unit::setPowerType(Powers new_powertype) +{ + SetByteValue(UNIT_FIELD_BYTES_0, 3, new_powertype); + + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE); + } + } + + switch(new_powertype) + { + default: + case POWER_MANA: + break; + case POWER_RAGE: + SetMaxPower(POWER_RAGE,GetCreatePowers(POWER_RAGE)); + SetPower( POWER_RAGE,0); + break; + case POWER_FOCUS: + SetMaxPower(POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); + SetPower( POWER_FOCUS,GetCreatePowers(POWER_FOCUS)); + break; + case POWER_ENERGY: + SetMaxPower(POWER_ENERGY,GetCreatePowers(POWER_ENERGY)); + SetPower( POWER_ENERGY,0); + break; + case POWER_HAPPINESS: + SetMaxPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + SetPower(POWER_HAPPINESS,GetCreatePowers(POWER_HAPPINESS)); + break; + } +} + +FactionTemplateEntry const* Unit::getFactionTemplateEntry() const +{ + FactionTemplateEntry const* entry = sFactionTemplateStore.LookupEntry(getFaction()); + if(!entry) + { + static uint64 guid = 0; // prevent repeating spam same faction problem + + if(GetGUID() != guid) + { + if(GetTypeId() == TYPEID_PLAYER) + sLog.outError("Player %s have invalid faction (faction template id) #%u", ((Player*)this)->GetName(), getFaction()); + else + sLog.outError("Creature (template id: %u) have invalid faction (faction template id) #%u", ((Creature*)this)->GetCreatureInfo()->Entry, getFaction()); + guid = GetGUID(); + } + } + return entry; +} + +bool Unit::IsHostileTo(Unit const* unit) const +{ + // always non-hostile to self + if(unit==this) + return false; + + // always non-hostile to GM in GM mode + if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) + return false; + + // always hostile to enemy + if(getVictim()==unit || unit->getVictim()==this) + return true; + + // test pet/charm masters instead pers/charmeds + Unit const* testerOwner = GetCharmerOrOwner(); + Unit const* targetOwner = unit->GetCharmerOrOwner(); + + // always hostile to owner's enemy + if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) + return true; + + // always hostile to enemy owner + if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) + return true; + + // always hostile to owner of owner's enemy + if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) + return true; + + Unit const* tester = testerOwner ? testerOwner : this; + Unit const* target = targetOwner ? targetOwner : unit; + + // always non-hostile to target with common owner, or to owner/pet + if(tester==target) + return false; + + // special cases (Duel, etc) + if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) + { + Player const* pTester = (Player const*)tester; + Player const* pTarget = (Player const*)target; + + // Duel + if(pTester->duel && pTester->duel->opponent == pTarget && pTester->duel->startTime != 0) + return true; + + // Group + if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) + return false; + + // Sanctuary + if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) + return false; + + // PvP FFA state + if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) + return true; + + //= PvP states + // Green/Blue (can't attack) + if(pTester->GetTeam()==pTarget->GetTeam()) + return false; + + // Red (can attack) if true, Blue/Yellow (can't attack) in another case + return pTester->IsPvP() && pTarget->IsPvP(); + } + + // faction base cases + FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); + FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); + if(!tester_faction || !target_faction) + return false; + + if(target->isAttackingPlayer() && tester->IsContestedGuard()) + return true; + + // PvC forced reaction and reputation case + if(tester->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player*)tester)->m_forcedReactions.find(target_faction->faction); + if(forceItr!=((Player*)tester)->m_forcedReactions.end()) + return forceItr->second <= REP_HOSTILE; + + // if faction have reputation then hostile state for tester at 100% dependent from at_war state + if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) + if(raw_target_faction->reputationListID >=0) + if(FactionState const* factionState = ((Player*)tester)->GetFactionState(raw_target_faction)) + return (factionState->Flags & FACTION_FLAG_AT_WAR); + } + // CvP forced reaction and reputation case + else if(target->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); + if(forceItr!=((Player const*)target)->m_forcedReactions.end()) + return forceItr->second <= REP_HOSTILE; + + // apply reputation state + FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction); + if(raw_tester_faction && raw_tester_faction->reputationListID >=0 ) + return ((Player const*)target)->GetReputationRank(raw_tester_faction) <= REP_HOSTILE; + } + + // common faction based case (CvC,PvC,CvP) + return tester_faction->IsHostileTo(*target_faction); +} + +bool Unit::IsFriendlyTo(Unit const* unit) const +{ + // always friendly to self + if(unit==this) + return true; + + // always friendly to GM in GM mode + if(unit->GetTypeId()==TYPEID_PLAYER && ((Player const*)unit)->isGameMaster()) + return true; + + // always non-friendly to enemy + if(getVictim()==unit || unit->getVictim()==this) + return false; + + // test pet/charm masters instead pers/charmeds + Unit const* testerOwner = GetCharmerOrOwner(); + Unit const* targetOwner = unit->GetCharmerOrOwner(); + + // always non-friendly to owner's enemy + if(testerOwner && (testerOwner->getVictim()==unit || unit->getVictim()==testerOwner)) + return false; + + // always non-friendly to enemy owner + if(targetOwner && (getVictim()==targetOwner || targetOwner->getVictim()==this)) + return false; + + // always non-friendly to owner of owner's enemy + if(testerOwner && targetOwner && (testerOwner->getVictim()==targetOwner || targetOwner->getVictim()==testerOwner)) + return false; + + Unit const* tester = testerOwner ? testerOwner : this; + Unit const* target = targetOwner ? targetOwner : unit; + + // always friendly to target with common owner, or to owner/pet + if(tester==target) + return true; + + // special cases (Duel) + if(tester->GetTypeId()==TYPEID_PLAYER && target->GetTypeId()==TYPEID_PLAYER) + { + Player const* pTester = (Player const*)tester; + Player const* pTarget = (Player const*)target; + + // Duel + if(pTester->duel && pTester->duel->opponent == target && pTester->duel->startTime != 0) + return false; + + // Group + if(pTester->GetGroup() && pTester->GetGroup()==pTarget->GetGroup()) + return true; + + // Sanctuary + if(pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY) && pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_SANCTUARY)) + return true; + + // PvP FFA state + if(pTester->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP) && pTarget->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_FFA_PVP)) + return false; + + //= PvP states + // Green/Blue (non-attackable) + if(pTester->GetTeam()==pTarget->GetTeam()) + return true; + + // Blue (friendly/non-attackable) if not PVP, or Yellow/Red in another case (attackable) + return !pTarget->IsPvP(); + } + + // faction base cases + FactionTemplateEntry const*tester_faction = tester->getFactionTemplateEntry(); + FactionTemplateEntry const*target_faction = target->getFactionTemplateEntry(); + if(!tester_faction || !target_faction) + return false; + + if(target->isAttackingPlayer() && tester->IsContestedGuard()) + return false; + + // PvC forced reaction and reputation case + if(tester->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player const*)tester)->m_forcedReactions.find(target_faction->faction); + if(forceItr!=((Player const*)tester)->m_forcedReactions.end()) + return forceItr->second >= REP_FRIENDLY; + + // if faction have reputation then friendly state for tester at 100% dependent from at_war state + if(FactionEntry const* raw_target_faction = sFactionStore.LookupEntry(target_faction->faction)) + if(raw_target_faction->reputationListID >=0) + if(FactionState const* FactionState = ((Player*)tester)->GetFactionState(raw_target_faction)) + return !(FactionState->Flags & FACTION_FLAG_AT_WAR); + } + // CvP forced reaction and reputation case + else if(target->GetTypeId()==TYPEID_PLAYER) + { + // forced reaction + ForcedReactions::const_iterator forceItr = ((Player const*)target)->m_forcedReactions.find(tester_faction->faction); + if(forceItr!=((Player const*)target)->m_forcedReactions.end()) + return forceItr->second >= REP_FRIENDLY; + + // apply reputation state + if(FactionEntry const* raw_tester_faction = sFactionStore.LookupEntry(tester_faction->faction)) + if(raw_tester_faction->reputationListID >=0 ) + return ((Player const*)target)->GetReputationRank(raw_tester_faction) >= REP_FRIENDLY; + } + + // common faction based case (CvC,PvC,CvP) + return tester_faction->IsFriendlyTo(*target_faction); +} + +bool Unit::IsHostileToPlayers() const +{ + FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); + if(!my_faction) + return false; + + FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); + if(raw_faction && raw_faction->reputationListID >=0 ) + return false; + + return my_faction->IsHostileToPlayers(); +} + +bool Unit::IsNeutralToAll() const +{ + FactionTemplateEntry const* my_faction = getFactionTemplateEntry(); + if(!my_faction) + return true; + + FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); + if(raw_faction && raw_faction->reputationListID >=0 ) + return false; + + return my_faction->IsNeutralToAll(); +} + +bool Unit::Attack(Unit *victim, bool meleeAttack) +{ + if(!victim || victim == this) + return false; + + // dead units can neither attack nor be attacked + if(!isAlive() || !victim->isAlive()) + return false; + + // player cannot attack in mount state + if(GetTypeId()==TYPEID_PLAYER && IsMounted()) + return false; + + // nobody can attack GM in GM-mode + if(victim->GetTypeId()==TYPEID_PLAYER) + { + if(((Player*)victim)->isGameMaster()) + return false; + } + else + { + if(((Creature*)victim)->IsInEvadeMode()) + return false; + } + + // remove SPELL_AURA_MOD_UNATTACKABLE at attack (in case non-interruptible spells stun aura applied also that not let attack) + if(HasAuraType(SPELL_AURA_MOD_UNATTACKABLE)) + RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE); + + if (m_attacking) + { + if (m_attacking == victim) + { + // switch to melee attack from ranged/magic + if( meleeAttack && !hasUnitState(UNIT_STAT_MELEE_ATTACKING) ) + { + addUnitState(UNIT_STAT_MELEE_ATTACKING); + SendAttackStart(victim); + return true; + } + return false; + } + AttackStop(); + } + + //Set our target + SetUInt64Value(UNIT_FIELD_TARGET, victim->GetGUID()); + + if(meleeAttack) + addUnitState(UNIT_STAT_MELEE_ATTACKING); + m_attacking = victim; + m_attacking->_addAttacker(this); + + if(m_attacking->GetTypeId()==TYPEID_UNIT && ((Creature*)m_attacking)->AI()) + ((Creature*)m_attacking)->AI()->AttackedBy(this); + + if(GetTypeId()==TYPEID_UNIT) + { + WorldPacket data(SMSG_AI_REACTION, 12); + data << GetGUID(); + data << uint32(AI_REACTION_AGGRO); // Aggro sound + ((WorldObject*)this)->SendMessageToSet(&data, true); + + ((Creature*)this)->CallAssistence(); + ((Creature*)this)->SetCombatStartPosition(GetPositionX(), GetPositionY(), GetPositionZ()); + } + + // delay offhand weapon attack to next attack time + if(haveOffhandWeapon()) + resetAttackTimer(OFF_ATTACK); + + if(meleeAttack) + SendAttackStart(victim); + + return true; +} + +bool Unit::AttackStop() +{ + if (!m_attacking) + return false; + + Unit* victim = m_attacking; + + m_attacking->_removeAttacker(this); + m_attacking = NULL; + + //Clear our target + SetUInt64Value(UNIT_FIELD_TARGET, 0); + + clearUnitState(UNIT_STAT_MELEE_ATTACKING); + + InterruptSpell(CURRENT_MELEE_SPELL); + + if( GetTypeId()==TYPEID_UNIT ) + { + // reset call assistance + ((Creature*)this)->SetNoCallAssistence(false); + } + + SendAttackStop(victim); + + return true; +} + +void Unit::CombatStop(bool cast) +{ + if(cast& IsNonMeleeSpellCasted(false)) + InterruptNonMeleeSpells(false); + + AttackStop(); + RemoveAllAttackers(); + if( GetTypeId()==TYPEID_PLAYER ) + ((Player*)this)->SendAttackSwingCancelAttack(); // melee and ranged forced attack cancel + ClearInCombat(); +} + +void Unit::CombatStopWithPets(bool cast) +{ + CombatStop(cast); + if(Pet* pet = GetPet()) + pet->CombatStop(cast); + if(Unit* charm = GetCharm()) + charm->CombatStop(cast); + if(GetTypeId()==TYPEID_PLAYER) + { + GuardianPetList const& guardians = ((Player*)this)->GetGuardians(); + for(GuardianPetList::const_iterator itr = guardians.begin(); itr != guardians.end(); ++itr) + if(Unit* guardian = Unit::GetUnit(*this,*itr)) + guardian->CombatStop(cast); + } +} + +bool Unit::isAttackingPlayer() const +{ + if(hasUnitState(UNIT_STAT_ATTACK_PLAYER)) + return true; + + Pet* pet = GetPet(); + if(pet && pet->isAttackingPlayer()) + return true; + + Unit* charmed = GetCharm(); + if(charmed && charmed->isAttackingPlayer()) + return true; + + for (int8 i = 0; i < MAX_TOTEM; i++) + { + if(m_TotemSlot[i]) + { + Creature *totem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); + if(totem && totem->isAttackingPlayer()) + return true; + } + } + + return false; +} + +void Unit::RemoveAllAttackers() +{ + while (!m_attackers.empty()) + { + AttackerSet::iterator iter = m_attackers.begin(); + if(!(*iter)->AttackStop()) + { + sLog.outError("WORLD: Unit has an attacker that isn't attacking it!"); + m_attackers.erase(iter); + } + } +} + +void Unit::ModifyAuraState(AuraState flag, bool apply) +{ + if (apply) + { + if (!HasFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1))) + { + SetFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); + if(GetTypeId() == TYPEID_PLAYER) + { + const PlayerSpellMap& sp_list = ((Player*)this)->GetSpellMap(); + for (PlayerSpellMap::const_iterator itr = sp_list.begin(); itr != sp_list.end(); ++itr) + { + if(itr->second->state == PLAYERSPELL_REMOVED) continue; + SpellEntry const *spellInfo = sSpellStore.LookupEntry(itr->first); + if (!spellInfo || !IsPassiveSpell(itr->first)) continue; + if (spellInfo->CasterAuraState == flag) + CastSpell(this, itr->first, true, NULL); + } + } + } + } + else + { + if (HasFlag(UNIT_FIELD_AURASTATE,1<<(flag-1))) + { + RemoveFlag(UNIT_FIELD_AURASTATE, 1<<(flag-1)); + Unit::AuraMap& tAuras = GetAuras(); + for (Unit::AuraMap::iterator itr = tAuras.begin(); itr != tAuras.end();) + { + SpellEntry const* spellProto = (*itr).second->GetSpellProto(); + if (spellProto->CasterAuraState == flag) + { + // exceptions (applied at state but not removed at state change) + // Rampage + if(spellProto->SpellIconID==2006 && spellProto->SpellFamilyName==SPELLFAMILY_WARRIOR && spellProto->SpellFamilyFlags==0x100000) + { + ++itr; + continue; + } + + RemoveAura(itr); + } + else + ++itr; + } + } + } +} + +Unit *Unit::GetOwner() const +{ + uint64 ownerid = GetOwnerGUID(); + if(!ownerid) + return NULL; + return ObjectAccessor::GetUnit(*this, ownerid); +} + +Unit *Unit::GetCharmer() const +{ + if(uint64 charmerid = GetCharmerGUID()) + return ObjectAccessor::GetUnit(*this, charmerid); + return NULL; +} + +Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() +{ + uint64 guid = GetCharmerOrOwnerGUID(); + if(IS_PLAYER_GUID(guid)) + return ObjectAccessor::GetPlayer(*this, guid); + + return GetTypeId()==TYPEID_PLAYER ? (Player*)this : NULL; +} + +Pet* Unit::GetPet() const +{ + if(uint64 pet_guid = GetPetGUID()) + { + if(Pet* pet = ObjectAccessor::GetPet(pet_guid)) + return pet; + + sLog.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid)); + const_cast(this)->SetPet(0); + } + + return NULL; +} + +Unit* Unit::GetCharm() const +{ + if(uint64 charm_guid = GetCharmGUID()) + { + if(Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid)) + return pet; + + sLog.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid)); + const_cast(this)->SetCharm(0); + } + + return NULL; +} + +void Unit::SetPet(Pet* pet) +{ + SetUInt64Value(UNIT_FIELD_SUMMON,pet ? pet->GetGUID() : 0); + + // FIXME: hack, speed must be set only at follow + if(pet) + for(int i = 0; i < MAX_MOVE_TYPE; ++i) + pet->SetSpeed(UnitMoveType(i),m_speed_rate[i],true); +} + +void Unit::SetCharm(Unit* charmed) +{ + SetUInt64Value(UNIT_FIELD_CHARM,charmed ? charmed->GetGUID() : 0); +} + +void Unit::AddPlayerToVision(Player* plr) +{ + if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) + { + setActive(true); + GetMap()->SwitchGridContainers((Creature*)this, true); + } + m_sharedVision.push_back(plr); + plr->SetFarsightTarget(this); +} + +void Unit::RemovePlayerFromVision(Player* plr) +{ + m_sharedVision.remove(plr); + if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT) + { + setActive(false); + GetMap()->SwitchGridContainers((Creature*)this, false); + } + plr->ClearFarsight(); +} + +void Unit::RemoveAllFromVision() +{ + while (!m_sharedVision.empty()) + { + Player* plr = *m_sharedVision.begin(); + m_sharedVision.erase(m_sharedVision.begin()); + plr->ClearFarsight(); + } +} + +void Unit::UncharmSelf() +{ + if (!GetCharmer()) + return; + + RemoveSpellsCausingAura(SPELL_AURA_MOD_CHARM); +} + +void Unit::UnpossessSelf(bool attack) +{ + if (!isPossessed() || !GetCharmer()) + return; + + if (GetCharmer()->GetTypeId() == TYPEID_PLAYER) + ((Player*)GetCharmer())->RemovePossess(attack); + else + { + GetCharmer()->SetCharm(0); + SetCharmerGUID(0); + m_isPossessed = false; + } +} + +void Unit::UnsummonAllTotems() +{ + for (int8 i = 0; i < MAX_TOTEM; ++i) + { + if(!m_TotemSlot[i]) + continue; + + Creature *OldTotem = ObjectAccessor::GetCreature(*this, m_TotemSlot[i]); + if (OldTotem && OldTotem->isTotem()) + ((Totem*)OldTotem)->UnSummon(); + } +} + +void Unit::SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical) +{ + // we guess size + WorldPacket data(SMSG_SPELLHEALLOG, (8+8+4+4+1)); + data.append(pVictim->GetPackGUID()); + data.append(GetPackGUID()); + data << uint32(SpellID); + data << uint32(Damage); + data << uint8(critical ? 1 : 0); + data << uint8(0); // unused in client? + SendMessageToSet(&data, true); +} + +void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype, bool critical) +{ + WorldPacket data(SMSG_SPELLENERGIZELOG, (8+8+4+4+4+1)); + data.append(pVictim->GetPackGUID()); + data.append(GetPackGUID()); + data << uint32(SpellID); + data << uint32(powertype); + data << uint32(Damage); + //data << uint8(critical ? 1 : 0); // removed in 2.4.0 + SendMessageToSet(&data, true); +} + +uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint32 pdamage, DamageEffectType damagetype) +{ + if(!spellProto || !pVictim || damagetype==DIRECT_DAMAGE ) + return pdamage; + + int32 BonusDamage = 0; + if( GetTypeId()==TYPEID_UNIT ) + { + // Pets just add their bonus damage to their spell damage + // note that their spell damage is just gain of their own auras + if (((Creature*)this)->isPet()) + { + BonusDamage = ((Pet*)this)->GetBonusDamage(); + } + // For totems get damage bonus from owner (statue isn't totem in fact) + else if (((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) + { + if(Unit* owner = GetOwner()) + return owner->SpellDamageBonus(pVictim, spellProto, pdamage, damagetype); + } + } + + // Damage Done + uint32 CastingTime = !IsChanneledSpell(spellProto) ? GetSpellCastTime(spellProto) : GetSpellDuration(spellProto); + + // Taken/Done fixed damage bonus auras + int32 DoneAdvertisedBenefit = SpellBaseDamageBonus(GetSpellSchoolMask(spellProto))+BonusDamage; + int32 TakenAdvertisedBenefit = SpellBaseDamageBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); + + // Damage over Time spells bonus calculation + float DotFactor = 1.0f; + if(damagetype == DOT) + { + int32 DotDuration = GetSpellDuration(spellProto); + // 200% limit + if(DotDuration > 0) + { + if(DotDuration > 30000) DotDuration = 30000; + if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; + int x = 0; + for(int j = 0; j < 3; j++) + { + if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_DAMAGE || + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) + { + x = j; + break; + } + } + int DotTicks = 6; + if(spellProto->EffectAmplitude[x] != 0) + DotTicks = DotDuration / spellProto->EffectAmplitude[x]; + if(DotTicks) + { + DoneAdvertisedBenefit /= DotTicks; + TakenAdvertisedBenefit /= DotTicks; + } + } + } + + // Taken/Done total percent damage auras + float DoneTotalMod = 1.0f; + float TakenTotalMod = 1.0f; + + // ..done + AuraList const& mModDamagePercentDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_DONE); + for(AuraList::const_iterator i = mModDamagePercentDone.begin(); i != mModDamagePercentDone.end(); ++i) + { + if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) && + (*i)->GetSpellProto()->EquippedItemClass == -1 && + // -1 == any item class (not wand then) + (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) + // 0 == any inventory type (not wand then) + { + DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + } + } + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // ..taken + AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); + for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) + if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // .. taken pct: scripted (increases damage of * against targets *) + AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) + { + switch((*i)->GetModifier()->m_miscvalue) + { + //Molten Fury + case 4920: case 4919: + if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_20_PERCENT)) + TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; break; + } + } + + // .. taken pct: dummy auras + AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) + { + switch((*i)->GetSpellProto()->SpellIconID) + { + //Cheat Death + case 2109: + if( ((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) ) + { + if(pVictim->GetTypeId() != TYPEID_PLAYER) + continue; + float mod = -((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL)*2*4; + if (mod < (*i)->GetModifier()->m_amount) + mod = (*i)->GetModifier()->m_amount; + TakenTotalMod *= (mod+100.0f)/100.0f; + } + break; + //Mangle + case 2312: + for(int j=0;j<3;j++) + { + if(GetEffectMechanic(spellProto, j)==MECHANIC_BLEED) + { + TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; + break; + } + } + break; + } + } + + // Distribute Damage over multiple effects, reduce by AoE + CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); + + // 50% for damage and healing spells for leech spells from damage bonus and 0% from healing + for(int j = 0; j < 3; ++j) + { + if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || + spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) + { + CastingTime /= 2; + break; + } + } + + switch(spellProto->SpellFamilyName) + { + case SPELLFAMILY_MAGE: + // Ignite - do not modify, it is (8*Rank)% damage of procing Spell + if(spellProto->Id==12654) + { + return pdamage; + } + // Ice Lance + else if((spellProto->SpellFamilyFlags & 0x20000LL) && spellProto->SpellIconID == 186) + { + CastingTime /= 3; // applied 1/3 bonuses in case generic target + if(pVictim->isFrozen()) // and compensate this for frozen target. + TakenTotalMod *= 3.0f; + } + // Pyroblast - 115% of Fire Damage, DoT - 20% of Fire Damage + else if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 184 ) + { + DotFactor = damagetype == DOT ? 0.2f : 1.0f; + CastingTime = damagetype == DOT ? 3500 : 4025; + } + // Fireball - 100% of Fire Damage, DoT - 0% of Fire Damage + else if((spellProto->SpellFamilyFlags & 0x1LL) && spellProto->SpellIconID == 185) + { + CastingTime = 3500; + DotFactor = damagetype == DOT ? 0.0f : 1.0f; + } + // Molten armor + else if (spellProto->SpellFamilyFlags & 0x0000000800000000LL) + { + CastingTime = 0; + } + // Arcane Missiles triggered spell + else if ((spellProto->SpellFamilyFlags & 0x200000LL) && spellProto->SpellIconID == 225) + { + CastingTime = 1000; + } + // Blizzard triggered spell + else if ((spellProto->SpellFamilyFlags & 0x80080LL) && spellProto->SpellIconID == 285) + { + CastingTime = 500; + } + break; + case SPELLFAMILY_WARLOCK: + // Life Tap + if((spellProto->SpellFamilyFlags & 0x40000LL) && spellProto->SpellIconID == 208) + { + CastingTime = 2800; // 80% from +shadow damage + DoneTotalMod = 1.0f; + TakenTotalMod = 1.0f; + } + // Dark Pact + else if((spellProto->SpellFamilyFlags & 0x80000000LL) && spellProto->SpellIconID == 154 && GetPetGUID()) + { + CastingTime = 3360; // 96% from +shadow damage + DoneTotalMod = 1.0f; + TakenTotalMod = 1.0f; + } + // Soul Fire - 115% of Fire Damage + else if((spellProto->SpellFamilyFlags & 0x8000000000LL) && spellProto->SpellIconID == 184) + { + CastingTime = 4025; + } + // Curse of Agony - 120% of Shadow Damage + else if((spellProto->SpellFamilyFlags & 0x0000000400LL) && spellProto->SpellIconID == 544) + { + DotFactor = 1.2f; + } + // Drain Mana - 0% of Shadow Damage + else if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 548) + { + CastingTime = 0; + } + // Drain Soul 214.3% + else if ((spellProto->SpellFamilyFlags & 0x4000LL) && spellProto->SpellIconID == 113 ) + { + CastingTime = 7500; + } + // Hellfire + else if ((spellProto->SpellFamilyFlags & 0x40LL) && spellProto->SpellIconID == 937) + { + CastingTime = damagetype == DOT ? 5000 : 500; // self damage seems to be so + } + // Unstable Affliction - 180% + else if (spellProto->Id == 31117 && spellProto->SpellIconID == 232) + { + CastingTime = 6300; + } + // Corruption 93% + else if ((spellProto->SpellFamilyFlags & 0x2LL) && spellProto->SpellIconID == 313) + { + DotFactor = 0.93f; + } + break; + case SPELLFAMILY_PALADIN: + // Consecration - 95% of Holy Damage + if((spellProto->SpellFamilyFlags & 0x20LL) && spellProto->SpellIconID == 51) + { + DotFactor = 0.95f; + CastingTime = 3500; + } + // Seal of Righteousness - 10.2%/9.8% ( based on weapon type ) of Holy Damage, multiplied by weapon speed + else if((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 25) + { + Item *item = ((Player*)this)->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND); + float wspeed = GetAttackTime(BASE_ATTACK)/1000.0f; + + if( item && item->GetProto()->InventoryType == INVTYPE_2HWEAPON) + CastingTime = uint32(wspeed*3500*0.102f); + else + CastingTime = uint32(wspeed*3500*0.098f); + } + // Judgement of Righteousness - 73% + else if ((spellProto->SpellFamilyFlags & 1024) && spellProto->SpellIconID == 25) + { + CastingTime = 2555; + } + // Seal of Vengeance - 17% per Fully Stacked Tick - 5 Applications + else if ((spellProto->SpellFamilyFlags & 0x80000000000LL) && spellProto->SpellIconID == 2292) + { + DotFactor = 0.17f; + CastingTime = 3500; + } + // Holy shield - 5% of Holy Damage + else if ((spellProto->SpellFamilyFlags & 0x4000000000LL) && spellProto->SpellIconID == 453) + { + CastingTime = 175; + } + // Blessing of Sanctuary - 0% + else if ((spellProto->SpellFamilyFlags & 0x10000000LL) && spellProto->SpellIconID == 29) + { + CastingTime = 0; + } + // Seal of Righteousness trigger - already computed for parent spell + else if ( spellProto->SpellFamilyName==SPELLFAMILY_PALADIN && spellProto->SpellIconID==25 && spellProto->AttributesEx4 & 0x00800000LL ) + { + return pdamage; + } + break; + case SPELLFAMILY_SHAMAN: + // totem attack + if (spellProto->SpellFamilyFlags & 0x000040000000LL) + { + if (spellProto->SpellIconID == 33) // Fire Nova totem attack must be 21.4%(untested) + CastingTime = 749; // ignore CastingTime and use as modifier + else if (spellProto->SpellIconID == 680) // Searing Totem attack 8% + CastingTime = 280; // ignore CastingTime and use as modifier + else if (spellProto->SpellIconID == 37) // Magma totem attack must be 6.67%(untested) + CastingTime = 234; // ignore CastingTimePenalty and use as modifier + } + // Lightning Shield (and proc shield from T2 8 pieces bonus ) 33% per charge + else if( (spellProto->SpellFamilyFlags & 0x00000000400LL) || spellProto->Id == 23552) + CastingTime = 1155; // ignore CastingTimePenalty and use as modifier + break; + case SPELLFAMILY_PRIEST: + // Mana Burn - 0% of Shadow Damage + if((spellProto->SpellFamilyFlags & 0x10LL) && spellProto->SpellIconID == 212) + { + CastingTime = 0; + } + // Mind Flay - 59% of Shadow Damage + else if((spellProto->SpellFamilyFlags & 0x800000LL) && spellProto->SpellIconID == 548) + { + CastingTime = 2065; + } + // Holy Fire - 86.71%, DoT - 16.5% + else if ((spellProto->SpellFamilyFlags & 0x100000LL) && spellProto->SpellIconID == 156) + { + DotFactor = damagetype == DOT ? 0.165f : 1.0f; + CastingTime = damagetype == DOT ? 3500 : 3035; + } + // Shadowguard - 28% per charge + else if ((spellProto->SpellFamilyFlags & 0x2000000LL) && spellProto->SpellIconID == 19) + { + CastingTime = 980; + } + // Touch of Weakeness - 10% + else if ((spellProto->SpellFamilyFlags & 0x80000LL) && spellProto->SpellIconID == 1591) + { + CastingTime = 350; + } + // Reflective Shield (back damage) - 0% (other spells fit to check not have damage effects/auras) + else if (spellProto->SpellFamilyFlags == 0 && spellProto->SpellIconID == 566) + { + CastingTime = 0; + } + // Holy Nova - 14% + else if ((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 1874) + { + CastingTime = 500; + } + break; + case SPELLFAMILY_DRUID: + // Hurricane triggered spell + if((spellProto->SpellFamilyFlags & 0x400000LL) && spellProto->SpellIconID == 220) + { + CastingTime = 500; + } + break; + case SPELLFAMILY_WARRIOR: + case SPELLFAMILY_HUNTER: + case SPELLFAMILY_ROGUE: + CastingTime = 0; + break; + default: + break; + } + + float LvlPenalty = CalculateLevelPenalty(spellProto); + + // Spellmod SpellDamage + float SpellModSpellDamage = 100.0f; + + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); + + SpellModSpellDamage /= 100.0f; + + float DoneActualBenefit = DoneAdvertisedBenefit * (CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; + float TakenActualBenefit = TakenAdvertisedBenefit; + if(spellProto->SpellFamilyName) + TakenActualBenefit *= (CastingTime / 3500.0f) * DotFactor * LvlPenalty; + + float tmpDamage = (float(pdamage)+DoneActualBenefit)*DoneTotalMod; + + // Add flat bonus from spell damage versus + tmpDamage += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_FLAT_SPELL_DAMAGE_VERSUS, creatureTypeMask); + + // apply spellmod to Done damage + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, tmpDamage); + + tmpDamage = (tmpDamage+TakenActualBenefit)*TakenTotalMod; + + if( GetTypeId() == TYPEID_UNIT && !((Creature*)this)->isPet() ) + tmpDamage *= ((Creature*)this)->GetSpellDamageMod(((Creature*)this)->GetCreatureInfo()->rank); + + return tmpDamage > 0 ? uint32(tmpDamage) : 0; +} + +int32 Unit::SpellBaseDamageBonus(SpellSchoolMask schoolMask) +{ + int32 DoneAdvertisedBenefit = 0; + + // ..done + AuraList const& mDamageDone = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE); + for(AuraList::const_iterator i = mDamageDone.begin();i != mDamageDone.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0 && + (*i)->GetSpellProto()->EquippedItemClass == -1 && + // -1 == any item class (not wand then) + (*i)->GetSpellProto()->EquippedItemInventoryTypeMask == 0 ) + // 0 == any inventory type (not wand then) + DoneAdvertisedBenefit += (*i)->GetModifier()->m_amount; + + if (GetTypeId() == TYPEID_PLAYER) + { + // Damage bonus from stats + AuraList const& mDamageDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_STAT_PERCENT); + for(AuraList::const_iterator i = mDamageDoneOfStatPercent.begin();i != mDamageDoneOfStatPercent.end(); ++i) + { + if((*i)->GetModifier()->m_miscvalue & schoolMask) + { + SpellEntry const* iSpellProto = (*i)->GetSpellProto(); + uint8 eff = (*i)->GetEffIndex(); + + // stat used dependent from next effect aura SPELL_AURA_MOD_SPELL_HEALING presence and misc value (stat index) + Stats usedStat = STAT_INTELLECT; + if(eff < 2 && iSpellProto->EffectApplyAuraName[eff+1]==SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT) + usedStat = Stats(iSpellProto->EffectMiscValue[eff+1]); + + DoneAdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); + } + } + // ... and attack power + AuraList const& mDamageDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_DAMAGE_OF_ATTACK_POWER); + for(AuraList::const_iterator i =mDamageDonebyAP.begin();i != mDamageDonebyAP.end(); ++i) + if ((*i)->GetModifier()->m_miscvalue & schoolMask) + DoneAdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); + + } + return DoneAdvertisedBenefit; +} + +int32 Unit::SpellBaseDamageBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) +{ + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + + int32 TakenAdvertisedBenefit = 0; + // ..done (for creature type by mask) in taken + AuraList const& mDamageDoneCreature = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); + for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; + + // ..taken + AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); + for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) + TakenAdvertisedBenefit += (*i)->GetModifier()->m_amount; + + return TakenAdvertisedBenefit; +} + +bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType) +{ + // not criting spell + if((spellProto->AttributesEx2 & SPELL_ATTR_EX2_CANT_CRIT)) + return false; + + float crit_chance = 0.0f; + switch(spellProto->DmgClass) + { + case SPELL_DAMAGE_CLASS_NONE: + return false; + case SPELL_DAMAGE_CLASS_MAGIC: + { + if (schoolMask & SPELL_SCHOOL_MASK_NORMAL) + crit_chance = 0.0f; + // For other schools + else if (GetTypeId() == TYPEID_PLAYER) + crit_chance = GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1 + GetFirstSchoolInMask(schoolMask)); + else + { + crit_chance = m_baseSpellCritChance; + crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); + } + // taken + if (pVictim && !IsPositiveSpell(spellProto->Id)) + { + // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE + crit_chance += pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE, schoolMask); + // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE + crit_chance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE); + // Modify by player victim resilience + if (pVictim->GetTypeId() == TYPEID_PLAYER) + crit_chance -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL); + // scripted (increase crit chance ... against ... target by x% + if(pVictim->isFrozen()) // Shatter + { + AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) + { + switch((*i)->GetModifier()->m_miscvalue) + { + case 849: crit_chance+= 10.0f; break; //Shatter Rank 1 + case 910: crit_chance+= 20.0f; break; //Shatter Rank 2 + case 911: crit_chance+= 30.0f; break; //Shatter Rank 3 + case 912: crit_chance+= 40.0f; break; //Shatter Rank 4 + case 913: crit_chance+= 50.0f; break; //Shatter Rank 5 + } + } + } + } + break; + } + case SPELL_DAMAGE_CLASS_MELEE: + case SPELL_DAMAGE_CLASS_RANGED: + { + if (pVictim) + { + crit_chance = GetUnitCriticalChance(attackType, pVictim); + crit_chance+= (int32(GetMaxSkillValueForLevel(pVictim)) - int32(pVictim->GetDefenseSkillValue(this))) * 0.04f; + crit_chance+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask); + } + break; + } + default: + return false; + } + // percent done + // only players use intelligence for critical chance computations + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance); + + crit_chance = crit_chance > 0.0f ? crit_chance : 0.0f; + if (roll_chance_f(crit_chance)) + return true; + return false; +} + +uint32 Unit::SpellCriticalBonus(SpellEntry const *spellProto, uint32 damage, Unit *pVictim) +{ + // Calculate critical bonus + int32 crit_bonus; + switch(spellProto->DmgClass) + { + case SPELL_DAMAGE_CLASS_MELEE: // for melee based spells is 100% + case SPELL_DAMAGE_CLASS_RANGED: + // TODO: write here full calculation for melee/ranged spells + crit_bonus = damage; + break; + default: + crit_bonus = damage / 2; // for spells is 50% + break; + } + + // adds additional damage to crit_bonus (from talents) + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRIT_DAMAGE_BONUS, crit_bonus); + + if(pVictim) + { + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + crit_bonus = int32(crit_bonus * GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRIT_PERCENT_VERSUS, creatureTypeMask)); + } + + if(crit_bonus > 0) + damage += crit_bonus; + + return damage; +} + +uint32 Unit::SpellHealingBonus(SpellEntry const *spellProto, uint32 healamount, DamageEffectType damagetype, Unit *pVictim) +{ + // For totems get healing bonus from owner (statue isn't totem in fact) + if( GetTypeId()==TYPEID_UNIT && ((Creature*)this)->isTotem() && ((Totem*)this)->GetTotemType()!=TOTEM_STATUE) + if(Unit* owner = GetOwner()) + return owner->SpellHealingBonus(spellProto, healamount, damagetype, pVictim); + + // Healing Done + + // These Spells are doing fixed amount of healing (TODO found less hack-like check) + if (spellProto->Id == 15290 || spellProto->Id == 39373 || + spellProto->Id == 33778 || spellProto->Id == 379 || + spellProto->Id == 38395 || spellProto->Id == 40972) + return healamount; + + int32 AdvertisedBenefit = SpellBaseHealingBonus(GetSpellSchoolMask(spellProto)); + uint32 CastingTime = GetSpellCastTime(spellProto); + + // Healing Taken + AdvertisedBenefit += SpellBaseHealingBonusForVictim(GetSpellSchoolMask(spellProto), pVictim); + + // Blessing of Light dummy effects healing taken from Holy Light and Flash of Light + if (spellProto->SpellFamilyName == SPELLFAMILY_PALADIN && (spellProto->SpellFamilyFlags & 0x00000000C0000000LL)) + { + AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator i = mDummyAuras.begin();i != mDummyAuras.end(); ++i) + { + if((*i)->GetSpellProto()->SpellVisual == 9180) + { + // Flash of Light + if ((spellProto->SpellFamilyFlags & 0x0000000040000000LL) && (*i)->GetEffIndex() == 1) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + // Holy Light + else if ((spellProto->SpellFamilyFlags & 0x0000000080000000LL) && (*i)->GetEffIndex() == 0) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + } + } + } + + float ActualBenefit = 0.0f; + + if (AdvertisedBenefit != 0) + { + // Healing over Time spells + float DotFactor = 1.0f; + if(damagetype == DOT) + { + int32 DotDuration = GetSpellDuration(spellProto); + if(DotDuration > 0) + { + // 200% limit + if(DotDuration > 30000) DotDuration = 30000; + if(!IsChanneledSpell(spellProto)) DotFactor = DotDuration / 15000.0f; + int x = 0; + for(int j = 0; j < 3; j++) + { + if( spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && ( + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_HEAL || + spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH) ) + { + x = j; + break; + } + } + int DotTicks = 6; + if(spellProto->EffectAmplitude[x] != 0) + DotTicks = DotDuration / spellProto->EffectAmplitude[x]; + if(DotTicks) + AdvertisedBenefit /= DotTicks; + } + } + + // distribute healing to all effects, reduce AoE damage + CastingTime = GetCastingTimeForBonus( spellProto, damagetype, CastingTime ); + + // 0% bonus for damage and healing spells for leech spells from healing bonus + for(int j = 0; j < 3; ++j) + { + if( spellProto->Effect[j] == SPELL_EFFECT_HEALTH_LEECH || + spellProto->Effect[j] == SPELL_EFFECT_APPLY_AURA && spellProto->EffectApplyAuraName[j] == SPELL_AURA_PERIODIC_LEECH ) + { + CastingTime = 0; + break; + } + } + + // Exception + switch (spellProto->SpellFamilyName) + { + case SPELLFAMILY_SHAMAN: + // Healing stream from totem (add 6% per tick from hill bonus owner) + if (spellProto->SpellFamilyFlags & 0x000000002000LL) + CastingTime = 210; + // Earth Shield 30% per charge + else if (spellProto->SpellFamilyFlags & 0x40000000000LL) + CastingTime = 1050; + break; + case SPELLFAMILY_DRUID: + // Lifebloom + if (spellProto->SpellFamilyFlags & 0x1000000000LL) + { + CastingTime = damagetype == DOT ? 3500 : 1200; + DotFactor = damagetype == DOT ? 0.519f : 1.0f; + } + // Tranquility triggered spell + else if (spellProto->SpellFamilyFlags & 0x80LL) + CastingTime = 667; + // Rejuvenation + else if (spellProto->SpellFamilyFlags & 0x10LL) + DotFactor = 0.845f; + // Regrowth + else if (spellProto->SpellFamilyFlags & 0x40LL) + { + DotFactor = damagetype == DOT ? 0.705f : 1.0f; + CastingTime = damagetype == DOT ? 3500 : 1010; + } + break; + case SPELLFAMILY_PRIEST: + // Holy Nova - 14% + if ((spellProto->SpellFamilyFlags & 0x8000000LL) && spellProto->SpellIconID == 1874) + CastingTime = 500; + break; + case SPELLFAMILY_PALADIN: + // Seal and Judgement of Light + if ( spellProto->SpellFamilyFlags & 0x100040000LL ) + CastingTime = 0; + break; + case SPELLFAMILY_WARRIOR: + case SPELLFAMILY_ROGUE: + case SPELLFAMILY_HUNTER: + CastingTime = 0; + break; + } + + float LvlPenalty = CalculateLevelPenalty(spellProto); + + // Spellmod SpellDamage + float SpellModSpellDamage = 100.0f; + + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_SPELL_BONUS_DAMAGE,SpellModSpellDamage); + + SpellModSpellDamage /= 100.0f; + + ActualBenefit = (float)AdvertisedBenefit * ((float)CastingTime / 3500.0f) * DotFactor * SpellModSpellDamage * LvlPenalty; + } + + // use float as more appropriate for negative values and percent applying + float heal = healamount + ActualBenefit; + + // TODO: check for ALL/SPELLS type + // Healing done percent + AuraList const& mHealingDonePct = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE_PERCENT); + for(AuraList::const_iterator i = mHealingDonePct.begin();i != mHealingDonePct.end(); ++i) + heal *= (100.0f + (*i)->GetModifier()->m_amount) / 100.0f; + + // apply spellmod to Done amount + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, damagetype == DOT ? SPELLMOD_DOT : SPELLMOD_DAMAGE, heal); + + // Healing Wave cast + if (spellProto->SpellFamilyName == SPELLFAMILY_SHAMAN && spellProto->SpellFamilyFlags & 0x0000000000000040LL) + { + // Search for Healing Way on Victim (stack up to 3 time) + int32 pctMod = 0; + Unit::AuraList const& auraDummy = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(Unit::AuraList::const_iterator itr = auraDummy.begin(); itr!=auraDummy.end(); ++itr) + if((*itr)->GetId() == 29203) + pctMod += (*itr)->GetModifier()->m_amount; + // Apply bonus + if (pctMod) + heal = heal * (100 + pctMod) / 100; + } + + // Healing taken percent + float minval = pVictim->GetMaxNegativeAuraModifier(SPELL_AURA_MOD_HEALING_PCT); + if(minval) + heal *= (100.0f + minval) / 100.0f; + + float maxval = pVictim->GetMaxPositiveAuraModifier(SPELL_AURA_MOD_HEALING_PCT); + if(maxval) + heal *= (100.0f + maxval) / 100.0f; + + if (heal < 0) heal = 0; + + return uint32(heal); +} + +int32 Unit::SpellBaseHealingBonus(SpellSchoolMask schoolMask) +{ + int32 AdvertisedBenefit = 0; + + AuraList const& mHealingDone = GetAurasByType(SPELL_AURA_MOD_HEALING_DONE); + for(AuraList::const_iterator i = mHealingDone.begin();i != mHealingDone.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + + // Healing bonus of spirit, intellect and strength + if (GetTypeId() == TYPEID_PLAYER) + { + // Healing bonus from stats + AuraList const& mHealingDoneOfStatPercent = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_STAT_PERCENT); + for(AuraList::const_iterator i = mHealingDoneOfStatPercent.begin();i != mHealingDoneOfStatPercent.end(); ++i) + { + // stat used dependent from misc value (stat index) + Stats usedStat = Stats((*i)->GetSpellProto()->EffectMiscValue[(*i)->GetEffIndex()]); + AdvertisedBenefit += int32(GetStat(usedStat) * (*i)->GetModifier()->m_amount / 100.0f); + } + + // ... and attack power + AuraList const& mHealingDonebyAP = GetAurasByType(SPELL_AURA_MOD_SPELL_HEALING_OF_ATTACK_POWER); + for(AuraList::const_iterator i = mHealingDonebyAP.begin();i != mHealingDonebyAP.end(); ++i) + if ((*i)->GetModifier()->m_miscvalue & schoolMask) + AdvertisedBenefit += int32(GetTotalAttackPowerValue(BASE_ATTACK) * (*i)->GetModifier()->m_amount / 100.0f); + } + return AdvertisedBenefit; +} + +int32 Unit::SpellBaseHealingBonusForVictim(SpellSchoolMask schoolMask, Unit *pVictim) +{ + int32 AdvertisedBenefit = 0; + AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_HEALING); + for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) + if(((*i)->GetModifier()->m_miscvalue & schoolMask) != 0) + AdvertisedBenefit += (*i)->GetModifier()->m_amount; + return AdvertisedBenefit; +} + +bool Unit::IsImmunedToDamage(SpellSchoolMask shoolMask, bool useCharges) +{ + // no charges dependent checks + SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; + for (SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) + if(itr->type & shoolMask) + return true; + + // charges dependent checks + SpellImmuneList const& damageList = m_spellImmune[IMMUNITY_DAMAGE]; + for (SpellImmuneList::const_iterator itr = damageList.begin(); itr != damageList.end(); ++itr) + { + if(itr->type & shoolMask) + { + if(useCharges) + { + AuraList const& auraDamageImmunity = GetAurasByType(SPELL_AURA_DAMAGE_IMMUNITY); + for(AuraList::const_iterator auraItr = auraDamageImmunity.begin(); auraItr != auraDamageImmunity.end(); ++auraItr) + { + if((*auraItr)->GetId()==itr->spellId) + { + if((*auraItr)->m_procCharges > 0) + { + --(*auraItr)->m_procCharges; + if((*auraItr)->m_procCharges==0) + RemoveAurasDueToSpell(itr->spellId); + } + break; + } + } + } + return true; + } + } + + return false; +} + +bool Unit::IsImmunedToSpell(SpellEntry const* spellInfo, bool useCharges) +{ + if (!spellInfo) + return false; + + // no charges first + + //FIX ME this hack: don't get feared if stunned + if (spellInfo->Mechanic == MECHANIC_FEAR ) + { + if ( hasUnitState(UNIT_STAT_STUNNED) ) + return true; + } + + // not have spells with charges currently + SpellImmuneList const& dispelList = m_spellImmune[IMMUNITY_DISPEL]; + for(SpellImmuneList::const_iterator itr = dispelList.begin(); itr != dispelList.end(); ++itr) + if(itr->type == spellInfo->Dispel) + return true; + + if( !(spellInfo->AttributesEx & SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE) && (spellInfo->Id != 42292)) // unaffected by school immunity + { + // not have spells with charges currently + SpellImmuneList const& schoolList = m_spellImmune[IMMUNITY_SCHOOL]; + for(SpellImmuneList::const_iterator itr = schoolList.begin(); itr != schoolList.end(); ++itr) + if( !(IsPositiveSpell(itr->spellId) && IsPositiveSpell(spellInfo->Id)) && + (itr->type & GetSpellSchoolMask(spellInfo)) ) + return true; + } + + // charges dependent checks + + SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; + for(SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) + { + if(itr->type == spellInfo->Mechanic) + { + if(useCharges) + { + AuraList const& auraMechImmunity = GetAurasByType(SPELL_AURA_MECHANIC_IMMUNITY); + for(AuraList::const_iterator auraItr = auraMechImmunity.begin(); auraItr != auraMechImmunity.end(); ++auraItr) + { + if((*auraItr)->GetId()==itr->spellId) + { + if((*auraItr)->m_procCharges > 0) + { + --(*auraItr)->m_procCharges; + if((*auraItr)->m_procCharges==0) + RemoveAurasDueToSpell(itr->spellId); + } + break; + } + } + } + return true; + } + } + + return false; +} + +bool Unit::IsImmunedToSpellEffect(uint32 effect, uint32 mechanic) const +{ + //If m_immuneToEffect type contain this effect type, IMMUNE effect. + SpellImmuneList const& effectList = m_spellImmune[IMMUNITY_EFFECT]; + for (SpellImmuneList::const_iterator itr = effectList.begin(); itr != effectList.end(); ++itr) + if(itr->type == effect) + return true; + + SpellImmuneList const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC]; + for (SpellImmuneList::const_iterator itr = mechanicList.begin(); itr != mechanicList.end(); ++itr) + if(itr->type == mechanic) + return true; + + return false; +} + +bool Unit::IsDamageToThreatSpell(SpellEntry const * spellInfo) const +{ + if(!spellInfo) + return false; + + uint32 family = spellInfo->SpellFamilyName; + uint64 flags = spellInfo->SpellFamilyFlags; + + if((family == 5 && flags == 256) || //Searing Pain + (family == 6 && flags == 8192) || //Mind Blast + (family == 11 && flags == 1048576)) //Earth Shock + return true; + + return false; +} + +void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage,WeaponAttackType attType, SpellEntry const *spellProto) +{ + if(!pVictim) + return; + + if(*pdamage == 0) + return; + + uint32 creatureTypeMask = pVictim->GetCreatureTypeMask(); + + // Taken/Done fixed damage bonus auras + int32 DoneFlatBenefit = 0; + int32 TakenFlatBenefit = 0; + + // ..done (for creature type by mask) in taken + AuraList const& mDamageDoneCreature = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); + for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + DoneFlatBenefit += (*i)->GetModifier()->m_amount; + + // ..done + // SPELL_AURA_MOD_DAMAGE_DONE included in weapon damage + + // ..done (base at attack power for marked target and base at attack power for creature type) + int32 APbonus = 0; + if(attType == RANGED_ATTACK) + { + APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS); + + // ..done (base at attack power and creature type) + AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_RANGED_ATTACK_POWER_VERSUS); + for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + APbonus += (*i)->GetModifier()->m_amount; + } + else + { + APbonus += pVictim->GetTotalAuraModifier(SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS); + + // ..done (base at attack power and creature type) + AuraList const& mCreatureAttackPower = GetAurasByType(SPELL_AURA_MOD_MELEE_ATTACK_POWER_VERSUS); + for(AuraList::const_iterator i = mCreatureAttackPower.begin();i != mCreatureAttackPower.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + APbonus += (*i)->GetModifier()->m_amount; + } + + if (APbonus!=0) // Can be negative + { + bool normalized = false; + if(spellProto) + { + for (uint8 i = 0; i<3;i++) + { + if (spellProto->Effect[i] == SPELL_EFFECT_NORMALIZED_WEAPON_DMG) + { + normalized = true; + break; + } + } + } + + DoneFlatBenefit += int32(APbonus/14.0f * GetAPMultiplier(attType,normalized)); + } + + // ..taken + AuraList const& mDamageTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_TAKEN); + for(AuraList::const_iterator i = mDamageTaken.begin();i != mDamageTaken.end(); ++i) + if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) + TakenFlatBenefit += (*i)->GetModifier()->m_amount; + + if(attType!=RANGED_ATTACK) + TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN); + else + TakenFlatBenefit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN); + + // Done/Taken total percent damage auras + float DoneTotalMod = 1; + float TakenTotalMod = 1; + + // ..done + // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage + // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage + + AuraList const& mDamageDoneVersus = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); + for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) + if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) + DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // ..taken + AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); + for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) + if((*i)->GetModifier()->m_miscvalue & GetMeleeDamageSchoolMask()) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + + // .. taken pct: dummy auras + AuraList const& mDummyAuras = pVictim->GetAurasByType(SPELL_AURA_DUMMY); + for(AuraList::const_iterator i = mDummyAuras.begin(); i != mDummyAuras.end(); ++i) + { + switch((*i)->GetSpellProto()->SpellIconID) + { + //Cheat Death + case 2109: + if((*i)->GetModifier()->m_miscvalue & SPELL_SCHOOL_MASK_NORMAL) + { + if(pVictim->GetTypeId() != TYPEID_PLAYER) + continue; + float mod = ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*(-8.0f); + if (mod < (*i)->GetModifier()->m_amount) + mod = (*i)->GetModifier()->m_amount; + TakenTotalMod *= (mod+100.0f)/100.0f; + } + break; + //Mangle + case 2312: + if(spellProto==NULL) + break; + // Should increase Shred (initial Damage of Lacerate and Rake handled in Spell::EffectSchoolDMG) + if(spellProto->SpellFamilyName==SPELLFAMILY_DRUID && (spellProto->SpellFamilyFlags==0x00008000LL)) + TakenTotalMod *= (100.0f+(*i)->GetModifier()->m_amount)/100.0f; + break; + } + } + + // .. taken pct: class scripts + AuraList const& mclassScritAuras = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for(AuraList::const_iterator i = mclassScritAuras.begin(); i != mclassScritAuras.end(); ++i) + { + switch((*i)->GetMiscValue()) + { + case 6427: case 6428: // Dirty Deeds + if(pVictim->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT)) + { + Aura* eff0 = GetAura((*i)->GetId(),0); + if(!eff0 || (*i)->GetEffIndex()!=1) + { + sLog.outError("Spell structure of DD (%u) changed.",(*i)->GetId()); + continue; + } + + // effect 0 have expected value but in negative state + TakenTotalMod *= (-eff0->GetModifier()->m_amount+100.0f)/100.0f; + } + break; + } + } + + if(attType != RANGED_ATTACK) + { + AuraList const& mModMeleeDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_MELEE_DAMAGE_TAKEN_PCT); + for(AuraList::const_iterator i = mModMeleeDamageTakenPercent.begin(); i != mModMeleeDamageTakenPercent.end(); ++i) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + } + else + { + AuraList const& mModRangedDamageTakenPercent = pVictim->GetAurasByType(SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT); + for(AuraList::const_iterator i = mModRangedDamageTakenPercent.begin(); i != mModRangedDamageTakenPercent.end(); ++i) + TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; + } + + float tmpDamage = float(int32(*pdamage) + DoneFlatBenefit) * DoneTotalMod; + + // apply spellmod to Done damage + if(spellProto) + { + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_DAMAGE, tmpDamage); + } + + tmpDamage = (tmpDamage + TakenFlatBenefit)*TakenTotalMod; + + // bonus result can be negative + *pdamage = tmpDamage > 0 ? uint32(tmpDamage) : 0; +} + +void Unit::ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply) +{ + if (apply) + { + for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(), next; itr != m_spellImmune[op].end(); itr = next) + { + next = itr; ++next; + if(itr->type == type) + { + m_spellImmune[op].erase(itr); + next = m_spellImmune[op].begin(); + } + } + SpellImmune Immune; + Immune.spellId = spellId; + Immune.type = type; + m_spellImmune[op].push_back(Immune); + } + else + { + for (SpellImmuneList::iterator itr = m_spellImmune[op].begin(); itr != m_spellImmune[op].end(); ++itr) + { + if(itr->spellId == spellId) + { + m_spellImmune[op].erase(itr); + break; + } + } + } + +} + +void Unit::ApplySpellDispelImmunity(const SpellEntry * spellProto, DispelType type, bool apply) +{ + ApplySpellImmune(spellProto->Id,IMMUNITY_DISPEL, type, apply); + + if (apply && spellProto->AttributesEx & SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY) + RemoveAurasWithDispelType(type); +} + +float Unit::GetWeaponProcChance() const +{ + // normalized proc chance for weapon attack speed + // (odd formula...) + if(isAttackReady(BASE_ATTACK)) + return (GetAttackTime(BASE_ATTACK) * 1.8f / 1000.0f); + else if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK)) + return (GetAttackTime(OFF_ATTACK) * 1.6f / 1000.0f); + return 0; +} + +float Unit::GetPPMProcChance(uint32 WeaponSpeed, float PPM) const +{ + // proc per minute chance calculation + if (PPM <= 0) return 0.0f; + uint32 result = uint32((WeaponSpeed * PPM) / 600.0f); // result is chance in percents (probability = Speed_in_sec * (PPM / 60)) + return result; +} + +void Unit::Mount(uint32 mount) +{ + if(!mount) + return; + + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_MOUNT); + + SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, mount); + + SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); + + // unsummon pet + if(GetTypeId() == TYPEID_PLAYER) + { + Pet* pet = GetPet(); + if(pet) + { + if(pet->isControlled()) + { + ((Player*)this)->SetTemporaryUnsummonedPetNumber(pet->GetCharmInfo()->GetPetNumber()); + ((Player*)this)->SetOldPetSpell(pet->GetUInt32Value(UNIT_CREATED_BY_SPELL)); + } + + ((Player*)this)->RemovePet(NULL,PET_SAVE_NOT_IN_SLOT); + } + else + ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); + } +} + +void Unit::Unmount() +{ + if(!IsMounted()) + return; + + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_MOUNTED); + + SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, 0); + RemoveFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNT ); + + // only resummon old pet if the player is already added to a map + // this prevents adding a pet to a not created map which would otherwise cause a crash + // (it could probably happen when logging in after a previous crash) + if(GetTypeId() == TYPEID_PLAYER && IsInWorld() && ((Player*)this)->GetTemporaryUnsummonedPetNumber() && isAlive()) + { + Pet* NewPet = new Pet; + if(!NewPet->LoadPetFromDB(this, 0, ((Player*)this)->GetTemporaryUnsummonedPetNumber(), true)) + delete NewPet; + + ((Player*)this)->SetTemporaryUnsummonedPetNumber(0); + } +} + +void Unit::SetInCombatWith(Unit* enemy) +{ + Unit* eOwner = enemy->GetCharmerOrOwnerOrSelf(); + if(eOwner->IsPvP()) + { + SetInCombatState(true); + return; + } + + //check for duel + if(eOwner->GetTypeId() == TYPEID_PLAYER && ((Player*)eOwner)->duel) + { + Unit const* myOwner = GetCharmerOrOwnerOrSelf(); + if(((Player const*)eOwner)->duel->opponent == myOwner) + { + SetInCombatState(true); + return; + } + } + SetInCombatState(false); +} + +void Unit::CombatStart(Unit* target) +{ + if(!target->IsStandState() && !target->hasUnitState(UNIT_STAT_STUNNED)) + target->SetStandState(PLAYER_STATE_NONE); + + if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER && ((Creature*)target)->AI()) + ((Creature*)target)->AI()->AttackStart(this); + + SetInCombatWith(target); + target->SetInCombatWith(this); + + if(Player* attackedPlayer = target->GetCharmerOrOwnerPlayerOrPlayerItself()) + SetContestedPvP(attackedPlayer); + + if(!isInCombat()) // remove this? + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ATTACK); +} + +void Unit::SetInCombatState(bool PvP) +{ + // only alive units can be in combat + if(!isAlive()) + return; + + if(PvP) + m_CombatTimer = 5000; + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); + + if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); +} + +void Unit::ClearInCombat() +{ + m_CombatTimer = 0; + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IN_COMBAT); + + if(isCharmed() || (GetTypeId()!=TYPEID_PLAYER && ((Creature*)this)->isPet())) + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_IN_COMBAT); + + // Player's state will be cleared in Player::UpdateContestedPvP + if(GetTypeId()!=TYPEID_PLAYER) + clearUnitState(UNIT_STAT_ATTACK_PLAYER); +} + +//TODO: remove this function +bool Unit::isTargetableForAttack() const +{ + return isAttackableByAOE() && !hasUnitState(UNIT_STAT_DIED); +} + +bool Unit::canAttack(Unit const* target) const +{ + assert(target); + + if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) + return false; + + if((m_invisibilityMask || target->m_invisibilityMask) && !canDetectInvisibilityOf(target)) + return false; + + if(target->GetVisibility() == VISIBILITY_GROUP_STEALTH && !canDetectStealthOf(target, GetDistance(target))) + return false; + + return true; +} + +bool Unit::isAttackableByAOE() const +{ + if(!isAlive()) + return false; + + if(HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE)) + return false; + + if(GetTypeId()==TYPEID_PLAYER && ((Player *)this)->isGameMaster()) + return false; + + return !isInFlight(); +} + +int32 Unit::ModifyHealth(int32 dVal) +{ + int32 gain = 0; + + if(dVal==0) + return 0; + + int32 curHealth = (int32)GetHealth(); + + int32 val = dVal + curHealth; + if(val <= 0) + { + SetHealth(0); + return -curHealth; + } + + int32 maxHealth = (int32)GetMaxHealth(); + + if(val < maxHealth) + { + SetHealth(val); + gain = val - curHealth; + } + else if(curHealth != maxHealth) + { + SetHealth(maxHealth); + gain = maxHealth - curHealth; + } + + return gain; +} + +int32 Unit::ModifyPower(Powers power, int32 dVal) +{ + int32 gain = 0; + + if(dVal==0) + return 0; + + int32 curPower = (int32)GetPower(power); + + int32 val = dVal + curPower; + if(val <= 0) + { + SetPower(power,0); + return -curPower; + } + + int32 maxPower = (int32)GetMaxPower(power); + + if(val < maxPower) + { + SetPower(power,val); + gain = val - curPower; + } + else if(curPower != maxPower) + { + SetPower(power,maxPower); + gain = maxPower - curPower; + } + + return gain; +} + +bool Unit::isVisibleForOrDetect(Unit const* u, bool detect, bool inVisibleList) const +{ + if(!u) + return false; + return u->canSeeOrDetect(this, detect, inVisibleList); +} + +bool Unit::canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList) const +{ + return true; +} + +bool Unit::canDetectInvisibilityOf(Unit const* u) const +{ + if(m_invisibilityMask & u->m_invisibilityMask) // same group + return true; + AuraList const& auras = GetAurasByType(SPELL_AURA_MOD_STALKED); // Hunter mark + for(AuraList::const_iterator iter = auras.begin(); iter != auras.end(); ++iter) + if((*iter)->GetCasterGUID()==u->GetGUID()) + return true; + + if(uint32 mask = (m_detectInvisibilityMask & u->m_invisibilityMask)) + { + for(uint32 i = 0; i < 10; ++i) + { + if(((1 << i) & mask)==0) + continue; + + // find invisibility level + uint32 invLevel = 0; + Unit::AuraList const& iAuras = u->GetAurasByType(SPELL_AURA_MOD_INVISIBILITY); + for(Unit::AuraList::const_iterator itr = iAuras.begin(); itr != iAuras.end(); ++itr) + if(((*itr)->GetModifier()->m_miscvalue)==i && invLevel < (*itr)->GetModifier()->m_amount) + invLevel = (*itr)->GetModifier()->m_amount; + + // find invisibility detect level + uint32 detectLevel = 0; + if(i==6 && GetTypeId()==TYPEID_PLAYER) // special drunk detection case + { + detectLevel = ((Player*)this)->GetDrunkValue(); + } + else + { + Unit::AuraList const& dAuras = GetAurasByType(SPELL_AURA_MOD_INVISIBILITY_DETECTION); + for(Unit::AuraList::const_iterator itr = dAuras.begin(); itr != dAuras.end(); ++itr) + if(((*itr)->GetModifier()->m_miscvalue)==i && detectLevel < (*itr)->GetModifier()->m_amount) + detectLevel = (*itr)->GetModifier()->m_amount; + } + + if(invLevel <= detectLevel) + return true; + } + } + + return false; +} + +bool Unit::canDetectStealthOf(Unit const* target, float distance) const +{ + if(hasUnitState(UNIT_STAT_STUNNED)) + return false; + if(distance < 0.24f) //collision + return true; + if(!HasInArc(M_PI, target)) //behind + return false; + if(HasAuraType(SPELL_AURA_DETECT_STEALTH)) + return true; + + //Visible distance based on stealth value (stealth rank 4 300MOD, 10.5 - 3 = 7.5) + float visibleDistance = 10.5f - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH) / 100.0f; + //Visible distance is modified by -Level Diff (every level diff = 1.0f in visible distance) + visibleDistance += int32(getLevelForTarget(target)) - int32(target->getLevelForTarget(this)); + //-Stealth Mod(positive like Master of Deception) and Stealth Detection(negative like paranoia) + //based on wowwiki every 5 mod we have 1 more level diff in calculation + visibleDistance += (float)(GetTotalAuraModifier(SPELL_AURA_MOD_DETECT) - target->GetTotalAuraModifier(SPELL_AURA_MOD_STEALTH_LEVEL)) / 5.0f; + + return distance < visibleDistance; +} + +void Unit::SetVisibility(UnitVisibility x) +{ + m_Visibility = x; + + if(IsInWorld()) + { + Map *m = MapManager::Instance().GetMap(GetMapId(), this); + + if(GetTypeId()==TYPEID_PLAYER) + m->PlayerRelocation((Player*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); + else + m->CreatureRelocation((Creature*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); + } +} + +void Unit::UpdateSpeed(UnitMoveType mtype, bool forced) +{ + int32 main_speed_mod = 0; + float stack_bonus = 1.0f; + float non_stack_bonus = 1.0f; + + switch(mtype) + { + case MOVE_WALK: + return; + case MOVE_RUN: + { + if (IsMounted()) // Use on mount auras + { + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_MOUNTED_SPEED); + stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_MOUNTED_SPEED_ALWAYS); + non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_MOUNTED_SPEED_NOT_STACK))/100.0f; + } + else + { + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SPEED); + stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_SPEED_ALWAYS); + non_stack_bonus = (100.0f + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_SPEED_NOT_STACK))/100.0f; + } + break; + } + case MOVE_WALKBACK: + return; + case MOVE_SWIM: + { + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_SWIM_SPEED); + break; + } + case MOVE_SWIMBACK: + return; + case MOVE_FLY: + { + if (IsMounted()) // Use on mount auras + main_speed_mod = GetMaxPositiveAuraModifier(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED); + else // Use not mount (shapeshift for example) auras (should stack) + main_speed_mod = GetTotalAuraModifier(SPELL_AURA_MOD_SPEED_FLIGHT); + stack_bonus = GetTotalAuraMultiplier(SPELL_AURA_MOD_FLIGHT_SPEED_ALWAYS); + non_stack_bonus = (100.0 + GetMaxPositiveAuraModifier(SPELL_AURA_MOD_FLIGHT_SPEED_NOT_STACK))/100.0f; + break; + } + case MOVE_FLYBACK: + return; + default: + sLog.outError("Unit::UpdateSpeed: Unsupported move type (%d)", mtype); + return; + } + + float bonus = non_stack_bonus > stack_bonus ? non_stack_bonus : stack_bonus; + // now we ready for speed calculation + float speed = main_speed_mod ? bonus*(100.0f + main_speed_mod)/100.0f : bonus; + + switch(mtype) + { + case MOVE_RUN: + case MOVE_SWIM: + case MOVE_FLY: + { + // Normalize speed by 191 aura SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED if need + // TODO: possible affect only on MOVE_RUN + if(int32 normalization = GetMaxPositiveAuraModifier(SPELL_AURA_USE_NORMAL_MOVEMENT_SPEED)) + { + // Use speed from aura + float max_speed = normalization / baseMoveSpeed[mtype]; + if (speed > max_speed) + speed = max_speed; + } + break; + } + default: + break; + } + + // Apply strongest slow aura mod to speed + int32 slow = GetMaxNegativeAuraModifier(SPELL_AURA_MOD_DECREASE_SPEED); + if (slow) + speed *=(100.0f + slow)/100.0f; + SetSpeed(mtype, speed, forced); +} + +float Unit::GetSpeed( UnitMoveType mtype ) const +{ + return m_speed_rate[mtype]*baseMoveSpeed[mtype]; +} + +void Unit::SetSpeed(UnitMoveType mtype, float rate, bool forced) +{ + if (rate < 0) + rate = 0.0f; + + // Update speed only on change + if (m_speed_rate[mtype] == rate) + return; + + m_speed_rate[mtype] = rate; + + propagateSpeedChange(); + + // Send speed change packet only for player + if (GetTypeId()!=TYPEID_PLAYER) + return; + + WorldPacket data; + if(!forced) + { + switch(mtype) + { + case MOVE_WALK: + data.Initialize(MSG_MOVE_SET_WALK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_RUN: + data.Initialize(MSG_MOVE_SET_RUN_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_WALKBACK: + data.Initialize(MSG_MOVE_SET_RUN_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_SWIM: + data.Initialize(MSG_MOVE_SET_SWIM_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_SWIMBACK: + data.Initialize(MSG_MOVE_SET_SWIM_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_TURN: + data.Initialize(MSG_MOVE_SET_TURN_RATE, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_FLY: + data.Initialize(MSG_MOVE_SET_FLIGHT_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + case MOVE_FLYBACK: + data.Initialize(MSG_MOVE_SET_FLIGHT_BACK_SPEED, 8+4+1+4+4+4+4+4+4+4); + break; + default: + sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); + return; + } + + data.append(GetPackGUID()); + data << uint32(0); //movement flags + data << uint8(0); //unk + data << uint32(getMSTime()); + data << float(GetPositionX()); + data << float(GetPositionY()); + data << float(GetPositionZ()); + data << float(GetOrientation()); + data << uint32(0); //flag unk + data << float(GetSpeed(mtype)); + SendMessageToSet( &data, true ); + } + else + { + // register forced speed changes for WorldSession::HandleForceSpeedChangeAck + // and do it only for real sent packets and use run for run/mounted as client expected + ++((Player*)this)->m_forced_speed_changes[mtype]; + switch(mtype) + { + case MOVE_WALK: + data.Initialize(SMSG_FORCE_WALK_SPEED_CHANGE, 16); + break; + case MOVE_RUN: + data.Initialize(SMSG_FORCE_RUN_SPEED_CHANGE, 17); + break; + case MOVE_WALKBACK: + data.Initialize(SMSG_FORCE_RUN_BACK_SPEED_CHANGE, 16); + break; + case MOVE_SWIM: + data.Initialize(SMSG_FORCE_SWIM_SPEED_CHANGE, 16); + break; + case MOVE_SWIMBACK: + data.Initialize(SMSG_FORCE_SWIM_BACK_SPEED_CHANGE, 16); + break; + case MOVE_TURN: + data.Initialize(SMSG_FORCE_TURN_RATE_CHANGE, 16); + break; + case MOVE_FLY: + data.Initialize(SMSG_FORCE_FLIGHT_SPEED_CHANGE, 16); + break; + case MOVE_FLYBACK: + data.Initialize(SMSG_FORCE_FLIGHT_BACK_SPEED_CHANGE, 16); + break; + default: + sLog.outError("Unit::SetSpeed: Unsupported move type (%d), data not sent to client.",mtype); + return; + } + data.append(GetPackGUID()); + data << (uint32)0; + if (mtype == MOVE_RUN) + data << uint8(0); // new 2.1.0 + data << float(GetSpeed(mtype)); + SendMessageToSet( &data, true ); + } + if(Pet* pet = GetPet()) + pet->SetSpeed(MOVE_RUN, m_speed_rate[mtype],forced); +} + +void Unit::SetHover(bool on) +{ + if(on) + CastSpell(this,11010,true); + else + RemoveAurasDueToSpell(11010); +} + +void Unit::setDeathState(DeathState s) +{ + if (s != ALIVE && s!= JUST_ALIVED) + { + CombatStop(); + DeleteThreatList(); + ClearComboPointHolders(); // any combo points pointed to unit lost at it death + + if(IsNonMeleeSpellCasted(false)) + InterruptNonMeleeSpells(false); + } + + if (s == JUST_DIED) + { + RemoveAllAurasOnDeath(); + UnsummonAllTotems(); + + // Possessed unit died, restore control to possessor + UnpossessSelf(false); + RemoveAllFromVision(); + + ModifyAuraState(AURA_STATE_HEALTHLESS_20_PERCENT, false); + ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, false); + // remove aurastates allowing special moves + ClearAllReactives(); + ClearDiminishings(); + } + else if(s == JUST_ALIVED) + { + RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); // clear skinnable for creature and player (at battleground) + } + + if (m_deathState != ALIVE && s == ALIVE) + { + //_ApplyAllAuraMods(); + } + m_deathState = s; +} + +/*######################################## +######## ######## +######## AGGRO SYSTEM ######## +######## ######## +########################################*/ +bool Unit::CanHaveThreatList() const +{ + // only creatures can have threat list + if( GetTypeId() != TYPEID_UNIT ) + return false; + + // only alive units can have threat list + if( !isAlive() ) + return false; + + // pets and totems can not have threat list + if( ((Creature*)this)->isPet() || ((Creature*)this)->isTotem() ) + return false; + + return true; +} + +//====================================================================== + +float Unit::ApplyTotalThreatModifier(float threat, SpellSchoolMask schoolMask) +{ + if(!HasAuraType(SPELL_AURA_MOD_THREAT)) + return threat; + + SpellSchools school = GetFirstSchoolInMask(schoolMask); + + return threat * m_threatModifier[school]; +} + +//====================================================================== + +void Unit::AddThreat(Unit* pVictim, float threat, SpellSchoolMask schoolMask, SpellEntry const *threatSpell) +{ + // Only mobs can manage threat lists + if(CanHaveThreatList()) + m_ThreatManager.addThreat(pVictim, threat, schoolMask, threatSpell); +} + +//====================================================================== + +void Unit::DeleteThreatList() +{ + m_ThreatManager.clearReferences(); +} + +//====================================================================== + +void Unit::TauntApply(Unit* taunter) +{ + assert(GetTypeId()== TYPEID_UNIT); + + if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) + return; + + if(!CanHaveThreatList()) + return; + + Unit *target = getVictim(); + if(target && target == taunter) + return; + + SetInFront(taunter); + if (((Creature*)this)->AI()) + ((Creature*)this)->AI()->AttackStart(taunter); + + m_ThreatManager.tauntApply(taunter); +} + +//====================================================================== + +void Unit::TauntFadeOut(Unit *taunter) +{ + assert(GetTypeId()== TYPEID_UNIT); + + if(!taunter || (taunter->GetTypeId() == TYPEID_PLAYER && ((Player*)taunter)->isGameMaster())) + return; + + if(!CanHaveThreatList()) + return; + + Unit *target = getVictim(); + if(!target || target != taunter) + return; + + if(m_ThreatManager.isThreatListEmpty()) + { + if(((Creature*)this)->AI()) + ((Creature*)this)->AI()->EnterEvadeMode(); + return; + } + + m_ThreatManager.tauntFadeOut(taunter); + target = m_ThreatManager.getHostilTarget(); + + if (target && target != taunter) + { + SetInFront(target); + if (((Creature*)this)->AI()) + ((Creature*)this)->AI()->AttackStart(target); + } +} + +//====================================================================== + +bool Unit::SelectHostilTarget() +{ + //function provides main threat functionality + //next-victim-selection algorithm and evade mode are called + //threat list sorting etc. + + assert(GetTypeId()== TYPEID_UNIT); + Unit* target = NULL; + + //This function only useful once AI has been initialized + if (!((Creature*)this)->AI()) + return false; + + if(!m_ThreatManager.isThreatListEmpty()) + { + if(!HasAuraType(SPELL_AURA_MOD_TAUNT)) + { + target = m_ThreatManager.getHostilTarget(); + } + } + + if(target) + { + if(!hasUnitState(UNIT_STAT_STUNNED)) + SetInFront(target); + ((Creature*)this)->AI()->AttackStart(target); + return true; + } + + // no target but something prevent go to evade mode + if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_TAUNT) ) + return false; + + // last case when creature don't must go to evade mode: + // it in combat but attacker not make any damage and not enter to aggro radius to have record in threat list + // for example at owner command to pet attack some far away creature + // Note: creature not have targeted movement generator but have attacker in this case + if( GetMotionMaster()->GetCurrentMovementGeneratorType() != TARGETED_MOTION_TYPE ) + { + for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr) + { + if( (*itr)->IsInMap(this) && canAttack(*itr) && (*itr)->isInAccessiblePlaceFor((Creature*)this) ) + return false; + } + } + + // enter in evade mode in other case + ((Creature*)this)->AI()->EnterEvadeMode(); + + return false; +} + +//====================================================================== +//====================================================================== +//====================================================================== + +int32 Unit::CalculateSpellDamage(SpellEntry const* spellProto, uint8 effect_index, int32 effBasePoints, Unit const* target) +{ + Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; + + uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; + + int32 level = int32(getLevel()) - int32(spellProto->spellLevel); + if (level > spellProto->maxLevel && spellProto->maxLevel > 0) + level = spellProto->maxLevel; + + float basePointsPerLevel = spellProto->EffectRealPointsPerLevel[effect_index]; + float randomPointsPerLevel = spellProto->EffectDicePerLevel[effect_index]; + int32 basePoints = int32(effBasePoints + level * basePointsPerLevel); + int32 randomPoints = int32(spellProto->EffectDieSides[effect_index] + level * randomPointsPerLevel); + float comboDamage = spellProto->EffectPointsPerComboPoint[effect_index]; + + // prevent random generator from getting confused by spells casted with Unit::CastCustomSpell + int32 randvalue = spellProto->EffectBaseDice[effect_index] >= randomPoints ? spellProto->EffectBaseDice[effect_index]:irand(spellProto->EffectBaseDice[effect_index], randomPoints); + int32 value = basePoints + randvalue; + //random damage + if(comboDamage != 0 && unitPlayer && target && (target->GetGUID() == unitPlayer->GetComboTarget())) + value += (int32)(comboDamage * comboPoints); + + if(Player* modOwner = GetSpellModOwner()) + { + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_ALL_EFFECTS, value); + switch(effect_index) + { + case 0: + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT1, value); + break; + case 1: + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT2, value); + break; + case 2: + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_EFFECT3, value); + break; + } + } + + if(spellProto->Attributes & SPELL_ATTR_LEVEL_DAMAGE_CALCULATION && spellProto->spellLevel && + spellProto->Effect[effect_index] != SPELL_EFFECT_WEAPON_PERCENT_DAMAGE && + spellProto->Effect[effect_index] != SPELL_EFFECT_KNOCK_BACK) + value = int32(value*0.25f*exp(getLevel()*(70-spellProto->spellLevel)/1000.0f)); + + return value; +} + +int32 Unit::CalculateSpellDuration(SpellEntry const* spellProto, uint8 effect_index, Unit const* target) +{ + Player* unitPlayer = (GetTypeId() == TYPEID_PLAYER) ? (Player*)this : NULL; + + uint8 comboPoints = unitPlayer ? unitPlayer->GetComboPoints() : 0; + + int32 minduration = GetSpellDuration(spellProto); + int32 maxduration = GetSpellMaxDuration(spellProto); + + int32 duration; + + if( minduration != -1 && minduration != maxduration ) + duration = minduration + int32((maxduration - minduration) * comboPoints / 5); + else + duration = minduration; + + if (duration > 0) + { + int32 mechanic = GetEffectMechanic(spellProto, effect_index); + // Find total mod value (negative bonus) + int32 durationMod_always = target->GetTotalAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD, mechanic); + // Find max mod (negative bonus) + int32 durationMod_not_stack = target->GetMaxNegativeAuraModifierByMiscValue(SPELL_AURA_MECHANIC_DURATION_MOD_NOT_STACK, mechanic); + + int32 durationMod = 0; + // Select strongest negative mod + if (durationMod_always > durationMod_not_stack) + durationMod = durationMod_not_stack; + else + durationMod = durationMod_always; + + if (durationMod != 0) + duration = int32(int64(duration) * (100+durationMod) /100); + + if (duration < 0) duration = 0; + } + + return duration; +} + +DiminishingLevels Unit::GetDiminishing(DiminishingGroup group) +{ + for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) + { + if(i->DRGroup != group) + continue; + + if(!i->hitCount) + return DIMINISHING_LEVEL_1; + + if(!i->hitTime) + return DIMINISHING_LEVEL_1; + + // If last spell was casted more than 15 seconds ago - reset the count. + if(i->stack==0 && getMSTimeDiff(i->hitTime,getMSTime()) > 15000) + { + i->hitCount = DIMINISHING_LEVEL_1; + return DIMINISHING_LEVEL_1; + } + // or else increase the count. + else + { + return DiminishingLevels(i->hitCount); + } + } + return DIMINISHING_LEVEL_1; +} + +void Unit::IncrDiminishing(DiminishingGroup group) +{ + // Checking for existing in the table + bool IsExist = false; + for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) + { + if(i->DRGroup != group) + continue; + + IsExist = true; + if(i->hitCount < DIMINISHING_LEVEL_IMMUNE) + i->hitCount += 1; + + break; + } + + if(!IsExist) + m_Diminishing.push_back(DiminishingReturn(group,getMSTime(),DIMINISHING_LEVEL_2)); +} + +void Unit::ApplyDiminishingToDuration(DiminishingGroup group, int32 &duration,Unit* caster,DiminishingLevels Level) +{ + if(duration == -1 || group == DIMINISHING_NONE || caster->IsFriendlyTo(this) ) + return; + + // Duration of crowd control abilities on pvp target is limited by 10 sec. (2.2.0) + if(duration > 10000 && IsDiminishingReturnsGroupDurationLimited(group)) + { + // test pet/charm masters instead pets/charmeds + Unit const* targetOwner = GetCharmerOrOwner(); + Unit const* casterOwner = caster->GetCharmerOrOwner(); + + Unit const* target = targetOwner ? targetOwner : this; + Unit const* source = casterOwner ? casterOwner : caster; + + if(target->GetTypeId() == TYPEID_PLAYER && source->GetTypeId() == TYPEID_PLAYER) + duration = 10000; + } + + float mod = 1.0f; + + // Some diminishings applies to mobs too (for example, Stun) + if((GetDiminishingReturnsGroupType(group) == DRTYPE_PLAYER && GetTypeId() == TYPEID_PLAYER) || GetDiminishingReturnsGroupType(group) == DRTYPE_ALL) + { + DiminishingLevels diminish = Level; + switch(diminish) + { + case DIMINISHING_LEVEL_1: break; + case DIMINISHING_LEVEL_2: mod = 0.5f; break; + case DIMINISHING_LEVEL_3: mod = 0.25f; break; + case DIMINISHING_LEVEL_IMMUNE: mod = 0.0f;break; + default: break; + } + } + + duration = int32(duration * mod); +} + +void Unit::ApplyDiminishingAura( DiminishingGroup group, bool apply ) +{ + // Checking for existing in the table + for(Diminishing::iterator i = m_Diminishing.begin(); i != m_Diminishing.end(); ++i) + { + if(i->DRGroup != group) + continue; + + i->hitTime = getMSTime(); + + if(apply) + i->stack += 1; + else if(i->stack) + i->stack -= 1; + + break; + } +} + +Unit* Unit::GetUnit(WorldObject& object, uint64 guid) +{ + return ObjectAccessor::GetUnit(object,guid); +} + +bool Unit::isVisibleForInState( Player const* u, bool inVisibleList ) const +{ + return isVisibleForOrDetect(u,false,inVisibleList); +} + +uint32 Unit::GetCreatureType() const +{ + if(GetTypeId() == TYPEID_PLAYER) + { + SpellShapeshiftEntry const* ssEntry = sSpellShapeshiftStore.LookupEntry(((Player*)this)->m_form); + if(ssEntry && ssEntry->creatureType > 0) + return ssEntry->creatureType; + else + return CREATURE_TYPE_HUMANOID; + } + else + return ((Creature*)this)->GetCreatureInfo()->type; +} + +/*####################################### +######## ######## +######## STAT SYSTEM ######## +######## ######## +#######################################*/ + +bool Unit::HandleStatModifier(UnitMods unitMod, UnitModifierType modifierType, float amount, bool apply) +{ + if(unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) + { + sLog.outError("ERROR in HandleStatModifier(): non existed UnitMods or wrong UnitModifierType!"); + return false; + } + + float val = 1.0f; + + switch(modifierType) + { + case BASE_VALUE: + case TOTAL_VALUE: + m_auraModifiersGroup[unitMod][modifierType] += apply ? amount : -amount; + break; + case BASE_PCT: + case TOTAL_PCT: + if(amount <= -100.0f) //small hack-fix for -100% modifiers + amount = -200.0f; + + val = (100.0f + amount) / 100.0f; + m_auraModifiersGroup[unitMod][modifierType] *= apply ? val : (1.0f/val); + break; + + default: + break; + } + + if(!CanModifyStats()) + return false; + + switch(unitMod) + { + case UNIT_MOD_STAT_STRENGTH: + case UNIT_MOD_STAT_AGILITY: + case UNIT_MOD_STAT_STAMINA: + case UNIT_MOD_STAT_INTELLECT: + case UNIT_MOD_STAT_SPIRIT: UpdateStats(GetStatByAuraGroup(unitMod)); break; + + case UNIT_MOD_ARMOR: UpdateArmor(); break; + case UNIT_MOD_HEALTH: UpdateMaxHealth(); break; + + case UNIT_MOD_MANA: + case UNIT_MOD_RAGE: + case UNIT_MOD_FOCUS: + case UNIT_MOD_ENERGY: + case UNIT_MOD_HAPPINESS: UpdateMaxPower(GetPowerTypeByAuraGroup(unitMod)); break; + + case UNIT_MOD_RESISTANCE_HOLY: + case UNIT_MOD_RESISTANCE_FIRE: + case UNIT_MOD_RESISTANCE_NATURE: + case UNIT_MOD_RESISTANCE_FROST: + case UNIT_MOD_RESISTANCE_SHADOW: + case UNIT_MOD_RESISTANCE_ARCANE: UpdateResistances(GetSpellSchoolByAuraGroup(unitMod)); break; + + case UNIT_MOD_ATTACK_POWER: UpdateAttackPowerAndDamage(); break; + case UNIT_MOD_ATTACK_POWER_RANGED: UpdateAttackPowerAndDamage(true); break; + + case UNIT_MOD_DAMAGE_MAINHAND: UpdateDamagePhysical(BASE_ATTACK); break; + case UNIT_MOD_DAMAGE_OFFHAND: UpdateDamagePhysical(OFF_ATTACK); break; + case UNIT_MOD_DAMAGE_RANGED: UpdateDamagePhysical(RANGED_ATTACK); break; + + default: + break; + } + + return true; +} + +float Unit::GetModifierValue(UnitMods unitMod, UnitModifierType modifierType) const +{ + if( unitMod >= UNIT_MOD_END || modifierType >= MODIFIER_TYPE_END) + { + sLog.outError("ERROR: trial to access non existed modifier value from UnitMods!"); + return 0.0f; + } + + if(modifierType == TOTAL_PCT && m_auraModifiersGroup[unitMod][modifierType] <= 0.0f) + return 0.0f; + + return m_auraModifiersGroup[unitMod][modifierType]; +} + +float Unit::GetTotalStatValue(Stats stat) const +{ + UnitMods unitMod = UnitMods(UNIT_MOD_STAT_START + stat); + + if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) + return 0.0f; + + // value = ((base_value * base_pct) + total_value) * total_pct + float value = m_auraModifiersGroup[unitMod][BASE_VALUE] + GetCreateStat(stat); + value *= m_auraModifiersGroup[unitMod][BASE_PCT]; + value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; + value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; + + return value; +} + +float Unit::GetTotalAuraModValue(UnitMods unitMod) const +{ + if(unitMod >= UNIT_MOD_END) + { + sLog.outError("ERROR: trial to access non existed UnitMods in GetTotalAuraModValue()!"); + return 0.0f; + } + + if(m_auraModifiersGroup[unitMod][TOTAL_PCT] <= 0.0f) + return 0.0f; + + float value = m_auraModifiersGroup[unitMod][BASE_VALUE]; + value *= m_auraModifiersGroup[unitMod][BASE_PCT]; + value += m_auraModifiersGroup[unitMod][TOTAL_VALUE]; + value *= m_auraModifiersGroup[unitMod][TOTAL_PCT]; + + return value; +} + +SpellSchools Unit::GetSpellSchoolByAuraGroup(UnitMods unitMod) const +{ + SpellSchools school = SPELL_SCHOOL_NORMAL; + + switch(unitMod) + { + case UNIT_MOD_RESISTANCE_HOLY: school = SPELL_SCHOOL_HOLY; break; + case UNIT_MOD_RESISTANCE_FIRE: school = SPELL_SCHOOL_FIRE; break; + case UNIT_MOD_RESISTANCE_NATURE: school = SPELL_SCHOOL_NATURE; break; + case UNIT_MOD_RESISTANCE_FROST: school = SPELL_SCHOOL_FROST; break; + case UNIT_MOD_RESISTANCE_SHADOW: school = SPELL_SCHOOL_SHADOW; break; + case UNIT_MOD_RESISTANCE_ARCANE: school = SPELL_SCHOOL_ARCANE; break; + + default: + break; + } + + return school; +} + +Stats Unit::GetStatByAuraGroup(UnitMods unitMod) const +{ + Stats stat = STAT_STRENGTH; + + switch(unitMod) + { + case UNIT_MOD_STAT_STRENGTH: stat = STAT_STRENGTH; break; + case UNIT_MOD_STAT_AGILITY: stat = STAT_AGILITY; break; + case UNIT_MOD_STAT_STAMINA: stat = STAT_STAMINA; break; + case UNIT_MOD_STAT_INTELLECT: stat = STAT_INTELLECT; break; + case UNIT_MOD_STAT_SPIRIT: stat = STAT_SPIRIT; break; + + default: + break; + } + + return stat; +} + +Powers Unit::GetPowerTypeByAuraGroup(UnitMods unitMod) const +{ + Powers power = POWER_MANA; + + switch(unitMod) + { + case UNIT_MOD_MANA: power = POWER_MANA; break; + case UNIT_MOD_RAGE: power = POWER_RAGE; break; + case UNIT_MOD_FOCUS: power = POWER_FOCUS; break; + case UNIT_MOD_ENERGY: power = POWER_ENERGY; break; + case UNIT_MOD_HAPPINESS: power = POWER_HAPPINESS; break; + + default: + break; + } + + return power; +} + +float Unit::GetTotalAttackPowerValue(WeaponAttackType attType) const +{ + UnitMods unitMod = (attType == RANGED_ATTACK) ? UNIT_MOD_ATTACK_POWER_RANGED : UNIT_MOD_ATTACK_POWER; + + float val = GetTotalAuraModValue(unitMod); + if(val < 0.0f) + val = 0.0f; + + return val; +} + +float Unit::GetWeaponDamageRange(WeaponAttackType attType ,WeaponDamageRange type) const +{ + if (attType == OFF_ATTACK && !haveOffhandWeapon()) + return 0.0f; + + return m_weaponDamage[attType][type]; +} + +void Unit::SetLevel(uint32 lvl) +{ + SetUInt32Value(UNIT_FIELD_LEVEL, lvl); + + // group update + if ((GetTypeId() == TYPEID_PLAYER) && ((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_LEVEL); +} + +void Unit::SetHealth(uint32 val) +{ + uint32 maxHealth = GetMaxHealth(); + if(maxHealth < val) + val = maxHealth; + + SetUInt32Value(UNIT_FIELD_HEALTH, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_HP); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_HP); + } + } +} + +void Unit::SetMaxHealth(uint32 val) +{ + uint32 health = GetHealth(); + SetUInt32Value(UNIT_FIELD_MAXHEALTH, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_HP); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_HP); + } + } + + if(val < health) + SetHealth(val); +} + +void Unit::SetPower(Powers power, uint32 val) +{ + uint32 maxPower = GetMaxPower(power); + if(maxPower < val) + val = maxPower; + + SetStatInt32Value(UNIT_FIELD_POWER1 + power, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); + } + + // Update the pet's character sheet with happiness damage bonus + if(pet->getPetType() == HUNTER_PET && power == POWER_HAPPINESS) + { + pet->UpdateDamagePhysical(BASE_ATTACK); + } + } +} + +void Unit::SetMaxPower(Powers power, uint32 val) +{ + uint32 cur_power = GetPower(power); + SetStatInt32Value(UNIT_FIELD_MAXPOWER1 + power, val); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); + } + } + + if(val < cur_power) + SetPower(power, val); +} + +void Unit::ApplyPowerMod(Powers power, uint32 val, bool apply) +{ + ApplyModUInt32Value(UNIT_FIELD_POWER1+power, val, apply); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_CUR_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_CUR_POWER); + } + } +} + +void Unit::ApplyMaxPowerMod(Powers power, uint32 val, bool apply) +{ + ApplyModUInt32Value(UNIT_FIELD_MAXPOWER1+power, val, apply); + + // group update + if(GetTypeId() == TYPEID_PLAYER) + { + if(((Player*)this)->GetGroup()) + ((Player*)this)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_MAX_POWER); + } + else if(((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MAX_POWER); + } + } +} + +void Unit::ApplyAuraProcTriggerDamage( Aura* aura, bool apply ) +{ + AuraList& tAuraProcTriggerDamage = m_modAuras[SPELL_AURA_PROC_TRIGGER_DAMAGE]; + if(apply) + tAuraProcTriggerDamage.push_back(aura); + else + tAuraProcTriggerDamage.remove(aura); +} + +uint32 Unit::GetCreatePowers( Powers power ) const +{ + // POWER_FOCUS and POWER_HAPPINESS only have hunter pet + switch(power) + { + case POWER_MANA: return GetCreateMana(); + case POWER_RAGE: return 1000; + case POWER_FOCUS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 100); + case POWER_ENERGY: return 100; + case POWER_HAPPINESS: return (GetTypeId()==TYPEID_PLAYER || !((Creature const*)this)->isPet() || ((Pet const*)this)->getPetType()!=HUNTER_PET ? 0 : 1050000); + } + + return 0; +} + +void Unit::AddToWorld() +{ + WorldObject::AddToWorld(); +} + +void Unit::RemoveFromWorld() +{ + // cleanup + if(IsInWorld()) + { + RemoveNotOwnSingleTargetAuras(); + } + + WorldObject::RemoveFromWorld(); +} + +void Unit::CleanupsBeforeDelete() +{ + if(m_uint32Values) // only for fully created object + { + InterruptNonMeleeSpells(true); + m_Events.KillAllEvents(false); // non-delatable (currently casted spells) will not deleted now but it will deleted at call in Map::RemoveAllObjectsInRemoveList + CombatStop(); + ClearComboPointHolders(); + DeleteThreatList(); + getHostilRefManager().setOnlineOfflineState(false); + RemoveAllAuras(); + RemoveAllGameObjects(); + RemoveAllDynObjects(); + GetMotionMaster()->Clear(false); // remove different non-standard movement generators. + + UnpossessSelf(false); + RemoveAllFromVision(); + } + RemoveFromWorld(); +} + + + +CharmInfo* Unit::InitCharmInfo(Unit *charm) +{ + if(!m_charmInfo) + m_charmInfo = new CharmInfo(charm); + return m_charmInfo; +} + +CharmInfo::CharmInfo(Unit* unit) +: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0) +{ + for(int i =0; i<4; ++i) + { + m_charmspells[i].spellId = 0; + m_charmspells[i].active = ACT_DISABLED; + } +} + +void CharmInfo::InitPetActionBar() +{ + // the first 3 SpellOrActions are attack, follow and stay + for(uint32 i = 0; i < 3; i++) + { + PetActionBar[i].Type = ACT_COMMAND; + PetActionBar[i].SpellOrAction = COMMAND_ATTACK - i; + + PetActionBar[i + 7].Type = ACT_REACTION; + PetActionBar[i + 7].SpellOrAction = COMMAND_ATTACK - i; + } + for(uint32 i=0; i < 4; i++) + { + PetActionBar[i + 3].Type = ACT_DISABLED; + PetActionBar[i + 3].SpellOrAction = 0; + } +} + +void CharmInfo::InitEmptyActionBar() +{ + for(uint32 x = 1; x < 10; ++x) + { + PetActionBar[x].Type = ACT_CAST; + PetActionBar[x].SpellOrAction = 0; + } + PetActionBar[0].Type = ACT_COMMAND; + PetActionBar[0].SpellOrAction = COMMAND_ATTACK; +} + +void CharmInfo::InitPossessCreateSpells() +{ + InitEmptyActionBar(); + if(m_unit->GetTypeId() == TYPEID_UNIT) + { + for(uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) + { + uint32 spellid = ((Creature*)m_unit)->m_spells[i]; + if(IsPassiveSpell(spellid)) + m_unit->CastSpell(m_unit, spellid, true); + else + AddSpellToAB(0, spellid, ACT_CAST); + } + } +} + +void CharmInfo::InitCharmCreateSpells() +{ + if(m_unit->GetTypeId() == TYPEID_PLAYER) //charmed players don't have spells + { + InitEmptyActionBar(); + return; + } + + InitPetActionBar(); + + for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) + { + uint32 spellId = ((Creature*)m_unit)->m_spells[x]; + m_charmspells[x].spellId = spellId; + + if(!spellId) + continue; + + if (IsPassiveSpell(spellId)) + { + m_unit->CastSpell(m_unit, spellId, true); + m_charmspells[x].active = ACT_PASSIVE; + } + else + { + ActiveStates newstate; + bool onlyselfcast = true; + SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); + + if(!spellInfo) onlyselfcast = false; + for(uint32 i = 0;i<3 && onlyselfcast;++i) //non existent spell will not make any problems as onlyselfcast would be false -> break right away + { + if(spellInfo->EffectImplicitTargetA[i] != TARGET_SELF && spellInfo->EffectImplicitTargetA[i] != 0) + onlyselfcast = false; + } + + if(onlyselfcast || !IsPositiveSpell(spellId)) //only self cast and spells versus enemies are autocastable + newstate = ACT_DISABLED; + else + newstate = ACT_CAST; + + AddSpellToAB(0, spellId, newstate); + } + } +} + +bool CharmInfo::AddSpellToAB(uint32 oldid, uint32 newid, ActiveStates newstate) +{ + for(uint8 i = 0; i < 10; i++) + { + if((PetActionBar[i].Type == ACT_DISABLED || PetActionBar[i].Type == ACT_ENABLED || PetActionBar[i].Type == ACT_CAST) && PetActionBar[i].SpellOrAction == oldid) + { + PetActionBar[i].SpellOrAction = newid; + if(!oldid) + { + if(newstate == ACT_DECIDE) + PetActionBar[i].Type = ACT_DISABLED; + else + PetActionBar[i].Type = newstate; + } + + return true; + } + } + return false; +} + +void CharmInfo::ToggleCreatureAutocast(uint32 spellid, bool apply) +{ + if(IsPassiveSpell(spellid)) + return; + + for(uint32 x = 0; x < CREATURE_MAX_SPELLS; ++x) + { + if(spellid == m_charmspells[x].spellId) + { + m_charmspells[x].active = apply ? ACT_ENABLED : ACT_DISABLED; + } + } +} + +void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow) +{ + m_petnumber = petnumber; + if(statwindow) + m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, m_petnumber); + else + m_unit->SetUInt32Value(UNIT_FIELD_PETNUMBER, 0); +} + +bool Unit::isFrozen() const +{ + AuraList const& mRoot = GetAurasByType(SPELL_AURA_MOD_ROOT); + for(AuraList::const_iterator i = mRoot.begin(); i != mRoot.end(); ++i) + if( GetSpellSchoolMask((*i)->GetSpellProto()) & SPELL_SCHOOL_MASK_FROST) + return true; + return false; +} + +struct ProcTriggeredData +{ + ProcTriggeredData(SpellEntry const * _spellInfo, uint32 _spellParam, Aura* _triggeredByAura, uint32 _cooldown) + : spellInfo(_spellInfo), spellParam(_spellParam), triggeredByAura(_triggeredByAura), + triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura->GetId(),triggeredByAura->GetEffIndex())), + cooldown(_cooldown) + {} + + SpellEntry const * spellInfo; + uint32 spellParam; + Aura* triggeredByAura; + Unit::spellEffectPair triggeredByAura_SpellPair; + uint32 cooldown; +}; + +typedef std::list< ProcTriggeredData > ProcTriggeredList; + +void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, AuraTypeSet const& procAuraTypes, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellSchoolMask damageSchoolMask ) +{ + for(AuraTypeSet::const_iterator aur = procAuraTypes.begin(); aur != procAuraTypes.end(); ++aur) + { + // List of spells (effects) that proceed. Spell prototype and aura-specific value (damage for TRIGGER_DAMAGE) + ProcTriggeredList procTriggered; + + AuraList const& auras = GetAurasByType(*aur); + for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) + { + next = i; ++next; + + SpellEntry const *spellProto = (*i)->GetSpellProto(); + if(!spellProto) + continue; + + SpellProcEventEntry const *spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); + if(!spellProcEvent) + { + // used to prevent spam in log about same non-handled spells + static std::set nonHandledSpellProcSet; + + if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) + { + sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); + nonHandledSpellProcSet.insert(spellProto->Id); + } + + // spell.dbc use totally different flags, that only can create problems if used. + continue; + } + + // Check spellProcEvent data requirements + if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) + continue; + + // Check if current equipment allows aura to proc + if(!isVictim && GetTypeId() == TYPEID_PLAYER ) + { + if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) + { + Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); + + if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) + continue; + } + else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) + { + // Check if player is wearing shield + Item *item = ((Player*)this)->GetShield(true); + if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) + continue; + } + } + + float chance = (float)spellProto->procChance; + + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); + + if(!isVictim && spellProcEvent->ppmRate != 0) + { + uint32 WeaponSpeed = GetAttackTime(attType); + chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); + } + + if(roll_chance_f(chance)) + { + uint32 cooldown = spellProcEvent->cooldown; + + uint32 i_spell_eff = (*i)->GetEffIndex(); + + int32 i_spell_param; + switch(*aur) + { + case SPELL_AURA_PROC_TRIGGER_SPELL: + i_spell_param = procFlag; + break; + case SPELL_AURA_DUMMY: + case SPELL_AURA_PRAYER_OF_MENDING: + case SPELL_AURA_MOD_HASTE: + i_spell_param = i_spell_eff; + break; + case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: + i_spell_param = (*i)->GetModifier()->m_miscvalue; + break; + default: + i_spell_param = (*i)->GetModifier()->m_amount; + break; + } + + procTriggered.push_back( ProcTriggeredData(spellProto,i_spell_param,*i, cooldown) ); + } + } + + // Handle effects proceed this time + for(ProcTriggeredList::iterator i = procTriggered.begin(); i != procTriggered.end(); ++i) + { + // Some auras can be deleted in function called in this loop (except first, ofc) + // Until storing auras in std::multimap to hard check deleting by another way + if(i != procTriggered.begin()) + { + bool found = false; + AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); + AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); + for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) + { + if(itr->second==i->triggeredByAura) + { + found = true; + break; + } + } + + if(!found) + { + sLog.outError("Spell aura %u (id:%u effect:%u) has been deleted before call spell proc event handler",*aur,i->triggeredByAura_SpellPair.first,i->triggeredByAura_SpellPair.second); + sLog.outError("It can be deleted one from early processed auras:"); + for(ProcTriggeredList::iterator i2 = procTriggered.begin(); i != i2; ++i2) + sLog.outError(" Spell aura %u (id:%u effect:%u)",*aur,i2->triggeredByAura_SpellPair.first,i2->triggeredByAura_SpellPair.second); + sLog.outError(" "); + continue; + } + } + + // save charges existence before processing to prevent crash at access to deleted triggered aura after + bool triggeredByAuraWithCharges = i->triggeredByAura->m_procCharges > 0; + + bool casted = false; + switch(*aur) + { + case SPELL_AURA_PROC_TRIGGER_SPELL: + { + sLog.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleProcTriggerSpell(pTarget, damage, i->triggeredByAura, procSpell,i->spellParam,attType,i->cooldown); + break; + } + case SPELL_AURA_PROC_TRIGGER_DAMAGE: + { + sLog.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", i->spellParam, i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + uint32 damage = i->spellParam; + SpellNonMeleeDamageLog(pTarget, i->spellInfo->Id, damage, true, true); + casted = true; + break; + } + case SPELL_AURA_DUMMY: + { + sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleDummyAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); + break; + } + case SPELL_AURA_PRAYER_OF_MENDING: + { + sLog.outDebug("ProcDamageAndSpell(mending): casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + + // aura can be deleted at casts + int32 heal = i->triggeredByAura->GetModifier()->m_amount; + uint64 caster_guid = i->triggeredByAura->GetCasterGUID(); + + // jumps + int32 jumps = i->triggeredByAura->m_procCharges-1; + + // current aura expire + i->triggeredByAura->m_procCharges = 1; // will removed at next charges decrease + + // next target selection + if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) + { + Aura* aura = i->triggeredByAura; + + SpellEntry const* spellProto = aura->GetSpellProto(); + uint32 effIdx = aura->GetEffIndex(); + + float radius; + if (spellProto->EffectRadiusIndex[effIdx]) + radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); + else + radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); + + if(Player* caster = ((Player*)aura->GetCaster())) + { + caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); + + if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) + { + // aura will applied from caster, but spell casted from current aura holder + SpellModifier *mod = new SpellModifier; + mod->op = SPELLMOD_CHARGES; + mod->value = jumps-5; // negative + mod->type = SPELLMOD_FLAT; + mod->spellId = spellProto->Id; + mod->effectId = effIdx; + mod->lastAffected = NULL; + mod->mask = spellProto->SpellFamilyFlags; + mod->charges = 0; + + caster->AddSpellMod(mod, true); + CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,aura,caster->GetGUID()); + caster->AddSpellMod(mod, false); + } + } + } + + // heal + CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); + casted = true; + break; + } + case SPELL_AURA_MOD_HASTE: + { + sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleHasteAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); + break; + } + case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN: + { + // nothing do, just charges counter + // but count only in case appropriate school damage + casted = i->triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; + break; + } + case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: + { + sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); + casted = HandleOverrideClassScriptAuraProc(pTarget, i->spellParam, damage, i->triggeredByAura, procSpell,i->cooldown); + break; + } + default: + { + // nothing do, just charges counter + casted = true; + break; + } + } + + // Update charge (aura can be removed by triggers) + if(casted && triggeredByAuraWithCharges) + { + // need found aura (can be dropped by triggers) + AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); + AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); + for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) + { + if(itr->second == i->triggeredByAura) + { + if(i->triggeredByAura->m_procCharges > 0) + i->triggeredByAura->m_procCharges -= 1; + + i->triggeredByAura->UpdateAuraCharges(); + break; + } + } + } + } + + // Safely remove auras with zero charges + for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) + { + next = i; ++next; + if((*i)->m_procCharges == 0) + { + RemoveAurasDueToSpell((*i)->GetId()); + next = auras.begin(); + } + } + } +} + +SpellSchoolMask Unit::GetMeleeDamageSchoolMask() const +{ + return SPELL_SCHOOL_MASK_NORMAL; +} + +Player* Unit::GetSpellModOwner() +{ + if(GetTypeId()==TYPEID_PLAYER) + return (Player*)this; + if(((Creature*)this)->isPet() || ((Creature*)this)->isTotem()) + { + Unit* owner = GetOwner(); + if(owner && owner->GetTypeId()==TYPEID_PLAYER) + return (Player*)owner; + } + return NULL; +} + +///----------Pet responses methods----------------- +void Unit::SendPetCastFail(uint32 spellid, uint8 msg) +{ + Unit *owner = GetCharmerOrOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_PET_CAST_FAILED, (4+1)); + data << uint32(spellid); + data << uint8(msg); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetActionFeedback (uint8 msg) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_PET_ACTION_FEEDBACK, 1); + data << uint8(msg); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetTalk (uint32 pettalk) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_PET_ACTION_SOUND, 8+4); + data << uint64(GetGUID()); + data << uint32(pettalk); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetSpellCooldown (uint32 spellid, time_t cooltime) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_SPELL_COOLDOWN, 8+1+4+4); + data << uint64(GetGUID()); + data << uint8(0x0); // flags (0x1, 0x2) + data << uint32(spellid); + data << uint32(cooltime); + + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetClearCooldown (uint32 spellid) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_CLEAR_COOLDOWN, (4+8)); + data << uint32(spellid); + data << uint64(GetGUID()); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +void Unit::SendPetAIReaction(uint64 guid) +{ + Unit* owner = GetOwner(); + if(!owner || owner->GetTypeId() != TYPEID_PLAYER) + return; + + WorldPacket data(SMSG_AI_REACTION, 12); + data << uint64(guid) << uint32(00000002); + ((Player*)owner)->GetSession()->SendPacket(&data); +} + +///----------End of Pet responses methods---------- + +void Unit::StopMoving() +{ + clearUnitState(UNIT_STAT_MOVING); + + // send explicit stop packet + // rely on vmaps here because for example stormwind is in air + float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); + //if (fabs(GetPositionZ() - z) < 2.0f) + // Relocate(GetPositionX(), GetPositionY(), z); + Relocate(GetPositionX(), GetPositionY(),GetPositionZ()); + + SendMonsterMove(GetPositionX(), GetPositionY(), GetPositionZ(), 0, true, 0); + + // update position and orientation; + WorldPacket data; + BuildHeartBeatMsg(&data); + SendMessageToSet(&data,false); +} + +void Unit::SetFeared(bool apply, uint64 casterGUID, uint32 spellID) +{ + if( apply ) + { + if(HasAuraType(SPELL_AURA_PREVENTS_FLEEING)) + return; + + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); + + GetMotionMaster()->MovementExpired(false); + CastStop(GetGUID()==casterGUID ? spellID : 0); + + Unit* caster = ObjectAccessor::GetUnit(*this,casterGUID); + + GetMotionMaster()->MoveFleeing(caster); // caster==NULL processed in MoveFleeing + } + else + { + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING); + + GetMotionMaster()->MovementExpired(false); + + if( GetTypeId() != TYPEID_PLAYER && isAlive() ) + { + // restore appropriate movement generator + if(getVictim()) + GetMotionMaster()->MoveChase(getVictim()); + else + GetMotionMaster()->Initialize(); + + // attack caster if can + Unit* caster = ObjectAccessor::GetObjectInWorld(casterGUID, (Unit*)NULL); + if(caster && caster != getVictim() && ((Creature*)this)->AI()) + ((Creature*)this)->AI()->AttackStart(caster); + } + } + + if (GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->SetClientControl(this, !apply); +} + +void Unit::SetConfused(bool apply, uint64 casterGUID, uint32 spellID) +{ + if( apply ) + { + SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); + + CastStop(GetGUID()==casterGUID ? spellID : 0); + + GetMotionMaster()->MoveConfused(); + } + else + { + RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED); + + GetMotionMaster()->MovementExpired(false); + + if (GetTypeId() == TYPEID_UNIT) + { + // if in combat restore movement generator + if(getVictim()) + GetMotionMaster()->MoveChase(getVictim()); + } + } + + if(GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->SetClientControl(this, !apply); +} + +bool Unit::IsSitState() const +{ + uint8 s = getStandState(); + return s == PLAYER_STATE_SIT_CHAIR || s == PLAYER_STATE_SIT_LOW_CHAIR || + s == PLAYER_STATE_SIT_MEDIUM_CHAIR || s == PLAYER_STATE_SIT_HIGH_CHAIR || + s == PLAYER_STATE_SIT; +} + +bool Unit::IsStandState() const +{ + uint8 s = getStandState(); + return !IsSitState() && s != PLAYER_STATE_SLEEP && s != PLAYER_STATE_KNEEL; +} + +void Unit::SetStandState(uint8 state) +{ + SetByteValue(UNIT_FIELD_BYTES_1, 0, state); + + if (IsStandState()) + RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_NOT_SEATED); + + if(GetTypeId()==TYPEID_PLAYER) + { + WorldPacket data(SMSG_STANDSTATE_UPDATE, 1); + data << (uint8)state; + ((Player*)this)->GetSession()->SendPacket(&data); + } +} + +bool Unit::IsPolymorphed() const +{ + return GetSpellSpecific(getTransForm())==SPELL_MAGE_POLYMORPH; +} + +void Unit::SetDisplayId(uint32 modelId) +{ + SetUInt32Value(UNIT_FIELD_DISPLAYID, modelId); + + if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(!pet->isControlled()) + return; + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_MODEL_ID); + } +} + +void Unit::ClearComboPointHolders() +{ + while(!m_ComboPointHolders.empty()) + { + uint32 lowguid = *m_ComboPointHolders.begin(); + + Player* plr = objmgr.GetPlayer(MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); + if(plr && plr->GetComboTarget()==GetGUID()) // recheck for safe + plr->ClearComboPoints(); // remove also guid from m_ComboPointHolders; + else + m_ComboPointHolders.erase(lowguid); // or remove manually + } +} + +void Unit::ClearAllReactives() +{ + + for(int i=0; i < MAX_REACTIVE; ++i) + m_reactiveTimer[i] = 0; + + if (HasAuraState( AURA_STATE_DEFENSE)) + ModifyAuraState(AURA_STATE_DEFENSE, false); + if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_PARRY)) + ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); + if (HasAuraState( AURA_STATE_CRIT)) + ModifyAuraState(AURA_STATE_CRIT, false); + if (getClass() == CLASS_HUNTER && HasAuraState( AURA_STATE_HUNTER_CRIT_STRIKE) ) + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); + + if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->ClearComboPoints(); +} + +void Unit::UpdateReactives( uint32 p_time ) +{ + for(int i = 0; i < MAX_REACTIVE; ++i) + { + ReactiveType reactive = ReactiveType(i); + + if(!m_reactiveTimer[reactive]) + continue; + + if ( m_reactiveTimer[reactive] <= p_time) + { + m_reactiveTimer[reactive] = 0; + + switch ( reactive ) + { + case REACTIVE_DEFENSE: + if (HasAuraState(AURA_STATE_DEFENSE)) + ModifyAuraState(AURA_STATE_DEFENSE, false); + break; + case REACTIVE_HUNTER_PARRY: + if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_PARRY)) + ModifyAuraState(AURA_STATE_HUNTER_PARRY, false); + break; + case REACTIVE_CRIT: + if (HasAuraState(AURA_STATE_CRIT)) + ModifyAuraState(AURA_STATE_CRIT, false); + break; + case REACTIVE_HUNTER_CRIT: + if ( getClass() == CLASS_HUNTER && HasAuraState(AURA_STATE_HUNTER_CRIT_STRIKE) ) + ModifyAuraState(AURA_STATE_HUNTER_CRIT_STRIKE, false); + break; + case REACTIVE_OVERPOWER: + if(getClass() == CLASS_WARRIOR && GetTypeId() == TYPEID_PLAYER) + ((Player*)this)->ClearComboPoints(); + break; + default: + break; + } + } + else + { + m_reactiveTimer[reactive] -= p_time; + } + } +} + +Unit* Unit::SelectNearbyTarget() const +{ + CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + std::list targets; + + { + Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); + Trinity::UnitListSearcher searcher(targets, u_check); + + TypeContainerVisitor, WorldTypeMapContainer > world_unit_searcher(searcher); + TypeContainerVisitor, GridTypeMapContainer > grid_unit_searcher(searcher); + + CellLock cell_lock(cell, p); + cell_lock->Visit(cell_lock, world_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); + cell_lock->Visit(cell_lock, grid_unit_searcher, *MapManager::Instance().GetMap(GetMapId(), this)); + } + + // remove current target + if(getVictim()) + targets.remove(getVictim()); + + // remove not LoS targets + for(std::list::iterator tIter = targets.begin(); tIter != targets.end();) + { + if(!IsWithinLOSInMap(*tIter)) + { + std::list::iterator tIter2 = tIter; + ++tIter; + targets.erase(tIter2); + } + else + ++tIter; + } + + // no appropriate targets + if(targets.empty()) + return NULL; + + // select random + uint32 rIdx = urand(0,targets.size()-1); + std::list::const_iterator tcIter = targets.begin(); + for(uint32 i = 0; i < rIdx; ++i) + ++tcIter; + + return *tcIter; +} + +void Unit::ApplyAttackTimePercentMod( WeaponAttackType att,float val, bool apply ) +{ + float remainingTimePct = (float)m_attackTimer[att] / (GetAttackTime(att) * m_modAttackSpeedPct[att]); + if(val > 0) + { + ApplyPercentModFloatVar(m_modAttackSpeedPct[att], val, !apply); + ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,val,!apply); + } + else + { + ApplyPercentModFloatVar(m_modAttackSpeedPct[att], -val, apply); + ApplyPercentModFloatValue(UNIT_FIELD_BASEATTACKTIME+att,-val,apply); + } + m_attackTimer[att] = uint32(GetAttackTime(att) * m_modAttackSpeedPct[att] * remainingTimePct); +} + +void Unit::ApplyCastTimePercentMod(float val, bool apply ) +{ + if(val > 0) + ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,val,!apply); + else + ApplyPercentModFloatValue(UNIT_MOD_CAST_SPEED,-val,apply); +} + +uint32 Unit::GetCastingTimeForBonus( SpellEntry const *spellProto, DamageEffectType damagetype, uint32 CastingTime ) +{ + if (CastingTime > 7000) CastingTime = 7000; + if (CastingTime < 1500) CastingTime = 1500; + + if(damagetype == DOT && !IsChanneledSpell(spellProto)) + CastingTime = 3500; + + int32 overTime = 0; + uint8 effects = 0; + bool DirectDamage = false; + bool AreaEffect = false; + + for ( uint32 i=0; i<3;i++) + { + switch ( spellProto->Effect[i] ) + { + case SPELL_EFFECT_SCHOOL_DAMAGE: + case SPELL_EFFECT_POWER_DRAIN: + case SPELL_EFFECT_HEALTH_LEECH: + case SPELL_EFFECT_ENVIRONMENTAL_DAMAGE: + case SPELL_EFFECT_POWER_BURN: + case SPELL_EFFECT_HEAL: + DirectDamage = true; + break; + case SPELL_EFFECT_APPLY_AURA: + switch ( spellProto->EffectApplyAuraName[i] ) + { + case SPELL_AURA_PERIODIC_DAMAGE: + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_PERIODIC_LEECH: + if ( GetSpellDuration(spellProto) ) + overTime = GetSpellDuration(spellProto); + break; + default: + // -5% per additional effect + ++effects; + break; + } + default: + break; + } + + if(IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetA[i])) || IsAreaEffectTarget(Targets(spellProto->EffectImplicitTargetB[i]))) + AreaEffect = true; + } + + // Combined Spells with Both Over Time and Direct Damage + if ( overTime > 0 && CastingTime > 0 && DirectDamage ) + { + // mainly for DoTs which are 3500 here otherwise + uint32 OriginalCastTime = GetSpellCastTime(spellProto); + if (OriginalCastTime > 7000) OriginalCastTime = 7000; + if (OriginalCastTime < 1500) OriginalCastTime = 1500; + // Portion to Over Time + float PtOT = (overTime / 15000.f) / ((overTime / 15000.f) + (OriginalCastTime / 3500.f)); + + if ( damagetype == DOT ) + CastingTime = uint32(CastingTime * PtOT); + else if ( PtOT < 1.0f ) + CastingTime = uint32(CastingTime * (1 - PtOT)); + else + CastingTime = 0; + } + + // Area Effect Spells receive only half of bonus + if ( AreaEffect ) + CastingTime /= 2; + + // -5% of total per any additional effect + for ( uint8 i=0; i 175 ) + { + CastingTime -= 175; + } + else + { + CastingTime = 0; + break; + } + } + + return CastingTime; +} + +void Unit::UpdateAuraForGroup(uint8 slot) +{ + if(GetTypeId() == TYPEID_PLAYER) + { + Player* player = (Player*)this; + if(player->GetGroup()) + { + player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_AURAS); + player->SetAuraUpdateMask(slot); + } + } + else if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet()) + { + Pet *pet = ((Pet*)this); + if(pet->isControlled()) + { + Unit *owner = GetOwner(); + if(owner && (owner->GetTypeId() == TYPEID_PLAYER) && ((Player*)owner)->GetGroup()) + { + ((Player*)owner)->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_AURAS); + pet->SetAuraUpdateMask(slot); + } + } + } +} + +float Unit::GetAPMultiplier(WeaponAttackType attType, bool normalized) +{ + if (!normalized || GetTypeId() != TYPEID_PLAYER) + return float(GetAttackTime(attType))/1000.0f; + + Item *Weapon = ((Player*)this)->GetWeaponForAttack(attType); + if (!Weapon) + return 2.4; // fist attack + + switch (Weapon->GetProto()->InventoryType) + { + case INVTYPE_2HWEAPON: + return 3.3; + case INVTYPE_RANGED: + case INVTYPE_RANGEDRIGHT: + case INVTYPE_THROWN: + return 2.8; + case INVTYPE_WEAPON: + case INVTYPE_WEAPONMAINHAND: + case INVTYPE_WEAPONOFFHAND: + default: + return Weapon->GetProto()->SubClass==ITEM_SUBCLASS_WEAPON_DAGGER ? 1.7 : 2.4; + } +} + +Aura* Unit::GetDummyAura( uint32 spell_id ) const +{ + Unit::AuraList const& mDummy = GetAurasByType(SPELL_AURA_DUMMY); + for(Unit::AuraList::const_iterator itr = mDummy.begin(); itr != mDummy.end(); ++itr) + if ((*itr)->GetId() == spell_id) + return *itr; + + return NULL; +} + +bool Unit::IsUnderLastManaUseEffect() const +{ + return getMSTimeDiff(m_lastManaUse,getMSTime()) < 5000; +} + +void Unit::SetContestedPvP(Player *attackedPlayer) +{ + Player* player = GetCharmerOrOwnerPlayerOrPlayerItself(); + + if(!player || attackedPlayer && (attackedPlayer == player || player->duel && player->duel->opponent == attackedPlayer)) + return; + + player->SetContestedPvPTimer(30000); + if(!player->hasUnitState(UNIT_STAT_ATTACK_PLAYER)) + { + player->addUnitState(UNIT_STAT_ATTACK_PLAYER); + player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_CONTESTED_PVP); + // call MoveInLineOfSight for nearby contested guards + SetVisibility(GetVisibility()); + } + if(!hasUnitState(UNIT_STAT_ATTACK_PLAYER)) + { + addUnitState(UNIT_STAT_ATTACK_PLAYER); + // call MoveInLineOfSight for nearby contested guards + SetVisibility(GetVisibility()); + } +} + +void Unit::AddPetAura(PetAura const* petSpell) +{ + m_petAuras.insert(petSpell); + if(Pet* pet = GetPet()) + pet->CastPetAura(petSpell); +} + +void Unit::RemovePetAura(PetAura const* petSpell) +{ + m_petAuras.erase(petSpell); + if(Pet* pet = GetPet()) + pet->RemoveAurasDueToSpell(petSpell->GetAura(pet->GetEntry())); +} + +Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id) +{ + Pet* pet = new Pet(HUNTER_PET); + + if(!pet->CreateBaseAtCreature(creatureTarget)) + { + delete pet; + return NULL; + } + + pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, this->GetGUID()); + pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, this->GetGUID()); + pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,this->getFaction()); + pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id); + + if(!pet->InitStatsForLevel(creatureTarget->getLevel())) + { + sLog.outError("ERROR: Pet::InitStatsForLevel() failed for creature (Entry: %u)!",creatureTarget->GetEntry()); + delete pet; + return NULL; + } + + pet->GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true); + // this enables pet details window (Shift+P) + pet->AIM_Initialize(); + pet->InitPetCreateSpells(); + pet->SetHealth(pet->GetMaxHealth()); + + return pet; +} diff --git a/win/TrinityCore&Script VC80.sln b/win/TrinityCore&Script VC80.sln index 8431a55fb65..e5f59ada33c 100644 --- a/win/TrinityCore&Script VC80.sln +++ b/win/TrinityCore&Script VC80.sln @@ -1,151 +1,151 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC80\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC80\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" - ProjectSection(ProjectDependencies) = postProject - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} - {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} - {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC80\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC80\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC80\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC80\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC80\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC80\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" - ProjectSection(ProjectDependencies) = postProject - {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC80\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityScript", "..\src\bindings\scripts\VC80\80ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" - ProjectSection(ProjectDependencies) = postProject - {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWrappers", "VC80\ACE_vc8.vcproj", "{AD537C9A-FECA-1BAD-6757-8A6348EA12C8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 - {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC80\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC80\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" + ProjectSection(ProjectDependencies) = postProject + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {AD537C9A-FECA-1BAD-6757-8A6348EA12C8} + {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} + {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC80\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC80\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC80\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC80\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC80\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC80\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" + ProjectSection(ProjectDependencies) = postProject + {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC80\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityScript", "..\src\bindings\scripts\VC80\80ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" + ProjectSection(ProjectDependencies) = postProject + {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWrappers", "VC80\ACE_vc8.vcproj", "{AD537C9A-FECA-1BAD-6757-8A6348EA12C8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 + {AD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection +EndGlobal diff --git a/win/TrinityCore&Script VC90.sln b/win/TrinityCore&Script VC90.sln index 2e749c005c1..f320ab3f99f 100644 --- a/win/TrinityCore&Script VC90.sln +++ b/win/TrinityCore&Script VC90.sln @@ -1,151 +1,151 @@ -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC90\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC90\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" - ProjectSection(ProjectDependencies) = postProject - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} - {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} - {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC90\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC90\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC90\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC90\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC90\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC90\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" - ProjectSection(ProjectDependencies) = postProject - {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC90\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" - ProjectSection(ProjectDependencies) = postProject - {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ScriptsFull", "..\src\bindings\scripts\VC90\90ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" - ProjectSection(ProjectDependencies) = postProject - {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWraper", "VC90\ACE_vc9.vcproj", "{BD537C9A-FECA-1BAD-6757-8A6348EA12C8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 - {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 - {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 - {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 - {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 - {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 - {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 - {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 - {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 - {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 - {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 - {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(DPCodeReviewSolutionGUID) = preSolution - DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} - EndGlobalSection -EndGlobal +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game", "VC90\game.vcproj", "{1DC6C4DA-A028-41F3-877D-D5400C594F88}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shared", "VC90\shared.vcproj", "{90297C34-F231-4DF4-848E-A74BCC0E40ED}" + ProjectSection(ProjectDependencies) = postProject + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} = {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E} + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} = {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2} + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} = {BD537C9A-FECA-1BAD-6757-8A6348EA12C8} + {8072769E-CF10-48BF-B9E1-12752A5DAC6E} = {8072769E-CF10-48BF-B9E1-12752A5DAC6E} + {262199E8-EEDF-4700-A1D1-E9CC901CF480} = {262199E8-EEDF-4700-A1D1-E9CC901CF480} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zthread", "VC90\zthread.vcproj", "{262199E8-EEDF-4700-A1D1-E9CC901CF480}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "VC90\zlib.vcproj", "{8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "framework", "VC90\framework.vcproj", "{BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "g3dlite", "VC90\g3dlite.vcproj", "{8072769E-CF10-48BF-B9E1-12752A5DAC6E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockets", "VC90\sockets.vcproj", "{04BAF755-0D67-46F8-B1C6-77AE5368F3CB}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityCore", "VC90\TrinityCore.vcproj", "{A3A04E47-43A2-4C08-90B3-029CEF558594}" + ProjectSection(ProjectDependencies) = postProject + {563E9905-3657-460C-AE63-0AC39D162E23} = {563E9905-3657-460C-AE63-0AC39D162E23} + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + {1DC6C4DA-A028-41F3-877D-D5400C594F88} = {1DC6C4DA-A028-41F3-877D-D5400C594F88} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrinityRealm", "VC90\TrinityRealm.vcproj", "{563E9905-3657-460C-AE63-0AC39D162E23}" + ProjectSection(ProjectDependencies) = postProject + {90297C34-F231-4DF4-848E-A74BCC0E40ED} = {90297C34-F231-4DF4-848E-A74BCC0E40ED} + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} = {04BAF755-0D67-46F8-B1C6-77AE5368F3CB} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ScriptsFull", "..\src\bindings\scripts\VC90\90ScriptDev2.vcproj", "{4295C8A9-79B7-4354-8064-F05FB9CA0C96}" + ProjectSection(ProjectDependencies) = postProject + {A3A04E47-43A2-4C08-90B3-029CEF558594} = {A3A04E47-43A2-4C08-90B3-029CEF558594} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ACEWraper", "VC90\ACE_vc9.vcproj", "{BD537C9A-FECA-1BAD-6757-8A6348EA12C8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.ActiveCfg = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|Win32.Build.0 = Debug|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.ActiveCfg = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Debug|x64.Build.0 = Debug|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.ActiveCfg = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|Win32.Build.0 = Release|Win32 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.ActiveCfg = Release|x64 + {1DC6C4DA-A028-41F3-877D-D5400C594F88}.Release|x64.Build.0 = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.ActiveCfg = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|Win32.Build.0 = Debug|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.ActiveCfg = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Debug|x64.Build.0 = Debug|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.ActiveCfg = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|Win32.Build.0 = Release|Win32 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.ActiveCfg = Release|x64 + {90297C34-F231-4DF4-848E-A74BCC0E40ED}.Release|x64.Build.0 = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.ActiveCfg = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|Win32.Build.0 = Debug|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.ActiveCfg = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Debug|x64.Build.0 = Debug|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.ActiveCfg = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|Win32.Build.0 = Release|Win32 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.ActiveCfg = Release|x64 + {262199E8-EEDF-4700-A1D1-E9CC901CF480}.Release|x64.Build.0 = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.ActiveCfg = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|Win32.Build.0 = Debug|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.ActiveCfg = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Debug|x64.Build.0 = Debug|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.ActiveCfg = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|Win32.Build.0 = Release|Win32 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.ActiveCfg = Release|x64 + {8F1DEA42-6A5B-4B62-839D-C141A7BFACF2}.Release|x64.Build.0 = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.ActiveCfg = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|Win32.Build.0 = Debug|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.ActiveCfg = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Debug|x64.Build.0 = Debug|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.ActiveCfg = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|Win32.Build.0 = Release|Win32 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.ActiveCfg = Release|x64 + {BF6F5D0E-33A5-4E23-9E7D-DD481B7B5B9E}.Release|x64.Build.0 = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.ActiveCfg = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|Win32.Build.0 = Debug|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.ActiveCfg = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Debug|x64.Build.0 = Debug|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.ActiveCfg = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|Win32.Build.0 = Release|Win32 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.ActiveCfg = Release|x64 + {8072769E-CF10-48BF-B9E1-12752A5DAC6E}.Release|x64.Build.0 = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.ActiveCfg = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|Win32.Build.0 = Debug|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.ActiveCfg = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Debug|x64.Build.0 = Debug|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.ActiveCfg = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|Win32.Build.0 = Release|Win32 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.ActiveCfg = Release|x64 + {04BAF755-0D67-46F8-B1C6-77AE5368F3CB}.Release|x64.Build.0 = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.ActiveCfg = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|Win32.Build.0 = Debug|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.ActiveCfg = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Debug|x64.Build.0 = Debug|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.ActiveCfg = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|Win32.Build.0 = Release|Win32 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.ActiveCfg = Release|x64 + {A3A04E47-43A2-4C08-90B3-029CEF558594}.Release|x64.Build.0 = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.ActiveCfg = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|Win32.Build.0 = Debug|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.ActiveCfg = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Debug|x64.Build.0 = Debug|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.ActiveCfg = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|Win32.Build.0 = Release|Win32 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.ActiveCfg = Release|x64 + {563E9905-3657-460C-AE63-0AC39D162E23}.Release|x64.Build.0 = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.ActiveCfg = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|Win32.Build.0 = Debug|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.ActiveCfg = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Debug|x64.Build.0 = Debug|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.ActiveCfg = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|Win32.Build.0 = Release|Win32 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.ActiveCfg = Release|x64 + {4295C8A9-79B7-4354-8064-F05FB9CA0C96}.Release|x64.Build.0 = Release|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.ActiveCfg = Debug|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|Win32.Build.0 = Debug|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.ActiveCfg = Debug|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Debug|x64.Build.0 = Debug|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.ActiveCfg = Release|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|Win32.Build.0 = Release|Win32 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.ActiveCfg = Release|x64 + {BD537C9A-FECA-1BAD-6757-8A6348EA12C8}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(DPCodeReviewSolutionGUID) = preSolution + DPCodeReviewSolutionGUID = {00000000-0000-0000-0000-000000000000} + EndGlobalSection +EndGlobal -- cgit v1.2.3 From db6328e719e5f20fcddd1e272050e3afa97f1303 Mon Sep 17 00:00:00 2001 From: w12x Date: Tue, 18 Nov 2008 23:27:26 +0100 Subject: Backed out changeset 34515ac455ef --HG-- branch : trunk --- src/shared/Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/shared/Common.h b/src/shared/Common.h index d5c2eedfc5c..9bf44b78f16 100644 --- a/src/shared/Common.h +++ b/src/shared/Common.h @@ -146,7 +146,7 @@ #define stricmp strcasecmp #define strnicmp strncasecmp #define I64FMT "%016llX" -#define I64FMTD "%I64u" +#define I64FMTD "%llu" #define SI64FMTD "%lld" #endif -- cgit v1.2.3 From ea68727d27e699200236b3b7ecbe36b7f7061cfc Mon Sep 17 00:00:00 2001 From: megamage Date: Tue, 18 Nov 2008 19:40:06 -0600 Subject: *Merge from Mangos. Add MapReference. Author: hunuza. *Also re-commit the patches reverted in 255. --HG-- branch : trunk --- src/bindings/scripts/include/sc_creature.cpp | 26 +- src/bindings/scripts/include/sc_creature.h | 1 + .../shadow_labyrinth/boss_grandmaster_vorpil.cpp | 13 +- .../serpent_shrine/boss_lady_vashj.cpp | 8 +- .../serpent_shrine/boss_leotheras_the_blind.cpp | 27 +- .../instance_magtheridons_lair.cpp | 71 ++-- .../scripts/scripts/zone/karazhan/karazhan.cpp | 18 +- .../magisters_terrace/boss_felblood_kaelthas.cpp | 72 ++-- .../scripts/zone/sunwell_plateau/boss_felmyst.cpp | 28 +- .../scripts/zone/sunwell_plateau/boss_kalecgos.cpp | 13 +- .../scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp | 27 +- .../scripts/scripts/zone/zulaman/boss_hexlord.cpp | 22 +- .../scripts/scripts/zone/zulaman/boss_janalai.cpp | 9 +- .../scripts/zone/zulaman/instance_zulaman.cpp | 29 +- .../Utilities/LinkedReference/RefManager.h | 6 +- .../Utilities/LinkedReference/Reference.h | 5 +- src/game/BattleGround.h | 8 +- src/game/ItemPrototype.h | 2 +- src/game/Map.cpp | 186 +++++++--- src/game/Map.h | 27 +- src/game/MapInstanced.cpp | 7 +- src/game/MapInstanced.h | 6 +- src/game/MapManager.cpp | 10 +- src/game/MapRefManager.h | 44 +++ src/game/MapReference.h | 50 +++ src/game/NPCHandler.cpp | 12 +- src/game/ObjectAccessor.cpp | 52 ++- src/game/ObjectAccessor.h | 5 +- src/game/Player.cpp | 261 +++++++------ src/game/Player.h | 33 +- src/game/SpellAuras.cpp | 108 ++---- src/game/SpellAuras.h | 9 +- src/game/SpellEffects.cpp | 54 +-- src/game/StatSystem.cpp | 2 +- src/game/Unit.cpp | 411 +++++++++++---------- src/game/Unit.h | 15 +- win/VC71/game.vcproj | 6 + win/VC80/game.vcproj | 8 + win/VC90/game.vcproj | 8 + 39 files changed, 944 insertions(+), 755 deletions(-) create mode 100644 src/game/MapRefManager.h create mode 100644 src/game/MapReference.h (limited to 'src') diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index 1ee90c41029..0c946b8f26d 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -679,13 +679,11 @@ void ScriptedAI::DoZoneInCombat(Unit* pUnit) return; } - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::const_iterator i; - for (i = PlayerList.begin(); i != PlayerList.end(); ++i) - { - if((*i)->isAlive()) - pUnit->AddThreat(*i, 0.0f); - } + Map::PlayerList const &PlayerList = map->GetPlayers(); + for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) + if (Player* i_pl = i->getSource()) + if (!i_pl->isAlive()) + pUnit->AddThreat(i_pl, 0.0f); } void ScriptedAI::DoResetThreat() @@ -721,6 +719,20 @@ void ScriptedAI::DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float ((Player*)pUnit)->TeleportTo(pUnit->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT); } +void ScriptedAI::DoTeleportAll(float x, float y, float z, float o) +{ + Map *map = m_creature->GetMap(); + if (!map->IsDungeon()) + return; + + Map::PlayerList const &PlayerList = map->GetPlayers(); + for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) + if (Player* i_pl = i->getSource()) + if (!i_pl->isAlive()) + i_pl->TeleportTo(m_creature->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT); +} + + Unit* ScriptedAI::DoSelectLowestHpFriendly(float range, uint32 MinHPDiff) { CellPair p(Trinity::ComputeCellPair(m_creature->GetPositionX(), m_creature->GetPositionY())); diff --git a/src/bindings/scripts/include/sc_creature.h b/src/bindings/scripts/include/sc_creature.h index 99ca4672f65..c1d7f06f029 100644 --- a/src/bindings/scripts/include/sc_creature.h +++ b/src/bindings/scripts/include/sc_creature.h @@ -146,6 +146,7 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI //Teleports a player without dropping threat (only teleports to same map) void DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o); + void DoTeleportAll(float x, float y, float z, float o); //Returns friendly unit with the most amount of hp missing from max hp Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1); diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp index 16bd012e576..79553b85ff2 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp @@ -220,18 +220,7 @@ struct TRINITY_DLL_DECL boss_grandmaster_vorpilAI : public ScriptedAI if ( DrawnShadows_Timer < diff) { - Map *map = m_creature->GetMap(); - if(map->IsDungeon()) - { - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - for (InstanceMap::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) - { - if((*i)->isAlive()) - { - (*i)->TeleportTo(555,VorpilPosition[0][0],VorpilPosition[0][1],VorpilPosition[0][2],0); - } - } - } + DoTeleportAll(VorpilPosition[0][0],VorpilPosition[0][1],VorpilPosition[0][2],0); m_creature->Relocate(VorpilPosition[0][0],VorpilPosition[0][1],VorpilPosition[0][2],0); DoCast(m_creature,SPELL_DRAWN_SHADOWS,true); diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp index 6adc833e8a8..49f750acb6c 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp @@ -250,12 +250,12 @@ struct TRINITY_DLL_DECL boss_lady_vashjAI : public ScriptedAI { //remove old tainted cores to prevent cheating in phase 2 Map *map = m_creature->GetMap(); - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - for(InstanceMap::PlayerList::const_iterator i = PlayerList.begin();i != PlayerList.end(); ++i) + Map::PlayerList const &PlayerList = map->GetPlayers(); + for(Map::PlayerList::const_iterator i = PlayerList.begin();i != PlayerList.end(); ++i) { - if((*i)) + if(Player* i_pl = i->getSource()) { - (*i)->DestroyItemCount(31088, 1, true); + i_pl->DestroyItemCount(31088, 1, true); } } } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp index 53aa7c48d35..913eef3ec4e 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp @@ -754,19 +754,22 @@ struct TRINITY_DLL_DECL mob_greyheart_spellbinderAI : public ScriptedAI if(Earthshock_Timer < diff) { Map *map = m_creature->GetMap(); - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - for(InstanceMap::PlayerList::const_iterator itr = PlayerList.begin();itr != PlayerList.end(); ++itr) + Map::PlayerList const &PlayerList = map->GetPlayers(); + for(Map::PlayerList::const_iterator itr = PlayerList.begin();itr != PlayerList.end(); ++itr) { - bool isCasting = false; - for(uint8 i = 0; i < CURRENT_MAX_SPELL; ++i) - if((*itr)->m_currentSpells[i]) - isCasting = true; - - if(isCasting) - { - DoCast((*itr), SPELL_EARTHSHOCK); - break; - } + if (Player* i_pl = itr->getSource()) + { + bool isCasting = false; + for(uint8 i = 0; i < CURRENT_MAX_SPELL; ++i) + if(i_pl->m_currentSpells[i]) + isCasting = true; + + if(isCasting) + { + DoCast(i_pl, SPELL_EARTHSHOCK); + break; + } + } } Earthshock_Timer = 8000 + rand()%7000; }else Earthshock_Timer -= diff; diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp index 8a6815e068a..d8f598f451e 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp @@ -118,9 +118,6 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance void SetData(uint32 type, uint32 data) { - Player *player = GetPlayer(); - if(!player) return; - switch(type) { case DATA_MAGTHERIDON_EVENT: @@ -129,7 +126,7 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance RespawnTimer = 10000; if(data != IN_PROGRESS) { - if(GameObject *Door = GameObject::GetGameObject(*player, DoorGUID)) + if(GameObject *Door = instance->GetGameObjectInMap(DoorGUID)) Door->SetGoState(0); } break; @@ -142,7 +139,7 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance Encounters[1] = NOT_STARTED; for(std::set::iterator i = ChannelerGUID.begin(); i != ChannelerGUID.end(); ++i) { - if(Creature *Channeler = (Creature*)Unit::GetUnit(*player, *i)) + if(Creature *Channeler = instance->GetCreatureInMap(*i)) { if(Channeler->isAlive()) Channeler->AI()->EnterEvadeMode(); @@ -151,7 +148,7 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance } } CageTimer = 0; - if(GameObject *Door = GameObject::GetGameObject(*player, DoorGUID)) + if(GameObject *Door = instance->GetGameObjectInMap(DoorGUID)) Door->SetGoState(0); }break; case IN_PROGRESS: // Event start. @@ -161,7 +158,7 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance // Let all five channelers aggro. for(std::set::iterator i = ChannelerGUID.begin(); i != ChannelerGUID.end(); ++i) { - Creature *Channeler = (Creature*)Unit::GetUnit(*player, *i); + Creature *Channeler = instance->GetCreatureInMap(*i); if(Channeler && Channeler->isAlive()) { //if(Unit *target = Channeler->SelectNearbyTarget()) @@ -170,19 +167,19 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance } } // Release Magtheridon after two minutes. - Creature *Magtheridon = (Creature*)Unit::GetUnit(*player, MagtheridonGUID); + Creature *Magtheridon = instance->GetCreatureInMap(MagtheridonGUID); if(Magtheridon && Magtheridon->isAlive()) { Magtheridon->TextEmote("'s bonds begin to weaken!", 0); CageTimer = 120000; } - if(GameObject *Door = GameObject::GetGameObject(*player, DoorGUID)) + if(GameObject *Door = instance->GetGameObjectInMap(DoorGUID)) Door->SetGoState(1); }break; case DONE: // Add buff and check if all channelers are dead. for(std::set::iterator i = ChannelerGUID.begin(); i != ChannelerGUID.end(); ++i) { - Unit *Channeler = Unit::GetUnit(*player, *i); + Creature *Channeler = instance->GetCreatureInMap(*i); if(Channeler && Channeler->isAlive()) { //Channeler->CastSpell(Channeler, SPELL_SOUL_TRANSFER, true); @@ -197,7 +194,7 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance // true - collapse / false - reset for(std::set::iterator i = ColumnGUID.begin(); i != ColumnGUID.end(); ++i) { - if(GameObject *Column = GameObject::GetGameObject(*player, *i)) + if(GameObject *Column = instance->GetGameObjectInMap(*i)) Column->SetGoState(!data); } break; @@ -213,30 +210,26 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance return 0; } - Player* GetPlayer() - { - if(((InstanceMap*)instance)->GetPlayers().size()) - return ((InstanceMap*)instance)->GetPlayers().front(); - return NULL; - } - void AttackNearestTarget(Creature *creature) { float minRange = 999.0f; float range; Player* target = NULL; - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)instance)->GetPlayers(); - InstanceMap::PlayerList::const_iterator i; + Map::PlayerList const &PlayerList = instance->GetPlayers(); + Map::PlayerList::const_iterator i; for(i = PlayerList.begin(); i != PlayerList.end(); ++i) { - if((*i)->isTargetableForAttack()) + if(Player* i_pl = i->getSource()) { - range = (*i)->GetDistance(creature); - if(range < minRange) + if(i_pl->isTargetableForAttack()) { - minRange = range; - target = *i; - } + range = i_pl->GetDistance(creature); + if(range < minRange) + { + minRange = range; + target = i_pl; + } + } } } creature->AI()->AttackStart(target); @@ -248,14 +241,11 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance { if(CageTimer <= diff) { - if(Player *player = GetPlayer()) + Creature *Magtheridon = instance->GetCreatureInMap(MagtheridonGUID); + if(Magtheridon && Magtheridon->isAlive()) { - Creature *Magtheridon = (Creature*)Unit::GetUnit(*player, MagtheridonGUID); - if(Magtheridon && Magtheridon->isAlive()) - { - Magtheridon->clearUnitState(UNIT_STAT_STUNNED); - AttackNearestTarget(Magtheridon); - } + Magtheridon->clearUnitState(UNIT_STAT_STUNNED); + AttackNearestTarget(Magtheridon); } CageTimer = 0; }else CageTimer -= diff; @@ -265,17 +255,14 @@ struct TRINITY_DLL_DECL instance_magtheridons_lair : public ScriptedInstance { if(RespawnTimer <= diff) { - if(Player *player = GetPlayer()) + for(std::set::iterator i = ChannelerGUID.begin(); i != ChannelerGUID.end(); ++i) { - for(std::set::iterator i = ChannelerGUID.begin(); i != ChannelerGUID.end(); ++i) + if(Creature *Channeler = instance->GetCreatureInMap(*i)) { - if(Creature *Channeler = (Creature*)Unit::GetUnit(*player, *i)) - { - if(Channeler->isAlive()) - Channeler->AI()->EnterEvadeMode(); - else - Channeler->Respawn(); - } + if(Channeler->isAlive()) + Channeler->AI()->EnterEvadeMode(); + else + Channeler->Respawn(); } } RespawnTimer = 0; diff --git a/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp b/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp index b0ab0d86db5..704a142cec9 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp @@ -285,18 +285,18 @@ struct TRINITY_DLL_DECL npc_barnesAI : public npc_escortAI Map *map = m_creature->GetMap(); if(!map->IsDungeon()) return; - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - if(PlayerList.empty()) + Map::PlayerList const &PlayerList = map->GetPlayers(); + if(PlayerList.isEmpty()) return; RaidWiped = true; - for(InstanceMap::PlayerList::const_iterator i = PlayerList.begin();i != PlayerList.end(); ++i) - { - if((*i)->isAlive() && !(*i)->isGameMaster()) - { - RaidWiped = false; - break; - } + for(Map::PlayerList::const_iterator i = PlayerList.begin();i != PlayerList.end(); ++i) + { + if (i->getSource()->isAlive() && !i->getSource()->isGameMaster()) + { + RaidWiped = false; + break; + } } if(RaidWiped) diff --git a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp index 7a44e04dd6d..6bfb0d6464d 100644 --- a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp +++ b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp @@ -231,17 +231,17 @@ struct TRINITY_DLL_DECL boss_felblood_kaelthasAI : public ScriptedAI float x,y,z; m_creature->Relocate(KaelLocations[0][0], KaelLocations[0][1], LOCATION_Z, 0); Map *map = m_creature->GetMap(); - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::const_iterator i; + Map::PlayerList const &PlayerList = map->GetPlayers(); + Map::PlayerList::const_iterator i; for (i = PlayerList.begin(); i != PlayerList.end(); ++i) { - //if(!(*i)->isGameMaster()) - if((*i) && (*i)->isAlive()) - { - (*i)->CastSpell((*i), SPELL_TELEPORT_CENTER, true); - m_creature->GetNearPoint(m_creature,x,y,z,5,5,0); - (*i)->TeleportTo(m_creature->GetMapId(),x,y,LOCATION_Z,(*i)->GetOrientation()); - } + if (Player* i_pl = i->getSource()) + if(i_pl->isAlive()) + { + i_pl->CastSpell(i_pl, SPELL_TELEPORT_CENTER, true); + m_creature->GetNearPoint(m_creature,x,y,z,5,5,0); + i_pl->TeleportTo(m_creature->GetMapId(),x,y,LOCATION_Z,i_pl->GetOrientation()); + } } DoCast(m_creature, SPELL_TELEPORT_CENTER, true); } @@ -249,34 +249,38 @@ struct TRINITY_DLL_DECL boss_felblood_kaelthasAI : public ScriptedAI void CastGravityLapseKnockUp() { Map *map = m_creature->GetMap(); - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::const_iterator i; + Map::PlayerList const &PlayerList = map->GetPlayers(); + Map::PlayerList::const_iterator i; for (i = PlayerList.begin(); i != PlayerList.end(); ++i) - { - if((*i) && (*i)->isAlive()) + { + if (Player* i_pl = i->getSource()) + if(i_pl->isAlive()) // Knockback into the air - (*i)->CastSpell((*i), SPELL_GRAVITY_LAPSE_DOT, true, 0, 0, m_creature->GetGUID()); + i_pl->CastSpell(i_pl, SPELL_GRAVITY_LAPSE_DOT, true, 0, 0, m_creature->GetGUID()); } } void CastGravityLapseFly() // Use Fly Packet hack for now as players can't cast "fly" spells unless in map 530. Has to be done a while after they get knocked into the air... { Map *map = m_creature->GetMap(); - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::const_iterator i; + Map::PlayerList const &PlayerList = map->GetPlayers(); + Map::PlayerList::const_iterator i; for (i = PlayerList.begin(); i != PlayerList.end(); ++i) - { - if((*i) && (*i)->isAlive()) + { + if (Player* i_pl = i->getSource()) { - // Also needs an exception in spell system. - (*i)->CastSpell((*i), SPELL_GRAVITY_LAPSE_FLY, true, 0, 0, m_creature->GetGUID()); - // Use packet hack - WorldPacket data(12); - data.SetOpcode(SMSG_MOVE_SET_CAN_FLY); - data.append((*i)->GetPackGUID()); - data << uint32(0); - (*i)->SendMessageToSet(&data, true); - (*i)->SetSpeed(MOVE_FLY, 2.0f); + if(i_pl->isAlive()) + { + // Also needs an exception in spell system. + i_pl->CastSpell(i_pl, SPELL_GRAVITY_LAPSE_FLY, true, 0, 0, m_creature->GetGUID()); + // Use packet hack + WorldPacket data(12); + data.SetOpcode(SMSG_MOVE_SET_CAN_FLY); + data.append(i_pl->GetPackGUID()); + data << uint32(0); + i_pl->SendMessageToSet(&data, true); + i_pl->SetSpeed(MOVE_FLY, 2.0f); + } } } } @@ -284,19 +288,19 @@ struct TRINITY_DLL_DECL boss_felblood_kaelthasAI : public ScriptedAI void RemoveGravityLapse() { Map *map = m_creature->GetMap(); - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::const_iterator i; + Map::PlayerList const &PlayerList = map->GetPlayers(); + Map::PlayerList::const_iterator i; for (i = PlayerList.begin(); i != PlayerList.end(); ++i) { - if((*i)) + if(Player* i_pl = i->getSource()) { - (*i)->RemoveAurasDueToSpell(SPELL_GRAVITY_LAPSE_FLY); - (*i)->RemoveAurasDueToSpell(SPELL_GRAVITY_LAPSE_DOT); + i_pl->RemoveAurasDueToSpell(SPELL_GRAVITY_LAPSE_FLY); + i_pl->RemoveAurasDueToSpell(SPELL_GRAVITY_LAPSE_DOT); WorldPacket data(12); data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY); - data.append((*i)->GetPackGUID()); + data.append(i_pl->GetPackGUID()); data << uint32(0); - (*i)->SendMessageToSet(&data, true); + i_pl->SendMessageToSet(&data, true); } } } diff --git a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp index e703b4b6c26..afc95cc8191 100644 --- a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp +++ b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp @@ -295,7 +295,7 @@ struct TRINITY_DLL_DECL boss_felmystAI : public ScriptedAI Timer[EVENT_FLIGHT_SEQUENCE] = 0; break; case 2: - if(Player* target = SelectRandomPlayer(150)) + if(Unit* target = SelectUnit(SELECT_TARGET_RANDOM, 0, 150, true)) { Creature* Vapor = m_creature->SummonCreature(MOB_VAPOR, target->GetPositionX()-5+rand()%10, target->GetPositionY()-5+rand()%10, target->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 9000); if(Vapor) @@ -311,7 +311,7 @@ struct TRINITY_DLL_DECL boss_felmystAI : public ScriptedAI case 3: DespawnSummons(MOB_VAPOR_TRAIL); //m_creature->CastSpell(m_creature, SPELL_VAPOR_SELECT); need core support - if(Player* target = SelectRandomPlayer(150)) + if(Unit* target = SelectUnit(SELECT_TARGET_RANDOM, 0, 150, true)) { //target->CastSpell(target, SPELL_VAPOR_SUMMON, true); need core support Creature* Vapor = m_creature->SummonCreature(MOB_VAPOR, target->GetPositionX()-5+rand()%10, target->GetPositionY()-5+rand()%10, target->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 9000); @@ -330,7 +330,7 @@ struct TRINITY_DLL_DECL boss_felmystAI : public ScriptedAI Timer[EVENT_FLIGHT_SEQUENCE] = 1; break; case 5: - if(Player* target = SelectRandomPlayer(150)) + if(Unit* target = SelectUnit(SELECT_TARGET_RANDOM, 0, 150, true)) { BreathX = target->GetPositionX(); BreathY = target->GetPositionY(); @@ -433,7 +433,7 @@ struct TRINITY_DLL_DECL boss_felmystAI : public ScriptedAI Timer[EVENT_GAS_NOVA] = 20000 + rand()%5 * 1000; break; case EVENT_ENCAPSULATE: - if(Unit* target = SelectRandomPlayer(150)) + if(Unit* target = SelectUnit(SELECT_TARGET_RANDOM, 0, 150, true)) { m_creature->CastSpell(target, SPELL_ENCAPSULATE_CHANNEL, false); target->CastSpell(target, SPELL_ENCAPSULATE_EFFECT, true);// linked aura, need core patch to remove this hack @@ -515,26 +515,6 @@ struct TRINITY_DLL_DECL boss_felmystAI : public ScriptedAI (*i)->RemoveCorpse(); } } - - Player* SelectRandomPlayer(float range = 0.0f) - { - Map *map = m_creature->GetMap(); - if (!map->IsDungeon()) return NULL; - - InstanceMap::PlayerList PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::iterator i; - while(PlayerList.size()) - { - i = PlayerList.begin(); - advance(i, rand()%PlayerList.size()); - if((range == 0.0f || m_creature->IsWithinDistInMap(*i, range)) - && (*i)->isTargetableForAttack()) - return *i; - else - PlayerList.erase(i); - } - return NULL; - } }; struct TRINITY_DLL_DECL mob_felmyst_vaporAI : public ScriptedAI diff --git a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp index f3911b9b865..96a79107296 100644 --- a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp +++ b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp @@ -368,13 +368,12 @@ struct TRINITY_DLL_DECL boss_sathrovarrAI : public ScriptedAI { Map *map = m_creature->GetMap(); if(!map->IsDungeon()) return; - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::const_iterator i; - for (i = PlayerList.begin(); i != PlayerList.end(); ++i) - { - if((*i)->HasAura(AURA_SPECTRAL_REALM,0)) - (*i)->RemoveAurasDueToSpell(AURA_SPECTRAL_REALM); - } + Map::PlayerList const &PlayerList = map->GetPlayers(); + Map::PlayerList::const_iterator i; + for(i = PlayerList.begin(); i != PlayerList.end(); ++i) + if(Player* i_pl = i->getSource()) + if(i_pl->HasAura(AURA_SPECTRAL_REALM,0)) + i_pl->RemoveAurasDueToSpell(AURA_SPECTRAL_REALM); } void Enrage(); // demon and dragon should enrage at the same time diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp index 0116947e390..3548cf92566 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp @@ -577,20 +577,23 @@ struct TRINITY_DLL_DECL cthunAI : public Scripted_NoMovementAI Map *map = m_creature->GetMap(); if(!map->IsDungeon()) return; - InstanceMap::PlayerList const &PlayerList = ((InstanceMap*)map)->GetPlayers(); - for (InstanceMap::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) + Map::PlayerList const &PlayerList = map->GetPlayers(); + for (Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) { - //Play random sound to the zone - switch (rand()%8) + if (Player* i_pl = i->getSource()) { - case 0: (*i)->SendPlaySound(RND_WISPER_1, true); break; - case 1: (*i)->SendPlaySound(RND_WISPER_2, true); break; - case 2: (*i)->SendPlaySound(RND_WISPER_3, true); break; - case 3: (*i)->SendPlaySound(RND_WISPER_4, true); break; - case 4: (*i)->SendPlaySound(RND_WISPER_5, true); break; - case 5: (*i)->SendPlaySound(RND_WISPER_6, true); break; - case 6: (*i)->SendPlaySound(RND_WISPER_7, true); break; - case 7: (*i)->SendPlaySound(RND_WISPER_8, true); break; + //Play random sound to the zone + switch (rand()%8) + { + case 0: i_pl->SendPlaySound(RND_WISPER_1, true); break; + case 1: i_pl->SendPlaySound(RND_WISPER_2, true); break; + case 2: i_pl->SendPlaySound(RND_WISPER_3, true); break; + case 3: i_pl->SendPlaySound(RND_WISPER_4, true); break; + case 4: i_pl->SendPlaySound(RND_WISPER_5, true); break; + case 5: i_pl->SendPlaySound(RND_WISPER_6, true); break; + case 6: i_pl->SendPlaySound(RND_WISPER_7, true); break; + case 7: i_pl->SendPlaySound(RND_WISPER_8, true); break; + } } } diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp index d0a78f3c848..781a0c812ba 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp @@ -371,7 +371,7 @@ struct TRINITY_DLL_DECL boss_hex_lord_malacrassAI : public ScriptedAI if(SiphonSoul_Timer < diff) { - Player* target = SelectRandomPlayer(50); + Unit* target = SelectUnit(SELECT_TARGET_RANDOM, 0, 70, true); Unit *trigger = DoSpawnCreature(MOB_TEMP_TRIGGER, 0, 0, 0, 0, TEMPSUMMON_TIMED_DESPAWN, 30000); if(!target || !trigger) EnterEvadeMode(); else @@ -435,26 +435,6 @@ struct TRINITY_DLL_DECL boss_hex_lord_malacrassAI : public ScriptedAI } m_creature->CastSpell(target, PlayerAbility[PlayerClass][random].spell, false); } - - Player* SelectRandomPlayer(float range = 0.0f, bool alive = true) - { - Map *map = m_creature->GetMap(); - if (!map->IsDungeon()) return NULL; - - InstanceMap::PlayerList PlayerList = ((InstanceMap*)map)->GetPlayers(); - InstanceMap::PlayerList::iterator i; - while(PlayerList.size()) - { - i = PlayerList.begin(); - advance(i, rand()%PlayerList.size()); - if((range == 0.0f || m_creature->IsWithinDistInMap(*i, range)) - && (!alive || (*i)->isAlive())) - return *i; - else - PlayerList.erase(i); - } - return NULL; - } }; #define SPELL_BLOODLUST 43578 diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp index 0b460404f92..8cc7efb233b 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp @@ -397,11 +397,12 @@ struct TRINITY_DLL_DECL boss_janalaiAI : public ScriptedAI //Teleport every Player into the middle Map *map = m_creature->GetMap(); if(!map->IsDungeon()) return; - InstanceMap::PlayerList const &PlayerList =((InstanceMap*)map)->GetPlayers(); - for(InstanceMap::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) + Map::PlayerList const &PlayerList = map->GetPlayers(); + for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) { - if((*i)->isAlive()) - DoTeleportPlayer(*i, JanalainPos[0][0]-5+rand()%10, JanalainPos[0][1]-5+rand()%10, JanalainPos[0][2], 0); + if (Player* i_pl = i->getSource()) + if(i_pl->isAlive()) + DoTeleportPlayer(i_pl, JanalainPos[0][0]-5+rand()%10, JanalainPos[0][1]-5+rand()%10, JanalainPos[0][2], 0); } //m_creature->CastSpell(Temp, SPELL_SUMMON_PLAYERS, true); // core bug, spell does not work if too far return; diff --git a/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp b/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp index 2e9e481236f..2abf2d8becf 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp @@ -139,21 +139,28 @@ struct TRINITY_DLL_DECL instance_zulaman : public ScriptedInstance void OpenDoor(uint64 DoorGUID, bool open) { - if(((InstanceMap*)instance)->GetPlayers().size()) - if(Player* first = ((InstanceMap*)instance)->GetPlayers().front()) - if(GameObject *Door = GameObject::GetGameObject(*first, DoorGUID)) - Door->SetUInt32Value(GAMEOBJECT_STATE, open ? 0 : 1); + if(GameObject *Door = instance->GetGameObjectInMap(DoorGUID)) + Door->SetUInt32Value(GAMEOBJECT_STATE, open ? 0 : 1); } void SummonHostage(uint8 num) { - if(QuestMinute && ((InstanceMap*)instance)->GetPlayers().size()) - if(Player* first = ((InstanceMap*)instance)->GetPlayers().front()) - if(Unit* Hostage = first->SummonCreature(HostageInfo[num].npc, HostageInfo[num].x, HostageInfo[num].y, HostageInfo[num].z, HostageInfo[num].o, TEMPSUMMON_DEAD_DESPAWN, 0)) - { - Hostage->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); - Hostage->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); - } + if(!QuestMinute) + return; + + Map::PlayerList const &PlayerList = instance->GetPlayers(); + if (PlayerList.isEmpty()) + return; + + Map::PlayerList::const_iterator i = PlayerList.begin(); + if(Player* i_pl = i->getSource()) + { + if(Unit* Hostage = i_pl->SummonCreature(HostageInfo[num].npc, HostageInfo[num].x, HostageInfo[num].y, HostageInfo[num].z, HostageInfo[num].o, TEMPSUMMON_DEAD_DESPAWN, 0)) + { + Hostage->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); + Hostage->SetFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); + } + } } void CheckInstanceStatus() diff --git a/src/framework/Utilities/LinkedReference/RefManager.h b/src/framework/Utilities/LinkedReference/RefManager.h index 40b7cade914..599c4efab39 100644 --- a/src/framework/Utilities/LinkedReference/RefManager.h +++ b/src/framework/Utilities/LinkedReference/RefManager.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _REFMANAGER_H @@ -33,7 +33,9 @@ template class RefManager : public LinkedListHead virtual ~RefManager() { clearReferences(); } Reference* getFirst() { return ((Reference*) LinkedListHead::getFirst()); } + Reference const* getFirst() const { return ((Reference const*) LinkedListHead::getFirst()); } Reference* getLast() { return ((Reference*) LinkedListHead::getLast()); } + Reference const* getLast() const { return ((Reference const*) LinkedListHead::getLast()); } iterator begin() { return iterator(getFirst()); } iterator end() { return iterator(NULL); } diff --git a/src/framework/Utilities/LinkedReference/Reference.h b/src/framework/Utilities/LinkedReference/Reference.h index 8e969669b99..ca837c81f91 100644 --- a/src/framework/Utilities/LinkedReference/Reference.h +++ b/src/framework/Utilities/LinkedReference/Reference.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _REFERENCE_H @@ -74,6 +74,7 @@ template class Reference : public LinkedListElement } Reference* next() { return((Reference*)LinkedListElement::next()); } + Referenceconst* next() const { return((Reference const*)LinkedListElement::next()); } Reference* prev() { return((Reference*)LinkedListElement::prev()); } inline TO* operator ->() const { return iRefTo; } diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index 80bd52a14fe..e53ed1d21e6 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __BATTLEGROUND_H @@ -95,7 +95,8 @@ enum BattleGroundTimeIntervals START_DELAY3 = 15000, // ms used only in arena RESPAWN_ONE_DAY = 86400, // secs RESPAWN_IMMEDIATELY = 0, // secs - BUFF_RESPAWN_TIME = 180 // secs + BUFF_RESPAWN_TIME = 180, // secs + BG_HONOR_SCORE_TICKS = 330 // points }; enum BattleGroundBuffObjects @@ -433,7 +434,6 @@ class BattleGround virtual WorldSafeLocsEntry const* GetClosestGraveYard(float /*x*/, float /*y*/, float /*z*/, uint32 /*team*/) { return NULL; } virtual void AddPlayer(Player *plr); // must be implemented in BG subclass - virtual void RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket); // can be extended in in BG subclass diff --git a/src/game/ItemPrototype.h b/src/game/ItemPrototype.h index 42607095e65..4762bf1e26a 100644 --- a/src/game/ItemPrototype.h +++ b/src/game/ItemPrototype.h @@ -78,7 +78,7 @@ enum ItemBondingType { NO_BIND = 0, BIND_WHEN_PICKED_UP = 1, - BIND_WHEN_EQUIPPED = 2, + BIND_WHEN_EQUIPED = 2, BIND_WHEN_USE = 3, BIND_QUEST_ITEM = 4, BIND_QUEST_ITEM1 = 5 // not used in game diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 7b3e40c00b3..ba72775b5cf 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -35,6 +35,7 @@ #include "World.h" #include "ScriptCalls.h" #include "Group.h" +#include "MapRefManager.h" #include "MapInstanced.h" #include "InstanceSaveMgr.h" @@ -449,6 +450,8 @@ Map::LoadGrid(const Cell& cell, bool no_unload) bool Map::Add(Player *player) { + player->GetMapRef().link(this, player); + player->SetInstanceId(GetInstanceId()); // update player state for other player and visa-versa @@ -593,6 +596,55 @@ bool Map::loaded(const GridPair &p) const void Map::Update(const uint32 &t_diff) { + resetMarkedCells(); + + Trinity::ObjectUpdater updater(t_diff); + // for creature + TypeContainerVisitor grid_object_update(updater); + // for pets + TypeContainerVisitor world_object_update(updater); + + for(MapRefManager::iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) + { + Player* plr = iter->getSource(); + if(!plr->IsInWorld()) + continue; + + CellPair standing_cell(Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY())); + + // Check for correctness of standing_cell, it also avoids problems with update_cell + if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) + continue; + + // the overloaded operators handle range checking + // so ther's no need for range checking inside the loop + CellPair begin_cell(standing_cell), end_cell(standing_cell); + begin_cell << 1; begin_cell -= 1; // upper left + end_cell >> 1; end_cell += 1; // lower right + + for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) + { + for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) + { + // marked cells are those that have been visited + // don't visit the same cell twice + uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x; + if(!isCellMarked(cell_id)) + { + markCell(cell_id); + CellPair pair(x,y); + Cell cell(pair); + cell.data.Part.reserved = CENTER_DISTRICT; + cell.SetNoCreate(); + CellLock cell_lock(cell, pair); + cell_lock->Visit(cell_lock, grid_object_update, *this); + cell_lock->Visit(cell_lock, world_object_update, *this); + } + } + } + } + + // Don't unload grids if it's battleground, since we may have manually added GOs,creatures, those doesn't load from DB at grid re-load ! // This isn't really bother us, since as soon as we have instanced BG-s, the whole map unloads as the BG gets ended if (IsBattleGroundOrArena()) @@ -610,6 +662,7 @@ void Map::Update(const uint32 &t_diff) void Map::Remove(Player *player, bool remove) { + player->GetMapRef().unlink(); CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) { @@ -909,7 +962,7 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce) assert( grid != NULL); { - if(!pForce && ObjectAccessor::Instance().ActiveObjectsNearGrid(x, y, i_id, i_InstanceId) ) + if(!pForce && PlayersNearGrid(x, y) ) return false; DEBUG_LOG("Unloading grid[%u,%u] for map %u", x,y, i_id); @@ -1418,6 +1471,43 @@ bool Map::CanUnload(const uint32 &diff) return false; } +uint32 Map::GetPlayersCountExceptGMs() const +{ + uint32 count = 0; + for(MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) + if(!itr->getSource()->isGameMaster()) + ++count; + return count; +} + +void Map::SendToPlayers(WorldPacket const* data) const +{ + for(MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) + itr->getSource()->GetSession()->SendPacket(data); +} + +bool Map::PlayersNearGrid(uint32 x, uint32 y) const +{ + CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); + CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); + cell_min << 2; + cell_min -= 2; + cell_max >> 2; + cell_max += 2; + + for(MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) + { + Player* plr = iter->getSource(); + + CellPair p = Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()); + if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && + (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) + return true; + } + + return false; +} + template void Map::Add(Corpse *); template void Map::Add(Creature *); template void Map::Add(GameObject *); @@ -1453,7 +1543,7 @@ InstanceMap::~InstanceMap() */ bool InstanceMap::CanEnter(Player *player) { - if(std::find(i_Players.begin(),i_Players.end(),player)!=i_Players.end()) + if(player->GetMapRef().getTarget() == this) { sLog.outError("InstanceMap::CanEnter - player %s(%u) already in map %d,%d,%d!", player->GetName(), player->GetGUIDLow(), GetId(), GetInstanceId(), GetSpawnMode()); assert(false); @@ -1570,7 +1660,6 @@ bool InstanceMap::Add(Player *player) if(i_data) i_data->OnPlayerEnter(player); SetResetSchedule(false); - i_Players.push_back(player); player->SendInitWorldStates(); sLog.outDetail("MAP: Player '%s' entered the instance '%u' of map '%s'", player->GetName(), GetInstanceId(), GetMapName()); // initialize unload state @@ -1595,9 +1684,9 @@ void InstanceMap::Update(const uint32& t_diff) void InstanceMap::Remove(Player *player, bool remove) { sLog.outDetail("MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName()); - i_Players.remove(player); SetResetSchedule(true); - if(!m_unloadTimer && i_Players.empty()) + //if last player set unload timer + if(!m_unloadTimer && m_mapRefManager.getSize() == 1) m_unloadTimer = m_unloadWhenEmpty ? MIN_UNLOAD_DELAY : std::max(sWorld.getConfig(CONFIG_INSTANCE_UNLOAD_DELAY), (uint32)MIN_UNLOAD_DELAY); Map::Remove(player, remove); } @@ -1662,21 +1751,21 @@ bool InstanceMap::Reset(uint8 method) // note: since the map may not be loaded when the instance needs to be reset // the instance must be deleted from the DB by InstanceSaveManager - if(!i_Players.empty()) + if(HavePlayers()) { if(method == INSTANCE_RESET_ALL) { // notify the players to leave the instance so it can be reset - for(PlayerList::iterator itr = i_Players.begin(); itr != i_Players.end(); ++itr) - (*itr)->SendResetFailedNotify(GetId()); + for(MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) + itr->getSource()->SendResetFailedNotify(GetId()); } else { if(method == INSTANCE_RESET_GLOBAL) { // set the homebind timer for players inside (1 minute) - for(PlayerList::iterator itr = i_Players.begin(); itr != i_Players.end(); ++itr) - (*itr)->m_InstanceValid = false; + for(MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) + itr->getSource()->m_InstanceValid = false; } // the unload timer is not started @@ -1692,16 +1781,7 @@ bool InstanceMap::Reset(uint8 method) m_resetAfterUnload = true; } - return i_Players.empty(); -} - -uint32 InstanceMap::GetPlayersCountExceptGMs() const -{ - uint32 count = 0; - for(PlayerList::const_iterator itr = i_Players.begin(); itr != i_Players.end(); ++itr) - if(!(*itr)->isGameMaster()) - ++count; - return count; + return m_mapRefManager.isEmpty(); } void InstanceMap::PermBindAllPlayers(Player *player) @@ -1715,25 +1795,23 @@ void InstanceMap::PermBindAllPlayers(Player *player) Group *group = player->GetGroup(); // group members outside the instance group don't get bound - for(PlayerList::iterator itr = i_Players.begin(); itr != i_Players.end(); ++itr) + for(MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) { - if(*itr) + Player* plr = itr->getSource(); + // players inside an instance cannot be bound to other instances + // some players may already be permanently bound, in this case nothing happens + InstancePlayerBind *bind = plr->GetBoundInstance(save->GetMapId(), save->GetDifficulty()); + if(!bind || !bind->perm) { - // players inside an instance cannot be bound to other instances - // some players may already be permanently bound, in this case nothing happens - InstancePlayerBind *bind = (*itr)->GetBoundInstance(save->GetMapId(), save->GetDifficulty()); - if(!bind || !bind->perm) - { - (*itr)->BindToInstance(save, true); - WorldPacket data(SMSG_INSTANCE_SAVE_CREATED, 4); - data << uint32(0); - (*itr)->GetSession()->SendPacket(&data); - } - - // if the leader is not in the instance the group will not get a perm bind - if(group && group->GetLeaderGUID() == (*itr)->GetGUID()) - group->BindToInstance(save, true); + plr->BindToInstance(save, true); + WorldPacket data(SMSG_INSTANCE_SAVE_CREATED, 4); + data << uint32(0); + plr->GetSession()->SendPacket(&data); } + + // if the leader is not in the instance the group will not get a perm bind + if(group && group->GetLeaderGUID() == plr->GetGUID()) + group->BindToInstance(save, true); } } @@ -1745,11 +1823,14 @@ time_t InstanceMap::GetResetTime() void InstanceMap::UnloadAll(bool pForce) { - if(!i_Players.empty()) + if(HavePlayers()) { sLog.outError("InstanceMap::UnloadAll: there are still players in the instance at unload, should not happen!"); - for(PlayerList::iterator itr = i_Players.begin(); itr != i_Players.end(); ++itr) - if(*itr) (*itr)->TeleportTo((*itr)->m_homebindMapId, (*itr)->m_homebindX, (*itr)->m_homebindY, (*itr)->m_homebindZ, (*itr)->GetOrientation()); + for(MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) + { + Player* plr = itr->getSource(); + plr->TeleportTo(plr->m_homebindMapId, plr->m_homebindX, plr->m_homebindY, plr->m_homebindZ, plr->GetOrientation()); + } } if(m_resetAfterUnload == true) @@ -1758,10 +1839,10 @@ void InstanceMap::UnloadAll(bool pForce) Map::UnloadAll(pForce); } -void InstanceMap::SendResetWarnings(uint32 timeLeft) +void InstanceMap::SendResetWarnings(uint32 timeLeft) const { - for(PlayerList::iterator itr = i_Players.begin(); itr != i_Players.end(); ++itr) - (*itr)->SendInstanceResetWarning(GetId(), timeLeft); + for(MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) + itr->getSource()->SendInstanceResetWarning(GetId(), timeLeft); } void InstanceMap::SetResetSchedule(bool on) @@ -1769,7 +1850,7 @@ void InstanceMap::SetResetSchedule(bool on) // only for normal instances // the reset time is only scheduled when there are no payers inside // it is assumed that the reset time will rarely (if ever) change while the reset is scheduled - if(i_Players.empty() && !IsRaid() && !IsHeroic()) + if(!HavePlayers() && !IsRaid() && !IsHeroic()) { InstanceSave *save = sInstanceSaveManager.GetInstanceSave(GetInstanceId()); if(!save) sLog.outError("InstanceMap::SetResetSchedule: cannot turn schedule %s, no save available for instance %d of %d", on ? "on" : "off", GetInstanceId(), GetId()); @@ -1777,12 +1858,6 @@ void InstanceMap::SetResetSchedule(bool on) } } -void InstanceMap::SendToPlayers(WorldPacket const* data) const -{ - for(PlayerList::const_iterator itr = i_Players.begin(); itr != i_Players.end(); ++itr) - (*itr)->GetSession()->SendPacket(data); -} - /* ******* Battleground Instance Maps ******* */ BattleGroundMap::BattleGroundMap(uint32 id, time_t expiry, uint32 InstanceId) @@ -1796,7 +1871,7 @@ BattleGroundMap::~BattleGroundMap() bool BattleGroundMap::CanEnter(Player * player) { - if(std::find(i_Players.begin(),i_Players.end(),player)!=i_Players.end()) + if(player->GetMapRef().getTarget() == this) { sLog.outError("BGMap::CanEnter - player %u already in map!", player->GetGUIDLow()); assert(false); @@ -1817,7 +1892,6 @@ bool BattleGroundMap::Add(Player * player) Guard guard(*this); if(!CanEnter(player)) return false; - i_Players.push_back(player); // reset instance validity, battleground maps do not homebind player->m_InstanceValid = true; } @@ -1827,7 +1901,6 @@ bool BattleGroundMap::Add(Player * player) void BattleGroundMap::Remove(Player *player, bool remove) { sLog.outDetail("MAP: Removing player '%s' from bg '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName()); - i_Players.remove(player); Map::Remove(player, remove); } @@ -1838,15 +1911,14 @@ void BattleGroundMap::SetUnload() void BattleGroundMap::UnloadAll(bool pForce) { - while(!i_Players.empty()) + while(HavePlayers()) { - PlayerList::iterator itr = i_Players.begin(); - Player * plr = *itr; - if(plr) (plr)->TeleportTo((*itr)->m_homebindMapId, (*itr)->m_homebindX, (*itr)->m_homebindY, (*itr)->m_homebindZ, (*itr)->GetOrientation()); + Player * plr = m_mapRefManager.getFirst()->getSource(); + if(plr) (plr)->TeleportTo(plr->m_homebindMapId, plr->m_homebindX, plr->m_homebindY, plr->m_homebindZ, plr->GetOrientation()); // TeleportTo removes the player from this map (if the map exists) -> calls BattleGroundMap::Remove -> invalidates the iterator. // just in case, remove the player from the list explicitly here as well to prevent a possible infinite loop // note that this remove is not needed if the code works well in other places - i_Players.remove(plr); + plr->GetMapRef().unlink(); } Map::UnloadAll(pForce); diff --git a/src/game/Map.h b/src/game/Map.h index 2ded7cf0975..1765d6d09fa 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITY_MAP_H @@ -33,6 +33,7 @@ #include "Timer.h" #include "SharedDefines.h" #include "GameSystem/GridRefManager.h" +#include "MapRefManager.h" #include #include @@ -126,6 +127,7 @@ typedef UNORDERED_MAP CreatureMoveList; class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::ObjectLevelLockable { + friend class MapReference; public: Map(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode); virtual ~Map(); @@ -237,6 +239,14 @@ class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::O Creature* GetCreatureInMap(uint64 guid); GameObject* GetGameObjectInMap(uint64 guid); + bool HavePlayers() const { return !m_mapRefManager.isEmpty(); } + uint32 GetPlayersCountExceptGMs() const; + bool PlayersNearGrid(uint32 x,uint32 y) const; + + void SendToPlayers(WorldPacket const* data) const; + + typedef MapRefManager PlayerList; + PlayerList const& GetPlayers() const { return m_mapRefManager; } template void SwitchGridContainers(T* obj, bool active); private: void LoadVMap(int pX, int pY); @@ -286,6 +296,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::O uint32 i_InstanceId; uint32 m_unloadTimer; + MapRefManager m_mapRefManager; private: typedef GridReadGuard ReadGuard; typedef GridWriteGuard WriteGuard; @@ -325,8 +336,6 @@ enum InstanceResetMethod class TRINITY_DLL_SPEC InstanceMap : public Map { public: - typedef std::list PlayerList; // online players only - InstanceMap(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode); ~InstanceMap(); bool Add(Player *); @@ -337,14 +346,10 @@ class TRINITY_DLL_SPEC InstanceMap : public Map std::string GetScript() { return i_script; } InstanceData* GetInstanceData() { return i_data; } void PermBindAllPlayers(Player *player); - PlayerList const& GetPlayers() const { return i_Players;} - void SendToPlayers(WorldPacket const* data) const; time_t GetResetTime(); void UnloadAll(bool pForce); bool CanEnter(Player* player); - uint32 GetPlayersCountExceptGMs() const; - uint32 HavePlayers() const { return !i_Players.empty(); } - void SendResetWarnings(uint32 timeLeft); + void SendResetWarnings(uint32 timeLeft) const; void SetResetSchedule(bool on); private: bool m_resetAfterUnload; @@ -359,8 +364,6 @@ class TRINITY_DLL_SPEC InstanceMap : public Map class TRINITY_DLL_SPEC BattleGroundMap : public Map { public: - typedef std::list PlayerList; // online players only - BattleGroundMap(uint32 id, time_t, uint32 InstanceId); ~BattleGroundMap(); @@ -369,8 +372,6 @@ class TRINITY_DLL_SPEC BattleGroundMap : public Map bool CanEnter(Player* player); void SetUnload(); void UnloadAll(bool pForce); - private: - PlayerList i_Players; }; /*inline diff --git a/src/game/MapInstanced.cpp b/src/game/MapInstanced.cpp index 9a9128363f2..7b8f5fb9b64 100644 --- a/src/game/MapInstanced.cpp +++ b/src/game/MapInstanced.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "MapInstanced.h" @@ -26,7 +26,7 @@ #include "InstanceSaveMgr.h" #include "World.h" -MapInstanced::MapInstanced(uint32 id, time_t expiry, uint32 aInstanceId) : Map(id, expiry, 0, 0) +MapInstanced::MapInstanced(uint32 id, time_t expiry) : Map(id, expiry, 0, 0) { // initialize instanced maps list m_InstancedMaps.clear(); @@ -261,4 +261,3 @@ void MapInstanced::DestroyInstance(InstancedMaps::iterator &itr) delete itr->second; m_InstancedMaps.erase(itr++); } - diff --git a/src/game/MapInstanced.h b/src/game/MapInstanced.h index 44f39facbfe..cde37f9f3ff 100644 --- a/src/game/MapInstanced.h +++ b/src/game/MapInstanced.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITY_MAP_INSTANCED_H @@ -30,7 +30,7 @@ class TRINITY_DLL_DECL MapInstanced : public Map public: typedef UNORDERED_MAP< uint32, Map* > InstancedMaps; - MapInstanced(uint32 id, time_t, uint32 aInstanceId); + MapInstanced(uint32 id, time_t expiry); ~MapInstanced() {} // functions overwrite Map versions diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 86206fef49b..34aefdff074 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "MapManager.h" @@ -111,7 +111,7 @@ MapManager::_GetBaseMap(uint32 id) const MapEntry* entry = sMapStore.LookupEntry(id); if (entry && entry->Instanceable()) { - m = new MapInstanced(id, i_gridCleanUpDelay, 0); + m = new MapInstanced(id, i_gridCleanUpDelay); } else { @@ -246,6 +246,8 @@ MapManager::Update(time_t diff) if( !i_timer.Passed() ) return; + ObjectAccessor::Instance().UpdatePlayers(i_timer.GetCurrent()); + for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter) { checkAndCorrectGridStatesArray(); // debugging code, should be deleted some day @@ -336,7 +338,7 @@ uint32 MapManager::GetNumPlayersInInstances() MapInstanced::InstancedMaps &maps = ((MapInstanced *)map)->GetInstancedMaps(); for(MapInstanced::InstancedMaps::iterator mitr = maps.begin(); mitr != maps.end(); ++mitr) if(mitr->second->IsDungeon()) - ret += ((InstanceMap*)mitr->second)->GetPlayers().size(); + ret += ((InstanceMap*)mitr->second)->GetPlayers().getSize(); } return ret; } diff --git a/src/game/MapRefManager.h b/src/game/MapRefManager.h new file mode 100644 index 00000000000..da0c81a9138 --- /dev/null +++ b/src/game/MapRefManager.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2005-2008 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _MAPREFMANAGER +#define _MAPREFMANAGER + +#include "Utilities/LinkedReference/RefManager.h" + +class MapReference; + +class MapRefManager : public RefManager +{ + public: + typedef LinkedListHead::Iterator< MapReference > iterator; + typedef LinkedListHead::Iterator< MapReference const > const_iterator; + + MapReference* getFirst() { return (MapReference*)RefManager::getFirst(); } + MapReference const* getFirst() const { return (MapReference const*)RefManager::getFirst(); } + MapReference* getLast() { return (MapReference*)RefManager::getLast(); } + MapReference const* getLast() const { return (MapReference const*)RefManager::getLast(); } + + iterator begin() { return iterator(getFirst()); } + iterator end() { return iterator(NULL); } + iterator rbegin() { return iterator(getLast()); } + iterator rend() { return iterator(NULL); } + const_iterator begin() const { return const_iterator(getFirst()); } + const_iterator end() const { return const_iterator(getLast()); } +}; +#endif diff --git a/src/game/MapReference.h b/src/game/MapReference.h new file mode 100644 index 00000000000..b41796ea91b --- /dev/null +++ b/src/game/MapReference.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2005-2008 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _MAPREFERENCE_H +#define _MAPREFERENCE_H + +#include "Utilities/LinkedReference/Reference.h" +#include "Map.h" + +class TRINITY_DLL_SPEC MapReference : public Reference +{ + protected: + void targetObjectBuildLink() + { + // called from link() + getTarget()->m_mapRefManager.insertFirst(this); + getTarget()->m_mapRefManager.incSize(); + } + void targetObjectDestroyLink() + { + // called from unlink() + if(isValid()) getTarget()->m_mapRefManager.decSize(); + } + void sourceObjectDestroyLink() + { + // called from invalidate() + getTarget()->m_mapRefManager.decSize(); + } + public: + MapReference() : Reference() {} + ~MapReference() { unlink(); } + MapReference *next() { return (MapReference*)Reference::next(); } + MapReference const *next() const { return (MapReference const*)Reference::next(); } +}; +#endif diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp index 15a77c6c01e..4936e9f0991 100644 --- a/src/game/NPCHandler.cpp +++ b/src/game/NPCHandler.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -222,7 +222,7 @@ void WorldSession::HandleTrainerBuySpellOpcode( WorldPacket & recv_data ) // check present spell in trainer spell list TrainerSpellData const* trainer_spells = unit->GetTrainerSpells(); if(!trainer_spells) - return; + return; // not found, cheat? TrainerSpell const* trainer_spell = trainer_spells->Find(spellId); @@ -339,15 +339,13 @@ void WorldSession::HandleGossipSelectOptionOpcode( WorldPacket & recv_data ) if(!code.empty()) { - if (!Script->GossipSelectWithCode(_player, unit, _player->PlayerTalkClass->GossipOptionSender (option), _player->PlayerTalkClass->GossipOptionAction( option ), code.c_str())) unit->OnGossipSelect (_player, option); } else - { if (!Script->GossipSelect (_player, unit, _player->PlayerTalkClass->GossipOptionSender (option), _player->PlayerTalkClass->GossipOptionAction (option))) - unit->OnGossipSelect (_player, option); + unit->OnGossipSelect (_player, option); } } @@ -377,7 +375,7 @@ void WorldSession::HandleSpiritHealerActivateOpcode( WorldPacket & recv_data ) void WorldSession::SendSpiritResurrect() { - _player->ResurrectPlayer(0.5f,false, true); + _player->ResurrectPlayer(0.5f, true); _player->DurabilityLossAll(0.25f,true); diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index c03dbab09e9..8a7e8fbfa2c 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -142,7 +142,15 @@ Creature* ObjectAccessor::GetCreature(WorldObject const &u, uint64 guid) { Creature * ret = GetObjectInWorld(guid, (Creature*)NULL); - if(ret && ret->GetMapId() != u.GetMapId()) ret = NULL; + if(!ret) + return NULL; + + if(ret->GetMapId() != u.GetMapId()) + return NULL; + + if(ret->GetInstanceId() != u.GetInstanceId()) + return NULL; + return ret; } @@ -247,32 +255,6 @@ ObjectAccessor::SaveAllPlayers() itr->second->SaveToDB(); } -void -ObjectAccessor::_update() -{ - UpdateDataMapType update_players; - { - Guard guard(i_updateGuard); - while(!i_objects.empty()) - { - Object* obj = *i_objects.begin(); - i_objects.erase(i_objects.begin()); - if (!obj) - continue; - _buildUpdateObject(obj, update_players); - obj->ClearUpdateMask(false); - } - } - - WorldPacket packet; // here we allocate a std::vector with a size of 0x10000 - for(UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter) - { - iter->second.BuildPacket(&packet); - iter->first->GetSession()->SendPacket(&packet); - packet.clear(); // clean the string - } -} - void ObjectAccessor::UpdateObject(Object* obj, Player* exceptPlayer) { @@ -361,7 +343,7 @@ ObjectAccessor::_buildChangeObjectForPlayer(WorldObject *obj, UpdateDataMapType WorldObjectChangeAccumulator notifier(*obj, update_players); TypeContainerVisitor player_notifier(notifier); CellLock cell_lock(cell, p); - cell_lock->Visit(cell_lock, player_notifier, *MapManager::Instance().GetMap(obj->GetMapId(), obj)); + cell_lock->Visit(cell_lock, player_notifier, *obj->GetMap()); } Pet* @@ -519,6 +501,7 @@ ObjectAccessor::RemoveActiveObject( WorldObject * obj ) void ObjectAccessor::Update(uint32 diff) { + { // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects. HashMapHolder::MapType& playerMap = HashMapHolder::GetContainer(); @@ -589,8 +572,15 @@ ObjectAccessor::Update(uint32 diff) } } } +} - _update(); +void +ObjectAccessor::UpdatePlayers(uint32 diff) +{ + HashMapHolder::MapType& playerMap = HashMapHolder::GetContainer(); + for(HashMapHolder::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter) + if(iter->second->IsInWorld()) + iter->second->Update(diff); } bool @@ -677,14 +667,14 @@ ObjectAccessor::UpdateObjectVisibility(WorldObject *obj) CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); Cell cell(p); - MapManager::Instance().GetMap(obj->GetMapId(), obj)->UpdateObjectVisibility(obj,cell,p); + obj->GetMap()->UpdateObjectVisibility(obj,cell,p); } void ObjectAccessor::UpdateVisibilityForPlayer( Player* player ) { CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); Cell cell(p); - Map* m = MapManager::Instance().GetMap(player->GetMapId(),player); + Map* m = player->GetMap(); m->UpdatePlayerVisibility(player,cell,p); m->UpdateObjectsVisibilityFor(player,cell,p); diff --git a/src/game/ObjectAccessor.h b/src/game/ObjectAccessor.h index d0007d37f21..89ea6d1e43d 100644 --- a/src/game/ObjectAccessor.h +++ b/src/game/ObjectAccessor.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITY_OBJECTACCESSOR_H @@ -186,6 +186,7 @@ class TRINITY_DLL_DECL ObjectAccessor : public Trinity::SingletonSendPacket( &data ); } -void Player::EnvironmentalDamage(uint64 guid, EnvironmentalDamageType type, uint32 damage) +void Player::EnvironmentalDamage(uint64 guid, EnviromentalDamage type, uint32 damage) { WorldPacket data(SMSG_ENVIRONMENTALDAMAGELOG, (21)); data << (uint64)guid; @@ -1641,7 +1641,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati else { // far teleport to another map - Map* oldmap = IsInWorld() ? MapManager::Instance().GetMap(GetMapId(), this) : NULL; + Map* oldmap = IsInWorld() ? GetMap() : NULL; // check if we can enter before stopping combat / removing pet / totems / interrupting spells // Check enter rights before map getting to avoid creating instance copy for player @@ -3750,7 +3750,7 @@ void Player::SendDelayResponse(const uint32 ml_seconds) GetSession()->SendPacket( &data ); } -void Player::ResurrectPlayer(float restore_percent, bool updateToWorld, bool applySickness) +void Player::ResurrectPlayer(float restore_percent, bool applySickness) { WorldPacket data(SMSG_DEATH_RELEASE_LOC, 4*4); // remove spirit healer position data << uint32(-1); @@ -4281,7 +4281,7 @@ void Player::UpdateDefense() } } -void Player::HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, float amount, bool apply, bool affectStats) +void Player::HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, float amount, bool apply) { if(modGroup >= BASEMOD_END || modType >= MOD_END) { @@ -5243,7 +5243,7 @@ bool Player::SetPosition(float x, float y, float z, float orientation, bool tele return false; } - Map *m = MapManager::Instance().GetMap(GetMapId(), this); + Map *m = GetMap(); const float old_x = GetPositionX(); const float old_y = GetPositionY(); @@ -5261,7 +5261,7 @@ bool Player::SetPosition(float x, float y, float z, float orientation, bool tele m->PlayerRelocation(this, x, y, z, orientation); // reread after Map::Relocation - m = MapManager::Instance().GetMap(GetMapId(), this); + m = GetMap(); x = GetPositionX(); y = GetPositionY(); z = GetPositionZ(); @@ -6176,7 +6176,9 @@ uint32 Player::GetArenaTeamIdFromDB(uint64 guid, uint8 type) if(!result) return 0; - return (*result)[0].GetUInt32(); + uint32 id = (*result)[0].GetUInt32(); + delete result; + return id; } uint32 Player::GetZoneIdFromDB(uint64 guid) @@ -6707,7 +6709,7 @@ void Player::_ApplyItemBonuses(ItemPrototype const *proto,uint8 slot,bool apply) SetBaseWeaponDamage(attType, MAXDAMAGE, damage); } - if(!IsUseEquippedWeapon(slot==EQUIPMENT_SLOT_MAINHAND)) + if(!IsUseEquipedWeapon(slot==EQUIPMENT_SLOT_MAINHAND)) return; if (proto->Delay) @@ -8485,7 +8487,7 @@ Item* Player::GetWeaponForAttack(WeaponAttackType attackType, bool useable) cons if(!useable) return item; - if( item->IsBroken() || !IsUseEquippedWeapon(attackType==BASE_ATTACK) ) + if( item->IsBroken() || !IsUseEquipedWeapon(attackType==BASE_ATTACK) ) return NULL; return item; @@ -8640,6 +8642,7 @@ bool Player::IsValidPos( uint8 bag, uint8 slot ) return false; } + bool Player::HasItemCount( uint32 item, uint32 count, bool inBankAlso ) const { uint32 tempcount = 0; @@ -10155,7 +10158,7 @@ Item* Player::_StoreItem( uint16 pos, Item *pItem, uint32 count, bool clone, boo if( pItem->GetProto()->Bonding == BIND_WHEN_PICKED_UP || pItem->GetProto()->Bonding == BIND_QUEST_ITEM || - pItem->GetProto()->Bonding == BIND_WHEN_EQUIPPED && IsBagPos(pos) ) + pItem->GetProto()->Bonding == BIND_WHEN_EQUIPED && IsBagPos(pos) ) pItem->SetBinding( true ); if( bag == INVENTORY_SLOT_BAG_0 ) @@ -10201,7 +10204,7 @@ Item* Player::_StoreItem( uint16 pos, Item *pItem, uint32 count, bool clone, boo { if( pItem2->GetProto()->Bonding == BIND_WHEN_PICKED_UP || pItem2->GetProto()->Bonding == BIND_QUEST_ITEM || - pItem2->GetProto()->Bonding == BIND_WHEN_EQUIPPED && IsBagPos(pos) ) + pItem2->GetProto()->Bonding == BIND_WHEN_EQUIPED && IsBagPos(pos) ) pItem2->SetBinding( true ); pItem2->SetCount( pItem2->GetCount() + count ); @@ -10403,7 +10406,7 @@ void Player::VisualizeItem( uint8 slot, Item *pItem) return; // check also BIND_WHEN_PICKED_UP and BIND_QUEST_ITEM for .additem or .additemset case by GM (not binded at adding to inventory) - if( pItem->GetProto()->Bonding == BIND_WHEN_EQUIPPED || pItem->GetProto()->Bonding == BIND_WHEN_PICKED_UP || pItem->GetProto()->Bonding == BIND_QUEST_ITEM ) + if( pItem->GetProto()->Bonding == BIND_WHEN_EQUIPED || pItem->GetProto()->Bonding == BIND_WHEN_PICKED_UP || pItem->GetProto()->Bonding == BIND_QUEST_ITEM ) pItem->SetBinding( true ); sLog.outDebug( "STORAGE: EquipItem slot = %u, item = %u", slot, pItem->GetEntry()); @@ -10548,8 +10551,6 @@ void Player::DestroyItem( uint8 bag, uint8 slot, bool update ) if(pItem->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED)) CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", pItem->GetGUIDLow()); - ItemPrototype const *pProto = pItem->GetProto(); - RemoveEnchantmentDurations(pItem); RemoveItemDurations(pItem); @@ -14207,7 +14208,7 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff) for(int i = UNIT_FIELD_AURA; i <= UNIT_FIELD_AURASTATE; ++i) SetUInt32Value(i, 0); - //QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'",GetGUIDLow()); + //QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'",GetGUIDLow()); if(result) { @@ -14217,10 +14218,11 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff) uint64 caster_guid = fields[0].GetUInt64(); uint32 spellid = fields[1].GetUInt32(); uint32 effindex = fields[2].GetUInt32(); - int32 damage = (int32)fields[3].GetUInt32(); - int32 maxduration = (int32)fields[4].GetUInt32(); - int32 remaintime = (int32)fields[5].GetUInt32(); - int32 remaincharges = (int32)fields[6].GetUInt32(); + uint32 stackcount = fields[3].GetUInt32(); + int32 damage = (int32)fields[4].GetUInt32(); + int32 maxduration = (int32)fields[5].GetUInt32(); + int32 remaintime = (int32)fields[6].GetUInt32(); + int32 remaincharges = (int32)fields[7].GetUInt32(); SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid); if(!spellproto) @@ -14257,11 +14259,15 @@ void Player::_LoadAuras(QueryResult *result, uint32 timediff) if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) continue; - Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); - if(!damage) - damage = aura->GetModifier()->m_amount; - aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); - AddAura(aura); + for(uint32 i=0; iGetModifier()->m_amount; + aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); + AddAura(aura); + sLog.outString("Added aura spellid %u, effect %u", spellproto->Id, effindex); + } } while( result->NextRow() ); @@ -15320,31 +15326,54 @@ void Player::_SaveAuras() CharacterDatabase.PExecute("DELETE FROM character_aura WHERE guid = '%u'",GetGUIDLow()); AuraMap const& auras = GetAuras(); - for(AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) + + if (auras.empty()) + return; + + spellEffectPair lastEffectPair = auras.begin()->first; + uint32 stackCounter = 1; + + for(AuraMap::const_iterator itr = auras.begin(); ; ++itr) { - SpellEntry const *spellInfo = itr->second->GetSpellProto(); + if(itr == auras.end() || lastEffectPair != itr->first) + { + AuraMap::const_iterator itr2 = itr; + // save previous spellEffectPair to db + itr2--; + SpellEntry const *spellInfo = itr2->second->GetSpellProto(); - //skip all auras from spells that are passive or need a shapeshift - if (itr->second->IsPassive() || itr->second->IsRemovedOnShapeLost()) - continue; + //skip all auras from spells that are passive or need a shapeshift + if (!(itr2->second->IsPassive() || itr2->second->IsRemovedOnShapeLost())) + { + //do not save single target auras (unless they were cast by the player) + if (!(itr2->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo))) + { + uint8 i; + // or apply at cast SPELL_AURA_MOD_SHAPESHIFT or SPELL_AURA_MOD_STEALTH auras + for (i = 0; i < 3; i++) + if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT || + spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH) + break; - //do not save single target auras (unless they were cast by the player) - if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)) - continue; + if (i == 3) + { + CharacterDatabase.PExecute("INSERT INTO character_aura (guid,caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges) " + "VALUES ('%u', '" I64FMTD "' ,'%u', '%u', '%u', '%d', '%d', '%d', '%d')", + GetGUIDLow(), itr2->second->GetCasterGUID(), (uint32)itr2->second->GetId(), (uint32)itr2->second->GetEffIndex(), stackCounter, itr2->second->GetModifier()->m_amount,int(itr2->second->GetAuraMaxDuration()),int(itr2->second->GetAuraDuration()),int(itr2->second->m_procCharges)); + } + } + } - uint8 i; - // or apply at cast SPELL_AURA_MOD_SHAPESHIFT or SPELL_AURA_MOD_STEALTH auras - for (i = 0; i < 3; i++) - if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT || - spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH) + if(itr == auras.end()) break; + } - if (i == 3) + if (lastEffectPair == itr->first) + stackCounter++; + else { - CharacterDatabase.PExecute("DELETE FROM character_aura WHERE guid = '%u' and spell = '%u' and effect_index= '%u'",GetGUIDLow(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex()); - CharacterDatabase.PExecute("INSERT INTO character_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " - "VALUES ('%u', '" I64FMTD "' ,'%u', '%u', '%d', '%d', '%d', '%d')", - GetGUIDLow(), itr->second->GetCasterGUID(), (uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(), (*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); + lastEffectPair = itr->first; + stackCounter = 1; } } } @@ -17910,7 +17939,7 @@ void Player::learnSkillRewardedSpells(uint32 skill_id ) if (pAbility->classmask && !(pAbility->classmask & classMask)) continue; - if (SpellEntry const* spellentry = sSpellStore.LookupEntry(pAbility->spellId)) + if (sSpellStore.LookupEntry(pAbility->spellId)) { // Ok need learn spell learnSpell(pAbility->spellId); @@ -18323,7 +18352,6 @@ bool Player::RewardPlayerAndGroupAtKill(Unit* pVictim) Player* member_with_max_level = NULL; Player* not_gray_member_with_max_level = NULL; - // gets the max member level of the group, and the max member level that still gets XP pGroup->GetDataForXPAtKill(pVictim,count,sum_level,member_with_max_level,not_gray_member_with_max_level); if(member_with_max_level) @@ -18332,7 +18360,7 @@ bool Player::RewardPlayerAndGroupAtKill(Unit* pVictim) // also no XP gained if there is no member below gray level xp = (PvP || !not_gray_member_with_max_level) ? 0 : Trinity::XP::Gain(not_gray_member_with_max_level, pVictim); - // skip in check PvP case (for speed, not used) + /// skip in check PvP case (for speed, not used) bool is_raid = PvP ? false : sMapStore.LookupEntry(GetMapId())->IsRaid() && pGroup->isRaidGroup(); bool is_dungeon = PvP ? false : sMapStore.LookupEntry(GetMapId())->IsDungeon(); float group_rate = Trinity::XP::xp_in_group_rate(count,is_raid); @@ -18660,70 +18688,82 @@ void Player::SetCanBlock( bool value ) UpdateBlockPercentage(); } -void Player::HandleFallDamage(MovementInfo& movementInfo) +bool ItemPosCount::isContainedIn(ItemPosCountVec const& vec) const { - //Players with Feather Fall or low fall time, or physical immunity (charges used) are ignored - if (!isInFlight() && movementInfo.fallTime > 1100 && !isDead() && !isGameMaster() && - !HasAuraType(SPELL_AURA_HOVER) && !HasAuraType(SPELL_AURA_FEATHER_FALL) && - !HasAuraType(SPELL_AURA_FLY) && !IsImmunedToDamage(SPELL_SCHOOL_MASK_NORMAL,true) ) - { - //Safe fall, fall time reduction - int32 safe_fall = GetTotalAuraModifier(SPELL_AURA_SAFE_FALL); - uint32 fall_time = (movementInfo.fallTime > (safe_fall*10)) ? movementInfo.fallTime - (safe_fall*10) : 0; - - if(fall_time > 1100) //Prevent damage if fall time < 1100 - { - //Fall Damage calculation - float fallperc = float(fall_time)/1100; - uint32 damage = (uint32)(((fallperc*fallperc -1) / 9 * GetMaxHealth())*sWorld.getRate(RATE_DAMAGE_FALL)); - - float height = movementInfo.z; - UpdateGroundPositionZ(movementInfo.x,movementInfo.y,height); - - if (damage > 0) - { - //Prevent fall damage from being more than the player maximum health - if (damage > GetMaxHealth()) - damage = GetMaxHealth(); - - // Gust of Wind - if (GetDummyAura(43621)) - damage = GetMaxHealth()/2; - - EnvironmentalDamage(GetGUID(), DAMAGE_FALL, damage); - } - - //Z given by moveinfo, LastZ, FallTime, WaterZ, MapZ, Damage, Safefall reduction - DEBUG_LOG("FALLDAMAGE z=%f sz=%f pZ=%f FallTime=%d mZ=%f damage=%d SF=%d" , movementInfo.z, height, GetPositionZ(), movementInfo.fallTime, height, damage, safe_fall); - } - } + for(ItemPosCountVec::const_iterator itr = vec.begin(); itr != vec.end();++itr) + if(itr->pos == pos) + return true; + return false; } -void Player::HandleFallUnderMap() -{ - if(InBattleGround() && GetBattleGround() - && GetBattleGround()->HandlePlayerUnderMap(this)) - { - // do nothing, the handle already did if returned true - } - else - { - // NOTE: this is actually called many times while falling - // even after the player has been teleported away - // TODO: discard movement packets after the player is rooted - if(isAlive()) - { - EnvironmentalDamage(GetGUID(),DAMAGE_FALL_TO_VOID, GetMaxHealth()); - // change the death state to CORPSE to prevent the death timer from - // starting in the next player update - KillPlayer(); - BuildPlayerRepop(); - } - - // cancel the death timer here if started - RepopAtGraveyard(); - } -} +//*********************************** +//-------------TRINITY--------------- +//*********************************** + +void Player::HandleFallDamage(MovementInfo& movementInfo) +{ + //Players with Feather Fall or low fall time, or physical immunity (charges used) are ignored + if (!isInFlight() && movementInfo.fallTime > 1100 && !isDead() && !isGameMaster() && + !HasAuraType(SPELL_AURA_HOVER) && !HasAuraType(SPELL_AURA_FEATHER_FALL) && + !HasAuraType(SPELL_AURA_FLY) && !IsImmunedToDamage(SPELL_SCHOOL_MASK_NORMAL,true) ) + { + //Safe fall, fall time reduction + int32 safe_fall = GetTotalAuraModifier(SPELL_AURA_SAFE_FALL); + uint32 fall_time = (movementInfo.fallTime > (safe_fall*10)) ? movementInfo.fallTime - (safe_fall*10) : 0; + + if(fall_time > 1100) //Prevent damage if fall time < 1100 + { + //Fall Damage calculation + float fallperc = float(fall_time)/1100; + uint32 damage = (uint32)(((fallperc*fallperc -1) / 9 * GetMaxHealth())*sWorld.getRate(RATE_DAMAGE_FALL)); + + float height = movementInfo.z; + UpdateGroundPositionZ(movementInfo.x,movementInfo.y,height); + + if (damage > 0) + { + //Prevent fall damage from being more than the player maximum health + if (damage > GetMaxHealth()) + damage = GetMaxHealth(); + + // Gust of Wind + if (GetDummyAura(43621)) + damage = GetMaxHealth()/2; + + EnvironmentalDamage(GetGUID(), DAMAGE_FALL, damage); + } + + //Z given by moveinfo, LastZ, FallTime, WaterZ, MapZ, Damage, Safefall reduction + DEBUG_LOG("FALLDAMAGE z=%f sz=%f pZ=%f FallTime=%d mZ=%f damage=%d SF=%d" , movementInfo.z, height, GetPositionZ(), movementInfo.fallTime, height, damage, safe_fall); + } + } +} + +void Player::HandleFallUnderMap() +{ + if(InBattleGround() && GetBattleGround() + && GetBattleGround()->HandlePlayerUnderMap(this)) + { + // do nothing, the handle already did if returned true + } + else + { + // NOTE: this is actually called many times while falling + // even after the player has been teleported away + // TODO: discard movement packets after the player is rooted + if(isAlive()) + { + EnvironmentalDamage(GetGUID(),DAMAGE_FALL_TO_VOID, GetMaxHealth()); + // change the death state to CORPSE to prevent the death timer from + // starting in the next player update + KillPlayer(); + BuildPlayerRepop(); + } + + // cancel the death timer here if started + RepopAtGraveyard(); + } +} void Player::Possess(Unit *target) { @@ -18961,15 +19001,6 @@ bool Player::isAllowUseBattleGroundObject() ); } -bool ItemPosCount::isContainedIn(ItemPosCountVec const& vec) const -{ - for(ItemPosCountVec::const_iterator itr = vec.begin(); itr != vec.end();++itr) - if(itr->pos == this->pos) - return true; - - return false; -} - bool Player::isTotalImmunity() { AuraList const& immune = GetAurasByType(SPELL_AURA_SCHOOL_IMMUNITY); diff --git a/src/game/Player.h b/src/game/Player.h index 4b92f8316d0..87f0ad11ae8 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _PLAYER_H @@ -33,6 +33,7 @@ #include "Bag.h" #include "WorldSession.h" #include "Pet.h" +#include "MapReference.h" #include "Util.h" // for Tokens typedef #include @@ -779,7 +780,7 @@ enum TeleportToOptions }; /// Type of environmental damages -enum EnvironmentalDamageType +enum EnviromentalDamage { DAMAGE_EXHAUSTED = 0, DAMAGE_DROWNING = 1, @@ -1124,7 +1125,7 @@ class TRINITY_DLL_SPEC Player : public Unit uint32 GetWeaponProficiency() const { return m_WeaponProficiency; } uint32 GetArmorProficiency() const { return m_ArmorProficiency; } bool IsInFeralForm() const { return m_form == FORM_CAT || m_form == FORM_BEAR || m_form == FORM_DIREBEAR; } - bool IsUseEquippedWeapon( bool mainhand ) const + bool IsUseEquipedWeapon( bool mainhand ) const { // disarm applied only to mainhand weapon return !IsInFeralForm() && (!mainhand || !HasFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_DISARMED) ); @@ -1306,7 +1307,7 @@ class TRINITY_DLL_SPEC Player : public Unit if(d < 0) SetMoney (GetMoney() > uint32(-d) ? GetMoney() + d : 0); else - SetMoney (GetMoney() < MAX_MONEY_AMOUNT - d ? GetMoney() + d : MAX_MONEY_AMOUNT); + SetMoney (GetMoney() < uint32(MAX_MONEY_AMOUNT - d) ? GetMoney() + d : MAX_MONEY_AMOUNT); // "At Gold Limit" if(GetMoney() >= MAX_MONEY_AMOUNT) @@ -1428,7 +1429,6 @@ class TRINITY_DLL_SPEC Player : public Unit PlayerSpellMap const& GetSpellMap() const { return m_spells; } PlayerSpellMap & GetSpellMap() { return m_spells; } - ActionButtonList const& GetActionButtonList() const { return m_actionButtons; } void AddSpellMod(SpellModifier* mod, bool apply); int32 GetTotalFlatMods(uint32 spellId, SpellModOp op); @@ -1518,8 +1518,8 @@ class TRINITY_DLL_SPEC Player : public Unit void RemoveFromGroup() { RemoveFromGroup(GetGroup(),GetGUID()); } void SendUpdateToOutOfRangeGroupMembers(); - void SetInGuild(uint32 GuildId) { SetUInt32Value(PLAYER_GUILDID, GuildId); Player::SetUInt32ValueInDB(PLAYER_GUILDID, GuildId, this->GetGUID()); } - void SetRank(uint32 rankId){ SetUInt32Value(PLAYER_GUILDRANK, rankId); Player::SetUInt32ValueInDB(PLAYER_GUILDRANK, rankId, this->GetGUID()); } + void SetInGuild(uint32 GuildId) { SetUInt32Value(PLAYER_GUILDID, GuildId); Player::SetUInt32ValueInDB(PLAYER_GUILDID, GuildId, GetGUID()); } + void SetRank(uint32 rankId){ SetUInt32Value(PLAYER_GUILDRANK, rankId); Player::SetUInt32ValueInDB(PLAYER_GUILDRANK, rankId, GetGUID()); } void SetGuildIdInvited(uint32 GuildId) { m_GuildIdInvited = GuildId; } uint32 GetGuildId() { return GetUInt32Value(PLAYER_GUILDID); } static uint32 GetGuildIdFromDB(uint64 guid); @@ -1532,7 +1532,7 @@ class TRINITY_DLL_SPEC Player : public Unit void SetInArenaTeam(uint32 ArenaTeamId, uint8 slot) { SetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6), ArenaTeamId); - SetUInt32ValueInDB(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6), ArenaTeamId, this->GetGUID()); + SetUInt32ValueInDB(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6), ArenaTeamId, GetGUID()); } uint32 GetArenaTeamId(uint8 slot) { return GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (slot * 6)); } static uint32 GetArenaTeamIdFromDB(uint64 guid, uint8 slot); @@ -1608,7 +1608,7 @@ class TRINITY_DLL_SPEC Player : public Unit void SendDelayResponse(const uint32); void SendLogXPGain(uint32 GivenXP,Unit* victim,uint32 RestXP); - //Low Level Packets + //Low Level Packets void PlaySound(uint32 Sound, bool OnlySelf); //notifiers void SendAttackSwingCantAttack(); @@ -1640,7 +1640,7 @@ class TRINITY_DLL_SPEC Player : public Unit void CreateCorpse(); void KillPlayer(); uint32 GetResurrectionSpellId(); - void ResurrectPlayer(float restore_percent, bool updateToWorld = true, bool applySickness = false); + void ResurrectPlayer(float restore_percent, bool applySickness = false); void BuildPlayerRepop(); void RepopAtGraveyard(); @@ -1762,14 +1762,14 @@ class TRINITY_DLL_SPEC Player : public Unit void SetRegularAttackTime(); void SetBaseModValue(BaseModGroup modGroup, BaseModType modType, float value) { m_auraBaseMod[modGroup][modType] = value; } - void HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, float amount, bool apply, bool affectStats = true); + void HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, float amount, bool apply); float GetBaseModValue(BaseModGroup modGroup, BaseModType modType) const; float GetTotalBaseModValue(BaseModGroup modGroup) const; float GetTotalPercentageModValue(BaseModGroup modGroup) const { return m_auraBaseMod[modGroup][FLAT_MOD] + m_auraBaseMod[modGroup][PCT_MOD]; } void _ApplyAllStatBonuses(); void _RemoveAllStatBonuses(); - void _ApplyWeaponDependentAuraMods(Item *item,WeaponAttackType attackType,bool apply); + void _ApplyWeaponDependentAuraMods(Item *item, WeaponAttackType attackType, bool apply); void _ApplyWeaponDependentAuraCritMod(Item *item, WeaponAttackType attackType, Aura* aura, bool apply); void _ApplyWeaponDependentAuraDamageMod(Item *item, WeaponAttackType attackType, Aura* aura, bool apply); @@ -1934,10 +1934,10 @@ class TRINITY_DLL_SPEC Player : public Unit void SetRestTime(uint32 v) { m_restTime = v;}; /*********************************************************/ - /*** ENVIRONMENTAL SYSTEM ***/ + /*** ENVIROMENTAL SYSTEM ***/ /*********************************************************/ - void EnvironmentalDamage(uint64 guid, EnvironmentalDamageType type, uint32 damage); + void EnvironmentalDamage(uint64 guid, EnviromentalDamage type, uint32 damage); /*********************************************************/ /*** FLOOD FILTER SYSTEM ***/ @@ -2062,6 +2062,8 @@ class TRINITY_DLL_SPEC Player : public Unit Player* GetNextRandomRaidMember(float radius); GridReference &GetGridRef() { return m_gridRef; } + MapReference &GetMapRef() { return m_mapRef; } + bool isAllowedToLoot(Creature* creature); WorldLocation& GetTeleportDest() { return m_teleport_dest; } @@ -2307,6 +2309,7 @@ class TRINITY_DLL_SPEC Player : public Unit Item* _StoreItem( uint16 pos, Item *pItem, uint32 count, bool clone, bool update ); GridReference m_gridRef; + MapReference m_mapRef; }; void AddItemsSetItem(Player*player,Item *item); diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 37c02fb549d..55203554665 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -170,10 +170,10 @@ pAuraHandler AuraHandler[TOTAL_AURAS]= &Aura::HandleNoImmediateEffect, //112 SPELL_AURA_OVERRIDE_CLASS_SCRIPTS &Aura::HandleNoImmediateEffect, //113 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN implemented in Unit::MeleeDamageBonus &Aura::HandleNoImmediateEffect, //114 SPELL_AURA_MOD_RANGED_DAMAGE_TAKEN_PCT implemented in Unit::MeleeDamageBonus - &Aura::HandleAuraHealing, //115 SPELL_AURA_MOD_HEALING + &Aura::HandleNoImmediateEffect, //115 SPELL_AURA_MOD_HEALING implemented in Unit::SpellBaseHealingBonusForVictim &Aura::HandleNoImmediateEffect, //116 SPELL_AURA_MOD_REGEN_DURING_COMBAT &Aura::HandleNoImmediateEffect, //117 SPELL_AURA_MOD_MECHANIC_RESISTANCE implemented in Unit::MagicSpellHitResult - &Aura::HandleAuraHealingPct, //118 SPELL_AURA_MOD_HEALING_PCT + &Aura::HandleNoImmediateEffect, //118 SPELL_AURA_MOD_HEALING_PCT implemented in Unit::SpellHealingBonus &Aura::HandleUnused, //119 SPELL_AURA_SHARE_PET_TRACKING useless &Aura::HandleAuraUntrackable, //120 SPELL_AURA_UNTRACKABLE &Aura::HandleAuraEmpathy, //121 SPELL_AURA_EMPATHY @@ -191,7 +191,7 @@ pAuraHandler AuraHandler[TOTAL_AURAS]= &Aura::HandleAuraModIncreaseHealthPercent, //133 SPELL_AURA_MOD_INCREASE_HEALTH_PERCENT &Aura::HandleAuraModRegenInterrupt, //134 SPELL_AURA_MOD_MANA_REGEN_INTERRUPT &Aura::HandleModHealingDone, //135 SPELL_AURA_MOD_HEALING_DONE - &Aura::HandleAuraHealingPct, //136 SPELL_AURA_MOD_HEALING_DONE_PERCENT implemented in Unit::SpellHealingBonus + &Aura::HandleNoImmediateEffect, //136 SPELL_AURA_MOD_HEALING_DONE_PERCENT implemented in Unit::SpellHealingBonus &Aura::HandleModTotalPercentStat, //137 SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE &Aura::HandleHaste, //138 SPELL_AURA_MOD_HASTE &Aura::HandleForceReaction, //139 SPELL_AURA_FORCE_REACTION @@ -220,7 +220,7 @@ pAuraHandler AuraHandler[TOTAL_AURAS]= &Aura::HandleAuraPowerBurn, //162 SPELL_AURA_POWER_BURN_MANA &Aura::HandleNoImmediateEffect, //163 SPELL_AURA_MOD_CRIT_DAMAGE_BONUS_MELEE &Aura::HandleUnused, //164 useless, only one test spell - &Aura::HandleAuraAttackPowerAttacker, //165 SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus + &Aura::HandleNoImmediateEffect, //165 SPELL_AURA_MELEE_ATTACK_POWER_ATTACKER_BONUS implemented in Unit::MeleeDamageBonus &Aura::HandleAuraModAttackPowerPercent, //166 SPELL_AURA_MOD_ATTACK_POWER_PCT &Aura::HandleAuraModRangedAttackPowerPercent, //167 SPELL_AURA_MOD_RANGED_ATTACK_POWER_PCT &Aura::HandleNoImmediateEffect, //168 SPELL_AURA_MOD_DAMAGE_DONE_VERSUS implemented in Unit::SpellDamageBonus, Unit::MeleeDamageBonus @@ -1999,6 +1999,16 @@ void Aura::HandleAuraDummy(bool apply, bool Real) return; } + // Waiting to Resurrect + if(GetId()==2584) + { + // Waiting to resurrect spell cancel, we must remove player from resurrect queue + if(m_target->GetTypeId() == TYPEID_PLAYER) + if(BattleGround *bg = ((Player*)m_target)->GetBattleGround()) + bg->RemovePlayerFromResurrectQueue(m_target->GetGUID()); + return; + } + // Dark Fiend if(GetId()==45934) { @@ -2294,6 +2304,10 @@ void Aura::HandleAuraPeriodicDummy(bool apply, bool Real) void Aura::HandleAuraMounted(bool apply, bool Real) { + // only at real add/remove aura + if(!Real) + return; + if(apply) { CreatureInfo const* ci = objmgr.GetCreatureTemplate(m_modifier.m_miscvalue); @@ -2693,7 +2707,9 @@ void Aura::HandleAuraTransform(bool apply, bool Real) } else { - if (uint32 modelid = ci->GetRandomValidModelId()) m_target->SetDisplayId(modelid); + // Will use the default model here + if (uint32 modelid = ci->GetRandomValidModelId()) + m_target->SetDisplayId(modelid); // Dragonmaw Illusion (set mount model also) if(GetId()==42016 && m_target->GetMountID() && !m_target->GetAurasByType(SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED).empty()) @@ -3589,7 +3605,7 @@ void Aura::HandleModTaunt(bool apply, bool Real) /*********************************************************/ /*** MODIFY SPEED ***/ /*********************************************************/ -void Aura::HandleAuraModIncreaseSpeed(bool apply, bool Real) +void Aura::HandleAuraModIncreaseSpeed(bool /*apply*/, bool Real) { // all applied/removed only at real aura add/remove if(!Real) @@ -3598,7 +3614,7 @@ void Aura::HandleAuraModIncreaseSpeed(bool apply, bool Real) m_target->UpdateSpeed(MOVE_RUN, true); } -void Aura::HandleAuraModIncreaseMountedSpeed(bool apply, bool Real) +void Aura::HandleAuraModIncreaseMountedSpeed(bool /*apply*/, bool Real) { // all applied/removed only at real aura add/remove if(!Real) @@ -3637,7 +3653,7 @@ void Aura::HandleAuraModIncreaseFlightSpeed(bool apply, bool Real) m_target->UpdateSpeed(MOVE_FLY, true); } -void Aura::HandleAuraModIncreaseSwimSpeed(bool apply, bool Real) +void Aura::HandleAuraModIncreaseSwimSpeed(bool /*apply*/, bool Real) { // all applied/removed only at real aura add/remove if(!Real) @@ -3646,7 +3662,7 @@ void Aura::HandleAuraModIncreaseSwimSpeed(bool apply, bool Real) m_target->UpdateSpeed(MOVE_SWIM, true); } -void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real) +void Aura::HandleAuraModDecreaseSpeed(bool /*apply*/, bool Real) { // all applied/removed only at real aura add/remove if(!Real) @@ -3657,7 +3673,7 @@ void Aura::HandleAuraModDecreaseSpeed(bool apply, bool Real) m_target->UpdateSpeed(MOVE_FLY, true); } -void Aura::HandleAuraModUseNormalSpeed(bool apply, bool Real) +void Aura::HandleAuraModUseNormalSpeed(bool /*apply*/, bool Real) { // all applied/removed only at real aura add/remove if(!Real) @@ -4342,7 +4358,7 @@ void Aura::HandleModPercentStat(bool apply, bool Real) } } -void Aura::HandleModSpellDamagePercentFromStat(bool apply, bool Real) +void Aura::HandleModSpellDamagePercentFromStat(bool /*apply*/, bool Real) { if(m_target->GetTypeId() != TYPEID_PLAYER) return; @@ -4353,7 +4369,7 @@ void Aura::HandleModSpellDamagePercentFromStat(bool apply, bool Real) ((Player*)m_target)->UpdateSpellDamageAndHealingBonus(); } -void Aura::HandleModSpellHealingPercentFromStat(bool apply, bool Real) +void Aura::HandleModSpellHealingPercentFromStat(bool /*apply*/, bool Real) { if(m_target->GetTypeId() != TYPEID_PLAYER) return; @@ -4371,7 +4387,7 @@ void Aura::HandleAuraModDispelResist(bool apply, bool Real) m_target->CastSpell(m_target,44416,true,NULL,this,GetCasterGUID()); } -void Aura::HandleModSpellDamagePercentFromAttackPower(bool apply, bool Real) +void Aura::HandleModSpellDamagePercentFromAttackPower(bool /*apply*/, bool Real) { if(m_target->GetTypeId() != TYPEID_PLAYER) return; @@ -4382,7 +4398,7 @@ void Aura::HandleModSpellDamagePercentFromAttackPower(bool apply, bool Real) ((Player*)m_target)->UpdateSpellDamageAndHealingBonus(); } -void Aura::HandleModSpellHealingPercentFromAttackPower(bool apply, bool Real) +void Aura::HandleModSpellHealingPercentFromAttackPower(bool /*apply*/, bool Real) { if(m_target->GetTypeId() != TYPEID_PLAYER) return; @@ -4391,7 +4407,7 @@ void Aura::HandleModSpellHealingPercentFromAttackPower(bool apply, bool Real) ((Player*)m_target)->UpdateSpellDamageAndHealingBonus(); } -void Aura::HandleModHealingDone(bool apply, bool Real) +void Aura::HandleModHealingDone(bool /*apply*/, bool Real) { if(m_target->GetTypeId() != TYPEID_PLAYER) return; @@ -4431,7 +4447,7 @@ void Aura::HandleModTotalPercentStat(bool apply, bool Real) } } -void Aura::HandleAuraModResistenceOfStatPercent(bool apply, bool Real) +void Aura::HandleAuraModResistenceOfStatPercent(bool /*apply*/, bool Real) { if(m_target->GetTypeId() != TYPEID_PLAYER) return; @@ -4566,7 +4582,7 @@ void Aura::HandleModPowerRegen(bool apply, bool Real) // drinking ((Player*)m_target)->UpdateManaRegen(); } -void Aura::HandleModPowerRegenPCT(bool apply, bool Real) +void Aura::HandleModPowerRegenPCT(bool /*apply*/, bool Real) { // spells required only Real aura add/remove if(!Real) @@ -4580,7 +4596,7 @@ void Aura::HandleModPowerRegenPCT(bool apply, bool Real) ((Player*)m_target)->UpdateManaRegen(); } -void Aura::HandleModManaRegen(bool apply, bool Real) +void Aura::HandleModManaRegen(bool /*apply*/, bool Real) { // spells required only Real aura add/remove if(!Real) @@ -4667,7 +4683,7 @@ void Aura::HandleAuraModIncreaseHealthPercent(bool apply, bool Real) /*** FIGHT ***/ /********************************/ -void Aura::HandleAuraModParryPercent(bool apply, bool Real) +void Aura::HandleAuraModParryPercent(bool /*apply*/, bool Real) { if(m_target->GetTypeId()!=TYPEID_PLAYER) return; @@ -4675,7 +4691,7 @@ void Aura::HandleAuraModParryPercent(bool apply, bool Real) ((Player*)m_target)->UpdateParryPercentage(); } -void Aura::HandleAuraModDodgePercent(bool apply, bool Real) +void Aura::HandleAuraModDodgePercent(bool /*apply*/, bool Real) { if(m_target->GetTypeId()!=TYPEID_PLAYER) return; @@ -4684,7 +4700,7 @@ void Aura::HandleAuraModDodgePercent(bool apply, bool Real) //sLog.outError("BONUS DODGE CHANCE: + %f", float(m_modifier.m_amount)); } -void Aura::HandleAuraModBlockPercent(bool apply, bool Real) +void Aura::HandleAuraModBlockPercent(bool /*apply*/, bool Real) { if(m_target->GetTypeId()!=TYPEID_PLAYER) return; @@ -4693,7 +4709,7 @@ void Aura::HandleAuraModBlockPercent(bool apply, bool Real) //sLog.outError("BONUS BLOCK CHANCE: + %f", float(m_modifier.m_amount)); } -void Aura::HandleAuraModRegenInterrupt(bool apply, bool Real) +void Aura::HandleAuraModRegenInterrupt(bool /*apply*/, bool Real) { // spells required only Real aura add/remove if(!Real) @@ -4761,7 +4777,7 @@ void Aura::HandleModSpellCritChance(bool apply, bool Real) } } -void Aura::HandleModSpellCritChanceShool(bool apply, bool Real) +void Aura::HandleModSpellCritChanceShool(bool /*apply*/, bool Real) { // spells required only Real aura add/remove if(!Real) @@ -4843,39 +4859,6 @@ void Aura::HandleAuraModRangedAttackPower(bool apply, bool Real) m_target->HandleStatModifier(UNIT_MOD_ATTACK_POWER_RANGED, TOTAL_VALUE, float(m_modifier.m_amount), apply); } -void Aura::HandleAuraAttackPowerAttacker(bool apply, bool Real) -{ - // spells required only Real aura add/remove - if(!Real) - return; - Unit *caster = GetCaster(); - - if (!caster) - return; - - // Hunter's Mark - if (m_spellProto->SpellFamilyName == SPELLFAMILY_HUNTER && m_spellProto->SpellFamilyFlags & 0x0000000000000400LL) - { - // Check Improved Hunter's Mark bonus on caster - Unit::AuraList const& mOverrideClassScript = caster->GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for(Unit::AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i) - { - Modifier* mod = (*i)->GetModifier(); - // mproved Hunter's Mark script from 5236 to 5240 - if (mod->m_miscvalue >= 5236 && mod->m_miscvalue <= 5240) - { - // Get amount of ranged bonus for this spell.. - int32 ranged_bonus = caster->CalculateSpellDamage(m_spellProto, 1, m_spellProto->EffectBasePoints[1], m_target); - // Set melee attack power bonus % from ranged depends from Improved mask aura - m_modifier.m_amount = mod->m_amount * ranged_bonus / 100; - m_currentBasePoints = m_modifier.m_amount; - break; - } - } - return; - } -} - void Aura::HandleAuraModAttackPowerPercent(bool apply, bool Real) { //UNIT_FIELD_ATTACK_POWER_MULTIPLIER = multiplier - 1 @@ -5323,7 +5306,7 @@ void Aura::HandleForceMoveForward(bool apply, bool Real) m_target->RemoveFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FORCE_MOVE); } -void Aura::HandleAuraModExpertise(bool apply, bool Real) +void Aura::HandleAuraModExpertise(bool /*apply*/, bool Real) { if(m_target->GetTypeId() != TYPEID_PLAYER) return; @@ -5348,17 +5331,6 @@ void Aura::HandleModTargetResistance(bool apply, bool Real) m_target->ApplyModInt32Value(PLAYER_FIELD_MOD_TARGET_RESISTANCE,m_modifier.m_amount, apply); } -//HandleNoImmediateEffect auras implementation to support new stat system -void Aura::HandleAuraHealing(bool apply, bool Real) -{ - //m_target->HandleStatModifier(UNIT_MOD_HEALING, TOTAL_VALUE, float(m_modifier.m_amount), apply); -} - -void Aura::HandleAuraHealingPct(bool apply, bool Real) -{ - //m_target->HandleStatModifier(UNIT_MOD_HEALING, TOTAL_PCT, float(m_modifier.m_amount), apply); -} - void Aura::HandleShieldBlockValue(bool apply, bool Real) { BaseModType modType = FLAT_MOD; diff --git a/src/game/SpellAuras.h b/src/game/SpellAuras.h index e4fe29fbc60..d803d9ede13 100644 --- a/src/game/SpellAuras.h +++ b/src/game/SpellAuras.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITY_SPELLAURAS_H #define TRINITY_SPELLAURAS_H @@ -185,15 +185,12 @@ class TRINITY_DLL_SPEC Aura void HandleAuraAllowFlight(bool Apply, bool Real); void HandleModRating(bool apply, bool Real); void HandleModTargetResistance(bool apply, bool Real); - void HandleAuraAttackPowerAttacker(bool apply, bool Real); void HandleAuraModAttackPowerPercent(bool apply, bool Real); void HandleAuraModRangedAttackPowerPercent(bool apply, bool Real); void HandleAuraModRangedAttackPowerOfStatPercent(bool apply, bool Real); void HandleSpiritOfRedemption(bool apply, bool Real); - void HandleAuraHealingPct(bool apply, bool Real); void HandleModManaRegen(bool apply, bool Real); void HandleComprehendLanguage(bool apply, bool Real); - void HandleAuraHealing(bool apply, bool Real); void HandleShieldBlockValue(bool apply, bool Real); void HandleModSpellCritChanceShool(bool apply, bool Real); void HandleAuraRetainComboPoints(bool apply, bool Real); @@ -253,7 +250,7 @@ class TRINITY_DLL_SPEC Aura { uint8 slot = GetAuraSlot(); - // only aura inslot with charges and without stack limitation + // only aura in slot with charges and without stack limitation if (slot < MAX_AURAS && m_procCharges >= 1 && GetSpellProto()->StackAmount==0) SetAuraApplication(slot, m_procCharges - 1); } diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 2c663e90212..a492e06f5b1 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -1171,7 +1171,7 @@ void Spell::EffectDummy(uint32 i) //Converted Sentry Credit m_caster->CastSpell(m_caster, 45009, true); return; - } + } case 45030: // Impale Emissary { // Emissary of Hate Credit @@ -1274,7 +1274,7 @@ void Spell::EffectDummy(uint32 i) { //Polymorph Cast Visual Rank 1 const uint32 spell_list[6] = {32813, 32816, 32817, 32818, 32819, 32820}; - unitTarget->CastSpell( unitTarget, spell_list[urand(0, 5)], true); + unitTarget->CastSpell( unitTarget, spell_list[urand(0, 5)], true); } return; } @@ -2250,7 +2250,7 @@ void Spell::EffectPowerDrain(uint32 i) m_caster->ModifyPower(POWER_MANA,gain); //send log - m_caster->SendEnergizeSpellLog(m_caster, m_spellInfo->Id,gain,POWER_MANA,false); + m_caster->SendEnergizeSpellLog(m_caster, m_spellInfo->Id,gain,POWER_MANA); } } @@ -2266,7 +2266,7 @@ void Spell::EffectSendEvent(uint32 EffectIndex) case 23333: // Pickup Horde Flag /*do not uncomment . if(bg->GetTypeID()==BATTLEGROUND_WS) - bg->EventPlayerClickedOnFlag((Player*)m_caster, this->gameObjTarget); + bg->EventPlayerClickedOnFlag((Player*)m_caster, gameObjTarget); sLog.outDebug("Send Event Horde Flag Picked Up"); break; /* not used : @@ -2279,7 +2279,7 @@ void Spell::EffectSendEvent(uint32 EffectIndex) case 23335: // Pickup Alliance Flag /*do not uncomment ... (it will cause crash, because of null targetobject!) anyway this is a bad way to call that event, because it would cause recursion if(bg->GetTypeID()==BATTLEGROUND_WS) - bg->EventPlayerClickedOnFlag((Player*)m_caster, this->gameObjTarget); + bg->EventPlayerClickedOnFlag((Player*)m_caster, gameObjTarget); sLog.outDebug("Send Event Alliance Flag Picked Up"); break; /* not used : @@ -2290,18 +2290,18 @@ void Spell::EffectSendEvent(uint32 EffectIndex) break; case 23385: // Alliance Flag Returns if(bg->GetTypeID()==BATTLEGROUND_WS) - bg->EventPlayerClickedOnFlag((Player*)m_caster, this->gameObjTarget); + bg->EventPlayerClickedOnFlag((Player*)m_caster, gameObjTarget); sLog.outDebug("Alliance Flag Returned"); break; case 23386: // Horde Flag Returns if(bg->GetTypeID()==BATTLEGROUND_WS) - bg->EventPlayerClickedOnFlag((Player*)m_caster, this->gameObjTarget); + bg->EventPlayerClickedOnFlag((Player*)m_caster, gameObjTarget); sLog.outDebug("Horde Flag Returned"); break;*/ case 34976: /* if(bg->GetTypeID()==BATTLEGROUND_EY) - bg->EventPlayerClickedOnFlag((Player*)m_caster, this->gameObjTarget); + bg->EventPlayerClickedOnFlag((Player*)m_caster, gameObjTarget); */ break; default: @@ -2680,24 +2680,24 @@ void Spell::EffectEnergize(uint32 i) return; // Some level depends spells - int multiplier = 0; + int multiplier = 0; int level_diff = 0; switch (m_spellInfo->Id) { // Restore Energy case 9512: level_diff = m_caster->getLevel() - 40; - multiplier = 2; + multiplier = 2; break; // Blood Fury case 24571: level_diff = m_caster->getLevel() - 60; - multiplier = 10; + multiplier = 10; break; // Burst of Energy case 24532: level_diff = m_caster->getLevel() - 60; - multiplier = 4; + multiplier = 4; break; default: break; @@ -3759,7 +3759,7 @@ void Spell::EffectTeleUnitsFaceCaster(uint32 i) if(unitTarget->GetTypeId() == TYPEID_PLAYER) ((Player*)unitTarget)->TeleportTo(mapid, fx, fy, fz, -m_caster->GetOrientation(), TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET | (unitTarget==m_caster ? TELE_TO_SPELL : 0)); else - MapManager::Instance().GetMap(mapid, m_caster)->CreatureRelocation((Creature*)m_caster, fx, fy, fz, -m_caster->GetOrientation()); + m_caster->GetMap()->CreatureRelocation((Creature*)m_caster, fx, fy, fz, -m_caster->GetOrientation()); } void Spell::EffectLearnSkill(uint32 i) @@ -3780,13 +3780,13 @@ void Spell::EffectAddHonor(uint32 /*i*/) if(unitTarget->GetTypeId() != TYPEID_PLAYER) return; - sLog.outDebug("SpellEffect::AddHonor called for spell_id %u , that rewards %d honor points to player: %u", m_spellInfo->Id, this->damage, ((Player*)unitTarget)->GetGUIDLow()); + sLog.outDebug("SpellEffect::AddHonor called for spell_id %u , that rewards %d honor points to player: %u", m_spellInfo->Id, damage, ((Player*)unitTarget)->GetGUIDLow()); // TODO: find formula for honor reward based on player's level! // now fixed only for level 70 players: if (((Player*)unitTarget)->getLevel() == 70) - ((Player*)unitTarget)->RewardHonor(NULL, 1, this->damage); + ((Player*)unitTarget)->RewardHonor(NULL, 1, damage); } void Spell::EffectTradeSkill(uint32 /*i*/) @@ -4001,7 +4001,7 @@ void Spell::EffectTameCreature(uint32 /*i*/) pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()-1); // add to world - MapManager::Instance().GetMap(pet->GetMapId(), pet)->Add((Creature*)pet); + pet->GetMap()->Add((Creature*)pet); // visual effect for levelup pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()); @@ -4031,14 +4031,14 @@ void Spell::EffectSummonPet(uint32 i) if( OldSummon->isDead() ) return; - MapManager::Instance().GetMap(OldSummon->GetMapId(), OldSummon)->Remove((Creature*)OldSummon,false); + OldSummon->GetMap()->Remove((Creature*)OldSummon,false); OldSummon->SetMapId(m_caster->GetMapId()); float px, py, pz; m_caster->GetClosePoint(px, py, pz, OldSummon->GetObjectSize()); OldSummon->Relocate(px, py, pz, OldSummon->GetOrientation()); - MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)->Add((Creature*)OldSummon); + m_caster->GetMap()->Add((Creature*)OldSummon); if(m_caster->GetTypeId() == TYPEID_PLAYER && OldSummon->isControlled() ) { @@ -4121,10 +4121,10 @@ void Spell::EffectSummonPet(uint32 i) uint32 faction = m_caster->getFaction(); if(m_caster->GetTypeId() == TYPEID_UNIT) { - if ( ((Creature*)m_caster)->isTotem() ) - NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE); - else - NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE); + if ( ((Creature*)m_caster)->isTotem() ) + NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE); + else + NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE); } NewSummon->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, m_caster->GetGUID()); @@ -4446,6 +4446,7 @@ void Spell::EffectWeaponDmg(uint32 i) if(m_caster->GetTypeId()==TYPEID_PLAYER) ((Player*)m_caster)->AddComboPoints(unitTarget, 1); } + // Mangle (Cat): CP if(m_spellInfo->SpellFamilyName==SPELLFAMILY_DRUID && (m_spellInfo->SpellFamilyFlags==0x0000040000000000LL)) { @@ -4453,7 +4454,6 @@ void Spell::EffectWeaponDmg(uint32 i) ((Player*)m_caster)->AddComboPoints(unitTarget,1); } - // take ammo if(m_attackType == RANGED_ATTACK && m_caster->GetTypeId() == TYPEID_PLAYER) { @@ -5448,7 +5448,7 @@ void Spell::EffectSummonObject(uint32 i) m_caster->m_ObjectSlot[slot] = pGameObj->GetGUID(); } -void Spell::EffectResurrect(uint32 i) +void Spell::EffectResurrect(uint32 /*effIndex*/) { if(!unitTarget) return; @@ -5669,7 +5669,7 @@ void Spell::EffectSkinning(uint32 /*i*/) Creature* creature = (Creature*) unitTarget; int32 targetLevel = creature->getLevel(); - uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill(); + uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill(); ((Player*)m_caster)->SendLoot(creature->GetGUID(),LOOT_SKINNING); creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); @@ -5696,7 +5696,7 @@ void Spell::EffectCharge(uint32 /*i*/) m_caster->SendMonsterMove(x, y, z, 0, MOVEMENTFLAG_WALK_MODE, 1); if(m_caster->GetTypeId() != TYPEID_PLAYER) - MapManager::Instance().GetMap(m_caster->GetMapId(), m_caster)->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation()); + m_caster->GetMap()->CreatureRelocation((Creature*)m_caster,x,y,z,m_caster->GetOrientation()); // not all charge effects used in negative spells if ( !IsPositiveSpell(m_spellInfo->Id)) @@ -6132,7 +6132,7 @@ void Spell::EffectTransmitted(uint32 effIndex) linkedGO->SetSpellId(m_spellInfo->Id); linkedGO->SetOwnerGUID(m_caster->GetGUID() ); - MapManager::Instance().GetMap(linkedGO->GetMapId(), linkedGO)->Add(linkedGO); + linkedGO->GetMap()->Add(linkedGO); } else { diff --git a/src/game/StatSystem.cpp b/src/game/StatSystem.cpp index 0e766136696..3533c5c8a02 100644 --- a/src/game/StatSystem.cpp +++ b/src/game/StatSystem.cpp @@ -384,7 +384,7 @@ void Player::CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, fl weapon_mindamage = lvl*0.85*att_speed; weapon_maxdamage = lvl*1.25*att_speed; } - else if(!IsUseEquippedWeapon(attType==BASE_ATTACK)) //check if player not in form but still can't use weapon (broken/etc) + else if(!IsUseEquipedWeapon(attType==BASE_ATTACK)) //check if player not in form but still can't use weapon (broken/etc) { weapon_mindamage = BASE_MINDAMAGE; weapon_maxdamage = BASE_MAXDAMAGE; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index a6dae99b7ef..a78f1ca2c29 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -1148,8 +1148,6 @@ void Unit::DealFlatDamage(Unit *pVictim, SpellEntry const *spellInfo, uint32 *da // Physical Damage if ( GetSpellSchoolMask(spellInfo) & SPELL_SCHOOL_MASK_NORMAL ) { - uint32 modDamage=*damage; - // apply spellmod to Done damage if(Player* modOwner = GetSpellModOwner()) modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_DAMAGE, *damage); @@ -1434,7 +1432,7 @@ uint32 Unit::SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage { if(!this || !pVictim) return 0; - if(!this->isAlive() || !pVictim->isAlive()) + if(!isAlive() || !pVictim->isAlive()) return 0; SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellID); @@ -4127,12 +4125,17 @@ void Unit::RemoveNotOwnSingleTargetAuras() void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) { - if (IsSingleTargetSpell((*i).second->GetSpellProto())) + Aura* Aur = i->second; + SpellEntry const* AurSpellInfo = Aur->GetSpellProto(); + + Unit* caster = NULL; + if (IsSingleTargetSpell(AurSpellInfo)) { - if(Unit* caster = (*i).second->GetCaster()) + caster = Aur->GetCaster(); + if(caster) { AuraList& scAuras = caster->GetSingleCastAuras(); - scAuras.remove((*i).second); + scAuras.remove(Aur); } else { @@ -4141,7 +4144,8 @@ void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) } } - if ((*i).second->GetModifier()->m_auraname < TOTAL_AURAS) + // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) + if (Aur->GetModifier()->m_auraname < TOTAL_AURAS) { m_modAuras[(*i).second->GetModifier()->m_auraname].remove((*i).second); if((*i).second->GetSpellProto()->AuraInterruptFlags) @@ -4153,8 +4157,6 @@ void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) m_ccAuras.remove((*i).second); } - // remove from list before mods removing (prevent cyclic calls, mods added before including to aura list - use reverse order) - Aura* Aur = i->second; // Set remove mode Aur->SetRemoveMode(mode); // some ShapeshiftBoosts at remove trigger removing other auras including parent Shapeshift aura @@ -4162,13 +4164,22 @@ void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) m_Auras.erase(i); ++m_removedAuras; // internal count used by unit update - // Status unsummoned at aura remove + // Statue unsummoned at aura remove Totem* statue = NULL; - if(IsChanneledSpell(Aur->GetSpellProto())) - if(Unit* caster = Aur->GetCaster()) + bool caster_channeled = false; + if(IsChanneledSpell(AurSpellInfo)) + { + if(!caster) // can be already located for IsSingleTargetSpell case + caster = Aur->GetCaster(); + + if(caster) + { if(caster->GetTypeId()==TYPEID_UNIT && ((Creature*)caster)->isTotem() && ((Totem*)caster)->GetTotemType()==TOTEM_STATUE) statue = ((Totem*)caster); - + else + caster_channeled = caster==this; + } + } if(const std::vector *spell_triggered = spellmgr.GetSpellLinked(-(int32)Aur->GetSpellProto()->Id)) { @@ -4186,6 +4197,9 @@ void Unit::RemoveAura(AuraMap::iterator &i, AuraRemoveMode mode) Aur->_RemoveAura(); delete Aur; + if(caster_channeled) + RemoveAurasAtChanneledTarget (AurSpellInfo); + if(statue) statue->UnSummon(); @@ -4611,8 +4625,10 @@ void Unit::CastMeleeProcDamageAndSpell(Unit* pVictim, uint32 damage, SpellSchool ProcDamageAndSpell(pVictim, procAttacker, procVictim, damage, damageSchoolMask, spellCasted, isTriggeredSpell, attType); } -bool Unit::HandleHasteAuraProc(Unit *pVictim, SpellEntry const *hasteSpell, uint32 /*effIndex*/, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 /*procFlag*/, uint32 cooldown) +bool Unit::HandleHasteAuraProc(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const * /*procSpell*/, uint32 /*procFlag*/, uint32 cooldown) { + SpellEntry const *hasteSpell = triggeredByAura->GetSpellProto(); + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; @@ -4672,8 +4688,11 @@ bool Unit::HandleHasteAuraProc(Unit *pVictim, SpellEntry const *hasteSpell, uint return true; } -bool Unit::HandleDummyAuraProc(Unit *pVictim, SpellEntry const *dummySpell, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) +bool Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag, uint32 cooldown) { + SpellEntry const *dummySpell = triggeredByAura->GetSpellProto (); + uint32 effIndex = triggeredByAura->GetEffIndex (); + Item* castItem = triggeredByAura->GetCastItemGUID() && GetTypeId()==TYPEID_PLAYER ? ((Player*)this)->GetItemByGuid(triggeredByAura->GetCastItemGUID()) : NULL; @@ -6261,7 +6280,6 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredB if(!pVictim || !pVictim->isAlive()) return false; - uint32 spell = 0; switch(triggeredByAura->GetSpellProto()->Id) { case 20186: @@ -6291,7 +6309,6 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredB return false; // overwrite non existing triggered spell call in spell.dbc - uint32 spell = 0; switch(triggeredByAura->GetSpellProto()->Id) { case 20185: @@ -6491,8 +6508,10 @@ bool Unit::HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredB return true; } -bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) +bool Unit::HandleOverrideClassScriptAuraProc(Unit *pVictim, Aura *triggeredByAura, SpellEntry const *procSpell, uint32 cooldown) { + int32 scriptId = triggeredByAura->GetModifier()->m_miscvalue; + if(!pVictim || !pVictim->isAlive()) return false; @@ -7258,7 +7277,7 @@ void Unit::SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool c SendMessageToSet(&data, true); } -void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype, bool critical) +void Unit::SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, Powers powertype) { WorldPacket data(SMSG_SPELLENERGIZELOG, (8+8+4+4+4+1)); data.append(pVictim->GetPackGUID()); @@ -7358,7 +7377,7 @@ uint32 Unit::SpellDamageBonus(Unit *pVictim, SpellEntry const *spellProto, uint3 // ..taken AuraList const& mModDamagePercentTaken = pVictim->GetAurasByType(SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN); for(AuraList::const_iterator i = mModDamagePercentTaken.begin(); i != mModDamagePercentTaken.end(); ++i) - if((*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto)) + if( (*i)->GetModifier()->m_miscvalue & GetSpellSchoolMask(spellProto) ) TakenTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; // .. taken pct: scripted (increases damage of * against targets *) @@ -8206,7 +8225,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage,WeaponAttackType attT int32 TakenFlatBenefit = 0; // ..done (for creature type by mask) in taken - AuraList const& mDamageDoneCreature = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); + AuraList const& mDamageDoneCreature = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_CREATURE); for(AuraList::const_iterator i = mDamageDoneCreature.begin();i != mDamageDoneCreature.end(); ++i) if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) DoneFlatBenefit += (*i)->GetModifier()->m_amount; @@ -8274,7 +8293,7 @@ void Unit::MeleeDamageBonus(Unit *pVictim, uint32 *pdamage,WeaponAttackType attT // SPELL_AURA_MOD_DAMAGE_PERCENT_DONE included in weapon damage // SPELL_AURA_MOD_OFFHAND_DAMAGE_PCT included in weapon damage - AuraList const& mDamageDoneVersus = this->GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); + AuraList const& mDamageDoneVersus = GetAurasByType(SPELL_AURA_MOD_DAMAGE_DONE_VERSUS); for(AuraList::const_iterator i = mDamageDoneVersus.begin();i != mDamageDoneVersus.end(); ++i) if(creatureTypeMask & uint32((*i)->GetModifier()->m_miscvalue)) DoneTotalMod *= ((*i)->GetModifier()->m_amount+100.0f)/100.0f; @@ -8729,7 +8748,7 @@ void Unit::SetVisibility(UnitVisibility x) if(IsInWorld()) { - Map *m = MapManager::Instance().GetMap(GetMapId(), this); + Map *m = GetMap(); if(GetTypeId()==TYPEID_PLAYER) m->PlayerRelocation((Player*)this,GetPositionX(),GetPositionY(),GetPositionZ(),GetOrientation()); @@ -9791,8 +9810,6 @@ void Unit::CleanupsBeforeDelete() RemoveFromWorld(); } - - CharmInfo* Unit::InitCharmInfo(Unit *charm) { if(!m_charmInfo) @@ -9956,17 +9973,15 @@ bool Unit::isFrozen() const struct ProcTriggeredData { - ProcTriggeredData(SpellEntry const * _spellInfo, uint32 _spellParam, Aura* _triggeredByAura, uint32 _cooldown) - : spellInfo(_spellInfo), spellParam(_spellParam), triggeredByAura(_triggeredByAura), + ProcTriggeredData(Aura* _triggeredByAura, uint32 _cooldown) + : triggeredByAura(_triggeredByAura), triggeredByAura_SpellPair(Unit::spellEffectPair(triggeredByAura->GetId(),triggeredByAura->GetEffIndex())), cooldown(_cooldown) - {} + {} - SpellEntry const * spellInfo; - uint32 spellParam; - Aura* triggeredByAura; - Unit::spellEffectPair triggeredByAura_SpellPair; - uint32 cooldown; + Aura* triggeredByAura; // triggred aura, can be invalidate at triggered aura proccessing + Unit::spellEffectPair triggeredByAura_SpellPair; // spell pair, used for re-find aura (by pointer comparison in range) + uint32 cooldown; // possible hidden cooldown }; typedef std::list< ProcTriggeredData > ProcTriggeredList; @@ -9983,87 +9998,13 @@ void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag { next = i; ++next; - SpellEntry const *spellProto = (*i)->GetSpellProto(); - if(!spellProto) - continue; + Aura* i_aura = *i; - SpellProcEventEntry const *spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); - if(!spellProcEvent) - { - // used to prevent spam in log about same non-handled spells - static std::set nonHandledSpellProcSet; - - if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) - { - sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); - nonHandledSpellProcSet.insert(spellProto->Id); - } - - // spell.dbc use totally different flags, that only can create problems if used. - continue; - } - - // Check spellProcEvent data requirements - if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) + uint32 cooldown; // returned at next line + if(!IsTriggeredAtSpellProcEvent(i_aura->GetSpellProto(), procSpell, procFlag,attType,isVictim,cooldown)) continue; - // Check if current equipment allows aura to proc - if(!isVictim && GetTypeId() == TYPEID_PLAYER ) - { - if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) - { - Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); - - if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) - continue; - } - else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) - { - // Check if player is wearing shield - Item *item = ((Player*)this)->GetShield(true); - if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) - continue; - } - } - - float chance = (float)spellProto->procChance; - - if(Player* modOwner = GetSpellModOwner()) - modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); - - if(!isVictim && spellProcEvent->ppmRate != 0) - { - uint32 WeaponSpeed = GetAttackTime(attType); - chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); - } - - if(roll_chance_f(chance)) - { - uint32 cooldown = spellProcEvent->cooldown; - - uint32 i_spell_eff = (*i)->GetEffIndex(); - - int32 i_spell_param; - switch(*aur) - { - case SPELL_AURA_PROC_TRIGGER_SPELL: - i_spell_param = procFlag; - break; - case SPELL_AURA_DUMMY: - case SPELL_AURA_PRAYER_OF_MENDING: - case SPELL_AURA_MOD_HASTE: - i_spell_param = i_spell_eff; - break; - case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: - i_spell_param = (*i)->GetModifier()->m_miscvalue; - break; - default: - i_spell_param = (*i)->GetModifier()->m_amount; - break; - } - - procTriggered.push_back( ProcTriggeredData(spellProto,i_spell_param,*i, cooldown) ); - } + procTriggered.push_back( ProcTriggeredData(i_aura, cooldown) ); } // Handle effects proceed this time @@ -10096,106 +10037,71 @@ void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag } } - // save charges existence before processing to prevent crash at access to deleted triggered aura after - bool triggeredByAuraWithCharges = i->triggeredByAura->m_procCharges > 0; + /// this is aura triggering code call + Aura* triggeredByAura = i->triggeredByAura; + /// save charges existence before processing to prevent crash at access to deleted triggered aura after + /// used in speedup code check before check aura existance. + bool triggeredByAuraWithCharges = triggeredByAura->m_procCharges > 0; + + /// success in event proccesing + /// used in speedup code check before check aura existance. bool casted = false; + + /// process triggered code switch(*aur) { case SPELL_AURA_PROC_TRIGGER_SPELL: { - sLog.outDebug("ProcDamageAndSpell: casting spell %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleProcTriggerSpell(pTarget, damage, i->triggeredByAura, procSpell,i->spellParam,attType,i->cooldown); + sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s proc aura of spell %u)", + (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); + casted = HandleProcTriggerSpell(pTarget, damage, triggeredByAura, procSpell, procFlag, attType, i->cooldown); break; } case SPELL_AURA_PROC_TRIGGER_DAMAGE: { - sLog.outDebug("ProcDamageAndSpell: doing %u damage from spell id %u (triggered by %s aura of spell %u)", i->spellParam, i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - uint32 damage = i->spellParam; - SpellNonMeleeDamageLog(pTarget, i->spellInfo->Id, damage, true, true); + uint32 triggered_damage = triggeredByAura->GetModifier()->m_amount; + sLog.outDebug("ProcDamageAndSpell: doing %u damage (triggered by %s aura of spell %u)", + triggered_damage, (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); + SpellNonMeleeDamageLog(pTarget, triggeredByAura->GetId(), triggered_damage, true, true); casted = true; break; } case SPELL_AURA_DUMMY: { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleDummyAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); + uint32 effect = triggeredByAura->GetEffIndex(); + sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s dummy aura of spell %u)", + (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); + casted = HandleDummyAuraProc(pTarget, damage, triggeredByAura, procSpell, procFlag,i->cooldown); break; } case SPELL_AURA_PRAYER_OF_MENDING: { - sLog.outDebug("ProcDamageAndSpell(mending): casting spell id %u (triggered by %s dummy aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - - // aura can be deleted at casts - int32 heal = i->triggeredByAura->GetModifier()->m_amount; - uint64 caster_guid = i->triggeredByAura->GetCasterGUID(); - - // jumps - int32 jumps = i->triggeredByAura->m_procCharges-1; - - // current aura expire - i->triggeredByAura->m_procCharges = 1; // will removed at next charges decrease - - // next target selection - if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) - { - Aura* aura = i->triggeredByAura; - - SpellEntry const* spellProto = aura->GetSpellProto(); - uint32 effIdx = aura->GetEffIndex(); - - float radius; - if (spellProto->EffectRadiusIndex[effIdx]) - radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); - else - radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); - - if(Player* caster = ((Player*)aura->GetCaster())) - { - caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); + sLog.outDebug("ProcDamageAndSpell: casting mending (triggered by %s dummy aura of spell %u)", + (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); - if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) - { - // aura will applied from caster, but spell casted from current aura holder - SpellModifier *mod = new SpellModifier; - mod->op = SPELLMOD_CHARGES; - mod->value = jumps-5; // negative - mod->type = SPELLMOD_FLAT; - mod->spellId = spellProto->Id; - mod->effectId = effIdx; - mod->lastAffected = NULL; - mod->mask = spellProto->SpellFamilyFlags; - mod->charges = 0; - - caster->AddSpellMod(mod, true); - CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,aura,caster->GetGUID()); - caster->AddSpellMod(mod, false); - } - } - } - - // heal - CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); - casted = true; + casted = HandleMeandingAuraProc(triggeredByAura); break; } case SPELL_AURA_MOD_HASTE: { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s haste aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleHasteAuraProc(pTarget, i->spellInfo, i->spellParam, damage, i->triggeredByAura, procSpell, procFlag,i->cooldown); + sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s haste aura of spell %u)", + (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); + casted = HandleHasteAuraProc(pTarget, damage, triggeredByAura, procSpell, procFlag,i->cooldown); break; } case SPELL_AURA_MOD_DAMAGE_PERCENT_TAKEN: { // nothing do, just charges counter // but count only in case appropriate school damage - casted = i->triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; + casted = triggeredByAura->GetModifier()->m_miscvalue & damageSchoolMask; break; } case SPELL_AURA_OVERRIDE_CLASS_SCRIPTS: { - sLog.outDebug("ProcDamageAndSpell: casting spell id %u (triggered by %s aura of spell %u)", i->spellInfo->Id,(isVictim?"a victim's":"an attacker's"),i->triggeredByAura->GetId()); - casted = HandleOverrideClassScriptAuraProc(pTarget, i->spellParam, damage, i->triggeredByAura, procSpell,i->cooldown); + sLog.outDebug("ProcDamageAndSpell: casting spell (triggered by %s class script aura of spell %u)", + (isVictim?"a victim's":"an attacker's"),triggeredByAura->GetId()); + casted = HandleOverrideClassScriptAuraProc(pTarget, triggeredByAura, procSpell,i->cooldown); break; } default: @@ -10206,27 +10112,27 @@ void Unit::ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag } } - // Update charge (aura can be removed by triggers) + /// Update charge (aura can be removed by triggers) if(casted && triggeredByAuraWithCharges) { - // need found aura (can be dropped by triggers) + /// need re-found aura (can be dropped by triggers) AuraMap::const_iterator lower = GetAuras().lower_bound(i->triggeredByAura_SpellPair); AuraMap::const_iterator upper = GetAuras().upper_bound(i->triggeredByAura_SpellPair); for(AuraMap::const_iterator itr = lower; itr!= upper; ++itr) { - if(itr->second == i->triggeredByAura) + if(itr->second == triggeredByAura) // pointer still valid { - if(i->triggeredByAura->m_procCharges > 0) - i->triggeredByAura->m_procCharges -= 1; + if(triggeredByAura->m_procCharges > 0) + triggeredByAura->m_procCharges -= 1; - i->triggeredByAura->UpdateAuraCharges(); + triggeredByAura->UpdateAuraCharges(); break; } } } } - // Safely remove auras with zero charges + /// Safely remove auras with zero charges for(AuraList::const_iterator i = auras.begin(), next; i != auras.end(); i = next) { next = i; ++next; @@ -10339,7 +10245,7 @@ void Unit::StopMoving() // send explicit stop packet // rely on vmaps here because for example stormwind is in air - float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); + //float z = MapManager::Instance().GetBaseMap(GetMapId())->GetHeight(GetPositionX(), GetPositionY(), GetPositionZ(), true); //if (fabs(GetPositionZ() - z) < 2.0f) // Relocate(GetPositionX(), GetPositionY(), z); Relocate(GetPositionX(), GetPositionY(),GetPositionZ()); @@ -10823,9 +10729,9 @@ Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id) return NULL; } - pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, this->GetGUID()); - pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, this->GetGUID()); - pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,this->getFaction()); + pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, GetGUID()); + pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, GetGUID()); + pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,getFaction()); pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id); if(!pet->InitStatsForLevel(creatureTarget->getLevel())) @@ -10843,3 +10749,132 @@ Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id) return pet; } + +bool Unit::IsTriggeredAtSpellProcEvent(SpellEntry const* spellProto, SpellEntry const* procSpell, uint32 procFlag, WeaponAttackType attType, bool isVictim, uint32& cooldown ) +{ + SpellProcEventEntry const * spellProcEvent = spellmgr.GetSpellProcEvent(spellProto->Id); + + if(!spellProcEvent) + { + // used to prevent spam in log about same non-handled spells + static std::set nonHandledSpellProcSet; + + if(spellProto->procFlags != 0 && nonHandledSpellProcSet.find(spellProto->Id)==nonHandledSpellProcSet.end()) + { + sLog.outError("ProcDamageAndSpell: spell %u (%s aura source) not have record in `spell_proc_event`)",spellProto->Id,(isVictim?"a victim's":"an attacker's")); + nonHandledSpellProcSet.insert(spellProto->Id); + } + + // spell.dbc use totally different flags, that only can create problems if used. + return false; + } + + // Check spellProcEvent data requirements + if(!SpellMgr::IsSpellProcEventCanTriggeredBy(spellProcEvent, procSpell,procFlag)) + return false; + + // Check if current equipment allows aura to proc + if(!isVictim && GetTypeId() == TYPEID_PLAYER ) + { + if(spellProto->EquippedItemClass == ITEM_CLASS_WEAPON) + { + Item *item = ((Player*)this)->GetWeaponForAttack(attType,true); + + if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) + return false; + } + else if(spellProto->EquippedItemClass == ITEM_CLASS_ARMOR) + { + // Check if player is wearing shield + Item *item = ((Player*)this)->GetShield(true); + if(!item || !((1<GetProto()->SubClass) & spellProto->EquippedItemSubClassMask)) + return false; + } + } + + float chance = (float)spellProto->procChance; + + if(Player* modOwner = GetSpellModOwner()) + modOwner->ApplySpellMod(spellProto->Id,SPELLMOD_CHANCE_OF_SUCCESS,chance); + + if(!isVictim && spellProcEvent && spellProcEvent->ppmRate != 0) + { + uint32 WeaponSpeed = GetAttackTime(attType); + chance = GetPPMProcChance(WeaponSpeed, spellProcEvent->ppmRate); + } + + cooldown = spellProcEvent ? spellProcEvent->cooldown : 0; + return roll_chance_f(chance); +} + +bool Unit::HandleMeandingAuraProc( Aura* triggeredByAura ) +{ + // aura can be deleted at casts + SpellEntry const* spellProto = triggeredByAura->GetSpellProto(); + uint32 effIdx = triggeredByAura->GetEffIndex(); + int32 heal = triggeredByAura->GetModifier()->m_amount; + uint64 caster_guid = triggeredByAura->GetCasterGUID(); + + // jumps + int32 jumps = triggeredByAura->m_procCharges-1; + + // current aura expire + triggeredByAura->m_procCharges = 1; // will removed at next charges decrease + + // next target selection + if(jumps > 0 && GetTypeId()==TYPEID_PLAYER && IS_PLAYER_GUID(caster_guid)) + { + float radius; + if (spellProto->EffectRadiusIndex[effIdx]) + radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellProto->EffectRadiusIndex[effIdx])); + else + radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(spellProto->rangeIndex)); + + if(Player* caster = ((Player*)triggeredByAura->GetCaster())) + { + caster->ApplySpellMod(spellProto->Id, SPELLMOD_RADIUS, radius,NULL); + + if(Player* target = ((Player*)this)->GetNextRandomRaidMember(radius)) + { + // aura will applied from caster, but spell casted from current aura holder + SpellModifier *mod = new SpellModifier; + mod->op = SPELLMOD_CHARGES; + mod->value = jumps-5; // negative + mod->type = SPELLMOD_FLAT; + mod->spellId = spellProto->Id; + mod->effectId = effIdx; + mod->lastAffected = NULL; + mod->mask = spellProto->SpellFamilyFlags; + mod->charges = 0; + + caster->AddSpellMod(mod, true); + CastCustomSpell(target,spellProto->Id,&heal,NULL,NULL,true,NULL,triggeredByAura,caster->GetGUID()); + caster->AddSpellMod(mod, false); + } + } + } + + // heal + CastCustomSpell(this,33110,&heal,NULL,NULL,true,NULL,NULL,caster_guid); + return true; +} + +void Unit::RemoveAurasAtChanneledTarget(SpellEntry const* spellInfo) +{ + uint64 target_guid = GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT); + + if(!IS_UNIT_GUID(target_guid)) + return; + + Unit* target = ObjectAccessor::GetUnit(*this, target_guid); + if(!target) + return; + + for (AuraMap::iterator iter = target->GetAuras().begin(); iter != target->GetAuras().end(); ) + { + if (iter->second->GetId() == spellInfo->Id && iter->second->GetCasterGUID()==GetGUID()) + target->RemoveAura(iter); + else + ++iter; + } +} diff --git a/src/game/Unit.h b/src/game/Unit.h index 028c590c06f..4a5dc7e4bb9 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __UNIT_H @@ -933,7 +933,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject bool isInAccessiblePlaceFor(Creature const* c) const; void SendHealSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage, bool critical = false); - void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype, bool critical = false); + void SendEnergizeSpellLog(Unit *pVictim, uint32 SpellID, uint32 Damage,Powers powertype); uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell = false, bool useSpellDamage = true); void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0); void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0); @@ -1039,6 +1039,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject void RemoveAurasDueToSpellByDispel(uint32 spellId, uint64 casterGUID, Unit *dispeler); void RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit *stealer); void RemoveAurasDueToSpellByCancel(uint32 spellId); + void RemoveAurasAtChanneledTarget(SpellEntry const* spellInfo); void RemoveNotOwnSingleTargetAuras(); void RemoveSpellsCausingAura(AuraType auraType); @@ -1370,10 +1371,12 @@ class TRINITY_DLL_SPEC Unit : public WorldObject //void SendAttackStart(Unit* pVictim); // only from Unit::AttackStart(Unit*) void ProcDamageAndSpellFor( bool isVictim, Unit * pTarget, uint32 procFlag, AuraTypeSet const& procAuraTypes, WeaponAttackType attType, SpellEntry const * procSpell, uint32 damage, SpellSchoolMask damageSchoolMask ); - bool HandleDummyAuraProc(Unit *pVictim, SpellEntry const *spellProto, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag,uint32 cooldown); - bool HandleProcTriggerSpell(Unit *pVictim,uint32 damage, Aura* triggeredByAura, SpellEntry const *procSpell, uint32 procFlags,WeaponAttackType attType,uint32 cooldown); - bool HandleHasteAuraProc(Unit *pVictim, SpellEntry const *spellProto, uint32 effIndex, uint32 damage, Aura* triggeredByAura, SpellEntry const * procSpell, uint32 procFlag,uint32 cooldown); - bool HandleOverrideClassScriptAuraProc(Unit *pVictim, int32 scriptId, uint32 damage, Aura* triggeredByAura, SpellEntry const *procSpell,uint32 cooldown); + bool IsTriggeredAtSpellProcEvent( SpellEntry const* spellProto, SpellEntry const* procSpell, uint32 procFlag, WeaponAttackType attType, bool isVictim, uint32& cooldown ); + bool HandleDummyAuraProc( Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const* procSpell, uint32 procFlag, uint32 cooldown); + bool HandleProcTriggerSpell(Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const* procSpell, uint32 procFlag, WeaponAttackType attType, uint32 cooldown); + bool HandleHasteAuraProc( Unit *pVictim, uint32 damage, Aura* triggeredByAura, SpellEntry const* procSpell, uint32 procFlag, uint32 cooldown); + bool HandleOverrideClassScriptAuraProc(Unit *pVictim, Aura* triggeredByAura, SpellEntry const *procSpell, uint32 cooldown); + bool HandleMeandingAuraProc(Aura* triggeredByAura); uint32 m_state; // Even derived shouldn't modify uint32 m_CombatTimer; diff --git a/win/VC71/game.vcproj b/win/VC71/game.vcproj index 6c14ab272d6..722300b9e8a 100644 --- a/win/VC71/game.vcproj +++ b/win/VC71/game.vcproj @@ -336,6 +336,12 @@ + + + + diff --git a/win/VC80/game.vcproj b/win/VC80/game.vcproj index 9ce5146d8b1..d8bd6bf726d 100644 --- a/win/VC80/game.vcproj +++ b/win/VC80/game.vcproj @@ -626,6 +626,14 @@ RelativePath="..\..\src\game\MapManager.h" > + + + + diff --git a/win/VC90/game.vcproj b/win/VC90/game.vcproj index 9ca7efc8178..89f4341ebc6 100644 --- a/win/VC90/game.vcproj +++ b/win/VC90/game.vcproj @@ -631,6 +631,14 @@ RelativePath="..\..\src\game\MapManager.h" > + + + + -- cgit v1.2.3 From 0b61584e1b19afb8dbef376a4e2903d8631bfc1d Mon Sep 17 00:00:00 2001 From: w12x Date: Wed, 19 Nov 2008 10:50:34 +0100 Subject: Finally properly fix phased game event saving. --HG-- branch : trunk --- src/game/GameEvent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/game/GameEvent.cpp b/src/game/GameEvent.cpp index 88028290dba..67d895cfc89 100644 --- a/src/game/GameEvent.cpp +++ b/src/game/GameEvent.cpp @@ -1503,7 +1503,7 @@ void GameEvent::SaveWorldEventStateToDB(uint16 event_id) CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM game_event_save WHERE event_id = '%u'",event_id); if(mGameEvent[event_id].nextstart) - CharacterDatabase.PExecute("INSERT INTO game_event_save (event_id, state, next_start) VALUES ('%u','%u',FROM_UNIXTIME("I64FMTD"))",event_id,mGameEvent[event_id].state,mGameEvent[event_id].nextstart); + CharacterDatabase.PExecute("INSERT INTO game_event_save (event_id, state, next_start) VALUES ('%u','%u',FROM_UNIXTIME("I64FMTD"))",event_id,mGameEvent[event_id].state,(uint64)(mGameEvent[event_id].nextstart)); else CharacterDatabase.PExecute("INSERT INTO game_event_save (event_id, state, next_start) VALUES ('%u','%u','0000-00-00 00:00:00')",event_id,mGameEvent[event_id].state); CharacterDatabase.CommitTransaction(); -- cgit v1.2.3 From 1e997b95cc89c615adf2acd27a5f6916b78e0ff3 Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 20 Nov 2008 16:16:57 -0600 Subject: Re-commit 262 due to EOL issues. (no difference from 262) --HG-- branch : trunk --- sql/updates/262_characters.sql | 5 + sql/updates/262_realmd.sql | 2 + sql/updates/262_world.sql | 70 +++ sql/updates/262_world_runthisonlyonce.sql | 31 ++ src/bindings/scripts/ScriptMgr.cpp | 94 ++-- src/bindings/scripts/ScriptMgr.h | 59 +- .../scripts/areatrigger/areatrigger_scripts.cpp | 2 +- src/bindings/scripts/scripts/boss/boss_emeriss.cpp | 2 +- src/bindings/scripts/scripts/boss/boss_taerar.cpp | 4 +- src/bindings/scripts/scripts/boss/boss_ysondre.cpp | 4 +- .../scripts/scripts/creature/mob_event_ai.cpp | 2 +- .../scripts/creature/mob_generic_creature.cpp | 2 +- .../scripts/scripts/custom/custom_example.cpp | 2 +- .../scripts/custom/custom_gossip_codebox.cpp | 2 +- src/bindings/scripts/scripts/custom/test.cpp | 2 +- src/bindings/scripts/scripts/go/go_scripts.cpp | 18 +- src/bindings/scripts/scripts/guard/guards.cpp | 40 +- src/bindings/scripts/scripts/item/item_scripts.cpp | 38 +- src/bindings/scripts/scripts/item/item_test.cpp | 2 +- src/bindings/scripts/scripts/npc/npc_innkeeper.cpp | 2 +- .../scripts/scripts/npc/npc_professions.cpp | 10 +- src/bindings/scripts/scripts/npc/npcs_special.cpp | 16 +- .../zone/alterac_mountains/alterac_mountains.cpp | 2 +- .../auchenai_crypts/boss_exarch_maladaar.cpp | 6 +- .../mana_tombs/boss_nexusprince_shaffar.cpp | 4 +- .../aunchindoun/mana_tombs/boss_pandemonius.cpp | 2 +- .../sethekk_halls/boss_darkweaver_syth.cpp | 10 +- .../sethekk_halls/boss_tailonking_ikiss.cpp | 2 +- .../sethekk_halls/instance_sethekk_halls.cpp | 2 +- .../shadow_labyrinth/boss_ambassador_hellmaw.cpp | 2 +- .../boss_blackheart_the_inciter.cpp | 2 +- .../shadow_labyrinth/boss_grandmaster_vorpil.cpp | 4 +- .../aunchindoun/shadow_labyrinth/boss_murmur.cpp | 2 +- .../shadow_labyrinth/instance_shadow_labyrinth.cpp | 2 +- .../scripts/scripts/zone/azshara/azshara.cpp | 8 +- .../scripts/scripts/zone/azshara/boss_azuregos.cpp | 2 +- .../scripts/zone/azuremyst_isle/azuremyst_isle.cpp | 8 +- .../scripts/scripts/zone/barrens/the_barrens.cpp | 8 +- .../scripts/zone/black_temple/black_temple.cpp | 2 +- .../scripts/zone/black_temple/boss_bloodboil.cpp | 2 +- .../scripts/zone/black_temple/boss_illidan.cpp | 20 +- .../zone/black_temple/boss_mother_shahraz.cpp | 2 +- .../zone/black_temple/boss_reliquary_of_souls.cpp | 10 +- .../zone/black_temple/boss_shade_of_akama.cpp | 8 +- .../scripts/zone/black_temple/boss_supremus.cpp | 4 +- .../zone/black_temple/boss_teron_gorefiend.cpp | 6 +- .../zone/black_temple/boss_warlord_najentus.cpp | 4 +- .../scripts/zone/black_temple/illidari_council.cpp | 12 +- .../zone/black_temple/instance_black_temple.cpp | 2 +- .../zone/blackrock_depths/blackrock_depths.cpp | 6 +- .../blackrock_depths/boss_ambassador_flamelash.cpp | 2 +- .../zone/blackrock_depths/boss_angerrel.cpp | 2 +- .../zone/blackrock_depths/boss_anubshiah.cpp | 2 +- .../scripts/zone/blackrock_depths/boss_doomrel.cpp | 2 +- .../scripts/zone/blackrock_depths/boss_doperel.cpp | 2 +- .../boss_emperor_dagran_thaurissan.cpp | 2 +- .../blackrock_depths/boss_general_angerforge.cpp | 2 +- .../zone/blackrock_depths/boss_gloomrel.cpp | 2 +- .../blackrock_depths/boss_gorosh_the_dervish.cpp | 2 +- .../scripts/zone/blackrock_depths/boss_grizzle.cpp | 2 +- .../scripts/zone/blackrock_depths/boss_haterel.cpp | 2 +- .../boss_high_interrogator_gerstahn.cpp | 2 +- .../scripts/zone/blackrock_depths/boss_magmus.cpp | 2 +- .../blackrock_depths/boss_moira_bronzebeard.cpp | 2 +- .../zone/blackrock_depths/boss_seethrel.cpp | 2 +- .../scripts/zone/blackrock_depths/boss_vilerel.cpp | 2 +- .../zone/blackrock_spire/boss_drakkisath.cpp | 2 +- .../scripts/zone/blackrock_spire/boss_gyth.cpp | 2 +- .../scripts/zone/blackrock_spire/boss_halycon.cpp | 2 +- .../zone/blackrock_spire/boss_highlord_omokk.cpp | 2 +- .../blackrock_spire/boss_mother_smolderweb.cpp | 2 +- .../blackrock_spire/boss_overlord_wyrmthalak.cpp | 2 +- .../blackrock_spire/boss_pyroguard_emberseer.cpp | 2 +- .../blackrock_spire/boss_quartermaster_zigris.cpp | 2 +- .../zone/blackrock_spire/boss_rend_blackhand.cpp | 2 +- .../boss_shadow_hunter_voshgajin.cpp | 2 +- .../zone/blackrock_spire/boss_the_beast.cpp | 2 +- .../zone/blackrock_spire/boss_warmaster_voone.cpp | 2 +- .../blackwing_lair/boss_broodlord_lashlayer.cpp | 2 +- .../zone/blackwing_lair/boss_chromaggus.cpp | 2 +- .../scripts/zone/blackwing_lair/boss_ebonroc.cpp | 2 +- .../scripts/zone/blackwing_lair/boss_firemaw.cpp | 2 +- .../scripts/zone/blackwing_lair/boss_flamegor.cpp | 2 +- .../scripts/zone/blackwing_lair/boss_nefarian.cpp | 2 +- .../scripts/zone/blackwing_lair/boss_razorgore.cpp | 2 +- .../zone/blackwing_lair/boss_vaelastrasz.cpp | 2 +- .../zone/blackwing_lair/boss_victor_nefarius.cpp | 2 +- .../blades_edge_mountains.cpp | 12 +- .../scripts/zone/blasted_lands/blasted_lands.cpp | 4 +- .../scripts/zone/blasted_lands/boss_kruul.cpp | 2 +- .../scripts/zone/bloodmyst_isle/bloodmyst_isle.cpp | 4 +- .../zone/burning_steppes/burning_steppes.cpp | 2 +- .../caverns_of_time/dark_portal/boss_aeonus.cpp | 2 +- .../dark_portal/boss_chrono_lord_deja.cpp | 2 +- .../caverns_of_time/dark_portal/boss_temporus.cpp | 2 +- .../zone/caverns_of_time/hyjal/boss_archimonde.cpp | 8 +- .../scripts/zone/caverns_of_time/hyjal/hyjal.cpp | 6 +- .../zone/caverns_of_time/hyjal/instance_hyjal.cpp | 2 +- .../old_hillsbrad/boss_captain_skarloc.cpp | 2 +- .../old_hillsbrad/boss_epoch_hunter.cpp | 2 +- .../old_hillsbrad/boss_leutenant_drake.cpp | 4 +- .../old_hillsbrad/instance_old_hillsbrad.cpp | 2 +- .../old_hillsbrad/old_hillsbrad.cpp | 8 +- .../serpent_shrine/boss_fathomlord_karathress.cpp | 8 +- .../serpent_shrine/boss_hydross_the_unstable.cpp | 2 +- .../serpent_shrine/boss_lady_vashj.cpp | 16 +- .../serpent_shrine/boss_leotheras_the_blind.cpp | 8 +- .../serpent_shrine/boss_lurker_below.cpp | 6 +- .../serpent_shrine/boss_morogrim_tidewalker.cpp | 4 +- .../serpent_shrine/instance_serpent_shrine.cpp | 2 +- .../steam_vault/boss_hydromancer_thespia.cpp | 4 +- .../steam_vault/boss_mekgineer_steamrigger.cpp | 4 +- .../steam_vault/boss_warlord_kalithresh.cpp | 4 +- .../steam_vault/instance_steam_vault.cpp | 2 +- .../coilfang_resevoir/underbog/boss_hungarfen.cpp | 4 +- .../scripts/scripts/zone/dun_morogh/dun_morogh.cpp | 2 +- .../zone/dustwallow_marsh/dustwallow_marsh.cpp | 10 +- .../eastern_plaguelands/eastern_plaguelands.cpp | 8 +- .../scripts/zone/elwynn_forest/elwynn_forest.cpp | 2 +- .../scripts/zone/eversong_woods/eversong_woods.cpp | 4 +- .../scripts/scripts/zone/felwood/felwood.cpp | 2 +- .../scripts/scripts/zone/feralas/feralas.cpp | 4 +- .../scripts/scripts/zone/ghostlands/ghostlands.cpp | 8 +- .../scripts/zone/gruuls_lair/boss_gruul.cpp | 2 +- .../zone/gruuls_lair/boss_high_king_maulgar.cpp | 10 +- .../zone/gruuls_lair/instance_gruuls_lair.cpp | 2 +- .../blood_furnace/boss_broggok.cpp | 4 +- .../blood_furnace/boss_kelidan_the_breaker.cpp | 4 +- .../blood_furnace/boss_the_maker.cpp | 2 +- .../hellfire_ramparts/boss_omor_the_unscarred.cpp | 2 +- .../boss_watchkeeper_gargolmar.cpp | 2 +- .../magtheridons_lair/boss_magtheridon.cpp | 8 +- .../instance_magtheridons_lair.cpp | 2 +- .../shattered_halls/boss_nethekurse.cpp | 6 +- .../shattered_halls/boss_warbringer_omrogg.cpp | 4 +- .../shattered_halls/instance_shattered_halls.cpp | 2 +- .../hellfire_peninsula/boss_doomlord_kazzak.cpp | 2 +- .../zone/hellfire_peninsula/hellfire_peninsula.cpp | 6 +- .../scripts/scripts/zone/ironforge/ironforge.cpp | 2 +- .../zone/isle_of_queldanas/isle_of_queldanas.cpp | 6 +- .../scripts/scripts/zone/karazhan/boss_curator.cpp | 2 +- .../zone/karazhan/boss_maiden_of_virtue.cpp | 2 +- .../scripts/zone/karazhan/boss_midnight.cpp | 4 +- .../scripts/scripts/zone/karazhan/boss_moroes.cpp | 14 +- .../zone/karazhan/boss_prince_malchezaar.cpp | 4 +- .../scripts/zone/karazhan/boss_shade_of_aran.cpp | 8 +- .../zone/karazhan/boss_terestian_illhoof.cpp | 8 +- .../scripts/scripts/zone/karazhan/bosses_opera.cpp | 22 +- .../scripts/zone/karazhan/instance_karazhan.cpp | 2 +- .../scripts/scripts/zone/karazhan/karazhan.cpp | 18 +- .../scripts/scripts/zone/loch_modan/loch_modan.cpp | 2 +- .../magisters_terrace/boss_felblood_kaelthas.cpp | 14 +- .../magisters_terrace/boss_priestess_delrissa.cpp | 24 +- .../magisters_terrace/boss_selin_fireheart.cpp | 4 +- .../zone/magisters_terrace/boss_vexallus.cpp | 4 +- .../instance_magisters_terrace.cpp | 2 +- .../zone/maraudon/boss_celebras_the_cursed.cpp | 2 +- .../scripts/zone/maraudon/boss_landslide.cpp | 2 +- .../scripts/scripts/zone/maraudon/boss_noxxion.cpp | 2 +- .../zone/maraudon/boss_princess_theradras.cpp | 2 +- .../scripts/zone/molten_core/boss_baron_geddon.cpp | 2 +- .../scripts/scripts/zone/molten_core/boss_garr.cpp | 4 +- .../scripts/zone/molten_core/boss_gehennas.cpp | 2 +- .../scripts/zone/molten_core/boss_golemagg.cpp | 4 +- .../scripts/zone/molten_core/boss_lucifron.cpp | 2 +- .../scripts/zone/molten_core/boss_magmadar.cpp | 2 +- .../zone/molten_core/boss_majordomo_executus.cpp | 2 +- .../scripts/zone/molten_core/boss_ragnaros.cpp | 2 +- .../scripts/zone/molten_core/boss_shazzrah.cpp | 2 +- .../zone/molten_core/boss_sulfuron_harbinger.cpp | 4 +- .../zone/molten_core/instance_molten_core.cpp | 2 +- .../scripts/zone/molten_core/molten_core.cpp | 2 +- .../scripts/scripts/zone/moonglade/moonglade.cpp | 10 +- .../scripts/scripts/zone/mulgore/mulgore.cpp | 2 +- .../scripts/scripts/zone/nagrand/nagrand.cpp | 16 +- .../scripts/zone/naxxramas/boss_anubrekhan.cpp | 2 +- .../scripts/zone/naxxramas/boss_faerlina.cpp | 2 +- .../scripts/scripts/zone/naxxramas/boss_gluth.cpp | 2 +- .../zone/naxxramas/boss_highlord_mograine.cpp | 2 +- .../scripts/zone/naxxramas/boss_kelthuzad.cpp | 2 +- .../scripts/zone/naxxramas/boss_lady_blaumeux.cpp | 2 +- .../scripts/zone/naxxramas/boss_loatheb.cpp | 2 +- .../scripts/zone/naxxramas/boss_maexxna.cpp | 4 +- .../scripts/scripts/zone/naxxramas/boss_noth.cpp | 2 +- .../scripts/zone/naxxramas/boss_patchwerk.cpp | 2 +- .../scripts/zone/naxxramas/boss_razuvious.cpp | 2 +- .../scripts/zone/naxxramas/boss_sapphiron.cpp | 2 +- .../scripts/zone/naxxramas/boss_sir_zeliek.cpp | 2 +- .../scripts/zone/naxxramas/boss_thane_korthazz.cpp | 2 +- .../scripts/zone/netherstorm/netherstorm.cpp | 8 +- .../scripts/zone/onyxias_lair/boss_onyxia.cpp | 2 +- .../scripts/scripts/zone/orgrimmar/orgrimmar.cpp | 6 +- .../boss_amnennar_the_coldbringer.cpp | 2 +- .../zone/ruins_of_ahnqiraj/boss_ayamiss.cpp | 2 +- .../zone/ruins_of_ahnqiraj/boss_kurinnaxx.cpp | 2 +- .../scripts/zone/ruins_of_ahnqiraj/boss_moam.cpp | 2 +- .../zone/scarlet_monastery/boss_arcanist_doan.cpp | 2 +- .../boss_azshir_the_sleepless.cpp | 2 +- .../scarlet_monastery/boss_bloodmage_thalnos.cpp | 2 +- .../scripts/zone/scarlet_monastery/boss_herod.cpp | 2 +- .../boss_high_inquisitor_fairbanks.cpp | 2 +- .../boss_high_inquisitor_whitemane.cpp | 2 +- .../scarlet_monastery/boss_houndmaster_loksey.cpp | 2 +- .../scarlet_monastery/boss_interrogator_vishas.cpp | 2 +- .../boss_scarlet_commander_mograine.cpp | 2 +- .../scripts/zone/scarlet_monastery/boss_scorn.cpp | 2 +- .../zone/scholomance/boss_darkmaster_gandling.cpp | 2 +- .../scholomance/boss_death_knight_darkreaver.cpp | 2 +- .../scholomance/boss_doctor_theolen_krastinov.cpp | 2 +- .../zone/scholomance/boss_illucia_barov.cpp | 2 +- .../zone/scholomance/boss_instructor_malicia.cpp | 2 +- .../zone/scholomance/boss_jandice_barov.cpp | 4 +- .../scripts/zone/scholomance/boss_kormok.cpp | 2 +- .../zone/scholomance/boss_lord_alexei_barov.cpp | 2 +- .../zone/scholomance/boss_lorekeeper_polkelt.cpp | 2 +- .../zone/scholomance/boss_ras_frostwhisper.cpp | 2 +- .../scripts/zone/scholomance/boss_the_ravenian.cpp | 2 +- .../scripts/zone/scholomance/boss_vectus.cpp | 2 +- .../zone/scholomance/instance_scholomance.cpp | 2 +- .../scripts/zone/searing_gorge/searing_gorge.cpp | 6 +- .../shadowfang_keep/instance_shadowfang_keep.cpp | 2 +- .../zone/shadowfang_keep/shadowfang_keep.cpp | 2 +- .../zone/shadowmoon_valley/boss_doomwalker.cpp | 2 +- .../zone/shadowmoon_valley/shadowmoon_valley.cpp | 26 +- .../scripts/zone/shattrath/shattrath_city.cpp | 10 +- .../scripts/scripts/zone/silithus/silithus.cpp | 2 +- .../scripts/zone/silvermoon/silvermoon_city.cpp | 2 +- .../zone/silverpine_forest/silverpine_forest.cpp | 2 +- .../stonetalon_mountains/stonetalon_mountains.cpp | 2 +- .../scripts/zone/stormwind/stormwind_city.cpp | 10 +- .../zone/stranglethorn_vale/stranglethorn_vale.cpp | 2 +- .../zone/stratholme/boss_baron_rivendare.cpp | 2 +- .../zone/stratholme/boss_baroness_anastari.cpp | 2 +- .../zone/stratholme/boss_cannon_master_willey.cpp | 2 +- .../zone/stratholme/boss_dathrohan_balnazzar.cpp | 2 +- .../zone/stratholme/boss_magistrate_barthilas.cpp | 2 +- .../zone/stratholme/boss_maleki_the_pallid.cpp | 2 +- .../scripts/zone/stratholme/boss_nerubenkan.cpp | 2 +- .../zone/stratholme/boss_order_of_silver_hand.cpp | 2 +- .../zone/stratholme/boss_postmaster_malown.cpp | 2 +- .../zone/stratholme/boss_ramstein_the_gorger.cpp | 2 +- .../zone/stratholme/boss_timmy_the_cruel.cpp | 2 +- .../zone/stratholme/instance_stratholme.cpp | 2 +- .../scripts/scripts/zone/stratholme/stratholme.cpp | 10 +- .../zone/sunwell_plateau/boss_brutallus.cpp | 2 +- .../zone/sunwell_plateau/boss_eredar_twins.cpp | 6 +- .../scripts/zone/sunwell_plateau/boss_felmyst.cpp | 6 +- .../scripts/zone/sunwell_plateau/boss_kalecgos.cpp | 8 +- .../sunwell_plateau/instance_sunwell_plateau.cpp | 2 +- .../scripts/scripts/zone/tanaris/tanaris.cpp | 10 +- .../zone/tempest_keep/arcatraz/arcatraz.cpp | 6 +- .../arcatraz/boss_harbinger_skyriss.cpp | 4 +- .../tempest_keep/arcatraz/instance_arcatraz.cpp | 2 +- .../botanica/boss_high_botanist_freywinn.cpp | 2 +- .../zone/tempest_keep/botanica/boss_laj.cpp | 2 +- .../tempest_keep/botanica/boss_warp_splinter.cpp | 4 +- .../zone/tempest_keep/the_eye/boss_alar.cpp | 6 +- .../zone/tempest_keep/the_eye/boss_astromancer.cpp | 4 +- .../zone/tempest_keep/the_eye/boss_kaelthas.cpp | 14 +- .../zone/tempest_keep/the_eye/boss_void_reaver.cpp | 2 +- .../zone/tempest_keep/the_eye/instance_the_eye.cpp | 2 +- .../scripts/zone/tempest_keep/the_eye/the_eye.cpp | 2 +- .../the_mechanar/boss_gatewatcher_ironhand.cpp | 2 +- .../the_mechanar/boss_nethermancer_sepethrea.cpp | 4 +- .../the_mechanar/boss_pathaleon_the_calculator.cpp | 612 ++++++++++----------- .../the_mechanar/instance_mechanar.cpp | 180 +++--- .../zone/temple_of_ahnqiraj/boss_bug_trio.cpp | 6 +- .../scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp | 14 +- .../zone/temple_of_ahnqiraj/boss_fankriss.cpp | 2 +- .../zone/temple_of_ahnqiraj/boss_huhuran.cpp | 2 +- .../scripts/zone/temple_of_ahnqiraj/boss_ouro.cpp | 2 +- .../zone/temple_of_ahnqiraj/boss_sartura.cpp | 4 +- .../zone/temple_of_ahnqiraj/boss_skeram.cpp | 2 +- .../zone/temple_of_ahnqiraj/boss_twinemperors.cpp | 4 +- .../instance_temple_of_ahnqiraj.cpp | 2 +- .../temple_of_ahnqiraj/mob_anubisath_sentinel.cpp | 2 +- .../zone/terokkar_forest/terokkar_forest.cpp | 12 +- .../scripts/zone/thunder_bluff/thunder_bluff.cpp | 2 +- .../zone/tirisfal_glades/tirisfal_glades.cpp | 2 +- .../scripts/scripts/zone/uldaman/boss_ironaya.cpp | 2 +- .../scripts/scripts/zone/uldaman/uldaman.cpp | 4 +- .../scripts/scripts/zone/undercity/undercity.cpp | 6 +- .../western_plaguelands/western_plaguelands.cpp | 4 +- .../scripts/scripts/zone/westfall/westfall.cpp | 358 ++++++------ .../scripts/zone/winterspring/winterspring.cpp | 6 +- .../scripts/zone/zangarmarsh/zangarmarsh.cpp | 8 +- .../scripts/scripts/zone/zulaman/boss_akilzon.cpp | 4 +- .../scripts/scripts/zone/zulaman/boss_halazzi.cpp | 4 +- .../scripts/scripts/zone/zulaman/boss_hexlord.cpp | 18 +- .../scripts/scripts/zone/zulaman/boss_janalai.cpp | 10 +- .../scripts/scripts/zone/zulaman/boss_nalorakk.cpp | 2 +- .../scripts/scripts/zone/zulaman/boss_zuljin.cpp | 6 +- .../scripts/zone/zulaman/instance_zulaman.cpp | 12 +- .../scripts/scripts/zone/zulaman/zulaman.cpp | 4 +- .../scripts/scripts/zone/zulfarrak/zulfarrak.cpp | 4 +- .../scripts/scripts/zone/zulgurub/boss_arlokk.cpp | 2 +- .../scripts/zone/zulgurub/boss_gahzranka.cpp | 2 +- .../scripts/scripts/zone/zulgurub/boss_grilek.cpp | 2 +- .../scripts/scripts/zone/zulgurub/boss_hakkar.cpp | 2 +- .../scripts/zone/zulgurub/boss_hazzarah.cpp | 2 +- .../scripts/scripts/zone/zulgurub/boss_jeklik.cpp | 4 +- .../scripts/scripts/zone/zulgurub/boss_jindo.cpp | 6 +- .../scripts/zone/zulgurub/boss_mandokir.cpp | 4 +- .../scripts/scripts/zone/zulgurub/boss_marli.cpp | 4 +- .../scripts/zone/zulgurub/boss_renataki.cpp | 2 +- .../scripts/scripts/zone/zulgurub/boss_thekal.cpp | 6 +- .../scripts/scripts/zone/zulgurub/boss_venoxis.cpp | 2 +- .../scripts/zone/zulgurub/boss_wushoolay.cpp | 2 +- .../scripts/zone/zulgurub/instance_zulgurub.cpp | 2 +- src/game/AuctionHouse.cpp | 12 +- src/game/Bag.cpp | 13 +- src/game/Chat.cpp | 36 +- src/game/Chat.h | 14 +- src/game/Creature.cpp | 21 +- src/game/Creature.h | 17 +- src/game/CreatureAI.cpp | 4 +- src/game/CreatureAIImpl.h | 4 +- src/game/CreatureAIRegistry.cpp | 4 +- src/game/CreatureAISelector.cpp | 4 +- src/game/Formulas.h | 7 +- src/game/GMTicketHandler.cpp | 10 +- src/game/GMTicketMgr.h | 13 +- src/game/GameObject.h | 6 +- src/game/Item.cpp | 25 +- src/game/Item.h | 5 +- src/game/ItemEnchantmentMgr.cpp | 4 +- src/game/ItemEnchantmentMgr.h | 4 +- src/game/ItemHandler.cpp | 31 +- src/game/ItemPrototype.h | 40 +- src/game/Level2.cpp | 96 +--- src/game/Level3.cpp | 150 +++-- src/game/Mail.cpp | 15 +- src/game/Map.cpp | 6 +- src/game/Map.h | 9 +- src/game/MapManager.cpp | 2 +- src/game/MapManager.h | 7 +- src/game/ObjectMgr.cpp | 430 ++++++++++----- src/game/ObjectMgr.h | 69 ++- src/game/PlayerDump.cpp | 93 ++-- src/game/SpellHandler.cpp | 15 +- src/game/WaypointManager.cpp | 68 ++- src/game/WaypointManager.h | 3 +- src/game/WaypointMovementGenerator.cpp | 25 +- src/game/World.cpp | 63 ++- src/game/World.h | 79 +-- src/shared/Database/DBCEnums.h | 104 ++++ src/shared/Database/DBCStores.cpp | 35 +- src/shared/Database/DBCStores.h | 5 +- src/shared/Database/DBCStructure.h | 119 +--- src/shared/Database/SQLStorage.cpp | 160 +----- src/shared/Database/SQLStorage.h | 68 ++- src/shared/Database/SQLStorageImpl.h | 214 +++++++ src/shared/Database/dbcfile.cpp | 4 +- src/shared/Database/dbcfile.h | 4 +- src/shared/ProgressBar.cpp | 4 +- src/shared/ProgressBar.h | 4 +- src/trinitycore/CliRunnable.cpp | 10 +- src/trinitycore/Master.cpp | 16 +- src/trinitycore/WorldRunnable.cpp | 2 +- 359 files changed, 2718 insertions(+), 2132 deletions(-) create mode 100644 sql/updates/262_characters.sql create mode 100644 sql/updates/262_realmd.sql create mode 100644 sql/updates/262_world.sql create mode 100644 sql/updates/262_world_runthisonlyonce.sql create mode 100644 src/shared/Database/DBCEnums.h create mode 100644 src/shared/Database/SQLStorageImpl.h (limited to 'src') diff --git a/sql/updates/262_characters.sql b/sql/updates/262_characters.sql new file mode 100644 index 00000000000..fc08d8cda85 --- /dev/null +++ b/sql/updates/262_characters.sql @@ -0,0 +1,5 @@ +ALTER TABLE `guild_bank_tab` + CHANGE COLUMN `TabText` `TabText` text; + +ALTER TABLE `character_aura` ADD `stackcount` INT NOT NULL DEFAULT '1' AFTER `effect_index` ; +ALTER TABLE `pet_aura` ADD `stackcount` INT NOT NULL DEFAULT '1' AFTER `effect_index` ; \ No newline at end of file diff --git a/sql/updates/262_realmd.sql b/sql/updates/262_realmd.sql new file mode 100644 index 00000000000..facffa9a7d1 --- /dev/null +++ b/sql/updates/262_realmd.sql @@ -0,0 +1,2 @@ +ALTER TABLE `account` + CHANGE COLUMN `email` `email` text; \ No newline at end of file diff --git a/sql/updates/262_world.sql b/sql/updates/262_world.sql new file mode 100644 index 00000000000..2fe599e76e7 --- /dev/null +++ b/sql/updates/262_world.sql @@ -0,0 +1,70 @@ +DELETE FROM trinity_string WHERE entry IN (1119,1120,1121); + +INSERT INTO trinity_string VALUES +(1119,'You must use male or female as gender.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), +(1120,'You change gender of %s to %s.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), +(1121,'Your gender changed to %s by %s.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); + + +DELETE FROM command WHERE name IN ('modify gender'); + +INSERT INTO command VALUES +('modify gender',2,'Syntax: .modify gender male/female\r\n\r\nChange gender of selected player.'); + + +delete from `command` where `name` IN ('senditems','sendmail'); +insert into `command` (`name`, `security`, `help`) values +('senditems',3,'Syntax: .senditems #playername "#subject" "#text" itemid1[:count1] itemid2[:count2] ... itemidN[:countN]\r\n\r\nSend a mail to a player. Subject and mail text must be in "". If for itemid not provided related count values then expected 1, if count > max items in stack then items will be send in required amount stacks. All stacks amount in mail limited to 12.'), +('sendmail',1,'Syntax: .sendmail #playername "#subject" "#text"\r\n\r\nSend a mail to a player. Subject and mail text must be in "".'); + + +delete from `command` where `name` = 'sendmoney'; +insert into `command` (`name`, `security`, `help`) values +('sendmoney',3,'Syntax: .sendmoney #playername "#subject" "#text" #money\r\n\r\nSend mail with money to a player. Subject and mail text must be in "".'); + + +DELETE FROM trinity_string WHERE entry IN (453); + + +DROP TABLE IF EXISTS `db_script_string`; +CREATE TABLE `db_script_string` ( + `entry` int(11) unsigned NOT NULL default '0', + `content_default` text NOT NULL, + `content_loc1` text, + `content_loc2` text, + `content_loc3` text, + `content_loc4` text, + `content_loc5` text, + `content_loc6` text, + `content_loc7` text, + `content_loc8` text, + PRIMARY KEY (`entry`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + + +DELETE FROM `command` WHERE `name` IN ( + 'server exit', + 'server idleshutdown', + 'server idleshutdown cancel', + 'server idlerestart', + 'server idlerestart cancel', + 'server restart', + 'server restart cancel', + 'server shutdown', + 'server shutdown cancel' +); + +INSERT INTO `command` (`name`, `security`, `help`) VALUES +('server exit',4,'Syntax: .server exit\r\n\r\nTerminate mangosd NOW. Exit code 0.'), +('server idleshutdown',3,'Syntax: .server idleshutdown #delay [#exist_code]\r\n\r\nShut the server down after #delay seconds if no active connections are present (no players). Use #exist_code or 0 as program exist code.'), +('server idleshutdown cancel',3,'Syntax: .server idleshutdown cancel\r\n\r\nCancel the restart/shutdown timer if any.'), +('server idlerestart',3,'Syntax: .server idlerestart #delay\r\n\r\nRestart the server after #delay seconds if no active connections are present (no players). Use #exist_code or 2 as program exist code.'), +('server idlerestart cancel',3,'Syntax: .server idlerestart cancel\r\n\r\nCancel the restart/shutdown timer if any.'), +('server restart',3,'Syntax: .server restart #delay\r\n\r\nRestart the server after #delay seconds. Use #exist_code or 2 as program exist code.'), +('server restart cancel',3,'Syntax: .server restart cancel\r\n\r\nCancel the restart/shutdown timer if any.'), +('server shutdown',3,'Syntax: .server shutdown #delay [#exist_code]\r\n\r\nShut the server down after #delay seconds. Use #exist_code or 0 as program exist code.'), +('server shutdown cancel',3,'Syntax: .server shutdown cancel\r\n\r\nCancel the restart/shutdown timer if any.'); + +DELETE FROM trinity_string WHERE entry IN (251); +INSERT INTO trinity_string VALUES +(251,'Text%d (ID: %i): %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); \ No newline at end of file diff --git a/sql/updates/262_world_runthisonlyonce.sql b/sql/updates/262_world_runthisonlyonce.sql new file mode 100644 index 00000000000..fc5cc708063 --- /dev/null +++ b/sql/updates/262_world_runthisonlyonce.sql @@ -0,0 +1,31 @@ +ALTER TABLE event_scripts + DROP datatext, + ADD COLUMN dataint int(11) NOT NULL default '0' AFTER datalong2; + +ALTER TABLE gameobject_scripts + DROP datatext, + ADD COLUMN dataint int(11) NOT NULL default '0' AFTER datalong2; + +ALTER TABLE quest_end_scripts + DROP datatext, + ADD COLUMN dataint int(11) NOT NULL default '0' AFTER datalong2; + +ALTER TABLE quest_start_scripts + DROP datatext, + ADD COLUMN dataint int(11) NOT NULL default '0' AFTER datalong2; + +ALTER TABLE spell_scripts + DROP datatext, + ADD COLUMN dataint int(11) NOT NULL default '0' AFTER datalong2; + +ALTER TABLE creature_movement + DROP `text1`, + DROP `text2`, + DROP `text3`, + DROP `text4`, + DROP `text5`, + ADD COLUMN textid1 int(11) NOT NULL default '0' AFTER waittime, + ADD COLUMN textid2 int(11) NOT NULL default '0' AFTER textid1, + ADD COLUMN textid3 int(11) NOT NULL default '0' AFTER textid2, + ADD COLUMN textid4 int(11) NOT NULL default '0' AFTER textid3, + ADD COLUMN textid5 int(11) NOT NULL default '0' AFTER textid4; \ No newline at end of file diff --git a/src/bindings/scripts/ScriptMgr.cpp b/src/bindings/scripts/ScriptMgr.cpp index 840cdc4be60..ad6bcf76c08 100644 --- a/src/bindings/scripts/ScriptMgr.cpp +++ b/src/bindings/scripts/ScriptMgr.cpp @@ -17,7 +17,8 @@ #endif _TRINITY_SCRIPT_CONFIG //*** Global data *** -int nrscripts; +int num_db_scripts; +int num_sc_scripts; Script *m_scripts[MAX_SCRIPTS]; DatabaseType TScriptDB; @@ -47,7 +48,6 @@ enum ChatType // Text Maps UNORDERED_MAP TextMap; - //*** End Global data *** //*** EventAI data *** @@ -1180,15 +1180,16 @@ struct TSpellSummary { TRINITY_DLL_EXPORT void ScriptsFree() -{ +{ // Free Spell Summary delete []SpellSummary; // Free resources before library unload - for(int i=0;i> Loaded %i C++ Scripts (of %i ScriptNames defined in Mangos database)", num_sc_scripts, num_db_scripts); } //********************************* @@ -1848,32 +1849,29 @@ void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target) //********************************* //*** Functions used internally *** -TRINITY_DLL_EXPORT -char const* ScriptsVersion() +void Script::RegisterSelf() { - return "Default Trinity scripting library"; -} - -Script* GetScriptByName(std::string Name) -{ - if (Name.empty()) - return NULL; - - for(int i=0;iName == Name) - return m_scripts[i]; - } - return NULL; + m_scripts[id] = this; + ++num_sc_scripts; + } else + debug_log("SD2: RegisterSelf, but script named %s does not have ScriptName assigned in database.",(this)->Name.c_str()); } //******************************** //*** Functions to be Exported *** +TRINITY_DLL_EXPORT +char const* ScriptsVersion() +{ + return "Default Trinity scripting library"; +} TRINITY_DLL_EXPORT bool GossipHello ( Player * player, Creature *_Creature ) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pGossipHello) return false; player->PlayerTalkClass->ClearMenus(); @@ -1885,7 +1883,7 @@ bool GossipSelect( Player *player, Creature *_Creature, uint32 sender, uint32 ac { debug_log("TSCR: Gossip selection, sender: %d, action: %d",sender, action); - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pGossipSelect) return false; player->PlayerTalkClass->ClearMenus(); @@ -1897,7 +1895,7 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u { debug_log("TSCR: Gossip selection with code, sender: %d, action: %d",sender, action); - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pGossipSelectWithCode) return false; player->PlayerTalkClass->ClearMenus(); @@ -1907,7 +1905,7 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u TRINITY_DLL_EXPORT bool QuestAccept( Player *player, Creature *_Creature, Quest const *_Quest ) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pQuestAccept) return false; player->PlayerTalkClass->ClearMenus(); @@ -1917,7 +1915,7 @@ bool QuestAccept( Player *player, Creature *_Creature, Quest const *_Quest ) TRINITY_DLL_EXPORT bool QuestSelect( Player *player, Creature *_Creature, Quest const *_Quest ) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pQuestSelect) return false; player->PlayerTalkClass->ClearMenus(); @@ -1927,7 +1925,7 @@ bool QuestSelect( Player *player, Creature *_Creature, Quest const *_Quest ) TRINITY_DLL_EXPORT bool QuestComplete( Player *player, Creature *_Creature, Quest const *_Quest ) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pQuestComplete) return false; player->PlayerTalkClass->ClearMenus(); @@ -1937,7 +1935,7 @@ bool QuestComplete( Player *player, Creature *_Creature, Quest const *_Quest ) TRINITY_DLL_EXPORT bool ChooseReward( Player *player, Creature *_Creature, Quest const *_Quest, uint32 opt ) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pChooseReward) return false; player->PlayerTalkClass->ClearMenus(); @@ -1947,7 +1945,7 @@ bool ChooseReward( Player *player, Creature *_Creature, Quest const *_Quest, uin TRINITY_DLL_EXPORT uint32 NPCDialogStatus( Player *player, Creature *_Creature ) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pNPCDialogStatus) return 100; player->PlayerTalkClass->ClearMenus(); @@ -1957,8 +1955,8 @@ uint32 NPCDialogStatus( Player *player, Creature *_Creature ) TRINITY_DLL_EXPORT uint32 GODialogStatus( Player *player, GameObject *_GO ) { - Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); - if(!tmpscript || !tmpscript->pGODialogStatus) return 100; + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; + if (!tmpscript || !tmpscript->pGODialogStatus) return 100; player->PlayerTalkClass->ClearMenus(); return tmpscript->pGODialogStatus(player,_GO); @@ -1967,7 +1965,7 @@ uint32 GODialogStatus( Player *player, GameObject *_GO ) TRINITY_DLL_EXPORT bool ItemHello( Player *player, Item *_Item, Quest const *_Quest ) { - Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); + Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId]; if (!tmpscript || !tmpscript->pItemHello) return false; player->PlayerTalkClass->ClearMenus(); @@ -1977,7 +1975,7 @@ bool ItemHello( Player *player, Item *_Item, Quest const *_Quest ) TRINITY_DLL_EXPORT bool ItemQuestAccept( Player *player, Item *_Item, Quest const *_Quest ) { - Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); + Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId]; if (!tmpscript || !tmpscript->pItemQuestAccept) return false; player->PlayerTalkClass->ClearMenus(); @@ -1987,7 +1985,7 @@ bool ItemQuestAccept( Player *player, Item *_Item, Quest const *_Quest ) TRINITY_DLL_EXPORT bool GOHello( Player *player, GameObject *_GO ) { - Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; if (!tmpscript || !tmpscript->pGOHello) return false; player->PlayerTalkClass->ClearMenus(); @@ -1997,7 +1995,7 @@ bool GOHello( Player *player, GameObject *_GO ) TRINITY_DLL_EXPORT bool GOQuestAccept( Player *player, GameObject *_GO, Quest const *_Quest ) { - Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; if (!tmpscript || !tmpscript->pGOQuestAccept) return false; player->PlayerTalkClass->ClearMenus(); @@ -2007,7 +2005,7 @@ bool GOQuestAccept( Player *player, GameObject *_GO, Quest const *_Quest ) TRINITY_DLL_EXPORT bool GOChooseReward( Player *player, GameObject *_GO, Quest const *_Quest, uint32 opt ) { - Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; if (!tmpscript || !tmpscript->pGOChooseReward) return false; player->PlayerTalkClass->ClearMenus(); @@ -2017,9 +2015,7 @@ bool GOChooseReward( Player *player, GameObject *_GO, Quest const *_Quest, uint3 TRINITY_DLL_EXPORT bool AreaTrigger( Player *player, AreaTriggerEntry * atEntry) { - Script *tmpscript = NULL; - - tmpscript = GetScriptByName(GetAreaTriggerScriptNameById(atEntry->id)); + Script *tmpscript = m_scripts[GetAreaTriggerScriptId(atEntry->id)]; if (!tmpscript || !tmpscript->pAreaTrigger) return false; return tmpscript->pAreaTrigger(player, atEntry); @@ -2028,16 +2024,16 @@ bool AreaTrigger( Player *player, AreaTriggerEntry * atEntry) TRINITY_DLL_EXPORT CreatureAI* GetAI(Creature *_Creature) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); - + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->GetAI) return NULL; + return tmpscript->GetAI(_Creature); } TRINITY_DLL_EXPORT bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets) { - Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); + Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId]; if (!tmpscript || !tmpscript->pItemUse) return false; return tmpscript->pItemUse(player,_Item,targets); @@ -2046,7 +2042,7 @@ bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets) TRINITY_DLL_EXPORT bool ReceiveEmote( Player *player, Creature *_Creature, uint32 emote ) { - Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); + Script *tmpscript = m_scripts[_Creature->GetScriptId()]; if (!tmpscript || !tmpscript->pReceiveEmote) return false; return tmpscript->pReceiveEmote(player, _Creature, emote); @@ -2055,12 +2051,10 @@ bool ReceiveEmote( Player *player, Creature *_Creature, uint32 emote ) TRINITY_DLL_EXPORT InstanceData* CreateInstanceData(Map *map) { - Script *tmpscript = NULL; - - if (!map->IsDungeon()) return false; + if (!map->IsDungeon()) return NULL; - tmpscript = GetScriptByName(((InstanceMap*)map)->GetScript()); - if (!tmpscript || !tmpscript->GetInstanceData) return false; + Script *tmpscript = m_scripts[((InstanceMap*)map)->GetScriptId()]; + if (!tmpscript || !tmpscript->GetInstanceData) return NULL; return tmpscript->GetInstanceData(map); } diff --git a/src/bindings/scripts/ScriptMgr.h b/src/bindings/scripts/ScriptMgr.h index 83b2c0dd7a0..ef7bdfd3cce 100644 --- a/src/bindings/scripts/ScriptMgr.h +++ b/src/bindings/scripts/ScriptMgr.h @@ -24,46 +24,45 @@ class Map; class Unit; class WorldObject; -#define MAX_SCRIPTS 1000 //72 bytes each (approx 71kb) +#define MAX_SCRIPTS 5000 //72 bytes each (approx 351kb) #define VISIBLE_RANGE (166.0f) //MAX visible range (size of grid) #define DEFAULT_TEXT "" struct Script { Script() : -pGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGossipSelectWithCode(NULL), -pQuestSelect(NULL), pQuestComplete(NULL), pNPCDialogStatus(NULL), pGODialogStatus(NULL), pChooseReward(NULL), -pItemHello(NULL), pGOHello(NULL), pAreaTrigger(NULL), pItemQuestAccept(NULL), pGOQuestAccept(NULL), -pGOChooseReward(NULL),pReceiveEmote(NULL),pItemUse(NULL), GetAI(NULL), GetInstanceData(NULL) -{} + pGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGossipSelectWithCode(NULL), + pQuestSelect(NULL), pQuestComplete(NULL), pNPCDialogStatus(NULL), pGODialogStatus(NULL), pChooseReward(NULL), + pItemHello(NULL), pGOHello(NULL), pAreaTrigger(NULL), pItemQuestAccept(NULL), pGOQuestAccept(NULL), + pGOChooseReward(NULL),pReceiveEmote(NULL),pItemUse(NULL), GetAI(NULL), GetInstanceData(NULL) + {} -std::string Name; + std::string Name; -// Quest/gossip Methods to be scripted -bool (*pGossipHello )(Player*, Creature*); -bool (*pQuestAccept )(Player*, Creature*, Quest const* ); -bool (*pGossipSelect )(Player*, Creature*, uint32 , uint32 ); -bool (*pGossipSelectWithCode)(Player*, Creature*, uint32 , uint32 , const char* ); -bool (*pQuestSelect )(Player*, Creature*, Quest const* ); -bool (*pQuestComplete )(Player*, Creature*, Quest const* ); -uint32 (*pNPCDialogStatus )(Player*, Creature* ); -uint32 (*pGODialogStatus )(Player *player, GameObject * _GO ); -bool (*pChooseReward )(Player*, Creature*, Quest const*, uint32 ); -bool (*pItemHello )(Player*, Item*, Quest const* ); -bool (*pGOHello )(Player*, GameObject* ); -bool (*pAreaTrigger )(Player*, AreaTriggerEntry* ); -bool (*pItemQuestAccept )(Player*, Item *, Quest const* ); -bool (*pGOQuestAccept )(Player*, GameObject*, Quest const* ); -bool (*pGOChooseReward )(Player*, GameObject*_GO, Quest const*, uint32 ); -bool (*pReceiveEmote )(Player*, Creature*, uint32 ); -bool (*pItemUse )(Player*, Item*, SpellCastTargets const& ); + //Methods to be scripted + bool (*pGossipHello )(Player*, Creature*); + bool (*pQuestAccept )(Player*, Creature*, Quest const* ); + bool (*pGossipSelect )(Player*, Creature*, uint32 , uint32 ); + bool (*pGossipSelectWithCode)(Player*, Creature*, uint32 , uint32 , const char* ); + bool (*pQuestSelect )(Player*, Creature*, Quest const* ); + bool (*pQuestComplete )(Player*, Creature*, Quest const* ); + uint32 (*pNPCDialogStatus )(Player*, Creature* ); + uint32 (*pGODialogStatus )(Player*, GameObject * _GO ); + bool (*pChooseReward )(Player*, Creature*, Quest const*, uint32 ); + bool (*pItemHello )(Player*, Item*, Quest const* ); + bool (*pGOHello )(Player*, GameObject* ); + bool (*pAreaTrigger )(Player*, AreaTriggerEntry* ); + bool (*pItemQuestAccept )(Player*, Item *, Quest const* ); + bool (*pGOQuestAccept )(Player*, GameObject*, Quest const* ); + bool (*pGOChooseReward )(Player*, GameObject*, Quest const*, uint32 ); + bool (*pReceiveEmote )(Player*, Creature*, uint32 ); + bool (*pItemUse )(Player*, Item*, SpellCastTargets const& ); -CreatureAI* (*GetAI)(Creature*); -InstanceData* (*GetInstanceData)(Map*); -}; + CreatureAI* (*GetAI)(Creature*); + InstanceData* (*GetInstanceData)(Map*); -extern int nrscripts; -extern Script *m_scripts[MAX_SCRIPTS]; + void RegisterSelf(); +}; //Generic scripting text function void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target = NULL); diff --git a/src/bindings/scripts/scripts/areatrigger/areatrigger_scripts.cpp b/src/bindings/scripts/scripts/areatrigger/areatrigger_scripts.cpp index 117121d8530..83dda669e1f 100644 --- a/src/bindings/scripts/scripts/areatrigger/areatrigger_scripts.cpp +++ b/src/bindings/scripts/scripts/areatrigger/areatrigger_scripts.cpp @@ -40,5 +40,5 @@ void AddSC_areatrigger_scripts() newscript = new Script; newscript->Name="at_test"; newscript->pAreaTrigger = ATtest; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/boss/boss_emeriss.cpp b/src/bindings/scripts/scripts/boss/boss_emeriss.cpp index 99b3a845f95..a8af2b43e41 100644 --- a/src/bindings/scripts/scripts/boss/boss_emeriss.cpp +++ b/src/bindings/scripts/scripts/boss/boss_emeriss.cpp @@ -152,5 +152,5 @@ void AddSC_boss_emeriss() newscript = new Script; newscript->Name="boss_emeriss"; newscript->GetAI = GetAI_boss_emeriss; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/boss/boss_taerar.cpp b/src/bindings/scripts/scripts/boss/boss_taerar.cpp index 67d3364dd66..faed723cb4d 100644 --- a/src/bindings/scripts/scripts/boss/boss_taerar.cpp +++ b/src/bindings/scripts/scripts/boss/boss_taerar.cpp @@ -297,10 +297,10 @@ void AddSC_boss_taerar() newscript = new Script; newscript->Name="boss_taerar"; newscript->GetAI = GetAI_boss_taerar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_shade_of_taerar"; newscript->GetAI = GetAI_boss_shadeoftaerar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/boss/boss_ysondre.cpp b/src/bindings/scripts/scripts/boss/boss_ysondre.cpp index 3df1746bd76..b9fad649d71 100644 --- a/src/bindings/scripts/scripts/boss/boss_ysondre.cpp +++ b/src/bindings/scripts/scripts/boss/boss_ysondre.cpp @@ -237,10 +237,10 @@ void AddSC_boss_ysondre() newscript = new Script; newscript->Name="boss_ysondre"; newscript->GetAI = GetAI_boss_ysondre; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_dementeddruids"; newscript->GetAI = GetAI_mob_dementeddruids; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp index d7578731e91..af945282935 100644 --- a/src/bindings/scripts/scripts/creature/mob_event_ai.cpp +++ b/src/bindings/scripts/scripts/creature/mob_event_ai.cpp @@ -1400,5 +1400,5 @@ void AddSC_mob_event() newscript = new Script; newscript->Name="mob_eventai"; newscript->GetAI = GetAI_Mob_EventAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/creature/mob_generic_creature.cpp b/src/bindings/scripts/scripts/creature/mob_generic_creature.cpp index 0e03915df0e..02e34a8fa1e 100644 --- a/src/bindings/scripts/scripts/creature/mob_generic_creature.cpp +++ b/src/bindings/scripts/scripts/creature/mob_generic_creature.cpp @@ -168,5 +168,5 @@ void AddSC_generic_creature() newscript = new Script; newscript->Name="generic_creature"; newscript->GetAI = GetAI_generic_creature; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/custom/custom_example.cpp b/src/bindings/scripts/scripts/custom/custom_example.cpp index 133b2136a1c..d1a30fd06af 100644 --- a/src/bindings/scripts/scripts/custom/custom_example.cpp +++ b/src/bindings/scripts/scripts/custom/custom_example.cpp @@ -273,5 +273,5 @@ void AddSC_custom_example() newscript->pGossipHello = &GossipHello_custom_example; newscript->pGossipSelect = &GossipSelect_custom_example; newscript->pReceiveEmote = &ReceiveEmote_custom_example; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/custom/custom_gossip_codebox.cpp b/src/bindings/scripts/scripts/custom/custom_gossip_codebox.cpp index c8cfe711fc9..3963d31b98b 100644 --- a/src/bindings/scripts/scripts/custom/custom_gossip_codebox.cpp +++ b/src/bindings/scripts/scripts/custom/custom_gossip_codebox.cpp @@ -77,5 +77,5 @@ void AddSC_custom_gossip_codebox() newscript->pGossipHello = &GossipHello_custom_gossip_codebox; newscript->pGossipSelect = &GossipSelect_custom_gossip_codebox; newscript->pGossipSelectWithCode = &GossipSelectWithCode_custom_gossip_codebox; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/custom/test.cpp b/src/bindings/scripts/scripts/custom/test.cpp index 52d5c7d6f4f..e54716afcf0 100644 --- a/src/bindings/scripts/scripts/custom/test.cpp +++ b/src/bindings/scripts/scripts/custom/test.cpp @@ -196,5 +196,5 @@ void AddSC_test() newscript->GetAI = GetAI_test; newscript->pGossipHello = &GossipHello_npc_test; newscript->pGossipSelect = &GossipSelect_npc_test; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/go/go_scripts.cpp b/src/bindings/scripts/scripts/go/go_scripts.cpp index a06e588d916..511e283373a 100644 --- a/src/bindings/scripts/scripts/go/go_scripts.cpp +++ b/src/bindings/scripts/scripts/go/go_scripts.cpp @@ -165,45 +165,45 @@ void AddSC_go_scripts() newscript = new Script; newscript->Name="go_northern_crystal_pylon"; newscript->pGOHello = &GOHello_go_northern_crystal_pylon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_eastern_crystal_pylon"; newscript->pGOHello = &GOHello_go_eastern_crystal_pylon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_western_crystal_pylon"; newscript->pGOHello = &GOHello_go_western_crystal_pylon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_barov_journal"; newscript->pGOHello = &GOHello_go_barov_journal; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_field_repair_bot_74A"; newscript->pGOHello = &GOHello_go_field_repair_bot_74A; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_orb_of_command"; newscript->pGOHello = &GOHello_go_orb_of_command; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_tablet_of_madness"; newscript->pGOHello = &GOHello_go_tablet_of_madness; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_tablet_of_the_seven"; newscript->pGOHello = &GOHello_go_tablet_of_the_seven; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_teleporter"; newscript->pGOHello = &GOHello_go_teleporter; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/guard/guards.cpp b/src/bindings/scripts/scripts/guard/guards.cpp index fdc541665d1..a96ded0ac70 100644 --- a/src/bindings/scripts/scripts/guard/guards.cpp +++ b/src/bindings/scripts/scripts/guard/guards.cpp @@ -3980,75 +3980,75 @@ void AddSC_guards() newscript->pGossipHello = &GossipHello_guard_azuremyst; newscript->pGossipSelect = &GossipSelect_guard_azuremyst; newscript->GetAI = GetAI_guard_azuremyst; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_bluffwatcher"; newscript->pGossipHello = &GossipHello_guard_bluffwatcher; newscript->pGossipSelect = &GossipSelect_guard_bluffwatcher; newscript->GetAI = GetAI_guard_bluffwatcher; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_contested"; newscript->GetAI = GetAI_guard_contested; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_darnassus"; newscript->pGossipHello = &GossipHello_guard_darnassus; newscript->pGossipSelect = &GossipSelect_guard_darnassus; newscript->GetAI = GetAI_guard_darnassus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_dunmorogh"; newscript->pGossipHello = &GossipHello_guard_dunmorogh; newscript->pGossipSelect = &GossipSelect_guard_dunmorogh; newscript->GetAI = GetAI_guard_dunmorogh; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_durotar"; newscript->pGossipHello = &GossipHello_guard_durotar; newscript->pGossipSelect = &GossipSelect_guard_durotar; newscript->GetAI = GetAI_guard_durotar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_elwynnforest"; newscript->pGossipHello = &GossipHello_guard_elwynnforest; newscript->pGossipSelect = &GossipSelect_guard_elwynnforest; newscript->GetAI = GetAI_guard_elwynnforest; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_eversong"; newscript->pGossipHello = &GossipHello_guard_eversong; newscript->pGossipSelect = &GossipSelect_guard_eversong; newscript->GetAI = GetAI_guard_eversong; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_exodar"; newscript->pGossipHello = &GossipHello_guard_exodar; newscript->pGossipSelect = &GossipSelect_guard_exodar; newscript->GetAI = GetAI_guard_exodar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_ironforge"; newscript->pGossipHello = &GossipHello_guard_ironforge; newscript->pGossipSelect = &GossipSelect_guard_ironforge; newscript->GetAI = GetAI_guard_ironforge; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_mulgore"; newscript->pGossipHello = &GossipHello_guard_mulgore; newscript->pGossipSelect = &GossipSelect_guard_mulgore; newscript->GetAI = GetAI_guard_mulgore; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_orgrimmar"; @@ -4056,35 +4056,35 @@ void AddSC_guards() newscript->pGossipSelect = &GossipSelect_guard_orgrimmar; newscript->pReceiveEmote = &ReceiveEmote_guard_orgrimmar; newscript->GetAI = GetAI_guard_orgrimmar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_shattrath"; newscript->pGossipHello = &GossipHello_guard_shattrath; newscript->pGossipSelect = &GossipSelect_guard_shattrath; newscript->GetAI = GetAI_guard_shattrath; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_shattrath_aldor"; newscript->GetAI = GetAI_guard_shattrath_aldor; newscript->pGossipHello = &GossipHello_guard_shattrath_aldor; newscript->pGossipSelect = &GossipSelect_guard_shattrath_aldor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_shattrath_scryer"; newscript->GetAI = GetAI_guard_shattrath_scryer; newscript->pGossipHello = &GossipHello_guard_shattrath_scryer; newscript->pGossipSelect = &GossipSelect_guard_shattrath_scryer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_silvermoon"; newscript->pGossipHello = &GossipHello_guard_silvermoon; newscript->pGossipSelect = &GossipSelect_guard_silvermoon; newscript->GetAI = GetAI_guard_silvermoon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_stormwind"; @@ -4092,26 +4092,26 @@ void AddSC_guards() newscript->pGossipSelect = &GossipSelect_guard_stormwind; newscript->pReceiveEmote = &ReceiveEmote_guard_stormwind; newscript->GetAI = GetAI_guard_stormwind; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_teldrassil"; newscript->pGossipHello = &GossipHello_guard_teldrassil; newscript->pGossipSelect = &GossipSelect_guard_teldrassil; newscript->GetAI = GetAI_guard_teldrassil; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_tirisfal"; newscript->pGossipHello = &GossipHello_guard_tirisfal; newscript->pGossipSelect = &GossipSelect_guard_tirisfal; newscript->GetAI = GetAI_guard_tirisfal; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="guard_undercity"; newscript->pGossipHello = &GossipHello_guard_undercity; newscript->pGossipSelect = &GossipSelect_guard_undercity; newscript->GetAI = GetAI_guard_undercity; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/item/item_scripts.cpp b/src/bindings/scripts/scripts/item/item_scripts.cpp index 42ab5914262..372f438753c 100644 --- a/src/bindings/scripts/scripts/item/item_scripts.cpp +++ b/src/bindings/scripts/scripts/item/item_scripts.cpp @@ -455,95 +455,95 @@ void AddSC_item_scripts() newscript = new Script; newscript->Name="item_area_52_special"; newscript->pItemUse = ItemUse_item_area_52_special; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_arcane_charges"; newscript->pItemUse = ItemUse_item_arcane_charges; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_attuned_crystal_cores"; newscript->pItemUse = ItemUse_item_attuned_crystal_cores; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_blackwhelp_net"; newscript->pItemUse = ItemUse_item_blackwhelp_net; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_disciplinary_rod"; newscript->pItemUse = ItemUse_item_disciplinary_rod; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_draenei_fishing_net"; newscript->pItemUse = ItemUse_item_draenei_fishing_net; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_nether_wraith_beacon"; newscript->pItemUse = ItemUse_item_nether_wraith_beacon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_flying_machine"; newscript->pItemUse = ItemUse_item_flying_machine; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_gor_dreks_ointment"; newscript->pItemUse = ItemUse_item_gor_dreks_ointment; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_muiseks_vessel"; newscript->pItemUse = ItemUse_item_muiseks_vessel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_razorthorn_flayer_gland"; newscript->pItemUse = ItemUse_item_razorthorn_flayer_gland; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_tame_beast_rods"; newscript->pItemUse = ItemUse_item_tame_beast_rods; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_protovoltaic_magneto_collector"; newscript->pItemUse = ItemUse_item_protovoltaic_magneto_collector; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_soul_cannon"; newscript->pItemUse = ItemUse_item_soul_cannon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_sparrowhawk_net"; newscript->pItemUse = ItemUse_item_sparrowhawk_net; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_voodoo_charm"; newscript->pItemUse = ItemUse_item_voodoo_charm; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_vorenthals_presence"; newscript->pItemUse = ItemUse_item_vorenthals_presence; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_yehkinyas_bramble"; newscript->pItemUse = ItemUse_item_yehkinyas_bramble; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_zezzaks_shard"; newscript->pItemUse = ItemUse_item_zezzak_shard; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/item/item_test.cpp b/src/bindings/scripts/scripts/item/item_test.cpp index a1e3b6c13c1..1dce7157e21 100644 --- a/src/bindings/scripts/scripts/item/item_test.cpp +++ b/src/bindings/scripts/scripts/item/item_test.cpp @@ -38,5 +38,5 @@ void AddSC_item_test() newscript = new Script; newscript->Name="item_test"; newscript->pItemUse = ItemUse_item_test; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/npc/npc_innkeeper.cpp b/src/bindings/scripts/scripts/npc/npc_innkeeper.cpp index d0faf45c792..efc5e4b7b3a 100644 --- a/src/bindings/scripts/scripts/npc/npc_innkeeper.cpp +++ b/src/bindings/scripts/scripts/npc/npc_innkeeper.cpp @@ -140,5 +140,5 @@ void AddSC_npc_innkeeper() newscript->Name="npc_innkeeper"; newscript->pGossipHello = &GossipHello_npc_innkeeper; newscript->pGossipSelect = &GossipSelect_npc_innkeeper; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/npc/npc_professions.cpp b/src/bindings/scripts/scripts/npc/npc_professions.cpp index 30ecfc6788d..5061f195910 100644 --- a/src/bindings/scripts/scripts/npc/npc_professions.cpp +++ b/src/bindings/scripts/scripts/npc/npc_professions.cpp @@ -1177,29 +1177,29 @@ void AddSC_npc_professions() newscript->Name="npc_prof_alchemy"; newscript->pGossipHello = &GossipHello_npc_prof_alchemy; newscript->pGossipSelect = &GossipSelect_npc_prof_alchemy; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_prof_blacksmith"; newscript->pGossipHello = &GossipHello_npc_prof_blacksmith; newscript->pGossipSelect = &GossipSelect_npc_prof_blacksmith; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_prof_leather"; newscript->pGossipHello = &GossipHello_npc_prof_leather; newscript->pGossipSelect = &GossipSelect_npc_prof_leather; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_prof_tailor"; newscript->pGossipHello = &GossipHello_npc_prof_tailor; newscript->pGossipSelect = &GossipSelect_npc_prof_tailor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); /*newscript = new Script; newscript->Name="go_soothsaying_for_dummies"; newscript->pGOHello = &GOHello_go_soothsaying_for_dummies; //newscript->pGossipSelect = &GossipSelect_go_soothsaying_for_dummies; - m_scripts[nrscripts++] = newscript;*/ + newscript->RegisterSelf();*/ } diff --git a/src/bindings/scripts/scripts/npc/npcs_special.cpp b/src/bindings/scripts/scripts/npc/npcs_special.cpp index 3e1cb0a9165..00116746a68 100644 --- a/src/bindings/scripts/scripts/npc/npcs_special.cpp +++ b/src/bindings/scripts/scripts/npc/npcs_special.cpp @@ -835,44 +835,44 @@ void AddSC_npcs_special() newscript->pReceiveEmote = &ReceiveEmote_npc_chicken_cluck; newscript->pQuestAccept = &QuestAccept_npc_chicken_cluck; newscript->pQuestComplete = &QuestComplete_npc_chicken_cluck; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_dancing_flames"; newscript->pReceiveEmote = &ReceiveEmote_npc_dancing_flames; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_injured_patient"; newscript->GetAI = GetAI_npc_injured_patient; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_doctor"; newscript->GetAI = GetAI_npc_doctor; newscript->pQuestAccept = &QuestAccept_npc_doctor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_guardian"; newscript->GetAI = GetAI_npc_guardian; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_mount_vendor"; newscript->pGossipHello = &GossipHello_npc_mount_vendor; newscript->pGossipSelect = &GossipSelect_npc_mount_vendor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_rogue_trainer"; newscript->pGossipHello = &GossipHello_npc_rogue_trainer; newscript->pGossipSelect = &GossipSelect_npc_rogue_trainer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_sayge"; newscript->pGossipHello = &GossipHello_npc_sayge; newscript->pGossipSelect = &GossipSelect_npc_sayge; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/alterac_mountains/alterac_mountains.cpp b/src/bindings/scripts/scripts/zone/alterac_mountains/alterac_mountains.cpp index 98597afae3a..bb43a989a6b 100644 --- a/src/bindings/scripts/scripts/zone/alterac_mountains/alterac_mountains.cpp +++ b/src/bindings/scripts/scripts/zone/alterac_mountains/alterac_mountains.cpp @@ -58,5 +58,5 @@ void AddSC_alterac_mountains() newscript = new Script; newscript->Name="npc_ravenholdt"; newscript->GetAI = GetAI_npc_ravenholdt; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/auchenai_crypts/boss_exarch_maladaar.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/auchenai_crypts/boss_exarch_maladaar.cpp index 055e0cbdbb9..810486aede7 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/auchenai_crypts/boss_exarch_maladaar.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/auchenai_crypts/boss_exarch_maladaar.cpp @@ -348,15 +348,15 @@ void AddSC_boss_exarch_maladaar() newscript = new Script; newscript->Name="boss_exarch_maladaar"; newscript->GetAI = GetAI_boss_exarch_maladaar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_avatar_of_martyred"; newscript->GetAI = GetAI_mob_avatar_of_martyred; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_stolen_soul"; newscript->GetAI = GetAI_mob_stolen_soul; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_nexusprince_shaffar.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_nexusprince_shaffar.cpp index 3db39e4f477..a9589736784 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_nexusprince_shaffar.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_nexusprince_shaffar.cpp @@ -271,10 +271,10 @@ void AddSC_boss_nexusprince_shaffar() newscript = new Script; newscript->Name="boss_nexusprince_shaffar"; newscript->GetAI = GetAI_boss_nexusprince_shaffar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_ethereal_beacon"; newscript->GetAI = GetAI_mob_ethereal_beacon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_pandemonius.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_pandemonius.cpp index d4c950c754b..3542c3e484a 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_pandemonius.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/mana_tombs/boss_pandemonius.cpp @@ -134,5 +134,5 @@ void AddSC_boss_pandemonius() newscript = new Script; newscript->Name="boss_pandemonius"; newscript->GetAI = GetAI_boss_pandemonius; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_darkweaver_syth.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_darkweaver_syth.cpp index 1b77d81a908..0581e9ac3af 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_darkweaver_syth.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_darkweaver_syth.cpp @@ -392,25 +392,25 @@ void AddSC_boss_darkweaver_syth() newscript = new Script; newscript->Name="boss_darkweaver_syth"; newscript->GetAI = GetAI_boss_darkweaver_syth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_syth_fire"; newscript->GetAI = GetAI_mob_syth_arcane; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_syth_arcane"; newscript->GetAI = GetAI_mob_syth_arcane; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_syth_frost"; newscript->GetAI = GetAI_mob_syth_frost; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_syth_shadow"; newscript->GetAI = GetAI_mob_syth_shadow; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_tailonking_ikiss.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_tailonking_ikiss.cpp index ab9cd0f083b..be69ee79844 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_tailonking_ikiss.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/boss_tailonking_ikiss.cpp @@ -219,5 +219,5 @@ void AddSC_boss_talon_king_ikiss() newscript = new Script; newscript->Name="boss_talon_king_ikiss"; newscript->GetAI = GetAI_boss_talon_king_ikiss; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/instance_sethekk_halls.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/instance_sethekk_halls.cpp index b49d18445c2..4ae6ad5c7a4 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/instance_sethekk_halls.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/sethekk_halls/instance_sethekk_halls.cpp @@ -70,5 +70,5 @@ void AddSC_instance_sethekk_halls() newscript = new Script; newscript->Name = "instance_sethekk_halls"; newscript->GetInstanceData = GetInstanceData_instance_sethekk_halls; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_ambassador_hellmaw.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_ambassador_hellmaw.cpp index e565becfaba..20bf7c2d95e 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_ambassador_hellmaw.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_ambassador_hellmaw.cpp @@ -194,5 +194,5 @@ void AddSC_boss_ambassador_hellmaw() newscript = new Script; newscript->Name="boss_ambassador_hellmaw"; newscript->GetAI = GetAI_boss_ambassador_hellmaw; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_blackheart_the_inciter.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_blackheart_the_inciter.cpp index ed2784471b3..8dd0a5f7060 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_blackheart_the_inciter.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_blackheart_the_inciter.cpp @@ -173,5 +173,5 @@ void AddSC_boss_blackheart_the_inciter() newscript = new Script; newscript->Name="boss_blackheart_the_inciter"; newscript->GetAI = GetAI_boss_blackheart_the_inciter; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp index 79553b85ff2..ed7108ad3e7 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_grandmaster_vorpil.cpp @@ -363,10 +363,10 @@ void AddSC_boss_grandmaster_vorpil() newscript = new Script; newscript->Name="boss_grandmaster_vorpil"; newscript->GetAI = GetAI_boss_grandmaster_vorpil; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_voidtraveler"; newscript->GetAI = GetAI_mob_voidtraveler; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_murmur.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_murmur.cpp index 5b223b8d5ad..a5c387dc317 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_murmur.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/boss_murmur.cpp @@ -148,5 +148,5 @@ void AddSC_boss_murmur() newscript = new Script; newscript->Name="boss_murmur"; newscript->GetAI = GetAI_boss_murmur; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/instance_shadow_labyrinth.cpp b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/instance_shadow_labyrinth.cpp index 1d482754cbc..ff5afc179e2 100644 --- a/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/instance_shadow_labyrinth.cpp +++ b/src/bindings/scripts/scripts/zone/aunchindoun/shadow_labyrinth/instance_shadow_labyrinth.cpp @@ -174,5 +174,5 @@ void AddSC_instance_shadow_labyrinth() newscript = new Script; newscript->Name = "instance_shadow_labyrinth"; newscript->GetInstanceData = GetInstanceData_instance_shadow_labyrinth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/azshara/azshara.cpp b/src/bindings/scripts/scripts/zone/azshara/azshara.cpp index 92c522fba60..5a62f5ee6c5 100644 --- a/src/bindings/scripts/scripts/zone/azshara/azshara.cpp +++ b/src/bindings/scripts/scripts/zone/azshara/azshara.cpp @@ -492,23 +492,23 @@ void AddSC_azshara() newscript = new Script; newscript->Name="mobs_spitelashes"; newscript->GetAI = GetAI_mobs_spitelashes; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_loramus_thalipedes"; newscript->pGossipHello = &GossipHello_npc_loramus_thalipedes; newscript->pGossipSelect = &GossipSelect_npc_loramus_thalipedes; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_rizzle_sprysprocket"; newscript->GetAI = GetAI_mob_rizzle_sprysprocket; newscript->pGossipHello = &GossipHello_mob_rizzle_sprysprocket; newscript->pGossipSelect = &GossipSelect_mob_rizzle_sprysprocket; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_depth_charge"; newscript->GetAI = GetAI_mob_depth_charge; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/azshara/boss_azuregos.cpp b/src/bindings/scripts/scripts/zone/azshara/boss_azuregos.cpp index 2908dc04285..f688892d709 100644 --- a/src/bindings/scripts/scripts/zone/azshara/boss_azuregos.cpp +++ b/src/bindings/scripts/scripts/zone/azshara/boss_azuregos.cpp @@ -149,5 +149,5 @@ void AddSC_boss_azuregos() newscript = new Script; newscript->Name="boss_azuregos"; newscript->GetAI = GetAI_boss_azuregos; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp b/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp index 43209b64ba8..03e26504228 100644 --- a/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp +++ b/src/bindings/scripts/scripts/zone/azuremyst_isle/azuremyst_isle.cpp @@ -350,23 +350,23 @@ void AddSC_azuremyst_isle() newscript = new Script; newscript->Name="npc_draenei_survivor"; newscript->GetAI = GetAI_npc_draenei_survivor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_engineer_spark_overgrind"; newscript->GetAI = GetAI_npc_engineer_spark_overgrind; newscript->pGossipHello = &GossipHello_npc_engineer_spark_overgrind; newscript->pGossipSelect = &GossipSelect_npc_engineer_spark_overgrind; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_injured_draenei"; newscript->GetAI = GetAI_npc_injured_draenei; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_susurrus"; newscript->pGossipHello = &GossipHello_npc_susurrus; newscript->pGossipSelect = &GossipSelect_npc_susurrus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/barrens/the_barrens.cpp b/src/bindings/scripts/scripts/zone/barrens/the_barrens.cpp index 788f4e2b8ce..468efc4d6a3 100644 --- a/src/bindings/scripts/scripts/zone/barrens/the_barrens.cpp +++ b/src/bindings/scripts/scripts/zone/barrens/the_barrens.cpp @@ -369,22 +369,22 @@ void AddSC_the_barrens() newscript->Name="npc_beaten_corpse"; newscript->pGossipHello = &GossipHello_npc_beaten_corpse; newscript->pGossipSelect = &GossipSelect_npc_beaten_corpse; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_sputtervalve"; newscript->pGossipHello = &GossipHello_npc_sputtervalve; newscript->pGossipSelect = &GossipSelect_npc_sputtervalve; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_taskmaster_fizzule"; newscript->GetAI = GetAI_npc_taskmaster_fizzule; newscript->pReceiveEmote = &ReciveEmote_npc_taskmaster_fizzule; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_twiggy_flathead"; newscript->GetAI = GetAI_npc_twiggy_flathead; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/black_temple.cpp b/src/bindings/scripts/scripts/zone/black_temple/black_temple.cpp index 757f6acef06..68b581bae1c 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/black_temple.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/black_temple.cpp @@ -64,5 +64,5 @@ void AddSC_black_temple() newscript->Name = "npc_spirit_of_olum"; newscript->pGossipHello = GossipHello_npc_spirit_of_olum; newscript->pGossipSelect = GossipSelect_npc_spirit_of_olum; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_bloodboil.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_bloodboil.cpp index 44bf36cad93..3f56e3cd59b 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_bloodboil.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_bloodboil.cpp @@ -361,5 +361,5 @@ void AddSC_boss_gurtogg_bloodboil() newscript = new Script; newscript->Name="boss_gurtogg_bloodboil"; newscript->GetAI = GetAI_boss_gurtogg_bloodboil; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_illidan.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_illidan.cpp index ce03d8eac3a..c7f2ec460d9 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_illidan.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_illidan.cpp @@ -2247,52 +2247,52 @@ void AddSC_boss_illidan() newscript = new Script; newscript->Name = "boss_illidan_stormrage"; newscript->GetAI = GetAI_boss_illidan_stormrage; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_akama_illidan"; newscript->GetAI = GetAI_npc_akama_at_illidan; newscript->pGossipHello = GossipHello_npc_akama_at_illidan; newscript->pGossipSelect = GossipSelect_npc_akama_at_illidan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "boss_maiev_shadowsong"; newscript->GetAI = GetAI_boss_maiev; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_flame_of_azzinoth"; newscript->GetAI = GetAI_mob_flame_of_azzinoth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_blade_of_azzinoth"; newscript->GetAI = GetAI_blade_of_azzinoth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "gameobject_cage_trap"; newscript->pGOHello = GOHello_cage_trap; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_cage_trap_trigger"; newscript->GetAI = &GetAI_cage_trap_trigger; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_shadow_demon"; newscript->GetAI = GetAI_shadow_demon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_demon_fire"; newscript->GetAI = GetAI_demonfire; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_parasitic_shadowfiend"; newscript->GetAI = GetAI_parasitic_shadowfiend; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_mother_shahraz.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_mother_shahraz.cpp index 0f5d2af3c22..ee8a2c8348e 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_mother_shahraz.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_mother_shahraz.cpp @@ -357,5 +357,5 @@ void AddSC_boss_mother_shahraz() newscript = new Script; newscript->Name="boss_mother_shahraz"; newscript->GetAI = GetAI_boss_shahraz; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_reliquary_of_souls.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_reliquary_of_souls.cpp index 3d6233ca3f7..8c5bdbc4a4a 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_reliquary_of_souls.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_reliquary_of_souls.cpp @@ -723,25 +723,25 @@ void AddSC_boss_reliquary_of_souls() newscript = new Script; newscript->Name="boss_reliquary_of_souls"; newscript->GetAI = GetAI_boss_reliquary_of_souls; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_essence_of_suffering"; newscript->GetAI = GetAI_boss_essence_of_suffering; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_essence_of_desire"; newscript->GetAI = GetAI_boss_essence_of_desire; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_essence_of_anger"; newscript->GetAI = GetAI_boss_essence_of_anger; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_enslaved_soul"; newscript->GetAI = GetAI_npc_enslaved_soul; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp index 9c1d50950dc..3cd73df1bc7 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_shade_of_akama.cpp @@ -796,22 +796,22 @@ void AddSC_boss_shade_of_akama() newscript = new Script; newscript->Name="boss_shade_of_akama"; newscript->GetAI = GetAI_boss_shade_of_akama; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_ashtongue_channeler"; newscript->GetAI = GetAI_mob_ashtongue_channeler; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_ashtongue_sorcerer"; newscript->GetAI = GetAI_mob_ashtongue_sorcerer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_akama_shade"; newscript->GetAI = GetAI_npc_akama_shade; newscript->pGossipHello = &GossipHello_npc_akama; newscript->pGossipSelect = &GossipSelect_npc_akama; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_supremus.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_supremus.cpp index d6b2e08fac0..640977d0eb9 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_supremus.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_supremus.cpp @@ -236,10 +236,10 @@ void AddSC_boss_supremus() newscript = new Script; newscript->Name="boss_supremus"; newscript->GetAI = GetAI_boss_supremus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="molten_flame"; newscript->GetAI = GetAI_molten_flame; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_teron_gorefiend.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_teron_gorefiend.cpp index e2ab402c7ff..97fcde9265f 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_teron_gorefiend.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_teron_gorefiend.cpp @@ -575,15 +575,15 @@ void AddSC_boss_teron_gorefiend() newscript = new Script; newscript->Name = "mob_doom_blossom"; newscript->GetAI = GetAI_mob_doom_blossom; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_shadowy_construct"; newscript->GetAI = GetAI_mob_shadowy_construct; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_teron_gorefiend"; newscript->GetAI = GetAI_boss_teron_gorefiend; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/boss_warlord_najentus.cpp b/src/bindings/scripts/scripts/zone/black_temple/boss_warlord_najentus.cpp index f49c2ef17c7..f2fe6f64f2f 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/boss_warlord_najentus.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/boss_warlord_najentus.cpp @@ -258,10 +258,10 @@ void AddSC_boss_najentus() newscript = new Script; newscript->Name="boss_najentus"; newscript->GetAI = GetAI_boss_najentus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "go_najentus_spine"; newscript->pGOHello = &GOHello_go_najentus_spine; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/illidari_council.cpp b/src/bindings/scripts/scripts/zone/black_temple/illidari_council.cpp index 6e5cabc034c..42197029a89 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/illidari_council.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/illidari_council.cpp @@ -855,30 +855,30 @@ void AddSC_boss_illidari_council() newscript = new Script; newscript->Name="mob_illidari_council"; newscript->GetAI = GetAI_mob_illidari_council; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_blood_elf_council_voice_trigger"; newscript->GetAI = GetAI_mob_blood_elf_council_voice_trigger; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_gathios_the_shatterer"; newscript->GetAI = GetAI_boss_gathios_the_shatterer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lady_malande"; newscript->GetAI = GetAI_boss_lady_malande; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_veras_darkshadow"; newscript->GetAI = GetAI_boss_veras_darkshadow; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_high_nethermancer_zerevor"; newscript->GetAI = GetAI_boss_high_nethermancer_zerevor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/black_temple/instance_black_temple.cpp b/src/bindings/scripts/scripts/zone/black_temple/instance_black_temple.cpp index cfeb700282b..0ff92762389 100644 --- a/src/bindings/scripts/scripts/zone/black_temple/instance_black_temple.cpp +++ b/src/bindings/scripts/scripts/zone/black_temple/instance_black_temple.cpp @@ -332,5 +332,5 @@ void AddSC_instance_black_temple() newscript = new Script; newscript->Name = "instance_black_temple"; newscript->GetInstanceData = GetInstanceData_instance_black_temple; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/blackrock_depths.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/blackrock_depths.cpp index 95a920d39a3..c6e1cbcafe9 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/blackrock_depths.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/blackrock_depths.cpp @@ -221,17 +221,17 @@ void AddSC_blackrock_depths() newscript = new Script; newscript->Name="phalanx"; newscript->GetAI = GetAI_mob_phalanx; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_kharan_mighthammer"; newscript->pGossipHello = &GossipHello_npc_kharan_mighthammer; newscript->pGossipSelect = &GossipSelect_npc_kharan_mighthammer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_lokhtos_darkbargainer"; newscript->pGossipHello = &GossipHello_npc_lokhtos_darkbargainer; newscript->pGossipSelect = &GossipSelect_npc_lokhtos_darkbargainer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_ambassador_flamelash.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_ambassador_flamelash.cpp index b63691a3b6e..2bb2a2ae004 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_ambassador_flamelash.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_ambassador_flamelash.cpp @@ -102,5 +102,5 @@ void AddSC_boss_ambassador_flamelash() newscript = new Script; newscript->Name="boss_ambassador_flamelash"; newscript->GetAI = GetAI_boss_ambassador_flamelash; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_angerrel.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_angerrel.cpp index 13b9f31e734..cbf895cc3e4 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_angerrel.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_angerrel.cpp @@ -87,5 +87,5 @@ void AddSC_boss_angerrel() newscript = new Script; newscript->Name="boss_angerrel"; newscript->GetAI = GetAI_boss_angerrel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_anubshiah.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_anubshiah.cpp index 50cf2af8169..091863de655 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_anubshiah.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_anubshiah.cpp @@ -111,5 +111,5 @@ void AddSC_boss_anubshiah() newscript = new Script; newscript->Name="boss_anubshiah"; newscript->GetAI = GetAI_boss_anubshiah; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doomrel.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doomrel.cpp index b58ebc7b97a..867afe417cd 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doomrel.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doomrel.cpp @@ -135,5 +135,5 @@ void AddSC_boss_doomrel() newscript = new Script; newscript->Name="boss_doomrel"; newscript->GetAI = GetAI_boss_doomrel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doperel.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doperel.cpp index f9da16dd2fd..3c394476106 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doperel.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_doperel.cpp @@ -87,5 +87,5 @@ void AddSC_boss_doperel() newscript = new Script; newscript->Name="boss_doperel"; newscript->GetAI = GetAI_boss_doperel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_emperor_dagran_thaurissan.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_emperor_dagran_thaurissan.cpp index e8b1fb791ee..d463ed7f38f 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_emperor_dagran_thaurissan.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_emperor_dagran_thaurissan.cpp @@ -100,5 +100,5 @@ void AddSC_boss_draganthaurissan() newscript = new Script; newscript->Name="boss_emperor_dagran_thaurissan"; newscript->GetAI = GetAI_boss_draganthaurissan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_general_angerforge.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_general_angerforge.cpp index 0760bc65733..7e3b8d9fba7 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_general_angerforge.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_general_angerforge.cpp @@ -163,5 +163,5 @@ void AddSC_boss_general_angerforge() newscript = new Script; newscript->Name="boss_general_angerforge"; newscript->GetAI = GetAI_boss_general_angerforge; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gloomrel.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gloomrel.cpp index 30caa104b31..966fe4b8c22 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gloomrel.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gloomrel.cpp @@ -138,5 +138,5 @@ void AddSC_boss_gloomrel() newscript->GetAI = GetAI_boss_gloomrel; newscript->pGossipHello = &GossipHello_boss_gloomrel; newscript->pGossipSelect = &GossipSelect_boss_gloomrel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gorosh_the_dervish.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gorosh_the_dervish.cpp index 91770069779..f2b617b73f0 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gorosh_the_dervish.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_gorosh_the_dervish.cpp @@ -77,5 +77,5 @@ void AddSC_boss_gorosh_the_dervish() newscript = new Script; newscript->Name="boss_gorosh_the_dervish"; newscript->GetAI = GetAI_boss_gorosh_the_dervish; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_grizzle.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_grizzle.cpp index 7e489cca5a7..5005bb3935a 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_grizzle.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_grizzle.cpp @@ -82,5 +82,5 @@ void AddSC_boss_grizzle() newscript = new Script; newscript->Name="boss_grizzle"; newscript->GetAI = GetAI_boss_grizzle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_haterel.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_haterel.cpp index 778c68f73d3..53a94865002 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_haterel.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_haterel.cpp @@ -101,5 +101,5 @@ void AddSC_boss_haterel() newscript = new Script; newscript->Name="boss_haterel"; newscript->GetAI = GetAI_boss_haterel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_high_interrogator_gerstahn.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_high_interrogator_gerstahn.cpp index 8ee1a00c85b..43aa38ba4d4 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_high_interrogator_gerstahn.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_high_interrogator_gerstahn.cpp @@ -101,5 +101,5 @@ void AddSC_boss_high_interrogator_gerstahn() newscript = new Script; newscript->Name="boss_high_interrogator_gerstahn"; newscript->GetAI = GetAI_boss_high_interrogator_gerstahn; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_magmus.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_magmus.cpp index 0d163d31775..7703d6b2b31 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_magmus.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_magmus.cpp @@ -80,5 +80,5 @@ void AddSC_boss_magmus() newscript = new Script; newscript->Name="boss_magmus"; newscript->GetAI = GetAI_boss_magmus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_moira_bronzebeard.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_moira_bronzebeard.cpp index 208353e66f3..68923722380 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_moira_bronzebeard.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_moira_bronzebeard.cpp @@ -95,5 +95,5 @@ void AddSC_boss_moira_bronzebeard() newscript = new Script; newscript->Name="boss_moira_bronzebeard"; newscript->GetAI = GetAI_boss_moira_bronzebeard; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_seethrel.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_seethrel.cpp index 93f3c124f29..e8753971898 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_seethrel.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_seethrel.cpp @@ -111,5 +111,5 @@ void AddSC_boss_seethrel() newscript = new Script; newscript->Name="boss_seethrel"; newscript->GetAI = GetAI_boss_seethrel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_vilerel.cpp b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_vilerel.cpp index 0ecf70148fe..db1b0923f4c 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_depths/boss_vilerel.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_depths/boss_vilerel.cpp @@ -97,5 +97,5 @@ void AddSC_boss_vilerel() newscript = new Script; newscript->Name="boss_vilerel"; newscript->GetAI = GetAI_boss_vilerel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_drakkisath.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_drakkisath.cpp index c26ba2ed6b9..56f4b3f385f 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_drakkisath.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_drakkisath.cpp @@ -97,5 +97,5 @@ void AddSC_boss_drakkisath() newscript = new Script; newscript->Name="boss_drakkisath"; newscript->GetAI = GetAI_boss_drakkisath; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_gyth.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_gyth.cpp index 68107e820bf..d6089c269e7 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_gyth.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_gyth.cpp @@ -201,5 +201,5 @@ void AddSC_boss_gyth() newscript = new Script; newscript->Name="boss_gyth"; newscript->GetAI = GetAI_boss_gyth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_halycon.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_halycon.cpp index 0b2c09acccf..e0c5d69d631 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_halycon.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_halycon.cpp @@ -91,5 +91,5 @@ void AddSC_boss_halycon() newscript = new Script; newscript->Name="boss_halycon"; newscript->GetAI = GetAI_boss_halycon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_highlord_omokk.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_highlord_omokk.cpp index afaedcc4ad8..0ee0a9df7f8 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_highlord_omokk.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_highlord_omokk.cpp @@ -127,5 +127,5 @@ void AddSC_boss_highlordomokk() newscript = new Script; newscript->Name="boss_highlord_omokk"; newscript->GetAI = GetAI_boss_highlordomokk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_mother_smolderweb.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_mother_smolderweb.cpp index 8c1d3096597..c9686346057 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_mother_smolderweb.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_mother_smolderweb.cpp @@ -82,5 +82,5 @@ void AddSC_boss_mothersmolderweb() newscript = new Script; newscript->Name="boss_mother_smolderweb"; newscript->GetAI = GetAI_boss_mothersmolderweb; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_overlord_wyrmthalak.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_overlord_wyrmthalak.cpp index 5ab5847e38a..5852a12302e 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_overlord_wyrmthalak.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_overlord_wyrmthalak.cpp @@ -123,5 +123,5 @@ void AddSC_boss_overlordwyrmthalak() newscript = new Script; newscript->Name="boss_overlord_wyrmthalak"; newscript->GetAI = GetAI_boss_overlordwyrmthalak; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_pyroguard_emberseer.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_pyroguard_emberseer.cpp index f7705c647af..cbabb24d752 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_pyroguard_emberseer.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_pyroguard_emberseer.cpp @@ -89,5 +89,5 @@ void AddSC_boss_pyroguard_emberseer() newscript = new Script; newscript->Name="boss_pyroguard_emberseer"; newscript->GetAI = GetAI_boss_pyroguard_emberseer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_quartermaster_zigris.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_quartermaster_zigris.cpp index 7c0901e1f40..82561cb954f 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_quartermaster_zigris.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_quartermaster_zigris.cpp @@ -81,5 +81,5 @@ void AddSC_boss_quatermasterzigris() newscript = new Script; newscript->Name="quartermaster_zigris"; newscript->GetAI = GetAI_boss_quatermasterzigris; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_rend_blackhand.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_rend_blackhand.cpp index 7ca84b3c429..b80a941ad17 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_rend_blackhand.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_rend_blackhand.cpp @@ -87,5 +87,5 @@ void AddSC_boss_rend_blackhand() newscript = new Script; newscript->Name="boss_rend_blackhand"; newscript->GetAI = GetAI_boss_rend_blackhand; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_shadow_hunter_voshgajin.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_shadow_hunter_voshgajin.cpp index 17c73e43c82..83a324a2c38 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_shadow_hunter_voshgajin.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_shadow_hunter_voshgajin.cpp @@ -91,5 +91,5 @@ void AddSC_boss_shadowvosh() newscript = new Script; newscript->Name="boss_shadow_hunter_voshgajin"; newscript->GetAI = GetAI_boss_shadowvosh; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_the_beast.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_the_beast.cpp index d7e403d0e72..586addd9d76 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_the_beast.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_the_beast.cpp @@ -89,5 +89,5 @@ void AddSC_boss_thebeast() newscript = new Script; newscript->Name="boss_the_beast"; newscript->GetAI = GetAI_boss_thebeast; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_warmaster_voone.cpp b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_warmaster_voone.cpp index 7377b46526f..bcc1469ccd9 100644 --- a/src/bindings/scripts/scripts/zone/blackrock_spire/boss_warmaster_voone.cpp +++ b/src/bindings/scripts/scripts/zone/blackrock_spire/boss_warmaster_voone.cpp @@ -117,5 +117,5 @@ void AddSC_boss_warmastervoone() newscript = new Script; newscript->Name="boss_warmaster_voone"; newscript->GetAI = GetAI_boss_warmastervoone; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_broodlord_lashlayer.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_broodlord_lashlayer.cpp index 0e40276903a..2c69e8ff599 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_broodlord_lashlayer.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_broodlord_lashlayer.cpp @@ -124,5 +124,5 @@ void AddSC_boss_broodlord() newscript = new Script; newscript->Name="boss_broodlord"; newscript->GetAI = GetAI_boss_broodlord; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_chromaggus.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_chromaggus.cpp index ea683bd1a13..920a50d4e49 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_chromaggus.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_chromaggus.cpp @@ -310,5 +310,5 @@ void AddSC_boss_chromaggus() newscript = new Script; newscript->Name="boss_chromaggus"; newscript->GetAI = GetAI_boss_chromaggus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_ebonroc.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_ebonroc.cpp index 703dec09536..0dd8095a94b 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_ebonroc.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_ebonroc.cpp @@ -99,5 +99,5 @@ void AddSC_boss_ebonroc() newscript = new Script; newscript->Name="boss_ebonroc"; newscript->GetAI = GetAI_boss_ebonroc; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_firemaw.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_firemaw.cpp index 05a3e36948b..c1915d45a15 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_firemaw.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_firemaw.cpp @@ -90,5 +90,5 @@ void AddSC_boss_firemaw() newscript = new Script; newscript->Name="boss_firemaw"; newscript->GetAI = GetAI_boss_firemaw; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_flamegor.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_flamegor.cpp index fa34406b1fe..fbc8f4fa51a 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_flamegor.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_flamegor.cpp @@ -90,5 +90,5 @@ void AddSC_boss_flamegor() newscript = new Script; newscript->Name="boss_flamegor"; newscript->GetAI = GetAI_boss_flamegor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_nefarian.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_nefarian.cpp index b819fde0bd5..741e61ba4de 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_nefarian.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_nefarian.cpp @@ -223,5 +223,5 @@ void AddSC_boss_nefarian() newscript = new Script; newscript->Name="boss_nefarian"; newscript->GetAI = GetAI_boss_nefarian; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_razorgore.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_razorgore.cpp index bf76a08897f..98615b47758 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_razorgore.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_razorgore.cpp @@ -127,5 +127,5 @@ void AddSC_boss_razorgore() newscript = new Script; newscript->Name="boss_razorgore"; newscript->GetAI = GetAI_boss_razorgore; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_vaelastrasz.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_vaelastrasz.cpp index 05e4b39af7d..a708a7de195 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_vaelastrasz.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_vaelastrasz.cpp @@ -257,5 +257,5 @@ void AddSC_boss_vael() newscript->GetAI = GetAI_boss_vael; newscript->pGossipHello = &GossipHello_boss_vael; newscript->pGossipSelect = &GossipSelect_boss_vael; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_victor_nefarius.cpp b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_victor_nefarius.cpp index c9e92c7b75f..70bb6c15113 100644 --- a/src/bindings/scripts/scripts/zone/blackwing_lair/boss_victor_nefarius.cpp +++ b/src/bindings/scripts/scripts/zone/blackwing_lair/boss_victor_nefarius.cpp @@ -390,5 +390,5 @@ void AddSC_boss_victor_nefarius() newscript->GetAI = GetAI_boss_victor_nefarius; newscript->pGossipHello = &GossipHello_boss_victor_nefarius; newscript->pGossipSelect = &GossipSelect_boss_victor_nefarius; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blades_edge_mountains/blades_edge_mountains.cpp b/src/bindings/scripts/scripts/zone/blades_edge_mountains/blades_edge_mountains.cpp index 99dc4dbc82c..c47153aed7a 100644 --- a/src/bindings/scripts/scripts/zone/blades_edge_mountains/blades_edge_mountains.cpp +++ b/src/bindings/scripts/scripts/zone/blades_edge_mountains/blades_edge_mountains.cpp @@ -406,33 +406,33 @@ void AddSC_blades_edge_mountains() newscript = new Script; newscript->Name="mobs_bladespire_ogre"; newscript->GetAI = GetAI_mobs_bladespire_ogre; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mobs_nether_drake"; newscript->GetAI = GetAI_mobs_nether_drake; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_daranelle"; newscript->GetAI = GetAI_npc_daranelle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_overseer_nuaar"; newscript->pGossipHello = &GossipHello_npc_overseer_nuaar; newscript->pGossipSelect = &GossipSelect_npc_overseer_nuaar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_saikkal_the_elder"; newscript->pGossipHello = &GossipHello_npc_saikkal_the_elder; newscript->pGossipSelect = &GossipSelect_npc_saikkal_the_elder; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_skyguard_handler_irena"; newscript->pGossipHello = &GossipHello_npc_skyguard_handler_irena; newscript->pGossipSelect = &GossipSelect_npc_skyguard_handler_irena; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blasted_lands/blasted_lands.cpp b/src/bindings/scripts/scripts/zone/blasted_lands/blasted_lands.cpp index 9212f13946a..b47abcb4c15 100644 --- a/src/bindings/scripts/scripts/zone/blasted_lands/blasted_lands.cpp +++ b/src/bindings/scripts/scripts/zone/blasted_lands/blasted_lands.cpp @@ -149,11 +149,11 @@ void AddSC_blasted_lands() newscript->Name="npc_deathly_usher"; newscript->pGossipHello = &GossipHello_npc_deathly_usher; newscript->pGossipSelect = &GossipSelect_npc_deathly_usher; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_fallen_hero_of_horde"; newscript->pGossipHello = &GossipHello_npc_fallen_hero_of_horde; newscript->pGossipSelect = &GossipSelect_npc_fallen_hero_of_horde; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/blasted_lands/boss_kruul.cpp b/src/bindings/scripts/scripts/zone/blasted_lands/boss_kruul.cpp index 9de7b6d6085..250c382f028 100644 --- a/src/bindings/scripts/scripts/zone/blasted_lands/boss_kruul.cpp +++ b/src/bindings/scripts/scripts/zone/blasted_lands/boss_kruul.cpp @@ -178,5 +178,5 @@ void AddSC_boss_kruul() newscript = new Script; newscript->Name="boss_kruul"; newscript->GetAI = GetAI_boss_kruul; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/bloodmyst_isle/bloodmyst_isle.cpp b/src/bindings/scripts/scripts/zone/bloodmyst_isle/bloodmyst_isle.cpp index e52386fc020..3705d195ca3 100644 --- a/src/bindings/scripts/scripts/zone/bloodmyst_isle/bloodmyst_isle.cpp +++ b/src/bindings/scripts/scripts/zone/bloodmyst_isle/bloodmyst_isle.cpp @@ -131,11 +131,11 @@ void AddSC_bloodmyst_isle() newscript = new Script; newscript->Name="mob_webbed_creature"; newscript->GetAI = GetAI_mob_webbed_creature; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_captured_sunhawk_agent"; newscript->pGossipHello = &GossipHello_npc_captured_sunhawk_agent; newscript->pGossipSelect = &GossipSelect_npc_captured_sunhawk_agent; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/burning_steppes/burning_steppes.cpp b/src/bindings/scripts/scripts/zone/burning_steppes/burning_steppes.cpp index bd926a2e7cc..7f0c2f45118 100644 --- a/src/bindings/scripts/scripts/zone/burning_steppes/burning_steppes.cpp +++ b/src/bindings/scripts/scripts/zone/burning_steppes/burning_steppes.cpp @@ -147,5 +147,5 @@ void AddSC_burning_steppes() newscript->GetAI = GetAI_npc_ragged_john; newscript->pGossipHello = &GossipHello_npc_ragged_john; newscript->pGossipSelect = &GossipSelect_npc_ragged_john; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_aeonus.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_aeonus.cpp index f6dd7a167ff..db167ff5ab9 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_aeonus.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_aeonus.cpp @@ -117,5 +117,5 @@ void AddSC_boss_aeonus() newscript = new Script; newscript->Name="boss_aeonus"; newscript->GetAI = GetAI_boss_aeonus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_chrono_lord_deja.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_chrono_lord_deja.cpp index b6d00be0889..fcaade46067 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_chrono_lord_deja.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_chrono_lord_deja.cpp @@ -105,5 +105,5 @@ void AddSC_boss_chrono_lord_deja() newscript = new Script; newscript->Name="boss_chrono_lord_deja"; newscript->GetAI = GetAI_boss_chrono_lord_deja; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_temporus.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_temporus.cpp index a59ecc8e4b6..2dad8913576 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_temporus.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/dark_portal/boss_temporus.cpp @@ -139,5 +139,5 @@ void AddSC_boss_temporus() newscript = new Script; newscript->Name="boss_temporus"; newscript->GetAI = GetAI_boss_temporus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/boss_archimonde.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/boss_archimonde.cpp index 7e25c0c9b15..ab208aafba9 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/boss_archimonde.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/boss_archimonde.cpp @@ -769,20 +769,20 @@ void AddSC_boss_archimonde() newscript = new Script; newscript->Name="boss_archimonde"; newscript->GetAI = GetAI_boss_archimonde; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_doomfire"; newscript->GetAI = GetAI_mob_doomfire; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_doomfire_targetting"; newscript->GetAI = GetAI_mob_doomfire_targetting; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_ancient_wisp"; newscript->GetAI = GetAI_mob_ancient_wisp; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/hyjal.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/hyjal.cpp index 837f1f09872..51f147badc2 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/hyjal.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/hyjal.cpp @@ -200,18 +200,18 @@ void AddSC_hyjal() newscript->GetAI = GetAI_npc_jaina_proudmoore; newscript->pGossipHello = &GossipHello_npc_jaina_proudmoore; newscript->pGossipSelect = &GossipSelect_npc_jaina_proudmoore; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_thrall"; newscript->GetAI = GetAI_npc_thrall; newscript->pGossipHello = &GossipHello_npc_thrall; newscript->pGossipSelect = &GossipSelect_npc_thrall; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_tyrande_whisperwind"; newscript->pGossipHello = &GossipHello_npc_tyrande_whisperwind; newscript->pGossipSelect = &GossipSelect_npc_tyrande_whisperwind; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/instance_hyjal.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/instance_hyjal.cpp index a6f8e3a7305..3c3971d6036 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/instance_hyjal.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/hyjal/instance_hyjal.cpp @@ -199,5 +199,5 @@ void AddSC_instance_mount_hyjal() newscript = new Script; newscript->Name = "instance_hyjal"; newscript->GetInstanceData = GetInstanceData_instance_mount_hyjal; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_captain_skarloc.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_captain_skarloc.cpp index 19aff777b23..c43f5c2471c 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_captain_skarloc.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_captain_skarloc.cpp @@ -152,5 +152,5 @@ void AddSC_boss_captain_skarloc() newscript = new Script; newscript->Name="boss_captain_skarloc"; newscript->GetAI = GetAI_boss_captain_skarloc; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_epoch_hunter.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_epoch_hunter.cpp index 734ea93ffbe..510ef7a039f 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_epoch_hunter.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_epoch_hunter.cpp @@ -146,5 +146,5 @@ void AddSC_boss_epoch_hunter() newscript = new Script; newscript->Name="boss_epoch_hunter"; newscript->GetAI = GetAI_boss_epoch_hunter; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_leutenant_drake.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_leutenant_drake.cpp index 6733e4b8d41..76d96775056 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_leutenant_drake.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/boss_leutenant_drake.cpp @@ -194,10 +194,10 @@ void AddSC_boss_lieutenant_drake() newscript = new Script; newscript->Name="go_barrel_old_hillsbrad"; newscript->pGOHello = &GOHello_go_barrel_old_hillsbrad; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lieutenant_drake"; newscript->GetAI = GetAI_boss_lieutenant_drake; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/instance_old_hillsbrad.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/instance_old_hillsbrad.cpp index a6e4b377358..38a20c8adaf 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/instance_old_hillsbrad.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/instance_old_hillsbrad.cpp @@ -174,5 +174,5 @@ void AddSC_instance_old_hillsbrad() newscript = new Script; newscript->Name = "instance_old_hillsbrad"; newscript->GetInstanceData = GetInstanceData_instance_old_hillsbrad; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/old_hillsbrad.cpp b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/old_hillsbrad.cpp index 659636e1d35..596d327bc42 100644 --- a/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/old_hillsbrad.cpp +++ b/src/bindings/scripts/scripts/zone/caverns_of_time/old_hillsbrad/old_hillsbrad.cpp @@ -893,24 +893,24 @@ void AddSC_old_hillsbrad() newscript->Name="npc_brazen"; newscript->pGossipHello = &GossipHello_npc_brazen; newscript->pGossipSelect = &GossipSelect_npc_brazen; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_erozion"; newscript->pGossipHello = &GossipHello_npc_erozion; newscript->pGossipSelect = &GossipSelect_npc_erozion; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_thrall_old_hillsbrad"; newscript->pGossipHello = &GossipHello_npc_thrall_old_hillsbrad; newscript->pGossipSelect = &GossipSelect_npc_thrall_old_hillsbrad; newscript->GetAI = GetAI_npc_thrall_old_hillsbrad; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_taretha"; newscript->pGossipHello = &GossipHello_npc_taretha; newscript->pGossipSelect = &GossipSelect_npc_taretha; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_fathomlord_karathress.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_fathomlord_karathress.cpp index 9199bcadaf1..42a707ff930 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_fathomlord_karathress.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_fathomlord_karathress.cpp @@ -744,20 +744,20 @@ void AddSC_boss_fathomlord_karathress() newscript = new Script; newscript->Name="boss_fathomlord_karathress"; newscript->GetAI = GetAI_boss_fathomlord_karathress; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_fathomguard_sharkkis"; newscript->GetAI = GetAI_boss_fathomguard_sharkkis; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_fathomguard_tidalvess"; newscript->GetAI = GetAI_boss_fathomguard_tidalvess; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_fathomguard_caribdis"; newscript->GetAI = GetAI_boss_fathomguard_caribdis; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_hydross_the_unstable.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_hydross_the_unstable.cpp index 13b8ebbf312..07adcf4b225 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_hydross_the_unstable.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_hydross_the_unstable.cpp @@ -382,5 +382,5 @@ void AddSC_boss_hydross_the_unstable() newscript = new Script; newscript->Name="boss_hydross_the_unstable"; newscript->GetAI = GetAI_boss_hydross_the_unstable; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp index 49f750acb6c..232a828150c 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lady_vashj.cpp @@ -1029,42 +1029,42 @@ void AddSC_boss_lady_vashj() newscript = new Script; newscript->Name="boss_lady_vashj"; newscript->GetAI = GetAI_boss_lady_vashj; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_enchanted_elemental"; newscript->GetAI = GetAI_mob_enchanted_elemental; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_tainted_elemental"; newscript->GetAI = GetAI_mob_tainted_elemental; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_toxic_sporebat"; newscript->GetAI = GetAI_mob_toxic_sporebat; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_coilfang_elite"; newscript->GetAI = GetAI_mob_coilfang_elite; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_coilfang_strider"; newscript->GetAI = GetAI_mob_coilfang_strider; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_shield_generator_channel"; newscript->GetAI = GetAI_mob_shield_generator_channel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="item_tainted_core"; newscript->pItemUse = ItemUse_item_tainted_core; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp index 913eef3ec4e..70d4d6d2c56 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_leotheras_the_blind.cpp @@ -804,20 +804,20 @@ void AddSC_boss_leotheras_the_blind() newscript = new Script; newscript->Name="boss_leotheras_the_blind"; newscript->GetAI = GetAI_boss_leotheras_the_blind; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_leotheras_the_blind_demonform"; newscript->GetAI = GetAI_boss_leotheras_the_blind_demonform; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_greyheart_spellbinder"; newscript->GetAI = GetAI_mob_greyheart_spellbinder; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_inner_demon"; newscript->GetAI = GetAI_mob_inner_demon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lurker_below.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lurker_below.cpp index 924b15397ed..509eadc2006 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lurker_below.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_lurker_below.cpp @@ -167,16 +167,16 @@ void AddSC_boss_the_lurker_below() newscript = new Script; newscript->Name="boss_the_lurker_below"; newscript->GetAI = GetAI_boss_the_lurker_below; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_coilfang_guardian"; newscript->GetAI = GetAI_mob_coilfang_guardian; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_coilfang_ambusher"; newscript->GetAI = GetAI_mob_coilfang_ambusher; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_morogrim_tidewalker.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_morogrim_tidewalker.cpp index fa6a57a7fe4..900c3aad6d9 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_morogrim_tidewalker.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/boss_morogrim_tidewalker.cpp @@ -350,10 +350,10 @@ void AddSC_boss_morogrim_tidewalker() newscript = new Script; newscript->Name="boss_morogrim_tidewalker"; newscript->GetAI = GetAI_boss_morogrim_tidewalker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_water_globule"; newscript->GetAI = GetAI_mob_water_globule; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/instance_serpent_shrine.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/instance_serpent_shrine.cpp index de0f829c3d1..25b6a1a54d5 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/instance_serpent_shrine.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/serpent_shrine/instance_serpent_shrine.cpp @@ -215,5 +215,5 @@ void AddSC_instance_serpentshrine_cavern() newscript = new Script; newscript->Name = "instance_serpent_shrine"; newscript->GetInstanceData = GetInstanceData_instance_serpentshrine_cavern; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_hydromancer_thespia.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_hydromancer_thespia.cpp index f51a28d61b3..cb09a94044f 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_hydromancer_thespia.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_hydromancer_thespia.cpp @@ -188,10 +188,10 @@ void AddSC_boss_hydromancer_thespia() newscript = new Script; newscript->Name="boss_hydromancer_thespia"; newscript->GetAI = GetAI_boss_thespiaAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_coilfang_waterelemental"; newscript->GetAI = GetAI_mob_coilfang_waterelementalAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_mekgineer_steamrigger.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_mekgineer_steamrigger.cpp index d769b44d9cf..6f839359d0a 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_mekgineer_steamrigger.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_mekgineer_steamrigger.cpp @@ -271,10 +271,10 @@ void AddSC_boss_mekgineer_steamrigger() newscript = new Script; newscript->Name="boss_mekgineer_steamrigger"; newscript->GetAI = GetAI_boss_mekgineer_steamrigger; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_steamrigger_mechanic"; newscript->GetAI = GetAI_mob_steamrigger_mechanic; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_warlord_kalithresh.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_warlord_kalithresh.cpp index 85c6657bebb..a3b3c68ba82 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_warlord_kalithresh.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/boss_warlord_kalithresh.cpp @@ -226,10 +226,10 @@ void AddSC_boss_warlord_kalithresh() newscript = new Script; newscript->Name="mob_naga_distiller"; newscript->GetAI = GetAI_mob_naga_distiller; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_warlord_kalithresh"; newscript->GetAI = GetAI_boss_warlord_kalithresh; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/instance_steam_vault.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/instance_steam_vault.cpp index 798d04d6cfb..dc082244846 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/instance_steam_vault.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/steam_vault/instance_steam_vault.cpp @@ -166,5 +166,5 @@ void AddSC_instance_steam_vault() newscript = new Script; newscript->Name = "instance_steam_vault"; newscript->GetInstanceData = GetInstanceData_instance_steam_vault; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/coilfang_resevoir/underbog/boss_hungarfen.cpp b/src/bindings/scripts/scripts/zone/coilfang_resevoir/underbog/boss_hungarfen.cpp index 13ac880295b..34c854ad8bf 100644 --- a/src/bindings/scripts/scripts/zone/coilfang_resevoir/underbog/boss_hungarfen.cpp +++ b/src/bindings/scripts/scripts/zone/coilfang_resevoir/underbog/boss_hungarfen.cpp @@ -147,10 +147,10 @@ void AddSC_boss_hungarfen() newscript = new Script; newscript->Name="boss_hungarfen"; newscript->GetAI = GetAI_boss_hungarfen; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_underbog_mushroom"; newscript->GetAI = GetAI_mob_underbog_mushroom; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/dun_morogh/dun_morogh.cpp b/src/bindings/scripts/scripts/zone/dun_morogh/dun_morogh.cpp index c5f7bf6fc07..ee8c531593b 100644 --- a/src/bindings/scripts/scripts/zone/dun_morogh/dun_morogh.cpp +++ b/src/bindings/scripts/scripts/zone/dun_morogh/dun_morogh.cpp @@ -94,5 +94,5 @@ void AddSC_dun_morogh() newscript = new Script; newscript->Name="npc_narm_faulk"; newscript->GetAI = GetAI_npc_narm_faulk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/dustwallow_marsh/dustwallow_marsh.cpp b/src/bindings/scripts/scripts/zone/dustwallow_marsh/dustwallow_marsh.cpp index 7a8c1329b36..16e5d3fc62e 100644 --- a/src/bindings/scripts/scripts/zone/dustwallow_marsh/dustwallow_marsh.cpp +++ b/src/bindings/scripts/scripts/zone/dustwallow_marsh/dustwallow_marsh.cpp @@ -204,28 +204,28 @@ void AddSC_dustwallow_marsh() newscript = new Script; newscript->Name="mobs_risen_husk_spirit"; newscript->GetAI = GetAI_mobs_risen_husk_spirit; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_restless_apparition"; newscript->pGossipHello = &GossipHello_npc_restless_apparition; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_deserter_agitator"; newscript->GetAI = GetAI_npc_deserter_agitator; newscript->pGossipHello = &GossipHello_npc_deserter_agitator; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_lady_jaina_proudmoore"; newscript->pGossipHello = &GossipHello_npc_lady_jaina_proudmoore; newscript->pGossipSelect = &GossipSelect_npc_lady_jaina_proudmoore; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_nat_pagle"; newscript->pGossipHello = &GossipHello_npc_nat_pagle; newscript->pGossipSelect = &GossipSelect_npc_nat_pagle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/eastern_plaguelands/eastern_plaguelands.cpp b/src/bindings/scripts/scripts/zone/eastern_plaguelands/eastern_plaguelands.cpp index e8d44931f11..125fdf44817 100644 --- a/src/bindings/scripts/scripts/zone/eastern_plaguelands/eastern_plaguelands.cpp +++ b/src/bindings/scripts/scripts/zone/eastern_plaguelands/eastern_plaguelands.cpp @@ -158,23 +158,23 @@ void AddSC_eastern_plaguelands() newscript = new Script; newscript->Name="mobs_ghoul_flayer"; newscript->GetAI = GetAI_mobs_ghoul_flayer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_augustus_the_touched"; newscript->pGossipHello = &GossipHello_npc_augustus_the_touched; newscript->pGossipSelect = &GossipSelect_npc_augustus_the_touched; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_darrowshire_spirit"; newscript->GetAI = GetAI_npc_darrowshire_spirit; newscript->pGossipHello = &GossipHello_npc_darrowshire_spirit; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_tirion_fordring"; newscript->pGossipHello = &GossipHello_npc_tirion_fordring; newscript->pGossipSelect = &GossipSelect_npc_tirion_fordring; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/elwynn_forest/elwynn_forest.cpp b/src/bindings/scripts/scripts/zone/elwynn_forest/elwynn_forest.cpp index d91b4533de2..b1061213649 100644 --- a/src/bindings/scripts/scripts/zone/elwynn_forest/elwynn_forest.cpp +++ b/src/bindings/scripts/scripts/zone/elwynn_forest/elwynn_forest.cpp @@ -94,5 +94,5 @@ void AddSC_elwynn_forest() newscript = new Script; newscript->Name="npc_henze_faulk"; newscript->GetAI = GetAI_npc_henze_faulk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/eversong_woods/eversong_woods.cpp b/src/bindings/scripts/scripts/zone/eversong_woods/eversong_woods.cpp index 932dea11a60..4f9c2a775af 100644 --- a/src/bindings/scripts/scripts/zone/eversong_woods/eversong_woods.cpp +++ b/src/bindings/scripts/scripts/zone/eversong_woods/eversong_woods.cpp @@ -152,12 +152,12 @@ void AddSC_eversong_woods() newscript = new Script; newscript->Name="mobs_mana_tapped"; newscript->GetAI = GetAI_mobs_mana_tapped; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name= "npc_prospector_anvilward"; newscript->GetAI = GetAI_npc_prospector_anvilward; newscript->pGossipHello = &GossipHello_npc_prospector_anvilward; newscript->pGossipSelect = &GossipSelect_npc_prospector_anvilward; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/felwood/felwood.cpp b/src/bindings/scripts/scripts/zone/felwood/felwood.cpp index 59dc03456a4..2cd6d05579e 100644 --- a/src/bindings/scripts/scripts/zone/felwood/felwood.cpp +++ b/src/bindings/scripts/scripts/zone/felwood/felwood.cpp @@ -85,5 +85,5 @@ void AddSC_felwood() newscript->Name="npcs_riverbreeze_and_silversky"; newscript->pGossipHello = &GossipHello_npcs_riverbreeze_and_silversky; newscript->pGossipSelect = &GossipSelect_npcs_riverbreeze_and_silversky; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/feralas/feralas.cpp b/src/bindings/scripts/scripts/zone/feralas/feralas.cpp index ca8c5d0a02d..e0a89fe5905 100644 --- a/src/bindings/scripts/scripts/zone/feralas/feralas.cpp +++ b/src/bindings/scripts/scripts/zone/feralas/feralas.cpp @@ -76,10 +76,10 @@ void AddSC_feralas() newscript->Name="npc_gregan_brewspewer"; newscript->pGossipHello = &GossipHello_npc_gregan_brewspewer; newscript->pGossipSelect = &GossipSelect_npc_gregan_brewspewer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_screecher_spirit"; newscript->pGossipHello = &GossipHello_npc_screecher_spirit; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp b/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp index 35c7213d033..ade3931c75d 100644 --- a/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp +++ b/src/bindings/scripts/scripts/zone/ghostlands/ghostlands.cpp @@ -133,22 +133,22 @@ void AddSC_ghostlands() newscript->Name="npc_blood_knight_dawnstar"; newscript->pGossipHello = &GossipHello_npc_blood_knight_dawnstar; newscript->pGossipSelect = &GossipSelect_npc_blood_knight_dawnstar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_budd_nedreck"; newscript->pGossipHello = &GossipHello_npc_budd_nedreck; newscript->pGossipSelect = &GossipSelect_npc_budd_nedreck; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_rathis_tomber"; newscript->pGossipHello = &GossipHello_npc_rathis_tomber; newscript->pGossipSelect = &GossipSelect_npc_rathis_tomber; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "go_gilded_brazier"; newscript->pGOHello = &GOHello_gilded_brazier; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/gruuls_lair/boss_gruul.cpp b/src/bindings/scripts/scripts/zone/gruuls_lair/boss_gruul.cpp index bb2487b892e..1616d75e376 100644 --- a/src/bindings/scripts/scripts/zone/gruuls_lair/boss_gruul.cpp +++ b/src/bindings/scripts/scripts/zone/gruuls_lair/boss_gruul.cpp @@ -300,5 +300,5 @@ void AddSC_boss_gruul() newscript = new Script; newscript->Name="boss_gruul"; newscript->GetAI = GetAI_boss_gruul; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/gruuls_lair/boss_high_king_maulgar.cpp b/src/bindings/scripts/scripts/zone/gruuls_lair/boss_high_king_maulgar.cpp index 3c77b1a0acf..b0e53373a2f 100644 --- a/src/bindings/scripts/scripts/zone/gruuls_lair/boss_high_king_maulgar.cpp +++ b/src/bindings/scripts/scripts/zone/gruuls_lair/boss_high_king_maulgar.cpp @@ -817,25 +817,25 @@ void AddSC_boss_high_king_maulgar() newscript = new Script; newscript->Name="boss_high_king_maulgar"; newscript->GetAI = GetAI_boss_high_king_maulgar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_kiggler_the_crazed"; newscript->GetAI = GetAI_boss_kiggler_the_crazed; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_blindeye_the_seer"; newscript->GetAI = GetAI_boss_blindeye_the_seer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_olm_the_summoner"; newscript->GetAI = GetAI_boss_olm_the_summoner; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_krosh_firehand"; newscript->GetAI = GetAI_boss_krosh_firehand; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/gruuls_lair/instance_gruuls_lair.cpp b/src/bindings/scripts/scripts/zone/gruuls_lair/instance_gruuls_lair.cpp index 062800da3f6..3d058060722 100644 --- a/src/bindings/scripts/scripts/zone/gruuls_lair/instance_gruuls_lair.cpp +++ b/src/bindings/scripts/scripts/zone/gruuls_lair/instance_gruuls_lair.cpp @@ -184,5 +184,5 @@ void AddSC_instance_gruuls_lair() newscript = new Script; newscript->Name = "instance_gruuls_lair"; newscript->GetInstanceData = GetInstanceData_instance_gruuls_lair; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_broggok.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_broggok.cpp index 2237a85077a..1431be7dd51 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_broggok.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_broggok.cpp @@ -123,10 +123,10 @@ void AddSC_boss_broggok() newscript = new Script; newscript->Name="boss_broggok"; newscript->GetAI = GetAI_boss_broggokAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_broggok_poisoncloud"; newscript->GetAI = GetAI_mob_broggok_poisoncloudAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_kelidan_the_breaker.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_kelidan_the_breaker.cpp index bc5799ffe7e..092dfcd17be 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_kelidan_the_breaker.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_kelidan_the_breaker.cpp @@ -225,10 +225,10 @@ void AddSC_boss_kelidan_the_breaker() newscript = new Script; newscript->Name="boss_kelidan_the_breaker"; newscript->GetAI = GetAI_boss_kelidan_the_breaker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_shadowmoon_channeler"; newscript->GetAI = GetAI_mob_shadowmoon_channeler; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_the_maker.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_the_maker.cpp index ec85747032d..0c30651c9d5 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_the_maker.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/blood_furnace/boss_the_maker.cpp @@ -127,5 +127,5 @@ void AddSC_boss_the_maker() newscript = new Script; newscript->Name="boss_the_maker"; newscript->GetAI = GetAI_boss_the_makerAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_omor_the_unscarred.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_omor_the_unscarred.cpp index 676fbddf48c..1d8b1ec2c22 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_omor_the_unscarred.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_omor_the_unscarred.cpp @@ -209,5 +209,5 @@ void AddSC_boss_omor_the_unscarred() newscript = new Script; newscript->Name="boss_omor_the_unscarred"; newscript->GetAI = GetAI_boss_omor_the_unscarredAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_watchkeeper_gargolmar.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_watchkeeper_gargolmar.cpp index 21e9362a762..0d9e200c6e7 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_watchkeeper_gargolmar.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/hellfire_ramparts/boss_watchkeeper_gargolmar.cpp @@ -164,5 +164,5 @@ void AddSC_boss_watchkeeper_gargolmar() newscript = new Script; newscript->Name="boss_watchkeeper_gargolmar"; newscript->GetAI = GetAI_boss_watchkeeper_gargolmarAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/boss_magtheridon.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/boss_magtheridon.cpp index 4d7fe35891d..4d819b3537b 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/boss_magtheridon.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/boss_magtheridon.cpp @@ -545,21 +545,21 @@ void AddSC_boss_magtheridon() newscript = new Script; newscript->Name="boss_magtheridon"; newscript->GetAI = GetAI_boss_magtheridon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_hellfire_channeler"; newscript->GetAI = GetAI_mob_hellfire_channeler; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_manticron_cube"; newscript->pGOHello = &GOHello_go_Manticron_Cube; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_abyssal"; newscript->GetAI = GetAI_mob_abyssalAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } \ No newline at end of file diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp index d8f598f451e..51f22a1ff54 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/magtheridons_lair/instance_magtheridons_lair.cpp @@ -282,5 +282,5 @@ void AddSC_instance_magtheridons_lair() newscript = new Script; newscript->Name = "instance_magtheridons_lair"; newscript->GetInstanceData = GetInstanceData_instance_magtheridons_lair; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_nethekurse.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_nethekurse.cpp index 9d8335c527b..299f72a041b 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_nethekurse.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_nethekurse.cpp @@ -444,15 +444,15 @@ void AddSC_boss_grand_warlock_nethekurse() newscript = new Script; newscript->Name="boss_grand_warlock_nethekurse"; newscript->GetAI = GetAI_boss_grand_warlock_nethekurse; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_fel_orc_convert"; newscript->GetAI = GetAI_mob_fel_orc_convert; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_lesser_shadow_fissure"; newscript->GetAI = GetAI_mob_lesser_shadow_fissure; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_warbringer_omrogg.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_warbringer_omrogg.cpp index 092e82df0ed..2c128b3c047 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_warbringer_omrogg.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/boss_warbringer_omrogg.cpp @@ -394,10 +394,10 @@ void AddSC_boss_warbringer_omrogg() newscript = new Script; newscript->Name="boss_warbringer_omrogg"; newscript->GetAI = GetAI_boss_warbringer_omrogg; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_omrogg_heads"; newscript->GetAI = GetAI_mob_omrogg_heads; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/instance_shattered_halls.cpp b/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/instance_shattered_halls.cpp index 9dc78cb82cb..bee90392fe3 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/instance_shattered_halls.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_citadel/shattered_halls/instance_shattered_halls.cpp @@ -110,5 +110,5 @@ void AddSC_instance_shattered_halls() newscript = new Script; newscript->Name = "instance_shattered_halls"; newscript->GetInstanceData = GetInstanceData_instance_shattered_halls; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_peninsula/boss_doomlord_kazzak.cpp b/src/bindings/scripts/scripts/zone/hellfire_peninsula/boss_doomlord_kazzak.cpp index 51b4017b707..9b1822226a7 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_peninsula/boss_doomlord_kazzak.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_peninsula/boss_doomlord_kazzak.cpp @@ -137,5 +137,5 @@ void AddSC_boss_doomlordkazzak() newscript = new Script; newscript->Name="boss_doomlord_kazzak"; newscript->GetAI = GetAI_boss_doomlordkazzak; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/hellfire_peninsula/hellfire_peninsula.cpp b/src/bindings/scripts/scripts/zone/hellfire_peninsula/hellfire_peninsula.cpp index 1c3a4c71725..81d23457aab 100644 --- a/src/bindings/scripts/scripts/zone/hellfire_peninsula/hellfire_peninsula.cpp +++ b/src/bindings/scripts/scripts/zone/hellfire_peninsula/hellfire_peninsula.cpp @@ -171,17 +171,17 @@ void AddSC_hellfire_peninsula() newscript->Name="npc_wing_commander_dabiree"; newscript->pGossipHello = &GossipHello_npc_wing_commander_dabiree; newscript->pGossipSelect = &GossipSelect_npc_wing_commander_dabiree; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_gryphoneer_windbellow"; newscript->pGossipHello = &GossipHello_npc_gryphoneer_windbellow; newscript->pGossipSelect = &GossipSelect_npc_gryphoneer_windbellow; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_wing_commander_brack"; newscript->pGossipHello = &GossipHello_npc_wing_commander_brack; newscript->pGossipSelect = &GossipSelect_npc_wing_commander_brack; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/ironforge/ironforge.cpp b/src/bindings/scripts/scripts/zone/ironforge/ironforge.cpp index 7bb51ad499c..701f208f2a3 100644 --- a/src/bindings/scripts/scripts/zone/ironforge/ironforge.cpp +++ b/src/bindings/scripts/scripts/zone/ironforge/ironforge.cpp @@ -89,5 +89,5 @@ void AddSC_ironforge() newscript->Name="npc_royal_historian_archesonus"; newscript->pGossipHello = &GossipHello_npc_royal_historian_archesonus; newscript->pGossipSelect = &GossipSelect_npc_royal_historian_archesonus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/isle_of_queldanas/isle_of_queldanas.cpp b/src/bindings/scripts/scripts/zone/isle_of_queldanas/isle_of_queldanas.cpp index 9b2c1cda518..2690ecfa0ac 100644 --- a/src/bindings/scripts/scripts/zone/isle_of_queldanas/isle_of_queldanas.cpp +++ b/src/bindings/scripts/scripts/zone/isle_of_queldanas/isle_of_queldanas.cpp @@ -140,16 +140,16 @@ void AddSC_isle_of_queldanas() newscript->Name="npc_ayren_cloudbreaker"; newscript->pGossipHello = &GossipHello_npc_ayren_cloudbreaker; newscript->pGossipSelect = &GossipSelect_npc_ayren_cloudbreaker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_converted_sentry"; newscript->GetAI = GetAI_npc_converted_sentry; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_unrestrained_dragonhawk"; newscript->pGossipHello = &GossipHello_npc_unrestrained_dragonhawk; newscript->pGossipSelect = &GossipSelect_npc_unrestrained_dragonhawk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/boss_curator.cpp b/src/bindings/scripts/scripts/zone/karazhan/boss_curator.cpp index b560caad0d1..3c83b618604 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/boss_curator.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/boss_curator.cpp @@ -196,5 +196,5 @@ void AddSC_boss_curator() newscript = new Script; newscript->Name="boss_curator"; newscript->GetAI = GetAI_boss_curator; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/boss_maiden_of_virtue.cpp b/src/bindings/scripts/scripts/zone/karazhan/boss_maiden_of_virtue.cpp index e0bbadf5650..b4075e72b73 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/boss_maiden_of_virtue.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/boss_maiden_of_virtue.cpp @@ -179,5 +179,5 @@ void AddSC_boss_maiden_of_virtue() newscript = new Script; newscript->Name="boss_maiden_of_virtue"; newscript->GetAI = GetAI_boss_maiden_of_virtue; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/boss_midnight.cpp b/src/bindings/scripts/scripts/zone/karazhan/boss_midnight.cpp index 1be1a2df16f..1331e59c2f2 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/boss_midnight.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/boss_midnight.cpp @@ -362,10 +362,10 @@ void AddSC_boss_attumen() newscript = new Script; newscript->Name="boss_attumen"; newscript->GetAI = GetAI_boss_attumen; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_midnight"; newscript->GetAI = GetAI_boss_midnight; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/boss_moroes.cpp b/src/bindings/scripts/scripts/zone/karazhan/boss_moroes.cpp index 06a47787fa0..ce8f26ff0e5 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/boss_moroes.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/boss_moroes.cpp @@ -835,35 +835,35 @@ void AddSC_boss_moroes() newscript = new Script; newscript->Name="boss_moroes"; newscript->GetAI = GetAI_boss_moroes; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_baroness_dorothea_millstipe"; newscript->GetAI = GetAI_baroness_dorothea_millstipe; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_baron_rafe_dreuger"; newscript->GetAI = GetAI_baron_rafe_dreuger; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lady_catriona_von_indi"; newscript->GetAI = GetAI_lady_catriona_von_indi; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lady_keira_berrybuck"; newscript->GetAI = GetAI_lady_keira_berrybuck; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lord_robin_daris"; newscript->GetAI = GetAI_lord_robin_daris; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lord_crispin_ference"; newscript->GetAI = GetAI_lord_crispin_ference; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/boss_prince_malchezaar.cpp b/src/bindings/scripts/scripts/zone/karazhan/boss_prince_malchezaar.cpp index 6dfa4cb01b7..6d4e75afdb9 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/boss_prince_malchezaar.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/boss_prince_malchezaar.cpp @@ -666,10 +666,10 @@ void AddSC_boss_malchezaar() newscript = new Script; newscript->Name="boss_malchezaar"; newscript->GetAI = GetAI_boss_malchezaar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="netherspite_infernal"; newscript->GetAI = GetAI_netherspite_infernal; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/boss_shade_of_aran.cpp b/src/bindings/scripts/scripts/zone/karazhan/boss_shade_of_aran.cpp index 20cdb5b2d7d..71325d21f22 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/boss_shade_of_aran.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/boss_shade_of_aran.cpp @@ -654,20 +654,20 @@ void AddSC_boss_shade_of_aran() newscript = new Script; newscript->Name="boss_shade_of_aran"; newscript->GetAI = GetAI_boss_aran; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_shadow_of_aran"; newscript->GetAI = GetAI_shadow_of_aran; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_aran_elemental"; newscript->GetAI = GetAI_water_elemental; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); //newscript = new Script; //newscript->Name="mob_aran_blizzard"; //newscript->GetAI = GetAI_boss_aran; - //m_scripts[nrscripts++] = newscript; + //newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/boss_terestian_illhoof.cpp b/src/bindings/scripts/scripts/zone/karazhan/boss_terestian_illhoof.cpp index ddf6e9cb451..00a8cd46281 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/boss_terestian_illhoof.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/boss_terestian_illhoof.cpp @@ -436,20 +436,20 @@ void AddSC_boss_terestian_illhoof() newscript = new Script; newscript->Name="boss_terestian_illhoof"; newscript->GetAI = GetAI_boss_terestian_illhoof; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_karazhan_imp"; newscript->GetAI = GetAI_mob_karazhan_imp; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_kilrek"; newscript->GetAI = GetAI_mob_kilrek; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_demon_chain"; newscript->GetAI = GetAI_mob_demon_chain; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/bosses_opera.cpp b/src/bindings/scripts/scripts/zone/karazhan/bosses_opera.cpp index 91dab811d00..2509445f3d0 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/bosses_opera.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/bosses_opera.cpp @@ -1414,58 +1414,58 @@ void AddSC_bosses_opera() newscript = new Script; newscript->GetAI = GetAI_boss_dorothee; newscript->Name = "boss_dorothee"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_boss_strawman; newscript->Name = "boss_strawman"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_boss_tinhead; newscript->Name = "boss_tinhead"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_boss_roar; newscript->Name = "boss_roar"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_boss_crone; newscript->Name = "boss_crone"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_mob_tito; newscript->Name = "mob_tito"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_mob_cyclone; newscript->Name = "mob_cyclone"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); // Hood newscript = new Script; newscript->pGossipHello = GossipHello_npc_grandmother; newscript->pGossipSelect = GossipSelect_npc_grandmother; newscript->Name = "npc_grandmother"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_boss_bigbadwolf; newscript->Name = "boss_bigbadwolf"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); // Romeo And Juliet newscript = new Script; newscript->GetAI = GetAI_boss_julianne; newscript->Name = "boss_julianne"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->GetAI = GetAI_boss_romulo; newscript->Name = "boss_romulo"; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/instance_karazhan.cpp b/src/bindings/scripts/scripts/zone/karazhan/instance_karazhan.cpp index f683eea5336..29e07fe254f 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/instance_karazhan.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/instance_karazhan.cpp @@ -249,5 +249,5 @@ void AddSC_instance_karazhan() newscript = new Script; newscript->Name = "instance_karazhan"; newscript->GetInstanceData = GetInstanceData_instance_karazhan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp b/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp index 704a142cec9..404014565e6 100644 --- a/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp +++ b/src/bindings/scripts/scripts/zone/karazhan/karazhan.cpp @@ -290,13 +290,13 @@ struct TRINITY_DLL_DECL npc_barnesAI : public npc_escortAI return; RaidWiped = true; - for(Map::PlayerList::const_iterator i = PlayerList.begin();i != PlayerList.end(); ++i) - { - if (i->getSource()->isAlive() && !i->getSource()->isGameMaster()) - { - RaidWiped = false; - break; - } + for(Map::PlayerList::const_iterator i = PlayerList.begin();i != PlayerList.end(); ++i) + { + if (i->getSource()->isAlive() && !i->getSource()->isGameMaster()) + { + RaidWiped = false; + break; + } } if(RaidWiped) @@ -460,11 +460,11 @@ void AddSC_karazhan() newscript->Name = "npc_barnes"; newscript->pGossipHello = GossipHello_npc_barnes; newscript->pGossipSelect = GossipSelect_npc_barnes; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_berthold"; newscript->pGossipHello = GossipHello_npc_berthold; newscript->pGossipSelect = GossipSelect_npc_berthold; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/loch_modan/loch_modan.cpp b/src/bindings/scripts/scripts/zone/loch_modan/loch_modan.cpp index 966bf7c40a3..0e48a72535f 100644 --- a/src/bindings/scripts/scripts/zone/loch_modan/loch_modan.cpp +++ b/src/bindings/scripts/scripts/zone/loch_modan/loch_modan.cpp @@ -87,5 +87,5 @@ void AddSC_loch_modan() newscript->Name="npc_mountaineer_pebblebitty"; newscript->pGossipHello = &GossipHello_npc_mountaineer_pebblebitty; newscript->pGossipSelect = &GossipSelect_npc_mountaineer_pebblebitty; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp index 6bfb0d6464d..f08ff848237 100644 --- a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp +++ b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_felblood_kaelthas.cpp @@ -761,35 +761,35 @@ void AddSC_boss_felblood_kaelthas() newscript = new Script; newscript->Name = "boss_felblood_kaelthas"; newscript->GetAI = GetAI_boss_felblood_kaelthas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_arcane_sphere"; newscript->GetAI = GetAI_mob_arcane_sphere; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_felkael_phoenix"; newscript->GetAI = GetAI_mob_felkael_phoenix; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_felkael_phoenix_egg"; newscript->GetAI = GetAI_mob_felkael_phoenix_egg; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_felkael_flamestrike"; newscript->GetAI = GetAI_mob_felkael_flamestrike; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_kael_orb"; newscript->pGOHello = &GOHello_go_kael_orb; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="go_movie_orb"; newscript->pGOHello = &GOHello_go_movie_orb; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_priestess_delrissa.cpp b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_priestess_delrissa.cpp index bd4a336eff4..afae183a4ec 100644 --- a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_priestess_delrissa.cpp +++ b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_priestess_delrissa.cpp @@ -1355,60 +1355,60 @@ void AddSC_boss_priestess_delrissa() newscript = new Script; newscript->Name="boss_priestess_delrissa"; newscript->GetAI = GetAI_boss_priestess_delrissa; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_kagani_nightstrike"; newscript->GetAI = GetAI_boss_kagani_nightstrike; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_ellris_duskhallow"; newscript->GetAI = GetAI_ellris_duskhallow; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_eramas_brightblaze"; newscript->GetAI = GetAI_eramas_brightblaze; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_yazzai"; newscript->GetAI = GetAI_yazzai; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_warlord_salaris"; newscript->GetAI = GetAI_warlord_salaris; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_garaxxas"; newscript->GetAI = GetAI_garaxxas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_apoko"; newscript->GetAI = GetAI_apoko; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_zelfan"; newscript->GetAI = GetAI_zelfan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); /*newscript = new Script; newscript->Name="mob_high_explosive_sheep"; newscript->GetAI = GetAI_mob_high_explosive_sheep; - m_scripts[nrscripts++] = newscript;*/ + newscript->RegisterSelf();*/ /*newscript = new Script; newscript->Name="mob_fizzle"; newscript->GetAI = GetAI_mob_fizzle; - m_scripts[nrscripts++] = newscript;*/ + newscript->RegisterSelf();*/ /*newscript = new Script; newscript->Name="mob_sliver"; newscript->GetAI = GetAI_mob_sliver; - m_scripts[nrscripts++] = newscript;*/ + newscript->RegisterSelf();*/ } diff --git a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_selin_fireheart.cpp b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_selin_fireheart.cpp index 24526dac185..83174dd5a4c 100644 --- a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_selin_fireheart.cpp +++ b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_selin_fireheart.cpp @@ -403,10 +403,10 @@ void AddSC_boss_selin_fireheart() newscript = new Script; newscript->Name="boss_selin_fireheart"; newscript->GetAI = GetAI_boss_selin_fireheart; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_fel_crystal"; newscript->GetAI = GetAI_mob_fel_crystal; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_vexallus.cpp b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_vexallus.cpp index ff11b425bd2..4f073cb884d 100644 --- a/src/bindings/scripts/scripts/zone/magisters_terrace/boss_vexallus.cpp +++ b/src/bindings/scripts/scripts/zone/magisters_terrace/boss_vexallus.cpp @@ -238,10 +238,10 @@ void AddSC_boss_vexallus() newscript = new Script; newscript->Name="boss_vexallus"; newscript->GetAI = GetAI_boss_vexallus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_pure_energy"; newscript->GetAI = GetAI_mob_pure_energy; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/magisters_terrace/instance_magisters_terrace.cpp b/src/bindings/scripts/scripts/zone/magisters_terrace/instance_magisters_terrace.cpp index 8afecdc32e9..70d12865158 100644 --- a/src/bindings/scripts/scripts/zone/magisters_terrace/instance_magisters_terrace.cpp +++ b/src/bindings/scripts/scripts/zone/magisters_terrace/instance_magisters_terrace.cpp @@ -249,5 +249,5 @@ void AddSC_instance_magisters_terrace() newscript = new Script; newscript->Name = "instance_magisters_terrace"; newscript->GetInstanceData = GetInstanceData_instance_magisters_terrace; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/maraudon/boss_celebras_the_cursed.cpp b/src/bindings/scripts/scripts/zone/maraudon/boss_celebras_the_cursed.cpp index 543686e2648..8830b7f3e4b 100644 --- a/src/bindings/scripts/scripts/zone/maraudon/boss_celebras_the_cursed.cpp +++ b/src/bindings/scripts/scripts/zone/maraudon/boss_celebras_the_cursed.cpp @@ -93,5 +93,5 @@ void AddSC_boss_celebras_the_cursed() newscript = new Script; newscript->Name="celebras_the_cursed"; newscript->GetAI = GetAI_celebras_the_cursed; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/maraudon/boss_landslide.cpp b/src/bindings/scripts/scripts/zone/maraudon/boss_landslide.cpp index 20b93fe64b3..ab68f68c6e3 100644 --- a/src/bindings/scripts/scripts/zone/maraudon/boss_landslide.cpp +++ b/src/bindings/scripts/scripts/zone/maraudon/boss_landslide.cpp @@ -90,5 +90,5 @@ void AddSC_boss_landslide() newscript = new Script; newscript->Name="boss_landslide"; newscript->GetAI = GetAI_boss_landslide; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/maraudon/boss_noxxion.cpp b/src/bindings/scripts/scripts/zone/maraudon/boss_noxxion.cpp index c5d5a51ffb9..0ffe9cd7f56 100644 --- a/src/bindings/scripts/scripts/zone/maraudon/boss_noxxion.cpp +++ b/src/bindings/scripts/scripts/zone/maraudon/boss_noxxion.cpp @@ -145,5 +145,5 @@ void AddSC_boss_noxxion() newscript = new Script; newscript->Name="boss_noxxion"; newscript->GetAI = GetAI_boss_noxxion; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/maraudon/boss_princess_theradras.cpp b/src/bindings/scripts/scripts/zone/maraudon/boss_princess_theradras.cpp index 1920109f3d8..01cfb86a372 100644 --- a/src/bindings/scripts/scripts/zone/maraudon/boss_princess_theradras.cpp +++ b/src/bindings/scripts/scripts/zone/maraudon/boss_princess_theradras.cpp @@ -104,5 +104,5 @@ void AddSC_boss_ptheradras() newscript = new Script; newscript->Name="boss_princess_theradras"; newscript->GetAI = GetAI_boss_ptheradras; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_baron_geddon.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_baron_geddon.cpp index 163926881f6..75cf6cb0a45 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_baron_geddon.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_baron_geddon.cpp @@ -101,5 +101,5 @@ void AddSC_boss_baron_geddon() newscript = new Script; newscript->Name="boss_baron_geddon"; newscript->GetAI = GetAI_boss_baron_geddon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_garr.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_garr.cpp index 70e98d648ee..830af78c430 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_garr.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_garr.cpp @@ -140,10 +140,10 @@ void AddSC_boss_garr() newscript = new Script; newscript->Name="boss_garr"; newscript->GetAI = GetAI_boss_garr; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_firesworn"; newscript->GetAI = GetAI_mob_firesworn; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_gehennas.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_gehennas.cpp index f15c66f26af..dc8bd9a5d9c 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_gehennas.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_gehennas.cpp @@ -87,5 +87,5 @@ void AddSC_boss_gehennas() newscript = new Script; newscript->Name="boss_gehennas"; newscript->GetAI = GetAI_boss_gehennas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_golemagg.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_golemagg.cpp index 6d17621ceb2..ebefd0185fc 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_golemagg.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_golemagg.cpp @@ -192,10 +192,10 @@ void AddSC_boss_golemagg() newscript = new Script; newscript->Name="boss_golemagg"; newscript->GetAI = GetAI_boss_golemagg; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_core_rager"; newscript->GetAI = GetAI_mob_core_rager; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_lucifron.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_lucifron.cpp index 6e8938bc542..f45657c8dae 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_lucifron.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_lucifron.cpp @@ -86,5 +86,5 @@ void AddSC_boss_lucifron() newscript = new Script; newscript->Name="boss_lucifron"; newscript->GetAI = GetAI_boss_lucifron; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_magmadar.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_magmadar.cpp index a892c83f175..d08f393fbee 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_magmadar.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_magmadar.cpp @@ -93,5 +93,5 @@ void AddSC_boss_magmadar() newscript = new Script; newscript->Name="boss_magmadar"; newscript->GetAI = GetAI_boss_magmadar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_majordomo_executus.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_majordomo_executus.cpp index d61f08ee7e7..43be23046ea 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_majordomo_executus.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_majordomo_executus.cpp @@ -129,5 +129,5 @@ void AddSC_boss_majordomo() newscript = new Script; newscript->Name="boss_majordomo"; newscript->GetAI = GetAI_boss_majordomo; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_ragnaros.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_ragnaros.cpp index 723fba0edf7..d357d9580e9 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_ragnaros.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_ragnaros.cpp @@ -313,5 +313,5 @@ void AddSC_boss_ragnaros() newscript = new Script; newscript->Name="boss_ragnaros"; newscript->GetAI = GetAI_boss_ragnaros; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_shazzrah.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_shazzrah.cpp index c9d4f4f3eec..c78b9ac3c91 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_shazzrah.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_shazzrah.cpp @@ -117,5 +117,5 @@ void AddSC_boss_shazzrah() newscript = new Script; newscript->Name="boss_shazzrah"; newscript->GetAI = GetAI_boss_shazzrah; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/boss_sulfuron_harbinger.cpp b/src/bindings/scripts/scripts/zone/molten_core/boss_sulfuron_harbinger.cpp index 8a2a7764daa..0bc0e8e729e 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/boss_sulfuron_harbinger.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/boss_sulfuron_harbinger.cpp @@ -206,10 +206,10 @@ void AddSC_boss_sulfuron() newscript = new Script; newscript->Name="boss_sulfuron"; newscript->GetAI = GetAI_boss_sulfuron; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_flamewaker_priest"; newscript->GetAI = GetAI_mob_flamewaker_priest; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/instance_molten_core.cpp b/src/bindings/scripts/scripts/zone/molten_core/instance_molten_core.cpp index 42a2ec35678..efba77f41f0 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/instance_molten_core.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/instance_molten_core.cpp @@ -253,5 +253,5 @@ void AddSC_instance_molten_core() newscript = new Script; newscript->Name="instance_molten_core"; newscript->GetInstanceData = &GetInstance_instance_molten_core; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/molten_core/molten_core.cpp b/src/bindings/scripts/scripts/zone/molten_core/molten_core.cpp index e36f56c7817..9446fb54a12 100644 --- a/src/bindings/scripts/scripts/zone/molten_core/molten_core.cpp +++ b/src/bindings/scripts/scripts/zone/molten_core/molten_core.cpp @@ -84,5 +84,5 @@ void AddSC_molten_core() newscript = new Script; newscript->Name="mob_ancient_core_hound"; newscript->GetAI = GetAI_mob_ancient_core_hound; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/moonglade/moonglade.cpp b/src/bindings/scripts/scripts/zone/moonglade/moonglade.cpp index 7ac2326327b..1b0afbaaf94 100644 --- a/src/bindings/scripts/scripts/zone/moonglade/moonglade.cpp +++ b/src/bindings/scripts/scripts/zone/moonglade/moonglade.cpp @@ -545,27 +545,27 @@ void AddSC_moonglade() newscript->Name="npc_bunthen_plainswind"; newscript->pGossipHello = &GossipHello_npc_bunthen_plainswind; newscript->pGossipSelect = &GossipSelect_npc_bunthen_plainswind; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_great_bear_spirit"; newscript->pGossipHello = &GossipHello_npc_great_bear_spirit; newscript->pGossipSelect = &GossipSelect_npc_great_bear_spirit; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_silva_filnaveth"; newscript->pGossipHello = &GossipHello_npc_silva_filnaveth; newscript->pGossipSelect = &GossipSelect_npc_silva_filnaveth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_clintar_dreamwalker"; newscript->pQuestAccept = &QuestAccept_npc_clintar_dreamwalker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_clintar_spirit"; newscript->GetAI = GetAI_npc_clintar_spirit; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/mulgore/mulgore.cpp b/src/bindings/scripts/scripts/zone/mulgore/mulgore.cpp index d2fb6643423..44de5eab777 100644 --- a/src/bindings/scripts/scripts/zone/mulgore/mulgore.cpp +++ b/src/bindings/scripts/scripts/zone/mulgore/mulgore.cpp @@ -60,5 +60,5 @@ void AddSC_mulgore() newscript->Name="npc_skorn_whitecloud"; newscript->pGossipHello = &GossipHello_npc_skorn_whitecloud; newscript->pGossipSelect = &GossipSelect_npc_skorn_whitecloud; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/nagrand/nagrand.cpp b/src/bindings/scripts/scripts/zone/nagrand/nagrand.cpp index dcd3f57bef3..f662fe4c2c4 100644 --- a/src/bindings/scripts/scripts/zone/nagrand/nagrand.cpp +++ b/src/bindings/scripts/scripts/zone/nagrand/nagrand.cpp @@ -631,46 +631,46 @@ void AddSC_nagrand() newscript = new Script; newscript->Name="mob_shattered_rumbler"; newscript->GetAI = GetAI_mob_shattered_rumbler; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_lump"; newscript->GetAI = GetAI_mob_lump; newscript->pGossipHello = &GossipHello_mob_lump; newscript->pGossipSelect = &GossipSelect_mob_lump; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_sunspring_villager"; newscript->GetAI = GetAI_mob_sunspring_villager; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_altruis_the_sufferer"; newscript->pGossipHello = &GossipHello_npc_altruis_the_sufferer; newscript->pGossipSelect = &GossipSelect_npc_altruis_the_sufferer; newscript->pQuestAccept = &QuestAccept_npc_altruis_the_sufferer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_greatmother_geyah"; newscript->pGossipHello = &GossipHello_npc_greatmother_geyah; newscript->pGossipSelect = &GossipSelect_npc_greatmother_geyah; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_lantresor_of_the_blade"; newscript->pGossipHello = &GossipHello_npc_lantresor_of_the_blade; newscript->pGossipSelect = &GossipSelect_npc_lantresor_of_the_blade; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_creditmarker_visit_with_ancestors"; newscript->GetAI = GetAI_npc_creditmarker_visit_with_ancestors; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_sparrowhawk"; newscript->GetAI = GetAI_mob_sparrowhawk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_anubrekhan.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_anubrekhan.cpp index 50a4f867b4c..2b93e7828f9 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_anubrekhan.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_anubrekhan.cpp @@ -208,5 +208,5 @@ void AddSC_boss_anubrekhan() newscript = new Script; newscript->Name="boss_anubrekhan"; newscript->GetAI = GetAI_boss_anubrekhan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_faerlina.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_faerlina.cpp index 4add49e17b4..dbcf72510aa 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_faerlina.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_faerlina.cpp @@ -197,5 +197,5 @@ void AddSC_boss_faerlina() newscript = new Script; newscript->Name="boss_faerlina"; newscript->GetAI = GetAI_boss_faerlina; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_gluth.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_gluth.cpp index 09e3c1ecf25..b5b40a4b245 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_gluth.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_gluth.cpp @@ -170,5 +170,5 @@ void AddSC_boss_gluth() newscript = new Script; newscript->Name="boss_gluth"; newscript->GetAI = GetAI_boss_gluth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_highlord_mograine.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_highlord_mograine.cpp index 96d94ad51ad..d21e2a2119f 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_highlord_mograine.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_highlord_mograine.cpp @@ -174,5 +174,5 @@ void AddSC_boss_highlord_mograine() newscript = new Script; newscript->Name="boss_highlord_mograine"; newscript->GetAI = GetAI_boss_highlord_mograine; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_kelthuzad.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_kelthuzad.cpp index 3a47f6f5c27..e65bfb62fdd 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_kelthuzad.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_kelthuzad.cpp @@ -537,6 +537,6 @@ void AddSC_boss_kelthuzad() newscript = new Script; newscript->Name="boss_kelthuzad"; newscript->GetAI = GetAI_boss_kelthuzadAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); */ } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_lady_blaumeux.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_lady_blaumeux.cpp index ee3b47e478d..770f880557d 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_lady_blaumeux.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_lady_blaumeux.cpp @@ -143,5 +143,5 @@ void AddSC_boss_lady_blaumeux() newscript = new Script; newscript->Name="boss_lady_blaumeux"; newscript->GetAI = GetAI_boss_lady_blaumeux; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_loatheb.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_loatheb.cpp index 56fe786e6c8..4da5c6626cb 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_loatheb.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_loatheb.cpp @@ -212,5 +212,5 @@ void AddSC_boss_loatheb() newscript = new Script; newscript->Name="boss_loatheb"; newscript->GetAI = GetAI_boss_loatheb; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_maexxna.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_maexxna.cpp index 4c65feb9c7b..821ca832e65 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_maexxna.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_maexxna.cpp @@ -237,10 +237,10 @@ void AddSC_boss_maexxna() newscript = new Script; newscript->Name="boss_maexxna"; newscript->GetAI = GetAI_boss_maexxna; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_webwrap"; newscript->GetAI = GetAI_mob_webwrap; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_noth.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_noth.cpp index cda01c57e40..43616311bb4 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_noth.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_noth.cpp @@ -176,5 +176,5 @@ void AddSC_boss_noth() newscript = new Script; newscript->Name="boss_noth"; newscript->GetAI = GetAI_boss_noth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_patchwerk.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_patchwerk.cpp index d0edc7f46b3..2f51c9c3064 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_patchwerk.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_patchwerk.cpp @@ -156,5 +156,5 @@ void AddSC_boss_patchwerk() newscript = new Script; newscript->Name="boss_patchwerk"; newscript->GetAI = GetAI_boss_patchwerk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_razuvious.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_razuvious.cpp index d83f99bda43..ac7de1db7eb 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_razuvious.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_razuvious.cpp @@ -163,5 +163,5 @@ void AddSC_boss_razuvious() newscript = new Script; newscript->Name="boss_razuvious"; newscript->GetAI = GetAI_boss_razuvious; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_sapphiron.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_sapphiron.cpp index 0be1619ad74..75a2f20db14 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_sapphiron.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_sapphiron.cpp @@ -195,5 +195,5 @@ void AddSC_boss_sapphiron() newscript = new Script; newscript->Name="boss_sapphiron"; newscript->GetAI = GetAI_boss_sapphiron; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_sir_zeliek.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_sir_zeliek.cpp index 0a3ca7a951b..8dead488208 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_sir_zeliek.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_sir_zeliek.cpp @@ -142,5 +142,5 @@ void AddSC_boss_sir_zeliek() newscript = new Script; newscript->Name="boss_sir_zeliek"; newscript->GetAI = GetAI_boss_sir_zeliek; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/naxxramas/boss_thane_korthazz.cpp b/src/bindings/scripts/scripts/zone/naxxramas/boss_thane_korthazz.cpp index a040626258d..500f0955316 100644 --- a/src/bindings/scripts/scripts/zone/naxxramas/boss_thane_korthazz.cpp +++ b/src/bindings/scripts/scripts/zone/naxxramas/boss_thane_korthazz.cpp @@ -143,5 +143,5 @@ void AddSC_boss_thane_korthazz() newscript = new Script; newscript->Name="boss_thane_korthazz"; newscript->GetAI = GetAI_boss_thane_korthazz; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/netherstorm/netherstorm.cpp b/src/bindings/scripts/scripts/zone/netherstorm/netherstorm.cpp index 2d35802338e..4125c4e888e 100644 --- a/src/bindings/scripts/scripts/zone/netherstorm/netherstorm.cpp +++ b/src/bindings/scripts/scripts/zone/netherstorm/netherstorm.cpp @@ -400,22 +400,22 @@ void AddSC_netherstorm() newscript = new Script; newscript->Name="go_manaforge_control_console"; newscript->pGOHello = &GOHello_go_manaforge_control_console; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_manaforge_control_console"; newscript->GetAI = GetAI_npc_manaforge_control_console; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_protectorate_nether_drake"; newscript->pGossipHello = &GossipHello_npc_protectorate_nether_drake; newscript->pGossipSelect = &GossipSelect_npc_protectorate_nether_drake; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_veronia"; newscript->pGossipHello = &GossipHello_npc_veronia; newscript->pGossipSelect = &GossipSelect_npc_veronia; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/onyxias_lair/boss_onyxia.cpp b/src/bindings/scripts/scripts/zone/onyxias_lair/boss_onyxia.cpp index 7774f65411d..eb73f8bfb3a 100644 --- a/src/bindings/scripts/scripts/zone/onyxias_lair/boss_onyxia.cpp +++ b/src/bindings/scripts/scripts/zone/onyxias_lair/boss_onyxia.cpp @@ -229,5 +229,5 @@ void AddSC_boss_onyxia() newscript = new Script; newscript->Name="boss_onyxia"; newscript->GetAI = GetAI_boss_onyxiaAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/orgrimmar/orgrimmar.cpp b/src/bindings/scripts/scripts/zone/orgrimmar/orgrimmar.cpp index cb4be0499fc..76c7a5f3416 100644 --- a/src/bindings/scripts/scripts/zone/orgrimmar/orgrimmar.cpp +++ b/src/bindings/scripts/scripts/zone/orgrimmar/orgrimmar.cpp @@ -247,19 +247,19 @@ void AddSC_orgrimmar() newscript->Name="npc_neeru_fireblade"; newscript->pGossipHello = &GossipHello_npc_neeru_fireblade; newscript->pGossipSelect = &GossipSelect_npc_neeru_fireblade; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_shenthul"; newscript->GetAI = GetAI_npc_shenthul; newscript->pQuestAccept = &QuestAccept_npc_shenthul; newscript->pReceiveEmote = &ReciveEmote_npc_shenthul; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_thrall_warchief"; newscript->GetAI = GetAI_npc_thrall_warchief; newscript->pGossipHello = &GossipHello_npc_thrall_warchief; newscript->pGossipSelect = &GossipSelect_npc_thrall_warchief; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/razorfen_downs/boss_amnennar_the_coldbringer.cpp b/src/bindings/scripts/scripts/zone/razorfen_downs/boss_amnennar_the_coldbringer.cpp index 163db1c2756..e7f3184a60e 100644 --- a/src/bindings/scripts/scripts/zone/razorfen_downs/boss_amnennar_the_coldbringer.cpp +++ b/src/bindings/scripts/scripts/zone/razorfen_downs/boss_amnennar_the_coldbringer.cpp @@ -136,5 +136,5 @@ void AddSC_boss_amnennar_the_coldbringer() newscript = new Script; newscript->Name="boss_amnennar_the_coldbringer"; newscript->GetAI = GetAI_boss_amnennar_the_coldbringer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_ayamiss.cpp b/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_ayamiss.cpp index 03a53d50297..374daab3344 100644 --- a/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_ayamiss.cpp +++ b/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_ayamiss.cpp @@ -103,5 +103,5 @@ void AddSC_boss_ayamiss() newscript = new Script; newscript->Name="boss_ayamiss"; newscript->GetAI = GetAI_boss_ayamiss; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_kurinnaxx.cpp b/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_kurinnaxx.cpp index 3a287d8b6ae..124ebccbcbb 100644 --- a/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_kurinnaxx.cpp +++ b/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_kurinnaxx.cpp @@ -89,5 +89,5 @@ void AddSC_boss_kurinnaxx() newscript = new Script; newscript->Name="boss_kurinnaxx"; newscript->GetAI = GetAI_boss_kurinnaxx; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_moam.cpp b/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_moam.cpp index 836dd3f8065..12e58066456 100644 --- a/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_moam.cpp +++ b/src/bindings/scripts/scripts/zone/ruins_of_ahnqiraj/boss_moam.cpp @@ -113,5 +113,5 @@ void AddSC_boss_moam() newscript = new Script; newscript->Name="boss_moam"; newscript->GetAI = GetAI_boss_moam; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_arcanist_doan.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_arcanist_doan.cpp index 50764c4d022..aaa156b8092 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_arcanist_doan.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_arcanist_doan.cpp @@ -167,5 +167,5 @@ void AddSC_boss_arcanist_doan() newscript = new Script; newscript->Name="boss_arcanist_doan"; newscript->GetAI = GetAI_boss_arcanist_doan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_azshir_the_sleepless.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_azshir_the_sleepless.cpp index 4ea395a8038..10d340eae91 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_azshir_the_sleepless.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_azshir_the_sleepless.cpp @@ -93,5 +93,5 @@ void AddSC_boss_azshir_the_sleepless() newscript = new Script; newscript->Name="boss_azshir_the_sleepless"; newscript->GetAI = GetAI_boss_azshir_the_sleepless; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_bloodmage_thalnos.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_bloodmage_thalnos.cpp index 9fa5bee9714..ae2324d8615 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_bloodmage_thalnos.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_bloodmage_thalnos.cpp @@ -132,5 +132,5 @@ void AddSC_boss_bloodmage_thalnos() newscript = new Script; newscript->Name="boss_bloodmage_thalnos"; newscript->GetAI = GetAI_boss_bloodmage_thalnos; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_herod.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_herod.cpp index de1fd991c33..494def37c11 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_herod.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_herod.cpp @@ -193,5 +193,5 @@ void AddSC_boss_herod() newscript = new Script; newscript->Name="boss_herod"; newscript->GetAI = GetAI_boss_herod; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_fairbanks.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_fairbanks.cpp index 5742214e31d..a230629b871 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_fairbanks.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_fairbanks.cpp @@ -128,5 +128,5 @@ void AddSC_boss_high_inquisitor_fairbanks() newscript = new Script; newscript->Name="boss_high_inquisitor_fairbanks"; newscript->GetAI = GetAI_boss_high_inquisitor_fairbanks; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_whitemane.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_whitemane.cpp index 97fbce31b01..c10da64c4e9 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_whitemane.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_high_inquisitor_whitemane.cpp @@ -173,5 +173,5 @@ void AddSC_boss_high_inquisitor_whitemane() newscript = new Script; newscript->Name="boss_high_inquisitor_whitemane"; newscript->GetAI = GetAI_boss_high_inquisitor_whitemane; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_houndmaster_loksey.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_houndmaster_loksey.cpp index 6353f600460..e268d25c9d7 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_houndmaster_loksey.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_houndmaster_loksey.cpp @@ -74,5 +74,5 @@ void AddSC_boss_houndmaster_loksey() newscript = new Script; newscript->Name="boss_houndmaster_loksey"; newscript->GetAI = GetAI_boss_houndmaster_loksey; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_interrogator_vishas.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_interrogator_vishas.cpp index ede58d0997e..98cb742eb01 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_interrogator_vishas.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_interrogator_vishas.cpp @@ -109,5 +109,5 @@ void AddSC_boss_interrogator_vishas() newscript = new Script; newscript->Name="boss_interrogator_vishas"; newscript->GetAI = GetAI_boss_interrogator_vishas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scarlet_commander_mograine.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scarlet_commander_mograine.cpp index 5e87b1a2b77..1d8587d9f78 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scarlet_commander_mograine.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scarlet_commander_mograine.cpp @@ -156,5 +156,5 @@ void AddSC_boss_scarlet_commander_mograine() newscript = new Script; newscript->Name="boss_scarlet_commander_mograine"; newscript->GetAI = GetAI_boss_scarlet_commander_mograine; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scorn.cpp b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scorn.cpp index 1f9e3fb2487..95a206d1657 100644 --- a/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scorn.cpp +++ b/src/bindings/scripts/scripts/zone/scarlet_monastery/boss_scorn.cpp @@ -96,5 +96,5 @@ void AddSC_boss_scorn() newscript = new Script; newscript->Name="boss_scorn"; newscript->GetAI = GetAI_boss_scorn; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_darkmaster_gandling.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_darkmaster_gandling.cpp index f67bf9fe594..38e6ad85d8c 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_darkmaster_gandling.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_darkmaster_gandling.cpp @@ -188,5 +188,5 @@ void AddSC_boss_darkmaster_gandling() newscript = new Script; newscript->Name="boss_darkmaster_gandling"; newscript->GetAI = GetAI_boss_darkmaster_gandling; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_death_knight_darkreaver.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_death_knight_darkreaver.cpp index 747ec039363..fa410af2734 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_death_knight_darkreaver.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_death_knight_darkreaver.cpp @@ -55,5 +55,5 @@ void AddSC_boss_death_knight_darkreaver() newscript = new Script; newscript->Name="boss_death_knight_darkreaver"; newscript->GetAI = GetAI_boss_death_knight_darkreaver; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_doctor_theolen_krastinov.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_doctor_theolen_krastinov.cpp index 484a27dca98..3993a58f1cd 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_doctor_theolen_krastinov.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_doctor_theolen_krastinov.cpp @@ -104,5 +104,5 @@ void AddSC_boss_theolenkrastinov() newscript = new Script; newscript->Name="boss_doctor_theolen_krastinov"; newscript->GetAI = GetAI_boss_theolenkrastinov; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_illucia_barov.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_illucia_barov.cpp index 1edae02fcf3..4b871f8e173 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_illucia_barov.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_illucia_barov.cpp @@ -112,5 +112,5 @@ void AddSC_boss_illuciabarov() newscript = new Script; newscript->Name="boss_illucia_barov"; newscript->GetAI = GetAI_boss_illuciabarov; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_instructor_malicia.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_instructor_malicia.cpp index 705b2835843..15e5c93a982 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_instructor_malicia.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_instructor_malicia.cpp @@ -148,5 +148,5 @@ void AddSC_boss_instructormalicia() newscript = new Script; newscript->Name="boss_instructor_malicia"; newscript->GetAI = GetAI_boss_instructormalicia; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_jandice_barov.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_jandice_barov.cpp index dfae0432d12..e27dc31879e 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_jandice_barov.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_jandice_barov.cpp @@ -212,10 +212,10 @@ void AddSC_boss_jandicebarov() newscript = new Script; newscript->Name="boss_jandice_barov"; newscript->GetAI = GetAI_boss_jandicebarov; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_illusionofjandicebarov"; newscript->GetAI = GetAI_mob_illusionofjandicebarov; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_kormok.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_kormok.cpp index b3cc6fd0530..1e1fb1ef685 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_kormok.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_kormok.cpp @@ -151,5 +151,5 @@ void AddSC_boss_kormok() newscript = new Script; newscript->Name="boss_kormok"; newscript->GetAI = GetAI_boss_kormok; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_lord_alexei_barov.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_lord_alexei_barov.cpp index 49f3f733949..8d8f248aede 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_lord_alexei_barov.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_lord_alexei_barov.cpp @@ -94,5 +94,5 @@ void AddSC_boss_lordalexeibarov() newscript = new Script; newscript->Name="boss_lord_alexei_barov"; newscript->GetAI = GetAI_boss_lordalexeibarov; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_lorekeeper_polkelt.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_lorekeeper_polkelt.cpp index d17d2036d91..c05e4d64d1d 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_lorekeeper_polkelt.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_lorekeeper_polkelt.cpp @@ -109,5 +109,5 @@ void AddSC_boss_lorekeeperpolkelt() newscript = new Script; newscript->Name="boss_lorekeeper_polkelt"; newscript->GetAI = GetAI_boss_lorekeeperpolkelt; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_ras_frostwhisper.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_ras_frostwhisper.cpp index 0ea243c2d08..afe7eb8716a 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_ras_frostwhisper.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_ras_frostwhisper.cpp @@ -121,5 +121,5 @@ void AddSC_boss_rasfrost() newscript = new Script; newscript->Name="boss_boss_ras_frostwhisper"; newscript->GetAI = GetAI_boss_rasfrost; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_the_ravenian.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_the_ravenian.cpp index f27e8aa458f..d16b0f917ce 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_the_ravenian.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_the_ravenian.cpp @@ -114,5 +114,5 @@ void AddSC_boss_theravenian() newscript = new Script; newscript->Name="boss_the_ravenian"; newscript->GetAI = GetAI_boss_theravenian; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/boss_vectus.cpp b/src/bindings/scripts/scripts/zone/scholomance/boss_vectus.cpp index 954ee3b4eba..f92ae0732e1 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/boss_vectus.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/boss_vectus.cpp @@ -91,5 +91,5 @@ void AddSC_boss_vectus() newscript = new Script; newscript->Name="boss_vectus"; newscript->GetAI = GetAI_boss_vectus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/scholomance/instance_scholomance.cpp b/src/bindings/scripts/scripts/zone/scholomance/instance_scholomance.cpp index a48537068f8..036a34cd8fa 100644 --- a/src/bindings/scripts/scripts/zone/scholomance/instance_scholomance.cpp +++ b/src/bindings/scripts/scripts/zone/scholomance/instance_scholomance.cpp @@ -98,5 +98,5 @@ void AddSC_instance_scholomance() newscript = new Script; newscript->Name = "instance_scholomance"; newscript->GetInstanceData = GetInstanceData_instance_scholomance; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/searing_gorge/searing_gorge.cpp b/src/bindings/scripts/scripts/zone/searing_gorge/searing_gorge.cpp index 7a9ef1a5449..23281eb9050 100644 --- a/src/bindings/scripts/scripts/zone/searing_gorge/searing_gorge.cpp +++ b/src/bindings/scripts/scripts/zone/searing_gorge/searing_gorge.cpp @@ -143,17 +143,17 @@ void AddSC_searing_gorge() newscript->Name="npc_kalaran_windblade"; newscript->pGossipHello = &GossipHello_npc_kalaran_windblade; newscript->pGossipSelect = &GossipSelect_npc_kalaran_windblade; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_lothos_riftwaker"; newscript->pGossipHello = &GossipHello_npc_lothos_riftwaker; newscript->pGossipSelect = &GossipSelect_npc_lothos_riftwaker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_zamael_lunthistle"; newscript->pGossipHello = &GossipHello_npc_zamael_lunthistle; newscript->pGossipSelect = &GossipSelect_npc_zamael_lunthistle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/shadowfang_keep/instance_shadowfang_keep.cpp b/src/bindings/scripts/scripts/zone/shadowfang_keep/instance_shadowfang_keep.cpp index dfae8457abc..a854cc96989 100644 --- a/src/bindings/scripts/scripts/zone/shadowfang_keep/instance_shadowfang_keep.cpp +++ b/src/bindings/scripts/scripts/zone/shadowfang_keep/instance_shadowfang_keep.cpp @@ -148,5 +148,5 @@ void AddSC_instance_shadowfang_keep() newscript = new Script; newscript->Name = "instance_shadowfang_keep"; newscript->GetInstanceData = GetInstanceData_instance_shadowfang_keep; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/shadowfang_keep/shadowfang_keep.cpp b/src/bindings/scripts/scripts/zone/shadowfang_keep/shadowfang_keep.cpp index 65e1eaea8ba..d297ccbcdeb 100644 --- a/src/bindings/scripts/scripts/zone/shadowfang_keep/shadowfang_keep.cpp +++ b/src/bindings/scripts/scripts/zone/shadowfang_keep/shadowfang_keep.cpp @@ -113,5 +113,5 @@ void AddSC_shadowfang_keep() newscript->pGossipHello = &GossipHello_npc_shadowfang_prisoner; newscript->pGossipSelect = &GossipSelect_npc_shadowfang_prisoner; newscript->GetAI = GetAI_npc_shadowfang_prisoner; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/shadowmoon_valley/boss_doomwalker.cpp b/src/bindings/scripts/scripts/zone/shadowmoon_valley/boss_doomwalker.cpp index 89536b15ac2..a67318bc41c 100644 --- a/src/bindings/scripts/scripts/zone/shadowmoon_valley/boss_doomwalker.cpp +++ b/src/bindings/scripts/scripts/zone/shadowmoon_valley/boss_doomwalker.cpp @@ -212,5 +212,5 @@ void AddSC_boss_doomwalker() newscript = new Script; newscript->Name="boss_doomwalker"; newscript->GetAI = GetAI_boss_doomwalker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/shadowmoon_valley/shadowmoon_valley.cpp b/src/bindings/scripts/scripts/zone/shadowmoon_valley/shadowmoon_valley.cpp index 7bc1ad312a9..534a853302d 100644 --- a/src/bindings/scripts/scripts/zone/shadowmoon_valley/shadowmoon_valley.cpp +++ b/src/bindings/scripts/scripts/zone/shadowmoon_valley/shadowmoon_valley.cpp @@ -1106,73 +1106,73 @@ void AddSC_shadowmoon_valley() newscript = new Script; newscript->Name = "mob_mature_netherwing_drake"; newscript->GetAI = GetAI_mob_mature_netherwing_drake; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_enslaved_netherwing_drake"; newscript->GetAI = GetAI_mob_enslaved_netherwing_drake; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "mob_dragonmaw_peon"; newscript->GetAI = GetAI_mob_dragonmaw_peon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_drake_dealer_hurlunk"; newscript->pGossipHello = &GossipHello_npc_drake_dealer_hurlunk; newscript->pGossipSelect = &GossipSelect_npc_drake_dealer_hurlunk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_invis_legion_teleporter"; newscript->GetAI = GetAI_npc_invis_legion_teleporter; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npcs_flanis_swiftwing_and_kagrosh"; newscript->pGossipHello = &GossipHello_npcs_flanis_swiftwing_and_kagrosh; newscript->pGossipSelect = &GossipSelect_npcs_flanis_swiftwing_and_kagrosh; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_murkblood_overseer"; newscript->pGossipHello = &GossipHello_npc_murkblood_overseer; newscript->pGossipSelect = &GossipSelect_npc_murkblood_overseer; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_neltharaku"; newscript->pGossipHello = &GossipHello_npc_neltharaku; newscript->pGossipSelect = &GossipSelect_npc_neltharaku; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_karynaku"; newscript->pQuestAccept = &QuestAccept_npc_karynaku; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_oronok_tornheart"; newscript->pGossipHello = &GossipHello_npc_oronok_tornheart; newscript->pGossipSelect = &GossipSelect_npc_oronok_tornheart; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_overlord_morghor"; newscript->GetAI = GetAI_Overlord_Morghor; newscript->pQuestAccept = &QuestAccept_Overlord_Morghor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_lord_illidan_stormrage"; newscript->GetAI = GetAI_Lord_Illidan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_yarzill_the_merc"; newscript->GetAI = GetAI_Yarzill_The_Merc; newscript->pGossipHello = &GossipHello_npc_yarzill_fly; newscript->pGossipSelect = &GossipSelect_npc_yarzill_fly; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/shattrath/shattrath_city.cpp b/src/bindings/scripts/scripts/zone/shattrath/shattrath_city.cpp index 41cb56585ef..f974e0ec16d 100644 --- a/src/bindings/scripts/scripts/zone/shattrath/shattrath_city.cpp +++ b/src/bindings/scripts/scripts/zone/shattrath/shattrath_city.cpp @@ -414,28 +414,28 @@ void AddSC_shattrath_city() newscript->Name="npc_raliq_the_drunk"; newscript->pGossipHello = &GossipHello_npc_raliq_the_drunk; newscript->pGossipSelect = &GossipSelect_npc_raliq_the_drunk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_salsalabim"; newscript->GetAI = GetAI_npc_salsalabim; newscript->pGossipHello = &GossipHello_npc_salsalabim; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_shattrathflaskvendors"; newscript->pGossipHello = &GossipHello_npc_shattrathflaskvendors; newscript->pGossipSelect = &GossipSelect_npc_shattrathflaskvendors; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_zephyr"; newscript->pGossipHello = &GossipHello_npc_zephyr; newscript->pGossipSelect = &GossipSelect_npc_zephyr; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_kservant"; newscript->GetAI = GetAI_npc_kservantAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/silithus/silithus.cpp b/src/bindings/scripts/scripts/zone/silithus/silithus.cpp index 5e05fa60630..bf868318342 100644 --- a/src/bindings/scripts/scripts/zone/silithus/silithus.cpp +++ b/src/bindings/scripts/scripts/zone/silithus/silithus.cpp @@ -145,5 +145,5 @@ void AddSC_silithus() newscript->Name="npcs_rutgar_and_frankal"; newscript->pGossipHello = &GossipHello_npcs_rutgar_and_frankal; newscript->pGossipSelect = &GossipSelect_npcs_rutgar_and_frankal; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/silvermoon/silvermoon_city.cpp b/src/bindings/scripts/scripts/zone/silvermoon/silvermoon_city.cpp index 077c078b64a..d50a1fcbdf8 100644 --- a/src/bindings/scripts/scripts/zone/silvermoon/silvermoon_city.cpp +++ b/src/bindings/scripts/scripts/zone/silvermoon/silvermoon_city.cpp @@ -99,5 +99,5 @@ void AddSC_silvermoon_city() newscript = new Script; newscript->Name="npc_blood_knight_stillblade"; newscript->GetAI = GetAI_npc_blood_knight_stillblade; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/silverpine_forest/silverpine_forest.cpp b/src/bindings/scripts/scripts/zone/silverpine_forest/silverpine_forest.cpp index 597ab1ccb8d..b511ccbba4e 100644 --- a/src/bindings/scripts/scripts/zone/silverpine_forest/silverpine_forest.cpp +++ b/src/bindings/scripts/scripts/zone/silverpine_forest/silverpine_forest.cpp @@ -96,5 +96,5 @@ void AddSC_silverpine_forest() newscript->pGossipHello = &GossipHello_npc_astor_hadren; newscript->pGossipSelect = &GossipSelect_npc_astor_hadren; newscript->GetAI = GetAI_npc_astor_hadren; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stonetalon_mountains/stonetalon_mountains.cpp b/src/bindings/scripts/scripts/zone/stonetalon_mountains/stonetalon_mountains.cpp index 40cb6367379..28f0c644726 100644 --- a/src/bindings/scripts/scripts/zone/stonetalon_mountains/stonetalon_mountains.cpp +++ b/src/bindings/scripts/scripts/zone/stonetalon_mountains/stonetalon_mountains.cpp @@ -76,5 +76,5 @@ void AddSC_stonetalon_mountains() newscript->Name="npc_braug_dimspirit"; newscript->pGossipHello = &GossipHello_npc_braug_dimspirit; newscript->pGossipSelect = &GossipSelect_npc_braug_dimspirit; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stormwind/stormwind_city.cpp b/src/bindings/scripts/scripts/zone/stormwind/stormwind_city.cpp index b84b1d98cb6..9c34ec3d926 100644 --- a/src/bindings/scripts/scripts/zone/stormwind/stormwind_city.cpp +++ b/src/bindings/scripts/scripts/zone/stormwind/stormwind_city.cpp @@ -245,28 +245,28 @@ void AddSC_stormwind_city() newscript->Name="npc_archmage_malin"; newscript->pGossipHello = &GossipHello_npc_archmage_malin; newscript->pGossipSelect = &GossipSelect_npc_archmage_malin; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_bartleby"; newscript->GetAI = GetAI_npc_bartleby; newscript->pQuestAccept = &QuestAccept_npc_bartleby; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_dashel_stonefist"; newscript->GetAI = GetAI_npc_dashel_stonefist; newscript->pQuestAccept = &QuestAccept_npc_dashel_stonefist; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_general_marcus_jonathan"; newscript->pReceiveEmote = &ReceiveEmote_npc_general_marcus_jonathan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_lady_katrana_prestor"; newscript->pGossipHello = &GossipHello_npc_lady_katrana_prestor; newscript->pGossipSelect = &GossipSelect_npc_lady_katrana_prestor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stranglethorn_vale/stranglethorn_vale.cpp b/src/bindings/scripts/scripts/zone/stranglethorn_vale/stranglethorn_vale.cpp index 40ff438cbd1..426c56c679d 100644 --- a/src/bindings/scripts/scripts/zone/stranglethorn_vale/stranglethorn_vale.cpp +++ b/src/bindings/scripts/scripts/zone/stranglethorn_vale/stranglethorn_vale.cpp @@ -103,5 +103,5 @@ void AddSC_stranglethorn_vale() newscript = new Script; newscript->Name = "mob_yenniku"; newscript->GetAI = GetAI_mob_yenniku; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_baron_rivendare.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_baron_rivendare.cpp index d3cfa97be75..aac9c590c97 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_baron_rivendare.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_baron_rivendare.cpp @@ -211,5 +211,5 @@ void AddSC_boss_baron_rivendare() newscript = new Script; newscript->Name="boss_baron_rivendare"; newscript->GetAI = GetAI_boss_baron_rivendare; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_baroness_anastari.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_baroness_anastari.cpp index f1315e66b83..8c88353878c 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_baroness_anastari.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_baroness_anastari.cpp @@ -120,5 +120,5 @@ void AddSC_boss_baroness_anastari() newscript = new Script; newscript->Name="boss_baroness_anastari"; newscript->GetAI = GetAI_boss_baroness_anastari; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_cannon_master_willey.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_cannon_master_willey.cpp index 4c1bd05b432..d3e1c4e2a3a 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_cannon_master_willey.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_cannon_master_willey.cpp @@ -217,5 +217,5 @@ void AddSC_boss_cannon_master_willey() newscript = new Script; newscript->Name="boss_cannon_master_willey"; newscript->GetAI = GetAI_boss_cannon_master_willey; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_dathrohan_balnazzar.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_dathrohan_balnazzar.cpp index 3d084fe0736..67503358d9d 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_dathrohan_balnazzar.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_dathrohan_balnazzar.cpp @@ -312,5 +312,5 @@ void AddSC_boss_dathrohan_balnazzar() newscript = new Script; newscript->Name="boss_dathrohan_balnazzar"; newscript->GetAI = GetAI_boss_dathrohan_balnazzar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_magistrate_barthilas.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_magistrate_barthilas.cpp index cbea76cf205..daa8da39a67 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_magistrate_barthilas.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_magistrate_barthilas.cpp @@ -110,5 +110,5 @@ void AddSC_boss_magistrate_barthilas() newscript = new Script; newscript->Name="boss_magistrate_barthilas"; newscript->GetAI = GetAI_boss_magistrate_barthilas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_maleki_the_pallid.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_maleki_the_pallid.cpp index e0f9c43cba7..d3d60121a87 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_maleki_the_pallid.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_maleki_the_pallid.cpp @@ -115,5 +115,5 @@ void AddSC_boss_maleki_the_pallid() newscript = new Script; newscript->Name="boss_maleki_the_pallid"; newscript->GetAI = GetAI_boss_maleki_the_pallid; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_nerubenkan.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_nerubenkan.cpp index 3929f2513dd..b56e643bdb2 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_nerubenkan.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_nerubenkan.cpp @@ -134,5 +134,5 @@ void AddSC_boss_nerubenkan() newscript = new Script; newscript->Name="boss_nerubenkan"; newscript->GetAI = GetAI_boss_nerubenkan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_order_of_silver_hand.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_order_of_silver_hand.cpp index a76913b658c..ee92be7737d 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_order_of_silver_hand.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_order_of_silver_hand.cpp @@ -157,5 +157,5 @@ void AddSC_boss_order_of_silver_hand() newscript = new Script; newscript->Name="boss_silver_hand_bosses"; newscript->GetAI = GetAI_boss_silver_hand_bossesAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_postmaster_malown.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_postmaster_malown.cpp index a4eddd46b5e..d0514bd2eb8 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_postmaster_malown.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_postmaster_malown.cpp @@ -140,5 +140,5 @@ void AddSC_boss_postmaster_malown() newscript = new Script; newscript->Name="boss_postmaster_malown"; newscript->GetAI = GetAI_boss_postmaster_malown; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_ramstein_the_gorger.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_ramstein_the_gorger.cpp index 674d4403266..b2965f09edf 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_ramstein_the_gorger.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_ramstein_the_gorger.cpp @@ -88,5 +88,5 @@ void AddSC_boss_ramstein_the_gorger() newscript = new Script; newscript->Name="boss_ramstein_the_gorger"; newscript->GetAI = GetAI_boss_ramstein_the_gorger; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/boss_timmy_the_cruel.cpp b/src/bindings/scripts/scripts/zone/stratholme/boss_timmy_the_cruel.cpp index 2256c064e11..4f526041e35 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/boss_timmy_the_cruel.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/boss_timmy_the_cruel.cpp @@ -96,5 +96,5 @@ void AddSC_boss_timmy_the_cruel() newscript = new Script; newscript->Name="boss_timmy_the_cruel"; newscript->GetAI = GetAI_boss_timmy_the_cruel; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/instance_stratholme.cpp b/src/bindings/scripts/scripts/zone/stratholme/instance_stratholme.cpp index eff4edf91a8..74181d6a15e 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/instance_stratholme.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/instance_stratholme.cpp @@ -73,5 +73,5 @@ void AddSC_instance_stratholme() newscript = new Script; newscript->Name = "instance_stratholme"; newscript->GetInstanceData = GetInstanceData_instance_stratholme; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/stratholme/stratholme.cpp b/src/bindings/scripts/scripts/zone/stratholme/stratholme.cpp index 5097648a04a..2a38abe9311 100644 --- a/src/bindings/scripts/scripts/zone/stratholme/stratholme.cpp +++ b/src/bindings/scripts/scripts/zone/stratholme/stratholme.cpp @@ -310,26 +310,26 @@ void AddSC_stratholme() newscript = new Script; newscript->Name="mob_freed_soul"; newscript->GetAI = GetAI_mob_freed_soul; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_restless_soul"; newscript->GetAI = GetAI_mob_restless_soul; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mobs_spectral_ghostly_citizen"; newscript->GetAI = GetAI_mobs_spectral_ghostly_citizen; newscript->pReceiveEmote = &ReciveEmote_mobs_spectral_ghostly_citizen; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_mindless_skeleton"; newscript->GetAI = GetAI_mob_mindless_skeleton; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_thuzadin_acolyte"; newscript->GetAI = GetAI_mob_thuzadin_acolyte; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_brutallus.cpp b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_brutallus.cpp index fc1bca5233f..24ce8dc4a91 100644 --- a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_brutallus.cpp +++ b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_brutallus.cpp @@ -178,5 +178,5 @@ void AddSC_boss_brutallus() newscript = new Script; newscript->Name="boss_brutallus"; newscript->GetAI = GetAI_boss_brutallus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_eredar_twins.cpp b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_eredar_twins.cpp index b49f0e391f3..b7e076b85d3 100644 --- a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_eredar_twins.cpp +++ b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_eredar_twins.cpp @@ -761,15 +761,15 @@ void AddSC_boss_eredar_twins() newscript = new Script; newscript->Name="boss_sacrolash"; newscript->GetAI = GetAI_boss_sacrolash; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_alythess"; newscript->GetAI = GetAI_boss_alythess; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_shadow_image"; newscript->GetAI = GetAI_mob_shadow_image; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp index afc95cc8191..9f2b89b44f2 100644 --- a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp +++ b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_felmyst.cpp @@ -574,15 +574,15 @@ void AddSC_boss_felmyst() newscript = new Script; newscript->Name="boss_felmyst"; newscript->GetAI = GetAI_boss_felmyst; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_felmyst_vapor"; newscript->GetAI = GetAI_mob_felmyst_vapor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_felmyst_trail"; newscript->GetAI = GetAI_mob_felmyst_trail; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp index 96a79107296..79d0d3766b8 100644 --- a/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp +++ b/src/bindings/scripts/scripts/zone/sunwell_plateau/boss_kalecgos.cpp @@ -680,20 +680,20 @@ void AddSC_boss_kalecgos() newscript = new Script; newscript->Name="boss_kalecgos"; newscript->GetAI = GetAI_boss_kalecgos; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_sathrovarr"; newscript->GetAI = GetAI_boss_Sathrovarr; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_kalec"; newscript->GetAI = GetAI_boss_kalec; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="kalocegos_teleporter"; newscript->pGOHello = &GOkalocegos_teleporter; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } \ No newline at end of file diff --git a/src/bindings/scripts/scripts/zone/sunwell_plateau/instance_sunwell_plateau.cpp b/src/bindings/scripts/scripts/zone/sunwell_plateau/instance_sunwell_plateau.cpp index a94cf460a83..98b0bd443b1 100644 --- a/src/bindings/scripts/scripts/zone/sunwell_plateau/instance_sunwell_plateau.cpp +++ b/src/bindings/scripts/scripts/zone/sunwell_plateau/instance_sunwell_plateau.cpp @@ -192,5 +192,5 @@ void AddSC_instance_sunwell_plateau() newscript = new Script; newscript->Name = "instance_sunwell_plateau"; newscript->GetInstanceData = GetInstanceData_instance_sunwell_plateau; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tanaris/tanaris.cpp b/src/bindings/scripts/scripts/zone/tanaris/tanaris.cpp index 2eb6ab80335..c6700af3e67 100644 --- a/src/bindings/scripts/scripts/zone/tanaris/tanaris.cpp +++ b/src/bindings/scripts/scripts/zone/tanaris/tanaris.cpp @@ -374,29 +374,29 @@ void AddSC_tanaris() newscript = new Script; newscript->Name="mob_aquementas"; newscript->GetAI = GetAI_mob_aquementas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_custodian_of_time"; newscript->GetAI = GetAI_npc_custodian_of_time; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_marin_noggenfogger"; newscript->pGossipHello = &GossipHello_npc_marin_noggenfogger; newscript->pGossipSelect = &GossipSelect_npc_marin_noggenfogger; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_steward_of_time"; newscript->pGossipHello = &GossipHello_npc_steward_of_time; newscript->pGossipSelect = &GossipSelect_npc_steward_of_time; newscript->pQuestAccept = &QuestAccept_npc_steward_of_time; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_stone_watcher_of_norgannon"; newscript->pGossipHello = &GossipHello_npc_stone_watcher_of_norgannon; newscript->pGossipSelect = &GossipSelect_npc_stone_watcher_of_norgannon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/arcatraz.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/arcatraz.cpp index f928a41e1e0..624ad419243 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/arcatraz.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/arcatraz.cpp @@ -575,15 +575,15 @@ void AddSC_arcatraz() newscript = new Script; newscript->Name="npc_millhouse_manastorm"; newscript->GetAI = GetAI_npc_millhouse_manastorm; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_warden_mellichar"; newscript->GetAI = GetAI_npc_warden_mellichar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_zerekethvoidzone"; newscript->GetAI = GetAI_mob_zerekethvoidzoneAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/boss_harbinger_skyriss.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/boss_harbinger_skyriss.cpp index fcd8cf2c607..808604d2375 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/boss_harbinger_skyriss.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/boss_harbinger_skyriss.cpp @@ -367,10 +367,10 @@ void AddSC_boss_harbinger_skyriss() newscript = new Script; newscript->Name="boss_harbinger_skyriss"; newscript->GetAI = GetAI_boss_harbinger_skyriss; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_harbinger_skyriss_illusion"; newscript->GetAI = GetAI_boss_harbinger_skyriss_illusion; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/instance_arcatraz.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/instance_arcatraz.cpp index 93f21f2a72f..2325680d53b 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/instance_arcatraz.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/arcatraz/instance_arcatraz.cpp @@ -220,5 +220,5 @@ void AddSC_instance_arcatraz() newscript = new Script; newscript->Name = "instance_arcatraz"; newscript->GetInstanceData = GetInstanceData_instance_arcatraz; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_high_botanist_freywinn.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_high_botanist_freywinn.cpp index 201b5936ee9..334fdf07b98 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_high_botanist_freywinn.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_high_botanist_freywinn.cpp @@ -211,5 +211,5 @@ void AddSC_boss_high_botanist_freywinn() newscript = new Script; newscript->Name="boss_high_botanist_freywinn"; newscript->GetAI = GetAI_boss_high_botanist_freywinn; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_laj.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_laj.cpp index c714c470c55..09a237f53cf 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_laj.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_laj.cpp @@ -194,5 +194,5 @@ void AddSC_boss_laj() newscript = new Script; newscript->Name="boss_laj"; newscript->GetAI = GetAI_boss_laj; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_warp_splinter.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_warp_splinter.cpp index 5f7c87adff4..f0dc111e896 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_warp_splinter.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/botanica/boss_warp_splinter.cpp @@ -293,10 +293,10 @@ void AddSC_boss_warp_splinter() newscript = new Script; newscript->Name="boss_warp_splinter"; newscript->GetAI = GetAI_boss_warp_splinter; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_warp_splinter_treant"; newscript->GetAI = GetAI_mob_treant; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_alar.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_alar.cpp index 617fd29dbc2..138d3d19f99 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_alar.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_alar.cpp @@ -505,15 +505,15 @@ void AddSC_boss_alar() newscript = new Script; newscript->Name="boss_alar"; newscript->GetAI = GetAI_boss_alar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_ember_of_alar"; newscript->GetAI = GetAI_mob_ember_of_alar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_flame_patch_alar"; newscript->GetAI = GetAI_mob_flame_patch_alar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_astromancer.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_astromancer.cpp index 477aab20241..9e93eac4693 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_astromancer.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_astromancer.cpp @@ -536,10 +536,10 @@ void AddSC_boss_high_astromancer_solarian() newscript = new Script; newscript->Name="boss_high_astromancer_solarian"; newscript->GetAI = GetAI_boss_high_astromancer_solarian; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_solarium_priest"; newscript->GetAI = GetAI_mob_solarium_priest; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_kaelthas.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_kaelthas.cpp index ddbfbb65bf2..ca5d8dcf7dd 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_kaelthas.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_kaelthas.cpp @@ -1581,35 +1581,35 @@ void AddSC_boss_kaelthas() newscript = new Script; newscript->Name="boss_kaelthas"; newscript->GetAI = GetAI_boss_kaelthas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_thaladred_the_darkener"; newscript->GetAI = GetAI_boss_thaladred_the_darkener; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lord_sanguinar"; newscript->GetAI = GetAI_boss_lord_sanguinar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_grand_astromancer_capernian"; newscript->GetAI = GetAI_boss_grand_astromancer_capernian; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_master_engineer_telonicus"; newscript->GetAI = GetAI_boss_master_engineer_telonicus; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name= "mob_kael_flamestrike"; newscript->GetAI = GetAI_mob_kael_flamestrike; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_phoenix"; newscript->GetAI = GetAI_mob_phoenix; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_void_reaver.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_void_reaver.cpp index 406e7e4d9ab..de6335e79e3 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_void_reaver.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/boss_void_reaver.cpp @@ -195,5 +195,5 @@ void AddSC_boss_void_reaver() newscript = new Script; newscript->Name="boss_void_reaver"; newscript->GetAI = GetAI_boss_void_reaver; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/instance_the_eye.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/instance_the_eye.cpp index 3f1316d45e8..1fa1030a991 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/instance_the_eye.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/instance_the_eye.cpp @@ -172,5 +172,5 @@ void AddSC_instance_the_eye() newscript = new Script; newscript->Name = "instance_the_eye"; newscript->GetInstanceData = GetInstanceData_instance_the_eye; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/the_eye.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/the_eye.cpp index cd2962b509a..18d37e88bdc 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/the_eye.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_eye/the_eye.cpp @@ -94,5 +94,5 @@ void AddSC_the_eye() newscript = new Script; newscript->Name="mob_crystalcore_devastator"; newscript->GetAI = GetAI_mob_crystalcore_devastator; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_gatewatcher_ironhand.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_gatewatcher_ironhand.cpp index 90ec4076d21..dfc5d70bb42 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_gatewatcher_ironhand.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_gatewatcher_ironhand.cpp @@ -157,5 +157,5 @@ void AddSC_boss_gatewatcher_iron_hand() newscript = new Script; newscript->Name="boss_gatewatcher_iron_hand"; newscript->GetAI = GetAI_boss_gatewatcher_iron_hand; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_nethermancer_sepethrea.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_nethermancer_sepethrea.cpp index 866f641922c..d077f5b8c0c 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_nethermancer_sepethrea.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_nethermancer_sepethrea.cpp @@ -277,10 +277,10 @@ void AddSC_boss_nethermancer_sepethrea() newscript = new Script; newscript->Name="boss_nethermancer_sepethrea"; newscript->GetAI = GetAI_boss_nethermancer_sepethrea; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_ragin_flames"; newscript->GetAI = GetAI_mob_ragin_flames; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_pathaleon_the_calculator.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_pathaleon_the_calculator.cpp index 06c57082357..842da61d9bf 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_pathaleon_the_calculator.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/boss_pathaleon_the_calculator.cpp @@ -1,306 +1,306 @@ -/* Copyright (C) 2006 - 2008 ScriptDev2 -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -/* ScriptData -SDName: Boss Pathaleon the Calculator -SD%Complete: 50 -SDComment: Event missing. Script for himself 99% blizzlike. -SDCategory: Tempest Keep, The Mechanar -EndScriptData */ - -#include "precompiled.h" - -// Spells to be casted -#define SPELL_SUMMON_NETHER_WRAITH 35287 //Spell not working. Summon is working but Pets dont attack and wrong HP. -#define SPELL_MANA_TAP 36021 -#define SPELL_ARCANE_TORRENT 36022 -#define SPELL_DOMINATION 35280 -#define H_SPELL_ARCANE_EXPLOSION 34791 //Spell not right. -#define SPELL_ENRAGE 36992 - -// Add Spells -#define SPELL_DETONATION 35058 -#define SPELL_ARCANE_MISSILES 35034 - -// On Domination -#define SAY_SPELL_DOMINATION_1 "I'm looking for a team player... " -#define SOUND_SPELL_DOMINATION_1 11197 -#define SAY_SPELL_DOMINATION_2 "You work for me now!" -#define SOUND_SPELL_DOMINATION_2 11198 - -// On Summon -#define SAY_SUMMON_1 "Time to supplement my work force." -#define SOUND_SAY_SUMMON_1 11196 - -// On Enrage -#define SAY_ENRAGE_1 "A minor inconvenience." -#define SOUND_SAY_ENRAGE_1 11199 - -// On Aggro -#define SAY_AGGRO_1 "We are on a strict timetable. You will not interfere!" -#define SOUND_SAY_AGGRO_1 11193 - -//On Kill Unit -#define SAY_SLAY_1 "Looks like you lose" -#define SOUND_SLAY_1 11195 - -// On Death -#define SAY_DEATH_1 "The project will... continue." -#define SOUND_DEATH_1 11200 - - -struct TRINITY_DLL_DECL boss_pathaleon_the_calculatorAI : public ScriptedAI -{ - boss_pathaleon_the_calculatorAI(Creature *c) : ScriptedAI(c) - { - HeroicMode = m_creature->GetMap()->IsHeroic(); - Reset(); - } - - uint32 Summon_Timer; - uint32 ManaTap_Timer; - uint32 ArcaneTorrent_Timer; - uint32 Domination_Timer; - uint32 ArcaneExplosion_Timer; - bool HeroicMode; - bool Enraged; - - uint32 Counter; - Creature* Wraith; - - void Reset() - { - Summon_Timer = 30000; - ManaTap_Timer = 12000 + rand()%8000; - ArcaneTorrent_Timer = 16000 + rand()%9000; - Domination_Timer = 25000 + rand()%15000; - ArcaneExplosion_Timer = 8000 + rand()%5000; - - Enraged = false; - - Counter = 0; - - } - void Aggro(Unit *who) - { - DoYell(SAY_AGGRO_1,LANG_UNIVERSAL,NULL); - DoPlaySoundToSet(m_creature, SOUND_SAY_AGGRO_1); - } - - // On Killed Unit - void KilledUnit(Unit* victim) - { - - DoYell(SAY_SLAY_1, LANG_UNIVERSAL, NULL); - DoPlaySoundToSet(m_creature,SOUND_SLAY_1); - - } - - // On Death - void JustDied(Unit* Killer) - { - DoYell(SAY_DEATH_1,LANG_UNIVERSAL,NULL); - DoPlaySoundToSet(m_creature, SOUND_DEATH_1); - } - - void UpdateAI(const uint32 diff) - { - //Return since we have no target - if (!m_creature->SelectHostilTarget() || !m_creature->getVictim() ) - return; - - if(Summon_Timer < diff) - { - - Unit* target = NULL; - - for(int i = 0; i < 3;i++) - { - target = SelectUnit(SELECT_TARGET_RANDOM,0); - Wraith = m_creature->SummonCreature(21062,m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(),0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); - if (target) - Wraith->AI()->AttackStart(target); - } - - DoYell(SAY_SUMMON_1,LANG_UNIVERSAL,NULL); - DoPlaySoundToSet(m_creature, SOUND_SAY_SUMMON_1); - - Summon_Timer = 30000 + rand()%15000; - }else Summon_Timer -= diff; - - if(ManaTap_Timer < diff) - { - //time to cast - DoCast(m_creature->getVictim(),SPELL_MANA_TAP); - - //Cast again on time - ManaTap_Timer = 14000 + rand()%8000; - }else ManaTap_Timer -= diff; - - if(ArcaneTorrent_Timer < diff) - { - //time to cast - DoCast(m_creature->getVictim(),SPELL_ARCANE_TORRENT); - - //Cast again on time - ArcaneTorrent_Timer = 12000 + rand()%6000; - }else ArcaneTorrent_Timer -= diff; - - if(Domination_Timer < diff) - { - //time to cast - switch(rand()%2) - { - case 0: - DoYell(SAY_SPELL_DOMINATION_1, LANG_UNIVERSAL, NULL); - DoPlaySoundToSet(m_creature, SOUND_SPELL_DOMINATION_1); - break; - - case 1: - DoYell(SAY_SPELL_DOMINATION_2, LANG_UNIVERSAL, NULL); - DoPlaySoundToSet(m_creature, SOUND_SPELL_DOMINATION_2); - break; - } - - Unit* target = NULL; - target = SelectUnit(SELECT_TARGET_RANDOM,1); - if (target) DoCast(target,SPELL_DOMINATION); - - //Cast again on time - Domination_Timer = 25000 + rand()%5000; - }else Domination_Timer -= diff; - - //Only casting if Heroic Mode is used - if (HeroicMode) - { - if(ArcaneExplosion_Timer < diff) - { - //time to cast - DoCast(m_creature->getVictim(),H_SPELL_ARCANE_EXPLOSION); - - //Cast again on time - ArcaneExplosion_Timer = 10000 + rand()%4000; - }else ArcaneExplosion_Timer -= diff; - } - - if (!Enraged && m_creature->GetHealth()*100 / m_creature->GetMaxHealth() < 21) - { - - DoCast(m_creature, SPELL_ENRAGE); - DoYell(SAY_ENRAGE_1, LANG_UNIVERSAL, NULL); - DoPlaySoundToSet(m_creature,SOUND_SAY_ENRAGE_1); - Enraged = true; - - } - - DoMeleeAttackIfReady(); - } -}; -CreatureAI* GetAI_boss_pathaleon_the_calculator(Creature *_Creature) -{ - return new boss_pathaleon_the_calculatorAI (_Creature); -} - -struct TRINITY_DLL_DECL mob_nether_wraithAI : public ScriptedAI -{ - mob_nether_wraithAI(Creature *c) : ScriptedAI(c) {Reset();} - - ScriptedInstance *pInstance; - - uint32 ArcaneMissiles_Timer; - uint32 Detonation_Timer; - uint32 Die_Timer; - bool Detonation; - - void Reset() - { - ArcaneMissiles_Timer = 1000 + rand()%3000; - Detonation_Timer = 20000; - Die_Timer = 2200; - Detonation = false; - - } - - void Aggro(Unit* who) - { - } - - void UpdateAI(const uint32 diff) - { - Unit* target = NULL; - - if (!m_creature->SelectHostilTarget() || !m_creature->getVictim()) - return; - - if(ArcaneMissiles_Timer < diff) - { - - Unit* target = NULL; - target = SelectUnit(SELECT_TARGET_RANDOM,1); - if (!target) - target = m_creature->getVictim(); - if (target) - { - DoCast(target,SPELL_ARCANE_MISSILES); - } - - ArcaneMissiles_Timer = 5000 + rand()%5000; - }else ArcaneMissiles_Timer -=diff; - - if (!Detonation) - { - if(Detonation_Timer < diff) - { - //time to cast - DoCast(m_creature,SPELL_DETONATION); - Detonation = true; - - }else Detonation_Timer -= diff; - - } - - if (Detonation) - { - if (Die_Timer < diff) - { - m_creature->setDeathState(JUST_DIED); - m_creature->RemoveCorpse(); - }else Die_Timer -= diff; - } - - - DoMeleeAttackIfReady(); - } - -}; -CreatureAI* GetAI_mob_nether_wraith(Creature *_Creature) -{ - return new mob_nether_wraithAI (_Creature); -} - -void AddSC_boss_pathaleon_the_calculator() -{ - Script *newscript; - newscript = new Script; - newscript->Name="boss_pathaleon_the_calculator"; - newscript->GetAI = GetAI_boss_pathaleon_the_calculator; - m_scripts[nrscripts++] = newscript; - - newscript = new Script; - newscript->Name="mob_nether_wraith"; - newscript->GetAI = GetAI_mob_nether_wraith; - m_scripts[nrscripts++] = newscript; -} +/* Copyright (C) 2006 - 2008 ScriptDev2 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* ScriptData +SDName: Boss Pathaleon the Calculator +SD%Complete: 50 +SDComment: Event missing. Script for himself 99% blizzlike. +SDCategory: Tempest Keep, The Mechanar +EndScriptData */ + +#include "precompiled.h" + +// Spells to be casted +#define SPELL_SUMMON_NETHER_WRAITH 35287 //Spell not working. Summon is working but Pets dont attack and wrong HP. +#define SPELL_MANA_TAP 36021 +#define SPELL_ARCANE_TORRENT 36022 +#define SPELL_DOMINATION 35280 +#define H_SPELL_ARCANE_EXPLOSION 34791 //Spell not right. +#define SPELL_ENRAGE 36992 + +// Add Spells +#define SPELL_DETONATION 35058 +#define SPELL_ARCANE_MISSILES 35034 + +// On Domination +#define SAY_SPELL_DOMINATION_1 "I'm looking for a team player... " +#define SOUND_SPELL_DOMINATION_1 11197 +#define SAY_SPELL_DOMINATION_2 "You work for me now!" +#define SOUND_SPELL_DOMINATION_2 11198 + +// On Summon +#define SAY_SUMMON_1 "Time to supplement my work force." +#define SOUND_SAY_SUMMON_1 11196 + +// On Enrage +#define SAY_ENRAGE_1 "A minor inconvenience." +#define SOUND_SAY_ENRAGE_1 11199 + +// On Aggro +#define SAY_AGGRO_1 "We are on a strict timetable. You will not interfere!" +#define SOUND_SAY_AGGRO_1 11193 + +//On Kill Unit +#define SAY_SLAY_1 "Looks like you lose" +#define SOUND_SLAY_1 11195 + +// On Death +#define SAY_DEATH_1 "The project will... continue." +#define SOUND_DEATH_1 11200 + + +struct TRINITY_DLL_DECL boss_pathaleon_the_calculatorAI : public ScriptedAI +{ + boss_pathaleon_the_calculatorAI(Creature *c) : ScriptedAI(c) + { + HeroicMode = m_creature->GetMap()->IsHeroic(); + Reset(); + } + + uint32 Summon_Timer; + uint32 ManaTap_Timer; + uint32 ArcaneTorrent_Timer; + uint32 Domination_Timer; + uint32 ArcaneExplosion_Timer; + bool HeroicMode; + bool Enraged; + + uint32 Counter; + Creature* Wraith; + + void Reset() + { + Summon_Timer = 30000; + ManaTap_Timer = 12000 + rand()%8000; + ArcaneTorrent_Timer = 16000 + rand()%9000; + Domination_Timer = 25000 + rand()%15000; + ArcaneExplosion_Timer = 8000 + rand()%5000; + + Enraged = false; + + Counter = 0; + + } + void Aggro(Unit *who) + { + DoYell(SAY_AGGRO_1,LANG_UNIVERSAL,NULL); + DoPlaySoundToSet(m_creature, SOUND_SAY_AGGRO_1); + } + + // On Killed Unit + void KilledUnit(Unit* victim) + { + + DoYell(SAY_SLAY_1, LANG_UNIVERSAL, NULL); + DoPlaySoundToSet(m_creature,SOUND_SLAY_1); + + } + + // On Death + void JustDied(Unit* Killer) + { + DoYell(SAY_DEATH_1,LANG_UNIVERSAL,NULL); + DoPlaySoundToSet(m_creature, SOUND_DEATH_1); + } + + void UpdateAI(const uint32 diff) + { + //Return since we have no target + if (!m_creature->SelectHostilTarget() || !m_creature->getVictim() ) + return; + + if(Summon_Timer < diff) + { + + Unit* target = NULL; + + for(int i = 0; i < 3;i++) + { + target = SelectUnit(SELECT_TARGET_RANDOM,0); + Wraith = m_creature->SummonCreature(21062,m_creature->GetPositionX(), m_creature->GetPositionY(), m_creature->GetPositionZ(),0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000); + if (target) + Wraith->AI()->AttackStart(target); + } + + DoYell(SAY_SUMMON_1,LANG_UNIVERSAL,NULL); + DoPlaySoundToSet(m_creature, SOUND_SAY_SUMMON_1); + + Summon_Timer = 30000 + rand()%15000; + }else Summon_Timer -= diff; + + if(ManaTap_Timer < diff) + { + //time to cast + DoCast(m_creature->getVictim(),SPELL_MANA_TAP); + + //Cast again on time + ManaTap_Timer = 14000 + rand()%8000; + }else ManaTap_Timer -= diff; + + if(ArcaneTorrent_Timer < diff) + { + //time to cast + DoCast(m_creature->getVictim(),SPELL_ARCANE_TORRENT); + + //Cast again on time + ArcaneTorrent_Timer = 12000 + rand()%6000; + }else ArcaneTorrent_Timer -= diff; + + if(Domination_Timer < diff) + { + //time to cast + switch(rand()%2) + { + case 0: + DoYell(SAY_SPELL_DOMINATION_1, LANG_UNIVERSAL, NULL); + DoPlaySoundToSet(m_creature, SOUND_SPELL_DOMINATION_1); + break; + + case 1: + DoYell(SAY_SPELL_DOMINATION_2, LANG_UNIVERSAL, NULL); + DoPlaySoundToSet(m_creature, SOUND_SPELL_DOMINATION_2); + break; + } + + Unit* target = NULL; + target = SelectUnit(SELECT_TARGET_RANDOM,1); + if (target) DoCast(target,SPELL_DOMINATION); + + //Cast again on time + Domination_Timer = 25000 + rand()%5000; + }else Domination_Timer -= diff; + + //Only casting if Heroic Mode is used + if (HeroicMode) + { + if(ArcaneExplosion_Timer < diff) + { + //time to cast + DoCast(m_creature->getVictim(),H_SPELL_ARCANE_EXPLOSION); + + //Cast again on time + ArcaneExplosion_Timer = 10000 + rand()%4000; + }else ArcaneExplosion_Timer -= diff; + } + + if (!Enraged && m_creature->GetHealth()*100 / m_creature->GetMaxHealth() < 21) + { + + DoCast(m_creature, SPELL_ENRAGE); + DoYell(SAY_ENRAGE_1, LANG_UNIVERSAL, NULL); + DoPlaySoundToSet(m_creature,SOUND_SAY_ENRAGE_1); + Enraged = true; + + } + + DoMeleeAttackIfReady(); + } +}; +CreatureAI* GetAI_boss_pathaleon_the_calculator(Creature *_Creature) +{ + return new boss_pathaleon_the_calculatorAI (_Creature); +} + +struct TRINITY_DLL_DECL mob_nether_wraithAI : public ScriptedAI +{ + mob_nether_wraithAI(Creature *c) : ScriptedAI(c) {Reset();} + + ScriptedInstance *pInstance; + + uint32 ArcaneMissiles_Timer; + uint32 Detonation_Timer; + uint32 Die_Timer; + bool Detonation; + + void Reset() + { + ArcaneMissiles_Timer = 1000 + rand()%3000; + Detonation_Timer = 20000; + Die_Timer = 2200; + Detonation = false; + + } + + void Aggro(Unit* who) + { + } + + void UpdateAI(const uint32 diff) + { + Unit* target = NULL; + + if (!m_creature->SelectHostilTarget() || !m_creature->getVictim()) + return; + + if(ArcaneMissiles_Timer < diff) + { + + Unit* target = NULL; + target = SelectUnit(SELECT_TARGET_RANDOM,1); + if (!target) + target = m_creature->getVictim(); + if (target) + { + DoCast(target,SPELL_ARCANE_MISSILES); + } + + ArcaneMissiles_Timer = 5000 + rand()%5000; + }else ArcaneMissiles_Timer -=diff; + + if (!Detonation) + { + if(Detonation_Timer < diff) + { + //time to cast + DoCast(m_creature,SPELL_DETONATION); + Detonation = true; + + }else Detonation_Timer -= diff; + + } + + if (Detonation) + { + if (Die_Timer < diff) + { + m_creature->setDeathState(JUST_DIED); + m_creature->RemoveCorpse(); + }else Die_Timer -= diff; + } + + + DoMeleeAttackIfReady(); + } + +}; +CreatureAI* GetAI_mob_nether_wraith(Creature *_Creature) +{ + return new mob_nether_wraithAI (_Creature); +} + +void AddSC_boss_pathaleon_the_calculator() +{ + Script *newscript; + newscript = new Script; + newscript->Name="boss_pathaleon_the_calculator"; + newscript->GetAI = GetAI_boss_pathaleon_the_calculator; + newscript->RegisterSelf(); + + newscript = new Script; + newscript->Name="mob_nether_wraith"; + newscript->GetAI = GetAI_mob_nether_wraith; + newscript->RegisterSelf(); +} diff --git a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/instance_mechanar.cpp b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/instance_mechanar.cpp index c58ab523b90..d25b9d05470 100644 --- a/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/instance_mechanar.cpp +++ b/src/bindings/scripts/scripts/zone/tempest_keep/the_mechanar/instance_mechanar.cpp @@ -1,90 +1,90 @@ -/* Copyright (C) 2006 - 2008 ScriptDev2 - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* ScriptData -SDName: Instance_Mechanar -SD%Complete: 100 -SDComment: -SDCategory: Mechanar -EndScriptData */ - -#include "precompiled.h" -#include "def_mechanar.h" - -struct TRINITY_DLL_DECL instance_mechanar : public ScriptedInstance -{ - instance_mechanar(Map *Map) : ScriptedInstance(Map) {Initialize();}; - - - bool IsBossDied[1]; - - void OnCreatureCreate (Creature *creature, uint32 creature_entry) - { - } - - void Initialize() - { - IsBossDied[0] = false; - } - - bool IsEncounterInProgress() const - { - //not active - return false; - } - - uint32 GetData(uint32 type) - { - switch(type) - { - case DATA_SEPETHREAISDEAD: - if(IsBossDied[0]) - return 1; - break; - } - - return 0; - } - - uint64 GetData64 (uint32 identifier) - { - return 0; - } - - void SetData(uint32 type, uint32 data) - { - switch(type) - { - case DATA_SEPETHREA_DEATH: - IsBossDied[0] = true; - break; - } - } -}; - -InstanceData* GetInstanceData_instance_mechanar(Map* map) -{ - return new instance_mechanar(map); -} - -void AddSC_instance_mechanar() -{ - Script *newscript; - newscript = new Script; - newscript->Name = "instance_mechanar"; - newscript->GetInstanceData = GetInstanceData_instance_mechanar; - m_scripts[nrscripts++] = newscript; -} +/* Copyright (C) 2006 - 2008 ScriptDev2 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* ScriptData +SDName: Instance_Mechanar +SD%Complete: 100 +SDComment: +SDCategory: Mechanar +EndScriptData */ + +#include "precompiled.h" +#include "def_mechanar.h" + +struct TRINITY_DLL_DECL instance_mechanar : public ScriptedInstance +{ + instance_mechanar(Map *Map) : ScriptedInstance(Map) {Initialize();}; + + + bool IsBossDied[1]; + + void OnCreatureCreate (Creature *creature, uint32 creature_entry) + { + } + + void Initialize() + { + IsBossDied[0] = false; + } + + bool IsEncounterInProgress() const + { + //not active + return false; + } + + uint32 GetData(uint32 type) + { + switch(type) + { + case DATA_SEPETHREAISDEAD: + if(IsBossDied[0]) + return 1; + break; + } + + return 0; + } + + uint64 GetData64 (uint32 identifier) + { + return 0; + } + + void SetData(uint32 type, uint32 data) + { + switch(type) + { + case DATA_SEPETHREA_DEATH: + IsBossDied[0] = true; + break; + } + } +}; + +InstanceData* GetInstanceData_instance_mechanar(Map* map) +{ + return new instance_mechanar(map); +} + +void AddSC_instance_mechanar() +{ + Script *newscript; + newscript = new Script; + newscript->Name = "instance_mechanar"; + newscript->GetInstanceData = GetInstanceData_instance_mechanar; + newscript->RegisterSelf(); +} diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_bug_trio.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_bug_trio.cpp index 1dba25cd132..8f2f025f7f1 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_bug_trio.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_bug_trio.cpp @@ -334,15 +334,15 @@ void AddSC_bug_trio() newscript = new Script; newscript->Name="boss_kri"; newscript->GetAI = GetAI_boss_kri; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_vem"; newscript->GetAI = GetAI_boss_vem; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_yauj"; newscript->GetAI = GetAI_boss_yauj; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp index 3548cf92566..b789f68e9aa 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_cthun.cpp @@ -1329,35 +1329,35 @@ void AddSC_boss_cthun() newscript = new Script; newscript->Name="boss_eye_of_cthun"; newscript->GetAI = GetAI_eye_of_cthun; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_cthun"; newscript->GetAI = GetAI_cthun; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_eye_tentacle"; newscript->GetAI = GetAI_eye_tentacle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_claw_tentacle"; newscript->GetAI = GetAI_claw_tentacle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_giant_claw_tentacle"; newscript->GetAI = GetAI_giant_claw_tentacle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_giant_eye_tentacle"; newscript->GetAI = GetAI_giant_eye_tentacle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_giant_flesh_tentacle"; newscript->GetAI = GetAI_flesh_tentacle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_fankriss.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_fankriss.cpp index 331e43d83ef..babd0ebf7c2 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_fankriss.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_fankriss.cpp @@ -186,5 +186,5 @@ void AddSC_boss_fankriss() newscript = new Script; newscript->Name="boss_fankriss"; newscript->GetAI = GetAI_boss_fankriss; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_huhuran.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_huhuran.cpp index 7fb10528dff..51e030fa49d 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_huhuran.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_huhuran.cpp @@ -139,5 +139,5 @@ void AddSC_boss_huhuran() newscript = new Script; newscript->Name="boss_huhuran"; newscript->GetAI = GetAI_boss_huhuran; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_ouro.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_ouro.cpp index df7efb8f123..1e0e8fbca6d 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_ouro.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_ouro.cpp @@ -136,5 +136,5 @@ void AddSC_boss_ouro() newscript = new Script; newscript->Name="boss_ouro"; newscript->GetAI = GetAI_boss_ouro; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_sartura.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_sartura.cpp index 3315e49732c..c9a732493f7 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_sartura.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_sartura.cpp @@ -259,10 +259,10 @@ void AddSC_boss_sartura() newscript = new Script; newscript->Name="boss_sartura"; newscript->GetAI = GetAI_boss_sartura; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_sartura_royal_guard"; newscript->GetAI = GetAI_mob_sartura_royal_guard; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_skeram.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_skeram.cpp index 9d383ef0d61..9194354ddc0 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_skeram.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_skeram.cpp @@ -310,5 +310,5 @@ void AddSC_boss_skeram() newscript = new Script; newscript->Name="boss_skeram"; newscript->GetAI = GetAI_boss_skeram; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_twinemperors.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_twinemperors.cpp index 2ddb8be73c7..93525ad7246 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_twinemperors.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/boss_twinemperors.cpp @@ -689,10 +689,10 @@ void AddSC_boss_twinemperors() newscript = new Script; newscript->Name="boss_veknilash"; newscript->GetAI = GetAI_boss_veknilash; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_veklor"; newscript->GetAI = GetAI_boss_veklor; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/instance_temple_of_ahnqiraj.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/instance_temple_of_ahnqiraj.cpp index f502b2aa23d..84713b190cf 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/instance_temple_of_ahnqiraj.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/instance_temple_of_ahnqiraj.cpp @@ -161,5 +161,5 @@ void AddSC_instance_temple_of_ahnqiraj() newscript = new Script; newscript->Name = "instance_temple_of_ahnqiraj"; newscript->GetInstanceData = GetInstanceData_instance_temple_of_ahnqiraj; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp index 1c009721428..f5a55d711b7 100644 --- a/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp +++ b/src/bindings/scripts/scripts/zone/temple_of_ahnqiraj/mob_anubisath_sentinel.cpp @@ -309,7 +309,7 @@ void AddSC_mob_anubisath_sentinel() newscript = new Script; newscript->Name="mob_anubisath_sentinel"; newscript->GetAI = GetAI_mob_anubisath_sentinelAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } SentinelAbilityAura::~SentinelAbilityAura() {} diff --git a/src/bindings/scripts/scripts/zone/terokkar_forest/terokkar_forest.cpp b/src/bindings/scripts/scripts/zone/terokkar_forest/terokkar_forest.cpp index d38b7186172..d84c3c58133 100644 --- a/src/bindings/scripts/scripts/zone/terokkar_forest/terokkar_forest.cpp +++ b/src/bindings/scripts/scripts/zone/terokkar_forest/terokkar_forest.cpp @@ -368,32 +368,32 @@ void AddSC_terokkar_forest() newscript = new Script; newscript->Name="mob_unkor_the_ruthless"; newscript->GetAI = GetAI_mob_unkor_the_ruthless; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_infested_root_walker"; newscript->GetAI = GetAI_mob_infested_root_walker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_rotting_forest_rager"; newscript->GetAI = GetAI_mob_rotting_forest_rager; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_netherweb_victim"; newscript->GetAI = GetAI_mob_netherweb_victim; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_floon"; newscript->pGossipHello = &GossipHello_npc_floon; newscript->pGossipSelect = &GossipSelect_npc_floon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_skyguard_handler_deesak"; newscript->pGossipHello = &GossipHello_npc_skyguard_handler_deesak; newscript->pGossipSelect = &GossipSelect_npc_skyguard_handler_deesak; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/thunder_bluff/thunder_bluff.cpp b/src/bindings/scripts/scripts/zone/thunder_bluff/thunder_bluff.cpp index ae65bd9d232..4b7dcd5a84a 100644 --- a/src/bindings/scripts/scripts/zone/thunder_bluff/thunder_bluff.cpp +++ b/src/bindings/scripts/scripts/zone/thunder_bluff/thunder_bluff.cpp @@ -132,5 +132,5 @@ void AddSC_thunder_bluff() newscript->GetAI = GetAI_npc_cairne_bloodhoof; newscript->pGossipHello = &GossipHello_npc_cairne_bloodhoof; newscript->pGossipSelect = &GossipSelect_npc_cairne_bloodhoof; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/tirisfal_glades/tirisfal_glades.cpp b/src/bindings/scripts/scripts/zone/tirisfal_glades/tirisfal_glades.cpp index f95bc029752..d037b2b7e14 100644 --- a/src/bindings/scripts/scripts/zone/tirisfal_glades/tirisfal_glades.cpp +++ b/src/bindings/scripts/scripts/zone/tirisfal_glades/tirisfal_glades.cpp @@ -84,5 +84,5 @@ void AddSC_tirisfal_glades() newscript->Name="npc_calvin_montague"; newscript->GetAI = GetAI_npc_calvin_montague; newscript->pQuestAccept = &QuestAccept_npc_calvin_montague; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/uldaman/boss_ironaya.cpp b/src/bindings/scripts/scripts/zone/uldaman/boss_ironaya.cpp index 34f8fda78cf..db4b7c22df3 100644 --- a/src/bindings/scripts/scripts/zone/uldaman/boss_ironaya.cpp +++ b/src/bindings/scripts/scripts/zone/uldaman/boss_ironaya.cpp @@ -103,5 +103,5 @@ void AddSC_boss_ironaya() newscript = new Script; newscript->Name="boss_ironaya"; newscript->GetAI = GetAI_boss_ironaya; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/uldaman/uldaman.cpp b/src/bindings/scripts/scripts/zone/uldaman/uldaman.cpp index 1e1a6eb8462..e8453db9f65 100644 --- a/src/bindings/scripts/scripts/zone/uldaman/uldaman.cpp +++ b/src/bindings/scripts/scripts/zone/uldaman/uldaman.cpp @@ -177,11 +177,11 @@ void AddSC_uldaman() newscript = new Script; newscript->Name="mob_jadespine_basilisk"; newscript->GetAI = GetAI_mob_jadespine_basilisk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_lore_keeper_of_norgannon"; newscript->pGossipHello = &GossipHello_npc_lore_keeper_of_norgannon; newscript->pGossipSelect = &GossipSelect_npc_lore_keeper_of_norgannon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/undercity/undercity.cpp b/src/bindings/scripts/scripts/zone/undercity/undercity.cpp index b395121c73c..89ded786ce5 100644 --- a/src/bindings/scripts/scripts/zone/undercity/undercity.cpp +++ b/src/bindings/scripts/scripts/zone/undercity/undercity.cpp @@ -245,16 +245,16 @@ void AddSC_undercity() newscript->Name="npc_lady_sylvanas_windrunner"; newscript->GetAI = GetAI_npc_lady_sylvanas_windrunner; newscript->pChooseReward = &ChooseReward_npc_lady_sylvanas_windrunner; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_highborne_lamenter"; newscript->GetAI = GetAI_npc_highborne_lamenter; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_parqual_fintallas"; newscript->pGossipHello = &GossipHello_npc_parqual_fintallas; newscript->pGossipSelect = &GossipSelect_npc_parqual_fintallas; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/western_plaguelands/western_plaguelands.cpp b/src/bindings/scripts/scripts/zone/western_plaguelands/western_plaguelands.cpp index c3725b0afc9..3f8dee012f4 100644 --- a/src/bindings/scripts/scripts/zone/western_plaguelands/western_plaguelands.cpp +++ b/src/bindings/scripts/scripts/zone/western_plaguelands/western_plaguelands.cpp @@ -167,10 +167,10 @@ void AddSC_western_plaguelands() newscript->Name="npcs_dithers_and_arbington"; newscript->pGossipHello = &GossipHello_npcs_dithers_and_arbington; newscript->pGossipSelect = &GossipSelect_npcs_dithers_and_arbington; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_the_scourge_cauldron"; newscript->GetAI = GetAI_npc_the_scourge_cauldron; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/westfall/westfall.cpp b/src/bindings/scripts/scripts/zone/westfall/westfall.cpp index 446f71f1c56..40faa01a9f0 100644 --- a/src/bindings/scripts/scripts/zone/westfall/westfall.cpp +++ b/src/bindings/scripts/scripts/zone/westfall/westfall.cpp @@ -1,179 +1,179 @@ -/* Copyright (C) 2006 - 2008 ScriptDev2 - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* ScriptData -SDName: Westfall -SD%Complete: 90 -SDComment: Quest support: 155 -SDCategory: Westfall -EndScriptData */ - -/* ContentData -npc_defias_traitor -EndContentData */ - -#include "precompiled.h" -#include "../../npc/npc_escortAI.h" - -#define SAY_START -1000101 -#define SAY_PROGRESS -1000102 -#define SAY_END -1000103 -#define SAY_AGGRO_1 -1000104 -#define SAY_AGGRO_2 -1000105 - -#define QUEST_DEFIAS_BROTHERHOOD 155 - -struct TRINITY_DLL_DECL npc_defias_traitorAI : public npc_escortAI -{ - npc_defias_traitorAI(Creature *c) : npc_escortAI(c) {Reset();} - - bool IsWalking; - - void WaypointReached(uint32 i) - { - Unit* player = Unit::GetUnit((*m_creature), PlayerGUID); - - if (!player) - return; - - if (IsWalking && !m_creature->HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE)) - m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); - - switch (i) - { - case 35: - IsWalking = true; - break; - case 36: - DoScriptText(SAY_PROGRESS, m_creature, player); - break; - case 44: - DoScriptText(SAY_END, m_creature, player); - { - if (player && player->GetTypeId() == TYPEID_PLAYER) - ((Player*)player)->GroupEventHappens(QUEST_DEFIAS_BROTHERHOOD,m_creature); - } - break; - } - } - void Aggro(Unit* who) - { - switch(rand()%2) - { - case 0: DoScriptText(SAY_AGGRO_1, m_creature, who); break; - case 1: DoScriptText(SAY_AGGRO_2, m_creature, who); break; - } - } - - void Reset() - { - if (IsWalking && !m_creature->HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE)) - { - m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); - return; - } - IsWalking = false; - } - - void JustDied(Unit* killer) - { - if (PlayerGUID) - { - if (Unit* player = Unit::GetUnit((*m_creature), PlayerGUID)) - ((Player*)player)->FailQuest(QUEST_DEFIAS_BROTHERHOOD); - } - } - - void UpdateAI(const uint32 diff) - { - npc_escortAI::UpdateAI(diff); - } -}; - -bool QuestAccept_npc_defias_traitor(Player* player, Creature* creature, Quest const* quest) -{ - if (quest->GetQuestId() == QUEST_DEFIAS_BROTHERHOOD) - { - ((npc_escortAI*)(creature->AI()))->Start(true, true, true, player->GetGUID()); - DoScriptText(SAY_START, creature, player); - } - - return true; -} - -CreatureAI* GetAI_npc_defias_traitor(Creature *_Creature) -{ - npc_defias_traitorAI* thisAI = new npc_defias_traitorAI(_Creature); - - thisAI->AddWaypoint(0, -10508.40, 1068.00, 55.21); - thisAI->AddWaypoint(1, -10518.30, 1074.84, 53.96); - thisAI->AddWaypoint(2, -10534.82, 1081.92, 49.88); - thisAI->AddWaypoint(3, -10546.51, 1084.88, 50.13); - thisAI->AddWaypoint(4, -10555.29, 1084.45, 45.75); - thisAI->AddWaypoint(5, -10566.57, 1083.53, 42.10); - thisAI->AddWaypoint(6, -10575.83, 1082.34, 39.46); - thisAI->AddWaypoint(7, -10585.67, 1081.08, 37.77); - thisAI->AddWaypoint(8, -10600.08, 1078.19, 36.23); - thisAI->AddWaypoint(9, -10608.69, 1076.08, 35.88); - thisAI->AddWaypoint(10, -10621.26, 1073.00, 35.40); - thisAI->AddWaypoint(11, -10638.12, 1060.18, 33.61); - thisAI->AddWaypoint(12, -10655.87, 1038.99, 33.48); - thisAI->AddWaypoint(13, -10664.68, 1030.54, 32.70); - thisAI->AddWaypoint(14, -10708.68, 1033.86, 33.32); - thisAI->AddWaypoint(15, -10754.43, 1017.93, 32.79); - thisAI->AddWaypoint(16, -10802.26, 1018.01, 32.16); - thisAI->AddWaypoint(17, -10832.60, 1009.04, 32.71); - thisAI->AddWaypoint(18, -10866.56, 1006.51, 31.71); // Fix waypoints from roughly this point, test first to get proper one - thisAI->AddWaypoint(19, -10879.98, 1005.10, 32.84); - thisAI->AddWaypoint(20, -10892.45, 1001.32, 34.46); - thisAI->AddWaypoint(21, -10906.14, 997.11, 36.15); - thisAI->AddWaypoint(22, -10922.26, 1002.23, 35.74); - thisAI->AddWaypoint(23, -10936.32, 1023.38, 36.52); - thisAI->AddWaypoint(24, -10933.35, 1052.61, 35.85); - thisAI->AddWaypoint(25, -10940.25, 1077.66, 36.49); - thisAI->AddWaypoint(26, -10957.09, 1099.33, 36.83); - thisAI->AddWaypoint(27, -10956.53, 1119.90, 36.73); - thisAI->AddWaypoint(28, -10939.30, 1150.75, 37.42); - thisAI->AddWaypoint(29, -10915.14, 1202.09, 36.55); - thisAI->AddWaypoint(30, -10892.59, 1257.03, 33.37); - thisAI->AddWaypoint(31, -10891.93, 1306.66, 35.45); - thisAI->AddWaypoint(32, -10896.17, 1327.86, 37.77); - thisAI->AddWaypoint(33, -10906.03, 1368.05, 40.91); - thisAI->AddWaypoint(34, -10910.18, 1389.33, 42.62); - thisAI->AddWaypoint(35, -10915.42, 1417.72, 42.93); - thisAI->AddWaypoint(36, -10926.37, 1421.18, 43.04); // walk here and say - thisAI->AddWaypoint(37, -10952.31, 1421.74, 43.40); - thisAI->AddWaypoint(38, -10980.04, 1411.38, 42.79); - thisAI->AddWaypoint(39, -11006.06, 1420.47, 43.26); - thisAI->AddWaypoint(40, -11021.98, 1450.59, 43.09); - thisAI->AddWaypoint(41, -11025.36, 1491.59, 43.15); - thisAI->AddWaypoint(42, -11036.09, 1508.32, 43.28); - thisAI->AddWaypoint(43, -11060.68, 1526.72, 43.19); - thisAI->AddWaypoint(44, -11072.75, 1527.77, 43.20, 5000);// say and quest credit - - return (CreatureAI*)thisAI; -} - -void AddSC_westfall() -{ - Script *newscript; - - newscript = new Script; - newscript->Name="npc_defias_traitor"; - newscript->GetAI = &GetAI_npc_defias_traitor; - newscript->pQuestAccept = &QuestAccept_npc_defias_traitor; - m_scripts[nrscripts++] = newscript; -} +/* Copyright (C) 2006 - 2008 ScriptDev2 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* ScriptData +SDName: Westfall +SD%Complete: 90 +SDComment: Quest support: 155 +SDCategory: Westfall +EndScriptData */ + +/* ContentData +npc_defias_traitor +EndContentData */ + +#include "precompiled.h" +#include "../../npc/npc_escortAI.h" + +#define SAY_START -1000101 +#define SAY_PROGRESS -1000102 +#define SAY_END -1000103 +#define SAY_AGGRO_1 -1000104 +#define SAY_AGGRO_2 -1000105 + +#define QUEST_DEFIAS_BROTHERHOOD 155 + +struct TRINITY_DLL_DECL npc_defias_traitorAI : public npc_escortAI +{ + npc_defias_traitorAI(Creature *c) : npc_escortAI(c) {Reset();} + + bool IsWalking; + + void WaypointReached(uint32 i) + { + Unit* player = Unit::GetUnit((*m_creature), PlayerGUID); + + if (!player) + return; + + if (IsWalking && !m_creature->HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE)) + m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); + + switch (i) + { + case 35: + IsWalking = true; + break; + case 36: + DoScriptText(SAY_PROGRESS, m_creature, player); + break; + case 44: + DoScriptText(SAY_END, m_creature, player); + { + if (player && player->GetTypeId() == TYPEID_PLAYER) + ((Player*)player)->GroupEventHappens(QUEST_DEFIAS_BROTHERHOOD,m_creature); + } + break; + } + } + void Aggro(Unit* who) + { + switch(rand()%2) + { + case 0: DoScriptText(SAY_AGGRO_1, m_creature, who); break; + case 1: DoScriptText(SAY_AGGRO_2, m_creature, who); break; + } + } + + void Reset() + { + if (IsWalking && !m_creature->HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE)) + { + m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); + return; + } + IsWalking = false; + } + + void JustDied(Unit* killer) + { + if (PlayerGUID) + { + if (Unit* player = Unit::GetUnit((*m_creature), PlayerGUID)) + ((Player*)player)->FailQuest(QUEST_DEFIAS_BROTHERHOOD); + } + } + + void UpdateAI(const uint32 diff) + { + npc_escortAI::UpdateAI(diff); + } +}; + +bool QuestAccept_npc_defias_traitor(Player* player, Creature* creature, Quest const* quest) +{ + if (quest->GetQuestId() == QUEST_DEFIAS_BROTHERHOOD) + { + ((npc_escortAI*)(creature->AI()))->Start(true, true, true, player->GetGUID()); + DoScriptText(SAY_START, creature, player); + } + + return true; +} + +CreatureAI* GetAI_npc_defias_traitor(Creature *_Creature) +{ + npc_defias_traitorAI* thisAI = new npc_defias_traitorAI(_Creature); + + thisAI->AddWaypoint(0, -10508.40, 1068.00, 55.21); + thisAI->AddWaypoint(1, -10518.30, 1074.84, 53.96); + thisAI->AddWaypoint(2, -10534.82, 1081.92, 49.88); + thisAI->AddWaypoint(3, -10546.51, 1084.88, 50.13); + thisAI->AddWaypoint(4, -10555.29, 1084.45, 45.75); + thisAI->AddWaypoint(5, -10566.57, 1083.53, 42.10); + thisAI->AddWaypoint(6, -10575.83, 1082.34, 39.46); + thisAI->AddWaypoint(7, -10585.67, 1081.08, 37.77); + thisAI->AddWaypoint(8, -10600.08, 1078.19, 36.23); + thisAI->AddWaypoint(9, -10608.69, 1076.08, 35.88); + thisAI->AddWaypoint(10, -10621.26, 1073.00, 35.40); + thisAI->AddWaypoint(11, -10638.12, 1060.18, 33.61); + thisAI->AddWaypoint(12, -10655.87, 1038.99, 33.48); + thisAI->AddWaypoint(13, -10664.68, 1030.54, 32.70); + thisAI->AddWaypoint(14, -10708.68, 1033.86, 33.32); + thisAI->AddWaypoint(15, -10754.43, 1017.93, 32.79); + thisAI->AddWaypoint(16, -10802.26, 1018.01, 32.16); + thisAI->AddWaypoint(17, -10832.60, 1009.04, 32.71); + thisAI->AddWaypoint(18, -10866.56, 1006.51, 31.71); // Fix waypoints from roughly this point, test first to get proper one + thisAI->AddWaypoint(19, -10879.98, 1005.10, 32.84); + thisAI->AddWaypoint(20, -10892.45, 1001.32, 34.46); + thisAI->AddWaypoint(21, -10906.14, 997.11, 36.15); + thisAI->AddWaypoint(22, -10922.26, 1002.23, 35.74); + thisAI->AddWaypoint(23, -10936.32, 1023.38, 36.52); + thisAI->AddWaypoint(24, -10933.35, 1052.61, 35.85); + thisAI->AddWaypoint(25, -10940.25, 1077.66, 36.49); + thisAI->AddWaypoint(26, -10957.09, 1099.33, 36.83); + thisAI->AddWaypoint(27, -10956.53, 1119.90, 36.73); + thisAI->AddWaypoint(28, -10939.30, 1150.75, 37.42); + thisAI->AddWaypoint(29, -10915.14, 1202.09, 36.55); + thisAI->AddWaypoint(30, -10892.59, 1257.03, 33.37); + thisAI->AddWaypoint(31, -10891.93, 1306.66, 35.45); + thisAI->AddWaypoint(32, -10896.17, 1327.86, 37.77); + thisAI->AddWaypoint(33, -10906.03, 1368.05, 40.91); + thisAI->AddWaypoint(34, -10910.18, 1389.33, 42.62); + thisAI->AddWaypoint(35, -10915.42, 1417.72, 42.93); + thisAI->AddWaypoint(36, -10926.37, 1421.18, 43.04); // walk here and say + thisAI->AddWaypoint(37, -10952.31, 1421.74, 43.40); + thisAI->AddWaypoint(38, -10980.04, 1411.38, 42.79); + thisAI->AddWaypoint(39, -11006.06, 1420.47, 43.26); + thisAI->AddWaypoint(40, -11021.98, 1450.59, 43.09); + thisAI->AddWaypoint(41, -11025.36, 1491.59, 43.15); + thisAI->AddWaypoint(42, -11036.09, 1508.32, 43.28); + thisAI->AddWaypoint(43, -11060.68, 1526.72, 43.19); + thisAI->AddWaypoint(44, -11072.75, 1527.77, 43.20, 5000);// say and quest credit + + return (CreatureAI*)thisAI; +} + +void AddSC_westfall() +{ + Script *newscript; + + newscript = new Script; + newscript->Name="npc_defias_traitor"; + newscript->GetAI = &GetAI_npc_defias_traitor; + newscript->pQuestAccept = &QuestAccept_npc_defias_traitor; + newscript->RegisterSelf(); +} diff --git a/src/bindings/scripts/scripts/zone/winterspring/winterspring.cpp b/src/bindings/scripts/scripts/zone/winterspring/winterspring.cpp index 7d6f8ea30fb..08ead2eb1de 100644 --- a/src/bindings/scripts/scripts/zone/winterspring/winterspring.cpp +++ b/src/bindings/scripts/scripts/zone/winterspring/winterspring.cpp @@ -141,17 +141,17 @@ void AddSC_winterspring() newscript->Name="npc_lorax"; newscript->pGossipHello = &GossipHello_npc_lorax; newscript->pGossipSelect = &GossipSelect_npc_lorax; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_rivern_frostwind"; newscript->pGossipHello = &GossipHello_npc_rivern_frostwind; newscript->pGossipSelect = &GossipSelect_npc_rivern_frostwind; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_witch_doctor_mauari"; newscript->pGossipHello = &GossipHello_npc_witch_doctor_mauari; newscript->pGossipSelect = &GossipSelect_npc_witch_doctor_mauari; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zangarmarsh/zangarmarsh.cpp b/src/bindings/scripts/scripts/zone/zangarmarsh/zangarmarsh.cpp index 621d3e5da49..fdce0029e9d 100644 --- a/src/bindings/scripts/scripts/zone/zangarmarsh/zangarmarsh.cpp +++ b/src/bindings/scripts/scripts/zone/zangarmarsh/zangarmarsh.cpp @@ -261,23 +261,23 @@ void AddSC_zangarmarsh() newscript->Name="npcs_ashyen_and_keleth"; newscript->pGossipHello = &GossipHello_npcs_ashyen_and_keleth; newscript->pGossipSelect = &GossipSelect_npcs_ashyen_and_keleth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_cooshcoosh"; newscript->pGossipHello = &GossipHello_npc_cooshcoosh; newscript->pGossipSelect = &GossipSelect_npc_cooshcoosh; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_elder_kuruti"; newscript->pGossipHello = &GossipHello_npc_elder_kuruti; newscript->pGossipSelect = &GossipSelect_npc_elder_kuruti; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_mortog_steamhead"; newscript->pGossipHello = &GossipHello_npc_mortog_steamhead; newscript->pGossipSelect = &GossipSelect_npc_mortog_steamhead; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_akilzon.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_akilzon.cpp index c7327376ae1..4b9eb2afa88 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_akilzon.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_akilzon.cpp @@ -461,10 +461,10 @@ void AddSC_boss_akilzon() newscript = new Script; newscript->Name="boss_akilzon"; newscript->GetAI = GetAI_boss_akilzon; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_akilzon_eagle"; newscript->GetAI = GetAI_mob_soaring_eagle; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_halazzi.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_halazzi.cpp index 8daab23c6b2..19235677831 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_halazzi.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_halazzi.cpp @@ -394,10 +394,10 @@ void AddSC_boss_halazzi() newscript = new Script; newscript->Name="boss_halazzi"; newscript->GetAI = GetAI_boss_halazziAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_halazzi_lynx"; newscript->GetAI = GetAI_boss_spiritlynxAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp index 781a0c812ba..4d36a138765 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_hexlord.cpp @@ -868,45 +868,45 @@ void AddSC_boss_hex_lord_malacrass() newscript = new Script; newscript->Name="boss_hexlord_malacrass"; newscript->GetAI = GetAI_boss_hex_lord_malacrass; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_thurg"; newscript->GetAI = GetAI_boss_thurg; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_gazakroth"; newscript->GetAI = GetAI_boss_gazakroth; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_lord_raadan"; newscript->GetAI = GetAI_boss_lord_raadan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_darkheart"; newscript->GetAI = GetAI_boss_darkheart; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_slither"; newscript->GetAI = GetAI_boss_slither; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_fenstalker"; newscript->GetAI = GetAI_boss_fenstalker; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_koragg"; newscript->GetAI = GetAI_boss_koragg; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="boss_alyson_antille"; newscript->GetAI = GetAI_boss_alyson_antille; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } \ No newline at end of file diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp index 8cc7efb233b..463425a5ef3 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_janalai.cpp @@ -706,25 +706,25 @@ void AddSC_boss_janalai() newscript = new Script; newscript->Name="boss_janalai"; newscript->GetAI = GetAI_boss_janalaiAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_janalai_firebomb"; newscript->GetAI = GetAI_mob_jandalai_firebombAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_janalai_hatcher"; newscript->GetAI = GetAI_mob_amanishi_hatcherAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_janalai_hatchling"; newscript->GetAI = GetAI_mob_hatchlingAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_janalai_egg"; newscript->GetAI = GetAI_mob_eggAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_nalorakk.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_nalorakk.cpp index d51e1cdfa00..359bf496043 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_nalorakk.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_nalorakk.cpp @@ -300,5 +300,5 @@ void AddSC_boss_nalorakk() newscript = new Script; newscript->Name="boss_nalorakk"; newscript->GetAI = GetAI_boss_nalorakk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulaman/boss_zuljin.cpp b/src/bindings/scripts/scripts/zone/zulaman/boss_zuljin.cpp index 0b41f591d06..2fa0b83432a 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/boss_zuljin.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/boss_zuljin.cpp @@ -629,15 +629,15 @@ void AddSC_boss_zuljin() newscript = new Script; newscript->Name="boss_zuljin"; newscript->GetAI = GetAI_boss_zuljin; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="do_nothing"; newscript->GetAI = GetAI_do_nothing; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_zuljin_vortex"; newscript->GetAI = GetAI_feather_vortexAI; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp b/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp index 2abf2d8becf..c0c68c1a2e4 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/instance_zulaman.cpp @@ -147,11 +147,11 @@ struct TRINITY_DLL_DECL instance_zulaman : public ScriptedInstance { if(!QuestMinute) return; - - Map::PlayerList const &PlayerList = instance->GetPlayers(); - if (PlayerList.isEmpty()) - return; - + + Map::PlayerList const &PlayerList = instance->GetPlayers(); + if (PlayerList.isEmpty()) + return; + Map::PlayerList::const_iterator i = PlayerList.begin(); if(Player* i_pl = i->getSource()) { @@ -328,5 +328,5 @@ void AddSC_instance_zulaman() newscript = new Script; newscript->Name = "instance_zulaman"; newscript->GetInstanceData = GetInstanceData_instance_zulaman; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulaman/zulaman.cpp b/src/bindings/scripts/scripts/zone/zulaman/zulaman.cpp index 4927ff4869a..b28b8a9bd06 100644 --- a/src/bindings/scripts/scripts/zone/zulaman/zulaman.cpp +++ b/src/bindings/scripts/scripts/zone/zulaman/zulaman.cpp @@ -171,12 +171,12 @@ void AddSC_zulaman() newscript = new Script; newscript->Name="npc_forest_frog"; newscript->GetAI = GetAI_npc_forest_frog; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name = "npc_zulaman_hostage"; newscript->GetAI = GetAI_npc_zulaman_hostage; newscript->pGossipHello = GossipHello_npc_zulaman_hostage; newscript->pGossipSelect = GossipSelect_npc_zulaman_hostage; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulfarrak/zulfarrak.cpp b/src/bindings/scripts/scripts/zone/zulfarrak/zulfarrak.cpp index 6145f640634..a385314a12d 100644 --- a/src/bindings/scripts/scripts/zone/zulfarrak/zulfarrak.cpp +++ b/src/bindings/scripts/scripts/zone/zulfarrak/zulfarrak.cpp @@ -213,12 +213,12 @@ void AddSC_zulfarrak() newscript->GetAI = GetAI_npc_sergeant_bly; newscript->pGossipHello = &GossipHello_npc_sergeant_bly; newscript->pGossipSelect = &GossipSelect_npc_sergeant_bly; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="npc_weegli_blastfuse"; newscript->GetAI = GetAI_npc_weegli_blastfuse; newscript->pGossipHello = &GossipHello_npc_weegli_blastfuse; newscript->pGossipSelect = &GossipSelect_npc_weegli_blastfuse; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_arlokk.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_arlokk.cpp index e32538616f6..0d08f35c6a1 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_arlokk.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_arlokk.cpp @@ -207,5 +207,5 @@ void AddSC_boss_arlokk() newscript = new Script; newscript->Name="boss_arlokk"; newscript->GetAI = GetAI_boss_arlokk; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_gahzranka.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_gahzranka.cpp index 7168d647d49..bcbd8287c46 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_gahzranka.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_gahzranka.cpp @@ -88,5 +88,5 @@ void AddSC_boss_gahzranka() newscript = new Script; newscript->Name="boss_gahzranka"; newscript->GetAI = GetAI_boss_gahzranka; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_grilek.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_grilek.cpp index c882aa3ae6f..d9ab005a8d5 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_grilek.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_grilek.cpp @@ -88,5 +88,5 @@ void AddSC_boss_grilek() newscript = new Script; newscript->Name="boss_grilek"; newscript->GetAI = GetAI_boss_grilek; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_hakkar.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_hakkar.cpp index cdd4c42128b..93db797e25f 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_hakkar.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_hakkar.cpp @@ -252,5 +252,5 @@ void AddSC_boss_hakkar() newscript = new Script; newscript->Name="boss_hakkar"; newscript->GetAI = GetAI_boss_hakkar; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_hazzarah.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_hazzarah.cpp index 62140f5303d..166e5bb0467 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_hazzarah.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_hazzarah.cpp @@ -96,5 +96,5 @@ void AddSC_boss_hazzarah() newscript = new Script; newscript->Name="boss_hazzarah"; newscript->GetAI = GetAI_boss_hazzarah; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_jeklik.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_jeklik.cpp index 86b6068cb3a..ce63d6f1587 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_jeklik.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_jeklik.cpp @@ -288,10 +288,10 @@ void AddSC_boss_jeklik() newscript = new Script; newscript->Name="boss_jeklik"; newscript->GetAI = GetAI_boss_jeklik; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_batrider"; newscript->GetAI = GetAI_mob_batrider; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_jindo.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_jindo.cpp index a5752845b92..f133cc6bceb 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_jindo.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_jindo.cpp @@ -258,15 +258,15 @@ void AddSC_boss_jindo() newscript = new Script; newscript->Name="boss_jindo"; newscript->GetAI = GetAI_boss_jindo; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_healing_ward"; newscript->GetAI = GetAI_mob_healing_ward; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_shade_of_jindo"; newscript->GetAI = GetAI_mob_shade_of_jindo; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_mandokir.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_mandokir.cpp index 9781fae1f2d..a70f39e2210 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_mandokir.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_mandokir.cpp @@ -302,10 +302,10 @@ void AddSC_boss_mandokir() newscript = new Script; newscript->Name="boss_mandokir"; newscript->GetAI = GetAI_boss_mandokir; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_ohgan"; newscript->GetAI = GetAI_mob_ohgan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_marli.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_marli.cpp index de9a440ba38..5f276a6c3f8 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_marli.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_marli.cpp @@ -244,10 +244,10 @@ void AddSC_boss_marli() newscript = new Script; newscript->Name="boss_marli"; newscript->GetAI = GetAI_boss_marli; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_spawn_of_marli"; newscript->GetAI = GetAI_mob_spawn_of_marli; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_renataki.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_renataki.cpp index ada5cc6cdbc..7febe276dc1 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_renataki.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_renataki.cpp @@ -147,5 +147,5 @@ void AddSC_boss_renataki() newscript = new Script; newscript->Name="boss_renataki"; newscript->GetAI = GetAI_boss_renataki; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_thekal.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_thekal.cpp index b1b44f9b94d..0eebbc1dda6 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_thekal.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_thekal.cpp @@ -531,15 +531,15 @@ void AddSC_boss_thekal() newscript = new Script; newscript->Name="boss_thekal"; newscript->GetAI = GetAI_boss_thekal; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_zealot_lorkhan"; newscript->GetAI = GetAI_mob_zealot_lorkhan; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); newscript = new Script; newscript->Name="mob_zealot_zath"; newscript->GetAI = GetAI_mob_zealot_zath; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_venoxis.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_venoxis.cpp index 771b61c372f..3d8657d1b67 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_venoxis.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_venoxis.cpp @@ -196,5 +196,5 @@ void AddSC_boss_venoxis() newscript = new Script; newscript->Name="boss_venoxis"; newscript->GetAI = GetAI_boss_venoxis; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/boss_wushoolay.cpp b/src/bindings/scripts/scripts/zone/zulgurub/boss_wushoolay.cpp index 3ac05c97b04..83e682917ae 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/boss_wushoolay.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/boss_wushoolay.cpp @@ -80,5 +80,5 @@ void AddSC_boss_wushoolay() newscript = new Script; newscript->Name="boss_wushoolay"; newscript->GetAI = GetAI_boss_wushoolay; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/bindings/scripts/scripts/zone/zulgurub/instance_zulgurub.cpp b/src/bindings/scripts/scripts/zone/zulgurub/instance_zulgurub.cpp index 501c200fa5c..0e9a14a05b9 100644 --- a/src/bindings/scripts/scripts/zone/zulgurub/instance_zulgurub.cpp +++ b/src/bindings/scripts/scripts/zone/zulgurub/instance_zulgurub.cpp @@ -234,5 +234,5 @@ void AddSC_instance_zulgurub() newscript = new Script; newscript->Name = "instance_zulgurub"; newscript->GetInstanceData = GetInstanceData_instance_zulgurub; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/game/AuctionHouse.cpp b/src/game/AuctionHouse.cpp index ca549f4d404..5526240528b 100644 --- a/src/game/AuctionHouse.cpp +++ b/src/game/AuctionHouse.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "WorldPacket.h" @@ -89,8 +89,8 @@ bool WorldSession::SendAuctionInfo(WorldPacket & data, AuctionEntry* auction) sLog.outError("auction to item, that doesn't exist !!!!"); return false; } - data << auction->Id; - data << pItem->GetUInt32Value(OBJECT_FIELD_ENTRY); + data << (uint32) auction->Id; + data << (uint32) pItem->GetEntry(); for (uint8 i = 0; i < MAX_INSPECTED_ENCHANTMENT_SLOT; i++) { @@ -245,7 +245,7 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); return; } - // prevent sending bag with items (cheat: can be placed in bag after adding equipped empty bag to auction) + // prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction) if(!it) { SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND); @@ -716,7 +716,7 @@ void WorldSession::HandleAuctionListItems( WorldPacket & recv_data ) ItemLocale const *il = objmgr.GetItemLocale(proto->ItemId); if (il) { - if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty()) + if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty()) name = il->Name[loc_idx]; } } diff --git a/src/game/Bag.cpp b/src/game/Bag.cpp index 4b8284c7c37..765d40f3962 100644 --- a/src/game/Bag.cpp +++ b/src/game/Bag.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -41,7 +41,7 @@ Bag::~Bag() { for(int i = 0; i < MAX_BAG_SIZE; ++i) if (m_bagslot[i]) - delete m_bagslot[i]; + delete m_bagslot[i]; } void Bag::AddToWorld() @@ -71,7 +71,7 @@ bool Bag::Create(uint32 guidlow, uint32 itemid, Player const* owner) Object::_Create( guidlow, 0, HIGHGUID_CONTAINER ); - SetUInt32Value(OBJECT_FIELD_ENTRY, itemid); + SetEntry(itemid); SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f); SetUInt64Value(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : 0); @@ -85,7 +85,7 @@ bool Bag::Create(uint32 guidlow, uint32 itemid, Player const* owner) // Setting the number of Slots the Container has SetUInt32Value(CONTAINER_FIELD_NUM_SLOTS, itemProto->ContainerSlots); - // Cleanning 20 slots + // Cleaning 20 slots for (uint8 i = 0; i < MAX_BAG_SIZE; i++) { SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0); @@ -213,6 +213,7 @@ uint8 Bag::GetSlotByItemGUID(uint64 guid) const if(m_bagslot[i] != 0) if(m_bagslot[i]->GetGUID() == guid) return i; + return NULL_SLOT; } @@ -220,6 +221,6 @@ Item* Bag::GetItemByPos( uint8 slot ) const { if( slot < GetBagSize() ) return m_bagslot[slot]; - + return NULL; } diff --git a/src/game/Chat.cpp b/src/game/Chat.cpp index bff970be3b7..862cfc638ca 100644 --- a/src/game/Chat.cpp +++ b/src/game/Chat.cpp @@ -63,16 +63,44 @@ ChatCommand * ChatHandler::getCommandTable() { NULL, 0, false, NULL, "", NULL } }; + static ChatCommand serverIdleRestartCommandTable[] = + { + { "cancel", SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerShutDownCancelCommand,"", NULL }, + { "" , SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerIdleRestartCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + + static ChatCommand serverIdleShutdownCommandTable[] = + { + { "cancel", SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerShutDownCancelCommand,"", NULL }, + { "" , SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerIdleShutDownCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + + static ChatCommand serverRestartCommandTable[] = + { + { "cancel", SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerShutDownCancelCommand,"", NULL }, + { "" , SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerRestartCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + + static ChatCommand serverShutdownCommandTable[] = + { + { "cancel", SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerShutDownCancelCommand,"", NULL }, + { "" , SEC_ADMINISTRATOR, true, &ChatHandler::HandleServerShutDownCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + static ChatCommand serverCommandTable[] = { { "corpses", SEC_GAMEMASTER, true, &ChatHandler::HandleServerCorpsesCommand, "", NULL }, { "exit", SEC_CONSOLE, true, &ChatHandler::HandleServerExitCommand, "", NULL }, - { "idlerestart", SEC_ADMINISTRATOR, true, &ChatHandler::HandleIdleRestartCommand, "", NULL }, - { "idleshutdown", SEC_ADMINISTRATOR, true, &ChatHandler::HandleIdleShutDownCommand, "", NULL }, + { "idlerestart", SEC_ADMINISTRATOR, true, NULL, "", serverIdleRestartCommandTable }, + { "idleshutdown", SEC_ADMINISTRATOR, true, NULL, "", serverShutdownCommandTable }, { "info", SEC_PLAYER, true, &ChatHandler::HandleServerInfoCommand, "", NULL }, { "motd", SEC_PLAYER, true, &ChatHandler::HandleServerMotdCommand, "", NULL }, - { "restart", SEC_ADMINISTRATOR, true, &ChatHandler::HandleRestartCommand, "", NULL }, - { "shutdown", SEC_ADMINISTRATOR, true, &ChatHandler::HandleShutDownCommand, "", NULL }, + { "restart", SEC_ADMINISTRATOR, true, NULL, "", serverRestartCommandTable }, + { "shutdown", SEC_ADMINISTRATOR, true, NULL, "", serverShutdownCommandTable }, { "set", SEC_ADMINISTRATOR, true, NULL, "", serverSetCommandTable }, { NULL, 0, false, NULL, "", NULL } }; diff --git a/src/game/Chat.h b/src/game/Chat.h index 0ba253defd9..b62bae39d17 100644 --- a/src/game/Chat.h +++ b/src/game/Chat.h @@ -175,6 +175,7 @@ class ChatHandler bool HandleModifyHonorCommand (const char* args); bool HandleModifyRepCommand(const char* args); bool HandleModifyArenaCommand(const char* args); + bool HandleModifyGenderCommand(const char* args); bool HandleNpcAddCommand(const char* args); bool HandleNpcAddMoveCommand(const char* args); @@ -191,6 +192,7 @@ class ChatHandler bool HandleNpcSetMoveTypeCommand(const char* args); bool HandleNpcSpawnDistCommand(const char* args); bool HandleNpcSpawnTimeCommand(const char* args); + bool HandleNpcTameCommand(const char* args); bool HandleNpcTextEmoteCommand(const char* args); bool HandleNpcUnFollowCommand(const char* args); bool HandleNpcWhisperCommand(const char* args); @@ -215,6 +217,7 @@ class ChatHandler bool HandleReloadCommandCommand(const char* args); bool HandleReloadCreatureQuestRelationsCommand(const char* args); bool HandleReloadCreatureQuestInvRelationsCommand(const char* args); + bool HandleReloadDbScriptStringCommand(const char* args); bool HandleReloadGameGraveyardZoneCommand(const char* args); bool HandleReloadGameObjectScriptsCommand(const char* args); bool HandleReloadGameTeleCommand(const char* args); @@ -270,10 +273,15 @@ class ChatHandler bool HandleServerCorpsesCommand(const char* args); bool HandleServerExitCommand(const char* args); + bool HandleServerIdleRestartCommand(const char* args); + bool HandleServerIdleShutDownCommand(const char* args); bool HandleServerInfoCommand(const char* args); bool HandleServerMotdCommand(const char* args); + bool HandleServerRestartCommand(const char* args); bool HandleServerSetMotdCommand(const char* args); bool HandleServerSetLogLevelCommand(const char* args); + bool HandleServerShutDownCommand(const char* args); + bool HandleServerShutDownCancelCommand(const char* args); bool HandleAddHonorCommand(const char* args); bool HandleHonorAddKillCommand(const char* args); @@ -327,11 +335,6 @@ class ChatHandler bool HandleBanListAccountCommand(const char* args); bool HandleBanListCharacterCommand(const char* args); bool HandleBanListIPCommand(const char* args); - bool HandleIdleRestartCommand(const char* args); - bool HandleIdleShutDownCommand(const char* args); - bool HandleShutDownCommand(const char* args); - bool HandleRestartCommand(const char* args); - bool HandleSecurityCommand(const char* args); bool HandleGoXYCommand(const char* args); bool HandleGoXYZCommand(const char* args); bool HandleGoZoneXYCommand(const char* args); @@ -365,7 +368,6 @@ class ChatHandler bool HandleHideAreaCommand(const char* args); bool HandleAddItemCommand(const char* args); bool HandleAddItemSetCommand(const char* args); - bool HandleModifyGenderCommand(const char* args); bool HandlePetTpCommand(const char* args); bool HandlePetUnlearnCommand(const char* args); bool HandlePetLearnCommand(const char* args); diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 5e3d3ac9f8e..8a58deb7f91 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -177,7 +177,7 @@ void Creature::RemoveCorpse() float x,y,z,o; GetRespawnCoord(x, y, z, &o); - MapManager::Instance().GetMap(GetMapId(), this)->CreatureRelocation(this,x,y,z,o); + GetMap()->CreatureRelocation(this,x,y,z,o); } /** @@ -209,7 +209,7 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data ) } } - SetUInt32Value(OBJECT_FIELD_ENTRY, Entry); // normal entry always + SetEntry(Entry); // normal entry always m_creatureInfo = cinfo; // map mode related always // Cancel load if no model defined @@ -352,7 +352,7 @@ void Creature::Update(uint32 diff) lootForPickPocketed = false; lootForBody = false; - if(m_originalEntry != GetUInt32Value(OBJECT_FIELD_ENTRY)) + if(m_originalEntry != GetEntry()) UpdateEntry(m_originalEntry); CreatureInfo const *cinfo = GetCreatureInfo(); @@ -371,9 +371,9 @@ void Creature::Update(uint32 diff) setDeathState( JUST_ALIVED ); //Call AI respawn virtual function - AI()->JustRespawned(); + i_AI->JustRespawned(); - MapManager::Instance().GetMap(GetMapId(), this)->Add(this); + GetMap()->Add(this); } break; } @@ -435,7 +435,7 @@ void Creature::Update(uint32 diff) { // do not allow the AI to be changed during update m_AI_locked = true; - AI()->UpdateAI(diff); + i_AI->UpdateAI(diff); m_AI_locked = false; } @@ -2096,9 +2096,14 @@ uint32 Creature::getLevelForTarget( Unit const* target ) const return level; } -char const* Creature::GetScriptName() const +std::string Creature::GetScriptName() { - return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptName; + return objmgr.GetScriptName(GetScriptId()); +} + +uint32 Creature::GetScriptId() +{ + return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptID; } VendorItemData const* Creature::GetVendorItems() const diff --git a/src/game/Creature.h b/src/game/Creature.h index be421f26ad2..d5b6b23a025 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITYCORE_CREATURE_H @@ -205,10 +205,11 @@ struct CreatureInfo uint32 equipmentId; uint32 MechanicImmuneMask; uint32 flags_extra; - char const* ScriptName; + uint32 ScriptID; uint32 GetRandomValidModelId() const; uint32 GetFirstValidModelId() const; - + + // helpers SkillType GetRequiredLootSkill() const { if(type_flags & CREATURE_TYPEFLAGS_HERBLOOT) @@ -218,7 +219,7 @@ struct CreatureInfo else return SKILL_SKINNING; // normal case } - + bool isTameable() const { return type == CREATURE_TYPE_BEAST && family != 0 && (type_flags & CREATURE_TYPEFLAGS_TAMEBLE); @@ -498,7 +499,9 @@ class TRINITY_DLL_SPEC Creature : public Unit CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; } CreatureDataAddon const* GetCreatureAddon() const; - char const* GetScriptName() const; + + std::string GetScriptName(); + uint32 GetScriptId(); void prepareGossipMenu( Player *pPlayer, uint32 gossipid = 0 ); void sendPreparedGossip( Player* player ); @@ -524,7 +527,7 @@ class TRINITY_DLL_SPEC Creature : public Unit // overwrite WorldObject function for proper name localization const char* GetNameForLocaleIdx(int32 locale_idx) const; - + void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState bool LoadFromDB(uint32 guid, Map *map); diff --git a/src/game/CreatureAI.cpp b/src/game/CreatureAI.cpp index 3cb8db202fa..ad663d13b38 100644 --- a/src/game/CreatureAI.cpp +++ b/src/game/CreatureAI.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "CreatureAI.h" diff --git a/src/game/CreatureAIImpl.h b/src/game/CreatureAIImpl.h index 877ed885152..76ba93a3cb5 100644 --- a/src/game/CreatureAIImpl.h +++ b/src/game/CreatureAIImpl.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef CREATUREAIIMPL_H #define CREATUREAIIMPL_H diff --git a/src/game/CreatureAIRegistry.cpp b/src/game/CreatureAIRegistry.cpp index 7219f71cd81..a4ee030c34e 100644 --- a/src/game/CreatureAIRegistry.cpp +++ b/src/game/CreatureAIRegistry.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "CreatureAIRegistry.h" diff --git a/src/game/CreatureAISelector.cpp b/src/game/CreatureAISelector.cpp index 2e0d297305c..5e15efafe6f 100644 --- a/src/game/CreatureAISelector.cpp +++ b/src/game/CreatureAISelector.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Creature.h" diff --git a/src/game/Formulas.h b/src/game/Formulas.h index cef4fab9c7b..f9915a2001c 100644 --- a/src/game/Formulas.h +++ b/src/game/Formulas.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITY_FORMULAS_H @@ -29,7 +29,7 @@ namespace Trinity { inline uint32 hk_honor_at_level(uint32 level, uint32 count=1) { - return (uint32) ceil(count*(-0.53177f + 0.59357f * exp((level +23.54042f) / 26.07859f ))); + return (uint32)ceil(count*(-0.53177f + 0.59357f * exp((level +23.54042f) / 26.07859f ))); } } namespace XP @@ -80,6 +80,7 @@ namespace Trinity inline uint32 BaseGain(uint32 pl_level, uint32 mob_level, ContentLevels content) { + //TODO: need modifier for CONTENT_71_80 different from CONTENT_61_70? const uint32 nBaseExp = content == CONTENT_1_60 ? 45 : 235; if( mob_level >= pl_level ) { diff --git a/src/game/GMTicketHandler.cpp b/src/game/GMTicketHandler.cpp index 6d005c2806a..448730bd3ea 100644 --- a/src/game/GMTicketHandler.cpp +++ b/src/game/GMTicketHandler.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -66,8 +66,6 @@ void WorldSession::HandleGMTicketUpdateTextOpcode( WorldPacket & recv_data ) std::string ticketText; recv_data >> ticketText; - CharacterDatabase.escape_string(ticketText); - if(GMTicket* ticket = ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow())) ticket->SetText(ticketText.c_str()); else @@ -105,9 +103,7 @@ void WorldSession::HandleGMTicketCreateOpcode( WorldPacket & recv_data ) sLog.outDebug("TicketCreate: map %u, x %f, y %f, z %f, text %s, unk1 %u, unk2 %u", map, x, y, z, ticketText.c_str(), unk1, unk2); - CharacterDatabase.escape_string(ticketText); - - if(GMTicket* ticket = ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow())) + if(ticketmgr.GetGMTicket(GetPlayer()->GetGUIDLow())) { WorldPacket data( SMSG_GMTICKET_CREATE, 4 ); data << uint32(1); diff --git a/src/game/GMTicketMgr.h b/src/game/GMTicketMgr.h index a7b7a02ea17..1fd4e4c3a8f 100644 --- a/src/game/GMTicketMgr.h +++ b/src/game/GMTicketMgr.h @@ -50,7 +50,10 @@ class GMTicket { m_text = text ? text : ""; m_lastUpdate = time(NULL); - CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", m_text.c_str(), m_guid); + + std::string escapedString = m_text; + CharacterDatabase.escape_string(escapedString); + CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", escapedString.c_str(), m_guid); } void DeleteFromDB() const @@ -62,7 +65,11 @@ class GMTicket { CharacterDatabase.BeginTransaction(); DeleteFromDB(); - CharacterDatabase.PExecute("INSERT INTO character_ticket (guid, ticket_text) VALUES ('%u', '%s')", m_guid, GetText()); + + std::string escapedString = m_text; + CharacterDatabase.escape_string(escapedString); + + CharacterDatabase.PExecute("INSERT INTO character_ticket (guid, ticket_text) VALUES ('%u', '%s')", m_guid, escapedString.c_str()); CharacterDatabase.CommitTransaction(); } private: @@ -115,4 +122,4 @@ class GMTicketMgr }; #define ticketmgr Trinity::Singleton::Instance() -#endif \ No newline at end of file +#endif diff --git a/src/game/GameObject.h b/src/game/GameObject.h index 7dc5a879913..afeaba98cc9 100644 --- a/src/game/GameObject.h +++ b/src/game/GameObject.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITYCORE_GAMEOBJECT_H @@ -357,7 +357,7 @@ struct GameObjectInfo uint32 data[24]; } raw; }; - char *ScriptName; + uint32 ScriptId; }; struct GameObjectLocale diff --git a/src/game/Item.cpp b/src/game/Item.cpp index 2c4ebfb0a3e..0c264a76d8b 100644 --- a/src/game/Item.cpp +++ b/src/game/Item.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -179,7 +179,7 @@ bool ItemCanGoIntoBag(ItemPrototype const *pProto, ItemPrototype const *pBagProt case ITEM_SUBCLASS_CONTAINER: return true; case ITEM_SUBCLASS_SOUL_CONTAINER: - if(!(pProto->BagFamily & BAG_FAMILY_MASK_SHARDS)) + if(!(pProto->BagFamily & BAG_FAMILY_MASK_SOUL_SHARDS)) return false; return true; case ITEM_SUBCLASS_HERB_CONTAINER: @@ -247,7 +247,7 @@ bool Item::Create( uint32 guidlow, uint32 itemid, Player const* owner) { Object::_Create( guidlow, 0, HIGHGUID_ITEM ); - SetUInt32Value(OBJECT_FIELD_ENTRY, itemid); + SetEntry(itemid); SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f); SetUInt64Value(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : 0); @@ -429,7 +429,7 @@ void Item::DeleteFromInventoryDB() ItemPrototype const *Item::GetProto() const { - return objmgr.GetItemPrototype(GetUInt32Value(OBJECT_FIELD_ENTRY)); + return objmgr.GetItemPrototype(GetEntry()); } Player* Item::GetOwner()const @@ -762,9 +762,7 @@ bool Item::IsFitToSpellRequirements(SpellEntry const* spellInfo) const void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges) { // Better lost small time at check in comparison lost time at item save to DB. - if( GetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET)==id && - GetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET)==duration && - GetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET)==charges ) + if((GetEnchantmentId(slot) == id) && (GetEnchantmentDuration(slot) == duration) && (GetEnchantmentCharges(slot) == charges)) return; SetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET,id); @@ -775,7 +773,7 @@ void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint void Item::SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration) { - if(GetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET)==duration) + if(GetEnchantmentDuration(slot) == duration) return; SetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET,duration); @@ -784,17 +782,20 @@ void Item::SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration) void Item::SetEnchantmentCharges(EnchantmentSlot slot, uint32 charges) { + if(GetEnchantmentCharges(slot) == charges) + return; + SetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET,charges); SetState(ITEM_CHANGED); } void Item::ClearEnchantment(EnchantmentSlot slot) { - if(!GetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET)) + if(!GetEnchantmentId(slot)) return; - for(int x=0;x<3;x++) - SetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + x,0); + for(uint8 x = 0; x < 3; ++x) + SetUInt32Value(ITEM_FIELD_ENCHANTMENT + slot*MAX_ENCHANTMENT_OFFSET + x, 0); SetState(ITEM_CHANGED); } diff --git a/src/game/Item.h b/src/game/Item.h index 7b265b9cbf2..72c09b0c1da 100644 --- a/src/game/Item.h +++ b/src/game/Item.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITYCORE_ITEM_H @@ -228,7 +228,6 @@ class TRINITY_DLL_SPEC Item : public Object bool IsLimitedToAnotherMapOrZone( uint32 cur_mapId, uint32 cur_zoneId) const; bool GemsFitSockets() const; - uint32 GetEntry() const { return GetUInt32Value(OBJECT_FIELD_ENTRY); } uint32 GetCount() const { return GetUInt32Value (ITEM_FIELD_STACK_COUNT); } void SetCount(uint32 value) { SetUInt32Value (ITEM_FIELD_STACK_COUNT, value); } uint32 GetMaxStackCount() const { return GetProto()->Stackable; } diff --git a/src/game/ItemEnchantmentMgr.cpp b/src/game/ItemEnchantmentMgr.cpp index 6d4197b0335..52a2e5dc1eb 100644 --- a/src/game/ItemEnchantmentMgr.cpp +++ b/src/game/ItemEnchantmentMgr.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include diff --git a/src/game/ItemEnchantmentMgr.h b/src/game/ItemEnchantmentMgr.h index a6b84c17418..97053c1ec36 100644 --- a/src/game/ItemEnchantmentMgr.h +++ b/src/game/ItemEnchantmentMgr.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _ITEM_ENCHANTMENT_MGR_H diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index 5f9daa44336..c074ac98d77 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -313,9 +313,9 @@ void WorldSession::HandleItemQuerySingleOpcode( WorldPacket & recv_data ) ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId); if (il) { - if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty()) + if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty()) Name = il->Name[loc_idx]; - if (il->Description.size() > loc_idx && !il->Description[loc_idx].empty()) + if (il->Description.size() > size_t(loc_idx) && !il->Description[loc_idx].empty()) Description = il->Description[loc_idx]; } } @@ -360,6 +360,8 @@ void WorldSession::HandleItemQuerySingleOpcode( WorldPacket & recv_data ) data << pProto->Damage[i].DamageMax; data << pProto->Damage[i].DamageType; } + + // resistances (7) data << pProto->Armor; data << pProto->HolyRes; data << pProto->FireRes; @@ -367,10 +369,11 @@ void WorldSession::HandleItemQuerySingleOpcode( WorldPacket & recv_data ) data << pProto->FrostRes; data << pProto->ShadowRes; data << pProto->ArcaneRes; + data << pProto->Delay; data << pProto->Ammo_type; + data << pProto->RangedModRange; - data << (float)pProto->RangedModRange; for(int s = 0; s < 5; s++) { // send DBC data for cooldowns in same way as it used in Spell::SendSpellCooldown @@ -976,7 +979,7 @@ void WorldSession::HandleItemNameQueryOpcode(WorldPacket & recv_data) ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId); if (il) { - if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty()) + if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty()) Name = il->Name[loc_idx]; } } @@ -1027,7 +1030,7 @@ void WorldSession::HandleWrapItemOpcode(WorldPacket& recv_data) return; } - if(item==gift) // not possible with pacjket from real client + if(item==gift) // not possable with pacjket from real client { _player->SendEquipError( EQUIP_ERR_WRAPPED_CANT_BE_WRAPPED, item, NULL ); return; @@ -1072,16 +1075,16 @@ void WorldSession::HandleWrapItemOpcode(WorldPacket& recv_data) CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("INSERT INTO character_gifts VALUES ('%u', '%u', '%u', '%u')", GUID_LOPART(item->GetOwnerGUID()), item->GetGUIDLow(), item->GetEntry(), item->GetUInt32Value(ITEM_FIELD_FLAGS)); - item->SetUInt32Value(OBJECT_FIELD_ENTRY, gift->GetUInt32Value(OBJECT_FIELD_ENTRY)); + item->SetEntry(gift->GetEntry()); switch (item->GetEntry()) { - case 5042: item->SetUInt32Value(OBJECT_FIELD_ENTRY, 5043); break; - case 5048: item->SetUInt32Value(OBJECT_FIELD_ENTRY, 5044); break; - case 17303: item->SetUInt32Value(OBJECT_FIELD_ENTRY, 17302); break; - case 17304: item->SetUInt32Value(OBJECT_FIELD_ENTRY, 17305); break; - case 17307: item->SetUInt32Value(OBJECT_FIELD_ENTRY, 17308); break; - case 21830: item->SetUInt32Value(OBJECT_FIELD_ENTRY, 21831); break; + case 5042: item->SetEntry( 5043); break; + case 5048: item->SetEntry( 5044); break; + case 17303: item->SetEntry(17302); break; + case 17304: item->SetEntry(17305); break; + case 17307: item->SetEntry(17308); break; + case 21830: item->SetEntry(21831); break; } item->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, _player->GetGUID()); item->SetUInt32Value(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED); diff --git a/src/game/ItemPrototype.h b/src/game/ItemPrototype.h index 4762bf1e26a..8a90ad49adb 100644 --- a/src/game/ItemPrototype.h +++ b/src/game/ItemPrototype.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _ITEMPROTOTYPE_H @@ -99,16 +99,18 @@ enum ITEM_FLAGS ITEM_FLAGS_UNIQUE_EQUIPPED = 0x00080000, ITEM_FLAGS_USEABLE_IN_ARENA = 0x00200000, ITEM_FLAGS_THROWABLE = 0x00400000, // not used in game for check trow possibility, only for item in game tooltip - ITEM_FLAGS_SPECIALUSE = 0x00800000 // last used flag in 2.3.0 + ITEM_FLAGS_SPECIALUSE = 0x00800000, // last used flag in 2.3.0 + ITEM_FLAGS_BOA = 0x08000000, // bind on account + ITEM_FLAGS_MILLABLE = 0x20000000 }; enum BAG_FAMILY_MASK { BAG_FAMILY_MASK_ARROWS = 0x00000001, BAG_FAMILY_MASK_BULLETS = 0x00000002, - BAG_FAMILY_MASK_SHARDS = 0x00000004, + BAG_FAMILY_MASK_SOUL_SHARDS = 0x00000004, BAG_FAMILY_MASK_LEATHERWORKING_SUPP = 0x00000008, - BAG_FAMILY_MASK_UNUSED = 0x00000010, // not used currently + BAG_FAMILY_MASK_INSCRIPTION_SUPP = 0x00000010, BAG_FAMILY_MASK_HERBS = 0x00000020, BAG_FAMILY_MASK_ENCHANTING_SUPP = 0x00000040, BAG_FAMILY_MASK_ENGINEERING_SUPP = 0x00000080, @@ -116,13 +118,11 @@ enum BAG_FAMILY_MASK BAG_FAMILY_MASK_GEMS = 0x00000200, BAG_FAMILY_MASK_MINING_SUPP = 0x00000400, BAG_FAMILY_MASK_SOULBOUND_EQUIPMENT = 0x00000800, - BAG_FAMILY_MASK_VANITY_PETS = 0x00001000 + BAG_FAMILY_MASK_VANITY_PETS = 0x00001000, + BAG_FAMILY_MASK_CURRENCY_TOKENS = 0x00002000, + BAG_FAMILY_MASK_QUEST_ITEMS = 0x00004000 }; -/* TODO: Not entirely positive on need for this?? -enum SOCKET_CONTENT (); -*/ - enum SocketColor { SOCKET_COLOR_META = 1, @@ -275,7 +275,7 @@ enum ItemSubclassArmor ITEM_SUBCLASS_ARMOR_TOTEM = 9 }; -#define MAX_ITEM_SUBCLASS_ARMOR 10 +#define MAX_ITEM_SUBCLASS_ARMOR 10 enum ItemSubclassReagent { @@ -390,6 +390,22 @@ enum ItemSubclassJunk #define MAX_ITEM_SUBCLASS_JUNK 6 +enum ItemSubclassGlyph +{ + ITEM_SUBCLASS_GLYPH_WARRIOR = 1, + ITEM_SUBCLASS_GLYPH_PALADIN = 2, + ITEM_SUBCLASS_GLYPH_HUNTER = 3, + ITEM_SUBCLASS_GLYPH_ROGUE = 4, + ITEM_SUBCLASS_GLYPH_PRIEST = 5, + ITEM_SUBCLASS_GLYPH_DEATH_KNIGHT = 6, + ITEM_SUBCLASS_GLYPH_SHAMAN = 7, + ITEM_SUBCLASS_GLYPH_MAGE = 8, + ITEM_SUBCLASS_GLYPH_WARLOCK = 9, + ITEM_SUBCLASS_GLYPH_DRUID = 11 +}; + +#define MAX_ITEM_SUBCLASS_GLYPH 12 + const uint32 MaxItemSubclassValues[MAX_ITEM_CLASS] = { MAX_ITEM_SUBCLASS_CONSUMABLE, @@ -524,7 +540,7 @@ struct ItemPrototype uint32 GemProperties; // id from GemProperties.dbc uint32 RequiredDisenchantSkill; float ArmorDamageModifier; - char* ScriptName; + uint32 ScriptId; uint32 DisenchantID; uint32 FoodType; uint32 MinMoneyLoot; diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 643a5b6f819..bb6a4473e0b 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -2361,8 +2361,8 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) std::string show = show_str; // Check // Remember: "show" must also be the name of a column! - if( (show != "emote") && (show != "spell") && (show != "text1") && (show != "text2") - && (show != "text3") && (show != "text4") && (show != "text5") + if( (show != "emote") && (show != "spell") && (show != "textid1") && (show != "textid2") + && (show != "textid3") && (show != "textid4") && (show != "textid5") && (show != "waittime") && (show != "del") && (show != "move") && (show != "add") && (show != "model1") && (show != "model2") && (show != "orientation")) { @@ -2705,6 +2705,13 @@ bool ChatHandler::HandleWpModifyCommand(const char* args) return false; } + // set in game textids not supported + if( show == "textid1" || show == "textid2" || show == "textid3" || + show == "textid4" || show == "textid5" ) + { + return false; + } + WaypointMgr.SetNodeText(lowguid, point, show_str, arg_str); Creature* npcCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), MAKE_NEW_GUID(lowguid, data->id, HIGHGUID_UNIT)); @@ -2842,7 +2849,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) //pCreature->GetPositionX(); QueryResult *result = - WorldDatabase.PQuery( "SELECT id, point, waittime, emote, spell, text1, text2, text3, text4, text5, model1, model2 FROM creature_movement WHERE wpguid = %u", + WorldDatabase.PQuery( "SELECT id, point, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, model1, model2 FROM creature_movement WHERE wpguid = %u", target->GetGUIDLow() ); if(!result) { @@ -2854,7 +2861,7 @@ bool ChatHandler::HandleWpShowCommand(const char* args) const char* maxDIFF = "0.01"; PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUID()); - result = WorldDatabase.PQuery( "SELECT id, point, waittime, emote, spell, text1, text2, text3, text4, text5, model1, model2 FROM creature_movement WHERE (abs(position_x - %f) <= %s ) and (abs(position_y - %f) <= %s ) and (abs(position_z - %f) <= %s )", + result = WorldDatabase.PQuery( "SELECT id, point, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, model1, model2 FROM creature_movement WHERE (abs(position_x - %f) <= %s ) and (abs(position_y - %f) <= %s ) and (abs(position_z - %f) <= %s )", target->GetPositionX(), maxDIFF, target->GetPositionY(), maxDIFF, target->GetPositionZ(), maxDIFF); if(!result) { @@ -2871,11 +2878,9 @@ bool ChatHandler::HandleWpShowCommand(const char* args) int waittime = fields[2].GetUInt32(); uint32 emote = fields[3].GetUInt32(); uint32 spell = fields[4].GetUInt32(); - const char * text1 = fields[5].GetString(); - const char * text2 = fields[6].GetString(); - const char * text3 = fields[7].GetString(); - const char * text4 = fields[8].GetString(); - const char * text5 = fields[9].GetString(); + uint32 textid[MAX_WAYPOINT_TEXT]; + for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i) + textid[i] = fields[5+i].GetUInt32(); uint32 model1 = fields[10].GetUInt32(); uint32 model2 = fields[11].GetUInt32(); @@ -2888,11 +2893,8 @@ bool ChatHandler::HandleWpShowCommand(const char* args) PSendSysMessage(LANG_WAYPOINT_INFO_MODEL, 2, model2); PSendSysMessage(LANG_WAYPOINT_INFO_EMOTE, emote); PSendSysMessage(LANG_WAYPOINT_INFO_SPELL, spell); - PSendSysMessage(LANG_WAYPOINT_INFO_TEXT, 1, text1); - PSendSysMessage(LANG_WAYPOINT_INFO_TEXT, 2, text2); - PSendSysMessage(LANG_WAYPOINT_INFO_TEXT, 3, text3); - PSendSysMessage(LANG_WAYPOINT_INFO_TEXT, 4, text4); - PSendSysMessage(LANG_WAYPOINT_INFO_TEXT, 5, text5); + for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i) + PSendSysMessage(LANG_WAYPOINT_INFO_TEXT, i+1, textid[i], (textid[i] ? GetTrinityString(textid[i]) : "")); }while( result->NextRow() ); // Cleanup memory @@ -3213,8 +3215,8 @@ bool ChatHandler::HandleWpExportCommand(const char *args) PSendSysMessage("DEBUG: wp export, GUID: %u", lowguid); QueryResult *result = WorldDatabase.PQuery( - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - "SELECT point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, text1, text2, text3, text4, text5, id FROM creature_movement WHERE id = '%u' ORDER BY point", lowguid ); + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + "SELECT point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, id FROM creature_movement WHERE id = '%u' ORDER BY point", lowguid ); if (!result) { @@ -3231,7 +3233,7 @@ bool ChatHandler::HandleWpExportCommand(const char *args) Field *fields = result->Fetch(); outfile << "INSERT INTO creature_movement "; - outfile << "( id, point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, text1, text2, text3, text4, text5 ) VALUES "; + outfile << "( id, point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5 ) VALUES "; outfile << "( "; outfile << fields[15].GetUInt32(); // id @@ -3256,65 +3258,15 @@ bool ChatHandler::HandleWpExportCommand(const char *args) outfile << ", "; outfile << fields[9].GetUInt32(); // spell outfile << ", "; - const char *tmpChar = fields[10].GetString(); - if( !tmpChar ) - { - outfile << "NULL"; // text1 - } - else - { - outfile << "'"; - outfile << tmpChar; // text1 - outfile << "'"; - } + outfile << fields[10].GetUInt32(); // textid1 outfile << ", "; - tmpChar = fields[11].GetString(); - if( !tmpChar ) - { - outfile << "NULL"; // text2 - } - else - { - outfile << "'"; - outfile << tmpChar; // text2 - outfile << "'"; - } + outfile << fields[11].GetUInt32(); // textid2 outfile << ", "; - tmpChar = fields[12].GetString(); - if( !tmpChar ) - { - outfile << "NULL"; // text3 - } - else - { - outfile << "'"; - outfile << tmpChar; // text3 - outfile << "'"; - } + outfile << fields[12].GetUInt32(); // textid3 outfile << ", "; - tmpChar = fields[13].GetString(); - if( !tmpChar ) - { - outfile << "NULL"; // text4 - } - else - { - outfile << "'"; - outfile << tmpChar; // text4 - outfile << "'"; - } + outfile << fields[13].GetUInt32(); // textid4 outfile << ", "; - tmpChar = fields[14].GetString(); - if( !tmpChar ) - { - outfile << "NULL"; // text5 - } - else - { - outfile << "'"; - outfile << tmpChar; // text5 - outfile << "'"; - } + outfile << fields[14].GetUInt32(); // textid5 outfile << ");\n "; } while( result->NextRow() ); diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index a2f68a4ce58..1fb799cde6b 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -135,6 +135,7 @@ bool ChatHandler::HandleReloadAllScriptsCommand(const char*) HandleReloadQuestStartScriptsCommand("a"); HandleReloadSpellScriptsCommand("a"); SendGlobalSysMessage("DB tables `*_scripts` reloaded."); + HandleReloadDbScriptStringCommand("a"); return true; } @@ -601,6 +602,14 @@ bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg) return true; } +bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg) +{ + sLog.outString( "Re-Loading Script strings from `db_script_string`..."); + objmgr.LoadDbScriptStrings(); + SendGlobalSysMessage("DB table `db_script_string` reloaded."); + return true; +} + bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/) { sLog.outString( "Re-Loading Graveyard-zone links..."); @@ -1767,7 +1776,8 @@ bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/) // search highest talent rank uint32 spellid = 0; - for(int rank = 4; rank >= 0; --rank) + int rank = 4; + for(; rank >= 0; --rank) { if(talentInfo->RankID[rank]!=0) { @@ -4645,91 +4655,149 @@ bool ChatHandler::HandleResetAllCommand(const char * args) return true; } -bool ChatHandler::HandleShutDownCommand(const char* args) +bool ChatHandler::HandleServerShutDownCancelCommand(const char* args) +{ + sWorld.ShutdownCancel(); + return true; +} + +bool ChatHandler::HandleServerShutDownCommand(const char* args) { if(!*args) return false; - if(std::string(args)=="cancel") - { - sWorld.ShutdownCancel(); - } - else + char* time_str = strtok ((char*) args, " "); + char* exitcode_str = strtok (NULL, ""); + + int32 time = atoi (time_str); + + ///- Prevent interpret wrong arg value as 0 secs shutdown time + if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) + return false; + + if (exitcode_str) { - int32 time = atoi(args); + int32 exitcode = atoi (exitcode_str); - ///- Prevent interpret wrong arg value as 0 secs shutdown time - if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) + // Handle atoi() errors + if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) return false; - sWorld.ShutdownServ(time); + // Exit code should be in range of 0-125, 126-255 is used + // in many shells for their own return codes and code > 255 + // is not supported in many others + if (exitcode < 0 || exitcode > 125) + return false; + + sWorld.ShutdownServ (time, 0, exitcode); } + else + sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE); return true; } -bool ChatHandler::HandleRestartCommand(const char* args) +bool ChatHandler::HandleServerRestartCommand(const char* args) { if(!*args) return false; - if(std::string(args)=="cancel") - { - sWorld.ShutdownCancel(); - } - else + char* time_str = strtok ((char*) args, " "); + char* exitcode_str = strtok (NULL, ""); + + int32 time = atoi (time_str); + + ///- Prevent interpret wrong arg value as 0 secs shutdown time + if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) + return false; + + if (exitcode_str) { - int32 time = atoi(args); + int32 exitcode = atoi (exitcode_str); + + // Handle atoi() errors + if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) + return false; - ///- Prevent interpret wrong arg value as 0 secs shutdown time - if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) + // Exit code should be in range of 0-125, 126-255 is used + // in many shells for their own return codes and code > 255 + // is not supported in many others + if (exitcode < 0 || exitcode > 125) return false; - sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART); + sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode); } + else + sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE); return true; } -bool ChatHandler::HandleIdleRestartCommand(const char* args) +bool ChatHandler::HandleServerIdleRestartCommand(const char* args) { if(!*args) return false; - if(std::string(args)=="cancel") - { - sWorld.ShutdownCancel(); - } - else + char* time_str = strtok ((char*) args, " "); + char* exitcode_str = strtok (NULL, ""); + + int32 time = atoi (time_str); + + ///- Prevent interpret wrong arg value as 0 secs shutdown time + if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) + return false; + + if (exitcode_str) { - int32 time = atoi(args); + int32 exitcode = atoi (exitcode_str); + + // Handle atoi() errors + if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) + return false; - ///- Prevent interpret wrong arg value as 0 secs shutdown time - if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) + // Exit code should be in range of 0-125, 126-255 is used + // in many shells for their own return codes and code > 255 + // is not supported in many others + if (exitcode < 0 || exitcode > 125) return false; - sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE); + sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode); } + else + sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE); return true; } -bool ChatHandler::HandleIdleShutDownCommand(const char* args) +bool ChatHandler::HandleServerIdleShutDownCommand(const char* args) { if(!*args) return false; - if(std::string(args)=="cancel") - { - sWorld.ShutdownCancel(); - } - else + char* time_str = strtok ((char*) args, " "); + char* exitcode_str = strtok (NULL, ""); + + int32 time = atoi (time_str); + + ///- Prevent interpret wrong arg value as 0 secs shutdown time + if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0) + return false; + + if (exitcode_str) { - int32 time = atoi(args); + int32 exitcode = atoi (exitcode_str); - ///- Prevent interpret wrong arg value as 0 secs shutdown time - if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0) + // Handle atoi() errors + if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0')) return false; - sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE); + // Exit code should be in range of 0-125, 126-255 is used + // in many shells for their own return codes and code > 255 + // is not supported in many others + if (exitcode < 0 || exitcode > 125) + return false; + + sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode); } + else + sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE); return true; } diff --git a/src/game/Mail.cpp b/src/game/Mail.cpp index d91206bf6d9..6605cc78057 100644 --- a/src/game/Mail.cpp +++ b/src/game/Mail.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Mail.h" @@ -187,18 +187,17 @@ void WorldSession::HandleSendMail(WorldPacket & recv_data ) pl->SendMailResult(0, 0, MAIL_ERR_INTERNAL_ERROR); return; } - if (mailItem.item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || mailItem.item->GetUInt32Value(ITEM_FIELD_DURATION)) { pl->SendMailResult(0, 0, MAIL_ERR_INTERNAL_ERROR); return; } - if(COD && mailItem.item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED)) - { - pl->SendMailResult(0, 0, MAIL_ERR_CANT_SEND_WRAPPED_COD); - return; - } + if(COD && mailItem.item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED)) + { + pl->SendMailResult(0, 0, MAIL_ERR_CANT_SEND_WRAPPED_COD); + return; + } } } pl->SendMailResult(0, 0, MAIL_OK); diff --git a/src/game/Map.cpp b/src/game/Map.cpp index ba72775b5cf..3804560b662 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -1713,7 +1713,7 @@ void InstanceMap::CreateInstanceData(bool load) InstanceTemplate const* mInstance = objmgr.GetInstanceTemplate(GetId()); if (mInstance) { - i_script = mInstance->script; + i_script_id = mInstance->script_id; i_data = Script->CreateInstanceData(this); } @@ -1730,7 +1730,7 @@ void InstanceMap::CreateInstanceData(bool load) const char* data = fields[0].GetString(); if(data) { - sLog.outDebug("Loading instance data for `%s` with id %u", i_script.c_str(), i_InstanceId); + sLog.outDebug("Loading instance data for `%s` with id %u", objmgr.GetScriptName(i_script_id), i_InstanceId); i_data->Load(data); } delete result; @@ -1738,7 +1738,7 @@ void InstanceMap::CreateInstanceData(bool load) } else { - sLog.outDebug("New instance data, \"%s\" ,initialized!",i_script.c_str()); + sLog.outDebug("New instance data, \"%s\" ,initialized!", objmgr.GetScriptName(i_script_id)); i_data->Initialize(); } } diff --git a/src/game/Map.h b/src/game/Map.h index 1765d6d09fa..6e0e9cb37a9 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -105,7 +105,7 @@ struct InstanceTemplate float startLocY; float startLocZ; float startLocO; - char const* script; + uint32 script_id; }; enum LevelRequirementVsMode @@ -343,7 +343,7 @@ class TRINITY_DLL_SPEC InstanceMap : public Map void Update(const uint32&); void CreateInstanceData(bool load); bool Reset(uint8 method); - std::string GetScript() { return i_script; } + uint32 GetScriptId() { return i_script_id; } InstanceData* GetInstanceData() { return i_data; } void PermBindAllPlayers(Player *player); time_t GetResetTime(); @@ -355,10 +355,7 @@ class TRINITY_DLL_SPEC InstanceMap : public Map bool m_resetAfterUnload; bool m_unloadWhenEmpty; InstanceData* i_data; - std::string i_script; - // only online players that are inside the instance currently - // TODO ? - use the grid instead to access the players - PlayerList i_Players; + uint32 i_script_id; }; class TRINITY_DLL_SPEC BattleGroundMap : public Map diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp index 34aefdff074..26279cb76ec 100644 --- a/src/game/MapManager.cpp +++ b/src/game/MapManager.cpp @@ -222,7 +222,7 @@ bool MapManager::CanPlayerEnter(uint32 mapid, Player* player) return true; } -void MapManager::DeleteInstance(uint32 mapid, uint32 instanceId, uint8 mode) +void MapManager::DeleteInstance(uint32 mapid, uint32 instanceId) { Map *m = _GetBaseMap(mapid); if (m && m->Instanceable()) diff --git a/src/game/MapManager.h b/src/game/MapManager.h index 44197ccd84a..cba0a86d1a5 100644 --- a/src/game/MapManager.h +++ b/src/game/MapManager.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITY_MAPMANAGER_H @@ -27,6 +27,7 @@ #include "Common.h" #include "Map.h" #include "GridStates.h" + class Transport; class TRINITY_DLL_DECL MapManager : public Trinity::Singleton > @@ -44,7 +45,7 @@ class TRINITY_DLL_DECL MapManager : public Trinity::Singleton(this)->_GetBaseMap(id); } - void DeleteInstance(uint32 mapid, uint32 instanceId, uint8 mode); + void DeleteInstance(uint32 mapid, uint32 instanceId); inline uint16 GetAreaFlag(uint32 mapid, float x, float y) const { diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 43d867d779d..751a3ca4fbc 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -10,17 +10,18 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" #include "Database/DatabaseEnv.h" #include "Database/SQLStorage.h" +#include "Database/SQLStorageImpl.h" #include "Log.h" #include "MapManager.h" @@ -116,8 +117,12 @@ ObjectMgr::ObjectMgr() m_hiGoGuid = 1; m_hiDoGuid = 1; m_hiCorpseGuid = 1; - m_hiPetNumber = 1; + m_ItemTextId = 1; + m_mailid = 1; + m_auctionid = 1; + m_guildId = 1; + m_arenaTeamId = 1; mGuildBankTabPrice.resize(GUILD_BANK_MAX_TABS); mGuildBankTabPrice[0] = 100; @@ -415,7 +420,7 @@ void ObjectMgr::SendAuctionWonMail( AuctionEntry *auction ) sLog.outDebug( "AuctionWon body string : %s", msgAuctionWonBody.str().c_str() ); //prepare mail data... : - uint32 itemTextId = this->CreateItemText( msgAuctionWonBody.str() ); + uint32 itemTextId = CreateItemText( msgAuctionWonBody.str() ); // set owner to bidder (to prevent delete item with sender char deleting) // owner in `data` will set at mail receive and item extracting @@ -466,7 +471,7 @@ void ObjectMgr::SendAuctionSalePendingMail( AuctionEntry * auction ) sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str()); - uint32 itemTextId = this->CreateItemText( msgAuctionSalePendingBody.str() ); + uint32 itemTextId = CreateItemText( msgAuctionSalePendingBody.str() ); WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION); } @@ -498,7 +503,7 @@ void ObjectMgr::SendAuctionSuccessfulMail( AuctionEntry * auction ) sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str()); - uint32 itemTextId = this->CreateItemText( auctionSuccessfulBody.str() ); + uint32 itemTextId = CreateItemText( auctionSuccessfulBody.str() ); uint32 profit = auction->bid + auction->deposit - auctionCut; @@ -545,7 +550,6 @@ void ObjectMgr::SendAuctionExpiredMail( AuctionEntry * auction ) // will delete item or place to receiver mail list WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, GUID_LOPART(owner_guid), subject.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE); - } // owner not found else @@ -563,8 +567,8 @@ CreatureInfo const* ObjectMgr::GetCreatureTemplate(uint32 id) void ObjectMgr::LoadCreatureLocales() { - mCreatureLocaleMap.clear(); - + mCreatureLocaleMap.clear(); // need for reload case + QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,subname_loc1,name_loc2,subname_loc2,name_loc3,subname_loc3,name_loc4,subname_loc4,name_loc5,subname_loc5,name_loc6,subname_loc6,name_loc7,subname_loc7,name_loc8,subname_loc8 FROM locales_creature"); if(!result) @@ -623,7 +627,7 @@ void ObjectMgr::LoadCreatureLocales() sLog.outString(); sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() ); } - + void ObjectMgr::LoadNpcOptionLocales() { mNpcOptionLocaleMap.clear(); // need for reload case @@ -692,9 +696,19 @@ void ObjectMgr::LoadNpcOptionLocales() sLog.outString( ">> Loaded %u npc_option locale strings", mNpcOptionLocaleMap.size() ); } +struct SQLCreatureLoader : public SQLStorageLoaderBase +{ + template + void convert_from_str(uint32 field_pos, char *src, D &dst) + { + dst = D(objmgr.GetScriptId(src)); + } +}; + void ObjectMgr::LoadCreatureTemplates() { - sCreatureStorage.Load(); + SQLCreatureLoader loader; + loader.Load(sCreatureStorage); sLog.outString( ">> Loaded %u creature definitions", sCreatureStorage.RecordCount ); sLog.outString(); @@ -1512,7 +1526,7 @@ void ObjectMgr::LoadAuctions() aItem->deposit = fields[10].GetUInt32(); aItem->location = fields[11].GetUInt8(); //check if sold item exists - if ( this->GetAItem( aItem->item_guidlow ) ) + if ( GetAItem( aItem->item_guidlow ) ) { GetAuctionsMap( aItem->location )->AddAuction(aItem); } @@ -1532,8 +1546,8 @@ void ObjectMgr::LoadAuctions() void ObjectMgr::LoadItemLocales() { - mItemLocaleMap.clear(); - + mItemLocaleMap.clear(); // need for reload case + QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,description_loc1,name_loc2,description_loc2,name_loc3,description_loc3,name_loc4,description_loc4,name_loc5,description_loc5,name_loc6,description_loc6,name_loc7,description_loc7,name_loc8,description_loc8 FROM locales_item"); if(!result) @@ -1594,9 +1608,19 @@ void ObjectMgr::LoadItemLocales() sLog.outString( ">> Loaded %u Item locale strings", mItemLocaleMap.size() ); } +struct SQLItemLoader : public SQLStorageLoaderBase +{ + template + void convert_from_str(uint32 field_pos, char *src, D &dst) + { + dst = D(objmgr.GetScriptId(src)); + } +}; + void ObjectMgr::LoadItemPrototypes() { - sItemStorage.Load (); + SQLItemLoader loader; + loader.Load(sItemStorage); sLog.outString( ">> Loaded %u item prototypes", sItemStorage.RecordCount ); sLog.outString(); @@ -2506,7 +2530,7 @@ void ObjectMgr::LoadPlayerInfo() // skip expansion races if not playing with expansion if (sWorld.getConfig(CONFIG_EXPANSION) < 1 && (race == RACE_BLOODELF || race == RACE_DRAENEI)) continue; - + // skip expansion classes if not playing with expansion if (sWorld.getConfig(CONFIG_EXPANSION) < 2 && class_ == CLASS_DEATH_KNIGHT) continue; @@ -3555,7 +3579,7 @@ void ObjectMgr::LoadQuests() void ObjectMgr::LoadQuestLocales() { - mQuestLocaleMap.clear(); + mQuestLocaleMap.clear(); // need for reload case QueryResult *result = WorldDatabase.Query("SELECT entry," "Title_loc1,Details_loc1,Objectives_loc1,OfferRewardText_loc1,RequestItemsText_loc1,EndText_loc1,ObjectiveText1_loc1,ObjectiveText2_loc1,ObjectiveText3_loc1,ObjectiveText4_loc1," @@ -3749,7 +3773,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) scripts.clear(); // need for reload support - QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,datatext, x, y, z, o FROM %s", tablename ); + QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename ); uint32 count = 0; @@ -3771,16 +3795,16 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) Field *fields = result->Fetch(); ScriptInfo tmp; - tmp.id = fields[0].GetUInt32(); - tmp.delay = fields[1].GetUInt32(); - tmp.command = fields[2].GetUInt32(); - tmp.datalong = fields[3].GetUInt32(); + tmp.id = fields[0].GetUInt32(); + tmp.delay = fields[1].GetUInt32(); + tmp.command = fields[2].GetUInt32(); + tmp.datalong = fields[3].GetUInt32(); tmp.datalong2 = fields[4].GetUInt32(); - tmp.datatext = fields[5].GetCppString(); - tmp.x = fields[6].GetFloat(); - tmp.y = fields[7].GetFloat(); - tmp.z = fields[8].GetFloat(); - tmp.o = fields[9].GetFloat(); + tmp.dataint = fields[5].GetInt32(); + tmp.x = fields[6].GetFloat(); + tmp.y = fields[7].GetFloat(); + tmp.z = fields[8].GetFloat(); + tmp.o = fields[9].GetFloat(); // generic command args check switch(tmp.command) @@ -3792,6 +3816,18 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) sLog.outErrorDb("Table `%s` has invalid talk type (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.datalong,tmp.id); continue; } + if(tmp.dataint==0) + { + sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,tmp.id); + continue; + } + if(tmp.dataint < MIN_DB_SCRIPT_STRING_ID || tmp.dataint >= MAX_DB_SCRIPT_STRING_ID) + { + sLog.outErrorDb("Table `%s` has out of range text id (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID,tmp.id); + continue; + } + + // if(!objmgr.GetMangosStringLocale(tmp.dataint)) will checked after db_script_string loading break; } @@ -4156,8 +4192,8 @@ void ObjectMgr::LoadPageTexts() void ObjectMgr::LoadPageTextLocales() { - mPageTextLocaleMap.clear(); - + mPageTextLocaleMap.clear(); // need for reload case + QueryResult *result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text"); if(!result) @@ -4206,9 +4242,19 @@ void ObjectMgr::LoadPageTextLocales() sLog.outString( ">> Loaded %u PageText locale strings", mPageTextLocaleMap.size() ); } +struct SQLInstanceLoader : public SQLStorageLoaderBase +{ + template + void convert_from_str(uint32 field_pos, char *src, D &dst) + { + dst = D(objmgr.GetScriptId(src)); + } +}; + void ObjectMgr::LoadInstanceTemplate() { - sInstanceTemplate.Load(); + SQLInstanceLoader loader; + loader.Load(sInstanceTemplate); for(uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++) { @@ -4324,8 +4370,8 @@ void ObjectMgr::LoadGossipText() void ObjectMgr::LoadNpcTextLocales() { - mNpcTextLocaleMap.clear(); - + mNpcTextLocaleMap.clear(); // need for reload case + QueryResult *result = WorldDatabase.Query("SELECT entry," "Text0_0_loc1,Text0_1_loc1,Text1_0_loc1,Text1_1_loc1,Text2_0_loc1,Text2_1_loc1,Text3_0_loc1,Text3_1_loc1,Text4_0_loc1,Text4_1_loc1,Text5_0_loc1,Text5_1_loc1,Text6_0_loc1,Text6_1_loc1,Text7_0_loc1,Text7_1_loc1," "Text0_0_loc2,Text0_1_loc2,Text1_0_loc2,Text1_1_loc2,Text2_0_loc2,Text2_1_loc2,Text3_0_loc2,Text3_1_loc1,Text4_0_loc2,Text4_1_loc2,Text5_0_loc2,Text5_1_loc2,Text6_0_loc2,Text6_1_loc2,Text7_0_loc2,Text7_1_loc2," @@ -4622,7 +4668,7 @@ void ObjectMgr::LoadAreaTriggerScripts() Field *fields = result->Fetch(); uint32 Trigger_ID = fields[0].GetUInt32(); - std::string scriptName = fields[1].GetCppString(); + const char *scriptName = fields[1].GetString(); AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); if(!atEntry) @@ -4630,7 +4676,7 @@ void ObjectMgr::LoadAreaTriggerScripts() sLog.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID); continue; } - mAreaTriggerScripts[Trigger_ID] = scriptName; + mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName); } while( result->NextRow() ); delete result; @@ -4638,6 +4684,7 @@ void ObjectMgr::LoadAreaTriggerScripts() sLog.outString(); sLog.outString( ">> Loaded %u areatrigger scripts", count ); } + uint32 ObjectMgr::GetNearestTaxiNode( float x, float y, float z, uint32 mapid ) { bool found = false; @@ -4696,11 +4743,11 @@ void ObjectMgr::GetTaxiPath( uint32 source, uint32 destination, uint32 &path, ui uint16 ObjectMgr::GetTaxiMount( uint32 id, uint32 team ) { - uint32 mount_entry = 0; - uint32 mount_id = 0; + uint16 mount_entry = 0; + uint16 mount_id = 0; TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(id); - if (node) + if(node) { if (team == ALLIANCE) mount_entry = node->alliance_mount_type; else mount_entry = node->horde_mount_type; @@ -4939,7 +4986,6 @@ WorldSafeLocsEntry const *ObjectMgr::GetClosestGraveYard(float x, float y, float } } - // find now nearest graveyard at same map if(entryNear) return entryNear; @@ -5180,7 +5226,6 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_hiCharGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5188,23 +5233,16 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_hiCreatureGuid = (*result)[0].GetUInt32()+1; - delete result; } - result = CharacterDatabase.Query( "SELECT MAX(id) FROM character_pet" ); - if( result ) - { - m_hiPetGuid = (*result)[0].GetUInt32()+1; - - delete result; - } + // pet guids are not saved to DB, set to 0 (pet guid != pet id) + m_hiPetGuid = 0; result = CharacterDatabase.Query( "SELECT MAX(guid) FROM item_instance" ); if( result ) { m_hiItemGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5218,7 +5256,6 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_hiGoGuid = (*result)[0].GetUInt32()+1; - delete result; } @@ -5226,74 +5263,93 @@ void ObjectMgr::SetHighestGuids() if( result ) { m_auctionid = (*result)[0].GetUInt32()+1; - delete result; } - else - { - m_auctionid = 0; - } + result = CharacterDatabase.Query( "SELECT MAX(id) FROM mail" ); if( result ) { m_mailid = (*result)[0].GetUInt32()+1; - delete result; } - else - { - m_mailid = 0; - } + result = CharacterDatabase.Query( "SELECT MAX(id) FROM item_text" ); if( result ) { - m_ItemTextId = (*result)[0].GetUInt32(); - + m_ItemTextId = (*result)[0].GetUInt32()+1; delete result; } - else - m_ItemTextId = 0; result = CharacterDatabase.Query( "SELECT MAX(guid) FROM corpse" ); if( result ) { m_hiCorpseGuid = (*result)[0].GetUInt32()+1; + delete result; + } + result = CharacterDatabase.Query("SELECT MAX(arenateamid) FROM arena_team"); + if (result) + { + m_arenaTeamId = (*result)[0].GetUInt32()+1; + delete result; + } + + result = CharacterDatabase.Query( "SELECT MAX(guildid) FROM guild" ); + if (result) + { + m_guildId = (*result)[0].GetUInt32()+1; delete result; } } +uint32 ObjectMgr::GenerateArenaTeamId() +{ + if(m_arenaTeamId>=0xFFFFFFFE) + { + sLog.outError("Arena team ids overflow!! Can't continue, shutting down server. "); + World::StopNow(ERROR_EXIT_CODE); + } + return m_arenaTeamId++; +} + +uint32 ObjectMgr::GenerateGuildId() +{ + if(m_guildId>=0xFFFFFFFE) + { + sLog.outError("Guild ids overflow!! Can't continue, shutting down server. "); + World::StopNow(ERROR_EXIT_CODE); + } + return m_guildId++; +} + uint32 ObjectMgr::GenerateAuctionID() { - ++m_auctionid; - if(m_auctionid>=0xFFFFFFFF) + if(m_auctionid>=0xFFFFFFFE) { sLog.outError("Auctions ids overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_auctionid; + return m_auctionid++; } uint32 ObjectMgr::GenerateMailID() { - ++m_mailid; - if(m_mailid>=0xFFFFFFFF) + if(m_mailid>=0xFFFFFFFE) { sLog.outError("Mail ids overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_mailid; + return m_mailid++; } uint32 ObjectMgr::GenerateItemTextID() { - ++m_ItemTextId; - if(m_ItemTextId>=0xFFFFFFFF) + if(m_ItemTextId>=0xFFFFFFFE) { sLog.outError("Item text ids overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_ItemTextId; + return m_ItemTextId++; } uint32 ObjectMgr::CreateItemText(std::string text) @@ -5315,61 +5371,54 @@ uint32 ObjectMgr::GenerateLowGuid(HighGuid guidhigh) switch(guidhigh) { case HIGHGUID_ITEM: - ++m_hiItemGuid; - if(m_hiItemGuid>=0xFFFFFFFF) + if(m_hiItemGuid>=0xFFFFFFFE) { sLog.outError("Item guid overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_hiItemGuid; + return m_hiItemGuid++; case HIGHGUID_UNIT: - ++m_hiCreatureGuid; - if(m_hiCreatureGuid>=0x00FFFFFF) + if(m_hiCreatureGuid>=0x00FFFFFE) { sLog.outError("Creature guid overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_hiCreatureGuid; + return m_hiCreatureGuid++; case HIGHGUID_PET: - ++m_hiPetGuid; - if(m_hiPetGuid>=0x00FFFFFF) + if(m_hiPetGuid>=0x00FFFFFE) { sLog.outError("Pet guid overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_hiPetGuid; + return m_hiPetGuid++; case HIGHGUID_PLAYER: - ++m_hiCharGuid; - if(m_hiCharGuid>=0xFFFFFFFF) + if(m_hiCharGuid>=0xFFFFFFFE) { sLog.outError("Players guid overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_hiCharGuid; + return m_hiCharGuid++; case HIGHGUID_GAMEOBJECT: - ++m_hiGoGuid; - if(m_hiGoGuid>=0x00FFFFFF) + if(m_hiGoGuid>=0x00FFFFFE) { sLog.outError("Gameobject guid overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_hiGoGuid; + return m_hiGoGuid++; case HIGHGUID_CORPSE: - ++m_hiCorpseGuid; - if(m_hiCorpseGuid>=0xFFFFFFFF) + if(m_hiCorpseGuid>=0xFFFFFFFE) { sLog.outError("Corpse guid overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_hiCorpseGuid; + return m_hiCorpseGuid++; case HIGHGUID_DYNAMICOBJECT: - ++m_hiDoGuid; - if(m_hiDoGuid>=0xFFFFFFFF) + if(m_hiDoGuid>=0xFFFFFFFE) { sLog.outError("DynamicObject guid overflow!! Can't continue, shutting down server. "); - sWorld.m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); } - return m_hiDoGuid; + return m_hiDoGuid++; default: ASSERT(0); } @@ -5380,8 +5429,8 @@ uint32 ObjectMgr::GenerateLowGuid(HighGuid guidhigh) void ObjectMgr::LoadGameObjectLocales() { - mGameObjectLocaleMap.clear(); - + mGameObjectLocaleMap.clear(); // need for reload case + QueryResult *result = WorldDatabase.Query("SELECT entry," "name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8," "castbarcaption_loc1,castbarcaption_loc2,castbarcaption_loc3,castbarcaption_loc4," @@ -5449,9 +5498,19 @@ void ObjectMgr::LoadGameObjectLocales() sLog.outString( ">> Loaded %u gameobject locale strings", mGameObjectLocaleMap.size() ); } +struct SQLGameObjectLoader : public SQLStorageLoaderBase +{ + template + void convert_from_str(uint32 field_pos, char *src, D &dst) + { + dst = D(objmgr.GetScriptId(src)); + } +}; + void ObjectMgr::LoadGameobjectInfo() { - sGOStorage.Load(); + SQLGameObjectLoader loader; + loader.Load(sGOStorage); // some checks for(uint32 id = 1; id < sGOStorage.MaxEntry; id++) @@ -6624,12 +6683,12 @@ bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart, DeclinedName const& n return true; } -const char* ObjectMgr::GetAreaTriggerScriptName(uint32 id) +uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id) { - AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(id); + AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id); if(i!= mAreaTriggerScripts.end()) - return i->second.c_str(); - return ""; + return i->second; + return 0; } // Checks if player meets the condition @@ -6674,10 +6733,10 @@ bool PlayerCondition::Meets(Player const * player) const return true; return false; } - case CONDITION_NO_AURA: - return !player->HasAura(value1, value2); - case CONDITION_ACTIVE_EVENT: - return gameeventmgr.IsActiveEvent(value1); + case CONDITION_NO_AURA: + return !player->HasAura(value1, value2); + case CONDITION_ACTIVE_EVENT: + return gameeventmgr.IsActiveEvent(value1); default: return false; } @@ -6798,30 +6857,30 @@ bool PlayerCondition::IsValid(ConditionType condition, uint32 value1, uint32 val sLog.outErrorDb("Quest condition has useless data in value2 (%u)!", value2); break; } - case CONDITION_NO_AURA: - { - if(!sSpellStore.LookupEntry(value1)) - { - sLog.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1); - return false; - } - if(value2 > 2) - { - sLog.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2); - return false; - } - break; - } - case CONDITION_ACTIVE_EVENT: - { - GameEvent::GameEventDataMap const& events = gameeventmgr.GetEventMap(); - if(value1 >=events.size() || !events[value1].isValid()) - { - sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1); - return false; - } - break; - } + case CONDITION_NO_AURA: + { + if(!sSpellStore.LookupEntry(value1)) + { + sLog.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1); + return false; + } + if(value2 > 2) + { + sLog.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2); + return false; + } + break; + } + case CONDITION_ACTIVE_EVENT: + { + GameEvent::GameEventDataMap const& events = gameeventmgr.GetEventMap(); + if(value1 >=events.size() || !events[value1].isValid()) + { + sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1); + return false; + } + break; + } } return true; } @@ -6951,7 +7010,7 @@ bool ObjectMgr::AddGameTele(GameTele& tele) for(GameTeleMap::const_iterator itr = m_GameTeleMap.begin(); itr != m_GameTeleMap.end(); ++itr) if(itr->first > new_id) new_id = itr->first; - + // use next ++new_id; @@ -6991,7 +7050,7 @@ bool ObjectMgr::DeleteGameTele(std::string name) void ObjectMgr::LoadTrainerSpell() { - // For reload case + // For reload case for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr) itr->second.Clear(); m_mCacheTrainerSpellMap.clear(); @@ -7082,7 +7141,7 @@ void ObjectMgr::LoadTrainerSpell() void ObjectMgr::LoadVendors() { - // For reload case + // For reload case for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr) itr->second.Clear(); m_mCacheVendorItemMap.clear(); @@ -7189,6 +7248,7 @@ void ObjectMgr::LoadNpcOptions() // 0 1 2 3 4 5 6 7 8 "SELECT id,gossip_id,npcflag,icon,action,box_money,coded,option_text,box_text " "FROM npc_option"); + if( !result ) { barGoLink bar( 1 ); @@ -7341,10 +7401,84 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 m return true; } +void ObjectMgr::LoadScriptNames() +{ + m_scriptNames.push_back(""); + QueryResult *result = WorldDatabase.Query( + "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' " + "UNION " + "SELECT DISTINCT(script) FROM instance_template WHERE script <> ''"); + if(result) + { + do + { + m_scriptNames.push_back((*result)[0].GetString()); + } while (result->NextRow()); + delete result; + } + + std::sort(m_scriptNames.begin(), m_scriptNames.end()); +} + +uint32 ObjectMgr::GetScriptId(const char *name) +{ + // use binary search to find the script name in the sorted vector + // assume "" is the first element + if(!name) return 0; + ScriptNameMap::const_iterator itr = + std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name); + if(itr == m_scriptNames.end()) return 0; + return itr - m_scriptNames.begin(); +} + +void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set& ids) +{ + for(ScriptMapMap::const_iterator itrMM = scripts.begin(); itrMM != scripts.end(); ++itrMM) + { + for(ScriptMap::const_iterator itrM = itrMM->second.begin(); itrM != itrMM->second.end(); ++itrM) + { + if(itrM->second.dataint) + { + if(!GetTrinityStringLocale (itrM->second.dataint)) + sLog.outErrorDb( "Table `db_script_string` has not existed string id %u", *itrM); + + if(ids.count(itrM->second.dataint)) + ids.erase(itrM->second.dataint); + } + } + } +} + +void ObjectMgr::LoadDbScriptStrings() +{ + LoadTrinityStrings(WorldDatabase,"db_script_string",MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID); + + std::set ids; + + for(int32 i = MIN_DB_SCRIPT_STRING_ID; i < MAX_DB_SCRIPT_STRING_ID; ++i) + if(GetTrinityStringLocale(i)) + ids.insert(i); + + CheckScripts(sQuestEndScripts,ids); + CheckScripts(sQuestStartScripts,ids); + CheckScripts(sSpellScripts,ids); + CheckScripts(sGameObjectScripts,ids); + CheckScripts(sEventScripts,ids); + + for(std::set::const_iterator itr = ids.begin(); itr != ids.end(); ++itr) + sLog.outErrorDb( "Table `db_script_string` has unused string id %u", *itr); +} + // Functions for scripting access -const char* GetAreaTriggerScriptNameById(uint32 id) +uint32 GetAreaTriggerScriptId(uint32 trigger_id) { - return objmgr.GetAreaTriggerScriptName(id); + return objmgr.GetAreaTriggerScriptId(trigger_id); } bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value, int32 end_value) @@ -7359,3 +7493,13 @@ bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value, i // for scripting localized strings allowed use _only_ negative entries return objmgr.LoadTrinityStrings(db,table,end_value,start_value); } + +uint32 TRINITY_DLL_SPEC GetScriptId(const char *name) +{ + return objmgr.GetScriptId(name); +} + +ObjectMgr::ScriptNameMap & GetScriptNames() +{ + return objmgr.GetScriptNames(); +} diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index a5d8a679fdd..9595418ed22 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _OBJECTMGR_H @@ -84,7 +84,7 @@ struct ScriptInfo uint32 command; uint32 datalong; uint32 datalong2; - std::string datatext; + int32 dataint; float x; float y; float z; @@ -128,6 +128,13 @@ typedef UNORDERED_MAP MapOb typedef UNORDERED_MAP RespawnTimes; + +// mangos string ranges +#define MIN_TRINITY_STRING_ID 1 +#define MAX_TRINITY_STRING_ID 2000000000 +#define MIN_DB_SCRIPT_STRING_ID MAX_TRINITY_STRING_ID +#define MAX_DB_SCRIPT_STRING_ID 2000010000 + struct TrinityStringLocale { std::vector Content; // 0 -> default, i -> i-1 locale index @@ -207,8 +214,8 @@ enum ConditionType CONDITION_QUESTREWARDED = 8, // quest_id 0 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active. CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD ñommission aura active - CONDITION_NO_AURA = 11, // spell_id effindex - CONDITION_ACTIVE_EVENT = 12, // event_id + CONDITION_NO_AURA = 11, // spell_id effindex + CONDITION_ACTIVE_EVENT = 12, // event_id }; #define MAX_CONDITION 13 // maximum value in ConditionType enum @@ -250,7 +257,7 @@ struct PlayerCondition // NPC gossip text id typedef UNORDERED_MAP CacheNpcTextIdMap; - +typedef std::list CacheNpcOptionList; typedef UNORDERED_MAP CacheVendorItemMap; typedef UNORDERED_MAP CacheTrainerSpellMap; @@ -299,9 +306,10 @@ class ObjectMgr typedef UNORDERED_MAP QuestMap; + typedef UNORDERED_MAP AreaTriggerMap; - typedef UNORDERED_MAP AreaTriggerScriptMap; + typedef UNORDERED_MAP AreaTriggerScriptMap; typedef UNORDERED_MAP RepOnKillMap; @@ -309,6 +317,8 @@ class ObjectMgr typedef UNORDERED_MAP PetCreateSpellMap; + typedef std::vector ScriptNameMap; + Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);} Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); } @@ -476,7 +486,7 @@ class ObjectMgr AreaTrigger const* GetGoBackTrigger(uint32 Map) const; - const char* GetAreaTriggerScriptName(uint32 id); + uint32 GetAreaTriggerScriptId(uint32 trigger_id); ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const { @@ -522,7 +532,8 @@ class ObjectMgr void LoadSpellScripts(); bool LoadTrinityStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value); - bool LoadTrinityStrings() { return LoadTrinityStrings(WorldDatabase,"trinity_string",1,std::numeric_limits::max()); } + bool LoadTrinityStrings() { return LoadTrinityStrings(WorldDatabase,"trinity_string",MIN_TRINITY_STRING_ID,MAX_TRINITY_STRING_ID); } + void LoadDbScriptStrings(); void LoadPetCreateSpells(); void LoadCreatureLocales(); void LoadCreatureTemplates(); @@ -592,6 +603,8 @@ class ObjectMgr uint32 GenerateMailID(); uint32 GenerateItemTextID(); uint32 GeneratePetNumber(); + uint32 GenerateArenaTeamId(); + uint32 GenerateGuildId(); void LoadPlayerInfoInCache(); PCachePlayerInfo GetPlayerInfoFromCache(uint32 unPlayerGuid) const; @@ -668,7 +681,6 @@ class ObjectMgr if(itr==mPageTextLocaleMap.end()) return NULL; return &itr->second; } - NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const { NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry); @@ -693,7 +705,7 @@ class ObjectMgr } const char *GetTrinityString(int32 entry, int locale_idx) const; const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry,DBCLocaleIndex); } - int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; } + int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; } void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); } void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance); @@ -732,7 +744,7 @@ class ObjectMgr int GetIndexForLocale(LocaleConstant loc); LocaleConstant GetLocaleForIndex(int i); // guild bank tabs - const uint32 GetGuildBankTabPrice(uint8 Index) { return Index < GUILD_BANK_MAX_TABS ? mGuildBankTabPrice[Index] : 0; } + uint32 GetGuildBankTabPrice(uint8 Index) const { return Index < GUILD_BANK_MAX_TABS ? mGuildBankTabPrice[Index] : 0; } uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2); bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const @@ -753,7 +765,7 @@ class ObjectMgr GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; } bool AddGameTele(GameTele& data); bool DeleteGameTele(std::string name); - + CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; } uint32 GetNpcGossip(uint32 entry) const @@ -761,7 +773,7 @@ class ObjectMgr CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry); if(iter == m_mCacheNpcTextIdMap.end()) return 0; - + return iter->second; } @@ -782,15 +794,25 @@ class ObjectMgr return &iter->second; } - void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost, bool savetodb = true); - bool RemoveVendorItem(uint32 entry,uint32 item, bool savetodb = true); - bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set* skip_vendors = NULL, uint32 ORnpcflag = 0) const; + void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost, bool savetodb = true); // for event + bool RemoveVendorItem(uint32 entry,uint32 item, bool savetodb = true); // for event + bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set* skip_vendors = NULL, uint32 ORnpcflag = 0 ) const; + void LoadScriptNames(); + ScriptNameMap &GetScriptNames() { return m_scriptNames; } + const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; } + uint32 GetScriptId(const char *name); protected: + + // first free id for selected id type uint32 m_auctionid; uint32 m_mailid; uint32 m_ItemTextId; + uint32 m_arenaTeamId; + uint32 m_guildId; + uint32 m_hiPetNumber; + // first free low guid for seelcted guid type uint32 m_hiCharGuid; uint32 m_hiCreatureGuid; uint32 m_hiPetGuid; @@ -799,9 +821,7 @@ class ObjectMgr uint32 m_hiDoGuid; uint32 m_hiCorpseGuid; - uint32 m_hiPetNumber; - - QuestMap mQuestTemplates; + QuestMap mQuestTemplates; typedef UNORDERED_MAP GossipTextMap; typedef UNORDERED_MAP QuestAreaTriggerMap; @@ -848,6 +868,8 @@ class ObjectMgr GameTeleMap m_GameTeleMap; + ScriptNameMap m_scriptNames; + typedef std::vector LocalForIndex; LocalForIndex m_LocalForIndex; int GetOrNewIndexForLocale(LocaleConstant loc); @@ -855,6 +877,7 @@ class ObjectMgr int DBCLocaleIndex; private: void LoadScripts(ScriptMapMap& scripts, char const* tablename); + void CheckScripts(ScriptMapMap const& scripts,std::set& ids); void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr); void LoadQuestRelationsHelper(QuestRelations& map,char const* table); @@ -907,7 +930,9 @@ class ObjectMgr #define objmgr Trinity::Singleton::Instance() // scripting access functions -bool TRINITY_DLL_SPEC LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits::min()); -TRINITY_DLL_SPEC const char* GetAreaTriggerScriptNameById(uint32 id); +TRINITY_DLL_SPEC bool LoadTrinityStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits::min()); +TRINITY_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id); +TRINITY_DLL_SPEC uint32 GetScriptId(const char *name); +TRINITY_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames(); #endif diff --git a/src/game/PlayerDump.cpp b/src/game/PlayerDump.cpp index 78f90bc9c9e..7b32f547bff 100644 --- a/src/game/PlayerDump.cpp +++ b/src/game/PlayerDump.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -277,7 +277,7 @@ void PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl // for guid set stop if set is empty if(guids && guids->empty()) - return; // nothing to do + return; // nothing to do // setup for guids case start position GUIDs::const_iterator guids_itr; @@ -343,7 +343,7 @@ DumpReturn PlayerDumpWriter::WriteDump(std::string file, uint32 guid) { FILE *fout = fopen(file.c_str(), "w"); if (!fout) - return DUMP_FILE_OPEN_ERROR; + return DUMP_FILE_OPEN_ERROR; std::string dump = GetDump(guid); @@ -371,9 +371,10 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str return DUMP_TOO_MANY_CHARS; } } + FILE *fin = fopen(file.c_str(), "r"); if(!fin) - return DUMP_FILE_OPEN_ERROR; + return DUMP_FILE_OPEN_ERROR; QueryResult * result = NULL; char newguid[20], chraccount[20], newpetid[20], currpetid[20], lastpetid[20]; @@ -390,7 +391,8 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str } else incHighest = false; } - else guid = objmgr.m_hiCharGuid; + else + guid = objmgr.m_hiCharGuid; // normalize the name if specified and check if it exists if(!normalizePlayerName(name)) @@ -468,29 +470,25 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str { case DTT_CHAR_TABLE: if(!changenth(line, 1, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); break; case DTT_CHARACTER: // character t. { if(!changenth(line, 1, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); // guid, data field:guid, items if(!changenth(line, 2, chraccount)) - ROLLBACK(DUMP_FILE_BROKEN); - + ROLLBACK(DUMP_FILE_BROKEN); std::string vals = getnth(line, 3); if(!changetoknth(vals, OBJECT_FIELD_GUID+1, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); - + ROLLBACK(DUMP_FILE_BROKEN); for(uint16 field = PLAYER_FIELD_INV_SLOT_HEAD; field < PLAYER_FARSIGHT; field++) if(!changetokGuid(vals, field+1, items, objmgr.m_hiItemGuid, true)) - ROLLBACK(DUMP_FILE_BROKEN); - + ROLLBACK(DUMP_FILE_BROKEN); if(!changenth(line, 3, vals.c_str())) - ROLLBACK(DUMP_FILE_BROKEN); - + ROLLBACK(DUMP_FILE_BROKEN); if (name == "") { // check if the original name already exists @@ -503,50 +501,49 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str delete result; // rename on login: `at_login` field 30 in raw field list if(!changenth(line, 30, "1")) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); } } else if(!changenth(line, 4, name.c_str())) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_INVENTORY: // character_inventory t. { if(!changenth(line, 1, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); // bag, item if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid, true)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changeGuid(line, 4, items, objmgr.m_hiItemGuid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); + if(!changeGuid(line, 4, items, objmgr.m_hiItemGuid)) + ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_ITEM: // item_instance t. { // item, owner, data field:item, owner guid if(!changeGuid(line, 1, items, objmgr.m_hiItemGuid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changenth(line, 2, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); - + ROLLBACK(DUMP_FILE_BROKEN); + if(!changenth(line, 2, newguid)) + ROLLBACK(DUMP_FILE_BROKEN); std::string vals = getnth(line,3); if(!changetokGuid(vals, OBJECT_FIELD_GUID+1, items, objmgr.m_hiItemGuid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changetoknth(vals, ITEM_FIELD_OWNER+1, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changenth(line, 3, vals.c_str())) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); + if(!changetoknth(vals, ITEM_FIELD_OWNER+1, newguid)) + ROLLBACK(DUMP_FILE_BROKEN); + if(!changenth(line, 3, vals.c_str())) + ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_ITEM_GIFT: // character_gift { // guid,item_guid, if(!changenth(line, 1, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); + if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) + ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_PET: // character_pet t @@ -569,9 +566,9 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str // item, entry, owner, ... if(!changenth(line, 1, newpetid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changenth(line, 3, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); + if(!changenth(line, 3, newguid)) + ROLLBACK(DUMP_FILE_BROKEN); break; } @@ -582,12 +579,12 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str // lookup currpetid and match to new inserted pet id std::map :: const_iterator petids_iter = petids.find(atoi(currpetid)); if(petids_iter == petids.end()) // couldn't find new inserted id - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); snprintf(newpetid, 20, "%d", petids_iter->second); if(!changenth(line, 1, newpetid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); break; } @@ -595,20 +592,20 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str { // id,messageType,stationery,sender,receiver if(!changeGuid(line, 1, mails, objmgr.m_mailid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changenth(line, 5, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); + if(!changenth(line, 5, newguid)) + ROLLBACK(DUMP_FILE_BROKEN); break; } case DTT_MAIL_ITEM: // mail_items { // mail_id,item_guid,item_template,receiver if(!changeGuid(line, 1, mails, objmgr.m_mailid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) - ROLLBACK(DUMP_FILE_BROKEN); - if(!changenth(line, 4, newguid)) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); + if(!changeGuid(line, 2, items, objmgr.m_hiItemGuid)) + ROLLBACK(DUMP_FILE_BROKEN); + if(!changenth(line, 4, newguid)) + ROLLBACK(DUMP_FILE_BROKEN); break; } default: @@ -617,7 +614,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::string file, uint32 account, std::str } if(!CharacterDatabase.Execute(line.c_str())) - ROLLBACK(DUMP_FILE_BROKEN); + ROLLBACK(DUMP_FILE_BROKEN); } CharacterDatabase.CommitTransaction(); diff --git a/src/game/SpellHandler.cpp b/src/game/SpellHandler.cpp index 3ed9c04a259..0e318eb5ddc 100644 --- a/src/game/SpellHandler.cpp +++ b/src/game/SpellHandler.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -54,6 +54,12 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket) return; } + if(pItem->GetGUID() != item_guid) + { + pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL ); + return; + } + sLog.outDetail("WORLD: CMSG_USE_ITEM packet, bagIndex: %u, slot: %u, spell_count: %u , cast_count: %u, Item: %u, data length = %i", bagIndex, slot, spell_count, cast_count, pItem->GetEntry(), recvPacket.size()); ItemPrototype const *proto = pItem->GetProto(); @@ -237,7 +243,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket) uint32 flags = fields[1].GetUInt32(); pItem->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, 0); - pItem->SetUInt32Value(OBJECT_FIELD_ENTRY, entry); + pItem->SetEntry(entry); pItem->SetUInt32Value(ITEM_FIELD_FLAGS, flags); pItem->SetState(ITEM_CHANGED, pUser); delete result; @@ -259,7 +265,6 @@ void WorldSession::HandleGameObjectUseOpcode( WorldPacket & recv_data ) CHECK_PACKET_SIZE(recv_data,8); uint64 guid; - uint32 spellId = OPEN_CHEST; recv_data >> guid; @@ -322,7 +327,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) } Spell *spell = new Spell(_player, spellInfo, false); - spell->m_cast_count = cast_count; //set count of casts + spell->m_cast_count = cast_count; // set count of casts spell->prepare(&targets); } diff --git a/src/game/WaypointManager.cpp b/src/game/WaypointManager.cpp index d72ac1e266e..a6dda2477ff 100644 --- a/src/game/WaypointManager.cpp +++ b/src/game/WaypointManager.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Database/DatabaseEnv.h" @@ -24,20 +24,30 @@ #include "WaypointManager.h" #include "ProgressBar.h" #include "MapManager.h" +#include "ObjectMgr.h" INSTANTIATE_SINGLETON_1(WaypointManager); bool WaypointBehavior::isEmpty() { - return emote == 0 && spell == 0 && model1 == 0 && model2 == 0 && text[0].empty() && - text[1].empty() && text[2].empty() && text[3].empty() && text[4].empty(); + if (emote || spell || model1 || model2) + return false; + + for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i) + if(textid[i]) + return false; + + return true; } WaypointBehavior::WaypointBehavior(const WaypointBehavior &b) { - emote = b.emote; spell = b.spell; model1 = b.model1; model2 = b.model2; - text[0] = b.text[0]; text[1] = b.text[1]; text[2] = b.text[2]; - text[3] = b.text[3]; text[4] = b.text[4]; + emote = b.emote; + spell = b.spell; + model1 = b.model1; + model2 = b.model2; + for(int i=0; i < MAX_WAYPOINT_TEXT; ++i) + textid[i] = b.textid[i]; } void WaypointManager::Load() @@ -66,7 +76,7 @@ void WaypointManager::Load() delete result; } - result = WorldDatabase.Query("SELECT position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, text1, text2, text3, text4, text5, id, point FROM creature_movement"); + result = WorldDatabase.Query("SELECT position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, id, point FROM creature_movement"); if(result) { barGoLink bar( result->GetRowCount() ); @@ -113,11 +123,33 @@ void WaypointManager::Load() be.model2 = fields[5].GetUInt32(); be.emote = fields[7].GetUInt32(); be.spell = fields[8].GetUInt32(); - be.text[0] = fields[9].GetCppString(); - be.text[1] = fields[10].GetCppString(); - be.text[2] = fields[11].GetCppString(); - be.text[3] = fields[12].GetCppString(); - be.text[4] = fields[13].GetCppString(); + + // load and store without holes in array + int j = 0; + for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i) + { + be.textid[j] = fields[9+i].GetUInt32(); + if(be.textid[j]) + { + if (be.textid[j] < MIN_DB_SCRIPT_STRING_ID || be.textid[j] >= MAX_DB_SCRIPT_STRING_ID) + { + sLog.outErrorDb( "Table `db_script_string` not have string id %u", be.textid[j]); + continue; + } + + if (!objmgr.GetTrinityStringLocale (be.textid[j])) + { + sLog.outErrorDb("ERROR: Waypoint path %d (point %d), have invalid text id (%i) in `textid%d, ignored.", + id, point, be.textid[j], i+1); + continue; + } + + ++j; // to next internal field + } + } + // fill array tail + for(; j < MAX_WAYPOINT_TEXT; ++j) + be.textid[j] = 0; // save memory by not storing empty behaviors if(!be.isEmpty()) @@ -265,11 +297,11 @@ void WaypointManager::SetNodeText(uint32 id, uint32 point, const char *text_fiel WaypointNode &node = itr->second[point-1]; if(!node.behavior) node.behavior = new WaypointBehavior(); - if(field == "text1") node.behavior->text[0] = text ? text : ""; - if(field == "text2") node.behavior->text[1] = text ? text : ""; - if(field == "text3") node.behavior->text[2] = text ? text : ""; - if(field == "text4") node.behavior->text[3] = text ? text : ""; - if(field == "text5") node.behavior->text[4] = text ? text : ""; +// if(field == "text1") node.behavior->text[0] = text ? text : ""; +// if(field == "text2") node.behavior->text[1] = text ? text : ""; +// if(field == "text3") node.behavior->text[2] = text ? text : ""; +// if(field == "text4") node.behavior->text[3] = text ? text : ""; +// if(field == "text5") node.behavior->text[4] = text ? text : ""; if(field == "emote") node.behavior->emote = text ? atoi(text) : 0; if(field == "spell") node.behavior->spell = text ? atoi(text) : 0; if(field == "model1") node.behavior->model1 = text ? atoi(text) : 0; diff --git a/src/game/WaypointManager.h b/src/game/WaypointManager.h index 2fdf5622c2e..75f01cc82f3 100644 --- a/src/game/WaypointManager.h +++ b/src/game/WaypointManager.h @@ -25,11 +25,12 @@ #include #include "Utilities/UnorderedMap.h" +#define MAX_WAYPOINT_TEXT 5 struct WaypointBehavior { uint32 emote; uint32 spell; - std::string text[5]; + int32 textid[MAX_WAYPOINT_TEXT]; uint32 model1; uint32 model2; diff --git a/src/game/WaypointMovementGenerator.cpp b/src/game/WaypointMovementGenerator.cpp index ef3a8a04ef3..7969c375e81 100644 --- a/src/game/WaypointMovementGenerator.cpp +++ b/src/game/WaypointMovementGenerator.cpp @@ -21,11 +21,11 @@ /* creature_movement Table -alter table creature_movement add `text1` varchar(255) default NULL; -alter table creature_movement add `text2` varchar(255) default NULL; -alter table creature_movement add `text3` varchar(255) default NULL; -alter table creature_movement add `text4` varchar(255) default NULL; -alter table creature_movement add `text5` varchar(255) default NULL; +alter table creature_movement add `textid1` int(11) NOT NULL default '0'; +alter table creature_movement add `textid2` int(11) NOT NULL default '0'; +alter table creature_movement add `textid3` int(11) NOT NULL default '0'; +alter table creature_movement add `textid4` int(11) NOT NULL default '0'; +alter table creature_movement add `textid5` int(11) NOT NULL default '0'; alter table creature_movement add `emote` int(10) unsigned default '0'; alter table creature_movement add `spell` int(5) unsigned default '0'; alter table creature_movement add `wpguid` int(11) default '0'; @@ -148,22 +148,21 @@ WaypointMovementGenerator::Update(Creature &creature, const uint32 &di creature.CastSpell(&creature,behavior->spell, false); if(behavior->model1 != 0) creature.SetDisplayId(behavior->model1); - if(!behavior->text[0].empty()) + if(behavior->textid[0]) { - // Only one text is set - if( !behavior->text[1].empty() ) + // Not only one text is set + if( behavior->textid[1] ) { // Select one from max 5 texts (0 and 1 already checked) int i = 2; - for( ; i < 5; ++i ) - if( behavior->text[i].empty() ) + for( ; i < MAX_WAYPOINT_TEXT; ++i ) + if( !behavior->textid[i] ) break; - creature.Say(behavior->text[rand() % i].c_str(), 0, 0); - + creature.Say(behavior->textid[rand() % i], 0, 0); } else - creature.Say(behavior->text[0].c_str(), 0, 0); + creature.Say(behavior->textid[0], 0, 0); } } // wpBehaviour found i_hasDone[idx] = true; diff --git a/src/game/World.cpp b/src/game/World.cpp index d6017ac0669..64c2bd49099 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** \file @@ -66,6 +66,7 @@ INSTANTIATE_SINGLETON_1( World ); volatile bool World::m_stopEvent = false; +uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE; volatile uint32 World::m_worldLoopCounter = 0; float World::m_MaxVisibleDistanceForCreature = DEFAULT_VISIBILITY_DISTANCE; @@ -542,7 +543,6 @@ void World::LoadConfigSettings(bool reload) else m_configs[CONFIG_SOCKET_SELECTTIME] = sConfig.GetIntDefault("SocketSelectTime", DEFAULT_SOCKET_SELECT_TIME); - m_configs[CONFIG_GROUP_XP_DISTANCE] = sConfig.GetIntDefault("MaxGroupXPDistance", 74); /// \todo Add MonsterSight and GuarderSight (with meaning) in Trinityd.conf or put them as define m_configs[CONFIG_SIGHT_MONSTER] = sConfig.GetIntDefault("MonsterSight", 50); @@ -605,7 +605,6 @@ void World::LoadConfigSettings(bool reload) m_configs[CONFIG_SKIP_CINEMATICS] = 0; } - if(reload) { uint32 val = sConfig.GetIntDefault("MaxPlayerLevel", 60); @@ -769,8 +768,8 @@ void World::LoadConfigSettings(bool reload) m_configs[CONFIG_THREAT_RADIUS] = sConfig.GetIntDefault("ThreatRadius", 100); - // always use declined names in the Russian client - m_configs[CONFIG_DECLINED_NAMES_USED] = + // always use declined names in the russian client + m_configs[CONFIG_DECLINED_NAMES_USED] = (m_configs[CONFIG_REALM_ZONE] == REALM_ZONE_RUSSIAN) ? true : sConfig.GetBoolDefault("DeclinedNames", false); m_configs[CONFIG_LISTEN_RANGE_SAY] = sConfig.GetIntDefault("ListenRange.Say", 25); @@ -965,6 +964,9 @@ void World::SetInitialWorldSettings() LoadDBCStores(m_dataPath); DetectDBCLang(); + sLog.outString( "Loading Script Names..."); + objmgr.LoadScriptNames(); + sLog.outString( "Loading InstanceTemplate" ); objmgr.LoadInstanceTemplate(); @@ -1080,11 +1082,10 @@ void World::SetInitialWorldSettings() sLog.outString( "Loading Tavern Area Triggers..." ); objmgr.LoadTavernAreaTriggers(); - + sLog.outString( "Loading AreaTrigger script names..." ); objmgr.LoadAreaTriggerScripts(); - sLog.outString( "Loading Graveyard-zone links..."); objmgr.LoadGraveyardZones(); @@ -1164,7 +1165,7 @@ void World::SetInitialWorldSettings() sLog.outString( "Loading Npc Text Id..." ); objmgr.LoadNpcTextId(); // must be after load Creature and NpcText - + sLog.outString( "Loading Npc Options..." ); objmgr.LoadNpcOptions(); @@ -1192,6 +1193,9 @@ void World::SetInitialWorldSettings() objmgr.LoadGameObjectScripts(); // must be after load Creature/Gameobject(Template/Data) objmgr.LoadEventScripts(); // must be after load Creature/Gameobject(Template/Data) + sLog.outString( "Loading Scripts text locales..." ); // must be after Load*Scripts calls + objmgr.LoadDbScriptStrings(); + sLog.outString( "Initializing Scripts..." ); if(!LoadScriptingModule()) exit(1); @@ -1262,6 +1266,7 @@ void World::SetInitialWorldSettings() sLog.outString( "WORLD: World initialized" ); } + void World::DetectDBCLang() { uint32 m_lang_confid = sConfig.GetIntDefault("DBC.Locale", 255); @@ -1462,7 +1467,9 @@ void World::Update(time_t diff) m_timers[WUPDATE_EVENTS].Reset(); } - MapManager::Instance().DoDelayedMovesAndRemoves(); ///- Move all creatures with "delayed move" and remove and delete all objects with "delayed remove" + /// + ///- Move all creatures with "delayed move" and remove and delete all objects with "delayed remove" + MapManager::Instance().DoDelayedMovesAndRemoves(); // update the instance reset times sInstanceSaveManager.Update(); @@ -1582,6 +1589,8 @@ void World::ScriptsProcess() } } + //if(source && !source->IsInWorld()) source = NULL; + Object* target = NULL; if(step.targetGUID) @@ -1609,6 +1618,8 @@ void World::ScriptsProcess() } } + //if(target && !target->IsInWorld()) target = NULL; + switch (step.script->command) { case SCRIPT_COMMAND_TALK: @@ -1636,7 +1647,7 @@ void World::ScriptsProcess() switch(step.script->datalong) { case 0: // Say - ((Creature *)source)->Say(step.script->datatext.c_str(), LANG_UNIVERSAL, unit_target); + ((Creature *)source)->Say(step.script->dataint, LANG_UNIVERSAL, unit_target); break; case 1: // Whisper if(!unit_target) @@ -1644,13 +1655,13 @@ void World::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_TALK attempt to whisper (%u) NULL, skipping.",step.script->datalong); break; } - ((Creature *)source)->Whisper(step.script->datatext.c_str(),unit_target); + ((Creature *)source)->Whisper(step.script->dataint,unit_target); break; case 2: // Yell - ((Creature *)source)->Yell(step.script->datatext.c_str(), LANG_UNIVERSAL, unit_target); + ((Creature *)source)->Yell(step.script->dataint, LANG_UNIVERSAL, unit_target); break; case 3: // Emote text - ((Creature *)source)->TextEmote(step.script->datatext.c_str(), unit_target); + ((Creature *)source)->TextEmote(step.script->dataint, unit_target); break; default: break; // must be already checked at load @@ -1701,7 +1712,7 @@ void World::ScriptsProcess() break; } ((Unit *)source)->SendMonsterMoveWithSpeed(step.script->x, step.script->y, step.script->z, ((Unit *)source)->GetUnitMovementFlags(), step.script->datalong2 ); - MapManager::Instance().GetMap(((Unit *)source)->GetMapId(), ((Unit *)source))->CreatureRelocation(((Creature *)source), step.script->x, step.script->y, step.script->z, 0); + ((Unit *)source)->GetMap()->CreatureRelocation(((Creature *)source), step.script->x, step.script->y, step.script->z, 0); break; case SCRIPT_COMMAND_FLAG_SET: if(!source) @@ -1851,7 +1862,7 @@ void World::ScriptsProcess() go->SetLootState(GO_READY); go->SetRespawnTime(time_to_despawn); //despawn object in ? seconds - MapManager::Instance().GetMap(go->GetMapId(), go)->Add(go); + go->GetMap()->Add(go); break; } case SCRIPT_COMMAND_OPEN_DOOR: @@ -2373,13 +2384,13 @@ void World::_UpdateGameTime() m_gameTime = thisTime; ///- if there is a shutdown timer - if(m_ShutdownTimer > 0 && elapsed > 0) + if(!m_stopEvent && m_ShutdownTimer > 0 && elapsed > 0) { ///- ... and it is overdue, stop the world (set m_stopEvent) if( m_ShutdownTimer <= elapsed ) { if(!(m_ShutdownMask & SHUTDOWN_MASK_IDLE) || GetActiveAndQueuedSessionCount()==0) - m_stopEvent = true; + m_stopEvent = true; // exist code already set else m_ShutdownTimer = 1; // minimum timer value to wait idle state } @@ -2394,15 +2405,20 @@ void World::_UpdateGameTime() } /// Shutdown the server -void World::ShutdownServ(uint32 time, uint32 options) +void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode) { + // ignore if server shutdown at next tick + if(m_stopEvent) + return; + m_ShutdownMask = options; + m_ExitCode = exitcode; ///- If the shutdown time is 0, set m_stopEvent (except if shutdown is 'idle' with remaining sessions) if(time==0) { if(!(options & SHUTDOWN_MASK_IDLE) || GetActiveAndQueuedSessionCount()==0) - m_stopEvent = true; + m_stopEvent = true; // exist code already set else m_ShutdownTimer = 1; //So that the session count is re-evaluated at next world tick } @@ -2447,16 +2463,18 @@ void World::ShutdownMsg(bool show, Player* player) /// Cancel a planned server shutdown void World::ShutdownCancel() { - if(!m_ShutdownTimer) + // nothing cancel or too later + if(!m_ShutdownTimer || m_stopEvent) return; uint32 msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_CANCELLED : SERVER_MSG_SHUTDOWN_CANCELLED; m_ShutdownMask = 0; m_ShutdownTimer = 0; + m_ExitCode = SHUTDOWN_EXIT_CODE; // to default value SendServerMessage(msgid); - DEBUG_LOG("Server %s canceled.",(m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shuttingdown")); + DEBUG_LOG("Server %s cancelled.",(m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shuttingdown")); } /// Send a server message to the user(s) @@ -2501,6 +2519,7 @@ void World::UpdateSessions( time_t diff ) ///- and remove not active sessions from the list if(!itr->second->Update(diff)) // As interval = 0 { + RemoveQueuedPlayer (itr->second); delete itr->second; m_sessions.erase(itr); } diff --git a/src/game/World.h b/src/game/World.h index c1ceb6891a5..50065b360dd 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /// \addtogroup world The World @@ -51,6 +51,13 @@ enum ShutdownMask SHUTDOWN_MASK_IDLE = 2, }; +enum ShutdownExitCode +{ + SHUTDOWN_EXIT_CODE = 0, + ERROR_EXIT_CODE = 1, + RESTART_EXIT_CODE = 2, +}; + /// Timers for different object refresh rates enum WorldTimers { @@ -61,8 +68,7 @@ enum WorldTimers WUPDATE_UPTIME = 4, WUPDATE_CORPSES = 5, WUPDATE_EVENTS = 6, - WUPDATE_COUNT = 7, - + WUPDATE_COUNT = 7 }; /// Configuration elements @@ -105,6 +111,8 @@ enum WorldConfigs CONFIG_INSTANCE_IGNORE_LEVEL, CONFIG_INSTANCE_IGNORE_RAID, CONFIG_BATTLEGROUND_CAST_DESERTER, + CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_ENABLE, + CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY, CONFIG_INSTANCE_RESET_TIME_HOUR, CONFIG_INSTANCE_UNLOAD_DELAY, CONFIG_CAST_UNSTUCK, @@ -143,6 +151,7 @@ enum WorldConfigs CONFIG_WORLD_BOSS_LEVEL_DIFF, CONFIG_QUEST_LOW_LEVEL_HIDE_DIFF, CONFIG_QUEST_HIGH_LEVEL_HIDE_DIFF, + CONFIG_DETECT_POS_COLLISION, CONFIG_RESTRICTED_LFG_CHANNEL, CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL, CONFIG_TALENTS_INSPECTING, @@ -316,27 +325,26 @@ enum RealmZone /// Storage class for commands issued for delayed execution struct CliCommandHolder { - typedef void Print(const char*); + typedef void Print(const char*); - char *m_command; - Print* m_print; + char *m_command; + Print* m_print; - CliCommandHolder(const char *command, Print* zprint) - : m_print(zprint) - { - size_t len = strlen(command)+1; - m_command = new char[len]; - memcpy(m_command, command, len); - } + CliCommandHolder(const char *command, Print* zprint) + : m_print(zprint) + { + size_t len = strlen(command)+1; + m_command = new char[len]; + memcpy(m_command, command, len); + } - ~CliCommandHolder() { delete[] m_command; } + ~CliCommandHolder() { delete[] m_command; } }; /// The World class World { public: - static volatile bool m_stopEvent; static volatile uint32 m_worldLoopCounter; World(); @@ -344,7 +352,6 @@ class World WorldSession* FindSession(uint32 id) const; void AddSession(WorldSession *s); - bool RemoveSession(uint32 id); /// Get the number of current active sessions void UpdateMaxSessionCounters(); @@ -407,18 +414,20 @@ class World void SetInitialWorldSettings(); void LoadConfigSettings(bool reload = false); - void SendWorldText(int32 string_id, ...); + void SendWorldText(int32 string_id, ...); void SendGlobalMessage(WorldPacket *packet, WorldSession *self = 0, uint32 team = 0); void SendZoneMessage(uint32 zone, WorldPacket *packet, WorldSession *self = 0, uint32 team = 0); void SendZoneText(uint32 zone, const char *text, WorldSession *self = 0, uint32 team = 0); void SendServerMessage(uint32 type, const char *text = "", Player* player = NULL); /// Are we in the middle of a shutdown? - uint32 GetShutdownMask() const { return m_ShutdownMask; } bool IsShutdowning() const { return m_ShutdownTimer > 0; } - void ShutdownServ(uint32 time, uint32 options = 0); + void ShutdownServ(uint32 time, uint32 options, uint8 exitcode); void ShutdownCancel(); void ShutdownMsg(bool show = false, Player* player = NULL); + static uint8 GetExitCode() { return m_ExitCode; } + static void StopNow(uint8 exitcode) { m_stopEvent = true; m_ExitCode = exitcode; } + static bool IsStopped() { return m_stopEvent; } void Update(time_t diff); @@ -453,7 +462,7 @@ class World void KickAllLess(AccountTypes sec); void KickAllQueued(); BanReturn BanAccount(BanMode mode, std::string nameOrIP, std::string duration, std::string reason, std::string author); - bool RemoveBanAccount(BanMode mode, std::string nameOrIP); + bool RemoveBanAccount(BanMode mode, std::string nameOrIP); void ScriptsStart(std::map > const& scripts, uint32 id, Object* source, Object* target); void ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target); @@ -481,13 +490,13 @@ class World LocaleConstant GetAvailableDbcLocale(LocaleConstant locale) const { if(m_availableDbcLocaleMask & (1 << locale)) return locale; else return m_defaultDbcLocale; } - //used World DB version - void LoadDBVersion(); - char const* GetDBVersion() { return m_DBVersion.c_str(); } + //used World DB version + void LoadDBVersion(); + char const* GetDBVersion() { return m_DBVersion.c_str(); } - //used Script version - void SetScriptsVersion(char const* version) { m_ScriptsVersion = version ? version : "unknown scripting library"; } - char const* GetScriptsVersion() { return m_ScriptsVersion.c_str(); } + //used Script version + void SetScriptsVersion(char const* version) { m_ScriptsVersion = version ? version : "unknown scripting library"; } + char const* GetScriptsVersion() { return m_ScriptsVersion.c_str(); } protected: void _UpdateGameTime(); @@ -498,6 +507,11 @@ class World void InitDailyQuestResetTime(); void ResetDailyQuests(); private: + static volatile bool m_stopEvent; + static uint8 m_ExitCode; + uint32 m_ShutdownTimer; + uint32 m_ShutdownMask; + time_t m_startTime; time_t m_gameTime; IntervalTimer m_timers[WUPDATE_COUNT]; @@ -525,9 +539,6 @@ class World std::string m_dataPath; std::set m_forbiddenMapIds; - uint32 m_ShutdownTimer; - uint32 m_ShutdownMask; - // for max speed access static float m_MaxVisibleDistanceForCreature; static float m_MaxVisibleDistanceForPlayer; @@ -545,14 +556,14 @@ class World //Player Queue Queue m_QueuedPlayer; - + //sessions that are added async void AddSession_(WorldSession* s); ZThread::LockedQueue addSessQueue; - //used versions - std::string m_DBVersion; - std::string m_ScriptsVersion; + //used versions + std::string m_DBVersion; + std::string m_ScriptsVersion; }; extern uint32 realmID; diff --git a/src/shared/Database/DBCEnums.h b/src/shared/Database/DBCEnums.h new file mode 100644 index 00000000000..6ad7fdb127a --- /dev/null +++ b/src/shared/Database/DBCEnums.h @@ -0,0 +1,104 @@ +/* +* Copyright (C) 2005-2008 MaNGOS +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef DBCENUMS_H +#define DBCENUMS_H + +enum AreaTeams +{ + AREATEAM_NONE = 0, + AREATEAM_ALLY = 2, + AREATEAM_HORDE = 4 +}; + +enum AreaFlags +{ + AREA_FLAG_SNOW = 0x00000001, // snow (only Dun Morogh, Naxxramas, Razorfen Downs and Winterspring) + AREA_FLAG_UNK1 = 0x00000002, // unknown, (only Naxxramas and Razorfen Downs) + AREA_FLAG_UNK2 = 0x00000004, // Only used on development map + AREA_FLAG_SLAVE_CAPITAL = 0x00000008, // slave capital city flag? + AREA_FLAG_UNK3 = 0x00000010, // unknown + AREA_FLAG_SLAVE_CAPITAL2 = 0x00000020, // slave capital city flag? + AREA_FLAG_UNK4 = 0x00000040, // many zones have this flag + AREA_FLAG_ARENA = 0x00000080, // arena, both instanced and world arenas + AREA_FLAG_CAPITAL = 0x00000100, // main capital city flag + AREA_FLAG_CITY = 0x00000200, // only for one zone named "City" (where it located?) + AREA_FLAG_OUTLAND = 0x00000400, // outland zones? (only Eye of the Storm not have this flag, but have 0x00004000 flag) + AREA_FLAG_SANCTUARY = 0x00000800, // sanctuary area (PvP disabled) + AREA_FLAG_NEED_FLY = 0x00001000, // only Netherwing Ledge, Socrethar's Seat, Tempest Keep, The Arcatraz, The Botanica, The Mechanar, Sorrow Wing Point, Dragonspine Ridge, Netherwing Mines, Dragonmaw Base Camp, Dragonmaw Skyway + AREA_FLAG_UNUSED1 = 0x00002000, // not used now (no area/zones with this flag set in 2.4.2) + AREA_FLAG_OUTLAND2 = 0x00004000, // outland zones? (only Circle of Blood Arena not have this flag, but have 0x00000400 flag) + AREA_FLAG_PVP = 0x00008000, // pvp objective area? (Death's Door also has this flag although it's no pvp object area) + AREA_FLAG_ARENA_INSTANCE = 0x00010000, // used by instanced arenas only + AREA_FLAG_UNUSED2 = 0x00020000, // not used now (no area/zones with this flag set in 2.4.2) + AREA_FLAG_UNK5 = 0x00040000, // just used for Amani Pass, Hatchet Hills + AREA_FLAG_LOWLEVEL = 0x00100000 // used for some starting areas with area_level <=15 +}; + +enum FactionTemplateFlags +{ + FACTION_TEMPLATE_FLAG_CONTESTED_GUARD = 0x00001000, // faction will attack players that were involved in PvP combats +}; + +enum FactionMasks +{ + FACTION_MASK_PLAYER = 1, // any player + FACTION_MASK_ALLIANCE = 2, // player or creature from alliance team + FACTION_MASK_HORDE = 4, // player or creature from horde team + FACTION_MASK_MONSTER = 8 // aggressive creature from monster team + // if none flags set then non-aggressive creature +}; + +enum MapTypes +{ + MAP_COMMON = 0, + MAP_INSTANCE = 1, + MAP_RAID = 2, + MAP_BATTLEGROUND = 3, + MAP_ARENA = 4 +}; + +enum AbilytyLearnType +{ + ABILITY_LEARNED_ON_GET_PROFESSION_SKILL = 1, + ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL = 2 +}; + +enum ItemEnchantmentType +{ + ITEM_ENCHANTMENT_TYPE_NONE = 0, + ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL = 1, + ITEM_ENCHANTMENT_TYPE_DAMAGE = 2, + ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL = 3, + ITEM_ENCHANTMENT_TYPE_RESISTANCE = 4, + ITEM_ENCHANTMENT_TYPE_STAT = 5, + ITEM_ENCHANTMENT_TYPE_TOTEM = 6 +}; + +enum TotemCategoryType +{ + TOTEM_CATEGORY_TYPE_KNIFE = 1, + TOTEM_CATEGORY_TYPE_TOTEM = 2, + TOTEM_CATEGORY_TYPE_ROD = 3, + TOTEM_CATEGORY_TYPE_PICK = 21, + TOTEM_CATEGORY_TYPE_STONE = 22, + TOTEM_CATEGORY_TYPE_HAMMER = 23, + TOTEM_CATEGORY_TYPE_SPANNER = 24 +}; + +#endif diff --git a/src/shared/Database/DBCStores.cpp b/src/shared/Database/DBCStores.cpp index 020cd53e61d..71e3483a1ab 100644 --- a/src/shared/Database/DBCStores.cpp +++ b/src/shared/Database/DBCStores.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "DBCStores.h" @@ -121,21 +121,9 @@ DBCStorage sTaxiPathStore(TaxiPathEntryfmt); // DBC used only for initialization sTaxiPathSetBySource at startup. TaxiPathNodesByPath sTaxiPathNodesByPath; -struct TaxiPathNodeEntry -{ - uint32 path; - uint32 index; - uint32 mapid; - float x; - float y; - float z; - uint32 actionFlag; - uint32 delay; -}; -static DBCStorage sTaxiPathNodeStore(TaxiPathNodeEntryfmt); +static DBCStorage sTaxiPathNodeStore(TaxiPathNodeEntryfmt); DBCStorage sTotemCategoryStore(TotemCategoryEntryfmt); - DBCStorage sWorldMapAreaStore(WorldMapAreaEntryfmt); DBCStorage sWorldSafeLocsStore(WorldSafeLocsEntryfmt); @@ -235,7 +223,7 @@ void LoadDBCStores(std::string dataPath) flist.push_back(i); } } - + LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc"); @@ -283,21 +271,21 @@ void LoadDBCStores(std::string dataPath) for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) { SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j); - + if(!skillLine) continue; SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId); if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0) - { + { for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i) { CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i); if(!cFamily) continue; - if(skillLine->skillId != cFamily->skillLine && skillLine->skillId != cFamily->skillLine2) + if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1]) continue; sPetFamilySpellsStore[i].insert(spellInfo->Id); @@ -309,7 +297,6 @@ void LoadDBCStores(std::string dataPath) LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore, dbcPath,"SpellFocusObject.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore, dbcPath,"SpellRadius.dbc"); LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc"); @@ -455,11 +442,11 @@ void LoadDBCStores(std::string dataPath) // check at up-to-date DBC files (2425 is last item extended cost added in 2.4.3) // check at up-to-date DBC files (71 is last char title added in 2.4.3) // check at up-to-date DBC files (1768 is last area added in 2.4.3) - if( !sSpellStore.LookupEntry(53085) || - !sSkillLineAbilityStore.LookupEntry(17514) || + if( !sSpellStore.LookupEntry(53085) || + !sSkillLineAbilityStore.LookupEntry(17514) || !sMapStore.LookupEntry(598) || - !sGemPropertiesStore.LookupEntry(1127) || - !sItemExtendedCostStore.LookupEntry(2425) || + !sGemPropertiesStore.LookupEntry(1127) || + !sItemExtendedCostStore.LookupEntry(2425) || !sCharTitlesStore.LookupEntry(71) || !sAreaStore.LookupEntry(1768) ) { diff --git a/src/shared/Database/DBCStores.h b/src/shared/Database/DBCStores.h index 2c17935d9f5..0375f20c7eb 100644 --- a/src/shared/Database/DBCStores.h +++ b/src/shared/Database/DBCStores.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DBCSTORES_H @@ -75,7 +75,6 @@ class DBCStorage bool Load(char const* fn) { - DBCFile dbc; // Check if load was sucessful, only then continue if(!dbc.Load(fn, fmt)) diff --git a/src/shared/Database/DBCStructure.h b/src/shared/Database/DBCStructure.h index b57b031ef55..a71f80ac8c7 100644 --- a/src/shared/Database/DBCStructure.h +++ b/src/shared/Database/DBCStructure.h @@ -10,17 +10,18 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DBCSTRUCTURE_H #define DBCSTRUCTURE_H +#include "DBCEnums.h" #include "Platform/Define.h" #include @@ -36,42 +37,6 @@ #pragma pack(push,1) #endif -enum AreaTeams -{ - AREATEAM_NONE = 0, - AREATEAM_ALLY = 2, - AREATEAM_HORDE = 4 -}; - -enum AreaFlags -{ - AREA_FLAG_SNOW = 0x00000001, // snow (only Dun Morogh, Naxxramas, Razorfen Downs and Winterspring) - AREA_FLAG_UNK1 = 0x00000002, // unknown, (only Naxxramas and Razorfen Downs) - AREA_FLAG_UNK2 = 0x00000004, // Only used on development map - AREA_FLAG_SLAVE_CAPITAL = 0x00000008, // slave capital city flag? - AREA_FLAG_UNK3 = 0x00000010, // unknown - AREA_FLAG_SLAVE_CAPITAL2 = 0x00000020, // slave capital city flag? - AREA_FLAG_UNK4 = 0x00000040, // many zones have this flag - AREA_FLAG_ARENA = 0x00000080, // arena, both instanced and world arenas - AREA_FLAG_CAPITAL = 0x00000100, // main capital city flag - AREA_FLAG_CITY = 0x00000200, // only for one zone named "City" (where it located?) - AREA_FLAG_OUTLAND = 0x00000400, // outland zones? (only Eye of the Storm not have this flag, but have 0x00004000 flag) - AREA_FLAG_SANCTUARY = 0x00000800, // sanctuary area (PvP disabled) - AREA_FLAG_NEED_FLY = 0x00001000, // only Netherwing Ledge, Socrethar's Seat, Tempest Keep, The Arcatraz, The Botanica, The Mechanar, Sorrow Wing Point, Dragonspine Ridge, Netherwing Mines, Dragonmaw Base Camp, Dragonmaw Skyway - AREA_FLAG_UNUSED1 = 0x00002000, // not used now (no area/zones with this flag set in 2.4.2) - AREA_FLAG_OUTLAND2 = 0x00004000, // outland zones? (only Circle of Blood Arena not have this flag, but have 0x00000400 flag) - AREA_FLAG_PVP = 0x00008000, // pvp objective area? (Death's Door also has this flag although it's no pvp object area) - AREA_FLAG_ARENA_INSTANCE = 0x00010000, // used by instanced arenas only - AREA_FLAG_UNUSED2 = 0x00020000, // not used now (no area/zones with this flag set in 2.4.2) - AREA_FLAG_UNK5 = 0x00040000, // just used for Amani Pass, Hatchet Hills - AREA_FLAG_LOWLEVEL = 0x00100000 // used for some starting areas with area_level <=15 -}; - -enum FactionTemplateFlags -{ - FACTION_TEMPLATE_FLAG_CONTESTED_GUARD = 0x00001000, // faction will attack players that were involved in PvP combats -}; - struct AreaTableEntry { uint32 ID; // 0 @@ -179,7 +144,7 @@ struct ChrRacesEntry //char* string2[16]; // 48-63 used for DBC language detection/selection // 64 string flags, unused // 65-67 unused - uint32 addon; // 68 (0 - original race, 1 - tbc addon, ...) + uint32 addon; // 68 (0 - original race, 1 - tbc addon, ...) }; struct CreatureDisplayInfoEntry @@ -193,12 +158,11 @@ struct CreatureDisplayInfoEntry struct CreatureFamilyEntry { uint32 ID; // 0 - float minScale; // 1 - uint32 minScaleLevel; // 2 0/1 + float minScale; // 1 + uint32 minScaleLevel; // 2 0/1 float maxScale; // 3 uint32 maxScaleLevel; // 4 0/60 - uint32 skillLine; // 5 - uint32 skillLine2; // 6 + uint32 skillLine[2]; // 5-6 uint32 petFoodMask; // 7 char* Name[16]; // 8-23 // 24 string flags, unused @@ -244,15 +208,6 @@ struct FactionEntry // 52 string flags, unused }; -enum FactionMasks -{ - FACTION_MASK_PLAYER = 1, // any player - FACTION_MASK_ALLIANCE = 2, // player or creature from alliance team - FACTION_MASK_HORDE = 4, // player or creature from horde team - FACTION_MASK_MONSTER = 8 // aggressive creature from monster team - // if none flags set then non-aggressive creature -}; - struct FactionTemplateEntry { uint32 ID; // 0 @@ -301,6 +256,7 @@ struct GemPropertiesEntry }; #define GT_MAX_LEVEL 100 + struct GtCombatRatingsEntry { float ratio; @@ -431,15 +387,6 @@ struct MailTemplateEntry //char* content[16]; // 18-33 }; -enum MapTypes -{ - MAP_COMMON = 0, - MAP_INSTANCE = 1, - MAP_RAID = 2, - MAP_BATTLEGROUND = 3, - MAP_ARENA = 4 -}; - struct MapEntry { uint32 MapID; // 0 @@ -545,12 +492,6 @@ struct SkillLineEntry uint32 spellIcon; // 37 }; -enum AbilytyLearnType -{ - ABILITY_LEARNED_ON_GET_PROFESSION_SKILL = 1, - ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL = 2 -}; - struct SkillLineAbilityEntry { uint32 id; // 0, INDEX @@ -758,17 +699,6 @@ struct SpellDurationEntry int32 Duration[3]; }; -enum ItemEnchantmentType -{ - ITEM_ENCHANTMENT_TYPE_NONE = 0, - ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL = 1, - ITEM_ENCHANTMENT_TYPE_DAMAGE = 2, - ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL = 3, - ITEM_ENCHANTMENT_TYPE_RESISTANCE = 4, - ITEM_ENCHANTMENT_TYPE_STAT = 5, - ITEM_ENCHANTMENT_TYPE_TOTEM = 6 -}; - struct SpellItemEnchantmentEntry { uint32 ID; // 0 @@ -826,14 +756,6 @@ struct TalentTabEntry //char* internalname; // 22 }; -struct TaxiPathEntry -{ - uint32 ID; - uint32 from; - uint32 to; - uint32 price; -}; - struct TaxiNodesEntry { uint32 ID; // 0 @@ -847,15 +769,24 @@ struct TaxiNodesEntry uint32 alliance_mount_type; // 24 }; -enum TotemCategoryType +struct TaxiPathEntry +{ + uint32 ID; + uint32 from; + uint32 to; + uint32 price; +}; + +struct TaxiPathNodeEntry { - TOTEM_CATEGORY_TYPE_KNIFE = 1, - TOTEM_CATEGORY_TYPE_TOTEM = 2, - TOTEM_CATEGORY_TYPE_ROD = 3, - TOTEM_CATEGORY_TYPE_PICK = 21, - TOTEM_CATEGORY_TYPE_STONE = 22, - TOTEM_CATEGORY_TYPE_HAMMER = 23, - TOTEM_CATEGORY_TYPE_SPANNER = 24 + uint32 path; + uint32 index; + uint32 mapid; + float x; + float y; + float z; + uint32 actionFlag; + uint32 delay; }; struct TotemCategoryEntry diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index b9168cbc416..720e6e3e683 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -10,18 +10,16 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "SQLStorage.h" -#include "ProgressBar.h" -#include "Log.h" -#include "dbcfile.h" +#include "SQLStorageImpl.h" #ifdef DO_POSTGRESQL extern DatabasePostgre WorldDatabase; @@ -29,165 +27,57 @@ extern DatabasePostgre WorldDatabase; extern DatabaseMysql WorldDatabase; #endif -const char CreatureInfofmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis"; +const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis"; +const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiii"; const char CreatureDataAddonInfofmt[]="iiiiiiis"; const char CreatureModelfmt[]="iffbi"; const char CreatureInfoAddonInfofmt[]="iiiiiiis"; const char EquipmentInfofmt[]="iiiiiiiiii"; -const char GameObjectInfofmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis"; -const char ItemPrototypefmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii"; +const char GameObjectInfosrcfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis"; +const char GameObjectInfodstfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiii"; +const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii"; +const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiii"; const char PageTextfmt[]="isi"; const char SpellThreatfmt[]="ii"; -const char InstanceTemplatefmt[]="iiiiiiffffs"; +const char InstanceTemplatesrcfmt[]="iiiiiiffffs"; +const char InstanceTemplatedstfmt[]="iiiiiiffffi"; -SQLStorage sCreatureStorage(CreatureInfofmt,"entry","creature_template"); +SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template"); SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon"); SQLStorage sCreatureModelStorage(CreatureModelfmt,"modelid","creature_model_info"); SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon"); SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template"); -SQLStorage sGOStorage(GameObjectInfofmt,"entry","gameobject_template"); -SQLStorage sItemStorage(ItemPrototypefmt,"entry","item_template"); +SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template"); +SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template"); SQLStorage sPageTextStore(PageTextfmt,"entry","page_text"); SQLStorage sSpellThreatStore(SpellThreatfmt,"entry","spell_threat"); -SQLStorage sInstanceTemplate(InstanceTemplatefmt,"map","instance_template"); +SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map","instance_template"); void SQLStorage::Free () { uint32 offset=0; for(uint32 x=0;xFetch(); - RecordCount=fields[0].GetUInt32(); - delete result; - } - else - RecordCount = 0; - - result = WorldDatabase.PQuery("SELECT * FROM %s",table); - - if(!result) - { - sLog.outError("%s table is empty!\n",table); - RecordCount = 0; - return; - } - - uint32 recordsize=0; - uint32 offset=0; - - if(iNumFields!=result->GetFieldCount()) - { - RecordCount = 0; - sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n",table,iNumFields); - delete result; - exit(1); // Stop server at loading broken or non-compatiable table. - } - - //get struct size - uint32 sc=0; - uint32 bo=0; - uint32 bb=0; - for(uint32 x=0;xFetch(); - bar.step(); - char *p=(char*)&_data[recordsize*count]; - newIndex[fields[0].GetUInt32()]=p; - - offset=0; - for(uint32 x=0;x0); - offset+=sizeof(bool); - break; - case FT_BYTE: - *((char*)(&p[offset]))=(fields[x].GetUInt8()); - offset+=sizeof(char); - break; - case FT_INT: - *((uint32*)(&p[offset]))=fields[x].GetUInt32(); - offset+=sizeof(uint32); - break; - case FT_FLOAT: - *((float*)(&p[offset]))=fields[x].GetFloat(); - offset+=sizeof(float); - break; - case FT_STRING: - char const* tmp = fields[x].GetString(); - char* st; - if(!tmp) - { - st=new char[1]; - *st=0; - } - else - { - uint32 l=strlen(tmp)+1; - st=new char[l]; - memcpy(st,tmp,l); - } - *((char**)(&p[offset]))=st; - offset+=sizeof(char*); - break; - } - ++count; - }while( result->NextRow() ); - - delete result; - - pIndex =newIndex; - MaxEntry=maxi; - data=_data; + SQLStorageLoader loader; + loader.Load(*this); } diff --git a/src/shared/Database/SQLStorage.h b/src/shared/Database/SQLStorage.h index 5131a73fe4d..2d154f4e1ca 100644 --- a/src/shared/Database/SQLStorage.h +++ b/src/shared/Database/SQLStorage.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef SQLSTORAGE_H @@ -26,18 +26,26 @@ class SQLStorage { + template + friend struct SQLStorageLoaderBase; + public: - SQLStorage(const char*fmt,const char * _entry_field,const char * sqlname) + SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname) { - format=fmt; - entry_field = _entry_field; - table=sqlname; - data=NULL; - pIndex=NULL; - iNumFields =strlen(fmt); - MaxEntry = 0; + src_format = fmt; + dst_format = fmt; + init(_entry_field, sqlname); + } + + SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname) + { + src_format = src_fmt; + dst_format = dst_fmt; + init(_entry_field, sqlname); } + + ~SQLStorage() { Free(); @@ -56,15 +64,53 @@ class SQLStorage uint32 RecordCount; uint32 MaxEntry; uint32 iNumFields; + void Load(); void Free(); + private: + void init(const char * _entry_field, const char * sqlname) + { + entry_field = _entry_field; + table=sqlname; + data=NULL; + pIndex=NULL; + iNumFields = strlen(src_format); + MaxEntry = 0; + } + char** pIndex; char *data; - const char *format; + const char *src_format; + const char *dst_format; const char *table; const char *entry_field; //bool HasString; }; + +template +struct SQLStorageLoaderBase +{ + public: + void Load(SQLStorage &storage); + + template + void convert(uint32 field_pos, S src, D &dst); + template + void convert_to_str(uint32 field_pos, S src, char * & dst); + template + void convert_from_str(uint32 field_pos, char * src, D& dst); + void convert_str_to_str(uint32 field_pos, char *src, char *&dst); + + private: + template + void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset); + void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset); +}; + +struct SQLStorageLoader : public SQLStorageLoaderBase +{ +}; + #endif diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h new file mode 100644 index 00000000000..4f10c6eee05 --- /dev/null +++ b/src/shared/Database/SQLStorageImpl.h @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2005-2008 MaNGOS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "ProgressBar.h" +#include "Log.h" +#include "dbcfile.h" + +template +template +void SQLStorageLoaderBase::convert(uint32 field_pos, S src, D &dst) +{ + dst = D(src); +} + +template +void SQLStorageLoaderBase::convert_str_to_str(uint32 field_pos, char *src, char *&dst) +{ + if(!src) + { + dst = new char[1]; + *dst = 0; + } + else + { + uint32 l = strlen(src) + 1; + dst = new char[l]; + memcpy(dst, src, l); + } +} + +template +template +void SQLStorageLoaderBase::convert_to_str(uint32 field_pos, S src, char * & dst) +{ + dst = new char[1]; + *dst = 0; +} + +template +template +void SQLStorageLoaderBase::convert_from_str(uint32 field_pos, char * src, D& dst) +{ + dst = 0; +} + +template +template +void SQLStorageLoaderBase::storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset) +{ + T * subclass = (static_cast(this)); + switch(store.dst_format[x]) + { + case FT_LOGIC: + subclass->convert(x, value, *((bool*)(&p[offset])) ); + offset+=sizeof(bool); + break; + case FT_BYTE: + subclass->convert(x, value, *((char*)(&p[offset])) ); + offset+=sizeof(char); + break; + case FT_INT: + subclass->convert(x, value, *((uint32*)(&p[offset])) ); + offset+=sizeof(uint32); + break; + case FT_FLOAT: + subclass->convert(x, value, *((float*)(&p[offset])) ); + offset+=sizeof(float); + break; + case FT_STRING: + subclass->convert_to_str(x, value, *((char**)(&p[offset])) ); + offset+=sizeof(char*); + break; + } +} + +template +void SQLStorageLoaderBase::storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset) +{ + T * subclass = (static_cast(this)); + switch(store.dst_format[x]) + { + case FT_LOGIC: + subclass->convert_from_str(x, value, *((bool*)(&p[offset])) ); + offset+=sizeof(bool); + break; + case FT_BYTE: + subclass->convert_from_str(x, value, *((char*)(&p[offset])) ); + offset+=sizeof(char); + break; + case FT_INT: + subclass->convert_from_str(x, value, *((uint32*)(&p[offset])) ); + offset+=sizeof(uint32); + break; + case FT_FLOAT: + subclass->convert_from_str(x, value, *((float*)(&p[offset])) ); + offset+=sizeof(float); + break; + case FT_STRING: + subclass->convert_str_to_str(x, value, *((char**)(&p[offset])) ); + offset+=sizeof(char*); + break; + } +} + +template +void SQLStorageLoaderBase::Load(SQLStorage &store) +{ + uint32 maxi; + Field *fields; + QueryResult *result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.entry_field, store.table); + if(!result) + { + sLog.outError("Error loading %s table (not exist?)\n", store.table); + exit(1); // Stop server at loading non exited table or not accessable table + } + + maxi = (*result)[0].GetUInt32()+1; + delete result; + + result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table); + if(result) + { + fields = result->Fetch(); + store.RecordCount = fields[0].GetUInt32(); + delete result; + } + else + store.RecordCount = 0; + + result = WorldDatabase.PQuery("SELECT * FROM %s", store.table); + + if(!result) + { + sLog.outError("%s table is empty!\n", store.table); + store.RecordCount = 0; + return; + } + + uint32 recordsize = 0; + uint32 offset = 0; + + if(store.iNumFields != result->GetFieldCount()) + { + store.RecordCount = 0; + sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n", store.table, store.iNumFields); + delete result; + exit(1); // Stop server at loading broken or non-compatible table. + } + + //get struct size + uint32 sc=0; + uint32 bo=0; + uint32 bb=0; + for(uint32 x=0; x< store.iNumFields; x++) + if(store.dst_format[x]==FT_STRING) + ++sc; + else if (store.dst_format[x]==FT_LOGIC) + ++bo; + else if (store.dst_format[x]==FT_BYTE) + ++bb; + recordsize=(store.iNumFields-sc-bo-bb)*4+sc*sizeof(char*)+bo*sizeof(bool)+bb*sizeof(char); + + char** newIndex=new char*[maxi]; + memset(newIndex,0,maxi*sizeof(char*)); + + char * _data= new char[store.RecordCount *recordsize]; + uint32 count=0; + barGoLink bar( store.RecordCount ); + do + { + fields = result->Fetch(); + bar.step(); + char *p=(char*)&_data[recordsize*count]; + newIndex[fields[0].GetUInt32()]=p; + + offset=0; + for(uint32 x = 0; x < store.iNumFields; x++) + switch(store.src_format[x]) + { + case FT_LOGIC: + storeValue((bool)(fields[x].GetUInt32() > 0), store, p, x, offset); break; + case FT_BYTE: + storeValue((char)fields[x].GetUInt8(), store, p, x, offset); break; + case FT_INT: + storeValue((uint32)fields[x].GetUInt32(), store, p, x, offset); break; + case FT_FLOAT: + storeValue((float)fields[x].GetFloat(), store, p, x, offset); break; + case FT_STRING: + storeValue((char*)fields[x].GetString(), store, p, x, offset); break; + } + ++count; + }while( result->NextRow() ); + + delete result; + + store.pIndex = newIndex; + store.MaxEntry = maxi; + store.data = _data; +} diff --git a/src/shared/Database/dbcfile.cpp b/src/shared/Database/dbcfile.cpp index 07f7b662e73..c6c12a99b8b 100644 --- a/src/shared/Database/dbcfile.cpp +++ b/src/shared/Database/dbcfile.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include diff --git a/src/shared/Database/dbcfile.h b/src/shared/Database/dbcfile.h index cc2f117d6d1..8d0b2e45451 100644 --- a/src/shared/Database/dbcfile.h +++ b/src/shared/Database/dbcfile.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DBCFILE_H diff --git a/src/shared/ProgressBar.cpp b/src/shared/ProgressBar.cpp index 724e749c1d9..f4163a6133e 100644 --- a/src/shared/ProgressBar.cpp +++ b/src/shared/ProgressBar.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "ProgressBar.h" diff --git a/src/shared/ProgressBar.h b/src/shared/ProgressBar.h index de73596dd55..98720c90385 100644 --- a/src/shared/ProgressBar.h +++ b/src/shared/ProgressBar.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef TRINITYCORE_PROGRESSBAR_H #define TRINITYCORE_PROGRESSBAR_H diff --git a/src/trinitycore/CliRunnable.cpp b/src/trinitycore/CliRunnable.cpp index 065a6662a50..0af892819b6 100644 --- a/src/trinitycore/CliRunnable.cpp +++ b/src/trinitycore/CliRunnable.cpp @@ -169,7 +169,7 @@ bool ChatHandler::HandleCharacterDeleteCommand(const char* args) bool ChatHandler::HandleServerExitCommand(const char* args) { SendSysMessage(LANG_COMMAND_EXIT); - World::m_stopEvent = true; + World::StopNow(SHUTDOWN_EXIT_CODE); return true; } @@ -310,14 +310,14 @@ void CliRunnable::run() printf("TC>"); ///- As long as the World is running (no World::m_stopEvent), get the command line and handle it - while (!World::m_stopEvent) + while (!World::IsStopped()) { fflush(stdout); #ifdef linux - while (!kb_hit_return() && !World::m_stopEvent) + while (!kb_hit_return() && !World::IsStopped()) // With this, we limit CLI to 10commands/second usleep(100); - if (World::m_stopEvent) + if (World::IsStopped()) break; #endif char *command_str = fgets(commandbuf,sizeof(commandbuf),stdin); @@ -348,7 +348,7 @@ void CliRunnable::run() } else if (feof(stdin)) { - World::m_stopEvent = true; + World::StopNow(SHUTDOWN_EXIT_CODE); } } diff --git a/src/trinitycore/Master.cpp b/src/trinitycore/Master.cpp index 47a12484151..317a3a31a15 100644 --- a/src/trinitycore/Master.cpp +++ b/src/trinitycore/Master.cpp @@ -77,7 +77,7 @@ public: w_loops = 0; m_lastchange = 0; w_lastchange = 0; - while(!World::m_stopEvent) + while(!World::IsStopped()) { ZThread::Thread::sleep(1000); uint32 curtime = getMSTime(); @@ -172,13 +172,13 @@ public: // if use ra spend time waiting for io, if not use ra ,just sleep if (usera) - while (!World::m_stopEvent) + while (!World::IsStopped()) { h.Select (0, socketSelecttime); checkping (); } else - while (!World::m_stopEvent) + while (!World::IsStopped()) { ZThread::Thread::sleep (static_cast (socketSelecttime / 1000)); checkping (); @@ -323,7 +323,7 @@ int Master::Run() if (sWorldSocketMgr->StartNetwork (wsport, bind_ip.c_str ()) == -1) { sLog.outError ("Failed to start network"); - World::m_stopEvent = true; + World::StopNow(ERROR_EXIT_CODE); // go down and shutdown the server } @@ -394,7 +394,8 @@ int Master::Run() // fixes a memory leak related to detaching threads from the module UnloadScriptingModule(); - return sWorld.GetShutdownMask() & SHUTDOWN_MASK_RESTART ? 2 : 0; + // Exit the process with specified return value + return World::GetExitCode(); } /// Initialize connection to the databases @@ -477,17 +478,18 @@ void Master::clearOnlineAccounts() } /// Handle termination signals -/** Put the World::m_stopEvent to 'true' if a termination signal is caught **/ void Master::_OnSignal(int s) { switch (s) { case SIGINT: + World::StopNow(RESTART_EXIT_CODE); + break; case SIGTERM: #ifdef _WIN32 case SIGBREAK: #endif - World::m_stopEvent = true; + World::StopNow(SHUTDOWN_EXIT_CODE); break; } diff --git a/src/trinitycore/WorldRunnable.cpp b/src/trinitycore/WorldRunnable.cpp index 1a30740ddd9..5592b1d2064 100644 --- a/src/trinitycore/WorldRunnable.cpp +++ b/src/trinitycore/WorldRunnable.cpp @@ -51,7 +51,7 @@ void WorldRunnable::run() uint32 prevSleepTime = 0; // used for balanced full tick time length near WORLD_SLEEP_CONST ///- While we have not World::m_stopEvent, update the world - while (!World::m_stopEvent) + while (!World::IsStopped()) { ++World::m_worldLoopCounter; realCurrTime = getMSTime(); -- cgit v1.2.3 From e5e6ff9f1bb5ae1baeef52d5448a0759e7a7d6d8 Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 20 Nov 2008 17:40:13 -0600 Subject: Some missing changes. This should fix the bug that loading char causes crash. Please do not commit to the other tip (I do not know how to delete it). --HG-- branch : trunk --- src/game/CharacterHandler.cpp | 66 +++++++++++---------- src/game/Pet.cpp | 106 ++++++++++++++++++++++------------ src/game/SharedDefines.h | 2 +- src/shared/Database/DatabaseEnv.h | 4 +- src/shared/Database/DatabaseImpl.h | 4 +- src/shared/Database/DatabaseMysql.cpp | 4 +- src/shared/Database/DatabaseMysql.h | 4 +- src/shared/Database/Field.cpp | 4 +- src/shared/Database/Field.h | 4 +- src/shared/Database/QueryResult.h | 4 +- src/shared/Database/SqlOperations.cpp | 4 +- src/shared/Database/SqlOperations.h | 4 +- 12 files changed, 124 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp index 7a61a33fd4f..42732a17d2b 100644 --- a/src/game/CharacterHandler.cpp +++ b/src/game/CharacterHandler.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Common.h" @@ -64,7 +64,7 @@ bool LoginQueryHolder::Initialize() res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADFROM, "SELECT guid, account, data, name, race, class, position_x, position_y, position_z, map, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, trans_x, trans_y, trans_z, trans_o, transguid, extra_flags, stable_slots, at_login, zone, online, death_expire_time, taxi_path, dungeon_difficulty FROM characters WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADGROUP, "SELECT leaderGuid FROM group_member WHERE memberGuid ='%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADBOUNDINSTANCES, "SELECT id, permanent, map, difficulty, resettime FROM character_instance LEFT JOIN instance ON instance = id WHERE guid = '%u'", GUID_LOPART(m_guid)); - res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS, "SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid)); + res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADAURAS, "SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM character_aura WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSPELLS, "SELECT spell,slot,active,disabled FROM character_spell WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS, "SELECT quest,status,rewarded,explored,timer,mobcount1,mobcount2,mobcount3,mobcount4,itemcount1,itemcount2,itemcount3,itemcount4 FROM character_queststatus WHERE guid = '%u'", GUID_LOPART(m_guid)); res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS,"SELECT quest,time FROM character_queststatus_daily WHERE guid = '%u'", GUID_LOPART(m_guid)); @@ -180,6 +180,7 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) std::string name; uint8 race_,class_; + recv_data >> name; // recheck with known string size @@ -214,6 +215,7 @@ void WorldSession::HandleCharCreateOpcode( WorldPacket & recv_data ) ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(class_); ChrRacesEntry const* raceEntry = sChrRacesStore.LookupEntry(race_); + if( !classEntry || !raceEntry ) { data << (uint8)CHAR_CREATE_FAILED; @@ -607,7 +609,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder) pCurrChar->SetRank(0); } - if (!MapManager::Instance().GetMap(pCurrChar->GetMapId(), pCurrChar)->Add(pCurrChar)) + if (!pCurrChar->GetMap()->Add(pCurrChar)) { AreaTrigger const* at = objmgr.GetGoBackTrigger(pCurrChar->GetMapId()); if(at) @@ -999,35 +1001,35 @@ void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data) { uint64 guid; - CHECK_PACKET_SIZE(recv_data, 8+6); + CHECK_PACKET_SIZE(recv_data, 8); recv_data >> guid; // not accept declined names for unsupported languages std::string name; - if(!objmgr.GetPlayerNameByGUID(guid,name)) + if(!objmgr.GetPlayerNameByGUID(guid, name)) { - WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); - data << (uint32)1; - data << guid; + WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8); + data << uint32(1); + data << uint64(guid); SendPacket(&data); return; } std::wstring wname; - if(!Utf8toWStr(name,wname)) + if(!Utf8toWStr(name, wname)) { - WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); - data << (uint32)1; - data << guid; + WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8); + data << uint32(1); + data << uint64(guid); SendPacket(&data); return; } if(!isCyrillicCharacter(wname[0])) // name already stored as only single alphabet using { - WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); - data << (uint32)1; - data << guid; + WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8); + data << uint32(1); + data << uint64(guid); SendPacket(&data); return; } @@ -1035,35 +1037,37 @@ void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data) std::string name2; DeclinedName declinedname; + CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1); recv_data >> name2; - if(name2!=name) // character have different name + if(name2 != name) // character have different name { - WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); - data << (uint32)1; - data << guid; + WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8); + data << uint32(1); + data << uint64(guid); SendPacket(&data); return; } for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) { + CHECK_PACKET_SIZE(recv_data, recv_data.rpos() + 1); recv_data >> declinedname.name[i]; if(!normalizePlayerName(declinedname.name[i])) { - WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); - data << (uint32)1; - data << guid; + WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8); + data << uint32(1); + data << uint64(guid); SendPacket(&data); return; } } - if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname,0),declinedname)) + if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname, 0), declinedname)) { - WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); - data << (uint32)1; - data << guid; + WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8); + data << uint32(1); + data << uint64(guid); SendPacket(&data); return; } @@ -1074,11 +1078,11 @@ void WorldSession::HandleDeclinedPlayerNameOpcode(WorldPacket& recv_data) CharacterDatabase.BeginTransaction(); CharacterDatabase.PExecute("DELETE FROM character_declinedname WHERE guid = '%u'", GUID_LOPART(guid)); CharacterDatabase.PExecute("INSERT INTO character_declinedname (guid, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%s','%s','%s','%s','%s')", - GUID_LOPART(guid), declinedname.name[0].c_str(),declinedname.name[1].c_str(),declinedname.name[2].c_str(),declinedname.name[3].c_str(),declinedname.name[4].c_str()); + GUID_LOPART(guid), declinedname.name[0].c_str(), declinedname.name[1].c_str(), declinedname.name[2].c_str(), declinedname.name[3].c_str(), declinedname.name[4].c_str()); CharacterDatabase.CommitTransaction(); - WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT,4+8); - data << (uint32)0; // OK - data << guid; + WorldPacket data(SMSG_SET_PLAYER_DECLINED_NAMES_RESULT, 4+8); + data << uint32(0); // OK + data << uint64(guid); SendPacket(&data); } diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 9bf67fae2c1..987a106a16d 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -286,6 +286,11 @@ bool Pet::LoadPetFromDB( Unit* owner, uint32 petentry, uint32 petnumber, bool cu m_charmInfo->GetActionBarEntry(index)->Type = atol((*iter).c_str()); ++iter; m_charmInfo->GetActionBarEntry(index)->SpellOrAction = atol((*iter).c_str()); + + // patch for old data where some spells have ACT_DECIDE but should have ACT_CAST + // so overwrite old state + SpellEntry const *spellInfo = sSpellStore.LookupEntry(m_charmInfo->GetActionBarEntry(index)->SpellOrAction); + if (spellInfo && spellInfo->AttributesEx & SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET) m_charmInfo->GetActionBarEntry(index)->Type = ACT_CAST; } //init teach spells @@ -1322,7 +1327,7 @@ void Pet::_LoadAuras(uint32 timediff) for(int i = UNIT_FIELD_AURA; i <= UNIT_FIELD_AURASTATE; ++i) SetUInt32Value(i, 0); - QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); + QueryResult *result = CharacterDatabase.PQuery("SELECT caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); if(result) { @@ -1332,10 +1337,11 @@ void Pet::_LoadAuras(uint32 timediff) uint64 caster_guid = fields[0].GetUInt64(); uint32 spellid = fields[1].GetUInt32(); uint32 effindex = fields[2].GetUInt32(); - int32 damage = (int32)fields[3].GetUInt32(); - int32 maxduration = (int32)fields[4].GetUInt32(); - int32 remaintime = (int32)fields[5].GetUInt32(); - int32 remaincharges = (int32)fields[6].GetUInt32(); + uint32 stackcount= fields[3].GetUInt32(); + int32 damage = (int32)fields[4].GetUInt32(); + int32 maxduration = (int32)fields[5].GetUInt32(); + int32 remaintime = (int32)fields[6].GetUInt32(); + int32 remaincharges = (int32)fields[7].GetUInt32(); SpellEntry const* spellproto = sSpellStore.LookupEntry(spellid); if(!spellproto) @@ -1372,12 +1378,15 @@ void Pet::_LoadAuras(uint32 timediff) if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) continue; - Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); + for(uint32 i=0; iGetModifier()->m_amount; - aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); - AddAura(aura); + if(!damage) + damage = aura->GetModifier()->m_amount; + aura->SetLoadedState(caster_guid,damage,maxduration,remaintime,remaincharges); + AddAura(aura); + } } while( result->NextRow() ); @@ -1390,30 +1399,52 @@ void Pet::_SaveAuras() CharacterDatabase.PExecute("DELETE FROM pet_aura WHERE guid = '%u'",m_charmInfo->GetPetNumber()); AuraMap const& auras = GetAuras(); - for(AuraMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) - { - // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras. - SpellEntry const *spellInfo = itr->second->GetSpellProto(); - uint8 i; - for (i = 0; i < 3; i++) - if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER || - spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET ) - break; + if (auras.empty()) + return; - if (i != 3) - continue; - - if(itr->second->IsPassive()) - continue; + spellEffectPair lastEffectPair = auras.begin()->first; + uint32 stackCounter = 1; - /// do not save single target auras (unless they were cast by the player) - if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)) - continue; + for(AuraMap::const_iterator itr = auras.begin(); ; ++itr) + { + if(itr == auras.end() || lastEffectPair != itr->first) + { + AuraMap::const_iterator itr2 = itr; + // save previous spellEffectPair to db + itr2--; + SpellEntry const *spellInfo = itr2->second->GetSpellProto(); + /// do not save single target auras (unless they were cast by the player) + if (!(itr2->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo))) + { + if(!itr2->second->IsPassive()) + { + // skip all auras from spell that apply at cast SPELL_AURA_MOD_SHAPESHIFT or pet area auras. + uint8 i; + for (i = 0; i < 3; i++) + if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_STEALTH || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_OWNER || + spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PET ) + break; + + if (i == 3) + { + CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges) " + "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%u', '%d', '%d', '%d', '%d')", + m_charmInfo->GetPetNumber(), itr2->second->GetCasterGUID(),(uint32)itr2->second->GetId(), (uint32)itr2->second->GetEffIndex(), stackCounter, itr2->second->GetModifier()->m_amount,int(itr2->second->GetAuraMaxDuration()),int(itr2->second->GetAuraDuration()),int(itr2->second->m_procCharges)); + } + } + } + if(itr == auras.end()) + break; + } - CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " - "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')", - m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); + if (lastEffectPair == itr->first) + stackCounter++; + else + { + lastEffectPair = itr->first; + stackCounter = 1; + } } } @@ -1434,6 +1465,9 @@ bool Pet::addSpell(uint16 spell_id, uint16 active, PetSpellState state, uint16 s return false; } + // same spells don't have autocast option + if (spellInfo->AttributesEx & SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET) active = ACT_CAST; + PetSpellMap::iterator itr = m_spells.find(spell_id); if (itr != m_spells.end()) { @@ -1508,7 +1542,7 @@ bool Pet::addSpell(uint16 spell_id, uint16 active, PetSpellState state, uint16 s if (IsPassiveSpell(spell_id)) CastSpell(this, spell_id, true); else if(state == PETSPELL_NEW) - m_charmInfo->AddSpellToAB(oldspell_id, spell_id); + m_charmInfo->AddSpellToAB(oldspell_id, spell_id, active); if(newspell->active == ACT_ENABLED) ToggleAutocast(spell_id, true); @@ -1658,10 +1692,10 @@ void Pet::ToggleAutocast(uint32 spellid, bool apply) if(IsPassiveSpell(spellid)) return; - if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid)) - if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER - && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE) - return; + //if(const SpellEntry *tempSpell = GetSpellStore()->LookupEntry(spellid)) + // if(tempSpell->EffectImplicitTargetA[0] != TARGET_ALL_AROUND_CASTER + // && tempSpell->EffectImplicitTargetA[0] != TARGET_CHAIN_DAMAGE) + // return; PetSpellMap::const_iterator itr = m_spells.find((uint16)spellid); diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h index 481598f71ea..37dca1aa656 100644 --- a/src/game/SharedDefines.h +++ b/src/game/SharedDefines.h @@ -248,7 +248,7 @@ enum ItemQualities #define SPELL_ATTR_EX_UNK14 0x00004000 // 14 #define SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY 0x00008000 // 15 remove auras on immunity #define SPELL_ATTR_EX_UNAFFECTED_BY_SCHOOL_IMMUNE 0x00010000 // 16 unaffected by school immunity -#define SPELL_ATTR_EX_UNK17 0x00020000 // 17 +#define SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET 0x00020000 // 17 #define SPELL_ATTR_EX_UNK18 0x00040000 // 18 #define SPELL_ATTR_EX_UNK19 0x00080000 // 19 #define SPELL_ATTR_EX_REQ_COMBO_POINTS1 0x00100000 // 20 Req combo points on target diff --git a/src/shared/Database/DatabaseEnv.h b/src/shared/Database/DatabaseEnv.h index 7491464285d..cc09b7611db 100644 --- a/src/shared/Database/DatabaseEnv.h +++ b/src/shared/Database/DatabaseEnv.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #if !defined(DATABASEENV_H) diff --git a/src/shared/Database/DatabaseImpl.h b/src/shared/Database/DatabaseImpl.h index 694ac566db1..175de989d75 100644 --- a/src/shared/Database/DatabaseImpl.h +++ b/src/shared/Database/DatabaseImpl.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Database/Database.h" diff --git a/src/shared/Database/DatabaseMysql.cpp b/src/shared/Database/DatabaseMysql.cpp index 3d9358d9639..d11d29111be 100644 --- a/src/shared/Database/DatabaseMysql.cpp +++ b/src/shared/Database/DatabaseMysql.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DO_POSTGRESQL diff --git a/src/shared/Database/DatabaseMysql.h b/src/shared/Database/DatabaseMysql.h index 83d01758d58..23d1e4c8ff3 100644 --- a/src/shared/Database/DatabaseMysql.h +++ b/src/shared/Database/DatabaseMysql.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef DO_POSTGRESQL diff --git a/src/shared/Database/Field.cpp b/src/shared/Database/Field.cpp index 1c1f9193059..3ec30cdfb64 100644 --- a/src/shared/Database/Field.cpp +++ b/src/shared/Database/Field.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "DatabaseEnv.h" diff --git a/src/shared/Database/Field.h b/src/shared/Database/Field.h index ebfdf04cca3..a81c61e8516 100644 --- a/src/shared/Database/Field.h +++ b/src/shared/Database/Field.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #if !defined(FIELD_H) diff --git a/src/shared/Database/QueryResult.h b/src/shared/Database/QueryResult.h index e3d63c31029..5c26b04a2c0 100644 --- a/src/shared/Database/QueryResult.h +++ b/src/shared/Database/QueryResult.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #if !defined(QUERYRESULT_H) diff --git a/src/shared/Database/SqlOperations.cpp b/src/shared/Database/SqlOperations.cpp index 12eb5585c21..b229b9a5918 100644 --- a/src/shared/Database/SqlOperations.cpp +++ b/src/shared/Database/SqlOperations.cpp @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "SqlOperations.h" diff --git a/src/shared/Database/SqlOperations.h b/src/shared/Database/SqlOperations.h index 7d9ecee6832..a51e48bf929 100644 --- a/src/shared/Database/SqlOperations.h +++ b/src/shared/Database/SqlOperations.h @@ -10,12 +10,12 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __SQLOPERATIONS_H -- cgit v1.2.3 From 182c997573d79be6ee516396a37cd868e6e132bf Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 20 Nov 2008 18:13:10 -0600 Subject: *Re-commit some reverted patch: aura stacking check. By QAston. --HG-- branch : trunk --- src/game/SpellMgr.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++--------- src/game/SpellMgr.h | 7 +++-- src/game/Unit.cpp | 54 +++++++---------------------------- 3 files changed, 81 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 07a0df04450..688514dcb54 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -99,7 +99,7 @@ bool IsPassiveSpell(uint32 spellId) return (spellInfo->Attributes & SPELL_ATTR_PASSIVE) != 0; } -bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) +/*bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) { SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); @@ -113,7 +113,7 @@ bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_ return false; return true; -} +}*/ int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2) { @@ -244,14 +244,24 @@ bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2) case SPELL_STING: case SPELL_CURSE: case SPELL_ASPECT: + case SPELL_POSITIVE_SHOUT: + case SPELL_JUDGEMENT: + case SPELL_WARLOCK_CORRUPTION: + return spellSpec1==spellSpec2; + default: + return false; + } +} + +bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1,uint32 spellSpec2) +{ + switch(spellSpec1) + { case SPELL_TRACKER: case SPELL_WARLOCK_ARMOR: case SPELL_MAGE_ARMOR: case SPELL_ELEMENTAL_SHIELD: case SPELL_MAGE_POLYMORPH: - case SPELL_POSITIVE_SHOUT: - case SPELL_JUDGEMENT: - case SPELL_WARLOCK_CORRUPTION: return spellSpec1==spellSpec2; case SPELL_BATTLE_ELIXIR: return spellSpec2==SPELL_BATTLE_ELIXIR @@ -1030,10 +1040,10 @@ bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo) return true; } -bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const +bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool sameCaster) const { - if(spellId_1 == spellId_2) // auras due to the same spell - return false; + //if(spellId_1 == spellId_2) // auras due to the same spell + // return false; SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1); SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2); @@ -1041,22 +1051,65 @@ bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) cons if(!spellInfo_1 || !spellInfo_2) return false; + SpellSpecific spellId_spec_1 = GetSpellSpecific(spellId_1); + SpellSpecific spellId_spec_2 = GetSpellSpecific(spellId_2); + if (spellId_spec_1 && spellId_spec_2) + if (IsSingleFromSpellSpecificPerTarget(spellId_spec_1, spellId_spec_2) + ||(IsSingleFromSpellSpecificPerCaster(spellId_spec_1, spellId_spec_2) && sameCaster)) + return true; + if(spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName) return false; - if(!spellInfo_1->SpellFamilyName) // generic spells + // generic spells + if(!spellInfo_1->SpellFamilyName) { if(!spellInfo_1->SpellIconID || spellInfo_1->SpellIconID != spellInfo_2->SpellIconID) return false; } - else if (spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags) - return false; + + // if both elixirs are not battle/guardian/potions/flasks then always stack + else if(spellInfo_1->SpellFamilyName == SPELLFAMILY_POTION) + { + if(spellId_spec_1 || spellId_spec_2)) + return false; + } + + // check for class spells + else + { + if (spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags) + return false; + } for(uint32 i = 0; i < 3; ++i) + { if(spellInfo_1->Effect[i] != spellInfo_2->Effect[i] - || spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i]) - return false; + || spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i] + || spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i]) // paladin resist aura + return false; // need itemtype check? need an example to add that check + + if(spellInfo_1->EffectApplyAuraName[i] // both spell has the same auras + && !sameCaster + && spellInfo_1->Effect[i] != SPELL_EFFECT_APPLY_AREA_AURA_PARTY) // not area auras (shaman totem) + // a better check may be effect == SPELL_EFFECT_APPLY_AURA + { + switch(spellInfo_1->EffectApplyAuraName[i]) + { + // DOT or HOT from different casters will stack + case SPELL_AURA_PERIODIC_DAMAGE: + case SPELL_AURA_PERIODIC_HEAL: + case SPELL_AURA_PERIODIC_TRIGGER_SPELL: + case SPELL_AURA_PERIODIC_ENERGIZE: + case SPELL_AURA_PERIODIC_MANA_LEECH: + case SPELL_AURA_PERIODIC_LEECH: + return false; + default: + break; + } + } + } return true; } diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index 7de9c54c6cb..6e3c5c3ddff 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -284,7 +284,7 @@ inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect) return false; } -bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); +//bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); inline bool IsSealSpell(SpellEntry const *spellInfo) { @@ -300,7 +300,8 @@ inline bool IsElementalShield(SpellEntry const *spellInfo) } int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2); -bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2); +bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1, uint32 spellSpec2); +bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1, uint32 spellSpec2); bool IsPassiveSpell(uint32 spellId); inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo) @@ -768,7 +769,7 @@ class SpellMgr bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const; static bool canStackSpellRanks(SpellEntry const *spellInfo); - bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const; + bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool sameCaster) const; SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index a78f1ca2c29..027c9becb6b 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -3895,16 +3895,17 @@ bool Unit::RemoveNoStackAurasDueToAura(Aura *Aur) if(!is_triggered_by_spell) { - SpellSpecific i_spellId_spec = GetSpellSpecific(i_spellId); - - bool is_sspc = IsSingleFromSpellSpecificPerCaster(spellId_spec,i_spellId_spec); - - if( is_sspc && Aur->GetCasterGUID() == (*i).second->GetCasterGUID() ) - { - // cannot remove higher rank - if (spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) - if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) - return false; + bool sameCaster = Aur->GetCasterGUID() == (*i).second->GetCasterGUID(); + if( spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId, sameCaster) ) + { + //some spells should be not removed by lower rank of them + // what is this spell? + if (!sameCaster + &&(spellProto->Effect[effIndex]==SPELL_EFFECT_APPLY_AREA_AURA_PARTY) + &&(spellProto->DurationIndex==21) + &&(spellmgr.IsRankSpellDueToSpell(spellProto, i_spellId)) + &&(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0)) + return false; // Its a parent aura (create this aura in ApplyModifier) if ((*i).second->IsInUse()) @@ -3919,39 +3920,6 @@ bool Unit::RemoveNoStackAurasDueToAura(Aura *Aur) else next = m_Auras.begin(); } - else if( !is_sspc && spellmgr.IsNoStackSpellDueToSpell(spellId, i_spellId) ) - { - // Its a parent aura (create this aura in ApplyModifier) - if ((*i).second->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - RemoveAurasDueToSpell(i_spellId); - - if( m_Auras.empty() ) - break; - else - next = m_Auras.begin(); - } - // Potions stack aura by aura (elixirs/flask already checked) - else if( spellProto->SpellFamilyName == SPELLFAMILY_POTION && i_spellProto->SpellFamilyName == SPELLFAMILY_POTION ) - { - if (IsNoStackAuraDueToAura(spellId, effIndex, i_spellId, i_effIndex)) - { - if(CompareAuraRanks(spellId, effIndex, i_spellId, i_effIndex) < 0) - return false; // cannot remove higher rank - - // Its a parent aura (create this aura in ApplyModifier) - if ((*i).second->IsInUse()) - { - sLog.outError("Aura (Spell %u Effect %u) is in process but attempt removed at aura (Spell %u Effect %u) adding, need add stack rule for Unit::RemoveNoStackAurasDueToAura", i->second->GetId(), i->second->GetEffIndex(),Aur->GetId(), Aur->GetEffIndex()); - continue; - } - RemoveAura(i); - next = i; - } - } } } return true; -- cgit v1.2.3 From 2c95ee4b31962198e3e6803bf56fe604724a2111 Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 20 Nov 2008 18:54:50 -0600 Subject: *Add m_isAggressive. Only aggressive creatures will call AttackStart and MoveInLineOfSight. *Set melee dmg school for summoned creatures. *Fix some compiling errors. --HG-- branch : trunk --- src/game/Creature.cpp | 11 ++++++++--- src/game/Creature.h | 3 +++ src/game/GridNotifiersImpl.h | 6 +++--- src/game/Pet.cpp | 5 +++-- src/game/SpellMgr.cpp | 2 +- src/game/Totem.cpp | 3 +++ src/game/Unit.cpp | 3 ++- 7 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 8a58deb7f91..68b8ab1feae 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -122,7 +122,7 @@ Unit(), i_AI(NULL), i_AI_possessed(NULL), lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0), m_lootMoney(0), m_lootRecipient(0), m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f), -m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false), +m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false), m_isAggressive(true), m_regenTimer(2000), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0), m_AlreadyCallAssistence(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),m_creatureInfo(NULL), m_DBTableGuid(0) @@ -293,6 +293,7 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data ) SetUInt32Value(UNIT_FIELD_FLAGS,GetCreatureInfo()->unit_flags); SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags); + SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool)); SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor)); SetModifierValue(UNIT_MOD_RESISTANCE_HOLY, BASE_VALUE, float(GetCreatureInfo()->resistance1)); SetModifierValue(UNIT_MOD_RESISTANCE_FIRE, BASE_VALUE, float(GetCreatureInfo()->resistance2)); @@ -323,6 +324,12 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data ) if(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER) SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); + if(isTotem() || isCivilian() || GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER + || GetCreatureType() == CREATURE_TYPE_CRITTER) + m_isAggressive = false; + else + m_isAggressive = true; + return true; } @@ -1410,8 +1417,6 @@ bool Creature::LoadFromDB(uint32 guid, Map *map) SetHealth(m_deathState == ALIVE ? curhealth : 0); SetPower(POWER_MANA,data->curmana); - SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool)); - // checked at creature_template loading m_defaultMovementType = MovementGeneratorType(data->movementType); diff --git a/src/game/Creature.h b/src/game/Creature.h index d5b6b23a025..3713465fa79 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -426,6 +426,8 @@ class TRINITY_DLL_SPEC Creature : public Unit bool canWalk() const { return GetCreatureInfo()->InhabitType & INHABIT_GROUND; } bool canSwim() const { return GetCreatureInfo()->InhabitType & INHABIT_WATER; } bool canFly() const { return GetCreatureInfo()->InhabitType & INHABIT_AIR; } + bool isAggressive() const { return m_isAggressive; } + void SetAggressive(bool agg) { m_isAggressive = agg; } ///// TODO RENAME THIS!!!!! bool isCanTrainingOf(Player* player, bool msg) const; bool isCanIneractWithBattleMaster(Player* player, bool msg) const; @@ -636,6 +638,7 @@ class TRINITY_DLL_SPEC Creature : public Unit uint8 m_emoteState; bool m_isPet; // set only in Pet::Pet bool m_isTotem; // set only in Totem::Totem + bool m_isAggressive; void RegenerateMana(); void RegenerateHealth(); uint32 m_regenTimer; diff --git a/src/game/GridNotifiersImpl.h b/src/game/GridNotifiersImpl.h index 80ab442bcd6..41f7cc6c068 100644 --- a/src/game/GridNotifiersImpl.h +++ b/src/game/GridNotifiersImpl.h @@ -72,7 +72,7 @@ inline void PlayerCreatureRelocationWorker(Player* pl, Creature* c) pl->UpdateVisibilityOf(c); // Creature AI reaction - if(!c->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING)) + if(c->isAggressive() && !c->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING)) { if( c->AI() && c->IsWithinSightDist(pl) /*c->AI()->IsVisible(pl)*/ && !c->IsInEvadeMode() ) c->AI()->MoveInLineOfSight(pl); @@ -81,13 +81,13 @@ inline void PlayerCreatureRelocationWorker(Player* pl, Creature* c) inline void CreatureCreatureRelocationWorker(Creature* c1, Creature* c2) { - if(!c1->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING)) + if(c1->isAggressive() && !c1->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING)) { if( c1->AI() && c1->IsWithinSightDist(c2) /*c1->AI()->IsVisible(c2)*/ && !c1->IsInEvadeMode() ) c1->AI()->MoveInLineOfSight(c2); } - if(!c2->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING)) + if(c2->isAggressive() && !c2->hasUnitState(UNIT_STAT_CHASE | UNIT_STAT_SEARCHING | UNIT_STAT_FLEEING)) { if( c2->AI() && c1->IsWithinSightDist(c2) /*c2->AI()->IsVisible(c1)*/ && !c2->IsInEvadeMode() ) c2->AI()->MoveInLineOfSight(c1); diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index 987a106a16d..65d5fd73199 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -1466,7 +1466,8 @@ bool Pet::addSpell(uint16 spell_id, uint16 active, PetSpellState state, uint16 s } // same spells don't have autocast option - if (spellInfo->AttributesEx & SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET) active = ACT_CAST; + if (spellInfo->AttributesEx & SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET) + active = ACT_CAST; PetSpellMap::iterator itr = m_spells.find(spell_id); if (itr != m_spells.end()) @@ -1542,7 +1543,7 @@ bool Pet::addSpell(uint16 spell_id, uint16 active, PetSpellState state, uint16 s if (IsPassiveSpell(spell_id)) CastSpell(this, spell_id, true); else if(state == PETSPELL_NEW) - m_charmInfo->AddSpellToAB(oldspell_id, spell_id, active); + m_charmInfo->AddSpellToAB(oldspell_id, spell_id, (ActiveStates)active); if(newspell->active == ACT_ENABLED) ToggleAutocast(spell_id, true); diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 688514dcb54..98585fceaaf 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -1072,7 +1072,7 @@ bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool // if both elixirs are not battle/guardian/potions/flasks then always stack else if(spellInfo_1->SpellFamilyName == SPELLFAMILY_POTION) { - if(spellId_spec_1 || spellId_spec_2)) + if(spellId_spec_1 || spellId_spec_2) return false; } diff --git a/src/game/Totem.cpp b/src/game/Totem.cpp index 4f8b03827ae..73ae274644e 100644 --- a/src/game/Totem.cpp +++ b/src/game/Totem.cpp @@ -97,6 +97,9 @@ void Totem::Summon(Unit* owner) case TOTEM_STATUE: CastSpell(GetOwner(), GetSpell(), true); break; default: break; } + + if(GetEntry() == SENTRY_TOTEM_ENTRY) + SetAggressive(true); } void Totem::UnSummon() diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 027c9becb6b..c0868ce24f1 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8491,7 +8491,8 @@ void Unit::CombatStart(Unit* target) if(!target->IsStandState() && !target->hasUnitState(UNIT_STAT_STUNNED)) target->SetStandState(PLAYER_STATE_NONE); - if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER && ((Creature*)target)->AI()) + if(!target->isInCombat() && target->GetTypeId() != TYPEID_PLAYER + && ((Creature*)target)->isAggressive() && ((Creature*)target)->AI()) ((Creature*)target)->AI()->AttackStart(this); SetInCombatWith(target); -- cgit v1.2.3 From 5528b7c512ef7968b11ea93a48364a58b629b18b Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 20 Nov 2008 20:28:17 -0600 Subject: *Fix the bug that updatepacket is not sent to players. *TODO: move creature::update to map::update. This requires that move activeobjectlist to map. --HG-- branch : trunk --- src/game/Creature.cpp | 23 +++++++++++++++++++++++ src/game/Creature.h | 1 + src/game/GridNotifiers.h | 36 +++++++++++++++++++++++++++++------- src/game/Map.cpp | 7 ++++--- src/game/ObjectAccessor.cpp | 27 ++++++++++++++++++++++++++- src/game/Unit.cpp | 4 ++-- src/game/Unit.h | 2 +- 7 files changed, 86 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 68b8ab1feae..33d1fd2ea02 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1822,6 +1822,29 @@ void Creature::DoFleeToGetAssistance(float radius) // Optional parameter } } +Unit* Creature::SelectNearestTarget(float dist) const +{ + /*CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + Cell cell(p); + cell.data.Part.reserved = ALL_DISTRICT; + cell.SetNoCreate(); + + Unit *target; + + { + Trinity::NearestHostileUnitInAttackDistanceCheck u_check(this, dist); + Trinity::UnitLastSearcher searcher(target, u_check); + + TypeContainerVisitor, WorldTypeMapContainer > world_unit_searcher(searcher); + TypeContainerVisitor, GridTypeMapContainer > grid_unit_searcher(searcher); + + CellLock cell_lock(cell, p); + cell_lock->Visit(cell_lock, world_unit_searcher, GetMap()); + cell_lock->Visit(cell_lock, grid_unit_searcher, GetMap()); + }*/ + return NULL; +} + void Creature::CallAssistence() { if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed()) diff --git a/src/game/Creature.h b/src/game/Creature.h index 3713465fa79..eb5b2d711f0 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -559,6 +559,7 @@ class TRINITY_DLL_SPEC Creature : public Unit bool IsWithinSightDist(Unit const* u) const; float GetAttackDistance(Unit const* pl) const; + Unit* SelectNearestTarget(float dist = 0) const; void CallAssistence(); void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; } void DoFleeToGetAssistance(float radius = 50); diff --git a/src/game/GridNotifiers.h b/src/game/GridNotifiers.h index 972c209964c..57abea4d5a2 100644 --- a/src/game/GridNotifiers.h +++ b/src/game/GridNotifiers.h @@ -698,19 +698,41 @@ namespace Trinity // Creature checks - class InAttackDistanceFromAnyHostileCreatureCheck + class NearestHostileUnitInAttackDistanceCheck { public: - explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {} - bool operator()(Creature* u) + explicit NearestHostileUnitInAttackDistanceCheck(Creature* creature, float dist = 0) : m_creature(creature) { - if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit))) - return true; + m_range = (dist == 0 ? 9999 : dist); + m_force = (dist == 0 ? false : true); + } + bool operator()(Unit* u) + { + if(!u->isAlive() || !m_creature->IsHostileTo(u)) + return false; - return false; + float dist; + if(m_force) dist = m_range; + else + { + dist = m_creature->GetAttackDistance(u); + if(dist > m_range) dist = m_range; + } + if(!m_creature->IsWithinDistInMap(u, dist)) + return false; + + if(!m_creature->canSeeOrDetect(u, true, false)) + return false; + + m_range = m_creature->GetDistance(u); + return true; } + float GetLastRange() const { return m_range; } private: - Unit* const i_funit; + Creature* const m_creature; + float m_range; + bool m_force; + NearestHostileUnitInAttackDistanceCheck(NearestHostileUnitInAttackDistanceCheck const&); }; class NearestAssistCreatureInCreatureRangeCheck diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 3804560b662..39006c932c6 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -596,7 +596,9 @@ bool Map::loaded(const GridPair &p) const void Map::Update(const uint32 &t_diff) { - resetMarkedCells(); + // TODO: need have an active object list for every map + + /*resetMarkedCells(); Trinity::ObjectUpdater updater(t_diff); // for creature @@ -642,8 +644,7 @@ void Map::Update(const uint32 &t_diff) } } } - } - + }*/ // Don't unload grids if it's battleground, since we may have manually added GOs,creatures, those doesn't load from DB at grid re-load ! // This isn't really bother us, since as soon as we have instanced BG-s, the whole map unloads as the BG gets ended diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index 8a7e8fbfa2c..8d9f3f63fc2 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -503,6 +503,8 @@ ObjectAccessor::Update(uint32 diff) { { + //Player update now in MapManager -> UpdatePlayers + /* // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects. HashMapHolder::MapType& playerMap = HashMapHolder::GetContainer(); for(HashMapHolder::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter) @@ -511,8 +513,9 @@ ObjectAccessor::Update(uint32 diff) { iter->second->Update(diff); } - } + }*/ + // TODO: move this to Map::Update // clone the active object list, because update might remove from it std::set activeobjects(i_activeobjects); @@ -572,6 +575,28 @@ ObjectAccessor::Update(uint32 diff) } } } + + UpdateDataMapType update_players; + { + Guard guard(i_updateGuard); + while(!i_objects.empty()) + { + Object* obj = *i_objects.begin(); + i_objects.erase(i_objects.begin()); + if (!obj) + continue; + _buildUpdateObject(obj, update_players); + obj->ClearUpdateMask(false); + } + } + + WorldPacket packet; // here we allocate a std::vector with a size of 0x10000 + for(UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter) + { + iter->second.BuildPacket(&packet); + iter->first->GetSession()->SendPacket(&packet); + packet.clear(); // clean the string + } } void diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index c0868ce24f1..9a78c50857f 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -10424,7 +10424,7 @@ void Unit::UpdateReactives( uint32 p_time ) } } -Unit* Unit::SelectNearbyTarget() const +Unit* Unit::SelectNearbyTarget(float dist) const { CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); Cell cell(p); @@ -10434,7 +10434,7 @@ Unit* Unit::SelectNearbyTarget() const std::list targets; { - Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); + Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, dist); Trinity::UnitListSearcher searcher(targets, u_check); TypeContainerVisitor, WorldTypeMapContainer > world_unit_searcher(searcher); diff --git a/src/game/Unit.h b/src/game/Unit.h index 4a5dc7e4bb9..cd5770cccd6 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -762,7 +762,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject Unit* getVictim() const { return m_attacking; } void CombatStop(bool cast = false); void CombatStopWithPets(bool cast = false); - Unit* SelectNearbyTarget() const; + Unit* SelectNearbyTarget(float dist = ATTACK_DISTANCE) const; void addUnitState(uint32 f) { m_state |= f; } bool hasUnitState(const uint32 f) const { return (m_state & f); } -- cgit v1.2.3 From 71707df1dec2aa77864d9a853c34108bb6021138 Mon Sep 17 00:00:00 2001 From: megamage Date: Fri, 21 Nov 2008 10:07:11 -0600 Subject: *Let creature search nearby target before enter evade mode *Add function canStartAttack to reduce code in MoveInLineOfSight *Fix a bug that cancelling bind sight auras may crash the server --HG-- branch : trunk --- src/bindings/scripts/include/sc_creature.cpp | 28 +++++++++------------------- src/game/Creature.cpp | 26 ++++++++++++++++++++------ src/game/Creature.h | 1 + src/game/GridNotifiers.h | 23 +++++++++++------------ src/game/SpellHandler.cpp | 3 ++- src/game/Unit.cpp | 10 ++++++++++ 6 files changed, 53 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/bindings/scripts/include/sc_creature.cpp b/src/bindings/scripts/include/sc_creature.cpp index 0c946b8f26d..ca7dc435b09 100644 --- a/src/bindings/scripts/include/sc_creature.cpp +++ b/src/bindings/scripts/include/sc_creature.cpp @@ -73,17 +73,7 @@ bool ScriptedAI::IsVisible(Unit* who) const void ScriptedAI::MoveInLineOfSight(Unit *who) { - if(m_creature->getVictim() || !m_creature->IsHostileTo(who) || !who->isInAccessiblePlaceFor(m_creature)) - return; - - if(!m_creature->canFly() && m_creature->GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE) - return; - - if(!m_creature->IsWithinDistInMap(who, m_creature->GetAttackDistance(who)) || !m_creature->IsWithinLOSInMap(who)) - return; - - if(m_creature->canAttack(who)) - //who->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH); + if(!m_creature->getVictim() && m_creature->canStartAttack(who)) AttackStart(who); } @@ -679,10 +669,10 @@ void ScriptedAI::DoZoneInCombat(Unit* pUnit) return; } - Map::PlayerList const &PlayerList = map->GetPlayers(); - for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) - if (Player* i_pl = i->getSource()) - if (!i_pl->isAlive()) + Map::PlayerList const &PlayerList = map->GetPlayers(); + for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) + if (Player* i_pl = i->getSource()) + if (!i_pl->isAlive()) pUnit->AddThreat(i_pl, 0.0f); } @@ -725,10 +715,10 @@ void ScriptedAI::DoTeleportAll(float x, float y, float z, float o) if (!map->IsDungeon()) return; - Map::PlayerList const &PlayerList = map->GetPlayers(); - for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) - if (Player* i_pl = i->getSource()) - if (!i_pl->isAlive()) + Map::PlayerList const &PlayerList = map->GetPlayers(); + for(Map::PlayerList::const_iterator i = PlayerList.begin(); i != PlayerList.end(); ++i) + if (Player* i_pl = i->getSource()) + if (!i_pl->isAlive()) i_pl->TeleportTo(m_creature->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT); } diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 33d1fd2ea02..91eb04b07f5 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1543,6 +1543,19 @@ bool Creature::IsWithinSightDist(Unit const* u) const return IsWithinDistInMap(u, sWorld.getConfig(CONFIG_SIGHT_MONSTER)); } +bool Creature::canStartAttack(Unit const* who) const +{ + if(!who->isInAccessiblePlaceFor(this) + || !canFly() && GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE + || !IsWithinDistInMap(who, GetAttackDistance(who))) + return false; + + if(!canAttack(who)) + return false; + + return IsWithinLOSInMap(who); +} + float Creature::GetAttackDistance(Unit const* pl) const { float aggroRate = sWorld.getRate(RATE_CREATURE_AGGRO); @@ -1824,12 +1837,12 @@ void Creature::DoFleeToGetAssistance(float radius) // Optional parameter Unit* Creature::SelectNearestTarget(float dist) const { - /*CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); + CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - Unit *target; + Unit *target = NULL; { Trinity::NearestHostileUnitInAttackDistanceCheck u_check(this, dist); @@ -1839,10 +1852,11 @@ Unit* Creature::SelectNearestTarget(float dist) const TypeContainerVisitor, GridTypeMapContainer > grid_unit_searcher(searcher); CellLock cell_lock(cell, p); - cell_lock->Visit(cell_lock, world_unit_searcher, GetMap()); - cell_lock->Visit(cell_lock, grid_unit_searcher, GetMap()); - }*/ - return NULL; + cell_lock->Visit(cell_lock, world_unit_searcher, *GetMap()); + cell_lock->Visit(cell_lock, grid_unit_searcher, *GetMap()); + } + + return target; } void Creature::CallAssistence() diff --git a/src/game/Creature.h b/src/game/Creature.h index eb5b2d711f0..5d0ca5b5946 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -557,6 +557,7 @@ class TRINITY_DLL_SPEC Creature : public Unit bool canSeeOrDetect(Unit const* u, bool detect, bool inVisibleList) const; bool IsWithinSightDist(Unit const* u) const; + bool canStartAttack(Unit const* u) const; float GetAttackDistance(Unit const* pl) const; Unit* SelectNearestTarget(float dist = 0) const; diff --git a/src/game/GridNotifiers.h b/src/game/GridNotifiers.h index 57abea4d5a2..3561f30861c 100644 --- a/src/game/GridNotifiers.h +++ b/src/game/GridNotifiers.h @@ -701,35 +701,34 @@ namespace Trinity class NearestHostileUnitInAttackDistanceCheck { public: - explicit NearestHostileUnitInAttackDistanceCheck(Creature* creature, float dist = 0) : m_creature(creature) + explicit NearestHostileUnitInAttackDistanceCheck(Creature const* creature, float dist = 0) : m_creature(creature) { m_range = (dist == 0 ? 9999 : dist); m_force = (dist == 0 ? false : true); } bool operator()(Unit* u) { - if(!u->isAlive() || !m_creature->IsHostileTo(u)) + // TODO: addthreat for every enemy in range? + if(!m_creature->IsWithinDistInMap(u, m_range)) return false; - float dist; - if(m_force) dist = m_range; + if(m_force) + { + if(!m_creature->canAttack(u)) + return false; + } else { - dist = m_creature->GetAttackDistance(u); - if(dist > m_range) dist = m_range; + if(!m_creature->canStartAttack(u)) + return false; } - if(!m_creature->IsWithinDistInMap(u, dist)) - return false; - - if(!m_creature->canSeeOrDetect(u, true, false)) - return false; m_range = m_creature->GetDistance(u); return true; } float GetLastRange() const { return m_range; } private: - Creature* const m_creature; + Creature const *m_creature; float m_range; bool m_force; NearestHostileUnitInAttackDistanceCheck(NearestHostileUnitInAttackDistanceCheck const&); diff --git a/src/game/SpellHandler.cpp b/src/game/SpellHandler.cpp index 0e318eb5ddc..07d8b18b543 100644 --- a/src/game/SpellHandler.cpp +++ b/src/game/SpellHandler.cpp @@ -368,10 +368,11 @@ void WorldSession::HandleCancelAuraOpcode( WorldPacket& recvPacket) spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_CHARM || spellInfo->EffectApplyAuraName[i] == SPELL_AURA_BIND_SIGHT) { + // Fix me: creature may be killed during player aura cancel _player->RemoveAurasDueToSpellByCancel(spellId); if (_player->GetCharm()) _player->GetCharm()->RemoveAurasDueToSpellByCancel(spellId); - else if (_player->GetFarsightTarget()->GetTypeId() != TYPEID_DYNAMICOBJECT) + else if (_player->GetFarsightTarget() && _player->GetFarsightTarget()->GetTypeId() != TYPEID_DYNAMICOBJECT) ((Unit*)_player->GetFarsightTarget())->RemoveAurasDueToSpellByCancel(spellId); return; } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 9a78c50857f..94f647cdd46 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8542,6 +8542,9 @@ bool Unit::canAttack(Unit const* target) const { assert(target); + if(!IsHostileTo(target)) + return false; + if(!target->isAttackableByAOE() || target->hasUnitState(UNIT_STAT_DIED)) return false; @@ -9126,6 +9129,13 @@ bool Unit::SelectHostilTarget() } } + // search nearby enemy before enter evade mode + if(Unit *target = ((Creature*)this)->SelectNearestTarget()) + { + ((Creature*)this)->AI()->AttackStart(target); + return true; + } + // enter in evade mode in other case ((Creature*)this)->AI()->EnterEvadeMode(); -- cgit v1.2.3