package extend.mj.player.state;

import java.util.Map.Entry;

import com.game.ActionEvent;
import com.game.Global;
import com.game.Router;
import com.taurus.core.entity.ITObject;

import com.taurus.core.entity.TObject;
import extend.mj.EXActionEvent;
import extend.mj.EXPlayer;
import extend.mj.RuleWeight;
import extend.mj.tip.Tip;

/**
 * ���ץ����ʾ״̬
 * 
 */
public class EXPlayerDrawTipState extends EXPlayerTipState {
	
	@Override
	public void execute(EXPlayer owner, String cmd, int gid, Object param) {
		super.execute(owner, cmd, gid, param);
		if (cmd.equals(EXActionEvent.EVENT_ACTION)) {
			ITObject netParam = (ITObject) param;
			int id = netParam.getInt("id");
			boolean win = (owner.tipMgr.weight &RuleWeight.SELF_WIN)!=0 ;
			if(Global.gameId == 1 && win && id == 0)return;
			owner.tipMgr.doAction(id);
		}else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) {
			int id = 0;
			/*
			for (Entry<Integer, Tip> entry : owner.tipMgr.tipMap.entrySet()) {
				Tip tip = entry.getValue();
				if(tip.type == RuleWeight.TYPE_WIN) {
					id = tip.id;
					break;
				}
			}
			 */
			owner.tipMgr.doAction(id);
		}
		else if (cmd.equals(EXActionEvent.EVENT_DISCARD))
		{
			boolean flag = false;
			for (Entry<Integer, Tip> entry : owner.tipMgr.tipMap.entrySet()) {
				Tip tip = entry.getValue();
				if(tip.type == RuleWeight.TYPE_WIN) {
				    flag = true;
				}
				else {
					flag = false;
				}
			}
			if (flag)
			{
				int id = 0;
				owner.tipMgr.doAction(id);
				owner.stateMachine.execute(EXActionEvent.EVENT_DISCARD, 0, param);
			}
			else {
				ITObject reconParam = new TObject();
				owner.sendEvent(Router.GAME_EVT__UPDATE_RECONECT, reconParam);
			}
		}
	}

}
