package extend.zp;

import java.util.Map.Entry;

import com.game.Util;
import com.game.data.BasePlayBack;
import com.game.data.Player;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TArray;
import com.taurus.core.entity.TObject;

public class PlayBack extends  BasePlayBack{
	
	public PlayBack(EXRoom room){
		super(room);
		info.putInt("left_card", room.card.getCount());
		ITArray infoList = new TArray();
		for (Entry<Integer, Player> entry : room.playerMapById.entrySet()) {
			ITObject obj = TObject.newInstance();
			EXPlayer player = (EXPlayer)entry.getValue();
			obj.putInt("aid", player.playerid);
			obj.putUtfString("nick", player.nick);
			obj.putInt("sex", player.sex);
			obj.putUtfString("portrait", player.portrait);
			obj.putInt("seat", player.seat);
			ITArray cardInhand = Util.toTArray(player.cardInhand);
			obj.putTArray("hand_card", cardInhand);
			obj.putInt("score", player.score.total_score);
			infoList.addTObject(obj);
		}
		info.putTArray("playerData", infoList);
	}
	
	
	public void showCardCommand(int seat,int card,int left_count,boolean discard){
		ITObject data = TObject.newInstance();
		data.putInt("card", card);
		data.putInt("left_count", left_count);
		data.putBoolean("discard", discard);
		addCommand("ShowCard",seat,data);
	}
	
	
	public void addCardCommand(int seat,int card){
		ITObject data = TObject.newInstance();
		data.putInt("card", card);
		addCommand("AddCard",seat,data);
	}
	
	public void addOutCardCommand(int seat,int card){
		ITObject data = TObject.newInstance();
		data.putInt("card", card);
		addCommand("OutCard",seat,data);
	}
	
	public void addGetCardCommand(int seat, int card, int left_count) {
		ITObject data = TObject.newInstance();
		data.putInt("card", card);
		data.putInt("left_count", left_count);
		addCommand("GetCard", seat, data);
	}

	public void addThrowCardCommand(int seat, int card) {
		ITObject data = TObject.newInstance();
		data.putInt("card", card);
		addCommand("ThrowCard", seat, data);
	}
	
	public void addAddCardCommand(int seat, int card, int leftCount) {
		ITObject data = TObject.newInstance();
		data.putInt("card", card);
		data.putInt("left_count", leftCount);
		addCommand("AddCard", seat, data);
	}
	
	public void addActionCommand(int seat,int type,int card,int from_seat,ITArray opcardArray,int huxi){
		ITObject cmdData = TObject.newInstance();
		cmdData.putInt("card", card);
		cmdData.putInt("type", type);
		cmdData.putInt("from_seat", from_seat);
		if(opcardArray!=null)
		cmdData.putTArray("opcard", opcardArray);
		cmdData.putInt("huxi", huxi);
		addCommand("Action",seat,cmdData);
	}
	
	public void addWinCardCommand(int seat,boolean zimo){
		ITObject cmdData = TObject.newInstance();
		addCommand("Win",seat,cmdData);
	}
	
	public void addCommand(String cmd, int seat, ITObject data) {
		ITObject cmdObj = TObject.newInstance();
		cmdObj.putUtfString("cmd", cmd);
		cmdObj.putInt("seat", seat);
		cmdObj.putTObject("data", data);
		cmdList.addTObject(cmdObj);
	}
	
	public void addResultCommand(ITObject data) {
		addCommand("Result",0,data);
	}
	
}
