miduo_client/Assets/ManagedResources/~Lua/Modules/Incarnation/IncarnationLottery.lua

381 lines
15 KiB
Lua
Raw Normal View History

2025-03-14 11:58:20 +08:00
local IncarnationLottery = {}
2021-12-02 15:18:56 +08:00
local sortingOrder = 0
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local artConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
2024-09-06 10:38:56 +08:00
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
local privilegeConfig = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
2021-12-02 15:18:56 +08:00
local lotterySpecialConfig = ConfigManager.GetConfig(ConfigName.LotterySpecialConfig)
local wishSoulData
function IncarnationLottery:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = IncarnationLottery })
return b
end
--初始化组件(用于子类重写)
function IncarnationLottery:InitComponent()
self.spLoader = SpriteLoader.New()
2024-09-06 10:38:56 +08:00
self.btnHelp = Util.GetGameObject(self.gameObject, "help")
self.helpPosition = self.btnHelp:GetComponent("RectTransform").localPosition
2021-12-02 15:18:56 +08:00
2024-09-06 10:38:56 +08:00
self.limit = Util.GetGameObject(self.gameObject, "limitdi/limit"):GetComponent("Text")
2021-12-02 15:18:56 +08:00
--rightUp
2024-09-06 10:38:56 +08:00
self.rightUp = Util.GetGameObject(self.gameObject, "rightUp")
self.btnReward = Util.GetGameObject(self.rightUp, "reward")
self.btnStore = Util.GetGameObject(self.rightUp, "store")
self.btnGift = Util.GetGameObject(self.rightUp, "gift")
self.btnGiftEffect = Util.GetGameObject(self.btnGift, "Fx_Circle 1")
2021-12-02 15:18:56 +08:00
self.btns = {}
2024-09-06 10:38:56 +08:00
for i = 1, 2 do
2021-12-02 15:18:56 +08:00
self.btns[i] = {}
2024-09-06 10:38:56 +08:00
self.btns[i].btn = Util.GetGameObject(self.rightUp, "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")
self.btns[i].reward = Util.GetGameObject(self.btns[i].btn.gameObject, "reward"):GetComponent("Text")
2021-12-02 15:18:56 +08:00
end
--center
2024-09-06 10:38:56 +08:00
self.center = Util.GetGameObject(self.gameObject, "center/TurnTable/itemlist")
2021-12-02 15:18:56 +08:00
self.icons = {}
2024-09-06 10:38:56 +08:00
for i = 1, 10 do
2021-12-02 15:18:56 +08:00
self.icons[i] = {}
2024-09-06 10:38:56 +08:00
self.icons[i].go = Util.GetGameObject(self.center, "item" .. i)
self.icons[i].pre = Util.GetGameObject(self.icons[i].go, "pre")
self.icons[i].kuang = Util.GetGameObject(self.icons[i].pre, "itemPos")
self.icons[i].icon = Util.GetGameObject(self.icons[i].pre, "icon"):GetComponent("Image")
self.icons[i].num = Util.GetGameObject(self.icons[i].pre, "numDi/Text"):GetComponent("Text")
2021-12-02 15:18:56 +08:00
end
2024-09-06 10:38:56 +08:00
self.updateTimes = Util.GetGameObject(self.gameObject, "updateTimes")
2021-12-02 15:18:56 +08:00
--self.updateTimesTip = Util.GetGameObject(self.updateTimes,"Text"):GetComponent("Text")
2024-09-06 10:38:56 +08:00
self.updateTimesTip1 = Util.GetGameObject(self.updateTimes, "Text1"):GetComponent("Text")
self.mask = Util.GetGameObject(self.gameObject, "mask")
2021-12-02 15:18:56 +08:00
self._last = 0
self._cyclesNum = 10
self.reward = {}
end
--绑定事件(用于子类重写)
function IncarnationLottery:BindEvent()
2021-12-03 13:21:15 +08:00
Util.AddOnceClick(self.btnHelp, function()
2024-09-06 10:38:56 +08:00
UIManager.OpenPanel(UIName.HelpPopup, self.actConfig.HelpId, self.helpPosition.x, self.helpPosition.y)
2021-12-02 15:18:56 +08:00
end)
2024-09-06 10:38:56 +08:00
Util.AddOnceClick(self.btnReward, function()
UIManager.OpenPanel(UIName.GeneralBigPopup, GENERAL_POPUP_TYPE.RecrutDetail, self.actConfig.HelpId, self.actType,
PRE_REWARD_POOL_TYPE.Incarnation, PRE_REWARD_POOL_TYPE.Incarnation)
2021-12-02 15:18:56 +08:00
end)
2021-12-03 13:21:15 +08:00
Util.AddOnceClick(self.btnStore, function()
2021-12-02 15:18:56 +08:00
JumpManager.GoJump(40049)
end)
2024-09-06 10:38:56 +08:00
Util.AddOnceClick(self.btnGift, function()
JumpManager.GoJump(40050, nil, self.actId)
2021-12-02 15:18:56 +08:00
end)
end
--添加事件监听(用于子类重写)
function IncarnationLottery:AddListener()
2024-09-06 10:38:56 +08:00
2021-12-02 15:18:56 +08:00
end
--移除事件监听(用于子类重写)
function IncarnationLottery:RemoveListener()
end
--界面打开时调用(用于子类重写)
2024-09-06 10:38:56 +08:00
function IncarnationLottery:OnOpen(_activityConfig, _index, parent)
2021-12-02 15:18:56 +08:00
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
end
function IncarnationLottery:OnSortingOrderChange(_sortingOrder)
sortingOrder = _sortingOrder or 0
2024-09-06 10:38:56 +08:00
Util.SetParticleSortLayer(self.btnGiftEffect, sortingOrder + 1)
2021-12-02 15:18:56 +08:00
end
-- 打开,重新打开时回调
function IncarnationLottery:OnShow(_sortingOrder)
self.gameObject:SetActive(true)
sortingOrder = _sortingOrder
2024-09-06 10:38:56 +08:00
Util.SetParticleSortLayer(self.btnGiftEffect, sortingOrder + 1)
2021-12-02 15:18:56 +08:00
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
2024-09-06 10:38:56 +08:00
local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups, "PageType",
self.actConfig.PageType, "ActiveType", self.actConfig.ActiveType, "ActId", id)
2021-12-02 15:18:56 +08:00
if config then
self.actConfig = config
end
end
end
2024-09-06 10:38:56 +08:00
end
local array = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySetting, "ActivityId", self.actId)
2021-12-02 15:18:56 +08:00
self.singleRecruit = array[1]
self.tenRecruit = array[2]
2024-09-06 10:38:56 +08:00
self.freeTimesId = self.singleRecruit.FreeTimes
self.maxtimesId = self.singleRecruit.MaxTimes
2021-12-02 15:18:56 +08:00
self:contentShow()
self:refreshMagicNum()
2024-09-06 10:38:56 +08:00
self:refreshBtnShow() --刷新按钮显示
2021-12-02 15:18:56 +08:00
self.center.transform.localRotation = Quaternion.Euler(Vector3.zero)
self._last = self.center.transform.localRotation.z
self:DelayMaskWithBool(false)
self:TurnTable(1)
end
--五个魂印头像
function IncarnationLottery:contentShow()
self.reward = {}
self.rewardWeight = {}
local data = RecruitManager.GetRewardPreviewData(PRE_REWARD_POOL_TYPE.Incarnation)
2024-09-06 10:38:56 +08:00
for i = 1, #self.icons do
local str1 = data[i].Reward[1] .. "#" .. data[i].Reward[2]
self.icons[i].kuang:GetComponent("Image").sprite = self.spLoader:LoadSprite(GetQuantityImageByquality(itemConfig
[data[i].Reward[1]].Quantity))
2021-12-02 15:18:56 +08:00
self.icons[i].icon.sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(data[i].Reward[1]))
self.icons[i].num.text = data[i].Reward[2]
self.reward[str1] = i
self.rewardWeight[str1] = data[i].WeightShow
2024-09-06 10:38:56 +08:00
Util.AddOnceClick(self.icons[i].kuang, function()
if itemConfig[data[i].Reward[1]].ItemType == ItemType.SelfBox then
2024-09-06 10:38:56 +08:00
UIManager.OpenPanel(UIName.RewardBoxPanel, nil, data[i].Reward[1])
else
2024-09-06 10:38:56 +08:00
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, data[i].Reward[1])
end
2021-12-06 09:58:04 +08:00
end)
2021-12-02 15:18:56 +08:00
end
end
function IncarnationLottery:refreshMagicNum()
2021-12-03 13:21:15 +08:00
-- self.actData = ActivityGiftManager.GetActivityTypeInfo(self.actType)
self.actData = CommonActPageManager.GetData(self.actType)
2024-09-06 10:38:56 +08:00
CommonActPageManager.ShowIcon(self.btnGift, self.actData.activityId)
2021-12-02 15:18:56 +08:00
2024-09-06 10:38:56 +08:00
--local d = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySpecialConfig,"Type",self.singleRecruit.MergePool)
2021-12-02 15:18:56 +08:00
--self.updateTimesTip.text = string.format("<color=#cbb981>召唤<color=#%s>%s</color>次必得红色碎片</color>","ff850c",d[1].Count - self.actData.value)
local endTime = ActivityGiftManager.GetTaskEndTime(self.actType) - PlayerManager.serverTime
2024-09-06 10:38:56 +08:00
self.updateTimesTip1.text = string.format(Language[11617], self:TimeToDHMS(endTime))
local timeDown = CalculateSecondsNowTo_N_OClock(0)
2021-12-02 15:18:56 +08:00
self.timer = Timer.New(function()
if endTime < 1 then
self.timer:Stop()
self.timer = nil
self:OnShow(sortingOrder)
return
else
2024-09-06 10:38:56 +08:00
self.updateTimesTip1.text = string.format(Language[11617], self:TimeToDHMS(endTime))
2021-12-02 15:18:56 +08:00
end
endTime = endTime - 1
2024-09-06 10:38:56 +08:00
timeDown = timeDown - 1
2021-12-02 15:18:56 +08:00
end, 1, -1, true)
self.timer:Start()
end
2021-12-06 15:53:01 +08:00
function IncarnationLottery:GetSendStr(reId)
local str = ""
if lotterySetting[reId] and lotterySetting[reId].TenTimesMustGetItem and #lotterySetting[reId].TenTimesMustGetItem > 0 then
2024-09-06 10:38:56 +08:00
for k, v in ipairs(lotterySetting[reId].TenTimesMustGetItem) do
2021-12-06 15:53:01 +08:00
if str == "" then
2024-09-06 10:38:56 +08:00
str = str .. Language[10601]
2021-12-06 15:53:01 +08:00
else
2024-09-06 10:38:56 +08:00
str = str .. Language[10602]
2021-12-06 15:53:01 +08:00
end
2024-09-06 10:38:56 +08:00
str = str .. v[2] .. Language[10227] .. itemConfig[v[1]].Name
2021-12-06 15:53:01 +08:00
end
end
return str
end
2024-09-06 10:38:56 +08:00
function IncarnationLottery:refreshBtnShow()
2021-12-02 15:18:56 +08:00
local curTimes = PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId)
2024-09-06 10:38:56 +08:00
self.limit.text = Language[10596] .. curTimes .. "/" .. privilegeConfig[self.maxtimesId].Condition[1][2]
2021-12-02 15:18:56 +08:00
local freeTime = 0
if self.freeTimesId and self.freeTimesId > 0 then
freeTime = PrivilegeManager.GetPrivilegeRemainValue(self.freeTimesId)
2024-09-06 10:38:56 +08:00
RecruitManager.freeUseTimeList[self.freeTimesId] = freeTime
2021-12-02 15:18:56 +08:00
end
2024-09-06 10:38:56 +08:00
2021-12-02 15:18:56 +08:00
--按钮赋值
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)
2024-09-06 10:38:56 +08:00
local itemId = 0
local itemNum = 0
2021-12-02 15:18:56 +08:00
local type = 0
if n == 1 then
type = self.singleRecruit.Id
2021-12-06 10:26:43 +08:00
--m.info.text = "1次"
2021-12-02 15:18:56 +08:00
else
type = self.tenRecruit.Id
2024-09-06 10:38:56 +08:00
--m.info.text = "10次"
2021-12-02 15:18:56 +08:00
end
local d = {}
2024-09-06 10:38:56 +08:00
if (isFree) then
m.info.text = Language[10583]
2021-12-02 15:18:56 +08:00
else
local d = RecruitManager.GetExpendData(type)
2024-09-06 10:38:56 +08:00
itemId = d[1]
itemNum = d[2]
2021-12-02 15:18:56 +08:00
m.icon.sprite = self.spLoader:LoadSprite(artConfig[itemConfig[itemId].ResourceID].Name)
2024-09-06 10:38:56 +08:00
m.num.text = tostring(itemNum)
2021-12-02 15:18:56 +08:00
end
2021-12-06 15:53:01 +08:00
m.reward.text = self:GetSendStr(n == 1 and self.singleRecruit.Id or self.tenRecruit.Id)
2024-09-06 10:38:56 +08:00
Util.AddOnceClick(m.btn, function()
2021-12-02 15:18:56 +08:00
if not isFree then
if BagManager.GetItemCountById(itemId) < itemNum then
2024-09-19 20:14:12 +08:00
PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[itemId].Name) .. Language[10584])
2021-12-02 15:18:56 +08:00
return
end
end
local recrutId = n == 1 and self.singleRecruit.Id or self.tenRecruit.Id
local recrutNum = n == 1 and 1 or 10
local uiName = n == 1 and UIName.QianKunBoxBuyOnePanel or UIName.QianKunBoxBuyTenPanel
2024-09-06 10:38:56 +08:00
self:Recruit(recrutNum, recrutId, uiName)
end)
2021-12-02 15:18:56 +08:00
end
end
2024-09-06 10:38:56 +08:00
function IncarnationLottery:Recruit(recrutType, recrutId, uiName)
if PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId) + recrutType > privilegeConfig[self.maxtimesId].Condition[1][2] then
2024-08-29 21:36:51 +08:00
PopupTipPanel.ShowTip(Language[10587])
2021-12-02 15:18:56 +08:00
return
end
RecruitManager.RecruitRequest(recrutId, function(msg)
2024-09-06 10:38:56 +08:00
PrivilegeManager.RefreshPrivilegeUsedTimes(self.maxtimesId, recrutType) --记录抽卡次数
2021-12-02 15:18:56 +08:00
--先转转盘
local index = 1
local rotate = self.center.transform.localRotation
2024-09-06 10:38:56 +08:00
2021-12-02 15:18:56 +08:00
local bestIndex = 0
2021-12-06 15:43:05 +08:00
if recrutId == self.tenRecruit.Id then
2021-12-02 15:18:56 +08:00
local weight = nil
2024-09-06 10:38:56 +08:00
for i = 1, #msg.drop.itemlist do
local str = msg.drop.itemlist[i].itemId .. "#" .. msg.drop.itemlist[i].itemNum
2021-12-06 15:43:05 +08:00
if self.rewardWeight[str] then
if not weight then
2021-12-02 15:18:56 +08:00
weight = self.rewardWeight[str]
bestIndex = self.reward[str]
2021-12-06 15:43:05 +08:00
else
2021-12-06 17:26:03 +08:00
if weight > self.rewardWeight[str] then
2021-12-06 15:43:05 +08:00
weight = self.rewardWeight[str]
bestIndex = self.reward[str]
end
2021-12-02 15:18:56 +08:00
end
end
end
else
local drop = {}
drop = msg.drop.itemlist[1]
2024-09-06 10:38:56 +08:00
local str2 = drop.itemId .. "#" .. drop.itemNum
bestIndex = self.reward[drop.itemId .. "#" .. drop.itemNum]
2021-12-02 15:18:56 +08:00
end
2024-09-06 10:38:56 +08:00
self:TurnTable(2, bestIndex, function()
UIManager.OpenPanel(uiName, msg.drop, recrutId, { RecruitType.QianKunBoxTen, RecruitType.QianKunBoxTen })
end)
--UIManager.OpenPanel(uiName, msg.drop,recrutId,{RecruitType.QianKunBoxTen,RecruitType.QianKunBoxTen})
end, self.freeTimesId)
2021-12-02 15:18:56 +08:00
end
2024-09-06 10:38:56 +08:00
function IncarnationLottery:TurnTable(turnType, pos, fun)
if turnType == 1 then --默认旋转
self._cyclesNum = 43200 --一直循环
2021-12-03 18:03:36 +08:00
self:TurnEffectReset(60)
2024-09-06 10:38:56 +08:00
elseif turnType == 2 then --抽奖旋转 至指定位置
2021-12-02 15:18:56 +08:00
self:DelayMaskWithBool(true)
self._cyclesNum = 3
2024-09-06 10:38:56 +08:00
self:TurnEffectReset(2, true, pos, function() --当效果播放完毕后 从管理器取得数据
2021-12-02 15:18:56 +08:00
self:DelayMaskWithBool(false)
if fun then
fun()
2024-09-06 10:38:56 +08:00
end
2021-12-02 15:18:56 +08:00
end)
end
end
function IncarnationLottery:DelayMaskWithBool(isShow)
self.mask.gameObject:SetActive(isShow)
end
---转盘滚动特效重设 1移动速度值越小越快 2是否停止 3停止位置
2024-09-06 10:38:56 +08:00
function IncarnationLottery:TurnEffectReset(turnSpeed, isStop, pos, func)
2021-12-02 15:18:56 +08:00
local s = function()
if isStop then
2021-12-07 14:41:09 +08:00
SoundManager.PlaySound(SoundConfig.Audio_fangcunzhuanpan_0)
2024-09-06 10:38:56 +08:00
self._last = self.center.transform.localRotation.z
2021-12-03 18:03:36 +08:00
local a = self._cyclesNum * -360 - (10 - pos + 1) * 36;
2024-09-06 10:38:56 +08:00
self.tween:Kill()
self.tween = self.center.transform:DORotate(Vector3.New(0, 0, a - self._last), turnSpeed):SetEase(Ease
.OutQuad):OnComplete(function()
Timer.New(function()
if func then --回调
2021-12-02 15:18:56 +08:00
func()
2024-09-06 10:38:56 +08:00
end
self.tween:Kill()
end, 0.75):Start()
2021-12-02 15:18:56 +08:00
end)
2024-09-06 10:38:56 +08:00
Timer.New(function()
self._last = self.center.transform.localRotation.z
self.center.transform:DOPunchRotation(Vector3.New(0, 0, self._last - 10), 2, 2, 0) --:SetEase(Ease.OutQuad):SetLoops(2,0)
end, turnSpeed - 0.07):Start()
2021-12-02 15:18:56 +08:00
else
2024-09-06 10:38:56 +08:00
self.tween = self.center.transform:DORotate(Vector3.New(0, 0, self._last - 360), turnSpeed, 1):SetLoops(-1, 0)
:SetEase(Ease.Linear):OnComplete(function()
end)
2021-12-02 15:18:56 +08:00
end
2024-09-06 10:38:56 +08:00
end
2021-12-02 15:18:56 +08:00
s()
2024-09-06 10:38:56 +08:00
end
2021-12-02 15:18:56 +08:00
--- 将一段时间转换为天时分秒
function IncarnationLottery: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
2024-09-06 10:38:56 +08:00
return string.format(Language[10571], minute, sec)
2021-12-02 15:18:56 +08:00
else
2024-09-06 10:38:56 +08:00
return string.format(Language[10572], day, hour)
2021-12-02 15:18:56 +08:00
end
end
--界面关闭时调用(用于子类重写)
function IncarnationLottery:OnClose()
self.gameObject:SetActive(false)
if self.timer then
self.timer:Stop()
self.timer = nil
end
if self.shopView then
SubUIManager.Close(self.shopView)
end
self.shopView = nil
end
2024-09-06 10:38:56 +08:00
2021-12-02 15:18:56 +08:00
--界面销毁时调用(用于子类重写)
function IncarnationLottery:OnDestroy()
self.btns = {}
if self.shopView then
SubUIManager.Close(self.shopView)
end
self.shopView = nil
end
2024-09-06 10:38:56 +08:00
return IncarnationLottery