Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Windows.Forms;
- using ff14bot;
- using ff14bot.Behavior;
- using ff14bot.Helpers;
- using ff14bot.Managers;
- using ff14bot.Objects;
- using TreeSharp;
- using ff14bot.AClasses;
- using Action = TreeSharp.Action;
- namespace Kupo
- {
- public abstract class KupoRoutine : CombatRoutine
- {
- public override sealed string Name { get { return "Kupo [" + GetType().Name + "]"; } }
- #region CombatRoutine implementation
- private Composite _heal, _combat, _preCombatbuffs,_combatbuffs, _pull;
- public override void Pulse()
- {
- Extensions.DoubleCastPreventionDict.RemoveAll(t => DateTime.UtcNow > t);
- }
- public sealed override Composite HealBehavior
- {
- get { return _heal ?? (_heal = CreateHeal()); }
- }
- public sealed override Composite CombatBehavior
- {
- get
- {
- return _combat ?? (_combat = CreateCombat());
- }
- }
- public sealed override Composite PreCombatBuffBehavior
- {
- get { return _preCombatbuffs ?? (_preCombatbuffs = CreatePreCombatBuffs()); }
- }
- public sealed override Composite CombatBuffBehavior
- {
- get
- {
- return _combatbuffs ?? (_combatbuffs = new PrioritySelector(new Action(ret => { CacheAuras(); return RunStatus.Failure; }), CreateCombatBuffs()));
- }
- }
- public sealed override Composite PullBehavior
- {
- get { return _pull ?? (_pull = CreatePull()); }
- }
- #region Aura Caching for High Performance
- /* Note: This only caches auras on you, and your target. Nothing else! */
- public static IEnumerable<Aura> LocalPlayerAuras, TargetAuras;
- void CacheAuras()
- {
- LocalPlayerAuras = Core.Player.CharacterAuras;
- if (Core.Player.HasTarget)
- {
- TargetAuras = Core.Player.CurrentTargetCharacter.CharacterAuras;
- }
- }
- #endregion
- #region Hidden Overrides
- public sealed override void Combat(){base.Combat();}
- public sealed override void CombatBuff(){base.CombatBuff();}
- public sealed override void Death(){base.Death();}
- public sealed override void Heal(){base.Heal();}
- public sealed override Composite MoveToTargetBehavior{get{return base.MoveToTargetBehavior;}}
- public sealed override bool NeedCombatBuffs{get{return base.NeedCombatBuffs;}}
- public sealed override bool NeedDeath{get{return base.NeedDeath;}}
- public sealed override bool NeedHeal{get{return base.NeedHeal;}}
- public sealed override bool NeedPreCombatBuffs{get{return base.NeedPreCombatBuffs;}}
- public sealed override bool NeedPullBuffs{get{return base.NeedPullBuffs;}}
- public sealed override bool NeedRest{get{return base.NeedRest;}}
- public sealed override void PreCombatBuff(){base.PreCombatBuff();}
- public sealed override void Pull(){base.Pull();}
- public sealed override void Rest(){base.Rest();}
- public override void Initialize()
- {
- RegisterHotkeys();
- //CombatLogHandler.Initialize();
- }
- public override void ShutDown()
- {
- UnregisterHotkeys();
- //CombatLogHandler.Shutdown();
- }
- #endregion
- #endregion
- #region Required Implementations
- protected virtual Composite CreateCombat()
- {
- return new HookExecutor("Kupo_Combat_Root",
- "Root composite for Kupo combat. Rotations will be plugged into this hook.",
- new Action(r=> RunStatus.Failure));
- }
- protected virtual Composite CreatePreCombatBuffs()
- {
- return new HookExecutor("Kupo_PreCombatBuffs_Root",
- "Root composite for Kupo buffs. Rotations will be plugged into this hook.",
- new Action(r => RunStatus.Failure));
- }
- protected virtual Composite CreateCombatBuffs()
- {
- return new HookExecutor("Kupo_CombatBuffs_Root",
- "Root composite for Kupo buffs. Rotations will be plugged into this hook.",
- new Action(r => RunStatus.Failure));
- }
- protected virtual Composite CreateHeal()
- {
- return new HookExecutor("Kupo_Heals_Root",
- "Root composite for Kupo heals. Rotations will be plugged into this hook.",
- new Action(r => RunStatus.Failure));
- }
- protected virtual Composite CreatePull()
- {
- return new HookExecutor("Kupo_Pull_Root",
- "Root composite for Kupo pull. Rotations will be plugged into this hook.",
- new Action(r => RunStatus.Failure));
- }
- protected bool InterruptsEnabled { get; set; }
- protected virtual void UnregisterHotkeys()
- {
- //HotkeysManager.Unregister("Kupo Toggle Interrupt");
- }
- protected virtual void RegisterHotkeys()
- {
- /*HotkeysManager.Register("Kupo Toggle Interrupt",
- Keys.NumPad1,
- ModifierKeys.Alt,
- o =>
- {
- InterruptsEnabled = !InterruptsEnabled;
- Logging.Write("Interrupts enabled: " + InterruptsEnabled);
- });
- // Default this to true please. Thanks!
- InterruptsEnabled = true;*/
- }
- #endregion
- #region Unit Wrappers
- protected GameObject GetTargetMissingDebuff(GameObject near, string debuff, float distance = -1f)
- {
- return UnfriendlyUnits.FirstOrDefault(u => u.Location.Distance3D(near.Location) <= distance && !u.HasAura(debuff, true));
- }
- protected int EnemiesNearTarget(float range)
- {
- var target = Core.Player.CurrentTarget;
- if (target == null)
- return 0;
- var tarLoc = target.Location;
- return UnfriendlyUnits.Count(u => u.ObjectId != target.ObjectId && u.Location.Distance3D(tarLoc) <= range);
- }
- //protected IEnumerable<GameObject> UnfriendlyMeleeUnits { get { return UnfriendlyUnits.Where(u => Actionmanager.InSpellInRangeLOS()); } }
- protected IEnumerable<GameObject> UnfriendlyUnits
- {
- get
- {
- return
- GameObjectManager.Characters.Where(u => !u.IsDead && u.CanAttack);
- }
- }
- #endregion
- #region Spell Casting
- protected Composite Cast(string spell, Selection<bool> reqs = null, Selection<GameObject> onTarget = null,
- bool ignoreCanCast = false)
- {
- return
- new Decorator(
- ret =>
- {
- // Check reqs if its there.
- if (reqs != null && !reqs(ret))
- return false;
- // To ignore CanCast stuff (CanCast returns false while channeling, useful to be ignored for dots)
- if (!ignoreCanCast && !Actionmanager.CanCast(spell, onTarget != null ? onTarget(ret) : Core.Player.CurrentTarget))
- return false;
- return true;
- },
- new Action(ret =>
- {
- var castingSpell = Core.Player.SpellCastInfo;
- // If we're casting something other than what we should be, stop casting it. (Channeling /stopcast stuff)
- if (castingSpell != null && castingSpell.SpellData.Name != spell)
- Actionmanager.StopCasting();
- Logging.Write("Casting " + spell);
- Actionmanager.DoAction(spell, (onTarget != null ? onTarget(ret) : Core.Player.CurrentTarget));
- }));
- }
- protected Composite Apply(string spell, Selection<bool> reqs = null, Selection<GameObject> onTarget = null,
- int msLeft = 0, bool ignoreCanCast = false)
- {
- return new Decorator(ret =>
- {
- // Check reqs if its there.
- if (reqs != null && !reqs(ret))
- return false;
- // Specific target, or just our general target.
- GameObject target = onTarget != null ? onTarget(ret) : Core.Player.CurrentTarget;
- // To ignore CanCast stuff (CanCast returns false while channeling, useful to be ignored for dots)
- if (!ignoreCanCast && !Actionmanager.CanCast(spell, target))
- return false;
- if (Extensions.DoubleCastPreventionDict.Contains(target, spell))
- return false;
- // Check aura. Should be doing stackCount = 0, but 1 is more accurate.
- if (!target.HasAura(spell, true, msLeft))
- return true;
- return false;
- },
- new Action(ret =>
- {
- var castingSpell = Core.Player.SpellCastInfo;
- // If we're casting something other than what we should be, stop casting it. (Channeling /stopcast stuff)
- if (castingSpell != null && castingSpell.SpellData.Name != spell)
- Actionmanager.StopCasting();
- var unit = (onTarget != null ? onTarget(ret) : Core.Player.CurrentTarget);
- Logging.Write("Applying " + spell);
- Actionmanager.DoAction(spell, unit);
- Extensions.UpdateDoubleCastDict(spell, unit);
- }));
- }
- #endregion
- protected delegate T Selection<out T>(object context);
- }
- public static class Extensions
- {
- public static void RemoveAll<TKey, TValue>(this Dictionary<TKey, TValue> dic,
- Func<TValue, bool> predicate)
- {
- var keys = dic.Keys.Where(k => predicate(dic[k])).ToList();
- foreach (var key in keys)
- {
- dic.Remove(key);
- }
- }
- public static void UpdateDoubleCastDict(string spellName, GameObject unit)
- {
- if (unit == null)
- return;
- DateTime expir = DateTime.UtcNow + TimeSpan.FromSeconds(3);
- string key = DoubleCastKey(unit.ObjectId, spellName);
- if (DoubleCastPreventionDict.ContainsKey(key))
- DoubleCastPreventionDict[key] = expir;
- DoubleCastPreventionDict.Add(key, expir);
- }
- public static string DoubleCastKey(uint guid, string spellName)
- {
- return guid.ToString("X") + "-" + spellName;
- }
- public static string DoubleCastKey(GameObject unit, string spell)
- {
- return DoubleCastKey(unit.ObjectId, spell);
- }
- public static bool Contains(this Dictionary<string, DateTime> dict, GameObject unit, string spellName)
- {
- return dict.ContainsKey(DoubleCastKey(unit, spellName));
- }
- public static bool ContainsAny(this Dictionary<string, DateTime> dict, GameObject unit, params string[] spellNames)
- {
- return spellNames.Any(s => dict.ContainsKey(DoubleCastKey(unit, s)));
- }
- public static bool ContainsAll(this Dictionary<string, DateTime> dict, GameObject unit, params string[] spellNames)
- {
- return spellNames.All(s => dict.ContainsKey(DoubleCastKey(unit, s)));
- }
- public static readonly Dictionary<string, DateTime> DoubleCastPreventionDict = new Dictionary<string, DateTime>();
- public static Aura GetCachedAuraByName(this GameObject unit, string auraName, bool myAura = true)
- {
- Aura aura = null;
- ulong guid = myAura ? Core.Player.ObjectId : 0;
- if (unit.IsMe)
- {
- foreach (var a in KupoRoutine.LocalPlayerAuras)
- {
- if (a.Name == auraName)
- {
- if (myAura && a.CasterId != guid)
- continue;
- aura = a;
- break;
- }
- }
- }
- else if (unit.ObjectId == Core.Player.CurrentTargetObjId)
- {
- foreach (var a in KupoRoutine.TargetAuras)
- {
- if (a.Name == auraName)
- {
- if (myAura && a.CasterId != guid)
- continue;
- aura = a;
- break;
- }
- }
- }
- else
- {
- // If we only want *my* auras, then check for it.
- if (myAura)
- {
- foreach (var a in unit.ToCharacter.CharacterAuras)
- {
- if (a.Name == auraName && a.CasterId == guid)
- return a;
- }
- return null;
- }
- // Otherwise, return the first we find.
- aura = unit.ToCharacter.GetAuraByName(auraName);
- }
- return aura;
- }
- public static bool HasAura(this GameObject unit, string aura, bool isMyAura = false, int msLeft = 0)
- {
- Aura result = unit.GetCachedAuraByName(aura);
- if (result == null)
- return false;
- if (isMyAura && result.CasterId != Core.Player.ObjectId)
- return false;
- if (result.TimespanLeft.TotalMilliseconds > msLeft)
- return true;
- return false;
- }
- public static bool HasCachedAura(this GameObject unit, string aura)
- {
- return unit.GetCachedAuraByName(aura) != null;
- }
- public static TimeSpan AuraTimeLeft(this GameObject unit, string aura, bool myAura = true)
- {
- var a = unit.GetCachedAuraByName(aura);
- if (a == null)
- return TimeSpan.Zero;
- return a.TimespanLeft;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment