@@ -7,15 +7,12 @@ import { DefensiveBonuses, OffensiveBonuses, SkillBonuses } from '@engine/config
77import { Position , DirectionData , directionFromIndex , WorldInstance , activeWorld } from '@engine/world' ;
88import { Item , ItemContainer } from '@engine/world/items' ;
99import { ActionCancelType , ActionPipeline } from '@engine/action' ;
10- import { soundIds } from '@engine/world/config' ;
1110
1211import { WalkingQueue } from './walking-queue' ;
13- import { Animation , DamageType , Graphic , UpdateFlags } from './update-flags' ;
14- import { Skill , Skills } from './skills' ;
12+ import { Animation , Graphic , UpdateFlags } from './update-flags' ;
13+ import { Skills } from './skills' ;
1514import { Pathfinding } from './pathfinding' ;
16- import { Attack , AttackDamageType } from './player/attack' ;
17- import { Behavior } from './behaviors' ;
18- import { Effect , EffectType } from './effect' ;
15+ import { Effect } from './effect' ;
1916import { ActorMetadata } from './metadata' ;
2017
2118
@@ -53,13 +50,6 @@ export abstract class Actor {
5350 public pathfinding : Pathfinding = new Pathfinding ( this ) ;
5451 public lastMovementPosition : Position ;
5552 // #region Behaviors and Combat flags/checks
56- public inCombat : boolean = false ;
57- public meleeDistance : number = 1 ;
58- public Behaviors : Behavior [ ] = [ ] ;
59- public isDead : boolean = false ;
60- public combatTargets : Actor [ ] = [ ] ;
61- public hitPoints = this . skills . hitpoints . level * 4 ;
62- public maxHitPoints = this . skills . hitpoints . level * 4 ;
6353 public effects : Effect [ ] = [ ] ; //spells, effects, prayers, etc
6454
6555 protected randomMovementInterval ;
@@ -75,7 +65,6 @@ export abstract class Actor {
7565 private _walkDirection : number ;
7666 private _runDirection : number ;
7767 private _faceDirection : number ;
78- private _damageType = AttackDamageType . Crush ;
7968 private _bonuses : { offensive : OffensiveBonuses , defensive : DefensiveBonuses , skill : SkillBonuses } ;
8069
8170 protected constructor ( actorType : ActorType ) {
@@ -100,159 +89,6 @@ export abstract class Actor {
10089 } ;
10190 }
10291
103- public get highestCombatSkill ( ) : Skill {
104- const attack = this . skills . getLevel ( 'attack' ) ;
105- const magic = this . skills . getLevel ( 'magic' ) ;
106- const ranged = this . skills . getLevel ( 'ranged' ) ;
107-
108- if ( ranged > magic && ranged > ranged ) return ranged ;
109- else if ( magic > attack && magic > ranged ) return magic ;
110- else return attack ;
111- }
112-
113- //https://oldschool.runescape.wiki/w/Attack_range#:~:text=All%20combat%20magic%20spells%20have,also%20allow%20longrange%20attack%20style
114- // range should be within 10 tiles for magic
115- // range should be within 7 for magic staff
116- // https://www.theoatrix.net/post/how-defence-works-in-osrs
117- // https://oldschool.runescape.wiki/w/Damage_per_second/Magic
118- // https://oldschool.runescape.wiki/w/Successful_hit
119- // 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
120- // 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
121- public getAttackRoll ( defender ) : Attack {
122-
123- //the amount of damage is random from 0 to Max
124- //stance modifiers
125- const _stance_defense = 3 ;
126- const _stance_accurate = 0 ;
127- const _stance_controlled = 1 ;
128-
129- // base level
130- // ToDo: calculate prayer effects
131- // round decimal result calulcation up
132- // add 8
133- // ToDo: add void bonues (effects)
134- // round result down
135- let equipmentBonus = this . bonuses . offensive . crush ?? 0 ;
136- if ( equipmentBonus <= 0 ) {
137- equipmentBonus = 1 ;
138- }
139- /*
140- * To calculate your maximum hit:
141-
142- Effective strength level
143- Multiply by(Equipment Melee Strength + 64)
144- Add 320
145- Divide by 640
146- Round down to nearest integer
147- Multiply by gear bonus
148- Round down to nearest integer
149- */
150- const stanceModifier = _stance_accurate ;
151- const strengthLevel = ( this . skills . attack . level + stanceModifier + 8 ) ;
152- let attackCalc = strengthLevel * ( equipmentBonus + 64 ) + 320 ;
153- attackCalc = Math . round ( attackCalc / 640 ) ;
154- //console.log(`strengthLevel = ${strengthLevel} \r\n attackCalc = ${attackCalc} \r\n equipmentBonus = ${equipmentBonus}`);
155- const maximumHit = Math . round ( attackCalc * equipmentBonus ) ;
156-
157- /*
158- To calculate your effective attack level:
159-
160- (Attack level + Attack level boost) * prayer bonus
161- Round down to nearest integer
162- + 3 if using the accurate attack style, +1 if using controlled
163- + 8
164- Multiply by 1.1 if wearing void
165- Round down to nearest integer
166- */
167- const attackLevel = this . skills . attack . level ;
168- let effectiveAttackLevel = attackLevel ;
169-
170- //Prayer/Effect bonus - calculate ALL the good and bad effects at once! (prayers, and magic effects, etc.)
171- this . effects . filter ( a => a . EffectType === EffectType . Attack ) . forEach ( ( effect ) => {
172- effectiveAttackLevel += ( attackLevel * effect . Modifier ) ;
173- } ) ;
174- effectiveAttackLevel = Math . round ( effectiveAttackLevel ) + stanceModifier ;
175-
176- /*
177- * Calculate the Attack roll
178- Effective attack level * (Equipment Attack bonus + 64)
179- Multiply by gear bonus
180- Round down to nearest integer
181- * */
182- let attack = new Attack ( ) ;
183- attack . damageType = this . damageType ?? AttackDamageType . Crush ;
184- attack . attackRoll = Math . round ( effectiveAttackLevel * ( equipmentBonus + 64 ) ) ;
185- attack = defender . getDefenseRoll ( attack ) ;
186- attack . maximumHit = maximumHit ;
187- if ( attack . attackRoll >= attack . defenseRoll ) attack . hitChance = 1 - ( ( attack . defenseRoll + 2 ) / ( 2 * ( attack . attackRoll + 1 ) ) )
188- if ( attack . attackRoll < attack . defenseRoll ) attack . hitChance = attack . attackRoll / ( 2 * attack . defenseRoll + 1 ) ;
189-
190- attack . damage = Math . round ( ( maximumHit * attack . hitChance ) / 2 ) ;
191- return attack ;
192- }
193-
194- public getDefenseRoll ( attack : Attack ) : Attack {
195- //attack need to know the damage roll, which is the item bonuses the weapon damage type etc.
196-
197-
198- //stance modifiers
199- const _stance_defense = 3 ;
200- const _stance_accurate = 0 ;
201- const _stance_controlled = 1 ;
202-
203- // base level
204- // calculate prayer effects
205- // round decimal result calculation up
206- // add 8
207- // ToDo: add void bonuses (effects)
208- // round result down
209-
210- const equipmentBonus : number = this . bonuses . defensive . crush ?? 0 ; //object prototyping to find property by name (JS style =/)
211-
212- const stanceModifier : number = _stance_accurate ;
213-
214-
215- attack . defenseRoll = ( this . skills . defence . level + stanceModifier + 8 ) * ( equipmentBonus + 64 ) ;
216- //Prayer/Effect bonus - calculate ALL the good and bad effects at once! (prayers, and magic effects, etc.)
217- this . effects . filter ( a => a . EffectType === EffectType . BoostDefence || a . EffectType === EffectType . LowerDefence ) . forEach ( ( effect ) => {
218- attack . defenseRoll += ( this . skills . defence . level * effect . Modifier ) ;
219- } ) ;
220- attack . defenseRoll = Math . round ( attack . defenseRoll ) ;
221- return attack ;
222- //+ stance modifier
223- }
224- // #endregion
225-
226- public damage ( amount : number , damageType : DamageType = DamageType . DAMAGE ) {
227- const armorReduction = 0 ;
228- const spellDamageReduction = 0 ;
229- const poisonReistance = 0 ;
230- amount -= armorReduction ;
231- this . hitPoints -= amount ;
232- this . skills . setHitpoints ( this . hitPoints ) ;
233- this . updateFlags . addDamage ( amount , amount === 0 ? DamageType . NO_DAMAGE : damageType ,
234- this . hitPoints , this . maxHitPoints ) ;
235- //this actor should respond when hit
236- activeWorld . playLocationSound ( this . position , soundIds . npc . human . noArmorHitPlayer , 5 )
237- this . playAnimation ( this . getBlockAnimation ( ) ) ;
238- }
239-
240-
241-
242- //public damage(amount: number, damageType: DamageType = DamageType.DAMAGE): 'alive' | 'dead' {
243- // let remainingHitpoints: number = this.skills.hitpoints.level - amount;
244- // const maximumHitpoints: number = this.skills.hitpoints.levelForExp;
245- // if(remainingHitpoints < 0) {
246- // remainingHitpoints = 0;
247- // }
248-
249- // this.skills.setHitpoints(remainingHitpoints);
250- // this.updateFlags.addDamage(amount, amount === 0 ? DamageType.NO_DAMAGE : damageType,
251- // remainingHitpoints, maximumHitpoints);
252-
253- // return remainingHitpoints === 0 ? 'dead' : 'alive';
254- //}
255-
25692 /**
25793 * Waits for the actor to reach the specified position before resolving it's promise.
25894 * The promise will be rejected if the actor's walking queue changes or their movement is otherwise canceled.
@@ -401,28 +237,6 @@ export abstract class Actor {
401237 return true ;
402238 }
403239
404- public tail ( target : Actor ) : void {
405- this . face ( target , false , false , false ) ;
406-
407- if ( this . metadata . tailing && this . metadata . tailing . equals ( target ) ) {
408- return ;
409- }
410-
411- this . metadata . tailing = target ;
412-
413- this . moveTo ( target ) ;
414- const subscription = target . walkingQueue . movementEvent . subscribe ( async ( ) => this . moveTo ( target ) ) ;
415-
416- this . actionsCancelled . pipe (
417- filter ( type => type !== 'pathing-movement' ) ,
418- take ( 1 )
419- ) . subscribe ( ( ) => {
420- subscription . unsubscribe ( ) ;
421- this . face ( null ) ;
422- delete this . metadata . tailing ;
423- } ) ;
424- }
425-
426240 public face ( face : Position | Actor | null , clearWalkingQueue : boolean = true , autoClear : boolean = true , clearedByWalking : boolean = true ) : void {
427241 if ( face === null ) {
428242 this . clearFaceActor ( ) ;
@@ -628,8 +442,6 @@ export abstract class Actor {
628442 return true ;
629443 }
630444
631- public abstract getAttackAnimation ( ) : number ;
632- public abstract getBlockAnimation ( ) : number ;
633445 public abstract equals ( actor : Actor ) : boolean ;
634446
635447 public get position ( ) : Position {
@@ -684,14 +496,6 @@ export abstract class Actor {
684496 this . _faceDirection = value ;
685497 }
686498
687- public get damageType ( ) {
688- return this . _damageType ;
689- }
690-
691- public set damageType ( value ) {
692- this . _damageType = value ;
693- }
694-
695499 public get busy ( ) : boolean {
696500 return this . _busy ;
697501 }
0 commit comments