I had posted this as a response to a request on another thread.
Code:
#region Using Directives
using ArcheBuddy.Bot.Classes;
using System;
using System.Linq;
using System.Threading;
using System.ComponentModel;
#endregion
namespace Experiment
{
public class OwnersMark
: Core, INotifyPropertyChanged
{
#region Public Static Methods
public static string GetPluginAuthor()
{
return "AUser";
}
public static string GetPluginVersion()
{
return "1.0.0.3";
}
public static string GetPluginDescription()
{
return "Keep Owner's Mark on Vehicle";
}
#endregion
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(name));
}
void HandleStateChange(object sender, PropertyChangedEventArgs e)
{
Log("Mount Status: " + (PlayerMounted ? "Sitting" : "Standing"));
if (PlayerMounted)
refreshBuff(true);
}
#endregion
#region Properties
private bool _mounted;
public bool PlayerMounted
{
get { return _mounted; }
set
{
var original = _mounted;
_mounted = value;
if (_mounted != original)
OnPropertyChanged("PlayerMounted");
}
}
#endregion
#region Public Methods
//Call on plugin start
public void PluginRun()
{
ClearLogs();
Log("Starting ------------------");
foreach (var mount in getCreatures().Where(a => a.ownerUniqId == me.uniqId && (a.type == BotTypes.Slave || a.type == BotTypes.Mount)))
Log(string.Format("Name: {0} Type: {1}", mount.name, mount.type.ToString()));
SetGroupStatus("Guard", true);
this.PropertyChanged += HandleStateChange;
DoIt();
}
//Call on plugin stop
public void PluginStop()
{
Log("Stopping ------------------");
DelGroupStatus("Guard");
this.PropertyChanged -= HandleStateChange;
}
public void DoIt()
{
while (true)
{
PlayerMounted = this.isMounted();
if (GetGroupStatus("Guard"))
if (PlayerMounted)
refreshBuff();
Thread.Sleep(50);
}
}
#endregion
#region Private Methods
private void refreshBuff(bool forceRecast = false)
{
var mount = this.getSlave();
BindSlave();
Thread.Sleep(1000);
if (forceRecast)
{
// Disregard existing buff and reset
SetTarget(mount);
UseSkill("Owner's Mark");
}
else if (!mount.getBuffs().Any(a => a.name == "Owner's Mark"))
{
// Apply only if buff doesn't already exist
UseSkill("Owner's Mark");
}
}
#endregion
}
}
Last edited: