BattleDBLogic.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. local Config = require("Config")
  2. local LuaMongo = _G.lua_mongo
  3. local DB = require("common.DB")
  4. local Util = require("common.Util")
  5. local CommonDB = require("common.CommonDB")
  6. local CombatLogic = require("combat.CombatLogic")
  7. local QueryByNodeID = {nodeID = nil}
  8. function queryBattleDbByNodeID(nodeID)
  9. QueryByNodeID.nodeID = nodeID
  10. LuaMongo.find(DB.db_battle_shark, QueryByNodeID)
  11. local videoDb = {}
  12. return LuaMongo.next(videoDb) and videoDb
  13. end
  14. function updateBattleDB(roleBase,nodeID,combatInfo,videoUuid)
  15. local videoTb = queryBattleDbByNodeID(nodeID)
  16. local now = os.time()
  17. -- 如果没有战斗记录,插入战斗记录
  18. local useTime = CombatLogic.getCombatUseTime(combatInfo)
  19. if videoTb == nil then
  20. local video = {}
  21. video.nodeID = nodeID
  22. video.shark = {{},{},{}}
  23. video.shark[1].param = roleBase.zhandouli
  24. video.shark[1].videoUuid = videoUuid
  25. video.shark[1].roleBase = roleBase
  26. video.shark[2].param = useTime
  27. video.shark[2].videoUuid = videoUuid
  28. video.shark[2].roleBase = roleBase
  29. video.shark[3].param = now
  30. video.shark[3].videoUuid = videoUuid
  31. video.shark[3].roleBase = roleBase
  32. LuaMongo.insert(DB.db_battle_shark, video)
  33. else
  34. local tempShark = videoTb.shark
  35. local isChange = nil
  36. -- 如果战力小,更换Uuid
  37. if roleBase.zhandouli < (videoTb.shark[1].param or 0) then
  38. tempShark[1].param = roleBase.zhandouli
  39. tempShark[1].videoUuid = videoUuid
  40. tempShark[1].roleBase = roleBase
  41. isChange = true
  42. end
  43. -- 拿出通关时间最短Uuid
  44. if useTime < videoTb.shark[2].param then
  45. tempShark[2].param = useTime
  46. tempShark[2].videoUuid = videoUuid
  47. tempShark[2].roleBase = roleBase
  48. isChange = true
  49. end
  50. -- 拿出通关时间最近Uuid
  51. if now > videoTb.shark[3].param then
  52. tempShark[3].param = now
  53. tempShark[3].videoUuid = videoUuid
  54. tempShark[3].roleBase = roleBase
  55. isChange = true
  56. end
  57. QueryByNodeID.nodeID = nodeID
  58. LuaMongo.update(DB.db_battle_shark,QueryByNodeID,videoTb)
  59. end
  60. end