package extend.zp.player.rulestate;

import java.util.Map.Entry;

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

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


public class PRWinState extends StateBase<EXPlayer> {

	@Override
	public void enter(EXPlayer owner) {
		EXRoom room = owner.getRoom();
		EXPlayer activePlayer = (EXPlayer) owner.room.playerMapBySeat.get(owner.room.activeSeat);
		owner.winer = 1;
		owner.hutype = activePlayer.playerid == owner.playerid ? 1 : 2;//1����
		owner.winCard = room.showCard == 0 ? owner.actionCard : room.showCard;
		for (Entry<Integer, Player> entry : room.playerMapById.entrySet()) {
			if (entry.getKey().equals(owner.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			fromPlayer.winer = 2;
		}
		int huXi = 0, specialHuXi = 0;
		if (owner.winType == 3) {
			huXi = room.caclWin(owner, activePlayer.playerid == owner.playerid ? true : false);
			specialHuXi = room.caclSpecialScore(owner);
		}else if (owner.winType == 2) {
			huXi = room.caclWin(owner, activePlayer.playerid == owner.playerid ? true : false);
		}else if (owner.winType == 1) {
			specialHuXi = room.caclSpecialScore(owner);
		}
		owner.allHuXi = huXi + specialHuXi;
		int score = owner.allHuXi;//CardUtil.huxiToScore(owner.allHuXi);
		room.addAllScore(owner,score,EXScore.WIN);
		if (room.config.containsKey(Config.ROOM_CONFIG_ZHUANGXIAN) && owner.huXi >= 18) {
			int liuzi_score = 0, dengNum = 1 + (owner.huXi - 18);
			int deng = room.config.getInt(Config.ROOM_CONFIG_YIDENG);
			if (deng == 0) {
				liuzi_score = 80*dengNum;
			}else if (deng == 1) {
				liuzi_score = 100*dengNum;
			}else if (deng == 2) {
				liuzi_score = 200*dengNum;
			}
			room.addDouLiuZiScore(owner, liuzi_score > room.douLiuZi ? -room.douLiuZi : -liuzi_score, EXScore.DOULIUZISCORE);
		}
		Global.logger.info(owner  + "  self win!  hutype:"+owner.hutype);
		
		EXMainServer.gameCtr.winEvent(owner,owner.seat);

		owner.room.bankerSeat = owner.seat;
		room.endGame();
	}


}
