diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 302c994..acf55a2 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -254,6 +254,7 @@ actionCodes = { Activity_advLevelRpc = 671, Activity_buyBattleCommandLvlRpc = 672, Activity_returnerTaskRpc = 673, + Activity_actNewUserTaskRpc = 674, Radio_startQuestRpc = 700, Radio_finishQuestRpc = 701, diff --git a/src/actions/ActivityAction.lua b/src/actions/ActivityAction.lua index 340a6c2..9d53c3b 100644 --- a/src/actions/ActivityAction.lua +++ b/src/actions/ActivityAction.lua @@ -320,6 +320,47 @@ function _M.actBattleCommandTaskRpc(agent, data) return true end +function _M.actNewUserTaskRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local taskId = msg.id + local calTask = role:getProperty("nbTask") or {} + local record = calTask["r"] or {} + local flag = record[taskId] or 0 + if flag == 1 then return 1 end + local open, actId = role.activity:isOpen("NewUserTask") + local actData = csvdb["activity_ctrlCsv"][actId] + if not open then return 2 end + if not actData then return 3 end + + local taskList = csvdb["activity_taskCsv"][actData.condition] + if not taskList then return 4 end + local taskCfg = taskList[taskId] + if not taskCfg then return 5 end + if taskCfg.key ~= actData.condition then return 6 end + + if (calTask[taskId] or 0) < taskCfg.condition1 then return 7 end + + record[taskId] = 1 + calTask["r"] = record + + role:updateProperty({field = "nbTask", value = calTask}) + + local reward, change = role:award(taskCfg.reward, {log = {desc = "newUserTask"}}) + + role:log("activity", { + activity_id = taskId, -- 活动ID(或活动指定任务的ID) + activity_type = role.activity.ActivityType.NewUserTask, -- 活动类型,见活动类型枚举表 + activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} + }) + + role:checkTaskEnter("FinishSpeTask", {taskId = taskId, actId = actId}) + + SendPacket(actionCodes.Activity_actNewUserTaskRpc, MsgPack.pack(role:packReward(reward, change))) + + return true +end + function _M.exchangeRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) diff --git a/src/models/Activity.lua b/src/models/Activity.lua index 8e3001c..e517890 100644 --- a/src/models/Activity.lua +++ b/src/models/Activity.lua @@ -39,6 +39,7 @@ Activity.ActivityType = { HeroBackFree = 37, -- 无损耗归还 BattleCommandTask = 38, -- 战令任务活动 + NewUserTask = 41, -- 新用户任务 } local function checkActivityType(activityType) @@ -641,6 +642,110 @@ activityFunc[Activity.ActivityType.Exchange] = { end, } +-- 新用户活动任务 +activityFunc[Activity.ActivityType.NewUserTask] = { + ["init"] = function(self, actType, isCrossDay, notify) + local nbTask = self.owner:getProperty("nbTask") + nbTask = {} + self.owner:updateProperty({field="nbTask", value=nbTask}) + local role = self.owner + local buildL = role.dinerData:getProperty("buildL") + local curLevel = buildL:getv(1, 1) + role:checkTaskEnter("DinerLevelUp", {level = curLevel}) + + role:checkTaskEnter("HeroLvlCollect", {}) + role:checkTaskEnter("HeroQualityCollect", {}) + + local curPopular = role.dinerData:getProperty("popular") + role:checkTaskEnter("DinerPopular", {count = curPopular}) + + local rLevel = role:getProperty("level") + role:checkTaskEnter("RoleLevelUp", {level = rLevel}) + + local towerInfo = role:getProperty("towerInfo") + role:checkTaskEnter("TowerPass", {count = towerInfo.l, type = 1}) + --"PvpWin" + --role:checkTaskEnter("HangPass", {id = 0}) + role:checkCalendaTask(true, 15, 3) + role:checkTaskEnter("HeroStarCollect", {}) + role:checkTaskEnter("RuneQualityCollect", {}) + + end, + ["crossDay"] = function(self, actType, notify, actId) + local actData = self.owner:getProperty("nbTask") or {} + local record = actData["r"] or {} + local actCfg = csvdb["activity_taskCsv"][actId] + if not actCfg then return end + local change = false + for taskId, cfg in pairs(actCfg) do + if cfg["resetType"] == 1 then -- 每日重置 + record[taskId] = nil + actData[taskId] = nil + change = true + end + end + if change then + self.owner:updateProperty({field="nbTask", value=actData}) + end + end, + ["crossWeek"] = function(self, actType, notify, actId) + local actData = self.owner:getProperty("nbTask") or {} + local record = actData["r"] or {} + local actCfg = csvdb["activity_taskCsv"][actId] + if not actCfg then return end + local change = false + for taskId, cfg in pairs(actCfg) do + if cfg["resetType"] == 2 then -- 每周重置 + record[taskId] = nil + actData[taskId] = nil + change = true + end + end + if change then + self.owner:updateProperty({field="nbTask", value=actData}) + end + end, + ["close"] = function(self, actType, notify) + self.owner:updateProperty({field="nbTask", value={}}) + end, +} + +-- 兑换 +activityFunc[Activity.ActivityType.Exchange] = { + ["init"] = function(self, actType, isCrossDay, notify, actId) + local actData = self:getActData(actType) or {} + actData[actId] = {} + self:updateActData(actType, actData, not notify) + end, + ["login"] = function(self, actType, actId) + activityFunc[Activity.ActivityType.Exchange]["crossDay"](self, actType, true, actId) + end, + ["crossDay"] = function(self, actType, notify, actId) + local actData = self:getActData(actType) or {} + local lastTs = actData["ts"] or 0 + local timeNow = skynet.timex() + local cfg = csvdb["activity_ctrlCsv"][actId] + if not cfg then return end + local refreshTimes = cfg.condition2:toArray(false, "=") + for i = 1, #refreshTimes do + local rt = toUnixtime(refreshTimes[i]..string_format("%02x", RESET_TIME)) + if timeNow >= rt and rt > lastTs then + lastTs = rt + actData = {} + end + end + if not next(actData) then + actData["ts"] = timeNow + self:updateActData(actType, actData, not notify) + end + end, + ["close"] = function(self, actType, notify, actId) + local actData = self:getActData(actType) or {} + actData[actId] = nil + self:updateActData(actType, actData, not notify) + end, +} + -- 扭蛋机 activityFunc[Activity.ActivityType.Gachakon] = { ["init"] = function(self, actType, isCrossDay, notify, actId) diff --git a/src/models/Role.lua b/src/models/Role.lua index 511169e..01e6dda 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -193,8 +193,9 @@ Role.schema = { downCvR = {"number", 0}, -- 下载cv扩展包奖励 feedback = {"table", {}}, -- 反馈相关信息 {flag = false, count = 0} flag是否评论过,count 提示次数 - calTask = {"table", {}}, -- 英雄令活动 日历任务活动 + calTask = {"table", {}}, -- 英雄帖活动 日历任务活动 bcTask = {"table", {}}, -- 英雄令活动 日历任务活动 临时使用 + nbTask = {"table", {}}, -- 新用户活动 radioTask = {"table", {}}, -- 电台任务 {id = {time=end_ts,heros=heros}} 表crusadeCsv seaport = {"table", {}}, -- 海岛贸易季 {time = 1234567890, donate = {}, collect = {[1] = {team = "1=2=3", time = 1234567890}}, shop = {}} @@ -436,6 +437,7 @@ function Role:data() ctime = self:getProperty("ctime"), calTask = self:getProperty("calTask"), bcTask = self:getProperty("bcTask"), + nbTask = self:getProperty("nbTask"), radioTask = self:getProperty("radioTask"), seaport = self:getProperty("seaport"), diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index 14d51d1..6fa3800 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -104,6 +104,7 @@ local ItemReason = { calendaTask = 1009, -- 英雄帖 actMilecrisis = 1010, -- 物资危机 battleCommandTask = 1011, -- 将军令任务 + newUserTask = 1012, -- 新玩家任务 -- 餐厅 greenHourse = 1101, -- 食材获得 diff --git a/src/models/RoleTask.lua b/src/models/RoleTask.lua index f98b83a..e55fc2e 100644 --- a/src/models/RoleTask.lua +++ b/src/models/RoleTask.lua @@ -323,6 +323,11 @@ local BattleCommandTaskListener = { listen = CalendaTaskListener["listen"] } +local NewUserTaskListener = { + func = "checkNewUserTask", + listen = CalendaTaskListener["listen"] +} + local ReturnerTask = { func = "checkReturnerTask", listen = CalendaTaskListener["listen"] @@ -338,6 +343,7 @@ local TaskListeners = { CalendaTaskListener, BattleCommandTaskListener, ReturnerTask, + NewUserTaskListener, } local RoleTask = {} @@ -835,6 +841,19 @@ function RoleTask.bind(Role) self:checkActTask(notNotify, keyName, actData, mainType, subType, param1, param2) end + function Role:checkNewUserTask(notNotify, mainType, subType, param1, param2) + --print("check new user task", mainType, subType, param1, param2) + local actEnum = "NewUserTask" + local keyName = "nbTask" + if not self.activity then return end + local open, actId = self.activity:isOpen(actEnum) + local actData = csvdb["activity_ctrlCsv"][actId] + if not actData then return end + if not open then return end + + self:checkActTask(notNotify, keyName, actData, mainType, subType, param1, param2) + end + function Role:checkReturnerTask(notNotify, mainType, subType, param1, param2) -- print("check returner task", mainType, subType, param1, param2) local returner = self:getProperty("returner") or {} -- libgit2 0.21.2