diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index d5f86bc..871b5e9 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -63,6 +63,7 @@ actionCodes = { Adv_repayWheelSurfRpc = 168, Adv_rankRpc = 169, Adv_quickHangRpc = 170, + Adv_refreshSupportRpc = 171, Hero_loadInfos = 201, Hero_updateProperty = 202, diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 8aeb86a..aa83f20 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -84,6 +84,7 @@ function _M.startAdvRpc( agent, data ) local chapterId = msg.chapterId --关卡id local layer = msg.layer or 1 --选择层数 local format = msg.format --编队 + local supportIdx = msg.supportIdx --选择的支援效果 --上一个关卡结束才可以开始新的关卡 if role:getAdvData():isRunning() then return 8 end @@ -109,7 +110,7 @@ function _M.startAdvRpc( agent, data ) local relayData = role:getAdvData():isHaveRelay(layer, chapterId) if not relayData then return end -- 不是中继层 if advElM < relayData.unlockfloor then return end --未解锁 - end + end else -- 普通模式判断 if role.dailyData:getProperty("advC") >= role:getAdvHangLimit() then return 2 end -- 是否有体力 if layer > chapterData.limitlevel then return 4 end @@ -137,9 +138,30 @@ function _M.startAdvRpc( agent, data ) role.dailyData:updateProperty({field = "advC", delta = 1}) end - role:getAdvData():initByChapter(chapterId, layer, false, false, layer ~= 1, true) + local support = {} -- 支援效果 + if AdvCommon.isEndless(chapterId) then + -- 选择的支援效果 + local advSup = role:getProperty("advSup") + if supportIdx then + if advSup[supportIdx] then + table.insert(support, advSup[supportIdx]) + end + role:advRandomSupportEffect() -- 选完就重新随机 + end + -- 增加 默认增加的支援效果 + local active = role:getAdvActiveSupportEffect() + for aId, _ in pairs(active) do + local curData = csvdb["adv_supportCsv"][aId] + if curData.type == 2 then + table.insert(support, aId) + end + end + end + + role:getAdvData():initByChapter(chapterId, layer, false, false, layer ~= 1, true, support) role:checkTaskEnter("AdvStart", {id = chapterId}) role:checkTaskEnter("AdvStartSelf", {id = chapterId}) + adv:popBackEvents() -- 清一下事件 SendPacket(actionCodes.Adv_startAdvRpc, '') return true end @@ -647,18 +669,18 @@ end function _M.finishAchievRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) - -- local ctype = msg.ctype -- 领取类型 1 成就 2 pt累计奖励 + local ctype = msg.ctype or 2 -- 领取类型 1 成就 2 pt累计奖励 local chapterId = msg.chapterId --章节id local taskId = msg.taskId -- 领取id local adv = role:getAdvData() local status, reward - -- if ctype == 1 then - -- status = adv:finishAchievement(chapterId, taskId) - -- elseif ctype == 2 then + if ctype == 1 then + status, reward = adv:finishAchievement(chapterId, taskId) + elseif ctype == 2 then status, reward = adv:getAchievementReward(chapterId, taskId) - -- end + end if not status then return end adv:updateAchievement() SendPacket(actionCodes.Adv_finishAchievRpc, MsgPack.pack({reward = reward})) @@ -701,4 +723,23 @@ function _M.rankRpc(agent, data) return true end +function _M.refreshSupportRpc(agent, data) + local role = agent.role + + local cr = role.dailyData:getProperty("advSupRe") + local al = role:getAdvSupportFreeCount() + + if cr < al then --免费 + role.dailyData:updateProperty({field = advSupRe, delta = 1}) + else -- 付费 + if not role:checkItemEnough({[ItemId.Diamond] = globalCsv.adv_support_refresh_cost}) then return end + role:costItems({[ItemId.Diamond] = globalCsv.adv_support_refresh_cost}) + end + + role:advRandomSupportEffect() + + SendPacket(actionCodes.Adv_refreshSupportRpc, '') + return true +end + return _M \ No newline at end of file diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index a5ace10..bbddb92 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -38,6 +38,7 @@ function Adv:initByInfo(advInfo) self.waitArtifact = advInfo.waitAF self.cacheUnlock = advInfo.cacheUnlock or {} self.shopStatus = advInfo.shopStatus or {} + self.support = advInfo.support or {} self.maps = {} for id, map in ipairs(advInfo.maps or {}) do @@ -62,7 +63,7 @@ function Adv:isHaveRelay(level, chapterId) end -- 随机新的地图 -function Adv:initByChapter(chapterId, level, isToNext, notNotify, isRelay, isEnter) +function Adv:initByChapter(chapterId, level, isToNext, notNotify, isRelay, isEnter, support) if not self.chapterId then -- 开始新的章节 self.chapterId = chapterId self:checkAchievement(Adv.AchievType.StartBattle, 1) @@ -78,6 +79,11 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify, isRelay, isEnt self.lchoose = self.lchoose or {} self.cacheUnlock = self.cacheUnlock or {} self.shopStatus = self.shopStatus or {} + self.support = self.support or {} + + if isEnter then -- 把 支援效果初始化为易用用的形式 + self:initSupport(support or {}) + end -- 随机出地图 local mapId @@ -112,6 +118,9 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify, isRelay, isEnt self:initLayerTask() + -- 支援效果生效一些 + self:activeSomeSupport() + self:checkTask(Adv.TaskType.Arrive) self:checkAdvUnlock(1, self.level) if isToNext then @@ -137,34 +146,7 @@ function Adv:clear() self.isRelay = nil self.cacheUnlock = {} self.shopStatus = {} -end - -function Adv:isRunning() - if self.chapterId then return true end - return false -end - --- 强制结束 -function Adv:forceOver(notNotify) - if self:isRunning() then - self:clear() - local advTeam = self.owner:getProperty("advTeam") - advTeam.player = nil - - local reward = self.owner:getProperty("advItems"):toNumMap() - for itemId, count in pairs(reward) do - reward[itemId] = math.ceil(count * globalCsv.adv_fail_reward_ratio / 100) -- 奖励相当于失败 - end - self.owner:award(reward) - - self.owner:updateProperties({ - advInfo = {}, - advTeam = advTeam, - advItems = "", - advAFGet = {}, - advAFWear = {}, - }, notNotify) - end + self.support = {} end function Adv:saveDB(notNotify) @@ -182,6 +164,7 @@ function Adv:saveDB(notNotify) advInfo.waitAF = self.waitArtifact advInfo.cacheUnlock = self.cacheUnlock advInfo.shopStatus = self.shopStatus + advInfo.support = self.support advInfo.maps = {} self.battle:saveDB() @@ -201,6 +184,161 @@ function Adv:saveDB(notNotify) self.owner:updateProperties({advInfo = advInfo, advTeam = advTeam}, notNotify) end +function Adv:initSupport(supports) + self.support = {} + + local supportEffect = {} + -- 获得道具 1=道具id=道具数量 + supportEffect[1] = function(_, itemId, num) + self.support[1] = self.support[1] or {} + self.support[1][itemId] = (self.support[1][itemId] or 0) + num + end + + -- 获得mapbuff 2=mapbuffid + supportEffect[2] = function(_, buffId) + self.support[2] = self.support[2] or {} + table.insert(self.support[2], buffId) + end + + -- 获得mappassive 3=mappassive + supportEffect[3] = function(_, passiveId) + self.support[3] = self.support[3] or {} + table.insert(self.support[3], passiveId) + end + + -- 首层额外刷新 4=类型=id=数量(类型1=choose/2=building/3=click/4=drop/5=shop) + supportEffect[4] = function(_, etype, id, num) + self.support[4] = self.support[4] or {} + self.support[4][etype] = self.support[4][etype] or {} + self.support[4][etype][id] = (self.support[4][etype][id] or 0) + num + end + + -- 每层额外刷新 5=类型=id=数量(类型1=choose/2=building/3=click/4=drop/5=shop) + supportEffect[5] = function(_, etype, id, num) + self.support[5] = self.support[5] or {} + self.support[5][etype] = self.support[5][etype] or {} + self.support[5][etype][id] = (self.support[5][etype][id] or 0) + num + end + + -- 获得随机神器 6=数量 + supportEffect[6] = function(num) + self.support[6] = (self.support[6] or 0) + num + end + + -- 获得3选1神器 7=选择次数(连续选择,每次选择重新随机) + supportEffect[7] = function(num) + self.support[7] = (self.support[7] or 0) + num + end + + for _, supportId in ipairs(supports) do + local supportData = csvdb["adv_supportCsv"][supportId] + for _, effect in ipairs(supportData.effect:toArray()) do + local cur = effect:toArray(true, "=") + if supportEffect[cur[1]] then + supportEffect[cur[1]](table.unpack(cur)) + end + end + end +end + +function Adv:activeSomeSupport() + -- 奖励物品 + if self.support[1] then + self:award(self.support[1]) + self.support[1] = nil + end + + -- 加buff + if self.support[2] then + for _, buffId in ipairs(self.support[2]) do + self.battle.player:addBuff(buffId) + end + self.support[2] = nil + end + + --加被动技 + if self.support[3] then + for _, passiveId in ipairs(self.support[3]) do + self.battle.player:addPassive({id = passiveId}) + end + self.support[3] = nil + end + + -- 加随机神器 + if self.support[6] then + local pool = {} + for id, temp in pairs(csvdb["adv_artifactCsv"]) do + if not self:isHaveArtifact(id) and self.owner:isArtifactOpen(id, self:isEndless()) then + table.insert(pool, id) + end + end + for i = 1, math.min(self.support[6], #pool) do + local idx = math.randomInt(1, #pool) + self:award({[pool[idx]] = 1}) + table.remove(pool, idx) + end + self.support[6] = nil + end + + self:supportChooseArtifact() +end + +function Adv:supportChooseArtifact() + -- 加 三选一 神器 + if self.support[7] then + if self.support[7] > 0 then + self:waitChooseArtifact() + end + self.support[7] = self.support[7] - 1 + if self.support[7] <= 0 then + self.support[7] = nil + end + end +end + +function Adv:supportFirstLayerAddEvent() + if self.support[4] then + local temp = self.support[4] + self.support[4] = nil + return temp + end +end + +function Adv:supportEveryLayerAddEvent() + return self.support[5] +end + + +function Adv:isRunning() + if self.chapterId then return true end + return false +end + +-- 强制结束 +function Adv:forceOver(notNotify) + if self:isRunning() then + self:clear() + local advTeam = self.owner:getProperty("advTeam") + advTeam.player = nil + + local reward = self.owner:getProperty("advItems"):toNumMap() + for itemId, count in pairs(reward) do + reward[itemId] = math.ceil(count * globalCsv.adv_fail_reward_ratio / 100) -- 奖励相当于失败 + end + self.owner:award(reward) + + self.owner:updateProperties({ + advInfo = {}, + advTeam = advTeam, + advItems = "", + advAFGet = {}, + advAFWear = {}, + }, notNotify) + end +end + + + -- 1=抵达x层;2=通关x层;3=完成指定事件;4=完成指定连锁事件 function Adv:checkAdvUnlock(utype, value) if not self.chapterId then return end @@ -453,6 +591,10 @@ function Adv:chooseArtifact(index) if not self.waitArtifact or not self.waitArtifact[index] then return end self:award({[self.waitArtifact[index]] = 1}) self.waitArtifact = nil + + -- 支援效果继续选择 + self:supportChooseArtifact() + return true end diff --git a/src/adv/AdvMap.lua b/src/adv/AdvMap.lua index dddccef..8de2539 100644 --- a/src/adv/AdvMap.lua +++ b/src/adv/AdvMap.lua @@ -392,6 +392,48 @@ createMap = function(self, mapId, isEnter, isNewRelay) end end + -- 低保事件 + local exEvent = {} + -- 首层额外刷新 + if isEnter then + local first = self.adv:supportFirstLayerAddEvent() + if first then + exEvent = first + end + end + -- 每层额外刷新 + if not self.adv.isRelay then + local every = self.adv:supportEveryLayerAddEvent() + if every then + for etype, events in pairs(every) do + exEvent[etype] = exEvent[etype] or {} + for id, num in pairs(events) do + exEvent[etype][id] = (exEvent[etype][id] or 0) + num + end + end + end + end + local lastCount = stagePool["global"][AdvCodeRandomStage] and #stagePool["global"][AdvCodeRandomStage] or 0 + for etype, events in pairs(exEvent) do + if lastCount <= 0 then break end + for id, num in pairs(events) do + if lastCount <= 0 then break end + for i = 1, num do + if lastCount <= 0 then break end + + local idx = math.randomInt(1, lastCount) + local cur = stagePool["global"][AdvCodeRandomStage][idx] + + giveEvent(cur["room"], cur["block"], etype, id) + + table.remove(stagePool["global"][AdvCodeRandomStage], idx) + lastCount = lastCount - 1 + stagePool[cur["room"]][AdvCodeRandomStage][cur["block"]] = nil + end + end + end + + -- 全地图事件 优先级高 for stageType, events in pairs(mapData["events"]) do for _, event in ipairs(events) do diff --git a/src/adv/AdvTask.lua b/src/adv/AdvTask.lua index 1d11ec7..18d74f7 100644 --- a/src/adv/AdvTask.lua +++ b/src/adv/AdvTask.lua @@ -225,9 +225,13 @@ function AdvTask.bind(Adv) local advAchievChange = {} - local function insertChange(chapterId, taskId, value) + local function insertChange(chapterId, taskId, value, pts) local achievField = AdvCommon.isEndless(chapterId) and "advEAchiev" or "advAchiev" - table.insert(advAchievChange, {type = achievField, field = {chapterId, taskId}, value = value}) + if pts then + table.insert(advAchievChange, {type = achievField, field = {chapterId, "pts", taskId}, value = value}) + else + table.insert(advAchievChange, {type = achievField, field = {chapterId, taskId}, value = value}) + end end function Adv:checkAchievement(taskType, count, cond, cond2) @@ -302,35 +306,48 @@ function AdvTask.bind(Adv) status = oldStatus + count end end - if (status or -1) >= data.value1 then - status = -1 - end - if status and status ~= oldStatus then - insertChange(self.chapterId, taskId, status) - if status == -1 then - local ptcount = (self.owner:getProperty(achievField)[self.chapterId] or {})[-1] or 0 - ptcount = ptcount + data.pt - insertChange(self.chapterId, -1, ptcount) + + if self:isEndless() then + if status and status ~= oldStatus then + insertChange(self.chapterId, taskId, status) + end + else + if (status or -1) >= data.value1 then + status = -1 + end + if status and status ~= oldStatus then + insertChange(self.chapterId, taskId, status) + if status == -1 then + local ptcount = (self.owner:getProperty(achievField)[self.chapterId] or {})[-1] or 0 + ptcount = ptcount + data.pt + insertChange(self.chapterId, -1, ptcount) + end end end - end end end - -- --说不用领取 注释掉 - -- function Adv:finishAchievement(chapterId, taskId) - -- local achievData = (csvdb["adv_achievementCsv"][chapterId] or {})[taskId] - -- local status = (self.owner:getProperty("advAchiev")[chapterId] or {})[taskId] or -1 - - -- if status >= achievData.value1 then - -- insertChange(chapterId, taskId, -1) - -- local count = (self.owner:getProperty("advAchiev")[chapterId] or {})[-1] or 0 - -- count = count + achievData.pt - -- insertChange(chapterId, -1, count) - -- return true - -- end - -- end + -- 说不用领取 注释掉 + -- 又说要领取 打开 修改 + function Adv:finishAchievement(chapterId, taskId) + if not AdvCommon.isEndless(chapterId) then return end -- 暂时只有无尽可以领奖 + local achievField = AdvCommon.isEndless(chapterId) and "advEAchiev" or "advAchiev" + local achievData = (csvdb["adv_achievementCsv"][chapterId] or {})[taskId] + local status = (self.owner:getProperty(achievField)[chapterId] or {})[taskId] or -1 + + local reward = {} + if status >= achievData.value1 then + insertChange(chapterId, taskId, -1) + local count = (self.owner:getProperty(achievField)[chapterId] or {})[-1] or 0 + count = count + achievData.pt + insertChange(chapterId, -1, count) + + -- 发放奖励 + reward = self.owner:award(achievData.reward) + return true, reward + end + end function Adv:getAchievementReward(chapterId, taskId) local achievField = AdvCommon.isEndless(chapterId) and "advEAchiev" or "advAchiev" @@ -340,7 +357,7 @@ function AdvTask.bind(Adv) if status == -1 or count < achievData.pt then return end local reward = self.owner:award(achievData.reward) - insertChange(chapterId, taskId, -1) + insertChange(chapterId, taskId, -1, true) return true, reward end diff --git a/src/models/Daily.lua b/src/models/Daily.lua index ce922d1..afe60fc 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -22,6 +22,8 @@ Daily.schema = { dailySDC = {"table", {}}, -- daily shop diamond count {[id] = count} -- 每日商城购买次数统计 dailySDD = {"table", {}}, -- daily shop diamond disount {[id] = 1} -- 每日商城折扣统计 + + advSupRe = {"number", 0}, -- 冒险支援效果刷新次数 } function Daily:updateProperty(params) @@ -92,6 +94,7 @@ function Daily:data() pvpFree = self:getProperty("pvpFree"), dailySDC = self:getProperty("dailySDC"), dailySDD = self:getProperty("dailySDD"), + advSupRe = self:getProperty("advSupRe"), } end diff --git a/src/models/Role.lua b/src/models/Role.lua index 4aae5a8..15d2e8b 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -76,7 +76,8 @@ Role.schema = { advShop = {"table", {}}, -- 冒险內的商店限制购买次数记录 {goodId = count} advEAchiev = {"table", {}}, -- 冒险无尽冒险手册 advRelay = {"table", {}}, -- 冒险中继点记录 {[chapter] = {[level] = 1}, [-1] = {[level] = 1}} -- -1 无尽 方便重置 - + advSup = {"table", {}}, -- 冒险支援效果 待选项 + --挂机相关 hangPass = {"table", {}}, -- 挂机通过的最大关卡 hangTeam = {"table", {}}, -- 挂机队伍 @@ -266,6 +267,7 @@ function Role:data() advDrawB = self:getProperty("advDrawB"), advShop = self:getProperty("advShop"), advEAchiev = self:getProperty("advEAchiev"), + advSup = self:getProperty("advSup"), hangPass = self:getProperty("hangPass"), hangTeam = self:getProperty("hangTeam"), diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index bac9567..e54e490 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -32,7 +32,9 @@ function RolePlugin.bind(Role) self.dailyData:refreshDailyData(notify) self.dinerData:refreshDailyData(notify) self:setProperty("dTask", {}) + self:advRandomSupportEffect() response.dTask = {} + response.advSup = self:getProperty("advSup") if isCrossWeek(ltime, now) then @@ -810,6 +812,61 @@ function RolePlugin.bind(Role) end end + -- 获得激活的冒险效果 + function Role:getAdvActiveSupportEffect() + local effect = {} + local advEAchiev = self:getProperty("advEAchiev") + for id, status in pairs(advEAchiev[self.advElChapter] or {}) do + if status == -1 then + local achvData = csvdb["adv_achievementCsv"][id] + if achvData.support ~= 0 then + effect[achvData.support] = 1 + end + end + end + return effect + end + + --获取冒险支援效果免费刷新次数 + function Role:getAdvSupportFreeCount() + local count = 1 --默认每天有1次 + local openEffects = self:getAdvActiveSupportEffect() + for aId, _ in pairs(openEffects) do + local curData = csvdb["adv_supportCsv"][aId] + if curData.type == 2 then + for _, effect in ipairs(curData.effect:toArray()) do + local cur = effect:toArray(true, "=") + if cur[1] == 8 then + count = count + cur[2] + end + end + end + end + return count + end + + -- 冒险随机新的支援效果 + function Role:advRandomSupportEffect(notNotify) + local pool = {} + local openEffects = self:getAdvActiveSupportEffect() + for id, data in pairs(csvdb["adv_supportCsv"]) do + if data.type == 0 then + if openEffects[id] then + table.insert(pool, data) + end + elseif data.type == 1 then + table.insert(pool, data) + end + end + + local advSup = {} + for i = 1, math.min(3, #pool) do + local idx = math.randWeight(pool, "showup") + table.insert(advSup, pool[idx].id) + table.remove(pool, idx) + end + self:updateProperty({field = "advSup", value = advSup, notNotify = notNotify}) + end local StdDinerRankTime = toUnixtime("20190101"..string.format("%02x", RESET_RANK_TIME)) --跨天时间 function Role:getCurDinerRankKey() -- libgit2 0.21.2