local RoleLogic = require("role.RoleLogic")
local HeroExcel = require("excel.hero")
local Msg = require("core.Msg")
local Config = require("Config")
local HeroGrid = require("hero.HeroGrid")
local Grid = require("bag.Grid")
local HeroDefine = require("hero.HeroDefine")
local ItemDefine = require("bag.ItemDefine")
local HeroLogic = require("hero.HeroLogic")
local RoleDefine = require("role.RoleDefine")
local Lang = require("common.Lang")

function StrategyQueryByHeroID(human,heroID)
    if HeroExcel.hero[heroID] == nil then
        return
    end
    human.db.lookGl = 1
    local fatherID = HeroExcel.hero[heroID].id
    local msgRet = Msg.gc.GC_HERO_STRATEGY_QUERY
    msgRet.simpleMsg.icon = HeroExcel.hero[heroID].head
    msgRet.simpleMsg.name = HeroExcel.hero[heroID].name
    msgRet.simpleMsg.weightLv = HeroExcel.hero[heroID].grade
    local strategyConfig = HeroExcel.strategy
    if strategyConfig[fatherID] == nil then
        return
    end
    local totalPoint = 0
    for i = 1,#strategyConfig[fatherID].stats do
        msgRet.stats.power[i] = strategyConfig[fatherID].stats[i]
        totalPoint = totalPoint + strategyConfig[fatherID].stats[i]
    end
    msgRet.stats.power[0] = #strategyConfig[fatherID].stats
    msgRet.stats.totalPoint = totalPoint
    msgRet.stats.dingwei = strategyConfig[fatherID].dingwei

    -- xy todo ³Ùµã²¹ÉÏÏà¹ØÂß¼­
    local heroData = {}
    local allHeroData = {}
    local len = 0
    local camp = HeroExcel.hero[heroID].camp
    if allHeroData[camp] ~= nil then
        for i = 1,#allHeroData[camp] do
            if allHeroData[camp][i].id == fatherID then
                len = len + 1
                heroData[len] = {}
                heroData[len] = allHeroData[camp][i]
            end
        end
    end
    local cnt = #heroData 
    local count = 0
    for i = 1,cnt do
        count = count + 1
        HeroGrid.makeHeroInfo(msgRet.manito[count].heroInfo, heroData[count])
        RoleLogic.makeRoleBase(heroData[count].roleBase,msgRet.manito[count].player)
        msgRet.manito[count].heroIndex = heroData[count].index
        msgRet.manito[count].svrName = heroData[count].srvName or ""
        msgRet.manito[count].zhandouli = heroData[count].zhandouli
        if count >= 3 then
            break
        end
    end
    if cnt < 3 then
        count = count + 1
        local config = HeroExcel.hero
        local mobanId = strategyConfig[fatherID].heroID
        local heroSimple = {}
        local heroDynamic = {}
        local heroStatic = {}

        local heroGrid = HeroGrid.getCacheHeroGrid(mobanId)
	    HeroGrid.makeHeroSimple(heroSimple, heroGrid)
        HeroGrid.makeHeroInfo(msgRet.manito[count].heroInfo, heroGrid)
        local player = {}
        player.name = Lang.TUIJIAN_HERO
        RoleLogic.makeRoleBase(player,msgRet.manito[count].player)
        msgRet.manito[count].heroIndex = 0
        msgRet.manito[count].svrName = Config.SVR_NAME
        msgRet.manito[count].zhandouli = heroSimple.zhandouli
    end
    msgRet.manito[0] = count
    msgRet.strategy = strategyConfig[fatherID].strategy
    msgRet.last = strategyConfig[fatherID].last or 0
    msgRet.next = strategyConfig[fatherID].next or 0
    local heroGrid = HeroGrid.getCacheHeroGrid(heroID)
	HeroGrid.makeHeroSimple(msgRet.heroSimple, heroGrid, nil, human)
	HeroGrid.makeHeroDynamic(msgRet.heroDynamic, heroGrid, nil, human)		
	HeroGrid.makeHeroStatic(msgRet.heroStatic,heroGrid.id)		
    Msg.send(msgRet,human.fd)
end

function heroDetailMsgQuery(human,uuid,heroIndex,heroId)

end

function heroGlDot(human)
    local msgRet = Msg.gc.GC_HERO_GL_DOT_QUERY
    msgRet.isDot = 1
    if human.db.lookGl ~= nil then
        msgRet.isDot = 0
    end
    Msg.send(msgRet,human.fd)
end