Skip to content

Commit

Permalink
Core/Spells: more code updates...
Browse files Browse the repository at this point in the history
  • Loading branch information
streetrat committed Nov 22, 2014
1 parent 8518232 commit 926a37a
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 107 deletions.
9 changes: 6 additions & 3 deletions src/server/game/AI/CoreAI/UnitAI.cpp
Expand Up @@ -227,17 +227,20 @@ void UnitAI::FillAISpellInfo()
UPDATE_TARGET(AITARGET_SELF)
else
{
for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j)
for (SpellEffectInfo const* effect: spellInfo->GetEffectsForDifficulty(DIFFICULTY_NONE))

This comment has been minimized.

Copy link
@Subv

Subv Nov 22, 2014

Contributor

Space between effect and :

{
uint32 targetType = spellInfo->Effects[j].TargetA.GetTarget();
if (!effect)
continue;

uint32 targetType = effect->TargetA.GetTarget();

if (targetType == TARGET_UNIT_TARGET_ENEMY
|| targetType == TARGET_DEST_TARGET_ENEMY)
UPDATE_TARGET(AITARGET_VICTIM)
else if (targetType == TARGET_UNIT_DEST_AREA_ENEMY)
UPDATE_TARGET(AITARGET_ENEMY)

if (spellInfo->Effects[j].Effect == SPELL_EFFECT_APPLY_AURA)
if (effect->Effect == SPELL_EFFECT_APPLY_AURA)
{
if (targetType == TARGET_UNIT_TARGET_ENEMY)
UPDATE_TARGET(AITARGET_DEBUFF)
Expand Down
29 changes: 16 additions & 13 deletions src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
Expand Up @@ -823,13 +823,13 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
return false;

SpellInfo const* spellInfo = sSpellMgr->EnsureSpellInfo(e.action.cast.spell);
for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j)
for (SpellEffectInfo const* effect : spellInfo->GetEffectsForDifficulty(DIFFICULTY_NONE))
{
if (spellInfo->Effects[j].IsEffect(SPELL_EFFECT_KILL_CREDIT) || spellInfo->Effects[j].IsEffect(SPELL_EFFECT_KILL_CREDIT2))
if (effect && (effect->IsEffect(SPELL_EFFECT_KILL_CREDIT) || effect->IsEffect(SPELL_EFFECT_KILL_CREDIT2)))
{
if (spellInfo->Effects[j].TargetA.GetTarget() == TARGET_UNIT_CASTER)
if (effect->TargetA.GetTarget() == TARGET_UNIT_CASTER)
TC_LOG_ERROR("sql.sql", "SmartAIMgr: Entry " SI64FMTD " SourceType %u Event %u Action %u Effect: SPELL_EFFECT_KILL_CREDIT: (SpellId: %u targetA: %u - targetB: %u) has invalid target for this Action",
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.cast.spell, spellInfo->Effects[j].TargetA.GetTarget(), spellInfo->Effects[j].TargetB.GetTarget());
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.action.cast.spell, effect->TargetA.GetTarget(), effect->TargetB.GetTarget());
}
}
break;
Expand Down Expand Up @@ -1277,19 +1277,22 @@ void SmartAIMgr::LoadHelperStores()
if (!spellInfo)
continue;

for (uint32 j = 0; j < MAX_SPELL_EFFECTS; ++j)
for (SpellEffectInfo const* effect : spellInfo->GetEffectsForDifficulty(DIFFICULTY_NONE))
{
if (spellInfo->Effects[j].IsEffect(SPELL_EFFECT_SUMMON))
SummonCreatureSpellStore.insert(std::make_pair(uint32(spellInfo->Effects[j].MiscValue), std::make_pair(i, SpellEffIndex(j))));
if (!effect)
continue;

if (effect->IsEffect(SPELL_EFFECT_SUMMON))
SummonCreatureSpellStore.insert(std::make_pair(uint32(effect->MiscValue), std::make_pair(i, SpellEffIndex(effect->EffectIndex))));

else if (spellInfo->Effects[j].IsEffect(SPELL_EFFECT_SUMMON_OBJECT_WILD))
SummonGameObjectSpellStore.insert(std::make_pair(uint32(spellInfo->Effects[j].MiscValue), std::make_pair(i, SpellEffIndex(j))));
else if (effect->IsEffect(SPELL_EFFECT_SUMMON_OBJECT_WILD))
SummonGameObjectSpellStore.insert(std::make_pair(uint32(effect->MiscValue), std::make_pair(i, SpellEffIndex(effect->EffectIndex))));

else if (spellInfo->Effects[j].IsEffect(SPELL_EFFECT_KILL_CREDIT) || spellInfo->Effects[j].IsEffect(SPELL_EFFECT_KILL_CREDIT2))
KillCreditSpellStore.insert(std::make_pair(uint32(spellInfo->Effects[j].MiscValue), std::make_pair(i, SpellEffIndex(j))));
else if (effect->IsEffect(SPELL_EFFECT_KILL_CREDIT) || effect->IsEffect(SPELL_EFFECT_KILL_CREDIT2))
KillCreditSpellStore.insert(std::make_pair(uint32(effect->MiscValue), std::make_pair(i, SpellEffIndex(effect->EffectIndex))));

else if (spellInfo->Effects[j].IsEffect(SPELL_EFFECT_CREATE_ITEM))
CreateItemSpellStore.insert(std::make_pair(uint32(spellInfo->Effects[j].ItemType), std::make_pair(i, SpellEffIndex(j))));
else if (effect->IsEffect(SPELL_EFFECT_CREATE_ITEM))
CreateItemSpellStore.insert(std::make_pair(uint32(effect->ItemType), std::make_pair(i, SpellEffIndex(effect->EffectIndex))));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/server/game/Achievements/AchievementMgr.cpp
Expand Up @@ -138,13 +138,14 @@ bool AchievementCriteriaData::IsValid(AchievementCriteriaEntry const* criteria)
criteria->ID, criteria->type, (dataType == ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA?"ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA":"ACHIEVEMENT_CRITERIA_DATA_TYPE_T_AURA"), dataType, aura.spell_id);
return false;
}
if (aura.effect_idx >= 3)
SpellEffectInfo const* effect = spellEntry->GetEffect(DIFFICULTY_NONE, aura.effect_idx);
if (!effect)
{
TC_LOG_ERROR("sql.sql", "Table `achievement_criteria_data` (Entry: %u Type: %u) for data type %s (%u) has wrong spell effect index in value2 (%u), ignored.",
criteria->ID, criteria->type, (dataType == ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA?"ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA":"ACHIEVEMENT_CRITERIA_DATA_TYPE_T_AURA"), dataType, aura.effect_idx);
return false;
}
if (!spellEntry->Effects[aura.effect_idx].ApplyAuraName)
if (!effect->ApplyAuraName)
{
TC_LOG_ERROR("sql.sql", "Table `achievement_criteria_data` (Entry: %u Type: %u) for data type %s (%u) has non-aura spell effect (ID: %u Effect: %u), ignores.",
criteria->ID, criteria->type, (dataType == ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA?"ACHIEVEMENT_CRITERIA_DATA_TYPE_S_AURA":"ACHIEVEMENT_CRITERIA_DATA_TYPE_T_AURA"), dataType, aura.spell_id, aura.effect_idx);
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Combat/ThreatManager.cpp
Expand Up @@ -41,8 +41,8 @@ float ThreatCalcHelper::calcThreat(Unit* hatedUnit, Unit* /*hatingUnit*/, float
threat *= threatEntry->pctMod;

// Energize is not affected by Mods
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; i++)
if (threatSpell->Effects[i].Effect == SPELL_EFFECT_ENERGIZE || threatSpell->Effects[i].ApplyAuraName == SPELL_AURA_PERIODIC_ENERGIZE)
for (SpellEffectInfo const* effect : threatSpell->GetEffectsForDifficulty(hatedUnit->GetMap()->GetDifficulty()))
if (effect && (effect->Effect == SPELL_EFFECT_ENERGIZE || effect->ApplyAuraName == SPELL_AURA_PERIODIC_ENERGIZE))
return threat;

if (Player* modOwner = hatedUnit->GetSpellModOwner())
Expand Down
30 changes: 24 additions & 6 deletions src/server/game/Conditions/ConditionMgr.cpp
Expand Up @@ -1131,6 +1131,9 @@ bool ConditionMgr::addToSpellImplicitTargetConditions(Condition* cond)
std::list<uint32> sharedMasks;
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
{
SpellEffectInfo const* effect = spellInfo->GetEffect(DIFFICULTY_NONE, i);
if (!effect)
continue;
// check if effect is already a part of some shared mask
bool found = false;
for (std::list<uint32>::iterator itr = sharedMasks.begin(); itr != sharedMasks.end(); ++itr)
Expand All @@ -1146,10 +1149,13 @@ bool ConditionMgr::addToSpellImplicitTargetConditions(Condition* cond)

// build new shared mask with found effect
uint32 sharedMask = (1<<i);
ConditionList* cmp = spellInfo->Effects[i].ImplicitTargetConditions;
ConditionList* cmp = effect->ImplicitTargetConditions;
for (uint8 effIndex = i+1; effIndex < MAX_SPELL_EFFECTS; ++effIndex)
{
if (spellInfo->Effects[effIndex].ImplicitTargetConditions == cmp)
SpellEffectInfo const* inner = spellInfo->GetEffect(DIFFICULTY_NONE, effIndex);
if (!inner)
continue;
if (inner->ImplicitTargetConditions == cmp)
sharedMask |= 1<<effIndex;
}
sharedMasks.push_back(sharedMask);
Expand All @@ -1168,8 +1174,12 @@ bool ConditionMgr::addToSpellImplicitTargetConditions(Condition* cond)
if (firstEffIndex >= MAX_SPELL_EFFECTS)
return false;

SpellEffectInfo const* effect = spellInfo->GetEffect(DIFFICULTY_NONE, firstEffIndex);
if (!effect)
continue;

// get shared data
ConditionList* sharedList = spellInfo->Effects[firstEffIndex].ImplicitTargetConditions;
ConditionList* sharedList = effect->ImplicitTargetConditions;

// there's already data entry for that sharedMask
if (sharedList)
Expand All @@ -1190,9 +1200,13 @@ bool ConditionMgr::addToSpellImplicitTargetConditions(Condition* cond)
bool assigned = false;
for (uint8 i = firstEffIndex; i < MAX_SPELL_EFFECTS; ++i)
{
SpellEffectInfo const* eff = spellInfo->GetEffect(DIFFICULTY_NONE, firstEffIndex);
if (!eff)
continue;

if ((1<<i) & commonMask)
{
spellInfo->Effects[i].ImplicitTargetConditions = sharedList;
const_cast<SpellEffectInfo*>(eff)->ImplicitTargetConditions = sharedList;
assigned = true;
}
}
Expand Down Expand Up @@ -1443,7 +1457,11 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
if (!((1<<i) & cond->SourceGroup))
continue;

switch (spellInfo->Effects[i].TargetA.GetSelectionCategory())
SpellEffectInfo const* effect = spellInfo->GetEffect(DIFFICULTY_NONE, i);
if (!effect)
continue;

switch (effect->TargetA.GetSelectionCategory())
{
case TARGET_SELECT_CATEGORY_NEARBY:
case TARGET_SELECT_CATEGORY_CONE:
Expand All @@ -1453,7 +1471,7 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
break;
}

switch (spellInfo->Effects[i].TargetB.GetSelectionCategory())
switch (effect->TargetB.GetSelectionCategory())
{
case TARGET_SELECT_CATEGORY_NEARBY:
case TARGET_SELECT_CATEGORY_CONE:
Expand Down

0 comments on commit 926a37a

Please sign in to comment.