@@ -16,6 +16,7 @@ import { Pathfinding } from './pathfinding';
1616import { Attack , AttackDamageType } from './player/attack' ;
1717import { Behavior } from './behaviors' ;
1818import { Effect , EffectType } from './effect' ;
19+ import { ActorMetadata } from './metadata' ;
1920
2021
2122export type ActorType = 'player' | 'npc' ;
@@ -33,7 +34,16 @@ export abstract class Actor {
3334 public readonly inventory : ItemContainer = new ItemContainer ( 28 ) ;
3435 public readonly bank : ItemContainer = new ItemContainer ( 376 ) ;
3536 public readonly actionPipeline = new ActionPipeline ( this ) ;
36- public readonly metadata : { [ key : string ] : any } = { } ;
37+
38+ /**
39+ * The map of available metadata for this actor.
40+ *
41+ * You cannot guarantee that this will be populated with data, so you should always check for the existence of the
42+ * metadata you are looking for before using it.
43+ *
44+ * @author jameskmonger
45+ */
46+ public readonly metadata : Partial < ActorMetadata > = { } ;
3747
3848 /**
3949 * @deprecated - use new action system instead
@@ -109,13 +119,13 @@ export abstract class Actor {
109119 // 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
110120 // 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
111121 public getAttackRoll ( defender ) : Attack {
112-
122+
113123 //the amount of damage is random from 0 to Max
114124 //stance modifiers
115125 const _stance_defense = 3 ;
116126 const _stance_accurate = 0 ;
117127 const _stance_controlled = 1 ;
118-
128+
119129 // base level
120130 // ToDo: calculate prayer effects
121131 // round decimal result calulcation up
@@ -131,7 +141,7 @@ export abstract class Actor {
131141
132142 Effective strength level
133143 Multiply by(Equipment Melee Strength + 64)
134- Add 320
144+ Add 320
135145 Divide by 640
136146 Round down to nearest integer
137147 Multiply by gear bonus
@@ -211,7 +221,7 @@ export abstract class Actor {
211221 return attack ;
212222 //+ stance modifier
213223 }
214- // #endregion
224+ // #endregion
215225
216226 public damage ( amount : number , damageType : DamageType = DamageType . DAMAGE ) {
217227 const armorReduction = 0 ;
@@ -347,7 +357,7 @@ export abstract class Actor {
347357
348358 public follow ( target : Actor ) : void {
349359 this . face ( target , false , false , false ) ;
350- this . metadata [ ' following' ] = target ;
360+ this . metadata . following = target ;
351361
352362 this . moveBehind ( target ) ;
353363 const subscription = target . walkingQueue . movementEvent . subscribe ( ( ) => {
@@ -362,7 +372,7 @@ export abstract class Actor {
362372 ) . subscribe ( ( ) => {
363373 subscription . unsubscribe ( ) ;
364374 this . face ( null ) ;
365- delete this . metadata [ ' following' ] ;
375+ delete this . metadata . following ;
366376 } ) ;
367377 }
368378
@@ -376,7 +386,7 @@ export abstract class Actor {
376386 if ( distance <= 1 ) {
377387 return false ;
378388 }
379-
389+
380390 if ( distance > 16 ) {
381391 this . clearFaceActor ( ) ;
382392 this . metadata . faceActorClearedByWalking = true ;
@@ -398,7 +408,7 @@ export abstract class Actor {
398408 return ;
399409 }
400410
401- this . metadata [ ' tailing' ] = target ;
411+ this . metadata . tailing = target ;
402412
403413 this . moveTo ( target ) ;
404414 const subscription = target . walkingQueue . movementEvent . subscribe ( async ( ) => this . moveTo ( target ) ) ;
@@ -409,7 +419,7 @@ export abstract class Actor {
409419 ) . subscribe ( ( ) => {
410420 subscription . unsubscribe ( ) ;
411421 this . face ( null ) ;
412- delete this . metadata [ ' tailing' ] ;
422+ delete this . metadata . tailing ;
413423 } ) ;
414424 }
415425
@@ -424,8 +434,8 @@ export abstract class Actor {
424434 this . updateFlags . facePosition = face ;
425435 } else if ( face instanceof Actor ) {
426436 this . updateFlags . faceActor = face ;
427- this . metadata [ ' faceActor' ] = face ;
428- this . metadata [ ' faceActorClearedByWalking' ] = clearedByWalking ;
437+ this . metadata . faceActor = face ;
438+ this . metadata . faceActorClearedByWalking = clearedByWalking ;
429439
430440 if ( autoClear ) {
431441 setTimeout ( ( ) => {
@@ -441,9 +451,9 @@ export abstract class Actor {
441451 }
442452
443453 public clearFaceActor ( ) : void {
444- if ( this . metadata [ ' faceActor' ] ) {
454+ if ( this . metadata . faceActor ) {
445455 this . updateFlags . faceActor = null ;
446- this . metadata [ ' faceActor' ] = undefined ;
456+ this . metadata . faceActor = undefined ;
447457 }
448458 }
449459
0 commit comments