1
|
|
|
<?php |
2
|
|
|
namespace modules\bataille\app\controller; |
3
|
|
|
use core\App; |
4
|
|
|
|
5
|
|
|
class Base { |
6
|
|
|
private $batiments; |
7
|
|
|
|
8
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
9
|
|
|
public function __construct() { |
10
|
|
|
|
11
|
|
|
} |
12
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
|
16
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
17
|
|
|
public function getBatiments() { |
18
|
|
|
return $this->batiments; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* fonction qui va initaliser la base |
23
|
|
|
*/ |
24
|
|
|
public function getMaBase() { |
25
|
|
|
$this->getInfoBase(); |
26
|
|
|
|
27
|
|
|
$this->getBasesJoueur(); |
28
|
|
|
|
29
|
|
|
Bataille::getRessource(); |
30
|
|
|
|
31
|
|
|
Bataille::setValues([ |
32
|
|
|
"production_eau" => Bataille::getBatiment()->getProduction("eau"), |
33
|
|
|
"production_electricite" => Bataille::getBatiment()->getProduction("electricite"), |
34
|
|
|
"production_fer" => Bataille::getBatiment()->getProduction("fer"), |
35
|
|
|
"production_fuel" => Bataille::getBatiment()->getProduction("fuel"), |
36
|
|
|
"stockage_entrepot" => Bataille::getBatiment()->getStockage(), |
37
|
|
|
"stockage_grenier" => Bataille::getBatiment()->getStockage("grenier") |
38
|
|
|
]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param null $id_base |
43
|
|
|
* fonction qui va récupérer les infos de la base |
44
|
|
|
*/ |
45
|
|
|
public function getInfoBase($id_base = null) { |
46
|
|
|
$dbc = App::getDb(); |
47
|
|
|
|
48
|
|
|
if ($id_base == null) { |
49
|
|
|
$id_base = Bataille::getIdBase(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$query = $dbc->select("nom_base")->select("points")->from("_bataille_base")->where("ID_base", "=", $id_base)->get(); |
53
|
|
|
|
54
|
|
|
if ((is_array($query)) && (count($query) > 0)) { |
55
|
|
|
foreach ($query as $obj) { |
56
|
|
|
Bataille::setValues([ |
57
|
|
|
"nom_base" => $obj->nom_base, |
58
|
|
|
"points" => $obj->points |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* fonction qui recupere tous les batiments de la base |
66
|
|
|
*/ |
67
|
|
|
public function getBatimentsBase() { |
68
|
|
|
$dbc = App::getDb(); |
69
|
|
|
|
70
|
|
|
$query = $dbc->select()->from("_bataille_batiment")->where("ID_base", "=", Bataille::getIdBase())->get(); |
71
|
|
|
|
72
|
|
|
if (count($query) > 0) { |
73
|
|
|
$batiments = []; |
74
|
|
|
|
75
|
|
|
foreach ($query as $obj) { |
76
|
|
|
$taille_batiment = Bataille::getBatiment()->getTailleBatiment($obj->nom_batiment_sql); |
77
|
|
|
$construction = ""; |
78
|
|
|
|
79
|
|
|
if ($obj->construction) { |
80
|
|
|
$construction = "construction"; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$batiments[] = [ |
84
|
|
|
"nom_batiment" => $obj->nom_batiment, |
85
|
|
|
"nom_batiment_sql" => $obj->nom_batiment_sql, |
86
|
|
|
"niveau" => $obj->niveau, |
87
|
|
|
"posx" => $obj->posx, |
88
|
|
|
"posy" => $obj->posy, |
89
|
|
|
"width" => $taille_batiment[0], |
90
|
|
|
"height" => $taille_batiment[1], |
91
|
|
|
"construction" => $construction |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
Bataille::setValues(["batiments" => $batiments]); |
96
|
|
|
|
97
|
|
|
$this->setBatimentsBase($batiments); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param null $id_identite |
103
|
|
|
* fonction qui récupère les bases d'un joueur |
104
|
|
|
*/ |
105
|
|
|
public function getBasesJoueur($id_identite = null) { |
106
|
|
|
$dbc = App::getDb(); |
107
|
|
|
$exclude = 0; |
108
|
|
|
|
109
|
|
|
if ($id_identite === null) { |
110
|
|
|
$id_identite = Bataille::getIdIdentite(); |
111
|
|
|
$exclude = Bataille::getIdBase(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$this->getPseudoJoueur($id_identite); |
115
|
|
|
|
116
|
|
|
$query = $dbc->select() |
117
|
|
|
->from("_bataille_base") |
118
|
|
|
->where("ID_identite", "=", $id_identite, "AND") |
119
|
|
|
->where("ID_base", "!=", $exclude) |
120
|
|
|
->orderBy("ID_base", "DESC") |
121
|
|
|
->get(); |
122
|
|
|
|
123
|
|
View Code Duplication |
if ((is_array($query)) && (count($query) > 0)) { |
124
|
|
|
$une_base = []; |
125
|
|
|
foreach ($query as $obj) { |
126
|
|
|
$une_base[] = [ |
127
|
|
|
"id_base" => $obj->ID_base, |
128
|
|
|
"nom_base" => $obj->nom_base, |
129
|
|
|
"points_base" => $obj->points, |
130
|
|
|
"posx" => $obj->posx, |
131
|
|
|
"posy" => $obj->posy |
132
|
|
|
]; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
Bataille::setValues(["base_joueur" => $une_base]); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param $id_identite |
141
|
|
|
* fonction qui renvoi le pseudo d'un joueur en fonction de son ID |
142
|
|
|
*/ |
143
|
|
|
private function getPseudoJoueur($id_identite) { |
144
|
|
|
$dbc = App::getDb(); |
145
|
|
|
|
146
|
|
|
$query = $dbc->select("pseudo")->from("identite")->where("ID_identite", "=", $id_identite)->get(); |
147
|
|
|
|
148
|
|
|
foreach ($query as $obj) { |
149
|
|
|
Bataille::setValues(["pseudo" => $obj->pseudo]); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
|
156
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
157
|
|
|
private function setBatimentsBase($batiments) { |
158
|
|
|
$this->batiments = $batiments; |
159
|
|
|
} |
160
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
161
|
|
|
} |