-
Notifications
You must be signed in to change notification settings - Fork 5
/
SoulbindSimulation.rb
199 lines (182 loc) · 6.62 KB
/
SoulbindSimulation.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
require "rubygems"
require "bundler/setup"
require_relative "lib/DataMaps"
require_relative "lib/HeroInterface"
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"
Logging.Initialize("SoulbindSimulation")
fightstyle, fightstyleFile = Interactive.SelectTemplate("Fightstyles/Fightstyle_")
classfolder = Interactive.SelectSubfolder("Templates")
template, templateFile = Interactive.SelectTemplate(["Templates/#{classfolder}/", ""], classfolder)
classId = ClassAndSpecIds[classfolder][:class_id]
# Read spec from template profile
spec = ProfileHelper.GetValueFromTemplate("spec", templateFile)
unless spec
Logging.LogScriptError "No spec= string found in profile!"
exit
end
specId = ClassAndSpecIds[classfolder][:specs][spec]
# Read talents from template profile
talents = ProfileHelper.GetValueFromTemplate("talents", templateFile)
unless talents
Logging.LogScriptError "No talents= string found in profile!"
exit
end
covenant = Interactive.SelectFromArray("Covenant", ["Kyrian", "Necrolord", "Night-Fae", "Venthyr"])
covenant_simc = covenant.downcase.gsub("-", "_")
# Log all interactively set settings
puts
Logging.LogScriptInfo "Summarizing input:"
Logging.LogScriptInfo "-- Class: #{classfolder}"
Logging.LogScriptInfo "-- Profile: #{template}"
Logging.LogScriptInfo "-- Fightstyle: #{fightstyle}"
puts
simcInput = []
Logging.LogScriptInfo "Generating profilesets..."
simcInput.push 'name="Template"'
simcInput.push "covenant=" + covenant_simc
simcInput.push "soulbind="
simcInput.push ""
# Get better combination overrides if CombinationBasedCharts is enabled. These will be run in addition to defaults.
combinationOverrides = HeroInterface.GetBestCombinationOverrides(fightstyle, template, talents)
# Create additional Template base profilesets for the talent overrides
additionalTalents = combinationOverrides.keys.collect { |x| (data = /.*talents:(\p{Digit}+).*\Z/.match(x)) ? data[1] : nil }.uniq.compact
additionalTalents.each do |talentString|
simcInput.push "profileset.\"TalentTemplate_#{talentString}\"+=talents=#{talentString}"
end
# Add empty override set for the default loop
combinationOverrides[nil] = []
conduitList = JSONParser.ReadFile("#{SimcConfig["ProfilesFolder"]}/Conduits.json")
soulbindSettings = JSONParser.ReadFile("#{SimcConfig["ProfilesFolder"]}/SoulbindSettings.json")
combinationOverrides.each do |optionsString, overrides|
# Generate soulbind profiles
soulbindSettings["soulbindSims"].each do |soulbind_trait|
next if soulbind_trait["covenant"] != covenant_simc
name = "#{soulbind_trait["spellName"]} (#{soulbind_trait["soulbindName"]})#{"--" if optionsString}#{optionsString}"
name += "@Use#{soulbind_trait["useFinalBase"]}" if soulbind_trait["useFinalBase"]
name += "@Base#{soulbind_trait["isFinalBase"]}" if soulbind_trait["isFinalBase"]
name += "_1"
prefix = "profileset.\"#{name}\"+="
simcInput.push(prefix + "name=\"#{name}\"")
soulbind_str = "#{soulbind_trait["spellId"]}"
if soulbind_trait["useFinalBase"]
basetrait = soulbindSettings["soulbindSims"].find {|x| x["isFinalBase"] == soulbind_trait["useFinalBase"] }
soulbind_str += "/#{basetrait["spellId"]}"
end
simcInput.push(prefix + "soulbind=#{soulbind_str}")
if soulbind_trait["additionalInput"]
soulbind_trait["additionalInput"].each do |input|
simcInput.push(prefix + "#{input}")
end
end
overrides.each do |override|
simcInput.push(prefix + "#{override}")
end
simcInput.push ""
end
# Generate conduit profiles
conduitList.each do |conduit|
next unless conduit["specs"].include?(specId)
next unless conduit["conduitType"] == 1
specific_covenant = soulbindSettings["covenantConduitsMap"][conduit["conduitSpellID"].to_s]
next if specific_covenant && specific_covenant != covenant_simc
soulbindSettings["conduitRanks"].each do |rank|
name = "#{conduit["conduitName"]}#{"--" if optionsString}#{optionsString}_#{rank[1]}"
prefix = "profileset.\"#{name}\"+="
simcInput.push(prefix + "name=\"#{name}\"")
simcInput.push(prefix + "soulbind=#{conduit["conduitId"]}:#{rank[0]}")
if conduit["additionalInput"]
conduit["additionalInput"].each do |input|
simcInput.push(prefix + "#{input}")
end
end
overrides.each do |override|
simcInput.push(prefix + "#{override}")
end
end
simcInput.push ""
end
end
simulationFilename = "SoulbindSimulation_#{fightstyle}_#{template}_#{covenant}"
params = [
"#{SimcConfig["ConfigFolder"]}/SimcSoulbindConfig.simc",
fightstyleFile,
templateFile,
simcInput,
]
SimcHelper.RunSimulation(params, simulationFilename)
# Read JSON Output
results = JSONResults.new(simulationFilename)
# Process results
Logging.LogScriptInfo "Processing results..."
templateDPS = 0
otherBases = {}
talentDPS = {}
columns = []
sims = {}
results.getAllDPSResults().each do |name, dps|
if name.start_with?("TalentTemplate_")
talentString = name.split("_")[1]
talentDPS[talentString] = dps
elsif data = /\A(.+)_(\p{Digit}+)\Z/.match(name)
sims[data[1]] = {} unless sims[data[1]]
sims[data[1]][data[2].to_i] = dps
columns.push(data[2].to_i)
splitcheck = data[1].split("@Base")
if splitcheck.count > 1
basename = splitcheck[1]
basename += "T" if data[1].include?("talents:") #HAX
otherBases[basename] = dps
end
elsif name == "Template"
templateDPS = dps
end
end
columns.uniq!
columns.sort!
# Construct the report
Logging.LogScriptInfo "Construct the report..."
report = []
# Header
header = ["Power"]
columns.each do |col|
header.push(col.to_s)
end
report.push(header)
# Body
sims.each do |name, values|
actor = []
actor.push(name.split("@Use")[0].split("@Base")[0])
columns.each do |col|
if values[col]
if (data = /.*talents:(\p{Digit}+).*\Z/.match(name)) && talentDPS[data[1]]
compare = talentDPS[data[1]]
splitcheck = name.split("@Use")
if splitcheck.count > 1
compare = otherBases["#{splitcheck[1]}T"]
end
actor.push(values[col] - compare)
else
compare = templateDPS
splitcheck = name.split("@Use")
if splitcheck.count > 1
compare = otherBases[splitcheck[1]]
end
actor.push(values[col] - compare)
end
else
actor.push(0)
end
end
report.push(actor)
end
# Write the report(s)
ReportWriter.WriteArrayReport(results, report)
Logging.LogScriptInfo "Done! Press enter to quit..."
Interactive.GetInputOrArg()