aboutsummaryrefslogtreecommitdiffstats
path: root/inc/perso.inc
blob: 421b0a80f6819b8c144ed549deadd96367289d4f (plain)
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
<?php
/**
 * Manages player's stats: life, experience, level.
 *
 * @package inc\perso.inc
 * @author     Alexandre Renoux
 * @author     Pierre-Emmanuel Novac
 */

/**
 * Returns all player's stats after initializing them if needed.
 *
 * @return int[]  arrays containing player's stats
 */
function sendPerso() {
	if(empty($_SESSION["perso"]))
		initPerso();
	return $_SESSION["perso"];
}

/**
 * Increases a player's stat.
 *
 * @param int  $prop  stat to increase
 * @return void
 */
function increasePerso($prop, $num) {
	if(empty($_SESSION["perso"]))
		initPerso();
	$_SESSION["perso"][$prop] += $num;
}

/**
 * Copies stats given in POST request to session.
 *
 * @return void
 */
function updatePerso(){
	$hp = $_POST["hp"];
	$xp = $_POST["xp"];
	$lv = $_POST["lv"];
	$_SESSION["perso"]["hp"] = +$hp;
	$_SESSION["perso"]["xp"] = +$xp;
	$_SESSION["perso"]["lv"] = +$lv;
}

/**
 * Initializes the player's stats.
 *
 * @return void
 */
function initPerso(){
	$_SESSION["perso"]["hp"] = 5;
	$_SESSION["perso"]["xp"] = 0;
	$_SESSION["perso"]["lv"] = 3;
}

?>