Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ADDON_NAME, PRIVATE_TABLE = ...
- local _G = getfenv(0)
- local UIParent = _G.UIParent
- local WorldFrame = _G.WorldFrame
- local GetTime = _G.GetTime
- local UnitGUID = _G.UnitGUID
- local IsMounted = _G.IsMounted
- local CanLootUnit = _G.CanLootUnit
- local CreateFrame = _G.CreateFrame
- local MouselookStop = _G.MouselookStop
- local IsMouselooking = _G.IsMouselooking
- local InCombatLockdown = _G.InCombatLockdown
- local IsEquippedItemType = _G.IsEquippedItemType
- local CanScanResearchSite = _G.CanScanResearchSite
- local ClearOverrideBindings = _G.ClearOverrideBindings
- local SetOverrideBindingClick = _G.SetOverrideBindingClick
- local LibStub = _G.LibStub
- local AceAddon = LibStub("AceAddon-3.0")
- PRIVATE_TABLE.addon = PRIVATE_TABLE.addon or {}
- local BUTTON_NAME = "LootARangMaticOld"
- local ACTION_DOUBLE_WAIT = 0.4
- local MIN_ACTION_DOUBLECLICK = 0.05
- local LOOT_A_RANG_1_ID = 60854
- local LOOT_A_RANG_2_ID = 109167
- local FETCH_SPELL_ID = 125050
- local COMBAT_MOUNT_SPELL_IDS = {[164222]=true, [165803]=true}
- --settings to be
- local hideErrors = true
- local Addon = AceAddon:NewAddon(PRIVATE_TABLE.addon, ADDON_NAME, "AceEvent-3.0", "AceHook-3.0")
- local options = {
- type = "group",
- args = {
- engineeringOnlyWarn = {
- name = "Engineering Only Warn",
- desc = "Warn when character doesn't have needed 125 engineering skill.",
- type = "toggle",
- set = function(info,val) Addon.settings.global.engineeringOnlyWarn = val end,
- get = function(info) return Addon.settings.global.engineeringOnlyWarn end
- },
- draenorOnlyWarn = {
- name = "Draenor Only Warn",
- desc = "Warn when not in Draenor.",
- type = "toggle",
- set = function(info,val) Addon.settings.global.draenorOnlyWarn = val end,
- get = function(info) return Addon.settings.global.draenorOnlyWarn end
- },
- onlyLootTargetOrMouseover = {
- name = "Only loot Target or Mouseover",
- desc = "",
- type = "toggle",
- set = function(info,val) Addon.settings.global.onlyLootTargetOrMouseover = val end,
- get = function(info) return Addon.settings.global.onlyLootTargetOrMouseover end
- },
- onlyLootTargetOrMouseoverInDigsite = {
- name = "Only loot Target or Mouseover while in a Digsite",
- desc = "",
- type = "toggle",
- set = function(info,val) Addon.settings.global.onlyLootTargetOrMouseoverInDigsite = val end,
- get = function(info) return Addon.settings.global.onlyLootTargetOrMouseoverInDigsite end
- },
- onlyLootTargetOrMouseoverFishing = {
- name = "Only loot Target or Mouseover while Fishing Pole is Equipped",
- desc = "",
- type = "toggle",
- set = function(info,val) Addon.settings.global.onlyLootTargetOrMouseoverFishing = val end,
- get = function(info) return Addon.settings.global.onlyLootTargetOrMouseoverFishing end
- },
- hideErrors = {
- name = "Try to Hide Errors",
- desc = "",
- type = "toggle",
- set = function(info,val) Addon.settings.global.hideErrors = val end,
- get = function(info) return Addon.settings.global.hideErrors end
- },
- }
- }
- local FISHING_POLES_NAME = GetItemSubClassInfo(LE_ITEM_CLASS_WEAPON, LE_ITEM_WEAPON_FISHINGPOLE);
- local function HoldingFishingPole()
- if not FISHING_POLES_NAME then
- FISHING_POLES_NAME = GetItemSubClassInfo(LE_ITEM_CLASS_WEAPON, LE_ITEM_WEAPON_FISHINGPOLE);
- end
- return IsEquippedItemType(FISHING_POLES_NAME)
- end
- local function InCombat()
- return PRIVATE_TABLE.inCombat or InCombatLockdown()
- end
- local function CheckForLoot()
- return Addon.settings.global.onlyLootTargetOrMouseover
- or (Addon.settings.global.onlyLootTargetOrMouseoverInDigsite and CanScanResearchSite())
- or (Addon.settings.global.onlyLootTargetOrMouseoverFishing and HoldingFishingPole())
- end
- local function TargetOrMouseoverHasLoot()
- local targetGUID, mouseoverGUID = UnitGUID("target"), UnitGUID("mouseover")
- return (targetGUID and CanLootUnit(targetGUID)) or (mouseoverGUID and CanLootUnit(mouseoverGUID))
- end
- local function HasEngineering()
- prof1, prof2 = GetProfessions()
- _, _, rank1, _, _, _, skillID1 = GetProfessionInfo(prof1)
- _, _, rank2, _, _, _, skillID2 = GetProfessionInfo(prof2)
- return (skillID1 == 202 and rank1 >= 1) or (skillID2 == 202 and rank2 >= 1)
- end
- local function MountBlockingCast()
- if not IsMounted() then
- return false;
- end
- local i = 1;
- local name, _, _, _, _, _, _, _, _, _, spellID = UnitBuff("player", i, "CANCELABLE");
- while name do
- if COMBAT_MOUNT_SPELL_IDS[spellID] then
- return false;
- end
- i = i + 1;
- name, _, _, _, _, _, _, _, _, _, spellID = UnitBuff("player", i, "CANCELABLE");
- end;
- return true;
- end
- local function SafeToLoot()
- if PRIVATE_TABLE.moveing or MountBlockingCast() or InCombat() then
- return false
- end
- if CheckForLoot() and not TargetOrMouseoverHasLoot() then
- return false
- end
- return true
- end
- function Addon:WantsToLoot()
- return SafeToLoot() and (
- (PlayerHasToy(LOOT_A_RANG_1_ID) and select(1, GetItemCooldown(LOOT_A_RANG_1_ID)) == 0)
- or (PlayerHasToy(LOOT_A_RANG_2_ID) and select(1, GetItemCooldown(LOOT_A_RANG_2_ID)) == 0)
- or (IsSpellKnown(FETCH_SPELL_ID) and select(1, GetSpellCooldown(FETCH_SPELL_ID)) == 0)
- )
- end
- function Addon:RequestSkip()
- PRIVATE_TABLE.skipLoot = true
- end
- local Sound_EnableErrorSpeech = GetCVar("Sound_EnableErrorSpeech")
- function Addon:OnInitialize()
- if not PRIVATE_TABLE.secureActionButton then
- local button = CreateFrame("Button", BUTTON_NAME, UIParent, "SecureActionButtonTemplate")
- button:Hide()
- button:EnableMouse(true)
- button:RegisterForClicks("RightButtonUp")
- button:SetAttribute("action", nil)
- button:SetScript("PreClick", function(self, mouse_button, is_down)
- if hideErrors then
- Sound_EnableErrorSpeech = GetCVar("Sound_EnableErrorSpeech")
- SetCVar("Sound_EnableErrorSpeech",0)
- UIErrorsFrame:UnregisterEvent("UI_ERROR_MESSAGE")
- end
- end)
- button:SetScript("PostClick", function(self, mouse_button, is_down)
- C_Timer.After(0.2, function()
- if hideErrors then
- UIErrorsFrame:RegisterEvent("UI_ERROR_MESSAGE")
- SetCVar("Sound_EnableErrorSpeech",Sound_EnableErrorSpeech)
- end
- end)
- if PRIVATE_TABLE.bindingOn and not InCombat() then
- ClearOverrideBindings(self)
- PRIVATE_TABLE.bindingOn = false
- else
- PRIVATE_TABLE.bindingStuck = true
- end
- end)
- PRIVATE_TABLE.secureActionButton = button
- end
- Addon.settings = LibStub("AceDB-3.0"):New("LootARangMatic", {
- global = {
- engineeringOnlyWarn = false,
- draenorOnlyWarn = true,
- onlyLootTargetOrMouseover = true,
- onlyLootTargetOrMouseoverInDigsite = true,
- onlyLootTargetOrMouseoverFishing = true,
- hideErrors = true,
- }
- })
- LibStub("AceConfig-3.0"):RegisterOptionsTable("LootARangMatic", options, {"lrm", "lootarangmatic"})
- end
- function Addon:OnEnable()
- self:RegisterEvent("PLAYER_REGEN_DISABLED", "OnRegenDisabled")
- self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnRegenEnabled")
- self:RegisterEvent("PLAYER_STARTED_MOVING", "OnPlayerMoveStart")
- self:RegisterEvent("PLAYER_STOPPED_MOVING", "OnPlayerMoveStop")
- self:SecureHookScript(WorldFrame, "OnMouseDown", "OnMouseDown")
- end
- function Addon:OnDisable()
- self:UnregisterEvent("PLAYER_REGEN_DISABLED")
- self:UnregisterEvent("PLAYER_REGEN_ENABLED")
- self:UnregisterEvent("PLAYER_STARTED_MOVING")
- self:UnregisterEvent("PLAYER_STOPPED_MOVING")
- self:Unhook(WorldFrame, "OnMouseDown")
- end
- function Addon:OnRegenDisabled()
- PRIVATE_TABLE.inCombat = true
- if PRIVATE_TABLE.bindingOn or PRIVATE_TABLE.bindingStuck then
- ClearOverrideBindings(PRIVATE_TABLE.secureActionButton)
- PRIVATE_TABLE.bindingOn = false
- PRIVATE_TABLE.bindingStuck = false
- end
- end
- function Addon:OnRegenEnabled()
- PRIVATE_TABLE.inCombat = false
- if PRIVATE_TABLE.bindingStuck then
- ClearOverrideBindings(PRIVATE_TABLE.secureActionButton)
- PRIVATE_TABLE.bindingOn = false
- PRIVATE_TABLE.bindingStuck = false
- end
- end
- function Addon:OnPlayerMoveStart()
- PRIVATE_TABLE.moveing = true
- end
- function Addon:OnPlayerMoveStop()
- PRIVATE_TABLE.moveing = false
- end
- function Addon:OnMouseDown(frame, button, down)
- if button == "RightButton" then
- if PRIVATE_TABLE.lastClicked then
- local doubleTime = GetTime() - PRIVATE_TABLE.lastClicked
- if doubleTime < ACTION_DOUBLE_WAIT and doubleTime > MIN_ACTION_DOUBLECLICK then
- PRIVATE_TABLE.lastClicked = nil
- if SafeToLoot() then
- if PRIVATE_TABLE.skipLoot then
- PRIVATE_TABLE.skipLoot = false
- else
- local useIssue, bind = "", false
- if not bind and PlayerHasToy(LOOT_A_RANG_1_ID) and select(2, GetItemCooldown(LOOT_A_RANG_1_ID)) == 0 then
- if HasEngineering() then
- PRIVATE_TABLE.secureActionButton:SetAttribute("type", "item")
- PRIVATE_TABLE.secureActionButton:SetAttribute("item", select(1, GetItemInfo(LOOT_A_RANG_1_ID)))
- bind = true;
- else
- if Addon.settings.global.engineeringOnlyWarn then
- useIssue = format("Can't use %s without 125 skill in Engineering", select(2, GetItemInfo(LOOT_A_RANG_1_ID)))
- end
- end
- end
- if not bind and PlayerHasToy(LOOT_A_RANG_2_ID) and select(2, GetItemCooldown(LOOT_A_RANG_2_ID)) == 0 then
- local currentMapId = C_Map.GetBestMapForUnit("player")
- if(currentMapId) then
- if MapUtil.GetMapParentInfo(currentMapId, Enum.UIMapType.Continent).mapID == 572 then
- PRIVATE_TABLE.secureActionButton:SetAttribute("type", "item")
- PRIVATE_TABLE.secureActionButton:SetAttribute("item", select(1, GetItemInfo(LOOT_A_RANG_2_ID)))
- bind = true;
- else
- if Addon.settings.global.draenorOnlyWarn then
- useIssue = format("Can only use use %s in Draenor", select(2, GetItemInfo(LOOT_A_RANG_2_ID)))
- end
- end
- end
- end
- if not bind and IsSpellKnown(FETCH_SPELL_ID) and select(2, GetSpellCooldown(FETCH_SPELL_ID)) == 0 then
- PRIVATE_TABLE.secureActionButton:SetAttribute("type", "spell")
- PRIVATE_TABLE.secureActionButton:SetAttribute("spell", select(1, GetSpellInfo(FETCH_SPELL_ID)))
- bind = true;
- end
- if not bind and not PlayerHasToy(LOOT_A_RANG_1_ID) and not PlayerHasToy(LOOT_A_RANG_2_ID) and not IsSpellKnown(FETCH_SPELL_ID) then
- useIssue = "No Loot-A-Rang or Fetch glyph found."
- end
- if bind then
- if IsMouselooking() then
- MouselookStop()
- end
- SetOverrideBindingClick(PRIVATE_TABLE.secureActionButton, true, "BUTTON2", BUTTON_NAME)
- PRIVATE_TABLE.bindingOn = true
- else
- print(useIssue)
- end
- end
- end
- elseif doubleTime >= ACTION_DOUBLE_WAIT then
- PRIVATE_TABLE.lastClicked = GetTime()
- end
- else
- PRIVATE_TABLE.lastClicked = GetTime()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement