public static Composite Buff(SimpleStringDelegate name, TimeSpan expires, UnitSelectionDelegate onUnit = null, SimpleBooleanDelegate require = null, bool myBuff = true, HasGcd gcd = HasGcd.Yes, params string[] buffNames) { if (onUnit == null) onUnit = u => Me.CurrentTarget; if (require == null) require = req => true; return new Decorator( ret => { if (onUnit == null || name == null || require == null) return false; _buffUnit = onUnit(ret); if (_buffUnit == null) return false; _buffName = name(ret); if (_buffName == null) return false; SpellFindResults sfr; if (!SpellManager.FindSpell(_buffName, out sfr)) { AddUndefinedSpell(_buffName); return false; } WoWSpell spell = sfr.Override ?? sfr.Original; _buffName = spell.Name; if (DoubleCastContains(_buffUnit, _buffName)) return false; if (!spell.CanCast && (sfr.Override == null || !sfr.Original.CanCast)) { if (SingularSettings.DebugSpellCasting) Logger.WriteFile("BuffCanCast[{0}]: spell specific CanCast failed (#{1})", spell.Name, spell.Id); return false; } bool hasExpired; if (!buffNames.Any()) { hasExpired = _buffUnit.HasAuraExpired(_buffName, expires, myBuff); if (SingularSettings.DebugSpellCasting) { if (hasExpired ) Logger.WriteDebug("Buff=expired: '{0}')={1}: hasspell={2}, auraleft={3:F1} secs", _buffName, hasExpired, SpellManager.HasSpell(_buffName).ToYN(), _buffUnit.GetAuraTimeLeft(_buffName, true).TotalSeconds); else Logger.WriteDebug("Buff=present: '{0}')={1}: hasspell={2}, auraleft={3:F1} secs", _buffName, hasExpired, SpellManager.HasSpell(_buffName).ToYN(), _buffUnit.GetAuraTimeLeft(_buffName, true).TotalSeconds); } return hasExpired; } hasExpired = SpellManager.HasSpell(_buffName) && buffNames.All(b => _buffUnit.HasKnownAuraExpired(b, expires, myBuff)); if (hasExpired && SingularSettings.DebugSpellCasting) Logger.WriteDebug("Spell.Buff(r=>'{0}')={1}: hasspell={2}, all auras less than {3:F1} secs", _buffName, hasExpired, SpellManager.HasSpell(_buffName).ToYN(), expires.TotalSeconds); return hasExpired; }, new Sequence( // new Action(ctx => _lastBuffCast = name), Cast(sp => _buffName, chkMov => true, onUnit, require, cancel => false /* causes cast to complete */, gcd: gcd ), new Action(ret => UpdateDoubleCast( _buffName, _buffUnit)) ) ); }
public static Composite Buff(SimpleStringDelegate name, bool myBuff, UnitSelectionDelegate onUnit, SimpleBooleanDelegate requirements, int expirSecs, params string[] buffNames) { return new Decorator( ret => { if (onUnit == null || name == null || requirements == null) return false; _buffUnit = onUnit(ret); if (_buffUnit == null) return false; _buffName = name(ret); if (_buffName == null) return false; if (DoubleCastPreventionDict.Contains(_buffUnit, _buffName)) return false; bool hasExpired; if (!buffNames.Any()) { hasExpired = _buffUnit.HasAuraExpired(_buffName, expirSecs, myBuff); if (hasExpired && SingularSettings.Debug) Logger.WriteDebug("Spell.Buff(r=>'{0}'): hasspell={1}, auraleft={2:F1} secs", _buffName, SpellManager.HasSpell(_buffName).ToYN(), _buffUnit.GetAuraTimeLeft(_buffName, true).TotalSeconds); return hasExpired; } hasExpired = SpellManager.HasSpell(_buffName) && buffNames.All(b => _buffUnit.HasKnownAuraExpired(b, expirSecs, myBuff)); if (hasExpired && SingularSettings.Debug) Logger.WriteDebug("Spell.Buff(r=>'{0}'): hasspell={1}, all auras less than {2:F1} secs", _buffName, SpellManager.HasSpell(_buffName).ToYN(), expirSecs ); return hasExpired; }, new Sequence( // new Action(ctx => _lastBuffCast = name), Cast(name, chkMov => true, onUnit, requirements, cancel => false /* causes cast to complete */ ), new Action(ret => UpdateDoubleCastDict(name(ret), onUnit(ret))) ) ); }