Juice sell price

This commit is contained in:
2026-10-26 19:32:46 -03:00
parent e729b92d20
commit e5221ba681
17 changed files with 182 additions and 47 deletions
+23 -1
View File
@@ -1,17 +1,19 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// juice: one fluid named and colored after the bworld:juiceable item in its data, and the juicer that makes it
// juice: one fluid named, colored and valued after the bworld:juiceable item in its data, and the juicer that makes it
import { assert, assertEquals } from "@std/assert";
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import type { FluidJson } from "$/common/mod_data.ts";
import type { ClientContext, Instances, Visual, VisualBlock } from "$/common/mod_api/client.ts";
import { CHUNK_AREA, CHUNK_SIZE } from "$/common/constants.ts";
import { block_value, display_name } from "$/common/utils.ts";
import { sell_value } from "$/common/inventory.ts";
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 { copy_dir, stone_floor, test_game } from "./helpers.ts";
const CLOUDBERRY = "testberries:cloudberry";
@@ -63,6 +65,26 @@ Deno.test("juice made from any item with bworld:juiceable is named after it, in
]);
});
Deno.test("juice in any container sells for JUICE_VALUE times the items it took, rounded up", async () => {
const { game } = await setup();
const sellable = EverythingRegistry.entries<ItemRegistry>("items")
.filter(([, item]) => item.components?.["bworld:juiceable"] && item.base_sell_value !== undefined);
const containers = EverythingRegistry.entries<ItemRegistry>("items").filter(([, item]) => item.fluid_container);
assert(sellable.length > 0 && containers.length > 0);
for (const [id, item] of sellable) {
const { juice } = item.components!["bworld:juiceable"] as JuiceableParams;
for (const [container, info] of containers) {
const full = { fluid: { id: "bworld:juice", data: { item: id } } };
const value = sell_value(container, full, game.mods.fluid_rules)! - (info.base_sell_value ?? 0);
const exact = JUICE_VALUE * item.base_sell_value! * info.fluid_container!.capacity / juice;
assert(Number.isInteger(value) && value >= exact - 1e-9 && value < exact + 1, `${container} of ${id}`);
}
}
// juice from what can't be sold, the cloudberry, can't be sold either
assertEquals(game.mods.fluid_rules.sell_value({ id: "bworld:juice", data: { item: CLOUDBERRY } }), undefined);
});
Deno.test("the juicer takes juiceable items, juices one every 4 presses, and fills empty containers from it", async () => {
const t = await setup();
t.join(1, "alice");