32 lines
951 B
Plaintext
32 lines
951 B
Plaintext
|
|
// Resource nodes: each node has a finite amount stored in a building variable.
|
||
|
|
|
||
|
|
fn harvest(ctx, tool, resource, item, skill, verb) {
|
||
|
|
if !ctx.has_item(tool, 1) {
|
||
|
|
ctx.message(`You need a ${tool} to ${verb} the ${ctx.target_name()}.`);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
let left = ctx.get_var(resource);
|
||
|
|
// Higher skill levels sometimes yield a bonus.
|
||
|
|
let amount = 1;
|
||
|
|
if ctx.random(10) < ctx.skill_level(skill) {
|
||
|
|
amount = 2;
|
||
|
|
}
|
||
|
|
ctx.give_item(item, amount);
|
||
|
|
ctx.add_xp(skill, 10);
|
||
|
|
ctx.set_var(resource, left - 1);
|
||
|
|
if left - 1 <= 0 {
|
||
|
|
ctx.destroy_target();
|
||
|
|
ctx.message(`The ${ctx.target_name()} is depleted.`);
|
||
|
|
} else {
|
||
|
|
ctx.message(`You ${verb} the ${ctx.target_name()} and get ${amount} ${item}.`);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn chop(ctx) {
|
||
|
|
harvest(ctx, "axe", "wood", "log", "woodcutting", "chop")
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn mine(ctx) {
|
||
|
|
harvest(ctx, "pickaxe", "ore", "iron_ore", "mining", "mine")
|
||
|
|
}
|