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,9 +998,12 @@ router.put("/:id/:action/:value?", async (req, res) => {
|
||||
break;
|
||||
}
|
||||
const offer = req.body;
|
||||
let target;
|
||||
/* Verify that the offer sent by the active player matches what
|
||||
* 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') {
|
||||
let mismatch = false;
|
||||
target = game.players[offer.color];
|
||||
offer.gives.forEach(item => {
|
||||
const isOffered = target.gives.find(
|
||||
match => match.type === item.type && match.count === item.count);
|
||||
@ -1019,26 +1022,34 @@ router.put("/:id/:action/:value?", async (req, res) => {
|
||||
error = `Unfortunately, trades were re-negotiated in transit and the deal is invalid!`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Transfer goods */
|
||||
offer.gives.forEach(item => {
|
||||
player.gets.forEach(item => {
|
||||
if (target) {
|
||||
target[item.type] -= item.count;
|
||||
}
|
||||
player[item.type] += item.count;
|
||||
});
|
||||
offer.gets.forEach(item => {
|
||||
player.gives.forEach(item => {
|
||||
if (target) {
|
||||
target[item.type] += item.count;
|
||||
}
|
||||
player[item.type] -= item.count;
|
||||
});
|
||||
|
||||
delete game.turn.offer;
|
||||
if (target) {
|
||||
delete target.gives;
|
||||
delete target.gets;
|
||||
}
|
||||
delete session.player.gives;
|
||||
delete session.player.gets;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user