@@ -13,11 +13,16 @@ class DamageController {
1313 return this . _parent . ActiveActor . CombatController
1414 }
1515
16+ private resolveTarget ( direct : boolean ) : CombatController {
17+ return direct ? this . _parent : this . _parent . ActiveActor . CombatController
18+ }
19+
1620 public CalculateArmorReduction (
1721 type : DamageType ,
1822 value : number ,
1923 ap : boolean ,
20- irreducible : boolean
24+ irreducible : boolean ,
25+ direct = false
2126 ) : number {
2227 if (
2328 irreducible ||
@@ -27,15 +32,16 @@ class DamageController {
2732 type === DamageType . AppliedBurn
2833 )
2934 return 0
30- return this . _parent . ActiveActor . StatController . getCurrent ( StatKey . ARMOR ) || 0
35+ return this . resolveTarget ( direct ) . StatController . getCurrent ( StatKey . ARMOR ) || 0
3136 }
3237
3338 public CalculateDamage (
3439 type : DamageType ,
3540 value : number ,
3641 ap : boolean = false ,
3742 irreducible = false ,
38- reliable = 0
43+ reliable = 0 ,
44+ direct = false
3945 ) : { total : number ; resist : string [ ] ; condition : string [ ] } {
4046 const out = { total : value , resist : [ ] as string [ ] , condition : [ ] as string [ ] }
4147
@@ -60,9 +66,14 @@ class DamageController {
6066
6167 if ( irreducible ) return out
6268
63- out . total = Math . max ( 0 , out . total - this . CalculateArmorReduction ( type , value , ap , irreducible ) )
69+ out . total = Math . max (
70+ 0 ,
71+ out . total - this . CalculateArmorReduction ( type , value , ap , irreducible , direct )
72+ )
6473
65- const resist = this . _active . Resistances . find ( r => r . type === type . toLowerCase ( ) )
74+ const resist = this . resolveTarget ( direct ) . Resistances . find (
75+ r => r . type === type . toLowerCase ( )
76+ )
6677
6778 if ( resist ) {
6879 if ( resist . condition === 'vulnerable' ) {
@@ -88,30 +99,33 @@ class DamageController {
8899 type : DamageType ,
89100 value : number ,
90101 ap : boolean = false ,
91- irreducible = false
102+ irreducible = false ,
103+ direct = false
92104 ) : void {
93105 if ( this . _parent . SaveLock ) return
94106
107+ const target = this . resolveTarget ( direct )
108+
95109 if (
96110 type === DamageType . Heat . toLowerCase ( ) &&
97- ! this . _parent . ActiveActor . StatController . getMax ( StatKey . STRESS )
111+ ! target . StatController . getMax ( StatKey . STRESS )
98112 ) {
99113 type = DamageType . Energy
100114 }
101115
102- const damage = this . CalculateDamage ( type , value , ap , irreducible )
116+ const damage = this . CalculateDamage ( type , value , ap , irreducible , 0 , direct )
103117
104- this . ApplyDamage ( type , damage . total )
118+ this . ApplyDamage ( type , damage . total , direct )
105119
106120 this . _parent . CombatLog . TakeDamage ( value , type )
107121 this . _parent . CombatLog . ArmorReduced (
108- this . CalculateArmorReduction ( type , value , ap , irreducible )
122+ this . CalculateArmorReduction ( type , value , ap , irreducible , direct )
109123 )
110124 if ( this . _parent . IsDestroyed ) this . _parent . CombatLog . LoseMech ( )
111125 }
112126
113- public ApplyDamage ( type : DamageType , value : number ) : void {
114- const target = this . _active
127+ public ApplyDamage ( type : DamageType , value : number , direct = false ) : void {
128+ const target = this . resolveTarget ( direct )
115129
116130 if ( type . toLowerCase ( ) === DamageType . Heat . toLowerCase ( ) ) {
117131 target . ApplyHeat ( value )
@@ -139,9 +153,9 @@ class DamageController {
139153 }
140154 }
141155
142- this . _parent . ActiveActor . StatController . setCurrentStat (
156+ target . StatController . setCurrentStat (
143157 StatKey . HP ,
144- this . _parent . ActiveActor . StatController . getCurrent ( StatKey . HP ) - value
158+ target . StatController . getCurrent ( StatKey . HP ) - value
145159 )
146160 this . _parent . log ( `Took ${ value } ${ type } damage` )
147161 this . _parent . CombatLog . StatChange ( - value , 'hp' )
0 commit comments