/
nineteensixtynine.game.php
686 lines (583 loc) · 27.7 KB
/
nineteensixtynine.game.php
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
<?php
/**
*------
* BGA framework: © Gregory Isabelli <gisabelli@boardgamearena.com> & Emmanuel Colin <ecolin@boardgamearena.com>
* nineteensixtynine implementation : © <Your name here> <Your email address here>
*
* 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.
* -----
*
* nineteensixtynine.game.php
*
* This is the main file for your game logic.
*
* In this PHP file, you are going to defines the rules of the game.
*
*/
require_once( APP_GAMEMODULE_PATH.'module/table/table.game.php' );
class nineteensixtynine extends Table
{
function nineteensixtynine( )
{
parent::__construct();
self::initGameStateLabels( array(
"current_income_turn" => 10,
"current_purchase_turn" => 11,
"current_mission_turn" => 12,
"current_intelligence_turn" => 13,
"current_round" => 14,
"pending_person_type" => 30
) );
$this->playerBoardTypeList = array('astronautics','ground-control','insurance','intelligence','investors',
'launchpad','lunar-module','orbital-module','robotics','simulation','technology','vector-rocket');
}
function personTypeToInt($personType) {
$keys = array_keys($this->matScientistList);
$search = array_search($personType, $keys);
return $search === false ? 10 : $search;
}
function intToPersonType($personTypeInt) {
if($personTypeInt == 10) return 'spy';
$keys = array_keys($this->matScientistList);
return $keys[$personTypeInt];
}
protected function getGameName( )
{
return "nineteensixtynine";
}
/*
setupNewGame:
This method is called only once, when a new game is launched.
In this method, you must setup the game according to the game rules, so that
the game is ready to be played.
*/
protected function setupNewGame( $players, $options = array() )
{
$sql = "DELETE FROM player WHERE 1 ";
self::DbQuery( $sql );
$default_colors = array( "ff0000", "008000", "0000ff", "ffa500", "773300" );
shuffle($this->matCountries);
$sql = "INSERT INTO player (player_id, player_color, player_canal, player_name, player_avatar, player_country) VALUES ";
$values = array();
foreach( $players as $player_id => $player ) {
$color = array_shift( $default_colors );
$country = array_shift ($this->matCountries );
$values[] = "('".$player_id."','$color','".$player['player_canal']."','".addslashes( $player['player_name'] )."','".addslashes( $player['player_avatar'] )."','".$country."')";
}
$sql .= implode( $values, ',' );
self::DbQuery( $sql );
self::reloadPlayersBasicInfos();
$this->DbQuery( "UPDATE player SET player_score = 2" );
/*
//create scientists
foreach($this->matScientistList as $type => $scientist) {
foreach(range(1, $scientist['quantity']) as $i)
$this->DbQuery( "INSERT INTO scientist(type, location) VALUES('$type', 'board')" );
}
//create spies
foreach(range(1, 10) as $i) $this->DbQuery( "INSERT INTO spy(location) VALUES('board')" );
*/
//create playerboard
foreach($players as $player_id => $player) {
foreach($this->playerBoardTypeList as $type) {
foreach(range(1, 2) as $i) $this->DbQuery( "INSERT INTO playerboard(player_id, number, type) VALUES($player_id, $i, '$type')" );
$this->DbQuery( "INSERT INTO playerboard_spy(player_id, type) VALUES($player_id, '$type')" );
}
}
//create cards
foreach($this->matIntelligenceCards as $card) {
$point = $card['point'];
for($i = 0; $i < $card['quantity']; $i++) {
$this->DbQuery( "INSERT INTO intelligence_card(point, location, position) VALUES($point, 'deck', 0)" );
}
}
$cardList = $this->getObjectListFromDB("SELECT id from intelligence_card");
shuffle($cardList);
foreach($cardList as $index => $card) {
$id = $card['id'];
$this->DbQuery( "UPDATE intelligence_card SET position = $index WHERE id = $id" );
}
//new game bug
$this->setGameStateValue("current_round", 1);
$this->setGameStateValue("current_income_turn", 1);
$this->activeNextPlayer();
}
/*
getAllDatas:
Gather all informations about current game situation (visible by the current player).
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)
*/
protected function getAllDatas()
{
$result = array( 'players' => array() );
$current_player_id = self::getCurrentPlayerId(); // !! We must only return informations visible by this player !!
// Get information about players
// Note: you can retrieve some extra field you added for "player" table in "dbmodel.sql" if you need it.
$sql = "SELECT player_id id, player_score score, player_money money, player_country country FROM player ";
$result['players'] = self::getCollectionFromDb( $sql );
$result['currentRound'] = $this->getGameStateValue("current_round");
$result['playersheet'] = $this->getObjectListFromDB("SELECT player_id as playerId, type AS sheetType, scientist_type AS scientistType, number AS number FROM playerboard WHERE scientist_type IS NOT NULL" );
$result['playersheetSpy'] = $this->getObjectListFromDB("SELECT player_id as playerId, type AS sheetType FROM playerboard_spy WHERE playerboard_id IS NOT NULL");
$result['playerCardNumber'] = $this->getCollectionFromDB("SELECT player_id as playerId, COUNT(*) as countCard FROM intelligence_card WHERE location = 'player' GROUP BY player_id");
foreach($this->loadPlayersBasicInfos() as $playerId => $playerData) {
if(!array_key_exists($playerId, $result['playerCardNumber'])) {
$result['playerCardNumber'][$playerId] = array('playerId' => $playerId, 'countCard' => 0);
}
}
$result['myIntelligenceCard'] = $this->getObjectListFromDB("SELECT * FROM intelligence_card where player_id = $current_player_id");
return $result;
}
/*
getGameProgression:
Compute and return the current game progression.
The number returned must be an integer beween 0 (=the game just started) and
100 (= the game is finished or almost finished).
This method is called each time we are in a game state with the "updateGameProgression" property set to true
(see states.inc.php)
*/
function getGameProgression()
{
// TODO: compute and return the game progression
return 0;
}
//////////////////////////////////////////////////////////////////////////////
//////////// Utility functions
////////////
/*
In this space, you can put any utility methods useful for your game logic
*/
function dbIncScorePoint($playerId, $scorePoint) {
$this->DbQuery("UPDATE player SET player_score = player_score + $scorePoint WHERE player_id = $playerId");
}
function dbIncMoney($playerId, $money) {
$this->DbQuery("UPDATE player SET player_money = player_money + $money WHERE player_id = $playerId");
}
function dbGetMoney($playerId) {
$player = $this->getObjectFromDB( "SELECT player_money money FROM player WHERE player_id='$playerId'" );
return $player['money'];
}
function dbGetPrestige($playerId) {
$player = $this->getObjectFromDB( "SELECT player_score score FROM player WHERE player_id='$playerId'" );
return $player['score'];
}
/*
* Return if a scientist type is still available to play
* @params $scientistType the type of scientist
* @return Boolean
*/
function dbAreScientistsAvailable($scientistType) {
$counter = $this->getObjectFromDB( "SELECT COUNT(*) AS count FROM playerboard WHERE scientist_type = '$scientistType'" );
return $counter['count'] < $this->matScientistList[$scientistType]['quantity'];
}
/*
* Return if spies are still available to play
* @params $scientistType the type of scientist
* @return Boolean
*/
function dbAreSpiesAvailable() {
$counter = $this->getObjectFromDB( "SELECT COUNT(*) AS count FROM playerboard WHERE scientist_type = 'spy'" );
return $counter['count'] < $this->matSpy['quantity'];
}
function dbAreIntelligenceCardsAvailable() {
$counter = $this->getObjectFromDB( "SELECT COUNT(*) AS count FROM intelligence_card WHERE location = 'deck'" );
return $counter['count'] > 0;
}
/*
* Fill an empty playerboard with a scientist
* @param $scientistType
* @param $playerId
* @param $sheetType
* @return Number scientistNumber just inserted
*/
function dbPurchaseScientist($scientistType, $playerId, $sheetType) {
$toUpdate = $this->getObjectFromDB("SELECT id, number FROM playerboard WHERE player_id = $playerId AND type = '$sheetType' AND scientist_type IS NULL ORDER BY number LIMIT 1");
$toUpdateId = $toUpdate['id'];
$this->DbQuery("UPDATE playerboard SET scientist_type = '$scientistType' WHERE id = $toUpdateId");
return $toUpdate;
}
/*
* Fill an empty playerboard_spy with a spy
* @param $playerId
* @param $sheetType
*/
function dbPurchaseSpy($playerId, $sheetType, $playerBoardId) {
$this->DbQuery("UPDATE playerboard_spy SET playerboard_id = $playerBoardId WHERE player_id = $playerId AND type = '$sheetType'");
}
function dbPurchaseIntelligenceCard($playerId) {
$card = $this->getObjectFromDB('SELECT * FROM intelligence_card WHERE location="deck" ORDER BY position LIMIT 1');
$cardId = $card['id'];
$this->DbQuery("UPDATE intelligence_card SET location='player', player_id=$playerId WHERE id = $cardId");
return $card;
}
/*
* Returns assumable spies
* @params $currentPlayer Id of current player
* @return List of available sheet grouped by playerId
*/
function dbGetAssumableSpies($currentPlayerId) {
//TODO controllare spie già piazzate dal giocatore
//posso piazzare tranne in questi casi: 1- ho già piazzato una spia del tipo corrente, 2- il destinatario ha già una spia sulla plancia
$return = array();
$availableSheetList = $this->getObjectListFromDB("SELECT type FROM playerboard_spy WHERE player_id = $currentPlayerId AND playerboard_id IS NULL");
$playerIdList = array_keys($this->loadPlayersBasicInfos());
foreach($playerIdList as $playerId) if($playerId != $currentPlayerId) {
$tempPlayer = array();
foreach($availableSheetList as $sheet) {
$sheetType = $sheet['type'];
$counter = $this->getObjectFromDB("SELECT COUNT(*) AS count FROM playerboard WHERE player_id = $playerId AND type = '$sheetType' AND scientist_type = 'spy'");
if($counter['count'] == 0) {
$tempPlayer[] = $sheetType;
}
}
$return[$playerId] = $tempPlayer;
}
return $return;
//return $this->getObjectListFromDB("SELECT owner_player_id AS player_id, owner_type AS type FROM playerboard_spy WHERE owner_player_id <> $currentPlayer AND spy_id IS NULL");
}
//////////////////////////////////////////////////////////////////////////////
//////////// Validation functions
////////////
function valUserHasMoney($playerId, $requiredMoney, $exception = true) {
$money = $this->dbGetMoney($playerId);
$hasMoney = $money >= $requiredMoney;
if($exception && !$hasMoney) {
throw new BgaUserException( self::_("You have not enough money to take this action") );
}
return $hasMoney;
}
function valUserHasPrestige($playerId, $prestige, $exception = true) {
$score = $this->dbGetPrestige($playerId);
$hasPrestige = $score >= $prestige;
if($exception && !$hasPrestige) {
throw new BgaUserException( self::_("You have not enough prestige points to take this action") );
}
return $hasPrestige;
}
function valScientistIsAvailable($scientist, $exception = true) {
$available = $this->dbAreScientistsAvailable($scientist);
if($exception && !$available) {
throw new BgaUserException( self::_("This kind of scientist is no more available to hire") );
}
return $available;
}
function valSpiesAreAvailable($exception = true) {
$available = $this->dbAreSpiesAvailable();
if($exception && !$available) {
throw new BgaUserException( self::_("Spies are no more available to hire") );
}
return $available;
}
function valIntelligenceCardsAreAvailable($exception = true) {
$available = $this->dbAreIntelligenceCardsAvailable();
if($exception && !$available) {
throw new BgaUserException( self::_("Intelligence Cards are no more available to draw") );
}
return $available;
}
function valScientistIsPurchasable($playerId, $scientistType, $sheetType, $exception = true) {
$fromDb = $this->getObjectListFromDB("SELECT scientist_type as type FROM playerboard WHERE player_id = $playerId AND type = '$sheetType' AND scientist_type IS NOT NULL");
if(count($fromDb) == 0) {
$purchasable = true;
} else if(count($fromDb) > 1) {
$purchasable = false;
} else {
if($scientistType == 'basic') $purchasable = true;
else {
$purchasable = $fromDb[0]['type'] != $scientistType;
}
}
if($exception && !$purchasable) {
throw new BgaUserException( self::_("You cannot assume this scientist on this research box") );
}
return $purchasable;
}
function valSpyIsPurchasable($currentPlayerId, $sheetType, $targetPlayerId, $exception = true) {
if($currentPlayerId == $targetPlayerId) {
$purchasable = false;
} else {
$availableSheetList = $this->getObjectListFromDB("SELECT type FROM playerboard_spy WHERE player_id = $currentPlayerId AND playerboard_id IS NULL");
if(!in_array($sheetType, array_map(create_function('$o', 'return $o[\'type\'];'), $availableSheetList))) {
$purchasable = false;
} else {
$counter = $this->getObjectFromDB("SELECT COUNT(*) AS count FROM playerboard WHERE player_id = $targetPlayerId AND type = '$sheetType' AND scientist_type = 'spy'");
$purchasable = $counter['count'] == 0;
}
}
if($exception && !$purchasable) {
throw new BgaUserException( self::_("You cannot assume spy on this research box") );
}
return $purchasable;
}
//////////////////////////////////////////////////////////////////////////////
//////////// Player actions
////////////
/*
Each time a player is doing some game action, one of the methods below is called.
(note: each method below must match an input method in nineteensixtynine.action.php)
*/
function acConfirmIncome($status) {
$playerId = $this->getActivePlayerId();
$playerName = $this->getActivePlayerName();
if($status > 0) $this->valUserHasPrestige($playerId, $status);
$currentRound = $this->getGameStateValue("current_round");
if($status == 0) {
$income = $currentRound + 11;
$this->notifyAllPlayers("message", clienttranslate('${playerName} takes default income: ${income}M'), array(
"playerName" => $playerName,
"income" => $income
));
} else {
$income = $currentRound + 11 + $status * 2;
$this->notifyAllPlayers("message", clienttranslate('${playerName} takes extra income: ${income}M and loses ${prestige} prestige'), array(
"playerName" => $playerName,
"income" => $income,
"prestige" => $status
));
}
$this->dbIncMoney($playerId, $income);
$this->notifyAllPlayers("moneyChanged", "", array(
"playerId" => $playerId,
"money" => $income
));
if($status > 0) {
$this->dbIncScorePoint($playerId, -($status));
$this->notifyAllPlayers("scorePointAcquired", "", array(
"playerId" => $playerId,
"scorePoint" => -($status)
));
}
$this->gamestate->nextState('afterIncome');
}
function acPurchaseScientist($scientistType) {
$playerId = $this->getActivePlayerId();
$playerName = $this->getActivePlayerName();
$this->valScientistIsAvailable($scientistType);
$this->valUserHasMoney($playerId, $this->matScientistList[$scientistType]['price']);
$this->setGameStateValue("pending_person_type", $this->personTypeToInt($scientistType));
$this->notifyAllPlayers("message", clienttranslate('${playerName} purchases a ${type} scientist.'), array(
"playerName" => $playerName,
"type" => $this->matScientistList[$scientistType]['name']
));
$this->gamestate->nextState('placeScientist');
}
function acPurchaseSpy() {
$playerId = $this->getActivePlayerId();
$playerName = $this->getActivePlayerName();
$this->valSpiesAreAvailable();
$this->valUserHasMoney($playerId, $this->matSpy['price']);
$this->setGameStateValue("pending_person_type", $this->personTypeToInt('spy'));
$this->notifyAllPlayers("message", clienttranslate('${playerName} purchases a spy.'), array(
"playerName" => $playerName
));
$this->gamestate->nextState('placeSpy');
}
function acPurchaseCard() {
$playerId = $this->getActivePlayerId();
$playerName = $this->getActivePlayerName();
$this->valIntelligenceCardsAreAvailable();
$this->valUserHasMoney($playerId, 2);
$purchasedCard = $this->dbPurchaseIntelligenceCard($playerId);
$this->dbIncMoney($playerId, -2);
$this->notifyAllPlayers("moneyChanged", "", array(
"playerId" => $playerId,
"money" => -2
));
$this->notifyAllPlayers("intelligenceCardPurchased", "", array(
"playerId" => $playerId
));
$this->notifyPlayer($playerId, "intelligenceCardDrawn", "", array(
"intelligenceCard" => $purchasedCard
));
$this->notifyAllPlayers("message", clienttranslate('${playerName} purchases an intellingece card.'), array(
"playerName" => $playerName
));
$this->notifyPlayer($playerId, "message", clienttranslate('You have drawn an intellingece card with value ${value}.'), array(
"value" => $purchasedCard['point']
));
}
function acConfirmScientistPlace($sheetType) {
$pendingScientistType = $this->intToPersonType($this->getGameStateValue("pending_person_type"));
//TODO ha senso rimuovere il pending o chissenefrega?
$playerId = $this->getActivePlayerId();
$pendingScientistCost = $this->matScientistList[$pendingScientistType]['price'];
$this->valScientistIsPurchasable($playerId, $pendingScientistType, $sheetType);
$purchasedScientist = $this->dbPurchaseScientist($pendingScientistType, $playerId, $sheetType);
$this->dbIncMoney($playerId, -$pendingScientistCost);
$this->notifyAllPlayers("moneyChanged", "", array(
"playerId" => $playerId,
"money" => -$pendingScientistCost
));
$this->notifyAllPlayers("scientistPurchased", "", array(
"playerId" => $playerId,
"scientistType" => $pendingScientistType,
"sheetType" => $sheetType,
"number" => $purchasedScientist['number']
));
//TODO notifica messaggio
$this->gamestate->nextState('purchase');
}
function acConfirmSpyPlace($sheetType, $targetPlayerId) {
$playerId = $this->getActivePlayerId();
$spyCost = $this->matSpy['price'];
$this->valSpyIsPurchasable($playerId, $sheetType, $targetPlayerId);
$purchasedSpy = $this->dbPurchaseScientist('spy', $targetPlayerId, $sheetType);
$this->dbPurchaseSpy($playerId, $sheetType, $purchasedSpy['id']);
$this->dbIncMoney($playerId, -$spyCost);
$this->notifyAllPlayers("moneyChanged", "", array(
"playerId" => $playerId,
"money" => -$spyCost
));
$this->notifyAllPlayers("scientistPurchased", "", array(
"playerId" => $targetPlayerId,
"scientistType" => 'spy',
"sheetType" => $sheetType,
"number" => $purchasedSpy['number']
));
$this->notifyAllPlayers("spyPurchased", "", array(
"playerId" => $playerId,
"sheetType" => $sheetType
));
//TODO notifica messaggio
$this->gamestate->nextState('purchase');
}
function acPass() {
$this->gamestate->nextState('afterPurchase');
}
//////////////////////////////////////////////////////////////////////////////
//////////// Game state arguments
////////////
/*
Here, you can create methods defined as "game state arguments" (see "args" property in states.inc.php).
These methods function is to return some additional information that is specific to the current
game state.
*/
function argPurchase() {
$availableScientists = array();
$playerId = $this->getActivePlayerId();
//TODO need to check also if player has free space for each kind of scientists
foreach($this->matScientistList as $type => $scientist) {
$quantity = $scientist['quantity'];
if($this->valScientistIsAvailable($type, false)) {
if($this->valUserHasMoney($playerId, $scientist['price'], false)) {
$availableScientists[] = $type;
}
}
}
$availableSpies = $this->valSpiesAreAvailable(false) && $this->valUserHasMoney($playerId, $this->matSpy['price'], false);
$availableIntelligenceCards = $this->valIntelligenceCardsAreAvailable(false) && $this->valUserHasMoney($playerId, 2, false);
return array(
"availableScientists" => $availableScientists,
"availableSpies" => $availableSpies,
"availableIntelligenceCards" => $availableIntelligenceCards
);
}
function argPlaceScientist() {
$pendingScientistType = $this->intToPersonType($this->getGameStateValue("pending_person_type"));
$playerId = $this->getActivePlayerId();
$availableSheets = array();
foreach($this->playerBoardTypeList as $type) {
if($this->valScientistIsPurchasable($playerId, $pendingScientistType, $type, false)) $availableSheets[] = $type;
}
return array(
"availableSheets" => $availableSheets
);
}
function argPlaceSpy() {
$availableSheets = array();
$currentPlayerId = $this->getActivePlayerId();
$playerIdList = array_keys($this->loadPlayersBasicInfos());
foreach($playerIdList as $playerId) if($playerId != $currentPlayerId) {
$tempPlayer = array();
foreach($this->playerBoardTypeList as $sheetType) {
if($this->valSpyIsPurchasable($currentPlayerId, $sheetType, $playerId, false)) {
$tempPlayer[] = $sheetType;
}
}
$availableSheets[$playerId] = $tempPlayer;
}
return array(
"availableSheets" => $availableSheets
);
}
//////////////////////////////////////////////////////////////////////////////
//////////// Game state actions
////////////
/*
Here, you can create methods defined as "game state actions" (see "action" property in states.inc.php).
The action method of state X is called everytime the current game state is set to X.
*/
function stBeforeRound() {
$currentRound = $this->incGameStateValue("current_round", 1);
$this->setGameStateValue("current_income_turn", 0);
$this->setGameStateValue("current_purchase_turn", 0);
$this->notifyAllPlayers("message", clienttranslate('Round ${currentRound} started!'), array(
"currentRound" => $currentRound
));
$this->notifyAllPlayers("newRound", "", array(
"currentRound" => $currentRound
));
$this->activeNextPlayer(); //to activate the next from the previous first player
$this->gamestate->nextState("beforeIncome");
}
function stBeforeIncome() {
$this->incGameStateValue("current_income_turn", 1);
$this->activeNextPlayer();
$this->gamestate->nextState("income");
}
function stAfterIncome() {
$currentIncomeTurn = $this->getGameStateValue("current_income_turn");
if($currentIncomeTurn == $this->getPlayersNumber()) $this->gamestate->nextState("beforePurchase");
else $this->gamestate->nextState("beforeIncome");
}
function stBeforePurchase() {
$this->incGameStateValue("current_purchase_turn", 1);
$this->activeNextPlayer();
$this->gamestate->nextState("purchase");
}
function stAfterPurchase() {
$currentPurchaseTurn = $this->getGameStateValue("current_purchase_turn");
if($currentPurchaseTurn == self::getPlayersNumber()) $this->gamestate->nextState("afterRound");
else $this->gamestate->nextState("beforePurchase");
}
function stAfterRound() {
$currentRound = $this->getGameStateValue("current_round");
if($currentRound == 7) $this->gamestate->nextState("gameEnd");
else $this->gamestate->nextState("beforeRound");
}
//////////////////////////////////////////////////////////////////////////////
//////////// Zombie
////////////
/*
zombieTurn:
This method is called each time it is the turn of a player who has quit the game (= "zombie" player).
You can do whatever you want in order to make sure the turn of this player ends appropriately
(ex: pass).
*/
function zombieTurn( $state, $active_player )
{
$statename = $state['name'];
if ($state['type'] == "activeplayer") {
switch ($statename) {
default:
$this->gamestate->nextState( "zombiePass" );
break;
}
return;
}
if ($state['type'] == "multipleactiveplayer") {
// Make sure player is in a non blocking status for role turn
$sql = "
UPDATE player
SET player_is_multiactive = 0
WHERE player_id = $active_player
";
self::DbQuery( $sql );
$this->gamestate->updateMultiactiveOrNextState( '' );
return;
}
throw new feException( "Zombie mode not supported at this game state: ".$statename );
}
}