@@ -287,20 +287,28 @@ export function getKOChance(
287
287
? ' after ' + serializeText ( hazards . texts . concat ( eot . texts ) )
288
288
: '' ;
289
289
290
+ function KOChance (
291
+ chance : number | undefined ,
292
+ n : number ,
293
+ multipleTurns = false ,
294
+ ) {
295
+ if ( chance === 0 ) return { chance : undefined , n, text : qualifier + 'not a KO' } ;
296
+ let text = chance === undefined ? qualifier + 'possible '
297
+ : chance === 1 ? qualifier || 'guaranteed '
298
+ // prevent displaying misleading 100% or 0% chances
299
+ : `${ qualifier } ${ Math . max ( Math . min ( Math . round ( chance * 1000 ) , 999 ) , 1 ) / 10 } % chance to ` ;
300
+ // using the number of hits we can determine the type of KO we are checking for
301
+ text += n === 1 ? 'OHKO' + hazardsText
302
+ : ( multipleTurns ? `KO in ${ n } turns` : `${ n } HKO` ) + afterText ;
303
+ return { chance, n, text} ;
304
+ }
305
+
290
306
if ( ( move . timesUsed === 1 && move . timesUsedWithMetronome === 1 ) || move . isZ ) {
291
307
const chance = computeKOChance (
292
308
damage , defender . curHP ( ) - hazards . damage , 0 , 1 , 1 , defender . maxHP ( ) , toxicCounter
293
309
) ;
294
- if ( chance === 1 ) {
295
- return { chance, n : 1 , text : `guaranteed OHKO${ hazardsText } ` } ; // eot wasn't considered
296
- } else if ( chance > 0 ) {
297
- // note: still not accounting for EOT due to poor eot damage handling
298
- return {
299
- chance,
300
- n : 1 ,
301
- text : qualifier + Math . round ( chance * 1000 ) / 10 + `% chance to OHKO${ hazardsText } ` ,
302
- } ;
303
- }
310
+ // note: still not accounting for EOT due to poor eot damage handling
311
+ if ( chance > 0 ) return KOChance ( chance , 1 ) ;
304
312
305
313
// Parental Bond's combined first + second hit only is accurate for chance to OHKO, for
306
314
// multihit KOs its only approximated. We should be doing squashMultihit here instead of
@@ -315,28 +323,21 @@ export function getKOChance(
315
323
const chance = computeKOChance (
316
324
damage , defender . curHP ( ) - hazards . damage , eot . damage , i , 1 , defender . maxHP ( ) , toxicCounter
317
325
) ;
318
- if ( chance === 1 ) {
319
- return { chance, n : i , text : `${ qualifier || 'guaranteed ' } ${ i } HKO${ afterText } ` } ;
320
- } else if ( chance > 0 ) {
321
- return {
322
- chance,
323
- n : i ,
324
- text : qualifier + Math . round ( chance * 1000 ) / 10 + `% chance to ${ i } HKO${ afterText } ` ,
325
- } ;
326
- }
326
+ if ( chance > 0 ) return KOChance ( chance , i ) ;
327
327
}
328
328
329
329
for ( let i = 5 ; i <= 9 ; i ++ ) {
330
330
if (
331
331
predictTotal ( damage [ 0 ] , eot . damage , i , 1 , toxicCounter , defender . maxHP ( ) ) >=
332
332
defender . curHP ( ) - hazards . damage
333
333
) {
334
- return { chance : 1 , n : i , text : ` ${ qualifier || 'guaranteed ' } ${ i } HKO ${ afterText } ` } ;
334
+ return KOChance ( 1 , i ) ;
335
335
} else if (
336
336
predictTotal ( damage [ damage . length - 1 ] , eot . damage , i , 1 , toxicCounter , defender . maxHP ( ) ) >=
337
337
defender . curHP ( ) - hazards . damage
338
338
) {
339
- return { n : i , text : qualifier + `possible ${ i } HKO${ afterText } ` } ;
339
+ // possible but no concrete chance
340
+ return KOChance ( undefined , i ) ;
340
341
}
341
342
}
342
343
} else {
@@ -348,22 +349,7 @@ export function getKOChance(
348
349
defender . maxHP ( ) ,
349
350
toxicCounter
350
351
) ;
351
- if ( chance === 1 ) {
352
- return {
353
- chance,
354
- n : move . timesUsed ,
355
- text : `${ qualifier || 'guaranteed ' } KO in ${ move . timesUsed } turns${ afterText } ` ,
356
- } ;
357
- } else if ( chance > 0 ) {
358
- return {
359
- chance,
360
- n : move . timesUsed ,
361
- text :
362
- qualifier +
363
- Math . round ( chance * 1000 ) / 10 +
364
- `% chance to ${ move . timesUsed } HKO${ afterText } ` ,
365
- } ;
366
- }
352
+ if ( chance > 0 ) return KOChance ( chance , move . timesUsed , chance === 1 ) ;
367
353
368
354
if ( predictTotal (
369
355
damage [ 0 ] ,
@@ -375,11 +361,7 @@ export function getKOChance(
375
361
) >=
376
362
defender . curHP ( ) - hazards . damage
377
363
) {
378
- return {
379
- chance : 1 ,
380
- n : move . timesUsed ,
381
- text : `${ qualifier || 'guaranteed ' } KO in ${ move . timesUsed } turns${ afterText } ` ,
382
- } ;
364
+ return KOChance ( 1 , move . timesUsed , true ) ;
383
365
} else if (
384
366
predictTotal (
385
367
damage [ damage . length - 1 ] ,
@@ -391,12 +373,10 @@ export function getKOChance(
391
373
) >=
392
374
defender . curHP ( ) - hazards . damage
393
375
) {
394
- return {
395
- n : move . timesUsed ,
396
- text : qualifier + `possible KO in ${ move . timesUsed } turns${ afterText } ` ,
397
- } ;
376
+ // possible but no real idea
377
+ return KOChance ( undefined , move . timesUsed , true ) ;
398
378
}
399
- return { n : move . timesUsed , text : qualifier + 'not a KO' } ;
379
+ return KOChance ( 0 , move . timesUsed ) ;
400
380
}
401
381
402
382
return { chance : 0 , n : 0 , text : '' } ;
0 commit comments