added a hashset to fix double checking of powercards in the visitor

This commit is contained in:
Fleischer Hanno
2024-12-10 14:36:26 +01:00
parent 9f8fd9c22f
commit e952233d20

View File

@@ -1,5 +1,6 @@
package pp.mdga.server.automaton.game.turn; package pp.mdga.server.automaton.game.turn;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.card.PowerCard; import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.NoPowerCardMessage; import pp.mdga.message.client.NoPowerCardMessage;
@@ -40,6 +41,7 @@ public class PowerCardState extends TurnAutomatonState {
private ServerCardVisitor visitor; private ServerCardVisitor visitor;
private PowerCard selectedCard; private PowerCard selectedCard;
private final Set<Piece> selectedPieces = new HashSet<>(); private final Set<Piece> selectedPieces = new HashSet<>();
private final Set<BonusCard> chekedCards = new HashSet<>();
/** /**
* Constructs a server state of the specified game logic. * Constructs a server state of the specified game logic.
@@ -53,15 +55,20 @@ public PowerCardState(TurnState turnAutomaton, ServerGameLogic logic) {
this.shieldCardState = new ShieldCardState(this, logic); this.shieldCardState = new ShieldCardState(this, logic);
this.swapCardState = new SwapCardState(this, logic); this.swapCardState = new SwapCardState(this, logic);
this.turboCardState = new TurboCardState(this, logic); this.turboCardState = new TurboCardState(this, logic);
} }
@Override @Override
public void enter() { public void enter() {
chekedCards.clear();
LOGGER.log(System.Logger.Level.INFO, "Enter PowerCardState state."); LOGGER.log(System.Logger.Level.INFO, "Enter PowerCardState state.");
this.setCurrentState(this.choosePowerCardState); this.setCurrentState(this.choosePowerCardState);
this.visitor = new ServerCardVisitor(this.logic); this.visitor = new ServerCardVisitor(this.logic);
for (PowerCard card : this.turnAutomaton.getPlayer().getHandCards()) { for (PowerCard card : this.turnAutomaton.getPlayer().getHandCards()) {
card.accept(this.visitor); if (!chekedCards.contains(card.getCard())) {
chekedCards.add(card.getCard());
card.accept(this.visitor);
}
} }
if (this.visitor.getCards().isEmpty()) { if (this.visitor.getCards().isEmpty()) {