package extend.mj.player.rulestate;


import java.util.Map.Entry;

import com.game.Util;
import com.game.data.Player;
import com.game.state.StateBase;

import extend.mj.Config;
import extend.mj.EXMainServer;
import extend.mj.EXPlayer;
import extend.mj.EXRoom;
import extend.mj.EXScore;

/**
 * ��Ӧ��������״̬
 * 
 *
 * 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);
		room.addAllScore(owner, room.di_fen,EXScore.WIN);
		boolean jiabei = true;
		boolean wuguijiabei = room.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI);
		if (wuguijiabei && room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG))
		{
		    if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0)
			{
				room.addAllScore(owner, room.di_fen,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;
		}
		
		EXMainServer.gameCtr.winEvent(owner,owner.seat,owner.winCard);
		room.niao_selfWin(owner,owner.winCard );
		owner.room.bankerSeat = owner.seat;
		owner.settleLog.add(Config.SETTLE_ZIMO);
		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

	}

}
