PO Rune Crafting Code Test

Just some code examples of how one might implement some sort of rune craft system, or, weapon / armour craft too.

by Sam Fereday

HTML

<div id="output"></div>

CSS

body {
  font: 75%/1.4em arial;
}

#output {
  width: 50%;
  word-wrap: break-word;
}

JavaScript

// Assumes that the Runestone is new, doesn't cater to modification of existing yet.
// All runes start off as 'moonstones'. Compressed natural magical elements that have become rocks over time.
var Moonstone = function(){};
Moonstone.prototype = {
	name: null,
  level: 0,
  expForLevel: 100,
  currentExp: 0,
	attackType: null,
  damageType: null,
  afterState: null,
  magicCore: null,
  stats: {
  	outputDamage: 0,
    mentalRequirement: 0,
    castTime: 0
  },
  setAttackType: function(str) {
  	// multiShot, singleShot
    this.attackType = str;
  },
  setDamageType: function(str) {
  	// all targets, single target
    this.damageType = str;
  },
  setMagicCore: function(str) {
  	// could be all sorts (thunder, fire, fire2, thunder 3, etc)
    this.magicCore = str;
  },
  setAfterState: function(str) {
  	// some magics can apply after effects
    this.afterState = str;
  },
  setAccessory: function(str) {
		// sets an accessory to affect the rune stones base stats in a certain way
		this.accessory = str;
  },
  calculateEffectiveness: function() {
  	// Get all the above properties and decide what to do with them. Performs a lookup on a data table for the ID given on core, and also any accessory added.
    // Just a test for now
    this.stats.outputDamage = 120;
    this.stats.mentalRequirement = 234;
    this.stats.castTime = 2000;
  },
  advance: function() {
  	// Advances the level of this moonstone over time in use, it'll get more powerful as time goes on.
    this.level += 1;
    // Calculate exp, etc, then re-evaluate power.
    this.calculateEffectiveness();
  },
  setName: function(str) {
  	// Finally set a name for this Moonstone
    this.name = str;
  }
};

// Step 1: Grab an empty Moonstone (found through various means)
var emptyMoonstone = new Moonstone();

// Step 2: Apply the attack type (set by an item or scroll probably)
emptyMoonstone.setAttackType("multiShot");

// Step 3: Apply the damage type (same as...