c5221ef1747b492ae6c59ba596f211f8d44cf08c
[brisk.git] / web / briskin5 / Obj / rules_together17.phh
1 <?php
2 /*
3  *  brisk - rules_together17.phh
4  *
5  *  Copyright (C) 2017 Matteo Nastasi
6  *                          mailto: nastasi@alternativeoutput.it
7  *                                  matteo.nastasi@milug.org
8  *                          web: http://www.alternativeoutput.it
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details. You should have received a
19  * copy of the GNU General Public License along with this program; if
20  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21  * Suite 330, Boston, MA 02111-1307, USA.
22  *
23  */
24
25 require_once("briskin5.phh");
26 require_once("rules_base.phh");
27
28 class Rules_together17 extends Rules_no_draw {
29     function __construct($table)
30     {
31         parent::__construct($table);
32         $this->id = 4;
33     }
34
35     function tourn_points(&$user, $user_pos)
36     {
37         $card = $this->table->card;
38         unset($user->asta_tourn_pts);
39         $user->asta_tourn_pts = array(0, 0, 0, 0);
40         $tourn_values = array(11, 10, 4,3,2, 1,1,1,1,1);
41
42         for ($i = 0 ; $i < BIN5_PLAYERS_N * BIN5_CARD_HAND ; $i++) {
43
44             if ($card[$i]->owner == $user_pos) {
45                 $user->asta_tourn_pts[(int)($i / 10)] += $tourn_values[$i % 10];
46             }
47         }
48     }
49
50     function tourn_points_max($user)
51     {
52
53         $mx = 0;
54         for ($i = 0 ; $i < 4 ; $i++) {
55             error_log("tourn_pts_max ");
56             error_log(print_r($user->asta_tourn_pts, TRUE));
57             if ($user->asta_tourn_pts[$i] > $mx) {
58                 $mx = $user->asta_tourn_pts[$i];
59             }
60         }
61
62         return $mx;
63     }
64
65     function rules_asta(&$bri, $curtime, $action, $user, &$ret_s, $a_card, $a_pnt) {
66         /*
67 Per le chiamate da 62 a 70 bisognerà avere 13 punti ( esempi.: asso e fante oppure tre
68 e cavallo oppure re, cavallo, fante, sette, sei, cinque, quattro) ;
69 Per chiamate da 71 ad 80 bisognerà avere 19 punti ( esempi.: asso, re, cavallo e 6
70 oppure tre, re, fante, 7, 6 e 5 );
71 Per chiamate da 81 a 90 bisognerà avere 23 punti ( esempi.: asso, tre e fante oppure
72 asso, re, cavallo, fante, 6, 5 e 4);
73 Per chiamate da 91 a 100 bisognerà avere 25 punti ( esempi.: asso, tre, re e 7 oppure
74 asso, tre, cavallo e fante );
75 Per chiamate da 101 a 120 bisognerà avere 28 punti ( esempi.:asso, tre, re e cavallo
76 oppure asso, tre, cavallo, 7, 6, 5 e 4 ).
77         */
78
79         $index_cur = $this->table->gstart % BIN5_PLAYERS_N;
80
81         // Abbandono dell'asta
82         if ($a_card <= -1) {
83             log_wr("Abbandona l'asta.");
84             $this->table->asta_pla[$index_cur] = FALSE;
85             $user->asta_card  = -1;
86             $this->table->asta_pla_n--;
87
88             return TRUE;
89         }
90         else if ($a_card <= 9) {
91             $ret_s = "";
92
93             do {
94                 if ($a_card >= 0 && $a_card < 9 && $a_card > $this->table->asta_card) {
95                     return TRUE;
96                 }
97                 else if ($a_card == 9 &&
98                          $a_pnt > ($this->table->asta_pnt >= 61 ? $this->table->asta_pnt : 60)
99                          && $a_pnt <= 120) {
100                     if ($a_pnt < 71)
101                         $min_pts = 13;
102                     else if ($a_pnt < 80)
103                         $min_pts = 19;
104                     else if ($a_pnt < 90)
105                         $min_pts = 23;
106                     else if ($a_pnt < 100)
107                         $min_pts = 25;
108                     else
109                         $min_pts = 28;
110
111                     $max_hand_pts = $this->tourn_points_max($user);
112                     if ($max_hand_pts < $min_pts) {
113                         // FIXME_LANG
114                         $ret_s = sprintf("Hai chiamato un due a %d ma in mano hai al massimo %d punti-torneo, non puoi.",
115                                          $a_pnt, $max_hand_pts);
116                         break;
117                     }
118                 }
119                 else {
120                     break;
121                 }
122
123                 $user->asta_card  = $a_card;
124                 $this->table->asta_card = $a_card;
125                 if ($a_card == 9) {
126                     $user->asta_pnt   = $a_pnt;
127                     $this->table->asta_pnt  = $a_pnt;
128                 }
129
130                 return TRUE;
131             } while (0);
132         }
133
134         return FALSE;
135     }
136
137 } // class Rules_no_draw
138
139 ?>