package server.lobby.state;

import io.netty.channel.Channel;
import proto.Command;
import server.game.Contract;
import server.game.Player;
import server.lobby.Lobby;

public class ContractState extends AState {

    private int playerTurn;
    private Contract contract;

    public ContractState(Lobby lobby) {
        super("Contract", lobby);
    }

    @Override
    public AState initialize() {
        this.getLobby().broadcast("You need to put contracts.", null);
        this.playerTurn = 0;
        this.displayTurnMessage();
        return this;
    }

    @Override
    public boolean isFinished() {
        return this.playerTurn >= 4;
    }

    @Override
    public AState getNextState() {
        if (this.contract != null) {
            return new TurnState(this.getLobby(), this.contract);
        } else {
            this.getLobby().broadcast("Anyone put a contract. Replay the round.", null);
            return new DrawState(this.getLobby());
        }
    }

    @Override
    public void handleAction(Channel channel, Command.LobbyCmd cmd) {
        if (cmd.getCmdType().equals(Command.LobbyCmd.CmdType.CONTRACT)) {
            Player player = this.getLobby().getPlayer(channel);
            if (this.getLobby().getPlayers().toArray()[this.playerTurn].equals(player)) {
                if (cmd.getContract().getType().equals(Command.Contract.Type.PASS)) {
                    this.getLobby().broadcast(player.getName() + " passed.", null);
                } else {
                    this.getLobby().broadcast(player.getName() + " put a contract: " + cmd.getContract().getType()
                            + " " + cmd.getContract().getValue() + ".", null);
                    this.contract = new Contract(player.getTeam(), cmd.getContract().getType(), cmd.getContract().getValue());
                }

                this.playerTurn++;
                this.displayTurnMessage();
            } else {
                this.getLobby().sendMsg("[SERVER] This is not your turn.", channel);
            }
        }
    }

    private void displayTurnMessage() {
        Player player = (Player) this.getLobby().getPlayers().toArray()[this.playerTurn];
        this.getLobby().broadcast("This is the turn of " + player.getName() + " to put a contract.", null);
        this.getLobby().sendMsg("[SERVER] This is your turn to choose a contract.",
                this.getLobby().getChannelByPlayer(player));
    }

}

@@ -101,23 +101,75 @@
 r.game.C
-ontract
+ard;%0D%0Aimport server.game.Contract;%0D%0Aimport server.game.Deck
 ;%0D%0Aimpor
@@ -1232,32 +1232,888 @@
  %7B%0D%0A            
+this.handleContract(channel, cmd);%0D%0A        %7D else if (cmd.getCmdType().equals(Command.LobbyCmd.CmdType.SHOW_CARDS)) %7B%0D%0A            this.handleShowCards(channel, cmd);%0D%0A        %7D%0D%0A    %7D%0D%0A%0D%0A    private void handleShowCards(Channel channel, Command.LobbyCmd cmd) %7B%0D%0A        Deck deck = this.getLobby().getPlayer(channel).getDeck();%0D%0A%0D%0A        StringBuilder stringBuilder = new StringBuilder();%0D%0A%0D%0A        stringBuilder.append(%22%5BSERVER%5D List of your cards:%22);%0D%0A        for (Card card : deck.getCards()) %7B%0D%0A            stringBuilder.append(%22%5Cn-%3E %22)%0D%0A                    .append(card.getFaceName())%0D%0A                    .append(%22 of %22)%0D%0A                    .append(card.getColorName());%0D%0A        %7D%0D%0A%0D%0A        this.getLobby().sendMsg(stringBuilder.toString(), channel);%0D%0A    %7D%0D%0A%0D%0A    private void handleContract(Channel channel, Command.LobbyCmd cmd) %7B%0D%0A        
 Player player = 
@@ -2141,36 +2141,32 @@
 ayer(channel);%0D%0A
-    
         if (this
@@ -2244,28 +2244,24 @@
             
-  
-  
 if (cmd.getC
@@ -2327,36 +2327,32 @@
                 
-    
 this.getLobby().
@@ -2404,36 +2404,32 @@
 );%0D%0A            
-  
-  
 %7D else %7B%0D%0A      
@@ -2414,36 +2414,32 @@
       %7D else %7B%0D%0A
-    
                 
@@ -2558,20 +2558,16 @@
         
- 
-   
 + %22 %22 + 
@@ -2602,36 +2602,32 @@
  + %22.%22, null);%0D%0A
-    
                 
@@ -2742,28 +2742,24 @@
             
-    
 %7D%0D%0A%0D%0A       
@@ -2759,28 +2759,24 @@
             
-   
- 
 this.playerT
@@ -2783,20 +2783,16 @@
 urn++;%0D%0A
-    
         
@@ -2823,36 +2823,32 @@
 age();%0D%0A        
-  
-  
 %7D else %7B%0D%0A      
@@ -2833,36 +2833,32 @@
       %7D else %7B%0D%0A
-    
             this
@@ -2923,31 +2923,16 @@
 nnel);%0D%0A
-            %7D%0D%0A
         

Add showCards to ContractState.