Juice sell price
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// the base game's block and item behavior: hoeing, chests, furnaces, crops and the watering can
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { sell_value } from "$/common/inventory.ts";
|
||||
import { CYCLE_TICKS } from "$/common/time.ts";
|
||||
import { display_name, get_state_value } from "$/common/utils.ts";
|
||||
import { container_items, menu_data, menu_items, opened_menu, stone_floor, test_game } from "./helpers.ts";
|
||||
@@ -131,6 +132,32 @@ Deno.test("a shipping bin sells what's in it every morning for as few coins as i
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test("a shipping bin sells a stack for what its data makes it worth, like a bottle by its juice", async () => {
|
||||
const t = await setup();
|
||||
const [fruit] = EverythingRegistry.entries<ItemRegistry>("items")
|
||||
.find(([, item]) => item.components?.["bworld:juiceable"] && item.base_sell_value !== undefined)!;
|
||||
const full = { fluid: { id: "bworld:juice", data: { item: fruit } } };
|
||||
t.send(1, { type: "chat", text: `/give bworld:glass_bottle 3 ${JSON.stringify(full)}` });
|
||||
t.game.set_block(1, 100, 0, "bworld:shipping_bin");
|
||||
const bottles = slot_of(t.take(1), "bworld:glass_bottle");
|
||||
|
||||
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
|
||||
const opened = opened_menu(t.take(1));
|
||||
move_to_menu(t, opened, bottles, 0);
|
||||
t.send(1, { type: "close_menu", menu: opened.id });
|
||||
t.take(1);
|
||||
t.game.set_time((t.game.world.day + 1) * CYCLE_TICKS - 1);
|
||||
t.game.tick();
|
||||
|
||||
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
|
||||
const sold = menu_items(t.take(1)).slice(0, 27).filter((item: Msg) => item);
|
||||
const coin_value = (id: string) => EverythingRegistry.get<ItemRegistry>("items", id)!.base_sell_value!;
|
||||
const paid = sold.reduce((total: number, coin: Msg) => total + coin.count * coin_value(coin.id), 0);
|
||||
const value = sell_value("bworld:glass_bottle", full, t.game.mods.fluid_rules)!;
|
||||
assert(value > 0);
|
||||
assertEquals(paid, 3 * value);
|
||||
});
|
||||
|
||||
Deno.test("a furnace burns fuel to smelt, shows its progress, and only lets the result be taken", async () => {
|
||||
const t = await setup([["bworld:iron_ore", 2], ["bworld:coal", 1]]);
|
||||
t.game.set_block(1, 100, 0, "bworld:furnace");
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// items that hold one fluid, full or empty: how many stack, what they look like, and turning the held one into another
|
||||
// items that hold one fluid, full or empty: how many stack, what they look like, what they sell for, and turning the
|
||||
// held one into another
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { item_tooltip } from "$/client/gui/tooltip.ts";
|
||||
import { item_layers } from "$/client/rendering/item_renderer.ts";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import { ItemStack, sell_value } from "$/common/inventory.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
const JAR = "testjars:jar";
|
||||
const FLASK = "testjars:flask";
|
||||
const FULL = { fluid: { id: "testjars:syrup", data: { tree: "maple" } } };
|
||||
|
||||
// mods/bworld, and testjars: syrup, and a jar of 250 mB that stacks to 16 empty and 4 full, drawn with the syrup in it
|
||||
// and a red label
|
||||
// mods/bworld, and testjars: syrup worth 10 a bucket, a jar of 250 mB that stacks to 16 empty and 4 full, drawn with
|
||||
// the syrup in it and a red label, and a flask of 1000 mB worth 2 on its own
|
||||
async function setup() {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_jars_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
@@ -21,7 +23,10 @@ async function setup() {
|
||||
Deno.writeTextFileSync(`${dir}/testjars/${path}`, JSON.stringify(json));
|
||||
};
|
||||
write("manifest.json", { format_version: 1, id: "testjars", name: "Test Jars", version: "1.0.0" });
|
||||
write("fluids/syrup.json", { format_version: 1, fluid: { id: "testjars:syrup", color: "#a0522d" } });
|
||||
write("fluids/syrup.json", {
|
||||
format_version: 1,
|
||||
fluid: { id: "testjars:syrup", color: "#a0522d", base_sell_value: 10 },
|
||||
});
|
||||
write("items/jar.json", {
|
||||
format_version: 1,
|
||||
item: {
|
||||
@@ -32,6 +37,10 @@ async function setup() {
|
||||
layers: [{ texture: "engine:break_0", tint: "fluid" }, { texture: "engine:break_1", tint: "#ff0000" }],
|
||||
},
|
||||
});
|
||||
write("items/flask.json", {
|
||||
format_version: 1,
|
||||
item: { id: FLASK, texture: "engine:missing", base_sell_value: 2, fluid_container: { capacity: 1000 } },
|
||||
});
|
||||
const t = await test_game(dir);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
t.join(1, "alice");
|
||||
@@ -65,6 +74,17 @@ Deno.test("a layer tinted fluid is drawn in the fluid's color while there's one,
|
||||
assertEquals(jar(FULL), [{ texture: "engine:break_0", color: [0xa0 / 255, 0x52 / 255, 0x2d / 255] }, red]);
|
||||
});
|
||||
|
||||
Deno.test("a full fluid container sells for its own value and its fluid's, rounded up", async () => {
|
||||
const t = await setup();
|
||||
const value = (id: string, data?: unknown) => sell_value(id, data, t.game.mods.fluid_rules);
|
||||
// a jar of syrup is 2.5, and a flask of it is the flask's 2 and the syrup's 10
|
||||
assertEquals([value(JAR), value(JAR, FULL)], [undefined, 3]);
|
||||
assertEquals([value(FLASK), value(FLASK, FULL)], [2, 12]);
|
||||
const jar = new ItemStack(JAR);
|
||||
jar.data = FULL;
|
||||
assertEquals(item_tooltip(jar).map((line) => line.text), ["Jar", "Syrup, 250 mB", "3"]);
|
||||
});
|
||||
|
||||
Deno.test("exchange_held puts the result in the hand from a stack of one, and in the inventory from more", async () => {
|
||||
const t = await setup();
|
||||
t.api.give_item(JAR, 3);
|
||||
|
||||
+23
-1
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user