32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
// what the base game's effects do over time, see mods/bworld/effects. speed and slowness are only attribute
|
|
// modifiers, and resistance and water breathing work where damage and air happen, like minecraft's
|
|
import type { ServerContext } from "bworld/server";
|
|
|
|
// every n ticks, n halving with each level: minecraft's regeneration and poison
|
|
function every(ticks: number, amplifier: number, n: number) {
|
|
const interval = n >> amplifier;
|
|
return interval > 0 ? ticks % interval === 0 : true;
|
|
}
|
|
|
|
export function register_effects(ctx: ServerContext) {
|
|
ctx.components.register_effect<{ every: number }>("bworld:heal_over_time", {
|
|
should_tick: (ticks, amplifier, params) => every(ticks, amplifier, params.every),
|
|
on_tick(entity) {
|
|
if (entity.health < entity.max_health) entity.heal(1);
|
|
},
|
|
});
|
|
ctx.components.register_effect<{ every: number }>("bworld:poison", {
|
|
should_tick: (ticks, amplifier, params) => every(ticks, amplifier, params.every),
|
|
on_tick(entity) {
|
|
// never kills
|
|
if (entity.health > 1) entity.damage(1, "magic");
|
|
},
|
|
});
|
|
// instant: amount for level 1, doubling with each level
|
|
ctx.components.register_effect<{ amount: number }>("bworld:heal", {
|
|
on_tick(entity, amplifier, params) {
|
|
entity.heal(Math.max(params.amount << amplifier, 0));
|
|
},
|
|
});
|
|
}
|