package extend.zp.player.state;

import java.util.Map.Entry;

import com.game.ActionEvent;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;

import extend.zp.EXActionEvent;
import extend.zp.EXPlayer;
import extend.zp.RuleWeight;
import extend.zp.tip.Tip;


public class EXPlayerDrawTipState extends EXPlayerTipState {
	public void enter(EXPlayer owner) {
		super.enter(owner);
		////System.out.println("outs DI enter");
		owner.getRoom().tipMap.put(owner.playerid, owner.tipMgr);
	}

	@Override
	public void exit(EXPlayer owner) {
		// TODO Auto-generated method stub
		super.exit(owner);
		////System.out.println("outs DI exit");
		owner.getRoom().tipMap.remove(owner.playerid);
	}

	public void reload(EXPlayer owner) {
		this.enter(owner);
	}

	@Override
	public void execute(EXPlayer owner, String cmd, int gid, Object param) {

		super.execute(owner, cmd, gid, param);
		////System.out.println("outs DI execute");
		if (cmd.equals(EXActionEvent.EVENT_ACTION)) {
			////System.out.println("drawtip:");
			ITObject netParam = (ITObject) param;
			int id = netParam.getInt("id");
			ITArray biid = netParam.containsKey("biid")?netParam.getTArray("biid"):null;
			owner.tipMgr.doAction(id,biid);
		}else if (ActionEvent.EVENT_TIMER_AUTO.equals(cmd)) {
			int id = owner.tipMgr.getUid();
			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,null);
		}
	}
}
