1- import { EventBus } from "../core/EventBus" ;
2- import { GameView , PlayerView } from "../core/game/GameView" ;
3- import { ClientID } from "../core/Schemas" ;
4- import { ShowSkinTestModalEvent } from "./graphics/layers/SkinTestWinModal" ;
5- import { SendAttackIntentEvent } from "./Transport" ;
1+ import { ColorPalette } from "../CosmeticSchemas" ;
2+ import { Execution , Game , PlayerID } from "../game/Game" ;
3+ import { GameView , PlayerView } from "../game/GameView" ;
4+ import { ClientID } from "../Schemas" ;
65
7- export class TestSkinExecution {
6+ export class TestSkinExecution implements Execution {
87 private myPlayer : PlayerView | null = null ;
98 private initialAttackTimeoutId : ReturnType < typeof setTimeout > | null = null ;
109 private modalTimeoutId : ReturnType < typeof setTimeout > | null = null ;
10+ private active = true ;
1111
1212 constructor (
1313 private gameView : GameView ,
14- private eventBus : EventBus ,
1514 private clientID : ClientID ,
16-
17- private isActive : ( ) => boolean ,
18- // callback to request the runner stop the game before showing the modal
15+ private isRunnerActive : ( ) => boolean ,
1916 private onShowModalRequested : ( ) => void ,
17+ private onAttackIntent : ( targetID : PlayerID | null , troops : number ) => void ,
18+ private onShowModal : (
19+ patternName : string ,
20+ colorPalette : ColorPalette | null ,
21+ ) => void ,
2022 ) { }
2123
24+ isActive ( ) : boolean {
25+ return this . active ;
26+ }
27+
28+ activeDuringSpawnPhase ( ) : boolean {
29+ return false ;
30+ }
31+
32+ init ( _mg : Game , _ticks : number ) : void { }
33+
34+ tick ( _ticks : number ) : void { }
35+
2236 public start ( ) {
2337 // schedule the initial attack
2438 this . scheduleInitialAttack ( 100 ) ;
@@ -30,12 +44,13 @@ export class TestSkinExecution {
3044 }
3145 this . modalTimeoutId = setTimeout ( ( ) => {
3246 this . modalTimeoutId = null ;
33- if ( ! this . isActive ( ) ) return ;
47+ if ( ! this . isRunnerActive ( ) ) return ;
3448 this . showModal ( ) ;
3549 } , 120000 ) ;
3650 }
3751
3852 public stop ( ) {
53+ this . active = false ;
3954 if ( this . initialAttackTimeoutId !== null ) {
4055 clearTimeout ( this . initialAttackTimeoutId ) ;
4156 this . initialAttackTimeoutId = null ;
@@ -74,7 +89,7 @@ export class TestSkinExecution {
7489 const patternName = myPlayer . cosmetics . pattern . name ;
7590 const colorPalette = myPlayer . cosmetics . pattern . colorPalette ?? null ;
7691
77- this . eventBus . emit ( new ShowSkinTestModalEvent ( patternName , colorPalette ) ) ;
92+ this . onShowModal ( patternName , colorPalette ) ;
7893 }
7994
8095 private scheduleInitialAttack ( delayMs : number ) {
@@ -84,13 +99,13 @@ export class TestSkinExecution {
8499 }
85100 this . initialAttackTimeoutId = setTimeout ( ( ) => {
86101 this . initialAttackTimeoutId = null ;
87- if ( ! this . isActive ( ) ) return ;
102+ if ( ! this . isRunnerActive ( ) ) return ;
88103 this . initialAttack ( ) ;
89104 } , delayMs ) ;
90105 }
91106
92107 private initialAttack ( ) {
93- if ( ! this . isActive ( ) ) return ;
108+ if ( ! this . isRunnerActive ( ) ) return ;
94109
95110 if ( this . myPlayer === null ) {
96111 const myPlayer = this . gameView . playerByClientID ( this . clientID ) ;
@@ -103,8 +118,6 @@ export class TestSkinExecution {
103118 }
104119
105120 const troopCount = this . myPlayer . troops ( ) ?? 1000000 ;
106- this . eventBus . emit (
107- new SendAttackIntentEvent ( null , Math . floor ( troopCount / 2 ) ) ,
108- ) ;
121+ this . onAttackIntent ( null , Math . floor ( troopCount / 2 ) ) ;
109122 }
110123}
0 commit comments