diff --git a/server/spying.js b/server/spying.js index 9f7600d..45c95d5 100644 --- a/server/spying.js +++ b/server/spying.js @@ -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, diff --git a/sql/create_database_structure.sql b/sql/create_database_structure.sql index c997ba6..34c4b2a 100644 --- a/sql/create_database_structure.sql +++ b/sql/create_database_structure.sql @@ -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, diff --git a/sql/update.sql b/sql/update.sql index f4467ff..0b16593 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -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 ;