|
|
@@ -13,9 +13,41 @@ local Log = require("common.Log")
|
|
|
local YunYingLogic = require("yunying.YunYingLogic")
|
|
|
|
|
|
ABS_ACT_ID = 9001
|
|
|
+NEW_HERO_MODULE_FN = "absAct.NewHeroLogic"
|
|
|
+NEW_HERO_ACT_TYPES = {}
|
|
|
--
|
|
|
function initAfterHot()
|
|
|
-
|
|
|
+ NEW_HERO_ACT_TYPES = {}
|
|
|
+ for _, config in pairs(AbsActExcel.absActivity) do
|
|
|
+ if config.moduleFn == NEW_HERO_MODULE_FN then
|
|
|
+ NEW_HERO_ACT_TYPES[#NEW_HERO_ACT_TYPES + 1] = config.type
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+function getActiveActId(human)
|
|
|
+ for _, actType in ipairs(NEW_HERO_ACT_TYPES) do
|
|
|
+ local state, actId = AbsActLogic.isStartedByType(human, actType)
|
|
|
+ if state and actId then
|
|
|
+ return actId
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+local function getGiftConfig(giftId, actId)
|
|
|
+ local config = AbsActExcel.absEva[giftId]
|
|
|
+ if not config or config.actId ~= actId then
|
|
|
+ return
|
|
|
+ end
|
|
|
+ return config
|
|
|
+end
|
|
|
+
|
|
|
+local function copyRewardList(reward)
|
|
|
+ local items = {}
|
|
|
+ for _, v in ipairs(reward) do
|
|
|
+ items[#items + 1] = {v[1], v[2], v[3]}
|
|
|
+ end
|
|
|
+ return items
|
|
|
end
|
|
|
|
|
|
--
|
|
|
@@ -35,7 +67,11 @@ end
|
|
|
|
|
|
--
|
|
|
function getLeftTime(human, YInfo, funcConfig)
|
|
|
- local ret, endTime, startTime = AbsActLogic.isStarted(human, ABS_ACT_ID)
|
|
|
+ local actId = funcConfig and funcConfig.funcID or getActiveActId(human)
|
|
|
+ if not actId then
|
|
|
+ return 0
|
|
|
+ end
|
|
|
+ local ret, endTime, startTime = AbsActLogic.isStarted(human, actId)
|
|
|
if ret == true then
|
|
|
return endTime - os.time()
|
|
|
else
|
|
|
@@ -44,31 +80,66 @@ function getLeftTime(human, YInfo, funcConfig)
|
|
|
end
|
|
|
|
|
|
function getNewHeroID(human)
|
|
|
- local startedFlag, endTime, startTime = AbsActLogic.isStarted(human, ABS_ACT_ID)
|
|
|
- if not startedFlag then return 0 end
|
|
|
- local absActConfig = AbsActExcel.absActivity[ABS_ACT_ID]
|
|
|
+ local actId = getActiveActId(human)
|
|
|
+ if not actId then return 0 end
|
|
|
+ local absActConfig = AbsActExcel.absActivity[actId]
|
|
|
if not absActConfig then return 0 end
|
|
|
|
|
|
return absActConfig.icon
|
|
|
end
|
|
|
|
|
|
+local function getActClientIndex(actId)
|
|
|
+ if actId == 9001 then
|
|
|
+ return 1
|
|
|
+ elseif actId == 9002 then
|
|
|
+ return 2
|
|
|
+ elseif actId == 9003 then
|
|
|
+ return 3
|
|
|
+ end
|
|
|
+ return 0
|
|
|
+end
|
|
|
+
|
|
|
+local function getActLogType(actId)
|
|
|
+ if actId == 9002 then
|
|
|
+ return "newhero_reward_9002"
|
|
|
+ elseif actId == 9003 then
|
|
|
+ return "newhero_reward_9003"
|
|
|
+ end
|
|
|
+ return "newhero_reward"
|
|
|
+end
|
|
|
+
|
|
|
function getAndSendMsg(human, id, actId)
|
|
|
local now = os.time()
|
|
|
local startedFlag, endTime, startTime = AbsActLogic.isStarted(human, id)
|
|
|
- if not startedFlag then return end
|
|
|
+ if not startedFlag then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
|
|
|
+ end
|
|
|
local absActConfig = AbsActExcel.absActivity[id]
|
|
|
- if not absActConfig then return end
|
|
|
+ if not absActConfig then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
|
|
|
local absAct = human.db.absAct[id]
|
|
|
- if not absAct then return end
|
|
|
+ if not absAct then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
|
|
|
local msgRet = Msg.gc.GC_ABS_NEWHERO
|
|
|
msgRet.id = absActConfig.icon
|
|
|
msgRet.startTime = startTime
|
|
|
msgRet.endTime = endTime
|
|
|
+ msgRet.actIndex = getActClientIndex(id)
|
|
|
|
|
|
local index = 0
|
|
|
- for giftId, v in ipairs(AbsActExcel.absEva) do
|
|
|
+ local giftIds = {}
|
|
|
+ for giftId, v in pairs(AbsActExcel.absEva) do
|
|
|
+ if v.actId == id then
|
|
|
+ giftIds[#giftIds + 1] = giftId
|
|
|
+ end
|
|
|
+ end
|
|
|
+ table.sort(giftIds)
|
|
|
+ for _, giftId in ipairs(giftIds) do
|
|
|
+ local v = AbsActExcel.absEva[giftId]
|
|
|
index = index + 1
|
|
|
for j = 1, #v.reward do
|
|
|
Grid.makeItem(msgRet.giftlist[index].item[j], v.reward[j][1], v.reward[j][2])
|
|
|
@@ -105,13 +176,16 @@ function getAndSendMsg(human, id, actId)
|
|
|
end
|
|
|
end
|
|
|
msgRet.giftlist[0] = index
|
|
|
+ if index == 0 then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
|
|
|
Msg.send(msgRet, human.fd)
|
|
|
end
|
|
|
|
|
|
-function getgiftbybuyid(buyid)
|
|
|
- for giftId, v in ipairs(AbsActExcel.absEva) do
|
|
|
- if v.buyID == buyid then
|
|
|
+function getgiftbybuyid(buyid, actId)
|
|
|
+ for giftId, v in pairs(AbsActExcel.absEva) do
|
|
|
+ if v.buyID == buyid and v.actId == actId then
|
|
|
return giftId
|
|
|
end
|
|
|
end
|
|
|
@@ -120,14 +194,35 @@ end
|
|
|
function newheroGift(human, id, buyConf, isFirst, cnt, buyNum)
|
|
|
local state = AbsActLogic.isStarted(human, id)
|
|
|
local absConfig = AbsActExcel.absActivity[id]
|
|
|
- if absConfig == nil or not state then return end
|
|
|
+ if absConfig == nil then
|
|
|
+ Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
|
|
|
+ "[NewHeroLogic.newheroGift] absActivity config not found, actId=%s, buyID=%s, newUniqueTag=%s",
|
|
|
+ tostring(id), tostring(buyConf and buyConf.id), tostring(human.db.newUniqueTag)))
|
|
|
+ return
|
|
|
+ end
|
|
|
+ if not state then
|
|
|
+ Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
|
|
|
+ "[NewHeroLogic.newheroGift] act not started, actId=%s, buyID=%s, newUniqueTag=%s, now=%s",
|
|
|
+ tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag), os.time()))
|
|
|
+ return
|
|
|
+ end
|
|
|
|
|
|
-- 存在多个特惠礼包 同时 开放
|
|
|
- local giftid = getgiftbybuyid(buyConf.id)
|
|
|
- if not giftid then return end
|
|
|
+ local giftid = getgiftbybuyid(buyConf.id, id)
|
|
|
+ if not giftid then
|
|
|
+ Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
|
|
|
+ "[NewHeroLogic.newheroGift] absEva gift not found, actId=%s, buyID=%s, newUniqueTag=%s",
|
|
|
+ tostring(id), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
|
|
|
+ return
|
|
|
+ end
|
|
|
|
|
|
- local config = AbsActExcel.absEva[giftid]
|
|
|
- if not config then return end
|
|
|
+ local config = getGiftConfig(giftid, id)
|
|
|
+ if not config then
|
|
|
+ Log.write(Log.LOGID_OSS_COMMON_ACT, string.format(
|
|
|
+ "[NewHeroLogic.newheroGift] absEva gift config invalid, actId=%s, giftId=%s, buyID=%s, newUniqueTag=%s",
|
|
|
+ tostring(id), tostring(giftid), tostring(buyConf.id), tostring(human.db.newUniqueTag)))
|
|
|
+ return
|
|
|
+ end
|
|
|
|
|
|
AbsActLogic.checkAbsActClean(human, id)
|
|
|
|
|
|
@@ -167,8 +262,8 @@ function newheroGift(human, id, buyConf, isFirst, cnt, buyNum)
|
|
|
-- BagLogic.addItemList(human, config.reward, "newhero_reward")
|
|
|
human.db.absAct[id].newheroCnt[giftid] = nowBuyCnt + 1
|
|
|
-- 发放物品
|
|
|
- -- local items = { }
|
|
|
- BagLogic.addItemList(human, config.reward, "newhero_reward")
|
|
|
+ local items = copyRewardList(config.reward)
|
|
|
+ BagLogic.addItemList(human, items, getActLogType(id))
|
|
|
|
|
|
Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
|
|
|
AbsActLogic.actDetailQuery(human, id)
|
|
|
@@ -176,20 +271,34 @@ end
|
|
|
|
|
|
|
|
|
function giftBuy(human, giftid)
|
|
|
- local state = AbsActLogic.isStarted(human, ABS_ACT_ID)
|
|
|
- if state ~= true then return end
|
|
|
- local absConfig = AbsActExcel.absActivity[ABS_ACT_ID]
|
|
|
- if not absConfig then return end
|
|
|
+ local actId = getActiveActId(human)
|
|
|
+ if not actId then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
|
|
|
+ end
|
|
|
+
|
|
|
+ local state = AbsActLogic.isStarted(human, actId)
|
|
|
+ if state ~= true then
|
|
|
+ return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
|
|
|
+ end
|
|
|
+ local absConfig = AbsActExcel.absActivity[actId]
|
|
|
+ if not absConfig then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
|
|
|
- AbsActLogic.checkAbsActClean(human, ABS_ACT_ID)
|
|
|
+ AbsActLogic.checkAbsActClean(human, actId)
|
|
|
|
|
|
-- 存在多个特惠礼包 同时 开放
|
|
|
- local config = AbsActExcel.absEva[giftid]
|
|
|
- if config.buyID ~= 0 then return end
|
|
|
+ local config = getGiftConfig(giftid, actId)
|
|
|
+ if not config then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
|
|
|
+ end
|
|
|
+ if config.buyID ~= 0 then
|
|
|
+ return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
|
|
|
+ end
|
|
|
|
|
|
-- 初始化已购买次数
|
|
|
- human.db.absAct[ABS_ACT_ID].newheroCnt = human.db.absAct[ABS_ACT_ID].newheroCnt or { }
|
|
|
- local nowBuyCnt = human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] or 0
|
|
|
+ human.db.absAct[actId].newheroCnt = human.db.absAct[actId].newheroCnt or { }
|
|
|
+ local nowBuyCnt = human.db.absAct[actId].newheroCnt[giftid] or 0
|
|
|
-- 判断是否达到购买上限
|
|
|
if nowBuyCnt >= config.limit then
|
|
|
Broadcast.sendErr(human, Lang.HERO_BAG_BUY_CAP_NO_CNT)
|
|
|
@@ -214,28 +323,32 @@ function giftBuy(human, giftid)
|
|
|
end
|
|
|
end
|
|
|
|
|
|
- BagLogic.delItem(human, itemID, itemCnt, "newhero_reward")
|
|
|
+ BagLogic.delItem(human, itemID, itemCnt, getActLogType(actId))
|
|
|
|
|
|
-- 增加已购买次数
|
|
|
- human.db.absAct[ABS_ACT_ID].newheroCnt[giftid] = nowBuyCnt + 1
|
|
|
+ human.db.absAct[actId].newheroCnt[giftid] = nowBuyCnt + 1
|
|
|
-- 发放物品
|
|
|
- -- local items = { }
|
|
|
- BagLogic.addItemList(human, AbsActExcel.absEva[giftid].reward, "newhero_reward")
|
|
|
+ local items = copyRewardList(config.reward)
|
|
|
+ BagLogic.addItemList(human, items, getActLogType(actId))
|
|
|
|
|
|
Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
|
|
|
|
|
|
- AbsActLogic.actDetailQuery(human, ABS_ACT_ID)
|
|
|
+ AbsActLogic.actDetailQuery(human, actId)
|
|
|
end
|
|
|
|
|
|
function updateDaily(human, id)
|
|
|
- if human.db.absAct[ABS_ACT_ID] then
|
|
|
- human.db.absAct[ABS_ACT_ID] = {}
|
|
|
+ if not id then return end
|
|
|
+
|
|
|
+ if human.db.absAct[id] then
|
|
|
+ human.db.absAct[id] = {}
|
|
|
end
|
|
|
- local state = AbsActLogic.isStarted(human, ABS_ACT_ID)
|
|
|
+ local state = AbsActLogic.isStarted(human, id)
|
|
|
if state ~= true then
|
|
|
- human.db.drawCard.list[8] = {}
|
|
|
+ if getActiveActId(human) == nil then
|
|
|
+ human.db.drawCard.list[8] = {}
|
|
|
+ end
|
|
|
end
|
|
|
- AbsActLogic.actDetailQuery(human, ABS_ACT_ID)
|
|
|
+ AbsActLogic.actDetailQuery(human, id)
|
|
|
end
|
|
|
|
|
|
-- function GetRemainNum(human, nBuyID)
|
|
|
@@ -256,4 +369,4 @@ function updateDaily(human, id)
|
|
|
-- else
|
|
|
-- return config.limit - human.db.absAct[ABS_ACT_ID].newheroCnt[giftid]
|
|
|
-- end
|
|
|
--- end
|
|
|
+-- end
|