BattleDBLogic.lua 2.5 KB

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