|
|
@@ -0,0 +1,203 @@
|
|
|
+--新商业化活动——登录豪礼
|
|
|
+--db
|
|
|
+--[=[
|
|
|
+ human.db.absAct[id] = {
|
|
|
+ loginDay = nil, --活动期间登录的天数
|
|
|
+ getRewardRecord = nil, {1,3,2,6} --已领取的奖励记录, 记录的是第几天
|
|
|
+ }
|
|
|
+]=]--
|
|
|
+
|
|
|
+local Msg = require("core.Msg")
|
|
|
+local Grid = require("bag.Grid")
|
|
|
+local BagLogic = require("bag.BagLogic")
|
|
|
+local AbsActLogic = require("absAct.AbsActLogic")
|
|
|
+local Broadcast = require("broadcast.Broadcast")
|
|
|
+local Lang = require("common.Lang")
|
|
|
+local Config = require("excel.absAct").AbsLoginReward
|
|
|
+local AbsActExcel = require("excel.absAct")
|
|
|
+local YunYingLogic = require("yunying.YunYingLogic")
|
|
|
+
|
|
|
+local LOGTAG = "AbsLoginReward" --日志标识
|
|
|
+
|
|
|
+
|
|
|
+local function check(tbl, day)
|
|
|
+ if not tbl or not day then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ for _, v in ipairs(tbl) do
|
|
|
+ if v == day then
|
|
|
+ return true
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ return false
|
|
|
+end
|
|
|
+
|
|
|
+function isOpen(human, YYInfo, funcConfig)
|
|
|
+ local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
|
|
|
+ return state, endTime, startTime
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+function isActive(human, YYInfo, funcConfig)
|
|
|
+ local state = isOpen(human, YYInfo, funcConfig)
|
|
|
+ return not state
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+--红点判断
|
|
|
+function isRed(human, YYInfo, funcConfig)
|
|
|
+ local actData = human.db.absAct[funcConfig.funcID]
|
|
|
+ if not actData then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local loginDay = actData.loginDay
|
|
|
+ if not loginDay then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ local getRewardRecord = actData.getRewardRecord
|
|
|
+ if getRewardRecord and #getRewardRecord >= loginDay then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ return true
|
|
|
+end
|
|
|
+
|
|
|
+function onLogin(human, id)
|
|
|
+ local state = AbsActLogic.isStarted(human, id)
|
|
|
+ if not state then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local actData = human.db.absAct[id]
|
|
|
+ if not actData then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ --处理活动更到线上前,玩家当天已经登录,没有记录当天登录的情况
|
|
|
+ if not actData.loginDay then
|
|
|
+ actData.loginDay = 1
|
|
|
+ --红点刷新
|
|
|
+ YunYingLogic.sendBanner(human)
|
|
|
+ local config = AbsActExcel.absActivity[id]
|
|
|
+ YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+--跨天函数
|
|
|
+function updateDaily(human, id)
|
|
|
+ local state = AbsActLogic.isStarted(human, id)
|
|
|
+ if not state then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local actData = human.db.absAct[id]
|
|
|
+ if not actData then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ actData.loginDay =( actData.loginDay or 0) + 1
|
|
|
+
|
|
|
+ --红点刷新
|
|
|
+ YunYingLogic.sendBanner(human)
|
|
|
+ local config = AbsActExcel.absActivity[id]
|
|
|
+ YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+--查询
|
|
|
+function Query(human, id)
|
|
|
+ local state = AbsActLogic.isStarted(human, id)
|
|
|
+ if not state then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
|
|
|
+ end
|
|
|
+
|
|
|
+ local actData = human.db.absAct[id]
|
|
|
+ if not actData then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
|
|
|
+ end
|
|
|
+
|
|
|
+ local msgRet = Msg.gc.GC_LOGINREWARD_QUERY
|
|
|
+ local dayRewardData = msgRet.dayRewardData
|
|
|
+
|
|
|
+
|
|
|
+ dayRewardData[0] = #Config
|
|
|
+ local loginDay = actData.loginDay
|
|
|
+ local getRewardRecord = actData.getRewardRecord
|
|
|
+
|
|
|
+ for day, cfg in ipairs(Config) do
|
|
|
+ dayRewardData[day].day = day
|
|
|
+ dayRewardData[day].state = 0
|
|
|
+ local isGet = check(getRewardRecord, day)
|
|
|
+
|
|
|
+ if loginDay and loginDay >= day and isGet then
|
|
|
+ dayRewardData[day].state = 2
|
|
|
+ elseif loginDay and loginDay >= day and not isGet then
|
|
|
+ dayRewardData[day].state = 1
|
|
|
+ end
|
|
|
+
|
|
|
+ local rewardInfo = dayRewardData[day].rewardInfo
|
|
|
+ rewardInfo[0] = #cfg.item
|
|
|
+ for idx, itemInfo in ipairs(cfg.item) do
|
|
|
+ Grid.makeItem(rewardInfo[idx], itemInfo[1], itemInfo[2])
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ Msg.send(msgRet, human.fd)
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+--领奖
|
|
|
+function GetReward(human, id, dayIndex)
|
|
|
+ local state = AbsActLogic.isStarted(human, id)
|
|
|
+ if not state then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
|
|
|
+ end
|
|
|
+
|
|
|
+ local actData = human.db.absAct[id]
|
|
|
+ if not actData then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
|
|
|
+ end
|
|
|
+
|
|
|
+ local loginDay = actData.loginDay
|
|
|
+ if not loginDay or dayIndex > loginDay then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_TIME_NOT_ENOUGH)
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ local getRewardRecord = actData.getRewardRecord
|
|
|
+ if getRewardRecord then
|
|
|
+ if check(getRewardRecord, dayIndex) then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ if dayIndex > #Config then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
|
|
|
+ end
|
|
|
+
|
|
|
+ --更新db
|
|
|
+ getRewardRecord = getRewardRecord or {}
|
|
|
+ table.insert(getRewardRecord, dayIndex)
|
|
|
+ actData.getRewardRecord = getRewardRecord
|
|
|
+
|
|
|
+ --发放奖励
|
|
|
+ local targetDayReward = Config[dayIndex].item
|
|
|
+ BagLogic.addItemList(human, targetDayReward, LOGTAG)
|
|
|
+
|
|
|
+ --发下客户端更新数据
|
|
|
+ Query(human, id) --暂定使用查询协议更新数据
|
|
|
+
|
|
|
+
|
|
|
+ --更新红点
|
|
|
+ if #getRewardRecord >= loginDay then
|
|
|
+ YunYingLogic.sendBanner(human)
|
|
|
+ local config = AbsActExcel.absActivity[id]
|
|
|
+ YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
|
|
|
+ end
|
|
|
+end
|