Added 'ineffective' as a success outcome for spying

This commit is contained in:
2019-06-12 16:07:52 +10:00
parent 92dc79f367
commit 451d70eda1
3 changed files with 29 additions and 15 deletions
+15 -3
View File
@@ -135,7 +135,7 @@ const spyLogRequest = (connection) => (req, res) => {
return;
}
let hideData = req.body.id === result.defenderId && result.success === 'success';
let hideData = req.body.id === result.defenderId && (result.success === 'success' || result.success === 'ineffective');
//creating a new entry
ret[result.id] = {
@@ -237,8 +237,8 @@ const spyGameplayLogic = (connection, pendingSpying) => {
} else {
//steal this much gold on success
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) => {
let query = 'INSERT INTO pastSpying (eventTime, attackerId, defenderId, attackingUnits, success, spoilsGold) VALUES (?, ?, ?, ?, ?, ?);';
connection.query(query, [pendingSpying.eventTime, pendingSpying.attackerId, pendingSpying.defenderId, pendingSpying.attackingUnits, spoilsGold ? 'success' : 'ineffective', spoilsGold], (err) => {
if (err) throw err;
let query = 'UPDATE profiles SET gold = gold + ? WHERE accountId = ?;';
@@ -439,6 +439,9 @@ const spyStealEquipmentSelectItemsToSteal = (connection, attackerId, defenderId,
spyStealEquipmentIncrementItemsToInventory(connection, attackerId, items);
spyStealEquipmentDecrementItemsFromInventory(connection, defenderId, items);
recordEquipmentStolen(connection, items, pastSpyingId);
if (items.length) {
updateSuccessStatus(connection, 'success', pastSpyingId); //QOL improvement
}
};
const spyStealEquipmentIncrementItemsToInventory = (connection, accountId, items) => {
@@ -516,6 +519,15 @@ const recordEquipmentStolen = (connection, items, pastSpyingId) => {
});
};
const updateSuccessStatus = (connection, status, pastSpyingId) => {
let query = 'UPDATE pastSpying SET success = ? WHERE id = ?;';
connection.query(query, [status, pastSpyingId], (err) => {
if (err) throw err;
log('Success status updated', pastSpyingId, status);
});
}
module.exports = {
spyRequest: spyRequest,
spyStatusRequest: spyStatusRequest,
+1 -1
View File
@@ -145,7 +145,7 @@ CREATE TABLE IF NOT EXISTS pastSpying (
defenderId INTEGER UNSIGNED,
attackingUnits INTEGER UNSIGNED,
success ENUM ('success', 'failure'),
success ENUM ('success', 'failure', 'ineffective'),
spoilsGold INTEGER,
+13 -11
View File
@@ -1,18 +1,20 @@
#NOTE: ALWAYS, ALWAYS, ALWAYS write a script in revert.sql that undoes these changes
ALTER TABLE
profiles
ADD COLUMN
ladderRank INTEGER UNSIGNED
AFTER
accountId
pastSpying
MODIFY COLUMN
success ENUM ('success', 'failure', 'ineffective')
;
ALTER TABLE
profiles
ADD COLUMN
ladderRankWeight FLOAT UNSIGNED
AFTER
ladderRank
UPDATE
pastSpying
SET
success = 'ineffective'
WHERE
success = 'success'
AND
spoilsGold = 0
AND
(SELECT COUNT(*) FROM equipmentStolen WHERE pastSpyingId = pastSpying.id) = 0
;