private WoWUnit GetNpc() { return(ObjectManager.GetObjectsOfType <WoWUnit>() .Where( u => u.IsAlive && MobIds.Contains(((int)u.Entry)) && (u.ThreatInfo.ThreatStatus > ThreatStatus.UnitNotInThreatTable || !Query.IsInCompetition(u, NonCompeteDistance))) .OrderBy(u => u.DistanceSqr) .FirstOrDefault()); }
public InteractWith(Dictionary <string, string> args) : base(args) { try { // QuestRequirement* attributes are explained here... // http://www.thebuddyforum.com/mediawiki/index.php?title=Honorbuddy_Programming_Cookbook:_QuestId_for_Custom_Behaviors // ...and also used for IsDone processing. WaitForNpcs = GetAttributeAsBoolean("WaitForNpcs", false, null) ?? true; BuyItemCount = GetAttributeAsInteger("BuyItemCount", false, 1, 1000, null) ?? 1; BuyItemId = GetAttributeAsItemId("BuyItemId", false, null) ?? 0; BuySlot = GetAttributeAsInteger("BuySlot", false, -1, 100, null) ?? -1; CollectionDistance = GetAttributeAsInteger("CollectionDistance", false, 1, 10000, null) ?? 100; GossipOptions = GetAttributeAsIntegerArray("GossipOptions", false, -1, 10, new [] { "GossipOption" }) ?? new int[0]; Loot = GetAttributeAsBoolean("Loot", false, null) ?? false; MobIds = GetNumberedAttributesAsIntegerArray("MobId", 1, 1, int.MaxValue, new [] { "MobID", "NpcId" }) ?? new int[0]; ObjType = GetAttributeAsEnum <ObjectType>("ObjectType", false, new [] { "MobType" }) ?? ObjectType.Npc; NotMoving = GetAttributeAsBoolean("NotMoving", false, null) ?? false; NumOfTimes = GetAttributeAsNumOfTimes("NumOfTimes", false, null) ?? 1; QuestId = GetAttributeAsQuestId("QuestId", false, null) ?? 0; QuestRequirementComplete = GetAttributeAsEnum <QuestCompleteRequirement>("QuestCompleteRequirement", false, null) ?? QuestCompleteRequirement.NotComplete; QuestRequirementInLog = GetAttributeAsEnum <QuestInLogRequirement>("QuestInLogRequirement", false, null) ?? QuestInLogRequirement.InLog; Range = GetAttributeAsRange("Range", false, null) ?? 4; WaitTime = GetAttributeAsWaitTime("WaitTime", false, null) ?? 3000; Existing = GetAttributeAsBoolean("Existing", false, null) ?? false; Alive = GetAttributeAsBoolean("Alive", false, null) ?? false; for (int i = 0; i < GossipOptions.Length; ++i) { GossipOptions[i] -= 1; } WoWUnit mob = ObjectManager.GetObjectsOfType <WoWUnit>() .Where(unit => MobIds.Contains((int)unit.Entry)) .FirstOrDefault(); MobName = ((mob != null) && !string.IsNullOrEmpty(mob.Name)) ? mob.Name : ("Mob(" + MobIds[0] + ")"); } catch (Exception except) { // Maintenance problems occur for a number of reasons. The primary two are... // * Changes were made to the behavior, and boundary conditions weren't properly tested. // * The Honorbuddy core was changed, and the behavior wasn't adjusted for the new changes. // In any case, we pinpoint the source of the problem area here, and hopefully it // can be quickly resolved. UtilLogMessage("error", "BEHAVIOR MAINTENANCE PROBLEM: " + except.Message + "\nFROM HERE:\n" + except.StackTrace + "\n"); IsAttributeProblem = true; } }
// Private LINQ queries... private IEnumerable <WoWObject> ViableTargets() { return(ObjectManager.GetObjectsOfType <WoWObject>(true, false) .Where(target => (target.IsValid && MobIds.Contains((int)target.Entry) && TargetAurasShowing(target, _targetAuraToButtonMap).Any() && (target.Distance < HuntingGroundRadius) && !target.IsLocallyBlacklisted() && !BlacklistIfPlayerNearby(target) && Query.IsStateMatch_IgnoreMobsInBlackspots(target, IgnoreMobsInBlackspots))) .OrderBy(target => Me.Location.SurfacePathDistance(target.Location))); }
// 24Feb2013-08:11UTC chinajade private bool IsViableForItemUse(WoWUnit wowUnit) { return (Query.IsViable(wowUnit) && wowUnit.IsAlive && wowUnit.Attackable && MobIds.Contains((int)wowUnit.Entry) && Query.IsViableForInteracting(wowUnit, IgnoreMobsInBlackspots, NonCompeteDistance) && Query.IsViableForPulling(wowUnit, IgnoreMobsInBlackspots, NonCompeteDistance) && (ItemUseAlwaysSucceeds || !wowUnit.HasAura(ItemAppliesAuraId)) && wowUnit.CollectionDistance() <= CollectionDistance); }
protected override Composite CreateBehavior() { return(_root ?? (_root = new PrioritySelector( new Decorator(c => Npc != null, new Action(c => { if (!Npc.Attackable) { Blacklist.Add(Npc.Guid, new TimeSpan(0, 5, 0)); } if ((Me.Combat && (Me.GotTarget && Me.CurrentTarget != Npc && !MobIds.Contains((int)Me.CurrentTarget.Entry)) || Me.HealthPercent < HealthPercent) || IsDone) { return RunStatus.Success; } WoWUnit lootable = ObjectManager.GetObjectsOfType <WoWUnit>().OrderBy(u => u.Distance). FirstOrDefault(u => u.Lootable); if (lootable != null) { if (!lootable.WithinInteractRange) { if (Npc.Distance < 30 && SpellManager.CanCast("Death Grip")) { SpellManager.Cast("Death Grip"); WoWMovement.MoveStop(); } else { Navigator.MoveTo(lootable.Location); } } else { lootable.Interact(); } if (Logic.Inventory.Frames.LootFrame.LootFrame.Instance != null && Logic.Inventory.Frames.LootFrame.LootFrame.Instance.IsVisible) { Logic.Inventory.Frames.LootFrame.LootFrame.Instance.LootAll(); if (Me.GotTarget) { Blacklist.Add(Me.CurrentTarget, new TimeSpan(1, 0, 0)); } Me.ClearTarget(); } return RunStatus.Running; } if (!Me.GotTarget || Me.CurrentTarget != Npc) { Npc.Target(); } if (!Npc.WithinInteractRange) { TreeRoot.GoalText = string.Format("Moving to {0}", Npc.Name); Navigator.MoveTo(WoWMathHelper.CalculatePointFrom(Me.Location, Npc.Location, 3)); } else { if (Me.IsMoving) { WoWMovement.MoveStop(); } if (!Me.IsAutoAttacking || !Me.IsSafelyFacing(ObjectManager.Me.CurrentTarget)) { TreeRoot.GoalText = string.Format("Bullying {0}", Npc.Name); Npc.Interact(); } } return RunStatus.Running; })), new Action(c => Navigator.MoveTo(Location)) ))); }
public InteractWith(Dictionary <string, string> args) : base(args) { try { // Warn of deprecated attributes... if (args.ContainsKey("BuySlot")) { LogMessage("warning", "*****\n" + "* THE BUYSLOT ATTRIBUTE IS DEPRECATED, and may be retired in a near, future release.\n" + "*\n" + "* BuySlot presents a number of problems. If a vendor presents 'seasonal' or\n" + "* limited-quantity wares, the slot number for the desired item can change.\n" + "\n" + "* Please update the profile to use *BuyItemId* attribute in preference to BuySlot.\n" + "*****"); } // QuestRequirement* attributes are explained here... // http://www.thebuddyforum.com/mediawiki/index.php?title=Honorbuddy_Programming_Cookbook:_QuestId_for_Custom_Behaviors // ...and also used for IsDone processing. BuyItemCount = GetAttributeAsNullable <int>("BuyItemCount", false, ConstrainAs.CollectionCount, null) ?? 1; BuyItemId = GetAttributeAsNullable <int>("BuyItemId", false, ConstrainAs.ItemId, null) ?? 0; BuySlot = GetAttributeAsNullable <int>("BuySlot", false, new ConstrainTo.Domain <int>(-1, 100), null) ?? -1; CollectionDistance = GetAttributeAsNullable <double>("CollectionDistance", false, ConstrainAs.Range, null) ?? 100; GossipOptions = GetAttributeAsArray <int>("GossipOptions", false, new ConstrainTo.Domain <int>(-1, 10), new[] { "GossipOption" }, null); Location = GetAttributeAsNullable <WoWPoint>("", false, ConstrainAs.WoWPointNonEmpty, null) ?? Me.Location; Loot = GetAttributeAsNullable <bool>("Loot", false, null, null) ?? false; MobIds = GetNumberedAttributesAsArray <int>("MobId", 1, ConstrainAs.MobId, new[] { "NpcId" }); ObjType = GetAttributeAsNullable <ObjectType>("ObjectType", false, null, new[] { "MobType" }) ?? ObjectType.Npc; NpcState = GetAttributeAsNullable <NpcStateType>("MobState", false, null, new[] { "NpcState" }) ?? NpcStateType.DontCare; NavigationState = GetAttributeAsNullable <NavigationType>("Nav", false, null, new[] { "Navigation" }) ?? NavigationType.Mesh; MobHpPercentLeft = GetAttributeAsNullable <double>("MobHpPercentLeft", false, ConstrainAs.Percent, new[] { "HpLeftAmount" }) ?? 100.0; NotMoving = GetAttributeAsNullable <bool>("NotMoving", false, null, null) ?? false; NumOfTimes = GetAttributeAsNullable <int>("NumOfTimes", false, ConstrainAs.RepeatCount, null) ?? 1; QuestId = GetAttributeAsNullable("QuestId", false, ConstrainAs.QuestId(this), null) ?? 0; QuestRequirementComplete = GetAttributeAsNullable <QuestCompleteRequirement>("QuestCompleteRequirement", false, null, null) ?? QuestCompleteRequirement.NotComplete; QuestRequirementInLog = GetAttributeAsNullable <QuestInLogRequirement>("QuestInLogRequirement", false, null, null) ?? QuestInLogRequirement.InLog; Range = GetAttributeAsNullable <double>("Range", false, ConstrainAs.Range, null) ?? 4.0; WaitForNpcs = GetAttributeAsNullable <bool>("WaitForNpcs", false, null, null) ?? true; WaitTime = GetAttributeAsNullable <int>("WaitTime", false, ConstrainAs.Milliseconds, null) ?? 3000; IgnoreCombat = GetAttributeAsNullable <bool>("IgnoreCombat", false, null, null) ?? false; for (int i = 0; i < GossipOptions.Length; ++i) { GossipOptions[i] -= 1; } IEnumerable <WoWUnit> mobs = ObjectManager.GetObjectsOfType <WoWUnit>(true, false) .Where(unit => MobIds.Contains((int)unit.Entry)); MobNames = string.Join(", ", mobs.Select(mob => (!string.IsNullOrEmpty(mob.Name) ? mob.Name : ("Mob(" + mob.Entry.ToString() + ")"))) .ToArray()); } catch (Exception except) { // Maintenance problems occur for a number of reasons. The primary two are... // * Changes were made to the behavior, and boundary conditions weren't properly tested. // * The Honorbuddy core was changed, and the behavior wasn't adjusted for the new changes. // In any case, we pinpoint the source of the problem area here, and hopefully it // can be quickly resolved. LogMessage("error", "BEHAVIOR MAINTENANCE PROBLEM: " + except.Message + "\nFROM HERE:\n" + except.StackTrace + "\n"); IsAttributeProblem = true; } }