381 lines
15 KiB
Lua
381 lines
15 KiB
Lua
local IncarnationLottery = {}
|
||
local sortingOrder = 0
|
||
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local artConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
|
||
local lotterySetting = ConfigManager.GetConfig(ConfigName.LotterySetting)
|
||
local privilegeConfig = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig)
|
||
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()
|
||
self.btnHelp = Util.GetGameObject(self.gameObject, "help")
|
||
self.helpPosition = self.btnHelp:GetComponent("RectTransform").localPosition
|
||
|
||
self.limit = Util.GetGameObject(self.gameObject, "limitdi/limit"):GetComponent("Text")
|
||
|
||
--rightUp
|
||
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")
|
||
self.btns = {}
|
||
for i = 1, 2 do
|
||
self.btns[i] = {}
|
||
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")
|
||
end
|
||
--center
|
||
self.center = Util.GetGameObject(self.gameObject, "center/TurnTable/itemlist")
|
||
self.icons = {}
|
||
for i = 1, 10 do
|
||
self.icons[i] = {}
|
||
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")
|
||
end
|
||
|
||
self.updateTimes = Util.GetGameObject(self.gameObject, "updateTimes")
|
||
--self.updateTimesTip = Util.GetGameObject(self.updateTimes,"Text"):GetComponent("Text")
|
||
self.updateTimesTip1 = Util.GetGameObject(self.updateTimes, "Text1"):GetComponent("Text")
|
||
self.mask = Util.GetGameObject(self.gameObject, "mask")
|
||
|
||
self._last = 0
|
||
self._cyclesNum = 10
|
||
self.reward = {}
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function IncarnationLottery:BindEvent()
|
||
Util.AddOnceClick(self.btnHelp, function()
|
||
UIManager.OpenPanel(UIName.HelpPopup, self.actConfig.HelpId, self.helpPosition.x, self.helpPosition.y)
|
||
end)
|
||
|
||
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)
|
||
end)
|
||
|
||
Util.AddOnceClick(self.btnStore, function()
|
||
JumpManager.GoJump(40049)
|
||
end)
|
||
|
||
Util.AddOnceClick(self.btnGift, function()
|
||
JumpManager.GoJump(40050, nil, self.actId)
|
||
end)
|
||
end
|
||
|
||
--添加事件监听(用于子类重写)
|
||
function IncarnationLottery:AddListener()
|
||
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function IncarnationLottery:RemoveListener()
|
||
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function IncarnationLottery:OnOpen(_activityConfig, _index, parent)
|
||
self.actConfig = _activityConfig
|
||
self.pageIndex = _index
|
||
self.parent = parent
|
||
end
|
||
|
||
function IncarnationLottery:OnSortingOrderChange(_sortingOrder)
|
||
sortingOrder = _sortingOrder or 0
|
||
Util.SetParticleSortLayer(self.btnGiftEffect, sortingOrder + 1)
|
||
end
|
||
|
||
-- 打开,重新打开时回调
|
||
function IncarnationLottery:OnShow(_sortingOrder)
|
||
self.gameObject:SetActive(true)
|
||
sortingOrder = _sortingOrder
|
||
Util.SetParticleSortLayer(self.btnGiftEffect, sortingOrder + 1)
|
||
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
|
||
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:contentShow()
|
||
self:refreshMagicNum()
|
||
self:refreshBtnShow() --刷新按钮显示
|
||
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)
|
||
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))
|
||
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
|
||
Util.AddOnceClick(self.icons[i].kuang, function()
|
||
if itemConfig[data[i].Reward[1]].ItemType == ItemType.SelfBox then
|
||
UIManager.OpenPanel(UIName.RewardBoxPanel, nil, data[i].Reward[1])
|
||
else
|
||
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, data[i].Reward[1])
|
||
end
|
||
end)
|
||
end
|
||
end
|
||
|
||
function IncarnationLottery:refreshMagicNum()
|
||
-- self.actData = ActivityGiftManager.GetActivityTypeInfo(self.actType)
|
||
self.actData = CommonActPageManager.GetData(self.actType)
|
||
CommonActPageManager.ShowIcon(self.btnGift, self.actData.activityId)
|
||
|
||
--local d = ConfigManager.GetAllConfigsDataByKey(ConfigName.LotterySpecialConfig,"Type",self.singleRecruit.MergePool)
|
||
--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
|
||
self.updateTimesTip1.text = string.format(Language[11617], self:TimeToDHMS(endTime))
|
||
local timeDown = CalculateSecondsNowTo_N_OClock(0)
|
||
self.timer = Timer.New(function()
|
||
if endTime < 1 then
|
||
self.timer:Stop()
|
||
self.timer = nil
|
||
self:OnShow(sortingOrder)
|
||
return
|
||
else
|
||
self.updateTimesTip1.text = string.format(Language[11617], self:TimeToDHMS(endTime))
|
||
end
|
||
endTime = endTime - 1
|
||
timeDown = timeDown - 1
|
||
end, 1, -1, true)
|
||
self.timer:Start()
|
||
end
|
||
|
||
function IncarnationLottery:GetSendStr(reId)
|
||
local str = ""
|
||
if lotterySetting[reId] and lotterySetting[reId].TenTimesMustGetItem and #lotterySetting[reId].TenTimesMustGetItem > 0 then
|
||
for k, v in ipairs(lotterySetting[reId].TenTimesMustGetItem) do
|
||
if str == "" then
|
||
str = str .. Language[10601]
|
||
else
|
||
str = str .. Language[10602]
|
||
end
|
||
str = str .. v[2] .. Language[10227] .. itemConfig[v[1]].Name
|
||
end
|
||
end
|
||
return str
|
||
end
|
||
|
||
function IncarnationLottery:refreshBtnShow()
|
||
local curTimes = PrivilegeManager.GetPrivilegeUsedTimes(self.maxtimesId)
|
||
self.limit.text = Language[10596] .. curTimes .. "/" .. privilegeConfig[self.maxtimesId].Condition[1][2]
|
||
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 = "1次"
|
||
else
|
||
type = self.tenRecruit.Id
|
||
--m.info.text = "10次"
|
||
end
|
||
local d = {}
|
||
if (isFree) then
|
||
m.info.text = Language[10583]
|
||
else
|
||
local d = RecruitManager.GetExpendData(type)
|
||
itemId = d[1]
|
||
itemNum = d[2]
|
||
m.icon.sprite = self.spLoader:LoadSprite(artConfig[itemConfig[itemId].ResourceID].Name)
|
||
m.num.text = tostring(itemNum)
|
||
end
|
||
m.reward.text = self:GetSendStr(n == 1 and self.singleRecruit.Id or self.tenRecruit.Id)
|
||
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 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
|
||
self:Recruit(recrutNum, recrutId, uiName)
|
||
end)
|
||
end
|
||
end
|
||
|
||
function IncarnationLottery:Recruit(recrutType, recrutId, uiName)
|
||
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) --记录抽卡次数
|
||
--先转转盘
|
||
local index = 1
|
||
local rotate = self.center.transform.localRotation
|
||
|
||
local bestIndex = 0
|
||
if recrutId == self.tenRecruit.Id then
|
||
local weight = nil
|
||
for i = 1, #msg.drop.itemlist do
|
||
local str = msg.drop.itemlist[i].itemId .. "#" .. msg.drop.itemlist[i].itemNum
|
||
if self.rewardWeight[str] then
|
||
if not weight then
|
||
weight = self.rewardWeight[str]
|
||
bestIndex = self.reward[str]
|
||
else
|
||
if weight > self.rewardWeight[str] then
|
||
weight = self.rewardWeight[str]
|
||
bestIndex = self.reward[str]
|
||
end
|
||
end
|
||
end
|
||
end
|
||
else
|
||
local drop = {}
|
||
drop = msg.drop.itemlist[1]
|
||
local str2 = drop.itemId .. "#" .. drop.itemNum
|
||
bestIndex = self.reward[drop.itemId .. "#" .. drop.itemNum]
|
||
end
|
||
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)
|
||
end
|
||
|
||
function IncarnationLottery:TurnTable(turnType, pos, fun)
|
||
if turnType == 1 then --默认旋转
|
||
self._cyclesNum = 43200 --一直循环
|
||
self:TurnEffectReset(60)
|
||
elseif turnType == 2 then --抽奖旋转 至指定位置
|
||
self:DelayMaskWithBool(true)
|
||
self._cyclesNum = 3
|
||
self:TurnEffectReset(2, true, pos, function() --当效果播放完毕后 从管理器取得数据
|
||
self:DelayMaskWithBool(false)
|
||
if fun then
|
||
fun()
|
||
end
|
||
end)
|
||
end
|
||
end
|
||
|
||
function IncarnationLottery:DelayMaskWithBool(isShow)
|
||
self.mask.gameObject:SetActive(isShow)
|
||
end
|
||
|
||
---转盘滚动特效重设 1移动速度,值越小越快 2是否停止 3停止位置
|
||
function IncarnationLottery:TurnEffectReset(turnSpeed, isStop, pos, func)
|
||
local s = function()
|
||
if isStop then
|
||
SoundManager.PlaySound(SoundConfig.Audio_fangcunzhuanpan_0)
|
||
self._last = self.center.transform.localRotation.z
|
||
local a = self._cyclesNum * -360 - (10 - pos + 1) * 36;
|
||
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 --回调
|
||
func()
|
||
end
|
||
self.tween:Kill()
|
||
end, 0.75):Start()
|
||
end)
|
||
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()
|
||
else
|
||
self.tween = self.center.transform:DORotate(Vector3.New(0, 0, self._last - 360), turnSpeed, 1):SetLoops(-1, 0)
|
||
:SetEase(Ease.Linear):OnComplete(function()
|
||
end)
|
||
end
|
||
end
|
||
s()
|
||
end
|
||
|
||
--- 将一段时间转换为天时分秒
|
||
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
|
||
return string.format(Language[10571], minute, sec)
|
||
else
|
||
return string.format(Language[10572], day, hour)
|
||
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
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function IncarnationLottery:OnDestroy()
|
||
self.btns = {}
|
||
if self.shopView then
|
||
SubUIManager.Close(self.shopView)
|
||
end
|
||
self.shopView = nil
|
||
end
|
||
|
||
return IncarnationLottery
|