aboutsummaryrefslogtreecommitdiffstats
path: root/inc/Item.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/Item.inc')
-rw-r--r--inc/Item.inc35
1 files changed, 34 insertions, 1 deletions
diff --git a/inc/Item.inc b/inc/Item.inc
index bf77818..a8ee302 100644
--- a/inc/Item.inc
+++ b/inc/Item.inc
@@ -1,16 +1,49 @@
<?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": increasePerso("bonusPower", +$v); break;
+ }
+ }
+ }
+
+ function addToXML($root, $count) {
+ $item = $root->addChild("item");
+ $item->addChild("name", $this->name);
+ $item->addChild("cost", $this->cost);
+ $item->addChild("icon", $this->icon);
+ $item->addChild("desc", $this->desc);
+ $xmlfeat = $item->addChild("feat");
+ foreach($this->feat as $k => $v)
+ $xmlfeat->addChild($k, $v);
+ $item->addChild("count", $count);
+ }
+
+ public static function fromXML($xml) {
+ $feats = array();
+ foreach($xml->feat[0] as $k => $v)
+ $feats[(string)$k] = (string)$v;
+
+ return new static((string)$xml->name, +(string)$xml->cost /* convert to number */, (string)$xml->icon, (string)$xml->desc, $feats);
}
}