Skip to content

Commit

Permalink
Added Slash commands and message on roll option
Browse files Browse the repository at this point in the history
-Some more UI tweaks
  • Loading branch information
AmionSky committed Mar 22, 2017
1 parent 96d779e commit 179392a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 25 deletions.
90 changes: 70 additions & 20 deletions AutoLoot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local tItemCategory = {
local tDefault = {
bEnabled = true,
bNoNeedWhenFullGuild = false,
bMessageOnRoll = false,
nNonNeedableRule = 2,
nUnlockedDyeRule = 4,

Expand Down Expand Up @@ -116,7 +117,7 @@ function AutoLoot:OnDocLoaded()
-- Register handlers for events, slash commands and timer, etc.
-- e.g. Apollo.RegisterEventHandler("KeyDown", "OnKeyDown", self)

Apollo.RegisterSlashCommand("autoloot", "OnConfigure", self)
Apollo.RegisterSlashCommand("autoloot", "OnSlashCommand", self)

Apollo.RegisterEventHandler("LootRollUpdate", "OnLootUpdate", self)

Expand Down Expand Up @@ -155,26 +156,28 @@ function AutoLoot:OnLootUpdate()
end

function AutoLoot:HandleItem(nLootId, itemDrop)
local strItemName = itemDrop:GetName()

--If option set, greed non-needable items
if self.tSettings.nNonNeedableRule ~= 4 and not GameLib.IsNeedRollAllowed(nLootId) then
self:UseRule(self.tSettings.nNonNeedableRule, nLootId)
self:UseRule(self.tSettings.nNonNeedableRule, nLootId, strItemName)
return
end

--Check the LootRules
if self:ByNameFindMatch(itemDrop:GetName(), nLootId) then return end
if self:ByNameFindMatch(strItemName, nLootId) then return end

if self.tSettings.nUnlockedDyeRule ~= 4 and itemDrop:GetItemCategory() == tItemCategory.Dyes then
local tItemInfo = itemDrop:GetDetailedInfo()

if tItemInfo.tPrimary.arUnlocks then
for _, tCur in ipairs(tItemInfo.tPrimary.arUnlocks) do
if tCur.bUnlocked then self:UseRule(self.tSettings.nUnlockedDyeRule, nLootId) else return end
if tCur.bUnlocked then self:UseRule(self.tSettings.nUnlockedDyeRule, nLootId, strItemName) else return end
end
end
end

if self:UseRule(self.tSettings.tLootRules.tByCategory[itemDrop:GetItemCategory()], nLootId) then return end
if self:UseRule(self.tSettings.tLootRules.tByCategory[itemDrop:GetItemCategory()], nLootId, strItemName) then return end
end

function AutoLoot:ByNameFindMatch(strItemName, nLootId)
Expand All @@ -192,33 +195,37 @@ function AutoLoot:ByNameFindMatch(strItemName, nLootId)

if nFoundRule == nil then return false end

return self:UseRule(nFoundRule, nLootId)
return self:UseRule(nFoundRule, nLootId, strItemName)
end

function AutoLoot:UseRule(nRule, nLootId)
function AutoLoot:UseRule(nRule, nLootId, strItemName)
local bSuccess = false

if nRule == 1 then
-- Need
if self.tSettings.bNoNeedWhenFullGuild and self.bFullGuildGroup then
return true
else
if not (self.tSettings.bNoNeedWhenFullGuild and self.bFullGuildGroup) then
GameLib.RollOnLoot(nLootId, true)
return true
end
bSuccess = true
elseif nRule == 2 then
-- Greed
GameLib.RollOnLoot(nLootId, false)
return true
bSuccess = true
elseif nRule == 3 then
-- Pass
GameLib.PassOnLoot(nLootId)
return true
bSuccess = true
elseif nRule == 4 then
-- Ignore
return true
else
-- Incorrect
return false
bSuccess = true
end

if bSuccess and self.tSettings.bMessageOnRoll and nRule < 4 and strItemName then
local msg = "AutoLoot: "..tRuleNames[nRule].."ed on item: "..strItemName
ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_System, msg)
end

return bSuccess
end

-- Full Guild checks
Expand Down Expand Up @@ -302,6 +309,44 @@ function AutoLoot:tableClone(t)
return target
end

function AutoLoot:Print(strText)
if strText then Print("Auto Loot: "..strText) end
end

-----------------------------------------------------------------------------------------------
-- AutoLoot Command Functions
-----------------------------------------------------------------------------------------------
function AutoLoot:OnSlashCommand(slash, args)
local tBoolText = { [true] = "Enabled", [false] = "Disabled" }

if args == "config" or args == "options" then
self:OnConfigure()
elseif args == "toggle" then
self.tSettings.bEnabled = not self.tSettings.bEnabled
self:Print(tBoolText[self.tSettings.bEnabled])
elseif args == "enable" then
self.tSettings.bEnabled = true
self:Print(tBoolText[true])
elseif args == "disable" then
self.tSettings.bEnabled = false
self:Print(tBoolText[false])
elseif args == "rollmsg" then
self.tSettings.bMessageOnRoll = not self.tSettings.bMessageOnRoll
self:Print("Roll Messages "..tBoolText[self.tSettings.bMessageOnRoll])
elseif args == "reset" then
self:OnResetSettings()
self:Print("Settings Reset")
else
Print("--- Auto Loot Help ---")
Print("config | Open settings window")
Print("toggle | Enable / Disable")
Print("enable | Enable the addon")
Print("disable | Disable the addon")
Print("rollmsg | Toggle messages on roll")
Print("reset | Reset to default settings")
end
end

-----------------------------------------------------------------------------------------------
-- AutoLootForm Functions
-----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -335,6 +380,7 @@ function AutoLoot:LoadSettings()
self.wndMain:FindChild("btnRule"):SetCheck(self.SortMode == 2)
self.wndMain:FindChild("ButtonEnabled"):SetCheck(self.tSettings.bEnabled)
self.wndMain:FindChild("ButtonFullGuild"):SetCheck(self.tSettings.bNoNeedWhenFullGuild)
self.wndMain:FindChild("ButtonRollMessage"):SetCheck(self.tSettings.bMessageOnRoll)

self:SetupRuleButton(self.wndMain:FindChild("AddRule"), 2)
self:SetupRuleButton(self.wndMain:FindChild("SelectRuleNonNeed"), self.tSettings.nNonNeedableRule)
Expand Down Expand Up @@ -421,9 +467,9 @@ function AutoLoot:OnMove()
self:RuleListClear()
end

function AutoLoot:OnResetSettings() --Currently unused
function AutoLoot:OnResetSettings()
self.tSettings = self:tableClone(tDefault)
self:LoadSettings()
if self.wndMain ~= nil then self:LoadSettings() end
end

function AutoLoot:ButtonEnabled(wndHandler, wndControl)
Expand All @@ -434,6 +480,10 @@ function AutoLoot:ButtonFullGuild(wndHandler, wndControl)
self.tSettings.bNoNeedWhenFullGuild = wndControl:IsChecked()
end

function AutoLoot:ButtonRollMessage(wndHandler, wndControl)
self.tSettings.bMessageOnRoll = wndControl:IsChecked()
end

-- Header

function AutoLoot:OnHeaderButton(wndHandler, wndControl)
Expand Down Expand Up @@ -489,7 +539,7 @@ function AutoLoot:OnRuleSelectCheck(wndHandler, wndControl)

local nCurrentData = wndControl:GetData()

for k,v in ipairs(wndChoices:FindChild("Controls"):GetChildren()) do
for _,v in ipairs(wndChoices:FindChild("Controls"):GetChildren()) do
v:SetCheck(nCurrentData == v:GetContentId())
end

Expand Down
14 changes: 9 additions & 5 deletions AutoLoot.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Forms>
<Form Class="Window" LAnchorPoint="0.5" LAnchorOffset="-300" TAnchorPoint="0.42" TAnchorOffset="-350" RAnchorPoint="0.5" RAnchorOffset="300" BAnchorPoint="0.42" BAnchorOffset="350" RelativeToClient="1" Font="Default" Text="" Template="" Name="AutoLootForm" Border="0" Picture="0" SwallowMouseClicks="1" Moveable="1" Escapable="1" Overlapped="0" BGColor="ffffffff" TextColor="ffffffff" TextId="" TooltipColor="" UseTemplateBG="0" IgnoreMouse="1" Tooltip="">
<Form Class="Window" LAnchorPoint="0.5" LAnchorOffset="-300" TAnchorPoint="0.42" TAnchorOffset="-350" RAnchorPoint="0.5" RAnchorOffset="300" BAnchorPoint="0.42" BAnchorOffset="350" RelativeToClient="1" Font="Default" Text="" Template="" Name="AutoLootForm" Border="0" Picture="0" SwallowMouseClicks="1" Moveable="1" Escapable="1" Overlapped="1" BGColor="ffffffff" TextColor="ffffffff" TextId="" TooltipColor="" UseTemplateBG="0" IgnoreMouse="0" Tooltip="">
<Event Name="WindowClosed" Function="OnClosed"/>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="27" TAnchorPoint="0" TAnchorOffset="70" RAnchorPoint="1" RAnchorOffset="-26" BAnchorPoint="1" BAnchorOffset="-20" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Holo_Background_General" TooltipType="OnCursor" Name="Background" TooltipColor="" Border="1" IgnoreMouse="1" UseTemplateBG="1" Visible="1" HideInEditor="0"/>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="37" TAnchorPoint="0" TAnchorOffset="82" RAnchorPoint="1" RAnchorOffset="-39" BAnchorPoint="1" BAnchorOffset="-35" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="" TooltipType="OnCursor" Name="Container" TooltipColor="" NewControlDepth="2" Picture="1" IgnoreMouse="0" Tooltip="" VScroll="0" HScroll="0" Border="0" UseTemplateBG="0" NewWindowDepth="1">
<Control Class="Button" Base="BK3:btnHolo_Check" Font="DefaultButton" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="10" RAnchorPoint="0.5" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="36" DT_VCENTER="1" DT_CENTER="0" BGColor="UI_BtnBGDefault" TextColor="UI_BtnTextHoloNormal" NormalTextColor="UI_BtnTextHoloNormal" PressedTextColor="UI_BtnTextHoloPressed" FlybyTextColor="UI_BtnTextHoloFlyby" PressedFlybyTextColor="UI_BtnTextHoloPressedFlyby" DisabledTextColor="UI_BtnTextHoloDisabled" TooltipType="OnCursor" Name="ButtonEnabled" TooltipColor="" FocusedTextColor="ffffffff" Text="Auto Loot Enabled" TextId="" Tooltip="" RelativeToClient="0" DrawAsCheckbox="1" TestAlpha="1">
<Control Class="Button" Base="BK3:btnHolo_Check" Font="DefaultButton" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="10" RAnchorPoint="0" RAnchorOffset="150" BAnchorPoint="0" BAnchorOffset="36" DT_VCENTER="1" DT_CENTER="0" BGColor="UI_BtnBGDefault" TextColor="UI_BtnTextHoloNormal" NormalTextColor="UI_BtnTextHoloNormal" PressedTextColor="UI_BtnTextHoloPressed" FlybyTextColor="UI_BtnTextHoloFlyby" PressedFlybyTextColor="UI_BtnTextHoloPressedFlyby" DisabledTextColor="UI_BtnTextHoloDisabled" TooltipType="OnCursor" Name="ButtonEnabled" TooltipColor="" FocusedTextColor="ffffffff" Text="Auto Loot Enabled" TextId="" Tooltip="" RelativeToClient="0" DrawAsCheckbox="1" TestAlpha="0">
<Event Name="ButtonCheck" Function="ButtonEnabled"/>
<Event Name="ButtonUncheck" Function="ButtonEnabled"/>
</Control>
<Control Class="Button" Base="BK3:btnHolo_Check" Font="DefaultButton" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="50" RAnchorPoint="0.5" RAnchorOffset="0" BAnchorPoint="0" BAnchorOffset="76" DT_VCENTER="1" DT_CENTER="0" BGColor="UI_BtnBGDefault" TextColor="UI_BtnTextHoloNormal" NormalTextColor="UI_BtnTextHoloNormal" PressedTextColor="UI_BtnTextHoloPressed" FlybyTextColor="UI_BtnTextHoloFlyby" PressedFlybyTextColor="UI_BtnTextHoloPressedFlyby" DisabledTextColor="UI_BtnTextHoloDisabled" TooltipType="OnCursor" Name="ButtonFullGuild" TooltipColor="" FocusedTextColor="ffffffff" Text="Don&apos;t need when in a full guild group" TextId="" Tooltip="" RelativeToClient="0" DrawAsCheckbox="1" TestAlpha="1">
<Control Class="Button" Base="BK3:btnHolo_Check" Font="DefaultButton" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="50" RAnchorPoint="0.5" RAnchorOffset="-10" BAnchorPoint="0" BAnchorOffset="76" DT_VCENTER="1" DT_CENTER="0" BGColor="UI_BtnBGDefault" TextColor="UI_BtnTextHoloNormal" NormalTextColor="UI_BtnTextHoloNormal" PressedTextColor="UI_BtnTextHoloPressed" FlybyTextColor="UI_BtnTextHoloFlyby" PressedFlybyTextColor="UI_BtnTextHoloPressedFlyby" DisabledTextColor="UI_BtnTextHoloDisabled" TooltipType="OnCursor" Name="ButtonFullGuild" TooltipColor="" FocusedTextColor="ffffffff" Text="Don&apos;t need when in a full guild group" TextId="" Tooltip="" RelativeToClient="0" DrawAsCheckbox="1" TestAlpha="0">
<Event Name="ButtonCheck" Function="ButtonFullGuild"/>
<Event Name="ButtonUncheck" Function="ButtonFullGuild"/>
</Control>
<Control Class="Button" Base="BK3:btnHolo_Check" Font="DefaultButton" ButtonType="Check" RadioGroup="" LAnchorPoint="0" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="80" RAnchorPoint="0.5" RAnchorOffset="-10" BAnchorPoint="0" BAnchorOffset="106" DT_VCENTER="1" DT_CENTER="0" BGColor="UI_BtnBGDefault" TextColor="UI_BtnTextHoloNormal" NormalTextColor="UI_BtnTextHoloNormal" PressedTextColor="UI_BtnTextHoloPressed" FlybyTextColor="UI_BtnTextHoloFlyby" PressedFlybyTextColor="UI_BtnTextHoloPressedFlyby" DisabledTextColor="UI_BtnTextHoloDisabled" TooltipType="OnCursor" Name="ButtonRollMessage" TooltipColor="" FocusedTextColor="ffffffff" Text="Show message when auto roll" TextId="" Tooltip="Show a message in the chat when the addon rolls or passes on an item." RelativeToClient="0" DrawAsCheckbox="1" TestAlpha="0" TooltipId="">
<Event Name="ButtonCheck" Function="ButtonRollMessage"/>
<Event Name="ButtonUncheck" Function="ButtonRollMessage"/>
</Control>
<Control Class="Window" LAnchorPoint="0.5" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="10" RAnchorPoint="1" RAnchorOffset="-11" BAnchorPoint="0" BAnchorOffset="40" RelativeToClient="1" Font="CRB_InterfaceMedium" Text="Non-Needable Loot:" BGColor="UI_WindowBGDefault" TextColor="UI_TextHoloTitle" Template="Default" TooltipType="OnCursor" Name="NonNeedable" TooltipColor="" TextId="" DT_VCENTER="1">
<Control Class="Button" Base="BK3:btnHolo_Blue_Small" Font="DefaultButton" ButtonType="Check" RadioGroup="" LAnchorPoint="1" LAnchorOffset="-90" TAnchorPoint=".5" TAnchorOffset="-27" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint=".5" BAnchorOffset="27" DT_VCENTER="1" DT_CENTER="1" BGColor="UI_BtnBGDefault" TextColor="UI_BtnTextDefault" NormalTextColor="UI_BtnTextHoloListNormal" PressedTextColor="UI_BtnTextHoloListPressed" FlybyTextColor="UI_BtnTextHoloListFlyby" PressedFlybyTextColor="UI_BtnTextHoloListPressedFlyby" DisabledTextColor="UI_BtnTextHoloListDisabled" TooltipType="OnCursor" Name="SelectRuleNonNeed" TooltipColor="" FocusedTextColor="ffffffff" Text="" TextId="GVT_Greed" Tooltip="" ContentType="" ContentId="1" NoClip="1" Overlapped="1" TestAlpha="1">
<Event Name="ButtonUncheck" Function="OnRuleSelectUncheck"/>
Expand All @@ -24,7 +28,7 @@
<Event Name="ButtonCheck" Function="OnRuleSelectCheck"/>
</Control>
</Control>
<Control Class="Window" LAnchorPoint="0.5" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="70" RAnchorPoint="1" RAnchorOffset="-11" BAnchorPoint="0" BAnchorOffset="100" RelativeToClient="1" Font="CRB_InterfaceMedium" Text="Housing Loot:" BGColor="UI_WindowBGDefault" TextColor="UI_TextHoloTitle" Template="Default" TooltipType="OnCursor" Name="Housing" TooltipColor="" TextId="" DT_VCENTER="1">
<Control Class="Window" LAnchorPoint="0.5" LAnchorOffset="10" TAnchorPoint="0" TAnchorOffset="70" RAnchorPoint="1" RAnchorOffset="-11" BAnchorPoint="0" BAnchorOffset="100" RelativeToClient="1" Font="CRB_InterfaceMedium" Text="Housing Items:" BGColor="UI_WindowBGDefault" TextColor="UI_TextHoloTitle" Template="Default" TooltipType="OnCursor" Name="Housing" TooltipColor="" TextId="" DT_VCENTER="1" Tooltip="" TooltipId="">
<Control Class="Button" Base="BK3:btnHolo_Blue_Small" Font="DefaultButton" ButtonType="Check" RadioGroup="" LAnchorPoint="1" LAnchorOffset="-90" TAnchorPoint=".5" TAnchorOffset="-27" RAnchorPoint="1" RAnchorOffset="0" BAnchorPoint=".5" BAnchorOffset="27" DT_VCENTER="1" DT_CENTER="1" BGColor="UI_BtnBGDefault" TextColor="UI_BtnTextDefault" NormalTextColor="UI_BtnTextHoloListNormal" PressedTextColor="UI_BtnTextHoloListPressed" FlybyTextColor="UI_BtnTextHoloListFlyby" PressedFlybyTextColor="UI_BtnTextHoloListPressedFlyby" DisabledTextColor="UI_BtnTextHoloListDisabled" TooltipType="OnCursor" Name="SelectRuleHousing" TooltipColor="" FocusedTextColor="ffffffff" Text="" TextId="GVT_Greed" Tooltip="" NoClip="1" Overlapped="1" TestAlpha="1">
<Event Name="ButtonUncheck" Function="OnRuleSelectUncheck"/>
<Event Name="ButtonCheck" Function="OnRuleSelectCheck"/>
Expand All @@ -48,7 +52,7 @@
</Control>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="5" TAnchorPoint="0" TAnchorOffset="29" RAnchorPoint="1" RAnchorOffset="-5" BAnchorPoint="1" BAnchorOffset="-57" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Holo_ScrollList" TooltipType="OnCursor" Name="RuleList" TooltipColor="" Visible="1" VScroll="1" IgnoreMouse="1" Tooltip="" Sprite="" Picture="0" HideInEditor="0" Border="1" UseTemplateBG="1" AutoHideScroll="0"/>
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="5" TAnchorPoint="1" TAnchorOffset="-51" RAnchorPoint="1" RAnchorOffset="-5" BAnchorPoint="1" BAnchorOffset="-3" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="AddOptions" TooltipColor="" Visible="1" VScroll="0" IgnoreMouse="1" Tooltip="" Sprite="" Picture="0" TextId="">
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="60" TAnchorPoint="0" TAnchorOffset="10" RAnchorPoint="0" RAnchorOffset="335" BAnchorPoint="1" BAnchorOffset="-10" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="AddNameBase" TooltipColor="" Sprite="BK3:UI_BK3_Holo_InsetSimple" Picture="1" IgnoreMouse="1" Tooltip="The name or a part of the name of the item." TooltipId="">
<Control Class="Window" LAnchorPoint="0" LAnchorOffset="60" TAnchorPoint="0" TAnchorOffset="10" RAnchorPoint="0" RAnchorOffset="335" BAnchorPoint="1" BAnchorOffset="-10" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="AddNameBase" TooltipColor="" Sprite="BK3:UI_BK3_Holo_InsetSimple" Picture="1" IgnoreMouse="1" Tooltip="The name or a part of the name of the item. Can drag &apos;n drop items." TooltipId="">
<Control Class="EditBox" LAnchorPoint="0" LAnchorOffset="5" TAnchorPoint="0" TAnchorOffset="0" RAnchorPoint="1" RAnchorOffset="-5" BAnchorPoint="1" BAnchorOffset="0" RelativeToClient="1" Font="Default" Text="" BGColor="UI_WindowBGDefault" TextColor="UI_WindowTextDefault" Template="Default" TooltipType="OnCursor" Name="AddName" TooltipColor="" Sprite="" Picture="0" DT_VCENTER="1" DT_SINGLELINE="1" LoseFocusOnExternalClick="1" Tooltip="">
<Event Name="DragDrop" Function="OnDragDropItem"/>
<Event Name="QueryDragDrop" Function="OnDragDropItemQuery"/>
Expand Down

0 comments on commit 179392a

Please sign in to comment.