Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading.Tasks;
- using Buddy.Coroutines;
- using Loki.Bot;
- using Loki.Bot.Pathfinding;
- using Loki.Game;
- using Loki.Common;
- using log4net;
- namespace Exilefollower
- {
- class Exilefollower : IBot
- {
- #region Implemention of IRunnable
- public void Start()
- {
- Log.DebugFormat("[ExiledFollower 2.0]: Starting...");
- Master.Instance = new Master();
- ItemEvaluator.Instance = DefaultItemEvaluator.Instance;
- LokiPoe.Input.Binding.Update();
- if (LokiPoe.InGameState.IsUsingLockstep)
- {
- PlayerMover.Instance = new LockstepPlayerMover();
- }
- else
- {
- PlayerMover.Instance = new PredictivePlayerMover();
- }
- LokiPoe.ProcessHookManager.Enable();
- coroutine = null;
- ExilePather.Reload();
- taskManager.Reset();
- taskManager.Add(new Tasks.AssistTask());
- taskManager.Add(new Tasks.FollowTask());
- taskManager.Freeze();
- PluginManager.Start();
- RoutineManager.Start();
- taskManager.Start();
- }
- public void Stop()
- {
- Log.DebugFormat("[ExiledFollower 2.0]: Stopping...");
- taskManager.Stop();
- PluginManager.Stop();
- RoutineManager.Stop();
- LokiPoe.ProcessHookManager.Disable();
- if(coroutine != null)
- {
- coroutine.Dispose();
- coroutine = null;
- }
- }
- public void Tick ()
- {
- if(coroutine == null)
- {
- coroutine = new Coroutine(() => MainCoroutine());
- }
- ExilePather.Reload();
- Loki.Bot.Logic.Bots.OldGrindBot.AreaStateCache.Tick();
- LatencyTracker.Tick();
- StaticLocationManager.Tick();
- taskManager.Tick();
- PluginManager.Tick();
- RoutineManager.Tick();
- if (coroutine.IsFinished)
- {
- Log.DebugFormat("[ExiledFollower 2.0]: finished with state {0}",coroutine.Status);
- BotManager.Stop();
- return;
- }
- try
- {
- coroutine.Resume();
- }
- catch
- {
- var c = coroutine;
- coroutine = null;
- c.Dispose();
- throw;
- }
- }
- #endregion
- #region Implemention of IAuthored
- public String Author
- {
- get
- {
- return "xTenshiSanx";
- }
- }
- public String Name
- {
- get
- {
- return "Exiledfollower 2.0";
- }
- }
- public String Description
- {
- get
- {
- return "Follows and assist the set Master";
- }
- }
- public String Version
- {
- get
- {
- return "2.0.0001";
- }
- }
- #endregion
- #region Implemention of IBase
- public void Initialize()
- {
- BotManager.OnBotChanged += OnBotChanged;
- }
- public void Deinitialize()
- {
- }
- #endregion
- #region Implemention of ILogic
- public async Task<bool> Logic(string type, params dynamic[] param)
- {
- return await taskManager.Execute(type, param);
- }
- public object Execute(string name, params dynamic[] param)
- {
- if (name.Equals("GetTaskManager"))
- {
- return taskManager;
- }
- return null;
- }
- #endregion
- #region Implemention of IConfigurable
- public System.Windows.Controls.UserControl Control
- {
- get
- {
- return null;
- }
- }
- public JsonSettings Settings
- {
- get
- {
- return null;
- }
- }
- #endregion
- #region Private Vars
- private static readonly TaskManager taskManager = new TaskManager();
- private Coroutine coroutine;
- private static readonly ILog Log = Logger.GetLoggerInstanceForType();
- #endregion
- #region Public Vars
- public static void WriteLog(params object[] parm)
- {
- if(parm.Length == 1)
- Log.DebugFormat("[Exiledfollower 2.0] {0}",parm[0]);
- else
- Log.DebugFormat("[Exiledfollower 2.0 ({1})] {0}", parm[0], parm[1]);
- }
- #endregion
- private void OnBotChanged(object sender, BotChangedEventArgs e)
- {
- if (e.New == this)
- {
- Log.DebugFormat("[Exiledfollower 2.0] is the new Bot");
- ItemEvaluator.Instance = DefaultItemEvaluator.Instance;
- }
- }
- private async Task MainCoroutine()
- {
- while (true)
- {
- if (LokiPoe.IsInLoginScreen)
- {
- foreach (var plugin in PluginManager.OrderedEnabledPlugins)
- {
- if (await plugin.Logic("login_screen_hook"))
- break;
- }
- }
- if (LokiPoe.IsInCharacterSelectionScreen)
- {
- foreach (var plugin in PluginManager.OrderedEnabledPlugins)
- {
- if (await plugin.Logic("character_selection_hook"))
- break;
- }
- }
- if (LokiPoe.IsInGame)
- {
- foreach (var plugin in PluginManager.OrderedEnabledPlugins)
- {
- await plugin.Logic("plugin_coroutine_event");
- }
- await taskManager.Execute("task_execute");
- }
- else
- {
- await Coroutine.Sleep(1000);
- continue;
- }
- await Coroutine.Yield();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement