[8551] code cleanup

moved arena/battleground check from spell::checkcast
to SpellMgr::GetSpellAllowedInLocationError

also i adjusted some spell_fail-codes related to battleground
cause a spell_fail_wrong_area always requires the areaid, else it
would output "not in area %s"

then we don't need to check for map->isarena() when player is already in an
arena

----
in Spell.h
i moved "isTargetableForAttack()" to the top - cause it was anyway used
in every case of that switch

and isTargetableForAttack for attack also checks for isAlive
and isInFlight

so this could get simplified
This commit is contained in:
balrok 2009-09-21 19:32:44 +02:00
parent 9143f19bef
commit 5385b385bc
4 changed files with 39 additions and 56 deletions

View file

@ -1282,14 +1282,16 @@ void Spell::SetTargetMap(uint32 effIndex,uint32 targetMode,UnitList& TagUnitMap)
else else
radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex)); radius = GetSpellMaxRange(sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex));
if(m_originalCaster)
if(Player* modOwner = m_originalCaster->GetSpellModOwner())
modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius, this);
uint32 EffectChainTarget = m_spellInfo->EffectChainTarget[effIndex]; uint32 EffectChainTarget = m_spellInfo->EffectChainTarget[effIndex];
if(m_originalCaster) if(m_originalCaster)
{
if(Player* modOwner = m_originalCaster->GetSpellModOwner()) if(Player* modOwner = m_originalCaster->GetSpellModOwner())
{
modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RADIUS, radius, this);
modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_JUMP_TARGETS, EffectChainTarget, this); modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_JUMP_TARGETS, EffectChainTarget, this);
}
}
// Get spell max affected targets // Get spell max affected targets
uint32 unMaxTargets = m_spellInfo->MaxAffectedTargets; uint32 unMaxTargets = m_spellInfo->MaxAffectedTargets;
@ -4098,27 +4100,12 @@ SpellCastResult Spell::CheckCast(bool strict)
if (non_caster_target && (m_spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET) && target->isInCombat()) if (non_caster_target && (m_spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET) && target->isInCombat())
return SPELL_FAILED_TARGET_AFFECTING_COMBAT; return SPELL_FAILED_TARGET_AFFECTING_COMBAT;
} }
// Spell casted only on battleground
if ((m_spellInfo->AttributesEx3 & SPELL_ATTR_EX3_BATTLEGROUND) && m_caster->GetTypeId() == TYPEID_PLAYER)
if(!((Player*)m_caster)->InBattleGround())
return SPELL_FAILED_ONLY_BATTLEGROUNDS;
// do not allow spells to be cast in arenas
// - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
// - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
if ((m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA) ||
GetSpellRecoveryTime(m_spellInfo) > 15 * MINUTE * IN_MILISECONDS && !(m_spellInfo->AttributesEx4 & SPELL_ATTR_EX4_USABLE_IN_ARENA))
if(MapEntry const* mapEntry = sMapStore.LookupEntry(m_caster->GetMapId()))
if(mapEntry->IsBattleArena())
return SPELL_FAILED_NOT_IN_ARENA;
// zone check // zone check
uint32 zone, area; uint32 zone, area;
m_caster->GetZoneAndAreaId(zone, area); m_caster->GetZoneAndAreaId(zone, area);
SpellCastResult locRes= spellmgr.GetSpellAllowedInLocationError(m_spellInfo,m_caster->GetMapId(),zone,area, SpellCastResult locRes= spellmgr.GetSpellAllowedInLocationError(m_spellInfo,m_caster->GetMapId(),zone,area,
m_caster->GetTypeId() == TYPEID_PLAYER ? ((Player*)m_caster) : NULL); m_caster->GetCharmerOrOwnerPlayerOrPlayerItself());
if (locRes != SPELL_CAST_OK) if (locRes != SPELL_CAST_OK)
return locRes; return locRes;

View file

@ -657,37 +657,33 @@ namespace MaNGOS
for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr) for(typename GridRefManager<T>::iterator itr = m.begin(); itr != m.end(); ++itr)
{ {
if( !itr->getSource()->isAlive() || (itr->getSource()->GetTypeId() == TYPEID_PLAYER && ((Player*)itr->getSource())->isInFlight())) if ( !itr->getSource()->isTargetableForAttack()
continue; // mostly phase check
|| !itr->getSource()->IsInMap(i_originalCaster))
// mostly phase check
if(!itr->getSource()->IsInMap(i_originalCaster))
continue; continue;
switch (i_TargetType) switch (i_TargetType)
{ {
case SPELL_TARGETS_HOSTILE: case SPELL_TARGETS_HOSTILE:
if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsHostileTo( itr->getSource() )) if (!i_originalCaster->IsHostileTo( itr->getSource() ))
continue; continue;
break; break;
case SPELL_TARGETS_NOT_FRIENDLY: case SPELL_TARGETS_NOT_FRIENDLY:
if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsFriendlyTo( itr->getSource() )) if (i_originalCaster->IsFriendlyTo( itr->getSource() ))
continue; continue;
break; break;
case SPELL_TARGETS_NOT_HOSTILE: case SPELL_TARGETS_NOT_HOSTILE:
if (!itr->getSource()->isTargetableForAttack() || i_originalCaster->IsHostileTo( itr->getSource() )) if (i_originalCaster->IsHostileTo( itr->getSource() ))
continue; continue;
break; break;
case SPELL_TARGETS_FRIENDLY: case SPELL_TARGETS_FRIENDLY:
if (!itr->getSource()->isTargetableForAttack() || !i_originalCaster->IsFriendlyTo( itr->getSource() )) if (!i_originalCaster->IsFriendlyTo( itr->getSource() ))
continue; continue;
break; break;
case SPELL_TARGETS_AOE_DAMAGE: case SPELL_TARGETS_AOE_DAMAGE:
{ {
if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem()) if(itr->getSource()->GetTypeId()==TYPEID_UNIT && ((Creature*)itr->getSource())->isTotem())
continue; continue;
if(!itr->getSource()->isTargetableForAttack())
continue;
Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf(); Unit* check = i_originalCaster->GetCharmerOrOwnerOrSelf();

View file

@ -2803,6 +2803,20 @@ SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spell
} }
// bg spell checks // bg spell checks
// do not allow spells to be cast in arenas
// - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
// - with greater than 15 min CD
if ((spellInfo->AttributesEx4 & SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA) ||
(GetSpellRecoveryTime(spellInfo) > 15 * MINUTE * IN_MILISECONDS && !(spellInfo->AttributesEx4 & SPELL_ATTR_EX4_USABLE_IN_ARENA)))
if (!player || !player->InArena())
return SPELL_FAILED_NOT_IN_ARENA;
// Spell casted only on battleground
if ((spellInfo->AttributesEx3 & SPELL_ATTR_EX3_BATTLEGROUND))
if (!player || !player->InBattleGround())
return SPELL_FAILED_ONLY_BATTLEGROUNDS;
switch(spellInfo->Id) switch(spellInfo->Id)
{ {
case 23333: // Warsong Flag case 23333: // Warsong Flag
@ -2811,59 +2825,45 @@ SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spell
case 34976: // Netherstorm Flag case 34976: // Netherstorm Flag
return map_id == 566 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA; return map_id == 566 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
case 2584: // Waiting to Resurrect case 2584: // Waiting to Resurrect
case 42792: // Recently Dropped Flag
case 43681: // Inactive
{
return player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_ONLY_BATTLEGROUNDS;
}
case 22011: // Spirit Heal Channel case 22011: // Spirit Heal Channel
case 22012: // Spirit Heal case 22012: // Spirit Heal
case 24171: // Resurrection Impact Visual case 24171: // Resurrection Impact Visual
case 42792: // Recently Dropped Flag
case 43681: // Inactive
case 44535: // Spirit Heal (mana) case 44535: // Spirit Heal (mana)
{ {
MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
if (!mapEntry) if (!mapEntry)
return SPELL_FAILED_INCORRECT_AREA; return SPELL_FAILED_INCORRECT_AREA;
return mapEntry->IsBattleGround()? SPELL_CAST_OK : SPELL_FAILED_ONLY_BATTLEGROUNDS;
return mapEntry->IsBattleGround() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
} }
case 44521: // Preparation case 44521: // Preparation
{ {
if (!player) if (!player)
return SPELL_FAILED_REQUIRES_AREA; return SPELL_FAILED_REQUIRES_AREA;
MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
if (!mapEntry)
return SPELL_FAILED_INCORRECT_AREA;
if (!mapEntry->IsBattleGround())
return SPELL_FAILED_REQUIRES_AREA;
BattleGround* bg = player->GetBattleGround(); BattleGround* bg = player->GetBattleGround();
return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA; return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_ONLY_BATTLEGROUNDS;
} }
case 32724: // Gold Team (Alliance) case 32724: // Gold Team (Alliance)
case 32725: // Green Team (Alliance) case 32725: // Green Team (Alliance)
case 35774: // Gold Team (Horde) case 35774: // Gold Team (Horde)
case 35775: // Green Team (Horde) case 35775: // Green Team (Horde)
{ {
MapEntry const* mapEntry = sMapStore.LookupEntry(map_id); return player && player->InArena() ? SPELL_CAST_OK : SPELL_FAILED_ONLY_IN_ARENA;
if (!mapEntry)
return SPELL_FAILED_INCORRECT_AREA;
return mapEntry->IsBattleArena() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
} }
case 32727: // Arena Preparation case 32727: // Arena Preparation
{ {
if (!player) if (!player)
return SPELL_FAILED_REQUIRES_AREA; return SPELL_FAILED_REQUIRES_AREA;
if (!player->InArena())
MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
if (!mapEntry)
return SPELL_FAILED_INCORRECT_AREA;
if (!mapEntry->IsBattleArena())
return SPELL_FAILED_REQUIRES_AREA; return SPELL_FAILED_REQUIRES_AREA;
BattleGround* bg = player->GetBattleGround(); BattleGround* bg = player->GetBattleGround();
return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA; return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_ONLY_IN_ARENA;
} }
} }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "8550" #define REVISION_NR "8551"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__