RoleSystemLogic.lua 8.4 KB

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