package extend.zp.player.rulestate;


import java.util.ArrayList;
import java.util.List;

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.zp.EXMainServer;
import extend.zp.EXPlayer;
import extend.zp.EXRoom;
import extend.zp.OpCard;
import extend.zp.RuleWeight;
import extend.zp.player.state.EXPlayerDiscardState;
import extend.zp.tip.Tip;
import extend.zp.uitl.CardUtil;

/**
 * ��Ӧ���ƴ���״̬
 * 
 */
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);

		activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class));
		int fromseat = activePlayer.seat;
		EXMainServer.gameCtr.changeActiveSeat(room, owner.seat);
		
		Tip actionTip = owner.actionTip;
		ITArray opcard = actionTip.opcard;
		int chowcard1 = opcard.getInt(0);
		int chowcard2 = opcard.getInt(1);
		int card= room.showCard;
		owner.suoCardList.add(card);
		room.showCard = 0;
		__chow(owner,chowcard1,chowcard2,card,fromseat);
		this.toNextState(owner);
	}

	private static final void __chow(EXPlayer owner,int chowcard1,int chowcard2,int card,int fromseat) {
		int type = RuleWeight.TYPE_CHOW;
		ITArray opcards = TArray.newInstance();
		opcards.addInt(chowcard1);
		opcards.addInt(chowcard2);
		OpCard opc = new OpCard(type, opcards, card);
		owner.opCardList.add(opc);
		
		Util.removeCard(owner.cardInhand, chowcard1, 1);
		Util.removeCard(owner.cardInhand, chowcard2, 1);
		opc.huXi = 0;
		List<Integer> chowGroup = new ArrayList<Integer>();
		chowGroup.add(card);
		chowGroup.add(chowcard1);
		chowGroup.add(chowcard2);
		EXMainServer.gameCtr.actionCard(owner, card, type, fromseat,opcards,0
				,CardUtil.getCardGroupHuxi1(chowGroup, owner.opCardList));
	}
	
	@Override
	public void toNextState(EXPlayer owner) {
		owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class));
	}

}
