Commit 1607a7f004e6c211a43deb58fdcbdced6de516d8

Authored by zhouahaihai
1 parent bcf5bfbb

冒险事件 new

Showing 2 changed files with 60 additions and 29 deletions   Show diff stats
src/ProtocolCode.lua
... ... @@ -54,6 +54,8 @@ actionCodes = {
54 54 Hang_roleFormatRpc = 255,
55 55 Hang_getRewardRpc = 256,
56 56 Hang_quickRpc = 257,
  57 + Hang_getRewardItemRpc = 258,
  58 + Hang_getRewardCoinRpc = 259,
57 59  
58 60 }
59 61  
... ...
src/adv/Adv.lua
... ... @@ -48,7 +48,7 @@ local function checkIsIn(checkValue, checkType, checkRange)
48 48 end
49 49  
50 50 --关卡事件库
51   -local function getEventLib(chapterId, level, needEventType)
  51 +local function getEventLib(chapterId, level, needEventType) -- needEventType 需要的事件
52 52 local chapter = math.floor(chapterId / 100) % 100
53 53  
54 54 local libsToType = {
... ... @@ -73,9 +73,11 @@ local function getEventLib(chapterId, level, needEventType)
73 73 if data.levelchapter == chapter then
74 74 if checkIsIn(level, data.leveltype, data.levellimit) then
75 75 if type(eventType) == "table" then
76   - eventLib[eventType[data.type]][id] = data
  76 + eventLib[eventType[data.type]][data.BlockEventType] = eventLib[eventType[data.type]][data.BlockEventType] or {}
  77 + eventLib[eventType[data.type]][data.BlockEventType][id] = {showup = data.showup, limit = data.limit}
77 78 else
78   - eventLib[eventType][id] = data
  79 + eventLib[eventType][data.BlockEventType] = eventLib[eventType][data.BlockEventType] or {}
  80 + eventLib[eventType][data.BlockEventType][id] = {showup = data.showup, limit = data.limit}
79 81 end
80 82 end
81 83 end
... ... @@ -91,8 +93,14 @@ end
91 93 -- 生成地图 是否可以生成地图上层判断
92 94 local function randomAdvMap(role, chapterId, level, notNotify)
93 95 local chapterData = csvdb["adv_chapterCsv"][chapterId]
94   - if not chapterData then return end
95   - if level > chapterData.limitlevel then return end
  96 + if not chapterData then
  97 + error("chapterId " .. chapterId .. " dont exist!")
  98 + return
  99 + end
  100 + if level > chapterData.limitlevel then
  101 + error("level overflow!")
  102 + return
  103 + end
96 104 --随出地图
97 105 local raw_pool = chapterData.mapid:toArray(true, "=")
98 106 local advInfo = role:getProperty("advInfo")
... ... @@ -108,11 +116,17 @@ local function randomAdvMap(role, chapterId, level, notNotify)
108 116 end
109 117 end
110 118 end
111   - if not next(pool) then return end
  119 + if not next(pool) then
  120 + error("mapIds is empty!")
  121 + return
  122 + end
112 123 local mapId = pool[math.randomInt(1, #pool)]
113 124 --随出事件
114 125 local mapData = csvdb["map_" .. csvdb["mapCsv"][mapId]["path"] .. "Csv"]
115   - if not mapData then return end
  126 + if not mapData then
  127 + error("mapId " .. mapId .. " dont exist!")
  128 + return
  129 + end
116 130  
117 131  
118 132 table.clear(advInfo)
... ... @@ -122,52 +136,67 @@ local function randomAdvMap(role, chapterId, level, notNotify)
122 136 advInfo.power = power
123 137 advInfo.enemyId = 1 --怪递增的索引
124 138 advInfo.rooms = {} -- {[roomId] = {event = {}, open = {}},} -- event 事件信息(具体信息查看randomEvent), open 是否解锁
125   -
126 139 --事件随机
127   - local eventLib = getEventLib(chapterId, level)
  140 + local eventLib = getEventLib(chapterId, level) -- 同时记录出现次数
128 141 local monsterEvents = {} --处理钥匙掉落
129 142 local haveBoss = false
130 143  
131 144 local function randomEvent(roomId, blockId, eventType)
132 145 if advInfo.rooms[roomId]["event"][blockId] then return end --已经有事件了 不覆盖
133   - local event = {etype = eventType}
  146 + local etype, especial = eventType, 0
  147 + if eventType > 100 then -- 特殊事件(固定)
  148 + etype = math.floor(eventType / 100)
  149 + especial = eventType % 100
  150 + end
  151 +
  152 + local event = {etype = etype}
134 153 local randomFunc = {}
  154 +
  155 + local function randomCommon()
  156 + if not eventLib[etype] or not next(eventLib[etype]) or not eventLib[etype][especial] or not next(eventLib[etype][especial]) then return false end
  157 + event.id = math.randWeight(eventLib[etype][especial], "showup")
  158 + if eventLib[etype][especial][event.id].limit > 1 then
  159 + eventLib[etype][especial][event.id].limit = eventLib[etype][especial][event.id].limit - 1
  160 + elseif eventLib[etype][especial][event.id].limit == 1 then
  161 + eventLib[etype][especial][event.id] = nil
  162 + end
  163 + end
  164 +
135 165 --入口
136 166 randomFunc[AdvEventType.In] = function()end
137 167 --出口
138 168 randomFunc[AdvEventType.Out] = function() end
139   -
140 169 --boss
141 170 randomFunc[AdvEventType.BOSS] = function()
142   - if not next(eventLib[eventType]) or haveBoss then return false end
  171 + if haveBoss then return false end
  172 + if randomCommon() == false then
  173 + return false
  174 + end
143 175 haveBoss = true
144   - event.id = math.randWeight(eventLib[eventType], "showup")
145 176 end
146 177 --怪物
147 178 randomFunc[AdvEventType.Monster] = function()
148   - if not next(eventLib[eventType]) then return false end
149   - event.id = math.randWeight(eventLib[eventType], "showup")
  179 + if randomCommon() == false then
  180 + return false
  181 + end
150 182 table.insert(monsterEvents, event)
151 183 end
  184 +
152 185 --选择点
153   - randomFunc[AdvEventType.Choose] = function()
154   - if not next(eventLib[eventType]) then return false end
155   - event.id = math.randWeight(eventLib[eventType], "showup")
156   - end
  186 + randomFunc[AdvEventType.Choose] = randomCommon
157 187 --掉落点
158   - randomFunc[AdvEventType.Drop] = randomFunc[AdvEventType.Choose]
  188 + randomFunc[AdvEventType.Drop] = randomCommon
159 189 --交易所
160   - randomFunc[AdvEventType.Trader] = randomFunc[AdvEventType.Choose]
  190 + randomFunc[AdvEventType.Trader] = randomCommon
161 191 --建筑
162   - randomFunc[AdvEventType.Build] = randomFunc[AdvEventType.Choose]
  192 + randomFunc[AdvEventType.Build] = randomCommon
163 193  
164   - if randomFunc[eventType] then
165   - if randomFunc[eventType]() ~= false then
  194 + if randomFunc[etype] then
  195 + if randomFunc[etype]() ~= false then
166 196 advInfo.rooms[roomId]["event"][blockId] = event
167 197 end
168 198 end
169 199 end
170   -
171 200 stagePool = {["global"] = {}}
172 201 for roomId, roomName in pairs(mapData["rooms"]) do
173 202 stagePool[roomId] = {}
... ... @@ -181,7 +210,7 @@ local function randomAdvMap(role, chapterId, level, notNotify)
181 210 end
182 211 for blockId, stageType in pairs(roomData["blocks"]) do
183 212 if AdvSpecialStage[stageType] then
184   - eventType = AdvEventType[AdvSpecialStage[stageType]]
  213 + eventType = AdvEventType[AdvSpecialStage[stageType]] -- 地块固定类型
185 214 randomEvent(roomId, blockId, eventType)
186 215 else
187 216 stagePool["global"][stageType] = stagePool["global"][stageType] or {}
... ... @@ -243,7 +272,7 @@ local function randomAdvMap(role, chapterId, level, notNotify)
243 272 print("这个地图没有钥匙!!! mapId : " .. mapId)
244 273 else
245 274 local event = monsterEvents[math.randomInt(1, #monsterEvents)]
246   - event.item = {ItemId.AdvKey, 1} --掉落钥匙 --todo
  275 + event.item = {ItemId.AdvKey, 1} --掉落钥匙
247 276 end
248 277 end
249 278 end
... ... @@ -556,8 +585,8 @@ function Adv:addNewMonsterRand(monsterId, where)
556 585  
557 586 if not monsterId then
558 587 local eventLib = getEventLib(self.advInfo.chapter, self.advInfo.level, AdvEventType.Monster)
559   - if not next(eventLib[AdvEventType.Monster]) then return false end
560   - monsterId = math.randWeight(eventLib[AdvEventType.Monster], "showup")
  588 + if not next(eventLib[AdvEventType.Monster][0]) then return false end
  589 + monsterId = math.randWeight(eventLib[AdvEventType.Monster][0], "showup")
561 590 end
562 591  
563 592 local event = {etype = AdvEventType.Monster, mId = self.advInfo.enemyId}
... ...