/
jeu.php
180 lines (145 loc) · 5.96 KB
/
jeu.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
<?php
if (!isset($_SESSION))
{
session_start();
}
require_once 'init.php';
print($stromae);
if(isset($_SESSION['idJoueurCourant']) && $_SESSION['idJoueurCourant'] != '')
{
$JoueurManager = new JoueurManager($db);
$Joueur = new Joueur($JoueurManager->get($_SESSION['idJoueurCourant']));
$Privilege = new Privilege($JoueurManager->getPrivilege($Joueur->getId()));
$listePersonnage = $JoueurManager->getListePersonnageFromJoueur($Joueur->getId());
//var_dump($listePersonnage);
$PersonnageManager = new PersonnageManager($db);
$Personnages = array();
$i = 0;
if(count($listePersonnage) > 0)
{
foreach ($listePersonnage as $key => $item)
{
if(!isset($_SESSION['personnageCourant']))
{
if($i == 0)
{
$_SESSION['personnageCourant'] = $item->id;
}
else{
$Personnages[] = new Personnage($PersonnageManager->get($item->id));
}
}
else
{
if($item->id != $_SESSION['personnageCourant'])
{
$Personnages[] = new Personnage($PersonnageManager->get($item->id));
}
}
$i = $i + 1;
}
}
else
{
header('Location: homepage.php');
}
$Personnage = new Personnage($PersonnageManager->get($_SESSION['personnageCourant']));
if($Personnage->tourDisponible() == false)
{
$Personnage->setMouvement(0);
$Personnage->setNombreAttaque(0);
$PersonnageManager->update($Personnage);
}
$CarteManager = new CarteManager($db);
$Carte = new Carte($CarteManager->get($Personnage->getPlanId()));
$listeAdversaire = $PersonnageManager->getAdversaire($Joueur->getId(),$Personnage->getPlanId());
$Adversaires = array();
if(count($listeAdversaire) > 0)
{
foreach ($listeAdversaire as $key => $item)
{
$Adversaires[] = new Personnage($PersonnageManager->get($item->id));
}
}
$PersonnagesTemp = array_merge($Personnages,$Adversaires);
$direction = $Personnage->getDirection($PersonnagesTemp, $Carte);
$PersonnageTypeManager = new PersonnageTypeManager($db);
$PersonnageType = new PersonnageType($PersonnageTypeManager->get($Personnage->getPersonnageTypeId()));
$EvolutionManager = new EvolutionManager($db);
//Récuperation de la liste des évolutions correspondant au personnage type
$evolutionGetBy = $EvolutionManager->getBy('personnageTypeId', $Personnage->getPersonnageTypeId());
$listeEvolution = array();
if(count($evolutionGetBy) > 0)
{
foreach ($evolutionGetBy as $evolution)
{
// Instance de chaque evolution
$iEvolution = new Evolution($evolution);
// Si l'expérience du personnage est comprise dans la tranche d'evolution
if( $iEvolution->getPalierInferieur() <= $Personnage->getExperience() && $iEvolution->getPalierSuperieur() > $Personnage->getExperience())
{
$iconePersonnageId = $iEvolution->getIconePersonnageId();
$Personnage->setIconePersonnageId($iconePersonnageId);
$PersonnageManager->update_iconepersonnage_personnage($Personnage);
//On met à jour le personnage
$Personnage = new Personnage($PersonnageManager->get($Personnage->getId()));
}
}
}
// Liste des joueurs
$listeJoueur = $JoueurManager->getAll();
// Contruction d'une variable selectJoueurs au format d'un optiongroup
$selectJoueurs = array();
if(count($listeJoueur) > 0)
{
foreach ($listeJoueur as $key => $item)
{
if( !isset($selectJoueurs[$item['roleNom']]) )
{
$selectJoueurs[$item['roleNom']] = array();
}
array_push($selectJoueurs[$item['roleNom']],new Joueur($item)) ;
}
}
$smarty->assign('carte', $Carte);
$smarty->assign('direction', $direction);
$smarty->assign('personnage', $Personnage);
$smarty->assign('personnages', $Personnages);
$smarty->assign('adversaires', $Adversaires);
$smarty->assign('personnageType', $PersonnageType);
$smarty->assign('Joueur', $Joueur);
$smarty->assign('selectJoueurs', $selectJoueurs);
$smarty->assign('Privilege', $Privilege);
$smarty->assign('messageMouvement', false);
$smarty->assign('messageAttaque', false);
if(isset($_SESSION['ajax']) && $_SESSION['ajax'] == true)
{
if(isset($_SESSION['messageMouvement']) && $_SESSION['messageMouvement'] == true)
{
$smarty->assign('tourDisponible', $_SESSION['tourDisponible']);
$smarty->assign('messageMouvement', true);
$smarty->assign('messageMouvementContent', $smarty->fetch('message/messageMouvement.tpl'));
}
if(isset($_SESSION['messageAttaque']) && $_SESSION['messageAttaque'] == true)
{
$smarty->assign('seToucher', $_SESSION['seToucher']);
$smarty->assign('nombreAttaqueDisponible', $_SESSION['nombreAttaqueDisponible']);
$smarty->assign('tourDisponible', $_SESSION['tourDisponible']);
$smarty->assign('personnageAttaquer', $_SESSION['personnageAttaquer']);
$smarty->assign('messageAttaque', true);
$smarty->assign('messageAttaqueContent', $smarty->fetch('message/messageAttaque.tpl'));
}
$smarty->display('page/jeu.tpl');
$_SESSION['ajax'] = false;
$_SESSION['messageMouvement'] = false;
$_SESSION['messageAttaque'] = false;
}
else {
$smarty->display('page/pageJeu.tpl');
}
}
else
{
header('Location: index.php');
}
?>