aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AI/CoreAI/PetAI.cpp19
-rw-r--r--src/server/game/Spells/Spell.cpp37
2 files changed, 28 insertions, 28 deletions
diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp
index 66b1253069c..bbf4f4e02ce 100644
--- a/src/server/game/AI/CoreAI/PetAI.cpp
+++ b/src/server/game/AI/CoreAI/PetAI.cpp
@@ -225,26 +225,17 @@ void PetAI::UpdateAI(uint32 diff)
//found units to cast on to
if (!targetSpellStore.empty())
{
- uint32 index = urand(0, targetSpellStore.size() - 1);
+ TargetSpellList::iterator it = targetSpellStore.begin();
+ std::advance(it, urand(0, targetSpellStore.size() - 1));
- Spell* spell = targetSpellStore[index].second;
- Unit* target = targetSpellStore[index].first;
+ Spell* spell = (*it).second;
+ Unit* target = (*it).first;
- targetSpellStore.erase(targetSpellStore.begin() + index);
+ targetSpellStore.erase(it);
SpellCastTargets targets;
targets.SetUnitTarget(target);
- if (!me->HasInArc(float(M_PI), target))
- {
- me->SetInFront(target);
- if (target && target->GetTypeId() == TYPEID_PLAYER)
- me->SendUpdateToPlayer(target->ToPlayer());
-
- if (owner && owner->GetTypeId() == TYPEID_PLAYER)
- me->SendUpdateToPlayer(owner->ToPlayer());
- }
-
spell->prepare(&targets);
}
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 2561ab57ca5..36f54fe17f6 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -5702,27 +5702,36 @@ bool Spell::CanAutoCast(Unit* target)
{
ObjectGuid targetguid = target->GetGUID();
- for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j)
+ // check if target already has the same or a more powerful aura
+ for (uint32 i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
- if (m_spellInfo->Effects[j].Effect == SPELL_EFFECT_APPLY_AURA)
+ if (!GetSpellInfo()->Effects[i].IsAura())
+ continue;
+
+ AuraType const& auraType = AuraType(GetSpellInfo()->Effects[i].ApplyAuraName);
+ Unit::AuraEffectList const& auras = target->GetAuraEffectsByType(auraType);
+ for (Unit::AuraEffectList::const_iterator auraIt = auras.begin(); auraIt != auras.end(); ++auraIt)
{
- if (m_spellInfo->StackAmount <= 1)
+ if (GetSpellInfo()->Id == (*auraIt)->GetSpellInfo()->Id)
+ return false;
+
+ switch (sSpellMgr->CheckSpellGroupStackRules(GetSpellInfo(), (*auraIt)->GetSpellInfo()))
{
- if (target->HasAuraEffect(m_spellInfo->Id, j))
+ case SPELL_GROUP_STACK_RULE_DEFAULT:
+ break;
+ case SPELL_GROUP_STACK_RULE_EXCLUSIVE:
return false;
- }
- else
- {
- if (AuraEffect* aureff = target->GetAuraEffect(m_spellInfo->Id, j))
- if (aureff->GetBase()->GetStackAmount() >= m_spellInfo->StackAmount)
+ case SPELL_GROUP_STACK_RULE_EXCLUSIVE_FROM_SAME_CASTER:
+ if (GetCaster() == (*auraIt)->GetCaster())
+ return false;
+ break;
+ case SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT: // this one has further checks, but i don't think they're necessary for autocast logic
+ case SPELL_GROUP_STACK_RULE_EXCLUSIVE_HIGHEST:
+ if (abs(GetSpellInfo()->Effects[i].BasePoints) <= abs((*auraIt)->GetAmount()))
return false;
+ break;
}
}
- else if (m_spellInfo->Effects[j].IsAreaAuraEffect())
- {
- if (target->HasAuraEffect(m_spellInfo->Id, j))
- return false;
- }
}
SpellCastResult result = CheckPetCast(target);