Skip to content

Instantly share code, notes, and snippets.

@callmephil
Created December 18, 2019 23:08
Show Gist options
  • Save callmephil/8c622d74f9c6e28686fb00da53caeb33 to your computer and use it in GitHub Desktop.
Save callmephil/8c622d74f9c6e28686fb00da53caeb33 to your computer and use it in GitHub Desktop.
spell_generic
class spell_gen_mount : public SpellScriptLoader
{
public:
spell_gen_mount(char const* name, uint32 mount0 = 0, uint32 mount60 = 0, uint32 mount100 = 0, uint32 mount150 = 0, uint32 mount280 = 0, uint32 mount310 = 0) : SpellScriptLoader(name),
_mount0(mount0), _mount60(mount60), _mount100(mount100), _mount150(mount150), _mount280(mount280), _mount310(mount310) { }
class spell_gen_mount_SpellScript : public SpellScript
{
PrepareSpellScript(spell_gen_mount_SpellScript);
public:
spell_gen_mount_SpellScript(uint32 mount0, uint32 mount60, uint32 mount100, uint32 mount150, uint32 mount280, uint32 mount310) : SpellScript(),
_mount0(mount0), _mount60(mount60), _mount100(mount100), _mount150(mount150), _mount280(mount280), _mount310(mount310) { }
private:
bool Validate(SpellInfo const* /*spellInfo*/) override
{
bool result = true;
if (_mount0)
result &= ValidateSpellInfo({ _mount0 });
if (_mount60)
result &= ValidateSpellInfo({ _mount60 });
if (_mount100)
result &= ValidateSpellInfo({ _mount100 });
if (_mount150)
result &= ValidateSpellInfo({ _mount150 });
if (_mount280)
result &= ValidateSpellInfo({ _mount280 });
if (_mount310)
result &= ValidateSpellInfo({ _mount310 });
return result;
}
void HandleMount(SpellEffIndex effIndex)
{
PreventHitDefaultEffect(effIndex);
if (Player* target = GetHitPlayer())
{
// Prevent stacking of mounts and client crashes upon dismounting
target->RemoveAurasByType(SPELL_AURA_MOUNTED, ObjectGuid::Empty, GetHitAura());
// Triggered spell id dependent on riding skill and zone
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(_mount150);
uint32 zoneid, areaid;
target->GetZoneAndAreaId(zoneid, areaid);
bool const canFly = spellInfo && (spellInfo->CheckLocation(target->GetMapId(), zoneid, areaid, target) == SPELL_CAST_OK);
uint32 mount = 0;
switch (target->GetBaseSkillValue(SKILL_RIDING))
{
case 0:
mount = _mount0;
break;
case 75:
mount = _mount60;
break;
case 150:
mount = _mount100;
break;
case 225:
if (canFly)
mount = _mount150;
else
mount = _mount100;
break;
case 300:
if (canFly)
{
if (_mount310 && target->Has310Flyer(false))
mount = _mount310;
else
mount = _mount280;
}
else
mount = _mount100;
break;
default:
break;
}
if (mount)
target->CastSpell(target, mount, true);
}
}
void Register() override
{
OnEffectHitTarget += SpellEffectFn(spell_gen_mount_SpellScript::HandleMount, EFFECT_2, SPELL_EFFECT_SCRIPT_EFFECT);
}
uint32 _mount0;
uint32 _mount60;
uint32 _mount100;
uint32 _mount150;
uint32 _mount280;
uint32 _mount310;
};
SpellScript* GetSpellScript() const override
{
return new spell_gen_mount_SpellScript(_mount0, _mount60, _mount100, _mount150, _mount280, _mount310);
}
private:
uint32 _mount0;
uint32 _mount60;
uint32 _mount100;
uint32 _mount150;
uint32 _mount280;
uint32 _mount310;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment