RoleSystemLogic.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. if isOpen(human,config.id) then
  160. net.isOpen = 1
  161. if config.touch == 1 then
  162. human.db.roleSys[net.id] = human.db.roleSys[net.id] or 1
  163. net.touch = human.db.roleSys[net.id]
  164. end
  165. if isDot(human,config) == true then
  166. mem[config.id] = true
  167. net.dot = 1
  168. else
  169. mem[config.id] = false
  170. net.dot = 0
  171. end
  172. else
  173. net.isOpen = 0
  174. net.dot = 0
  175. end
  176. end
  177. local function sendSystemAll(human)
  178. if not human.roleSystem then return end
  179. initDB(human)
  180. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  181. local len = 0
  182. local mem = human.roleSystem
  183. for id, config in pairs(RoleSystemExcel.roleSystem) do
  184. if not isNoSend(id) then
  185. len = len + 1
  186. local net = msgRet.list[len]
  187. wrapAll(human,mem,net,config)
  188. end
  189. end
  190. msgRet.list[0] = len
  191. Msg.send(msgRet,human.fd)
  192. end
  193. function senddSysemOpen(human)
  194. if not human.db.roleSysOpen then return end
  195. local msgRet = Msg.gc.GC_ROLESYSTEM_OPEN
  196. local len = 0
  197. for _, v in pairs(human.db.roleSysOpen) do
  198. len = len + 1
  199. msgRet.id[len] = v
  200. end
  201. msgRet.id[0] = len
  202. Msg.send(msgRet,human.fd)
  203. end
  204. local function sendSystemSingle(human, id)
  205. local config = RoleSystemExcel.roleSystem[id]
  206. if config == nil then
  207. return
  208. end
  209. if isNoSend(id) then return end
  210. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  211. local mem = human.roleSystem
  212. local net = msgRet.list[1]
  213. wrapAll(human,mem,net,config)
  214. msgRet.list[0] = 1
  215. Msg.send(msgRet,human.fd)
  216. end
  217. function onLogin(human)
  218. human.roleSystem = human.roleSystem or {}
  219. sendSystemAll(human)
  220. senddSysemOpen(human)
  221. end
  222. function onLvUp(human)
  223. sendSystemAll(human)
  224. end
  225. function onDotByUuid(uuid, id)
  226. local human = ObjHuman.onlineUuid[uuid]
  227. if human and human.fd then
  228. onDot(human, id)
  229. end
  230. end
  231. function onDot(human,id, noSend)
  232. if isOpen(human,id) ~= true then
  233. return
  234. end
  235. human.roleSystem = human.roleSystem or {}
  236. local oldDotStatus = human.roleSystem[id]
  237. local config = RoleSystemExcel.roleSystem[id]
  238. local newDotStatus = isDot(human,config)
  239. if oldDotStatus ~= newDotStatus then
  240. sendSystemSingle(human, id)
  241. end
  242. if noSend then
  243. sendSystemSingle(human, id)
  244. end
  245. end
  246. --是否关闭
  247. function isClose(human,id)
  248. if not isOpen(human, id) then
  249. sendSystemSingle(human, id)
  250. end
  251. end
  252. -- 是否有双倍
  253. function isDouble(human, id)
  254. if human.db.lv < DOUBLE_NEED_LV then return false end
  255. local config = RoleSystemExcel.roleSystem[id]
  256. if not config then return end
  257. local doubleDay = config.doubleDay
  258. if doubleDay == 0 then return end
  259. local weekDay = Util.getWeekDay()
  260. if doubleDay == weekDay then
  261. return true
  262. end
  263. return false
  264. end
  265. function checkMailTips(human)
  266. DrillLogic.sendDrillTip(human)
  267. end