From 4655191030cd6ab40608adbfca8906bc1c3f1148 Mon Sep 17 00:00:00 2001 From: Russell Date: Fri, 23 Jan 2015 15:57:07 +0000 Subject: [PATCH] Resolve the 0.1% chance issue with Weapons not generating due to a too high bonus --- index.html | 7 ++++--- weapons.js | 29 ++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 8668b4d..1332c09 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,8 @@ GrimoireJS - - + + @@ -57,6 +57,7 @@
@@ -71,4 +72,4 @@ Create an intelligence by running Intelligence.getItemIntelligence().print()Already input spells for wizard/sorceror, cleric, and druid. Check for other arcane and divine spells from other classes - \ No newline at end of file + diff --git a/weapons.js b/weapons.js index 825507a..171f103 100644 --- a/weapons.js +++ b/weapons.js @@ -107,7 +107,7 @@ Weapons.getSpecific = function(type) { } } }; //end getSpecific - + Weapons.data.meleeSpecial = [ {'name': 'Bane', 'bonus': 1}, {'name': 'Defending', 'bonus': 1}, @@ -432,7 +432,10 @@ Weapons.getWeapon = function(type, wClass, final) { 'cost': newWeapon.cost + Weapons.data.bonusCost[newWeapon.bonus + special.bonus].cost - Weapons.data.bonusCost[newWeapon.bonus].cost, }; } - break; + else { + weapon = newWeapon; //Don't apply the new special + } + break; } } else if(type == 'medium') { @@ -471,7 +474,10 @@ Weapons.getWeapon = function(type, wClass, final) { 'cost': newWeapon.cost + Weapons.data.bonusCost[newWeapon.bonus + special.bonus].cost - Weapons.data.bonusCost[newWeapon.bonus].cost, }; } - break; + else { + weapon = newWeapon; //Don't apply the new special + } + break; } } else if(type == 'major') { @@ -505,10 +511,23 @@ Weapons.getWeapon = function(type, wClass, final) { 'cost': newWeapon.cost + Weapons.data.bonusCost[newWeapon.bonus + special.bonus].cost - Weapons.data.bonusCost[newWeapon.bonus].cost, }; } - break; + else { + weapon = newWeapon; //Don't apply the new special + } + break; } } + if(weapon === undefined || Object.keys(weapon).length === 0) { + var err = new Error(); + console.log(type); + console.log(wClass); + console.log(final); + console.log("roll: " + roll); + console.log(newWeapon); + console.log(special); + return err.stack; + } var i = weapon.name.indexOf('+'); if(i != -1) { //move the '+X' to the front @@ -542,4 +561,4 @@ Weapons.getWeapons = function (numMinor, numMedium, numMajor, wClass) { weapons.push(Weapons.getWeapon('major', wClass)); }); return weapons; -}; \ No newline at end of file +};