aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-08 14:41:25 +0200
committerpiernov <piernov@piernov.org>2016-05-08 14:41:25 +0200
commitf734770dd4fe464a8c263218efa90fd487c6a608 (patch)
treee5f2b277d0272d622f1443590aca54a860cce76a /inc
parent2ecc9a72e9e932f1bf0431f391814837d8694884 (diff)
downloadcandybox-f734770dd4fe464a8c263218efa90fd487c6a608.tar.gz
candybox-f734770dd4fe464a8c263218efa90fd487c6a608.tar.bz2
candybox-f734770dd4fe464a8c263218efa90fd487c6a608.tar.xz
candybox-f734770dd4fe464a8c263218efa90fd487c6a608.zip
Add feature attribute to Item class + add consume() method to use those features + use coercion on updatePerso() values
Diffstat (limited to 'inc')
-rw-r--r--inc/Item.inc15
-rw-r--r--inc/perso.inc13
2 files changed, 24 insertions, 4 deletions
diff --git a/inc/Item.inc b/inc/Item.inc
index 907872e..f01b709 100644
--- a/inc/Item.inc
+++ b/inc/Item.inc
@@ -1,16 +1,29 @@
<?php
+require_once("perso.inc");
+
class Item {
public $name = "";
public $cost = 0;
public $icon = "";
public $desc = "";
+ public $feat = array();
- function __construct($name, $cost, $icon, $desc) {
+ function __construct($name, $cost, $icon, $desc, $feat) {
$this->name = $name;
$this->cost = $cost;
$this->icon = $icon;
$this->desc = $desc;
+ $this->feat = $feat;
+ }
+
+ function consume() {
+ foreach($this->feat as $k => $v) {
+ switch($k) {
+ case "hp": increasePerso("hp", +$v); break;
+ case "power": break;
+ }
+ }
}
function addToXML($root, $count) {
diff --git a/inc/perso.inc b/inc/perso.inc
index 0362d8c..f455173 100644
--- a/inc/perso.inc
+++ b/inc/perso.inc
@@ -1,17 +1,24 @@
<?php
+
function sendPerso() {
if(empty($_SESSION["perso"]))
initPerso();
return $_SESSION["perso"];
}
+function increasePerso($prop, $num) {
+ if(empty($_SESSION["perso"]))
+ initPerso();
+ $_SESSION["perso"][$prop] += $num;
+}
+
function updatePerso(){
$hp = $_POST["hp"];
$xp = $_POST["xp"];
$lv = $_POST["lv"];
- $_SESSION["perso"]["hp"] = $hp;
- $_SESSION["perso"]["xp"] = intval($xp);
- $_SESSION["perso"]["lv"] = $lv;
+ $_SESSION["perso"]["hp"] = +$hp;
+ $_SESSION["perso"]["xp"] = +$xp;
+ $_SESSION["perso"]["lv"] = +$lv;
}
function initPerso(){