Skip to content

Commit

Permalink
Add free candy support (#1662)
Browse files Browse the repository at this point in the history
* Updated to current Garbo version

* calculate `treatOutfit` manually

* Added Bill recommended fixes

* Trying this again

* Update packages/garbo/src/resources/candyMap.ts

Co-authored-by: neil <[email protected]>

* Requested use map location change

* Update packages/garbo/src/resources/candyMap.ts

Co-authored-by: neil <[email protected]>

* Update packages/garbo/src/resources/candyMap.ts

Co-authored-by: neil <[email protected]>

* Recommended changes

* misc fixes

* Update packages/garbo/src/resources/candyMap.ts

Co-authored-by: neil <[email protected]>

* Update packages/garbo/src/resources/candyMap.ts

Co-authored-by: neil <[email protected]>

* Fix yarn through yarn up; add limit so bill go mad

* Update packages/garbo/package.json

Co-authored-by: Skaazi <[email protected]>

* Fix yarn.lock

* Update packages/garbo/src/resources/candyMap.ts

Co-authored-by: Skaazi <[email protected]>

* use `skip` limit, not `tries` limit

* freeCandy ==> candyMap

* only use map if acquire succeeds; don't throw on fail

* informative errors

* fix lockfile?

* Update garbo-lib to libram 0.8.14 and remove 0.8.13 cache

* we want things to be profitable, not unprofitable

Co-authored-by: Skaazi <[email protected]>

* Update packages/garbo/src/resources/candyMap.ts

Co-authored-by: Shiverwarp <[email protected]>

---------

Co-authored-by: neil <[email protected]>
Co-authored-by: horrible little slime <[email protected]>
Co-authored-by: Skaazi <[email protected]>
Co-authored-by: Skaazi <[email protected]>
Co-authored-by: Shiverwarp <[email protected]>
  • Loading branch information
6 people authored Oct 24, 2023
1 parent 6481235 commit 96ab039
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 9 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/garbo-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"eslint": "^8.50.0",
"eslint-config-garbo": "^0.0.1",
"kolmafia": "^5.27628.0",
"libram": "^0.8.13",
"libram": "^0.8.14",
"lint-staged": "^14.0.1",
"madge": "^6.1.0",
"prettier": "^3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/garbo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"garbo-lib": "^0.0.1",
"grimoire-kolmafia": "^0.3.23",
"kolmafia": "^5.27628.0",
"libram": "^0.8.13"
"libram": "^0.8.14"
},
"devDependencies": {
"@babel/cli": "^7.22.15",
Expand Down
141 changes: 141 additions & 0 deletions packages/garbo/src/resources/candyMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { Outfit } from "grimoire-kolmafia";
import { $familiar, $item, get, getSaleValue, have, maxBy, sum } from "libram";
import {
canEquip,
getOutfits,
holiday,
mallPrice,
outfitPieces,
outfitTreats,
print,
runChoice,
toItem,
use,
visitUrl,
} from "kolmafia";
import { GarboTask } from "../tasks/engine";
import { garboValue } from "../garboValue";
import { acquire } from "../acquire";
import { GarboStrategy, Macro } from "../combat";

const HOUSE_NUMBERS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];

let blockHtml = "";

function getBlockHtml(): string {
blockHtml ||= visitUrl("place.php?whichplace=town&action=town_trickortreat");
return blockHtml;
}

function treatValue(outfit: string): number {
return sum(
Object.entries(outfitTreats(outfit)),
([candyName, probability]) => probability * garboValue(toItem(candyName)),
);
}

export function getTreatOutfit(): string {
const availableOutfits = getOutfits().filter((name) =>
outfitPieces(name).every((piece) => canEquip(piece)),
);
if (!availableOutfits.length) {
print(
"You don't seem to actually have any trick-or-treating outfits available, my friend!",
);
}
return maxBy(availableOutfits, treatValue);
}

export function treatOutfit(): Outfit {
const outfit = new Outfit();
const bestTreatOutfit = getTreatOutfit();
const pieces = outfitPieces(bestTreatOutfit);
for (const piece of pieces) {
if (!outfit.equip(piece)) {
print(
`Could not equip all pieces of trick-or-treating outfit ${bestTreatOutfit}: aborted on ${piece}`,
);
}
}

outfit.equip($familiar`Trick-or-Treating Tot`);
return outfit;
}

export function candyRichBlockValue(): number {
const outfitCandyValue = treatValue(getTreatOutfit());
const totOutfitCandyMultiplier = have($familiar`Trick-or-Treating Tot`)
? 1.6
: 1;
const bowlValue = (1 / 5) * getSaleValue($item`huge bowl of candy`);
const prunetsValue = have($familiar`Trick-or-Treating Tot`)
? 4 * 0.2 * getSaleValue($item`Prunets`)
: 0;

const outfitCandyTotal = 3 * outfitCandyValue * totOutfitCandyMultiplier;
return outfitCandyTotal + bowlValue + prunetsValue;
}

function shouldAcquireCandyMap(): boolean {
return (
!holiday().includes("Halloween") &&
mallPrice($item`map to a candy-rich block`) < 50000 && // Sanity value to prevent mall shenanigans
candyRichBlockValue() > mallPrice($item`map to a candy-rich block`)
);
}

function useCandyMapTask(): GarboTask {
return {
name: "Acquire Candy Map",
ready: () => shouldAcquireCandyMap(),
completed: () => get("_mapToACandyRichBlockUsed"),
do: (): void => {
if (
acquire(
1,
$item`map to a candy-rich block`,
candyRichBlockValue() - 1,
false,
)
) {
use($item`map to a candy-rich block`);
}
},
limit: { skip: 1 },
spendsTurn: false,
};
}

function doCandyTreat(): GarboTask {
return {
name: "Treat",
completed: () =>
!get("_mapToACandyRichBlockUsed") || holiday().includes("Halloween"),
outfit: treatOutfit,
do: (): void => {
// We do all treat houses in a row as one task for speed reasons
for (const house of HOUSE_NUMBERS) {
if (getBlockHtml().match(RegExp(`whichhouse=${house}>[^>]*?house_l`))) {
visitUrl(
`choice.php?whichchoice=804&option=3&whichhouse=${house}&pwd`,
);
} else if (
getBlockHtml().match(RegExp(`whichhouse=${house}>[^>]*?starhouse`))
) {
visitUrl(
`choice.php?whichchoice=804&option=3&whichhouse=${house}&pwd`,
);
runChoice(2);
visitUrl(`place.php?whichplace=town&action=town_trickortreat`);
}
}
},
limit: { skip: 1 },
spendsTurn: false,
combat: new GarboStrategy(Macro.abort()),
};
}

export function candyMapTasks(): GarboTask[] {
return [useCandyMapTask(), doCandyTreat()];
}
1 change: 1 addition & 0 deletions packages/garbo/src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./scepter";
export * from "./candyMap";
3 changes: 2 additions & 1 deletion packages/garbo/src/tasks/dailyItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { coinmasterPrice } from "../lib";
import { rufusPotion } from "../potions";
import { garboAverageValue, garboValue } from "../garboValue";
import { GarboTask } from "./engine";
import { augustSummonTasks } from "../resources";
import { augustSummonTasks, candyMapTasks } from "../resources";
import { doingGregFight } from "../resources/extrovermectin";

const SummonTomes = $skills`Summon Snowcones, Summon Stickers, Summon Sugar Sheets, Summon Rad Libs, Summon Smithsness`;
Expand Down Expand Up @@ -498,6 +498,7 @@ const DailyItemTasks: GarboTask[] = [
spendsTurn: false,
},
...augustSummonTasks(),
...candyMapTasks(),
];

export const DailyItemsQuest: Quest<GarboTask> = {
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4256,7 +4256,7 @@ __metadata:
eslint: ^8.50.0
eslint-config-garbo: ^0.0.1
kolmafia: ^5.27628.0
libram: ^0.8.13
libram: ^0.8.14
lint-staged: ^14.0.1
madge: ^6.1.0
prettier: ^3.0.3
Expand Down Expand Up @@ -4309,7 +4309,7 @@ __metadata:
garbo-lib: ^0.0.1
grimoire-kolmafia: ^0.3.23
kolmafia: ^5.27628.0
libram: ^0.8.13
libram: ^0.8.14
lint-staged: ^14.0.1
madge: ^6.1.0
prettier: ^3.0.3
Expand Down Expand Up @@ -4917,14 +4917,14 @@ __metadata:
languageName: node
linkType: hard

"libram@npm:^0.8.13":
version: 0.8.13
resolution: "libram@npm:0.8.13"
"libram@npm:^0.8.14":
version: 0.8.14
resolution: "libram@npm:0.8.14"
dependencies:
html-entities: ^2.4.0
peerDependencies:
kolmafia: ^5.26781.0
checksum: 5a323661384fac92549679d21ce68680c9fb5e094f418382347a80e104b9031337d3ea34855b4e68a2a39e704981f919d87ef58bffbe47b8352a2608a755f448
checksum: 342672a9a5f2b798c3493006b79c3cd9224a7cb4425960e218bc09244b7a48b4656b6535093cdbd37e93df88bbc4d6af3edb5395bc3a5fe624ef19714f50810a
languageName: node
linkType: hard

Expand Down

0 comments on commit 96ab039

Please sign in to comment.