Skip to content

Commit 8ac927c

Browse files
committed
EXTRAct common trade category info between TradeQueryGenerator and CompareTradeHelpers
1 parent 1727224 commit 8ac927c

2 files changed

Lines changed: 58 additions & 125 deletions

File tree

src/Classes/CompareTradeHelpers.lua

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -153,43 +153,53 @@ function M.findTradeModId(modLine, modType)
153153
return nil
154154
end
155155

156-
-- Helper: map slot name + item type to trade API category string
157-
function M.getTradeCategory(slotName, item)
158-
if not item or not item.base then return nil end
159-
local itemType = item.type or (item.base and item.base.type)
156+
-- Map slot name + item type to (trade API category string, itemCategoryTags key).
157+
-- queryStr: e.g. "armour.shield", "weapon.onemace"
158+
-- categoryLabel: e.g. "Shield", "1HMace", "1HWeapon" (nil for flask / generic jewel / unsupported)
159+
function M.getTradeCategoryInfo(slotName, item)
160+
if not slotName then return nil, nil end
161+
local itemType = item and (item.type or (item.base and item.base.type))
160162
if slotName:find("^Weapon %d") then
161-
if itemType == "Shield" then return "armour.shield"
162-
elseif itemType == "Quiver" then return "armour.quiver"
163-
elseif itemType == "Bow" then return "weapon.bow"
164-
elseif itemType == "Staff" then return "weapon.staff"
165-
elseif itemType == "Two Handed Sword" then return "weapon.twosword"
166-
elseif itemType == "Two Handed Axe" then return "weapon.twoaxe"
167-
elseif itemType == "Two Handed Mace" then return "weapon.twomace"
168-
elseif itemType == "Fishing Rod" then return "weapon.rod"
169-
elseif itemType == "One Handed Sword" then return "weapon.onesword"
170-
elseif itemType == "One Handed Axe" then return "weapon.oneaxe"
171-
elseif itemType == "One Handed Mace" or itemType == "Sceptre" then return "weapon.onemace"
172-
elseif itemType == "Wand" then return "weapon.wand"
173-
elseif itemType == "Dagger" then return "weapon.dagger"
174-
elseif itemType == "Claw" then return "weapon.claw"
175-
elseif itemType and itemType:find("Two Handed") then return "weapon.twomelee"
176-
elseif itemType and itemType:find("One Handed") then return "weapon.one"
177-
else return "weapon"
163+
if not itemType then return "weapon.one", "1HWeapon" end
164+
if itemType == "Shield" then return "armour.shield", "Shield"
165+
elseif itemType == "Quiver" then return "armour.quiver", "Quiver"
166+
elseif itemType == "Bow" then return "weapon.bow", "Bow"
167+
elseif itemType == "Staff" then return "weapon.staff", "Staff"
168+
elseif itemType == "Two Handed Sword" then return "weapon.twosword", "2HSword"
169+
elseif itemType == "Two Handed Axe" then return "weapon.twoaxe", "2HAxe"
170+
elseif itemType == "Two Handed Mace" then return "weapon.twomace", "2HMace"
171+
elseif itemType == "Fishing Rod" then return "weapon.rod", "FishingRod"
172+
elseif itemType == "One Handed Sword" then return "weapon.onesword", "1HSword"
173+
elseif itemType == "One Handed Axe" then return "weapon.oneaxe", "1HAxe"
174+
elseif itemType == "One Handed Mace" or itemType == "Sceptre" then return "weapon.onemace", "1HMace"
175+
elseif itemType == "Wand" then return "weapon.wand", "Wand"
176+
elseif itemType == "Dagger" then return "weapon.dagger", "Dagger"
177+
elseif itemType == "Claw" then return "weapon.claw", "Claw"
178+
elseif itemType:find("Two Handed") then return "weapon.twomelee", "2HWeapon"
179+
elseif itemType:find("One Handed") then return "weapon.one", "1HWeapon"
180+
else return "weapon", "1HWeapon"
178181
end
179-
elseif slotName == "Body Armour" then return "armour.chest"
180-
elseif slotName == "Helmet" then return "armour.helmet"
181-
elseif slotName == "Gloves" then return "armour.gloves"
182-
elseif slotName == "Boots" then return "armour.boots"
183-
elseif slotName == "Amulet" then return "accessory.amulet"
184-
elseif slotName == "Ring 1" or slotName == "Ring 2" or slotName == "Ring 3" then return "accessory.ring"
185-
elseif slotName == "Belt" then return "accessory.belt"
186-
elseif slotName:find("Abyssal") then return "jewel.abyss"
187-
elseif slotName:find("Jewel") then return "jewel"
188-
elseif slotName:find("Flask") then return "flask"
189-
else return nil
182+
elseif slotName == "Body Armour" then return "armour.chest", "Chest"
183+
elseif slotName == "Helmet" then return "armour.helmet", "Helmet"
184+
elseif slotName == "Gloves" then return "armour.gloves", "Gloves"
185+
elseif slotName == "Boots" then return "armour.boots", "Boots"
186+
elseif slotName == "Amulet" then return "accessory.amulet", "Amulet"
187+
elseif slotName == "Ring 1" or slotName == "Ring 2" or slotName == "Ring 3" then return "accessory.ring", "Ring"
188+
elseif slotName == "Belt" then return "accessory.belt", "Belt"
189+
elseif slotName:find("Abyssal") then return "jewel.abyss", "AbyssJewel"
190+
elseif slotName:find("Jewel") then return "jewel", nil
191+
elseif slotName:find("Flask") then return "flask", "Flask"
192+
else return nil, nil
190193
end
191194
end
192195

196+
-- Helper: map slot name + item type to trade API category string
197+
function M.getTradeCategory(slotName, item)
198+
if not item or not item.base then return nil end
199+
local queryStr = M.getTradeCategoryInfo(slotName, item)
200+
return queryStr
201+
end
202+
193203
-- Helper: get a display-friendly category name from slot name
194204
function M.getTradeCategoryLabel(slotName, item)
195205
if not item or not item.base then return "Item" end

src/Classes/TradeQueryGenerator.lua

Lines changed: 16 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ local curl = require("lcurl.safe")
99
local m_max = math.max
1010
local s_format = string.format
1111
local t_insert = table.insert
12+
local tradeHelpers = LoadModule("Classes/CompareTradeHelpers")
1213

1314
-- TODO generate these from data files
1415
local itemCategoryTags = {
@@ -762,103 +763,25 @@ function TradeQueryGeneratorClass:StartQuery(slot, options)
762763
itemCategory = "AnyJewel"
763764
itemCategoryQueryStr = "jewel"
764765
end
765-
elseif slot.slotName:find("^Weapon %d") then
766-
if existingItem then
767-
if existingItem.type == "Shield" then
768-
itemCategoryQueryStr = "armour.shield"
769-
itemCategory = "Shield"
770-
elseif existingItem.type == "Quiver" then
771-
itemCategoryQueryStr = "armour.quiver"
772-
itemCategory = "Quiver"
773-
elseif existingItem.type == "Bow" then
774-
itemCategoryQueryStr = "weapon.bow"
775-
itemCategory = "Bow"
776-
elseif existingItem.type == "Staff" then
777-
itemCategoryQueryStr = "weapon.staff"
778-
itemCategory = "Staff"
779-
elseif existingItem.type == "Two Handed Sword" then
780-
itemCategoryQueryStr = "weapon.twosword"
781-
itemCategory = "2HSword"
782-
elseif existingItem.type == "Two Handed Axe" then
783-
itemCategoryQueryStr = "weapon.twoaxe"
784-
itemCategory = "2HAxe"
785-
elseif existingItem.type == "Two Handed Mace" then
786-
itemCategoryQueryStr = "weapon.twomace"
787-
itemCategory = "2HMace"
788-
elseif existingItem.type == "Fishing Rod" then
789-
itemCategoryQueryStr = "weapon.rod"
790-
itemCategory = "FishingRod"
791-
elseif existingItem.type == "One Handed Sword" then
792-
itemCategoryQueryStr = "weapon.onesword"
793-
itemCategory = "1HSword"
794-
elseif existingItem.type == "One Handed Axe" then
795-
itemCategoryQueryStr = "weapon.oneaxe"
796-
itemCategory = "1HAxe"
797-
elseif existingItem.type == "One Handed Mace" or existingItem.type == "Sceptre" then
798-
itemCategoryQueryStr = "weapon.onemace"
799-
itemCategory = "1HMace"
800-
elseif existingItem.type == "Wand" then
801-
itemCategoryQueryStr = "weapon.wand"
802-
itemCategory = "Wand"
803-
elseif existingItem.type == "Dagger" then
804-
itemCategoryQueryStr = "weapon.dagger"
805-
itemCategory = "Dagger"
806-
elseif existingItem.type == "Claw" then
807-
itemCategoryQueryStr = "weapon.claw"
808-
itemCategory = "Claw"
809-
elseif existingItem.type:find("Two Handed") ~= nil then
810-
itemCategoryQueryStr = "weapon.twomelee"
811-
itemCategory = "2HWeapon"
812-
elseif existingItem.type:find("One Handed") ~= nil then
813-
itemCategoryQueryStr = "weapon.one"
814-
itemCategory = "1HWeapon"
766+
else
767+
itemCategoryQueryStr, itemCategory = tradeHelpers.getTradeCategoryInfo(slot.slotName, existingItem)
768+
769+
-- Generic Jewel slot: caller selects the jewel subtype.
770+
if slot.slotName:find("Jewel") ~= nil and not slot.slotName:find("Abyssal") then
771+
itemCategory = options.jewelType .. "Jewel"
772+
if itemCategory == "AbyssJewel" then
773+
itemCategoryQueryStr = "jewel.abyss"
774+
elseif itemCategory == "BaseJewel" then
775+
itemCategoryQueryStr = "jewel.base"
815776
else
816-
logToFile("'%s' is not supported for weighted trade query generation", existingItem.type)
817-
return
777+
itemCategoryQueryStr = "jewel"
818778
end
819-
else
820-
-- Item does not exist in this slot so assume 1H weapon
821-
itemCategoryQueryStr = "weapon.one"
822-
itemCategory = "1HWeapon"
823779
end
824-
elseif slot.slotName == "Body Armour" then
825-
itemCategoryQueryStr = "armour.chest"
826-
itemCategory = "Chest"
827-
elseif slot.slotName == "Helmet" then
828-
itemCategoryQueryStr = "armour.helmet"
829-
itemCategory = "Helmet"
830-
elseif slot.slotName == "Gloves" then
831-
itemCategoryQueryStr = "armour.gloves"
832-
itemCategory = "Gloves"
833-
elseif slot.slotName == "Boots" then
834-
itemCategoryQueryStr = "armour.boots"
835-
itemCategory = "Boots"
836-
elseif slot.slotName == "Amulet" then
837-
itemCategoryQueryStr = "accessory.amulet"
838-
itemCategory = "Amulet"
839-
elseif slot.slotName == "Ring 1" or slot.slotName == "Ring 2" or slot.slotName == "Ring 3" then
840-
itemCategoryQueryStr = "accessory.ring"
841-
itemCategory = "Ring"
842-
elseif slot.slotName == "Belt" then
843-
itemCategoryQueryStr = "accessory.belt"
844-
itemCategory = "Belt"
845-
elseif slot.slotName:find("Abyssal") ~= nil then
846-
itemCategoryQueryStr = "jewel.abyss"
847-
itemCategory = "AbyssJewel"
848-
elseif slot.slotName:find("Jewel") ~= nil then
849-
itemCategoryQueryStr = "jewel"
850-
itemCategory = options.jewelType .. "Jewel"
851-
if itemCategory == "AbyssJewel" then
852-
itemCategoryQueryStr = "jewel.abyss"
853-
elseif itemCategory == "BaseJewel" then
854-
itemCategoryQueryStr = "jewel.base"
780+
781+
if not itemCategoryQueryStr then
782+
logToFile("'%s' is not supported for weighted trade query generation", existingItem and existingItem.type or "n/a")
783+
return
855784
end
856-
elseif slot.slotName:find("Flask") ~= nil then
857-
itemCategoryQueryStr = "flask"
858-
itemCategory = "Flask"
859-
else
860-
logToFile("'%s' is not supported for weighted trade query generation", existingItem and existingItem.type or "n/a")
861-
return
862785
end
863786

864787
-- Create a temp item for the slot with no mods

0 commit comments

Comments
 (0)