From 2f32bc3153b7f2c2561e4603f912573921e6449f Mon Sep 17 00:00:00 2001 From: alexichi Date: Mon, 9 May 2016 20:26:51 +0200 Subject: add the use of the objects and the feature power and maxHP --- data/items.xml | 9 ++++++--- data/monsters.xml | 33 +++++++++++++++++++++------------ inc/Inventory.inc | 14 +++++++++----- inc/Item.inc | 2 +- inc/Monster.inc | 4 +++- inc/dungeon.inc | 3 ++- inc/perso.inc | 33 +++++++++++++++++++++++++++++++++ index.xhtml | 10 +++++++++- js/craftmine.js | 17 +++++++++++++++-- js/dungeon.js | 35 +++++++++++++++++++---------------- js/perso.js | 24 ++++++++++++++++++++++-- js/shop.js | 2 -- 12 files changed, 140 insertions(+), 46 deletions(-) diff --git a/data/items.xml b/data/items.xml index 9489b1a..4448b1c 100644 --- a/data/items.xml +++ b/data/items.xml @@ -5,7 +5,8 @@ Wooden Sword 10 - 10 + +1 + 1 āš” A sword that beginners need to use to improve their skills @@ -14,7 +15,8 @@ Metal Sword 15 - 30 + +3 + 1 āš” A sword which are often use buy skilled knight. The material is very good and the sword is very powerful @@ -34,7 +36,8 @@ Strength Bottle 10 - 20 + +2 + 3 šŸ¶ If used, you have 20% more chance to hit your enemy during the battle diff --git a/data/monsters.xml b/data/monsters.xml index ab29364..a8dc2f7 100644 --- a/data/monsters.xml +++ b/data/monsters.xml @@ -6,21 +6,24 @@ 1 3 1 - m + 1 + šŸ‘¾ monster2 2 3 2 - m + 2 + šŸ‘¾ monster3 3 4 3 - m + 3 + šŸ‘¾ @@ -29,44 +32,50 @@ 4 5 4 - m + 4 + šŸ‘¾ monster5 5 6 5 - m + 5 + šŸ‘¾ - monster5 + monster6 6 7 6 - m + 6 + šŸ‘¾ - monster6 + monster7 8 9 8 - m + 8 + šŸ‘¾ - monster7 + monster8 9 10 9 - m + 9 + šŸ‘¾ Boss 10 12 10 - m + 14 + šŸ‘¾ diff --git a/inc/Inventory.inc b/inc/Inventory.inc index 2be48f8..3e0137d 100644 --- a/inc/Inventory.inc +++ b/inc/Inventory.inc @@ -1,5 +1,7 @@ items as $k => $object){ if($object[0] == $item) { $nb = $this->items[$k][1]; - if($nb > 0) { - $this->items[$k][0]->consume(); - $this->items[$k][1]--; + if(limitUse($this->items[$k][0])){ + if($nb > 0) { + $this->items[$k][0]->consume(); + $this->items[$k][1]--; + } + if($nb-1 <= 0) $this->_removeItem($item); + return array($object[0], $nb-1); } - if($nb-1 <= 0) $this->_removeItem($item); - return array($object[0], $nb-1); } } return false; diff --git a/inc/Item.inc b/inc/Item.inc index 8eebbf8..a8ee302 100644 --- a/inc/Item.inc +++ b/inc/Item.inc @@ -21,7 +21,7 @@ class Item { foreach($this->feat as $k => $v) { switch($k) { case "hp": increasePerso("hp", +$v); break; - case "power": break; + case "power": increasePerso("bonusPower", +$v); break; } } } diff --git a/inc/Monster.inc b/inc/Monster.inc index c7063ec..ae48691 100644 --- a/inc/Monster.inc +++ b/inc/Monster.inc @@ -7,12 +7,14 @@ class Monster { public $hp = 1; public $xp = 0; public $level = 1; + public $power = 1; - function __construct($name, $level, $hp, $xp, $icon) { + function __construct($name, $level, $hp, $xp, $power, $icon) { $this->name = $name; $this->level = $level; $this->hp = $hp; $this->xp = $xp; + $this->power = $power; $this->icon = $icon; } diff --git a/inc/dungeon.inc b/inc/dungeon.inc index c023cf8..521303e 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -14,7 +14,8 @@ function generateMonster(){ $dungeon["monsters"][$floor][] = new Monster((string)$monster->name, intval($monster->level), intval($monster->hp), - intval($monster->xp), + intval($monster->xp), + intval($monster->power), (string)$monster->icon); } } diff --git a/inc/perso.inc b/inc/perso.inc index f455173..0a32b64 100644 --- a/inc/perso.inc +++ b/inc/perso.inc @@ -10,21 +10,54 @@ function increasePerso($prop, $num) { if(empty($_SESSION["perso"])) initPerso(); $_SESSION["perso"][$prop] += $num; + if($_SESSION["perso"]["hp"] > $_SESSION["perso"]["maxHP"]){//if you want to heal even if you have less than 3 hp to heal, heal until the max is attained + $diff = $_SESSION["perso"]["hp"] - $_SESSION["perso"]["maxHP"]; + $_SESSION["perso"]["hp"] -= $diff; + } +} + +/** + *traite le fait que wooden sword n'est pas cumulable + *metal sword non plus + *life bottle cumulable 3 fois + *si on clique sur wooden sword alors que on avait une metal sword, le bonusPower passe de +3 Ć  +1 + */ +function limitUse($item){ + $n = $item->name; + if($n =="Life Bottle")return true; + if(empty($_SESSION[$n])){ + $_SESSION[$n]=1; + return true; + } + else{ + $_SESSION[$n]++; + if($_SESSION[$n] >= $item->feat["limit"])return false; + else return true; + } } function updatePerso(){ $hp = $_POST["hp"]; + $maxHP = $_POST["maxHP"]; $xp = $_POST["xp"]; $lv = $_POST["lv"]; + $power = $_POST["power"]; + $bonusPower = $_POST["bonusPower"]; $_SESSION["perso"]["hp"] = +$hp; + $_SESSION["perso"]["maxHP"] = +$maxHP; $_SESSION["perso"]["xp"] = +$xp; $_SESSION["perso"]["lv"] = +$lv; + $_SESSION["perso"]["power"] = +$power; + $_SESSION["perso"]["bonusPower"] = +$bonusPower; } function initPerso(){ $_SESSION["perso"]["hp"] = 5; + $_SESSION["perso"]["maxHP"] = 5; $_SESSION["perso"]["xp"] = 0; $_SESSION["perso"]["lv"] = 3; + $_SESSION["perso"]["power"] = 3; + $_SESSION["perso"]["bonusPower"] = 0; } ?> diff --git a/index.xhtml b/index.xhtml index 1ea1bfe..eba0f43 100644 --- a/index.xhtml +++ b/index.xhtml @@ -30,9 +30,17 @@