package extend.pk.room.state;

import com.game.Global;

import com.game.data.Player;
import com.game.state.StateBase;
import extend.pk.EXMainServer;
import extend.pk.EXPlayer;
import extend.pk.EXRoom;
import extend.pk.player.state.EXPlayerBaoChunState;
import extend.pk.uitl.CardCheck;

import java.util.Map;


public class EXRoomBaoChunState extends StateBase<EXRoom> {

    @Override
    public void enter(EXRoom owner) {
        Global.logger.error("EXRoomBaoChunState enter");

        for (Map.Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
            EXPlayer player = (EXPlayer) entry.getValue();

            //检测是否自然春：
            Boolean ziRanChun = CardCheck.CheckZiRanChun(player.cardInhand,owner.config);
            if (ziRanChun){
                //自然春，不用报春直接倒牌
                player.ziranchun = 1;
                owner.ziranchunover = 1;
                this.over(player);
                return;
            }


            if (owner.bankerSeat!=player.seat){
                EXMainServer.gameCtr.changeActiveSeat(owner, player.seat);
                player.stateMachine.changeState(Global.getState(EXPlayerBaoChunState.class));
            }
        }

    }

    public void over(EXPlayer owner) {
        EXRoom room = owner.getRoom();

        room.win = owner;
        room.baochunstate = -1;
        Global.logger.error("EXPlayerDiscard: over");
        room.endGame();
    }
}
