package extend.mj;

import com.game.Util;
import com.game.data.Player;
import com.game.data.Room;
import com.game.data.Score;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TArray;
import com.taurus.core.entity.TObject;
import extend.mj.tip.TipManager;

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

/**
 * 
 * 
 *
 * 2017��8��30��
 * EXPlayer.java
 */
public class EXPlayer extends Player {
	// ����
	public List<Integer>	cardInhand;

	// ������
	public List<Integer>	outcardList;

	public List<Integer>    outputCardList;//打出过的牌，包括被吃碰杠

	public boolean istangzihu = false;//是否是塘子胡

	public ITArray			opCard;

	public List<int[]>		pongGroup;
	public List<int[]>		kongGroup;
	public List<int[]>		selfKongGroup;
	public List<OpCard>		opCardList;

	public int				drawCard	= 0;
	public int				winCard		= 0;

	public TipManager		tipMgr;
	
	public SettleLog 		settleLog;

	public boolean							autoOutCard		= false;
	/**
	 * ©��
	 */
	public boolean 			louhu = false;
	
	/**
	 * ǿ�Ƽ�����
	 */
	public boolean 			forceCheckWin = false;
	/**
	 * 0 С��   1 ���ܺ�
	 */
	public int 				winType = 0;

	/**
	 * 0 无 1 胡 2 输
	 */
	public int				last_winer			= 0;

	public List<Integer>	notPongKongList = new ArrayList<>();
	public List<Integer>	notPongList = new ArrayList<>();
	public List<Integer>    chengList = new ArrayList<>();

	public int				repeat_win;

	public Map<Integer, WinCardType> winMap;


	public int						hu_score;

	public int						di_score;


	public int 						ming_gang_num = 0;
	public int 						an_gang_num = 0;
	public int 						dian_gang_num = 0;
	public int						cheng_num = 0;
	public boolean					is_cheng = false;

	public boolean					tinghu10bei = false;

	public boolean					gangshangpao = false;


	public int liangang = 0;

	public boolean fengding;

	public EXPlayer(int playerid, Room table, String session_id) {
		super(playerid, table, session_id);

		cardInhand = new ArrayList<>();
		outcardList = new ArrayList<>();
		outputCardList = new ArrayList<>();
		pongGroup = new ArrayList<>();
		kongGroup = new ArrayList<>();
		selfKongGroup = new ArrayList<>();
		opCardList = new ArrayList<>();

		opCard = new TArray();

		tipMgr = new TipManager(this);
		
		settleLog = new SettleLog();
		settleLog.put(Config.SETTLE_ZIMO, 0);
		settleLog.put(Config.SETTLE_AN_KONG, 0);
		settleLog.put(Config.SETTLE_MING_KONG, 0);

		repeat_win = -1;
		hu_score = 0;
		di_score = 0;

		ming_gang_num = 0;
		an_gang_num = 0;
		dian_gang_num = 0;

		last_winer = 0;

		tinghu10bei = false;
		gangshangpao = false;
	}
	
	protected Score newScore() {
		return new EXScore(this);
	}

	public void initOpCard(ITArray opcard) {
		this.opCard.clear();
		for (int i = 0; i < opcard.size(); ++i) {
			this.opCard.addInt(opcard.getInt(i));
		}
	}

	public ITObject getReloadInfo() {
		ITObject playerData = super.getReloadInfo();
		ITArray disCard = Util.toTArray(this.outcardList);
		playerData.putTArray("outcard_list", disCard);
		ITArray chengList = Util.toTArray(this.chengList);
		playerData.putTArray("cheng_list", chengList);
		playerData.putInt("card_count", cardInhand.size());
		playerData.putInt("score", score.total_score);
		ITArray opcards = TArray.newInstance();
		for (OpCard opcard : opCardList) {
			ITObject opcardParam = new TObject();
			opcardParam.putInt("type", opcard.type);
			opcardParam.putInt("card", opcard.card);
			if (opcard.opcard != null)
			{
				List<Integer> tempOpCard = new ArrayList<>();
				for(int i = 0; i < opcard.opcard.length; i++)
				{
					if (opcard.opcard[i] > 0)
					{
						tempOpCard.add(opcard.opcard[i]);
					}
				}
				opcardParam.putTArray("opcard", Util.toTArray(tempOpCard));
			}
			opcards.addTObject(opcardParam);
		}
		playerData.putTArray("opcard", opcards);

		return playerData;
	}

	public void clear() {
		super.clear();
		this.cardInhand.clear();
		this.notPongKongList.clear();
		this.notPongList.clear();
		this.winer = 0;
		this.louhu = false;
		this.outcardList.clear();
		this.outputCardList.clear();
		this.drawCard = 0;
		this.kongGroup.clear();
		this.pongGroup.clear();
		this.selfKongGroup.clear();
		this.opCardList.clear();
		this.score.resetRound();
		this.winMap = null;
		this.hu_score = 0;
		this.istangzihu = false;
		this.di_score = 0;
		this.ming_gang_num = 0;
		this.an_gang_num = 0;
		this.dian_gang_num = 0;
		this.tinghu10bei = false;
		this.cheng_num = 0;
		this.fengding = false;
		this.chengList.clear();
	}
	
	public EXRoom getRoom() {
		return (EXRoom) room;
	}
}
