aboutsummaryrefslogtreecommitdiffstats
path: root/rogue-server.js
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2019-12-01 22:42:27 -0500
committerMatt Kohls <mattkohls13@gmail.com>2019-12-01 22:42:27 -0500
commit6f5579903f25e21419912ed851d0c2f6a7bdc151 (patch)
treef7f811f9d50eb8d24793983cbb9429865a166d7f /rogue-server.js
parent41b4d4b6a1921c8cf0af1c739fcdd986c595b3b7 (diff)
downloadrogue.js-6f5579903f25e21419912ed851d0c2f6a7bdc151.tar.gz
rogue.js-6f5579903f25e21419912ed851d0c2f6a7bdc151.tar.bz2
rogue.js-6f5579903f25e21419912ed851d0c2f6a7bdc151.zip
Adding some actions
Diffstat (limited to 'rogue-server.js')
-rw-r--r--rogue-server.js100
1 files changed, 77 insertions, 23 deletions
diff --git a/rogue-server.js b/rogue-server.js
index b7707c7..af0b10d 100644
--- a/rogue-server.js
+++ b/rogue-server.js
@@ -23,6 +23,18 @@ function genStat() {
return value;
}
+class Location {
+ constructor(x, y, floor) {
+ this.x = x;
+ this.y = y;
+ this.floor = floor;
+ }
+
+ get x { return this.x; }
+ get y { return this.y; }
+ get floor { return this.floor; }
+}
+
class Item {
constructor(bonus, type) {
this.bonus = bonus;
@@ -72,6 +84,7 @@ class Mob {
this.intelligence = intelligence;
this.wisdom = wisdom;
this.level = level;
+ this.location = location;
this.xp = 0;
this.hp = level * getBonus(constitution) + Math.floor(Math.random() * 6) * level;
this.hpMax = this.hp;
@@ -86,7 +99,7 @@ class Mob {
if(this.xp >= 100) {
this.xp = 0;
this.level += 1;
- this.hp += getBonus(this.constitution) + Math.floor(Math.random() * 6);
+ this.hpMax += getBonus(this.constitution) + Math.floor(Math.random() * 6);
}
}
@@ -132,6 +145,14 @@ class Mob {
this.hp = value;
}
+ get location() {
+ return this.location;
+ }
+
+ set location(value) {
+ this.location = value;
+ }
+
set action(value) {
this.action = value;
}
@@ -207,6 +228,7 @@ class Mob {
/** Turn generation **/
var mobs = [];
+var dead = [];
/**
* Generates the turn order by placing the index of the mob into an array.
@@ -229,33 +251,64 @@ function getInititive() {
return init
}
+function attack(mobA, mobB, type) {
+ var attack = mobs[mobA].attack(type);
+ var defence;
+ if(type == "staff") {
+ defence = mobs[mobB].spellResist;
+ } else if(type == "weapon") {
+ defence = mobs[mobB].ac;
+ }
+ if(attack >= defence) {
+ mobs[mobB].hp = mobs[mobB].hp - mobs[mobA].damage(type);
+ var xp = 1;
+ if(mobs[mobB].hp < 0 && dead.includes(mobB) == false) {
+ dead.push(mobB);
+ xp = 10;
+ }
+ mobs[mobA].addXP(xp);
+ }
+}
+
+function move(mob, dir) {
+
+
+}
+
+function cast(mob, dir) {
+
+}
+
function performActions(init) {
for(var i = init.length - 1; i > -1; i--) {
for(var j = 0; j < init[i].length; j++) {
+ var mob = init[i][j];
var message = "";
- switch(mobs[init[i][j]].action.type) {
- case 'wait':
- message = "You sit";
- break;
- case 'move':
-
- break;
- case 'cast':
-
- break;
- case 'drink':
- message = mobs[init[i][j]].drinkPotion();
- break;
- case 'pick':
- //message = mobs[init[i][j]].pickUp();
- break;
- case 'drop':
- message = "Item dropped";
- mobs[init[i][j]].drop(mobs[init[i][j]].action.message);
- default:
- break;
+ if(mobs[mob].hp > 0) {
+ switch(mobs[mob].action.type) {
+ case 'wait':
+ message = "You sit";
+ break;
+ case 'move':
+ move(mob, mobs[mob].action.message);
+ break;
+ case 'cast':
+ cast(mob, mobs[mob].action.message);
+ break;
+ case 'drink':
+ message = mobs[mob].drinkPotion();
+ break;
+ case 'pick':
+ //message = mobs[init[i][j]].pickUp();
+ break;
+ case 'drop':
+ message = "Item dropped";
+ mobs[mob].drop(mobs[mob].action.message);
+ default:
+ break;
+ }
}
- mobs[init[i][j]].action = new Action('done', message);
+ mobs[mob].action = new Action('done', message);
}
}
}
@@ -266,6 +319,7 @@ function sendResults() {
function genTurn() {
+ dead = new Array();
var init = getInititive();
performActions(init);