KLOffHookInfoItem.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. ---@class KLOffHookInfoItem:UIKmlLuaPanelBase
  2. ---@field view KLOffHookInfoItemView
  3. local KLOffHookInfoItem = class(UIKmlLuaPanelBase)
  4. local this =KLOffHookInfoItem
  5. ---创建时调用一次
  6. function this:Init()
  7. SL:KeepOpenPanel("KLOffHookInfoItem",true)
  8. GUI:setVisible(self.view.Exp, false)
  9. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_OFFLINE_ON_HOOK_INFO)
  10. end
  11. ---注册UI事件和服务器消息
  12. function this:RegistEvents()
  13. GUI:AddOnClickEvent(self.view.btnHelp, self, self.ShowHookTips)
  14. GUI:AddOnClickEvent(self.view.receiveExpBtn, self, self.ReqReceiveExpBtnOnClick)
  15. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_OFFLINE_ON_HOOK_INFO, self.RES_OFFLINE_ON_HOOK_INFO, self)
  16. end
  17. ---duration——离线挂机时长(单位秒)
  18. --fightDuration——打怪时长(单位秒)
  19. --fightExp——打怪获得的经验
  20. --freeDuration——泡点时长(单位秒)
  21. --freeExp——泡点经验
  22. --logInfo——离线挂机日志信息
  23. function this:RES_OFFLINE_ON_HOOK_INFO(_, message)
  24. --挂机信息
  25. GUI:Text_setString(self.view.txtOffline, SL:SecondToHMS(message.duration,true))
  26. GUI:Text_setString(self.view.txtFightMonsterExp, tostring(message.fightExp))
  27. GUI:Text_setString(self.view.txtFightMonsterTime, SL:SecondToHMS(message.fightDuration,true))
  28. GUI:Text_setString(self.view.txtBubbleTime, SL:SecondToHMS(message.freeDuration,true))
  29. GUI:Text_setString(self.view.txtBubbleExp, tostring(message.freeExp))
  30. GUI:Text_setString(self.view.totleExp, tostring(message.totalExp))
  31. GUI:setVisible(self.view.Exp, tonumber(message.totalExp) > 0 and message.receiveExp == false)
  32. --处理日志信息
  33. local logInfo = message.logInfo
  34. ---@type cfg_item_column[]
  35. local cfgs = {}
  36. local strList = {}
  37. local sortList = {}
  38. for k, v in pairs(logInfo.recoveredMoneyAmountMap) do
  39. for id, num in pairs(v) do
  40. if not cfgs[id] then
  41. cfgs[id] = SL:GetConfig("cfg_item", tonumber(id))
  42. end
  43. local time = tonumber(k)
  44. local str = string.format("%s 本次离线挂机自动回收获得%s*%s\n", self:FormatTime(time),cfgs[id].name, num)
  45. table.insert(strList, str)
  46. sortList[str] = time
  47. end
  48. end
  49. for k, v in pairs(logInfo.pickupMoneyAmountMap) do
  50. for id, num in pairs(v) do
  51. if not cfgs[id] then
  52. cfgs[id] = SL:GetConfig("cfg_item", tonumber(id))
  53. end
  54. local time = tonumber(k)
  55. local str = string.format("%s 本次离线挂机拾取%s*%s\n", self:FormatTime(time),cfgs[id].name, num)
  56. table.insert(strList, str)
  57. sortList[str] = time
  58. end
  59. end
  60. for k, v in pairs(logInfo.killedInfoMap) do
  61. for id, name in pairs(v) do
  62. ---@type cfg_map_info_column
  63. local cfg = SL:GetConfig("cfg_map_info", tonumber(id))
  64. local time = tonumber(k)
  65. local str = string.format("%s 在%s被%s击杀\n", self:FormatTime(time), cfg.mapname, name)
  66. table.insert(strList, str)
  67. sortList[str] = time
  68. end
  69. end
  70. if not table.isNullOrEmpty(message.openBubbleMap) then
  71. for k, v in pairs(message.openBubbleMap) do
  72. ---@type cfg_map_info_column
  73. local cfg = SL:GetConfig("cfg_map_info", v)
  74. local time = tonumber(k)
  75. local str = string.format("%s 在%s开启泡点\n", self:FormatTime(time), cfg.mapname)
  76. table.insert(strList, str)
  77. sortList[str] = time
  78. end
  79. end
  80. if message.timeout then
  81. ---@type cfg_global_column
  82. local global = SL:GetConfig("cfg_global", 6001)
  83. local hookTime = tonumber(global.value) // 60
  84. local time = tonumber(message.timeout)
  85. local str_ = string.format("%s <color=#FF2323>离线收益累计已达%s小时</color>,再次登录可重新获得离线收益\n", self:FormatTime(time), hookTime)
  86. table.insert(strList, str_)
  87. sortList[str_] = time
  88. end
  89. --按照时间排序
  90. table.sort(strList, function(a, b)
  91. if sortList[a] and sortList[b] then
  92. return sortList[a] > sortList[b]
  93. end
  94. end)
  95. local resStr = table.concat(strList) or ""
  96. --[[ if resStr ~= "" then
  97. string.replace(resStr, " ", "\\u3000")
  98. end]]
  99. GUI:Text_setString(self.view.logInfoTxt, resStr)
  100. end
  101. function this:ReqReceiveExpBtnOnClick()
  102. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECEIVE_OFFLINE_ON_HOOK_EXP)
  103. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_OFFLINE_ON_HOOK_INFO)
  104. end
  105. function this:ShowHookTips()
  106. local tbl = SL:GetConfig("cfg_rule_text", 9)
  107. SL:CommonStrTipsMessage({str = tbl.location, title="提示"})
  108. end
  109. ---创建或者刷新界面数据时调用
  110. function this:Refresh()
  111. end
  112. function this:Close()
  113. SL:KeepOpenPanel("KLOffHookInfoItem",false)
  114. end
  115. function this:FormatTime(time)
  116. return os.date("<color=#A3917E>%m-%d %H:%M:%S</color>", math.floor(time / 1000))
  117. end
  118. return this