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" />
--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" />
-2
View File
@@ -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.
+34 -26
View File
@@ -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);
});
+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 (!structure.statistics[type][name].visible && !structure.owned[name]) {
if (!structure.statistics[type][name].visible && !structure.owned[name]) { //TODO: sort out the visible mixup
return;
}
@@ -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);
@@ -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);