forked from jpeterbaker/bga_homeworlds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomeworlds.action.php
122 lines (110 loc) · 4.14 KB
/
homeworlds.action.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
<?php
/**
*------
* BGA framework: © Gregory Isabelli <gisabelli@boardgamearena.com> & Emmanuel Colin <ecolin@boardgamearena.com>
* Homeworlds implementation : © <Jonathan Baker> <babamots@gmail.com>
*
* This code has been produced on the BGA studio platform for use on https://boardgamearena.com.
* See http://en.doc.boardgamearena.com/Studio for more information.
* -----
*
* homeworlds.action.php
*
* Homeworlds main action entry point
*
*
* In this file, you are describing all the methods that can be called from your
* user interface logic (javascript).
*
* If you define a method "myAction" here, then you can call it from your javascript code with:
* this.ajaxcall( "/homeworlds/homeworlds/myAction.html", ...)
*
*/
class action_homeworlds extends APP_GameAction {
// Constructor: please do not modify
public function __default() {
if( self::isArg( 'notifwindow') ) {
$this->view = "common_notifwindow";
$this->viewArgs['table'] = self::getArg( "table", AT_posint, true );
}
else {
$this->view = "homeworlds_homeworlds";
self::trace( "Complete reinitialization of board game" );
}
}
// Define your action entry points there
public function act_creation(){
self::setAjaxMode();
$star1_id = self::getArg('star1_id','AT_posint',true);
$star2_id = self::getArg('star2_id','AT_posint',true);
$ship_id = self::getArg('ship_id' ,'AT_posint',true);
$this->game->creation($star1_id,$star2_id,$ship_id);
self::ajaxResponse();
}
public function act_power_action(){
self::setAjaxMode();
$power = self::getArg('power','AT_posint',true);
$piece_id = self::getArg('piece_id','AT_posint',false);
switch($power){
case 1:
$capture_id = self::getArg('capture_id','AT_posint',true);
$this->game->capture($piece_id,$capture_id);
break;
case 2:
$is_discovery = self::getArg('is_discovery','AT_bool',true);
if($is_discovery){
$star_color_num = self::getArg('star_color_num','AT_posint',true);
$star_pips = self::getArg('star_pips' ,'AT_posint',true);
$this->game->discover($piece_id,$star_color_num,$star_pips);
}
else{
$system_id = self::getArg('system_id','AT_posint',true);
$this->game->move($piece_id,$system_id);
}
break;
case 3:
$color_num = self::getArg('color_num','AT_posint',true);
$system_id = self::getArg('system_id','AT_posint',true);
$this->game->build($color_num,$system_id);
break;
case 4:
$color_num = self::getArg('color_num','AT_posint',true);
$this->game->trade($piece_id,$color_num);
break;
}
self::ajaxResponse();
}
public function act_sacrifice(){
self::setAjaxMode();
$ship_id = self::getArg('ship_id','AT_posint',true);
$this->game->sacrifice($ship_id);
self::ajaxResponse();
}
public function act_catastrophe(){
self::setAjaxMode();
$system_id = self::getArg('system_id','AT_posint',true);
$color = self::getArg('color','AT_posint',true);
$this->game->catastrophe($system_id,$color);
self::ajaxResponse();
}
public function act_pass(){
self::setAjaxMode();
$this->game->pass();
self::ajaxResponse();
}
public function act_restart_turn(){
self::setAjaxMode();
$this->game->restart();
self::ajaxResponse();
}
public function act_offer_draw(){
self::setAjaxMode();
$this->game->offer_draw();
self::ajaxResponse();
}
public function act_cancel_offer_draw(){
self::setAjaxMode();
$this->game->cancel_offer_draw();
self::ajaxResponse();
}
}