aboutsummaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/Inventory.inc15
-rw-r--r--inc/Item.inc2
-rw-r--r--inc/Monster.inc6
-rw-r--r--inc/dungeon.inc5
-rw-r--r--inc/perso.inc66
5 files changed, 85 insertions, 9 deletions
diff --git a/inc/Inventory.inc b/inc/Inventory.inc
index 58cf709..4a1add8 100644
--- a/inc/Inventory.inc
+++ b/inc/Inventory.inc
@@ -1,4 +1,7 @@
<?php
+
+require_once("perso.inc");
+
/**
* Represent the player's Inventory.
* Implemented as a singleton in the session.
@@ -110,12 +113,14 @@ class Inventory {
foreach($this->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 404c46b..435ca1c 100644
--- a/inc/Item.inc
+++ b/inc/Item.inc
@@ -63,7 +63,7 @@ class Item {
foreach($this->feat as $k => $v) {
switch($k) {
case "hp": increasePerso("hp", +$v); break;
- case "power": break; // TODO: do something with power
+ case "power": increasePerso("bonusPower", +$v); break;
}
}
}
diff --git a/inc/Monster.inc b/inc/Monster.inc
index d8fe619..d00532f 100644
--- a/inc/Monster.inc
+++ b/inc/Monster.inc
@@ -36,7 +36,7 @@ class Monster {
* @var int Monster's level.
*/
public $level = 1;
-
+ public $power = 1;
/**
* Monster's constructor
@@ -44,15 +44,17 @@ class Monster {
* @param string $name Monster's name
* @param int $level Monster's level
* @param int $hp Monster's HP
+ * @param int $power Monster's power
* @param int $xp Exp given by the Monster
* @param string $icon Item's icon
* @return void
*/
- 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 32d58ac..bf99685 100644
--- a/inc/dungeon.inc
+++ b/inc/dungeon.inc
@@ -10,6 +10,7 @@
require_once("messages.inc");
require_once("account.inc");
require_once("Monster.inc");
+require_once("perso.inc");
/**
* Loads all the dungeon's monsters from the XML file data/monsters.xml.
@@ -26,7 +27,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);
}
}
@@ -93,6 +95,7 @@ function sendDungeonProgress(){
$nb=$_POST["mob"];
$_SESSION["dungeon"]["flat"] = $f;
$_SESSION["dungeon"]["mob"] = $nb;
+ reusable();
}
/**
diff --git a/inc/perso.inc b/inc/perso.inc
index 421b0a8..e38fb4c 100644
--- a/inc/perso.inc
+++ b/inc/perso.inc
@@ -28,6 +28,63 @@ 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(empty($item->feat["limit"])) return true;
+ if(empty($_SESSION["usedItem"])){
+ initUsedItem();
+ $_SESSION["usedItem"][$n]["nbUse"]=1;
+ return true;
+ }
+ else{
+ if($_SESSION["usedItem"][$n]["nbUse"] >= $item->feat["limit"])return false;
+ else{
+ $_SESSION["usedItem"][$n]["nbUse"]++;
+ return true;
+ }
+ }
+}
+
+function initUsedItem(){
+ $_SESSION["usedItem"]["Strength Bottle"]["longevity"] = 0;//if longevity equals 2, it means that the item was used during 2 battles
+ $_SESSION["usedItem"]["Wooden Sword"]["longevity"] = 0;
+ $_SESSION["usedItem"]["Metal Sword"]["longevity"] = 0;
+ $_SESSION["usedItem"]["Strength Bottle"]["nbUse"] = 0;
+ $_SESSION["usedItem"]["Wooden Sword"]["nbUse"] = 0;
+ $_SESSION["usedItem"]["Metal Sword"]["nbUse"] = 0;
+}
+
+function reusable(){
+ if(empty($_SESSION["usedItem"])){
+ initUsedItem();
+ }
+ $_SESSION["usedItem"]["Strength Bottle"]["nbUse"]=0;
+ if($_SESSION["usedItem"]["Wooden Sword"]["nbUse"]>=1){
+ $_SESSION["usedItem"]["Wooden Sword"]["longevity"]++;
+ if($_SESSION["usedItem"]["Wooden Sword"]["longevity"]>=2){
+ $_SESSION["perso"]["powerBonus"] -= 1;
+ $_SESSION["usedItem"]["Wooden Sword"]["nbUse"]=0;
+ }
+ }
+ else if($_SESSION["usedItem"]["Metal Sword"]["nbUse"]>=1){
+ $_SESSION["usedItem"]["Metal Sword"]["longevity"]++;
+ if($_SESSION["usedItem"]["Metal Sword"]["longevity"]>=2){
+ $_SESSION["perso"]["powerBonus"] -= 3;
+ $_SESSION["usedItem"]["Metal Sword"]["nbUse"]=0;
+ }
+ }
}
/**
@@ -37,11 +94,17 @@ function increasePerso($prop, $num) {
*/
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;
}
/**
@@ -51,8 +114,11 @@ function updatePerso(){
*/
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;
}
?>