1+ import { setTimeout } from 'timers/promises'
2+
13/* -------------------------------------------------------------------------- */
24/* SUPERHEROREGENERATINGERROR (ERROR) */
35/* -------------------------------------------------------------------------- */
46
5- import { setTimeout } from 'timers/promises'
6-
77class SuperheroRegeneratingError extends Error {
88 public constructor ( superhero : ISuperhero ) {
99 super ( `${ superhero . getName ( ) } is regenerating` )
@@ -199,7 +199,6 @@ class SuperheroFight implements ISuperheroFight {
199199
200200 public executeTurn ( ) : Readonly < ExecutedTurn > | never {
201201 const { attacker, number, victim} = this . getTurn ( )
202-
203202 victim . setRegenerating ( false )
204203
205204 this . turn = {
@@ -210,12 +209,19 @@ class SuperheroFight implements ISuperheroFight {
210209
211210 try {
212211 const damageProducedByAttacker = attacker . produceDamage ( )
212+ const attackerAttackDamage : Readonly < [ number , number ] > =
213+ attacker . getAttackDamage ( )
214+
213215 const victimAvoidAttack = victim . evadeAttack ( )
214216
215- if ( ! victimAvoidAttack )
217+ if ( ! victimAvoidAttack ) {
216218 victim . receiveDamage ( damageProducedByAttacker )
219+ victim . setRegenerating (
220+ damageProducedByAttacker === attackerAttackDamage [ 1 ]
221+ )
217222
218- if ( victim . getLifePoints ( ) <= 0 ) this . winner = attacker
223+ if ( victim . getLifePoints ( ) <= 0 ) this . winner = attacker
224+ }
219225
220226 return {
221227 attacker,
@@ -253,8 +259,6 @@ class SuperheroFight implements ISuperheroFight {
253259 try {
254260 const executedTurn : Readonly < ExecutedTurn > =
255261 superheroFight . executeTurn ( )
256- const attackerAttackDamage : Readonly < [ number , number ] > =
257- executedTurn . attacker . getAttackDamage ( )
258262
259263 if ( executedTurn . victimAvoidAttack ) {
260264 console . log (
@@ -266,11 +270,6 @@ class SuperheroFight implements ISuperheroFight {
266270 continue
267271 }
268272
269- currentTurn . victim . setRegenerating (
270- executedTurn . damageProducedByAttacker ===
271- attackerAttackDamage [ 1 ]
272- )
273-
274273 console . log (
275274 `\n> Turn N°${
276275 currentTurn . number
0 commit comments