[11490] Alow implicit cast ObjectGuid->uint64 and only explicit uint64->ObjectGuid

Now safe allow this casts in like way after completed convertion to ObjectGuid use.
Also simplify code in result allowed auto cast to uint64.

Please _not_ add new uint64 storages (local and in structures) for guid values.
This commit is contained in:
VladimirMangos 2011-05-15 22:01:16 +04:00
parent ecdb435b1e
commit 249fb836ca
47 changed files with 194 additions and 210 deletions

View file

@ -188,10 +188,10 @@ void SpellCastTargets::setCorpseTarget(Corpse* corpse)
void SpellCastTargets::Update(Unit* caster)
{
m_GOTarget = !m_GOTargetGUID.IsEmpty() ? caster->GetMap()->GetGameObject(m_GOTargetGUID) : NULL;
m_unitTarget = !m_unitTargetGUID.IsEmpty() ?
m_GOTarget = m_GOTargetGUID ? caster->GetMap()->GetGameObject(m_GOTargetGUID) : NULL;
m_unitTarget = m_unitTargetGUID ?
( m_unitTargetGUID == caster->GetObjectGuid() ? caster : ObjectAccessor::GetUnit(*caster, m_unitTargetGUID) ) :
NULL;
NULL;
m_itemTarget = NULL;
if (caster->GetTypeId() == TYPEID_PLAYER)
@ -354,10 +354,7 @@ Spell::Spell( Unit* caster, SpellEntry const *info, bool triggered, ObjectGuid o
// Set health leech amount to zero
m_healthLeech = 0;
if(!originalCasterGUID.IsEmpty())
m_originalCasterGUID = originalCasterGUID;
else
m_originalCasterGUID = m_caster->GetObjectGuid();
m_originalCasterGUID = originalCasterGUID ? originalCasterGUID : m_caster->GetObjectGuid();
UpdateOriginalCasterPointer();
@ -2224,7 +2221,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
break;
}
case TARGET_GAMEOBJECT_ITEM:
if (!m_targets.getGOTargetGuid().IsEmpty())
if (m_targets.getGOTargetGuid())
AddGOTarget(m_targets.getGOTarget(), effIndex);
else if (m_targets.getItemTarget())
AddItemTarget(m_targets.getItemTarget(), effIndex);
@ -2640,14 +2637,14 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
targetUnitMap.push_back(m_caster);
break;
case SPELL_EFFECT_SUMMON_PLAYER:
if (m_caster->GetTypeId()==TYPEID_PLAYER && !((Player*)m_caster)->GetSelectionGuid().IsEmpty())
if (m_caster->GetTypeId()==TYPEID_PLAYER && ((Player*)m_caster)->GetSelectionGuid())
if (Player* target = sObjectMgr.GetPlayer(((Player*)m_caster)->GetSelectionGuid()))
targetUnitMap.push_back(target);
break;
case SPELL_EFFECT_RESURRECT_NEW:
if (m_targets.getUnitTarget())
targetUnitMap.push_back(m_targets.getUnitTarget());
if (!m_targets.getCorpseTargetGuid().IsEmpty())
if (m_targets.getCorpseTargetGuid())
{
if (Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid()))
if (Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGuid()))
@ -2705,7 +2702,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
case SPELL_EFFECT_SKIN_PLAYER_CORPSE:
if (m_targets.getUnitTarget())
targetUnitMap.push_back(m_targets.getUnitTarget());
else if (!m_targets.getCorpseTargetGuid().IsEmpty())
else if (m_targets.getCorpseTargetGuid())
{
if (Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid()))
if (Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGuid()))
@ -2912,7 +2909,7 @@ void Spell::cast(bool skipCheck)
UpdatePointers();
// cancel at lost main target unit
if (!m_targets.getUnitTarget() && !m_targets.getUnitTargetGuid().IsEmpty() && m_targets.getUnitTargetGuid() != m_caster->GetObjectGuid())
if (!m_targets.getUnitTarget() && m_targets.getUnitTargetGuid() && m_targets.getUnitTargetGuid() != m_caster->GetObjectGuid())
{
cancel();
m_caster->DecreaseCastCounter();
@ -3305,7 +3302,7 @@ void Spell::update(uint32 difftime)
// update pointers based at it's GUIDs
UpdatePointers();
if (!m_targets.getUnitTargetGuid().IsEmpty() && !m_targets.getUnitTarget())
if (m_targets.getUnitTargetGuid() && !m_targets.getUnitTarget())
{
cancel();
return;
@ -3924,7 +3921,7 @@ void Spell::SendLogExecute()
case SPELL_EFFECT_SUMMON_OBJECT_SLOT4:
if (Unit *unit = m_targets.getUnitTarget())
data << unit->GetPackGUID();
else if (!m_targets.getItemTargetGuid().IsEmpty())
else if (m_targets.getItemTargetGuid())
data << m_targets.getItemTargetGuid().WriteAsPacked();
else if (GameObject *go = m_targets.getGOTarget())
data << go->GetPackGUID();
@ -4695,7 +4692,7 @@ SpellCastResult Spell::CheckCast(bool strict)
}
// TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
// check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
if (!explicit_target_mode && m_caster->GetTypeId() == TYPEID_UNIT && !m_caster->GetCharmerOrOwnerGuid().IsEmpty())
if (!explicit_target_mode && m_caster->GetTypeId() == TYPEID_UNIT && m_caster->GetCharmerOrOwnerGuid())
{
// check correctness positive/negative cast target (pet cast real check and cheating check)
if(IsPositiveSpell(m_spellInfo->Id))
@ -4988,7 +4985,7 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return SPELL_FAILED_ERROR;
if (((Player*)m_caster)->GetSelectionGuid().IsEmpty())
if (!((Player*)m_caster)->GetSelectionGuid())
return SPELL_FAILED_BAD_IMPLICIT_TARGETS;
Pet* target = m_caster->GetMap()->GetPet(((Player*)m_caster)->GetSelectionGuid());
@ -5027,7 +5024,7 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_spellInfo->SpellFamilyName == SPELLFAMILY_SHAMAN && m_spellInfo->SpellIconID == 33)
{
// fire totems slot
if (m_caster->GetTotemGuid(TOTEM_SLOT_FIRE).IsEmpty())
if (!m_caster->GetTotemGuid(TOTEM_SLOT_FIRE))
return SPELL_FAILED_TOTEMS;
}
break;
@ -5096,7 +5093,7 @@ SpellCastResult Spell::CheckCast(bool strict)
return SPELL_FAILED_DONT_REPORT;
}
if (!plrCaster->GetPetGuid().IsEmpty() || !plrCaster->GetCharmGuid().IsEmpty())
if (plrCaster->GetPetGuid() || plrCaster->GetCharmGuid())
{
plrCaster->SendPetTameFailure(PETTAME_ANOTHERSUMMONACTIVE);
return SPELL_FAILED_DONT_REPORT;
@ -5300,10 +5297,10 @@ SpellCastResult Spell::CheckCast(bool strict)
{
if(summon_prop->Group == SUMMON_PROP_GROUP_PETS)
{
if (!m_caster->GetPetGuid().IsEmpty())
if (m_caster->GetPetGuid())
return SPELL_FAILED_ALREADY_HAVE_SUMMON;
if (!m_caster->GetCharmGuid().IsEmpty())
if (m_caster->GetCharmGuid())
return SPELL_FAILED_ALREADY_HAVE_CHARM;
}
}
@ -5312,7 +5309,7 @@ SpellCastResult Spell::CheckCast(bool strict)
}
case SPELL_EFFECT_SUMMON_PET:
{
if (!m_caster->GetPetGuid().IsEmpty()) //let warlock do a replacement summon
if (m_caster->GetPetGuid()) // let warlock do a replacement summon
{
Pet* pet = ((Player*)m_caster)->GetPet();
@ -5326,20 +5323,20 @@ SpellCastResult Spell::CheckCast(bool strict)
return SPELL_FAILED_ALREADY_HAVE_SUMMON;
}
if (!m_caster->GetCharmGuid().IsEmpty())
if (m_caster->GetCharmGuid())
return SPELL_FAILED_ALREADY_HAVE_CHARM;
break;
}
case SPELL_EFFECT_SUMMON_PLAYER:
{
if(m_caster->GetTypeId() != TYPEID_PLAYER)
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return SPELL_FAILED_BAD_TARGETS;
if(((Player*)m_caster)->GetSelectionGuid().IsEmpty())
if (!((Player*)m_caster)->GetSelectionGuid())
return SPELL_FAILED_BAD_TARGETS;
Player* target = sObjectMgr.GetPlayer(((Player*)m_caster)->GetSelectionGuid());
if( !target || ((Player*)m_caster) == target || !target->IsInSameRaidWith((Player*)m_caster) )
if (!target || ((Player*)m_caster) == target || !target->IsInSameRaidWith((Player*)m_caster))
return SPELL_FAILED_BAD_TARGETS;
// check if our map is dungeon
@ -5418,19 +5415,19 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_targets.getUnitTarget() == m_caster)
return SPELL_FAILED_BAD_TARGETS;
if (!m_caster->GetPetGuid().IsEmpty())
if (m_caster->GetPetGuid())
return SPELL_FAILED_ALREADY_HAVE_SUMMON;
if (!m_caster->GetCharmGuid().IsEmpty())
if (m_caster->GetCharmGuid())
return SPELL_FAILED_ALREADY_HAVE_CHARM;
if (!m_caster->GetCharmerGuid().IsEmpty())
if (m_caster->GetCharmerGuid())
return SPELL_FAILED_CHARMED;
if (!m_targets.getUnitTarget())
return SPELL_FAILED_BAD_IMPLICIT_TARGETS;
if (!m_targets.getUnitTarget()->GetCharmerGuid().IsEmpty())
if (m_targets.getUnitTarget()->GetCharmerGuid())
return SPELL_FAILED_CHARMED;
if (int32(m_targets.getUnitTarget()->getLevel()) > CalculateDamage(SpellEffectIndex(i),m_targets.getUnitTarget()))
@ -5443,19 +5440,19 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_targets.getUnitTarget() == m_caster)
return SPELL_FAILED_BAD_TARGETS;
if (!m_caster->GetPetGuid().IsEmpty())
if (m_caster->GetPetGuid())
return SPELL_FAILED_ALREADY_HAVE_SUMMON;
if (!m_caster->GetCharmGuid().IsEmpty())
if (m_caster->GetCharmGuid())
return SPELL_FAILED_ALREADY_HAVE_CHARM;
if (!m_caster->GetCharmerGuid().IsEmpty())
if (m_caster->GetCharmerGuid())
return SPELL_FAILED_CHARMED;
if (!m_targets.getUnitTarget())
return SPELL_FAILED_BAD_IMPLICIT_TARGETS;
if (!m_targets.getUnitTarget()->GetCharmerGuid().IsEmpty())
if (m_targets.getUnitTarget()->GetCharmerGuid())
return SPELL_FAILED_CHARMED;
if (int32(m_targets.getUnitTarget()->getLevel()) > CalculateDamage(SpellEffectIndex(i),m_targets.getUnitTarget()))
@ -5468,17 +5465,17 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return SPELL_FAILED_UNKNOWN;
if (!m_caster->GetCharmGuid().IsEmpty())
if (m_caster->GetCharmGuid())
return SPELL_FAILED_ALREADY_HAVE_CHARM;
if (!m_caster->GetCharmerGuid().IsEmpty())
if (m_caster->GetCharmerGuid())
return SPELL_FAILED_CHARMED;
Pet* pet = m_caster->GetPet();
if (!pet)
return SPELL_FAILED_NO_PET;
if (!pet->GetCharmerGuid().IsEmpty())
if (pet->GetCharmerGuid())
return SPELL_FAILED_CHARMED;
break;
@ -6133,7 +6130,7 @@ SpellCastResult Spell::CheckItems()
}
// check target item (for triggered case not report error)
if (!m_targets.getItemTargetGuid().IsEmpty())
if (m_targets.getItemTargetGuid())
{
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return m_IsTriggeredSpell && !(m_targets.m_targetMask & TARGET_FLAG_TRADE_ITEM)
@ -6701,7 +6698,7 @@ bool Spell::CheckTarget( Unit* target, SpellEffectIndex eff )
// player far away, maybe his corpse near?
if(target != m_caster && !target->IsWithinLOSInMap(m_caster))
{
if (!m_targets.getCorpseTargetGuid().IsEmpty())
if (m_targets.getCorpseTargetGuid())
return false;
Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid());
@ -7037,7 +7034,7 @@ void Spell::FillRaidOrPartyHealthPriorityTargets(UnitList &targetUnitMap, Unit*
WorldObject* Spell::GetAffectiveCasterObject() const
{
if (m_originalCasterGUID.IsEmpty())
if (!m_originalCasterGUID)
return m_caster;
if (m_originalCasterGUID.IsGameObject() && m_caster->IsInWorld())