package extend.zp.player.rule;

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

import com.taurus.core.util.Logger;
import extend.zp.EXPlayer;
import extend.zp.RuleWeight;
import extend.zp.player.rulestate.PRDealLiuState;
import extend.zp.tip.IRuleBase;
import extend.zp.tip.Tip;


public class RuleDealLiu implements IRuleBase {
    Logger logger = Logger.getLogger(getClass());
    @Override
    public boolean condition(EXPlayer player) {
        if (player.isDeadPut)
        {
            return false;
        }
        int eventCard = player.drawCard;
        boolean flag = false;
        //player.tipMgr.clean();
        logger.info("jefe RuleDealLiu:" + eventCard);

        if (eventCard > 0)
        {
            for (int i = 0; i < player.kanGroup.size(); i++) {
                if (eventCard == player.kanGroup.get(i)[0]) {
                    ITArray opcard = TArray.newInstance();
                    opcard.addInt(eventCard);
                    opcard.addInt(eventCard);
                    opcard.addInt(eventCard);
                    Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI);
                    player.tipMgr.addTip(tip);
                    flag = true;
                    break;
                }
            }

            for (int i = 0; i < player.tiGroup.size(); i++) {
                int card = player.tiGroup.get(i)[0];
                ITArray opcard = TArray.newInstance();
                opcard.addInt(card);
                opcard.addInt(card);
                opcard.addInt(card);
                Tip tip = new Tip(card, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI);
                player.tipMgr.addTip(tip);
                flag = true;
            }
        }
        else {
            for (int i = 0; i < player.tiGroup.size(); i++) {
                int card = player.tiGroup.get(i)[0];
                ITArray opcard = TArray.newInstance();
                opcard.addInt(card);
                opcard.addInt(card);
                opcard.addInt(card);
                Tip tip = new Tip(card, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI);
                player.tipMgr.addTip(tip);
                flag = true;
            }
        }
        logger.info("jefe RuleDealLiu end:" + flag);
        return flag;
    }

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