daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Sep 12th, 2017 184 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Runtime.Serialization;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. using System.Windows.Forms.VisualStyles;
  10. using nManager.FiniteStateMachine;
  11. using nManager.Helpful;
  12. using nManager.Plugins;
  13. using nManager.Wow.Bot.Tasks;
  14. using nManager.Wow.Class;
  15. using nManager.Wow.Enums;
  16. using nManager.Wow.Helpers;
  17. using Timer = nManager.Helpful.Timer;
  18. using Point = nManager.Wow.Class.Point;
  19. using ObjectManager = nManager.Wow.ObjectManager.ObjectManager;
  20.  
  21. #region Interface Implementation - Edition Expert only
  22.  
  23. public class Main : State, IPlugins
  24. {
  25.     private bool _checkFieldRunning;
  26.  
  27.     public bool Loop
  28.     {
  29.         get { return MyStatePlugin.InternalLoop; }
  30.         set { MyStatePlugin.InternalLoop = value; }
  31.     }
  32.  
  33.     public string Name
  34.     {
  35.         get { return MyStatePlugin.Name; }
  36.     }
  37.  
  38.     public string Author
  39.     {
  40.         get { return MyStatePlugin.Author; }
  41.     }
  42.  
  43.     public string Description
  44.     {
  45.         get { return MyStatePlugin.Description; }
  46.     }
  47.  
  48.     public string TargetVersion
  49.     {
  50.         get { return MyStatePlugin.TargetVersion; }
  51.     }
  52.  
  53.     public string Version
  54.     {
  55.         get { return MyStatePlugin.Version; }
  56.     }
  57.  
  58.     public bool IsStarted
  59.     {
  60.         get { return Loop && !_checkFieldRunning; }
  61.     }
  62.  
  63.     public void Dispose()
  64.     {
  65.         Loop = false;
  66.     }
  67.  
  68.     public void Initialize()
  69.     {
  70.         Logging.WriteDebug(string.Format("The plugin {0} is loading.", Name));
  71.         Initialize(false);
  72.     }
  73.  
  74.     public void ShowConfiguration()
  75.     {
  76.         MyStatePlugin.ShowConfiguration();
  77.     }
  78.  
  79.     public void ResetConfiguration()
  80.     {
  81.         MyStatePlugin.ResetConfiguration();
  82.     }
  83.  
  84.     public void CheckFields() // do not edit.
  85.     {
  86.         _checkFieldRunning = true;
  87.         Loop = true;
  88.         while (Loop)
  89.         {
  90.             Thread.Sleep(1000); // Don't do any action.
  91.         }
  92.     }
  93.  
  94.     public void Initialize(bool configOnly, bool resetSettings = false)
  95.     {
  96.         try
  97.         {
  98.             if (!configOnly && !resetSettings)
  99.                 Loop = true;
  100.             MyStatePlugin.Init();
  101.         }
  102.         catch (Exception e)
  103.         {
  104.             Logging.WriteError("IPlugins.Main.Initialize(bool configOnly, bool resetSettings = false): " + e);
  105.         }
  106.         Logging.Write(string.Format("The plugin {0} has stopped.", Name));
  107.     }
  108.  
  109.     public override int Priority
  110.     {
  111.         get { return MyStatePlugin.StatePriority; }
  112.         set { MyStatePlugin.StatePriority = value; }
  113.     }
  114.  
  115.     public override string DisplayName
  116.     {
  117.         get { return MyStatePlugin.Name; }
  118.     }
  119.  
  120.     public override bool NeedToRun
  121.     {
  122.         get { return MyStatePlugin.NeedToRun(); }
  123.     }
  124.  
  125.     public override List<State> NextStates
  126.     {
  127.         get { return new List<State>(); }
  128.     }
  129.  
  130.     public override List<State> BeforeStates
  131.     {
  132.         get { return new List<State>(); }
  133.     }
  134.  
  135.     public override void Run()
  136.     {
  137.         MyStatePlugin.Run();
  138.     }
  139. }
  140.  
  141. #endregion
  142.  
  143. #region Plugin core - Your plugin should be coded here
  144.  
  145. public static class MyStatePlugin
  146. {
  147.     /*
  148.      * Finite-state machine (FSM) requires a NeedToRun and a Run method.
  149.      * The NeedToRun() code will be checked by the main product currently running
  150.      * according to its priority.
  151.      * For example, "Pause" State have a priority of 200 while "Idle" State (Do nothing) have a priority of 0.
  152.      * Usually, main product activities have a priority of 20-30 while more important thing like resurrect have a priority of 100+.
  153.      * You can ask the list of priority for a defined product to developers on our Discord server.
  154.      * Note that if, say, you wanted  to make a plugin to leave a dungeon and do a ResetInstance(), you'd probably need
  155.      * to set a priority between 31 and 39 as Grinder main module have a priority of 30 and higher priority start at 40 with an increment of 10.
  156.      * Two plugins can have the same priority, but only the one loaded  first will be above the other so if you need your plugin to work well with
  157.      * another plugin you know. Make sure that the one that should get higher priority is not using the same number. (31 vs 39 instead of both having 39)
  158.      *
  159.      * Grinder Example
  160.      * Pause 200 > SelectProfileState 150 > Resurrect 140 > IsAttacked 130 > Regeneration 120 > ToTown 110 > Looting 100 > Travel 90 > SpecializationCheck 80
  161.      * LevelupCheck 70 > Trainers 60 > MillingState 50 > ProspectingState 40 > Grinding 30 > Farming 20 > MovementLoop 10 > Idle 0
  162.      * The bot wont accept your plugin if the priority is above 199 or below 1.
  163.      *
  164.      * Remember that you must not stuck the bot into the Run() code. You must make sure that your code can be called severals time in a row while performing
  165.      * the action just fine. (If you're going somewhere, don't make a "while(moving...)", instead make sure you always go back to your code with a valid "NeedToRun"
  166.      * and that if you already started a movement, then you just keep returning the code.
  167.      */
  168.     public static bool InternalLoop = true;
  169.     public static string Author = "Vesper";
  170.     public static string Name = "AntiDrowning";
  171.     public static string TargetVersion = "7.1.x";
  172.     public static string Version = "1.0.0";
  173.     public static int StatePriority = 31; // Have more priority than grinding itself, but will still resurrect/fight before doing that code.
  174.     public static string Description = "Will attempt to go back to the surface in case of drowning.";
  175.     private static readonly MyPluginSettings MySettings = MyPluginSettings.GetSettings();
  176.     private static Spell DruidMountSpell = new Spell("Travel Form");
  177.    
  178.     public static bool NeedToRun()
  179.     {
  180.         if (Usefuls.IsSwimming && ObjectManager.Me.BreathPercentage < 20)
  181.             return true;
  182.         return false;
  183.         /*
  184.         if (!Usefuls.IsSwimming || DrowningPercentage >= 20)
  185.             return false;
  186.         if (ObjectManager.Me.WowClass == WoWClass.Druid && DruidMountSpell.IsSpellUsable)
  187.             return true;
  188.         for (int i = 5; i <= 80; i+=5)
  189.         {
  190.             i = 15;
  191.             Point posAbove = ObjectManager.Me.Position;
  192.             posAbove.Z += i;
  193.             if (TraceLine.TraceLineGo(ObjectManager.Me.Position, posAbove))
  194.             {
  195.                 bool hitAllButLiquid = TraceLine.TraceLineGo(ObjectManager.Me.Position, posAbove, CGWorldFrameHitFlags.HitTestAllButLiquid);
  196.                 bool hitOnlyLiquid = TraceLine.TraceLineGo(ObjectManager.Me.Position, posAbove, CGWorldFrameHitFlags.HitTestLiquid);
  197.                 if (hitAllButLiquid && !hitOnlyLiquid)
  198.                 {
  199.                     // We hit something that is not water line first. We cannot go out of water from this position.
  200.                     return false;
  201.                 }
  202.                 if (hitOnlyLiquid)
  203.                     return true;
  204.             }
  205.             Thread.Sleep(100);
  206.         }
  207.         return true;
  208.         */
  209.     }
  210.  
  211.     public static void Run()
  212.     {
  213.         if (ObjectManager.Me.BreathPercentage >= 95)
  214.             return;
  215.         if (ObjectManager.Me.WowClass == WoWClass.Druid && !DruidMountSpell.IsSpellUsable)
  216.         {
  217.             DruidMountSpell.Cast();
  218.             var timerRegen = new Timer(5000);
  219.             while (ObjectManager.Me.BreathPercentage < 95 && !timerRegen.IsReady)
  220.             {
  221.                 Thread.Sleep(50);
  222.             }
  223.         }
  224.         else
  225.         {
  226.             Logging.WritePlugin("Trying to reach the surface...", Name);
  227.             MovementManager.StopMove();
  228.             MovementsAction.Ascend(true);
  229.             Timer timerSurface = new Timer(40000);
  230.             while (ObjectManager.Me.BreathPercentage < 95 && !timerSurface.IsReady)
  231.             {
  232.                 Thread.Sleep(50);
  233.             }
  234.             Thread.Sleep(150);
  235.             MovementsAction.Ascend(false);
  236.         }
  237.     }
  238.  
  239.     public static void Init()
  240.     {
  241.         /*
  242.          * You can use this area to do some logging or stuff.
  243.          */
  244.         Logging.WritePlugin("Loaded TnbAntiDrowning with BreathPercentage tolerance at " + MySettings.BreathPercentage + ".", Name);
  245.     }
  246.  
  247.     public static void ResetConfiguration()
  248.     {
  249.         string currentSettingsFile = Application.StartupPath + "\\Plugins\\Settings\\" + Name + ".xml";
  250.         var currentSetting = new MyPluginSettings();
  251.         currentSetting.ToForm();
  252.         currentSetting.Save(currentSettingsFile);
  253.     }
  254.  
  255.     public static void ShowConfiguration()
  256.     {
  257.         string currentSettingsFile = Application.StartupPath + "\\Plugins\\Settings\\" + Name + ".xml";
  258.         var currentSetting = new MyPluginSettings();
  259.         if (File.Exists(currentSettingsFile))
  260.         {
  261.             currentSetting = Settings.Load<MyPluginSettings>(currentSettingsFile);
  262.         }
  263.         currentSetting.ToForm();
  264.         currentSetting.Save(currentSettingsFile);
  265.     }
  266.  
  267.     [Serializable]
  268.     public class MyPluginSettings : Settings
  269.     {
  270.         public uint BreathPercentage = 100;
  271.  
  272.         public MyPluginSettings()
  273.         {
  274.             ConfigWinForm("Anti Drowning Settings");
  275.             AddControlInWinForm("Going to surface when", "BreathPercentage", "Example Title", "BelowPercentage");
  276.         }
  277.  
  278.         public static MyPluginSettings CurrentSetting { get; set; }
  279.  
  280.         public static MyPluginSettings GetSettings()
  281.         {
  282.             string currentSettingsFile = Application.StartupPath + "\\Plugins\\Settings\\" + Name + ".xml";
  283.             if (File.Exists(currentSettingsFile))
  284.             {
  285.                 return CurrentSetting = Load<MyPluginSettings>(currentSettingsFile);
  286.             }
  287.             return new MyPluginSettings();
  288.         }
  289.     }
  290. }
  291.  
  292. #endregion
RAW Paste Data
Top