-
Notifications
You must be signed in to change notification settings - Fork 5
/
ConsumableSimulation.rb
155 lines (136 loc) · 5.1 KB
/
ConsumableSimulation.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
require "rubygems"
require "bundler/setup"
require_relative "lib/DataMaps"
require_relative "lib/HeroInterface"
require_relative "lib/Interactive"
require_relative "lib/JSONResults"
require_relative "lib/Logging"
require_relative "lib/ReportWriter"
require_relative "lib/SimcConfig"
require_relative "lib/SimcHelper"
Logging.Initialize("ConsumableSimulation")
fightstyle, fightstyleFile = Interactive.SelectTemplate("Fightstyles/Fightstyle_")
classfolder = Interactive.SelectSubfolder("Templates")
template, templateFile = Interactive.SelectTemplate(["Templates/#{classfolder}/", ""], classfolder)
# 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
# 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 'food=disabled'
simcInput.push 'flask=disabled'
simcInput.push 'potion=disabled'
simcInput.push 'augmentation=disabled'
simcInput.push 'temporary_enchant=disabled'
simcInput.push ""
consumableList = JSONParser.ReadFile("#{SimcConfig["ProfilesFolder"]}/Consumables.json")
useOilTemplates = consumableList.any? {|x| x["specs"].include?(specId) && x["useOilTemplate"]}
oilProfilesets = []
# Additional template with shadowcore oil for potion interactions
simcInput.push("profileset.\"Oil_Template\"+=temporary_enchant=main_hand:shadowcore_oil") if useOilTemplates
# Get better combination overrides if CombinationBasedCharts is enabled. These will be run in addition to defaults.
#combinationOverrides = HeroInterface.GetBestCombinationOverrides(fightstyle, template, talents)
combinationOverrides = {}
# 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}"
if useOilTemplates
simcInput.push "profileset.\"Oil_TalentTemplate_#{talentString}\"+=talents=#{talentString}"
simcInput.push "profileset.\"Oil_TalentTemplate_#{talentString}\"+=temporary_enchant=main_hand:shadowcore_oil"
end
end
# Add empty override set for the default loop
combinationOverrides[nil] = []
combinationOverrides.each do |optionsString, overrides|
# Generate soulbind profiles
consumableList.each do |consumable|
next if !consumable["specs"].include?(specId)
name = "#{consumable["name"]}#{"--" if optionsString}#{optionsString}"
prefix = "profileset.\"#{name}\"+="
simcInput.push(prefix + "name=\"#{name}\"")
inputValue = consumable["value"] ? consumable["value"] : SimcHelper.TokenizeName(consumable["name"])
simcInput.push(prefix + "#{consumable["type"]}=#{inputValue}")
overrides.each do |override|
simcInput.push(prefix + "#{override}")
end
if consumable["useOilTemplate"]
simcInput.push(prefix + "temporary_enchant=main_hand:shadowcore_oil")
oilProfilesets.push(name)
end
simcInput.push ""
end
end
simulationFilename = "ConsumableSimulation_#{fightstyle}_#{template}"
params = [
"#{SimcConfig["ConfigFolder"]}/SimcConsumableConfig.simc",
fightstyleFile,
templateFile,
simcInput,
]
SimcHelper.RunSimulation(params, simulationFilename)
# Read JSON Output
results = JSONResults.new(simulationFilename)
# Process results
Logging.LogScriptInfo "Processing results..."
templateDPS = 0
oilTemplateDPS = 0
talentDPS = {}
oilTalentDPS = {}
sims = {}
results.getAllDPSResults().each do |name, dps|
if name.start_with?("TalentTemplate_")
talentString = name.split("_")[1]
talentDPS[talentString] = dps
elsif name.start_with?("Oil_TalentTemplate_")
talentString = name.split("_")[2]
oilTalentDPS[talentString] = dps
elsif name == "Template"
templateDPS = dps
elsif name == "Oil_Template"
oilTemplateDPS = dps
else
sims[name] = dps
end
end
# Construct the report
Logging.LogScriptInfo "Construct the report..."
report = []
# Header
def hashElementType(value)
return {"type" => value}
end
header = [hashElementType("string"), hashElementType("number")]
report.push(header)
# Body
sims.each do |name, value|
useOil = oilProfilesets.include?(name)
compareDPS = useOil ? oilTemplateDPS : templateDPS
if (data = /.*talents:(\p{Digit}+).*\Z/.match(name))
compareDPS = useOil ? oilTalentDPS[data[1]] : talentDPS[data[1]]
end
actor = [name, value - compareDPS]
report.push(actor)
end
# Write the report(s)
ReportWriter.WriteArrayReport(results, report)
Logging.LogScriptInfo "Done! Press enter to quit..."
Interactive.GetInputOrArg()