aboutsummaryrefslogtreecommitdiffstats
path: root/inc/Item.inc
blob: f01b7092f0d3d600b8a9e86bbcea85329822a301 (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
<?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, $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) {
		$item = $root->addChild("item");
		$item->addChild("name", $this->name);
		$item->addChild("cost", $this->cost);
		$item->addChild("icon", $this->icon);
		$item->addChild("desc", $this->desc);
		$item->addChild("count", $count);
	}

	public static function fromXML($xml) {
		return new static((string)$xml->name, +(string)$xml->cost /* convert to number */, (string)$xml->icon, (string)$xml->desc);
	}
}

?>