/// <summary> /// Ensure that the constraints are correct for the Flag aura to be applied /// </summary> protected override void CheckInitialize(CasterInfo casterInfo, Unit target, ref SpellFailedReason failReason) { if (!(target is Character)) { failReason = SpellFailedReason.BadTargets; } else { Instance = target.Region as WarsongGulch; if (Instance == null) { failReason = SpellFailedReason.IncorrectArea; } } }
/// <summary> /// Creates a new AreaAura which applies its effects to everyone in its radius of influence /// </summary> protected void Init(WorldObject holder, Spell spell) { m_holder = holder; if (holder is DynamicObject) { m_casterInfo = holder.Master.CasterInfo; } else { m_casterInfo = holder.CasterInfo; } m_spell = spell; if (spell.IsAreaAura) { m_targets = new Dictionary<Unit, Aura>(); } if (holder.AreaAura != null) { holder.AreaAura.Remove(true); } holder.AreaAura = this; }
public AuraIndexId GetAuraUID(CasterInfo caster, WorldObject target) { return GetAuraUID(IsBeneficialFor(caster, target)); }
public static void WriteChanneledSpells() { List<Spell> spells = new List<Spell>(1000); foreach (Spell spell in SpellHandler.ById) { if (spell == null) continue; if (spell.IsChanneled) { spells.Add(spell); } } using (var writer = new StreamWriter(ToolConfig.OutputDir + "ChanneledSpells.txt", false)) { var caster = new CasterInfo(); foreach (var spell in spells) { writer.WriteLine("Spell: " + spell); bool hasAmpl = false; bool hasCustomScript = false; foreach (SpellEffect effect in spell.Effects) { effect.DumpInfo(writer, "\t"); hasAmpl = hasAmpl || effect.Amplitude > 0; hasCustomScript = hasCustomScript || effect.IsScripted; } if (spell.GetDuration(caster, null) < 1) { Console.WriteLine(spell); } writer.WriteLine(); writer.WriteLine(); } } }
public static AuraEffectHandler CreateEffectHandler( SpellEffect spellEffect, CasterInfo caster, Unit target, int effectValue, ref SpellFailedReason failedReason) { var handler = spellEffect.AuraEffectHandlerCreator(); handler.m_spellEffect = spellEffect; handler.BaseEffectValue = effectValue; handler.CheckInitialize(caster, target, ref failedReason); return handler; }
public static List<AuraEffectHandler> CreateEffectHandlers(SpellEffect[] effects, CasterInfo caster, Unit target, bool beneficial) { if (effects == null) return null; try { List<AuraEffectHandler> effectHandlers = null; var failReason = SpellFailedReason.Ok; for (var i = 0; i < effects.Length; i++) { var effect = effects[i]; if (effect.HarmType == HarmType.Beneficial || !beneficial) { var effectValue = effect.CalcEffectValue(caster); var effectHandler = CreateEffectHandler(effect, caster, target, effectValue, ref failReason); if (failReason != SpellFailedReason.Ok) { return null; } if (effectHandlers == null) { effectHandlers = new List<AuraEffectHandler>(3); } effectHandlers.Add(effectHandler); } } return effectHandlers; } catch (Exception e) { LogUtil.ErrorException(e, "Failed to create AuraEffectHandlers for: " + effects.GetWhere(effect => effect != null).Spell); return null; } }
public int CalcEffectValue(CasterInfo casterInfo) { var caster = casterInfo.Caster; if (caster is Unit) { return CalcEffectValue((Unit)caster); } else { return CalcEffectValue(casterInfo.Level, 0); } }
public bool IsBeneficialFor(CasterInfo casterInfo, WorldObject target) { return HarmType == HarmType.Beneficial || (HarmType == HarmType.Neutral && (casterInfo.Caster == null || !casterInfo.Caster.MayAttack(target))); }
/// <summary> /// Stack or removes the given Aura, if possible. /// Returns whether the given incompatible Aura was removed or stacked. /// <param name="err">Ok, if stacked or no incompatible Aura was found</param> /// </summary> public static bool CheckStackOrOverride(Aura oldAura, CasterInfo caster, Spell spell, ref SpellFailedReason err) { if (oldAura.Spell.IsPreventionDebuff) { err = SpellFailedReason.AuraBounced; return false; } if (oldAura.Spell.CanStack && oldAura.Spell == spell) { // stack aura oldAura.Stack(caster); } else { if (caster == oldAura.CasterInfo) { if (spell != oldAura.Spell && spell.AuraCasterGroup != null && spell.AuraCasterGroup == oldAura.Spell.AuraCasterGroup && spell.AuraCasterGroup.Count > 1) { err = SpellFailedReason.AuraBounced; return false; } } else if (!spell.CanOverride(oldAura.Spell)) { err = SpellFailedReason.AuraBounced; return false; } // cancel previously existing Aura return oldAura.TryRemove(true); } return false; }
/// <summary> /// Stack or removes the Aura represented by the given spell, if possible. /// Returns true if there is no incompatible Aura or if it could be removed. /// <param name="err">Ok, if stacked or no incompatible Aura is blocking a new Aura</param> /// </summary> public bool CheckStackOrOverride(CasterInfo caster, AuraIndexId id, Spell spell, ref SpellFailedReason err) { var oldAura = GetAura(caster, id, spell); if (oldAura != null) { return CheckStackOrOverride(oldAura, caster, spell, ref err); } return true; }
/// <summary> /// Adds a new Aura with the given information to the Owner. /// Does not initialize the new Aura. /// If you use this method, make sure to call <c>Start()</c> on the newly created Aura. /// Overrides any existing Aura that matches. /// </summary> /// <returns>null if Spell is not an Aura</returns> public Aura AddAura(CasterInfo casterInfo, Spell spell, List<AuraEffectHandler> handlers, bool beneficial) { // create new Aura // Get an index for the aura var index = GetFreeIndex(beneficial); if (index == InvalidIndex) { // no more free index fields return null; } var aura = new Aura(this, casterInfo, spell, handlers, index, beneficial); AddAura(aura, false); return aura; }
/// <summary> /// Applies the given spell as a buff or debuff. /// Also initializes the new Aura. /// </summary> /// <returns>null if Spell is not an Aura</returns> public Aura AddAura(CasterInfo caster, Spell spell, bool noTimeout) { try { var beneficial = spell.IsBeneficialFor(caster, m_owner); var id = spell.GetAuraUID(beneficial); var err = SpellFailedReason.Ok; // check for existing auras & stacking var oldAura = GetAura(caster, id, spell); if (oldAura != null) { if (!CheckStackOrOverride(oldAura, caster, spell, ref err)) { if (err == SpellFailedReason.Ok) { // Stacked return oldAura; } if (caster.Caster is Character) { SpellHandler.SendCastFailed((Character)caster.Caster, 0, spell, err); } return null; } } // create new Aura var handlers = AuraHandler.CreateEffectHandlers(spell, caster, m_owner, beneficial); if (handlers != null) { var aura = AddAura(caster, spell, handlers, beneficial); if (aura != null) { aura.Start(null, noTimeout); } return aura; } } catch (Exception ex) { LogUtil.ErrorException(ex, "Unable to Add Aura {0} to {1}", spell, m_owner); } return null; }
/// <summary> /// Get an Aura that is incompatible with the one represented by the given spell. /// </summary> /// <returns>Whether or not another Aura may be applied</returns> public Aura GetAura(CasterInfo caster, AuraIndexId id, Spell spell) { var oldAura = this[id]; if (oldAura != null) { return oldAura; } else { // no aura found // check for per-caster-restrictions if (spell.AuraCasterGroup != null) { var count = 0; foreach (var aura in m_AuraArray) { if (aura.CasterInfo.CasterId == caster.CasterId && spell.AuraCasterGroup == aura.Spell.AuraCasterGroup) { count++; if (count >= spell.AuraCasterGroup.MaxCount) { return aura; } } } } } return null; }
/// <summary> /// /// Check whether this handler can be applied to the given target /// </summary> protected internal virtual void CheckInitialize(CasterInfo casterInfo, Unit target, ref SpellFailedReason failReason) { }
/// <summary> /// Returns the max duration for this Spell in milliseconds, /// including all modifiers. /// </summary> public int GetDuration(CasterInfo caster) { return GetDuration(caster, null); }
/// <summary> /// Returns the max duration for this Spell in milliseconds, /// including all modifiers. /// </summary> public int GetDuration(CasterInfo caster, Unit target) { var millis = Durations.Min; //if (Durations.LevelDelta > 0) //{ // millis += (int)caster.Level * Durations.LevelDelta; // if (Durations.Max > 0 && millis > Durations.Max) // { // millis = Durations.Max; // } //} if (Durations.Max > Durations.Min && IsFinishingMove && caster.CasterUnit != null) { // For some finishing moves, Duration depends on Combopoints millis += caster.CasterUnit.ComboPoints * ((Durations.Max - Durations.Min) / 5); } if (target != null && Mechanic != SpellMechanic.None) { var mod = target.GetMechanicDurationMod(Mechanic); if (mod != 0) { millis = UnitUpdates.GetMultiMod(mod / 100f, millis); } } var chr = caster.Caster as Character; if (chr != null) { millis = chr.PlayerSpells.GetModifiedInt(SpellModifierType.Duration, this, millis); } return millis; }
public static List<AuraEffectHandler> CreateEffectHandlers(Spell spell, CasterInfo caster, Unit target, bool beneficial) { return CreateEffectHandlers(spell.AuraEffects, caster, target, beneficial); }
public bool IsHarmfulFor(CasterInfo casterInfo, WorldObject target) { return HarmType == HarmType.Harmful || (HarmType == HarmType.Neutral && casterInfo.Caster != null && casterInfo.Caster.MayAttack(target)); }
protected override void CheckInitialize(CasterInfo casterInfo, Unit target, ref SpellFailedReason failReason) { if (target is Character) { var chr = (Character)target; var ap = target.TotalMeleeAP; var sp = chr.GetDamageDoneMod(DamageSchool.Holy); if (ap > sp) { totalBonus = ap; } else { totalBonus = sp; } } }