local Activity = class("Activity", require("shared.ModelBase")) local string_format = string.format -- activity_ctr showType Activity.ActivityType = { SsrUpPoolChange = 1, -- 特定英雄活动,切卡池 DoubleDrop = 2, -- 双倍掉落 Sign = 4, -- 签到 ChangeCG = 5, -- 客户端使用,切换抽卡界面 PaySignIn = 6, --付费签到 ExploreCommand = 7, -- 探索指令 PayBack = 8, --返利 BonusDouble = 9, -- 奖励关卡翻倍 CalendaTask = 10, -- 日历任务 FoodSell = 11, --贩卖周 料理 DrawHero = 12, --抽卡周 招募 AdvDraw = 13, --拾荒抽周 资助 OpenBox = 14, --拆解周 时钟箱 RaceDraw = 16, -- 定向招募活动 ChallengeLevel = 17, -- 挑战关卡活动 Exchange = 18, -- 兑换活动 HangDrop = 19, -- 挂机掉落活动 Gachakon = 20, -- 扭蛋活动 WishHeroPool = 23, -- 心愿卡池 ActHeroPool = 24, -- 活动卡池 ActShopGoods = 25, -- 活动商品 Crisis = 26, -- 宝藏怪活动 CommonSignIn = 28, --通用签到 FriendEnergy = 30, -- 好友互赠能量活动 } local function checkActivityType(activityType) if type(activityType) == "string" then activityType = Activity.ActivityType[activityType] end return activityType or 0 end function Activity:ctor(properties) Activity.super.ctor(self, properties) self._isOpen = {} end function Activity:getType(actType) if type(actType) == "string" then actType = Activity.ActivityType[actType] end return actType or 0 end Activity.schema = { actime = {"table", {}}, -- 最近检查某项活动的开始时间 {id = time} round = {"table", {}}, -- 记录活动到了第几轮 {id = roundnum} act4 = {"table", {}}, -- {0 = day, 1= -1, 2 = -1} == 签到活动 act6 = {"table", {}}, -- {0 = day, 1 = 1, 2 = 1} == 付费签到活动 act8 = {"number", 0}, -- 充值返利 act11 = {"table", {}}, -- {0 = 贩卖数量, 1=1, 2=1} 贩卖周活动 1表示领取过该档位的奖励 act12 = {"table", {}}, -- {0 = 抽卡次数, 1=1, 2=1} 抽卡周活动 1表示领取过该档位的奖励 act13 = {"table", {}}, -- {0 = 拾荒消耗远古金币数量, 1=1, 2=1} 拾荒周活动 1表示领取过该档位的奖励 act14 = {"table", {}}, -- {0 = 拆解数量, 1=1, 2=1} 拆解周活动 1表示领取过该档位的奖励 act17 = {"table", {}}, -- {id=关卡星数, totalDmg=Boss总伤害} act18 = {"table", {}, true}, -- {id=兑换数量} act19 = {"number", 0}, -- {挂机信息} act20 = {"table", {}}, -- {id=扭蛋抽出数量} act24 = {"table", {}, true}, -- 活动卡池 {id=repaynum} act26 = {"table", {}}, -- {task = {id = count}, socre = {id = status}} act28 = {"table", {}}, -- 每日活跃签到 {0=day, 1=1,2=1,3=1} act30 = {"table", {}}, -- {magic = 0, limit = 0, reward = {id = 1, id = 1}, giveAE = {}, getAE = {}} 奖励字段1表示领取过奖励 } function Activity:data() return { actime = self:getProperty("actime"), round = self:getProperty("round"), act4 = self:getProperty("act4"), act6 = self:getProperty("act6"), act8 = self:getProperty("act8"), act11 = self:getProperty("act11"), act12 = self:getProperty("act12"), act13 = self:getProperty("act13"), act14 = self:getProperty("act14"), act17 = self:getProperty("act17"), act18 = self:getProperty("act18"), act19 = self:getProperty("act19"), act20 = self:getProperty("act20"), act24 = self:getProperty("act24"), act26 = self:getProperty("act26"), act28 = self:getProperty("act28"), act30 = self:getProperty("act30"), } end function Activity:updateProperty(params) local type, default = table.unpack(self.schema[params.field]) if params.delta then self:incrProperty(params.field, params.delta) if not params.notNotify then self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) end return true end if params.value then self:setProperty(params.field, params.value) if not params.notNotify then self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field)) end return true end return false end function Activity:isOpenRaw(activityId, now) activityId = checkActivityType(activityId) local actData = csvdb["activity_ctrlCsv"][activityId] if not actData then return end if actData.time == "" then -- 关闭 return false end local st = 0 local et = 0 --local now = skynet.timex() if actData.ttype == 0 then -- 时间开放 local openTimes = actData.time:toArray(false, "=") if openTimes[1] ~= "0" then st = toUnixtime(openTimes[1]..string_format("%02x", RESET_TIME)) end if openTimes[2] ~= "0" then et = toUnixtime(openTimes[2]..string_format("%02x", RESET_TIME)) end elseif actData.ttype == 1 then -- 周期开放 local openTimes = actData.time:toArray(true, "=") local resetTime = toUnixtime(tostring(openTimes[1]) .. string_format("%02x", RESET_TIME)) local r = math.floor((now - resetTime) / (openTimes[3] * 86400)) st = resetTime + r * (openTimes[3] * 86400) et = st + openTimes[2] * 86400 else return end if now >= st and (et == 0 or now < et) then return true, st end return false end -- 缓存开放 function Activity:isOpen(activityType) activityType = checkActivityType(activityType) --return self._isOpen[activityType] local open = false for id, data in pairs(csvdb["activity_ctrlCsv"]) do if data.showType == activityType then open = self._isOpen[data.id] if open then return true, data.id end end end return false end function Activity:isOpenById(id, activityType) activityType = checkActivityType(activityType) local cfg = csvdb["activity_ctrlCsv"][id] if not cfg then return false end if activityType ~= 0 and cfg.showType ~= activityType then return false end return self._isOpen[id] end function Activity:getActData(actType) actType = checkActivityType(actType) return self:getProperty("act" .. actType) end function Activity:updateActData(actType, data, notNotify) actType = checkActivityType(actType) self:updateProperty({field = "act" .. actType, value = data, notNotify = notNotify}) end -- 跨天刷新 --登录刷新 function Activity:checkActivityStatus(now, isCrossDay, notify) self._isOpen = {} local actime = self:getProperty("actime") local change = false for actId, actData in pairs(csvdb["activity_ctrlCsv"]) do local isOpen, startTime = self:isOpenRaw(actId, now) self._isOpen[actId] = isOpen if isOpen then if actime[actId] and actime[actId] == startTime then -- 还是之前的状态 开放中 self:onLoginActivity(actId) else -- 重置 actime[actId] = startTime self:closeActivity(actId, notify, true) self:initActivity(actId, isCrossDay, notify) change = true end else if actime[actId] then self:closeActivity(actId, notify) actime[actId] = nil change = true end end end if change then self:updateProperty({field = "actime", value = actime, notNotify = not notify}) end end local activityFunc = {} activityFunc[Activity.ActivityType.Sign] = { -- ["check"] = function(self, actType, notify) -- 检查 -- end, ["init"] = function(self, actType, isCrossDay, notify) if not isCrossDay then activityFunc[Activity.ActivityType.Sign]["crossDay"](self, actType, notify) end end, -- ["close"] = function(self, actType, notify) -- end, ["crossDay"] = function(self, actType, notify) local curData = self:getActData(actType) curData[0] = (curData[0] or 0) + 1 local actData = csvdb["new_signInCsv"] if curData[0] > #actData then return end -- 满了就忽略了 -- 没满更新一下 self:updateActData(actType, curData, not notify) end, } --loop1:累计料理贩卖N次 --loop2:累计招募N次 --loop3:累计资助N次 --loop4:时钟箱拆解N个 function Activity:checkWeeklyAct(actType, notify, count, pool) local actInfoMap = { [Activity.ActivityType.DrawHero] = {mailId = MailId.ActDrawCardReward, table = "activity_loop2Csv"}, [Activity.ActivityType.AdvDraw] = {mailId = MailId.ActAdvDrawReward, table = "activity_loop3Csv"}, [Activity.ActivityType.OpenBox] = {mailId = MailId.ActOpenBoxReward, table = "activity_loop4Csv"}, [Activity.ActivityType.FoodSell] = {mailId = MailId.ActSellFoodReward, table = "activity_loop1Csv"} } if actType == Activity.ActivityType.DrawHero and pool == DrawCardType.FriendDraw then return end local info = actInfoMap[actType] if not info then return end local open, actId = self:isOpen(actType) if not open then return end local curData = self:getActData(actType) local roundData = self:getProperty("round") local curRound = roundData[actType] or 0 local ctrlData = csvdb["activity_ctrlCsv"][actId] if not ctrlData then return end if curRound >= ctrlData.condition then return end curData[0] = (curData[0] or 0) + count local totalCnt = 0 local finishCnt = 0 local maxCondition = 0 local flag = true while flag do --print("tatal number :", curData[0]) for i = 1, #csvdb[info.table] do local cfg = csvdb[info.table][i] --for k, cfg in pairs(csvdb[info.table] or {}) do totalCnt = totalCnt + 1 if maxCondition < cfg.condition1 then maxCondition = cfg.condition1 end --print("cur condition", cfg.condition1) if curData[0] < cfg.condition1 then flag = false break end --print(curData[0], cfg.condition1) if not curData[cfg.id] and curData[0] >= cfg.condition1 then if info.mailId then self.owner:log("activity", { activity_id = cfg.id, -- 活动ID(或活动指定任务的ID) activity_type = actType, -- 活动类型,见活动类型枚举表 activity_reward = cfg.reward:toNumMap(), -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} }) self.owner:sendMail(info.mailId, nil, cfg.reward, {cfg.condition1}) curData[cfg.id] = 1 end end if curData[cfg.id] then finishCnt = finishCnt + 1 end end if totalCnt == finishCnt then roundData[actType] = (roundData[actType] or 0) + 1 for k,v in pairs(curData) do if k == 0 then curData[k] = curData[0] >= maxCondition and curData[0] - maxCondition or 0 else curData[k] = nil end end --print("cur round ".. roundData[actType], ctrlData.condition) if roundData[actType] >= ctrlData.condition then curData[0] = maxCondition flag = false end self:updateProperty({field = "round", value = roundData, notNotify = not notify}) end end self:updateActData(actType, curData, not notify) end -- 抽卡周 activityFunc[Activity.ActivityType.DrawHero] = { ["check"] = function(self, actType, notify, count, pool) -- 检查 self:checkWeeklyAct(actType, notify, count, pool) end, ["init"] = function(self, actType, isCrossDay, notify) local roundData = self:getProperty("round") roundData[actType] = 0 self:updateProperty({field = "round", value = roundData, notNotify = not notify}) end, -- ["close"] = function(self, actType, notify) -- end, ["crossDay"] = function(self, actType, notify) self.owner:sendMail(MailId.ActDrawCard) end, } -- 售卖周 activityFunc[Activity.ActivityType.FoodSell] = { ["check"] = function(self, actType, notify, count) -- 检查 self:checkWeeklyAct(actType, notify, count) end, ["init"] = function(self, actType, isCrossDay, notify) local roundData = self:getProperty("round") roundData[actType] = 0 self:updateProperty({field = "round", value = roundData, notNotify = not notify}) end, -- ["close"] = function(self, actType, notify) -- end, ["crossDay"] = function(self, actType, notify) self.owner:sendMail(MailId.ActSellFood) end, } -- 拾荒周 activityFunc[Activity.ActivityType.AdvDraw] = { ["check"] = function(self, actType, notify, count) -- 检查 self:checkWeeklyAct(actType, notify, count) end, ["init"] = function(self, actType, isCrossDay, notify) local roundData = self:getProperty("round") roundData[actType] = 0 self:updateProperty({field = "round", value = roundData, notNotify = not notify}) end, -- ["close"] = function(self, actType, notify) -- end, ["crossDay"] = function(self, actType, notify) self.owner:sendMail(MailId.ActAdvDraw) end, } -- 拆解周 activityFunc[Activity.ActivityType.OpenBox] = { ["check"] = function(self, actType, notify, count) -- 检查 self:checkWeeklyAct(actType, notify, count) end, ["init"] = function(self, actType, isCrossDay, notify) local roundData = self:getProperty("round") roundData[actType] = 0 self:updateProperty({field = "round", value = roundData, notNotify = not notify}) end, -- ["close"] = function(self, actType, notify) -- end, ["crossDay"] = function(self, actType, notify) self.owner:sendMail(MailId.ActOpenBox) end, } -- 付费签到 activityFunc[Activity.ActivityType.PaySignIn] = { ["init"] = function(self, actType, isCrossDay, notify) self:updateActData(actType, {}, not notify) end, ["crossDay"] = function(self, actType, notify) local curData = self:getActData(actType) curData[0] = (curData[0] or 0) + 1 self:updateActData(actType, curData, not notify) end, ["close"] = function(self, actType, notify) self.owner.storeData:SetActGoodsFlag("paySignIn", 0) local rechargeRecord = self.owner.storeData:getProperty("payR") for id, cfg in pairs(csvdb["shop_rechargeCsv"]) do if cfg.shop == 2 and cfg.type == CardType.PaySignCard then rechargeRecord[id] = nil break end end self.owner.storeData:updateProperty({field="payR", value=rechargeRecord}) end, } -- 充值反馈 activityFunc[Activity.ActivityType.PayBack] = { ["check"] = function(self, actType, notify, twd) -- 检查 local oldVal = self:getActData(actType) or 0 local newVal = oldVal + twd local gift, checkPoint = self.owner:getPaybackReward(oldVal, newVal) if gift ~= "" then local strCp = table.concat(checkPoint ,"、") self.owner:sendMail(MailId.PayBackAward, nil, gift, {newVal, strCp}) end self:updateActData(actType, newVal, not notify) end, ["init"] = function(self, actType, isCrossDay, notify) self:updateActData(actType, {}, not notify) end, -- ["close"] = function(self, actType, notify) -- end, } -- 英雄帖 activityFunc[Activity.ActivityType.CalendaTask] = { ["init"] = function(self, actType, isCrossDay, notify) local calTask = self.owner:getProperty("calTask") calTask = {} local role = self.owner local buildL = role.dinerData:getProperty("buildL") local curLevel = buildL:getv(1, 1) role:checkTaskEnter("DinerLevelUp", {level = curLevel}) role:checkTaskEnter("HeroLvlCollect", {}) role:checkTaskEnter("HeroQualityCollect", {}) local curPopular = role.dinerData:getProperty("popular") role:checkTaskEnter("DinerPopular", {count = curPopular}) local rLevel = role:getProperty("level") role:checkTaskEnter("RoleLevelUp", {level = rLevel}) local towerInfo = role:getProperty("towerInfo") role:checkTaskEnter("TowerPass", {level = towerInfo.l}) --"PvpWin" --role:checkTaskEnter("HangPass", {id = 0}) role:checkCalendaTask(true, 15, 3) role:checkTaskEnter("HeroStarCollect", {}) role:checkTaskEnter("RuneQualityCollect", {}) end, ["close"] = function(self, actType, notify) self.owner:updateProperty({field="calTask", value={}}) end, } -- 兑换 activityFunc[Activity.ActivityType.Exchange] = { ["init"] = function(self, actType, isCrossDay, notify, actId) local actData = self:getActData(actType) or {} actData[actId] = {} self:updateActData(actType, actData, not notify) end, ["login"] = function(self, actType, actId) activityFunc[Activity.ActivityType.Exchange]["crossDay"](self, actType, true, actId) end, ["crossDay"] = function(self, actType, notify, actId) local actData = self:getActData(actType) or {} local lastTs = actData["ts"] or 0 local timeNow = skynet.timex() local cfg = csvdb["activity_ctrlCsv"][actId] if not cfg then return end local refreshTimes = cfg.condition2:toArray(false, "=") for i = 1, #refreshTimes do local rt = toUnixtime(refreshTimes[i]..string_format("%02x", RESET_TIME)) if timeNow >= rt and rt > lastTs then lastTs = rt actData = {} end end if not next(actData) then actData["ts"] = timeNow self:updateActData(actType, actData, not notify) end end, ["close"] = function(self, actType, notify, actId) local actData = self:getActData(actType) or {} actData[actId] = nil self:updateActData(actType, actData, not notify) end, } -- 扭蛋机 activityFunc[Activity.ActivityType.Gachakon] = { ["init"] = function(self, actType, isCrossDay, notify, actId) self:updateActData(actType, {}, not notify) end, ["crossDay"] = function(self, actType, notify) self:updateActData(actType, {}, not notify) end, } -- 活动卡池 activityFunc[Activity.ActivityType.ActHeroPool] = { ["init"] = function(self, actType, isCrossDay, notify, actId) end, ["close"] = function(self, actType, notify, actId) local actData = self:getActData(actType) local cfg = csvdb["activity_ctrlCsv"][actId] if not cfg then return end -- 保底次数转换成万能碎片 --local count = math.ceil(((actData[cfg.condition] or 0) / 100) * 60) --if count > 0 then -- local gift = {[723] = count} -- self.owner:sendMail(MailId.ActivityPoolRet, nil, gift, {}) --end actData[cfg.condition] = nil self:updateActData(actType, actData, not notify) end, } -- 挂机掉落 activityFunc[Activity.ActivityType.HangDrop] = { ["init"] = function(self, actType, isCrossDay, notify, actId) local actime = self:getProperty("actime") local ctime = self.owner:getProperty("ctime") local startTime = math.max(actime[actId], ctime) local actData = self:getActData(actType) or 0 local cfg = csvdb["activity_putCsv"][actId] if not cfg then return end actData = startTime self:updateActData(actType, actData, not notify) end } --ChallengeLevel activityFunc[Activity.ActivityType.ChallengeLevel] = { ["init"] = function(self, actType, isCrossDay, notify, actId) self:getBattleTicket(actId) end, ["login"] = function(self, actType, actId) self:getBattleTicket(actId) end } function Activity:onLoginActivity(actId) local actData = csvdb["activity_ctrlCsv"][actId] if not actData then return end local actType = actData.showType if activityFunc[actType] and activityFunc[actType]['login'] then activityFunc[actType]["login"](self, actType, actId) end end function Activity:initActivity(actId, isCrossDay, notify) local actData = csvdb["activity_ctrlCsv"][actId] if not actData then return end local actType = actData.showType if activityFunc[actType] and activityFunc[actType]['init'] then activityFunc[actType]["init"](self, actType, isCrossDay, notify, actId) end end function Activity:closeActivity(actId, notify, notUpdateAct) local actData = csvdb["activity_ctrlCsv"][actId] if not actData then return end local actType = actData.showType if activityFunc[actType] and activityFunc[actType]['close'] then activityFunc[actType]["close"](self, actType, notify, actId) end self:recycleActItem(actId) if Activity.schema["act".. actType] then if not Activity.schema["act" .. actType][3] then self:updateActData(actType, Activity.schema["act" .. actType][2], not notify or notUpdateAct) end end end function Activity:refreshDailyData(notify) for actId, status in pairs(self._isOpen) do local actData = csvdb["activity_ctrlCsv"][actId] if status and actData then local actType = actData.showType if activityFunc[actType] and activityFunc[actType]['crossDay'] then activityFunc[actType]["crossDay"](self, actType, notify, actId) end end end end function Activity:checkActivity(notNotify, activityType, ...) if not activityType then return end if not self:isOpen(activityType) then return end if activityFunc[activityType] and activityFunc[activityType]['check'] then activityFunc[activityType]["check"](self, activityType, not notNotify, ...) end end -- 获取此次挂机掉落翻倍时长 function Activity:getActHangDoubleTime(lastTs, nowTs) local type = "DoubleDrop" --local actId = checkActivityType(type) local isOpen, actId = self:isOpen(type) local openTs = self:getProperty("actime")[actId] or 0 local timeNow = skynet.timex() lastTs = math.max(lastTs, openTs) if isOpen then if nowTs > openTs and nowTs > lastTs then return nowTs - lastTs else return 0 end end return 0 end -- 获取活动卡池id function Activity:getActivityPool(mainType, subType) local open, actId = self:isOpen(Activity.ActivityType.SsrUpPoolChange) if not open then --if not self:isOpen(Activity.ActivityType.SsrUpPoolChange) then return 0 end local actData = csvdb["activity_ctrlCsv"][actId] if not actData then return 0 end local poolMap = actData.condition2:toMap(true, "=") local key = mainType .. "_" .. subType for k, v in pairs(poolMap) do if k == key then return v end end return 0 end -- 付费签到可领奖励 function Activity:getPaySignReward() local actGoodsFlag = self.owner.storeData:getProperty("actGoodsFlag") local index = GetActGoodsIndex("paySignIn") local flag = actGoodsFlag[index] or 0 if flag == 0 then return {} end if not self.owner.activity:isOpen("PaySignIn") then return {} end local diffDay = diffFromOpen() + 1 local curData = self:getActData("PaySignIn") local reward, change = {} for day, csvData in pairs(csvdb["pay_signInCsv"]) do if day <= diffDay then if not curData[day] then curData[day] = 1 -- 奖励 for itemId, count in pairs(csvData.reward:toNumMap()) do reward[itemId] = (reward[itemId] or 0) + count end end else break end end return reward, curData --if next(reward) then --role.activity:updateActData("PaySignIn", curData) --reward, change = role:award(reward, {log = {desc = "actPaySign"}}) --end --role:log("activity", { -- activity_id = curData[0], -- 活动ID(或活动指定任务的ID) -- activity_type = role.activity.ActivityType.PaySignIn, -- 活动类型,见活动类型枚举表 -- activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...} --}) --SendPacket(actionCodes.Activity_actPaySignRpc, MsgPack.pack(role:packReward(reward, change))) end -- 回收活动道具 function Activity:recycleActItem(actId) local role = self.owner local actCfg = csvdb["activity_ctrlCsv"][actId] if not actCfg then return end local gift = {} local costs = {} for _, arr in ipairs(actCfg.recycle:toTableArray(true)) do local fromId, toId, toNum = arr[1], arr[2], arr[3] local itemCount = role:getItemCount(fromId) if itemCount > 0 then costs[fromId] = (costs[fromId] or 0) + itemCount gift[toId] = (gift[toId] or 0) + toNum * itemCount end end if next(costs) then local itemStr = "" for k, v in pairs(costs) do if itemStr ~= "" then itemStr = itemStr .. " " end itemStr = itemStr .. k .. "=" .. v end role:costItems(costs, {log = {desc = "actRecycle"}}) role:sendMail(actCfg.recycle_email, nil, gift, {itemStr}) end end -- 活动挑战关卡计算门票 function Activity:getBattleTicket(actId) local role = self.owner local createTs = role:getProperty("ctime") local actCfg = csvdb["activity_ctrlCsv"][actId] if not actCfg then return 0 end local actStartTime = 0 local openTimes = actCfg.time:toArray(false, "=") actStartTime = toUnixtime(openTimes[1]..string_format("%02x", RESET_TIME)) local actData = self:getActData("ChallengeLevel") or {} local startTs = actData["ts"] or math.max(actStartTime, createTs) local timeNow = skynet.timex() local modify = false local arr = actCfg.condition2:toArray(true, "=") local ticketId, init, limit, duration = arr[1] or 0, arr[2] or 0, arr[3] or 0, arr[4] or 10000 local count = actData["ticket"] or init local add = math.max(math.floor((timeNow - startTs) / (duration * 60)), 0) local newCount= math.min(count + add, limit) if newCount ~= count or newCount >= limit then modify = true end add = newCount - count if modify or not next(actData) then actData["ticket"] = newCount actData["ts"] = newCount >= limit and timeNow or (startTs + add * duration * 60) self:updateActData("ChallengeLevel", actData) end end activityFunc[Activity.ActivityType.ActShopGoods] = { ["init"] = function(self, actType, isCrossDay, notify, actId) end, ["close"] = function(self, actType, notify) local rechargeRecord = self.owner.storeData:getProperty("payR") for id, cfg in pairs(csvdb["shop_rechargeCsv"]) do if cfg.shop == 3 and cfg.type == ShopPackType.ActShopPack then rechargeRecord[id] = nil end end self.owner.storeData:updateProperty({field="payR", value=rechargeRecord}) end, } activityFunc[Activity.ActivityType.FriendEnergy] = { ["init"] = function (self, actType, isCrossDay, notify, actId) local data = {magic = 0, limit = 0, reward = {}, giveAE = {}, getAE = {}, new = self:getActFriendNew()} self:updateActData(actType, data, not notify) end, ["login"] = function (self, actType) local actData = self:getActData(actType) or {} actData.new = self:getActFriendNew() self:updateActData(actType, actData, not notify) end, ["crossDay"] = function(self, actType, notify) local actData = self:getActData(actType) actData.limit = 0 actData.giveAE = {} actData.getAE = {} self:updateActData(actType, actData, not notify) end, ["close"] = function (self, actType, notify, actId) redisproxy:del(FRIEND_ENERGY:format(self.owner:getProperty("id"))) end } function Activity:getActFriendNew() local roleId = self.owner:getProperty("id") local friendIds = {} local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) for i = 1, #friends , 2 do local objId = tonumber(friends[i]) friendIds[objId] = 1 end local ids = {} local members = redisproxy:smembers(FRIEND_ENERGY:format(roleId)) for _, id in pairs(members) do if friendIds[tonumber(id)] then ids[tonumber(id)] = 1 end end return ids end activityFunc[Activity.ActivityType.Crisis] = { ["check"] = function(self, actType, notify, atype, count) -- 检查 count = count or 1 local isOpen, actId = self:isOpen(actType) local actData = self:getActData(actType) or {} actData.task = actData.task or {} local change = false local actCsv = csvdb["activity_crisisCsv"][actId] for id, actSet in pairs(actCsv) do if actSet.type == atype then local status = actData.task[id] or 0 if status ~= -1 then status = status + count if status >= actSet.condition1 then local reward if actSet.loop == 1 then local rcount = math.floor(status / actSet.condition1) reward = actSet.reward:toNumMap() for itemId, itemC in pairs(reward) do reward[itemId] = itemC * rcount end status = status % actSet.condition1 else reward = actSet.reward status = -1 end self.owner:award(reward, {log = {desc = "activity_crisis"}, notNotify = not notify}) end actData.task[id] = status change = true end end end if change then -- 更新下排行榜 self.owner:updateRankCommon(RANK_TYPE.ActCrisis, self.owner:getItemCount(ItemId.CrisisScore)) self:updateActData(actType, actData) end end, } activityFunc[Activity.ActivityType.CommonSignIn] = { ["init"] = function(self, actType, isCrossDay, notify, actId) if not isCrossDay then activityFunc[Activity.ActivityType.CommonSignIn]["crossDay"](self, actType, notify, actId) end end, ["crossDay"] = function(self, actType, notify, actId) local actCfg = csvdb["activity_ctrlCsv"][actId] if not actCfg then return end local conArr = actCfg.condition2:toArray(true, "=") -- 0 登录即可, 1 达到指定活跃度 if conArr[1] ~= 0 then return end local curData = self:getActData(actType) or {} curData[0] = (curData[0] or 0) + 1 self:updateActData(actType, curData, not notify) end, ["check"] = function(self, actType, notify, pre, cur) -- 检查 local isOpen, actId = self:isOpen(actType) local actData = self:getActData(actType) or {} local actCfg = csvdb["activity_ctrlCsv"][actId] if not actCfg then return end local conArr = actCfg.condition2:toArray("true", "=") -- 0 登录即可, 1 达到指定活跃度 if conArr[1] ~= 1 then return end local val = conArr[2] or 0 if pre < val and cur >= val then actData[0] = (actData[0] or 0) + 1 self:updateActData(actType, actData, not notify) end end, } return Activity