Commit 284482c639e450a29dd69cc4b6b2b15d95bb299b

Authored by zhouhaihai
1 parent 56484297

冒险成就

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