[7980] Implement item use target requirements store and check (new table item_required_target). Author: NoFantasy

Signed-off-by: VladimirMangos <vladimir@getmangos.com>

    * Also implement this table reload
    * Static Spell::SendCastResult function for call not from spell code.
      Can be also used in scripts where need send explicitly spell cast error to client.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-06-08 17:25:02 -05:00
parent 6578cce471
commit 4e130dcdfd
15 changed files with 257 additions and 35 deletions

View File

@@ -776,6 +776,23 @@ bool Item::IsFitToSpellRequirements(SpellEntry const* spellInfo) const
return true;
}
bool Item::IsTargetValidForItemUse(Unit* pUnitTarget)
{
ItemRequiredTargetMapBounds bounds = objmgr.GetItemRequiredTargetMapBounds(GetProto()->ItemId);
if (bounds.first == bounds.second)
return true;
if (!pUnitTarget)
return false;
for(ItemRequiredTargetMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
if(itr->second.IsFitToRequirements(pUnitTarget))
return true;
return false;
}
void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges)
{
// Better lost small time at check in comparison lost time at item save to DB.
@@ -982,3 +999,16 @@ bool Item::IsBindedNotWith( Player const* player ) const
return objmgr.GetPlayerAccountIdByGUID(GetOwnerGUID()) != player->GetSession()->GetAccountId();
}
}
bool ItemRequiredTarget::IsFitToRequirements( Unit* pUnitTarget ) const
{
switch(m_uiType)
{
case ITEM_TARGET_TYPE_CREATURE:
return pUnitTarget->isAlive();
case ITEM_TARGET_TYPE_DEAD:
return !pUnitTarget->isAlive();
default:
return false;
}
}