Make tool upgrades cost money
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:cobalt_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:cobalt_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:cobalt_axe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:cobalt_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:cobalt_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:cobalt_hoe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:cobalt_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:cobalt_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:cobalt_knife"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:cobalt_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:cobalt_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:cobalt_pickaxe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:cobalt_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:cobalt_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:cobalt_shovel"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:cobalt_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:cobalt_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:cobalt_watering_can"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:copper_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 5
|
||||
},
|
||||
"result": "bworld:copper_axe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:copper_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 5
|
||||
},
|
||||
"result": "bworld:copper_hoe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:copper_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 5
|
||||
},
|
||||
"result": "bworld:copper_knife"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:copper_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 5
|
||||
},
|
||||
"result": "bworld:copper_pickaxe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:copper_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 5
|
||||
},
|
||||
"result": "bworld:copper_shovel"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:copper_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 5
|
||||
},
|
||||
"result": "bworld:copper_watering_can"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:gold_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:gold_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:gold_axe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:gold_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:gold_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:gold_hoe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:gold_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:gold_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:gold_knife"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:gold_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:gold_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:gold_pickaxe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:gold_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:gold_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:gold_shovel"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:gold_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:gold_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:gold_watering_can"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:iron_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:iron_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:iron_axe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:iron_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:iron_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:iron_hoe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:iron_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:iron_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:iron_knife"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:iron_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:iron_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:iron_pickaxe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:iron_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:iron_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:iron_shovel"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:iron_ingot",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:iron_coin",
|
||||
"count": 2
|
||||
},
|
||||
"result": "bworld:iron_watering_can"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:stone",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:stone_axe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:stone",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:stone_hoe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:stone",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:stone_knife"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:stone",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:stone_pickaxe"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:stone",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:stone_shovel"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"id": "bworld:stone",
|
||||
"count": 5
|
||||
},
|
||||
"addition": {
|
||||
"id": "bworld:brass_coin",
|
||||
"count": 1
|
||||
},
|
||||
"result": "bworld:stone_watering_can"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ function register_furnace(ctx: ServerContext) {
|
||||
});
|
||||
}
|
||||
|
||||
// smithing table: a tool, some of a material and maybe a third item make a better tool, see smithing.ts.
|
||||
// smithing table: a tool, some of a material and maybe some of a third item make a better tool, see smithing.ts.
|
||||
// every player gets their own slots, and what's left in them goes back to the player when they close it
|
||||
|
||||
const TOOL = 0;
|
||||
@@ -439,7 +439,14 @@ function register_smithing_table(ctx: ServerContext) {
|
||||
const addition = container.get(ADDITION);
|
||||
if (!tool || !material) return undefined;
|
||||
const recipe = ctx.recipes.find<SmithingRecipe>(SMITHING, { tool, material, addition });
|
||||
return recipe && { result: recipe.result, material_count: recipe.material.count, tool, material, addition };
|
||||
return recipe && {
|
||||
result: recipe.result,
|
||||
material_count: recipe.material.count,
|
||||
addition_count: recipe.addition?.count ?? 0,
|
||||
tool,
|
||||
material,
|
||||
addition,
|
||||
};
|
||||
};
|
||||
|
||||
// the result slot shows what taking it would give, the upgraded tool keeps the old one's data
|
||||
@@ -470,7 +477,7 @@ function register_smithing_table(ctx: ServerContext) {
|
||||
if (!recipe || recipe.result !== item.id) return false;
|
||||
recipe.tool.count -= 1;
|
||||
recipe.material.count -= recipe.material_count;
|
||||
if (recipe.addition) recipe.addition.count -= 1;
|
||||
if (recipe.addition) recipe.addition.count -= recipe.addition_count;
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// smithing recipes: the smithing table upgrades a tool with some of a material and maybe one more item. the type is
|
||||
// registered by the shared script, so the server's menu and anything on a client find them the same way
|
||||
// smithing recipes: the smithing table upgrades a tool with some of a material and maybe some of one more item. the
|
||||
// type is registered by the shared script, so the server's menu and anything on a client find them the same way
|
||||
import type { ItemStack, SharedContext } from "bworld/shared";
|
||||
|
||||
export const SMITHING = "bworld:smithing";
|
||||
@@ -10,7 +10,7 @@ export const SMITHING = "bworld:smithing";
|
||||
export interface SmithingRecipe {
|
||||
tool: string;
|
||||
material: { id: string; count: number };
|
||||
addition?: string;
|
||||
addition?: { id: string; count: number };
|
||||
result: string;
|
||||
}
|
||||
|
||||
@@ -31,15 +31,16 @@ export function register_smithing(ctx: SharedContext) {
|
||||
material: read.stack(json.material, "material"),
|
||||
result: read.item(json.result, "result"),
|
||||
};
|
||||
if (json.addition !== undefined) recipe.addition = read.item(json.addition, "addition");
|
||||
const inputs = `${recipe.tool} ${recipe.material.id} ${recipe.addition}`;
|
||||
if (json.addition !== undefined) recipe.addition = read.stack(json.addition, "addition");
|
||||
const inputs = `${recipe.tool} ${recipe.material.id} ${recipe.addition?.id}`;
|
||||
if (seen.has(inputs)) throw new Error(`there's already one for ${recipe.tool} with ${recipe.material.id}`);
|
||||
seen.add(inputs);
|
||||
return recipe;
|
||||
},
|
||||
// with enough of the material
|
||||
// with enough of the material and the addition
|
||||
matches: (recipe, input) =>
|
||||
recipe.tool === input.tool.id && recipe.material.id === input.material.id &&
|
||||
input.material.count >= recipe.material.count && recipe.addition === input.addition?.id,
|
||||
input.material.count >= recipe.material.count && recipe.addition?.id === input.addition?.id &&
|
||||
(input.addition?.count ?? 0) >= (recipe.addition?.count ?? 0),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ function base_categories(tags: TagApi): RecipeCategory[] {
|
||||
draw(recipe, layout) {
|
||||
layout.slot({ ids: [recipe.tool], count: 1 }, 0, 0);
|
||||
layout.slot(stack(recipe.material), SLOT, 0);
|
||||
layout.slot(recipe.addition ? { ids: [recipe.addition], count: 1 } : undefined, SLOT * 2, 0);
|
||||
layout.slot(recipe.addition && stack(recipe.addition), SLOT * 2, 0);
|
||||
layout.texture("bworld:arrow_full", 61, 1, ARROW, ARROW);
|
||||
layout.slot({ ids: [recipe.result], count: 1 }, 90, 0);
|
||||
},
|
||||
|
||||
@@ -60,7 +60,7 @@ export function inputs(recipe: Recipe, tags: TagApi): Ingredient[] {
|
||||
return [{ ids: tags.expand(recipe.item), count: 1 }];
|
||||
case "bworld:smithing":
|
||||
return [{ ids: [recipe.tool], count: 1 }, stack(recipe.material)].concat(
|
||||
recipe.addition ? [{ ids: [recipe.addition], count: 1 }] : [],
|
||||
recipe.addition ? [stack(recipe.addition)] : [],
|
||||
);
|
||||
default: {
|
||||
const { grid, extras } = mod_recipe_inputs(recipe, tags);
|
||||
|
||||
Reference in New Issue
Block a user