package extend.mj.player.rulestate;

import com.game.Global;
import com.game.Util;
import com.game.player.state.PlayerWaitState;
import com.game.state.StateBase;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;
import extend.mj.*;
import extend.mj.player.state.EXPlayerDiscardState;

/**
 * 
 */
public class PRChowState extends StateBase<EXPlayer> {

	@Override
	public void enter(EXPlayer owner) {
		
		EXRoom room = owner.getRoom();
		EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat);
		if(activePlayer.outcardList.get(activePlayer.outcardList.size() - 1)!=room.activeCard){
			activePlayer.outcardList.remove(activePlayer.outcardList.size() - 2);
		}else{
			activePlayer.outcardList.remove(activePlayer.outcardList.size() - 1);
		}
		activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class));
		int fromseat = activePlayer.seat;
		EXMainServer.gameCtr.changeActiveSeat(room, owner.seat);

		ITArray opcard = owner.opCard;
		int chowcard1 = opcard.getInt(0);
		int chowcard2 = opcard.getInt(1);
		int card= room.activeCard;
		Util.removeCard(owner.cardInhand, chowcard1, 1);
		Util.removeCard(owner.cardInhand, chowcard2, 1);
		room.activeCard = 0;


		OpCard opc = new OpCard(RuleWeight.TYPE_CHOW, card);
		opc.opCard = new TArray();
		opc.opCard.addInt(chowcard1);
		opc.opCard.addInt(chowcard2);
		owner.opCardList.add(opc);



		EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_CHOW, fromseat,opc.opCard);
		
		if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){
			owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class));
		}
	}

	@Override
	public void toNextState(EXPlayer owner) {
		owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class));
	}

}
