/// <summary>
/// A player mover instance that uses Lightning Warp when it's not on cooldown to move faster.
/// </summary>
public class LightningWarpPlayerMover : IPlayerMover
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
private readonly IPlayerMover _corePlayerMover;
private readonly Stopwatch _castStopwatch = Stopwatch.StartNew();
/// <summary>
/// Assigns the current PlayerMover instance to one of this type.
/// </summary>
public static void Activate()
{
if (PlayerMover.Instance is LockstepPlayerMover || PlayerMover.Instance is PredictivePlayerMover)
{
PlayerMover.Instance = new LightningWarpPlayerMover(PlayerMover.Instance);
}
else
{
Log.ErrorFormat(
"[LightningWarpPlayerMover] LightningWarpPlayerMover.Activate only works when the current PlayerMover instance is LockstepPlayerMover or PredictivePlayerMover.");
}
}
internal LightningWarpPlayerMover(IPlayerMover corePlayerMover)
{
_corePlayerMover = corePlayerMover;
}
/// <summary>
/// Attempts to move towards a position. This function will perform pathfinding logic and take into consideration move distance
/// to try and smoothly move towards a point.
/// </summary>
/// <param name="position">The position to move towards.</param>
/// <param name="user">A user object passed.</param>
/// <returns>true if the position was moved towards, and false if there was a pathfinding error.</returns>
public bool MoveTowards(Vector2i position, params dynamic[] user)
{
var myPos = LokiPoe.Me.Position;
if (myPos.Distance(position) < 50)
{
return _corePlayerMover.MoveTowards(position, user);
}
if (_castStopwatch.ElapsedMilliseconds > 500)
{
var skill = LokiPoe.Me.SkillBarSkills.FirstOrDefault(s => s.Name == "Lightning Warp");
if (skill != null)
{
if (skill.CanUse())
{
var err = LokiPoe.InGameState.SkillBarPanel.UseAt(skill.Slot, false,
myPos.GetPointAtDistanceAfterThis(position, 50));
if (err != LokiPoe.InGameState.UseError.None)
{
Log.ErrorFormat("[LightningWarpPlayerMover] Use returned {0}.", err);
}
var lat = LatencyTracker.AverageLatency*2;
using (LokiPoe.Memory.ReleaseFrame(LokiPoe.UseHardlock))
{
Thread.Sleep(lat);
}
_castStopwatch.Restart();
}
}
}
return _corePlayerMover.MoveTowards(position, user);
}
}
/// <summary>
/// A player mover instance that uses Phase Run when it's not on cooldown to move faster.
/// </summary>
public class PhaseRunPlayerMover : IPlayerMover
{
private static readonly ILog Log = Logger.GetLoggerInstanceForType();
private readonly IPlayerMover _corePlayerMover;
/// <summary>
/// Assigns the current PlayerMover instance to one of this type.
/// </summary>
public static void Activate()
{
if (PlayerMover.Instance is LockstepPlayerMover || PlayerMover.Instance is PredictivePlayerMover)
{
PlayerMover.Instance = new PhaseRunPlayerMover(PlayerMover.Instance);
}
else
{
Log.ErrorFormat(
"[PhaseRunPlayerMover] Activate only works when the current PlayerMover instance is LockstepPlayerMover or PredictivePlayerMover.");
}
}
internal PhaseRunPlayerMover(IPlayerMover corePlayerMover)
{
_corePlayerMover = corePlayerMover;
}
/// <summary>
/// Attempts to move towards a position. This function will perform pathfinding logic and take into consideration move distance
/// to try and smoothly move towards a point.
/// </summary>
/// <param name="position">The position to move towards.</param>
/// <param name="user">A user object passed.</param>
/// <returns>true if the position was moved towards, and false if there was a pathfinding error.</returns>
public bool MoveTowards(Vector2i position, params dynamic[] user)
{
var skill = LokiPoe.Me.SkillBarSkills.FirstOrDefault(s => s.Name == "Phase Run");
if (skill != null)
{
if (skill.CanUse())
{
var err = LokiPoe.InGameState.SkillBarPanel.Use(skill.Slot, false);
if (err != LokiPoe.InGameState.UseError.None)
{
Log.ErrorFormat("[PhaseRunPlayerMover] Use returned {0}.", err);
}
}
}
return _corePlayerMover.MoveTowards(position, user);
}
}