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;

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

	@Override
	public void enter(EXPlayer owner) {
		EXRoom room = (EXRoom) owner.room;
		
		EXPlayer activePlayer =  (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat);
		int score = room.di_fen;
		int qg_type = room.config.getInt(Config.ROOM_CONFIG_QG_TYPE);
		if(qg_type == 0&&owner.winType == 1) {
			score = room.di_fen * ( room.maxPlayers - 1);
		}
		room.addScore(owner,activePlayer, score,EXScore.WIN);
		room.addPiaoNiaoScore(owner, activePlayer);
		boolean wuguijiabei = room.config.getBoolean(Config.ROOM_CONFIG_WUGUI_ZHUOPAO_JIABEI);
		if (wuguijiabei && room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) {
			if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) {
				room.addScore(owner,activePlayer, score,EXScore.WIN);
				room.addPiaoNiaoScore(owner, activePlayer);
				for (Map.Entry<Integer, Player> entry : room.playerMapById.entrySet()) {
					EXPlayer gangPlayer = (EXPlayer) entry.getValue();
					for(int i = 0; i < gangPlayer.opCardList.size(); i++)
					{
						OpCard op_card = gangPlayer.opCardList.get(i);
						if (op_card.type == RuleWeight.TYPE_SELF_KONG)
						{
							room.addAllScore(gangPlayer, 3, EXScore.KONG);
						}
						else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat == 0)
						{
							room.addAllScore(gangPlayer, 3, EXScore.KONG);
						}
						else if (op_card.type == RuleWeight.TYPE_KONG && op_card.seat > 0)
						{
							EXPlayer activePlayer2 =  (EXPlayer)room.playerMapBySeat.get(op_card.seat);
							room.addScore(gangPlayer,activePlayer2, 3,EXScore.KONG);
						}
					}
				}
			}
		}
		activePlayer.settleLog.add(Config.SETTLE_DIAN_PAO);
		activePlayer.winer = 2;
		
		owner.settleLog.add(Config.SETTLE_JIE_PAO);
		EXMainServer.gameCtr.winEvent(owner,activePlayer.seat,room.activeCard);

		room.bankerSeat = owner.seat;
		room.winCount += 1;
		owner.winer = 1;
		owner.winCard = room.activeCard;

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

}
