UnlimitDrawLogic.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. --------------------------------
  2. -- 文件名 : UnlimitDrawLogic.lua
  3. -- 文件说明 : 无限高抽
  4. -- 创建时间 : 2025/09/29
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local Msg = require("core.Msg")
  10. local Grid = require("bag.Grid")
  11. local HeroGrid = require("hero.HeroGrid")
  12. local HeroLogic = require("hero.HeroLogic")
  13. local BagLogic = require("bag.BagLogic")
  14. local Log = require("common.Log")
  15. local Broadcast = require("broadcast.Broadcast")
  16. local DrawCardExcel = require("excel.drawCard").drawCard
  17. local RandomLogic = require("common.RandomLogic")
  18. local HeroDefine = require("hero.HeroDefine")
  19. local HeroExcel = require("excel.hero").hero
  20. local HeroBook = require("hero.HeroBook")
  21. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  22. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  23. -- local DrawCardLogic = require("drawCard.DrawCardLogic")
  24. local UNLIMIT_CARD_ID = 12
  25. local UNLIMIT_CARD_LV = 35
  26. local LOGINDAY3 = 3 -- 登录3天
  27. local LOGINDAY7 = 7 -- 登录7天
  28. ----------------------------------------- 内部处理开始 -------------------------------------
  29. local function UnlimitDraw_CreateDB(human)
  30. human.db.UnlimitDraw = {
  31. nNowNum = 0,
  32. bLogin = false,
  33. bLv = false,
  34. nFirstLoginTime = 0,
  35. bNextLogin = false,
  36. tChacheHero = nil,
  37. }
  38. end
  39. local function UnlimitDraw_CheckDB(human)
  40. if not human.db.UnlimitDraw then
  41. UnlimitDraw_CreateDB(human)
  42. end
  43. end
  44. local function UnlimitDraw_GetNum(human)
  45. return human.db.UnlimitDraw.nNowNum
  46. end
  47. local function UnlimitDraw_SetNum(human, nValue)
  48. human.db.UnlimitDraw.nNowNum = human.db.UnlimitDraw.nNowNum + nValue
  49. if human.db.UnlimitDraw.nNowNum < 0 then
  50. human.db.UnlimitDraw.nNowNum = 0
  51. end
  52. end
  53. local function UnlimitDraw_GetLogin(human)
  54. return human.db.UnlimitDraw.bLogin
  55. end
  56. local function UnlimitDraw_SetLogin(human, bValue)
  57. human.db.UnlimitDraw.bLogin = bValue
  58. end
  59. local function UnlimitDraw_GetLoginTime(human)
  60. return human.db.UnlimitDraw.nFirstLoginTime
  61. end
  62. local function UnlimitDraw_SetLoginTime(human, nValue)
  63. human.db.UnlimitDraw.nFirstLoginTime = nValue
  64. end
  65. local function UnlimitDraw_GetLv(human)
  66. return human.db.UnlimitDraw.bLv
  67. end
  68. local function UnlimitDraw_SetLv(human, bValue)
  69. human.db.UnlimitDraw.bLv = bValue
  70. end
  71. local function UnlimitDraw_GetNextLogin(human)
  72. return human.db.UnlimitDraw.bNextLogin
  73. end
  74. local function UnlimitDraw_SetNextLogin(human, bValue)
  75. human.db.UnlimitDraw.bNextLogin = bValue
  76. end
  77. local function UnlimitDraw_SetCacheHero(human, tHeroInfo)
  78. human.db.UnlimitDraw.tChacheHero = tHeroInfo
  79. end
  80. local function UnlimitDraw_GetCacheHero(human)
  81. return human.db.UnlimitDraw.tChacheHero
  82. end
  83. local function UnlimitDraw_ClearCacheHero(human)
  84. human.db.UnlimitDraw.tChacheHero = nil
  85. end
  86. local function UnlimitDraw_randHeroID(human, config, randomIndex)
  87. local heroID = nil
  88. local rindex = RandomLogic.getRandom1(config.weight, nil, 2)
  89. local rconf = config.weight[rindex]
  90. local weightLv = rconf[1]
  91. heroID = heroID or HeroDefine.getRandHeroByWeightLv(weightLv)
  92. return heroID
  93. end
  94. local function UnlimitDraw_GetLoginDay(human)
  95. return human.db.UnlimitDraw.LoginDay or 0
  96. end
  97. local function UnlimitDraw_AddLoginDay(human, bValue)
  98. human.db.UnlimitDraw.LoginDay = (human.db.UnlimitDraw.LoginDay or 0) + bValue
  99. end
  100. ----------------------------------------- 客户端请求 -------------------------------------
  101. function UnlimitDrawLogic_Query(human)
  102. UnlimitDraw_CheckDB(human)
  103. local tMsgData = Msg.gc.GC_UNLIMITDRAW_QUERY
  104. tMsgData.nNowNum = UnlimitDraw_GetNum(human)
  105. tMsgData.tGetInfo[0] = 5
  106. tMsgData.tGetInfo[1] = UnlimitDraw_GetLogin(human) and 1 or 0
  107. tMsgData.tGetInfo[2] = UnlimitDraw_GetLv(human) and 1 or 0
  108. tMsgData.tGetInfo[3] = UnlimitDraw_GetNextLogin(human) and 1 or 0
  109. local nowLoginDay = UnlimitDraw_GetLoginDay(human)
  110. tMsgData.tGetInfo[4] = nowLoginDay >= LOGINDAY3 and 1 or 0
  111. tMsgData.tGetInfo[5] = nowLoginDay >= LOGINDAY7 and 1 or 0
  112. Msg.send(tMsgData, human.fd)
  113. end
  114. function UnlimitDrawLogic_Do(human)
  115. local nNowNum = UnlimitDraw_GetNum(human)
  116. if 0 >= nNowNum then
  117. return
  118. end
  119. local nDoNum = 10
  120. local config = DrawCardExcel[UNLIMIT_CARD_ID]
  121. if HeroLogic.getEmptyCnt(human) < nDoNum then
  122. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  123. end
  124. UnlimitDraw_ClearCacheHero(human)
  125. local heroLen = 0
  126. local heroList = {}
  127. local heroNewList = {}
  128. local heroIndexList = {}
  129. local fenjielist = {}
  130. local heroIDs = nil
  131. local randomMin = math.random(1, nDoNum)
  132. for i = 1, nDoNum, 1 do
  133. local nHeroID = UnlimitDraw_randHeroID(human, config, randomMin)
  134. if nHeroID then
  135. local heroConfig = HeroExcel[nHeroID]
  136. local star = heroConfig.star
  137. local name = heroConfig.name
  138. local grade = heroConfig.grade
  139. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  140. -- local heroIndex, fjlist = HeroLogic.addHero(human, nHeroID, nil, 1, "draw_card")
  141. heroLen = heroLen + 1
  142. heroList[heroLen] = nHeroID
  143. heroNewList[heroLen] = isNew
  144. if not heroIDs then
  145. heroIDs = nHeroID
  146. else
  147. heroIDs = heroIDs .. "|" .. nHeroID
  148. end
  149. else
  150. print("[UnlimitDrawLogic_Do] 生成英雄失败直接返回")
  151. return
  152. end
  153. end
  154. local tMsgData = Msg.gc.GC_UNLIMITDRAW_DO
  155. tMsgData.tHeros[0] = nDoNum
  156. for i = 1, heroLen do
  157. local heroID = heroList[i]
  158. local isNew = heroNewList and heroNewList[i]
  159. -- local index = heroIndexList and heroIndexList[i]
  160. HeroGrid.makeHeroNice(tMsgData.tHeros[i], heroID, 1, isNew)
  161. end
  162. UnlimitDraw_SetCacheHero(human, heroList)
  163. Msg.send(tMsgData, human.fd)
  164. end
  165. function UnlimitDrawLogic_Abandon(human)
  166. UnlimitDraw_ClearCacheHero(human)
  167. end
  168. function UnlimitDrawLogic_Get(human)
  169. local tHeroInfo = UnlimitDraw_GetCacheHero(human)
  170. if not tHeroInfo then
  171. return
  172. end
  173. local nNowNum = UnlimitDraw_GetNum(human)
  174. if 0 >= nNowNum then
  175. return
  176. end
  177. UnlimitDraw_SetNum(human, -1)
  178. local heroIndexList = {}
  179. local fenjielist = {}
  180. for _, nID in ipairs(tHeroInfo) do
  181. local heroIndex, fjlist = HeroLogic.addHero(human, nID,nil, 1, "UnlimitDrawCard")
  182. if fjlist and type(fjlist) == "table" then
  183. for fjItemID, fjItemCnt in pairs(fjlist) do
  184. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  185. end
  186. end
  187. table.insert(heroIndexList, heroIndex)
  188. end
  189. if nil ~= _G.next(fenjielist) then
  190. local tItem = {}
  191. for key, value in pairs(fenjielist) do
  192. table.insert(tItem, {key, value})
  193. end
  194. BagLogic.sendItemGetList(human, tItem, "UnlimitDrawCard")
  195. end
  196. UnlimitDraw_ClearCacheHero(human)
  197. UnlimitDrawLogic_Query(human)
  198. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_111, nil, true)
  199. end
  200. function onLogin(human)
  201. UnlimitDraw_CheckDB(human)
  202. local bSendDot = false
  203. local bLogin = UnlimitDraw_GetLogin(human)
  204. if false == bLogin then
  205. UnlimitDraw_SetLogin(human, true)
  206. UnlimitDraw_SetLoginTime(human, os.time())
  207. UnlimitDraw_SetNum(human, 1)
  208. UnlimitDraw_AddLoginDay(human, 1)
  209. bSendDot = true
  210. else
  211. local nLastTime = UnlimitDraw_GetLoginTime(human)
  212. local bNextLogin = UnlimitDraw_GetNextLogin(human)
  213. if not Util.isSameDay(nLastTime) and false == bNextLogin then
  214. UnlimitDraw_SetNextLogin(human, true)
  215. UnlimitDraw_SetNum(human, 1)
  216. bSendDot = true
  217. end
  218. if not Util.isSameDay(nLastTime) then
  219. local beforeLoginDay = UnlimitDraw_GetLoginDay(human)
  220. if beforeLoginDay <= LOGINDAY7 then
  221. UnlimitDraw_AddLoginDay(human, 1)
  222. UnlimitDraw_SetLoginTime(human, os.time())
  223. local nowLoginDay = UnlimitDraw_GetLoginDay(human)
  224. if (beforeLoginDay < LOGINDAY3 and nowLoginDay >= LOGINDAY3) or (beforeLoginDay < LOGINDAY7 and nowLoginDay >= LOGINDAY7) then
  225. UnlimitDraw_SetNum(human, 1)
  226. bSendDot = true
  227. end
  228. end
  229. end
  230. end
  231. local bLv = UnlimitDraw_GetLv(human)
  232. if false == bLv and human.db.lv >= UNLIMIT_CARD_LV then
  233. UnlimitDraw_SetLv(human, true)
  234. UnlimitDraw_SetNum(human, 1)
  235. bSendDot = true
  236. end
  237. if true == bSendDot then
  238. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_111)
  239. end
  240. end
  241. function onLvUp(human, nNewLv)
  242. local bLv = UnlimitDraw_GetLv(human)
  243. if false == bLv and nNewLv >= UNLIMIT_CARD_LV then
  244. UnlimitDraw_SetLv(human, true)
  245. UnlimitDraw_SetNum(human, 1)
  246. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_111, true)
  247. end
  248. end
  249. function ModuleisOpen(human)
  250. UnlimitDraw_CheckDB(human)
  251. if true == UnlimitDraw_GetLogin(human) and UnlimitDraw_GetLv(human) == true
  252. and true == UnlimitDraw_GetNextLogin(human) then
  253. local beforeLoginDay = UnlimitDraw_GetLoginDay(human)
  254. if UnlimitDraw_GetNum(human) > 0 or beforeLoginDay <= LOGINDAY7 then
  255. return true
  256. else
  257. print("[ModuleisOpen] 当前系统未开放")
  258. return false
  259. end
  260. end
  261. return true
  262. end
  263. function isDot(human)
  264. UnlimitDraw_CheckDB(human)
  265. if true == ModuleisOpen(human) then
  266. if UnlimitDraw_GetNum(human) > 0 then
  267. local nNowNum = UnlimitDraw_GetNum(human)
  268. print("[UnlimitDraw_isDot] 当前系统开放可抽取数量大于0 nNowNum = "..nNowNum)
  269. return true
  270. end
  271. end
  272. return false
  273. end