diff options
author | piernov <piernov@piernov.org> | 2016-05-09 22:06:30 +0200 |
---|---|---|
committer | piernov <piernov@piernov.org> | 2016-05-09 22:06:30 +0200 |
commit | f10c51f07a755d75a583f85316efbcd3bd1e4b6d (patch) | |
tree | 87419a11e12f5b7433459fcb5cb9da5211dcbd9e /inc/Item.inc | |
parent | 54635d17eef27eb2546d69599e4107b242509ced (diff) | |
parent | 2f32bc3153b7f2c2561e4603f912573921e6449f (diff) | |
download | candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.gz candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.bz2 candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.tar.xz candybox-f10c51f07a755d75a583f85316efbcd3bd1e4b6d.zip |
Merge branch 'alexichi' of ssh://piernov.org/srv/git/candybox into alexichi
Diffstat (limited to 'inc/Item.inc')
-rw-r--r-- | inc/Item.inc | 35 |
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); } } |