Currently, I am in the process of creating an RPG character builder where each character is allocated 10 points to distribute among their characteristics and select advantages.
Character Constructor
function character(str, dex, con, int, wis) {
this.str = str;
this.dex = dex;
this.con = con;
this.int = int;
this.wis = wis;
}
Creating a Character
var player = new character()
player.str = 1
player.dex = 1
player.con = 1
player.int = 1
player.wis = 1
player.HP = player.con * 5
player.MP = player.wis * 5
I have successfully designed a function that calculates the total points used for characteristics to ensure they don't exceed the limit. How can I incorporate the cost of advantages (advantage.cost) into this function to check if it exceeds the total points along with characteristics?
Additionally, how can I implement bonuses (e.g., the Acceleration advantage adds +1 dex to the character)?
Function to Calculate Total Points
var calculateTotalPoints = () => {
return player.str + player.dex + player.con + player.int + player.wis
}
const checkTotalPoints = () => {
if (calculateTotalPoints() > 10) {
console.log("You have exceeded the maximum number of points allowed")
} else {
console.log("Success!")
}
}
checkTotalPoints()
Advantages Constructor
If my character has these two advantages, how can I access their sum and apply the first bonus?
function advantage(name, cost, bonus) {
this.name = name;
this.cost = cost;
this.bonus = bonus
}
Example Advantages
var acceleration = new advantage("Acceleration", 1, player.dex + 1)
var adapter = new advantage("Adapter", 1)