Fixed network latency bug
This commit is contained in:
@@ -226,18 +226,3 @@ module.exports = {
|
||||
runCombatTick: runCombatTick,
|
||||
isAttacking: isAttacking
|
||||
}
|
||||
|
||||
/*
|
||||
> You can attack another player using your soldiers (it doesn't work without soldiers).
|
||||
> Doing so takes time, up to 10 seconds for every soldier you have.
|
||||
> Combat takes place at the end of the time delay, at which point you can attack people again (after reloading the page).
|
||||
> While attacking, you are undefended.
|
||||
> While undefended, your recruits act as combatants, otherwise your soldiers do.
|
||||
> The chance of success is determined by the ratio of each side's combatant strength.
|
||||
> Recruits have a strength equal to 0.25 times that of a soldier.
|
||||
> On a success, you steal 10% of the target's gold. On a failure, you steal 2% of the target's gold.
|
||||
> The attacking force will lose a percentage, rounded down, of their units - 5% on a success, 10% on a failure (edit: excluding the first 10 units).
|
||||
> If the server resets (which happens alot) combat still progresses as expected.
|
||||
* All combat is logged and presented to the player.
|
||||
*/
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
let weapons = [
|
||||
{ name: 'Stick', cost: 50, boost: 0.02, level: 1 },
|
||||
{ name: 'Dagger', cost: 75, boost: 0.03, level: 2 },
|
||||
{ name: 'Sword', cost: 100, boost: 0.04, level: 3 },
|
||||
{ name: 'Longsword', cost: 150, boost: 0.05, level: 4 },
|
||||
{ name: 'Frying Pan', cost: 200, boost: 0.06, level: 5 },
|
||||
];
|
||||
|
||||
let armour = [
|
||||
{ name: 'leather', cost: 75, boost: 0.02, level: 2 },
|
||||
{ name: 'gambeson', cost: 100, boost: 0.03, level: 3 },
|
||||
{ name: 'chainmail', cost: 150, boost: 0.04, level: 4 },
|
||||
{ name: 'platemail', cost: 200, boost: 0.05, level: 5 },
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
weapons: weapons,
|
||||
armour: armour
|
||||
};
|
||||
+19
-5
@@ -250,8 +250,8 @@ const trainRequest = (connection) => (req, res) => {
|
||||
}
|
||||
|
||||
//update the profile with new values
|
||||
let query = 'UPDATE profiles SET gold = gold - ?, recruits = recruits - 1, soldiers = soldiers + ?, spies = spies + ?, scientists = scientists + ? WHERE accountId = ?;';
|
||||
connection.query(query, [cost, fields.role === 'soldier' ? 1 : 0, fields.role === 'spy' ? 1 : 0, fields.role === 'scientist' ? 1 : 0, fields.id], (err) => {
|
||||
let query = 'UPDATE profiles SET gold = gold - ?, recruits = recruits - 1, soldiers = soldiers + ?, spies = spies + ?, scientists = scientists + ? WHERE accountId = ? AND gold >= ? AND recruits > 0;';
|
||||
connection.query(query, [cost, fields.role === 'soldier' ? 1 : 0, fields.role === 'spy' ? 1 : 0, fields.role === 'scientist' ? 1 : 0, fields.id, cost], (err) => {
|
||||
if (err) throw err;
|
||||
|
||||
//send the new profile data as JSON (NOTE: possible duplication)
|
||||
@@ -276,7 +276,7 @@ const trainRequest = (connection) => (req, res) => {
|
||||
scientists: results[0].scientists
|
||||
});
|
||||
res.end();
|
||||
log('Train successful', fields.username, fields.role, fields.id, fields.token);
|
||||
log('Train executed', fields.username, fields.role, fields.id, fields.token);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -344,8 +344,22 @@ const untrainRequest = (connection) => (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
//hacky
|
||||
let role = null;
|
||||
if (fields.role === 'soldier') {
|
||||
role = 'soldiers';
|
||||
} else if (fields.role === 'spy') {
|
||||
role = 'spies';
|
||||
} else if (fields.role === 'scientist') {
|
||||
role = 'scientists';
|
||||
} else {
|
||||
res.status(400).write(log('Unknown role found', fields.role));
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
//update the profile with new values
|
||||
let query = 'UPDATE profiles SET recruits = recruits + 1, soldiers = soldiers - ?, spies = spies - ?, scientists = scientists - ? WHERE accountId = ?;';
|
||||
let query = `UPDATE profiles SET recruits = recruits + 1, soldiers = soldiers - ?, spies = spies - ?, scientists = scientists - ? WHERE accountId = ? AND ${role} > 0;`;
|
||||
connection.query(query, [fields.role === 'soldier' ? 1 : 0, fields.role === 'spy' ? 1 : 0, fields.role === 'scientist' ? 1 : 0, fields.id], (err) => {
|
||||
if (err) throw err;
|
||||
|
||||
@@ -371,7 +385,7 @@ const untrainRequest = (connection) => (req, res) => {
|
||||
scientists: results[0].scientists
|
||||
});
|
||||
res.end();
|
||||
log('Untrain successful', fields.username, fields.role, fields.id, fields.token);
|
||||
log('Untrain executed', fields.username, fields.role, fields.id, fields.token);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user