-
Notifications
You must be signed in to change notification settings - Fork 0
/
heal.php
50 lines (38 loc) · 1.53 KB
/
heal.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
<?php
require __DIR__.'/header.php';
use App\Character;
use App\CharacterRepository;
use App\CharacterLog;
use App\CharacterLogRepository;
if (isset($_SESSION['id'])) {
$characterRepository = new CharacterRepository($base);
$myCharacter = $characterRepository->find($_SESSION['id']);
$friend = $characterRepository->find($_GET['id']);
if ($friend->getState() === Character::DEAD) {
echo "Vous venez de découvrir un corps sans vie ...";
} else {
if ($myCharacter->getAp() >= Character::HEAL_COST) {
// Point d'action
$myCharacter->setAp($myCharacter->getAp() - Character::HEAL_COST);
$characterRepository->updateAp($myCharacter);
// Heal
$heal = rand(1,50);
$hp = $friend->getHp() + $heal;
$friend->setHp($hp);
$characterRepository->updateHp($friend);
$message = $myCharacter->getName() . " soigne ". $friend->getName(). " pour " . $heal ." de soins <br>";
echo $message;
$myCharacter->experience+=50;
$characterRepository->update($myCharacter);
$myCharacter->checkExperience();
// J'enregistre les logs dans chaques journal
$characterLogRepository = new CharacterLogRepository($base);
$characterLogRepository->add($myCharacter, $message);
$characterLogRepository->add($friend, $message);
} else {
echo "Vous n'avez pas assez de point d'action";
}
}
}
require __DIR__.'/footer.php';
?>