|
1 | 1 | 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'; |
11 | 3 | import { loopingEvent } from '@engine/plugins'; |
12 | 4 | 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'; |
63 | 7 |
|
64 | 8 | const action: itemOnItemActionHandler = (details) => { |
65 | 9 | const { player, usedItem, usedWithItem, usedSlot, usedWithSlot } = details; |
|
0 commit comments