Added 'ineffective' as a success outcome for spying
This commit is contained in:
+15
-3
@@ -135,7 +135,7 @@ const spyLogRequest = (connection) => (req, res) => {
|
|||||||
return;
|
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
|
//creating a new entry
|
||||||
ret[result.id] = {
|
ret[result.id] = {
|
||||||
@@ -237,8 +237,8 @@ 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.2) : 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 (?, ?, ?, ?, ?, ?);';
|
||||||
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 ? 'success' : 'ineffective', spoilsGold], (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
let query = 'UPDATE profiles SET gold = gold + ? WHERE accountId = ?;';
|
let query = 'UPDATE profiles SET gold = gold + ? WHERE accountId = ?;';
|
||||||
@@ -439,6 +439,9 @@ const spyStealEquipmentSelectItemsToSteal = (connection, attackerId, defenderId,
|
|||||||
spyStealEquipmentIncrementItemsToInventory(connection, attackerId, items);
|
spyStealEquipmentIncrementItemsToInventory(connection, attackerId, items);
|
||||||
spyStealEquipmentDecrementItemsFromInventory(connection, defenderId, items);
|
spyStealEquipmentDecrementItemsFromInventory(connection, defenderId, items);
|
||||||
recordEquipmentStolen(connection, items, pastSpyingId);
|
recordEquipmentStolen(connection, items, pastSpyingId);
|
||||||
|
if (items.length) {
|
||||||
|
updateSuccessStatus(connection, 'success', pastSpyingId); //QOL improvement
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const spyStealEquipmentIncrementItemsToInventory = (connection, accountId, items) => {
|
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 = {
|
module.exports = {
|
||||||
spyRequest: spyRequest,
|
spyRequest: spyRequest,
|
||||||
spyStatusRequest: spyStatusRequest,
|
spyStatusRequest: spyStatusRequest,
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ CREATE TABLE IF NOT EXISTS pastSpying (
|
|||||||
defenderId INTEGER UNSIGNED,
|
defenderId INTEGER UNSIGNED,
|
||||||
attackingUnits INTEGER UNSIGNED,
|
attackingUnits INTEGER UNSIGNED,
|
||||||
|
|
||||||
success ENUM ('success', 'failure'),
|
success ENUM ('success', 'failure', 'ineffective'),
|
||||||
|
|
||||||
spoilsGold INTEGER,
|
spoilsGold INTEGER,
|
||||||
|
|
||||||
|
|||||||
+13
-11
@@ -1,18 +1,20 @@
|
|||||||
#NOTE: ALWAYS, ALWAYS, ALWAYS write a script in revert.sql that undoes these changes
|
#NOTE: ALWAYS, ALWAYS, ALWAYS write a script in revert.sql that undoes these changes
|
||||||
|
|
||||||
ALTER TABLE
|
ALTER TABLE
|
||||||
profiles
|
pastSpying
|
||||||
ADD COLUMN
|
MODIFY COLUMN
|
||||||
ladderRank INTEGER UNSIGNED
|
success ENUM ('success', 'failure', 'ineffective')
|
||||||
AFTER
|
|
||||||
accountId
|
|
||||||
;
|
;
|
||||||
|
|
||||||
ALTER TABLE
|
UPDATE
|
||||||
profiles
|
pastSpying
|
||||||
ADD COLUMN
|
SET
|
||||||
ladderRankWeight FLOAT UNSIGNED
|
success = 'ineffective'
|
||||||
AFTER
|
WHERE
|
||||||
ladderRank
|
success = 'success'
|
||||||
|
AND
|
||||||
|
spoilsGold = 0
|
||||||
|
AND
|
||||||
|
(SELECT COUNT(*) FROM equipmentStolen WHERE pastSpyingId = pastSpying.id) = 0
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user