RoleSystemLogic.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. --战令, 临时处理下, 如果多了再优化成通用方法
  65. if id == RoleSystemDefine.ROLE_SYS_ID_2005 then
  66. local WarOrder = require("shop.WarOrder")
  67. local res = WarOrder.isOpen(human)
  68. if not res then
  69. return false, config
  70. end
  71. end
  72. return true, config
  73. end
  74. -- 等级达到x级
  75. ROLE_SYSTEM_OPEN_NEED_LV = {}
  76. function getOpenLv(id)
  77. if ROLE_SYSTEM_OPEN_NEED_LV[id] then
  78. return ROLE_SYSTEM_OPEN_NEED_LV[id]
  79. end
  80. local config = RoleSystemExcel.roleSystem[id]
  81. if config then
  82. ROLE_SYSTEM_OPEN_NEED_LV[id] = config.lv
  83. return ROLE_SYSTEM_OPEN_NEED_LV[id]
  84. end
  85. return 0
  86. end
  87. -- 开服x天后开启
  88. function getOpenSvrDay(id)
  89. local config = RoleSystemExcel.roleSystem[id]
  90. if config.openSvrDay > 0 then
  91. local openDay = CommonDB.getServerOpenDay()
  92. if not openDay or openDay < config.openSvrDay then
  93. return config and config.openSvrDay or 0
  94. end
  95. end
  96. return 0
  97. end
  98. -- 获取开启条件说明
  99. function getOpenDesc(id)
  100. local config = RoleSystemExcel.roleSystem[id]
  101. if not config then return "" end
  102. if config.lv >= 999 then
  103. return Lang.COMMON_SYSTEM_READY
  104. end
  105. if config.openSvrDay > 0 and config.lv > 1 then
  106. return Util.format(Lang.COMMON_SYSTEM_OPENLV_TIME, config.lv, config.openSvrDay)
  107. end
  108. if config.openSvrDay > 0 then
  109. return Util.format(Lang.COMMON_SYSTEM_OPENTIME, config.openSvrDay)
  110. end
  111. return Util.format(Lang.COMMON_SYSTEM_OPENTIP, config.lv)
  112. end
  113. -- 不发送客户端
  114. local function isNoSend(id)
  115. return id > 10000
  116. end
  117. -- 是否有红点
  118. local function isDot(human,config)
  119. if human.db.lv < config.dotLv then
  120. return false
  121. end
  122. if config.module and config.module.isDot and config.module.isDot(human,config) then
  123. return true
  124. end
  125. return false
  126. end
  127. function touch(human, id)
  128. local roleExcel = RoleSystemExcel.roleSystem[id]
  129. if not roleExcel then return end
  130. if roleExcel.touch ~= 1 then return end
  131. local touch = human.db.roleSys[id]
  132. if not touch then return end
  133. human.db.roleSys[id] = 0
  134. onDot(human, id, true)
  135. end
  136. function open(human, id)
  137. if not human.db.roleSysOpen then
  138. human.db.roleSysOpen = {}
  139. end
  140. local len = #human.db.roleSysOpen
  141. if len >= ROLE_SYS_OPEN_ID_END then return end
  142. len = len + 1
  143. human.db.roleSysOpen[len] = id
  144. end
  145. -- 封装结构体
  146. local function wrapAll(human, mem, net, config)
  147. mem[config.id] = false
  148. net.id = config.id
  149. net.lv = getOpenLv(config.id)
  150. net.needDay = getOpenSvrDay(config.id)
  151. net.lockType = config.lock
  152. net.name = config.name
  153. net.desc = config.desc
  154. net.doubleDay = config.doubleDay
  155. net.doubleDesc = config.doubleDesc
  156. net.panelID = config.panelID or 0
  157. net.dobule = isDouble(human, config.id) and 1 or 0
  158. net.touch = 0
  159. net.isShow = config.isdisplay or 0
  160. if isOpen(human,config.id) then
  161. net.isOpen = 1
  162. if config.touch == 1 then
  163. human.db.roleSys[net.id] = human.db.roleSys[net.id] or 1
  164. net.touch = human.db.roleSys[net.id]
  165. end
  166. if isDot(human,config) == true then
  167. mem[config.id] = true
  168. net.dot = 1
  169. else
  170. mem[config.id] = false
  171. net.dot = 0
  172. end
  173. else
  174. net.isOpen = 0
  175. net.dot = 0
  176. end
  177. end
  178. local function sendSystemAll(human)
  179. if not human.roleSystem then return end
  180. initDB(human)
  181. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  182. local len = 0
  183. local mem = human.roleSystem
  184. for id, config in pairs(RoleSystemExcel.roleSystem) do
  185. if not isNoSend(id) then
  186. len = len + 1
  187. local net = msgRet.list[len]
  188. wrapAll(human,mem,net,config)
  189. end
  190. end
  191. msgRet.list[0] = len
  192. Msg.send(msgRet,human.fd)
  193. end
  194. function senddSysemOpen(human)
  195. if not human.db.roleSysOpen then return end
  196. local msgRet = Msg.gc.GC_ROLESYSTEM_OPEN
  197. local len = 0
  198. for _, v in pairs(human.db.roleSysOpen) do
  199. len = len + 1
  200. msgRet.id[len] = v
  201. end
  202. msgRet.id[0] = len
  203. Msg.send(msgRet,human.fd)
  204. end
  205. local function sendSystemSingle(human, id)
  206. local config = RoleSystemExcel.roleSystem[id]
  207. if config == nil then
  208. return
  209. end
  210. if isNoSend(id) then return end
  211. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  212. local mem = human.roleSystem
  213. local net = msgRet.list[1]
  214. wrapAll(human,mem,net,config)
  215. msgRet.list[0] = 1
  216. Msg.send(msgRet,human.fd)
  217. end
  218. function onLogin(human)
  219. human.roleSystem = human.roleSystem or {}
  220. sendSystemAll(human)
  221. senddSysemOpen(human)
  222. end
  223. function onLvUp(human)
  224. sendSystemAll(human)
  225. end
  226. function onDotByUuid(uuid, id)
  227. local human = ObjHuman.onlineUuid[uuid]
  228. if human and human.fd then
  229. onDot(human, id)
  230. end
  231. end
  232. function onDot(human,id, noSend)
  233. if isOpen(human,id) ~= true then
  234. return
  235. end
  236. human.roleSystem = human.roleSystem or {}
  237. local oldDotStatus = human.roleSystem[id]
  238. local config = RoleSystemExcel.roleSystem[id]
  239. local newDotStatus = isDot(human,config)
  240. if oldDotStatus ~= newDotStatus then
  241. sendSystemSingle(human, id)
  242. end
  243. if noSend then
  244. sendSystemSingle(human, id)
  245. end
  246. end
  247. --是否关闭
  248. function isClose(human,id)
  249. if not isOpen(human, id) then
  250. sendSystemSingle(human, id)
  251. end
  252. end
  253. -- 是否有双倍
  254. function isDouble(human, id)
  255. if human.db.lv < DOUBLE_NEED_LV then return false end
  256. local config = RoleSystemExcel.roleSystem[id]
  257. if not config then return end
  258. local doubleDay = config.doubleDay
  259. if doubleDay == 0 then return end
  260. local weekDay = Util.getWeekDay()
  261. if doubleDay == weekDay then
  262. return true
  263. end
  264. return false
  265. end
  266. function checkMailTips(human)
  267. DrillLogic.sendDrillTip(human)
  268. end