212 lines
6.4 KiB
Lua
212 lines
6.4 KiB
Lua
------------------------------------------------
|
||
--作者: 杨全福
|
||
--日期: 2021-10-26
|
||
--文件: LuckCatBYData.lua
|
||
--模块: LuckCatBYData
|
||
--描述: 绑玉招财猫活动数据
|
||
------------------------------------------------
|
||
local BaseData = require("Logic.YYHD.YYHDBaseData")
|
||
|
||
local LuckCatBYData = {
|
||
--倍率列表,总共8个
|
||
RateList = nil,
|
||
--次数对应消耗和充值
|
||
GearList = nil,
|
||
--抽奖记录列表
|
||
RecordList = nil,
|
||
--抽奖剩余次数
|
||
RemainCount = 0,
|
||
--当前充值金额
|
||
RechargeCount = 0,
|
||
|
||
--当前消耗元宝
|
||
CurCost = 0,
|
||
--到下一档的金额
|
||
NextNeed = 0,
|
||
--到下一档增加的次数
|
||
NextAddCount = 0,
|
||
--当前已经抽了的次数
|
||
CostCountTable = nil,
|
||
|
||
--当前限制次数
|
||
CurLimitCount = 0,
|
||
--当前已抽次数
|
||
CurCostCount = 0,
|
||
--显示上线红点
|
||
ShowOnlineRedPoint = false,
|
||
}
|
||
|
||
function LuckCatBYData:New(typeId)
|
||
local _n = Utils.DeepCopy(self)
|
||
local _mn = setmetatable(_n, {__index = BaseData:New(typeId)})
|
||
return _mn
|
||
end
|
||
|
||
--解析活动配置数据
|
||
function LuckCatBYData:ParseSelfCfgData(jsonTable)
|
||
self.ShowOnlineRedPoint = true
|
||
self.RateList = List:New()
|
||
if jsonTable.rate ~= nil then
|
||
local _rateParams = Utils.SplitNumber(jsonTable.rate, '_')
|
||
for i = 1, #_rateParams do
|
||
self.RateList:Add(_rateParams[i])
|
||
end
|
||
|
||
--补充到8个
|
||
local _rateCount = #self.RateList
|
||
if _rateCount < 8 then
|
||
local _addRate = 1
|
||
if _rateCount > 0 then
|
||
_addRate = self.RateList[_rateCount]
|
||
end
|
||
for i = _rateCount + 1, 8 do
|
||
self.RateList:Add(_addRate)
|
||
end
|
||
end
|
||
end
|
||
self.GearList = List:New()
|
||
if jsonTable.gear ~= nil then
|
||
local _gearParams = Utils.SplitStrByTableS(jsonTable.gear, {';', '_'})
|
||
for i = 1, #_gearParams do
|
||
local _limit = _gearParams[i][5]
|
||
if _limit == nil then
|
||
_limit = 0
|
||
end
|
||
self.GearList:Add({
|
||
Cost = _gearParams[i][1], --Cost消耗元宝
|
||
Need = _gearParams[i][2], --Need需求充值金额
|
||
Limit = _limit,
|
||
})
|
||
end
|
||
end
|
||
end
|
||
|
||
--解析活动玩家数据
|
||
function LuckCatBYData:ParsePlayerData(jsonTable)
|
||
self.RecordList = List:New()
|
||
if jsonTable.record ~= nil then
|
||
local _recordParams = Utils.SplitStrBySeps(jsonTable.record, {';', '_'})
|
||
for i = 1, #_recordParams do
|
||
self.RecordList:Add({
|
||
Name = _recordParams[i][1], --Name玩家名字
|
||
Rate = tonumber(_recordParams[i][2]) / 100, --Rate中奖倍数
|
||
Count = tonumber(_recordParams[i][3])--Count中奖数量
|
||
})
|
||
end
|
||
end
|
||
self.RemainCount = jsonTable.num or 0
|
||
self.RechargeCount = jsonTable.rechargeCount or 0
|
||
self.CostCountTable = {}
|
||
if jsonTable.serverDrawMap ~= nil then
|
||
for k, v in pairs(jsonTable.serverDrawMap) do
|
||
self.CostCountTable[tonumber(k)] = tonumber(v)
|
||
end
|
||
end
|
||
end
|
||
|
||
--刷新数据
|
||
function LuckCatBYData:RefreshData()
|
||
--计算当前可抽总次数
|
||
local _allCount = 0
|
||
for i = 1, #self.GearList do
|
||
if self.RechargeCount >= self.GearList[i].Need then
|
||
_allCount = i
|
||
end
|
||
end
|
||
local _curCount = _allCount - self.RemainCount + 1
|
||
--防错
|
||
if _curCount <= 0 or _curCount > #self.GearList then
|
||
self.CurCost = 0
|
||
self.NextNeed = 0
|
||
self.NextAddCount = 0
|
||
self.CurLimitCount = 0
|
||
self.CurCostCount = 0
|
||
else
|
||
local _curCfg = self.GearList[_curCount]
|
||
self.CurLimitCount = _curCfg.Limit
|
||
self.CurCostCount = self.CostCountTable[_curCfg.Need]
|
||
if self.CurCostCount == nil then
|
||
self.CurCostCount = 0
|
||
end
|
||
self.CurCost = _curCfg.Cost
|
||
self.NextNeed = 0
|
||
if _allCount < #self.GearList then
|
||
local _nextNeed = self.GearList[_allCount + 1].Need
|
||
--计算再冲多少钱可以增加次数
|
||
self.NextNeed = _nextNeed - self.RechargeCount
|
||
--计算下次充值可增加的抽奖次数
|
||
local _nextCount = 0
|
||
for i = 1, #self.GearList do
|
||
if _nextNeed >= self.GearList[i].Need then
|
||
_nextCount = i
|
||
end
|
||
end
|
||
self.NextAddCount = _nextCount - _allCount
|
||
end
|
||
end
|
||
self:CheckRedPoint()
|
||
end
|
||
|
||
--检查红点
|
||
function LuckCatBYData:CheckRedPoint()
|
||
self:RemoveRedPoint(nil)
|
||
if self.RemainCount > 0 and self.CurCostCount < self.CurLimitCount then
|
||
self:AddRedPoint(0, nil, nil, nil, true, nil)
|
||
end
|
||
if self.ShowOnlineRedPoint then
|
||
self:AddRedPoint(1, nil, nil, nil, true, nil)
|
||
end
|
||
end
|
||
|
||
--清除上线红点
|
||
function LuckCatBYData:ClearOnlineRedPoint()
|
||
if self.ShowOnlineRedPoint then
|
||
self.ShowOnlineRedPoint = false
|
||
self:CheckRedPoint()
|
||
end
|
||
end
|
||
|
||
--增加主角中奖记录
|
||
function LuckCatBYData:AddLocalRecord(rate, count)
|
||
--剩余次数减1
|
||
self.RemainCount = self.RemainCount - 1
|
||
local _lp = GameCenter.GameSceneSystem:GetLocalPlayer()
|
||
if _lp == nil then
|
||
return
|
||
end
|
||
self.RecordList:Insert({
|
||
Name = _lp.Name, --Name玩家名字
|
||
Rate = tonumber(rate) / 100, --Rate中奖倍数
|
||
Count = tonumber(count)--Count中奖数量
|
||
}, 1)
|
||
end
|
||
|
||
--发送抽奖请求
|
||
function LuckCatBYData:ReqChouJiang()
|
||
if self.RemainCount <= 0 or self.CurCostCount >= self.CurLimitCount then
|
||
Utils.ShowPromptByEnum("C_LUCKCAT_COUNT_NOTENOUGH")
|
||
return
|
||
end
|
||
local _haveGold = GameCenter.ItemContianerSystem:GetEconomyWithType(ItemTypeCode.BindGold)
|
||
if _haveGold < self.CurCost then
|
||
Utils.ShowPromptByEnum("C_LUCKCAT_BANGYU_NOTENOUGH")
|
||
return
|
||
end
|
||
GameCenter.Network.Send("MSG_Activity.ReqActivityDeal", {type = self.TypeId})
|
||
end
|
||
|
||
--处理运营活动返回
|
||
function LuckCatBYData:ResActivityDeal(jsonTable)
|
||
self:AddLocalRecord(jsonTable.rate, jsonTable.money)
|
||
if jsonTable.serverDrawMap ~= nil then
|
||
for k, v in pairs(jsonTable.serverDrawMap) do
|
||
self.CostCountTable[tonumber(k)] = tonumber(v)
|
||
end
|
||
end
|
||
self:RefreshData()
|
||
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_REFRESH_LUCKCAT_RESULT, jsonTable)
|
||
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_REFRESH_HDLIST)
|
||
end
|
||
|
||
return LuckCatBYData
|