*Clean up summon code.
--HG-- branch : trunk
This commit is contained in:
@@ -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)
|
||||
, m_owner(owner)
|
||||
{
|
||||
assert(m_owner);
|
||||
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)
|
||||
|
||||
@@ -38,8 +38,6 @@ class TempSummon : public Creature
|
||||
uint64 const& GetSummonerGUID() { return m_summonerGUID; }
|
||||
|
||||
SummonPropertiesEntry const *m_Properties;
|
||||
|
||||
bool SetOwner(Unit *owner, bool apply);
|
||||
private:
|
||||
TempSummonType m_type;
|
||||
uint32 m_timer;
|
||||
@@ -55,7 +53,7 @@ class Minion : public TempSummon
|
||||
void RemoveFromWorld();
|
||||
Unit *GetOwner() { return m_owner; }
|
||||
protected:
|
||||
Unit *m_owner;
|
||||
Unit * const m_owner;
|
||||
};
|
||||
|
||||
class Guardian : public Minion
|
||||
|
||||
+19
-22
@@ -110,35 +110,32 @@ void Totem::UnSummon()
|
||||
|
||||
CombatStop();
|
||||
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
|
||||
for(int i = SUMMON_SLOT_TOTEM; i < MAX_TOTEM_SLOT; ++i)
|
||||
if(m_owner->m_SummonSlot[i]==GetGUID())
|
||||
{
|
||||
if(owner->m_SummonSlot[i]==GetGUID())
|
||||
{
|
||||
owner->m_SummonSlot[i] = 0;
|
||||
break;
|
||||
}
|
||||
m_owner->m_SummonSlot[i] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
owner->RemoveAurasDueToSpell(GetSpell());
|
||||
m_owner->RemoveAurasDueToSpell(GetSpell());
|
||||
|
||||
//remove aura all party members too
|
||||
Group *pGroup = NULL;
|
||||
if (owner->GetTypeId() == TYPEID_PLAYER)
|
||||
//remove aura all party members too
|
||||
Group *pGroup = NULL;
|
||||
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)
|
||||
pGroup = ((Player*)owner)->GetGroup();
|
||||
if (pGroup)
|
||||
for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
|
||||
{
|
||||
for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
|
||||
{
|
||||
Player* Target = itr->getSource();
|
||||
if(Target && pGroup->SameSubGroup((Player*)owner, Target))
|
||||
Target->RemoveAurasDueToSpell(GetSpell());
|
||||
}
|
||||
Player* Target = itr->getSource();
|
||||
if(Target && pGroup->SameSubGroup((Player*)m_owner, Target))
|
||||
Target->RemoveAurasDueToSpell(GetSpell());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -8143,12 +8143,14 @@ Unit* Unit::GetCharm() const
|
||||
void Unit::SetMinion(Minion *minion, bool 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(!minion->SetOwner(this, true))
|
||||
return;
|
||||
|
||||
m_Controlled.insert(minion);
|
||||
|
||||
// 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
|
||||
{
|
||||
if(!minion->SetOwner(this, false))
|
||||
return;
|
||||
|
||||
m_Controlled.erase(minion);
|
||||
|
||||
if(minion->isPet() || minion->m_Properties && minion->m_Properties->Category == SUMMON_CATEGORY_PET)
|
||||
|
||||
Reference in New Issue
Block a user