Fixed "stealable", and wrote spy instructions

This commit is contained in:
2019-06-05 15:20:15 +10:00
parent c88162ef03
commit a1c0f279c2
6 changed files with 42 additions and 30 deletions
+3 -1
View File
@@ -71,7 +71,9 @@ Scientists don't fight. Instead, they offer other means of gaining advantage ove
<div class="break" /> <div class="break" />
--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 <span>all be killed</span>.
<div class="break" /> <div class="break" />
-2
View File
@@ -1,8 +1,6 @@
Major Major
--- ---
* Implement spies.
* Write the instructions for spies.
* Implement badges. * Implement badges.
* Write the instructions for badges. * Write the instructions for badges.
* Implement countdown timers for combat and training. * Implement countdown timers for combat and training.
+34 -26
View File
@@ -234,7 +234,7 @@ const spyGameplayLogic = (connection, pendingSpying) => {
}); });
} else { } else {
//steal this much gold on success //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", ?);'; 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) => { connection.query(query, [pendingSpying.eventTime, pendingSpying.attackerId, pendingSpying.defenderId, pendingSpying.attackingUnits, spoilsGold], (err) => {
if (err) throw err; if (err) throw err;
@@ -290,45 +290,52 @@ const spyStealEquipmentInner = (connection, attackerId, defenderId, attackingUni
connection.query(query, [defenderId], (err, results) => { connection.query(query, [defenderId], (err, results) => {
if (err) throw err; if (err) throw err;
//if he's not attacking, skip to the next step getStatistics((err, { statistics }) => {
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; 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 //if he's not attacking, skip to the next step
let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Armour";'; if (!attacking) {
connection.query(query, [defenderId], (err, armourResults) => { 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; 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 //armour
let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Weapon";'; let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Armour";';
connection.query(query, [defenderId], (err, results) => { connection.query(query, [defenderId], (err, armourResults) => {
if (err) throw err; 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; if (err) throw err;
//consumables removeForEachSoldier(results, soldierCount, (err, weaponResults) => {
let query = 'SELECT * FROM equipment WHERE accountId = ? AND type = "Consumable";';
connection.query(query, [defenderId], (err, results) => {
if (err) throw err; 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; if (err) throw err;
//splice the two arrays back together removeForEachSoldier(results, soldierCount, (err, consumableResults) => {
let results = weaponResults.concat(consumableResults, armourResults); 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) => { const removeForEachSoldier = (results, soldiers, cb) => {
getStatistics((err, { statistics }) => { getStatistics((err, { statistics }) => {
if (err) throw err; if (err) throw err;
results.sort((a, b) => statistics[a.type][a.name].combatBoost < statistics[b.type][b.name].combatBoost); results.sort((a, b) => statistics[a.type][a.name].combatBoost < statistics[b.type][b.name].combatBoost);
results = results.map((item) => { results = results.map((item) => {
@@ -357,7 +365,7 @@ const removeForEachSoldier = (results, soldiers, cb) => {
return item; 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); cb(undefined, results);
}); });
+1 -1
View File
@@ -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 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; return;
} }
@@ -37,6 +37,8 @@ class PagedCombatLog extends React.Component {
if (xhr.status === 200) { if (xhr.status === 200) {
let json = JSON.parse(xhr.responseText); let json = JSON.parse(xhr.responseText);
json.sort((a, b) => new Date(b.eventTime) - new Date(a.eventTime));
//on success //on success
this.setState(json); this.setState(json);
@@ -37,6 +37,8 @@ class PagedSpyingLog extends React.Component {
if (xhr.status === 200) { if (xhr.status === 200) {
let json = JSON.parse(xhr.responseText); let json = JSON.parse(xhr.responseText);
json.sort((a, b) => new Date(b.eventTime) - new Date(a.eventTime));
//on success //on success
this.setState(json); this.setState(json);