package extend.mj.player.rulestate;

import com.game.state.StateBase;
import extend.mj.*;
import extend.mj.uitl.WinCard;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

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

	@Override
	public void enter(EXPlayer owner) {
		EXRoom room = (EXRoom) owner.room;
		owner.winer = 1;
		EXPlayer activePlayer =  (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat);

		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))
		{
			room.addScore(owner,activePlayer, owner.hu_score, EXScore.WIN);
		}

		room.addPiaoNiaoScore(owner, activePlayer);
		activePlayer.settleLog.add(Config.SETTLE_DIAN_PAO);
		activePlayer.winer = 2;
		activePlayer.last_winer = 2;
		
		owner.settleLog.add(Config.SETTLE_JIE_PAO);
		EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard);

		if (room.config.getBoolean(Config.ROOM_CONFIG_XIAOHU_BEI))
		{
			List<Integer> typeList = new ArrayList<Integer>();
			for (Map.Entry<Integer, WinCardType> entry : owner.winMap.entrySet()) {
				WinCardType cardType = entry.getValue();
				if (cardType.IsDaHu())
				{
					typeList.add(cardType.type);
				}
			}

			if (typeList.size() > 0)
			{
				for(int i = 0; i < typeList.size(); i++) {
					int type = typeList.get(i);
					owner.winMap.remove(type);
				}
				//方便显示
				WinCard.putWinCardType(owner.winMap, WinCardType.XIAO_HU_ZHONG_DA_HU, 1,2, false, "大胡");
			}
		}

		if (room.lastBankerSeat == 0)
		{
			room.lastBankerSeat = room.bankerSeat;
		}
		room.bankerSeat = owner.seat;
		room.winCount += 1;

		owner.winCard = room.activeCard;

		room.winCallback( owner ,owner.winCard);
	}

}
