Progression.js
A component that handles leveling up and stat modification data returns.
by Sam Fereday
JavaScript
/* What does progression js do?
- Applies levels to your player data. This includes various experience calculations. It wont actually store anything on itself, but it will run number crunchers, and return the data in a new format for you to use or apply to the model passed in.
- The same will go for stats. Whilst again it wont really be storing these, it will work out the various stats types that you pass it. I'm tempted to stick in some enums that will contain various stat types to compare against. Come to think of it, passing in a config for this would be good. And you can add the calculation to perform on each one on each level.
- So whilst it does have a flat config on which to set all its base levels off, this is generally speaking more of a calculator.
*/
var Progression = function() {
// Algorithm enums
this.algorithmEnums = {
basic: 1,
advanced: 2
}
// Static algorithms sit in here
this.algorithms = [{
type: this.algorithmEnums.basic,
levelAlgorithm: function(){
return levelObject;
},
statAlgorithm: function(){
return statObject;
}
},
{
type: this.algorithmEnums.advanced,
levelAlgorithm: function(){
return levelObject;
},
statAlgorithm: function(){
return statObject;
}
}];
this.setCurrentAlgorightm(this.algorithmEnums.basic);
};
Progression.prototype.setCurrentAlgorithm = function(type) {
this.currentAlgorithm = this.algorithms.find(function(alg){
return alg.type === type;
});
};
Progression.prototype.levelUp = function(dataIn) {
if(!this.currentAlgorithm)
{
console.error("No algorithm set in list:", this.algorithms);
return;
}
return this.currentAlgorithm.levelAlgorithm(dataIn);
};
Progression.prototype.levelStats = function(dataIn) {
// This 'should' take the current stat and use the built in multiplier algorithm currently assigned.
if(!this.currentAlgorithm)
{
console.error("No algorithm set in list:", this.algorithms);
...