diff --git a/src/markets/specialSlave.js b/src/markets/specialSlave.js index f3bc54bda6b4ad1a6357c2fbe8e4cdd23c8a6f7c..4fe18fdbe4315918ef6a3ad7f92e3f9d0004f290 100644 --- a/src/markets/specialSlave.js +++ b/src/markets/specialSlave.js @@ -5,7 +5,7 @@ App.Markets.specialSlave = function() { const el = document.createElement("p"); let p; - const heroSlaves = App.Utils.buildHeroArray(); + let heroSlaves = App.Utils.buildHeroArray(); let slave; let selectedID; @@ -75,11 +75,55 @@ App.Markets.specialSlave = function() { } App.UI.DOM.appendNewElement("p", el, App.UI.DOM.generateLinksStrip(linkArray)); + if (V.cheatMode) { + let oneSlaveCost = (s) => { let cost = slaveCost(s); return cost + (10 * Math.trunc((cost / 10) * 2)); }; + let allHeroSlaves = App.Utils.buildHeroArray().map( + (hs) => { + const slave = App.Utils.getHeroSlave(hs); + return {slave: slave, cost: oneSlaveCost(slave), ID: hs.ID}; + } + ); + let totalCost = allHeroSlaves.reduce((acc, s) => acc += s.cost, 0); + + if (V.cash > totalCost) { + App.UI.DOM.appendNewElement( + "div", + el, + App.UI.DOM.link( + `Buy all of them for ${cashFormat(totalCost)}`, + () => { + for (const hero of allHeroSlaves) { + cashX(forceNeg(hero.cost), "slaveTransfer", hero.slave); + newSlave(hero.slave); + V.heroSlavesPurchased.push(hero.ID); + } + refresh(); + } + ) + ); + } else { + App.UI.DOM.appendNewElement( + "div", + el, + App.UI.DOM.disabledLink( + `Buy all of them for ${cashFormat(totalCost)}`, + [`Cannot afford`] + ) + ); + } + } + return el; function refresh() { - jQuery("#complete-catalog").empty().append(catalog()); - jQuery("#show-slave").empty().append(showSlave()); + heroSlaves = App.Utils.buildHeroArray(); + if (heroSlaves.length === 0) { + jQuery("#complete-catalog").empty().append(`There are no longer any special slaves available.`); + jQuery("#show-slave").empty(); + } else { + jQuery("#complete-catalog").empty().append(catalog()); + jQuery("#show-slave").empty().append(showSlave()); + } } }