Skip to content

Commit 8f90e20

Browse files
gruckionJameskmonger
authored andcommitted
refactor: Refactor old plugin move files, prep for tick based tasks
1 parent 169bcfa commit 8f90e20

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { randomBetween } from '@engine/util';
2+
import { IHarvestable } from '@engine/world/config';
3+
4+
export const canCut = (
5+
tree: IHarvestable,
6+
toolLevel: number,
7+
woodcuttingLevel: number
8+
): boolean => {
9+
const successChance = randomBetween(0, 255);
10+
11+
const percentNeeded =
12+
tree.baseChance + toolLevel + woodcuttingLevel;
13+
return successChance <= percentNeeded;
14+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
ObjectInteractionActionHook,
3+
} from '@engine/action';
4+
import { getTreeIds } from '@engine/world/config/harvestable-object';
5+
import { activate, canActivate, onComplete } from './woodcutting-task';
6+
7+
8+
export default {
9+
pluginId: 'rs:woodcutting',
10+
hooks: [
11+
{
12+
type: 'object_interaction',
13+
options: [ 'chop down', 'chop' ],
14+
objectIds: getTreeIds(),
15+
strength: 'normal',
16+
task: {
17+
canActivate,
18+
activate,
19+
onComplete,
20+
interval: 1
21+
}
22+
} as ObjectInteractionActionHook
23+
]
24+
};

src/plugins/skills/woodcutting/woodcutting.plugin.ts renamed to src/plugins/skills/woodcutting/woodcutting-task.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
12
import {
23
ObjectInteractionAction,
3-
ObjectInteractionActionHook,
44
TaskExecutor
55
} from '@engine/action';
66
import { Skill } from '@engine/world/actor/skills';
@@ -14,9 +14,9 @@ import { soundIds } from '@engine/world/config/sound-ids';
1414
import { Axe, getAxe, HarvestTool } from '@engine/world/config/harvest-tool';
1515
import { findItem } from '@engine/config/config-handler';
1616
import { activeWorld } from '@engine/world';
17+
import { canCut } from './chance';
1718

18-
19-
const canActivate = (task: TaskExecutor<ObjectInteractionAction>, taskIteration: number): boolean => {
19+
export const canActivate = (task: TaskExecutor<ObjectInteractionAction>, taskIteration: number): boolean => {
2020
const { actor, actionData: { position, object, player } } = task;
2121
const tree = getTreeFromHealthy(object.objectId);
2222

@@ -48,7 +48,7 @@ const canActivate = (task: TaskExecutor<ObjectInteractionAction>, taskIteration:
4848
};
4949

5050

51-
const activate = (task: TaskExecutor<ObjectInteractionAction>, taskIteration: number): boolean => {
51+
export const activate = (task: TaskExecutor<ObjectInteractionAction>, taskIteration: number): boolean => {
5252
const { actor, player, actionData, session } = task.getDetails();
5353
const { position: objectPosition, object: actionObject } = actionData;
5454
const tree: IHarvestable = session.tree;
@@ -77,7 +77,8 @@ const activate = (task: TaskExecutor<ObjectInteractionAction>, taskIteration: nu
7777
}
7878

7979
const percentNeeded = tree.baseChance + toolLevel + actor.skills.woodcutting.level;
80-
if(successChance <= percentNeeded) {
80+
const succeeds = canCut(tree, toolLevel, actor.skills.woodcutting.level);
81+
if(succeeds) {
8182
const targetName: string = findItem(tree.itemId).name.toLowerCase();
8283

8384
if(actor.inventory.hasSpace()) {
@@ -122,25 +123,6 @@ const activate = (task: TaskExecutor<ObjectInteractionAction>, taskIteration: nu
122123
return true;
123124
};
124125

125-
const onComplete = (task: TaskExecutor<ObjectInteractionAction>): void => {
126+
export const onComplete = (task: TaskExecutor<ObjectInteractionAction>): void => {
126127
task.actor.stopAnimation();
127128
};
128-
129-
130-
export default {
131-
pluginId: 'rs:woodcutting',
132-
hooks: [
133-
{
134-
type: 'object_interaction',
135-
options: [ 'chop down', 'chop' ],
136-
objectIds: getTreeIds(),
137-
strength: 'normal',
138-
task: {
139-
canActivate,
140-
activate,
141-
onComplete,
142-
interval: 1
143-
}
144-
} as ObjectInteractionActionHook
145-
]
146-
};

0 commit comments

Comments
 (0)