Skip to content

Commit eab8d0c

Browse files
committed
refactor: create types for remaining metadata properties
1 parent 99eb1b2 commit eab8d0c

File tree

6 files changed

+118
-22
lines changed

6 files changed

+118
-22
lines changed

src/engine/world/actor/actor.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ export abstract class Actor {
119119
// https://oldschool.runescape.wiki/w/Combat_level#:~:text=Calculating%20combat%20level,-Simply&text=Add%20your%20Strength%20and%20Attack,have%20your%20melee%20combat%20level.&text=Multiply%20this%20by%200.325%20and,have%20your%20magic%20combat%20level
120120
// https://oldschool.runescape.wiki/w/Damage_per_second/Melee#:~:text=1%20Step%20one%3A%20Calculate%20the%20effective%20strength%20level%3B,1.7%20Step%20seven%3A%20Calculate%20the%20melee%20damage%20output
121121
public getAttackRoll(defender): Attack {
122-
122+
123123
//the amount of damage is random from 0 to Max
124124
//stance modifiers
125125
const _stance_defense = 3;
126126
const _stance_accurate = 0;
127127
const _stance_controlled = 1;
128-
128+
129129
// base level
130130
// ToDo: calculate prayer effects
131131
// round decimal result calulcation up
@@ -141,7 +141,7 @@ export abstract class Actor {
141141
142142
Effective strength level
143143
Multiply by(Equipment Melee Strength + 64)
144-
Add 320
144+
Add 320
145145
Divide by 640
146146
Round down to nearest integer
147147
Multiply by gear bonus
@@ -221,7 +221,7 @@ export abstract class Actor {
221221
return attack;
222222
//+ stance modifier
223223
}
224-
// #endregion
224+
// #endregion
225225

226226
public damage(amount: number, damageType: DamageType = DamageType.DAMAGE) {
227227
const armorReduction = 0;
@@ -357,7 +357,7 @@ export abstract class Actor {
357357

358358
public follow(target: Actor): void {
359359
this.face(target, false, false, false);
360-
this.metadata['following'] = target;
360+
this.metadata.following = target;
361361

362362
this.moveBehind(target);
363363
const subscription = target.walkingQueue.movementEvent.subscribe(() => {
@@ -372,7 +372,7 @@ export abstract class Actor {
372372
).subscribe(() => {
373373
subscription.unsubscribe();
374374
this.face(null);
375-
delete this.metadata['following'];
375+
delete this.metadata.following;
376376
});
377377
}
378378

@@ -386,7 +386,7 @@ export abstract class Actor {
386386
if(distance <= 1) {
387387
return false;
388388
}
389-
389+
390390
if(distance > 16) {
391391
this.clearFaceActor();
392392
this.metadata.faceActorClearedByWalking = true;
@@ -408,7 +408,7 @@ export abstract class Actor {
408408
return;
409409
}
410410

411-
this.metadata['tailing'] = target;
411+
this.metadata.tailing = target;
412412

413413
this.moveTo(target);
414414
const subscription = target.walkingQueue.movementEvent.subscribe(async () => this.moveTo(target));
@@ -419,7 +419,7 @@ export abstract class Actor {
419419
).subscribe(() => {
420420
subscription.unsubscribe();
421421
this.face(null);
422-
delete this.metadata['tailing'];
422+
delete this.metadata.tailing;
423423
});
424424
}
425425

@@ -434,8 +434,8 @@ export abstract class Actor {
434434
this.updateFlags.facePosition = face;
435435
} else if(face instanceof Actor) {
436436
this.updateFlags.faceActor = face;
437-
this.metadata['faceActor'] = face;
438-
this.metadata['faceActorClearedByWalking'] = clearedByWalking;
437+
this.metadata.faceActor = face;
438+
this.metadata.faceActorClearedByWalking = clearedByWalking;
439439

440440
if(autoClear) {
441441
setTimeout(() => {
@@ -451,9 +451,9 @@ export abstract class Actor {
451451
}
452452

453453
public clearFaceActor(): void {
454-
if(this.metadata['faceActor']) {
454+
if(this.metadata.faceActor) {
455455
this.updateFlags.faceActor = null;
456-
this.metadata['faceActor'] = undefined;
456+
this.metadata.faceActor = undefined;
457457
}
458458
}
459459

src/engine/world/actor/metadata.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { ConstructedRegion } from '../map';
2+
import { Position } from '../position';
3+
import { Actor } from './actor';
24

35
/**
46
* The definition of the metadata available on an {@link Actor}.
@@ -12,10 +14,41 @@ export type ActorMetadata = {
1214
/**
1315
* The custom constructed map region for this actor.
1416
*
15-
* TODO Should this live on Actor rather than on {@link Player}? I don't think NPCs can have a custom map.
17+
* TODO (jameskmonger) Should this live on Actor rather than on {@link Player}? I don't think NPCs can have a custom map.
1618
*/
1719
customMap: ConstructedRegion;
1820

21+
/**
22+
* The player's current target position.
23+
*
24+
* Used within the action pipeline.
25+
*/
26+
walkingTo: Position;
27+
28+
/**
29+
* The actor currently being `tailed` by this actor.
30+
*
31+
* TODO (jameskmonger) we should delete this - only used by deleted code in the old combat plugin
32+
*/
33+
tailing: Actor;
34+
35+
/**
36+
* The actor currently being followed by this actor.
37+
*/
38+
following: Actor;
39+
40+
/**
41+
* The actor which the local actor is facing towards.
42+
*/
43+
faceActor: Actor;
44+
45+
/**
46+
* Whether a walk action has cleared the actor which the local actor is facing towards.
47+
*
48+
* TODO (jameskmonger) does this belong on this metadata?
49+
*/
50+
faceActorClearedByWalking: boolean;
51+
1952
/**
2053
* Set to true if the actor is currently teleporting.
2154
*/

src/engine/world/actor/player/metadata.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Subscription } from 'rxjs';
1+
import { Subject, Subscription } from 'rxjs';
22
import { Chunk } from '@engine/world/map';
33
import { Position } from '@engine/world/position';
4+
import { LandscapeObject } from '@runejs/filestore';
45

56
/**
67
* The definition of the metadata directly available on a {@link Player}.
@@ -31,6 +32,15 @@ export type PlayerMetadata = {
3132
*/
3233
lastPosition: Position;
3334

35+
/**
36+
* Used to prevent the `object_interaction` pipe from running.
37+
*
38+
* TODO (jameskmonger) We should probably deprecate this, it seems like it's already been
39+
* replaced by the `busy` property which is itself deprecated. This is only
40+
* used in Goblin Diplomacy.
41+
*/
42+
blockObjectInteractions: boolean;
43+
3444
/**
3545
* The player's currently open shop.
3646
*
@@ -44,4 +54,57 @@ export type PlayerMetadata = {
4454
* Used to remove a player from a shop when they close the shop's widget.
4555
*/
4656
shopCloseListener: Subscription;
57+
58+
/**
59+
* Allows listening to a player clicking on the tab at the specified index.
60+
*
61+
* The `event` property is a `Subject` that will emit a `boolean` value when the player clicks on the tab.
62+
*
63+
* TODO (jameskmonger) This is only used in Goblin Diplomacy. It is only present when the player is taking part
64+
* in Goblin Displomacy.
65+
*/
66+
tabClickEvent: {
67+
tabIndex: number;
68+
event: Subject<boolean>;
69+
};
70+
71+
/**
72+
* Used to process dialogue trees.
73+
*/
74+
dialogueIndices: Record<string, number>;
75+
76+
/**
77+
* The player's current dialogue tree.
78+
*
79+
* This is a `ParsedDialogueTree` type, but that type is not exported.
80+
*/
81+
dialogueTree: any;
82+
83+
/**
84+
* A list of custom landscape objects that have been spawned by the player.
85+
*
86+
* Initialised by, and used by, the `spawn-scenery` command.
87+
*/
88+
spawnedScenery: LandscapeObject[];
89+
90+
/**
91+
* The last custom landscape object that was spawned by the player.
92+
*
93+
* Used to provide `undo` functionality to the `spawn-scenery` command.
94+
*/
95+
lastSpawnedScenery: LandscapeObject;
96+
97+
/**
98+
* The timestamp of the last time the player lit a fire.
99+
*
100+
* Used to prevent the player from lighting fires too quickly.
101+
*
102+
* TODO (jameskmonger) this should not be using Dates for timing and will be converted in the new task system
103+
*/
104+
lastFire: number;
105+
106+
/**
107+
* The ID of the player's currently open skill guide.
108+
*/
109+
activeSkillGuide: number;
47110
};

src/engine/world/actor/walking-queue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class WalkingQueue {
144144

145145
const walkPosition = this.queue.shift();
146146

147-
if(this.actor.metadata['faceActorClearedByWalking'] === undefined || this.actor.metadata['faceActorClearedByWalking']) {
147+
if(this.actor.metadata.faceActorClearedByWalking === undefined || this.actor.metadata.faceActorClearedByWalking) {
148148
this.actor.clearFaceActor();
149149
}
150150

src/plugins/skills/firemaking.plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ const lightFire = (player: Player, position: Position, worldItemLog: WorldItem,
108108

109109
player.face(position, false);
110110
player.metadata.lastFire = Date.now();
111-
player.metadata.busy = false;
111+
player.busy = false;
112112
};
113113

114114
const action: itemOnItemActionHandler = (details) => {
115115
const { player, usedItem, usedWithItem, usedSlot, usedWithSlot } = details;
116116

117-
if(player.metadata['lastFire'] && Date.now() - player.metadata['lastFire'] < 600) {
117+
if(player.metadata.lastFire && Date.now() - player.metadata.lastFire < 600) {
118118
return;
119119
}
120120

@@ -134,7 +134,7 @@ const action: itemOnItemActionHandler = (details) => {
134134
player.removeItem(removeFromSlot);
135135
const worldItemLog = player.instance.spawnWorldItem(log, player.position, { owner: player, expires: 300 });
136136

137-
if(player.metadata['lastFire'] && Date.now() - player.metadata['lastFire'] < 1200 &&
137+
if(player.metadata.lastFire && Date.now() - player.metadata.lastFire < 1200 &&
138138
canChain(skillInfo.requiredLevel, player.skills.firemaking.level)) {
139139
lightFire(player, position, worldItemLog, skillInfo.experienceGained);
140140
} else {
@@ -151,7 +151,7 @@ const action: itemOnItemActionHandler = (details) => {
151151

152152
if(canLightFire) {
153153
loop.cancel();
154-
player.metadata.busy = true;
154+
player.busy = true;
155155
setTimeout(() => lightFire(player, position, worldItemLog, skillInfo.experienceGained), 1200);
156156
return;
157157
}

src/plugins/skills/skill-guides/skill-guides.plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function loadGuide(player: Player, guideId: number, subGuideId: number = 0, refr
6262
slot: 'screen',
6363
multi: false
6464
});
65-
player.metadata['activeSkillGuide'] = guideId;
65+
player.metadata.activeSkillGuide = guideId;
6666
}
6767

6868
export const guideHandler: buttonActionHandler = async (details) => {
@@ -82,7 +82,7 @@ export const subGuideHandler: widgetInteractionActionHandler = async (details) =
8282
guides = await loadSkillGuideConfigurations(skillGuidePath);
8383
}
8484

85-
const activeSkillGuide = player.metadata['activeSkillGuide'];
85+
const activeSkillGuide = player.metadata.activeSkillGuide;
8686

8787
if(!activeSkillGuide) {
8888
return;

0 commit comments

Comments
 (0)