miduo_client/Assets/ManagedResources/~Lua/Modules/Likability/LikabilityManager.lua

417 lines
13 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
function this.CheckIsMaxLv(heroId)
local totalCurNum,totalLv,totalNum = this.GetTotalHeroLikeLv(heroId)
if totalLv >= this.HeroLvList[#this.HeroLvList].lv then
return true
end
return false
end
function this.GetAllItemsData()
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
table.insert(list,data)
end
table.sort(list,function(a,b)
if a.property == b.property then
return a.id < b.id
end
return a.property < b.property
end)
return list
end
function this.SetRemainTimes(times,indextype)
if indextype < 0 then
this.remainTimes = this.remainTimes - times
elseif indextype > 0 then
this.remainTimes = this.remainTimes + times
else
this.remainTimes = times
end
end
function this.GetRemainTimes()
return this.remainTimes
end
function this.UpdateAllBackData(msg)
this.SetRemainTimes(msg.likableRemainTime,0)
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)
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)
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
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 index == 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.id] then
lv,totalNum = this.GetLv(2,this.AllHeroDataLikAbility[heroData.id].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
if this.remainTimes > 0 then
for k,v in pairs(this.ItemList) do
local num = BagManager.GetItemCountById(k)
if num > 0 then
return true
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()
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 所有的
function this.GetViewProData(indexType,add,lv,title1,title2,subtitle1,subtitle2,nextLv,all)
local data = this.CreatSingleProData(1,title1)
local list = {}
if indexType == 1 then
list = this.TotalLvList
else
list = this.HeroLvList
end
local num,lv,totalNum = LikabilityManager.GetTotalHeroLikeLv(indexType)
if all then
for i = 1,#list do
if list[i].lv ~= 0 then
local color = ""
if lv >= list[i].lv then
color = "5dc446"
else
color = "fdf5e5"
end
if title2 and title2 ~= "" then
table.insert(data.prolist,string.format(title2,color,list[i].lv,num,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 = "5dc446"
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 = {}
if indexType == 1 then
list = this.TotalLvList
else
list = this.HeroLvList
end
local newProList = {}
local str = ""
for k,v in pairs(prolist) do
local str1 = ""
if proType == 1 then
str1 = PropertyConfig[k].Info..":"..GetPropertyFormatStrOne(PropertyConfig[k].Style, v)
if nextLv and list[nextLv] then
local pro1 = LikabilityManager.GetProData(indexType,-1,nextLv)
if pro1[k] and pro1[k] > 0 then
str1 = PropertyConfig[k].Info..":"..GetPropertyFormatStrOne(PropertyConfig[k].Style, v).." "..string.format("(下级额外 +%s)",pro1[k])
end
end
else
local config = ConfigManager.GetConfigDataByKey(ConfigName.PrivilegeTypeConfig,"PrivilegeType",k)
str1 = string.format(config.Name,GetPropertyFormatStrOne(config.IfFloat, v))
end
table.insert(newProList,str1)
end
str = string.format(tag,color,(newProList[1] or ""),(newProList[2] or ""))
return str
end
return this