local Msg = require("core.Msg")
local RoleAttr = require("role.RoleAttr")
local RoleExcel = require("excel.role")
local RoleHeadLogic = require("role.RoleHeadLogic")

local function wrapChenghaoNet(net,id, conf, isActive)
	net.id = id
	net.name = conf.name
	net.desc = conf.desc
	local len = 0
	for k,v in ipairs(conf.attrs) do
		len = len + 1
		net.attrs[len].key = v[1]
		net.attrs[len].value = v[2]
	end
	net.attrs[0] = len
	net.isActive = isActive and 1 or 0
end

function query(human)
	local msgRet = Msg.gc.GC_CHENGHAO_QUERY
	local chenghaoDB = human.db.chenghao
	msgRet.list[0] = 0
	for id, cf in pairs(RoleExcel.chenghao) do
		local isActive = RoleHeadLogic.isActive(human, RoleHeadLogic.HEAD_TYPE_4, id)
		msgRet.list[0] = msgRet.list[0] + 1
		local net = msgRet.list[msgRet.list[0]]
		wrapChenghaoNet(net,id, cf, isActive)
	end
	msgRet.id = human.db.chenghao or 0
	--Msg.trace(msgRet)
	Msg.send(msgRet,human.fd)
end