RoleSystemLogic.lua 8.0 KB

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