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,6 +54,8 @@ actionCodes = {
54 Hang_roleFormatRpc = 255, 54 Hang_roleFormatRpc = 255,
55 Hang_getRewardRpc = 256, 55 Hang_getRewardRpc = 256,
56 Hang_quickRpc = 257, 56 Hang_quickRpc = 257,
  57 + Hang_getRewardItemRpc = 258,
  58 + Hang_getRewardCoinRpc = 259,
57 59
58 } 60 }
59 61
@@ -48,7 +48,7 @@ local function checkIsIn(checkValue, checkType, checkRange) @@ -48,7 +48,7 @@ local function checkIsIn(checkValue, checkType, checkRange)
48 end 48 end
49 49
50 --关卡事件库 50 --关卡事件库
51 -local function getEventLib(chapterId, level, needEventType) 51 +local function getEventLib(chapterId, level, needEventType) -- needEventType 需要的事件
52 local chapter = math.floor(chapterId / 100) % 100 52 local chapter = math.floor(chapterId / 100) % 100
53 53
54 local libsToType = { 54 local libsToType = {
@@ -73,9 +73,11 @@ local function getEventLib(chapterId, level, needEventType) @@ -73,9 +73,11 @@ local function getEventLib(chapterId, level, needEventType)
73 if data.levelchapter == chapter then 73 if data.levelchapter == chapter then
74 if checkIsIn(level, data.leveltype, data.levellimit) then 74 if checkIsIn(level, data.leveltype, data.levellimit) then
75 if type(eventType) == "table" then 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 else 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 end 81 end
80 end 82 end
81 end 83 end
@@ -91,8 +93,14 @@ end @@ -91,8 +93,14 @@ end
91 -- 生成地图 是否可以生成地图上层判断 93 -- 生成地图 是否可以生成地图上层判断
92 local function randomAdvMap(role, chapterId, level, notNotify) 94 local function randomAdvMap(role, chapterId, level, notNotify)
93 local chapterData = csvdb["adv_chapterCsv"][chapterId] 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 local raw_pool = chapterData.mapid:toArray(true, "=") 105 local raw_pool = chapterData.mapid:toArray(true, "=")
98 local advInfo = role:getProperty("advInfo") 106 local advInfo = role:getProperty("advInfo")
@@ -108,11 +116,17 @@ local function randomAdvMap(role, chapterId, level, notNotify) @@ -108,11 +116,17 @@ local function randomAdvMap(role, chapterId, level, notNotify)
108 end 116 end
109 end 117 end
110 end 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 local mapId = pool[math.randomInt(1, #pool)] 123 local mapId = pool[math.randomInt(1, #pool)]
113 --随出事件 124 --随出事件
114 local mapData = csvdb["map_" .. csvdb["mapCsv"][mapId]["path"] .. "Csv"] 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 table.clear(advInfo) 132 table.clear(advInfo)
@@ -122,52 +136,67 @@ local function randomAdvMap(role, chapterId, level, notNotify) @@ -122,52 +136,67 @@ local function randomAdvMap(role, chapterId, level, notNotify)
122 advInfo.power = power 136 advInfo.power = power
123 advInfo.enemyId = 1 --怪递增的索引 137 advInfo.enemyId = 1 --怪递增的索引
124 advInfo.rooms = {} -- {[roomId] = {event = {}, open = {}},} -- event 事件信息(具体信息查看randomEvent), open 是否解锁 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 local monsterEvents = {} --处理钥匙掉落 141 local monsterEvents = {} --处理钥匙掉落
129 local haveBoss = false 142 local haveBoss = false
130 143
131 local function randomEvent(roomId, blockId, eventType) 144 local function randomEvent(roomId, blockId, eventType)
132 if advInfo.rooms[roomId]["event"][blockId] then return end --已经有事件了 不覆盖 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 local randomFunc = {} 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 randomFunc[AdvEventType.In] = function()end 166 randomFunc[AdvEventType.In] = function()end
137 --出口 167 --出口
138 randomFunc[AdvEventType.Out] = function() end 168 randomFunc[AdvEventType.Out] = function() end
139 -  
140 --boss 169 --boss
141 randomFunc[AdvEventType.BOSS] = function() 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 haveBoss = true 175 haveBoss = true
144 - event.id = math.randWeight(eventLib[eventType], "showup")  
145 end 176 end
146 --怪物 177 --怪物
147 randomFunc[AdvEventType.Monster] = function() 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 table.insert(monsterEvents, event) 182 table.insert(monsterEvents, event)
151 end 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 advInfo.rooms[roomId]["event"][blockId] = event 196 advInfo.rooms[roomId]["event"][blockId] = event
167 end 197 end
168 end 198 end
169 end 199 end
170 -  
171 stagePool = {["global"] = {}} 200 stagePool = {["global"] = {}}
172 for roomId, roomName in pairs(mapData["rooms"]) do 201 for roomId, roomName in pairs(mapData["rooms"]) do
173 stagePool[roomId] = {} 202 stagePool[roomId] = {}
@@ -181,7 +210,7 @@ local function randomAdvMap(role, chapterId, level, notNotify) @@ -181,7 +210,7 @@ local function randomAdvMap(role, chapterId, level, notNotify)
181 end 210 end
182 for blockId, stageType in pairs(roomData["blocks"]) do 211 for blockId, stageType in pairs(roomData["blocks"]) do
183 if AdvSpecialStage[stageType] then 212 if AdvSpecialStage[stageType] then
184 - eventType = AdvEventType[AdvSpecialStage[stageType]] 213 + eventType = AdvEventType[AdvSpecialStage[stageType]] -- 地块固定类型
185 randomEvent(roomId, blockId, eventType) 214 randomEvent(roomId, blockId, eventType)
186 else 215 else
187 stagePool["global"][stageType] = stagePool["global"][stageType] or {} 216 stagePool["global"][stageType] = stagePool["global"][stageType] or {}
@@ -243,7 +272,7 @@ local function randomAdvMap(role, chapterId, level, notNotify) @@ -243,7 +272,7 @@ local function randomAdvMap(role, chapterId, level, notNotify)
243 print("这个地图没有钥匙!!! mapId : " .. mapId) 272 print("这个地图没有钥匙!!! mapId : " .. mapId)
244 else 273 else
245 local event = monsterEvents[math.randomInt(1, #monsterEvents)] 274 local event = monsterEvents[math.randomInt(1, #monsterEvents)]
246 - event.item = {ItemId.AdvKey, 1} --掉落钥匙 --todo 275 + event.item = {ItemId.AdvKey, 1} --掉落钥匙
247 end 276 end
248 end 277 end
249 end 278 end
@@ -556,8 +585,8 @@ function Adv:addNewMonsterRand(monsterId, where) @@ -556,8 +585,8 @@ function Adv:addNewMonsterRand(monsterId, where)
556 585
557 if not monsterId then 586 if not monsterId then
558 local eventLib = getEventLib(self.advInfo.chapter, self.advInfo.level, AdvEventType.Monster) 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 end 590 end
562 591
563 local event = {etype = AdvEventType.Monster, mId = self.advInfo.enemyId} 592 local event = {etype = AdvEventType.Monster, mId = self.advInfo.enemyId}