diff options
-rw-r--r-- | data/items.xml | 9 | ||||
-rw-r--r-- | data/monsters.xml | 33 | ||||
-rw-r--r-- | inc/Inventory.inc | 15 | ||||
-rw-r--r-- | inc/Item.inc | 2 | ||||
-rw-r--r-- | inc/Monster.inc | 6 | ||||
-rw-r--r-- | inc/dungeon.inc | 5 | ||||
-rw-r--r-- | inc/perso.inc | 66 | ||||
-rw-r--r-- | index.xhtml | 10 | ||||
-rw-r--r-- | js/craftmine.js | 17 | ||||
-rw-r--r-- | js/dungeon.js | 41 | ||||
-rw-r--r-- | js/perso.js | 25 | ||||
-rw-r--r-- | js/shop.js | 2 |
12 files changed, 184 insertions, 47 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 @@ <name>Wooden Sword</name> <cost>10</cost> <features> - <power>10</power> + <power>+1</power> + <limit>1</limit> </features> <icon>ā</icon> <description>A sword that beginners need to use to improve their skills</description> @@ -14,7 +15,8 @@ <name>Metal Sword</name> <cost>15</cost> <features> - <power>30</power> + <power>+3</power> + <limit>1</limit> </features> <icon>ā</icon> <description>A sword which are often use buy skilled knight. The material is very good and the sword is very powerful</description> @@ -34,7 +36,8 @@ <name>Strength Bottle</name> <cost>10</cost> <features> - <power>20</power> + <power>+2</power> + <limit>3</limit> </features> <icon>š¶</icon> <description>If used, you have 20% more chance to hit your enemy during the battle</description> 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 @@ <level>1</level> <hp>3</hp> <xp>1</xp> - <icon>m</icon> + <power>1</power> + <icon>š¾</icon> </monster> <monster > <name>monster2</name> <level>2</level> <hp>3</hp> <xp>2</xp> - <icon>m</icon> + <power>2</power> + <icon>š¾</icon> </monster> <monster> <name>monster3</name> <level>3</level> <hp>4</hp> <xp>3</xp> - <icon>m</icon> + <power>3</power> + <icon>š¾</icon> </monster> </floor> <floor name="floor2"> @@ -29,44 +32,50 @@ <level>4</level> <hp>5</hp> <xp>4</xp> - <icon>m</icon> + <power>4</power> + <icon>š¾</icon> </monster> <monster> <name>monster5</name> <level>5</level> <hp>6</hp> <xp>5</xp> - <icon>m</icon> + <power>5</power> + <icon>š¾</icon> </monster> <monster> - <name>monster5</name> + <name>monster6</name> <level>6</level> <hp>7</hp> <xp>6</xp> - <icon>m</icon> + <power>6</power> + <icon>š¾</icon> </monster> </floor> <floor name="floor3"> <monster> - <name>monster6</name> + <name>monster7</name> <level>8</level> <hp>9</hp> <xp>8</xp> - <icon>m</icon> + <power>8</power> + <icon>š¾</icon> </monster> <monster> - <name>monster7</name> + <name>monster8</name> <level>9</level> <hp>10</hp> <xp>9</xp> - <icon>m</icon> + <power>9</power> + <icon>š¾</icon> </monster> <monster> <name>Boss</name> <level>10</level> <hp>12</hp> <xp>10</xp> - <icon>m</icon> + <power>14</power> + <icon>š¾</icon> </monster> </floor> </dungeon> 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; } ?> diff --git a/index.xhtml b/index.xhtml index 1ea1bfe..eba0f43 100644 --- a/index.xhtml +++ b/index.xhtml @@ -30,9 +30,17 @@ </div> <div class="panel-body"> <ul class="list-group"> - <li class="list-group-item">HP<span id="hp" class="label label-success">5</span></li> + <li class="list-group-item">HP<span class="label label-success"> + <span id="hp">5</span> / + <span id="maxHP">5</span> + </span> + </li> <li class="list-group-item">LV<span id="lv" class="label label-success">1</span></li> <li class="list-group-item">Exp<span id="xp" class="label label-success">0</span></li> + <li class="list-group-item">Power<span class="label label-success"> + <span id="power">1</span> + + <span id="bonusPower">0</span> + </span></li> </ul> <ul class="list-group"> diff --git a/js/craftmine.js b/js/craftmine.js index 77cafee..fa70809 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -5,8 +5,11 @@ data = { miners: 0, level: 3, hp: 5, + maxHP: 5, xp: 0, - icon : "H" + power: 3, + bonusPower: 0, + icon : "šŖ" } function sendRequest(url, params, callback, isFile) { @@ -41,6 +44,16 @@ function debitAccount(amount) { updateData("gold"); } +function creditAccount(amount){ + data.gold += amount; + sendRequest("craftmine.php", "op=withdrawMine&amount="+amount, function(xhr) { + var gold = parseInt(xhr); + if(isNaN(gold)) return; + data.gold = gold; + updateData("gold"); + }); +} + function withdrawMine() { sendRequest("craftmine.php", "op=withdrawMine&amount="+data.mine, function(xhr) { var gold = parseInt(xhr); // Server's response is a string @@ -53,7 +66,7 @@ function withdrawMine() { function initCraftMine() { sendRequest("craftmine.php", "op=getCraftMine", function(ret) { - console.log(ret.perso); + //console.log(ret.perso); data.gold = parseInt(ret.gold); // Server's response is a string data.mine = 0; // Reset mine if(ret.perso) updatePerso(ret.perso); diff --git a/js/dungeon.js b/js/dungeon.js index 6ebf4dd..7d97b49 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -2,7 +2,7 @@ var timeout; function buildDungeon(){ sendRequest("craftmine.php", "op=buildDungeon", function(ret) { - displayDungeon(0,1,true);//mob 0 in the floor 1 and I access the dungeon for the first dungeon + displayDungeon(0,1,true);//mob 0 in the floor 1 and I access the dungeon for the first time debitAccount(ret.cost); showInfo("You can acces the dungeon now. Good Luck."); }); @@ -45,21 +45,23 @@ function battle(ret,nb,f){ } function strike(ret,nb, f){ - var lvDiff = data.level-parseInt(ret[0].level); + var powerDiff = (data.power+data.bonusPower)-parseInt(ret[nb].power); var hitRate = Math.floor((Math.random() * 100) + 1); var mobLife = document.getElementById("lifeMob").innerHTML; var persoLife = document.getElementById("lifePerso").innerHTML; if(mobLife == 0){ data.hp = persoLife; + data.bonusPower = 0; //Ć revoir car l'Ć©pĆ©e doit continuer Ć apporter un bonus endBattle("perso",nb,f,ret); return; } else if(persoLife == 0){ data.hp = 1; + data.bonusPower = 0;//when you die you lose your sword and all your power bonus endBattle("mob",nb,f,ret); return; } - if(hitRate<50+10*lvDiff){ + if(hitRate<50+10*powerDiff){ mobLife--; document.getElementById("lifeMob").innerHTML = parseInt(mobLife); } @@ -67,6 +69,11 @@ function strike(ret,nb, f){ persoLife--; document.getElementById("lifePerso").innerHTML = parseInt(persoLife); } + data.hp=persoLife; + sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&maxHP="+data.maxHP+"&xp="+data.xp+"&lv="+data.level+"&power="+data.power + +"&bonusPower="+data.bonusPower, function(){ + displayPerso(data.hp,data.maxHP,data.xp,data.level,data.power,data.bonusPower); + }); battle(ret,nb,f); } @@ -76,15 +83,7 @@ function endBattle(v,nb, f, ret){ //To level up you have to obtain 2 xp to go to lv 3, 3 to go to lv 4, etc //A mob level 2 , if defeated gives you 2 xp, ...etc else{ - data.xp += parseInt(ret[nb].xp); - if(data.xp>=data.level){ - data.xp-=data.level; - data.level++; - //need to send the xp to the server - sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){ - displayPerso(data.hp,data.xp,data.level); - }); - } + levelUp(ret[nb].xp); nb++;//go to the next mob in the same floor if(nb>=3){//floor changing nb=0;//reset the number of the mob @@ -100,8 +99,9 @@ function endBattle(v,nb, f, ret){ displayExit(); sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); } - sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&xp="+data.xp+"&lv="+data.level, function(){ - displayPerso(data.hp,parseInt(data.xp),data.level); + sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&maxHP="+data.maxHP+"&xp="+data.xp+"&lv="+data.level+"&power="+data.power + +"&bonusPower="+data.bonusPower, function(){ + displayPerso(data.hp,data.maxHP,data.xp,data.level,data.power,data.bonusPower); }); } @@ -114,8 +114,17 @@ function displayExit(){ function exitDungeon(boss){ sendRequest("craftmine.php", "op=exitDungeon", function() { window.clearTimeout(timeout); - document.getElementById("tab4").innerHTML = "<h4>Not available, you have to buy a ticket in the build section.</h4>"; - if(boss) showInfo("You have beaten the final boss! CONGRATULATIONS!"); + if(boss){//if the boss is beaten + levelUp(20);//you earn 20 xp + creditAccount(1000);//you earn 1000 gold coins + var tmphtml = "<h3>You have completed the dungeon! CONGRATULATIONS!</h3>"; + tmphmtl += "<ul>"; + tmphtml += "<li><h4>You have earned 1000 gold coins</h4></li>" + tmphmtl += "<li><h4>You have earned 20 xp</h4></li>"; + tmphmtl += "</ul>"; + document.getElementById("tab4").innerHTML = tmphtml; + } + else document.getElementById("tab4").innerHTML = "<h4>Not available, you have to buy a ticket in the build section.</h4>"; showInfo("You have left the dungeon"); }); } diff --git a/js/perso.js b/js/perso.js index 02a8892..7977a9d 100644 --- a/js/perso.js +++ b/js/perso.js @@ -1,12 +1,33 @@ -function displayPerso(hp,xp,lv){ +function displayPerso(hp,maxHP,xp,lv,power,bonusPower){ document.getElementById("hp").innerHTML = hp; + document.getElementById("maxHP").innerHTML = maxHP; document.getElementById("lv").innerHTML = lv; document.getElementById("xp").innerHTML = xp; + document.getElementById("power").innerHTML = power; + document.getElementById("bonusPower").innerHTML = bonusPower; } function updatePerso(perso) { data.hp = perso.hp; + data.maxHP = perso.maxHP; data.xp = perso.xp; data.level = perso.lv; - displayPerso(perso.hp, perso.xp, perso.lv); + data.power = perso.power; + data.bonusPower = perso.bonusPower; + displayPerso(perso.hp, perso.maxHP, perso.xp, perso.lv, perso.power, perso.bonusPower); +} + +function levelUp(xp){ + data.xp += parseInt(xp); + while(data.xp>=data.level){ + data.xp-=data.level; + data.level++; + data.power++; + data.maxHP+=2; + } + //need to send the xp to the server + sendRequest("craftmine.php", "op=updatePerso&hp="+data.hp+"&maxHP="+data.maxHP+"&xp="+data.xp+"&lv="+data.level + +"&power="+data.power+"&bonusPower="+bonusPower, function(){ + displayPerso(data.hp,data.maxHP,data.maxHP,data.xp,data.level,data.power,data.bonusPower); + }); } @@ -69,10 +69,8 @@ function useItem(name) { sendRequest("craftmine.php", "op=useItem&item="+name, function(ret) { if(!ret.item) return; if(ret.perso) updatePerso(ret.perso); - var item = document.querySelector("[data-name=\""+ret.item[0].name+"\"]"); var nb = ret.item[1]; - if(nb>=1) item.innerHTML = nb; else |