can only trade fields without buildings

This commit is contained in:
Johannes Schmelz 2024-12-06 16:06:40 +01:00
parent 551786bf30
commit b50b5e64d1

View File

@ -18,11 +18,16 @@ import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.message.client.TradeOffer;
import pp.monopoly.model.TradeHandler;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.Sound;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Represents the trade menu dialog in the Monopoly application.
@ -200,12 +205,34 @@ public class TradeMenu extends Dialog {
* @return an iterable of property fields
*/
private Iterable<PropertyField> getPropertyFields(boolean isLeft) {
return app.getGameLogic()
Set<PropertyField> building = app.getGameLogic()
.getBoardManager()
.getPropertyFields(app.getGameLogic()
.getPlayerHandler()
.getPlayerById(isLeft ? tradeHandler.getSender().getId() : tradeHandler.getReceiver().getId())
.getProperties());
.getProperties())
.stream()
.filter(p -> p instanceof BuildingProperty)
.map(p -> (BuildingProperty) p)
.filter(p -> p.getHouses() == 0)
.collect(Collectors.toSet());
Set<PropertyField> rest = app.getGameLogic()
.getBoardManager()
.getPropertyFields(app.getGameLogic()
.getPlayerHandler()
.getPlayerById(isLeft ? tradeHandler.getSender().getId() : tradeHandler.getReceiver().getId())
.getProperties())
.stream()
.filter(p -> !(p instanceof BuildingProperty))
.collect(Collectors.toSet());
List<PropertyField> combinedProperties = new ArrayList<>();
combinedProperties.addAll(building);
combinedProperties.addAll(rest);
combinedProperties = combinedProperties.stream().sorted(Comparator.comparingInt(PropertyField::getId)).collect(Collectors.toList());
return combinedProperties;
}
/** Creates a text field for currency input. */
private TextField createCurrencyInput() {