Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/light-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Tests: `server/tests/light-sources.test.cjs`.
- **Candle lantern, Extinguish** (lit white 4531 -> unlit 4529): "You extinguish the lantern." as
a spam line, the item changes in its slot (1000134 ticks 365, 575, 599; 1000135; 1000140).
The black one (4534 -> 4532) was not captured and is put out the same way.
- **Candle lantern, light** (tinderbox on unlit white 4529 -> lit 4531): "You light the lantern."
as a spam line and synth 3226 on the click tick, no sequence (1000134 ticks 438, 585, 780, 1144;
1000135 tick 221; 1000140 tick 763). The black one (4532 -> 4534) was not captured and is lit the
same way.
- **Last light, Extinguish:** with nothing else lit in the caves, the item stays lit and a game
message says why:
- candle lantern: "Extinguishing the lantern would leave you without a light source."
Expand All @@ -23,6 +27,7 @@ Tests: `server/tests/light-sources.test.cjs`.

## Ours

- The black candle lantern's lighting line and sound are the white one's (not captured).
- The lit emerald lantern (9065 -> 9064) is put out with the candle lantern's lines ("You
extinguish the lantern." spam, and its refusal as the last light): its own were not captured.
- The oil, bullseye and sapphire lanterns use the candle lantern's refusal line; they share its
Expand Down
18 changes: 13 additions & 5 deletions server/plugins/items/LightSources.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
* wording, not Wiki text or recorded dialogue.
*
* Captured (rsprox 70 tick 1626, 75 tick 11666): lighting a torch says "You light your torch." and plays
* no sequence and no sound. Nothing else was captured, so no other item gets a message or an animation, and
* the level refusal reuses OilLights' wording. The lit item replaces the unlit one in its slot (setId), so a
* no sequence and no sound. The white candle lantern says "You light the lantern." as a spam (filterable)
* line and plays synth 3226, with no sequence (rsprox local 1000134, 1000135, 1000140: 6 of 6 lightings);
* the black candle lantern does the same (Ours, as its Extinguish). Nothing else was captured, so no other
* item gets a message, sound or animation, and the level refusal reuses OilLights' wording. The lit item replaces the unlit one in its slot (setId), so a
* preset, untradeable or unbankable copy stays one, and the current level counts, so a boost lights what it
* should (Wiki).
*
Expand All @@ -37,15 +39,19 @@ const { isCooker } = require("../skills/Cooking.plugin");
const Darkness = require("../world/Darkness.plugin");

let core;
/** Unlit item id -> { lit, level, message? }. */
/** Synth played when a lantern is lit (the oil, bullseye and sapphire lanterns in OilLights use it too). */
const LANTERN_LIGHT_SOUND = 3226;
/** Unlit item id -> { lit, level, message?, spam?, sound? }. */
let lights;

function build(I) {
return new Map([
[I.UNLIT_TORCH, { lit: I.LIT_TORCH, level: 1, message: "You light your torch." }],
[I.CANDLE, { lit: I.LIT_CANDLE, level: 1 }],
[I.CANDLE_LANTERN, { lit: I.CANDLE_LANTERN_3, level: 4 }], // white
[I.CANDLE_LANTERN_4, { lit: I.CANDLE_LANTERN_6, level: 4 }], // black
// White: the spam line and synth 3226 on the click tick (rsprox local 1000134 t438/t585/t780/t1144,
// 1000135 t221, 1000140 t763). Ours: the black one (not captured) is lit the same way, as it is put out.
[I.CANDLE_LANTERN, { lit: I.CANDLE_LANTERN_3, level: 4, spam: "You light the lantern.", sound: LANTERN_LIGHT_SOUND }],
[I.CANDLE_LANTERN_4, { lit: I.CANDLE_LANTERN_6, level: 4, spam: "You light the lantern.", sound: LANTERN_LIGHT_SOUND }],
[I.UNLIT_BUG_LANTERN, { lit: I.LIT_BUG_LANTERN, level: 33 }],
[I.EMERALD_LANTERN, { lit: I.EMERALD_LANTERN_2, level: 49 }],
]);
Expand Down Expand Up @@ -99,6 +105,8 @@ function applyLight(player, item, source) {
item.setId(source.lit);
player.getInventory().refreshItems();
if (source.message) player.sendMessage(source.message);
if (source.spam) player.getPacketSender().sendTypedMessage(core.ChatType.SPAM, source.spam);
if (source.sound) player.getPacketSender().sendSound(source.sound, 100, 0);
// `light-sources:lit` { player, itemId }: the lit item, on its tick (the league's "Light a Torch",
// rsprox 237/1098 tick 16024, the tick the tinderbox was used).
core.PluginManager?.emitCustomEvent?.("light-sources:lit", { player, itemId: source.lit });
Expand Down
34 changes: 34 additions & 0 deletions server/tests/light-sources.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,40 @@ test("as captured (rsprox 70, 75): the torch says 'You light your torch.' and pl
assert.deepEqual(f.animations, [], "no sequence in the capture");
});

// rsprox local 1000134 t438/t585/t780/t1144, 1000135 t221, 1000140 t763 (rev 226): tinderbox on the unlit
// white candle lantern (4529) -> slot becomes 4531, spam "You light the lantern." and synth 3226, same tick.
test("as captured: a candle lantern says 'You light the lantern.' as spam and plays synth 3226", async (t) => {
// White as captured; black (not captured) is lit the same way.
for (const [unlit, lit] of [[I.CANDLE_LANTERN, I.CANDLE_LANTERN_3], [I.CANDLE_LANTERN_4, I.CANDLE_LANTERN_6]]) {
const f = actor(t, 4);
const typed = [];
const sounds = [];
const sender = f.p.getPacketSender();
t.mock.method(sender, "sendTypedMessage", (type, message) => { typed.push([type, message]); return sender; });
t.mock.method(sender, "sendSound", (id) => { sounds.push(id); return sender; });
f.inv.setItem(0, item(unlit));
f.inv.setItem(1, item(I.TINDERBOX));
await useOn(f, 1, 0);
assert.deepEqual(carried(f), [lit, I.TINDERBOX]);
assert.deepEqual(typed, [[core.ChatType.SPAM, "You light the lantern."]]);
assert.deepEqual(sounds, [3226]);
assert.deepEqual(f.animations, [], "no sequence in the capture");
}

// Below 4 Firemaking it stays unlit: no line, no sound.
const low = actor(t, 3);
const lowTyped = [];
const lowSounds = [];
const lowSender = low.p.getPacketSender();
t.mock.method(lowSender, "sendTypedMessage", (type, message) => { lowTyped.push(message); return lowSender; });
t.mock.method(lowSender, "sendSound", (id) => { lowSounds.push(id); return lowSender; });
low.inv.setItem(0, item(I.CANDLE_LANTERN));
low.inv.setItem(1, item(I.TINDERBOX));
await useOn(low, 1, 0);
assert.deepEqual(carried(low), [I.CANDLE_LANTERN, I.TINDERBOX]);
assert.deepEqual([lowTyped, lowSounds], [[], []]);
});

test("the other new lights play no animation either (none captured, none invented)", async (t) => {
for (const [label, unlit, , level] of LIGHTS.slice(1)) {
const f = actor(t, level);
Expand Down
Loading