Skip to content

Commit

Permalink
[11462] Missing ObjectGuids in spell code.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMangos committed May 10, 2011
1 parent 7d754c6 commit 2ef80ef
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 57 deletions.
60 changes: 27 additions & 33 deletions src/game/Spell.cpp
Expand Up @@ -871,10 +871,9 @@ void Spell::AddUnitTarget(Unit* pVictim, SpellEffectIndex effIndex)
m_UniqueTargetInfo.push_back(target);
}

void Spell::AddUnitTarget(uint64 unitGUID, SpellEffectIndex effIndex)
void Spell::AddUnitTarget(ObjectGuid unitGuid, SpellEffectIndex effIndex)
{
Unit* unit = m_caster->GetGUID() == unitGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, unitGUID);
if (unit)
if (Unit* unit = m_caster->GetObjectGuid() == unitGuid ? m_caster : ObjectAccessor::GetUnit(*m_caster, unitGuid))
AddUnitTarget(unit, effIndex);
}

Expand Down Expand Up @@ -923,10 +922,9 @@ void Spell::AddGOTarget(GameObject* pVictim, SpellEffectIndex effIndex)
m_UniqueGOTargetInfo.push_back(target);
}

void Spell::AddGOTarget(uint64 goGUID, SpellEffectIndex effIndex)
void Spell::AddGOTarget(ObjectGuid goGuid, SpellEffectIndex effIndex)
{
GameObject* go = m_caster->GetMap()->GetGameObject(goGUID);
if (go)
if (GameObject* go = m_caster->GetMap()->GetGameObject(goGuid))
AddGOTarget(go, effIndex);
}

Expand Down Expand Up @@ -2226,9 +2224,9 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
break;
}
case TARGET_GAMEOBJECT_ITEM:
if(m_targets.getGOTargetGUID())
if (!m_targets.getGOTargetGuid().IsEmpty())
AddGOTarget(m_targets.getGOTarget(), effIndex);
else if(m_targets.getItemTarget())
else if (m_targets.getItemTarget())
AddItemTarget(m_targets.getItemTarget(), effIndex);
break;
case TARGET_MASTER:
Expand Down Expand Up @@ -2649,15 +2647,11 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
case SPELL_EFFECT_RESURRECT_NEW:
if (m_targets.getUnitTarget())
targetUnitMap.push_back(m_targets.getUnitTarget());
if (m_targets.getCorpseTargetGUID())
if (!m_targets.getCorpseTargetGuid().IsEmpty())
{
Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGUID());
if(corpse)
{
Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGuid());
if(owner)
if (Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid()))
if (Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGuid()))
targetUnitMap.push_back(owner);
}
}
break;
case SPELL_EFFECT_SUMMON:
Expand Down Expand Up @@ -2711,9 +2705,9 @@ 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())
else if (!m_targets.getCorpseTargetGuid().IsEmpty())
{
if (Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGUID()))
if (Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid()))
if (Player* owner = ObjectAccessor::FindPlayer(corpse->GetOwnerGuid()))
targetUnitMap.push_back(owner);
}
Expand Down Expand Up @@ -2918,19 +2912,19 @@ void Spell::cast(bool skipCheck)
UpdatePointers();

// cancel at lost main target unit
if(!m_targets.getUnitTarget() && m_targets.getUnitTargetGUID() && m_targets.getUnitTargetGUID() != m_caster->GetGUID())
if (!m_targets.getUnitTarget() && !m_targets.getUnitTargetGuid().IsEmpty() && m_targets.getUnitTargetGuid() != m_caster->GetObjectGuid())
{
cancel();
m_caster->DecreaseCastCounter();
SetExecutedCurrently(false);
return;
}

if(m_caster->GetTypeId() != TYPEID_PLAYER && m_targets.getUnitTarget() && m_targets.getUnitTarget() != m_caster)
if (m_caster->GetTypeId() != TYPEID_PLAYER && m_targets.getUnitTarget() && m_targets.getUnitTarget() != m_caster)
m_caster->SetInFront(m_targets.getUnitTarget());

SpellCastResult castResult = CheckPower();
if(castResult != SPELL_CAST_OK)
if (castResult != SPELL_CAST_OK)
{
SendCastResult(castResult);
finish(false);
Expand All @@ -2940,7 +2934,7 @@ void Spell::cast(bool skipCheck)
}

// triggered cast called from Spell::prepare where it was already checked
if(!skipCheck)
if (!skipCheck)
{
castResult = CheckCast(false);
if(castResult != SPELL_CAST_OK)
Expand Down Expand Up @@ -3311,7 +3305,7 @@ void Spell::update(uint32 difftime)
// update pointers based at it's GUIDs
UpdatePointers();

if(m_targets.getUnitTargetGUID() && !m_targets.getUnitTarget())
if (!m_targets.getUnitTargetGuid().IsEmpty() && !m_targets.getUnitTarget())
{
cancel();
return;
Expand Down Expand Up @@ -3916,11 +3910,11 @@ void Spell::SendLogExecute()
case SPELL_EFFECT_SUMMON_OBJECT_SLOT2:
case SPELL_EFFECT_SUMMON_OBJECT_SLOT3:
case SPELL_EFFECT_SUMMON_OBJECT_SLOT4:
if(Unit *unit = m_targets.getUnitTarget())
if (Unit *unit = m_targets.getUnitTarget())
data << unit->GetPackGUID();
else if(m_targets.getItemTargetGUID())
data.appendPackGUID(m_targets.getItemTargetGUID());
else if(GameObject *go = m_targets.getGOTarget())
else if (!m_targets.getItemTargetGuid().IsEmpty())
data << m_targets.getItemTargetGuid().WriteAsPacked();
else if (GameObject *go = m_targets.getGOTarget())
data << go->GetPackGUID();
else
data << uint8(0); // guid
Expand Down Expand Up @@ -5571,7 +5565,7 @@ SpellCastResult Spell::CheckCast(bool strict)
if (!my_trade)
return SPELL_FAILED_NOT_TRADING;

TradeSlots slot = TradeSlots(m_targets.getItemTargetGUID());
TradeSlots slot = TradeSlots(m_targets.getItemTargetGuid().GetRawValue());
if (slot != TRADE_SLOT_NONTRADED)
return SPELL_FAILED_ITEM_NOT_READY;

Expand Down Expand Up @@ -6128,18 +6122,18 @@ SpellCastResult Spell::CheckItems()
}

// check target item (for triggered case not report error)
if(m_targets.getItemTargetGUID())
if (!m_targets.getItemTargetGuid().IsEmpty())
{
if(m_caster->GetTypeId() != TYPEID_PLAYER)
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return m_IsTriggeredSpell && !(m_targets.m_targetMask & TARGET_FLAG_TRADE_ITEM)
? SPELL_FAILED_DONT_REPORT : SPELL_FAILED_BAD_TARGETS;

if(!m_targets.getItemTarget())
if (!m_targets.getItemTarget())
return m_IsTriggeredSpell && !(m_targets.m_targetMask & TARGET_FLAG_TRADE_ITEM)
? SPELL_FAILED_DONT_REPORT : SPELL_FAILED_ITEM_GONE;

isVellumTarget = m_targets.getItemTarget()->GetProto()->IsVellum();
if(!m_targets.getItemTarget()->IsFitToSpellRequirements(m_spellInfo))
if (!m_targets.getItemTarget()->IsFitToSpellRequirements(m_spellInfo))
return m_IsTriggeredSpell && !(m_targets.m_targetMask & TARGET_FLAG_TRADE_ITEM)
? SPELL_FAILED_DONT_REPORT : SPELL_FAILED_EQUIPPED_ITEM_CLASS;

Expand Down Expand Up @@ -6696,10 +6690,10 @@ 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())
if (!m_targets.getCorpseTargetGuid().IsEmpty())
return false;

Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGUID());
Corpse *corpse = m_caster->GetMap()->GetCorpse(m_targets.getCorpseTargetGuid());
if(!corpse)
return false;

Expand Down
17 changes: 9 additions & 8 deletions src/game/Spell.h
Expand Up @@ -135,19 +135,20 @@ class SpellCastTargets
return *this;
}

uint64 getUnitTargetGUID() const { return m_unitTargetGUID.GetRawValue(); }
ObjectGuid getUnitTargetGuid() const { return m_unitTargetGUID; }
Unit *getUnitTarget() const { return m_unitTarget; }
void setUnitTarget(Unit *target);
void setDestination(float x, float y, float z);
void setSource(float x, float y, float z);

uint64 getGOTargetGUID() const { return m_GOTargetGUID.GetRawValue(); }
ObjectGuid getGOTargetGuid() const { return m_GOTargetGUID; }
GameObject *getGOTarget() const { return m_GOTarget; }
void setGOTarget(GameObject *target);

uint64 getCorpseTargetGUID() const { return m_CorpseTargetGUID.GetRawValue(); }
ObjectGuid getCorpseTargetGuid() const { return m_CorpseTargetGUID; }
void setCorpseTarget(Corpse* corpse);
uint64 getItemTargetGUID() const { return m_itemTargetGUID.GetRawValue(); }

ObjectGuid getItemTargetGuid() const { return m_itemTargetGUID; }
Item* getItemTarget() const { return m_itemTarget; }
uint32 getItemTargetEntry() const { return m_itemTargetEntry; }
void setItemTarget(Item* item);
Expand All @@ -156,7 +157,7 @@ class SpellCastTargets
{
if(m_itemTarget && (m_targetMask & TARGET_FLAG_TRADE_ITEM))
{
m_itemTargetGUID = m_itemTarget->GetGUID();
m_itemTargetGUID = m_itemTarget->GetObjectGuid();
m_itemTargetEntry = m_itemTarget->GetEntry();
}
}
Expand Down Expand Up @@ -496,7 +497,7 @@ class Spell
void TriggerGlobalCooldown();
void CancelGlobalCooldown();

void SendLoot(uint64 guid, LootType loottype);
void SendLoot(ObjectGuid guid, LootType loottype);
bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data
void UpdateOriginalCasterPointer();

Expand Down Expand Up @@ -608,9 +609,9 @@ class Spell
ItemTargetList m_UniqueItemInfo;

void AddUnitTarget(Unit* target, SpellEffectIndex effIndex);
void AddUnitTarget(uint64 unitGUID, SpellEffectIndex effIndex);
void AddUnitTarget(ObjectGuid unitGuid, SpellEffectIndex effIndex);
void AddGOTarget(GameObject* target, SpellEffectIndex effIndex);
void AddGOTarget(uint64 goGUID, SpellEffectIndex effIndex);
void AddGOTarget(ObjectGuid goGuid, SpellEffectIndex effIndex);
void AddItemTarget(Item* target, SpellEffectIndex effIndex);
void DoAllEffectOnTarget(TargetInfo *target);
void HandleDelayedSpellLaunch(TargetInfo *target);
Expand Down
20 changes: 11 additions & 9 deletions src/game/SpellEffects.cpp
Expand Up @@ -4302,7 +4302,7 @@ void Spell::EffectEnergisePct(SpellEffectIndex eff_idx)
m_caster->EnergizeBySpell(unitTarget, m_spellInfo->Id, gain, power);
}

void Spell::SendLoot(uint64 guid, LootType loottype)
void Spell::SendLoot(ObjectGuid guid, LootType loottype)
{
if (gameObjTarget)
{
Expand Down Expand Up @@ -4345,7 +4345,7 @@ void Spell::EffectOpenLock(SpellEffectIndex eff_idx)
Player* player = (Player*)m_caster;

uint32 lockId = 0;
uint64 guid = 0;
ObjectGuid guid;

// Get lockId
if (gameObjTarget)
Expand Down Expand Up @@ -4377,12 +4377,12 @@ void Spell::EffectOpenLock(SpellEffectIndex eff_idx)
}
}
lockId = goInfo->GetLockId();
guid = gameObjTarget->GetGUID();
guid = gameObjTarget->GetObjectGuid();
}
else if (itemTarget)
{
lockId = itemTarget->GetProto()->LockID;
guid = itemTarget->GetGUID();
guid = itemTarget->GetObjectGuid();
}
else
{
Expand Down Expand Up @@ -8059,7 +8059,7 @@ void Spell::EffectSummonObject(SpellEffectIndex eff_idx)
uint32 go_id = m_spellInfo->EffectMiscValue[eff_idx];

uint8 slot = 0;
switch(m_spellInfo->Effect[eff_idx])
switch (m_spellInfo->Effect[eff_idx])
{
case SPELL_EFFECT_SUMMON_OBJECT_SLOT1: slot = 0; break;
case SPELL_EFFECT_SUMMON_OBJECT_SLOT2: slot = 1; break;
Expand All @@ -8068,11 +8068,13 @@ void Spell::EffectSummonObject(SpellEffectIndex eff_idx)
default: return;
}

if(uint64 guid = m_caster->m_ObjectSlot[slot])
ObjectGuid guid = m_caster->m_ObjectSlotGuid[slot];

if (!guid.IsEmpty())
{
if(GameObject* obj = m_caster ? m_caster->GetMap()->GetGameObject(guid) : NULL)
if (GameObject* obj = m_caster ? m_caster->GetMap()->GetGameObject(guid) : NULL)
obj->SetLootState(GO_JUST_DEACTIVATED);
m_caster->m_ObjectSlot[slot] = 0;
m_caster->m_ObjectSlotGuid[slot].Clear();
}

GameObject* pGameObj = new GameObject;
Expand Down Expand Up @@ -8105,7 +8107,7 @@ void Spell::EffectSummonObject(SpellEffectIndex eff_idx)

map->Add(pGameObj);

m_caster->m_ObjectSlot[slot] = pGameObj->GetGUID();
m_caster->m_ObjectSlotGuid[slot] = pGameObj->GetObjectGuid();

pGameObj->SummonLinkedTrapIfAny();

Expand Down
8 changes: 4 additions & 4 deletions src/game/SpellHandler.cpp
Expand Up @@ -34,11 +34,11 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
uint8 bagIndex, slot;
uint8 unk_flags; // flags (if 0x02 - some additional data are received)
uint8 cast_count; // next cast if exists (single or not)
uint64 item_guid;
ObjectGuid itemGuid;
uint32 glyphIndex; // something to do with glyphs?
uint32 spellid; // casted spell id

recvPacket >> bagIndex >> slot >> cast_count >> spellid >> item_guid >> glyphIndex >> unk_flags;
recvPacket >> bagIndex >> slot >> cast_count >> spellid >> itemGuid >> glyphIndex >> unk_flags;

// TODO: add targets.read() check
Player* pUser = _player;
Expand Down Expand Up @@ -66,7 +66,7 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
return;
}

if (pItem->GetGUID() != item_guid)
if (pItem->GetObjectGuid() != itemGuid)
{
recvPacket.rpos(recvPacket.wpos()); // prevent spam at not read packet tail
pUser->SendEquipError(EQUIP_ERR_ITEM_NOT_FOUND, NULL, NULL );
Expand Down Expand Up @@ -250,7 +250,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
uint32 entry = fields[0].GetUInt32();
uint32 flags = fields[1].GetUInt32();

pItem->SetUInt64Value(ITEM_FIELD_GIFTCREATOR, 0);
pItem->SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid());
pItem->SetEntry(entry);
pItem->SetUInt32Value(ITEM_FIELD_FLAGS, flags);
pItem->SetState(ITEM_CHANGED, pUser);
Expand Down
1 change: 0 additions & 1 deletion src/game/Unit.cpp
Expand Up @@ -210,7 +210,6 @@ Unit::Unit() :

m_addDmgOnce = 0;

m_ObjectSlot[0] = m_ObjectSlot[1] = m_ObjectSlot[2] = m_ObjectSlot[3] = 0;
//m_Aura = NULL;
//m_AurasCheck = 2000;
//m_removeAuraTimer = 4;
Expand Down
2 changes: 1 addition & 1 deletion src/game/Unit.h
Expand Up @@ -1646,7 +1646,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void DecreaseCastCounter() { if (m_castCounter) --m_castCounter; }

uint32 m_addDmgOnce;
uint64 m_ObjectSlot[4];
ObjectGuid m_ObjectSlotGuid[4];
uint32 m_detectInvisibilityMask;
uint32 m_invisibilityMask;

Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11461"
#define REVISION_NR "11462"
#endif // __REVISION_NR_H__

0 comments on commit 2ef80ef

Please sign in to comment.