diff --git a/public/content/instructions.md b/public/content/instructions.md index 2acc58c..79c4d1e 100644 --- a/public/content/instructions.md +++ b/public/content/instructions.md @@ -71,7 +71,9 @@ Scientists don't fight. Instead, they offer other means of gaining advantage ove
---Coming Soon-- +Spies are another way to gain an advantage over your enemies. They're more expensive than soldiers, and they might not always produce results. However, they can be used at the same time as soldiers, and they can also steal your target's equipment. Spies have a 50% chance of stealing gold, and each spy has a 50% chance of stealing an item. Since their job is harder, they take 10 minutes for each spy used. + +Be careful though - if the spies are found, they will all be killed.
diff --git a/public/content/task_list.md b/public/content/task_list.md index 347ed26..aaf292d 100644 --- a/public/content/task_list.md +++ b/public/content/task_list.md @@ -1,8 +1,6 @@ Major --- -* Implement spies. -* Write the instructions for spies. * Implement badges. * Write the instructions for badges. * Implement countdown timers for combat and training. diff --git a/server/spying.js b/server/spying.js index b2a0cae..7461f05 100644 --- a/server/spying.js +++ b/server/spying.js @@ -234,7 +234,7 @@ const spyGameplayLogic = (connection, pendingSpying) => { }); } else { //steal this much gold on success - let spoilsGold = Math.random() >= 0.5 ? Math.floor(results[0].gold * 0.1) : 0; //50% chance of stealing gold + let spoilsGold = Math.random() >= 0.5 ? Math.floor(results[0].gold * 0.2) : 0; //50% chance of stealing gold let query = 'INSERT INTO pastSpying (eventTime, attackerId, defenderId, attackingUnits, success, spoilsGold) VALUES (?, ?, ?, ?, "success", ?);'; connection.query(query, [pendingSpying.eventTime, pendingSpying.attackerId, pendingSpying.defenderId, pendingSpying.attackingUnits, spoilsGold], (err) => { if (err) throw err; @@ -290,45 +290,52 @@ const spyStealEquipmentInner = (connection, attackerId, defenderId, attackingUni connection.query(query, [defenderId], (err, results) => { if (err) throw err; - //if he's not attacking, skip to the next step - if (!attacking) { - return spyStealEquipmentSelectItemsToSteal(connection, attackerId, defenderId, attackingUnits, results, pastSpyingId); - } - - //count the number of weapons/consumable items to be skipped, from strongest to weakest - let query = 'SELECT soldiers FROM profiles WHERE accountId = ?;'; - connection.query(query, [defenderId], (err, results) => { + getStatistics((err, { statistics }) => { if (err) throw err; - let soldierCount = results[0].soldiers; + //don't steal certain items + results = results.filter(item => statistics[item.type][item.name].stealable); - //armour - let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Armour";'; - connection.query(query, [defenderId], (err, armourResults) => { + //if he's not attacking, skip to the next step + if (!attacking) { + return spyStealEquipmentSelectItemsToSteal(connection, attackerId, defenderId, attackingUnits, results, pastSpyingId); + } + + //count the number of weapons/consumable items to be skipped, from strongest to weakest + let query = 'SELECT soldiers FROM profiles WHERE accountId = ?;'; + connection.query(query, [defenderId], (err, results) => { if (err) throw err; - //NOTE: Armour stays at home - it's never carried by soldiers (don't call removeForEachSoldier) + let soldierCount = results[0].soldiers; - //weapons - let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Weapon";'; - connection.query(query, [defenderId], (err, results) => { + //armour + let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Armour";'; + connection.query(query, [defenderId], (err, armourResults) => { if (err) throw err; - removeForEachSoldier(results, soldierCount, (err, weaponResults) => { + //NOTE: Armour stays at home - it's never carried by soldiers (don't call removeForEachSoldier) + + //weapons + let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Weapon";'; + connection.query(query, [defenderId], (err, results) => { if (err) throw err; - //consumables - let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Consumable";'; - connection.query(query, [defenderId], (err, results) => { + removeForEachSoldier(results, soldierCount, (err, weaponResults) => { if (err) throw err; - removeForEachSoldier(results, soldierCount, (err, consumableResults) => { + //consumables + let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Consumable";'; + connection.query(query, [defenderId], (err, results) => { if (err) throw err; - //splice the two arrays back together - let results = weaponResults.concat(consumableResults, armourResults); + removeForEachSoldier(results, soldierCount, (err, consumableResults) => { + if (err) throw err; - spyStealEquipmentSelectItemsToSteal(connection, attackerId, defenderId, attackingUnits, results, pastSpyingId); + //splice the two arrays back together + let results = weaponResults.concat(consumableResults, armourResults); + + spyStealEquipmentSelectItemsToSteal(connection, attackerId, defenderId, attackingUnits, results, pastSpyingId); + }); }); }); }); @@ -342,6 +349,7 @@ const spyStealEquipmentInner = (connection, attackerId, defenderId, attackingUni const removeForEachSoldier = (results, soldiers, cb) => { getStatistics((err, { statistics }) => { if (err) throw err; + results.sort((a, b) => statistics[a.type][a.name].combatBoost < statistics[b.type][b.name].combatBoost); results = results.map((item) => { @@ -357,7 +365,7 @@ const removeForEachSoldier = (results, soldiers, cb) => { return item; }); - results = results.filter(item => item.quantity > 0 && statistics[item.type][item.name].stealable); + results = results.filter(item => item.quantity > 0); cb(undefined, results); }); diff --git a/src/components/panels/equipment.jsx b/src/components/panels/equipment.jsx index 970c275..8e6cfa8 100644 --- a/src/components/panels/equipment.jsx +++ b/src/components/panels/equipment.jsx @@ -112,7 +112,7 @@ class Equipment extends React.Component { } //if you can't see it and you don't own it, don't render it (for legendary items) - if (!structure.statistics[type][name].visible && !structure.owned[name]) { + if (!structure.statistics[type][name].visible && !structure.owned[name]) { //TODO: sort out the visible mixup return; } diff --git a/src/components/panels/paged_combat_log.jsx b/src/components/panels/paged_combat_log.jsx index a997942..2bf6e0e 100644 --- a/src/components/panels/paged_combat_log.jsx +++ b/src/components/panels/paged_combat_log.jsx @@ -37,6 +37,8 @@ class PagedCombatLog extends React.Component { if (xhr.status === 200) { let json = JSON.parse(xhr.responseText); + json.sort((a, b) => new Date(b.eventTime) - new Date(a.eventTime)); + //on success this.setState(json); diff --git a/src/components/panels/paged_spying_log.jsx b/src/components/panels/paged_spying_log.jsx index 15d9608..4c02fc9 100644 --- a/src/components/panels/paged_spying_log.jsx +++ b/src/components/panels/paged_spying_log.jsx @@ -37,6 +37,8 @@ class PagedSpyingLog extends React.Component { if (xhr.status === 200) { let json = JSON.parse(xhr.responseText); + json.sort((a, b) => new Date(b.eventTime) - new Date(a.eventTime)); + //on success this.setState(json);