Skip to content

Commit e26c8bd

Browse files
committed
extract common trade category info between TradeQueryGenerator and CompareTradeHelpers
1 parent ea3bc53 commit e26c8bd

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 = {
@@ -727,103 +728,25 @@ function TradeQueryGeneratorClass:StartQuery(slot, options)
727728
calcNodesInsteadOfMods = true,
728729
}
729730
end
730-
elseif slot.slotName:find("^Weapon %d") then
731-
if existingItem then
732-
if existingItem.type == "Shield" then
733-
itemCategoryQueryStr = "armour.shield"
734-
itemCategory = "Shield"
735-
elseif existingItem.type == "Quiver" then
736-
itemCategoryQueryStr = "armour.quiver"
737-
itemCategory = "Quiver"
738-
elseif existingItem.type == "Bow" then
739-
itemCategoryQueryStr = "weapon.bow"
740-
itemCategory = "Bow"
741-
elseif existingItem.type == "Staff" then
742-
itemCategoryQueryStr = "weapon.staff"
743-
itemCategory = "Staff"
744-
elseif existingItem.type == "Two Handed Sword" then
745-
itemCategoryQueryStr = "weapon.twosword"
746-
itemCategory = "2HSword"
747-
elseif existingItem.type == "Two Handed Axe" then
748-
itemCategoryQueryStr = "weapon.twoaxe"
749-
itemCategory = "2HAxe"
750-
elseif existingItem.type == "Two Handed Mace" then
751-
itemCategoryQueryStr = "weapon.twomace"
752-
itemCategory = "2HMace"
753-
elseif existingItem.type == "Fishing Rod" then
754-
itemCategoryQueryStr = "weapon.rod"
755-
itemCategory = "FishingRod"
756-
elseif existingItem.type == "One Handed Sword" then
757-
itemCategoryQueryStr = "weapon.onesword"
758-
itemCategory = "1HSword"
759-
elseif existingItem.type == "One Handed Axe" then
760-
itemCategoryQueryStr = "weapon.oneaxe"
761-
itemCategory = "1HAxe"
762-
elseif existingItem.type == "One Handed Mace" or existingItem.type == "Sceptre" then
763-
itemCategoryQueryStr = "weapon.onemace"
764-
itemCategory = "1HMace"
765-
elseif existingItem.type == "Wand" then
766-
itemCategoryQueryStr = "weapon.wand"
767-
itemCategory = "Wand"
768-
elseif existingItem.type == "Dagger" then
769-
itemCategoryQueryStr = "weapon.dagger"
770-
itemCategory = "Dagger"
771-
elseif existingItem.type == "Claw" then
772-
itemCategoryQueryStr = "weapon.claw"
773-
itemCategory = "Claw"
774-
elseif existingItem.type:find("Two Handed") ~= nil then
775-
itemCategoryQueryStr = "weapon.twomelee"
776-
itemCategory = "2HWeapon"
777-
elseif existingItem.type:find("One Handed") ~= nil then
778-
itemCategoryQueryStr = "weapon.one"
779-
itemCategory = "1HWeapon"
731+
else
732+
itemCategoryQueryStr, itemCategory = tradeHelpers.getTradeCategoryInfo(slot.slotName, existingItem)
733+
734+
-- Generic Jewel slot: caller selects the jewel subtype.
735+
if slot.slotName:find("Jewel") ~= nil and not slot.slotName:find("Abyssal") then
736+
itemCategory = options.jewelType .. "Jewel"
737+
if itemCategory == "AbyssJewel" then
738+
itemCategoryQueryStr = "jewel.abyss"
739+
elseif itemCategory == "BaseJewel" then
740+
itemCategoryQueryStr = "jewel.base"
780741
else
781-
logToFile("'%s' is not supported for weighted trade query generation", existingItem.type)
782-
return
742+
itemCategoryQueryStr = "jewel"
783743
end
784-
else
785-
-- Item does not exist in this slot so assume 1H weapon
786-
itemCategoryQueryStr = "weapon.one"
787-
itemCategory = "1HWeapon"
788744
end
789-
elseif slot.slotName == "Body Armour" then
790-
itemCategoryQueryStr = "armour.chest"
791-
itemCategory = "Chest"
792-
elseif slot.slotName == "Helmet" then
793-
itemCategoryQueryStr = "armour.helmet"
794-
itemCategory = "Helmet"
795-
elseif slot.slotName == "Gloves" then
796-
itemCategoryQueryStr = "armour.gloves"
797-
itemCategory = "Gloves"
798-
elseif slot.slotName == "Boots" then
799-
itemCategoryQueryStr = "armour.boots"
800-
itemCategory = "Boots"
801-
elseif slot.slotName == "Amulet" then
802-
itemCategoryQueryStr = "accessory.amulet"
803-
itemCategory = "Amulet"
804-
elseif slot.slotName == "Ring 1" or slot.slotName == "Ring 2" or slot.slotName == "Ring 3" then
805-
itemCategoryQueryStr = "accessory.ring"
806-
itemCategory = "Ring"
807-
elseif slot.slotName == "Belt" then
808-
itemCategoryQueryStr = "accessory.belt"
809-
itemCategory = "Belt"
810-
elseif slot.slotName:find("Abyssal") ~= nil then
811-
itemCategoryQueryStr = "jewel.abyss"
812-
itemCategory = "AbyssJewel"
813-
elseif slot.slotName:find("Jewel") ~= nil then
814-
itemCategoryQueryStr = "jewel"
815-
itemCategory = options.jewelType .. "Jewel"
816-
if itemCategory == "AbyssJewel" then
817-
itemCategoryQueryStr = "jewel.abyss"
818-
elseif itemCategory == "BaseJewel" then
819-
itemCategoryQueryStr = "jewel.base"
745+
746+
if not itemCategoryQueryStr then
747+
logToFile("'%s' is not supported for weighted trade query generation", existingItem and existingItem.type or "n/a")
748+
return
820749
end
821-
elseif slot.slotName:find("Flask") ~= nil then
822-
itemCategoryQueryStr = "flask"
823-
itemCategory = "Flask"
824-
else
825-
logToFile("'%s' is not supported for weighted trade query generation", existingItem and existingItem.type or "n/a")
826-
return
827750
end
828751

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

0 commit comments

Comments
 (0)