375 lines
15 KiB
Lua
375 lines
15 KiB
Lua
local LingShouBaoGe = {}
|
|
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
|
|
local privilegeConfig = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local artConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
|
|
local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
|
|
local SpiritAnimalConfig = ConfigManager.GetConfig(ConfigName.SpiritAnimal)
|
|
local gloAcivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
|
|
|
|
local sortingOrder = 0
|
|
local parent
|
|
|
|
--按钮类型
|
|
local bType = {
|
|
Btn1 = 1,
|
|
Btn10 = 2
|
|
}
|
|
--type与lotterySetting表中的id对应
|
|
local btns = { [bType.Btn1] = { name = "Btn1", isInfo = Language[10478] }, [bType.Btn10] = { name = "Btn10", isInfo = Language[10479] } }
|
|
|
|
function LingShouBaoGe:New(gameObject)
|
|
local b = {}
|
|
b.gameObject = gameObject
|
|
b.transform = gameObject.transform
|
|
setmetatable(b, { __index = LingShouBaoGe })
|
|
return b
|
|
end
|
|
|
|
function LingShouBaoGe:InitComponent()
|
|
self.spLoader = SpriteLoader.New()
|
|
self.helpBtn = Util.GetGameObject(self.gameObject, "help")
|
|
self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition
|
|
|
|
self.preview = Util.GetGameObject(self.gameObject, "rightUp/preview")
|
|
self.change = Util.GetGameObject(self.gameObject, "rightUp/change")
|
|
self.detailBtn = Util.GetGameObject(self.gameObject, "rightUp/detailBtn")
|
|
self.lsth = Util.GetGameObject(self.gameObject, "rightUp/lsth")
|
|
|
|
self.upper = Util.GetGameObject(self.gameObject, "bottom/Image/times"):GetComponent("Text") ---召唤上限
|
|
self.tip1 = Util.GetGameObject(self.gameObject, "bottom/Tip1"):GetComponent("Text") ---刷新时间
|
|
self.tip2 = Util.GetGameObject(self.gameObject, "bottom/Tip2"):GetComponent("Text") ---必出
|
|
self.btnGroup = Util.GetGameObject(self.gameObject, "bottom/btngroup")
|
|
self.leftTime = Util.GetGameObject(self.gameObject, "bottom/lefttime"):GetComponent("Text")
|
|
|
|
self.grid = Util.GetGameObject(self.gameObject, "aniRoot")
|
|
self.title = Util.GetGameObject(self.gameObject, "Bg/title"):GetComponent("Image")
|
|
|
|
--mid
|
|
self.progressValue = Util.GetGameObject(self.gameObject, "mid/progress/value"):GetComponent("Image") --fillAmount
|
|
self.reward = Util.GetGameObject(self.gameObject, "mid/reward")
|
|
self.value = Util.GetGameObject(self.gameObject, "mid/value")
|
|
end
|
|
|
|
function LingShouBaoGe:BindEvent()
|
|
Util.AddOnceClick(self.helpBtn, function()
|
|
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.LingShouBaoGe, self.helpPosition.x, self.helpPosition.y)
|
|
end)
|
|
Util.AddOnceClick(self.detailBtn, function()
|
|
UIManager.OpenPanel(UIName.GeneralBigPopup, GENERAL_POPUP_TYPE.RecrutDetail, self.actConfig.HelpId, self.actType,
|
|
PRE_REWARD_POOL_TYPE.LING_SHOU_UP, PRE_REWARD_POOL_TYPE.LING_SHOU)
|
|
end)
|
|
Util.AddOnceClick(self.change, function()
|
|
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.LingShouBaoGe, self.actData, self.showData.monsterId,
|
|
function()
|
|
self:Refresh()
|
|
end)
|
|
end)
|
|
Util.AddOnceClick(self.lsth, function()
|
|
JumpManager.GoJump(40011)
|
|
end)
|
|
Util.AddOnceClick(self.preview, function()
|
|
local battleId = tonumber(self.showData.battleId)
|
|
local fdata, fseed = BattleManager.GetFakeBattleData(battleId)
|
|
local testFightData = {
|
|
fightData = fdata,
|
|
fightSeed = fseed,
|
|
fightType = 0,
|
|
maxRound = 20
|
|
}
|
|
UIManager.OpenPanel(UIName.BattlePanel, testFightData, BATTLE_TYPE.Test, function()
|
|
-- Timer.New(function ()
|
|
-- self:Refresh()
|
|
-- end,3):Start()
|
|
end)
|
|
end)
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function LingShouBaoGe:OnOpen(_activityConfig, _index, parent)
|
|
SoundManager.PlaySound(SoundConfig.UI_Siyuanzhen)
|
|
self.actConfig = _activityConfig
|
|
self.pageIndex = _index
|
|
self.parent = parent
|
|
end
|
|
|
|
function LingShouBaoGe:OnSortingOrderChange()
|
|
end
|
|
|
|
function LingShouBaoGe: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
|
|
|
|
self:Refresh()
|
|
end
|
|
|
|
function LingShouBaoGe:Refresh()
|
|
self.actData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.LingShouBaoGe)
|
|
self.curLingShowId = self.actData.choiceRewardId
|
|
self.activityId = self.actData.activityId
|
|
self.LSrewardData = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig, "ActivityId",
|
|
self.activityId)
|
|
local array = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySetting, "ActivityId", self.activityId)
|
|
self.singleRecruit = array[1]
|
|
self.tenRecruit = array[2]
|
|
|
|
CheckRedPointStatus(RedPointType.LingShouBaoGe)
|
|
self:refreshBtnShow() --刷新按钮显示
|
|
self:TimeCountDown() --时间
|
|
self:SetData() --加载界面数据立绘+进度条
|
|
end
|
|
|
|
local PositionList = {
|
|
[20007] = { pos = 176, title = "l_lingshou_fenghuang_zh" },
|
|
[20006] = { pos = 70, title = "l_lingshou_baize_zh" },
|
|
[20005] = { pos = 70, title = "l_lingshou_pixiu_zh" },
|
|
[20008] = { pos = 70, title = "l_lingshou_jinwu_zh" },
|
|
[20009] = { pos = 70, title = "l_lingshou_jukun_zh" },
|
|
}
|
|
function LingShouBaoGe:SetData()
|
|
self.rewardData = {}
|
|
self.showData = {}
|
|
self.rewardData, self.showData, self.curScore = DynamicActivityManager.LingShouBuildData()
|
|
self.title.sprite = self.spLoader:LoadSprite(PositionList[self.showData.monsterId].title)
|
|
if self.Live then
|
|
poolManager:UnLoadLive(self.bgName, self.Live)
|
|
end
|
|
--设置立绘
|
|
self.bgName = artConfig[SpiritAnimalConfig[self.showData.monsterId].Live].Name
|
|
local pos = SpiritAnimalConfig[self.showData.monsterId].Position
|
|
local scale = SpiritAnimalConfig[self.showData.monsterId].Scale
|
|
self.Live = poolManager:LoadLive(self.bgName, self.grid.transform, Vector3.one * scale * 0.8,
|
|
Vector2.New(pos[1], pos[2] + PositionList[self.showData.monsterId].pos))
|
|
local RoleLiveGOGraphic = self.Live:GetComponent("SkeletonGraphic")
|
|
RoleLiveGOGraphic.AnimationState:SetAnimation(0, "idle", true)
|
|
|
|
local leftTime = lotterySetting[self.singleRecruit.Id].DiamondBoxContain[1][2] - self.actData.value
|
|
self.tip2.text = Language[10480] ..
|
|
"<color=green>" .. leftTime .. Language[10481] ..
|
|
GetLanguageStrById(SpiritAnimalConfig[self.showData.monsterId].Name)
|
|
|
|
--设置奖励
|
|
self.progressValue.fillAmount = self.curScore / self.LSrewardData[#self.LSrewardData].Values[1][1]
|
|
Util.GetGameObject(self.value, "num"):GetComponent("Text").text = self.curScore
|
|
Util.GetGameObject(self.value, "tips"):GetComponent("Text").text = Language[10482]
|
|
|
|
for i = 1, self.reward.transform.childCount do
|
|
local item = self.reward.transform:GetChild(i - 1)
|
|
Util.GetGameObject(item, "num/Text"):GetComponent("Text").text = self.LSrewardData[i].Reward[1][2]
|
|
Util.GetGameObject(item, "Text"):GetComponent("Text").text = self.LSrewardData[i].Values[1][1]
|
|
Util.GetGameObject(item, "icon"):GetComponent("Image").sprite = self.spLoader:LoadSprite(artConfig
|
|
[SpiritAnimalConfig[self.showData.monsterId].Icon].Name)
|
|
Util.GetGameObject(item, "red"):SetActive(self.rewardData[i].state == 1)
|
|
local btn = Util.GetGameObject(item, "icon")
|
|
Util.AddOnceClick(btn, function()
|
|
if self.rewardData[i].state == 1 then
|
|
NetManager.GetActivityRewardRequest(self.rewardData[i].missionId, self.activityId, function(drop)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1, function()
|
|
self:Refresh()
|
|
end)
|
|
end)
|
|
else
|
|
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, self.showData.monsterId, nil)
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
local maxMoneyId
|
|
function LingShouBaoGe:refreshBtnShow()
|
|
--下方的数量显示
|
|
local maxtimesId = lotterySetting[self.singleRecruit.Id].MoneyTimes
|
|
maxMoneyId = lotterySetting[self.singleRecruit.Id].MoneyTimes
|
|
-- local curTimes=PrivilegeManager.GetPrivilegeUsedTimes(maxtimesId)
|
|
local curTimes = PrivilegeManager.GetPrivilegeRemainValue(maxtimesId)
|
|
self.upper.text = "今日妖晶召唤上限" .. curTimes .. "/" .. privilegeConfig[maxtimesId].Condition[1][2] --召唤上限
|
|
--if curTimes==0 then
|
|
maxtimesId = lotterySetting[self.singleRecruit.Id].MaxTimes
|
|
--end
|
|
|
|
--是否是免费抽
|
|
local freeTimesId = lotterySetting[self.singleRecruit.Id].FreeTimes
|
|
if freeTimesId > 0 then
|
|
self.freeTime = PrivilegeManager.GetPrivilegeRemainValue(freeTimesId)
|
|
RecruitManager.freeUseTimeList[freeTimesId] = self.freeTime
|
|
end
|
|
--按钮赋值
|
|
for n, m in ipairs(btns) do
|
|
local btn = Util.GetGameObject(self.btnGroup, m.name)
|
|
local redPot = Util.GetGameObject(btn.gameObject, "RedPoint")
|
|
local info = Util.GetGameObject(btn.gameObject, "Content/Info"):GetComponent("Text")
|
|
local icon = Util.GetGameObject(btn.gameObject, "Content/Icon"):GetComponent("Image")
|
|
local num = Util.GetGameObject(btn.gameObject, "Content/Num"):GetComponent("Text")
|
|
--存在免费次数 并且 免费>=1 并且是1按钮
|
|
local isFree = self.freeTime and self.freeTime >= 1 and n == bType.Btn1
|
|
redPot.gameObject:SetActive(isFree)
|
|
icon.gameObject:SetActive(not isFree)
|
|
num.gameObject:SetActive(not isFree)
|
|
self.tip1.gameObject:SetActive(self.freeTime == 0)
|
|
|
|
local itemId = 0
|
|
local itemNum = 0
|
|
local type = 0
|
|
|
|
type = n == bType.Btn1 and self.singleRecruit.Id or self.tenRecruit.Id
|
|
local str = n == bType.Btn1 and self.singleRecruit.CostItem or self.tenRecruit.CostItem
|
|
--local d = RecruitManager.GetExpendData(type)
|
|
local d = RecruitManager.GetExpendDataByCostItem(str, n, curTimes)
|
|
local payId = 0
|
|
if isFree then
|
|
info.text = " " .. Language[10493]
|
|
else
|
|
itemId = d[1]
|
|
itemNum = d[2]
|
|
icon.sprite = self.spLoader:LoadSprite(artResourcesConfig[itemConfig[itemId].ResourceID].Name)
|
|
info.text = m.isInfo
|
|
num.text = itemNum
|
|
if itemId == 16 then
|
|
payId = maxMoneyId
|
|
else
|
|
payId = maxtimesId
|
|
end
|
|
end
|
|
Util.AddOnceClick(btn, function()
|
|
local state = PlayerPrefs.GetInt(PlayerManager.uid .. "GeneralPopup_RecruitConfirm" .. RecruitType.BaoGeTen)
|
|
if n == bType.Btn1 then
|
|
if isFree then
|
|
self:Recruit(type, payId, 0, 0, state, freeTimesId, { RecruitType.BaoGeSingle, RecruitType.BaoGeTen })
|
|
else
|
|
self:Recruit(type, payId, itemId, itemNum, state, freeTimesId,
|
|
{ RecruitType.BaoGeSingle, RecruitType.BaoGeTen })
|
|
end
|
|
elseif n == bType.Btn10 then
|
|
self:Recruit(type, payId, itemId, itemNum, state, freeTimesId,
|
|
{ RecruitType.BaoGeTen, RecruitType.BaoGeTen })
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
function LingShouBaoGe:Recruit(id, RecruitMaxtimesId, itemId, itemNum, state, freeTimesId, recruitType)
|
|
local num = id % 2 == 0 and 1 or 10
|
|
-- --是否超过每日最大上限
|
|
-- if PrivilegeManager.GetPrivilegeRemainValue(RecruitMaxtimesId) < num then
|
|
-- PopupTipPanel.ShowTip(Language[10485])
|
|
-- return
|
|
-- end
|
|
if itemId ~= 0 then
|
|
if BagManager.GetItemCountById(itemId) < itemNum then
|
|
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name) .. Language[10486])
|
|
return
|
|
end
|
|
end
|
|
if itemId == 16 and state == 0 then
|
|
UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.RecruitConfirm, id,
|
|
function()
|
|
RecruitManager.RecruitRequest(id, function(msg)
|
|
PrivilegeManager.RefreshPrivilegeUsedTimes(maxMoneyId, num)
|
|
UIManager.OpenPanel(UIName.PokemonSingleResultPanel, id, msg.drop, self.activityId, recruitType,
|
|
function()
|
|
self:Refresh()
|
|
end)
|
|
end, freeTimesId, itemId, itemNum)
|
|
end, itemNum)
|
|
else
|
|
RecruitManager.RecruitRequest(id, function(msg)
|
|
PrivilegeManager.RefreshPrivilegeUsedTimes(RecruitMaxtimesId, num)
|
|
UIManager.OpenPanel(UIName.PokemonSingleResultPanel, id, msg.drop, self.activityId, recruitType, function()
|
|
self:Refresh()
|
|
end)
|
|
end, freeTimesId, itemId, itemNum)
|
|
end
|
|
end
|
|
|
|
--- 将一段时间转换为天时分秒
|
|
function LingShouBaoGe: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[10472], minute, sec)
|
|
else
|
|
return string.format(Language[10473], day, hour)
|
|
end
|
|
end
|
|
|
|
--刷新时间
|
|
function LingShouBaoGe:TimeCountDown()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
|
|
local timeDown = CalculateSecondsNowTo_N_OClock(0)
|
|
self.tip1.text = TimeToHMS(timeDown) .. Language[10488]
|
|
local timeDown2 = self.actData.endTime - GetTimeStamp()
|
|
self.leftTime.text = "周一零点重置宝阁值"
|
|
|
|
self.tip1.gameObject:SetActive((timeDown < timeDown2) and (self.freeTime == 0))
|
|
|
|
self.timer = Timer.New(function()
|
|
if timeDown < 1 then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
self:Refresh()
|
|
return
|
|
end
|
|
timeDown = timeDown - 1
|
|
self.tip1.text = TimeToHMS(timeDown) .. Language[10488]
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function LingShouBaoGe:OnClose()
|
|
self.gameObject:SetActive(false)
|
|
if self.Live then
|
|
poolManager:UnLoadLive(self.bgName, self.Live)
|
|
end
|
|
self.Live = nil
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
function LingShouBaoGe:OnDestroy()
|
|
if self.Live then
|
|
poolManager:UnLoadLive(self.bgName, self.Live)
|
|
end
|
|
self.Live = nil
|
|
self.spLoader:Destroy()
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function LingShouBaoGe:AddListener()
|
|
Game.GlobalEvent:AddEvent(GameEvent.Activity.UpMonsterChange, function()
|
|
self:Refresh()
|
|
end)
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function LingShouBaoGe:RemoveListener()
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.UpMonsterChange, function()
|
|
self:Refresh()
|
|
end)
|
|
end
|
|
|
|
return LingShouBaoGe
|