SpeedyAutoLoot自动拾取插件
SpeedyAutoLoot.lua
local AutoLoot = CreateFrame('Frame')SpeedyAutoLootDB = SpeedyAutoLootDB or {}
SpeedyAutoLootDB.global = SpeedyAutoLootDB.global or {}local BACKPACK_CONTAINER = BACKPACK_CONTAINER
local LOOT_SLOT_CURRENCY = LOOT_SLOT_CURRENCY
local LOOT_SLOT_ITEM = LOOT_SLOT_ITEM
local LOOT_SLOT_MONEY = LOOT_SLOT_MONEY
local NUM_BAG_SLOTS = NUM_BAG_SLOTS
local GetContainerNumFreeSlots = GetContainerNumFreeSlots
local GetCVarBool = GetCVarBool
local GetItemCount = GetItemCount
local GetItemInfo = GetItemInfo
local GetLootSlotInfo = GetLootSlotInfo
local GetLootSlotLink = GetLootSlotLink
local GetLootSlotType = GetLootSlotType
local GetNumLootItems = GetNumLootItems
local GetCursorPosition = GetCursorPosition
local IsFishingLoot = IsFishingLoot
local IsModifiedClick = IsModifiedClick
local LootSlot = LootSlot
local PlaySound = PlaySound
local SetCVar = SetCVar
local find = string.find
local select = select
local tContains = tContains
local errorList = { ERR_INV_FULL, ERR_ITEM_MAX_COUNT }
local fishingChannel = 'Master'function AutoLoot:PlayFishingSound()if IsFishingLoot() thenreturn (fishingChannel and PlaySound(SOUNDKIT.FISHING_REEL_IN, fishingChannel)) or PlaySound(SOUNDKIT.FISHING_REEL_IN)end
endfunction AutoLoot:PlayInventoryFullSound()if SpeedyAutoLootDB.global.enableSound and not self.isItemLocked thenPlaySound(SpeedyAutoLootDB.global.InventoryFullSound, 'Master')end
endfunction AutoLoot:LootUnderMouse(self, parent)if(GetCVar('lootUnderMouse') == '1') thenlocal x, y = GetCursorPosition()x = x / self:GetEffectiveScale()y = y / self:GetEffectiveScale()self:ClearAllPoints()self:SetPoint('TOPLEFT', UIParent, 'BOTTOMLEFT', x - 40, y + 20)self:GetCenter()self:Raise()elseself:ClearAllPoints()self:SetPoint('TOPLEFT', parent, 'TOPLEFT')end
endfunction AutoLoot:CalculateFreeSlots()local numTotalFree, numFreeSlots, bagFamily = 0for i = BACKPACK_CONTAINER, NUM_BAG_SLOTS donumFreeSlots, bagFamily = GetContainerNumFreeSlots(i)if bagFamily == 0 thennumTotalFree = numTotalFree + numFreeSlotsendendreturn numTotalFree
endfunction AutoLoot:ProcessLoot(itemLink, quantity, slotType)if slotType == LOOT_SLOT_MONEY thenreturn trueelseif slotType == LOOT_SLOT_CURRENCY thenreturn trueelseif slotType == LOOT_SLOT_ITEM thenif self:CalculateFreeSlots() > 0 thenreturn trueendlocal have = (GetItemCount(itemLink) or 0)if have > 0 thenlocal itemStackCount = (select(8,GetItemInfo(itemLink)) or 0)if itemStackCount > 1 thenwhile have > itemStackCount dohave = have - itemStackCountendlocal remain = itemStackCount - haveif remain >= quantity thenreturn trueendendendend
endfunction AutoLoot:ShowLootFrame(show)if self.XLoot thenif show thenself:LootUnderMouse(XLootFrame, UIParent)XLootFrame:SetParent(UIParent)XLootFrame:SetFrameStrata('DIALOG')self.isHidden = falseelseXLootFrame:SetParent(self)self.isHidden = trueendelseif self.ElvUI thenif show thenself:LootUnderMouse(ElvLootFrame, ElvLootFrameHolder)ElvLootFrame:SetParent(ElvLootFrameHolder)ElvLootFrame:SetFrameStrata('HIGH')self.isHidden = falseelseElvLootFrame:SetParent(self)self.isHidden = trueendelseif LootFrame:IsEventRegistered('LOOT_SLOT_CLEARED') thenLootFrame.page = 1;if show thenself:LootUnderMouse(LootFrame, UIParent)LootFrame_Show(LootFrame)self.isHidden = falseelseself.isHidden = trueendendself:PlayFishingSound()
endfunction AutoLoot:LootItems()local numItems = GetNumLootItems() or 0if numItems > 0 thenfor i = numItems, 1, -1 dolocal itemLink = GetLootSlotLink(i)local slotType = GetLootSlotType(i)local quantity, _, _, locked, isQuestItem = select(3, GetLootSlotInfo(i))if locked thenself.isItemLocked = lockedelseif isQuestItem or self:ProcessLoot(itemLink, quantity, slotType) thennumItems = numItems - 1LootSlot(i)endendif numItems > 0 thenself:ShowLootFrame(true)self:PlayInventoryFullSound()endend
endfunction AutoLoot:OnEvent(e, ...)if e == 'PLAYER_LOGIN' thenif XLootFrame thenself.XLoot = trueelseif ElvUI and ElvUI[1].private.general.loot thenself.ElvUI = trueendif SpeedyAutoLootDB.global.alwaysEnableAutoLoot thenSetCVar('autoLootDefault',1)endLootFrame:UnregisterEvent('LOOT_OPENED')self:ShowLootFrame(false)elseif (e == 'LOOT_READY' or e == 'LOOT_OPENED') and not self.isLooting thenself.isLooting = truelocal autoLoot = ...if autoLoot or GetCVarBool('autoLootDefault') ~= IsModifiedClick('AUTOLOOTTOGGLE') thenself:LootItems()elseself:ShowLootFrame(true)endelseif e == 'LOOT_CLOSED' thenself.isLooting = falseself.isHidden = falseself.isItemLocked = nilself:ShowLootFrame(false)elseif e == 'UI_ERROR_MESSAGE' and tContains(errorList, select(2,...)) thenif self.isLooting and self.isHidden thenself:ShowLootFrame(true)self:PlayInventoryFullSound()endend
endSLASH_SPEEDYAUTOLOOT1, SLASH_SPEEDYAUTOLOOT2, SLASH_SPEEDYAUTOLOOT3 = '/sal', '/speedyloot', '/speedyautoloot'
function SlashCmdList.SPEEDYAUTOLOOT(msg)local _, _, cmd, args = find(msg, '%s?(%w+)%s?(.*)')if not cmd or cmd == '' or cmd == 'help' thenprint('|cffEEE4AESpeedy AutoLoot:|r |cffEF6D6D/sal /speedyautoloot /speedyloot|r')print(' |cffEF6D6D/sal auto -|r |cffFAD1D1Enable Auto Looting for new/all characters|r')print(' |cffEF6D6D/sal sound -|r |cffFAD1D1Play a Sound when Inventory is full while looting|r')print(' |cffEF6D6D/sal set (SoundID) -|r |cffFAD1D1Set a Sound (SoundID), Example: /sal set 139|r')elseif cmd == 'auto' thenif SpeedyAutoLootDB.global.alwaysEnableAutoLoot thenSpeedyAutoLootDB.global.alwaysEnableAutoLoot = falseprint('|cffEEE4AESpeedy AutoLoot:|r |cffB6B6B6Auto Loot for all Characters disabled.')elseSpeedyAutoLootDB.global.alwaysEnableAutoLoot = trueprint('|cffEEE4AESpeedy AutoLoot:|r |cff37DB33Auto Loot for all Characters enabled.')endelseif cmd == 'sound' thenif SpeedyAutoLootDB.global.enableSound thenSpeedyAutoLootDB.global.enableSound = falseprint('|cffEEE4AESpeedy AutoLoot:|r |cffB6B6B6Don\'t play a sound when inventory is full.')elseif not SpeedyAutoLootDB.global.InventoryFullSound thenSpeedyAutoLootDB.global.InventoryFullSound = 139endSpeedyAutoLootDB.global.enableSound = trueprint('|cffEEE4AESpeedy AutoLoot:|r |cff37DB33Play a sound when inventory is full.')endelseif cmd == 'set' and args ~= '' thenlocal SoundID = tonumber(args:match('%d+'))if SoundID thenSpeedyAutoLootDB.global.InventoryFullSound = tonumber(args:match('%d+'))PlaySound(SoundID, 'Master')print('|cffEEE4AESpeedy AutoLoot: Set Sound|r |cff37DB33'..SoundID..'|r')endend
endfunction AutoLoot:OnLoad()self:SetToplevel(true)self:Hide()self:SetScript('OnEvent', function(_, ...)self:OnEvent(...)end)for _,e in next, ({ 'PLAYER_LOGIN','LOOT_READY','LOOT_OPENED','LOOT_CLOSED','UI_ERROR_MESSAGE' }) doself:RegisterEvent(e)end
end
AutoLoot:OnLoad()
SpeedyAutoLoot.toc
## Interface: 11302
## Title: |cffEEE4AESpeedy AutoLoot|r
## Notes: |cff58C6FALoot at ludicrous speed!|r
## Author: Yuyuli
## Version: 2.0.9
## SavedVariables: SpeedyAutoLootDBSpeedyAutoLoot.lua