package extend.mj.player.rulestate;


import com.game.Util;
import com.game.data.Player;
import com.game.state.StateBase;
import extend.mj.*;

import java.util.Map.Entry;

/**
 * ��Ӧ��������״̬
 * 
 *
 * 2017��8��30��
 * PRSelfWinState.java
 */
public class PRSelfWinState extends StateBase<EXPlayer> {

	@Override
	public void enter(EXPlayer owner) {

		EXRoom room = owner.getRoom();
		owner.winCard = owner.drawCard;
		owner.winer = 1;

		Util.removeCard(owner.cardInhand, owner.winCard, 1);

		int niao = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO);
		int opt = owner.room.config.getInt(Config.ROOM_CONFIG_NIAO_OPT);

		//爆炸马 加倍的情况
		if (!(niao == Config.NIAO_TYPE_ALL && opt == 1))
		{
			if (room.config.getBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO) && room.get12ZhangLuoDi(owner) != null)
			{
				EXPlayer badPlayer = room.get12ZhangLuoDi(owner);
				room.addScore(owner,badPlayer, owner.hu_score * (room.maxPlayers - 1), EXScore.WIN);
			}
			else
			{
				room.addAllScore(owner, owner.hu_score,EXScore.WIN);
			}
		}

		room.addAllPiaoNiaoScore(owner);
		for (Entry<Integer, Player> entry : room.playerMapById.entrySet()) {
			if (entry.getKey().equals(owner.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			fromPlayer.winer = 2;
			fromPlayer.last_winer = 2;
		}

		EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard);

		if (room.lastBankerSeat == 0)
		{
			room.lastBankerSeat = room.bankerSeat;
		}
		owner.room.bankerSeat = owner.seat;
		owner.settleLog.add(Config.SETTLE_ZIMO);
		room.niao_selfWin(owner,owner.winCard);
		room.endGame();
	}

	@Override
	public void toNextState(EXPlayer owner) {
		// TODO Auto-generated method stub

	}

	@Override
	public void exit(EXPlayer owner) {
		// TODO Auto-generated method stub

	}

	@Override
	public void execute(EXPlayer owner, String cmd, int gid, Object param) {
		// TODO Auto-generated method stub

	}

}
