RoleSystemLogic.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. local RoleSystemExcel = require("excel.roleSystem")
  2. local Util = require("common.Util")
  3. local Lang = require("common.Lang")
  4. local CommonDB = require("common.CommonDB")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local Broadcast = require("broadcast.Broadcast")
  8. local DrillLogic = require("drill.DrillLogic")
  9. local ZhuanpanExcel = require("excel.zhuanpan")
  10. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  11. DOUBLE_NEED_LV = 10 -- 福利双倍 开启等级
  12. --邮件提示ID
  13. ROLE_MAILTIPS_ID1 = 1 --圣树试炼
  14. ROLE_SYS_OPEN_ID_START = 1 --
  15. ROLE_SYS_OPEN_ID_END = 50 --
  16. local function initDB(human)
  17. human.db.roleSys = human.db.roleSys or {}
  18. end
  19. function initAfterHot()
  20. for id, conf in pairs(RoleSystemExcel.roleSystem) do
  21. conf.id = id
  22. if conf.modulePath == "" then
  23. else
  24. conf.module = load("return require(\""..conf.modulePath.."\")")()
  25. end
  26. end
  27. end
  28. function isOpen(human, id, sendErr)
  29. local config = RoleSystemExcel.roleSystem[id]
  30. if not config then
  31. return
  32. end
  33. -- 开服天数
  34. if config.openSvrDay > 0 then
  35. local openDay = CommonDB.getServerOpenDay()
  36. if not openDay then
  37. if sendErr then
  38. Broadcast.sendErr(human, Lang.COMMON_SYSTEM_NEED_OPENTIME)
  39. end
  40. return false, config
  41. end
  42. if openDay < config.openSvrDay then
  43. if sendErr then
  44. Broadcast.sendErr(human, Util.format(Lang.COMMON_SYSTEM_OPENTIME, config.openSvrDay))
  45. end
  46. return false, config
  47. end
  48. end
  49. -- 等级
  50. if human.db.lv < config.lv then
  51. if sendErr then
  52. Broadcast.sendErr(human, Util.format(Lang.COMMON_SYSTEM_OPENTIP, config.lv))
  53. end
  54. return false, config
  55. end
  56. -- 寻星
  57. if id == RoleSystemDefine.ROLE_SYS_ID_501 then
  58. local now = os.time()
  59. local zpOpenTime = os.time(ZhuanpanExcel.define[1].time)
  60. if now < zpOpenTime then
  61. return false
  62. end
  63. end
  64. return true, config
  65. end
  66. -- 等级达到x级
  67. ROLE_SYSTEM_OPEN_NEED_LV = {}
  68. function getOpenLv(id)
  69. if ROLE_SYSTEM_OPEN_NEED_LV[id] then
  70. return ROLE_SYSTEM_OPEN_NEED_LV[id]
  71. end
  72. local config = RoleSystemExcel.roleSystem[id]
  73. if config then
  74. ROLE_SYSTEM_OPEN_NEED_LV[id] = config.lv
  75. return ROLE_SYSTEM_OPEN_NEED_LV[id]
  76. end
  77. return 0
  78. end
  79. -- 开服x天后开启
  80. function getOpenSvrDay(id)
  81. local config = RoleSystemExcel.roleSystem[id]
  82. if config.openSvrDay > 0 then
  83. local openDay = CommonDB.getServerOpenDay()
  84. if not openDay or openDay < config.openSvrDay then
  85. return config and config.openSvrDay or 0
  86. end
  87. end
  88. return 0
  89. end
  90. -- 获取开启条件说明
  91. function getOpenDesc(id)
  92. local config = RoleSystemExcel.roleSystem[id]
  93. if not config then return "" end
  94. if config.lv >= 999 then
  95. return Lang.COMMON_SYSTEM_READY
  96. end
  97. if config.openSvrDay > 0 and config.lv > 1 then
  98. return Util.format(Lang.COMMON_SYSTEM_OPENLV_TIME, config.lv, config.openSvrDay)
  99. end
  100. if config.openSvrDay > 0 then
  101. return Util.format(Lang.COMMON_SYSTEM_OPENTIME, config.openSvrDay)
  102. end
  103. return Util.format(Lang.COMMON_SYSTEM_OPENTIP, config.lv)
  104. end
  105. -- 不发送客户端
  106. local function isNoSend(id)
  107. return id > 10000
  108. end
  109. -- 是否有红点
  110. local function isDot(human,config)
  111. if human.db.lv < config.dotLv then
  112. return false
  113. end
  114. if config.module and config.module.isDot and config.module.isDot(human,config) then
  115. return true
  116. end
  117. return false
  118. end
  119. function touch(human, id)
  120. local roleExcel = RoleSystemExcel.roleSystem[id]
  121. if not roleExcel then return end
  122. if roleExcel.touch ~= 1 then return end
  123. local touch = human.db.roleSys[id]
  124. if not touch then return end
  125. human.db.roleSys[id] = 0
  126. onDot(human, id, true)
  127. end
  128. function open(human, id)
  129. if not human.db.roleSysOpen then
  130. human.db.roleSysOpen = {}
  131. end
  132. local len = #human.db.roleSysOpen
  133. if len >= ROLE_SYS_OPEN_ID_END then return end
  134. len = len + 1
  135. human.db.roleSysOpen[len] = id
  136. end
  137. -- 封装结构体
  138. local function wrapAll(human, mem, net, config)
  139. mem[config.id] = false
  140. net.id = config.id
  141. net.lv = getOpenLv(config.id)
  142. net.needDay = getOpenSvrDay(config.id)
  143. net.lockType = config.lock
  144. net.name = config.name
  145. net.desc = config.desc
  146. net.doubleDay = config.doubleDay
  147. net.doubleDesc = config.doubleDesc
  148. net.panelID = config.panelID or 0
  149. net.dobule = isDouble(human, config.id) and 1 or 0
  150. net.touch = 0
  151. if isOpen(human,config.id) then
  152. net.isOpen = 1
  153. if config.touch == 1 then
  154. human.db.roleSys[net.id] = human.db.roleSys[net.id] or 1
  155. net.touch = human.db.roleSys[net.id]
  156. end
  157. if isDot(human,config) == true then
  158. mem[config.id] = true
  159. net.dot = 1
  160. else
  161. mem[config.id] = false
  162. net.dot = 0
  163. end
  164. else
  165. net.isOpen = 0
  166. net.dot = 0
  167. end
  168. end
  169. local function sendSystemAll(human)
  170. if not human.roleSystem then return end
  171. initDB(human)
  172. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  173. local len = 0
  174. local mem = human.roleSystem
  175. for id, config in pairs(RoleSystemExcel.roleSystem) do
  176. if not isNoSend(id) then
  177. len = len + 1
  178. local net = msgRet.list[len]
  179. wrapAll(human,mem,net,config)
  180. end
  181. end
  182. msgRet.list[0] = len
  183. Msg.send(msgRet,human.fd)
  184. end
  185. function senddSysemOpen(human)
  186. if not human.db.roleSysOpen then return end
  187. local msgRet = Msg.gc.GC_ROLESYSTEM_OPEN
  188. local len = 0
  189. for _, v in pairs(human.db.roleSysOpen) do
  190. len = len + 1
  191. msgRet.id[len] = v
  192. end
  193. msgRet.id[0] = len
  194. Msg.send(msgRet,human.fd)
  195. end
  196. local function sendSystemSingle(human, id)
  197. local config = RoleSystemExcel.roleSystem[id]
  198. if config == nil then
  199. return
  200. end
  201. if isNoSend(id) then return end
  202. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  203. local mem = human.roleSystem
  204. local net = msgRet.list[1]
  205. wrapAll(human,mem,net,config)
  206. msgRet.list[0] = 1
  207. Msg.send(msgRet,human.fd)
  208. end
  209. function onLogin(human)
  210. human.roleSystem = human.roleSystem or {}
  211. sendSystemAll(human)
  212. senddSysemOpen(human)
  213. end
  214. function onLvUp(human)
  215. sendSystemAll(human)
  216. end
  217. function onDotByUuid(uuid, id)
  218. local human = ObjHuman.onlineUuid[uuid]
  219. if human and human.fd then
  220. onDot(human, id)
  221. end
  222. end
  223. function onDot(human,id, noSend)
  224. if isOpen(human,id) ~= true then
  225. return
  226. end
  227. human.roleSystem = human.roleSystem or {}
  228. local oldDotStatus = human.roleSystem[id]
  229. local config = RoleSystemExcel.roleSystem[id]
  230. local newDotStatus = isDot(human,config)
  231. if oldDotStatus ~= newDotStatus then
  232. sendSystemSingle(human, id)
  233. end
  234. if noSend then
  235. sendSystemSingle(human, id)
  236. end
  237. end
  238. -- 是否有双倍
  239. function isDouble(human, id)
  240. if human.db.lv < DOUBLE_NEED_LV then return false end
  241. local config = RoleSystemExcel.roleSystem[id]
  242. if not config then return end
  243. local doubleDay = config.doubleDay
  244. if doubleDay == 0 then return end
  245. local weekDay = Util.getWeekDay()
  246. if doubleDay == weekDay then
  247. return true
  248. end
  249. return false
  250. end
  251. function checkMailTips(human)
  252. DrillLogic.sendDrillTip(human)
  253. end