@@ -2,49 +2,54 @@ import { AttackType } from "../../types/enum/Game"
22import { distanceM } from "../../utils/distance"
33import type { Board } from "../board"
44import type { PokemonEntity } from "../pokemon-entity"
5+ import { DelayedCommand } from "../simulation-command"
56import { AbilityStrategy } from "./ability-strategy"
67
78export class PetalDanceStrategy extends AbilityStrategy {
89 requiresTarget = false
910 process ( pokemon : PokemonEntity , board : Board , target : null , crit : boolean ) {
10- super . process ( pokemon , board , target , crit , true )
11+ super . process ( pokemon , board , target , crit )
1112
1213 const damage = [ 20 , 30 , 50 , 100 ] [ pokemon . stars - 1 ] ?? 100
1314 const count = [ 3 , 4 , 5 , 6 ] [ pokemon . stars - 1 ] ?? 6
1415
15- const enemies = board . cells . filter (
16- ( p ) => p && p . team !== pokemon . team
17- ) as PokemonEntity [ ]
18- const enemiesHit = enemies
19- . sort (
20- ( a , b ) =>
21- distanceM (
22- a . positionX ,
23- a . positionY ,
24- pokemon . positionX ,
25- pokemon . positionY
26- ) -
27- distanceM (
28- b . positionX ,
29- b . positionY ,
30- pokemon . positionX ,
31- pokemon . positionY
32- )
33- )
34- . slice ( 0 , count )
16+ const enemies = board . cells
17+ . filter ( ( p ) : p is PokemonEntity => p != null && p . team !== pokemon . team )
18+ . map ( ( entity ) => ( {
19+ entity,
20+ distance : distanceM (
21+ entity . positionX ,
22+ entity . positionY ,
23+ pokemon . positionX ,
24+ pokemon . positionY
25+ )
26+ } ) )
27+ . sort ( ( a , b ) => a . distance - b . distance )
28+
29+ const projectileSpeed = 10
3530
36- enemiesHit . forEach ( ( enemy ) => {
37- enemy . handleSpecialDamage (
38- damage ,
39- board ,
40- AttackType . SPECIAL ,
41- pokemon ,
42- crit
31+ for ( let i = 0 ; i < count ; i ++ ) {
32+ const { entity : enemy , distance } = enemies [ i % enemies . length ]
33+ pokemon . commands . push (
34+ new DelayedCommand ( ( ) => {
35+ if ( enemy . hp > 0 ) {
36+ enemy . handleSpecialDamage (
37+ damage ,
38+ board ,
39+ AttackType . SPECIAL ,
40+ pokemon ,
41+ crit
42+ )
43+ }
44+ } , i * 100 + ( distance * 1000 / projectileSpeed ) )
4345 )
46+
4447 pokemon . broadcastAbility ( {
45- positionX : enemy . positionX ,
46- positionY : enemy . positionY
48+ skill : "PETAL_DANCE_PROJECTILE" ,
49+ targetX : enemy . positionX ,
50+ targetY : enemy . positionY ,
51+ delay : i * 100
4752 } )
48- } )
53+ }
4954 }
5055}
0 commit comments