From 284482c639e450a29dd69cc4b6b2b15d95bb299b Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Thu, 7 May 2020 20:30:37 +0800 Subject: [PATCH] 冒险成就 --- src/actions/AdvAction.lua | 2 ++ src/actions/GmAction.lua | 1 - src/adv/AdvTask.lua | 40 ++++++++++++++++++++++++++++------------ src/models/Role.lua | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 2c24597..00e9c48 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -511,6 +511,8 @@ function _M.upArtifactRpc(agent, data) adv:backCost(cost) if status == 1 then -- 现在穿着呢。更新下 adv:saveDB() + else + adv:updateAchievement() end SendPacket(actionCodes.Adv_upArtifactRpc, '') return true diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 998e6bb..89e0917 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -213,7 +213,6 @@ function _M.fbc(role, pms) -- 直接通关 end end addPre(carbonId) - role:updateProperty({field = "hangInfo", value = {}}) role:updateProperty({field = "hangPass", value = passCarbon}) role:checkTaskEnter("HangPass", {id = carbonId}) diff --git a/src/adv/AdvTask.lua b/src/adv/AdvTask.lua index 7b0433d..74894b4 100644 --- a/src/adv/AdvTask.lua +++ b/src/adv/AdvTask.lua @@ -248,18 +248,33 @@ function AdvTask.bind(Adv) local advAchievChange = {} - local function insertChange(chapterId, taskId, value, pts) + local function insertChange(self, chapterId, taskId, value, pts) local achievField = AdvCommon.isEndless(chapterId) and "advEAchiev" or "advAchiev" + local dbData = self.owner:getProperty(achievField) if pts then - table.insert(advAchievChange, {type = achievField, field = {chapterId, "pts", taskId}, value = value}) + advAchievChange[achievField] = advAchievChange[achievField] or {} + advAchievChange[achievField][chapterId] = advAchievChange[achievField][chapterId] or {} + advAchievChange[achievField][chapterId]["pts"] = advAchievChange[achievField][chapterId]["pts"] or {} + advAchievChange[achievField][chapterId]["pts"][taskId] = value + + dbData[chapterId] = dbData[chapterId] or {} + dbData[chapterId]["pts"] = dbData[chapterId]["pts"] or {} + dbData[chapterId]["pts"][taskId] = value else - table.insert(advAchievChange, {type = achievField, field = {chapterId, taskId}, value = value}) + advAchievChange[achievField] = advAchievChange[achievField] or {} + advAchievChange[achievField][chapterId] = advAchievChange[achievField][chapterId] or {} + advAchievChange[achievField][chapterId][taskId] = value + + dbData[chapterId] = dbData[chapterId] or {} + dbData[chapterId][taskId] = value end end function Adv:checkAchievement(taskType, count, cond, cond2) local achievField = self:isEndless() and "advEAchiev" or "advAchiev" - local advAchiev = self.owner:getProperty(achievField)[self.chapterId] or {} + local dbData = self.owner:getProperty(achievField) + dbData[self.chapterId] = dbData[self.chapterId] or {} + local advAchiev = dbData[self.chapterId] for taskId , data in pairs(csvdb["adv_achievementCsv"][self.chapterId] or {}) do local oldStatus = advAchiev[taskId] or 0 if oldStatus ~= -1 and data.type == taskType then @@ -332,18 +347,18 @@ function AdvTask.bind(Adv) if self:isEndless() then if status and status ~= oldStatus then - insertChange(self.chapterId, taskId, status) + insertChange(self, self.chapterId, taskId, status) end else if (status or -1) >= data.value1 then status = -1 end if status and status ~= oldStatus then - insertChange(self.chapterId, taskId, status) + insertChange(self, self.chapterId, taskId, status) if status == -1 then - local ptcount = (self.owner:getProperty(achievField)[self.chapterId] or {})[-1] or 0 + local ptcount = advAchiev[-1] or 0 ptcount = ptcount + data.pt - insertChange(self.chapterId, -1, ptcount) + insertChange(self, self.chapterId, -1, ptcount) end end end @@ -361,10 +376,10 @@ function AdvTask.bind(Adv) local reward = {} if status >= achievData.value1 then - insertChange(chapterId, taskId, -1) + insertChange(self, chapterId, taskId, -1) local count = (self.owner:getProperty(achievField)[chapterId] or {})[-1] or 0 count = count + achievData.pt - insertChange(chapterId, -1, count) + insertChange(self, chapterId, -1, count) -- 发放奖励 reward = self.owner:award(achievData.reward, {log = {desc = "advAchiev", int1 = chapterId, int2 = taskId}}) @@ -380,13 +395,14 @@ function AdvTask.bind(Adv) if status == -1 or count < achievData.pt then return end local reward = self.owner:award(achievData.reward, {log = {desc = "advAchievReward", int1 = chapterId, int2 = taskId}}) - insertChange(chapterId, taskId, -1, true) + insertChange(self, chapterId, taskId, -1, true) return true, reward end function Adv:updateAchievement(notNotify) if not next(advAchievChange) then return end - self.owner:changeUpdates(advAchievChange, notNotify) + self.owner:changeMapUpdates(advAchievChange, notNotify) + advAchievChange = {} end end diff --git a/src/models/Role.lua b/src/models/Role.lua index d2152dc..550f574 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -192,8 +192,39 @@ function Role:notifyUpdateProperties(params) SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params)) end +local mapToList +mapToList = function(map) + local result = {} + if type(map) == "table" then + for k, v in pairs(map) do + for _, _one in ipairs(mapToList(v)) do + table.insert(result, {k, table.unpack(_one)}) + end + end + else + table.insert(result, {map}) + end + return result +end + +function Role:changeMapUpdates(params, notNotify) + local changes = {} + for _, one in ipairs(mapToList(params)) do + local ftype = table.remove(one, 1) + local value = table.remove(one, #one) + if ftype and value and #one > 0 then + table.insert(changes, {type = ftype, field = #one > 1 and one or one[1], value = value}) + else + print("ERROR: changeMapUpdates") + dump(params) + end + end + self:changeUpdates(changes, notNotify) +end + -- 某些字段 更新改变量 改变量的定义由字段自身决定 {{type = ""}, } function Role:changeUpdates(params, notNotify) + local needSetProperty = {} local changeUpdateFunc = { -- ["loveStatus"] = function(info) -- self:setProperty("loveStatus", self:getProperty("loveStatus"):setv(info["field"], info["value"])) @@ -219,7 +250,7 @@ function Role:changeUpdates(params, notNotify) else curValue[info["field"]] = info["value"] end - self:setProperty(fieldType) + needSetProperty[fieldType] = 1 return {type = fieldType, field = info["field"], value = info["value"]} end, ["onlyToC"] = function(info) @@ -238,6 +269,10 @@ function Role:changeUpdates(params, notNotify) table.insert(updates, changeUpdateFunc["tableCommon"](one["type"], one)) end end + + for fieldType, _ in pairs(needSetProperty) do + self:setProperty(fieldType) + end if not notNotify and next(updates) then SendPacket(actionCodes.Role_changeUpdate, MsgPack.pack(updates)) end -- libgit2 0.21.2