RoleSystemLogic.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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 CommonDefine = require("common.CommonDefine")
  12. local Grid = require("bag.Grid")
  13. local BagLogic = require("bag.BagLogic")
  14. DOUBLE_NEED_LV = 10 -- 福利双倍 开启等级
  15. --邮件提示ID
  16. ROLE_MAILTIPS_ID1 = 1 --圣树试炼
  17. ROLE_SYS_OPEN_ID_START = 1 --
  18. ROLE_SYS_OPEN_ID_END = 50 --
  19. local function initDB(human)
  20. human.db.roleSys = human.db.roleSys or {}
  21. end
  22. local function RoleSystem_InitPrizeDB(human)
  23. human.db.roleSystemPrize = {}
  24. for id, conf in pairs(RoleSystemExcel.roleSystem) do
  25. if conf.isdisplay == 1 then
  26. human.db.roleSystemPrize[id] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  27. end
  28. end
  29. end
  30. local function RoleSystem_CheckPrize(human)
  31. if not human.db.roleSystemPrize then
  32. RoleSystem_InitPrizeDB(human)
  33. end
  34. for id, conf in pairs(RoleSystemExcel.roleSystem) do
  35. if conf.isdisplay == 1 then
  36. if not human.db.roleSystemPrize[id] then
  37. human.db.roleSystemPrize[id] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  38. end
  39. if true == isOpen(human,conf.id) then
  40. local nState = human.db.roleSystemPrize[id]
  41. if CommonDefine.COMMON_PRIZE_STATE_NOGET == nState then
  42. human.db.roleSystemPrize[id] = CommonDefine.COMMON_PRIZE_STATE_CANGET
  43. end
  44. end
  45. end
  46. end
  47. end
  48. function initAfterHot()
  49. for id, conf in pairs(RoleSystemExcel.roleSystem) do
  50. conf.id = id
  51. if conf.modulePath == "" then
  52. else
  53. conf.module = load("return require(\""..conf.modulePath.."\")")()
  54. end
  55. end
  56. end
  57. function isOpen(human, id, sendErr)
  58. local config = RoleSystemExcel.roleSystem[id]
  59. if not config then
  60. return
  61. end
  62. -- 开服天数
  63. if config.openSvrDay > 0 then
  64. local openDay = CommonDB.getServerOpenDay()
  65. if not openDay then
  66. if sendErr then
  67. Broadcast.sendErr(human, Lang.COMMON_SYSTEM_NEED_OPENTIME)
  68. end
  69. return false, config
  70. end
  71. if openDay < config.openSvrDay then
  72. if sendErr then
  73. Broadcast.sendErr(human, Util.format(Lang.COMMON_SYSTEM_OPENTIME, config.openSvrDay))
  74. end
  75. return false, config
  76. end
  77. end
  78. -- 等级
  79. if human.db.lv < config.lv then
  80. if sendErr then
  81. Broadcast.sendErr(human, Util.format(Lang.COMMON_SYSTEM_OPENTIP, config.lv))
  82. end
  83. return false, config
  84. end
  85. -- 寻星
  86. if id == RoleSystemDefine.ROLE_SYS_ID_501 then
  87. local now = os.time()
  88. local zpOpenTime = os.time(ZhuanpanExcel.define[1].time)
  89. if now < zpOpenTime then
  90. return false
  91. end
  92. end
  93. --战令, 临时处理下, 如果多了再优化成通用方法
  94. if id == RoleSystemDefine.ROLE_SYS_ID_2005 then
  95. local WarOrder = require("shop.WarOrder")
  96. local res = WarOrder.isOpen(human)
  97. if not res then
  98. return false, config
  99. end
  100. end
  101. return true, config
  102. end
  103. -- 等级达到x级
  104. ROLE_SYSTEM_OPEN_NEED_LV = {}
  105. function getOpenLv(id)
  106. if ROLE_SYSTEM_OPEN_NEED_LV[id] then
  107. return ROLE_SYSTEM_OPEN_NEED_LV[id]
  108. end
  109. local config = RoleSystemExcel.roleSystem[id]
  110. if config then
  111. ROLE_SYSTEM_OPEN_NEED_LV[id] = config.lv
  112. return ROLE_SYSTEM_OPEN_NEED_LV[id]
  113. end
  114. return 0
  115. end
  116. -- 开服x天后开启
  117. function getOpenSvrDay(id)
  118. local config = RoleSystemExcel.roleSystem[id]
  119. if config.openSvrDay > 0 then
  120. local openDay = CommonDB.getServerOpenDay()
  121. if not openDay or openDay < config.openSvrDay then
  122. return config and config.openSvrDay or 0
  123. end
  124. end
  125. return 0
  126. end
  127. -- 获取开启条件说明
  128. function getOpenDesc(id)
  129. local config = RoleSystemExcel.roleSystem[id]
  130. if not config then return "" end
  131. if config.lv >= 999 then
  132. return Lang.COMMON_SYSTEM_READY
  133. end
  134. if config.openSvrDay > 0 and config.lv > 1 then
  135. return Util.format(Lang.COMMON_SYSTEM_OPENLV_TIME, config.lv, config.openSvrDay)
  136. end
  137. if config.openSvrDay > 0 then
  138. return Util.format(Lang.COMMON_SYSTEM_OPENTIME, config.openSvrDay)
  139. end
  140. return Util.format(Lang.COMMON_SYSTEM_OPENTIP, config.lv)
  141. end
  142. -- 不发送客户端
  143. local function isNoSend(id)
  144. return id > 10000
  145. end
  146. -- 是否有红点
  147. local function isDot(human,config)
  148. if human.db.lv < config.dotLv then
  149. return false
  150. end
  151. if config.module and config.module.isDot and config.module.isDot(human,config) then
  152. return true
  153. end
  154. return false
  155. end
  156. function touch(human, id)
  157. local roleExcel = RoleSystemExcel.roleSystem[id]
  158. if not roleExcel then return end
  159. if roleExcel.touch ~= 1 then return end
  160. local touch = human.db.roleSys[id]
  161. if not touch then return end
  162. human.db.roleSys[id] = 0
  163. onDot(human, id, true)
  164. end
  165. function open(human, id)
  166. if not human.db.roleSysOpen then
  167. human.db.roleSysOpen = {}
  168. end
  169. local len = #human.db.roleSysOpen
  170. if len >= ROLE_SYS_OPEN_ID_END then return end
  171. len = len + 1
  172. human.db.roleSysOpen[len] = id
  173. end
  174. -- 封装结构体
  175. local function wrapAll(human, mem, net, config)
  176. mem[config.id] = false
  177. net.id = config.id
  178. net.lv = getOpenLv(config.id)
  179. net.needDay = getOpenSvrDay(config.id)
  180. net.lockType = config.lock
  181. net.name = config.name
  182. net.desc = config.desc
  183. net.doubleDay = config.doubleDay
  184. net.doubleDesc = config.doubleDesc
  185. net.panelID = config.panelID or 0
  186. net.dobule = isDouble(human, config.id) and 1 or 0
  187. net.touch = 0
  188. net.isShow = config.isdisplay or 0
  189. if isOpen(human,config.id) then
  190. net.isOpen = 1
  191. if config.touch == 1 then
  192. human.db.roleSys[net.id] = human.db.roleSys[net.id] or 1
  193. net.touch = human.db.roleSys[net.id]
  194. end
  195. if isDot(human,config) == true then
  196. mem[config.id] = true
  197. net.dot = 1
  198. else
  199. mem[config.id] = false
  200. net.dot = 0
  201. end
  202. else
  203. net.isOpen = 0
  204. net.dot = 0
  205. end
  206. end
  207. local function sendSystemAll(human)
  208. if not human.roleSystem then return end
  209. initDB(human)
  210. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  211. local len = 0
  212. local mem = human.roleSystem
  213. for id, config in pairs(RoleSystemExcel.roleSystem) do
  214. if not isNoSend(id) then
  215. len = len + 1
  216. local net = msgRet.list[len]
  217. wrapAll(human,mem,net,config)
  218. end
  219. end
  220. msgRet.list[0] = len
  221. Msg.send(msgRet,human.fd)
  222. end
  223. function senddSysemOpen(human)
  224. if not human.db.roleSysOpen then return end
  225. local msgRet = Msg.gc.GC_ROLESYSTEM_OPEN
  226. local len = 0
  227. for _, v in pairs(human.db.roleSysOpen) do
  228. len = len + 1
  229. msgRet.id[len] = v
  230. end
  231. msgRet.id[0] = len
  232. Msg.send(msgRet,human.fd)
  233. end
  234. local function sendSystemSingle(human, id)
  235. local config = RoleSystemExcel.roleSystem[id]
  236. if config == nil then
  237. return
  238. end
  239. if isNoSend(id) then return end
  240. local msgRet = Msg.gc.GC_ROLESYSTEM_QUERY
  241. local mem = human.roleSystem
  242. local net = msgRet.list[1]
  243. wrapAll(human,mem,net,config)
  244. msgRet.list[0] = 1
  245. Msg.send(msgRet,human.fd)
  246. end
  247. function onLogin(human)
  248. human.roleSystem = human.roleSystem or {}
  249. sendSystemAll(human)
  250. senddSysemOpen(human)
  251. RoleSystem_CheckPrize(human)
  252. end
  253. function onLvUp(human)
  254. sendSystemAll(human)
  255. RoleSystem_CheckPrize(human)
  256. end
  257. function onDotByUuid(uuid, id)
  258. local human = ObjHuman.onlineUuid[uuid]
  259. if human and human.fd then
  260. onDot(human, id)
  261. end
  262. end
  263. function onDot(human,id, noSend)
  264. if isOpen(human,id) ~= true then
  265. return
  266. end
  267. human.roleSystem = human.roleSystem or {}
  268. local oldDotStatus = human.roleSystem[id]
  269. local config = RoleSystemExcel.roleSystem[id]
  270. local newDotStatus = isDot(human,config)
  271. if oldDotStatus ~= newDotStatus then
  272. sendSystemSingle(human, id)
  273. end
  274. if noSend then
  275. sendSystemSingle(human, id)
  276. end
  277. end
  278. --是否关闭
  279. function isClose(human,id)
  280. if not isOpen(human, id) then
  281. sendSystemSingle(human, id)
  282. end
  283. end
  284. -- 是否有双倍
  285. function isDouble(human, id)
  286. if human.db.lv < DOUBLE_NEED_LV then return false end
  287. local config = RoleSystemExcel.roleSystem[id]
  288. if not config then return end
  289. local doubleDay = config.doubleDay
  290. if doubleDay == 0 then return end
  291. local weekDay = Util.getWeekDay()
  292. if doubleDay == weekDay then
  293. return true
  294. end
  295. return false
  296. end
  297. function checkMailTips(human)
  298. DrillLogic.sendDrillTip(human)
  299. end
  300. function RoleSystem_QueryPrize(human)
  301. if not human.db.roleSystemPrize then
  302. RoleSystem_InitPrizeDB(human)
  303. end
  304. local tMsgData = Msg.gc.GC_ROLESYSTEM_PRIZE_QUERY
  305. tMsgData.tList[0] = 0
  306. local nLen = 0
  307. for id, conf in pairs(RoleSystemExcel.roleSystem) do
  308. if conf.isdisplay == 1 then
  309. nLen = nLen + 1
  310. local tData = tMsgData.tList[nLen]
  311. tData.nID = id
  312. if not human.db.roleSystemPrize[id] then
  313. human.db.roleSystemPrize[id] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  314. end
  315. tData.nStatus = human.db.roleSystemPrize[id]
  316. tData.tItemList[0] = #conf.reward
  317. for i, value in ipairs(conf.reward) do
  318. local tItemData = tData.tItemList[i]
  319. Grid.makeItem(tItemData, value[1], value[2])
  320. end
  321. end
  322. end
  323. tMsgData.tList[0] = nLen
  324. Msg.send(tMsgData, human.fd)
  325. print("[RoleSystem_QueryPrize] 下发活动预告奖励结束")
  326. end
  327. function RoleSystem_GetPrize(human)
  328. local tItem = {}
  329. for id, conf in pairs(RoleSystemExcel.roleSystem) do
  330. if conf.isdisplay == 1 then
  331. local nStatus = human.db.roleSystemPrize[id] or CommonDefine.COMMON_PRIZE_STATE_NOGET
  332. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nStatus then
  333. for _, v in ipairs(conf.reward) do
  334. if not tItem[v[1]] then
  335. tItem[v[1]] = 0
  336. end
  337. tItem[v[1]] = tItem[v[1]] + v[2]
  338. end
  339. human.db.roleSystemPrize[id] = CommonDefine.COMMON_PRIZE_STATE_GET
  340. end
  341. end
  342. end
  343. if nil ~= _G.next(tItem) then
  344. local tGoods = {}
  345. for nID, nNum in pairs(tItem) do
  346. table.insert(tGoods, {nID, nNum})
  347. end
  348. BagLogic.addItemList(human, tItem, "rolesystemprize")
  349. RoleSystem_QueryPrize(human)
  350. end
  351. end