RoleSystemLogic.lua 7.6 KB

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