So i've been having some issues with performance drops, when checking for Auras on a raid boss which is fully debuffed.
So i looked over my code, and i'm often using during this: First check if aura exist and then queuing for the actual aura to get the duration, and figured that would course alot of overhead.
And then i was like hmm, i want to make my own universal method for this, which return that the aura exists, and the actual WoWAura object.
the result:
made an enum to toggle which collection i was going to use:
The actual method:
usage:
That way with 1 lookup i get both the bool from the method's return value, and the WoWAura from the method's "Out" value.
feel free to copy paste if this is something you could use
So i looked over my code, and i'm often using during this: First check if aura exist and then queuing for the actual aura to get the duration, and figured that would course alot of overhead.
And then i was like hmm, i want to make my own universal method for this, which return that the aura exists, and the actual WoWAura object.
the result:
made an enum to toggle which collection i was going to use:
PHP:
public enum AuraSelect
{
ActiveAuras, PassiveAuras, Debuffs, Buffs, Auras, GetAllAuras, Simple
}
The actual method:
PHP:
public bool AuraExist(WoWUnit unit, WoWAura aura, bool MeIsOwner, AuraSelect AuraPlacement, out WoWAura foundAura)
{
try
{
Dictionary<string, WoWAura> collection = new Dictionary<string, WoWAura>();
WoWAura _aura = null;
if (unit == null || aura == null)
{
foundAura = null;
return false;
}
switch (AuraPlacement)
{
case AuraSelect.ActiveAuras:
collection = unit.ActiveAuras;
break;
case AuraSelect.PassiveAuras:
collection = unit.PassiveAuras;
break;
case AuraSelect.Debuffs:
collection = unit.Debuffs;
break;
case AuraSelect.Buffs:
collection = unit.Buffs;
break;
case AuraSelect.Auras:
collection = unit.Auras;
break;
case AuraSelect.GetAllAuras:
collection = unit.GetAllAuras().ToDictionary(keySelector => keySelector.Name);
break;
case AuraSelect.Simple:
foundAura = aura;
return aura != null;
}
ulong MyGuid = Me.Guid;
_aura = collection.Values.First(thisAura => thisAura.SpellId == aura.SpellId && (!MeIsOwner || thisAura.CreatorGuid == MyGuid) && (thisAura.IsPassive || thisAura.TimeLeft.TotalMilliseconds > StyxWoW.WoWClient.Latency));
foundAura = _aura;
return _aura != null;
}
catch (ArgumentNullException)
{
foundAura = null;
return false;
}
catch (Exception ex)
{
Logging.WriteException(ex);
throw;
}
}
usage:
PHP:
//GlobalVar
WoWAura AuraHolder = null;
//Usage:
!Method.AuraExist(Me.CurrentTarget, WarlockAuras.UnstableAffliction(), true, AuraSelect.Debuffs, out AuraHolder) || AuraHolder.TimeLeft.TotalMilliseconds < WarlockSpells.UnstableAffliction.CastTime
//cast if not Exist, or if its about to expire
That way with 1 lookup i get both the bool from the method's return value, and the WoWAura from the method's "Out" value.
feel free to copy paste if this is something you could use
