Skip to content

Commit

Permalink
Script/ToCr: Fix crash for lord jaraxxus Mistress Kiss + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent-Michael committed Jan 30, 2013
1 parent 261e482 commit 8814d8c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,14 @@ class npc_koltira_deathweaver : public CreatureScript
waveTimer -= uiDiff;
}
}

private:
uint8 wave;
uint32 waveTimer;
uint64 valrothGUID;

};

CreatureAI* GetAI(Creature* creature) const
{
return new npc_koltira_deathweaverAI(creature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ enum BossSpells
SPELL_FEL_INFERNO = 67047,
SPELL_FEL_STREAK = 66494,
SPELL_LORD_HITTIN = 66326, // special effect preventing more specific spells be cast on the same player within 10 seconds
SPELL_MISTRESS_KISS_DEBUFF = 66334,
SPELL_MISTRESS_KISS_DAMAGE_SILENCE = 66359
};

Expand Down Expand Up @@ -533,6 +532,21 @@ class spell_mistress_kiss : public SpellScriptLoader
}
};

class MistressKissTargetSelector
{
public:
MistressKissTargetSelector() { }

bool operator()(WorldObject* unit) const
{
if (unit->GetTypeId() == TYPEID_PLAYER)
if (unit->ToPlayer()->getPowerType() == POWER_MANA)
return false;

return true;
}
};

class spell_mistress_kiss_area : public SpellScriptLoader
{
public:
Expand All @@ -542,44 +556,27 @@ class spell_mistress_kiss_area : public SpellScriptLoader
{
PrepareSpellScript(spell_mistress_kiss_area_SpellScript)

bool Load()
void FilterTargets(std::list<WorldObject*>& targets)
{
if (GetCaster())
if (sSpellMgr->GetSpellIdForDifficulty(SPELL_MISTRESS_KISS_DEBUFF, GetCaster()))
return true;
return false;
}
// get a list of players with mana
targets.remove_if(MistressKissTargetSelector());
if (targets.empty())
return;

void HandleScript(SpellEffIndex /*effIndex*/)
{
Unit* caster = GetCaster();
Unit* target = GetHitUnit();
if (caster && target)
caster->CastSpell(target, SPELL_MISTRESS_KISS_DEBUFF, true);
WorldObject* target = Trinity::Containers::SelectRandomContainerElement(targets);
targets.clear();
targets.push_back(target);
}

void FilterTargets(std::list<WorldObject*>& targets)
void HandleScript(SpellEffIndex /*effIndex*/)
{
// get a list of players with mana
std::list<WorldObject*> _targets;
for (std::list<WorldObject*>::iterator itr = targets.begin(); itr != targets.end(); ++itr)
if ((*itr)->ToUnit()->getPowerType() == POWER_MANA)
_targets.push_back(*itr);

// pick a random target and kiss him
if (WorldObject* _target = Trinity::Containers::SelectRandomContainerElement(_targets))
{
// correctly fill "targets" for the visual effect
targets.clear();
targets.push_back(_target);
if (Unit* caster = GetCaster())
caster->CastSpell(_target->ToUnit(), SPELL_MISTRESS_KISS_DEBUFF, true);

This comment has been minimized.

Copy link
@QAston

QAston Jan 31, 2013

Contributor

Doing other things than selecting targets in this hook (FilterTargets) is a bad idea (I'm talking about the code before this fix)

}
GetCaster()->CastSpell(GetHitUnit(), uint32(GetEffectValue()), true);
}

void Register()
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_mistress_kiss_area_SpellScript::FilterTargets, EFFECT_0, TARGET_UNIT_SRC_AREA_ENEMY);
OnEffectHitTarget += SpellEffectFn(spell_mistress_kiss_area_SpellScript::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
}
};

Expand Down

1 comment on commit 8814d8c

@DDuarte
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #9012

Please sign in to comment.