Siege

Three types work together in a siege: engines, ladders and piles of stones. The server decides what happens to them, including an engine's cycle, crew, ammunition, health and the result of each shot. Players' games draw them and report where a stone landed.

All three types have the same basics: the static spawn, all(dimension?), getById(id) and destroyAll(dimension?), and the instance method destroy().

const { SiegeEngine } = kcds.world;
const { Vector3 } = kcds.math;
const { Events } = kcds.core;

const trebuchet = SiegeEngine.spawn('trebuchet', new Vector3(100, 200, 10));
trebuchet.ammo = 5;
trebuchet.load();

Events.on('siegeEngineReady', (engine) => {
  engine.fire(new Vector3(200, 200, 10));
});

Events.on('siegeImpact', (engine, where, attacker) => {
  console.info(`Stone landed at ${where.x}, ${where.y}`);
});

Engines

SiegeEngine.spawn(kind, position, orientation?, dimension?)

KindRangeCrew places
'trebuchet'25 to 250 m2
'cannon'10 to 200 mnone

Read only: cycle (idle, drawing, loading, ready, firing), loaded, position, rotation, minRange, maxRange, reloadTime, wrecked, crewSeats, crew, operator.

Read and write:

PropertyNotes
speed0.1 to 20
damage
blastRadius0 to 100
usable
rangelimited to what the engine can reach
maxHealthalso sets health
health0 wrecks the engine
ammoa negative number means it never runs out
crewMinimum0 to crewSeats

Methods:

  • load(), fire(target, attacker?) and aim(target) return { accepted, reason, seconds }.
  • inReach(target) returns '' when the target can be hit, otherwise the reason.
  • showAimLine(enabled), aimLine() and repair().
  • assignGunner(player) gives a player the place. null frees it, and it returns false if the player has left.

Events: siegeEngineSpawn, siegeEngineReady, siegeFire(engine, attacker, target), siegeImpact(engine, position, attacker), siegeEngineDamage(engine, amount, attacker), siegeEngineWreck(engine, attacker), siegeEngineDestroy, and siegeEngineUse(player, engine, action). For siegeEngineUse, the action is operate, leave, load or fire, and returning false refuses it.

Ladders

SiegeLadder.spawn(kind, position, orientation?, dimension?)

KindHeight
siege9.75 m
tall5.5 m
short3.25 m
low2 m

SiegeLadder.describe(kind) returns { kind, model, height, lean }, or null for an unknown kind.

Read only: pose (standing, pushed, down, raising, broken), height, climbable, pusher, position, rotation. Read and write: usable.

Methods: push(player) knocks over a standing ladder in 4.5 s and raise(player) puts up a fallen one in 5.7 s. Both return { accepted, reason, seconds }. There are also break() and repair().

Events: siegeLadderSpawn, siegeLadderUse(player, ladder, action) with push or raise, siegeLadderFall(ladder, pusher), siegeLadderRaise(ladder), siegeLadderDestroy.

Stone piles

StonePile.spawn(position, orientation?, dimension?)

Read only: position, rotation.

Read and write:

PropertyAccepted valuesDefault
stonesa negative number becomes -1, an endless pile
usable
damage0 to 100060
blastRadius0 to 101.5

A dropped stone hurts everyone within blastRadius, with full damage at the point of impact and a quarter at the edge.

Events: stonePileSpawn, stonePileThrow(player, pile), stoneImpact(pile, position, player), stonePileDestroy.

Reference: SiegeEngine, SiegeLadder, StonePile.