miduo_client/Assets/ManagedResources/~Lua/Modules/Operating/TimeLimitedCall.lua

326 lines
14 KiB
Lua

local TimeLimitedCall= quick_class("TimeLimitedCall")
local ActivityDetail = require("Modules/Operating/ActivityDetail")--活动详情
local RewardPreview = require("Modules/Operating/RewardPreview")--奖励预览
local sortingOrder = 0
local lotterySetting=ConfigManager.GetConfig(ConfigName.LotterySetting)
local privilegeConfig=ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
local artResourcesConfig =ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
local heroConfig=ConfigManager.GetConfig(ConfigName.HeroConfig)
--按钮类型
local bType={
Btn1=1,
Btn10=2
}
--type与lotterySetting表中的id对应
local btns={ [bType.Btn1]={name="btngroup/once",isInfo=Language[10644],type=RecruitType.TimeLimitSingle}, [bType.Btn10]={name="btngroup/ten",isInfo=Language[12182],type=RecruitType.TimeLimitTen}}
local tabs={"btngroup/activity","btngroup/reward"}
local secectTab=-1
local hero={[1]={name="Bg/hero1",id=10001,hero="x_xianshizaohuan_fx"},[2]={name="Bg/hero3",id=10041,hero="x_xianshizaohuan_ttjz"},[3]={name="Bg/hero2",id=10089,hero="x_xianshizaohuan_rd"}}
local curLv=0 --当前阶段id
function TimeLimitedCall:ctor(mainPanel, gameObject)
self.mainPanel = mainPanel
self.gameObject = gameObject
self:InitComponent(gameObject)
self:BindEvent()
end
function TimeLimitedCall:InitComponent(gameObject)
self.helpBtn = Util.GetGameObject(self.gameObject,"btngroup/help")
self.helpPosition=self.helpBtn:GetComponent("RectTransform").localPosition
self.activityBtn = Util.GetGameObject(self.gameObject,"btngroup/activity")
self.rewardBtn = Util.GetGameObject(self.gameObject,"btngroup/reward")
self.timeupdate=Util.GetGameObject(self.gameObject,"timeupdate"):GetComponent("Text") --剩余时间
self.upper=Util.GetGameObject(self.gameObject,"maxtimes"):GetComponent("Text") ---召唤上限
self.slider = Util.GetGameObject(self.gameObject, "nextlevel/Slider"):GetComponent("Slider")
self.sliderText=Util.GetGameObject(self.gameObject,"nextlevel/Text"):GetComponent("Text")
self.curtext = Util.GetGameObject(self.gameObject, "curvalue/Text"):GetComponent("Text")
self.frame = Util.GetGameObject(self.gameObject, "curvalue/frame"):GetComponent("Image")
self.nextReward = Util.GetGameObject(self.gameObject, "nextlevel/reward")
self.icon = Util.GetGameObject(self.frame.gameObject, "icon"):GetComponent("Image")
self.detail= Util.GetGameObject(self.gameObject, "detail")
self.reward= Util.GetGameObject(self.gameObject, "reward")
self.getBtn=Util.GetGameObject(self.gameObject,"nextlevel")
self.effect=Util.GetGameObject(self.gameObject,"juneng_chenggong")
self.hero1 = Util.GetGameObject(self.gameObject,"Bg/hero1")
self.hero2 = Util.GetGameObject(self.gameObject,"Bg/hero2")
self.hero3 = Util.GetGameObject(self.gameObject,"Bg/hero3")
self.recruitTimeUpdate = Util.GetGameObject(self.gameObject,"recruitTimesUpdate/Text1") :GetComponent("Text") --时间
self.recruitTimesUpdate = Util.GetGameObject(self.gameObject,"recruitTimesUpdate/Text") :GetComponent("Text") --剩余次数
end
function TimeLimitedCall:BindEvent()
Util.AddClick(self.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.TimeLimitedCall,self.helpPosition.x,self.helpPosition.y)
--UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.TimeLimitedCall,self.helpPosition.x,self.helpPosition.y)
end)
Util.AddClick(self.activityBtn, function()
secectTab=1
self:RefreshTabBtn()
ActivityDetail.new(self.detail,1)
end)
Util.AddClick(self.rewardBtn, function()
secectTab=2
self:RefreshTabBtn()
local fb = ConfigManager.GetConfigData(ConfigName.FakeBattle, 1001)
local testFightData = {
fightData = loadstring("return "..fb.FightData)(),
fightSeed = fb.TimeSeed,
fightType = 0,
maxRound = 20
}
UIManager.OpenPanel(UIName.BattlePanel, testFightData, BATTLE_TYPE.Test)
end)
Util.AddClick(self.hero1, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, 10001, 5)
end)
Util.AddClick(self.hero2, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, 10089, 5)
end)
Util.AddClick(self.hero3, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, 10041, 5)
end)
end
function TimeLimitedCall:OnShow(_sortingOrder)
sortingOrder = _sortingOrder
self.gameObject:SetActive(true)
local UpHero=RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.TIME_LIMITED_UP)
table.sort(UpHero,function(a,b) return a.Reward[1]<b.Reward[1] end)
for n,m in ipairs(hero) do
Util.GetGameObject(self.gameObject,m.name.."/hero"):GetComponent("Image").sprite=Util.LoadSprite(m.hero)
local configinfo= ConfigManager.GetConfigDataByKey(ConfigName.HeroConfig, "Id", UpHero[n].Reward[1])
Util.GetGameObject(self.gameObject,m.name.."/icon"):GetComponent("Image").sprite=Util.LoadSprite(GetJobSpriteStrByJobNum(configinfo.PropertyName))
Util.GetGameObject(self.gameObject,m.name.."/name"):GetComponent("Text").text=configinfo.ReadingName
--SetHeroStars(Util.GetGameObject(self.gameObject,m.name.."/starlayout"),5)
end
secectTab=-1
self:RefreshTabBtn()
self:RefreshGetHeroTimes()
self:TimeCountDown()
self:RefreshNextLevelReward()
end
function TimeLimitedCall:RefreshTabBtn()
for n, m in pairs(tabs) do
if n~=secectTab then
Util.GetGameObject(self.gameObject,tabs[n].."/select").gameObject:SetActive(false)
else
Util.GetGameObject(self.gameObject,tabs[n].."/select").gameObject:SetActive(true)
end
end
end
function TimeLimitedCall:RefreshNextLevelReward()
local curActivityId=0
local curLvstate = 0
local curTimes = 0
curActivityId=ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.FindFairy)
local data1= ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",curActivityId) --通过活动id获取阶段任务
local rewarditem
for n,m in ipairs(data1) do
curTimes,curLvstate = self:GetMissionStateById(m.Id,curActivityId)
if(curTimes>=m.Values[1][1]) then
if curLvstate==0 then
curLvstate=0
curLv=m.Id
rewarditem=m
break
end
else
curLvstate=2
curLv=m.Id
rewarditem=m
break
end
end
local o= SubUIManager.Open(SubUIConfig.ItemView,self.nextReward.transform)
o:OnOpen(false, {rewarditem.Reward[1][1],rewarditem.Reward[1][2]}, 0.73, false)
o.gameObject:SetActive(true)
Util.GetGameObject(o.gameObject,"item/frame"):GetComponent("Button").enabled=false
if (curLvstate==0) then
self.slider.gameObject:SetActive(false)
local vec=self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D
vec.y=22.4
self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D=vec
self.sliderText.text=Language[12183]
self.sliderText.fontSize=26
Util.AddOnceClick(self.getBtn,function()
NetManager.GetActivityRewardRequest(curLv, curActivityId,
function(respond)
UIManager.OpenPanel(UIName.RewardItemPopup, respond, 1)
self:RefreshNextLevelReward()
self:RefreshGetHeroTimes()
end)
end)
self.effect.gameObject:SetActive(true)
else
self.slider.gameObject:SetActive(true)
Util.GetGameObject(self.slider.gameObject,"Text"):GetComponent("Text").text=curTimes.."/"..rewarditem.Values[1][1]
local vec=self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D
vec.y=22.4
self.sliderText.transform:GetComponent("RectTransform").anchoredPosition3D=vec
self.sliderText.text=Language[12184]..curTimes.."/"..rewarditem.Values[1][1]
self.sliderText.fontSize=26
self.slider.value=curTimes/rewarditem.Values[1][1]
self.effect.gameObject:SetActive(false)
Util.AddOnceClick(self.getBtn,function()
RewardPreview.new(self.reward)
end)
end
local reMaintimes = ActivityGiftManager.GetActivityValueInfo(curActivityId)
LogBlue(ConfigManager.GetConfigData(ConfigName.LotterySpecialConfig,18).Count)
reMaintimes = ConfigManager.GetConfigData(ConfigName.LotterySpecialConfig,18).Count - reMaintimes
LogBlue("reMaintimes:"..reMaintimes)
self.recruitTimesUpdate.text = string.format("召唤<color=#F27D0F>%s</color>次必得UP神将",reMaintimes)
local info= ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.FindFairy)
LogBlue(info.endTime)
LogBlue(info.startTime)
info = info.endTime - info.startTime
info = self:TimeToDHMS(info)
self.recruitTimeUpdate.text = string.format("活动剩余时间:"..info)
end
--- 将一段时间转换为天时分秒
function TimeLimitedCall:TimeToDHMS(second)
local day = math.floor(second / (24 * 3600))
local minute = math.floor(second / 60) % 60
local sec = second % 60
local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600)
if day <= 0 and hour <= 0 then
return string.format("%s分%s秒",minute, sec)
else
return string.format("%s天%s小时",day, hour)
end
end
function TimeLimitedCall:GetMissionStateById(num,activityId)
LogBlue("activityId:"..activityId.. ",num:"..num)
local mission= ActivityGiftManager.GetActivityInfo(activityId,num) --从后端获取到的阶段数据
LogBlue(mission.progress.." "..mission.state)
return mission.progress,mission.state
end
--刷新剩余次数
function TimeLimitedCall:RefreshGetHeroTimes()
local freeTimesId=lotterySetting[RecruitType.TimeLimitSingle].FreeTimes
local maxtimesId=lotterySetting[RecruitType.TimeLimitSingle].MaxTimes --lotterySetting表中的MaxTimes对应privilegeConfig表中的id
local curTimes=PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)
self.curtext.text=curTimes
self.upper.text= Language[12185]..curTimes.."/"..privilegeConfig[maxtimesId].Condition[1][2]--特权上限
local freeTime= 0
if freeTimesId>0 then
freeTime= PrivilegeManager.GetPrivilegeRemainValue(freeTimesId)
RecruitManager.freeUseTimeList[freeTimesId]=freeTime
end
--按钮赋值
for n, m in ipairs(btns) do
local btn=Util.GetGameObject(self.gameObject,m.name)
local redPot=Util.GetGameObject(btn.gameObject,"redPoint")
local info=Util.GetGameObject(btn.gameObject,"layout/Text"):GetComponent("Text")
local icon=Util.GetGameObject(btn.gameObject,"layout/icon"):GetComponent("Image")
local num=Util.GetGameObject(btn.gameObject,"layout/num"):GetComponent("Text")
--存在免费次数 并且 免费>=1 并且是1按钮
local isFree=freeTime and freeTime >= 1 and n==bType.Btn1
redPot.gameObject:SetActive(isFree)
icon.gameObject:SetActive(not isFree)
num.gameObject:SetActive(not isFree)
self.timeupdate.gameObject:SetActive(not isFree)
local itemId=0
local itemNum=0
local d
if(isFree) then
info.text=Language[11759]
else
d=RecruitManager.GetExpendData(m.type)
itemId=d[1]
itemNum=d[2]
icon.sprite=Util.LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
info.text=m.isInfo
num.text= tostring(itemNum)
end
Util.AddOnceClick(btn,function()
if not isFree then
if BagManager.GetItemCountById(itemId)<d[2] then
PopupTipPanel.ShowTip(itemConfig[itemId].Name..Language[10492])
return
end
end
if n==bType.Btn1 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)+1>privilegeConfig[maxtimesId].Condition[1][2] then
PopupTipPanel.ShowTip(Language[11760])
return
end
RecruitManager.RecruitRequest(m.type, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(maxtimesId,1)--记录抽卡次数
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero[1],m.type,bType.Btn1)
CheckRedPointStatus(RedPointType.TimeLimited)
end,freeTimesId)
elseif n==bType.Btn10 then
if PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)+10>privilegeConfig[maxtimesId].Condition[1][2] then
PopupTipPanel.ShowTip(Language[11760])
return
end
RecruitManager.RecruitRequest(m.type, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(maxtimesId,10)--记录抽卡次数
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero, m.type,bType.Btn10)
CheckRedPointStatus(RedPointType.TimeLimited)
end,freeTimesId)
end
end)
end
end
--刷新时间
function TimeLimitedCall:TimeCountDown()
if self.timer then
self.timer:Stop()
self.timer = nil
end
local timeDown=CalculateSecondsNowTo_N_OClock(5)--ActivityGiftManager.GetTaskRemainTime(ActivityTypeDef.FindFairy)
self.timeupdate.text = TimeToHMS(timeDown).."后刷新"
self.timer = Timer.New(function()
if timeDown < 1 then
self.timer:Stop()
self.timer = nil
return
end
timeDown = timeDown - 1
self.timeupdate.text = TimeToHMS(timeDown).."后刷新"
end, 1, -1, true)
self.timer:Start()
end
function TimeLimitedCall:OnHide()
self.gameObject:SetActive(false)
if self.timer then
self.timer:Stop()
self.timer = nil
end
end
function TimeLimitedCall:OnDestroy()
ActivityDetail.OnDestroy()
RewardPreview.OnDestroy()
end
return TimeLimitedCall