| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- --------------------------------
- -- 文件名 : WeekendLoopActCard.lua
- -- 文件说明 : 周末冲刺活动-抽卡
- -- 创建时间 : 2024/12/03
- -- 创建人 : FC
- --------------------------------
- local Util = require("common.Util")
- local Lang = require("common.Lang")
- local Broadcast = require("broadcast.Broadcast")
- local MailExcel = require("excel.mail")
- local Msg = require("core.Msg")
- local ObjHuman = require("core.ObjHuman")
- local WeekLoopActDef = require("WeekendLoopActivity.WeekendLoopActDefine")
- local WeekLoopActCof = require("excel.WeekLoopAct")
- local CommonDB = require("common.CommonDB")
- local MailManager = require("mail.MailManager")
- 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 HeroExcel = require("excel.hero")
- local WeekendLoopActManger = require("WeekendLoopActivity.WeekendLoopActManager")
- ----------------------------------------- 内部处理开始 -------------------------------------
- tCardPrize = nil
- -- 写日志
- local function WeekActCard_WriteLog(human, szFuncName, sztext)
- Log.write(Log.LOGID_OSS_WEEKLOOP_ACT, szFuncName..sztext.." _id = "..human.db._id.." name = "..human.db.name)
- end
- -- 下发数据
- local function WeekActCard_SendData(tMsgData, fd)
- Msg.send(tMsgData, fd)
- end
- -- 获取配置
- local function WeekActCard_GetConfig()
- if not WeekLoopActCof then
- return nil
- end
- return WeekLoopActCof.Card
- end
- -- 获取配置
- local function WeekActCard_GetConfigByType(nType)
- if not tCardPrize or not tCardPrize[nType] then
- return nil
- end
- return tCardPrize[nType]
- end
- -- 初始化抽卡类型
- local function WeekActCard_ResetCardType(human)
- if not human then
- print("[WeekActCard_ResetCardType] 参数不正确")
- return false
- end
- if not human.db.nWeekCardType then
- human.db.nWeekCardType = 1
- else
- -- math.fmod()
- local nLen = (human.db.nWeekCardType + 1) % WeekLoopActDef.WEEKACT_CARD_TYPE_LEN
- human.db.nWeekCardType = (0 == nLen) and WeekLoopActDef.WEEKACT_CARD_TYPE_LEN or nLen
- end
- return true
- end
- -- 获取抽卡类型
- local function WeekActCard_GetCardType(human)
- if not human then
- print("[WeekActCard_GetCardType] 参数不正确")
- return -1
- end
- return WeekendLoopActManger.WeekLoopACT_GetCardBatch()
- -- if not human.db.nWeekCardType then
- -- local bRet = WeekActCard_ResetCardType(human)
- -- if false == bRet then
- -- WeekActCard_WriteLog(human, "[WeekActCard_GetCardType]", "获取抽卡类型,不存在对应字段,重新初始化失败")
- -- return -1
- -- end
- -- WeekActCard_WriteLog(human, "[WeekActCard_GetCardType]", "获取抽卡类型,不存在对应字段,初始化顺序有问题, 重新初始化成功")
- -- end
- -- return human.db.nWeekCardType
- end
- -- 通过人物抽卡类型获取配置
- local function WeekActCard_GetConfigByHuman(human)
- if not human then
- return nil
- end
- local nNowType = WeekActCard_GetCardType(human)
- if -1 >= nNowType then
- return nil
- end
- return WeekActCard_GetConfigByType(nNowType)
- end
- -- 初始化奖励信息
- local function WeekActCard_ResetPrize(human)
- if not human then
- return false
- end
- local nNowType = WeekActCard_GetCardType(human)
- if -1 >= nNowType then
- print("[WeekActCard_ResetPrize] 获取抽卡类型失败")
- return false
- end
- local tConfig = WeekActCard_GetConfigByType(nNowType)
- if not tConfig then
- return false
- end
- if not human.db.tWeekCardPrize then
- human.db.tWeekCardPrize = {}
- end
- for nID, v in pairs(tConfig) do
- human.db.tWeekCardPrize[nID] = WeekLoopActDef.WEEKACT_STATE_NONE
- end
-
- return true
- end
- -- 获取奖励表
- local function WeekActCard_GetDBPrize(human)
- if not human then
- return nil
- end
- if not human.db.tWeekCardPrize then
- return nil
- end
-
- return human.db.tWeekCardPrize
- end
- -- 获取奖励ID状态
- local function WeekActCard_GetPrizeStatus(human, nID)
- if not human then
- return WeekLoopActDef.WEEKACT_STATE_NONE
- end
- local tPrize = WeekActCard_GetDBPrize(human)
- if not tPrize or not tPrize[nID] then
- return WeekLoopActDef.WEEKACT_STATE_NONE
- end
-
- return tPrize[nID]
- end
- -- 设置奖励ID状态
- local function WeekActCard_SetPrizeStatus(human, nID, nStatus)
- if not human then
- return false
- end
- local tPrize = WeekActCard_GetDBPrize(human)
- if not tPrize or not tPrize[nID] then
- print("[WeekActCard_SetPrizeStatus] 获取不到对应的奖励表 "..nID.." nStatus = "..nStatus)
- return false
- end
- tPrize[nID] = nStatus
- return true
- end
- -- 初始化抽卡数量
- local function WeekActCard_ResetCardNum(human)
- if not human then
- print("[WeekActCard_ResetCardNum] 参数不正确")
- return false
- end
- human.db.nWeekCardNum = 0
- return true
- end
- -- 获取抽卡数量
- local function WeekActCard_GetCardNum(human)
- if not human then
- print("[WeekActCard_GetCardNum] 参数不正确")
- return -1
- end
- if not human.db.nWeekCardNum then
- local bRet = WeekActCard_ResetCardNum(human)
- if false == bRet then
- WeekActCard_WriteLog(human, "[WeekActCard_GetGuYuNum]", "获取抽卡数量,不存在对应字段,重新初始化失败")
- return -1
- end
- WeekActCard_WriteLog(human, "[WeekActCard_GetGuYuNum]", "获取抽卡数量,不存在对应字段,初始化顺序有问题, 重新初始化成功")
- end
- return human.db.nWeekCardNum
- end
- -- 设置抽卡数量
- local function WeekActCard_SetCardNum(human, nValue)
- if not human then
- print("[WeekActCard_SetCardNum] 参数不正确")
- return
- end
- local nNowCard = WeekActCard_GetCardNum(human)
- if -1 >= nNowCard then
- WeekActCard_WriteLog(human, "[WeekActCard_SetCardNum]", "获取古玉数量失败")
- return
- end
- local nNewGuYu = nNowCard + nValue
- if 0 > nNewGuYu then
- nNewGuYu = 0
- end
- human.db.nWeekCardNum = nNewGuYu
- end
- ----------------------------------------- 外部调用 -------------------------------------
- function Init()
- tCardPrize = {}
- local tConfig = WeekActCard_GetConfig()
- if not tConfig then
- return false
- end
- for nID, v in pairs(tConfig) do
- local nType = v.nType
- if not tCardPrize[nType] then
- tCardPrize[nType] = {}
- end
- local nTrueID = nID % WeekLoopActDef.WEEKACT_CARD_PRIZEID_LEN
- tCardPrize[nType][nTrueID] = v
- end
- return true
- end
- -- 重置数据
- function WeekActCard_ResetData(human)
- if not human then
- return
- end
- -- 先更新抽卡类型
- --WeekActCard_ResetCardType(human)
- -- 重置抽卡数量
- WeekActCard_ResetCardNum(human)
- -- 重置奖励信息
- if false == WeekActCard_ResetPrize(human) then
- print("[WeekActCard_ResetData] 重置抽卡奖励数据失败")
- return
- end
- WeekActCard_WriteLog(human, "[WeekActCard_ResetData]", "抽卡奖励相关重置完成")
- print("[WeekActCard_ResetData] 抽卡 数据重置结束 ")
- end
- -- 是否有红点
- function isRed(human)
- local tPrize = WeekActCard_GetConfigByHuman(human)
- if not tPrize then
- return false
- end
- for nID, v in pairs(tPrize) do
- if WeekLoopActDef.WEEKACT_STATE_CANGET == WeekActCard_GetPrizeStatus(human, nID) then
- return true
- end
- end
- return false
- end
- -- 抽卡回调
- function WeekActCard_UseCard(human, nAddNum, nType)
- if not human or 0 >= nAddNum then
- return
- end
- local nNowType = WeekActCard_GetCardType(human)
- print("[WeekActCard_UseCard] nNowType = "..nNowType.." nType = "..nType)
- if nNowType ~= nType then
- return
- end
- local DBID = human.db._id
- local szName = human.db.name
- local tConfig = WeekActCard_GetConfigByHuman(human)
- if not tConfig then
- print("[WeekActCard_UseCard] 获取不到配置 DBID = "..DBID.." name = "..szName)
- return
- end
- WeekActCard_SetCardNum(human, nAddNum)
-
- local nNowCard = WeekActCard_GetCardNum(human)
- if -1 >= nNowCard then
- WeekActCard_WriteLog(human, "[WeekActCard_UseCard]", "获取玩家当前抽卡次数失败 nAddNum = "..nAddNum)
- print("[WeekActCard_UseCard] 获取不到抽卡次数 DBID = "..DBID.." name = "..szName.." nAddNum = "..nAddNum)
- return
- end
- local bChange = false
- for nID, v in pairs(tConfig) do
- local nStatus = WeekActCard_GetPrizeStatus(human, nID)
- if nNowCard >= v.nNum and WeekLoopActDef.WEEKACT_STATE_NONE == nStatus then
- bChange = true
- local bRet = WeekActCard_SetPrizeStatus(human, nID, WeekLoopActDef.WEEKACT_STATE_CANGET)
- if false == bRet then
- print("[WeekActCard_UseCard] 设置失败 nID = "..nID.." nStatus = "..nStatus.." num = "..v.nNum)
- end
- end
- end
- if true == bChange then
- WeekActCard_Query(human)
- WeekendLoopActManger.WeekLoopACT_SendActInfo(human)
- end
- end
- -- 获取名称
- function GetName(human)
- if not human then
- return WeekLoopActDef.TWEEKACT_CARD_PANELID_NAME[1]
- end
- local nNowCardType = WeekActCard_GetCardType(human)
- if -1 >= nNowCardType then
- return WeekLoopActDef.TWEEKACT_CARD_PANELID_NAME[1]
- end
- if not WeekLoopActDef.TWEEKACT_CARD_PANELID_NAME[nNowCardType] then
- return WeekLoopActDef.TWEEKACT_CARD_PANELID_NAME[1]
- end
- return WeekLoopActDef.TWEEKACT_CARD_PANELID_NAME[nNowCardType]
- end
- ----------------------------------------- 客户端请求 -------------------------------------
- -- 客户端请求-抽卡信息
- function WeekActCard_Query(human)
- if not human then
- return
- end
- local DBID = human.db._id
- local szName = human.db.name
- local tConfig = WeekActCard_GetConfigByHuman(human)
- if not tConfig then
- print("[WeekActCard_Query] 获取不到配置 DBID = "..DBID.." name = "..szName)
- return
- end
- local tMsgData = Msg.gc.GC_WEEKLOOP_ACT_CARDQUERY
- tMsgData.byType = WeekActCard_GetCardType(human)
- tMsgData.nNowNum = WeekActCard_GetCardNum(human)
- tMsgData.list[0] = 0
- for nID, v in pairs(tConfig) do
- tMsgData.list[0] = tMsgData.list[0] + 1
- local tData = tMsgData.list[tMsgData.list[0]]
- tData.nNum = v.nNum
- tData.nID = nID
- tData.desc = v.szdesc
- tData.nState = WeekActCard_GetPrizeStatus(human, nID)
- tData.item[0] = #v.prize
- for nIndex, tItem in ipairs(v.prize) do
- local nGoodsID = tItem[1]
- local nGoodsNum = tItem[2]
- Grid.makeItem(tData.item[nIndex], nGoodsID, nGoodsNum)
- end
- end
- WeekActCard_SendData(tMsgData, human.fd)
- end
- -- 客户端请求领取奖励
- function WeekActCard_GetPrize(human)
- if not human then
- return
- end
- local DBID = human.db._id
- local szName = human.db.name
- local tConfig = WeekActCard_GetConfigByHuman(human)
- if not tConfig then
- print("[WeekActCard_GetPrize] 获取不到配置 DBID = "..DBID.." name = "..szName)
- return
- end
- local tItemList = {}
- for nID, v in pairs(tConfig) do
- if WeekLoopActDef.WEEKACT_STATE_CANGET == WeekActCard_GetPrizeStatus(human, nID) then
- if false == WeekActCard_SetPrizeStatus(human, nID, WeekLoopActDef.WEEKACT_STATE_FINISH) then
- print("[WeekActCard_GetPrize] 奖励领取失败 nID = "..nID)
- WeekActCard_WriteLog(human, "[WeekActCard_GetPrize]", "领取奖励, 设置奖励状态失败 nID = "..nID)
- break
- end
- for _, data in ipairs(v.prize) do
- local nItemID = data[1]
- local nItemNum = data[2]
- tItemList[nItemID] = tItemList[nItemID] or 0
- tItemList[nItemID] = tItemList[nItemID] + nItemNum
- end
- end
- end
- if nil ~= _G.next(tItemList) then
- local tGoodsInfo = {}
- for k, v in pairs(tItemList) do
- table.insert(tGoodsInfo, {k,v})
- -- 获取奖励写日志
- WeekActCard_WriteLog(human, "[WeekActCard_GetPrize]", "玩家获取奖励 nGoodsID = "..k.." nGoodsNum = "..v)
- end
- BagLogic.addItemList(human, tGoodsInfo, "week_loop_act")
- BagLogic.sendItemGetList(human, tItemList, "week_loop_act")
- end
- WeekActCard_Query(human)
- WeekendLoopActManger.WeekLoopACT_SendActInfo(human)
- end
|