Skip to content

Commit b10682e

Browse files
committed
docs: add more docs to firemaking
docs: top level plugin docs
1 parent 536d8e9 commit b10682e

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

src/plugins/skills/firemaking/chance.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
/**
2+
* Roll a chance to light a fire.
3+
*
4+
* TODO (jameskmonger) this was ported from the old codebase and needs to be documented.
5+
*
6+
* @param logLevel The firemaking level required to light the log.
7+
* @param playerLevel The player's current firemaking level.
8+
* @returns `true` if the player successfully lights the fire, `false` otherwise.
9+
*/
110
export const canLight = (logLevel: number, playerLevel: number): boolean => {
211
playerLevel++;
312
const hostRatio = Math.random() * logLevel;
413
const clientRatio = Math.random() * ((playerLevel - logLevel) * (1 + (logLevel * 0.01)));
514
return hostRatio < clientRatio;
615
};
716

17+
/**
18+
* Roll a chance to 'chain' a fire.
19+
*
20+
* TODO (jameskmonger) this was ported from the old codebase and needs to be documented.
21+
* what is "chain"?
22+
*
23+
* @param logLevel The firemaking level required to light the log.
24+
* @param playerLevel The player's current firemaking level.
25+
* @returns `true` if the player successfully lights the fire, `false` otherwise.
26+
*/
827
export const canChain = (logLevel: number, playerLevel: number): boolean => {
928
playerLevel++;
1029
const hostRatio = Math.random() * logLevel;

src/plugins/skills/firemaking/firemaking-task.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ import { Burnable } from './types';
2424
* @author jameskmonger
2525
*/
2626
class FiremakingTask extends ActorWorldItemInteractionTask<Player> {
27-
private skillInfo: Burnable;
27+
/**
28+
* The log being lit.
29+
*/
30+
private logInfo: Burnable;
31+
32+
/**
33+
* The number of ticks that `execute` has been called inside this task.
34+
*/
2835
private elapsedTicks = 0;
2936
private canLightFire = false;
3037

@@ -40,9 +47,9 @@ class FiremakingTask extends ActorWorldItemInteractionTask<Player> {
4047
) {
4148
super(player, logWorldItem);
4249

43-
this.skillInfo = FIREMAKING_LOGS.find(l => l.logItem.gameId === logWorldItem.itemId);
50+
this.logInfo = FIREMAKING_LOGS.find(l => l.logItem.gameId === logWorldItem.itemId);
4451

45-
if (!this.skillInfo) {
52+
if (!this.logInfo) {
4653
throw new Error(`Invalid firemaking log item id: ${logWorldItem.itemId}`);
4754
}
4855
}
@@ -73,7 +80,7 @@ class FiremakingTask extends ActorWorldItemInteractionTask<Player> {
7380

7481
if (this.canLightFire) {
7582
if (tickCount === 2) {
76-
lightFire(this.actor, this.actor.position, this.worldItem, this.skillInfo.experienceGained);
83+
lightFire(this.actor, this.actor.position, this.worldItem, this.logInfo.experienceGained);
7784
this.stop();
7885
}
7986

@@ -91,7 +98,7 @@ class FiremakingTask extends ActorWorldItemInteractionTask<Player> {
9198
// OSRS wiki implies that there isn't
9299
// https://oldschool.runescape.wiki/w/Firemaking#Success_chance
93100
const passedMinimumThreshold = tickCount > 10;
94-
this.canLightFire = passedMinimumThreshold && canLight(this.skillInfo.requiredLevel, this.actor.skills.firemaking.level);
101+
this.canLightFire = passedMinimumThreshold && canLight(this.logInfo.requiredLevel, this.actor.skills.firemaking.level);
95102

96103
// if we can now light the fire, reset the timer so that on the next tick we can begin lighting the fire
97104
if (this.canLightFire) {
@@ -109,6 +116,12 @@ class FiremakingTask extends ActorWorldItemInteractionTask<Player> {
109116
}
110117
}
111118

119+
/**
120+
* Run the firemaking task for a player.
121+
*
122+
* @param player The player that is attempting to light the fire.
123+
* @param worldItemLog The WorldItem that represents the log.
124+
*/
112125
export function runFiremakingTask(player: Player, worldItemLog: WorldItem) {
113126
player.enqueueTask(FiremakingTask, [ worldItemLog ]);
114127
}

src/plugins/skills/firemaking/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { canChain } from './chance';
55
import { lightFire } from './light-fire';
66
import { runFiremakingTask } from './firemaking-task';
77

8-
const action: itemOnItemActionHandler = (details) => {
8+
/**
9+
* Action hook for lighting a log with a tinderbox in the player's inventory.
10+
*/
11+
const tinderboxOnLogHandler: itemOnItemActionHandler = (details) => {
912
const { player, usedItem, usedWithItem, usedSlot, usedWithSlot } = details;
1013

1114
if(player.metadata.lastFire && Date.now() - player.metadata.lastFire < 600) {
@@ -27,23 +30,30 @@ const action: itemOnItemActionHandler = (details) => {
2730
player.removeItem(removeFromSlot);
2831
const worldItemLog = player.instance.spawnWorldItem(log, player.position, { owner: player, expires: 300 });
2932

33+
// TODO (jameskmonger) chaining functionality needs documentation, I can't find anything about it online
3034
if(player.metadata.lastFire && Date.now() - player.metadata.lastFire < 1200 &&
3135
canChain(skillInfo.requiredLevel, player.skills.firemaking.level)) {
3236
lightFire(player, player.position, worldItemLog, skillInfo.experienceGained);
3337
} else {
34-
player.sendMessage(`You attempt to light the logs.`);
38+
player.sendMessage('You attempt to light the logs.');
3539

3640
runFiremakingTask(player, worldItemLog);
3741
}
3842
};
3943

44+
/**
45+
* Firemaking plugin
46+
*
47+
* TODO:
48+
* - Document/remove `canChain` functionality - this is not documented anywhere online (RS wiki etc)
49+
*/
4050
export default {
4151
pluginId: 'rs:firemaking',
4252
hooks: [
4353
{
4454
type: 'item_on_item',
4555
items: FIREMAKING_LOGS.map(log => ({ item1: itemIds.tinderbox, item2: log.logItem.gameId })),
46-
handler: action
56+
handler: tinderboxOnLogHandler
4757
} as ItemOnItemActionHook,
4858
{
4959
type: 'item_on_world_item',

src/plugins/skills/firemaking/light-fire.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ const fireDurationTicks = (): number => {
88
return randomBetween(100, 200); // 1-2 minutes
99
};
1010

11+
/**
12+
* Light a fire at the specified position.
13+
*
14+
* @param player The player lighting the fire.
15+
* @param position The position to light the fire at.
16+
* @param worldItemLog The world item representing the log.
17+
* @param burnExp The experience gained for lighting the fire.
18+
*/
1119
export const lightFire = (player: Player, position: Position, worldItemLog: WorldItem, burnExp: number): void => {
1220
player.instance.despawnWorldItem(worldItemLog);
1321
const fireObject: LandscapeObject = {
@@ -20,7 +28,7 @@ export const lightFire = (player: Player, position: Position, worldItemLog: Worl
2028
};
2129

2230
player.playAnimation(null);
23-
player.sendMessage(`The fire catches and the logs begin to burn.`);
31+
player.sendMessage('The fire catches and the logs begin to burn.');
2432
player.skills.firemaking.addExp(burnExp);
2533

2634
if(!player.walkingQueue.moveIfAble(-1, 0)) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import { ItemDetails } from '@engine/config';
22

3+
/**
4+
* The definition for a burnable log.
5+
*/
36
export type Burnable = {
7+
/**
8+
* The item details for the log.
9+
*/
410
logItem: ItemDetails;
11+
12+
/**
13+
* The firemaking level required to light the log.
14+
*/
515
requiredLevel: number;
16+
17+
/**
18+
* The experience gained for lighting the log.
19+
*/
620
experienceGained: number;
721
}

0 commit comments

Comments
 (0)