GodsDescendInfo.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. ---@class GodsDescendInfo @注释
  2. ---@field godsDescendData {id:number, cfgid:number, name:string, state:number, ownerid:number, ownername:string}[]
  3. GodsDescendInfo = class()
  4. local this = GodsDescendInfo
  5. function this:ctor()
  6. end
  7. function this:Init()
  8. this.godsDescendData = {}
  9. this.deadStates = {}
  10. self:RegistMessages()
  11. end
  12. function this:RegistMessages()
  13. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GODS_DESCENDED_DATA , self.RES_GODS_DESCENDED_DATA)
  14. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GODS_DESCENDED_MONSTER_STATE_CHANGE , self.RES_GODS_DESCENDED_MONSTER_STATE_CHANGE)
  15. end
  16. ---@param message {monsterdata:table}
  17. function this.RES_GODS_DESCENDED_DATA(id, message)
  18. table.clear(this.godsDescendData)
  19. table.clear(this.deadStates)
  20. for mapId, v in pairs(message.monsterdata) do
  21. if not this.godsDescendData[mapId] then
  22. this.godsDescendData[mapId] = {}
  23. end
  24. if not this.deadStates[mapId] then
  25. this.deadStates[mapId] = {}
  26. end
  27. for k, value in pairs(v) do
  28. if not this.godsDescendData[mapId][k] then
  29. this.godsDescendData[mapId][k] = {}
  30. end
  31. ---@param data {id:number, cfgid:number, name:string, state:number, ownerid:number, ownername:string}
  32. for _, data in pairs(value) do
  33. this.godsDescendData[mapId][k][data.id] = data
  34. this.deadStates[mapId][data.id] = data.state
  35. end
  36. end
  37. end
  38. SL:onLUAEvent(LUA_EVENT_GODSDESCEND_DATA_CHANGE)
  39. SL:RefreshPanelALLRedStateKmlByCondition("checkGodDescentMonster")
  40. end
  41. ---@param message {id:number, mapid:number, cfgid:number, name:string, state:number, ownerid:number, ownername:string}[]
  42. function this.RES_GODS_DESCENDED_MONSTER_STATE_CHANGE(id, message)
  43. for mapId, v in pairs(message) do
  44. if not this.godsDescendData[mapId] then
  45. this.godsDescendData[mapId] = {}
  46. end
  47. if not this.deadStates[mapId] then
  48. this.deadStates[mapId] = {}
  49. end
  50. if not this.godsDescendData[mapId][v.cfgid] then
  51. this.godsDescendData[mapId][v.cfgid] = {}
  52. end
  53. this.godsDescendData[mapId][v.cfgid][v.id] = v
  54. this.deadStates[mapId][v.id] = v.state
  55. end
  56. SL:onLUAEvent(LUA_EVENT_GODSDESCEND_DATA_CHANGE, message)
  57. SL:RefreshPanelALLRedStateKmlByCondition("checkGodDescentMonster")
  58. end
  59. ---@return {id:number, cfgid:number, name:string, state:number, ownerid:number, ownername:string}[]
  60. function this.GetMonsterInfosByCfgId(cfgId)
  61. cfgId = tostring(cfgId)
  62. local res = {}
  63. for mapId, v in pairs(this.godsDescendData) do
  64. if v[cfgId] then
  65. for _, data in pairs(v[cfgId]) do
  66. table.insert(res, data)
  67. end
  68. end
  69. end
  70. return res
  71. end
  72. ---@return {id:number, cfgid:number, name:string, state:number, ownerid:number, ownername:string}
  73. function this.GetMonsterInfosById(cfgId, id)
  74. for mapId, v in pairs(this.godsDescendData) do
  75. if v[cfgId] and v[cfgId][id] then
  76. return v[cfgId][id]
  77. end
  78. end
  79. return nil
  80. end
  81. --获取是否有怪物存活(红点状态)
  82. function this.GetRedState()
  83. local red = false
  84. for _, v in pairs(this.deadStates) do
  85. for k, data in pairs(v) do
  86. if data ~= 2 then
  87. red = true
  88. break
  89. end
  90. end
  91. end
  92. return red
  93. end
  94. function this.CheckActivityCondition(id)
  95. local message = ""
  96. ---@type cfg_activity_rule_column
  97. -- local tbl = SL:GetConfig("cfg_activity_rule", id)
  98. -- if tbl.condition and tbl.condition[1] then
  99. -- local condition = tbl.condition[1]
  100. -- local level = condition[1]
  101. -- local strength_level = condition[2]
  102. -- local append_level = condition[3]
  103. -- local player_level = SL:GetMetaValue("LEVEL")
  104. -- local all_strength_level = EquipFunc.GetAllStrengthLevel()
  105. -- local all_append_level = EquipFunc.GetAllAppendLevel()
  106. -- if player_level < level then
  107. -- message = level.."级开启,无法进入"
  108. -- return false, message
  109. -- end
  110. -- if all_strength_level < strength_level then
  111. -- return false, SL:GetConfig('cfg_string',257).text
  112. -- end
  113. -- if all_append_level < append_level then
  114. -- return false, SL:GetConfig('cfg_string',257).text
  115. -- end
  116. -- --[[ if not this.IsHavePrivilege() then
  117. -- return false, SL:GetConfig('cfg_string',258).text
  118. -- end]]
  119. -- end
  120. return true, message
  121. end
  122. function this.CheckActivityConditionMapId(id)
  123. local message = ""
  124. ---@type cfg_activity_rule_column
  125. local mapid = SL:GetConfig("cfg_activity_rule",id).mapid[1]
  126. local tbl = SL:GetConfig("cfg_map_info",mapid)
  127. if tbl.condition and #tbl.condition > 0 then
  128. local condition = tbl.condition
  129. local level = condition[1]
  130. local strength_level = condition[2]
  131. local append_level = condition[3]
  132. local player_level = SL:GetMetaValue("LEVEL")
  133. local all_strength_level = EquipFunc.GetAllStrengthLevel()
  134. local all_append_level = EquipFunc.GetAllAppendLevel()
  135. if player_level < level then
  136. message = level.."级开启,无法进入"
  137. return false, message
  138. end
  139. if all_strength_level < strength_level then
  140. return false, SL:GetConfig('cfg_string',257).text
  141. end
  142. if all_append_level < append_level then
  143. return false, SL:GetConfig('cfg_string',257).text
  144. end
  145. --[[ if not this.IsHavePrivilege() then
  146. return false, SL:GetConfig('cfg_string',258).text
  147. end]]
  148. end
  149. return true, message
  150. end
  151. function this.IsHavePrivilege()
  152. if InfoManager.monthCardInfo.IsGetMonthCard or InfoManager.monthCardInfo.IsGetDailyCard then
  153. --有月卡或是日卡
  154. return true
  155. end
  156. return false
  157. end
  158. function this:Reset()
  159. this.godsDescendData = {}
  160. this.deadStates = {}
  161. end