package extend.zp.player.rule;

import com.game.Global;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;

import extend.zp.EXPlayer;
import extend.zp.OpCard;
import extend.zp.RuleWeight;
import extend.zp.player.rulestate.PRCheck;
import extend.zp.player.rulestate.PRDiscardPaoState;
import extend.zp.tip.IRuleBase;
import extend.zp.uitl.CardUtil;


public class RuleDiscardPao implements IRuleBase {
	@Override
	public boolean condition(EXPlayer player) {
		//判断是否可以偎
		boolean c =  PRCheck.check(player);
		if (!c){
			return false;
		}

		int eventCard = player.getRoom().activeCard;
		for (int i = 0; i < player.kanGroup.size(); i++) {
			if (eventCard == player.kanGroup.get(i)[0]) {
				player.getRoom().activeCard = 0;
				player.kanGroup.remove(i);
				CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_KAN, eventCard, eventCard, eventCard, 0));
				ITArray opcard = TArray.newInstance();
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				player.initOpCard(opcard);
				this.action(player);
				return false;
			}
		}
		for (int i = 0; i < player.weiGroup.size(); i++) {
			if (eventCard == player.weiGroup.get(i)[0]) {
				player.getRoom().activeCard = 0;
				player.weiGroup.remove(i);
				CardUtil.removeOpcard(player.opCardList, new OpCard(RuleWeight.TYPE_WEI, eventCard, eventCard, eventCard, 0));
				ITArray opcard = TArray.newInstance();
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				player.initOpCard(opcard);
				this.action(player);
				return false;
			}
		}
		return false;
	}

	@Override
	public void action(EXPlayer player) {
		player.stateMachine.changeState(Global.getState(PRDiscardPaoState.class));
	}
}
