484 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			Lua
		
	
			
		
		
	
	
			484 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			Lua
		
	
LikabilityManager = {}
 | 
						||
local this = LikabilityManager
 | 
						||
local PropertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
 | 
						||
local PrivilegeTypeConfig = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
 | 
						||
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
 | 
						||
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
 | 
						||
this.heroDatas = {}
 | 
						||
 | 
						||
function this.Initialize()
 | 
						||
    this.AllHeroDataLikAbility = {}
 | 
						||
    this.HeroLvList = {}
 | 
						||
    this.TotalLvList = {}
 | 
						||
    this.ItemList = {}
 | 
						||
    this.InitializeTableData()
 | 
						||
end
 | 
						||
 | 
						||
 | 
						||
function this.InitializeTableData()
 | 
						||
    for k,v in ConfigPairs(ConfigManager.GetConfig(ConfigName.LikeAbility)) do
 | 
						||
        local data = {}
 | 
						||
        data.Id = v.Id
 | 
						||
        data.Type = v.Type
 | 
						||
        data.lv = v.Level
 | 
						||
        data.value = this.GetTotalValue(data.lv,v.Type)
 | 
						||
        data.Property = v.Property
 | 
						||
        data.priPro = v.PrivilegeProperty
 | 
						||
        if v.Type == 1 then
 | 
						||
            table.insert(this.TotalLvList,data)
 | 
						||
        else
 | 
						||
            table.insert(this.HeroLvList,data)
 | 
						||
        end
 | 
						||
    end
 | 
						||
    table.sort(this.TotalLvList,function(a,b)
 | 
						||
        return a.lv < b.lv
 | 
						||
    end)
 | 
						||
    table.sort(this.HeroLvList,function(a,b)
 | 
						||
        return a.lv < b.lv
 | 
						||
    end)
 | 
						||
 | 
						||
    local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.ItemConfig,"ItemType",ItemType.likeabilityItem)
 | 
						||
    for i = 1,#configs do
 | 
						||
        if not this.ItemList[configs[i].Id] then
 | 
						||
            this.ItemList[configs[i].Id] = {}
 | 
						||
        end
 | 
						||
        local str = string.split(configs[i].ResolveReward,"|")
 | 
						||
        for j = 1,#str do
 | 
						||
            local str1 = string.split(str[j],"#")
 | 
						||
            if not this.ItemList[configs[i].Id][tonumber(str1[1])] then
 | 
						||
                this.ItemList[configs[i].Id][tonumber(str1[1])] = tonumber(str1[2])
 | 
						||
            end
 | 
						||
        end 
 | 
						||
    end
 | 
						||
end
 | 
						||
 | 
						||
function this.GetTotalValue(lv,indexType)
 | 
						||
    local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.LikeAbility,"Type",indexType)
 | 
						||
    local num = 0
 | 
						||
    if lv == 0 then
 | 
						||
        return num
 | 
						||
    end
 | 
						||
    for i = 1,lv do
 | 
						||
        if configs[i].FavorDegree and configs[i].FavorDegree > 0 then
 | 
						||
            num = num + configs[i].FavorDegree
 | 
						||
        end      
 | 
						||
    end
 | 
						||
    return num
 | 
						||
end
 | 
						||
 | 
						||
-- -1  判断总好感度等级是否最大       其他 神将
 | 
						||
function this.CheckIsMaxLv(heroId)
 | 
						||
    local totalCurNum,totalLv,totalNum = this.GetTotalHeroLikeLv(heroId)
 | 
						||
    if heroId < 0 then
 | 
						||
        if totalLv >= this.TotalLvList[#this.TotalLvList].lv then
 | 
						||
            return true
 | 
						||
        end
 | 
						||
    else
 | 
						||
        if totalLv >= this.HeroLvList[#this.HeroLvList].lv then
 | 
						||
            return true
 | 
						||
        end
 | 
						||
    end
 | 
						||
    
 | 
						||
    return false
 | 
						||
end
 | 
						||
 | 
						||
function this.GetAllItemsData(pro)
 | 
						||
    local list = {}
 | 
						||
    for k,v in pairs(this.ItemList) do
 | 
						||
        local data = {}
 | 
						||
        data.num = BagManager.GetItemCountById(k)
 | 
						||
        data.id = k
 | 
						||
        data.property = ItemConfig[k].PropertyName
 | 
						||
        data.Quantity = ItemConfig[k].Quantity
 | 
						||
        if data.property == 0 then
 | 
						||
            data.sortId = -1
 | 
						||
        elseif data.property == pro then
 | 
						||
            data.sortId = 0
 | 
						||
        else
 | 
						||
            data.sortId = data.property
 | 
						||
        end
 | 
						||
        table.insert(list,data)
 | 
						||
    end
 | 
						||
    table.sort(list,function(a,b)
 | 
						||
        if a.sortId == b.sortId then
 | 
						||
            if a.Quantity == b.Quantity then
 | 
						||
                return a.id < b.id
 | 
						||
            end
 | 
						||
            return a.Quantity > b.Quantity
 | 
						||
        else
 | 
						||
            return a.sortId < b.sortId
 | 
						||
        end
 | 
						||
    end)
 | 
						||
    return list
 | 
						||
end
 | 
						||
 | 
						||
function this.UpdateAllBackData(msg)
 | 
						||
    for i = 1,#msg.infoList do
 | 
						||
        this.UpdatelBackData(msg.infoList[i].heroStaticid,msg.infoList[i].likableNum)
 | 
						||
    end
 | 
						||
end
 | 
						||
 | 
						||
function this.UpdatelBackData(heroId,value,isAdd)
 | 
						||
    if not this.AllHeroDataLikAbility[heroId] then
 | 
						||
        this.AllHeroDataLikAbility[heroId] = {}
 | 
						||
        this.AllHeroDataLikAbility[heroId].value = 0
 | 
						||
        this.AllHeroDataLikAbility[heroId].likeLv = 0
 | 
						||
    end
 | 
						||
    if not isAdd or isAdd == 0 then
 | 
						||
        this.AllHeroDataLikAbility[heroId].value = value
 | 
						||
    else
 | 
						||
        this.AllHeroDataLikAbility[heroId].value = this.AllHeroDataLikAbility[heroId].value + value
 | 
						||
    end
 | 
						||
    this.AllHeroDataLikAbility[heroId].likeLv = this.GetTotalHeroLikeLv(value)
 | 
						||
    local herodata = HeroManager.GetAllHeroList()
 | 
						||
    for k,v in pairs(herodata) do
 | 
						||
        HeroPropManager.SetFuncPropDirty(Func_Prop_Type.LikeAbility)
 | 
						||
        if v.id == heroId then
 | 
						||
            HeroPropManager.SetDirtyByType(v.dynamicId, Hero_Prop_Type.LikeAbility)
 | 
						||
        end
 | 
						||
    end
 | 
						||
end
 | 
						||
 | 
						||
function this.UpdatelSingleHeroData(heroId,itemId,itemNum)
 | 
						||
    local value = 0
 | 
						||
    local tempheroConfig = heroConfig[heroId]
 | 
						||
    value = this.ItemList[itemId][tempheroConfig.PropertyName]*itemNum
 | 
						||
    this.UpdatelBackData(heroId,value,1)
 | 
						||
    BagManager.HeroLvUpUpdateItemsNum(itemId,itemNum)
 | 
						||
    PopupTipPanel.ShowTip("好感度+"..value)
 | 
						||
end
 | 
						||
 | 
						||
--过去
 | 
						||
function this.GetCurItemValue(heroId,itemId,itemNum)
 | 
						||
    local value = 0
 | 
						||
    local tempheroConfig = heroConfig[heroId]
 | 
						||
    LogError("heroid=="..heroId)
 | 
						||
    LogError("itemid=="..itemId)
 | 
						||
    value = this.ItemList[itemId][tempheroConfig.PropertyName]*itemNum
 | 
						||
    return value
 | 
						||
end
 | 
						||
 | 
						||
-- -1 总好感度      其他是神将id
 | 
						||
function this.GetTotalHeroLikeLv(index)
 | 
						||
    local totalCurNum,totalLv,totalNum = 0,0,0
 | 
						||
    if index < 0 then
 | 
						||
        for k,v in pairs(this.AllHeroDataLikAbility) do
 | 
						||
            totalCurNum = totalCurNum + v.value
 | 
						||
        end
 | 
						||
        totalLv,totalNum = this.GetLv(1,totalCurNum)
 | 
						||
    else
 | 
						||
        totalCurNum = this.AllHeroDataLikAbility[index] and this.AllHeroDataLikAbility[index].value or 0
 | 
						||
        totalLv,totalNum = this.GetLv(2,totalCurNum)
 | 
						||
    end
 | 
						||
    return totalCurNum,totalLv,totalNum
 | 
						||
end
 | 
						||
 | 
						||
--indexType      1: 获取总好感度等级         2:获取单个神将好感度等级   
 | 
						||
function this.GetLv(indexType,value)
 | 
						||
    local list = {}
 | 
						||
    if indexType == 1 then
 | 
						||
        list = this.TotalLvList
 | 
						||
    else
 | 
						||
        list = this.HeroLvList
 | 
						||
    end
 | 
						||
    for i = 1,#list do
 | 
						||
        if value < list[i].value then
 | 
						||
            return list[i].lv - 1,list[i].value
 | 
						||
        end
 | 
						||
    end
 | 
						||
    return list[#list].lv,list[#list].value
 | 
						||
end
 | 
						||
 | 
						||
--indexType      1: 获取总好感度属性         2:获取单个神将好感度属性      
 | 
						||
--index      -1 获取累加的好感度属性     其他 获取某级的好感度属性 
 | 
						||
--lv 累加到某级
 | 
						||
function this.GetProData(indexType,index,lv)
 | 
						||
    local list = {}
 | 
						||
    if indexType == 1 then
 | 
						||
        list = this.TotalLvList
 | 
						||
    else
 | 
						||
        list = this.HeroLvList
 | 
						||
    end
 | 
						||
    local allPro = {}
 | 
						||
    if index >= 0 then
 | 
						||
        for _,n in ipairs(list) do
 | 
						||
            if indexType == n.Type and lv == n.lv then
 | 
						||
                if n.Property and #n.Property > 0 then
 | 
						||
                    for i = 1,#n.Property do
 | 
						||
                        if not allPro[n.Property[i][1]] then
 | 
						||
                            allPro[n.Property[i][1]] = 0
 | 
						||
                        end
 | 
						||
                        allPro[n.Property[i][1]] = allPro[n.Property[i][1]] + n.Property[i][2]
 | 
						||
                    end
 | 
						||
                end
 | 
						||
                break
 | 
						||
            end
 | 
						||
        end
 | 
						||
    else
 | 
						||
        for _,n in ipairs(list) do
 | 
						||
            if n.Property and #n.Property > 0 and lv >= n.lv then
 | 
						||
                if n.Property and #n.Property > 0 then
 | 
						||
                    for i = 1,#n.Property do
 | 
						||
                        if not allPro[n.Property[i][1]] then
 | 
						||
                            allPro[n.Property[i][1]] = 0
 | 
						||
                        end
 | 
						||
                        allPro[n.Property[i][1]] = allPro[n.Property[i][1]] + n.Property[i][2]
 | 
						||
                    end
 | 
						||
                end
 | 
						||
            end
 | 
						||
        end
 | 
						||
    end
 | 
						||
    return allPro
 | 
						||
end
 | 
						||
--获取权益属性加成
 | 
						||
function this.GetPrivilageProData(indexType,index,lv)
 | 
						||
    local list = {}
 | 
						||
    if indexType == 1 then
 | 
						||
        list = this.TotalLvList
 | 
						||
    else
 | 
						||
        list = this.HeroLvList
 | 
						||
    end
 | 
						||
    local allPro = {}
 | 
						||
    if index >= 0 then
 | 
						||
        for _,n in ipairs(list) do
 | 
						||
            if indexType == n.Type and lv == n.lv then
 | 
						||
                if n.priPro and #n.priPro > 0 then
 | 
						||
                    for i = 1,#n.priPro do
 | 
						||
                        if not allPro[n.priPro[i][1]] then
 | 
						||
                            allPro[n.priPro[i][1]] = 0
 | 
						||
                        end
 | 
						||
                        allPro[n.priPro[i][1]] = allPro[n.priPro[i][1]] + n.priPro[i][2]
 | 
						||
                    end                   
 | 
						||
                end
 | 
						||
                break
 | 
						||
            end
 | 
						||
        end
 | 
						||
    else
 | 
						||
        for _,n in ipairs(list) do
 | 
						||
            if n.priPro and #n.priPro > 0 and lv >= n.lv then
 | 
						||
                if n.priPro and #n.priPro > 0 then
 | 
						||
                    for i = 1,#n.priPro do
 | 
						||
                        if not allPro[n.priPro[i][1]] then
 | 
						||
                            allPro[n.priPro[i][1]] = 0
 | 
						||
                        end
 | 
						||
                        allPro[n.priPro[i][1]] = allPro[n.priPro[i][1]] + n.priPro[i][2]
 | 
						||
                    end
 | 
						||
                end
 | 
						||
            end
 | 
						||
        end
 | 
						||
    end
 | 
						||
    return allPro
 | 
						||
end
 | 
						||
 | 
						||
function this.GetTotalForce(heroData)
 | 
						||
    local SingleProVal = {}
 | 
						||
    local AllHeroProVal = {}
 | 
						||
    local lv,totalNum = 0,0
 | 
						||
    if heroData then
 | 
						||
        if this.AllHeroDataLikAbility[heroData.tId] then
 | 
						||
            lv,totalNum = this.GetLv(2,this.AllHeroDataLikAbility[heroData.tId].value)
 | 
						||
            SingleProVal = this.GetProData(2,-1,lv)
 | 
						||
        end
 | 
						||
    end
 | 
						||
    local totalCurNum,totalLv,totalNum = this.GetTotalHeroLikeLv(-1)
 | 
						||
    AllHeroProVal = this.GetProData(1,-1,totalLv)
 | 
						||
    -- for k,v in pairs(SingleProVal) do
 | 
						||
    --     LogGreen("SingleProVal   k:"..k.."          v:"..v)
 | 
						||
    -- end
 | 
						||
    -- for k,v in pairs(AllHeroProVal) do
 | 
						||
    --     LogGreen("AllHeroProVal   k:"..k.."          v:"..v)
 | 
						||
    -- end
 | 
						||
    return SingleProVal, AllHeroProVal
 | 
						||
end
 | 
						||
 | 
						||
function this.CheckRedPot()
 | 
						||
    if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.LikeAbility) then
 | 
						||
        for k,v in pairs(this.ItemList) do
 | 
						||
            local num = BagManager.GetItemCountById(k)
 | 
						||
            if num > 0 then
 | 
						||
                 --计算玩家拥有的英雄中对应星级的英雄的数量    
 | 
						||
                for i, v in pairs(PlayerManager.heroHandBook) do
 | 
						||
                    local conFig = ConfigManager.GetConfigData(ConfigName.HeroConfig,i)
 | 
						||
                    if conFig and conFig.Star == 5 then     
 | 
						||
                        if not this.CheckIsMaxLv(i) then
 | 
						||
                            return true 
 | 
						||
                        end
 | 
						||
                    end
 | 
						||
                end
 | 
						||
            end
 | 
						||
        end
 | 
						||
    end
 | 
						||
    return false
 | 
						||
end
 | 
						||
 | 
						||
function this.GetCurSortHeroListData(proId)
 | 
						||
    local list = {}
 | 
						||
     --计算玩家拥有的英雄中对应星级的英雄的数量    
 | 
						||
     for i, v in pairs(PlayerManager.heroHandBook) do
 | 
						||
        local conFig = ConfigManager.GetConfigData(ConfigName.HeroConfig,i)
 | 
						||
        if conFig then     
 | 
						||
            if conFig.Star == 5 and (proId == 0 or conFig.PropertyName == proId) then
 | 
						||
               table.insert(list,conFig)
 | 
						||
            end
 | 
						||
        end
 | 
						||
    end
 | 
						||
    this.SortHerosData(list)
 | 
						||
    this.heroDatas = list
 | 
						||
    return list
 | 
						||
end
 | 
						||
 | 
						||
function this.SortHerosData(heroData)
 | 
						||
    table.sort(heroData,function(a,b)
 | 
						||
        return a.Sort < b.Sort
 | 
						||
    end)
 | 
						||
    return heroData
 | 
						||
end
 | 
						||
 | 
						||
--type   1是标题 界面显示用                2是内容
 | 
						||
--content  内容
 | 
						||
function this.CreatSingleProData(type,content)
 | 
						||
    local data = {}
 | 
						||
    data.type = type
 | 
						||
    data.content = content
 | 
						||
    data.prolist = {}
 | 
						||
    return data
 | 
						||
end
 | 
						||
--indexType  1总好感度     2:神将
 | 
						||
--add -1 是累加    其他是不累加
 | 
						||
--等级
 | 
						||
--title1标题
 | 
						||
--title2子标题
 | 
						||
--subtitle1普通属性内容
 | 
						||
--subtitle2特权属性内容
 | 
						||
--nextLv: 下一等级
 | 
						||
--all 所有的
 | 
						||
 | 
						||
local isall
 | 
						||
function this.GetViewProData(indexType,add,lv,title1,title2,subtitle1,subtitle2,nextLv,all)
 | 
						||
    isall = all
 | 
						||
    local data = this.CreatSingleProData(1,title1)
 | 
						||
    local list = {}
 | 
						||
    if indexType == 1 then
 | 
						||
        list = this.TotalLvList
 | 
						||
    else
 | 
						||
        list = this.HeroLvList
 | 
						||
    end
 | 
						||
    local num,lv2,totalNum = LikabilityManager.GetTotalHeroLikeLv(indexType)
 | 
						||
    if all then
 | 
						||
        for i = 1,#list do
 | 
						||
            if list[i].lv ~= 0 then
 | 
						||
                local color = ""
 | 
						||
                local tempNum = 0 
 | 
						||
                if lv >= list[i].lv then
 | 
						||
                    color = "00FF00"
 | 
						||
                    tempNum = list[i].value
 | 
						||
                else
 | 
						||
                    color = "fdf5e5"     
 | 
						||
                    tempNum = num  
 | 
						||
                end
 | 
						||
                if title2 and title2 ~= "" then
 | 
						||
                    table.insert(data.prolist,string.format(title2,color,list[i].lv,tempNum,list[i].value))
 | 
						||
                end
 | 
						||
                local str1,str2 = this.GetViewProDatas(indexType,add,list[i].lv,subtitle1,subtitle2,nextLv,color)
 | 
						||
                table.insert(data.prolist,str1)
 | 
						||
                table.insert(data.prolist,str2)
 | 
						||
            end
 | 
						||
        end
 | 
						||
    else
 | 
						||
        local color = "00FF00"
 | 
						||
        if title2 and title2 ~= "" then
 | 
						||
            table.insert(data.prolist,string.format(title2,color,lv,num,totalNum))
 | 
						||
        end
 | 
						||
        local str1,str2 = this.GetViewProDatas(indexType,add,lv,subtitle1,subtitle2,nextLv,color)
 | 
						||
        table.insert(data.prolist,str1)
 | 
						||
        table.insert(data.prolist,str2)
 | 
						||
    end
 | 
						||
    return data
 | 
						||
end
 | 
						||
 | 
						||
--indexType  1总好感度     2:神将
 | 
						||
--add -1 是累加    其他是不累加
 | 
						||
--等级
 | 
						||
--title1标题
 | 
						||
--title2子标题
 | 
						||
--subtitle1普通属性内容
 | 
						||
--subtitle2特权属性内容
 | 
						||
--nextLv: 下一等级
 | 
						||
function this.GetViewProDatas(indexType,add,lv,subtitle1,subtitle2,nextLv,color)
 | 
						||
    local num = 0
 | 
						||
    if indexType > 1 then
 | 
						||
        indexType = 2
 | 
						||
    end
 | 
						||
    local str1,str2 = "",""
 | 
						||
    local pro1 = LikabilityManager.GetProData(indexType,add,lv)
 | 
						||
    if LengthOfTable(pro1) > 0 then
 | 
						||
        str1 = this.SetProvalue(pro1,1,subtitle1,nextLv,indexType,color)
 | 
						||
    end
 | 
						||
    local pro2 = LikabilityManager.GetPrivilageProData(indexType,add,lv)
 | 
						||
    if LengthOfTable(pro2) > 0 then
 | 
						||
        str2 = this.SetProvalue(pro2,2,subtitle2,nextLv,indexType,color)
 | 
						||
    end
 | 
						||
    return str1,str2
 | 
						||
end
 | 
						||
 | 
						||
--属性列表 ,1属性  2特权,  标签,
 | 
						||
function this.SetProvalue(prolist,proType,tag,nextLv,indexType,_color)
 | 
						||
    local list = {}
 | 
						||
    local color1 = _color
 | 
						||
    if indexType == 1 then
 | 
						||
        list = this.TotalLvList
 | 
						||
    else
 | 
						||
        list = this.HeroLvList
 | 
						||
    end
 | 
						||
    if indexType == 1 and not isall then
 | 
						||
        color1 = "fdf5e5"
 | 
						||
    end
 | 
						||
    local newProList = {}
 | 
						||
    local str = ""
 | 
						||
    LogError("#prolist=="..#prolist)
 | 
						||
    for k,v in pairs(prolist) do
 | 
						||
        local str1 = ""
 | 
						||
        if proType == 1 then
 | 
						||
            str1 = PropertyConfig[k].Info..string.format("  <color=#%s>+%s</color>",_color,GetPropertyFormatStrOne(PropertyConfig[k].Style, v) )  
 | 
						||
            if nextLv and not this.CheckIsMaxLv2(indexType,nextLv) then
 | 
						||
                local pro1 = LikabilityManager.GetProData(indexType,nextLv,nextLv)
 | 
						||
                if pro1[k] and pro1[k] > 0 then
 | 
						||
                    str1 = str1.."       "..string.format("<color=#%s>(下级额外 +%s)</color>",color1,pro1[k])
 | 
						||
                end
 | 
						||
            end
 | 
						||
        else
 | 
						||
            local config = ConfigManager.TryGetConfigDataByKey(ConfigName.PrivilegeTypeConfig,"PrivilegeType",k)
 | 
						||
            if config then
 | 
						||
                local tempStr = ""
 | 
						||
                if v > 0 then
 | 
						||
                    tempStr = GetEquipPropertyFormatStr(config.IfFloat, v)
 | 
						||
                else
 | 
						||
                    tempStr = string.format("%d%%", 0)
 | 
						||
                end
 | 
						||
                str1 = string.format(config.Name,string.format("<color=#%s>%s</color>",_color,tempStr))
 | 
						||
            end
 | 
						||
        end
 | 
						||
        table.insert(newProList,str1) 
 | 
						||
    end
 | 
						||
    
 | 
						||
    str = string.format(tag,color1,(newProList[1] or ""),(newProList[2] or ""),(newProList[3] or ""),(newProList[4] or ""))
 | 
						||
    LogError("str==="..str)
 | 
						||
    return str
 | 
						||
end
 | 
						||
 | 
						||
function this.CheckIsMaxLv2(indexType,nextLv)
 | 
						||
    local list = {}
 | 
						||
    if indexType == 1 then
 | 
						||
        list = this.TotalLvList
 | 
						||
    else
 | 
						||
        list = this.HeroLvList
 | 
						||
    end
 | 
						||
    for i = 1,#list do
 | 
						||
        if list[i].lv == nextLv then
 | 
						||
            return false
 | 
						||
        end
 | 
						||
    end
 | 
						||
    return true
 | 
						||
end
 | 
						||
 | 
						||
return this |