-
Notifications
You must be signed in to change notification settings - Fork 5
/
Combinator.rb
264 lines (237 loc) · 8.76 KB
/
Combinator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
require "rubygems"
require "bundler/setup"
require_relative "lib/Interactive"
require_relative "lib/JSONParser"
require_relative "lib/JSONResults"
require_relative "lib/Logging"
require_relative "lib/ProfileHelper"
require_relative "lib/ReportWriter"
require_relative "lib/SimcConfig"
require_relative "lib/SimcHelper"
require_relative "lib/HeroInterface"
Logging.Initialize("Combinator")
fightstyle, fightstyleFile = Interactive.SelectTemplate("Fightstyles/Fightstyle_")
classfolder = Interactive.SelectSubfolder("Templates")
profile, profileFile = Interactive.SelectTemplate(["Templates/#{classfolder}/", ""], classfolder)
#Read spec from profile
spec = ProfileHelper.GetValueFromTemplate("spec", profileFile)
unless spec
Logging.LogScriptError "No spec= string found in profile!"
exit
end
# Read talents from template profile
talents = ProfileHelper.GetValueFromTemplate("talents", profileFile)
unless talents
Logging.LogScriptError "No talents= string found in profile!"
exit
end
gearProfile, gearProfileFile = Interactive.SelectTemplate("Combinator/CombinatorGear_")
talentdatasets = Interactive.SelectTalentPermutations(talents)
# Handle if top talents is required
top_tds = nil
talentdatasets.each do |tds|
if tds == "top"
toptalents = HeroInterface.GetBestTalentBuild(fightstyle, profile, talents)
top_tds = toptalents.chars.collect {|x| [x.to_i] } if toptalents
break
end
end
if top_tds
talentdatasets.delete_if {|x| x == "top" }
if !talentdatasets.any? {|tds| tds.reduce(&:product).collect(&:flatten).include?(top_tds.flatten)}
talentdatasets.push(top_tds)
end
end
# Log all interactively set settings
puts
Logging.LogScriptInfo "Summarizing input:"
Logging.LogScriptInfo "-- Fightstyle: #{fightstyle}"
Logging.LogScriptInfo "-- Class: #{classfolder}"
Logging.LogScriptInfo "-- Profile: #{profile}"
Logging.LogScriptInfo "-- Gear: #{gearProfile}"
Logging.LogScriptInfo "-- Talents: #{talentdatasets}"
puts
# Read gear setups from JSON
gear = YAML.load(File.read(gearProfileFile))
# Step by step cross products with requirement checks
rawCombinations = []
gear["combinatorSlots"].each.with_index(1) do |slot, slotNum|
gear[slot]["options"].delete_if { |x| x["requires"] && x["requires"]["spec"] && !x["requires"]["spec"].include?(spec) }
newOptions = gear[slot]["options"]
if slotNum > 1
rawCombinations = rawCombinations.product(newOptions) # Cross product everything
rawCombinations = rawCombinations.collect(&:flatten) # Remove inner nested arrays
else
rawCombinations = newOptions.collect { |x| [x] } # Create nested arrays for first/single slot combinations
end
# Delete invalid combinations via requirements
rawCombinations.delete_if do |combination|
delete = false
combination.each_with_index do |part, idx|
combinatorSlot = gear[gear["combinatorSlots"][idx]]
combinatorOption = part
# Check requirements
if combinatorOption["requires"]
combinatorOption["requires"].each do |reqSlot, req|
next if reqSlot == "spec" # handled above
refidx = gear["combinatorSlots"].index(reqSlot)
if refidx == nil
delete = true
next
end
req = [req] if req.is_a?(String)
delete = true if !req.include?(combination[refidx]["name"])
end
end
end
next delete
end
# Final cleanups, after checking requirements because there might be duplicate options with different requirements
rawCombinations = rawCombinations.collect { |x| x.uniq { |y| y["name"] } } # Everything inside should be unique (AAB -> AB)
rawCombinations = rawCombinations.select { |x| x.length == slotNum } # Only desired amount of combinator slots
rawCombinations = rawCombinations.uniq { |x| x.collect { |y| y["name"] }.sort } # Only generally unique combinations (no ABC and ACB)
end
# Build gear combination inputs
gearCombinations = {}
rawCombinations.each do |combination|
inputStringsBySimcSlot = {}
names = combination.collect { |x| x["name"] }
hideFromName = []
# Go through slots
combination.each_with_index do |part, idx|
combinatorSlot = gear[gear["combinatorSlots"][idx]]
combinatorOption = part
hideFromName.push(combinatorOption["name"]) if combinatorOption["hidden"]
# Fetch simc input info
next unless combinatorSlot["simcSlot"] # Skip virtual slots
next unless combinatorOption["simcString"] # Skip virtual options
inputStringsBySimcSlot[combinatorSlot["simcSlot"]] ||= []
inputStringsBySimcSlot[combinatorSlot["simcSlot"]].push(combinatorOption["simcString"])
if combinatorOption["additionalInput"]
combinatorOption["additionalInput"].each do |add|
inputStringsBySimcSlot[add["simcSlot"]] ||= []
inputStringsBySimcSlot[add["simcSlot"]].push(add["simcString"])
end
end
end
# Generate and store actual simc input
inputStrings = []
inputStringsBySimcSlot.each do |slot, arr|
inputStrings.push("#{slot}=#{arr.join("/")}")
end
nameArr = names - hideFromName
profileName = nameArr.join("_")
gearCombinations[profileName] = inputStrings
end
# Debug write
#File.open("temp.yml", "w") { |file| file.write(gearCombinations.to_yaml) }
#exit
# Combine gear with talents and write simc input to file
simcInput = []
simcInput.push "name=Template"
if gear["legendary"]
# Create overrides with legendary bonus_ids removed from input
legoList = JSONParser.ReadFile("#{SimcConfig["ProfilesFolder"]}/Legendaries.json")
legoBonusIds = legoList.collect { |x| x["legendaryBonusID"] }
simcInput.push "# Overrides with removed legendary bonus ids where present"
ProfileHelper.RemoveBonusIds(legoBonusIds, profileFile).each do |override|
simcInput.push override
end
simcInput.push "# Overrides done!"
end
simcInput.push ""
Logging.LogScriptInfo "Generating combinations..."
talentdatasets.each do |talentdata|
talentdata[0].each do |t1|
talentdata[1].each do |t2|
talentdata[2].each do |t3|
talentdata[3].each do |t4|
talentdata[4].each do |t5|
talentdata[5].each do |t6|
talentdata[6].each do |t7|
talentInput = "#{t1}#{t2}#{t3}#{t4}#{t5}#{t6}#{t7}"
talentOverrides = ProfileHelper.GetTalentOverrides("Combinator/#{classfolder}/TalentOverrides/#{profile}", talentInput)
gearCombinations.each do |gearName, strings|
name = "#{talentInput}_#{gearName}"
prefix = "profileset.\"#{name}\"+="
simcInput.push(prefix + "name=\"#{name}\"")
simcInput.push(prefix + "talents=#{talentInput}")
talentOverrides.each do |talentOverride|
simcInput.push(prefix + talentOverride)
end
strings.each do |string|
simcInput.push(prefix + string)
end
simcInput.push ""
end
end
end
end
end
end
end
end
end
# Special naming extensions
combinatorStyle = ""
if gear["combinatorExtension"]
combinatorStyle = "-#{gear["combinatorExtension"]}"
end
combinatorVariation = ""
if gear["combinatorVariation"]
combinatorVariation = "_#{gear["combinatorVariation"]}"
end
simulationFilename = "Combinator#{combinatorStyle}_#{fightstyle}_#{profile}#{combinatorVariation}"
params = [
"#{SimcConfig["ConfigFolder"]}/SimcCombinatorConfig.simc",
fightstyleFile,
profileFile,
simcInput,
]
if SimcConfig["CombinatorUseMultiStage"]
SimcHelper.RunMultiStageSimulation(params, simulationFilename)
else
SimcHelper.RunSimulation(params, simulationFilename)
end
# Process results
Logging.LogScriptInfo "Processing results..."
results = JSONResults.new(simulationFilename, SimcConfig["CombinatorUseMultiStage"])
sims = results.getAllDPSResults()
sims.delete("Template")
priorityDps = results.getPriorityDPSResults()
# Construct the report
Logging.LogScriptInfo "Construct the report..."
report = []
sims.each do |name, value|
actor = []
# Split profile name (mostly for web display)
if data = name.match(/\A(\d+)_?([^;]*)\Z/)
# Talents
actor.push(data[1])
# Gear
if not data[2].empty?
gearName = data[2].gsub(/_/, "; ")
else
gearName = "None"
end
actor.push(gearName)
else
# We should not get here, but leave it as failsafe
Logging.LogScriptError "Matching result name failed: #{name}"
actor.push(name)
end
actor.push(value) # DPS
actor.push(priorityDps[name]) if priorityDps[name] # Priority DPS
report.push(actor)
end
# Sort the report by the DPS value in DESC order
report.sort! { |x, y| y[2] <=> x[2] }
# Add the initial rank
report.each_with_index { |actor, index|
actor.unshift(index + 1)
}
# Write the report(s)
ReportWriter.WriteArrayReport(results, report)
puts
Logging.LogScriptInfo "Done! Press enter to quit..."
Interactive.GetInputOrArg()