From 349c6fe7ecf10e5929dc27c2446853f0fe416077 Mon Sep 17 00:00:00 2001 From: alexichi Date: Wed, 27 Apr 2016 12:59:51 +0200 Subject: add loadShop() and categories in the xml file and modify the presentation of the items in the shop --- data/items.xml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 data/items.xml (limited to 'data') diff --git a/data/items.xml b/data/items.xml new file mode 100644 index 0000000..528d37a --- /dev/null +++ b/data/items.xml @@ -0,0 +1,41 @@ + + + + + Wooden Sword + 50 + + 10 + + + A sword that beginners need to use to improve their skills + + + Metal Sword + 200 + + 30 + + + A sword which are often use buy skilled knight. The material is very good and the sword is very powerful + + + + + Life Bottle + 100 + + 🍶 + A bottle which can heal you by regaining hp + + + Strength Bottle + 250 + + 20 + + 🍶 + If used, you have 20% more chance to hit your enemy during the battle + + + -- cgit v1.2.3-70-g09d2 From caf62cfe0e439fc13f7c297954c4aeb21112a2ec Mon Sep 17 00:00:00 2001 From: piernov Date: Wed, 27 Apr 2016 20:46:27 +0200 Subject: Add data/save directory --- data/save/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 data/save/.gitignore (limited to 'data') diff --git a/data/save/.gitignore b/data/save/.gitignore new file mode 100644 index 0000000..4fcbff5 --- /dev/null +++ b/data/save/.gitignore @@ -0,0 +1 @@ +*.save.xml -- cgit v1.2.3-70-g09d2 From 3c297defe63a2af75cc7aafcfa5cf74dd1f2c20a Mon Sep 17 00:00:00 2001 From: alexichi Date: Fri, 29 Apr 2016 21:04:45 +0200 Subject: I lower the prices because it was getting on my nerves --- data/items.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'data') diff --git a/data/items.xml b/data/items.xml index 528d37a..6c19b84 100644 --- a/data/items.xml +++ b/data/items.xml @@ -3,7 +3,7 @@ Wooden Sword - 50 + 10 10 @@ -12,7 +12,7 @@ Metal Sword - 200 + 15 30 @@ -23,14 +23,14 @@ Life Bottle - 100 + 5 🍶 A bottle which can heal you by regaining hp Strength Bottle - 250 + 10 20 -- cgit v1.2.3-70-g09d2 From 31866085151518f468794dc71b541543e6b2f691 Mon Sep 17 00:00:00 2001 From: alexichi Date: Sun, 1 May 2016 11:32:08 +0200 Subject: add the beginning part of the dungeon When you have enough money you can buy a ticket and access the dungeon I made a file monsters.xml . It's a bit like the code with the shop but modified When you press the button launch in the onglet dungeon , it display "Battle!" in the console --- craftmine.php | 3 ++- data/monsters.xml | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ inc/Monster.inc | 19 +++++++++++++++++ inc/dungeon.inc | 39 ++++++++++++++++++++++++++++++++++ inc/messages.inc | 3 ++- index.xhtml | 3 +++ js/dungeon.js | 18 ++++++++++++++++ 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 data/monsters.xml create mode 100644 inc/Monster.inc create mode 100644 inc/dungeon.inc create mode 100644 js/dungeon.js (limited to 'data') diff --git a/craftmine.php b/craftmine.php index 78c5e37..4cd6b00 100644 --- a/craftmine.php +++ b/craftmine.php @@ -4,7 +4,7 @@ require_once("inc/mine.inc"); require_once("inc/guild.inc"); require_once("inc/shop.inc"); require_once("inc/craftmine.inc"); - +require_once("inc/dungeon.inc"); session_start(); // Must be placed *BEFORE* $_SESSION is actually used and *AFTER* all classes are imported /** @@ -42,6 +42,7 @@ switch($op) { case "getCraftMine": sendCraftMine(); break; case "buildShop": buildShop(); break; case "buyItem": buyItem(); break; + case "buildDungeon" : buildDungeon(); break; default: reportBadRequest(); } diff --git a/data/monsters.xml b/data/monsters.xml new file mode 100644 index 0000000..86cf422 --- /dev/null +++ b/data/monsters.xml @@ -0,0 +1,63 @@ + + + + + monster1 + 1 + 2 + m + + + monster2 + 2 + 3 + m + + + monster3 + 3 + 4 + m + + + + + monster4 + 4 + 5 + m + + + monster5 + 5 + 6 + m + + + monster5 + 6 + 7 + m + + + + + monster6 + 8 + 9 + m + + + monster7 + 9 + 10 + m + + + Boss + 10 + 12 + m + + + diff --git a/inc/Monster.inc b/inc/Monster.inc new file mode 100644 index 0000000..fbb0fe9 --- /dev/null +++ b/inc/Monster.inc @@ -0,0 +1,19 @@ +name = $name; + $this->level = $level; + $this->hp = $hp; + $this->icon = $icon; + + } +} + +?> diff --git a/inc/dungeon.inc b/inc/dungeon.inc new file mode 100644 index 0000000..b2277f0 --- /dev/null +++ b/inc/dungeon.inc @@ -0,0 +1,39 @@ +(string)$monsters["cost"],"monsters"=>array()); + foreach($monsters as $f){ + $floor = (string)$f["name"]; + $dungeon["monsters"][$floor] = array(); + foreach($f as $monster){ + $dungeon["monsters"][$floor][] = new Monster((string)$monster->name, + intval($monster->level), + intval($monster->hp), + (string)$monster->icon); + } + } + return $dungeon; +} + +function initDungeon() { + $_SESSION["dungeon"] = true; +} + +function buildDungeon() { + $dungeon=generateMonster(); + if(!empty($_SESSION["dungeon"])) { + sendError("dungeon_already_available"); + } + elseif(debitAccount($dungeon["cost"])) { + initDungeon(); + $_SESSION["mine"]["gold"] -= $dungeon["cost"]; + echo json_encode($dungeon); + } +} + +?> diff --git a/inc/messages.inc b/inc/messages.inc index d6ea87e..c24bd18 100644 --- a/inc/messages.inc +++ b/inc/messages.inc @@ -5,7 +5,8 @@ $messages = array( "gold_insufficient" => "You don't have enough gold.", "shop_missing_item" => "This item does not exist.", "guild_not_yet_created" => "You need to create a guild first.", - "guild_already_built" => "You have aready built a guild." + "guild_already_built" => "You have aready built a guild.", + "dungeon_already_available" => "You can already access the dungeon" ); function sendError($msg) { diff --git a/index.xhtml b/index.xhtml index aa29615..2745c8a 100644 --- a/index.xhtml +++ b/index.xhtml @@ -15,6 +15,8 @@ + +
@@ -69,6 +71,7 @@
  • +
diff --git a/js/dungeon.js b/js/dungeon.js new file mode 100644 index 0000000..1760afa --- /dev/null +++ b/js/dungeon.js @@ -0,0 +1,18 @@ +function buildDungeon(){ + sendRequest("craftmine.php", "op=buildDungeon", function(ret) { + displayDungeon(); + debitAccount(ret.cost); + showInfo("You can acces the dungeon now. Good Luck."); + }); +} + +function displayDungeon(){ + var tmphtml = "
"; + tmphtml += ""; + //tmphtml += ""; + document.getElementById("tab4").innerHTML = tmphtml; +} + +function launchDungeon(){ + console.log("Battle!"); +} -- cgit v1.2.3-70-g09d2 From 64b1663e55544e1ed0e072c4f624688625691c9f Mon Sep 17 00:00:00 2001 From: alexichi Date: Sun, 1 May 2016 13:55:08 +0200 Subject: Add dungeon without fight system You can buy a "ticket" to access the dungeon If you exit you have to buy another ticket Problem when we update the page, the default sentence is displayed while it said that you can access the dungeon --- craftmine.php | 2 ++ data/items.xml | 4 ++-- inc/dungeon.inc | 11 +++++++++++ js/craftmine.js | 5 ++++- js/dungeon.js | 30 +++++++++++++++++++++++++++--- 5 files changed, 46 insertions(+), 6 deletions(-) (limited to 'data') diff --git a/craftmine.php b/craftmine.php index 4cd6b00..72817cc 100644 --- a/craftmine.php +++ b/craftmine.php @@ -43,6 +43,8 @@ switch($op) { case "buildShop": buildShop(); break; case "buyItem": buyItem(); break; case "buildDungeon" : buildDungeon(); break; + case "launchDungeon" : launchDungeon(); break; + case "exitDungeon" : exitDungeon(); break; default: reportBadRequest(); } diff --git a/data/items.xml b/data/items.xml index 6c19b84..8888796 100644 --- a/data/items.xml +++ b/data/items.xml @@ -25,7 +25,7 @@ Life Bottle 5 - 🍶 + 💧 A bottle which can heal you by regaining hp @@ -34,7 +34,7 @@ 20 - 🍶 + 💧 If used, you have 20% more chance to hit your enemy during the battle diff --git a/inc/dungeon.inc b/inc/dungeon.inc index b2277f0..8c26c92 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -36,4 +36,15 @@ function buildDungeon() { } } +function launchDungeon(){ + $dungeon=generateMonster(); + $opponent = $dungeon["monsters"]["floor1"]; + echo json_encode($opponent); +} + +function exitDungeon(){ + $_SESSION["dungeon"] = false; + echo json_encode(array("a" => 7));//Cette ligne ne sert qu'à contourner l'erreur créé à cause de sendRequest. A revoir. +} + ?> diff --git a/js/craftmine.js b/js/craftmine.js index 92fa45a..c40106c 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -1,8 +1,11 @@ data = { + name: "You", gold: 0, mine: 0, miners: 0, - level: 1 + level: 1, + hp: 1, + icon : "H" } function sendRequest(url, params, callback) { diff --git a/js/dungeon.js b/js/dungeon.js index 1760afa..d20a3cf 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -8,11 +8,35 @@ function buildDungeon(){ function displayDungeon(){ var tmphtml = "
"; - tmphtml += ""; - //tmphtml += ""; + tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; } function launchDungeon(){ - console.log("Battle!"); + sendRequest("craftmine.php", "op=launchDungeon", function(ret) { + document.getElementById("launch").style.display = "none"; + displayBattle(ret); + }); +} + +function displayBattle(ret){ + var tmphtml = "
"; + tmphtml += "

Battle

"; + tmphtml += "
    "; + tmphtml += "
  • "; + tmphtml += ""; + tmphtml += ""; + tmphtml += "
  • "; + tmphtml += "
"; + tmphtml += "
"; + tmphtml += "

"; + tmphtml += ""; + document.getElementById("tab4").innerHTML = tmphtml; +} + +function exitDungeon(){ + sendRequest("craftmine.php", "op=exitDungeon", function() { + document.getElementById("tab4").innerHTML = "

Look at how poor you are! You can't access the dungeon, it is only for the elite.

"; + showInfo("You have left the dungeon"); + }); } -- cgit v1.2.3-70-g09d2 From 1efc4a15c8ab913bf8bdb1aef9f3b5720b3b7762 Mon Sep 17 00:00:00 2001 From: alexichi Date: Thu, 5 May 2016 20:28:26 +0200 Subject: add dungeon server side and improve some details like the difference between floors --- craftmine.php | 1 + data/items.xml | 4 +-- data/monsters.xml | 2 +- inc/dungeon.inc | 16 ++++++++--- inc/messages.inc | 3 +- js/craftmine.js | 7 +++-- js/dungeon.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++--------- 7 files changed, 90 insertions(+), 25 deletions(-) (limited to 'data') diff --git a/craftmine.php b/craftmine.php index 242e1fd..43fdc66 100644 --- a/craftmine.php +++ b/craftmine.php @@ -51,6 +51,7 @@ switch($op) { case "buildDungeon" : buildDungeon(); break; case "launchDungeon" : launchDungeon(); break; case "exitDungeon" : exitDungeon(); break; + case "sendDungeonProgress" : sendDungeonProgress(); break; case "saveGame": saveGame(); break; case "downSave": downSave(); break; case "listSaves": listSaves(); break; diff --git a/data/items.xml b/data/items.xml index 8888796..6c19b84 100644 --- a/data/items.xml +++ b/data/items.xml @@ -25,7 +25,7 @@ Life Bottle 5 - 💧 + 🍶 A bottle which can heal you by regaining hp @@ -34,7 +34,7 @@ 20 - 💧 + 🍶 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 86cf422..630e83a 100644 --- a/data/monsters.xml +++ b/data/monsters.xml @@ -4,7 +4,7 @@ monster1 1 - 2 + 3 m diff --git a/inc/dungeon.inc b/inc/dungeon.inc index 81e2ba7..ebe74b7 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -21,12 +21,12 @@ function generateMonster(){ } function initDungeon() { - $_SESSION["dungeon"] = true; + $_SESSION["dungeon"]["access"] = true; } function sendDungeon() { if(!empty($_SESSION["dungeon"])) - return generateMonster(); + return $_SESSION["dungeon"]; else return false; } @@ -43,14 +43,22 @@ function buildDungeon() { } function launchDungeon(){ + $f= $_POST["floor"]; $dungeon=generateMonster(); - $opponent = $dungeon["monsters"]["floor1"]; + $opponent = $dungeon["monsters"]["floor".$f]; echo json_encode($opponent); } +function sendDungeonProgress(){ + $f= $_POST["floor"]; + $nb=$_POST["mob"]; + $_SESSION["dungeon"]["flat"] = $f; + $_SESSION["dungeon"]["mob"] = $nb; +} + + function exitDungeon(){ $_SESSION["dungeon"] = false; - echo json_encode(array("a" => 7));//Cette ligne ne sert qu'à contourner l'erreur créé à cause de sendRequest. A revoir. } ?> diff --git a/inc/messages.inc b/inc/messages.inc index c51adba..1f25ed3 100644 --- a/inc/messages.inc +++ b/inc/messages.inc @@ -6,8 +6,7 @@ $messages = array( "shop_missing_item" => "This item does not exist.", "guild_not_yet_created" => "You need to create a guild first.", "guild_already_built" => "You have aready built a guild.", - "dungeon_already_available" => "You can already access the dungeon" - + "dungeon_already_available" => "You can already access the dungeon", "gamesave_ok" => "Game saved.", "gamesave_error" => "An error occured when trying to save the game.", "gamesave_not_found" => "Couldn't find the specified save file.", diff --git a/js/craftmine.js b/js/craftmine.js index ffc9b5e..9af9b9f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -3,8 +3,8 @@ data = { gold: 0, mine: 0, miners: 0, - level: 1, - hp: 1, + level: 4, + hp: 5, icon : "H" } @@ -56,7 +56,8 @@ function initCraftMine() { data.mine = 0; // Reset mine if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - if(ret.dungeon) displayDungeon(); + if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); + else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true); data.miners = parseInt(ret.miners); updateData("gold", "mine", "miners"); }) diff --git a/js/dungeon.js b/js/dungeon.js index d20a3cf..c6ce014 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -1,41 +1,97 @@ +var timeout; + function buildDungeon(){ sendRequest("craftmine.php", "op=buildDungeon", function(ret) { - displayDungeon(); + displayDungeon(0,1,true);//mob 0 in the floor 1 and I access the dungeon for the first dungeon debitAccount(ret.cost); showInfo("You can acces the dungeon now. Good Luck."); }); } -function displayDungeon(){ +function displayDungeon(nb,f,firstTime){ var tmphtml = "
"; - tmphtml += ""; + tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; } -function launchDungeon(){ - sendRequest("craftmine.php", "op=launchDungeon", function(ret) { - document.getElementById("launch").style.display = "none"; - displayBattle(ret); +function launchDungeon(nb,f,firstTime){ + sendRequest("craftmine.php", "op=launchDungeon&floor="+f, function(ret) { + if(nb==0 && firstTime){ + document.getElementById("launch").style.display = "none"; + } + displayBattle(ret,nb,f); }); } -function displayBattle(ret){ +function displayBattle(ret,nb,f){ var tmphtml = "
"; - tmphtml += "

Battle

"; + tmphtml += "

Battle floor "+ f +"

"; tmphtml += "
    "; tmphtml += "
  • "; - tmphtml += ""; - tmphtml += ""; + tmphtml += ""; + tmphtml += ""; tmphtml += "
  • "; tmphtml += "
"; tmphtml += "
"; - tmphtml += "

"; - tmphtml += ""; document.getElementById("tab4").innerHTML = tmphtml; + displayExit(); + battle(ret,nb,f); +} + +function battle(ret,nb,f){ + timeout=window.setTimeout(strike, 1000, ret, nb, f); +} + +function strike(ret,nb, f){ + var lvDiff = data.level-parseInt(ret[0].level); + var hitRate = Math.floor((Math.random() * 100) + 1); + var mobLife = document.getElementById("lifeMob").innerHTML; + var persoLife = document.getElementById("lifePerso").innerHTML; + if(mobLife == 0){ + endBattle("perso",nb,f); + return; + } + else if(persoLife == 0){ + endBattle("mob",nb); + return; + } + if(hitRate<50+10*lvDiff){ + mobLife--; + document.getElementById("lifeMob").innerHTML = parseInt(mobLife); + } + else{ + persoLife--; + document.getElementById("lifePerso").innerHTML = parseInt(persoLife); + } + battle(ret,nb,f); +} + +function endBattle(v,nb, f){ + window.clearTimeout(timeout); + if(v=="mob")exitDungeon();//if you die in the dungeon, you are immediately sent out of the dungeon + nb++;//go to the next mob in the same floor + if(nb>=3){//floor changing + nb=0;//reset the number of the mob + f++;//increment the number of the floor + } + var tmphtml = "Le " + v + " a gagné."; + tmphtml += "" + document.getElementById("tab4").innerHTML = tmphtml; + displayExit(); + sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); +} + +function displayExit(){ + var tmphtml = "

"; + tmphtml += ""; + document.getElementById("tab4").innerHTML += tmphtml; } function exitDungeon(){ sendRequest("craftmine.php", "op=exitDungeon", function() { + window.clearTimeout(timeout); document.getElementById("tab4").innerHTML = "

Look at how poor you are! You can't access the dungeon, it is only for the elite.

"; showInfo("You have left the dungeon"); }); -- cgit v1.2.3-70-g09d2 From f171811a44364f605712aff1ca0808bfe570ef6e Mon Sep 17 00:00:00 2001 From: alexichi Date: Thu, 5 May 2016 23:06:29 +0200 Subject: add xp system and perso server side --- craftmine.php | 3 +++ data/monsters.xml | 9 +++++++++ inc/Monster.inc | 4 +++- inc/craftmine.inc | 2 ++ inc/dungeon.inc | 5 +++-- inc/perso.inc | 17 +++++++++++++++++ index.xhtml | 4 ++++ js/craftmine.js | 13 +++++++++++-- js/dungeon.js | 38 ++++++++++++++++++++++++++------------ js/perso.js | 5 +++++ 10 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 inc/perso.inc create mode 100644 js/perso.js (limited to 'data') diff --git a/craftmine.php b/craftmine.php index 43fdc66..d47989c 100644 --- a/craftmine.php +++ b/craftmine.php @@ -6,6 +6,7 @@ require_once("inc/shop.inc"); require_once("inc/craftmine.inc"); require_once("inc/dungeon.inc"); require_once("inc/savegame.inc"); +require_once("inc/perso.inc"); session_start(); // Must be placed *BEFORE* $_SESSION is actually used and *AFTER* all classes are imported @@ -52,6 +53,8 @@ switch($op) { case "launchDungeon" : launchDungeon(); break; case "exitDungeon" : exitDungeon(); break; case "sendDungeonProgress" : sendDungeonProgress(); break; + case "updatePerso" : updatePerso(); break; + case "sendPerso" : sendPerso(); break; case "saveGame": saveGame(); break; case "downSave": downSave(); break; case "listSaves": listSaves(); break; diff --git a/data/monsters.xml b/data/monsters.xml index 630e83a..ab29364 100644 --- a/data/monsters.xml +++ b/data/monsters.xml @@ -5,18 +5,21 @@ monster1 1 3 + 1 m
monster2 2 3 + 2 m monster3 3 4 + 3 m @@ -25,18 +28,21 @@ monster4 4 5 + 4 m monster5 5 6 + 5 m monster5 6 7 + 6 m @@ -45,18 +51,21 @@ monster6 8 9 + 8 m monster7 9 10 + 9 m Boss 10 12 + 10 m diff --git a/inc/Monster.inc b/inc/Monster.inc index fbb0fe9..c7063ec 100644 --- a/inc/Monster.inc +++ b/inc/Monster.inc @@ -5,12 +5,14 @@ class Monster { public $icon = ""; public $desc = ""; public $hp = 1; + public $xp = 0; public $level = 1; - function __construct($name, $level, $hp, $icon) { + function __construct($name, $level, $hp, $xp, $icon) { $this->name = $name; $this->level = $level; $this->hp = $hp; + $this->xp = $xp; $this->icon = $icon; } diff --git a/inc/craftmine.inc b/inc/craftmine.inc index 0d6a445..f5dbbb1 100644 --- a/inc/craftmine.inc +++ b/inc/craftmine.inc @@ -3,6 +3,7 @@ require_once("mine.inc"); require_once("shop.inc"); require_once("dungeon.inc"); +require_once("perso.inc"); function sendCraftMine() { $data = array("gold" => sendMine(), @@ -10,6 +11,7 @@ function sendCraftMine() { "inventory" => Inventory::sendContent(), "miners" => sendMiners(), "dungeon" => sendDungeon(), + "perso" => sendPerso(), ); echo json_encode($data); } diff --git a/inc/dungeon.inc b/inc/dungeon.inc index ebe74b7..c023cf8 100644 --- a/inc/dungeon.inc +++ b/inc/dungeon.inc @@ -12,8 +12,9 @@ function generateMonster(){ $dungeon["monsters"][$floor] = array(); foreach($f as $monster){ $dungeon["monsters"][$floor][] = new Monster((string)$monster->name, - intval($monster->level), - intval($monster->hp), + intval($monster->level), + intval($monster->hp), + intval($monster->xp), (string)$monster->icon); } } diff --git a/inc/perso.inc b/inc/perso.inc new file mode 100644 index 0000000..075f8ae --- /dev/null +++ b/inc/perso.inc @@ -0,0 +1,17 @@ + diff --git a/index.xhtml b/index.xhtml index ed3e7a6..7921cab 100644 --- a/index.xhtml +++ b/index.xhtml @@ -17,12 +17,16 @@ +

CraftMine

+
+ HP : 5/ LV : 1/ exp : 0 +
diff --git a/js/craftmine.js b/js/craftmine.js index 9af9b9f..c7a396f 100644 --- a/js/craftmine.js +++ b/js/craftmine.js @@ -5,6 +5,7 @@ data = { miners: 0, level: 4, hp: 5, + xp: 0, icon : "H" } @@ -52,12 +53,20 @@ function withdrawMine() { function initCraftMine() { sendRequest("craftmine.php", "op=getCraftMine", function(ret) { + console.log(ret.perso); data.gold = parseInt(ret.gold); // Server's response is a string data.mine = 0; // Reset mine + if(ret.perso){ + data.hp = ret.perso.hp; + data.xp = ret.perso.xp; + data.level = ret.perso.lv; + displayPerso(ret.perso.hp,ret.perso.xp,ret.perso.lv); + } if(ret.shop) displayShop(ret.shop); displayInventory(ret.inventory); - if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); - else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true); + if(ret.dungeon == false){}//if we have left the donjon + else if(typeof ret.dungeon.mob == "undefined") displayDungeon(0,1,true); //if we have reload just after buying the ticket + else displayDungeon(ret.dungeon.mob,ret.dungeon.flat,true);//if we have reload in the middle of the dungeon data.miners = parseInt(ret.miners); updateData("gold", "mine", "miners"); }) diff --git a/js/dungeon.js b/js/dungeon.js index c6ce014..65d1081 100644 --- a/js/dungeon.js +++ b/js/dungeon.js @@ -50,11 +50,12 @@ function strike(ret,nb, f){ var mobLife = document.getElementById("lifeMob").innerHTML; var persoLife = document.getElementById("lifePerso").innerHTML; if(mobLife == 0){ - endBattle("perso",nb,f); + data.hp = persoLife; + endBattle("perso",nb,f,ret); return; } else if(persoLife == 0){ - endBattle("mob",nb); + endBattle("mob",nb,f,ret); return; } if(hitRate<50+10*lvDiff){ @@ -68,19 +69,32 @@ function strike(ret,nb, f){ battle(ret,nb,f); } -function endBattle(v,nb, f){ +function endBattle(v,nb, f, ret){ window.clearTimeout(timeout); if(v=="mob")exitDungeon();//if you die in the dungeon, you are immediately sent out of the dungeon - nb++;//go to the next mob in the same floor - if(nb>=3){//floor changing - nb=0;//reset the number of the mob - f++;//increment the number of the floor + //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 += 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); + }); + } + nb++;//go to the next mob in the same floor + if(nb>=3){//floor changing + nb=0;//reset the number of the mob + f++;//increment the number of the floor + } + var tmphtml = "Le " + v + " a gagné."; + tmphtml += "" + document.getElementById("tab4").innerHTML = tmphtml; + displayExit(); + sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); } - var tmphtml = "Le " + v + " a gagné."; - tmphtml += "" - document.getElementById("tab4").innerHTML = tmphtml; - displayExit(); - sendRequest("craftmine.php", "op=sendDungeonProgress&floor="+f+"&mob="+nb); } function displayExit(){ diff --git a/js/perso.js b/js/perso.js new file mode 100644 index 0000000..365cf54 --- /dev/null +++ b/js/perso.js @@ -0,0 +1,5 @@ +function displayPerso(hp,xp,lv){ + document.getElementById("hp").innerHTML = hp; + document.getElementById("lv").innerHTML = lv; + document.getElementById("xp").innerHTML = xp; +} -- cgit v1.2.3-70-g09d2 From e46e058e34c030c4a5342e82dd24ac49104d56e9 Mon Sep 17 00:00:00 2001 From: piernov Date: Sun, 8 May 2016 14:39:31 +0200 Subject: Add features hp+3 to Life Bottle --- data/items.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'data') diff --git a/data/items.xml b/data/items.xml index 6c19b84..9489b1a 100644 --- a/data/items.xml +++ b/data/items.xml @@ -24,7 +24,9 @@ Life Bottle 5 - + + +3 + 🍶 A bottle which can heal you by regaining hp -- cgit v1.2.3-70-g09d2 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(-) (limited to 'data') 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 @@
    -
  • HP5
  • +
  • HP + 5 / + 5 + +
  • LV1
  • Exp0
  • +
  • Power + 1 + + 0 +
    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..2921c7d 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); } @@ -76,15 +78,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 +94,8 @@ 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 +108,17 @@ function displayExit(){ function exitDungeon(boss){ sendRequest("craftmine.php", "op=exitDungeon", function() { window.clearTimeout(timeout); - document.getElementById("tab4").innerHTML = "

    Not available, you have to buy a ticket in the build section.

    "; - 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 = "

    You have completed the dungeon! CONGRATULATIONS!

    "; + tmphmtl += "
      "; + tmphtml += "
    • You have earned 1000 gold coins

    • " + tmphmtl += "
    • You have earned 20 xp

    • "; + tmphmtl += "
    "; + document.getElementById("tab4").innerHTML = tmphtml; + } + else document.getElementById("tab4").innerHTML = "

    Not available, you have to buy a ticket in the build section.

    "; showInfo("You have left the dungeon"); }); } diff --git a/js/perso.js b/js/perso.js index 02a8892..44b82eb 100644 --- a/js/perso.js +++ b/js/perso.js @@ -1,12 +1,32 @@ -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); + }); } diff --git a/js/shop.js b/js/shop.js index a520a38..b6d4cee 100644 --- a/js/shop.js +++ b/js/shop.js @@ -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 -- cgit v1.2.3-70-g09d2