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.PRTiState;
import extend.zp.tip.IRuleBase;
import extend.zp.uitl.CardUtil;


public class RuleTi implements IRuleBase {
	@Override
	public boolean condition(EXPlayer player) {
		int eventCard = player.drawCard;
		for (int i = 0; i < player.kanGroup.size(); i++) {
			if (eventCard == player.kanGroup.get(i)[0]) {
				player.winCard = player.drawCard;
				player.drawCard = 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);
				break;
			}
		}
		for (int i = 0; i < player.weiGroup.size(); i++) {
			if (eventCard == player.weiGroup.get(i)[0]) {
				player.winCard = player.drawCard;
				player.drawCard = 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);
				break;
			}
		}
		return false;
	}

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