Created
October 24, 2017 17:20
-
-
Save callmephil/d314314f55c5cf18b542ec9ad58e4391 to your computer and use it in GitHub Desktop.
RetroPortedMountFlyingFix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class spell_gen_mount : public SpellScriptLoader | |
{ | |
public: | |
spell_gen_mount(const char* 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) { } | |
bool Validate(SpellInfo const* /*spellInfo*/) override | |
{ | |
if (_mount0 && !sSpellMgr->GetSpellInfo(_mount0)) | |
return false; | |
if (_mount60 && !sSpellMgr->GetSpellInfo(_mount60)) | |
return false; | |
if (_mount100 && !sSpellMgr->GetSpellInfo(_mount100)) | |
return false; | |
if (_mount150 && !sSpellMgr->GetSpellInfo(_mount150)) | |
return false; | |
if (_mount280 && !sSpellMgr->GetSpellInfo(_mount280)) | |
return false; | |
if (_mount310 && !sSpellMgr->GetSpellInfo(_mount310)) | |
return false; | |
return true; | |
} | |
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 | |
bool canFly = false; | |
uint32 map = GetVirtualMapForMapAndZone(target->GetMapId(), target->GetZoneId()); | |
if (map == 530 || (map == 571 && target->HasSpell(SPELL_COLD_WEATHER_FLYING))) | |
canFly = true; | |
AreaTableEntry const* area = sAreaTableStore.LookupEntry(target->GetAreaId()); | |
if (!area || (canFly && (area->flags & AREA_FLAG_NO_FLY_ZONE))) | |
canFly = false; | |
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) | |
{ | |
PreventHitAura(); | |
target->CastSpell(target, mount, true); | |
} | |
} | |
} | |
void Register() override | |
{ | |
OnEffectHitTarget += SpellEffectFn(spell_gen_mount_SpellScript::HandleMount, EFFECT_2, SPELL_EFFECT_SCRIPT_EFFECT); | |
} | |
private: | |
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