|
|
@@ -0,0 +1,277 @@
|
|
|
+--------------------------------
|
|
|
+-- 文件名 : UnlimitDrawLogic.lua
|
|
|
+-- 文件说明 : 无限高抽
|
|
|
+-- 创建时间 : 2025/09/29
|
|
|
+-- 创建人 : FC
|
|
|
+--------------------------------
|
|
|
+local Util = require("common.Util")
|
|
|
+local Lang = require("common.Lang")
|
|
|
+local Msg = require("core.Msg")
|
|
|
+local Grid = require("bag.Grid")
|
|
|
+local HeroGrid = require("hero.HeroGrid")
|
|
|
+local HeroLogic = require("hero.HeroLogic")
|
|
|
+local BagLogic = require("bag.BagLogic")
|
|
|
+local Log = require("common.Log")
|
|
|
+local Broadcast = require("broadcast.Broadcast")
|
|
|
+local DrawCardExcel = require("excel.drawCard").drawCard
|
|
|
+local RandomLogic = require("common.RandomLogic")
|
|
|
+local HeroDefine = require("hero.HeroDefine")
|
|
|
+local HeroExcel = require("excel.hero").hero
|
|
|
+local HeroBook = require("hero.HeroBook")
|
|
|
+
|
|
|
+-- local DrawCardLogic = require("drawCard.DrawCardLogic")
|
|
|
+
|
|
|
+local UNLIMIT_CARD_ID = 12
|
|
|
+local UNLIMIT_CARD_LV = 25
|
|
|
+
|
|
|
+----------------------------------------- 内部处理开始 -------------------------------------
|
|
|
+local function UnlimitDraw_CreateDB(human)
|
|
|
+ human.db.UnlimitDraw = {
|
|
|
+ nNowNum = 0,
|
|
|
+ bLogin = false,
|
|
|
+ bLv = false,
|
|
|
+ nFirstLoginTime = 0,
|
|
|
+ bNextLogin = false,
|
|
|
+ tChacheHero = nil,
|
|
|
+ }
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_CheckDB(human)
|
|
|
+ if not human.db.UnlimitDraw then
|
|
|
+ UnlimitDraw_CreateDB(human)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_GetNum(human)
|
|
|
+ return human.db.UnlimitDraw.nNowNum
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_SetNum(human, nValue)
|
|
|
+ human.db.UnlimitDraw.nNowNum = human.db.UnlimitDraw.nNowNum + nValue
|
|
|
+ if human.db.UnlimitDraw.nNowNum < 0 then
|
|
|
+ human.db.UnlimitDraw.nNowNum = 0
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_GetLogin(human)
|
|
|
+ return human.db.UnlimitDraw.bLogin
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_SetLogin(human, bValue)
|
|
|
+ human.db.UnlimitDraw.bLogin = bValue
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_GetLoginTime(human)
|
|
|
+ return human.db.UnlimitDraw.nFirstLoginTime
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_SetLoginTime(human, nValue)
|
|
|
+ human.db.UnlimitDraw.nFirstLoginTime = nValue
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_GetLv(human)
|
|
|
+ return human.db.UnlimitDraw.bLv
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_SetLv(human, bValue)
|
|
|
+ human.db.UnlimitDraw.bLv = bValue
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_GetNextLogin(human)
|
|
|
+ return human.db.UnlimitDraw.bNextLogin
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_SetNextLogin(human, bValue)
|
|
|
+ human.db.UnlimitDraw.bNextLogin = bValue
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_SetCacheHero(human, tHeroInfo)
|
|
|
+ human.db.UnlimitDraw.tChacheHero = tHeroInfo
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_GetCacheHero(human)
|
|
|
+ return human.db.UnlimitDraw.tChacheHero
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_ClearCacheHero(human)
|
|
|
+ human.db.UnlimitDraw.tChacheHero = nil
|
|
|
+end
|
|
|
+
|
|
|
+local function UnlimitDraw_randHeroID(human, config, randomIndex)
|
|
|
+ local heroID = nil
|
|
|
+ local rindex = RandomLogic.getRandom1(config.weight, nil, 2)
|
|
|
+ local rconf = config.weight[rindex]
|
|
|
+ local weightLv = rconf[1]
|
|
|
+
|
|
|
+ heroID = heroID or HeroDefine.getRandHeroByWeightLv(weightLv)
|
|
|
+ return heroID
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+----------------------------------------- 客户端请求 -------------------------------------
|
|
|
+function UnlimitDrawLogic_Query(human)
|
|
|
+ UnlimitDraw_CheckDB(human)
|
|
|
+
|
|
|
+ local tMsgData = Msg.gc.GC_UNLIMITDRAW_QUERY
|
|
|
+
|
|
|
+ tMsgData.nNowNum = UnlimitDraw_GetNum(human)
|
|
|
+ tMsgData.tGetInfo[0] = 3
|
|
|
+ tMsgData.tGetInfo[1] = UnlimitDraw_GetLogin(human) and 1 or 0
|
|
|
+ tMsgData.tGetInfo[2] = UnlimitDraw_GetLv(human) and 1 or 0
|
|
|
+ tMsgData.tGetInfo[3] = UnlimitDraw_GetNextLogin(human) and 1 or 0
|
|
|
+
|
|
|
+ Msg.send(tMsgData, human.fd)
|
|
|
+end
|
|
|
+
|
|
|
+function UnlimitDrawLogic_Do(human)
|
|
|
+ local nNowNum = UnlimitDraw_GetNum(human)
|
|
|
+ if 0 >= nNowNum then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local nDoNum = 10
|
|
|
+ local config = DrawCardExcel[UNLIMIT_CARD_ID]
|
|
|
+
|
|
|
+ if HeroLogic.getEmptyCnt(human) < nDoNum then
|
|
|
+ return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
|
|
|
+ end
|
|
|
+
|
|
|
+ UnlimitDraw_ClearCacheHero(human)
|
|
|
+
|
|
|
+ local heroLen = 0
|
|
|
+ local heroList = {}
|
|
|
+ local heroNewList = {}
|
|
|
+ local heroIndexList = {}
|
|
|
+ local fenjielist = {}
|
|
|
+ local heroIDs = nil
|
|
|
+
|
|
|
+ local randomMin = math.random(1, nDoNum)
|
|
|
+ for i = 1, nDoNum, 1 do
|
|
|
+ local nHeroID = UnlimitDraw_randHeroID(human, config, randomMin)
|
|
|
+ if nHeroID then
|
|
|
+ local heroConfig = HeroExcel[nHeroID]
|
|
|
+ local star = heroConfig.star
|
|
|
+ local name = heroConfig.name
|
|
|
+ local grade = heroConfig.grade
|
|
|
+ local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
|
|
|
+ -- local heroIndex, fjlist = HeroLogic.addHero(human, nHeroID, nil, 1, "draw_card")
|
|
|
+
|
|
|
+ heroLen = heroLen + 1
|
|
|
+ heroList[heroLen] = nHeroID
|
|
|
+ heroNewList[heroLen] = isNew
|
|
|
+
|
|
|
+ if not heroIDs then
|
|
|
+ heroIDs = nHeroID
|
|
|
+ else
|
|
|
+ heroIDs = heroIDs .. "|" .. nHeroID
|
|
|
+ end
|
|
|
+ else
|
|
|
+ print("[UnlimitDrawLogic_Do] 生成英雄失败直接返回")
|
|
|
+ return
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ local tMsgData = Msg.gc.GC_UNLIMITDRAW_DO
|
|
|
+ tMsgData.tHeros[0] = nDoNum
|
|
|
+ for i = 1, heroLen do
|
|
|
+ local heroID = heroList[i]
|
|
|
+ local isNew = heroNewList and heroNewList[i]
|
|
|
+ -- local index = heroIndexList and heroIndexList[i]
|
|
|
+ HeroGrid.makeHeroNice(tMsgData.tHeros[i], heroID, 1, isNew)
|
|
|
+ end
|
|
|
+
|
|
|
+ UnlimitDraw_SetCacheHero(human, heroList)
|
|
|
+ Msg.send(tMsgData, human.fd)
|
|
|
+end
|
|
|
+
|
|
|
+function UnlimitDrawLogic_Abandon(human)
|
|
|
+ UnlimitDraw_ClearCacheHero(human)
|
|
|
+end
|
|
|
+
|
|
|
+function UnlimitDrawLogic_Get(human)
|
|
|
+ local tHeroInfo = UnlimitDraw_GetCacheHero(human)
|
|
|
+ if not tHeroInfo then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local heroIndexList = {}
|
|
|
+ local fenjielist = {}
|
|
|
+ for _, nID in ipairs(tHeroInfo) do
|
|
|
+ local heroIndex, fjlist = HeroLogic.addHero(human, nID,nil, 1, "UnlimitDrawCard")
|
|
|
+ if fjlist and type(fjlist) == "table" then
|
|
|
+ for fjItemID, fjItemCnt in pairs(fjlist) do
|
|
|
+ fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ table.insert(heroIndexList, heroIndex)
|
|
|
+ end
|
|
|
+
|
|
|
+ if nil ~= _G.next(fenjielist) then
|
|
|
+ local tItem = {}
|
|
|
+ for key, value in pairs(fenjielist) do
|
|
|
+ table.insert(tItem, {key, value})
|
|
|
+ end
|
|
|
+ BagLogic.sendItemGetList(human, tItem, "UnlimitDrawCard")
|
|
|
+ end
|
|
|
+
|
|
|
+ UnlimitDraw_SetNum(human, -1)
|
|
|
+ UnlimitDrawLogic_Query(human)
|
|
|
+end
|
|
|
+
|
|
|
+function onLogin(human)
|
|
|
+ UnlimitDraw_CheckDB(human)
|
|
|
+
|
|
|
+ local bLogin = UnlimitDraw_GetLogin(human)
|
|
|
+ if false == bLogin then
|
|
|
+ UnlimitDraw_SetLogin(human, true)
|
|
|
+ UnlimitDraw_SetLoginTime(human, os.time())
|
|
|
+ UnlimitDraw_SetNum(human, 1)
|
|
|
+ else
|
|
|
+ local nLastTime = UnlimitDraw_GetLoginTime(human)
|
|
|
+ local bNextLogin = UnlimitDraw_GetNextLogin(human)
|
|
|
+ if not Util.isSameDay(nLastTime) and false == bNextLogin then
|
|
|
+ UnlimitDraw_SetNextLogin(human, true)
|
|
|
+ UnlimitDraw_SetNum(human, 1)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ local bLv = UnlimitDraw_GetLv(human)
|
|
|
+ if false == bLv and human.db.lv >= UNLIMIT_CARD_LV then
|
|
|
+ UnlimitDraw_SetLv(human, true)
|
|
|
+ UnlimitDraw_SetNum(human, 1)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+function onLvUp(human, nNewLv)
|
|
|
+ local bLv = UnlimitDraw_GetLv(human)
|
|
|
+ if false == bLv and nNewLv >= UNLIMIT_CARD_LV then
|
|
|
+ UnlimitDraw_SetLv(human, true)
|
|
|
+ UnlimitDraw_SetNum(human, 1)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+function ModuleisOpen(human)
|
|
|
+ UnlimitDraw_CheckDB(human)
|
|
|
+
|
|
|
+ if true == UnlimitDraw_GetLogin(human) and UnlimitDraw_GetLv(human) == true
|
|
|
+ and true == UnlimitDraw_GetNextLogin(human) then
|
|
|
+ if UnlimitDraw_GetNum(human) > 0 then
|
|
|
+ return true
|
|
|
+ else
|
|
|
+ return false
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ return true
|
|
|
+end
|
|
|
+
|
|
|
+function isDot(human)
|
|
|
+ UnlimitDraw_CheckDB(human)
|
|
|
+
|
|
|
+ if true == ModuleisOpen(human) then
|
|
|
+ return UnlimitDraw_GetNum(human) > 0 and true or false
|
|
|
+ end
|
|
|
+
|
|
|
+ return false
|
|
|
+end
|