Skip to content

Commit d0b4e80

Browse files
committed
improve maximizer brick with new maximizer ASH functionality
If you want the full benefits, I recommend setting verboseMaximizer to true. Also note the chit.maximizer.noTies setting, which defaults to true!
1 parent c0c566b commit d0b4e80

5 files changed

Lines changed: 221 additions & 57 deletions

File tree

docs/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ Helpers are there merely for convenience; they will NOT try to auto-adventure fo
397397

398398
- Default: true
399399

400+
- chit.maximizer.noTies: If true, always add -tie to maximizer queries if it's not already present.
401+
402+
- Default: true
403+
404+
- chit.maximizer.filters, chit.maximizer.max, chit.maximizer.scope: Variables used to track state
405+
for the maximizer brick across reloads. There should be no need to configure them from the command
406+
line, and doing so might even cause problems, because some need to be formatted correctly.
407+
400408
# Credits
401409

402410
- Primary Maintainer: [soolar](https://github.com/soolar)

src/relay/charpane.ash

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
script "Character Information Toolbox";
2-
since r28878; // fix for socp shop
2+
since r28883; // maximize enhancements
33
import "zlib.ash";
44
import "chit_global.ash";
55
import "chit_itemInfo.ash";
@@ -67,6 +67,10 @@ chit_setvar("chit.stats.showbars", true);
6767
chit_setvar("chit.thrall.showname", false);
6868
chit_setvar("chit.next.maxlen", 30);
6969
chit_setvar("chit.toolbar.moods", "true"); // do not change to boolean, "bonus" is also valid
70+
chit_setvar("chit.maximizer.noTies", true);
71+
chit_setvar("chit.maximizer.filters", "string", "", false);
72+
chit_setvar("chit.maximizer.max", "string", "", false);
73+
chit_setvar("chit.maximizer.scope", "int", 0, false);
7074

7175
/************************************************************************************
7276
CHaracter Info Toolbox

src/relay/chit_brickMaximizer.ash

Lines changed: 186 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,201 @@
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+
168
void 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>');

src/relay/chit_familiarInfo.ash

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,8 @@ record fam_rec {
952952
string reason;
953953
};
954954

955+
string[string] recommendedMaximizerStrings();
956+
955957
fam_rec [int] getFamRecs(slot s) {
956958
familiar activeFam =
957959
s == $slot[familiar] ? my_familiar()
@@ -1005,10 +1007,9 @@ fam_rec [int] getFamRecs(slot s) {
10051007
? $familiars[Mu, Exotic Parrot]
10061008
: $familiars[Twitching Space Critter, Bad Vibe, Bulky Buddy Box, Holiday Log, Pet Coral,
10071009
Pet Rock, Synthetic Rock, Toothsome Rock, Exotic Parrot];
1008-
1009-
1010-
boolean highlandsTime = $strings[step1, step2] contains get_property('questL09Topping');
1011-
string nsQuest = get_property('questL13Final');
1010+
boolean [familiar] meatFams = s == $slot[familiar]
1011+
? $familiars[Hobo Monkey, Leprechaun]
1012+
: $familiars[Golden Monkey, Ghost of Crimbo Commerce, Happy Medium, Knob Goblin Organ Grinder];
10121013

10131014
if(s == $slot[familiar]) {
10141015
addFirstIf($strings[started, step1] contains get_property('questL11Black') &&
@@ -1019,27 +1020,17 @@ fam_rec [int] getFamRecs(slot s) {
10191020
Stinky Gravy Fairy, Sleazy Gravy Fairy, Spooky Gravy Fairy], 'felonia');
10201021
}
10211022

1022-
// this is probably not an exhaustive list of reasons to want ML
1023-
addFirstIf(get_property('questL03Rat') == 'step1', mlFams, 'rat kings');
1024-
addFirstIf(get_property('cyrptCrannyEvilness').to_int() > 13, mlFams, 'ghuol whelps');
1025-
addFirstIf(highlandsTime && get_property('oilPeakProgress').to_float() > 0, mlFams, 'oil peak');
1026-
addFirstIf(available_amount($item[unstable fulminate]) > 0, mlFams, 'wine bomb');
1027-
1028-
// this is also probably not an exhaustive list of reasons to want init
1029-
addFirstIf(get_property('cyrptAlcoveEvilness').to_int() > 13, initFams, 'modern zmobie');
1030-
addFirstIf(highlandsTime && (get_property('twinPeakProgress').to_int() & 7) == 7
1031-
&& initiative_modifier() < 40, initFams, 'twin peaks');
1032-
addFirstIf(nsQuest != 'unstarted' && get_property('nsContestants1').to_int() < 0, initFams, 'init test');
1033-
1034-
addFirstIf(nsQuest == 'step6', skinFams, 'towerkilling');
1035-
1036-
boolean kitchenTime = get_property('questM20Necklace') == 'started';
1037-
boolean cantTakeTheHeat = numeric_modifier('Hot Resistance') < 9 || numeric_modifier('Stench Resistance') < 9;
1038-
addFirstIf(kitchenTime && cantTakeTheHeat, resFams, 'haunted kitchen');
1039-
addFirstIf($strings[step3, step4] contains get_property('questL08Trapper')
1040-
&& numeric_modifier('Cold Resistance') < 5, resFams, 'misty peak');
1041-
addFirstIf(highlandsTime && get_property('booPeakProgress').to_int() > 0, resFams, 'surviving a-boo clues');
1042-
addFirstIf(nsQuest == 'step4', resFams, 'hedge maze');
1023+
string[string] maxRecs = recommendedMaximizerStrings();
1024+
void addFirstIfMaxRecsContain(string content, boolean[familiar] fams) {
1025+
foreach rec,reason in maxRecs {
1026+
addFirstIf(rec.contains_text(content), fams, reason);
1027+
}
1028+
}
1029+
addFirstIfMaxRecsContain('meat', meatFams);
1030+
addFirstIfMaxRecsContain('ML', mlFams);
1031+
addFirstIfMaxRecsContain('init', initFams);
1032+
addFirstIfMaxRecsContain('damage aura, thorns', skinFams);
1033+
addFirstIfMaxRecsContain(' res', resFams);
10431034

10441035
return recs;
10451036
}

src/relay/chit_global.ash

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ string normalize_prop(string value, string type) {
520520
return value;
521521
}
522522

523-
string define_prop(string name, string type, string def) {
524-
if(!property_exists(name)) {
523+
string define_prop(string name, string type, string def, boolean useDEFAULT) {
524+
if(!property_exists(name) && useDEFAULT) {
525525
set_property(name, "DEFAULT:" + def);
526526
}
527527

@@ -540,7 +540,7 @@ string define_prop(string name, string type, string def) {
540540

541541
string value = normalize_prop(raw_value, type);
542542

543-
if(value == normalize_prop(def, type) && !nondefault)
543+
if(value == normalize_prop(def, type) && !nondefault && useDEFAULT)
544544
set_property(name, "DEFAULT:" + def);
545545
else if(raw_value != value) {
546546
if(nondefault) {
@@ -554,9 +554,10 @@ string define_prop(string name, string type, string def) {
554554
return value;
555555
}
556556

557-
void chit_setvar(string name, string type, string def) {
558-
cvars[name] = define_prop(name, type, def);
557+
void chit_setvar(string name, string type, string def, boolean useDEFAULT) {
558+
cvars[name] = define_prop(name, type, def, useDEFAULT);
559559
}
560+
void chit_setvar(string name, string type, string def) { chit_setvar(name, type, def, true); }
560561
void chit_setvar(string name, boolean def) { chit_setvar(name, "boolean", def); }
561562
void chit_setvar(string name, string def) { chit_setvar(name, "string", def); }
562563
void chit_setvar(string name, int def) { chit_setvar(name, "int", def); }

0 commit comments

Comments
 (0)