Core/Misc: Misc cleanups and changing of fields

This commit is contained in:
hondacrx
2018-05-13 20:26:05 -04:00
parent 868c67c8f0
commit 7d4c0b7634
38 changed files with 269 additions and 244 deletions
+2 -1
View File
@@ -2338,8 +2338,9 @@ namespace Game.Entities
vSchoolAbsorbCopy.Sort(new AbsorbAuraOrderPred());
// absorb without mana cost
foreach (var absorbAurEff in vSchoolAbsorbCopy.ToList())
for (var i = 0; i < vSchoolAbsorbCopy.Count; ++i )
{
var absorbAurEff = vSchoolAbsorbCopy[i];
if (damageInfo.GetDamage() == 0)
break;
+3 -3
View File
@@ -578,7 +578,7 @@ namespace Game.Entities
return obj.GetExactDist2dSq(i_source) <= i_distSq;
}
public override void Visit(ICollection<Player> objs)
public override void Visit(IList<Player> objs)
{
foreach (var target in objs)
{
@@ -598,7 +598,7 @@ namespace Game.Entities
}
}
public override void Visit(ICollection<Creature> objs)
public override void Visit(IList<Creature> objs)
{
foreach (var target in objs)
{
@@ -614,7 +614,7 @@ namespace Game.Entities
}
}
}
public override void Visit(ICollection<DynamicObject> objs)
public override void Visit(IList<DynamicObject> objs)
{
foreach (var target in objs)
{
+4 -2
View File
@@ -566,8 +566,9 @@ namespace Game.Entities
public void GetAllMinionsByEntry(List<TempSummon> Minions, uint entry)
{
foreach (var unit in m_Controlled)
for (var i = 0; i < m_Controlled.Count; ++i)
{
Unit unit = m_Controlled[i];
if (unit.GetEntry() == entry && unit.IsSummon()) // minion, actually
Minions.Add(unit.ToTempSummon());
}
@@ -575,8 +576,9 @@ namespace Game.Entities
void RemoveAllMinionsByEntry(uint entry)
{
foreach (var unit in m_Controlled.ToList())
for (var i = 0; i < m_Controlled.Count; ++i)
{
Unit unit = m_Controlled[i];
if (unit.GetEntry() == entry && unit.IsTypeId(TypeId.Unit)
&& unit.ToCreature().IsSummon()) // minion, actually
unit.ToTempSummon().UnSummon();
+48 -39
View File
@@ -2290,11 +2290,11 @@ namespace Game.Entities
public void RemoveAllGroupBuffsFromCaster(ObjectGuid casterGUID)
{
foreach (var iter in m_ownedAuras.KeyValueList)
foreach (var pair in GetOwnedAuras())
{
Aura aura = iter.Value;
Aura aura = pair.Value;
if (aura.GetCasterGUID() == casterGUID && aura.GetSpellInfo().IsGroupBuff())
RemoveOwnedAura(iter);
RemoveOwnedAura(pair);
}
}
@@ -3345,20 +3345,19 @@ namespace Game.Entities
// Such situation occurs when player is logging in inside an instance and fails the entry check for any reason.
// The aura that was loaded from db (indirectly, via linked casts) gets removed before it has a chance
// to register in m_appliedAuras
var list = GetOwnedAuras().ToList();
for (var i = 0; i < list.Count; i++)
foreach (var pair in GetOwnedAuras())
{
Aura aura = list[i].Value;
Aura aura = pair.Value;
if (aura.GetCasterGUID() != GetGUID() && aura.IsSingleTarget())
{
if (onPhaseChange)
RemoveOwnedAura(list[i]);
RemoveOwnedAura(pair);
else
{
Unit caster = aura.GetCaster();
if (!caster || !caster.IsInPhase(this))
RemoveOwnedAura(list[i]);
RemoveOwnedAura(pair);
}
}
}
@@ -3372,12 +3371,13 @@ namespace Game.Entities
}
}
// All aura base removes should go threw this function!
public void RemoveOwnedAura(KeyValuePair<uint, Aura> pair, AuraRemoveMode removeMode = AuraRemoveMode.Default)
public void RemoveOwnedAura(KeyValuePair<uint, Aura> keyValuePair, AuraRemoveMode removeMode = AuraRemoveMode.Default)
{
Aura aura = pair.Value;
Aura aura = keyValuePair.Value;
Contract.Assert(!aura.IsRemoved());
m_ownedAuras.Remove(pair);
m_ownedAuras.Remove(keyValuePair);
m_removedAuras.Add(aura);
// Unregister single target aura
@@ -3388,32 +3388,37 @@ namespace Game.Entities
}
public void RemoveOwnedAura(uint spellId, ObjectGuid casterGUID = default(ObjectGuid), uint reqEffMask = 0, AuraRemoveMode removeMode = AuraRemoveMode.Default)
{
var list = m_ownedAuras.Where(p => p.Key == spellId);
foreach (var pair in list.ToList())
foreach (var pair in GetOwnedAuras())
{
if (pair.Key != spellId)
continue;
if (((pair.Value.GetEffectMask() & reqEffMask) == reqEffMask) && (casterGUID.IsEmpty() || pair.Value.GetCasterGUID() == casterGUID))
RemoveOwnedAura(pair, removeMode);
}
}
public void RemoveOwnedAura(Aura aura, AuraRemoveMode removeMode = AuraRemoveMode.Default)
public void RemoveOwnedAura(Aura auraToRemove, AuraRemoveMode removeMode = AuraRemoveMode.Default)
{
if (aura.IsRemoved())
if (auraToRemove.IsRemoved())
return;
Contract.Assert(aura.GetOwner() == this);
Contract.Assert(auraToRemove.GetOwner() == this);
if (removeMode == AuraRemoveMode.None)
{
Log.outError(LogFilter.Spells, "Unit.RemoveOwnedAura() called with unallowed removeMode AURA_REMOVE_NONE, spellId {0}", aura.GetId());
Log.outError(LogFilter.Spells, "Unit.RemoveOwnedAura() called with unallowed removeMode AURA_REMOVE_NONE, spellId {0}", auraToRemove.GetId());
return;
}
uint spellId = aura.GetId();
uint spellId = auraToRemove.GetId();
var range = m_ownedAuras.Where(p => p.Key == spellId);
foreach (var pair in range.ToList())
var range = m_ownedAuras.LookupByKey(spellId);
foreach (var pair in GetOwnedAuras())
{
if (pair.Value == aura)
if (pair.Key != spellId)
continue;
if (pair.Value == auraToRemove)
{
RemoveOwnedAura(pair, removeMode);
return;
@@ -3425,25 +3430,27 @@ namespace Game.Entities
public void RemoveAurasDueToSpell(uint spellId, ObjectGuid casterGUID = default(ObjectGuid), uint reqEffMask = 0, AuraRemoveMode removeMode = AuraRemoveMode.Default)
{
var list = m_appliedAuras.LookupByKey(spellId);
if (list.Empty())
return;
foreach (var spell in list.ToList())
foreach (var pair in GetAppliedAuras())
{
Aura aura = spell.GetBase();
if (((aura.GetEffectMask() & reqEffMask) == reqEffMask)
&& (casterGUID.IsEmpty() || aura.GetCasterGUID() == casterGUID))
if (pair.Key != spellId)
continue;
Aura aura = pair.Value.GetBase();
if (((aura.GetEffectMask() & reqEffMask) == reqEffMask) && (casterGUID.IsEmpty() || aura.GetCasterGUID() == casterGUID))
{
RemoveAura(spell, removeMode);
RemoveAura(pair, removeMode);
}
}
}
public void RemoveAurasDueToSpellByDispel(uint spellId, uint dispellerSpellId, ObjectGuid casterGUID, Unit dispeller, byte chargesRemoved = 1)
{
var range = m_ownedAuras.LookupByKey(spellId);
foreach (var aura in range)
foreach (var pair in GetOwnedAuras())
{
if (pair.Key != spellId)
continue;
Aura aura = pair.Value;
if (aura.GetCasterGUID() == casterGUID)
{
DispelInfo dispelInfo = new DispelInfo(dispeller, dispellerSpellId, chargesRemoved);
@@ -3458,7 +3465,6 @@ namespace Game.Entities
// Call AfterDispel hook on AuraScript
aura.CallScriptAfterDispel(dispelInfo);
return;
}
}
@@ -3523,7 +3529,7 @@ namespace Game.Entities
uint spellId = aurApp.GetBase().GetId();
var range = m_appliedAuras.Where(p => p.Key == spellId);
foreach (var pair in range.ToList())
foreach (var pair in range)
{
if (aurApp == pair.Value)
{
@@ -3568,7 +3574,7 @@ namespace Game.Entities
public void RemoveAppliedAuras(Func<AuraApplication, bool> check)
{
foreach (var pair in m_appliedAuras.KeyValueList)
foreach (var pair in GetAppliedAuras())
{
if (check(pair.Value))
RemoveAura(pair);
@@ -3577,7 +3583,7 @@ namespace Game.Entities
public void RemoveOwnedAuras(Func<Aura, bool> check)
{
foreach (var pair in m_ownedAuras)
foreach (var pair in GetOwnedAuras())
{
if (check(pair.Value))
RemoveOwnedAura(pair);
@@ -3627,7 +3633,7 @@ namespace Game.Entities
foreach (var pair in GetOwnedAuras())
{
var appMap = pair.Value.GetApplicationMap();
foreach (var aurApp in appMap.Values.ToList())
foreach (var aurApp in appMap.Values)
{
Unit target = aurApp.GetTarget();
if (target == this)
@@ -3681,6 +3687,7 @@ namespace Game.Entities
{
if (pair.Value == null)
continue;
Aura aura = pair.Value;
if (!aura.GetSpellInfo().HasAura(GetMap().GetDifficultyID(), type))
RemoveOwnedAura(pair, AuraRemoveMode.Default);
@@ -4174,9 +4181,10 @@ namespace Game.Entities
}
bool remove = false;
for (var i = 0; i < m_appliedAuras.KeyValueList.Count; i++)
var appliedAuraList = GetAppliedAuras();
for (var i = 0; i < appliedAuraList.Count; i++)
{
var app = m_appliedAuras.KeyValueList[i];
var app = appliedAuraList[i];
if (remove)
{
remove = false;
@@ -4187,8 +4195,9 @@ namespace Game.Entities
continue;
RemoveAura(app, AuraRemoveMode.Default);
if (i == m_appliedAuras.KeyValueList.Count - 1)
if (i == appliedAuraList.Count - 1)
break;
remove = true;
}
}
+11 -6
View File
@@ -202,14 +202,15 @@ namespace Game.Entities
Aura i_aura = app.Value;
if (i_aura == null)
continue;
i_aura.UpdateOwner(diff, this);
}
// remove expired auras - do that after updates(used in scripts?)
foreach (var aura in GetOwnedAuras())
foreach (var pair in GetOwnedAuras())
{
if (aura.Value != null && aura.Value.IsExpired())
RemoveOwnedAura(aura, AuraRemoveMode.Expire);
if (pair.Value != null && pair.Value.IsExpired())
RemoveOwnedAura(pair, AuraRemoveMode.Expire);
}
foreach (var aura in m_visibleAurasToUpdate)
@@ -221,8 +222,9 @@ namespace Game.Entities
if (!m_gameObj.Empty())
{
foreach (var go in m_gameObj.ToList())
for (var i = 0; i < m_gameObj.Count; ++i)
{
GameObject go = m_gameObj[i];
if (!go.isSpawned())
{
go.SetOwnerGUID(ObjectGuid.Empty);
@@ -547,8 +549,9 @@ namespace Game.Entities
public void RemoveDynObject(uint spellId)
{
foreach (var dynObj in m_dynObj.ToList())
for (var i = 0; i < m_dynObj.Count; ++i)
{
var dynObj = m_dynObj[i];
if (dynObj.GetSpellId() == spellId)
dynObj.Remove();
}
@@ -699,8 +702,9 @@ namespace Game.Entities
if (m_areaTrigger.Empty())
return;
foreach (var areaTrigger in m_areaTrigger.ToList())
for (var i = 0; i < m_areaTrigger.Count; ++i)
{
AreaTrigger areaTrigger = m_areaTrigger[i];
if (areaTrigger.GetSpellId() == spellId)
areaTrigger.Remove();
}
@@ -710,6 +714,7 @@ namespace Game.Entities
{
if (m_areaTrigger.Empty())
return;
foreach (AreaTrigger areaTrigger in m_areaTrigger)
{
if (areaTrigger.GetAuraEffect() == aurEff)