*Clean up summon code.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-05-03 10:45:34 -05:00
parent f9b13b45e0
commit f6e8ccb239
4 changed files with 33 additions and 58 deletions
+8 -27
View File
@@ -257,37 +257,18 @@ void TempSummon::SaveToDB()
{ {
} }
bool TempSummon::SetOwner(Unit *owner, bool apply)
{
if(apply)
{
if(!AddUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID()))
{
sLog.outCrash("Unit %u is summoned by %u but it already has a owner", GetEntry(), owner->GetEntry());
return false;
}
if(owner->GetTypeId() == TYPEID_PLAYER)
{
m_ControlledByPlayer = true;
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
}
}
else
{
if(!RemoveUInt64Value(UNIT_FIELD_SUMMONEDBY, owner->GetGUID()))
{
sLog.outCrash("Unit %u is unsummoned by %u but it has another owner", GetEntry(), owner->GetEntry());
return false;
}
}
return true;
}
Minion::Minion(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon(properties, owner) Minion::Minion(SummonPropertiesEntry const *properties, Unit *owner) : TempSummon(properties, owner)
, m_owner(owner) , m_owner(owner)
{ {
assert(m_owner);
m_summonMask |= SUMMON_MASK_MINION; m_summonMask |= SUMMON_MASK_MINION;
SetUInt64Value(UNIT_FIELD_SUMMONEDBY, m_owner->GetGUID());
if(m_owner->GetTypeId() == TYPEID_PLAYER)
{
m_ControlledByPlayer = true;
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
}
} }
void Minion::InitSummon(uint32 duration) void Minion::InitSummon(uint32 duration)
+1 -3
View File
@@ -38,8 +38,6 @@ class TempSummon : public Creature
uint64 const& GetSummonerGUID() { return m_summonerGUID; } uint64 const& GetSummonerGUID() { return m_summonerGUID; }
SummonPropertiesEntry const *m_Properties; SummonPropertiesEntry const *m_Properties;
bool SetOwner(Unit *owner, bool apply);
private: private:
TempSummonType m_type; TempSummonType m_type;
uint32 m_timer; uint32 m_timer;
@@ -55,7 +53,7 @@ class Minion : public TempSummon
void RemoveFromWorld(); void RemoveFromWorld();
Unit *GetOwner() { return m_owner; } Unit *GetOwner() { return m_owner; }
protected: protected:
Unit *m_owner; Unit * const m_owner;
}; };
class Guardian : public Minion class Guardian : public Minion
+19 -22
View File
@@ -110,35 +110,32 @@ void Totem::UnSummon()
CombatStop(); CombatStop();
RemoveAurasDueToSpell(GetSpell()); RemoveAurasDueToSpell(GetSpell());
Unit *owner = GetOwner();
if (owner) // clear owenr's totem slot
for(int i = SUMMON_SLOT_TOTEM; i < MAX_TOTEM_SLOT; ++i)
{ {
// clear owenr's totem slot if(m_owner->m_SummonSlot[i]==GetGUID())
for(int i = SUMMON_SLOT_TOTEM; i < MAX_TOTEM_SLOT; ++i)
{ {
if(owner->m_SummonSlot[i]==GetGUID()) m_owner->m_SummonSlot[i] = 0;
{ break;
owner->m_SummonSlot[i] = 0;
break;
}
} }
}
owner->RemoveAurasDueToSpell(GetSpell()); m_owner->RemoveAurasDueToSpell(GetSpell());
//remove aura all party members too //remove aura all party members too
Group *pGroup = NULL; Group *pGroup = NULL;
if (owner->GetTypeId() == TYPEID_PLAYER) if (m_owner->GetTypeId() == TYPEID_PLAYER)
{
// Not only the player can summon the totem (scripted AI)
pGroup = ((Player*)m_owner)->GetGroup();
if (pGroup)
{ {
// Not only the player can summon the totem (scripted AI) for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
pGroup = ((Player*)owner)->GetGroup();
if (pGroup)
{ {
for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next()) Player* Target = itr->getSource();
{ if(Target && pGroup->SameSubGroup((Player*)m_owner, Target))
Player* Target = itr->getSource(); Target->RemoveAurasDueToSpell(GetSpell());
if(Target && pGroup->SameSubGroup((Player*)owner, Target))
Target->RemoveAurasDueToSpell(GetSpell());
}
} }
} }
} }
+5 -6
View File
@@ -8143,12 +8143,14 @@ Unit* Unit::GetCharm() const
void Unit::SetMinion(Minion *minion, bool apply) void Unit::SetMinion(Minion *minion, bool apply)
{ {
sLog.outDebug("SetMinion %u for %u, apply %u", minion->GetEntry(), GetEntry(), apply); sLog.outDebug("SetMinion %u for %u, apply %u", minion->GetEntry(), GetEntry(), apply);
if(minion->GetOwnerGUID() != GetGUID())
{
sLog.outCrash("SetMinion: Minion %u is not the minion of owner %u", minion->GetEntry(), GetEntry());
return;
}
if(apply) if(apply)
{ {
if(!minion->SetOwner(this, true))
return;
m_Controlled.insert(minion); m_Controlled.insert(minion);
// Can only have one pet. If a new one is summoned, dismiss the old one. // Can only have one pet. If a new one is summoned, dismiss the old one.
@@ -8204,9 +8206,6 @@ void Unit::SetMinion(Minion *minion, bool apply)
} }
else else
{ {
if(!minion->SetOwner(this, false))
return;
m_Controlled.erase(minion); m_Controlled.erase(minion);
if(minion->isPet() || minion->m_Properties && minion->m_Properties->Category == SUMMON_CATEGORY_PET) if(minion->isPet() || minion->m_Properties && minion->m_Properties->Category == SUMMON_CATEGORY_PET)