Commit 284482c639e450a29dd69cc4b6b2b15d95bb299b

Authored by zhouhaihai
1 parent 56484297

冒险成就

src/actions/AdvAction.lua
... ... @@ -511,6 +511,8 @@ function _M.upArtifactRpc(agent, data)
511 511 adv:backCost(cost)
512 512 if status == 1 then -- 现在穿着呢。更新下
513 513 adv:saveDB()
  514 + else
  515 + adv:updateAchievement()
514 516 end
515 517 SendPacket(actionCodes.Adv_upArtifactRpc, '')
516 518 return true
... ...
src/actions/GmAction.lua
... ... @@ -213,7 +213,6 @@ function _M.fbc(role, pms) -- 直接通关
213 213 end
214 214 end
215 215 addPre(carbonId)
216   - role:updateProperty({field = "hangInfo", value = {}})
217 216 role:updateProperty({field = "hangPass", value = passCarbon})
218 217 role:checkTaskEnter("HangPass", {id = carbonId})
219 218  
... ...
src/adv/AdvTask.lua
... ... @@ -248,18 +248,33 @@ function AdvTask.bind(Adv)
248 248  
249 249 local advAchievChange = {}
250 250  
251   - local function insertChange(chapterId, taskId, value, pts)
  251 + local function insertChange(self, chapterId, taskId, value, pts)
252 252 local achievField = AdvCommon.isEndless(chapterId) and "advEAchiev" or "advAchiev"
  253 + local dbData = self.owner:getProperty(achievField)
253 254 if pts then
254   - table.insert(advAchievChange, {type = achievField, field = {chapterId, "pts", taskId}, value = value})
  255 + advAchievChange[achievField] = advAchievChange[achievField] or {}
  256 + advAchievChange[achievField][chapterId] = advAchievChange[achievField][chapterId] or {}
  257 + advAchievChange[achievField][chapterId]["pts"] = advAchievChange[achievField][chapterId]["pts"] or {}
  258 + advAchievChange[achievField][chapterId]["pts"][taskId] = value
  259 +
  260 + dbData[chapterId] = dbData[chapterId] or {}
  261 + dbData[chapterId]["pts"] = dbData[chapterId]["pts"] or {}
  262 + dbData[chapterId]["pts"][taskId] = value
255 263 else
256   - table.insert(advAchievChange, {type = achievField, field = {chapterId, taskId}, value = value})
  264 + advAchievChange[achievField] = advAchievChange[achievField] or {}
  265 + advAchievChange[achievField][chapterId] = advAchievChange[achievField][chapterId] or {}
  266 + advAchievChange[achievField][chapterId][taskId] = value
  267 +
  268 + dbData[chapterId] = dbData[chapterId] or {}
  269 + dbData[chapterId][taskId] = value
257 270 end
258 271 end
259 272  
260 273 function Adv:checkAchievement(taskType, count, cond, cond2)
261 274 local achievField = self:isEndless() and "advEAchiev" or "advAchiev"
262   - local advAchiev = self.owner:getProperty(achievField)[self.chapterId] or {}
  275 + local dbData = self.owner:getProperty(achievField)
  276 + dbData[self.chapterId] = dbData[self.chapterId] or {}
  277 + local advAchiev = dbData[self.chapterId]
263 278 for taskId , data in pairs(csvdb["adv_achievementCsv"][self.chapterId] or {}) do
264 279 local oldStatus = advAchiev[taskId] or 0
265 280 if oldStatus ~= -1 and data.type == taskType then
... ... @@ -332,18 +347,18 @@ function AdvTask.bind(Adv)
332 347  
333 348 if self:isEndless() then
334 349 if status and status ~= oldStatus then
335   - insertChange(self.chapterId, taskId, status)
  350 + insertChange(self, self.chapterId, taskId, status)
336 351 end
337 352 else
338 353 if (status or -1) >= data.value1 then
339 354 status = -1
340 355 end
341 356 if status and status ~= oldStatus then
342   - insertChange(self.chapterId, taskId, status)
  357 + insertChange(self, self.chapterId, taskId, status)
343 358 if status == -1 then
344   - local ptcount = (self.owner:getProperty(achievField)[self.chapterId] or {})[-1] or 0
  359 + local ptcount = advAchiev[-1] or 0
345 360 ptcount = ptcount + data.pt
346   - insertChange(self.chapterId, -1, ptcount)
  361 + insertChange(self, self.chapterId, -1, ptcount)
347 362 end
348 363 end
349 364 end
... ... @@ -361,10 +376,10 @@ function AdvTask.bind(Adv)
361 376  
362 377 local reward = {}
363 378 if status >= achievData.value1 then
364   - insertChange(chapterId, taskId, -1)
  379 + insertChange(self, chapterId, taskId, -1)
365 380 local count = (self.owner:getProperty(achievField)[chapterId] or {})[-1] or 0
366 381 count = count + achievData.pt
367   - insertChange(chapterId, -1, count)
  382 + insertChange(self, chapterId, -1, count)
368 383  
369 384 -- 发放奖励
370 385 reward = self.owner:award(achievData.reward, {log = {desc = "advAchiev", int1 = chapterId, int2 = taskId}})
... ... @@ -380,13 +395,14 @@ function AdvTask.bind(Adv)
380 395 if status == -1 or count < achievData.pt then return end
381 396  
382 397 local reward = self.owner:award(achievData.reward, {log = {desc = "advAchievReward", int1 = chapterId, int2 = taskId}})
383   - insertChange(chapterId, taskId, -1, true)
  398 + insertChange(self, chapterId, taskId, -1, true)
384 399 return true, reward
385 400 end
386 401  
387 402 function Adv:updateAchievement(notNotify)
388 403 if not next(advAchievChange) then return end
389   - self.owner:changeUpdates(advAchievChange, notNotify)
  404 + self.owner:changeMapUpdates(advAchievChange, notNotify)
  405 + advAchievChange = {}
390 406 end
391 407  
392 408 end
... ...
src/models/Role.lua
... ... @@ -192,8 +192,39 @@ function Role:notifyUpdateProperties(params)
192 192 SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params))
193 193 end
194 194  
  195 +local mapToList
  196 +mapToList = function(map)
  197 + local result = {}
  198 + if type(map) == "table" then
  199 + for k, v in pairs(map) do
  200 + for _, _one in ipairs(mapToList(v)) do
  201 + table.insert(result, {k, table.unpack(_one)})
  202 + end
  203 + end
  204 + else
  205 + table.insert(result, {map})
  206 + end
  207 + return result
  208 +end
  209 +
  210 +function Role:changeMapUpdates(params, notNotify)
  211 + local changes = {}
  212 + for _, one in ipairs(mapToList(params)) do
  213 + local ftype = table.remove(one, 1)
  214 + local value = table.remove(one, #one)
  215 + if ftype and value and #one > 0 then
  216 + table.insert(changes, {type = ftype, field = #one > 1 and one or one[1], value = value})
  217 + else
  218 + print("ERROR: changeMapUpdates")
  219 + dump(params)
  220 + end
  221 + end
  222 + self:changeUpdates(changes, notNotify)
  223 +end
  224 +
195 225 -- 某些字段 更新改变量 改变量的定义由字段自身决定 {{type = ""}, }
196 226 function Role:changeUpdates(params, notNotify)
  227 + local needSetProperty = {}
197 228 local changeUpdateFunc = {
198 229 -- ["loveStatus"] = function(info)
199 230 -- self:setProperty("loveStatus", self:getProperty("loveStatus"):setv(info["field"], info["value"]))
... ... @@ -219,7 +250,7 @@ function Role:changeUpdates(params, notNotify)
219 250 else
220 251 curValue[info["field"]] = info["value"]
221 252 end
222   - self:setProperty(fieldType)
  253 + needSetProperty[fieldType] = 1
223 254 return {type = fieldType, field = info["field"], value = info["value"]}
224 255 end,
225 256 ["onlyToC"] = function(info)
... ... @@ -238,6 +269,10 @@ function Role:changeUpdates(params, notNotify)
238 269 table.insert(updates, changeUpdateFunc["tableCommon"](one["type"], one))
239 270 end
240 271 end
  272 +
  273 + for fieldType, _ in pairs(needSetProperty) do
  274 + self:setProperty(fieldType)
  275 + end
241 276 if not notNotify and next(updates) then
242 277 SendPacket(actionCodes.Role_changeUpdate, MsgPack.pack(updates))
243 278 end
... ...