r-paper-scissors
A module to use for rock, paper, scissors style battle
by Sam Fereday
JavaScript
/// You could use this for a bunch of things, whatever you like
const Modifiers = { // Won't always be so generic
strOverLevel: 1.01,
hpOverLevel: 1.01
};
const StaticData = { // Won't always be a const since 'lvl' has to change
user: {
level: 1, // Level is the only thing that changes, as everthing else grows from base stats combined with this.
baseStats: {
hp: 100, // All entities have a base health to work from
att: 30, // The affective damage your weapon does
vit: 10, // More vitality, the higher the curve on your health
str: 10, // Similar to vit
luck: 4 // If this is higher, you score a greater chance at positive things for your char rolls
}
},
opponent: {
level: 2,
baseStats: {
hp: 100,
att: 30,
vit: 10,
str: 10,
luck: 4
}
}
};
const Outcomes = {
WIN: 0,
TIE: 1,
LOSE: 2
};
const Types = {
ROCK: 0,
PAPER: 1,
SCISSORS: 2
};
class Helpers {
static getDMGForLevel(lvl, str, att) {
return ((str * att) * Modifiers.strOverLevel) * lvl;
}
static getHealthForLevel(lvl, vit, hp) {
console.log(lvl, vit, hp)
return ((vit * hp) * Modifiers.hpOverLevel) * lvl;
}
}
class Actor {
constructor(name) {
this.name = name;
this.maxHP = 0;
this.HP = 0;
return this;
}
setHealth(n) {
this.maxHP = n;
this.HP = n;
return this;
}
damage(n, ceilDamage) {
if (ceilDamage)
n = Math.round(n);
this.HP -= n;
this.HP = this.HP < 0 ? 0 : this.HP;
this.HP = this.HP > this.maxHP ? this.maxHP : this.HP;
if (this.isDead()) {
console.info(this.name + " just lost " + Math.abs(n) + " health and has " + this.HP + " remaining of " + this.maxHP + ".");
console.info(this.name + " has perished.");
return;
}
if (n === 0) {
console.info(this.name + " lost no health.");
} else {
console.info(this.name + " just lost " + Math.abs(n) + " health and has " +...