package extend.pk.player.state;


import com.game.ActionEvent;
import com.game.Global;
import com.game.player.state.PlayerWaitState;
import com.game.state.StateBase;
import com.taurus.core.entity.ITObject;

import extend.pk.Config;
import extend.pk.EXActionEvent;
import extend.pk.EXMainServer;
import extend.pk.EXPlayer;

/**
 * 
 */
public class EXPlayerDaNiaoTipState extends StateBase<EXPlayer> {
	@Override
	public void enter(EXPlayer owner) {
		if(!owner.isEntrust()) {
			EXMainServer.gameCtr.daNiaoTipEvent(owner,0);
		}
		owner.startActionTimer();
	}

	/**
	 * 重连
	 * @param owner
	 */
	@Override
	public void reload(EXPlayer owner) {
		EXMainServer.gameCtr.daNiaoTipEvent(owner,1);
		owner.startActionTimer();
	}


	@Override
	public void exit(EXPlayer owner) {
		owner.stopActionTimer();
	}


	private void _action(EXPlayer owner,int id,int gid) {
		//记录打鸟
		if (owner.room.config.getInt(Config.GAME_DANIAO)==1){
			//10分
			owner.niaoValue = 10;
		}else if(owner.room.config.getInt(Config.GAME_DANIAO)==2){
			//20分
			owner.niaoValue = 20;
		}else if(owner.room.config.getInt(Config.GAME_DANIAO)==3){
			//30分
			owner.niaoValue = 30;
		}
		owner.daNiao = id;
		Global.logger.info("owner.daNiao:"+owner.daNiao);
		if(id==1) {
			owner.getRoom().daNiaoScore+=owner.niaoValue;
		}
		Global.logger.info("owner.getRoom().daNiaoScore:"+owner.getRoom().daNiaoScore);

		owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
		owner.getRoom().daNiaoCount --;
		EXMainServer.gameCtr.daNiaoEvent(owner);
		owner.room.status=1;
		owner.room.isplaying=true;
		Global.logger.info("owner.room.status:"+owner.room.status);

		owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_DA_NIAO, gid, null);
	}

	@Override
	public void execute(EXPlayer owner, String cmd, int gid, Object param) {
		super.execute(owner, cmd, gid, param);
		if (cmd.equals(EXActionEvent.EVENT_DA_NIAO)) {
			ITObject netParam = (ITObject) param;
			int niaoflag = netParam.getInt("niaoflag");
			_action(owner, niaoflag, gid);
		}else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO) || cmd.equals(ActionEvent.EVENT_ENTRUST)) {
			_action(owner,0,gid);
		}
		else if(cmd.equals(ActionEvent.EVENT_OFFLINE)) {
			owner.startActionTimer();
		}

	}

}
