Commit 2d87caee38c361ef9d5efcd1b55538abb2c32078

Authored by zhouhaihai
1 parent 7b2dc17c

地块替换优化 新的效果类型

src/adv/Adv.lua
... ... @@ -1184,9 +1184,6 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1184 1184 end
1185 1185 end,
1186 1186 [3] = function() --发现怪物
1187   - if block:getEventType() == AdvEventType.Build then
1188   - self.battle:removeBuildByPos(room.roomId, block.blockId)
1189   - end
1190 1187 self:getCurMap():addNewMonsterRand(effect[2], {room, block})
1191 1188 self:pushBackEvent(AdvBackEventType.Monster, {id = effect[2]})
1192 1189 clearBlock = false
... ... @@ -1208,52 +1205,35 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1208 1205 etype = AdvEventType.Trader,
1209 1206 id = effect[2]
1210 1207 })
1211   - block:randomEvent()
1212 1208 self:pushBackEvent(AdvBackEventType.Trader, {id = effect[2]})
1213 1209 clearBlock = false
1214 1210 end,
1215 1211 [7] = function() -- 建筑
1216   - if block:getEventType() == AdvEventType.Build then
1217   - self.battle:removeBuildByPos(room.roomId, block.blockId)
1218   - end
1219 1212 block:updateEvent({
1220 1213 etype = AdvEventType.Build,
1221 1214 id = effect[2]
1222 1215 })
1223   - block:randomEvent()
1224 1216 clearBlock = false
1225 1217 end,
1226 1218 [8] = function() -- 选择
1227   - if block:getEventType() == AdvEventType.Build then
1228   - self.battle:removeBuildByPos(room.roomId, block.blockId)
1229   - end
1230 1219 block:updateEvent({
1231 1220 etype = AdvEventType.Choose,
1232 1221 id = effect[2]
1233 1222 })
1234   - block:randomEvent()
1235 1223 clearBlock = false
1236 1224 end,
1237 1225 [9] = function() -- click
1238   - if block:getEventType() == AdvEventType.Build then
1239   - self.battle:removeBuildByPos(room.roomId, block.blockId)
1240   - end
1241 1226 block:updateEvent({
1242 1227 etype = AdvEventType.Click,
1243 1228 id = effect[2]
1244 1229 })
1245   - block:randomEvent()
1246 1230 clearBlock = false
1247 1231 end,
1248 1232 [10] = function() -- 陷阱
1249   - if block:getEventType() == AdvEventType.Build then
1250   - self.battle:removeBuildByPos(room.roomId, block.blockId)
1251   - end
1252 1233 block:updateEvent({
1253 1234 etype = AdvEventType.Trap,
1254 1235 id = effect[2]
1255 1236 })
1256   - block:randomEvent()
1257 1237 clearBlock = false
1258 1238 end,
1259 1239 [11] = function() -- 获得神器
... ... @@ -1270,6 +1250,18 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1270 1250 self:getCurMap():showMap()
1271 1251 self:backMapShow()
1272 1252 end,
  1253 + [14] = function() -- 指定地块召唤 指定类型的id
  1254 + local change = self:getCurMap():layEventToStage(effect[2], effect[3], effect[4], effect[5])
  1255 + for _, one in ipairs(change) do
  1256 + self:backBlockChange(one[1].roomId, one[2].blockId)
  1257 + end
  1258 + end,
  1259 + [15] = function() -- 移除指定事件
  1260 + local change = self:getCurMap():clearEventById(effect[2], effect[3], effect[4])
  1261 + for _, one in ipairs(change) do
  1262 + self:backBlockChange(one[1].roomId, one[2].blockId)
  1263 + end
  1264 + end,
1273 1265 }
1274 1266 assert(doEffect[effect[1]], "error effect, event_" .. (tag or "choose") .. "Csv id :" .. (block.event and block.event.id or 0) .. "effect " .. effect[1])
1275 1267 doEffect[effect[1]]()
... ... @@ -1624,7 +1616,6 @@ function Adv:doActive(activeId, target)
1624 1616 etype = AdvEventType.Trader,
1625 1617 id = traderId,
1626 1618 })
1627   - target:randomEvent()
1628 1619 self:backBlockChange(target.room.roomId, target.blockId)
1629 1620 self:pushBackEvent(AdvBackEventType.Trader, {id = traderId})
1630 1621 end
... ... @@ -1636,7 +1627,6 @@ function Adv:doActive(activeId, target)
1636 1627 doActiveEffect[3] = function(_, monsterId)
1637 1628 for _, target in ipairs(targers) do
1638 1629 if not target.lock and not target.isDead then
1639   - self.battle:removeEnemyById(target.id)
1640 1630 self:getCurMap():addNewMonsterRand(monsterId, {self:getRoom(target.roomId), self:getBlock(target.roomId, target.blockId)})
1641 1631 self:backBlockChange(target.roomId, target.blockId)
1642 1632 self:pushBackEvent(AdvBackEventType.Monster, {id = monsterId})
... ...
src/adv/AdvBlock.lua
... ... @@ -33,8 +33,31 @@ function Block:getEventType()
33 33 return self.event and self.event.etype
34 34 end
35 35  
  36 +function Block:getStageType()
  37 + return self.room:getStageType(self.blockId)
  38 +end
  39 +
36 40 function Block:updateEvent(event, isInit)
  41 + if not isInit then
  42 + -- 有些事件删除 需要处理
  43 + if self:isBuild() then
  44 + self.room.map.adv.battle:removeBuildByPos(self.room.roomId, self.blockId)
  45 + elseif self:isMonster() then
  46 + if block.event.mId then
  47 + self.room.map.adv.battle:removeEnemyById(block.event.mId)
  48 + end
  49 + end
  50 + end
37 51 self.event = event
  52 + if not isInit and self.event then
  53 + -- 判断下类型是不是错的
  54 + if not self:getEventData() then
  55 + self:clear()
  56 + assert(false, "updateEvent error, : event " .. (event.etype or "nil"))
  57 + return
  58 + end
  59 + self:randomEvent()
  60 + end
38 61 end
39 62  
40 63 function Block:clear()
... ... @@ -74,7 +97,9 @@ function Block:randomEvent()
74 97 randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster]
75 98 --掉落
76 99 randomFunc[AdvEventType.Drop] = function()
77   - self.event.item = csvdb["event_dropCsv"][self.event.id]["range"]:randWeight(true)
  100 + if not self.event.item then
  101 + self.event.item = csvdb["event_dropCsv"][self.event.id]["range"]:randWeight(true)
  102 + end
78 103 end
79 104 --交易
80 105 randomFunc[AdvEventType.Trader] = function()
... ...
src/adv/AdvMap.lua
... ... @@ -123,17 +123,101 @@ function Map:addNewMonsterRand(monsterId, where)
123 123 end
124 124  
125 125 local event = {
126   - type = AdvEventType.Monster,
  126 + etype = AdvEventType.Monster,
127 127 id = monsterId,
128 128 }
129 129 block:updateEvent(event)
130 130  
131   - local enemy = self.adv.battle:addEnemy(room, block)
132   - enemy:triggerPassive(Passive.BORN_ONCE)
133   -
134 131 return room, block
135 132 end
136 133  
  134 +-- 在指定地块类型上 放置指定类型事件id
  135 +function Map:layEventToStage(eventType, eventId, count, stage)
  136 + local pool = {}
  137 + for _, room_ in pairs(self.rooms) do
  138 + for _, block_ in pairs(room_.blocks) do
  139 + if block_.isOpen and not block_.event and block_:getStageType() == stage then
  140 + table.insert(pool, {room_, block_})
  141 + end
  142 + end
  143 + end
  144 + if not next(pool) then return {} end
  145 + local change = {}
  146 + count = math.min(#pool, count)
  147 + for i = 1, count do
  148 + local idx = math.randomInt(1, #pool)
  149 + local room, block = pool[idx][1], pool[idx][2]
  150 + table.remove(pool, idx)
  151 +
  152 + local event = {
  153 + etype = eventType,
  154 + id = eventId,
  155 + }
  156 + block:updateEvent(event)
  157 + table.insert(change, {room, block})
  158 + end
  159 + return change
  160 +end
  161 +
  162 +-- 地图中指定事件 切换为另一个事件
  163 +function Map:eventChangeToOther(eventTypeF, eventIdF, eventTypeT, eventIdT, count)
  164 + count = count or 1
  165 + local pool = {}
  166 + for _, room_ in pairs(self.rooms) do
  167 + for _, block_ in pairs(room_.blocks) do
  168 + if block_.isOpen and block_:getEventType() == eventTypeF and block_.event.id == eventIdF then
  169 + table.insert(pool, {room_, block_})
  170 + end
  171 + end
  172 + end
  173 + if not next(pool) then return {} end
  174 + local change = {}
  175 + count = math.min(#pool, count)
  176 + for i = 1, count do
  177 + local idx = math.randomInt(1, #pool)
  178 + local room, block = pool[idx][1], pool[idx][2]
  179 + table.remove(pool, idx)
  180 +
  181 + local event = {
  182 + etype = eventTypeT,
  183 + id = eventIdT,
  184 + }
  185 + block:updateEvent(event)
  186 + table.insert(change, {room, block})
  187 + end
  188 + return change
  189 +end
  190 +
  191 +function Map:clearEventById(eventType, eventId, count)
  192 + count = count or 0
  193 + eventId = eventId or 0
  194 +
  195 + local pool = {}
  196 + for _, room_ in pairs(self.rooms) do
  197 + for _, block_ in pairs(room_.blocks) do
  198 + if block_.isOpen and block_:getEventType() == eventType and (eventId == 0 or block_.event.id == eventId) then
  199 + table.insert(pool, {room_, block_})
  200 + end
  201 + end
  202 + end
  203 + if not next(pool) then return {} end
  204 + local change = {}
  205 + if count == 0 then
  206 + count = #pool
  207 + else
  208 + count = math.min(#pool, count)
  209 + end
  210 + for i = 1, count do
  211 + local idx = math.randomInt(1, #pool)
  212 + local room, block = pool[idx][1], pool[idx][2]
  213 + table.remove(pool, idx)
  214 +
  215 + block:updateEvent(nil)
  216 + table.insert(change, {room, block})
  217 + end
  218 + return change
  219 +end
  220 +
137 221 -- 随机翻开 num 个 以开放的房间的 地块
138 222 function Map:openBlockRand(num, isPlayer, ignoreBack)
139 223 local pool = {}
... ...
src/adv/AdvPassive.lua
... ... @@ -479,4 +479,29 @@ function Passive:effect10(count, triggerPms)
479 479 end
480 480 end
481 481  
  482 +-- 将地图上的A事件替换成B事件
  483 +function Passive:effect11(eventTypeF, triggerPms, eventIdF, eventTypeT, eventIdT, count)
  484 + local change = self.owner.battle.adv:getCurMap():eventChangeToOther(eventTypeF, eventIdF, eventTypeT, eventIdT, count)
  485 + for _, one in ipairs(change) do
  486 + self.owner.battle.adv:backBlockChange(one[1].roomId, one[2].blockId)
  487 + end
  488 +end
  489 +
  490 +-- 在指定地点召唤event项目
  491 +function Passive:effect12(eventType, triggerPms, eventId, count, stage)
  492 + local change = self.owner.battle.adv:getCurMap():layEventToStage(eventType, eventId, count, stage)
  493 + for _, one in ipairs(change) do
  494 + self.owner.battle.adv:backBlockChange(one[1].roomId, one[2].blockId)
  495 + end
  496 +end
  497 +
  498 +-- 移除指定项目
  499 +function Passive:effect13(eventType, triggerPms, eventId, count)
  500 + local change = self.owner.battle.adv:getCurMap():clearEventById(eventType, eventId, count)
  501 + for _, one in ipairs(change) do
  502 + self.owner.battle.adv:backBlockChange(one[1].roomId, one[2].blockId)
  503 + end
  504 +end
  505 +
  506 +
482 507 return Passive
483 508 \ No newline at end of file
... ...
src/adv/AdvRoom.lua
... ... @@ -13,14 +13,15 @@ function Room:ctor(map, roomId, csvData, info, isPath, isNewRelay, mapType)
13 13 self.isBossRoom = false -- boss房间 --击败boss 以后重置为false
14 14 self.isShow = false
15 15 self.battleAfterCall = {}
  16 + self.csvData = csvData
16 17  
17 18 self.blocks = {}
18   - self:loadBlocks(csvData, info, isNewRelay, mapType)
  19 + self:loadBlocks(info, isNewRelay, mapType)
19 20 end
20 21  
21   -function Room:loadBlocks(csvData, info, isNewRelay, mapType)
  22 +function Room:loadBlocks(info, isNewRelay, mapType)
22 23 local isFirstOpen = false
23   - for blockId, _ in pairs(csvData["blocks"]) do
  24 + for blockId, _ in pairs(self.csvData["blocks"]) do
24 25 self.blocks[blockId] = Block.new(self, blockId, info.event[blockId], info.open == 1 or info.open[blockId], info.trap[blockId])
25 26 if not self.isPath and self.blocks[blockId]:isBoss() then
26 27 self.isBossRoom = true
... ... @@ -47,6 +48,12 @@ function Room:loadBlocks(csvData, info, isNewRelay, mapType)
47 48 end
48 49 end
49 50  
  51 +function Room:getStageType(blockId)
  52 + if not self.blocks[blockId] then return end
  53 + if not self.csvData["blocks"][blockId] then return end
  54 + return self.csvData["blocks"][blockId]
  55 +end
  56 +
50 57 function Room:initBattleAfter()
51 58 for _, callback in ipairs(self.battleAfterCall) do
52 59 callback()
... ...