Trading with bank seems to work
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
parent
8686663d80
commit
5cc69d04bc
@ -998,47 +998,58 @@ router.put("/:id/:action/:value?", async (req, res) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const offer = req.body;
|
const offer = req.body;
|
||||||
|
let target;
|
||||||
/* Verify that the offer sent by the active player matches what
|
/* Verify that the offer sent by the active player matches what
|
||||||
* the latest offer was that was received by the requesting player */
|
* the latest offer was that was received by the requesting player */
|
||||||
let mismatch = false, target = game.players[offer.color];
|
if (!offer.name || offer.name !== 'The bank') {
|
||||||
offer.gives.forEach(item => {
|
let mismatch = false;
|
||||||
const isOffered = target.gives.find(
|
target = game.players[offer.color];
|
||||||
match => match.type === item.type && match.count === item.count);
|
offer.gives.forEach(item => {
|
||||||
if (!isOffered) {
|
const isOffered = target.gives.find(
|
||||||
mismatch = true;
|
match => match.type === item.type && match.count === item.count);
|
||||||
|
if (!isOffered) {
|
||||||
|
mismatch = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
offer.gets.forEach(item => {
|
||||||
|
const isOffered = target.gets.find(
|
||||||
|
match => match.type === item.type && match.count === item.count);
|
||||||
|
if (!isOffered) {
|
||||||
|
mismatch = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (mismatch) {
|
||||||
|
error = `Unfortunately, trades were re-negotiated in transit and the deal is invalid!`;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
offer.gets.forEach(item => {
|
|
||||||
const isOffered = target.gets.find(
|
|
||||||
match => match.type === item.type && match.count === item.count);
|
|
||||||
if (!isOffered) {
|
|
||||||
mismatch = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (mismatch) {
|
|
||||||
error = `Unfortunately, trades were re-negotiated in transit and the deal is invalid!`;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Transfer goods */
|
/* Transfer goods */
|
||||||
offer.gives.forEach(item => {
|
player.gets.forEach(item => {
|
||||||
target[item.type] -= item.count;
|
if (target) {
|
||||||
|
target[item.type] -= item.count;
|
||||||
|
}
|
||||||
player[item.type] += item.count;
|
player[item.type] += item.count;
|
||||||
});
|
});
|
||||||
offer.gets.forEach(item => {
|
player.gives.forEach(item => {
|
||||||
target[item.type] += item.count;
|
if (target) {
|
||||||
|
target[item.type] += item.count;
|
||||||
|
}
|
||||||
player[item.type] -= item.count;
|
player[item.type] -= item.count;
|
||||||
});
|
});
|
||||||
|
|
||||||
delete game.turn.offer;
|
delete game.turn.offer;
|
||||||
delete target.gives;
|
if (target) {
|
||||||
delete target.gets;
|
delete target.gives;
|
||||||
|
delete target.gets;
|
||||||
|
}
|
||||||
delete session.player.gives;
|
delete session.player.gives;
|
||||||
delete session.player.gets;
|
delete session.player.gets;
|
||||||
|
|
||||||
game.turn.actions = [];
|
game.turn.actions = [];
|
||||||
|
|
||||||
addChatMessage(game, session, `${session.name} has accepted a trade offer from ${offer.name}.`);
|
addChatMessage(game, session, `${session.name} has accepted a trade ` +
|
||||||
|
`offer from ${(offer.name === 'The bank') ? 'the bank' : offer.name}.`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user