Core/Units: Added helper methods to cancel mount/shapeshift auras (#30477)

This commit is contained in:
Meji
2024-12-29 00:44:05 +01:00
committed by GitHub
parent 75bc3021da
commit 0b16756172
3 changed files with 53 additions and 1 deletions

View File

@@ -26027,7 +26027,7 @@ void Player::UpdateAreaDependentAuras(uint32 newArea)
{
// use m_zoneUpdateId for speed: UpdateArea called from UpdateZone or instead UpdateZone in both cases m_zoneUpdateId up-to-date
if (iter->second->GetSpellInfo()->CheckLocation(GetMapId(), m_zoneUpdateId, newArea, this) != SPELL_CAST_OK)
RemoveOwnedAura(iter);
RemoveOwnedAura(iter, AURA_REMOVE_BY_INTERRUPT);
else
++iter;
}

View File

@@ -8132,6 +8132,18 @@ void Unit::Dismount()
}
}
void Unit::CancelMountAura(bool force)
{
if (!HasAuraType(SPELL_AURA_MOUNTED))
return;
RemoveAurasByType(SPELL_AURA_MOUNTED, [force](AuraApplication const* aurApp)
{
SpellInfo const* spellInfo = aurApp->GetBase()->GetSpellInfo();
return force || (!spellInfo->HasAttribute(SPELL_ATTR0_NO_AURA_CANCEL) && spellInfo->IsPositive() && !spellInfo->IsPassive());
});
}
MountCapabilityEntry const* Unit::GetMountCapability(uint32 mountType) const
{
if (!mountType)
@@ -8234,6 +8246,11 @@ void Unit::UpdateMountCapability()
if (IsLoading())
return;
if (SpellShapeshiftFormEntry const* spellShapeshiftForm = sSpellShapeshiftFormStore.LookupEntry(GetShapeshiftForm()))
if (uint32 mountType = spellShapeshiftForm->MountTypeID)
if (!GetMountCapability(mountType))
CancelTravelShapeshiftForm(AURA_REMOVE_BY_INTERRUPT);
AuraEffectVector mounts = CopyAuraEffectList(GetAuraEffectsByType(SPELL_AURA_MOUNTED));
for (AuraEffect* aurEff : mounts)
{
@@ -9234,6 +9251,38 @@ void Unit::SetShapeshiftForm(ShapeshiftForm form)
SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::ShapeshiftForm), form);
}
void Unit::CancelShapeshiftForm(bool onlyTravelShapeshiftForm /*= false*/, AuraRemoveMode removeMode /*= AURA_REMOVE_BY_DEFAULT*/, bool force /*= false*/)
{
ShapeshiftForm form = GetShapeshiftForm();
if (form == FORM_NONE)
return;
bool isTravelShapeshiftForm = [form]()
{
if (SpellShapeshiftFormEntry const* shapeInfo = sSpellShapeshiftFormStore.LookupEntry(form))
{
if (shapeInfo->MountTypeID)
return true;
if (shapeInfo->ID == FORM_TRAVEL_FORM || shapeInfo->ID == FORM_AQUATIC_FORM)
return true;
}
return false;
}();
if (onlyTravelShapeshiftForm && !isTravelShapeshiftForm)
return;
AuraEffectVector shapeshifts = CopyAuraEffectList(GetAuraEffectsByType(SPELL_AURA_MOD_SHAPESHIFT));
for (AuraEffect* aurEff : shapeshifts)
{
SpellInfo const* spellInfo = aurEff->GetBase()->GetSpellInfo();
if (force || (!spellInfo->HasAttribute(SPELL_ATTR0_NO_AURA_CANCEL) && spellInfo->IsPositive() && !spellInfo->IsPassive()))
aurEff->GetBase()->Remove(removeMode);
}
}
bool Unit::IsInFeralForm() const
{
ShapeshiftForm form = GetShapeshiftForm();

View File

@@ -910,6 +910,7 @@ class TC_GAME_API Unit : public WorldObject
void SetCosmeticMountDisplayId(uint32 mountDisplayId) { SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::CosmeticMountDisplayID), mountDisplayId); }
void Mount(uint32 mount, uint32 vehicleId = 0, uint32 creatureEntry = 0);
void Dismount();
void CancelMountAura(bool force = false);
MountCapabilityEntry const* GetMountCapability(uint32 mountType) const;
void UpdateMountCapability();
@@ -1479,6 +1480,8 @@ class TC_GAME_API Unit : public WorldObject
ShapeshiftForm GetShapeshiftForm() const { return ShapeshiftForm(*m_unitData->ShapeshiftForm); }
void SetShapeshiftForm(ShapeshiftForm form);
void CancelShapeshiftForm(bool onlyTravelShapeshiftForm = false, AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT, bool force = false);
void CancelTravelShapeshiftForm(AuraRemoveMode removeMode = AURA_REMOVE_BY_DEFAULT, bool force = false) { CancelShapeshiftForm(true, removeMode, force); };
bool IsInFeralForm() const;