Guest User

Untitled

a guest
May 31st, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.82 KB | None | 0 0
  1. // Behavior originally contributed by mastahg.
  2. //
  3. // DOCUMENTATION:
  4. //    
  5. //
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading;
  11. using CommonBehaviors.Actions;
  12. using Styx.Combat.CombatRoutine;
  13. using Styx.Helpers;
  14. using Styx.Logic.BehaviorTree;
  15. using Styx.Logic.Combat;
  16. using Styx.Logic.Inventory.Frames.Gossip;
  17. using Styx.Logic.Pathing;
  18. using Styx.Logic.Profiles.Quest;
  19. using Styx.Logic.Questing;
  20. using Styx.WoWInternals;
  21. using Styx.WoWInternals.WoWObjects;
  22. using TreeSharp;
  23. using Action = TreeSharp.Action;
  24.  
  25.  
  26. namespace Styx.Bot.Quest_Behaviors
  27. {
  28.     public class TheGrandMelee : CustomForcedBehavior
  29.     {
  30.         ~TheGrandMelee()
  31.         {
  32.             Dispose(false);
  33.         }
  34.  
  35.         public TheGrandMelee(Dictionary<string, string> args)
  36.             : base(args)
  37.         {
  38.             try
  39.             {
  40.                 // QuestRequirement* attributes are explained here...
  41.                 //    http://www.thebuddyforum.com/mediawiki/index.php?title=Honorbuddy_Programming_Cookbook:_QuestId_for_Custom_Behaviors
  42.                 // ...and also used for IsDone processing.
  43.                 Location = GetAttributeAsNullable<WoWPoint>("", true, ConstrainAs.WoWPointNonEmpty, null) ??MountSpot;
  44.                 QuestId = GetAttributeAsNullable<int>("QuestId", true, ConstrainAs.QuestId(this), null) ?? 0;
  45.                 //MobIds = GetAttributeAsNullable<int>("MobId", true, ConstrainAs.MobId, null) ?? 0;
  46.                 QuestRequirementComplete = QuestCompleteRequirement.NotComplete;
  47.                 QuestRequirementInLog = QuestInLogRequirement.InLog;
  48.  
  49.  
  50.             }
  51.  
  52.             catch (Exception except)
  53.             {
  54.                 // Maintenance problems occur for a number of reasons.  The primary two are...
  55.                 // * Changes were made to the behavior, and boundary conditions weren't properly tested.
  56.                 // * The Honorbuddy core was changed, and the behavior wasn't adjusted for the new changes.
  57.                 // In any case, we pinpoint the source of the problem area here, and hopefully it
  58.                 // can be quickly resolved.
  59.                 LogMessage("error",
  60.                            "BEHAVIOR MAINTENANCE PROBLEM: " + except.Message + "\nFROM HERE:\n" + except.StackTrace +
  61.                            "\n");
  62.                 IsAttributeProblem = true;
  63.             }
  64.         }
  65.  
  66.         uint[] Mounts = new uint[]{33798,33796,33799,33842,33791};
  67.         uint[] Enemy = new uint[] { 33384, 33306,33285,33382,33383};
  68.         uint[] EnemyDebuff = new uint[] { 64816, 64811, 64812, 64813, 64815 };
  69.  
  70.         WoWItem HordeLance()
  71.         {
  72.             return StyxWoW.Me.BagItems.FirstOrDefault(x => x.Entry == 46070);
  73.         }
  74.         WoWItem ArgentLance()
  75.         {
  76.             return StyxWoW.Me.BagItems.FirstOrDefault(x => x.Entry == 46106);
  77.         }
  78.  
  79.         WoWItem BestLance()
  80.         {
  81.             return HordeLance() ?? ArgentLance();
  82.         }
  83.  
  84.         // Attributes provided by caller
  85.         public uint[] MobIds { get; private set; }
  86.         public int QuestId { get; private set; }
  87.         public QuestCompleteRequirement QuestRequirementComplete { get; private set; }
  88.         public QuestInLogRequirement QuestRequirementInLog { get; private set; }
  89.         public WoWPoint Location { get; private set; }
  90.  
  91.         // Private variables for internal state
  92.         private bool _isBehaviorDone;
  93.         private bool _isDisposed;
  94.         private Composite _root;
  95.  
  96.  
  97.  
  98.         // Private properties
  99.         private LocalPlayer Me
  100.         {
  101.             get { return (ObjectManager.Me); }
  102.         }
  103.  
  104.  
  105.  
  106.         public void Dispose(bool isExplicitlyInitiatedDispose)
  107.         {
  108.             if (!_isDisposed)
  109.             {
  110.                 // NOTE: we should call any Dispose() method for any managed or unmanaged
  111.                 // resource, if that resource provides a Dispose() method.
  112.  
  113.                 // Clean up managed resources, if explicit disposal...
  114.                 if (isExplicitlyInitiatedDispose)
  115.                 {
  116.                     // empty, for now
  117.                 }
  118.  
  119.                 // Clean up unmanaged resources (if any) here...
  120.                 TreeRoot.GoalText = string.Empty;
  121.                 TreeRoot.StatusText = string.Empty;
  122.  
  123.                 // Call parent Dispose() (if it exists) here ...
  124.                 base.Dispose();
  125.             }
  126.  
  127.             _isDisposed = true;
  128.         }
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.         #region Overrides of CustomForcedBehavior
  136.  
  137.         public bool IsQuestComplete()
  138.         {
  139.             var quest = StyxWoW.Me.QuestLog.GetQuestById((uint)QuestId);
  140.             return quest == null || quest.IsCompleted;
  141.         }
  142.  
  143.  
  144.         public Composite DoneYet
  145.         {
  146.             get
  147.             {
  148.                 return
  149.                     new Decorator(ret => IsQuestComplete() && !Me.Combat, new Action(delegate
  150.                     {
  151.                         TreeRoot.StatusText = "Finished!";
  152.                         _isBehaviorDone = true;
  153.                         return RunStatus.Success;
  154.                     }));
  155.  
  156.             }
  157.         }
  158.  
  159.        
  160.  
  161.         public void UsePetSkill(string action)
  162.         {
  163.  
  164.             var spell = StyxWoW.Me.PetSpells.FirstOrDefault(p => p.ToString() == action);
  165.             if (spell == null)
  166.                 return;
  167.  
  168.             Logging.Write(string.Format("[Pet] Casting {0}", action));
  169.             Lua.DoString("CastPetAction({0})", spell.ActionBarIndex + 1);
  170.  
  171.         }
  172.  
  173.         WoWUnit Mount
  174.         {
  175.             get
  176.             {
  177.                 return
  178.                     ObjectManager.GetObjectsOfType<WoWUnit>().FirstOrDefault(
  179.                         x => Mounts.Contains(x.Entry) && x.NpcFlags == 16777216);
  180.             }
  181.         }
  182.  
  183.         //WoWPoint endspot = new WoWPoint(1076.7,455.7638,-44.20478);
  184.         // WoWPoint spot = new WoWPoint(1109.848,462.9017,-45.03053);
  185.         WoWPoint MountSpot = new WoWPoint(8426.872,711.7554,547.294);
  186.        
  187.         Composite GetNearMounts
  188.         {
  189.             get
  190.             {
  191.                 return new PrioritySelector(
  192.                     new Decorator(r => Me.Location.Distance(Location) > 15, new Action(r => Navigator.MoveTo(Location))),
  193.                      new Decorator(r => Me.Location.Distance(Location) < 15, new Action(r => Mount.Interact()))  
  194.                        
  195.                        
  196.                         );
  197.             }
  198.         }
  199.  
  200.  
  201.         Composite MountUp
  202.         {
  203.             get
  204.             {
  205.                 return new Decorator(r=>!Me.IsOnTransport,GetNearMounts);
  206.             }
  207.         }
  208.  
  209.         WoWUnit MyMount
  210.         {
  211.             get { return ObjectManager.GetObjectsOfType<WoWUnit>().FirstOrDefault(x => x.CreatedByUnitGuid == Me.Guid); }
  212.         }
  213.  
  214.  
  215.  
  216.         WoWUnit WhichNPC
  217.         {
  218.             get
  219.             {
  220.                 return ObjectManager.GetObjectsOfType<WoWUnit>().Where(x => Debuffs.ContainsKey(x.Entry) && !Me.HasAura((int)Debuffs[x.Entry])).OrderBy(u=>u.Distance).FirstOrDefault();
  221.             }
  222.         }
  223.  
  224.         Composite BuffUp
  225.         {
  226.             get
  227.             {
  228.                 return new Decorator(r =>!Me.Combat && !MyMount.ActiveAuras.ContainsKey("Defend") || ( MyMount.ActiveAuras.ContainsKey("Defend") && MyMount.ActiveAuras["Defend"].StackCount < 3), new Action(r=>UsePetSkill("Defend")));
  229.             }
  230.         }
  231.  
  232.  
  233.         private Composite BarkNpc
  234.         {
  235.             get
  236.             {
  237.                 return new PrioritySelector(
  238.                     new Decorator(r=>!Me.Combat && Me.Location.Distance(WhichNPC.Location)> 5, new Action(r=>Navigator.MoveTo(WhichNPC.Location))),
  239.                     new Decorator(r=>!Me.Combat && Me.Location.Distance(WhichNPC.Location)<= 5, new Action(r=>
  240.                                                                                                                {
  241.                                                                                                                    WhichNPC.Interact();
  242.                                                                                                                    WhichNPC.Target();
  243.                                                                                                                    Thread.Sleep(1000);
  244.                           Lua.DoString("SelectGossipOption(1)");
  245.                                                                                                                }
  246.                         ))
  247.                    
  248.                    
  249.                    
  250.                     );
  251.             }
  252.         }
  253.  
  254.  
  255.  
  256.  
  257.         private Composite Fight
  258.         {
  259.             get
  260.             {
  261.                 return
  262.                     new Decorator(r => Me.Combat, new Action(r =>
  263.                                                                  {
  264.                                                                      //Me.CurrentTarget.Face();
  265.                                                                      //if (Me.CurrentTarget.Distance > 10)
  266.                                                                      //   Navigator.MoveTo(Me.CurrentTarget.Location);
  267.  
  268.                                                                      var moveTo = WoWMathHelper.CalculatePointFrom(StyxWoW.Me.Location, StyxWoW.Me.CurrentTarget.Location, -10f);
  269.  
  270.                                                                      if (Navigator.CanNavigateFully(StyxWoW.Me.Location, moveTo))
  271.                                                                      {
  272.                                                                          Navigator.MoveTo(moveTo);
  273.                                                                      }
  274.                                                                  
  275.                                                                      if (!MyMount.ActiveAuras.ContainsKey("Defend") || ( MyMount.ActiveAuras.ContainsKey("Defend") && MyMount.ActiveAuras["Defend"].StackCount < 3))
  276.                                                                      {
  277.                                                                          UsePetSkill("Defend");
  278.                                                                      }
  279.                                                                      else
  280.                                                                      {
  281.                                                                          Me.CurrentTarget.Face();
  282.                                                                          UsePetSkill("Thrust");
  283.                                                                          UsePetSkill("Charge");
  284.                                                                          UsePetSkill("Shield-Breaker");
  285.                                                                      }
  286.                                                                  }
  287.                         ))
  288.  
  289.  
  290.  
  291.                     ;
  292.             }
  293.         }
  294.  
  295.         Dictionary<uint,uint> Debuffs = new Dictionary<uint, uint>();
  296.  
  297.         Composite LanceUp
  298.         {
  299.             get
  300.             {
  301.                 return new Decorator(r => Me.Inventory.Equipped.MainHand != BestLance(), new Action(r=>BestLance().Use()));
  302.             }
  303.         }
  304.  
  305.         Composite HealUp
  306.         {
  307.             get
  308.             {
  309.                 return new Decorator(r => !Me.Combat && MyMount.HealthPercent < 50, new Action(r => UsePetSkill("Refresh Mount")));
  310.             }
  311.         }
  312.  
  313.         protected override Composite CreateBehavior()
  314.         {
  315.             return _root ??
  316.                    (_root =
  317.                     new Decorator(ret => !_isBehaviorDone,
  318.                                   new PrioritySelector(DoneYet, LanceUp, MountUp, BuffUp, HealUp,BarkNpc,Fight, new ActionAlwaysSucceed())));
  319.         }
  320.  
  321.  
  322.  
  323.         public override void Dispose()
  324.         {
  325.             Dispose(true);
  326.             GC.SuppressFinalize(this);
  327.         }
  328.  
  329.  
  330.         public override bool IsDone
  331.         {
  332.             get
  333.             {
  334.                 return (_isBehaviorDone     // normal completion
  335.                         || !UtilIsProgressRequirementsMet(QuestId, QuestRequirementInLog, QuestRequirementComplete));
  336.             }
  337.         }
  338.  
  339.  
  340.         public override void OnStart()
  341.         {
  342.  
  343.             // This reports problems, and stops BT processing if there was a problem with attributes...
  344.             // We had to defer this action, as the 'profile line number' is not available during the element's
  345.             // constructor call.
  346.             OnStart_HandleAttributeProblem();
  347.             Logging.Write("Quest Behavior made by mastahg.");
  348.             // If the quest is complete, this behavior is already done...
  349.             // So we don't want to falsely inform the user of things that will be skipped.
  350.             if (!IsDone)
  351.             {
  352.  
  353.                 for (int i = 0; i < Enemy.Count(); i++)
  354.                 {
  355.                     Debuffs.Add(Enemy[i], EnemyDebuff[i]);
  356.                 }
  357.                 if (TreeRoot.Current != null && TreeRoot.Current.Root != null && TreeRoot.Current.Root.LastStatus != RunStatus.Running)
  358.                 {
  359.                     var currentRoot = TreeRoot.Current.Root;
  360.                     if (currentRoot is GroupComposite)
  361.                     {
  362.                         var root = (GroupComposite)currentRoot;
  363.                         root.InsertChild(0, CreateBehavior());
  364.                     }
  365.                 }
  366.  
  367.                 // Me.QuestLog.GetQuestById(27761).GetObjectives()[2].
  368.  
  369.                 PlayerQuest quest = StyxWoW.Me.QuestLog.GetQuestById((uint)QuestId);
  370.  
  371.                 TreeRoot.GoalText = this.GetType().Name + ": " +
  372.                                     ((quest != null) ? ("\"" + quest.Name + "\"") : "In Progress");
  373.             }
  374.  
  375.  
  376.  
  377.  
  378.         }
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.         #endregion
  387.     }
  388. }
Advertisement
Add Comment
Please, Sign In to add comment