// This enumeration helps to create a spell script for all three anti-venoms of the First Aid profession. enum AntiVenomSpellIDs { SPELL_ANTI_VENOM = 7932, SPELL_STRONG_ANTI_VENOM = 7933, SPELL_POWERFUL_ANTI_VENOM = 23786 }; // Item: 6452 - Anti-Venom | Spell: 7932 - Anti-Venom // Item: 6453 - Strong Anti-Venom | Spell: 7933 - Strong Anti-Venom // Item: 19440 - Powerful Anti-Venom | Spell: 23786 - Powerful Anti-Venom class spell_item_anti_venom : public SpellScript { PrepareSpellScript(spell_item_anti_venom); // Only load spell script if the Anti-Venom spell is used by an existing player. bool Load() override { return GetCaster() && GetCaster()->GetTypeId() == TYPEID_PLAYER; } /* Check if target is affected by poisons. - If yes, HandleDummy() will be executed, handling the removal of poisons. - If not, error message "Nothing to dispel" will be shown. */ SpellCastResult CheckForPoison() { Unit* t = GetExplTargetUnit(); if (!t) t = GetCaster(); bool b = false; uint32 maxSLevel; switch (GetSpellInfo()->Id) { case SPELL_ANTI_VENOM: maxSLevel = 25; break; case SPELL_STRONG_ANTI_VENOM: maxSLevel = 35; break; case SPELL_POWERFUL_ANTI_VENOM: maxSLevel = 60; break; default: // should not happen. fail save. maxSLevel = 0; break; } // Iterate through all auras of the player. for (auto itr = t->GetOwnedAuras().begin(); itr != t->GetOwnedAuras().end(); ++itr) { // Second contained item is the actual spell behind the aura. Aura* aura = itr->second; // dMask: dispel mask | sLevel: spell level uint32 dMask = aura->GetSpellInfo()->GetDispelMask(); uint32 sLevel = aura->GetSpellInfo()->SpellLevel; /* If the aura - is removable by effects dispeling poisons and - the spell level is less or equal to the maximum spell level of the poison debuff the anti venom can cure, then ... */ if (dMask == (1 << DISPEL_POISON) && sLevel <= maxSLevel) b = true; // ... remember it for later. } // If no poison debuff aura was found... if (!b) return SPELL_FAILED_NOTHING_TO_DISPEL; // ... return with error message: "Nothing to dispel." else return SPELL_CAST_OK; // ... else, all good. Continue to handle the spell effect with HandleDummy(). } /* The method handling the effect. - Determines the target the Anti-Venom will be used on. - Removes all poisons on the target up to the designated spell level. */ void HandleDummy(SpellEffIndex /*effIndex*/) { // p: Player using the Anti-Venom. | t: Target the Anti-Venom is used on. Unit* p = GetCaster(); Unit* t = GetExplTargetUnit(); // maxSLevel: maximum spell level of the poison debuff the anti venom can cure uint32 maxSLevel; // Anti-Venom used with no target. Set target t to the caster, to use the Anti-Venom on himself. if (!t) t = GetCaster(); /* set maxSLevel according to the anti venom used. Anti-Venom : up to spell level 25. Strong Anti-Venom : up to spell level 35. Powerful Anti-Venom : up to spell level 60. */ switch (GetSpellInfo()->Id) { case SPELL_ANTI_VENOM: maxSLevel = 25; break; case SPELL_STRONG_ANTI_VENOM: maxSLevel = 35; break; case SPELL_POWERFUL_ANTI_VENOM: maxSLevel = 60; break; default: // should not happen. fail save. maxSLevel = 0; break; } // Iterate through all auras of the player. for (auto itr = t->GetOwnedAuras().begin(); itr != t->GetOwnedAuras().end(); ++itr) { // Second contained item is the actual spell behind the aura. Aura* aura = itr->second; // dMask: dispel mask of the aura | sLevel: spell level of the aura uint32 dMask = aura->GetSpellInfo()->GetDispelMask(); uint32 sLevel = aura->GetSpellInfo()->SpellLevel; /* If the aura - is removable by effects dispeling poisons and - the spell level is less or equal to the maximum spell level of the poison debuff the anti venom can cure, then ... */ if (dMask == (1 << DISPEL_POISON) && sLevel <= maxSLevel) t->RemoveAura(aura, AURA_REMOVE_BY_DEFAULT); // ... remove the poison aura. } } void Register() override { OnCheckCast += SpellCheckCastFn(spell_item_anti_venom::CheckForPoison); OnEffectHit += SpellEffectFn(spell_item_anti_venom::HandleDummy, EFFECT_0, SPELL_EFFECT_DUMMY); } }; void AddSC_item_spell_scripts() { RegisterSpellScript(spell_item_anti_venom); }