miduo_client/Assets/ManagedResources/~Lua/Modules/DynamicActivity/ActivityDetail.lua

445 lines
17 KiB
Lua

local ActivityDetail= quick_class("ActivityDetail")
local sortingOrder = 0
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local listUpPre={} --限时召唤
local rate={}
local listSoulUpPre={} --魂印
local soulRate={}
local listMonsterUpPre={} --灵兽
local monsterRate={}
local mainMonsterRate=0
local listNewHeroUpPre={} --降妖夺宝
local newHeroRate={}
local mainNewHeroRate=0
local panelType
local detailText={
[1] = HELP_TYPE.TimeLimitedCall,
[2] = HELP_TYPE.QianKunBox,
[3] = HELP_TYPE.LingShouBaoGe,
[4] = HELP_TYPE.XiangYaoDuoBao,
}
function ActivityDetail:ctor(gameObject,type,effect)
self.gameObject = gameObject
if effect then
self.effect = effect
end
panelType = type
self:InitComponent(gameObject)
self:BindEvent()
self:OnShow()
end
function ActivityDetail:InitComponent(gameObject)
self.closeBtn=Util.GetGameObject(self.gameObject,"close")
self.itemGrid=Util.GetGameObject(self.gameObject,"panel/itemGrid")
self.LookDetailBtn=Util.GetGameObject(self.gameObject,"panel/Image3/updetail")
self.content1=Util.GetGameObject(self.gameObject,"panel/content")
self.content =Util.GetGameObject(self.content1,"Text"):GetComponent("Text")
self.time=Util.GetGameObject(self.gameObject,"tip"):GetComponent("Text")
end
function ActivityDetail:BindEvent()
Util.AddClick(self.closeBtn.gameObject,function() self:OnHide() end)
Util.AddClick(self.LookDetailBtn.gameObject,function() self:LookDetailBtnAction() end)
end
function ActivityDetail:OnShow()
self.gameObject:SetActive(true)
local str=GetLanguageStrById(ConfigManager.TryGetConfigData(ConfigName.QAConfig,detailText[panelType]).content)--内容详情可以复用
str = string.gsub(str,"{","<color=#D48A07>")
str = string.gsub(str,"}","</color>")
str = string.gsub(str,"|","\n")--换行
self.content.text= str
local str2
--判断抽取的类型
if panelType == 1 then--限时召唤
self:ReFreshUpHero()
self:RefreshHeroRate()
str2=ActivityGiftManager.GetTimeStartToEnd(ActivityTypeDef.FindFairy)
elseif panelType==2 then--乾坤包囊
self:ReFreshUpSoul()
self:RefreshSoulRate()
str2=ActivityGiftManager.GetTimeStartToEnd(ActivityTypeDef.QianKunBox)
elseif panelType==3 then--灵兽宝阁
self:ReFreshUpMonster()
self:RefreshMonsterRate()
str2=ActivityGiftManager.GetTimeStartToEnd(ActivityTypeDef.LingShouBaoGe)
elseif panelType==4 then--降妖夺宝
self:ReFreshUpNewHero()
self:RefreshNewHeroRate()
str2=ActivityGiftManager.GetTimeStartToEnd(ActivityTypeDef.XiangYaoDuoBao)
end
self.time.text=Language[10454]..str2
end
--============================降妖夺宝功能======================================
function ActivityDetail:ReFreshUpNewHero()
self.LookDetailBtn:SetActive(false)
local UpMonster=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.XIANG_YAO_UP)
local rewardData,showData,curScore = DynamicActivityManager.XiangYaoBuildData()
if(not listNewHeroUpPre) then
listNewHeroUpPre={}
end
if(not newHeroRate) then
newHeroRate={}
end
for n,m in ipairs(UpMonster) do
if m and m.Reward[1] == showData.monsterId then
if not listNewHeroUpPre[n] then
listNewHeroUpPre[n] = SubUIManager.Open(SubUIConfig.ItemView,self.itemGrid.transform)
end
listNewHeroUpPre[n]:OnOpen(false, {m.Reward[1], m.Reward[2]}, 1.1, true)
local weight = self:ReculateUpNewHeroRate(m.Reward[1])
local tempName = listNewHeroUpPre[n].name:GetComponent("Text").text
mainNewHeroRate = weight
listNewHeroUpPre[n].name:GetComponent("Text").text="<color=#EDB64C>"..string.format("%.2f", (weight/100000)*100) .."%</color>"
listNewHeroUpPre[n].gameObject:SetActive(true)
table.insert(newHeroRate,{tag=Language[10455],name=tempName,value=weight})
end
end
end
--计算所有的比重
function ActivityDetail:ReculateUpNewHeroRate(id)
local UpMonster=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.XIANG_YAO_UP)
for n,m in ipairs(UpMonster) do
if m and id==m.Reward[1] then
return m.Weight
end
end
return 0
end
function ActivityDetail:RefreshNewHeroRate()
local list1={}
local list2={}
local list3={}
local monsterRateList={}
local allValue
local UpMonster=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.XIANG_YAO_UP)
for index, v in ipairs(UpMonster) do
if itemConfig[v.Reward[1]].HeroStar[2]==5 then
table.insert(list1,v)--五星应雄
elseif itemConfig[v.Reward[1]].HeroStar[2]==4 then
table.insert(list2,v)--四星应雄
elseif itemConfig[v.Reward[1]].HeroStar[2]==3 then
table.insert(list3,v)--三星应雄
end
end
-- --LogGreen(self:ReculateRate(list1).." "..self:ReculateRate(list2).." "..self:ReculateRate(list3).." mainNewHeroRate:"..mainNewHeroRate)
table.insert(monsterRateList,{tag=Language[12123],name=Language[12124],value=self:ReculateRate(list1)-mainNewHeroRate})
table.insert(monsterRateList,{tag=Language[12125],name=Language[12126],value=self:ReculateRate(list2)})
table.insert(monsterRateList,{tag=Language[12127],name=Language[12128],value=self:ReculateRate(list3)})
allValue = self:ReculateRate(list1) + self:ReculateRate(list2) + self:ReculateRate(list3)
for n,m in ipairs(monsterRateList) do
if m and m.value>0 then
local o=Util.GetGameObject(self.gameObject,"panel/rate/rate/rateprefab"..n)
if not o then
else
o.gameObject:SetActive(true)
Util.GetGameObject(o.gameObject,"star"):GetComponent("Text") .text=m.tag
Util.GetGameObject(o.gameObject,"name"):GetComponent("Text") .text=m.name
Util.GetGameObject(o.gameObject,"rate"):GetComponent("Text") .text=string.format("%.2f",(m.value/allValue)*100).."%"
end
end
end
end
--============================灵兽宝阁功能======================================
function ActivityDetail:ReFreshUpMonster()
self.LookDetailBtn:SetActive(false)
local UpMonster=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.LING_SHOU_UP)
local rewardData,showData,curScore = DynamicActivityManager.LingShouBuildData()
if(not listMonsterUpPre) then
listMonsterUpPre={}
end
if(not monsterRate) then
monsterRate={}
end
for n,m in ipairs(UpMonster) do
if m and m.Reward[1] == showData.monsterId then
if not listMonsterUpPre[n] then
listMonsterUpPre[n] = SubUIManager.Open(SubUIConfig.ItemView,self.itemGrid.transform)
end
listMonsterUpPre[n]:OnOpen(false, {m.Reward[1], m.Reward[2]}, 1.1, true)
local weight = self:ReculateUpMonsterRate(m.Reward[1])
local tempName = listMonsterUpPre[n].name:GetComponent("Text").text
mainMonsterRate = weight
listMonsterUpPre[n].name:GetComponent("Text").text="<color=#EDB64C>"..string.format("%.2f", (weight/100000)*100) .."%</color>"
listMonsterUpPre[n].gameObject:SetActive(true)
table.insert(monsterRate,{tag=Language[10455],name=tempName,value=weight})
end
end
end
--计算所有的比重
function ActivityDetail:ReculateUpMonsterRate(id)
local UpMonster=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.LING_SHOU_UP)
for n,m in ipairs(UpMonster) do
if m and id==m.Reward[1] then
return m.Weight
end
end
return 0
end
function ActivityDetail:RefreshMonsterRate()
local list1={}
local list2={}
local list3={}
local list4={}
local monsterRateList={}
local UpMonster=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.LING_SHOU_UP)
for index, v in ipairs(UpMonster) do
if itemConfig[v.Reward[1]].Quantity==5 and (itemConfig[v.Reward[1]].ItemType==22 or itemConfig[v.Reward[1]].ItemType==21) then
table.insert(list1,v)--金色灵兽碎片
elseif itemConfig[v.Reward[1]].Quantity==4 and (itemConfig[v.Reward[1]].ItemType==22 or itemConfig[v.Reward[1]].ItemType==21) then
table.insert(list2,v)--紫色灵兽碎片
elseif itemConfig[v.Reward[1]].Quantity==3 and (itemConfig[v.Reward[1]].ItemType==22 or itemConfig[v.Reward[1]].ItemType==21) then
table.insert(list3,v)--蓝色灵兽碎片
else
table.insert(list4,v)--其他
end
end
table.insert(monsterRateList,{tag=Language[10176],name=Language[12294],value=self:ReculateRate(list1)-mainMonsterRate})
table.insert(monsterRateList,{tag=Language[10178],name=Language[12295],value=self:ReculateRate(list2)})
table.insert(monsterRateList,{tag=Language[10179],name=Language[12296],value=self:ReculateRate(list3)})
table.insert(monsterRateList,{tag=Language[10459],name=Language[12297],value=self:ReculateRate(list4)})
for n,m in ipairs(monsterRateList) do
if m and m.value>0 then
local o=Util.GetGameObject(self.gameObject,"panel/rate/rate/rateprefab"..n)
if not o then
else
o.gameObject:SetActive(true)
Util.GetGameObject(o.gameObject,"star"):GetComponent("Text") .text=m.tag
Util.GetGameObject(o.gameObject,"name"):GetComponent("Text") .text=m.name
Util.GetGameObject(o.gameObject,"rate"):GetComponent("Text") .text=string.format("%.2f",(m.value/100000)*100).."%"
end
end
end
end
--============================乾坤包囊功能======================================
function ActivityDetail:ReFreshUpSoul()
self.LookDetailBtn:SetActive(false)
local UpSoul=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.LOTTERY_SOUL_UP)
if(not listSoulUpPre) then
listSoulUpPre={}
end
if(not soulRate) then
soulRate={}
end
for n,m in ipairs(UpSoul) do
if m then
if not listSoulUpPre[n] then
listSoulUpPre[n] = SubUIManager.Open(SubUIConfig.ItemView,self.itemGrid.transform)
end
listSoulUpPre[n]:OnOpen(false, {m.Reward[1], m.Reward[2]}, 1.1, true)
local weight = self:ReculateUpSoulRate(m.Reward[1])
local tempName = listSoulUpPre[n].name:GetComponent("Text").text
listSoulUpPre[n].name:GetComponent("Text").text="<color=#EDB64C>"..string.format("%.2f", (weight/100000)*100) .."%</color>"
listSoulUpPre[n].gameObject:SetActive(true)
table.insert(soulRate,{tag=Language[10455],name=tempName,value=weight})
end
end
end
--计算所有的比重
function ActivityDetail:ReculateUpSoulRate(id)
local Soul=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.LOTTERY_SOUL)
for n,m in ipairs(Soul) do
if m and id==m.Reward[1] then
return m.Weight
end
end
return 0
end
function ActivityDetail:RefreshSoulRate()
local list4={}
local list5={}
local list6={}
local list7={}
local soul=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.LOTTERY_SOUL)
for index, v in ipairs(soul) do
if itemConfig[v.Reward[1]].Quantity==4 and itemConfig[v.Reward[1]].ItemType==13 then
table.insert(list4,v)--紫色
elseif itemConfig[v.Reward[1]].Quantity==5 and itemConfig[v.Reward[1]].ItemType==13 then
table.insert(list5,v)--金色
elseif itemConfig[v.Reward[1]].Quantity==6 and itemConfig[v.Reward[1]].ItemType==13 then
table.insert(list6,v)--红色
else
table.insert(list7,v)--其他
end
end
table.insert(soulRate,{tag=Language[10177],name=Language[10459]..Language[10177],value=self:ReculateRate(list6)-soulRate[1].value-soulRate[2].value-soulRate[3].value})
table.insert(soulRate,{tag=Language[10176],name=Language[10176],value=self:ReculateRate(list5)})
table.insert(soulRate,{tag=Language[10178],name=Language[10178],value=self:ReculateRate(list4)})
table.insert(soulRate,{tag=Language[10459],name=Language[10459],value=self:ReculateRate(list7)})
for n,m in ipairs(soulRate) do
if m and m.value>0 then
local o=Util.GetGameObject(self.gameObject,"panel/rate/rate/rateprefab"..n)
if not o then
else
o.gameObject:SetActive(true)
Util.GetGameObject(o.gameObject,"star"):GetComponent("Text") .text=m.tag
Util.GetGameObject(o.gameObject,"name"):GetComponent("Text") .text=m.name
Util.GetGameObject(o.gameObject,"rate"):GetComponent("Text") .text=string.format("%.2f",(m.value/100000)*100).."%"
end
end
end
end
--============================限时召唤功能======================================
function ActivityDetail:ReFreshUpHero()
self.LookDetailBtn:SetActive(true)
local UpHero=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.TIME_LIMITED_UP)
if(not listUpPre) then
listUpPre={}
end
if(not rate) then
rate={}
end
for n,m in ipairs(UpHero) do
if m then
if not listUpPre[n] then
listUpPre[n] = SubUIManager.Open(SubUIConfig.ItemView,self.itemGrid.transform)
end
listUpPre[n]:OnOpen(false, {m.Reward[1], m.Reward[2]}, 1.1, true)
local weight = self:ReculateUpHeroRate(m.Reward[1])
local tempName = listUpPre[n].name:GetComponent("Text").text
listUpPre[n].name:GetComponent("Text").text="<color=#EDB64C>"..string.format("%.2f", (weight/100000)*100) .."%</color>"
listUpPre[n].gameObject:SetActive(true)
table.insert(rate,{tag=Language[10460],name=tempName,value=weight})
end
end
end
function ActivityDetail:ReculateUpHeroRate(id)
local Hero=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.TIME_LIMITED)
for n,m in ipairs(Hero) do
if m and id==m.Reward[1] then
return m.Weight
end
end
return 0
end
function ActivityDetail:RefreshHeroRate()
local list3={}
local list4={}
local list5={}
local list2={}
local hero=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.TIME_LIMITED)
for index, v in ipairs(hero) do
if itemConfig[v.Reward[1]].HeroStar[2]==3 then
table.insert(list3,v)
elseif itemConfig[v.Reward[1]].HeroStar[2]==4 then
table.insert(list4,v)
elseif itemConfig[v.Reward[1]].HeroStar[2]==5 then
table.insert(list5,v)
elseif itemConfig[v.Reward[1]].HeroStar[2]==2 then
table.insert(list2,v)
end
end
table.insert(rate,{tag=Language[10461],name=Language[10462],value=self:ReculateRate(list5)-rate[1].value-rate[2].value-rate[3].value})
table.insert(rate,{tag=Language[10463],name=Language[10464],value=self:ReculateRate(list4)})
table.insert(rate,{tag=Language[10465],name=Language[10466],value=self:ReculateRate(list3)})
table.insert(rate,{tag=Language[10467],name=Language[10468],value=self:ReculateRate(list2)})
for n,m in ipairs(rate) do
if m and m.value>0 then
local o=Util.GetGameObject(self.gameObject,"panel/rate/rate/rateprefab"..n)
if not o then
else
o.gameObject:SetActive(true)
Util.GetGameObject(o.gameObject,"star"):GetComponent("Text") .text=m.tag
Util.GetGameObject(o.gameObject,"name"):GetComponent("Text") .text=m.name
Util.GetGameObject(o.gameObject,"rate"):GetComponent("Text") .text=string.format("%.2f",(m.value/100000)*100).."%"
end
end
end
end
--通用计算权重功能
function ActivityDetail:ReculateRate(list)
local weight=0
for index, v in ipairs(list) do
weight=v.Weight+weight
end
return weight
end
function ActivityDetail:LookDetailBtnAction()
if panelType == 1 then
UIManager.OpenPanel(UIName.HeroPreviewPanel,true,false)
elseif panelType ==2 then
LogPurple("打开魂印奖励预览")
elseif panelType ==3 then
LogPurple("打开魂印奖励预览")
end
end
function ActivityDetail:OnHide()
self.gameObject:SetActive(false)
if self.effect then
self.effect:SetActive(true)
end
if rate then
for n,m in ipairs(rate) do
if not rate[n] then
local o=Util.GetGameObject(self.gameObject,"panel/rate/rateprefab"..n)
o.gameObject.SetActive(false)
end
end
rate={}
end
if soulRate then
for n,m in ipairs(soulRate) do
if not soulRate[n] then
local o=Util.GetGameObject(self.gameObject,"panel/rate/rateprefab"..n)
o.gameObject.SetActive(false)
end
end
soulRate={}
end
if monsterRate then
for n,m in ipairs(monsterRate) do
if not monsterRate[n] then
local o=Util.GetGameObject(self.gameObject,"panel/rate/rateprefab"..n)
o.gameObject.SetActive(false)
end
end
monsterRate={}
end
end
function ActivityDetail:OnDestroy()
listUpPre=nil
rate=nil
listSoulUpPre=nil
soulRate=nil
listMonsterUpPre=nil
monsterRate=nil
listNewHeroUpPre=nil
newHeroRate=nil
end
return ActivityDetail