Skip to content

Commit

Permalink
refactored part that dependent on localization specific names
Browse files Browse the repository at this point in the history
also added definitions to make easier write and read code
  • Loading branch information
AmsTaFFix committed Sep 3, 2022
1 parent 4c1b863 commit 55aea17
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 83 deletions.
212 changes: 139 additions & 73 deletions AutoGear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
-- factor in racial weapon bonuses
-- eye of arachnida slot nil error

---@type AutoGearAddon
local _, T = ...;

--check whether it's WoW Classic, TBC, BFA, or Shadowlands for automatic compatibility
Expand All @@ -33,6 +34,11 @@ local IsBFA = GetNumExpansions() == 8
local IsWotLK = GetNumExpansions() == 3
local IsSL = GetNumExpansions() == 9

---TOC Version which from started Mists of Pandaria expansion
local TOC_VERSION_MOA = 50000
---Current TOC version
local TOC_VERSION_CURRENT = select(4, GetBuildInfo())

local _ --prevent taint when using throwaway variable
local reason
--local lastlink
Expand Down Expand Up @@ -2320,24 +2326,24 @@ function AutoGearConsiderAllItems(lootRollItemID, lootRollID, questRewardID, arb
end
--create all future equip actions required (only if not rolling currently)
if (not lootRollItemID and not questRewardID and not noActions) then
for i = 1, 18 do
if i == INVSLOT_MAINHAND or i == INVSLOT_OFFHAND then
for invSlot = 1, 18 do
if invSlot == INVSLOT_MAINHAND or invSlot == INVSLOT_OFFHAND then
--skip for now
else
local equippedInfo = AutoGearReadItemInfo(i)
local equippedInfo = AutoGearReadItemInfo(invSlot)
local equippedScore = AutoGearDetermineItemScore(equippedInfo, AutoGearCurrentWeighting)
if ((not AutoGearBestItems[i].equipped) and AutoGearBestItems[i].score > equippedScore) then
AutoGearPrint("AutoGear: "..(AutoGearBestItems[i].info.link or "nothing").." ("..string.format("%.2f", AutoGearBestItems[i].score)..") was determined to be better than "..(equippedInfo.link or "nothing").." ("..string.format("%.2f", equippedScore).."). "..((AutoGearDB.Enabled == true) and "Equipping." or "Would equip if automatic gear equipping was enabled."), 1)
AutoGearPrintItem(AutoGearBestItems[i].info)
if ((not AutoGearBestItems[invSlot].equipped) and AutoGearBestItems[invSlot].score > equippedScore) then
AutoGearPrint("AutoGear: "..(AutoGearBestItems[invSlot].info.link or "nothing").." ("..string.format("%.2f", AutoGearBestItems[invSlot].score)..") was determined to be better than "..(equippedInfo.link or "nothing").." ("..string.format("%.2f", equippedScore).."). "..((AutoGearDB.Enabled == true) and "Equipping." or "Would equip if automatic gear equipping was enabled."), 1)
AutoGearPrintItem(AutoGearBestItems[invSlot].info)
AutoGearPrintItem(equippedInfo)
anythingBetter = 1
local newAction = {}
newAction.action = "equip"
newAction.t = GetTime()
newAction.container = AutoGearBestItems[i].bag
newAction.slot = AutoGearBestItems[i].slot
newAction.replaceSlot = i
newAction.info = AutoGearBestItems[i].info
newAction.container = AutoGearBestItems[invSlot].bag
newAction.slot = AutoGearBestItems[invSlot].slot
newAction.replaceSlot = invSlot
newAction.info = AutoGearBestItems[invSlot].info
table.insert(futureAction, newAction)
end
end
Expand Down Expand Up @@ -2393,12 +2399,12 @@ function AutoGearConsiderAllItems(lootRollItemID, lootRollID, questRewardID, arb
AutoGearPrintItem(equippedOff)
end
else
local i = 16
if (offSwap) then i = 17 end
local equippedInfo = AutoGearReadItemInfo(i)
local invSlot = 16
if (offSwap) then invSlot = 17 end
local equippedInfo = AutoGearReadItemInfo(invSlot)
local equippedScore = AutoGearDetermineItemScore(equippedInfo, AutoGearCurrentWeighting)
AutoGearPrint("AutoGear: "..(AutoGearBestItems[i].info.link or "nothing").." ("..string.format("%.2f", AutoGearBestItems[i].score)..") was determined to be better than "..(equippedInfo.link or "nothing").." ("..string.format("%.2f", equippedScore).."). "..((AutoGearDB.Enabled == true) and "Equipping." or "Would equip if automatic gear equipping was enabled."), 1)
AutoGearPrintItem(AutoGearBestItems[i].info)
AutoGearPrint("AutoGear: "..(AutoGearBestItems[invSlot].info.link or "nothing").." ("..string.format("%.2f", AutoGearBestItems[invSlot].score)..") was determined to be better than "..(equippedInfo.link or "nothing").." ("..string.format("%.2f", equippedScore).."). "..((AutoGearDB.Enabled == true) and "Equipping." or "Would equip if automatic gear equipping was enabled."), 1)
AutoGearPrintItem(AutoGearBestItems[invSlot].info)
AutoGearPrintItem(equippedInfo)
end
end
Expand Down Expand Up @@ -2608,6 +2614,10 @@ function AutoGearReadItemInfo(inventoryID, lootRollID, container, slot, questRew
info.MetaSockets = 0
local class, spec = AutoGearGetClassAndSpec()
local weaponType = AutoGearGetWeaponType(info.link)
local itemEquipLoc = ""
if info.id then
itemEquipLoc = select(9, GetItemInfo(info.id))
end
for i = 1, AutoGearTooltip:NumLines() do
local mytext = getglobal("AutoGearTooltipTextLeft"..i)
if (mytext) then
Expand Down Expand Up @@ -2708,35 +2718,66 @@ function AutoGearReadItemInfo(inventoryID, lootRollID, container, slot, questRew
end
end

if (text=="mount") then info.isMount = 1 end
if (text=="head") then info.Slot = "HeadSlot" info.SlotConst = INVSLOT_HEAD end
if (text=="neck") then info.Slot = "NeckSlot" info.SlotConst = INVSLOT_NECK end
if (text=="shoulder") then info.Slot = "ShoulderSlot" info.SlotConst = INVSLOT_SHOULDER end
if (text==L["back"]) then info.Slot = "BackSlot" info.SlotConst = INVSLOT_BACK end
if (text=="chest") then info.Slot = "ChestSlot" info.SlotConst = INVSLOT_CHEST end
if (text==L["shirt"]) then info.Slot = "ShirtSlot" info.SlotConst = INVSLOT_BODY end
if (text=="tabard") then info.Slot = "TabardSlot" info.SlotConst = INVSLOT_TABARD end
if (text==L["wrist"]) then info.Slot = "WristSlot" info.SlotConst = INVSLOT_WRIST end
if (text==L["hands"]) then info.Slot = "HandsSlot" info.SlotConst = INVSLOT_HAND end
if (text=="waist") then info.Slot = "WaistSlot" info.SlotConst = INVSLOT_WAIST end
if (text==L["legs"]) then info.Slot = "LegsSlot" info.SlotConst = INVSLOT_LEGS end
if (text==L["feet"]) then info.Slot = "FeetSlot" info.SlotConst = INVSLOT_FEET end
if (text=="finger") then info.Slot = "Finger0Slot" info.SlotConst = INVSLOT_FINGER1 end
if (text=="trinket") then info.Slot = "Trinket0Slot" info.SlotConst = INVSLOT_TRINKET1 end
if (text=="main hand") then
if (text == "mount") then
info.isMount = 1
end
if (itemEquipLoc == "INVTYPE_HEAD") then
info.Slot = "HeadSlot"
info.SlotConst = INVSLOT_HEAD
elseif (itemEquipLoc == "INVTYPE_NECK") then
info.Slot = "NeckSlot"
info.SlotConst = INVSLOT_NECK
elseif (itemEquipLoc == "INVTYPE_SHOULDER") then
info.Slot = "ShoulderSlot"
info.SlotConst = INVSLOT_SHOULDER
elseif (itemEquipLoc == "INVTYPE_CLOAK") then
info.Slot = "BackSlot"
info.SlotConst = INVSLOT_BACK
elseif (itemEquipLoc == "INVTYPE_CHEST") then
info.Slot = "ChestSlot"
info.SlotConst = INVSLOT_CHEST
elseif (itemEquipLoc == "INVTYPE_BODY") then
info.Slot = "ShirtSlot"
info.SlotConst = INVSLOT_BODY
elseif (itemEquipLoc == "INVTYPE_TABARD") then
info.Slot = "TabardSlot"
info.SlotConst = INVSLOT_TABARD
elseif (itemEquipLoc == "INVTYPE_WRIST") then
info.Slot = "WristSlot"
info.SlotConst = INVSLOT_WRIST
elseif (itemEquipLoc == "INVTYPE_HAND") then
info.Slot = "HandsSlot"
info.SlotConst = INVSLOT_HAND
elseif (itemEquipLoc == "INVTYPE_WAIST") then
info.Slot = "WaistSlot"
info.SlotConst = INVSLOT_WAIST
elseif (itemEquipLoc == "INVTYPE_LEGS") then
info.Slot = "LegsSlot"
info.SlotConst = INVSLOT_LEGS
elseif (itemEquipLoc == "INVTYPE_FEET") then
info.Slot = "FeetSlot"
info.SlotConst = INVSLOT_FEET
elseif (itemEquipLoc == "INVTYPE_FINGER") then
info.Slot = "Finger0Slot"
info.SlotConst = INVSLOT_FINGER1
elseif (itemEquipLoc == "INVTYPE_TRINKET") then
info.Slot = "Trinket0Slot"
info.SlotConst = INVSLOT_TRINKET1
elseif (itemEquipLoc == "INVTYPE_WEAPONMAINHAND") then
if (weapons == "dagger" and weaponType ~= LE_ITEM_WEAPON_DAGGER) then
cannotUse = 1
reason = "(this spec needs a dagger main hand)"
elseif (weapons == "dagger and any" and weaponType ~= LE_ITEM_WEAPON_DAGGER) then
cannotUse = 1
reason = "(this spec needs a dagger main hand)"
elseif (weapons == "2h" or weapons == "ranged" or weapons == "2hDW") then --Alitwin: adding 2hdw
elseif (weapons == "2h" or weapons == "ranged" or weapons == "2hDW") then
--Alitwin: adding 2hdw
cannotUse = 1
reason = "(this spec needs a two-hand weapon)"
end
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND
end
if (text==L["two-hand"]) then
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND
elseif (itemEquipLoc == "INVTYPE_2HWEAPON") then
if (weapons == "weapon and shield") then
cannotUse = 1
reason = "(this spec needs weapon and shield)"
Expand All @@ -2747,22 +2788,28 @@ function AutoGearReadItemInfo(inventoryID, lootRollID, container, slot, questRew
cannotUse = 1
reason = "(this spec should use a ranged weapon)"
end
if (weapons == "2hDW") then --Alitwin: adding 2hdw
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND
info.Slot2 = "SecondaryHandSlot" info.Slot2Const = INVSLOT_OFFHAND
if (weapons == "2hDW") then
--Alitwin: adding 2hdw
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND
info.Slot2 = "SecondaryHandSlot"
info.Slot2Const = INVSLOT_OFFHAND
else
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND; info.IncludeOffHand=1
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND;
info.IncludeOffHand = 1
end
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND; info.IncludeOffHand=1
end
if (text=="held in off-hand") then
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND;
info.IncludeOffHand = 1
elseif (itemEquipLoc == "INVTYPE_HOLDABLE") then
if (weapons == "2h" or (weapons == "dual wield" and CanDualWield()) or weapons == "weapon and shield" or weapons == "ranged") then
cannotUse = 1
reason = "(this spec needs the off-hand for a weapon or shield)"
end
info.Slot = "SecondaryHandSlot" info.SlotConst = INVSLOT_OFFHAND
end
if (text==L["off hand"]) then
info.Slot = "SecondaryHandSlot"
info.SlotConst = INVSLOT_OFFHAND
elseif (itemEquipLoc == "INVTYPE_WEAPONOFFHAND") then
if (weapons == "2h" or weapons == "ranged") then
cannotUse = 1
reason = "(this spec should use a two-hand weapon)"
Expand All @@ -2776,47 +2823,53 @@ function AutoGearReadItemInfo(inventoryID, lootRollID, container, slot, questRew
cannotUse = 1
reason = "(this spec should dual wield and not use a shield)"
end
info.Slot = "SecondaryHandSlot" info.SlotConst = INVSLOT_OFFHAND
end
if (text=="one-hand") then
if (weapons == "2h" or weapons == "ranged" or weapons == "2hDW") then --Alitwin: adding 2hdw

info.Slot = "SecondaryHandSlot"
info.SlotConst = INVSLOT_OFFHAND
elseif (itemEquipLoc == "INVTYPE_WEAPON") then
if (weapons == "2h" or weapons == "ranged" or weapons == "2hDW") then
--Alitwin: adding 2hdw
cannotUse = 1
reason = "(this spec should use a two-handed weapon or dual wield two-handers)"
end
if (weapons == "dagger" and weaponType == LE_ITEM_WEAPON_DAGGER) then
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND
info.Slot2 = "SecondaryHandSlot" info.Slot2Const = INVSLOT_OFFHAND
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND
info.Slot2 = "SecondaryHandSlot"
info.Slot2Const = INVSLOT_OFFHAND
elseif (weapons == "dagger" and weaponType ~= LE_ITEM_WEAPON_DAGGER) then
cannotUse = 1
reason = "(this spec needs a dagger in each hand)"
elseif (weapons == "dagger and any" and weaponType ~= LE_ITEM_WEAPON_DAGGER) then
info.Slot = "SecondaryHandSlot" info.SlotConst = INVSLOT_OFFHAND
info.Slot = "SecondaryHandSlot"
info.SlotConst = INVSLOT_OFFHAND
elseif (((weapons == "dual wield") and CanDualWield()) or weapons == "dagger and any") then
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND
info.Slot2 = "SecondaryHandSlot" info.Slot2Const = INVSLOT_OFFHAND
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND
info.Slot2 = "SecondaryHandSlot"
info.Slot2Const = INVSLOT_OFFHAND
elseif (weapons ~= LE_ITEM_WEAPON_DAGGER) then
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND
end
end
if (IsClassic or IsTBC or IsWotLK) then
if (text=="wand" or
text=="gun" or
text=="ranged" or
text=="crossbow" or
text=="idol" or
text=="libram" or
text=="totem" or
text=="sigil" or
text=="relic") then
info.Slot = "RangedSlot" info.SlotConst = INVSLOT_RANGED

if (TOC_VERSION_CURRENT < TOC_VERSION_MOA) then
-- ranged slots exists until Mists of Pandaria expansion
if (itemEquipLoc == "INVTYPE_THROWN" or itemEquipLoc == "INVTYPE_RELIC"
or itemEquipLoc == "INVTYPE_RANGEDRIGHT"
) then
info.Slot = "RangedSlot"
info.SlotConst = INVSLOT_RANGED
end
else
if (text=="ranged") then
info.Slot = "MainHandSlot" info.SlotConst = INVSLOT_MAINHAND
if (itemEquipLoc == "INVTYPE_RANGED") then
if (weapons ~= "ranged" and weaponType ~= LE_ITEM_WEAPON_WAND) then
cannotUse = 1
reason = "(this class or spec should not use a ranged 2h weapon)"
end
info.Slot = "MainHandSlot"
info.SlotConst = INVSLOT_MAINHAND
end
end

Expand Down Expand Up @@ -2868,9 +2921,14 @@ function AutoGearReadItemInfo(inventoryID, lootRollID, container, slot, questRew
reason = "(classId = " .. classId .. ", it is not usable)"
elseif (not info.Slot) then
cannotUse = 1
reason = "(info.Slot was nil)"
reason = "(info.Slot was nil. itemEquipLoc = '".. tostring(itemEquipLoc) .."')"
end

if not cannotUse then
info.canUse = "yes"
else
info.canUse = "no"
end
--if (cannotUse) then AutoGearPrint("Cannot use "..(info.link or (inventoryID and "inventoryID "..inventoryID or "(nil)")).." "..reason, 3) end
info.reason = reason

Expand Down Expand Up @@ -3277,9 +3335,17 @@ function AutoGearTooltipHook(tooltip)
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
tooltip:AddDoubleLine("AutoGear: info.Slot2Const:",
tostring(tooltipItemInfo.Slot2Const or "nil"),
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
tostring(tooltipItemInfo.Slot2Const or "nil"),
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
tooltip:AddDoubleLine("AutoGear: info.reason:",
tostring(tooltipItemInfo.reason or "nil"),
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
tooltip:AddDoubleLine("AutoGear: info.canUse:",
tostring(tooltipItemInfo.canUse or 0),
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
-- tooltip:AddDoubleLine("AutoGear: AGDIS returns:",
-- tostring(AutoGearDetermineItemScore(tooltipItemInfo, AutoGearCurrentWeighting) or "nil"),
-- HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b,
Expand Down Expand Up @@ -3401,4 +3467,4 @@ function AutoGearMain()
end
end
end
end
end
16 changes: 16 additions & 0 deletions _definitions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---@class AutoGearAddon
---@field public Localization table<string, string> Table used for localization.

---Returns info for an item
---@param itemId string|number
---@return string, string, number, number, number, string, string, number, string, string, number
function GetItemInfo(itemId) end

---Returns info for the current client build.
---
---version, build, date, tocversion
---
---Example:
---```/dump GetBuildInfo() -- "9.0.2", "36665", "Nov 17 2020", 90002```
---@return string,string,string,number
function GetBuildInfo() end
1 change: 1 addition & 0 deletions localization.core.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@type AutoGearAddon
local _, T = ...;
T.Localization = {}
local function defaultFunc(_, key)
Expand Down
14 changes: 4 additions & 10 deletions localization.ru.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
---@type AutoGearAddon
local _, T = ...;
if GetLocale() == "ruRU" then
T.Localization["legs"] = "ноги";
T.Localization["armor"] = "броня";
T.Localization["block"] = "блокирование";
T.Localization["mount"] = "средство передвижения"

T.Localization["two-hand"] = "двуручное";
T.Localization["feet"] = "ступни";
T.Localization["hands"] = "кисти рук";
T.Localization["back"] = "спина";
T.Localization["wrist"] = "запястья";
T.Localization["shirt"] = "рубашка";
T.Localization["off hand"] = "левая рука";
T.Localization["block"] = "блокирование";
T.Localization["armor"] = "броня";

T.Localization["strength"] = "сила";
T.Localization["agility"] = "ловкость";
Expand Down

0 comments on commit 55aea17

Please sign in to comment.