Core/Spells:

- corrected structure of SMSG_PET_CAST_FAILED (fixes highlighted action buttons)
- simplified spell focus check
This commit is contained in:
joschiwald committed 2013-08-14 15:45:36 +02:00
1 parent 783021a8cb
commit e87402dd05
7 files changed
+94 -126

No files matched your search

+68 -41
View File
@@ -2038,6 +2038,15 @@ void Spell::SearchChainTargets(std::list<WorldObject*>& targets, uint32 chainTar
}
}
GameObject* Spell::SearchSpellFocus()
{
GameObject* focus = NULL;
Trinity::GameObjectFocusCheck check(m_caster, m_spellInfo->RequiresSpellFocus);
Trinity::GameObjectSearcher<Trinity::GameObjectFocusCheck> searcher(m_caster, focus, check);
SearchTargets<Trinity::GameObjectSearcher<Trinity::GameObjectFocusCheck> > (searcher, GRID_MAP_TYPE_MASK_GAMEOBJECT, m_caster, m_caster, m_caster->GetVisibilityRange());
return focus;
}
void Spell::prepareDataForTriggerSystem(AuraEffect const* /*triggeredByAura*/)
{
//==========================================================================================
@@ -3755,27 +3764,9 @@ void Spell::finish(bool ok)
m_caster->AttackStop();
}
void Spell::SendCastResult(SpellCastResult result)
void Spell::WriteCastResultInfo(WorldPacket& data, Player* caster, SpellInfo const* spellInfo, uint8 castCount, SpellCastResult result, SpellCustomErrors customError)
{
if (result == SPELL_CAST_OK)
return;
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return;
if (m_caster->ToPlayer()->GetSession()->PlayerLoading()) // don't send cast results at loading time
return;
SendCastResult(m_caster->ToPlayer(), m_spellInfo, m_cast_count, result, m_customError);
}
void Spell::SendCastResult(Player* caster, SpellInfo const* spellInfo, uint8 cast_count, SpellCastResult result, SpellCustomErrors customError /*= SPELL_CUSTOM_ERROR_NONE*/)
{
if (result == SPELL_CAST_OK)
return;
WorldPacket data(SMSG_CAST_FAILED, (4+1+1));
data << uint8(cast_count); // single cast or multi 2.3 (0/1)
data << uint8(castCount); // single cast or multi 2.3 (0/1)
data << uint32(spellInfo->Id);
data << uint8(result); // problem
switch (result)
@@ -3876,9 +3867,52 @@ void Spell::SendCastResult(Player* caster, SpellInfo const* spellInfo, uint8 cas
default:
break;
}
}
void Spell::SendCastResult(Player* caster, SpellInfo const* spellInfo, uint8 castCount, SpellCastResult result, SpellCustomErrors customError /*= SPELL_CUSTOM_ERROR_NONE*/)
{
if (result == SPELL_CAST_OK)
return;
WorldPacket data(SMSG_CAST_FAILED, 1 + 4 + 1);
WriteCastResultInfo(data, caster, spellInfo, castCount, result, customError);
caster->GetSession()->SendPacket(&data);
}
void Spell::SendCastResult(SpellCastResult result)
{
if (result == SPELL_CAST_OK)
return;
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return;
if (m_caster->ToPlayer()->GetSession()->PlayerLoading()) // don't send cast results at loading time
return;
SendCastResult(m_caster->ToPlayer(), m_spellInfo, m_cast_count, result, m_customError);
}
void Spell::SendPetCastResult(SpellCastResult result)
{
if (result == SPELL_CAST_OK)
return;
Unit* owner = m_caster->GetCharmerOrOwner();
if (!owner)
return;
Player* player = owner->ToPlayer();
if (!player)
return;
WorldPacket data(SMSG_PET_CAST_FAILED, 1 + 4 + 1);
WriteCastResultInfo(data, player, m_spellInfo, m_cast_count, result, m_customError);
player->GetSession()->SendPacket(&data);
}
void Spell::SendSpellStart()
{
if (!IsNeedSendToClient())
@@ -4981,9 +5015,17 @@ SpellCastResult Spell::CheckCast(bool strict)
return SPELL_FAILED_NOT_MOUNTED;
}
// check spell focus object
if (m_spellInfo->RequiresSpellFocus)
{
focusObject = SearchSpellFocus();
if (!focusObject)
return SPELL_FAILED_REQUIRES_SPELL_FOCUS;
}
SpellCastResult castResult = SPELL_CAST_OK;
// always (except passive spells) check items (focus object can be required for any type casts)
// always (except passive spells) check items (only player related checks)
if (!m_spellInfo->IsPassive())
{
castResult = CheckItems();
@@ -5585,6 +5627,11 @@ SpellCastResult Spell::CheckPetCast(Unit* target)
if (creatureCaster->HasSpellCooldown(m_spellInfo->Id))
return SPELL_FAILED_NOT_READY;
// Check if spell is affected by GCD
if (m_spellInfo->StartRecoveryCategory > 0)
if (m_caster->GetCharmInfo() && m_caster->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(m_spellInfo))
return SPELL_FAILED_NOT_READY;
return CheckCast(true);
}
@@ -5947,26 +5994,6 @@ SpellCastResult Spell::CheckItems()
return SPELL_FAILED_EQUIPPED_ITEM_CLASS;
}
// check spell focus object
if (m_spellInfo->RequiresSpellFocus)
{
CellCoord p(Trinity::ComputeCellCoord(m_caster->GetPositionX(), m_caster->GetPositionY()));
Cell cell(p);
GameObject* ok = NULL;
Trinity::GameObjectFocusCheck go_check(m_caster, m_spellInfo->RequiresSpellFocus);
Trinity::GameObjectSearcher<Trinity::GameObjectFocusCheck> checker(m_caster, ok, go_check);
TypeContainerVisitor<Trinity::GameObjectSearcher<Trinity::GameObjectFocusCheck>, GridTypeMapContainer > object_checker(checker);
Map& map = *m_caster->GetMap();
cell.Visit(p, object_checker, map, *m_caster, m_caster->GetVisibilityRange());
if (!ok)
return SPELL_FAILED_REQUIRES_SPELL_FOCUS;
focusObject = ok; // game object found in range
}
// do not take reagents for these item casts
if (!(m_CastItem && m_CastItem->GetTemplate()->Flags & ITEM_PROTO_FLAG_TRIGGERED_CAST))
{