package extend.mj;

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

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;

/**
 * 
 * 
 */
public class EXPlayer extends Player {

	public List<Integer>	cardInhand;


	public List<Integer>	outcardList;

	public ITArray			opCard;

	public List<OpCard>		opCardList;

	public int				drawCard	= 0;
	
	public int 				outCardCount = 0;

	public boolean 			skipDraw	=false;
	public int				winCard		= 0;
	
	public boolean 			tianting 	= false;
	
	public TipManager		tipMgr;
	
	public SettleLog		settleLog;
	

	public boolean 			louhu = false;
	

	public boolean							autoOutCard		= false;

	public Map<Integer, WinCardType>	winMap;
	
	public OpenKong 	openKong;
	public Set<Integer> 	llsCardRecord;
	public int	piaoNiao = 0;
	
	public int win_count;
	public boolean fengding;
	public List<QSLog>			qsList;

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

		cardInhand = new ArrayList<>();
		outcardList = new ArrayList<>();
		
		opCardList = new ArrayList<>();
		opCard = new TArray();

		tipMgr = new TipManager(this);
		llsCardRecord = new HashSet<Integer>();
		
		settleLog = new SettleLog();
		settleLog.put(Config.SETTLE_XIAO_DIAN_PAO, 0);
		settleLog.put(Config.SETTLE_XIAO_JIE_PAO, 0);
		settleLog.put(Config.SETTLE_XIAO_ZIMO, 0);
		settleLog.put(Config.SETTLE_DA_DIAN_PAO, 0);
		settleLog.put(Config.SETTLE_DA_JIE_PAO, 0);
		settleLog.put(Config.SETTLE_DA_ZIMO, 0);
		
		qsList = new ArrayList<>();
	}
	
	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);
		playerData.putInt("card_count", cardInhand.size());
		playerData.putInt("score", score.total_score);
		playerData.putBoolean("auto", this.autoOutCard);
		playerData.putInt("draw_card", this.drawCard);
		playerData.putInt("piao_niao", this.piaoNiao);
		playerData.putInt("win_count", this.win_count);
		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) {
				opcardParam.putTArray("opcard", opcard.opCard);
			}
			opcards.addTObject(opcardParam);
		}
		playerData.putTArray("opcard", opcards);

		return playerData;
	}

	public void clear() {
		super.clear();
		this.cardInhand.clear();
		this.winer = 0;
		this.louhu = false;
		this.outcardList.clear();
		this.drawCard = 0;
		this.outCardCount = 0;
		this.opCardList.clear();
		this.score.resetRound();
		this.autoOutCard = false;
		this.openKong = null;
		this.winMap = null;
		this.skipDraw = false;
		this.tianting = false;
		this.piaoNiao = 0;
		this.qsList.clear();
		this.fengding = false;
		getRoom().activeKong = null;
		this.llsCardRecord.clear();
	}
	

	public EXRoom getRoom() {
		return (EXRoom) room;
	}
	
}
