TeamMemberData = class("TeamMemberData");

TeamMemberData.KeyType = {
	[SessionTeam_pb.EMEMBERDATA_NAME] = "name",

	[SessionTeam_pb.EMEMBERDATA_CAT] = "cat",
	-- 基礎等級
	[SessionTeam_pb.EMEMBERDATA_BASELEVEL] = "baselv",
	-- 職業
	[SessionTeam_pb.EMEMBERDATA_PROFESSION] = "profession",
	-- 地圖id
  	[SessionTeam_pb.EMEMBERDATA_MAPID] = "mapid",
	-- 頭像
  	[SessionTeam_pb.EMEMBERDATA_PORTRAIT] = "portrait",
	-- 相框
  	[SessionTeam_pb.EMEMBERDATA_FRAME] = "frame",
	-- 副本id
  	[SessionTeam_pb.EMEMBERDATA_RAIDID] = "raid",
	-- 離線狀態 0:線上 ~0:離線
  	[SessionTeam_pb.EMEMBERDATA_OFFLINE] = "offline",
	-- 血量
  	[SessionTeam_pb.EMEMBERDATA_HP] = "hp",
  	[SessionTeam_pb.EMEMBERDATA_MAXHP] = "hpmax",
	-- 藍量
  	[SessionTeam_pb.EMEMBERDATA_SP] = "sp",
  	[SessionTeam_pb.EMEMBERDATA_MAXSP] = "spmax",
	-- 是否為隊長 1:隊長 2:隊員
  	[SessionTeam_pb.EMEMBERDATA_JOB] = "job",
  	-- 隊員的攻擊目標
  	[SessionTeam_pb.EMEMBERDATA_TARGETID] = "targetid",
  	-- 牽手目標id
  	[SessionTeam_pb.EMEMBERDATA_JOINHANDID] = "joinhandid",
  	-- 身體
  	[SessionTeam_pb.EMEMBERDATA_BODY] = "body",
  	-- 身體顏色
  	[SessionTeam_pb.EMEMBERDATA_CLOTHCOLOR] = "bodycolor",
  	-- 頭髮
  	[SessionTeam_pb.EMEMBERDATA_HAIR] = "hair",
  	-- 眼鏡
  	[SessionTeam_pb.EMEMBERDATA_EYE] = "eye",
  	-- 頭髮顏色
  	[SessionTeam_pb.EMEMBERDATA_HAIRCOLOR] = "haircolor",
  	-- 右手武器
  	[SessionTeam_pb.EMEMBERDATA_RIGHTHAND] = "rightWeapon",
  	-- 左手武器
  	[SessionTeam_pb.EMEMBERDATA_LEFTHAND] = "leftWeapon",
  	-- 頭飾
  	[SessionTeam_pb.EMEMBERDATA_HEAD] = "head",
  	-- 背部
  	[SessionTeam_pb.EMEMBERDATA_BACK] = "back",
  	-- 臉部
  	[SessionTeam_pb.EMEMBERDATA_FACE] = "face",
  	-- 嘴巴
  	[SessionTeam_pb.EMEMBERDATA_MOUTH] = "mouth",
  	-- 尾巴
  	[SessionTeam_pb.EMEMBERDATA_TAIL] = "tail",
  	-- 公會id
  	[SessionTeam_pb.EMEMBERDATA_GUILDID] = "guildid",
  	-- 公會名字
  	[SessionTeam_pb.EMEMBERDATA_GUILDNAME] = "guildname",
  	-- 性別
  	[SessionTeam_pb.EMEMBERDATA_GENDER] = "gender",
  	-- 是否可以眨眼
  	[SessionTeam_pb.EMEMBERDATA_BLINK] = "blink",
  	-- 分線id
  	[SessionTeam_pb.EMEMBERDATA_ZONEID] = "zoneid",
	-- 是否自動上車  	
  	[SessionTeam_pb.EMEMBERDATA_AUTOFOLLOW] = "autofollow",

  	[SessionTeam_pb.EMEMBERDATA_RELIVETIME] = "resttime",
  	-- 僱用時間
  	[SessionTeam_pb.EMEMBERDATA_EXPIRETIME] = "expiretime",
  	
  	[SessionTeam_pb.EMEMBERDATA_CAT_OWNER] = "masterid",

  	[SessionTeam_pb.EMEMBERDATA_GUILDRAIDINDEX or 38] = "guildraidindex",

  	--[SessionTeam_pb.EMEMBERDATA_REALTIMEVOICE] = "realtimevoice",

  	-- 合奏型別技能列表
  	[SessionTeam_pb.EMEMBERDATA_ENSEMBLESKILL] = "ensembleskill",
}

TeamMemberDataMapType = {
	["ensembleskill"] = 1,
}

TeamMemberDataStringType = {
	["name"] = 1,
	["guildname"] = 1,
}

function TeamMemberData:ctor(teamMember, index)
	self.index = index;

	self.pos = LuaVector3();

	self:SetData(teamMember);
end

function TeamMemberData:SetData(tmdata)
	if(tmdata)then
		-- guid
		if(tmdata.guid)then
			self.id = tmdata.guid;
		end
		-- 名字
		if(tmdata.name)then
			self.name = tmdata.name;
		end
		-- 倒計時(申請的玩家需要)
		if(tmdata.time)then
			self.time = tmdata.time;
		end
		if(tmdata.datas)then
			self:SetMemberData(tmdata.datas);
		end
	end
end

function TeamMemberData:SetMemberData(memberDatas)
	-- local updateStr = "TeamMemberData: | ".." id:"..tostring(self.id).." | ".." name:"..tostring(self.name).." | ";
	for i=1,#memberDatas do
		local data = memberDatas[i];
		local key = self.KeyType[data.type];

		-- if key == "realtimevoice" then
		-- 	GVoiceProxy.Instance:RecvTeamRealTimeVoice( data.value== 1,self.id)
		-- end	

		if(key)then
			if TeamMemberDataMapType[key] then
				local value = self[key]
				if value == nil then
					value = {}
					self[key] = value
				else
					TableUtility.TableClear(value)
				end
				for j=1, #data.values do
					local values = data.values[j]
					value[values] = values
				end
			elseif TeamMemberDataStringType[key] then
				self[key] = data.data;
			else
				self[key] = data.value;
			end
			-- updateStr = updateStr..string.format("%s:%s | ", key, tostring(data.value));
		end
	end
	-- helplog(updateStr);
	self:UpdateHireMemberInfo();
end

function TeamMemberData:UpdatePos(pos)
	-- 位置
	self.pos:Set(pos.x/1000, pos.y/1000, pos.z/1000);
end

function TeamMemberData:IsOffline()
	if(self.offline and self.offline == 1)then
		return true;
	end
	return false;
end

function TeamMemberData:CanBlink()
	return self.blink == 1 or self.blink == true;
end

function TeamMemberData:IsHireMember()
	if(self.cat == nil)then
		return false;
	end
	return self.cat ~= 0;
end

-- CatInfo begin
function TeamMemberData:UpdateHireMemberInfo()
	if(self.cat ~= nil)then
		self.catdata = Table_MercenaryCat[self.cat];
		if(self.catdata)then
			local MonsterID = self.catdata.MonsterID;
			local monsterData = MonsterID and Table_Monster[MonsterID];
			if(monsterData)then
				self.name = monsterData.NameZh;
				self.profession = nil;

				-- bodyInfo
				self.body = monsterData.Body;
				-- self.bodycolor = monsterData.BodyColor;
				self.hair = monsterData.Hair;
				self.eye = monsterData.Eye;
				-- self.haircolor = monsterData.HairColor;
				self.rightWeapon = monsterData.RightHand;
				self.leftWeapon = monsterData.LeftHand;	
				self.head = monsterData.Head;
				self.back = monsterData.Wing;
				self.face = monsterData.Face;
				self.mouth = monsterData.Mount;
				self.tail = monsterData.tail;
			end
		end
	else
		self.catdata = nil;
	end
end

function TeamMemberData:GetRealTimeVoice()
	return self.realtimevoice or 1
end

function TeamMemberData:SetMasterName(mastername)
	self.mastername = mastername;
end

function TeamMemberData:SetRestTime(time)
	self.resttime = time or 0;
end
-- CatInfo end

function TeamMemberData:Exit()
	self.pos:Destroy();
	self.pos = nil;
end






