forked from elaskavaia/bga-eminentdomain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheminentdomain.js
3139 lines (2843 loc) · 108 KB
/
eminentdomain.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* ------ BGA framework: © Gregory Isabelli <gisabelli@boardgamearena.com> & Emmanuel Colin <ecolin@boardgamearena.com> EminentDomain
* implementation : © Alena Laskavaia <laskava@gmail.com>
*
* This code has been produced on the BGA studio platform for use on http://boardgamearena.com. See
* http://en.boardgamearena.com/#!doc/Studio for more information. -----
*
* eminentdomain.js
*
* EminentDomain user interface script
*
* In this file, you are describing the logic of your user interface, in Javascript language.
*
*/
var SYM_RIGHTARROW = " → ";
define(["dojo", "dojo/_base/declare", "ebg/core/gamegui", "ebg/counter",
// load my own module!!!
g_gamethemeurl + "modules/sharedparent.js"], function (dojo, declare) {
return declare("bgagame.eminentdomain", bgagame.sharedparent, // parent declared in shared module
{
constructor: function () {
console.log('eminentdomain constructor');
g_img_preload = ['cards.jpg', 'board.jpg', 'planets.jpg'];
this.curstate = null;
this.pendingUpdate = false;
this.curActive = false;
this.defaultTooltipDelay = 600;
},
/*
* setup:
*
* This method must set up the game user interface according to current game situation specified in parameters.
*
* The method is called each time the game interface is displayed to a player, ie: _ when the game starts _ when a player refreshes
* the game page (F5)
*
* "gamedatas" argument contains all datas retrieved by your "getAllDatas" PHP method.
*/
setup: function (gamedatas) {
console.log("Starting game setup", gamedatas);
// dojo.destroy('debug_output');
this.inSetup = true;
// Setting up player boards
this.inherited(arguments);
if (!this.isSpectator) {
// ok
} else {
dojo.style($('hand_area'), "display", "none");
}
if (gamedatas.variants.learning_variant_on) {
dojo.addClass($('thething'), "learning_variant_on");
dojo.place("<div class='noresearch'>" + _("Learning Game<br>No Reasearch") + "</div>", 'supply_research');
}
this.updateEndOfGameMessage(gamedatas);
if (!this.isReadOnly()) {
this.checkPreferencesConsistency(this.gamedatas.server_prefs);
}
this.setupPreference();
console.log("Ending game setup");
},
checkPreferencesConsistency: function (backPrefs) {
//console.log('check pref',backPrefs,this.prefs);
for (var key in backPrefs) {
let value = backPrefs[key];
let pref = key;
let user_value = parseInt(this.prefs[pref].value);
if (this.prefs[pref] !== undefined && user_value != value) {
var args = { pref: pref, value: user_value, player: this.player_id };
backPrefs[key] = user_value;
this.ajaxcall("/" + this.game_name + "/" + this.game_name + "/" + 'changePreference' + ".html", args,//
this, () => { }, (err, res) => { if (err) console.error("changePreference callback failed " + res); else console.log("changePreference sent " + pref + "=" + user_value); });
}
}
},
setupPreference: function () {
// Extract the ID and value from the UI control
var _this = this;
function onchange(e) {
var match = e.target.id.match(/^preference_[cf]ontrol_(\d+)$/);
if (!match) {
return;
}
var prefId = +match[1];
var prefValue = +e.target.value;
_this.prefs[prefId].value = prefValue;
_this.onPreferenceChange(prefId, prefValue);
}
dojo.query(".preference_control").connect("onchange", onchange);
// Call onPreferenceChange() now
dojo.query("#ingame_menu_content .preference_control").forEach((el) => onchange({ target: el }));
},
onPreferenceChange: function (prefId, prefValue) {
console.log("Preference changed", prefId, prefValue);
if (!this.isReadOnly()) {
this.checkPreferencesConsistency(this.gamedatas.server_prefs);
}
},
updateEndOfGameMessage: function (args) {
var endmessage = _('End of game is triggered.');
endmessage += " ";
if (this.gamedatas.variants.extra_turn_variant_on) {
if (args.extra_turn) {
endmessage += _('This is last round (extra).');
if (this.player_id == args.leader) {
endmessage += " " + _('This is your last turn.');
}
} else {
endmessage += _('There will be an extra round.');
}
} else {
endmessage += _('This is last round.');
if (this.player_id == args.leader) {
endmessage += " " + _('This is your last turn.');
}
}
$('endofgamewarning').innerHTML = endmessage;
if (this.gamedatas.end_of_game || args.end_of_game) {
dojo.addClass($('thething'), "end_of_game");
}
},
setupGameTokens: function () {
if (!this.isSpectator) {
this.drawHandIcon(5, 'hand_icon', this.player_color, -2);
}
this.updateCountersSafe(this.gamedatas.counters);
for (var token in this.gamedatas.tokens) {
var tokenInfo = this.gamedatas.tokens[token];
var location = tokenInfo.location;
if (!$(location) && this.gamedatas.tokens[location]) {
this.placeTokenWithTips(location);
}
this.placeTokenWithTips(token);
}
dojo.query(".counter,.slot_tooltip").forEach(dojo.hitch(this, function (node) {
this.updateTooltip(node.id);
}));
this.connectClass('card_bottom', 'onclick', 'onCard');
this.connectClass('supply_tech', 'onclick', 'onCard');
this.connectClass('discard', 'onclick', 'onDiscard');
this.connect($('discard_planets'), 'onclick', 'onDiscard');
// Labels
$('deck_display').setAttribute('data-title', _('Deck'));
$('discard_display').setAttribute('data-title', _('Discard'));
this.connectClass('gslider', 'oninput', 'onSlider');
this.connectClass('gcheckbox', 'oninput', 'onCheckbox');
console.log("enging token setup");
//dojo.place(this.getJemImg('green'),'bboard');
},
setupPlayer: function (player_id, playerInfo) {
// console.log("player info " + player_id, playerInfo);
var color = playerInfo.color;
var playerBoardDiv = dojo.byId('player_board_' + player_id);
// var name = "player_" + player_id + "_status";
// dojo.place("pnum_" + player_id, name, "before");
dojo.place('miniboard_' + color, playerBoardDiv);
this.drawHandIcon(1, 'deck_icon_' + color, color, 0);
this.drawHandIcon(2, 'discard_icon_' + color, color);
this.drawHandIcon(5, 'hand_icon_' + color, color, -2);
// player position
var name = "player_" + player_id + "_status";
dojo.place("pnum_" + player_id, name, "before");
// player deck
if (this.player_id == player_id) {
dojo.connect($('deck_' + color), "onclick", this, "onDeck");
dojo.style($('deck_' + color), 'cursor', 'pointer');
}
$('setaside_' + color).setAttribute('data-title', _('Set Aside Zone'));
},
// /////////////////////////////////////////////////
// // Game & client states
// onEnteringState: this method is called each time we are entering into a new game state.
// You can use this method to perform some user interface changes at this moment.
//
onEnteringState: function (stateName, args) {
console.log('Entering state: ' + stateName, args);
this.curstate = stateName;
dojo.addClass($('thething'), stateName);
if (!this.on_client_state) {
this.clientStateArgs = {
action: 'none',
choices: [],
unprocessed_choices: '',
boost: '',
};
if (args && args.args && args.args.end_of_game) {
dojo.addClass($('thething'), "end_of_game");
}
switch (stateName) {
case 'scenarioSelection':
this.clientStateArgs.action = 'selectScenario';
if (this.isCurrentPlayerActive()) {
this.expandScenario();
} else {
this.hideScenario();
}
break;
case 'gamePlayerSetup':
location.reload();
break;
case 'playerTurnAction':
this.clientStateArgs.action = 'playAction';
var color = this.getPlayerColor(this.getActivePlayerId());
this.updatePermCounters(color, args.args.perm_boost_num);
this.updateEndOfGameMessage(args.args);
if (args.args.card) {
var myargs = args.args;
this.clientStateArgs.nocancel = true;
setTimeout(() => this.playAction(myargs.card, myargs.rules)
, 300);
break;
}
break;
case 'playerTurnRole':
this.clientStateArgs.action = 'playRole';
var color = this.getPlayerColor(this.getActivePlayerId());
this.updatePermCounters(color, args.args.perm_boost_num);
this.updateEndOfGameMessage(args.args);
break;
case 'playerTurnFollow':
this.clientStateArgs.action = 'playFollow';
this.updateEndOfGameMessage(args.args);
break;
case 'playerTurnDiscard':
case 'playerTurnPreDiscard':
this.clientStateArgs.action = 'playDiscard';
break;
case 'playerTurnSurvey':
case 'playerTurnSurveyFollow':
case 'client_playerTurnSurvey':
this.clientStateArgs.action = 'playPick';
break;
case 'playerTurnRoleExtra':
if (!this.isCurrentPlayerActive())
break;
this.clientStateArgs.action = 'playExtra';
if (this.instantaneousMode) {
break;
}
//console.log(args.args.rules);
if (args.args.rules == 'R') { //scientific method
var oargs = args.args;
this.clientStateArgs.unprocessed_choices = oargs.rules;
this.clientStateArgs.card = oargs.card;
this.clientStateArgs.nocancel = true;
var total = oargs.boost_rem;
this.setClientStateAction('client_selectTechCard',
_('Select a technology to research <div class="icon research"></div>x${boost_count}'), 0, {
boost_count: total,
});
this.addActionButton('button_skip', _('Skip'), (e) => {
if (this.commitOperationAndSubmit('R', 'skip')) {
this.expandTech(false);
}
});
break;
}
if (args.args.survey) { //survey select card
this.clientStateArgs.action = 'playPick';
this.clientStateArgs.nocancel = true;
this.setClientStateAction('client_playerTurnSurvey', this.gamedatas.gamestate.descriptionmyturn, 0);
break;
}
this.clientStateArgs.unprocessed_choices = args.args.rules;
this.clientStateArgs.nocancel = true;
setTimeout(() => this.actionPrompt(), 300);
break;
default:
break;
}
//console.log('-- settings cargs ', this.clientStateArgs);
dojo.query(".selected").removeClass("selected");
dojo.query(".toremove").removeClass("toremove");
this.adjust3D();
} else {
console.log('-- client state --');
// this.runAutoBot();
}
if (args) {
args = args.args;
}
// Call appropriate method
var methodName = "onEnteringState_" + stateName;
if (this[methodName] !== undefined) {
console.log('Calling ' + methodName, args);
this[methodName](args);
}
if (this.pendingUpdate) {
this.onUpdateActionButtons(stateName, args);
this.pendingUpdate = false;
}
},
// onLeavingState: this method is called each time we are leaving a game state.
// You can use this method to perform some user interface changes at this moment.
//
onLeavingState: function (stateName) {
console.log('Leaving state: ' + stateName);
//console.log('-- cargs: ' + stateName, this.clientStateArgs);
dojo.query(".active_slot").removeClass('active_slot');
dojo.query(".selected").removeClass('selected');
dojo.query(".claimed").removeClass('claimed');
dojo.removeClass($('thething'), stateName);
this.curActive = false;
//this.expandTech(false);
},
onUpdateActionButtons_playerTurnRole: function (args) {
dojo.query(".board .card_role:last-child").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .tech.state_1.activatable").addClass('active_slot');
this.addImageActionButton('button_warfare', this.createDiv("icon warfare role"), dojo.hitch(this, function () {
this.clientStateArgs.role = 'W';
this.clientStateArgs.card = this.getRoleCard('warfare');
if (!this.clientStateArgs.card.startsWith("x_"))
this.placeTokenLocal(this.clientStateArgs.card, 'setaside_' + this.player_color, 12);
this.setClientStateAction('client_selectBoostOrLeader');
}));
this.addImageActionButton('button_colonize', this.createDiv("icon colonize role"), dojo.hitch(this, function () {
this.clientStateArgs.role = 'C';
this.clientStateArgs.card = this.getRoleCard('colonize');
if (!this.clientStateArgs.card.startsWith("x_"))
this.placeTokenLocal(this.clientStateArgs.card, 'setaside_' + this.player_color, 12);
this.setClientStateAction('client_selectBoostOrLeader');
}));
this.addImageActionButton('button_survey', this.createDiv("icon survey role"), dojo.hitch(this, function () {
this.clientStateArgs.role = 'S';
this.clientStateArgs.card = this.getRoleCard('survey');
if (!this.clientStateArgs.card.startsWith("x_"))
this.placeTokenLocal(this.clientStateArgs.card, 'setaside_' + this.player_color, 12);
this.setClientStateAction('client_selectBoost');
}));
if (!this.gamedatas.variants.learning_variant_on) {
this.addImageActionButton('button_research', this.createDiv("icon research role"), dojo.hitch(this, function () {
this.clientStateArgs.role = 'R';
this.clientStateArgs.card = this.getRoleCard('research');
if (!this.clientStateArgs.card.startsWith("x_"))
this.placeTokenLocal(this.clientStateArgs.card, 'setaside_' + this.player_color, 12);
this.setClientStateAction('client_selectBoost');
}));
}
this.addImageActionButton('button_produce', this.createDiv("icon produce role"), dojo.hitch(this, function () {
this.clientStateArgs.role = 'P';
this.clientStateArgs.card = this.getRoleCard('produce');
if (!this.clientStateArgs.card.startsWith("x_"))
this.placeTokenLocal(this.clientStateArgs.card, 'setaside_' + this.player_color, 12);
this.setClientStateAction('client_selectBoost');
}));
this.addImageActionButton('button_trade', this.createDiv("icon trade role"), dojo.hitch(this, function () {
this.clientStateArgs.role = 'T';
this.clientStateArgs.card = this.getRoleCard('produce');
if (!this.clientStateArgs.card.startsWith("x_"))
this.placeTokenLocal(this.clientStateArgs.card, 'setaside_' + this.player_color, 12);
this.setClientStateAction('client_selectBoost');
}));
return true;
},
// onUpdateActionButtons: in this method you can manage "action buttons" that are displayed in the
// action status bar (ie: the HTML links in the status bar).
//
onUpdateActionButtons: function (stateName, args) {
//console.log('onUpdateActionButtons: ' + stateName, args);
if (this.curstate != stateName) { // delay firing this
this.pendingUpdate = true;
this.curActive = false;
//console.log(' DELAYED onUpdateActionButtons');
return;
}
if (!this.isCurrentPlayerActive()) {
return;
}
console.log('onUpdateActionButtons: ' + stateName, args);
var hookiscalled = false;
this.pendingUpdate = false;
// Call appropriate method
var methodName = "onUpdateActionButtons_" + stateName;
if (this[methodName] !== undefined) {
console.log('Calling ' + methodName, args.args);
if (this[methodName](args) == false) return;
hookiscalled = true;
}
if (!hookiscalled) {
switch (stateName) {
case 'playerTurnAction':
dojo.query(".hand > .card").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .tech.state_1.activatable").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .state_1.actionable").addClass('active_slot');
if (args.can_play_role_first) {
this.addActionButton('button_playrolefirst', _("Play Role first"), () => {
this.ajaxClientStateAction('skipAction');
});
} else {
this.addActionButton('button_skip', _("Skip Action"),
() => this.confirmationDialog(_("Please confirm if you don't want to take any action this turn."), () => this.ajaxClientStateAction('skipAction')));
}
break;
case 'playerTurnDiscard':
case 'playerTurnPreDiscard':
var hcards = dojo.query(".hand > .card");
hcards.addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .tech.state_1.activatable").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .tech.state_10.activatable").addClass('active_slot');
this.addDoneButton();
if (args.hand_size < hcards.length) {
this.setDescriptionOnMyTurn(_('${you} must discard from your hand down to ${hand_size} cards'));
};
if (stateName == 'playerTurnPreDiscard') {
this.addActionButton('button_wait', _("Wait"), () => this.ajaxClientStateAction('playWait'));
this.addTooltip('button_wait',
_("Now you can discard cards instead of waiting until end of turn. If you do your turn will end automatically."),
_("Click Wait to skip discarding now and do it after after player done following"), 1000);
}
break;
case 'playerTurnSurvey':
case 'playerTurnSurveyFollow':
case 'client_playerTurnSurvey':
dojo.query(".hand > .card_planet").addClass('active_slot');
break;
case 'playerTurnGameEnd':
this.addActionButton('button_skip', _("End Game"), dojo.hitch(this, function () {
this.ajaxClientStateAction('skipAction');
}));
break;
case 'playerTurnRole':
// hook
break;
case 'playerTurnFollow':
var role = args.role;
var div = this.createDiv("icon role " + role);
if ((role != 'S' && role != 'R') || args.active_follower == this.player_id) {
this.addImageActionButton('button_follow', _("Follow") + " " + div, () => {
this.clientStateArgs.role = role;
this.clientStateArgs.card = 'x_follow';
this.clientStateArgs.choices = [];
var pinfo = this.gamedatas.gamestate.args.pinfo[this.player_id];
//console.log("pinfo", pinfo);
// bureacracy
var bureacracy = this.playerHasOnTableau("card_tech_3_97");
if (bureacracy && (role != 'C' || role != 'W')) {
this.setClientStateAction('client_selectBoostOrLeader', '', 0, pinfo);
} else {
this.setClientStateAction('client_selectBoost', '', 0, pinfo);
}
});
var freedomOfTrade = this.playerHasOnTableau("card_tech_E_2");
if (freedomOfTrade) {
var as_role = '';
if (role == 'P') {
as_role = 'T';
} else if (role == 'T') {
as_role = 'P';
}
if (as_role) {
var div = this.createDiv("icon role " + as_role);
this.addImageActionButton('button_follow2', _("Follow as ") + " " + div, () => {
this.clientStateArgs.role = as_role;
this.clientStateArgs.card = 'x_follow';
this.clientStateArgs.choices = [];
var pinfo = this.gamedatas.gamestate.args.pinfo[this.player_id];
this.setClientStateAction('client_selectBoost', '', 0, pinfo);
});
}
}
} else {
var tip = _("Cannot follow out of order for this role, will wait until your turn");
this.addImageActionButton('button_follow_red', _("Follow") + " " + div, () => {
this.showMessage(tip, "info");
this.ajaxClientStateAction('playWait');
}, 'red', tip);
}
this.addActionButton('button_dissent', _("Dissent"), dojo.hitch(this, function () {
this.ajaxClientStateAction('playDissent');
}));
if (this.prefs[150].value == 2) { // auto dissent with timer
if (args.pinfo[this.player_id].can_follow == false) {
var timeout = parseInt(Math.random() * 10) + 10;
this.addButtonTimer('button_dissent', undefined, timeout);
}
}
if (args.active_follower != this.player_id) {
this.addActionButton('button_wait', _("Wait"), dojo.hitch(this, function () {
this.ajaxClientStateAction('playWait');
}));
if ($('button_follow_red')) {
this.addTooltip('button_wait', _("Cannot follow out of order for this role, will wait until your turn"),
_("Click Wait to stop the player turn timer and wait for your turn"), 1000);
} else
this.addTooltip('button_wait', _("Now you can make your move out of order since it won't interfere with other player. However you can press Wait and wait for your turn"),
_("Click Wait to stop the player turn timer and wait for your turn"), 1000);
}
break;
case 'client_selectRoleCard':
dojo.query(".board .card_role:not(.card_bottom):last-child").addClass('active_slot');
break;
case 'client_selectCardToRemove':
dojo.query(".hand > .card").addClass('active_slot');
this.addDoneButton();
var rules = this.clientStateArgs.unprocessed_choices.replace("!", "");
var total = rules.length;
if (total == 0) {
this
.setDescriptionOnMyTurn(_('Selected cards will be removed permanently, press Done to confirm'));
} else if (rules[0] == 'e') {
this.setDescriptionOnMyTurn(_('Select up to ${total} card(s) to remove from the game'), {
total: total
});
if (!dojo.hasClass(this.clientStateArgs.card, 'toremove') &&
!dojo.hasClass(this.clientStateArgs.card, 'permanent') &&
!dojo.hasClass(this.clientStateArgs.card, 'planet')) {
dojo.addClass(this.clientStateArgs.card, 'active_slot');
this.addActionButton('button_self', _("Remove Itself"), dojo.hitch(this, function () {
dojo.addClass(this.clientStateArgs.card, 'toremove');
this.commitOperationAndSubmit('e', this.clientStateArgs.card);
}));
}
} else if (rules[0] == 'E') {
this.setDescriptionOnMyTurn(_('Select any number of cards to remove from the game'), {
total: total
});
}
break;
case 'client_selectPlanetToProduce':
// var planets = this.gamedatas.gamestate.args.planets;
// console.log(planets);
// resource slot on planet
dojo.query(".tableau_" + this.player_color + " .planet.state_1.has_slots").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .tech.has_slots").addClass('active_slot');
this.setDescriptionOnMyTurn(_('Select a planet to produce: ${boost_count} left'), {
boost_count: this.clientStateArgs.unprocessed_choices.length
});
this.addActionButton('random', _('All Random'), () => {
// produce on random planets
var num = this.clientStateArgs.unprocessed_choices.length;
for (var i = 0; i < num; i++) {
if (!this.commitOperation('p', 'x_random', 'n', 'x')) {
break;
}
}
this.actionPromptAndCommit();
});
this.addDoneButton();
break;
case 'client_selectResourceToTrade':
// resource on planet and cards
var ress = dojo.query(".tableau_" + this.player_color + " .resource.state_2");
ress.addClass('active_slot');
// weapon emporium
if (this.getFirstChild(".tableau_" + this.player_color + " #card_tech_2_74")) {
dojo.query("#tableau_fighter_" + this.player_color + " .fighter_F:last-child").addClass('active_slot');
dojo.query("#tableau_" + this.player_color + " .fighter_F").addClass('active_slot');
dojo.query(".hand_" + this.player_color + " .card.as_fighter_F").addClass('active_slot');
}
// hand card as resources
dojo.query(".hand_" + this.player_color + " .card.as_resource").addClass('active_slot');
this.setDescriptionOnMyTurn(_('Select a resource to trade: ${boost_count} left'), {
boost_count: this.clientStateArgs.unprocessed_choices.length
});
if (ress.length > 0)
this.addActionButton('random', _('All Random'), () => {
// produce on random planets
var num = this.clientStateArgs.unprocessed_choices.length;
var allres = dojo.query(".tableau_" + this.player_color + " .resource.active_slot");
this.shuffleArray(allres);
for (var i = 0; i < num; i++) {
if (i >= allres.length) break;
var resource = allres[i].id;
var planet = allres[i].parentNode.id;
if (this.commitOperation('t', planet, resource)) {
dojo.removeClass(resource, 'active_slot');
this.placeTokenLocal(resource, 'setaside_' + this.player_color, 1)
}
}
this.actionPromptAndCommit();
});
this.addDoneButton();
break;
case 'client_selectResourceType':
// resource on planet
//dojo.query(".stock_resource .resource").addClass('active_slot');
//debugger;
var resources = ['w', 'f', 's', 'i'];
var handler = (restype) => {
this.commitOperationAndSubmit('y', restype);
}
if (this.gamedatas.gamestate.args.restypes) {
resources = this.gamedatas.gamestate.args.restypes;
for (var i in resources) {
var r = resources[i];
if (r == 'n') { // any
resources = ['w', 'f', 's', 'i'];
break;
}
}
}
if (this.gamedatas.gamestate.args.buthandler) {
handler = this.gamedatas.gamestate.args.buthandler;
}
for (var i in resources) {
var r = resources[i];
var div = this.createDiv("resource resource_" + r);
this.addImageActionButton('button_' + r, div, (event) => {
var id = event.currentTarget.id;
dojo.stopEvent(event);
var restype = id.replace("button_", "");
handler(restype);
});
}
if (resources.length == 1) {
// auto
setTimeout(() => handler(resources[0]), 300);
}
break;
case 'client_selectActionAttack':
this.setDescriptionOnMyTurn(_('Select a planet to attack'));
dojo.query(".tableau_" + this.player_color + " .card_planet.state_0").addClass('active_slot');
if (this.playerHasOnTableau('card_tech_E_38')) {
dojo.query(".tableau" + " .card_planet.state_1").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .card_planet.state_1").removeClass('active_slot');
}
if (this.clientStateArgs.card == 'card_tech_E_36') { // annex
dojo.query(".tableau" + " .card_planet.state_0").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .card_planet.state_0").removeClass('active_slot');
}
if (this.clientStateArgs.choices.length > 0) {
this.setDescriptionOnMyTurn(_('Select another planet to attack'));
this.addActionButton('button_skip', _("Skip Attack"), (e) => {
this.commitOperationAndSubmit('a', "skip");// XXX check if works on server
});
}
break;
case 'client_selectFaceDownPlanetSettleOnly':
dojo.query(".tableau_" + this.player_color + " .card_planet.state_0").addClass('active_slot');
var message = _('Select a planet to settle');
this.setDescriptionOnMyTurn(message);
this.addDoneButton();
break;
case 'client_selectFaceDownPlanet':
dojo.query(".tableau_" + this.player_color + " .card_planet.state_0").addClass('active_slot');
if (this.clientStateArgs.action == 'playAction') {
var rule = this.clientStateArgs.unprocessed_choices[0];
var message = _('${You} may select planet to settle or add colonies');
switch (rule) {
//.
case 's': // settle or +1 colony
this.addActionButton('button_settle', _("Settle 1 Planet"), dojo.hitch(this,
function () {
this.setClientStateAction('client_selectFaceDownPlanetSettleOnly');
}));
this.addImageActionButton('button_colony', _("+1 Colony ") + this.createDiv("icon colonize"), dojo.hitch(this,
function () {
this.clientStateArgs.unprocessed_choices = "c";
this.setClientStateAction('client_selectFaceDownPlanetColonize',
_('Select a planet to add a colony'));
}), 'blue');
break;
case 'S':// settle or skip
var message = _('${You} may select planet to settle or skip');
this.addActionButton('button_skip', _("Skip Settle"), dojo.hitch(this,
function () {
this.commitOperationAndSubmit('S', "skip");
}));
break;
default:
break;
}
this.setDescriptionOnMyTurn(message);
}
this.addDoneButton();
break;
case 'client_selectTechCard':
//debugger;
var totalResearch = args.perm_boost_count + args.hand_boost_count;
if (this.gamedatas.gamestate.args.extra) {
totalResearch = args.boost_rem;
}
var techs = this.gamedatas.gamestate.args.tech;
var settledTypes = 0;
for (tech in techs) {
var info = techs[tech];
if (info.canattack || info.b <= totalResearch) {
if (tech.startsWith('card_fleet_i')) {
dojo.query(".tableau_" + this.player_color + " .fleet_basic").addClass('active_slot');
} else
dojo.addClass(tech, 'active_slot');
}
settledTypes++;
}
if (dojo.query(".tech.active_slot").length == 0) {
if (settledTypes == 0)
this.showError(_("You cannot research any technologies, you need at least one settled planet"));
else if (totalResearch < 3)
this.showError(_("You cannot research any technologies, you need at least 3 reasearch icons or fleet"));
else if (!this.gamedatas.gamestate.args.extra)
this.showError(_("You cannot research any technologies"));
this.setDescriptionOnMyTurn(_('${You} cannot research'));
if (this.gamedatas.gamestate.args.extra) {
//
} else if (this.clientStateArgs.card != 'x_follow') {
this.addDoneButton(_("Forfeit Technology card, gain Role card only"));
} else {
this.addDoneButton(_("Forfeit Technology card"));
}
} else {
this.expandTech(true, ".tech.active_slot:not(.fleet_basic)", "selection_area");
this.addActionButton('button_skip', _('Forfeit Technology card, gain Role card only'), (e) => {
this.clientStateArgs.choices.push(['x']);
this.ajaxClientStateAction();
this.expandTech(false);
});
}
if (this.gamedatas.gamestate.args.extra) {
this.setMainTitle(this.getTokenName(this.gamedatas.gamestate.args.card) + ":", 'before');
}
break;
case 'client_selectFaceDownPlanetColonize':
dojo.query(".tableau_" + this.player_color + " .card_planet.state_0").addClass('active_slot');
dojo.query(".tableau_" + this.player_color + " .coloniseable").addClass('active_slot');
this.addDoneButton();
break;
case 'client_selectBoostOrLeader':
var info = this.getTokenDisplayInfo(this.clientStateArgs.card);
var laction;
if (info == null && this.clientStateArgs.card == 'x_follow') {
laction = this.clientStateArgs.role;
} else {
laction = info.l;
}
//console.log(laction, this.clientStateArgs);
this.setDescriptionOnMyTurn(_('${You} may choose leader bonus or select more role boost'));
switch (laction) {
case 'a':
case 'W':
this.addActionButton('button_attack', "<span class='yellow'>Leader:</span> Attack 1 Planet", dojo.hitch(this, function () {
this.clientStateArgs.unprocessed_choices = 'a';
this.setClientStateAction('client_selectActionAttack');
}));
break;
case 's':
case 'C':
this.addActionButton('button_settle', "<span class='yellow'>Leader:</span> Settle 1 Planet", dojo.hitch(this, function () {
this.clientStateArgs.unprocessed_choices = 's';
this.setClientStateAction('client_selectFaceDownPlanetSettleOnly');
}));
break;
default:
if (info != null && info.r == 'P/T') {
this.setDescriptionOnMyTurn(_('${You} must select between produce and trade'));
this.addImageActionButton('button_produce', this.createDiv("icon produce"), dojo.hitch(this,
function () {
this.clientStateArgs.role = 'P';
this.setClientStateAction('client_selectBoost');
}));
this.addImageActionButton('button_trade', this.createDiv("icon trade"), dojo.hitch(this, function () {
this.clientStateArgs.role = 'T';
this.setClientStateAction('client_selectBoost');
}));
dojo.destroy('button_skip');
this.addCancelButton();
} else {
this.setDescriptionOnMyTurn(_('${You} may select more role boost'));
}
break;
}
// fallthrough
case 'client_selectBoost':
var icon = this.clientStateArgs.role;
var hand_boost = args['hand_boost'][icon];
var possible_boost = 0;
if (hand_boost) {
for (var card in hand_boost) {
if ($(card)) dojo.addClass(card, 'active_slot');
possible_boost++;
}
}
args.perm_boost_count = args['perm_boost_num'][icon];
if (!args.hand_boost_count) {
if (this.clientStateArgs.card.startsWith('x_')) {
args.hand_boost_count = 0;
} else {
args.hand_boost_count = 1; // role itself
//possible_boost++;
}
}
if (icon == 'C') {
args.perm_boost_count = 0;
} else if (getPart(this.clientStateArgs.card, 2) == 'bottom') {
args.perm_boost_count++; // Empty stack gives 1 boost except for Colonize
}
//console.log(this.clientStateArgs.card);
if (stateName != 'client_selectBoostOrLeader') {
this.setDescriptionOnMyTurn(_('${You} may select more role boost'));
}
var follow = this.clientStateArgs.card == 'x_follow';
var total = args.perm_boost_count + args.hand_boost_count;
var messagex = '${icon} x ${total}'; // when 1 - keep number 1 there
if (total == 2)
messagex = '${icon}${icon}';
else if (total == 3)
messagex = '${icon}${icon}${icon}';
else if (total == 4)
messagex = '${icon}${icon}${icon}${icon}';
if (possible_boost)
messagex += ' ' + ('(unused boost ${remaining_boost})');
var icondiv = this.format_string_recursive(messagex, {
icon: this.createDiv("icon " + this.clientStateArgs.role),
total: total,
remaining_boost: possible_boost
});
args.possible_boost = possible_boost;
if (this.clientStateArgs.role == 'S') {
var thorough_survery = this.playerHasOnTableau('card_tech_E_24')
var lookup = total - 1;
if (!follow) lookup++;
if (thorough_survery && lookup - 2 >= 2) {
var div = _("Execute with Thorough Survey ") + " " + icondiv;
var but = this.addImageActionButton('button_done_' + total + "_ts", div, 'onExecuteRole', 'blue');
var ll = lookup - 2;
this.addTooltip(but.id, _('Draw') + " " + ll + " - " + _('Keep 2'), '', 1000);
}
var div = _("Execute Role ") + " " + icondiv;
var col = 'blue';
if (lookup <= 0) col = 'red';
var but = this.addImageActionButton('button_done_' + total, div, 'onExecuteRole', col);
this.addTooltip(but, _('Draw') + " " + lookup + " - " + _('Keep 1'), '', 1000);
} else if (this.clientStateArgs.role != 'P/T') {
var div = _("Execute Role ") + " " + icondiv;
this.addImageActionButton('button_done_' + total, div, 'onExecuteRole', 'blue');
}
break;
case 'client_confirm':
this.addDoneButton('Confirm');
break;
}
}
if (this.on_client_state && !this.clientStateArgs.nocancel) {
this.addCancelButton();
}
if (this.clientStateArgs.boost) {
var str = this.clientStateArgs.boost;
var choices_arr = str.trim().split(' ');
for (var i = 0; i < choices_arr.length; i++) {
var element = choices_arr[i];
if ($(element)) dojo.addClass(element, 'selected');
else
console.error("Unknown node for selection: ", element);
}
}
if (this.clientStateArgs.choices) {
var choices_arr = this.clientStateArgs.choices;
for (var i = 0; i < choices_arr.length; i++) {
var element_a = choices_arr[i];
var operands = element_a;
var element = operands.length > 1 ? operands[1] : operands[0];
if ($(element)) dojo.addClass(element, 'selected');
else if (element == 'x' || element == 'z') {
// skip
} else
console.error("Unknown node for selection", element, choices_arr);
}
}
if (this.clientStateArgs.card && $(this.clientStateArgs.card)) dojo.addClass(this.clientStateArgs.card, 'selected');
// this.updateBreadCrumbs(this.on_client_state);
},
// /////////////////////////////////////////////////
// // Utility methods
/*
*
* Here, you can defines some utility methods that you can use everywhere in your javascript script.
*
*/
getPlaceRedirect: function (token, tokenInfo) {
if (!tokenInfo) {
return {
location: 'dev_null',
inlinecoords: false,
temp: true
};
}
var location = tokenInfo.location;
var result = {
location: location,
inlinecoords: false
};
if (location.startsWith('discard_planets')) {
// nothing
} else if (location == 'discard_display') {
result.createOn = 'discard_' + this.player_color;
} else if (location == 'deck_display') {
result.createOn = 'deck_' + this.player_color;
} else if (location.startsWith('discard_' + this.player_color)) {
result.temp = true;
} else if (location.startsWith('discard')) {
result.temp = true;
} else if (location.startsWith('dev_null')) {
result.temp = true;
} else if (location.startsWith('tableau') && token.startsWith('card')) {
// result.location = token + "_group";
result.createOn = location;
var color = getPart(location, 1);
var sep = '';
if (token.startsWith('scenario')) {
sep = "sep_scenario_" + color;
} else {
var cardtype = getPart(token, 1);
if (cardtype == 'planet') {