Untitled diff

Created Diff never expires
2 removals
Words removed5
Total words1012
Words removed (%)0.49
326 lines
21 additions
Words added48
Total words1055
Words added (%)4.55
344 lines
using System.IO;
using System.IO;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Markup;
using log4net;
using log4net;
using System;
using System;
using Loki.Bot;
using Loki.Bot;
using Loki.Bot.Logic.Bots.BasicGrindBot;
using Loki.Bot.Logic.Bots.BasicGrindBot;
using Loki.Bot.Pathfinding;
using Loki.Bot.Pathfinding;
using Loki.Bot.v3;
using Loki.Bot.v3;
using Loki.Game;
using Loki.Game;
using Loki.Game.Objects;
using Loki.Game.Objects;
using Loki.Utilities;
using Loki.Utilities;
namespace DominusFight
namespace DominusFight
{
{
internal class DominusFight : IPlugin
internal class DominusFight : IPlugin
{
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
private bool _enabled;
private bool _enabled;
private bool _skip;
private bool _skip;
/// <summary> The name of the plugin. </summary>
/// <summary> The name of the plugin. </summary>
public string Name
public string Name
{
{
get { return "DominusFight"; }
get { return "DominusFight"; }
}
}
/// <summary> The description of the plugin. </summary>
/// <summary> The description of the plugin. </summary>
public string Description
public string Description
{
{
get { return "A plugin that handles the logic required for fighting Dominus."; }
get { return "A plugin that handles the logic required for fighting Dominus."; }
}
}
/// <summary>The author of the plugin.</summary>
/// <summary>The author of the plugin.</summary>
public string Author
public string Author
{
{
get { return "Bossland GmbH"; }
get { return "Bossland GmbH"; }
}
}
/// <summary>The version of the plugin.</summary>
/// <summary>The version of the plugin.</summary>
public Version Version
public Version Version
{
{
get { return new Version(0, 0, 1, 1); }
get { return new Version(0, 0, 1, 1); }
}
}
/// <summary>Initializes this plugin.</summary>
/// <summary>Initializes this plugin.</summary>
public void Initialize()
public void Initialize()
{
{
Log.DebugFormat("[DominusFight] Initialize");
Log.DebugFormat("[DominusFight] Initialize");
}
}
/// <summary> The plugin start callback. Do any initialization here. </summary>
/// <summary> The plugin start callback. Do any initialization here. </summary>
public void Start()
public void Start()
{
{
Log.DebugFormat("[DominusFight] Start");
Log.DebugFormat("[DominusFight] Start");
GameEventManager.AreaChanged += GameEventManagerOnAreaChanged;
GameEventManager.AreaChanged += GameEventManagerOnAreaChanged;
Reset();
Reset();
// Check to see if the current grind zone is for Dominus.
// Check to see if the current grind zone is for Dominus.
if (BasicGrindBotSettings.Instance.GrindZoneName != "The Upper Sceptre of God")
if (BasicGrindBotSettings.Instance.GrindZoneName != "The Upper Sceptre of God")
{
{
Log.InfoFormat("[DominusFight] The area to grind is not Dominus. Skipping execution until a restart or area change.");
Log.InfoFormat("[DominusFight] The area to grind is not Dominus. Skipping execution until a restart or area change.");
_skip = true;
_skip = true;
return;
return;
}
}
// We want to change the behavior after exploration, so we can start the boss fight, and stay in it
// We want to change the behavior after exploration, so we can start the boss fight, and stay in it
// though different phases.
// though different phases.
if (!TaskManager.AddAfter(new HandleDominusArea(), "ExploreTask"))
if (!TaskManager.AddAfter(new HandleDominusArea(), "ExploreTask"))
{
{
Log.ErrorFormat("[DominusFight] AddAfter failed.");
Log.ErrorFormat("[DominusFight] AddAfter failed.");
BotManager.Stop();
BotManager.Stop();
}
}
}
}
/// <summary> The plugin tick callback. Do any update logic here. </summary>
/// <summary> The plugin tick callback. Do any update logic here. </summary>
public void Tick()
public void Tick()
{
{
if (_skip)
if (_skip)
return;
return;
if (!LokiPoe.IsInGame || LokiPoe.Me.IsInTown || LokiPoe.Me.IsDead)
if (!LokiPoe.IsInGame || LokiPoe.Me.IsInTown || LokiPoe.Me.IsDead)
return;
return;
}
}
/// <summary> The plugin stop callback. Do any pre-dispose cleanup here. </summary>
/// <summary> The plugin stop callback. Do any pre-dispose cleanup here. </summary>
public void Stop()
public void Stop()
{
{
Log.DebugFormat("[DominusFight] Stop");
Log.DebugFormat("[DominusFight] Stop");
GameEventManager.AreaChanged -= GameEventManagerOnAreaChanged;
GameEventManager.AreaChanged -= GameEventManagerOnAreaChanged;
}
}
#region Implementation of IConfigurable
#region Implementation of IConfigurable
public JsonSettings Settings
public JsonSettings Settings
{
{
get { return DominusFightSettings.Instance; }
get { return DominusFightSettings.Instance; }
}
}
/// <summary> The plugin's settings control. This will be added to the Exilebuddy Settings tab.</summary>
/// <summary> The plugin's settings control. This will be added to the Exilebuddy Settings tab.</summary>
public UserControl Control
public UserControl Control
{
{
get
get
{
{
using (var fs = new FileStream(@"Plugins\DominusFight\SettingsGui.xaml", FileMode.Open))
using (var fs = new FileStream(@"Plugins\DominusFight\SettingsGui.xaml", FileMode.Open))
{
{
var root = (UserControl)XamlReader.Load(fs);
var root = (UserControl)XamlReader.Load(fs);
// Your settings binding here.
// Your settings binding here.
// Your settings event handlers here.
// Your settings event handlers here.
return root;
return root;
}
}
}
}
}
}
#endregion
#endregion
#region Implementation of IEnableable
#region Implementation of IEnableable
/// <summary>Is this plugin currently enabled?</summary>
/// <summary>Is this plugin currently enabled?</summary>
public bool IsEnabled
public bool IsEnabled
{
{
get { return _enabled; }
get { return _enabled; }
}
}
/// <summary> The plugin is being enabled.</summary>
/// <summary> The plugin is being enabled.</summary>
public void Enable()
public void Enable()
{
{
Log.DebugFormat("[DominusFight] Enable");
Log.DebugFormat("[DominusFight] Enable");
_enabled = true;
_enabled = true;
}
}
/// <summary> The plugin is being disabled.</summary>
/// <summary> The plugin is being disabled.</summary>
public void Disable()
public void Disable()
{
{
Log.DebugFormat("[DominusFight] Disable");
Log.DebugFormat("[DominusFight] Disable");
_enabled = false;
_enabled = false;
}
}
#endregion
#endregion
#region Implementation of IDisposable
#region Implementation of IDisposable
/// <summary> </summary>
/// <summary> </summary>
public void Dispose()
public void Dispose()
{
{
}
}
#endregion
#endregion
#region Override of Object
#region Override of Object
/// <summary>
/// <summary>
///
///
/// </summary>
/// </summary>
/// <returns></returns>
/// <returns></returns>
public override string ToString()
public override string ToString()
{
{
return Name + ": " + Description;
return Name + ": " + Description;
}
}
#endregion
#endregion
private void GameEventManagerOnAreaChanged(object sender, AreaChangedEventArgs areaChangedEventArgs)
private void GameEventManagerOnAreaChanged(object sender, AreaChangedEventArgs areaChangedEventArgs)
{
{
Reset();
Reset();
}
}
private void Reset()
private void Reset()
{
{
Log.DebugFormat("[DominusFight] Now resetting task state.");
Log.DebugFormat("[DominusFight] Now resetting task state.");
_skip = false;
_skip = false;
}
}
/// <summary>
/// <summary>
/// This task helps BasicGrindBot stay in the Dominus boss fight area, resetting exploration to
/// This task helps BasicGrindBot stay in the Dominus boss fight area, resetting exploration to
/// keep the bot moving around to trigger different phases.
/// keep the bot moving around to trigger different phases.
/// </summary>
/// </summary>
public class HandleDominusArea : ITask
public class HandleDominusArea : ITask
{
{
private bool _enabled = true;
private bool _enabled = true;
private bool _skip;
/// <summary>The name of this task.</summary>
/// <summary>The name of this task.</summary>
public string Name
public string Name
{
{
get { return "HandleDominusArea"; }
get { return "HandleDominusArea"; }
}
}
/// <summary>A description of what this task does.</summary>
/// <summary>A description of what this task does.</summary>
public string Description
public string Description
{
{
get { return "This task helps BasicGrindBot stay in the Dominus boss fight area, resetting exploration to keep the bot moving around to trigger different phases."; }
get { return "This task helps BasicGrindBot stay in the Dominus boss fight area, resetting exploration to keep the bot moving around to trigger different phases."; }
}
}
/// <summary>The author of this task.</summary>
/// <summary>The author of this task.</summary>
public string Author
public string Author
{
{
get { return "Bossland GmbH"; }
get { return "Bossland GmbH"; }
}
}
/// <summary>The version of this task.</summary>
/// <summary>The version of this task.</summary>
public Version Version
public Version Version
{
{
get { return new Version(0, 0, 1, 1); }
get { return new Version(0, 0, 1, 1); }
}
}
private Vector2i _towerFightStarterPos;
private Vector2i _towerFightStarterPos;
/// <summary>
/// <summary>
/// The tasks's execution logic.
/// The tasks's execution logic.
/// </summary>
/// </summary>
/// <returns>true if the TaskManager should not execute any other tasks, and false if it should.</returns>
/// <returns>true if the TaskManager should not execute any other tasks, and false if it should.</returns>
public async Task<bool> Execute()
public async Task<bool> Execute()
{
{
if (!LokiPoe.CurrentWorldArea.IsOverworldArea)
if (!LokiPoe.CurrentWorldArea.IsOverworldArea)
return false;
return false;
if (_skip)
return false;
// When we first spawn into the area, exploration should take us within range of everything.
// When we first spawn into the area, exploration should take us within range of everything.
// Start out by triggering the fight itself.
// Start out by triggering the fight itself.
if (_towerFightStarterPos == Vector2i.Zero)
if (_towerFightStarterPos == Vector2i.Zero)
{
{
var fightStarter =
var fightStarter =
LokiPoe.ObjectManager.GetObjectByMetadata(
LokiPoe.ObjectManager.GetObjectByMetadata(
"Metadata/Monsters/Demonmodular/TowerSpawners/TowerFightStarter");
"Metadata/Monsters/Demonmodular/TowerSpawners/TowerFightStarter");
if (fightStarter != null)
if (fightStarter != null)
{
{
_towerFightStarterPos = ExilePather.WalkablePositionFor(fightStarter, 10);
_towerFightStarterPos = ExilePather.WalkablePositionFor(fightStarter, 10);
Log.InfoFormat("[DominusFight] _fightStarterPos: {0}.", _towerFightStarterPos);
Log.InfoFormat("[DominusFight] _fightStarterPos: {0}.", _towerFightStarterPos);
if (!await Coroutines.MoveToLocation(_towerFightStarterPos, 10, 30000))
if (!await Coroutines.MoveToLocation(_towerFightStarterPos, 10, 30000))
{
{
Log.ErrorFormat("[DominusFight] MoveToLocation failed.");
Log.ErrorFormat("[DominusFight] MoveToLocation failed.");
}
}
return true;
return true;
}
}
}
}
// Check to see if the boss fight is over. Logic for actually completing the quest for the first time
// Check to see if the boss fight is over. Logic for actually completing the quest for the first time
// is not implemented.
// is not implemented.
var npc = LokiPoe.ObjectManager.GetObjectByName<Npc>("Lady Dialla");
var npc = LokiPoe.ObjectManager.GetObjectByName<Npc>("Lady Dialla");
if (npc != null)
if (npc != null)
{
{
// Wait for her to spawn in and be usable.
// Wait for her to spawn in and be usable.
if (npc.IsTargetable)
if (npc.IsTargetable)
{
{
Log.InfoFormat("[DominusFight] Lady Dialla was found. Now completing the boss fight.");
Log.InfoFormat("[DominusFight] Lady Dialla was found. Now marking this task to skip executing.");
BasicGrindBotSettings.Instance.NeedsTownRun = 2;
//BasicGrindBotSettings.Instance.NeedsTownRun = 2;
_skip = true;
}
}
return true;
return true;
}
}
// Simply move towards Dominus if nothing else is running.
// Simply move towards Dominus if nothing else is running.
var dom = LokiPoe.ObjectManager.GetObjectByName<Monster>("Dominus, High Templar");
var dom = LokiPoe.ObjectManager.GetObjectByName<Monster>("Dominus, High Templar");
if (dom != null)
if (dom != null)
{
{
if (!dom.IsDead)
if (!dom.IsDead)
{
{
PlayerMover.MoveTowards(dom.Position);
PlayerMover.MoveTowards(dom.Position);
return true;
return true;
}
}
}
}
dom = LokiPoe.ObjectManager.GetObjectByName<Monster>("Dominus, Ascendant");
dom = LokiPoe.ObjectManager.GetObjectByName<Monster>("Dominus, Ascendant");
if (dom != null)
if (dom != null)
{
{
if (!dom.IsDead)
if (!dom.IsDead)
{
{
PlayerMover.MoveTowards(dom.Position);
PlayerMover.MoveTowards(dom.Position);
return true;
return true;
}
}
}
}
// Reset the explorer, so we move around the area looking for things that might be out of view.
// Reset the explorer, so we move around the area looking for things that might be out of view.
// It's up to the CR to avoid getting stuck killing Miscreations near their spawner.
// It's up to the CR to avoid getting stuck killing Miscreations near their spawner.
if (AreaStateCache.Current.Explorer != null)
if (AreaStateCache.Current.Explorer != null)
{
{
Log.InfoFormat("[DominusFight] Now resetting the explorer.");
Log.InfoFormat("[DominusFight] Now resetting the explorer.");
AreaStateCache.Current.Explorer.Reset();
AreaStateCache.Current.Explorer.Reset();
}
}
// Don't execute any tasks afterwards. This forces the BasicGrindBot to say in the boss area.
// Don't execute any tasks afterwards. This forces the BasicGrindBot to say in the boss area.
return true;
return true;
}
}
/// <summary>The bot Start event.</summary>
/// <summary>The bot Start event.</summary>
public void Start()
public void Start()
{
{
GameEventManager.AreaChanged += GameEventManagerOnAreaChanged;
}
}
/// <summary>The bot Tick event.</summary>
/// <summary>The bot Tick event.</summary>
public void Tick()
public void Tick()
{
{
}
}
/// <summary>The bot Stop event.</summary>
/// <summary>The bot Stop event.</summary>
public void Stop()
public void Stop()
{
{
GameEventManager.AreaChanged -= GameEventManagerOnAreaChanged;
}
}
/// <summary>Is this task currently enabled?</summary>
/// <summary>Is this task currently enabled?</summary>
public bool IsEnabled
public bool IsEnabled
{
{
get { return _enabled; }
get { return _enabled; }
}
}
/// <summary>Called when the task should be enabled.</summary>
/// <summary>Called when the task should be enabled.</summary>
public void Enable()
public void Enable()
{
{
_enabled = true;
_enabled = true;
}
}
/// <summary>Called when the task should be disabled.</summary>
/// <summary>Called when the task should be disabled.</summary>
public void Disable()
public void Disable()
{
{
_enabled = false;
_enabled = false;
}
}
private void GameEventManagerOnAreaChanged(object sender, AreaChangedEventArgs areaChangedEventArgs)
{
Reset();
}
private void Reset()
{
Log.DebugFormat("[HandleDominusArea] Now resetting task state.");
_skip = false;
}
}
}
}
}
}
}