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

385 lines
16 KiB
Lua

local TimeLimitedCall = {}
local sortingOrder = 0
local globalActive = ConfigManager.GetConfig(ConfigName.GlobalActivity)
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)
function TimeLimitedCall:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = TimeLimitedCall })
return b
end
--初始化组件(用于子类重写)
function TimeLimitedCall:InitComponent()
self.spLoader = SpriteLoader.New()
self.helpBtn = Util.GetGameObject(self.gameObject, "help")
self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition
self.btnActivity = Util.GetGameObject(self.gameObject, "btngroup/btnActivity")
self.btnRewardBtn = Util.GetGameObject(self.gameObject, "btngroup/btnRewardBtn")
self.btnRewardBtn:SetActive(false)
self.btns = {}
self.bgs = {}
for i = 1, 2 do
self.bgs[i] = {}
self.bgs[i].bg = Util.GetGameObject(self.gameObject, "Bg" .. i)
self.bgs[i].title = Util.GetGameObject(self.bgs[i].bg, "Image (3)"):GetComponent("Image")
self.bgs[i].heros = {}
for j = 1, 3 do
self.bgs[i].heros[j] = {}
self.bgs[i].heros[j].hero = Util.GetGameObject(self.bgs[i].bg, "hero" .. j)
self.bgs[i].heros[j].heroIma = Util.GetGameObject(self.bgs[i].heros[j].hero, "hero"):GetComponent("Image")
self.bgs[i].heros[j].heroIcon = Util.GetGameObject(self.bgs[i].heros[j].hero, "icon"):GetComponent("Image")
self.bgs[i].heros[j].heroName = Util.GetGameObject(self.bgs[i].heros[j].hero, "name"):GetComponent("Text")
end
self.btns[i] = {}
self.btns[i].btn = Util.GetGameObject(self.gameObject, "btngroup/btn" .. i)
self.btns[i].red = Util.GetGameObject(self.btns[i].btn.gameObject, "redPoint")
self.btns[i].info = Util.GetGameObject(self.btns[i].btn.gameObject, "layout/Text"):GetComponent("Text")
self.btns[i].icon = Util.GetGameObject(self.btns[i].btn.gameObject, "layout/icon"):GetComponent("Image")
self.btns[i].num = Util.GetGameObject(self.btns[i].btn.gameObject, "layout/num"):GetComponent("Text")
end
self.timeupdate = Util.GetGameObject(self.gameObject, "timeupdate"):GetComponent("Text") --免费次数剩余刷新时间
self.upper = Util.GetGameObject(self.gameObject, "maxtimes/times"):GetComponent("Text") ---召唤上限
self.recruitTimeUpdate = Util.GetGameObject(self.gameObject, "recruitTimesUpdate/Text1"):GetComponent("Text") --活动剩余时间
self.recruitTimesUpdate = Util.GetGameObject(self.gameObject, "recruitTimesUpdate/Text"):GetComponent("Text") --保底剩余次数
self.getBtn = Util.GetGameObject(self.gameObject, "nextlevel")
self.slider = Util.GetGameObject(self.getBtn, "Slider"):GetComponent("Slider")
self.sliderText = Util.GetGameObject(self.getBtn, "Text"):GetComponent("Text")
self.sliderText2 = Util.GetGameObject(self.slider.gameObject, "Text"):GetComponent("Text")
self.nextReward = Util.GetGameObject(self.getBtn, "reward")
self.effect = Util.GetGameObject(self.nextReward, "juneng_chenggong")
end
--绑定事件(用于子类重写)
function TimeLimitedCall:BindEvent()
Util.AddOnceClick(self.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup, self.actConfig.HelpId, self.helpPosition.x, self.helpPosition.y)
end)
Util.AddOnceClick(self.btnActivity, function()
UIManager.OpenPanel(UIName.GeneralBigPopup, GENERAL_POPUP_TYPE.RecrutDetail, self.actConfig.HelpId, self.actType,
PRE_REWARD_POOL_TYPE.TIME_LIMITED_UP, PRE_REWARD_POOL_TYPE.TIME_LIMITED)
end)
end
--添加事件监听(用于子类重写)
function TimeLimitedCall:AddListener()
end
--移除事件监听(用于子类重写)
function TimeLimitedCall:RemoveListener()
end
--界面打开时调用(用于子类重写)
function TimeLimitedCall:OnOpen(_activityConfig, _index, parent)
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
end
function TimeLimitedCall:OnSortingOrderChange()
end
-- 打开,重新打开时回调
function TimeLimitedCall:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
sortingOrder = _sortingOrder
self.actId = self.actConfig.ActId
self.actType = self.actConfig.ActiveType > 0 and self.actConfig.ActiveType or self.actConfig.FunType
if self.actConfig.IfBack == 1 then
if self.actConfig.ActiveType > 0 then
local id = ActivityGiftManager.IsActivityTypeOpen(self.actConfig.ActiveType)
if id and id > 0 then
self.actId = id
local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups, "PageType",
self.actConfig.PageType, "ActiveType", self.actConfig.ActiveType, "ActId", id)
if config then
self.actConfig = config
end
end
end
end
for k, v in ipairs(self.bgs) do
v.bg.gameObject:SetActive(false)
end
local array = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySetting, "ActivityId", self.actId)
self.singleRecruit = array[1]
self.tenRecruit = array[2]
self.freeTimesId = self.singleRecruit.FreeTimes
self.maxtimesId = self.singleRecruit.MaxTimes
self:RefreshHeroData()
self:RefreshGetHeroTimes()
self:TimeCountDown()
self:RefreshNextLevelReward()
end
function TimeLimitedCall:RefreshHeroData()
for k, v in ipairs(self.bgs) do
v.bg.gameObject:SetActive(false)
end
self.bgs[self.actConfig.UIName[2]].bg.gameObject:SetActive(true)
self.bgs[self.actConfig.UIName[2]].title.sprite = self.spLoader:LoadSprite(self.actConfig.Icon[6])
self.bgs[self.actConfig.UIName[2]].title:SetNativeSize()
self.UpHero = RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.TIME_LIMITED_UP)
table.sort(self.UpHero, function(a, b)
return a.Id < b.Id
end)
for n, m in ipairs(self.UpHero) do
self.bgs[self.actConfig.UIName[2]].heros[n].heroIma.sprite = self.spLoader:LoadSprite(self.actConfig.Icon[n + 2])
local configinfo = ConfigManager.GetConfigDataByKey(ConfigName.HeroConfig, "Id", m.Reward[1])
--LogGreen("configinfo.PropertyName:"..configinfo.PropertyName)
self.bgs[self.actConfig.UIName[2]].heros[n].heroIcon.sprite = self.spLoader:LoadSprite(GetJobSpriteStrByJobNum(
configinfo.PropertyName))
self.bgs[self.actConfig.UIName[2]].heros[n].heroName.text = GetLanguageStrById(configinfo.ReadingName)
Util.AddOnceClick(self.bgs[self.actConfig.UIName[2]].heros[n].hero, function()
UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, m.Reward[1], 5)
end)
end
end
--刷新剩余次数
function TimeLimitedCall:RefreshGetHeroTimes()
local curTimes = PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId)
self.upper.text = Language[10596] .. curTimes .. "/" .. privilegeConfig[self.maxtimesId].Condition[1][2] --特权上限
self.timeupdate.gameObject:SetActive(true)
local freeTime = 0
if self.freeTimesId and self.freeTimesId > 0 then
freeTime = PrivilegeManager.GetPrivilegeRemainValue(self.freeTimesId)
RecruitManager.freeUseTimeList[self.freeTimesId] = freeTime
end
--按钮赋值
for n, m in ipairs(self.btns) do
--存在免费次数 并且 免费>=1 并且是1按钮
local isFree = freeTime >= 1 and n == 1
m.red.gameObject:SetActive(isFree)
m.icon.gameObject:SetActive(not isFree)
m.num.gameObject:SetActive(not isFree)
local itemId = 0
local itemNum = 0
local type = 0
if n == 1 then
type = self.singleRecruit.Id
m.info.text = Language[10577]
else
type = self.tenRecruit.Id
m.info.text = Language[10578]
end
local d = {}
if (isFree) then
self.timeupdate.gameObject:SetActive(false)
m.info.text = Language[10583]
else
local d = RecruitManager.GetExpendData(type)
itemId = d[1]
itemNum = d[2]
m.icon.sprite = self.spLoader:LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
m.num.text = tostring(itemNum)
end
Util.AddOnceClick(m.btn, function()
if not isFree then
if BagManager.GetItemCountById(itemId) < itemNum then
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name) .. Language[10584])
return
end
end
local state = PlayerPrefs.GetInt(PlayerManager.uid .. "GeneralPopup_RecruitConfirm" ..
RecruitType.TimeLimitTen)
local recrutId = n == 1 and self.singleRecruit.Id or self.tenRecruit.Id
local recrutNum = n == 1 and 1 or 10
if state == 0 and itemId == 16 and not isFree then
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitConfirm, recrutId, function()
self:Recruit(recrutNum, recrutId, n)
end)
else
self:Recruit(recrutNum, recrutId, n)
end
end)
end
local reMaintimes = ActivityGiftManager.GetActivityValueInfo(self.actId)
local totalTimes = ConfigManager.GetConfigDataByKey(ConfigName.LotterySpecialConfig, "Type",
self.singleRecruit.MergePool).Count
reMaintimes = totalTimes - reMaintimes
if reMaintimes == 0 then
reMaintimes = totalTimes
end
self.recruitTimesUpdate.text = string.format(Language[10611], reMaintimes)
end
function TimeLimitedCall:Recruit(recrutType, recrutId, bType)
if PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId) + recrutType > privilegeConfig[self.maxtimesId].Condition[1][2] then
PopupTipPanel.ShowTip(Language[10587])
return
end
RecruitManager.RecruitRequest(recrutId, function(msg)
PrivilegeManager.RefreshPrivilegeUsedTimes(self.maxtimesId, recrutType) --记录抽卡次数
if bType == 1 then
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero[1], recrutId, bType,
{ RecruitType.TimeLimitSingle, RecruitType.TimeLimitTen })
else
UIManager.OpenPanel(UIName.SingleRecruitPanel, msg.drop.Hero, recrutId, bType,
{ RecruitType.TimeLimitSingle, RecruitType.TimeLimitTen })
end
CheckRedPointStatus(RedPointType.TimeLimited)
end, self.freeTimesId)
end
--刷新时间
function TimeLimitedCall:TimeCountDown()
if self.timer then
self.timer:Stop()
self.timer = nil
end
local timeDown = CalculateSecondsNowTo_N_OClock(0) --ActivityGiftManager.GetTaskRemainTime(ActivityTypeDef.FindFairy)
local endTime = ActivityGiftManager.GetTaskEndTime(self.actType) - PlayerManager.serverTime
self.recruitTimeUpdate.text = string.format(Language[10495] .. self:TimeToDHMS(endTime))
self.timeupdate.text = TimeToHMS(timeDown) .. Language[10585]
self.timer = Timer.New(function()
if timeDown < 1 then
self:RefreshGetHeroTimes()
return
else
self.timeupdate.text = TimeToHMS(timeDown) .. Language[10585]
end
if endTime < 1 then
self.timer:Stop()
self.timer = nil
self:OnShow(sortingOrder)
return
else
self.recruitTimeUpdate.text = string.format(Language[10495] .. self:TimeToDHMS(endTime))
end
endTime = endTime - 1
timeDown = timeDown - 1
end, 1, -1, true)
self.timer:Start()
end
function TimeLimitedCall:RefreshNextLevelReward()
-- 0 无法领取 1已领取 2可领取 -1 全部领取完
local curState = 0
local data1 = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig, "ActivityId", self.actId) --通过活动id获取阶段任务
local rewardItem = nil
local mission = nil
for n, m in ipairs(data1) do
mission = ActivityGiftManager.GetActivityInfo(self.actId, m.Id)
if (mission.progress >= m.Values[1][1]) then
if mission.state == 0 then
rewardItem = m
curState = 2
break
end
else
curState = 0
rewardItem = m
break
end
end
--所有任务都已完成
if not rewardItem then
curState = -1
rewardItem = data1[#data1]
end
OperatingManager.TimeLimitedTimes = mission.progress
if not self.itemView then
self.itemView = SubUIManager.Open(SubUIConfig.ItemView, self.nextReward.transform)
end
self.itemView:OnOpen(false, { rewardItem.Reward[1][1], rewardItem.Reward[1][2] }, 0.73, false)
self.itemView.gameObject:SetActive(true)
Util.GetGameObject(self.itemView.gameObject, "item/frame"):GetComponent("Button").enabled = false
if (curState == 2) then
local temp = mission.progress <= rewardItem.Values[1][1] and mission.progress or rewardItem.Values[1][1]
self.sliderText2.text = temp .. "/" .. rewardItem.Values[1][1]
self.slider.value = temp / 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[10609]
self.sliderText.fontSize = 26
Util.AddOnceClick(self.getBtn, function()
NetManager.GetActivityRewardRequest(mission.missionId, self.actId,
function(respond)
UIManager.OpenPanel(UIName.RewardItemPopup, respond, 1)
self:RefreshNextLevelReward()
self:RefreshGetHeroTimes()
end)
end)
self.effect.gameObject:SetActive(true)
elseif (curState == -1) then
self.slider.value = 1
Util.GetGameObject(self.slider.gameObject, "Text"):GetComponent("Text").text = "300/300"
self.sliderText.text = Language[10612]
Util.AddOnceClick(self.getBtn, function()
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecrutReward, self.actType, self.actId)
end)
else
self.slider.gameObject:SetActive(true)
Util.GetGameObject(self.slider.gameObject, "Text"):GetComponent("Text").text = mission.progress ..
"/" .. 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[10613] .. mission.progress .. "/" .. rewardItem.Values[1][1]
self.sliderText.fontSize = 26
self.slider.value = mission.progress / rewardItem.Values[1][1]
self.effect.gameObject:SetActive(false)
Util.AddOnceClick(self.getBtn, function()
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecrutReward, self.actType, self.actId)
end)
end
end
--- 将一段时间转换为天时分秒
function TimeLimitedCall:TimeToDHMS(second)
local day = math.floor(second / (24 * 3600))
local minute = math.floor(second / 60) % 60
local sec = math.floor(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(Language[10571], minute, sec)
else
return string.format(Language[10572], day, hour)
end
end
--界面关闭时调用(用于子类重写)
function TimeLimitedCall:OnClose()
self.gameObject:SetActive(false)
if self.timer then
self.timer:Stop()
self.timer = nil
end
end
--界面销毁时调用(用于子类重写)
function TimeLimitedCall:OnDestroy()
self.spLoader:Destroy()
self.btns = {}
SubUIManager.Close(self.itemView)
self.itemView = nil
end
return TimeLimitedCall