Skip to content

Commit 854e597

Browse files
committed
refactor: move lightFire and chance methods into separate files
1 parent 83ca7f4 commit 854e597

File tree

3 files changed

+57
-59
lines changed

3 files changed

+57
-59
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const canLight = (logLevel: number, playerLevel: number): boolean => {
2+
playerLevel++;
3+
const hostRatio = Math.random() * logLevel;
4+
const clientRatio = Math.random() * ((playerLevel - logLevel) * (1 + (logLevel * 0.01)));
5+
return hostRatio < clientRatio;
6+
};
7+
8+
export const canChain = (logLevel: number, playerLevel: number): boolean => {
9+
playerLevel++;
10+
const hostRatio = Math.random() * logLevel;
11+
const clientRatio = Math.random() * ((playerLevel - logLevel) * (1 + (logLevel * 0.01)));
12+
return clientRatio - hostRatio < 3.5;
13+
};

src/plugins/skills/firemaking/index.ts

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,9 @@
11
import { itemOnItemActionHandler } from '@engine/action';
2-
import { Player } from '@engine/world/actor/player/player';
3-
import { WorldItem } from '@engine/world/items/world-item';
4-
import { Position } from '@engine/world/position';
5-
import { randomBetween } from '@engine/util/num';
6-
import { objectIds } from '@engine/world/config/object-ids';
7-
import { itemIds } from '@engine/world/config/item-ids';
8-
import { soundIds } from '@engine/world/config/sound-ids';
9-
import { animationIds } from '@engine/world/config/animation-ids';
10-
import { LandscapeObject } from '@runejs/filestore';
2+
import { itemIds, soundIds, animationIds } from '@engine/world/config';
113
import { loopingEvent } from '@engine/plugins';
124
import { FIREMAKING_LOGS } from './data';
13-
14-
const canLight = (logLevel: number, playerLevel: number): boolean => {
15-
playerLevel++;
16-
const hostRatio = Math.random() * logLevel;
17-
const clientRatio = Math.random() * ((playerLevel - logLevel) * (1 + (logLevel * 0.01)));
18-
return hostRatio < clientRatio;
19-
};
20-
21-
const canChain = (logLevel: number, playerLevel: number): boolean => {
22-
playerLevel++;
23-
const hostRatio = Math.random() * logLevel;
24-
const clientRatio = Math.random() * ((playerLevel - logLevel) * (1 + (logLevel * 0.01)));
25-
return clientRatio - hostRatio < 3.5;
26-
};
27-
28-
const fireDuration = (): number => {
29-
return randomBetween(100, 200); // 1-2 minutes
30-
};
31-
32-
const lightFire = (player: Player, position: Position, worldItemLog: WorldItem, burnExp: number): void => {
33-
player.instance.despawnWorldItem(worldItemLog);
34-
const fireObject: LandscapeObject = {
35-
objectId: objectIds.fire,
36-
x: position.x,
37-
y: position.y,
38-
level: position.level,
39-
type: 10,
40-
orientation: 0
41-
};
42-
43-
player.playAnimation(null);
44-
player.sendMessage(`The fire catches and the logs begin to burn.`);
45-
player.skills.firemaking.addExp(burnExp);
46-
47-
if(!player.walkingQueue.moveIfAble(-1, 0)) {
48-
if(!player.walkingQueue.moveIfAble(1, 0)) {
49-
if(!player.walkingQueue.moveIfAble(0, -1)) {
50-
player.walkingQueue.moveIfAble(0, 1);
51-
}
52-
}
53-
}
54-
55-
player.instance.spawnTemporaryGameObject(fireObject, position, fireDuration()).then(() => {
56-
player.instance.spawnWorldItem({ itemId: itemIds.ashes, amount: 1 }, position, { expires: 300 });
57-
});
58-
59-
player.face(position, false);
60-
player.metadata.lastFire = Date.now();
61-
player.busy = false;
62-
};
5+
import { canChain, canLight } from './chance';
6+
import { lightFire } from './light-fire';
637

648
const action: itemOnItemActionHandler = (details) => {
659
const { player, usedItem, usedWithItem, usedSlot, usedWithSlot } = details;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { randomBetween } from '@engine/util';
2+
import { Position, WorldItem } from '@engine/world';
3+
import { Player } from '@engine/world/actor';
4+
import { objectIds, itemIds } from '@engine/world/config';
5+
import { LandscapeObject } from '@runejs/filestore';
6+
7+
const fireDurationTicks = (): number => {
8+
return randomBetween(100, 200); // 1-2 minutes
9+
};
10+
11+
export const lightFire = (player: Player, position: Position, worldItemLog: WorldItem, burnExp: number): void => {
12+
player.instance.despawnWorldItem(worldItemLog);
13+
const fireObject: LandscapeObject = {
14+
objectId: objectIds.fire,
15+
x: position.x,
16+
y: position.y,
17+
level: position.level,
18+
type: 10,
19+
orientation: 0
20+
};
21+
22+
player.playAnimation(null);
23+
player.sendMessage(`The fire catches and the logs begin to burn.`);
24+
player.skills.firemaking.addExp(burnExp);
25+
26+
if(!player.walkingQueue.moveIfAble(-1, 0)) {
27+
if(!player.walkingQueue.moveIfAble(1, 0)) {
28+
if(!player.walkingQueue.moveIfAble(0, -1)) {
29+
player.walkingQueue.moveIfAble(0, 1);
30+
}
31+
}
32+
}
33+
34+
player.instance.spawnTemporaryGameObject(fireObject, position, fireDurationTicks()).then(() => {
35+
player.instance.spawnWorldItem({ itemId: itemIds.ashes, amount: 1 }, position, { expires: 300 });
36+
});
37+
38+
player.face(position, false);
39+
player.metadata.lastFire = Date.now();
40+
player.metadata.busy = false;
41+
};

0 commit comments

Comments
 (0)