1+ record maximizer_result {
2+ string display;
3+ string command;
4+ float score ;
5+ effect effect ;
6+ item item ;
7+ skill skill ;
8+ string afterdisplay;
9+ };
10+
11+ string [string ] recommendedMaximizerStrings () {
12+ string [string ] res;
13+
14+ void recommendIf (boolean condition, string recommendation, string reason) {
15+ if (condition) {
16+ if (res contains recommendation) {
17+ res[recommendation] += ' , ' + reason;
18+ } else {
19+ res[recommendation] = reason;
20+ }
21+ }
22+ }
23+
24+ boolean highlandsTime = $strings [step1, step2 ] contains get_property (' questL09Topping' );
25+ string nsQuest = get_property (' questL13Final' );
26+ boolean nunsTime = get_property (' sidequestNunsCompleted' ) == ' none' &&
27+ get_property (' questL12War' ) == ' step1' &&
28+ get_property (' fratboysDefeated' ).to_int () >= 192 ;
29+ boolean kitchenTime = get_property (' questM20Necklace' ) == ' started' ;
30+ boolean peakTime = $strings [step3, step4 ] contains get_property (' questL08Trapper' );
31+ boolean wantPassiveDamage = nsQuest == ' step6' ;
32+ boolean wantSpellDamage = nsQuest == ' step8' ;
33+
34+ recommendIf (nsQuest == ' step7' , ' meat' , ' wall of meat' );
35+ recommendIf (nunsTime, ' meat, outfit frat warrior fatigues' , ' nuns' );
36+ // probably not an exhaustive list of reasons to want ML
37+ recommendIf (get_property (' questL03Rat' ) == ' step1' , ' ML' , ' rat kings' );
38+ recommendIf (get_property (' cyrptCrannyEvilness' ).to_int () > 13 , ' ML, -combat' , ' ghuol whelps' );
39+ recommendIf (highlandsTime && get_property (' oilPeakProgress' ).to_float () > 0 , ' ML, 0.2 item' , ' oil peak' );
40+ recommendIf (available_amount ($item [unstable fulminate ] ) > 0 , ' 82 max, ML' , ' wine bomb' );
41+ // likewise probably not exhaustive list of reasons to want init
42+ recommendIf (get_property (' cyrptAlcoveEvilness' ).to_int () > 13 ,
43+ ' init 850 max, -combat' , ' modern zmobie' );
44+ recommendIf (highlandsTime && (get_property (' twinPeakProgress' ).to_int () & 7 ) == 7 ,
45+ ' init 40 max, -combat' , ' twin peaks' );
46+ recommendIf (nsQuest != ' unstarted' && get_property (' nsContestants1' ).to_int () < 0 ,
47+ ' 400 max, init' , ' init test' );
48+ // probably want more ele res considerations
49+ recommendIf (kitchenTime, ' hot res 9 max, stench res 9 max' , ' kitchen' );
50+ recommendIf (peakTime, ' cold res 5 max, 0.02 meat' , ' peak' );
51+ recommendIf (highlandsTime && get_property (' booPeakProgress' ).to_int () > 0 , ' cold res, spooky res, 0.05 hp' , ' surviving a-boo clues' );
52+ recommendIf (nsQuest == ' step4' , ' all res' , ' hedge maze' );
53+ // some towerkilling recs
54+ recommendIf (wantPassiveDamage, ' damage aura, thorns' , ' wall of skin' );
55+ recommendIf (wantSpellDamage,
56+ ' spell damage percent, 200 lantern, 0.5 myst, -1000 damage aura, -1000 thorns' , ' wall of bones' );
57+ // other ns contests
58+ string testStat = get_property (' nsChallenge1' ).to_lower_case ();
59+ recommendIf (nsQuest != ' unstarted' && get_property (' nsContestants2' ).to_int () < 0 && testStat != ' none' ,
60+ ' 600 max, ' + testStat, testStat + ' test' );
61+ string testElement = get_property (' nsChallenge2' ).to_lower_case ();
62+ recommendIf (nsQuest != ' unstarted' && get_property (' nsContestants3' ).to_int () < 0 && testElement != ' none' ,
63+ ' 100 max, ' + testElement + ' damage, ' + testElement + ' spell damage' , testElement + ' test' );
64+
65+ return res;
66+ }
67+
168void bakeMaximizer () {
269 buffer result;
370
71+ string [string ] recommendations = recommendedMaximizerStrings ();
472 string [string ] fields = form_fields ();
73+ string equipWhere = fields[" maxequipwhere" ];
74+ int equipScope = equipWhere == " pullbuy" ? 2 : equipWhere == " create" ? 1 : equipWhere == " onhand"
75+ ? 0 : cvars[" chit.maximizer.scope" ].to_int ();
76+ boolean [string ] allFilters = $strings [equip,cast,wish,other,usable,booze,food,spleen ] ;
77+ maximizer_result[int ] maximizeOut;
78+ string maxFilters = " " ;
79+ if (fields contains " tomax" ) {
80+ set_property (' chit.maximizer.max' , fields[" tomax" ]);
81+ set_property (' chit.maximizer.scope' , equipScope);
82+ foreach filter in allFilters {
83+ if (fields[" max" + filter].to_boolean ()) {
84+ maxFilters = maxFilters .simple_list_add (filter, ' ,' );
85+ }
86+ }
87+ if (maxFilters == ' ' && cvars[' chit.maximizer.filters' ] != ' ' ) {
88+ maxFilters = cvars[" chit.maximizer.filters" ];
89+ } else {
90+ set_property (' chit.maximizer.filters' , maxFilters);
91+ }
92+ string actualMax = fields[" tomax" ];
93+ if (cvars[" chit.maximizer.noTies" ].to_boolean () && ! actualMax .contains_text (' -tie' )) {
94+ actualMax += " ,-tie" ;
95+ }
96+ maximizeOut = maximize (actualMax, get_property (" autoBuyPriceLimit" ).to_int (), 2 , equipScope, maxFilters);
97+ } else {
98+ maxFilters = cvars[" chit.maximizer.filters" ];
99+ }
5100
6101 result .append (' <table id="chit_maximizer" class="chit_brick nospace"><tbody>' );
7- result .append (' <tr><th class="label" colspan="5">Maximizer</th></tr><tr>' );
8- result .append (' <td class="info" colspan="5">' );
102+ result .append (' <tr><th class="label" colspan="5">Maximizer' );
103+ if (fields contains " tomax" ) {
104+ result .append (' (Current score: ' );
105+ result .append (current_maximizer_score (fields[" tomax" ]).to_string (' %,.2f' ));
106+ result .append (' )' );
107+ }
108+ result .append (' </th></tr>' );
9109 result .append (' <form action="./charpane.php">' );
110+ result .append (' <tr><td class="info" colspan="3">' );
10111 result .append (' <input type="hidden" name="autoopen" value="maximizer" />' );
11112 result .append (' <input type="text" name="tomax" value="' );
12113 if (fields contains " tomax" ) {
13114 result .append (fields[" tomax" ]);
14115 } else {
15- result .append (get_property ( ' _chitLastMax ' ) );
116+ result .append (cvars[ " chit.maximizer.max " ] );
16117 }
17- result .append (' " />' );
18- result .append (' <button type="submit" name="action" value="maximize">Maximize</button>' );
19- result .append (' </form>' );
118+ result .append (' "' );
119+ if (recommendations .count () > 0 ) {
120+ result .append (' list="maxsuggestions"' );
121+ }
122+ result .append (' />' );
123+ if (recommendations .count () > 0 ) {
124+ result .append (' <datalist id="maxsuggestions">' );
125+ foreach str, reason in recommendations {
126+ result .append (' <option value="' );
127+ result .append (str);
128+ result .append (' " label="' );
129+ result .append (reason);
130+ result .append (' " />' );
131+ }
132+ result .append (' </datalist>' );
133+ }
134+ result .append (' </td><td>' );
135+ result .append (' <button type="submit" name="action" value="maximize">Max</button>' );
136+ result .append (' </td><td>' );
137+ result .append (' <input type="radio" id="maxonhand" name="maxequipwhere" value="onhand"' );
138+ if (equipScope == 0 ) {
139+ result .append (' checked' );
140+ }
141+ result .append (' />' );
142+ result .append (' <label for="maxonhand">On hand</label>' );
20143 result .append (' </td></tr>' );
144+ result .append (' <tr><td>' );
145+ int count = 0 ;
146+ foreach filter in allFilters {
147+ result .append (' <input type="checkbox"' );
148+ if (maxFilters .simple_list_contains (filter, ' ,' )) {
149+ result .append (' checked' );
150+ }
151+ result .append (' name="max' );
152+ result .append (filter);
153+ result .append (' " id="max' );
154+ result .append (filter);
155+ result .append (' " value="true" />' );
156+ result .append (' <label for="max' );
157+ result .append (filter);
158+ result .append (' ">' );
159+ result .append (filter);
160+ result .append (' </label>' );
161+ result .append (' </td><td>' );
162+ count += 1 ;
163+ if (count == 4 ) {
164+ result .append (' <input type="radio" id="maxcreatable" name="maxequipwhere" value="create"' );
165+ if (equipScope == 1 ) {
166+ result .append (' checked' );
167+ }
168+ result .append (' />' );
169+ result .append (' <label for="maxcreatable">Create</label>' );
170+ result .append (' </td></tr><tr><td>' );
171+ }
172+ }
173+ result .append (' <input type="radio" id="maxpullbuy" name="maxequipwhere" value="pullbuy"' );
174+ if (equipScope == 2 ) {
175+ result .append (' checked' );
176+ }
177+ result .append (' />' );
178+ result .append (' <label for="maxpullbuy">Pull/Buy</label>' );
179+ result .append (' </td></tr>' );
180+ result .append (' </form>' );
21181
22182 if (fields contains " tomax" ) {
23- set_property (' _chitLastMax' , fields[" tomax" ]);
183+ matcher m = create_matcher (" ^\\ s*([\\ d\\ .]+)\\ s*[Mm][Aa][Xx]\\ s*," , fields[" tomax" ]);
184+ if (m .find ()) {
185+ float maxThreshold = m .group (1 ).to_float ();
186+ if (current_maximizer_score (fields[" tomax" ]) >= maxThreshold) {
187+ result .append (' <tr><td colspan="5"><b>You already met your goal! Don\' t waste anything!</b></td></tr>' );
188+ }
189+ }
24190 result .append (' <tr class="darkrow"><td>Icon</td><td>Commmand</td><td>Score</td><td>Info</td><td>Go!</td></tr>' );
25- foreach i,plan in maximize (fields[ " tomax " ], get_property ( " autoBuyPriceLimit " ). to_int (), 2 , true , true ) {
191+ foreach i,plan in maximizeOut {
26192 result .append (' <tr' );
27193 if (i % 2 == 1 ) {
28194 result .append (' class="darkrow"' );
29195 }
30196 result .append (' ><td class="smallicon">' );
31197 chit_info effInfo = getEffectInfo(plan.effect);
32- if (plan .item != $item [none ] && ( plan .display . contains_text ( ' >keep ' ) || plan . display . contains_text ( ' equip ' )) ) {
198+ if (plan .item != $item [none ] && plan .effect == $ effect [ none ] ) {
33199 result .addItemIcon (plan .item , ' ' , true );
34200 } else if (plan .skill != $skill [none ] ) {
35201 chit_info skillInfo = new chit_info(plan.skill, effInfo.desc, DROPS_NONE, DANGER_NONE,
@@ -43,23 +209,16 @@ void bakeMaximizer() {
43209 result .append (' </td><td>' );
44210 result .append (plan .score .to_string (plan .score % 1 == 0 ? ' %.0f' : ' %.2f' ));
45211 result .append (' </td><td>' );
46- if (plan .skill != $skill [none ] ) {
47- string cost = skillCost (plan .skill );
48- if (cost != ' ' ) {
49- result .append (cost);
50- result .append (' , ' );
51- }
52- result .append (turns_per_cast (plan .skill ).formatInt ());
53- result .append (' adv duration' );
54- } else if (plan .item != $item [none ] && plan .effect != $effect [none ] ) {
55- result .append (chit_available (plan .item ).formatInt ());
56- result .append (' available, ' );
57- result .append (numeric_modifier (plan .item , ' Effect Duration' ).formatInt ());
58- result .append (' adv duration' );
59- } else if (plan .display .starts_with (' uneffect' )) {
60- result .append (chit_available ($item [soft green echo eyedrop antidote ] ).formatInt ());
61- result .append (' SGEEAs on hand' );
212+ string after = plan .afterdisplay ;
213+ matcher afterMatcher = create_matcher (' \\ (\\ +?\\ d+\\ )\\ s*' , after);
214+ if (afterMatcher .find ()) {
215+ after = after .replace_string (afterMatcher .group (0 ), ' ' );
216+ }
217+ afterMatcher = create_matcher (' , \\ +?\\ d+\\ )' , after);
218+ if (afterMatcher .find ()) {
219+ after = after .replace_string (afterMatcher .group (0 ), ' )' );
62220 }
221+ result .append (after);
63222 result .append (' </td><td>' );
64223 if (plan .command != ' ' ) {
65224 result .append (' <form action="./charpane.php">' );
@@ -75,7 +234,8 @@ void bakeMaximizer() {
75234 result .append (' disabled ' );
76235 }
77236 result .append (' type="submit" name="action" value="cliexec">' );
78- result .append (plan .display .split_string (' ' )[0 ]);
237+ string [int ] splitDisplay = plan .display .split_string (' ' );
238+ result .append (splitDisplay[0 ] == ' ...or' ? splitDisplay[1 ] : splitDisplay[0 ]);
79239 result .append (' </button></form>' );
80240 }
81241 result .append (' </td></tr>' );
0 commit comments