fix trade reject

This commit is contained in:
Johannes Schmelz 2024-12-01 02:07:39 +01:00
parent f3ec17b0b1
commit 4af08ffffd

View File

@ -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<PropertyField> offered = new HashSet<>();
Set<PropertyField> 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<PropertyField> 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<PropertyField> 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) {