Sell value for wine

This commit is contained in:
2026-10-31 19:55:15 -03:00
parent b08de6bf81
commit facbbb07da
2 changed files with 32 additions and 10 deletions
+17 -9
View File
@@ -157,10 +157,13 @@ export const JUICER_PRESSES = 4;
// what juice sells for, as a multiple of what the items pressed to make it sell for
export const JUICE_VALUE = 1.2;
// what wine sells for, as a multiple of what the juice it's fermented from sells for, mB for mB
export const WINE_VALUE = 2;
// juice is one fluid for every fruit, like create's potion fluid: which fruit sits in its data, { item }. it's named
// after that item, "Strawberry Juice", in the color its bworld:juiceable says, and sells for JUICE_VALUE times the
// items it took. wine is too, fermented from the juice (see fermenting.ts), keeping its fruit: "Strawberry Wine"
// items it took. wine is too, fermented from the juice (see fermenting.ts), keeping its fruit: "Strawberry Wine", and
// sells for WINE_VALUE times that juice
function register_juice_and_wine(ctx: SharedContext) {
const item_of = (data: unknown) => {
const item = (data as { item?: unknown } | undefined)?.item;
@@ -177,15 +180,20 @@ function register_juice_and_wine(ctx: SharedContext) {
return item && juiceable(item)?.color;
},
});
ctx.fluids.register("bworld:wine", from_fruit("Wine"));
ctx.fluids.register("bworld:juice", {
...from_fruit("Juice"),
// what 1000 mB of the fruit's juice sells for
const juice_value = (data: unknown) => {
const item = item_of(data);
if (!item) return undefined;
const juice = juiceable(item)?.juice;
const value = ctx.items.sell_value(item);
return juice && value !== undefined ? JUICE_VALUE * value * 1000 / juice : undefined;
};
ctx.fluids.register("bworld:juice", { ...from_fruit("Juice"), sell_value: juice_value });
ctx.fluids.register("bworld:wine", {
...from_fruit("Wine"),
sell_value(data) {
const item = item_of(data);
if (!item) return undefined;
const juice = juiceable(item)?.juice;
const value = ctx.items.sell_value(item);
return juice && value !== undefined ? JUICE_VALUE * value * 1000 / juice : undefined;
const value = juice_value(data);
return value === undefined ? undefined : WINE_VALUE * value;
},
});
}
+15 -1
View File
@@ -13,7 +13,7 @@ import { block_visuals, Visuals } from "$/client/rendering/visuals.ts";
import { AssetManager } from "$/client/assets.ts";
import { fluid_rules, set_fluid_rules } from "$/client/fluid_rules.ts";
import { setup as setup_client } from "$/mods/bworld/scripts/client.ts";
import { JUICE_VALUE, type JuiceableParams } from "$/mods/bworld/scripts/shared.ts";
import { JUICE_VALUE, type JuiceableParams, WINE_VALUE } from "$/mods/bworld/scripts/shared.ts";
import type { FermentableRecipe } from "$/mods/bworld/scripts/fermenting.ts";
import { copy_dir, stone_floor, test_game } from "./helpers.ts";
@@ -246,6 +246,20 @@ Deno.test("every juice ferments into wine from the same fruit, named after it in
}
});
Deno.test("wine sells for WINE_VALUE times the juice from the same fruit, and not at all when that juice can't be sold", async () => {
const { game } = await setup();
const rules = game.mods.fluid_rules;
const sellable = EverythingRegistry.entries<ItemRegistry>("items")
.filter(([, item]) => item.components?.["bworld:juiceable"] && item.base_sell_value !== undefined);
assert(sellable.length > 0);
for (const [id] of sellable) {
const juice = rules.sell_value({ id: "bworld:juice", data: { item: id } })!;
assertEquals(rules.sell_value({ id: "bworld:wine", data: { item: id } }), WINE_VALUE * juice);
}
// the cloudberry can't be sold, so neither can its juice or wine
assertEquals(rules.sell_value({ id: "bworld:wine", data: { item: CLOUDBERRY } }), undefined);
});
Deno.test("a broken bworld:fermentable recipe stops the server from starting", async () => {
const juice = { fluid: { id: "bworld:juice" }, amount: 100 };
for (