1
1
use crate :: content:: custom_phase_actions:: {
2
2
CurrentCustomPhaseEvent , CustomPhaseAdvanceRewardRequest , CustomPhaseEventAction ,
3
- CustomPhasePaymentRequest , CustomPhaseRequest , CustomPhaseResourceRewardRequest ,
3
+ CustomPhasePaymentRequest , CustomPhasePositionRequest , CustomPhaseRequest ,
4
+ CustomPhaseResourceRewardRequest ,
4
5
} ;
5
6
use crate :: events:: { Event , EventOrigin } ;
6
7
use crate :: game:: UndoContext ;
7
- use crate :: player_events:: { CustomPhaseInfo , PlayerCommands } ;
8
+ use crate :: player_events:: { CustomPhaseEvent , PlayerCommands } ;
9
+ use crate :: position:: Position ;
8
10
use crate :: resource_pile:: ResourcePile ;
9
11
use crate :: { content:: custom_actions:: CustomActionType , game:: Game , player_events:: PlayerEvents } ;
10
12
use std:: collections:: HashMap ;
@@ -90,7 +92,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
90
92
+ Clone ,
91
93
) -> Self
92
94
where
93
- E : Fn ( & mut PlayerEvents ) -> & mut Event < Game , CustomPhaseInfo , V > + ' static + Clone ,
95
+ E : Fn ( & mut PlayerEvents ) -> & mut CustomPhaseEvent < V > + ' static + Clone ,
94
96
{
95
97
let origin = self . get_key ( ) ;
96
98
self . add_player_event_listener (
@@ -156,7 +158,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
156
158
gain_reward : impl Fn ( & mut PlayerCommands , & Game , & Vec < ResourcePile > ) + ' static + Clone ,
157
159
) -> Self
158
160
where
159
- E : Fn ( & mut PlayerEvents ) -> & mut Event < Game , CustomPhaseInfo , V > + ' static + Clone ,
161
+ E : Fn ( & mut PlayerEvents ) -> & mut CustomPhaseEvent < V > + ' static + Clone ,
160
162
{
161
163
self . add_payment_request_listener (
162
164
event,
@@ -180,7 +182,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
180
182
gain_reward : impl Fn ( & mut Game , usize , & str , & Vec < ResourcePile > ) + ' static + Clone ,
181
183
) -> Self
182
184
where
183
- E : Fn ( & mut PlayerEvents ) -> & mut Event < Game , CustomPhaseInfo , V > + ' static + Clone ,
185
+ E : Fn ( & mut PlayerEvents ) -> & mut CustomPhaseEvent < V > + ' static + Clone ,
184
186
{
185
187
self . add_state_change_event_listener (
186
188
event,
@@ -217,7 +219,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
217
219
gain_reward_log : impl Fn ( & Game , usize , & str , & ResourcePile , bool ) -> String + ' static + Clone ,
218
220
) -> Self
219
221
where
220
- E : Fn ( & mut PlayerEvents ) -> & mut Event < Game , CustomPhaseInfo , V > + ' static + Clone ,
222
+ E : Fn ( & mut PlayerEvents ) -> & mut CustomPhaseEvent < V > + ' static + Clone ,
221
223
{
222
224
let g = gain_reward_log. clone ( ) ;
223
225
self . add_state_change_event_listener (
@@ -266,7 +268,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
266
268
gain_reward : impl Fn ( & mut Game , usize , & str , & str , bool ) + ' static + Clone ,
267
269
) -> Self
268
270
where
269
- E : Fn ( & mut PlayerEvents ) -> & mut Event < Game , CustomPhaseInfo , V > + ' static + Clone ,
271
+ E : Fn ( & mut PlayerEvents ) -> & mut CustomPhaseEvent < V > + ' static + Clone ,
270
272
{
271
273
let g = gain_reward. clone ( ) ;
272
274
self . add_state_change_event_listener (
@@ -302,6 +304,47 @@ pub(crate) trait AbilityInitializerSetup: Sized {
302
304
)
303
305
}
304
306
307
+ fn add_position_reward_request_listener < E , V > (
308
+ self ,
309
+ event : E ,
310
+ priority : i32 ,
311
+ request : impl Fn ( & mut Game , usize , & V ) -> Option < CustomPhasePositionRequest > + ' static + Clone ,
312
+ gain_reward : impl Fn ( & mut PlayerCommands , & Game , & Position ) + ' static + Clone ,
313
+ ) -> Self
314
+ where
315
+ E : Fn ( & mut PlayerEvents ) -> & mut CustomPhaseEvent < V > + ' static + Clone ,
316
+ {
317
+ let g = gain_reward. clone ( ) ;
318
+ self . add_state_change_event_listener (
319
+ event,
320
+ priority,
321
+ move |game, player_index, _player_name, details| {
322
+ let req = request ( game, player_index, details) ;
323
+ if let Some ( r) = & req {
324
+ if r. choices . len ( ) == 1 {
325
+ game. with_commands ( player_index, |commands, game| {
326
+ g ( commands, game, & r. choices [ 0 ] ) ;
327
+ } ) ;
328
+ return None ;
329
+ }
330
+ }
331
+ req. map ( CustomPhaseRequest :: SelectPosition )
332
+ } ,
333
+ move |game, player_index, _player_name, action, request| {
334
+ if let CustomPhaseRequest :: SelectPosition ( request) = & request {
335
+ if let CustomPhaseEventAction :: SelectPosition ( reward) = action {
336
+ assert ! ( request. choices. contains( & reward) , "Invalid position" ) ;
337
+ game. with_commands ( player_index, |commands, game| {
338
+ gain_reward ( commands, game, & reward) ;
339
+ } ) ;
340
+ return ;
341
+ }
342
+ }
343
+ panic ! ( "Invalid state" ) ;
344
+ } ,
345
+ )
346
+ }
347
+
305
348
fn add_custom_action ( self , action : CustomActionType ) -> Self {
306
349
let deinitializer_action = action. clone ( ) ;
307
350
let key = self . get_key ( ) . clone ( ) ;
0 commit comments