From 4af08ffffd1e8496501affcd7fefe7b70a781270 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 1 Dec 2024 02:07:39 +0100 Subject: [PATCH] fix trade reject --- .../monopoly/game/server/ServerGameLogic.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index 8bc7920..6891a17 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -256,38 +256,41 @@ public class ServerGameLogic implements ClientInterpreter { TradeHandler tradeHandler = msg.getTradeHandler(); + + Player receiver = playerHandler.getPlayerById(tradeHandler.getReceiver().getId()); Player sender = playerHandler.getPlayerById(tradeHandler.getSender().getId()); + + if(msg.isAccepted()) { + Set offered = new HashSet<>(); - Set offered = new HashSet<>(); + for (PropertyField propertyField : tradeHandler.getOfferedProperties()) { + offered.add( (PropertyField) boardManager.getFieldAtIndex(propertyField.getId())); + } - for (PropertyField propertyField : tradeHandler.getOfferedProperties()) { - offered.add( (PropertyField) boardManager.getFieldAtIndex(propertyField.getId())); + Set requested = new HashSet<>(); + + for (PropertyField propertyField : tradeHandler.getRequestedProperties()) { + requested.add( (PropertyField) boardManager.getFieldAtIndex(propertyField.getId())); + } + + executeTrade(sender, receiver, offered, requested); + + sender.earnMoney(tradeHandler.getRequestedAmount()); + sender.pay(tradeHandler.getOfferedAmount()); + receiver.earnMoney(tradeHandler.getOfferedAmount()); + receiver.pay(tradeHandler.getRequestedAmount()); + + for (int i = 0; i < tradeHandler.getOfferedJailCards(); i++) { + sender.removeJailCard(); + receiver.addJailCard(); + } + + for (int i = 0; i < tradeHandler.getRequestedAmount(); i++) { + sender.addJailCard(); + receiver.removeJailCard(); + } } - - Set requested = new HashSet<>(); - - for (PropertyField propertyField : tradeHandler.getRequestedProperties()) { - requested.add( (PropertyField) boardManager.getFieldAtIndex(propertyField.getId())); - } - - executeTrade(sender, receiver, offered, requested); - - sender.earnMoney(tradeHandler.getRequestedAmount()); - sender.pay(tradeHandler.getOfferedAmount()); - receiver.earnMoney(tradeHandler.getOfferedAmount()); - receiver.pay(tradeHandler.getRequestedAmount()); - - for (int i = 0; i < tradeHandler.getOfferedJailCards(); i++) { - sender.removeJailCard(); - receiver.addJailCard(); - } - - for (int i = 0; i < tradeHandler.getRequestedAmount(); i++) { - sender.addJailCard(); - receiver.removeJailCard(); - } - updateAllPlayers(); if (receiver != null && sender != null) {