package extend.mj.player.rulestate;

import java.util.Map.Entry;

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

import extend.mj.*;

/**
 * 
 */
public class PRSelfWinState extends StateBase<EXPlayer> {

	@Override
	public void enter(EXPlayer owner) {

		EXRoom room = owner.getRoom();
		owner.winCard = owner.drawCard;
		owner.winer = 1;
		owner.win_count ++;
		for (Entry<Integer, Player> entry : room.playerMapById.entrySet()) {
			if (entry.getKey().equals(owner.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			fromPlayer.winer = 2;
			fromPlayer.win_count = 0;
		}
		for (Entry<Integer, WinCardType> entry : owner.winMap.entrySet()) {
			WinCardType wct = entry.getValue();
			for(int i = 0;i<wct.value; ++i) {
				room.addAllScore(owner,wct.score,EXScore.WIN);
			}
		}

		room.addAllPiaoNiaoScore(owner);
		Global.logger.info(owner + " selfWin:" + owner.winMap.toString());
		
		
		owner.settleLog.add(owner.winMap.containsKey(WinCardType.XIAOHU)?Config.SETTLE_XIAO_ZIMO:Config.SETTLE_DA_ZIMO);
		EXMainServer.gameCtr.winEvent(owner,owner.seat);
		room.niao_selfWin(owner);
		owner.room.bankerSeat = owner.seat;
		room.endGame();
	}


}
