@@ -12,15 +12,25 @@ local t_insert = table.insert
1212local tradeHelpers = LoadModule (" Classes/TradeHelpers" )
1313local utils = LoadModule (" Modules/Utils" )
1414
15- -- a table which tells us what subtypes each category we can search for contains
15+ -- a table which tells us what subtypes each category we can search for
16+ -- contains. the commented out lines are type-subtype combinations which don't
17+ -- exist yet, but might exist in the future
1618local tradeCategoryNames = {
1719 [" Ring" ] = { " Ring" },
1820 [" Amulet" ] = { " Amulet" },
1921 [" Belt" ] = { " Belt" },
20- [" Chest" ] = { " Body Armour" , " Body Armour: Armour" , " Body Armour: Armour/Energy Shield" , " Body Armour: Armour/Evasion" , " Body Armour: Armour/Evasion/Energy Shield" , " Body Armour: Energy Shield" , " Body Armour: Evasion" , " Body Armour: Evasion/Energy Shield" , " Body Armour: Ward" },
21- [" Helmet" ] = { " Helmet" , " Helmet: Armour" , " Helmet: Armour/Energy Shield" , " Helmet: Armour/Evasion" , " Helmet: Armour/Evasion/Energy Shield" , " Helmet: Energy Shield" , " Helmet: Evasion" , " Helmet: Evasion/Energy Shield" , " Helmet: Ward" },
22- [" Gloves" ] = { " Gloves: Armour" , " Gloves: Armour/Energy Shield" , " Gloves: Armour/Evasion" , " Gloves: Armour/Evasion/Energy Shield" , " Gloves: Energy Shield" , " Gloves: Evasion" , " Gloves: Evasion/Energy Shield" , " Gloves: Ward" },
23- [" Boots" ] = { " Boots" , " Boots: Armour" , " Boots: Armour/Energy Shield" , " Boots: Armour/Evasion" , " Boots: Armour/Evasion/Energy Shield" , " Boots: Energy Shield" , " Boots: Evasion" , " Boots: Evasion/Energy Shield" , " Boots: Ward" },
22+ [" Chest" ] = { " Body Armour" , " Body Armour: Armour" , " Body Armour: Armour/Energy Shield" , " Body Armour: Armour/Evasion" , " Body Armour: Armour/Evasion/Energy Shield" , " Body Armour: Energy Shield" , " Body Armour: Evasion" , " Body Armour: Evasion/Energy Shield" ,
23+ -- "Body Armour: Ward"
24+ },
25+ [" Helmet" ] = { " Helmet" , " Helmet: Armour" , " Helmet: Armour/Energy Shield" , " Helmet: Armour/Evasion" ,
26+ -- "Helmet: Armour/Evasion/Energy Shield",
27+ " Helmet: Energy Shield" , " Helmet: Evasion" , " Helmet: Evasion/Energy Shield" , " Helmet: Ward" },
28+ [" Gloves" ] = { " Gloves: Armour" , " Gloves: Armour/Energy Shield" , " Gloves: Armour/Evasion" ,
29+ -- "Gloves: Armour/Evasion/Energy Shield",
30+ " Gloves: Energy Shield" , " Gloves: Evasion" , " Gloves: Evasion/Energy Shield" , " Gloves: Ward" },
31+ [" Boots" ] = { " Boots" , " Boots: Armour" , " Boots: Armour/Energy Shield" , " Boots: Armour/Evasion" ,
32+ -- "Boots: Armour/Evasion/Energy Shield",
33+ " Boots: Energy Shield" , " Boots: Evasion" , " Boots: Evasion/Energy Shield" , " Boots: Ward" },
2434 [" Quiver" ] = { " Quiver" },
2535 [" Shield" ] = { " Shield" , " Shield: Armour" , " Shield: Armour/Energy Shield" , " Shield: Armour/Evasion" , " Shield: Energy Shield" , " Shield: Evasion" , " Shield: Evasion/Energy Shield" },
2636 [" 1HWeapon" ] = { " Claw" , " Dagger" , " One Handed Axe" , " One Handed Mace" , " Wand" , " Sceptre" , " One Handed Sword" , " One Handed Sword: Thrusting" },
@@ -45,35 +55,55 @@ local tradeCategoryNames = {
4555 [" ManaFlask" ] = { " Flask: Mana" },
4656 [" Flask" ] = { " Flask: Utility" },
4757}
48-
49- -- Build lists of tags present on a given item category
50- local tradeCategoryTags = {}
51- for type , bases in pairs (data .itemBaseLists ) do
52- for _ , base in ipairs (bases ) do
53- if not base .hidden then
54- if not tradeCategoryTags [type ] then
55- tradeCategoryTags [type ] = {}
56- end
57- local baseTags = {}
58- for tag , _ in pairs (base .base .tags ) do
59- if tag ~= " default" and tag ~= " demigods" and not tag :match (" _basetype" ) and tag ~= " not_for_sale" then -- filter fluff tags not used on mods.
60- baseTags [tag ] = true
58+ local basesForType
59+
60+ local function canModSpawnForItemCategory (mod , category )
61+ -- lazy load type list as it's only required when generating QueryMods.lua
62+ if not basesForType then
63+ basesForType = {}
64+ for _ , bases in pairs (data .itemBaseLists ) do
65+ for _ , base in ipairs (bases ) do
66+ local base = base .base
67+ -- gather a table which maps from type: subtype to a list of bases
68+ if not base .hidden and base .type then
69+ local type = base .type
70+ local subType = base .subType
71+ if not basesForType [type ] then
72+ basesForType [type ] = {}
73+ end
74+ table.insert (basesForType [type ], base )
75+ if subType then
76+ if not basesForType [type .. " : " .. subType ] then
77+ basesForType [type .. " : " .. subType ] = {}
78+ end
79+ table.insert (basesForType [type .. " : " .. subType ], base )
80+ end
6181 end
6282 end
63- for _ , tag in pairs (base .base .influenceTags or {}) do
64- baseTags [tag ] = true
65- end
66- local present = false
67- for i , tags in ipairs (tradeCategoryTags [type ]) do
68- if tableDeepEquals (baseTags , tags ) then
69- present = true
83+ end
84+ end
85+ -- mock item
86+ local itemClass = new (" Item" )
87+ local itemObj = {}
88+ -- add all influences to fake item
89+ for _ , curInfluenceInfo in ipairs (itemLib .influenceInfo .all ) do
90+ itemObj [curInfluenceInfo .key ] = true
91+ end
92+ for _ , type in ipairs (tradeCategoryNames [category ]) do
93+ -- crafted mod
94+ if not mod .weightKey then
95+ return mod .types [category ]
96+ else
97+ -- test if item can spawn for any base of the given type
98+ for _ , base in ipairs (basesForType [type ] or error (" missing bases for type " .. type )) do
99+ itemObj .base = base
100+ if itemClass .GetModSpawnWeight (itemObj , mod ) > 0 then
101+ return true
70102 end
71103 end
72- if not present then
73- t_insert (tradeCategoryTags [type ], baseTags )
74- end
75104 end
76105 end
106+ return false
77107end
78108--- @return table[] ? category list of entries for the mod type
79109local function getStatEntries (modType )
@@ -131,27 +161,6 @@ local TradeQueryGeneratorClass = newClass("TradeQueryGenerator", function(self,
131161 self .lastMaxLevel = nil
132162end )
133163
134- local function canModSpawnForItemCategory (mod , names )
135- for _ , name in pairs (tradeCategoryNames [names ]) do
136- -- crafted mod
137- if not mod .weightKey then
138- return mod .types [name ]
139- else
140- for _ , tags in ipairs (tradeCategoryTags [name ] or {}) do
141- for i , key in ipairs (mod .weightKey ) do
142- if tags [key ] then
143- if mod .affix :find (" Elevated" ) or mod .weightVal [i ] > 0 then
144- return true
145- else
146- break
147- end
148- end
149- end
150- end
151- end
152- end
153- return false
154- end
155164function TradeQueryGeneratorClass .WeightedRatioOutputs (baseOutput , newOutput , statWeights )
156165 local meanStatDiff = 0
157166
@@ -476,30 +485,12 @@ function TradeQueryGeneratorClass:InitMods()
476485
477486 -- implicit mods
478487 for _ , entry in pairsSortByKey (data .itemBases ) do
479- if entry .implicit ~= nil then
480- local mod = { type = " Implicit" }
481- for modLine in string.gmatch (entry .implicit , " ([^" .. " \n " .. " ]+)" ) do
482- t_insert (mod , modLine )
483- end
484-
485- local found = false
486- for _ , modLine in ipairs (mod ) do
487- if modLine :find (" Grants Level" ) then
488- goto continue
489- end
490- for _ , v in pairs (data .itemMods .ItemExclusive ) do
491- if v [1 ] == modLine then
492- found = true
493- mod = v
494- mod .type = " Implicit"
495- break
496- end
497- end
498- end
499- if not found then
500- ConPrintf (" unknown implicit mod: %s" , mod [1 ])
501- goto continue
502- end
488+ if entry .type == " Graft" then
489+ goto continue
490+ end
491+ for _ , modId in ipairs (entry .implicitIds or {}) do
492+ local mod = copyTable (data .itemMods .ItemExclusive [modId ] or error (" mod id doesn't exist " .. modId ))
493+ mod .type = " Implicit"
503494
504495 -- create trade type mask for base type
505496 local maskOverride = {}
0 commit comments