StanceLink = {} StanceLink.Const = { ChatCmd = {"/stancelink", "/slnk"}, ChatOpt = { { option = "set", desc = "links your currently equipped arms to your stance, so that whenever you enter that stance, you regain those arms.", method = "Add" }, { option = "clear", desc = "removes any link you might have with your current stance, so no arms will be equipped in future on changing to it.", method = "Clear" }, { option = "list", desc = "details whatever links you have setup between stances and arms.", method = "List" } }, Title = "StanceLink", Version = "r1a0", Desc = "Automatically equip weapons on warrior stance changes.", Chat = { SetArmLink = "%s (main-hand) and %s (secondary-hand) will now be equipped when you enter %s.", ClearArmLink = "The link for your %s has been cleared." }, Stance = { Ba = "Battle Stance", Bk = "Berserker Stance", De = "Defensive Stance" } } local const = StanceLink.Const StanceLink.Defaults = { [const.Stance.Ba] = {}, [const.Stance.Bk] = {}, [const.Stance.De] = {} } StanceLink.Obj = AceAddon:new{ name = const.Title, version = const.Version, description = const.Desc, author = "Rowne", aceCompatible = "100", category = ACE_CATEGORY_INTERFACE, db = AceDbClass:new("StanceLinkDB"), defaults = StanceLink.Defaults, cmd = AceChatCmdClass:new(const.ChatCmd, const.ChatOpt), Enable = function(self) self:RegisterEvent("PLAYER_AURAS_CHANGED", "ArmsSwap") end, Set = function(self, i, s) local db = self:DetermineStance() if not db then return end local h1 = GetInventoryItemName(CharacterMainHandSlot:GetID()) local h2 = GetInventoryItemName(CharacterSecondaryHandSlot:GetID()) self:Msg(const.Chat.SetArmLink, h1, h2, db) db = self:Get(db) db["Main-hand:"] = h1 db["Secondary-hand:"] = h2 end, Clear = function(self, i) local db = self:DetermineStance() if not db then return end self:Msg(const.Chat.ClearArmLink, db) db = self:Get(db) db = {} end, List = function(self) local doList = function(type) local tmpDB = {} for k, v in self:Get(type) do tinsert(tmpDB, {text = k, val = v}) end self.cmd:report(type.."...", tmpDB) end doList(const.Stance.Ba) doList(const.Stance.Bk) doList(const.Stance.De) end, DetermineStance = function(self) local b b = b or self:Buffs(const.Stance.Ba, true) b = b or self:Buffs(const.Stance.Bk, true) b = b or self:Buffs(const.Stance.De, true) return b end, ArmsSwap = function(self) local db = self:DetermineStance() if not db then return end db = self:Get(db) local h1 = db["Main-hand:"] local h2 = db["Secondary-hand:"] h1 = self:FindItemByName(h1) h2 = self:FindItemByName(h2) PickupContainerItem(h1.x, h1.y) EquipCursorItem(16) PickupContainerItem(h2.x, h2.y) EquipCursorItem(17) end } StanceLink.Obj:RegisterForLoad() ace:RegisterFunctions(StanceLink.Obj, { version = 1.0, Msg = function(self, ...) self.cmd:msg(unpack(arg)) end, Get = function(self, var) return self.db:get(self.profilePath, var) end, Buffs = function(b, n) local t = CreateFrame("GameTooltip", "TempBuffTip", UIParent, "GameTooltipTemplate") t:SetOwner(TempBuffTip, "ANCHOR_NONE") local eC = FALSE t:ClearLines() for k, v in b do if eC then break end for j = 1, 10 do if not UnitBuff("player", j) and not UnitDebuff("player", j) then break end if UnitBuff("player", j) then t:SetUnitBuff("player", j) local m = TempBuffTipTextLeft1:GetText() if strfind(m, v) then eC = n and b or TRUE break end end if UnitDebuff("player", j) then t:SetUnitDebuff("player", j) local m = TempBuffTipTextLeft1:GetText() if strfind(m, v) then eC = n and b or TRUE break end end end end return eC end, FindItemByName = function(n) for x = 0,NUM_BAG_FRAMES do for y = 1, GetContainerNumSlots(x) do if strfind(GetContainerItemLink(x, y) or "", n) then return {x = x, y = y} end end end end })