using log4net;
using Loki.Bot;
using Loki.Common;
using Loki.Game;
using Loki.Game.Objects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace VaalCaster
{
public class VaalCaster : IPlugin
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
#region Implementation of IAuthored
/// <summary> The name of the plugin. </summary>
public string Name
{
get
{
return "VaalCaster";
}
}
/// <summary>The author of the plugin.</summary>
public string Author
{
get
{
return "Bossland GmbH";
}
}
/// <summary> The description of the plugin. </summary>
public string Description
{
get
{
return "A plugin that casts vaal skills under specific conditions.";
}
}
/// <summary>The version of the plugin.</summary>
public string Version
{
get
{
return "0.0.1.1";
}
}
#endregion
#region Implementation of IBase
/// <summary>Initializes this plugin.</summary>
public void Initialize()
{
Log.DebugFormat("[VaalCaster] Initialize");
}
/// <summary>Deinitializes this object. This is called when the object is being unloaded from the bot.</summary>
public void Deinitialize()
{
Log.DebugFormat("[VaalCaster] Deinitialize");
}
#endregion
#region Implementation of IRunnable
/// <summary> The plugin start callback. Do any initialization here. </summary>
public void Start()
{
Log.DebugFormat("[VaalCaster] Start");
}
/// <summary> The plugin tick callback. Do any update logic here. </summary>
public void Tick()
{
if (!LokiPoe.IsInGame || LokiPoe.Me.IsInTown || LokiPoe.Me.IsDead)
return;
var monsters = LokiPoe.ObjectManager.GetObjectsByType<Monster>()
.Where(m => !m.IsDead &&
m.IsHostile &&
m.Distance < 60).ToList();
//use vaal skill on unique monster
if (monsters.Any(m => m.Rarity == Loki.Game.GameData.Rarity.Unique))
{
UseVaalSkill();
return;
}
var hasBoxes = LokiPoe.ObjectManager.GetObjectsByType<Chest>()
.Any(b => b.IsStrongBox &&
!b.IsOpened &&
b.Distance < 20);
if (!monsters.Any() && hasBoxes)
{
//use skill before opening box
UseVaalSkill();
return;
}
}
public void UseVaalSkill()
{
var skill = LokiPoe.InGameState.SkillBarPanel.Skills.FirstOrDefault(s => s.Name == "Vaal Haste");
if (IsCastableHelper(skill) && skill.CanUse())
{
var err1 = LokiPoe.InGameState.SkillBarPanel.Use(skill.Slot, false);
Log.ErrorFormat("[Logic] Use returned {0} for {1}.", err1, skill.Name);
}
}
private bool IsCastableHelper(Skill skill)
{
return skill != null && skill.IsCastable && !skill.IsTotem && !skill.IsTrap && !skill.IsMine;
}
/// <summary> The plugin stop callback. Do any pre-dispose cleanup here. </summary>
public void Stop()
{
Log.DebugFormat("[VaalCaster] Stop");
}
#endregion
#region Implementation of IConfigurable
/// <summary>The settings object. This will be registered in the current configuration.</summary>
public JsonSettings Settings
{
get
{
return null;
}
}
/// <summary> The plugin's settings control. This will be added to the Exilebuddy Settings tab.</summary>
public UserControl Control
{
get
{
return null;
}
}
#endregion
#region Implementation of ILogic
/// <summary>
/// Coroutine logic to execute.
/// </summary>
/// <param name="type">The requested type of logic to execute.</param>
/// <param name="param">Data sent to the object from the caller.</param>
/// <returns>true if logic was executed to handle this type and false otherwise.</returns>
public async Task<bool> Logic(string type, params dynamic[] param)
{
return false;
}
/// <summary>
/// Non-coroutine logic to execute.
/// </summary>
/// <param name="name">The name of the logic to invoke.</param>
/// <param name="param">The data passed to the logic.</param>
/// <returns>Data from the executed logic.</returns>
public object Execute(string name, params dynamic[] param)
{
return null;
}
#endregion
#region Implementation of IEnableable
/// <summary> The plugin is being enabled.</summary>
public void Enable()
{
Log.DebugFormat("[VaalCaster] Enable");
}
/// <summary> The plugin is being disabled.</summary>
public void Disable()
{
Log.DebugFormat("[VaalCaster] Disable");
}
#endregion
#region Override of Object
/// <summary>Returns a string that represents the current object.</summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString()
{
return Name + ": " + Description;
}
#endregion
}
}