using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
using Zeta;
using Zeta.Common;
using Zeta.Common.Plugins;
using Zeta.Internals;
using Zeta.Internals.Actors;
using Zeta.Internals.Service;
namespace Unstucker
{
public class Unstucker : IPlugin
{
#region Iplugin
public bool Equals(IPlugin other)
{
// we should probably be comparing versions too
return other.Name == Name;
}
public string Author
{
get { return "eax"; }
}
public string Description
{
get { return "Automatically teleports player back to down when stuck."; }
}
public string Name
{
get { return "Unstucker"; }
}
public Version Version
{
get { return new Version(1, 0); }
}
public Window DisplayWindow { get { return null; } }
/// <summary> Executes the shutdown action. This is called when the bot is shutting down. (Not when Stop() is called) </summary>
public void OnShutdown()
{
}
/// <summary> Executes the enabled action. This is called when the user has enabled this specific plugin via the GUI. </summary>
public void OnEnabled()
{
Logging.Write("Unstucker enabled.");
}
/// <summary> Executes the disabled action. This is called whent he user has disabled this specific plugin via the GUI. </summary>
public void OnDisabled()
{
Logging.Write("Unstucker disabled.");
}
#endregion
private DateTime LastCheckTime { get; set; }
private DateTime LastLogTime { get; set; }
private List<Vector3> LoggedPositions { get; set; };
private static float GetMaxDistanceTraveled(List<Vector3> positions)
{
float max = 0F;
for (int i = 0; i < positions.Count; ++i)
for (int j = 0; j < positions.Count; ++j)
max = Math.Max(max, Math.Abs(positions[i].Distance(positions[j])));
return max;
}
public void OnInitialize()
{
LastCheckTime = DateTime.Now;
LastLogTime = DateTime.Now;
LoggedPositions = new List<Vector3>();
LoggedPositions.Add(ZetaDia.Actors.Me.Position);
}
public void OnPulse()
{
// if we're not in game or if...we're not valid?...then we do nothing
if (!ZetaDia.IsInGame || !ZetaDia.Me.IsValid)
return;
// if it's been 10 seconds since we've logged a position, then we log a new position
if (DateTime.Now.Subtract(LastLogTime).TotalSeconds > 10)
{
LastLogTime = DateTime.Now;
LoggedPositions.Add(ZetaDia.Actors.Me.Position);
}
// if it's been 60 seconds since we've last evaluated the logged positions, evaluate the logged positions
if (DateTime.Now.Subtract(LastCheckTime).TotalSeconds > 60)
{
LastCheckTime = DateTime.Now;
// if our person has not traveled 10 yards or whatever in the last 60 seconds, we're stuck
if (GetMaxDistanceTraveled(LoggedPositions) < 10f)
{
if (!ZetaDia.Actors.Me.IsInTown)
{
ZetaDia.Actors.Me.UseTownPortal();
Thread.Sleep(8000);
}
ZetaDia.Service.Games.LeaveGame();
}
// ok now we reset everything
LastLogTime = DateTime.Now;
LoggedPositions.Clear();
}
}
}
}