From 1607a7f004e6c211a43deb58fdcbdced6de516d8 Mon Sep 17 00:00:00 2001 From: zhouahaihai Date: Mon, 8 Apr 2019 15:39:17 +0800 Subject: [PATCH] 冒险事件 new --- src/ProtocolCode.lua | 2 ++ src/adv/Adv.lua | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 85bf29f..6571315 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -54,6 +54,8 @@ actionCodes = { Hang_roleFormatRpc = 255, Hang_getRewardRpc = 256, Hang_quickRpc = 257, + Hang_getRewardItemRpc = 258, + Hang_getRewardCoinRpc = 259, } diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index eb40d43..1ef21aa 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -48,7 +48,7 @@ local function checkIsIn(checkValue, checkType, checkRange) end --关卡事件库 -local function getEventLib(chapterId, level, needEventType) +local function getEventLib(chapterId, level, needEventType) -- needEventType 需要的事件 local chapter = math.floor(chapterId / 100) % 100 local libsToType = { @@ -73,9 +73,11 @@ local function getEventLib(chapterId, level, needEventType) if data.levelchapter == chapter then if checkIsIn(level, data.leveltype, data.levellimit) then if type(eventType) == "table" then - eventLib[eventType[data.type]][id] = data + eventLib[eventType[data.type]][data.BlockEventType] = eventLib[eventType[data.type]][data.BlockEventType] or {} + eventLib[eventType[data.type]][data.BlockEventType][id] = {showup = data.showup, limit = data.limit} else - eventLib[eventType][id] = data + eventLib[eventType][data.BlockEventType] = eventLib[eventType][data.BlockEventType] or {} + eventLib[eventType][data.BlockEventType][id] = {showup = data.showup, limit = data.limit} end end end @@ -91,8 +93,14 @@ end -- 生成地图 是否可以生成地图上层判断 local function randomAdvMap(role, chapterId, level, notNotify) local chapterData = csvdb["adv_chapterCsv"][chapterId] - if not chapterData then return end - if level > chapterData.limitlevel then return end + if not chapterData then + error("chapterId " .. chapterId .. " dont exist!") + return + end + if level > chapterData.limitlevel then + error("level overflow!") + return + end --随出地图 local raw_pool = chapterData.mapid:toArray(true, "=") local advInfo = role:getProperty("advInfo") @@ -108,11 +116,17 @@ local function randomAdvMap(role, chapterId, level, notNotify) end end end - if not next(pool) then return end + if not next(pool) then + error("mapIds is empty!") + return + end local mapId = pool[math.randomInt(1, #pool)] --随出事件 local mapData = csvdb["map_" .. csvdb["mapCsv"][mapId]["path"] .. "Csv"] - if not mapData then return end + if not mapData then + error("mapId " .. mapId .. " dont exist!") + return + end table.clear(advInfo) @@ -122,52 +136,67 @@ local function randomAdvMap(role, chapterId, level, notNotify) advInfo.power = power advInfo.enemyId = 1 --怪递增的索引 advInfo.rooms = {} -- {[roomId] = {event = {}, open = {}},} -- event 事件信息(具体信息查看randomEvent), open 是否解锁 - --事件随机 - local eventLib = getEventLib(chapterId, level) + local eventLib = getEventLib(chapterId, level) -- 同时记录出现次数 local monsterEvents = {} --处理钥匙掉落 local haveBoss = false local function randomEvent(roomId, blockId, eventType) if advInfo.rooms[roomId]["event"][blockId] then return end --已经有事件了 不覆盖 - local event = {etype = eventType} + local etype, especial = eventType, 0 + if eventType > 100 then -- 特殊事件(固定) + etype = math.floor(eventType / 100) + especial = eventType % 100 + end + + local event = {etype = etype} local randomFunc = {} + + local function randomCommon() + if not eventLib[etype] or not next(eventLib[etype]) or not eventLib[etype][especial] or not next(eventLib[etype][especial]) then return false end + event.id = math.randWeight(eventLib[etype][especial], "showup") + if eventLib[etype][especial][event.id].limit > 1 then + eventLib[etype][especial][event.id].limit = eventLib[etype][especial][event.id].limit - 1 + elseif eventLib[etype][especial][event.id].limit == 1 then + eventLib[etype][especial][event.id] = nil + end + end + --入口 randomFunc[AdvEventType.In] = function()end --出口 randomFunc[AdvEventType.Out] = function() end - --boss randomFunc[AdvEventType.BOSS] = function() - if not next(eventLib[eventType]) or haveBoss then return false end + if haveBoss then return false end + if randomCommon() == false then + return false + end haveBoss = true - event.id = math.randWeight(eventLib[eventType], "showup") end --怪物 randomFunc[AdvEventType.Monster] = function() - if not next(eventLib[eventType]) then return false end - event.id = math.randWeight(eventLib[eventType], "showup") + if randomCommon() == false then + return false + end table.insert(monsterEvents, event) end + --选择点 - randomFunc[AdvEventType.Choose] = function() - if not next(eventLib[eventType]) then return false end - event.id = math.randWeight(eventLib[eventType], "showup") - end + randomFunc[AdvEventType.Choose] = randomCommon --掉落点 - randomFunc[AdvEventType.Drop] = randomFunc[AdvEventType.Choose] + randomFunc[AdvEventType.Drop] = randomCommon --交易所 - randomFunc[AdvEventType.Trader] = randomFunc[AdvEventType.Choose] + randomFunc[AdvEventType.Trader] = randomCommon --建筑 - randomFunc[AdvEventType.Build] = randomFunc[AdvEventType.Choose] + randomFunc[AdvEventType.Build] = randomCommon - if randomFunc[eventType] then - if randomFunc[eventType]() ~= false then + if randomFunc[etype] then + if randomFunc[etype]() ~= false then advInfo.rooms[roomId]["event"][blockId] = event end end end - stagePool = {["global"] = {}} for roomId, roomName in pairs(mapData["rooms"]) do stagePool[roomId] = {} @@ -181,7 +210,7 @@ local function randomAdvMap(role, chapterId, level, notNotify) end for blockId, stageType in pairs(roomData["blocks"]) do if AdvSpecialStage[stageType] then - eventType = AdvEventType[AdvSpecialStage[stageType]] + eventType = AdvEventType[AdvSpecialStage[stageType]] -- 地块固定类型 randomEvent(roomId, blockId, eventType) else stagePool["global"][stageType] = stagePool["global"][stageType] or {} @@ -243,7 +272,7 @@ local function randomAdvMap(role, chapterId, level, notNotify) print("这个地图没有钥匙!!! mapId : " .. mapId) else local event = monsterEvents[math.randomInt(1, #monsterEvents)] - event.item = {ItemId.AdvKey, 1} --掉落钥匙 --todo + event.item = {ItemId.AdvKey, 1} --掉落钥匙 end end end @@ -556,8 +585,8 @@ function Adv:addNewMonsterRand(monsterId, where) if not monsterId then local eventLib = getEventLib(self.advInfo.chapter, self.advInfo.level, AdvEventType.Monster) - if not next(eventLib[AdvEventType.Monster]) then return false end - monsterId = math.randWeight(eventLib[AdvEventType.Monster], "showup") + if not next(eventLib[AdvEventType.Monster][0]) then return false end + monsterId = math.randWeight(eventLib[AdvEventType.Monster][0], "showup") end local event = {etype = AdvEventType.Monster, mId = self.advInfo.enemyId} -- libgit2 0.21.2