craftiestelk
New Member
- Joined
- Jun 3, 2011
- Messages
- 123
- Reaction score
- 1
On todays edition of "Craftiestelk does shit he doesn't know how to do!", it's programming C#!
I have never really done any programming in C# or any other C-language, only Java and Python. After looking through several other plugins, and taking some major influence from AutoEquip2 (lovely plugin, Nesox!), I've finally made a plugin that will compile without errors (and according to debug, it works!).
The plugin will roll Need of it sees one of 8 mount-items drop (the ones from 5-mans, not from raids). At least that is the theory. It will also not roll need if you already know the mount (no need to be a dick). However, it's kinda hard to test it, so I'm posting it here as a beta/WIP for people to test if they're interested.
WARNING: This plugin _may_ roll Greed or Pass on a mount, or just sit there doing nothing, as I'm not sure how to make sure it overrides the loot-rolling before other addons (like AutoEquip2). So try it out, no promises from me. If you do try it, please please post here if it works or doesn't work (with a log if it doesn't).
And for anyone with knowledge in C#, if you see any glaring mistakes/errors (there are bound to be some), please point them out and I'll be mighty grateful. If anyone want to modify, fix, reuse, or in other ways play around with my code, be my guest. However I'd like a mention if you use large amounts of the code.
Code:

The plugin will roll Need of it sees one of 8 mount-items drop (the ones from 5-mans, not from raids). At least that is the theory. It will also not roll need if you already know the mount (no need to be a dick). However, it's kinda hard to test it, so I'm posting it here as a beta/WIP for people to test if they're interested.
WARNING: This plugin _may_ roll Greed or Pass on a mount, or just sit there doing nothing, as I'm not sure how to make sure it overrides the loot-rolling before other addons (like AutoEquip2). So try it out, no promises from me. If you do try it, please please post here if it works or doesn't work (with a log if it doesn't).
And for anyone with knowledge in C#, if you see any glaring mistakes/errors (there are bound to be some), please point them out and I'll be mighty grateful. If anyone want to modify, fix, reuse, or in other ways play around with my code, be my guest. However I'd like a mention if you use large amounts of the code.
Code:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.BehaviorTree;
using Styx.Logic.Inventory;
using Styx.Plugins.PluginClass;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
namespace Styx.Bot.Plugins.MountRoll
{
public partial class MountRoll : HBPlugin
{
#region Overrides of HBPlugin
/// <summary>Initializes this plugin after it has been properly loaded.</summary>
public override void Initialize()
{
Lua.Events.AttachEvent("START_LOOT_ROLL", HandleLootRoll);
Lua.Events.AttachEvent("CONFIRM_LOOT_ROLL", HandleConfirmLootRoll);
}
/// <summary>Dispose of this plugin, cleaning up any resources it uses.</summary>
public override void Dispose()
{
Lua.Events.DetachEvent("START_LOOT_ROLL", HandleLootRoll);
Lua.Events.DetachEvent("CONFIRM_LOOT_ROLL", HandleConfirmLootRoll);
}
public override string Name { get { return "MountRoll"; } }
public override string Author { get { return "Craftiestelk"; } }
public override Version Version { get { return new Version(1, 0, 0); } }
#endregion
//list of all raredrop mounts from 5-man normal/heroics (NO RAID MOUNTS)
//ID of the item, spellID of the mount (to avoid rolling on one you already know)
private static Dictionary<uint, uint> _needID = new Dictionary<uint, uint>()
{
{13335,17481}, //Deathcharger's Reins
{63040,88742}, //Reins of the Drake of the North Wind
{63043,88746}, //Reins of the Vitreous Stone Drake
{69747,98204}, //Amani Battle Bear
{44151,59996}, //Reins of the Blue Proto-Drake
{43951,59569}, //Reins of the Bronze Drake
{32768,41252}, //Reins of the Raven Lord
{35513,46628} //Swift White Hawkstrider
};
public override void Pulse()
{
return;
}
private static uint numMounts = Lua.GetReturnVal<uint>("return GetNumCompanions(\"MOUNT\")",0);
private static uint[] knownMounts = MountRoll.GetKnownMounts(numMounts);
//return a list of all known mounts by spellID
private static uint[] GetKnownMounts(uint numMounts)
{
if (numMounts == 0)
{
Log("No mounts known, exiting");
return null;
}
var mountList = new uint[numMounts];
for (int i = 1; i <= numMounts; i++)
{
var mountInfo = Lua.LuaGetReturnValue("return GetCompanionInfo(\"MOUNT\","+i+")", "mounts.lua");
if (mountInfo.Count < 6 || Int32.Parse(mountInfo[2]) == 0)
{
Log(true, "Error parsing mounts, cancelling");
return null;
}
mountList[i-1] = Convert.ToUInt32(mountInfo[2]);
Log(true, "Added mount to list of known: {0} : {1}", mountInfo[2], mountInfo[1]);
}
return mountList;
}
private void HandleLootRoll(object sender, LuaEventArgs e)
{
string rollId = e.Args[0].ToString();
string itemLink = Lua.GetReturnVal<string>("return GetLootRollItemLink(" + rollId + ")", 0);
string[] splitted = itemLink.Split(':');
uint itemId;
if (string.IsNullOrEmpty(itemLink) || (splitted.Length == 0 || splitted.Length < 2) || (!uint.TryParse(splitted[1], out itemId) || itemId == 0))
{
Log("Parsing ItemLink for lootroll failed!");
Log("ItemLink:{0}", itemLink);
return;
}
ItemInfo rollItemInfo = ItemInfo.FromId(itemId);
if (rollItemInfo == null)
{
Log("Retrieving item info for roll item failed");
Log("Item Id:{0} ItemLink:{1}", itemId, itemLink);
return;
}
string rollItemName = rollItemInfo.Name;
if (_needID.ContainsKey(itemId) && !knownMounts.Contains(_needID[itemId]))
{
Log("Mount found: {0}, rolling need!", rollItemName);
Lua.DoString("RollOnLoot(" + rollId + ", 1)");
}
}
}
public partial class MountRoll
{
private void HandleConfirmLootRoll(object sender, LuaEventArgs e)
{
//Log("Confirming Loot Roll");
double rollId = (double) e.Args[0];
double rollType = (double)e.Args[1];
//Log("RollId:{0} RollType:{1}", rollId, rollType);
Lua.DoString("ConfirmLootRoll({0},{1})", rollId, rollType);
}
private static void Log(bool isDebug, string format, params object [] args)
{
if (isDebug)
Logging.WriteDebug("[MountRoll]: {0}", string.Format(format, args));
else
Logging.Write("[MountRoll]: {0}", string.Format(format, args));
}
private static void Log(string format, params object [] args)
{
Log(false, format, args);
}
private static void Log(string message)
{
Log(false, message);
}
}
}