Apoc
Well-Known Member
- Joined
- Jan 16, 2010
- Messages
- 2,790
- Reaction score
- 94
So, I got tired of using my slow scripts to switch between MF and DPS gear, so I wrote a quick plugin to handle it for me.
It will swap any gear in your backpack that has MF into their correct slot, and then revert those changes, all by the press of a hotkey! (Default is F1)
The plugin doesn't care where your items are, or what type. I wrote this very quickly as a proof-of-concept and maybe some example code of how hotkeys work in Demonbuddy.
I will not be supporting this plugin. If you guys find bugs, hopefully you can fix them yourselves.
Usage: simply hit F1 in game and it will swap your gear!
It will swap any gear in your backpack that has MF into their correct slot, and then revert those changes, all by the press of a hotkey! (Default is F1)
The plugin doesn't care where your items are, or what type. I wrote this very quickly as a proof-of-concept and maybe some example code of how hotkeys work in Demonbuddy.
I will not be supporting this plugin. If you guys find bugs, hopefully you can fix them yourselves.
Usage: simply hit F1 in game and it will swap your gear!
Code:
using System;using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using Zeta;
using Zeta.Common;
using Zeta.Common.Plugins;
using Zeta.Internals.Actors;
namespace Demonbuddy.Plugins.QuickMFSwap
{
internal class MFSwap : IPlugin
{
private static Dictionary<InventorySlot, ACDItem> _originalItems;
private static readonly HashSet<int> IgnoreItems = new HashSet<int>();
private static bool _wearingMagicFindGear;
#region IPlugin Members
public bool Equals(IPlugin other)
{
return Name == other.Name;
}
public string Author { get { return "Apoc"; } }
public Version Version { get { return new Version(1, 0); } }
public string Name { get { return "MF Swapper"; } }
public string Description { get { return "Instantly swaps between MF gear and DPS gear"; } }
public Window DisplayWindow { get { return null; } }
public void OnPulse()
{
}
public void OnInitialize()
{
}
public void OnShutdown()
{
}
public void OnEnabled()
{
Hotkeys.RegisterHotkey("Quick MF Swap", SwapGear, Keys.F1);
}
public void OnDisabled()
{
#if DEBUG
// Only available in the next build of DB.
Hotkeys.RemoveHotkey("Quick MF Swap");
#endif
}
#endregion
private static void SwapGear()
{
using (ZetaDia.Memory.AcquireFrame())
{
ZetaDia.Actors.Update();
if (!_wearingMagicFindGear)
{
_originalItems =
ZetaDia.Me.Inventory.Equipped.ToDictionary(
key => key.InventorySlot, v => v);
IgnoreItems.Clear();
// Equip MF items for each slot. (Find the highest MF ones and equip)
Equip(InventorySlot.PlayerNeck);
Equip(InventorySlot.PlayerRightFinger);
Equip(InventorySlot.PlayerLeftFinger);
Equip(InventorySlot.PlayerHead);
Equip(InventorySlot.PlayerShoulders);
Equip(InventorySlot.PlayerTorso);
Equip(InventorySlot.PlayerBracers);
Equip(InventorySlot.PlayerHands);
Equip(InventorySlot.PlayerWaist);
Equip(InventorySlot.PlayerLegs);
Equip(InventorySlot.PlayerFeet);
Equip(InventorySlot.PlayerRightHand);
Equip(InventorySlot.PlayerLeftHand);
// Simple state holder so we know when we're wearing MF gear.
_wearingMagicFindGear = true;
}
else
{
// Go back to our original set of gear, in their exact places!
foreach (var i in _originalItems)
{
ZetaDia.Me.Inventory.EquipItem(i.Value.DynamicId, i.Key);
}
_wearingMagicFindGear = false;
}
}
}
private static ACDItem GetBestMagicFindItem(InventorySlot slot)
{
List<int> ignoreItemIds = _originalItems.Values.Select(i => i.DynamicId).ToList();
// For each item that matches the slot we're requesting, get the highest MF.
return (from i in ZetaDia.Me.Inventory.Backpack
// Ensure the item is valid.
// Correct slot, and not on ignore lists.
where i.ValidInventorySlots.Contains(slot) &&
!ignoreItemIds.Contains(i.DynamicId) &&
!IgnoreItems.Contains(i.DynamicId) &&
// Make sure the item actually has MF!
i.Stats.MagicFind > 0
// Order by highest MF
orderby i.Stats.MagicFind descending
// Grab the first.
select i).FirstOrDefault();
}
private static void Equip(InventorySlot slot)
{
ACDItem i = GetBestMagicFindItem(slot);
if (i != null)
{
ZetaDia.Me.Inventory.EquipItem(i.DynamicId, slot);
// We equipped the item, so lets ignore it for the next run of getting best equip.
// This avoids a bug with equipping the same ring twice!
IgnoreItems.Add(i.DynamicId);
}
}
}
}