GameMapHeart.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. GameMapHeart = {}
  2. local TIME_TAG = "G$_MAP_HEART_TIME"
  3. function GameMapHeart.getMapHeartTime()
  4. local timeMap = getsysvar(TIME_TAG)
  5. if timeMap == nil then
  6. timeMap = {}
  7. timeMap[1] = {}
  8. timeMap[3] = {}
  9. timeMap[5] = {}
  10. setsysvar(TIME_TAG, timeMap)
  11. end
  12. return timeMap
  13. end
  14. function GameMapHeart.setMapHeartTime(allTimeMap)
  15. setsysvar(TIME_TAG, allTimeMap)
  16. end
  17. function GameMapHeart.getTime(timeMap, uniMapId)
  18. local time = table.getValue(timeMap, uniMapId)
  19. if time == nil then
  20. return 0
  21. end
  22. return time
  23. end
  24. function GameMapHeart.setTime(allTimeMap, timeMap, uniMapId, timeSec)
  25. setsysvar(TIME_TAG, allTimeMap)
  26. end
  27. function GameMapHeart.AddMap(uniMapId)
  28. end
  29. function GameMapHeart.RemoveMap(uniMapId)
  30. local allMapTime = GameMapHeart.getMapHeartTime()
  31. for _, timeInfo in pairs(allMapTime) do
  32. timeInfo[uniMapId] = nil
  33. end
  34. end
  35. function GameMapHeart.doSecondHeart(allTimeMap, nowSec, uniMapId, mapId)
  36. local mapSecondHeartTime = allTimeMap[1]
  37. local diff = nowSec - GameMapHeart.getTime(mapSecondHeartTime, uniMapId)
  38. if diff >= 1 then
  39. mapSecondHeartTime[uniMapId] = nowSec
  40. if lua_mapsecondheart ~= nil then
  41. gameDebug.debug(lua_mapsecondheart, uniMapId, mapId)
  42. end
  43. end
  44. end
  45. function GameMapHeart.do3SecondHeart(allTimeMap, nowSec, uniMapId, mapId)
  46. local map3secondHeartTime = allTimeMap[3]
  47. local diff = nowSec - GameMapHeart.getTime(map3secondHeartTime, uniMapId)
  48. if diff >= 3 then
  49. map3secondHeartTime[uniMapId] = nowSec
  50. if lua_map3secondheart ~= nil then
  51. gameDebug.debug(lua_map3secondheart, uniMapId, mapId)
  52. end
  53. end
  54. end
  55. function GameMapHeart.do5SecondHeart(allTimeMap, nowSec, uniMapId, mapId)
  56. local map5secondHeartTime = allTimeMap[5]
  57. local diff = nowSec - GameMapHeart.getTime(map5secondHeartTime, uniMapId)
  58. if diff >= 5 then
  59. map5secondHeartTime[uniMapId] = nowSec
  60. if lua_map5secondheart ~= nil then
  61. gameDebug.debug(lua_map5secondheart, uniMapId, mapId)
  62. end
  63. end
  64. end
  65. function GameMapHeart.DoHeart()
  66. local allmap = getallmap(1)
  67. local type = type(allmap)
  68. if type == "string" then
  69. allmap = string.split(allmap, ",")
  70. end
  71. local allTimeMap = GameMapHeart.getMapHeartTime()
  72. --此处不依赖系统时间,可以用lua time库
  73. local nowSec = os.time()
  74. for _, uniMapId in pairs(allmap) do
  75. local mapCfgId, _ = gamemap.parseMapKey(uniMapId)
  76. gameDebug.debug(GameMapHeart.doSecondHeart, allTimeMap, nowSec, uniMapId, mapCfgId)
  77. gameDebug.debug(GameMapHeart.do3SecondHeart, allTimeMap, nowSec, uniMapId, mapCfgId)
  78. gameDebug.debug(GameMapHeart.do5SecondHeart, allTimeMap, nowSec, uniMapId, mapCfgId)
  79. end
  80. GameMapHeart.setMapHeartTime(allTimeMap)
  81. end