Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.46 KB | None | 0 0
  1. using System;
  2. using System.Threading.Tasks;
  3.  
  4. using Buddy.Coroutines;
  5. using Loki.Bot;
  6. using Loki.Bot.Pathfinding;
  7. using Loki.Game;
  8. using Loki.Common;
  9. using log4net;
  10.  
  11. namespace Exilefollower
  12. {
  13. class Exilefollower : IBot
  14. {
  15. #region Implemention of IRunnable
  16. public void Start()
  17. {
  18. Log.DebugFormat("[ExiledFollower 2.0]: Starting...");
  19.  
  20. Master.Instance = new Master();
  21.  
  22. ItemEvaluator.Instance = DefaultItemEvaluator.Instance;
  23.  
  24. LokiPoe.Input.Binding.Update();
  25.  
  26. if (LokiPoe.InGameState.IsUsingLockstep)
  27. {
  28. PlayerMover.Instance = new LockstepPlayerMover();
  29. }
  30. else
  31. {
  32. PlayerMover.Instance = new PredictivePlayerMover();
  33. }
  34.  
  35. LokiPoe.ProcessHookManager.Enable();
  36.  
  37. coroutine = null;
  38.  
  39. ExilePather.Reload();
  40.  
  41. taskManager.Reset();
  42.  
  43.  
  44. taskManager.Add(new Tasks.AssistTask());
  45. taskManager.Add(new Tasks.FollowTask());
  46.  
  47. taskManager.Freeze();
  48.  
  49. PluginManager.Start();
  50. RoutineManager.Start();
  51.  
  52. taskManager.Start();
  53. }
  54.  
  55. public void Stop()
  56. {
  57. Log.DebugFormat("[ExiledFollower 2.0]: Stopping...");
  58.  
  59. taskManager.Stop();
  60. PluginManager.Stop();
  61. RoutineManager.Stop();
  62.  
  63. LokiPoe.ProcessHookManager.Disable();
  64.  
  65. if(coroutine != null)
  66. {
  67. coroutine.Dispose();
  68. coroutine = null;
  69. }
  70. }
  71.  
  72. public void Tick ()
  73. {
  74. if(coroutine == null)
  75. {
  76. coroutine = new Coroutine(() => MainCoroutine());
  77. }
  78.  
  79. ExilePather.Reload();
  80.  
  81. Loki.Bot.Logic.Bots.OldGrindBot.AreaStateCache.Tick();
  82. LatencyTracker.Tick();
  83. StaticLocationManager.Tick();
  84. taskManager.Tick();
  85. PluginManager.Tick();
  86. RoutineManager.Tick();
  87.  
  88. if (coroutine.IsFinished)
  89. {
  90. Log.DebugFormat("[ExiledFollower 2.0]: finished with state {0}",coroutine.Status);
  91. BotManager.Stop();
  92. return;
  93. }
  94.  
  95. try
  96. {
  97. coroutine.Resume();
  98. }
  99. catch
  100. {
  101. var c = coroutine;
  102. coroutine = null;
  103. c.Dispose();
  104. throw;
  105. }
  106. }
  107. #endregion
  108.  
  109. #region Implemention of IAuthored
  110.  
  111. public String Author
  112. {
  113. get
  114. {
  115. return "xTenshiSanx";
  116. }
  117. }
  118.  
  119. public String Name
  120. {
  121. get
  122. {
  123. return "Exiledfollower 2.0";
  124. }
  125. }
  126.  
  127. public String Description
  128. {
  129. get
  130. {
  131. return "Follows and assist the set Master";
  132. }
  133. }
  134.  
  135. public String Version
  136. {
  137. get
  138. {
  139. return "2.0.0001";
  140. }
  141. }
  142. #endregion
  143.  
  144. #region Implemention of IBase
  145.  
  146. public void Initialize()
  147. {
  148. BotManager.OnBotChanged += OnBotChanged;
  149. }
  150.  
  151. public void Deinitialize()
  152. {
  153.  
  154. }
  155.  
  156. #endregion
  157.  
  158. #region Implemention of ILogic
  159.  
  160. public async Task<bool> Logic(string type, params dynamic[] param)
  161. {
  162. return await taskManager.Execute(type, param);
  163. }
  164.  
  165. public object Execute(string name, params dynamic[] param)
  166. {
  167. if (name.Equals("GetTaskManager"))
  168. {
  169. return taskManager;
  170. }
  171. return null;
  172. }
  173.  
  174. #endregion
  175.  
  176. #region Implemention of IConfigurable
  177.  
  178. public System.Windows.Controls.UserControl Control
  179. {
  180. get
  181. {
  182. return null;
  183. }
  184. }
  185.  
  186. public JsonSettings Settings
  187. {
  188. get
  189. {
  190. return null;
  191. }
  192. }
  193.  
  194. #endregion
  195.  
  196. #region Private Vars
  197.  
  198. private static readonly TaskManager taskManager = new TaskManager();
  199.  
  200. private Coroutine coroutine;
  201.  
  202. private static readonly ILog Log = Logger.GetLoggerInstanceForType();
  203.  
  204. #endregion
  205.  
  206. #region Public Vars
  207.  
  208. public static void WriteLog(params object[] parm)
  209. {
  210. if(parm.Length == 1)
  211. Log.DebugFormat("[Exiledfollower 2.0] {0}",parm[0]);
  212. else
  213. Log.DebugFormat("[Exiledfollower 2.0 ({1})] {0}", parm[0], parm[1]);
  214. }
  215.  
  216. #endregion
  217.  
  218. private void OnBotChanged(object sender, BotChangedEventArgs e)
  219. {
  220. if (e.New == this)
  221. {
  222. Log.DebugFormat("[Exiledfollower 2.0] is the new Bot");
  223. ItemEvaluator.Instance = DefaultItemEvaluator.Instance;
  224. }
  225. }
  226.  
  227. private async Task MainCoroutine()
  228. {
  229. while (true)
  230. {
  231. if (LokiPoe.IsInLoginScreen)
  232. {
  233. foreach (var plugin in PluginManager.OrderedEnabledPlugins)
  234. {
  235. if (await plugin.Logic("login_screen_hook"))
  236. break;
  237. }
  238. }
  239. if (LokiPoe.IsInCharacterSelectionScreen)
  240. {
  241. foreach (var plugin in PluginManager.OrderedEnabledPlugins)
  242. {
  243. if (await plugin.Logic("character_selection_hook"))
  244. break;
  245. }
  246. }
  247. if (LokiPoe.IsInGame)
  248. {
  249. foreach (var plugin in PluginManager.OrderedEnabledPlugins)
  250. {
  251. await plugin.Logic("plugin_coroutine_event");
  252. }
  253. await taskManager.Execute("task_execute");
  254. }
  255. else
  256. {
  257. await Coroutine.Sleep(1000);
  258. continue;
  259. }
  260. await Coroutine.Yield();
  261. }
  262. }
  263. }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement