using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using Clio.Utilities; using Clio.XmlEngine; using ff14bot.Behavior; using ff14bot.Helpers; using ff14bot.Managers; using ff14bot.Navigation; using ff14bot.NeoProfiles; using ff14bot.RemoteWindows; using TreeSharp; using Action = TreeSharp.Action; namespace ff14bot.NeoProfile { [XmlElement("UseItemNPC")] public class UseItemNPCTag : ProfileBehavior { private bool _done; public bool useditem = false; [Clio.XmlEngine.XmlAttribute("XYZ")] public Vector3 XYZ { get { return Position; } set { Position = value; } } public Vector3 Position; [XmlAttribute("Name")] public string Name { get; set; } [XmlAttribute("ItemID")] public uint ItemID { get; set; } [XmlAttribute("NPCID")] public uint NPC { get; set; } [DefaultValue(0)] [XmlAttribute("DestinationID")] public int DestinationID { get; set; } [DefaultValue(3)] [XmlAttribute("Distance")] public float Distance { get; set; } public override bool IsDone { get { return _done; } } private bool IsFinished { get { var unit = GameObjectManager.GetObjectByNPCId(NPC); if (unit != null) { return !unit.IsVisible; } return true; } } protected Composite Behavior() { return new PrioritySelector( new Decorator(ret => Core.Me.Location.Distance(Position) <= Distance && IsFinished && useditem, new Action(ret => _done = true)), new Decorator(ret => Talk.DialogOpen, new Action(r => { Talk.Next(); } )), new Decorator(ret => !useditem && Core.Player.InCombat && Core.Me.Location.Distance(Position) <= Distance, new Action(r => { foreach (BagSlot item in InventoryManager.FilledSlots) { if (item.RawItemId == ItemID) { item.UseItem(GameObjectManager.GetObjectByNPCId(NPC)); useditem = true; } } } )), new Decorator(ret => Core.Me.Location.Distance(Position) <= Distance, new Action(r => { Navigator.PlayerMover.MoveStop(); GameObjectManager.GetObjectByNPCId(Convert.ToUInt32(DestinationID)).Interact(); } )), CommonBehaviors.MoveAndStop(ret => Position, Distance, stopInRange: true, destinationName: Name), new ActionAlwaysSucceed() ); } /// /// This gets called when a while loop starts over so reset anything that is used inside the IsDone check /// protected override void OnResetCachedDone() { _done = false; } private Composite _cache; protected override void OnStart() { //We need to cache the behaviors creation because we use the GUID to remove it later. _cache = Behavior(); TreeHooks.Instance.InsertHook("TreeStart", 0, _cache); } protected override void OnDone() { TreeHooks.Instance.RemoveHook("TreeStart", _cache); } } }