|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace modules\bataille\app\controller; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class Unite { |
|
7
|
|
|
private $coef_unite; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
//-------------------------- BUILDER ----------------------------------------------------------------------------// |
|
12
|
|
View Code Duplication |
public function __construct() { |
|
|
|
|
|
|
13
|
|
|
$dbc1 = Bataille::getDb(); |
|
14
|
|
|
|
|
15
|
|
|
$query = $dbc1->select("coef_niveau_unite")->from("configuration")->where("ID_configuration", "=", 1)->get(); |
|
16
|
|
|
|
|
17
|
|
|
if ((is_array($query)) && (count($query) == 1)) { |
|
18
|
|
|
foreach ($query as $obj) $this->coef_unite = $obj->coef_niveau_unite; |
|
19
|
|
|
} |
|
20
|
|
|
} |
|
21
|
|
|
//-------------------------- END BUILDER ----------------------------------------------------------------------------// |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
//-------------------------- GETTER ----------------------------------------------------------------------------// |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param $unite |
|
28
|
|
|
* @param $niveau |
|
29
|
|
|
* @param $type |
|
30
|
|
|
* @return array |
|
31
|
|
|
* récupère les caractéristiques de l'unité en fonction de son niveau |
|
32
|
|
|
*/ |
|
33
|
|
|
private function getCaracteristiqueUnite($unite, $niveau, $type) { |
|
34
|
|
|
$dbc1 = Bataille::getDb(); |
|
35
|
|
|
|
|
36
|
|
|
$query = $dbc1->select() |
|
37
|
|
|
->from("unites") |
|
38
|
|
|
->where("nom", "=", $unite, "AND") |
|
39
|
|
|
->where("type", "=", $type, "") |
|
40
|
|
|
->get(); |
|
41
|
|
|
|
|
42
|
|
|
if ((is_array($query)) && (count($query) == 1)) { |
|
43
|
|
|
foreach ($query as $obj) { |
|
44
|
|
|
$base_carac = unserialize($obj->caracteristique); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$coef = $this->coef_unite*$niveau; |
|
48
|
|
|
|
|
49
|
|
|
if ($niveau == 1) $coef = 1; |
|
50
|
|
|
|
|
51
|
|
|
return [ |
|
52
|
|
|
"attaque" => round($base_carac["attaque"]*$coef), |
|
|
|
|
|
|
53
|
|
|
"defense" => round($base_carac["defense"]*$coef), |
|
54
|
|
|
"resistance" => round($base_carac["resistance"]*$coef), |
|
55
|
|
|
"vitesse" => $base_carac["vitesse"] |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
else { |
|
59
|
|
|
return []; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param $type |
|
65
|
|
|
* fonction qui permet de récupérer les unités qu'i est possible de recruter en fonction |
|
66
|
|
|
* du type (batiment sur lequel on a cliqué) |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getUnitePossibleRecruter($type) { |
|
69
|
|
|
//on recup toutes les unites deja recherchée donc que l'on peut faire |
|
70
|
|
|
$unites = Bataille::getCentreRecherche()->getAllRechercheType($type); |
|
71
|
|
|
|
|
72
|
|
|
//recupérer les caractéristiques de l'unité en question |
|
73
|
|
|
for ($i=0 ; $i<count($unites) ; $i++) { |
|
|
|
|
|
|
74
|
|
|
$unites[$i]["caracteristique"] = $this->getCaracteristiqueUnite($unites[$i]["recherche"], $unites[$i]["niveau"], $type); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
//si pas d'unites encore recherchees on renvoit un array juste avec 0 dedans |
|
78
|
|
|
Bataille::setValues(["unites" => $unites]); |
|
79
|
|
|
} |
|
80
|
|
|
//-------------------------- END GETTER ----------------------------------------------------------------------------// |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
//-------------------------- SETTER ----------------------------------------------------------------------------// |
|
84
|
|
|
//-------------------------- END SETTER ----------------------------------------------------------------------------// |
|
85
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.