Commit 2d87caee38c361ef9d5efcd1b55538abb2c32078

Authored by zhouhaihai
1 parent 7b2dc17c

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

@@ -1184,9 +1184,6 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1184,9 +1184,6 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1184 end 1184 end
1185 end, 1185 end,
1186 [3] = function() --发现怪物 1186 [3] = function() --发现怪物
1187 - if block:getEventType() == AdvEventType.Build then  
1188 - self.battle:removeBuildByPos(room.roomId, block.blockId)  
1189 - end  
1190 self:getCurMap():addNewMonsterRand(effect[2], {room, block}) 1187 self:getCurMap():addNewMonsterRand(effect[2], {room, block})
1191 self:pushBackEvent(AdvBackEventType.Monster, {id = effect[2]}) 1188 self:pushBackEvent(AdvBackEventType.Monster, {id = effect[2]})
1192 clearBlock = false 1189 clearBlock = false
@@ -1208,52 +1205,35 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1208,52 +1205,35 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1208 etype = AdvEventType.Trader, 1205 etype = AdvEventType.Trader,
1209 id = effect[2] 1206 id = effect[2]
1210 }) 1207 })
1211 - block:randomEvent()  
1212 self:pushBackEvent(AdvBackEventType.Trader, {id = effect[2]}) 1208 self:pushBackEvent(AdvBackEventType.Trader, {id = effect[2]})
1213 clearBlock = false 1209 clearBlock = false
1214 end, 1210 end,
1215 [7] = function() -- 建筑 1211 [7] = function() -- 建筑
1216 - if block:getEventType() == AdvEventType.Build then  
1217 - self.battle:removeBuildByPos(room.roomId, block.blockId)  
1218 - end  
1219 block:updateEvent({ 1212 block:updateEvent({
1220 etype = AdvEventType.Build, 1213 etype = AdvEventType.Build,
1221 id = effect[2] 1214 id = effect[2]
1222 }) 1215 })
1223 - block:randomEvent()  
1224 clearBlock = false 1216 clearBlock = false
1225 end, 1217 end,
1226 [8] = function() -- 选择 1218 [8] = function() -- 选择
1227 - if block:getEventType() == AdvEventType.Build then  
1228 - self.battle:removeBuildByPos(room.roomId, block.blockId)  
1229 - end  
1230 block:updateEvent({ 1219 block:updateEvent({
1231 etype = AdvEventType.Choose, 1220 etype = AdvEventType.Choose,
1232 id = effect[2] 1221 id = effect[2]
1233 }) 1222 })
1234 - block:randomEvent()  
1235 clearBlock = false 1223 clearBlock = false
1236 end, 1224 end,
1237 [9] = function() -- click 1225 [9] = function() -- click
1238 - if block:getEventType() == AdvEventType.Build then  
1239 - self.battle:removeBuildByPos(room.roomId, block.blockId)  
1240 - end  
1241 block:updateEvent({ 1226 block:updateEvent({
1242 etype = AdvEventType.Click, 1227 etype = AdvEventType.Click,
1243 id = effect[2] 1228 id = effect[2]
1244 }) 1229 })
1245 - block:randomEvent()  
1246 clearBlock = false 1230 clearBlock = false
1247 end, 1231 end,
1248 [10] = function() -- 陷阱 1232 [10] = function() -- 陷阱
1249 - if block:getEventType() == AdvEventType.Build then  
1250 - self.battle:removeBuildByPos(room.roomId, block.blockId)  
1251 - end  
1252 block:updateEvent({ 1233 block:updateEvent({
1253 etype = AdvEventType.Trap, 1234 etype = AdvEventType.Trap,
1254 id = effect[2] 1235 id = effect[2]
1255 }) 1236 })
1256 - block:randomEvent()  
1257 clearBlock = false 1237 clearBlock = false
1258 end, 1238 end,
1259 [11] = function() -- 获得神器 1239 [11] = function() -- 获得神器
@@ -1270,6 +1250,18 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) @@ -1270,6 +1250,18 @@ local function chooseCommon(self, room, block, chooseData, choose, tag)
1270 self:getCurMap():showMap() 1250 self:getCurMap():showMap()
1271 self:backMapShow() 1251 self:backMapShow()
1272 end, 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 assert(doEffect[effect[1]], "error effect, event_" .. (tag or "choose") .. "Csv id :" .. (block.event and block.event.id or 0) .. "effect " .. effect[1]) 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 doEffect[effect[1]]() 1267 doEffect[effect[1]]()
@@ -1624,7 +1616,6 @@ function Adv:doActive(activeId, target) @@ -1624,7 +1616,6 @@ function Adv:doActive(activeId, target)
1624 etype = AdvEventType.Trader, 1616 etype = AdvEventType.Trader,
1625 id = traderId, 1617 id = traderId,
1626 }) 1618 })
1627 - target:randomEvent()  
1628 self:backBlockChange(target.room.roomId, target.blockId) 1619 self:backBlockChange(target.room.roomId, target.blockId)
1629 self:pushBackEvent(AdvBackEventType.Trader, {id = traderId}) 1620 self:pushBackEvent(AdvBackEventType.Trader, {id = traderId})
1630 end 1621 end
@@ -1636,7 +1627,6 @@ function Adv:doActive(activeId, target) @@ -1636,7 +1627,6 @@ function Adv:doActive(activeId, target)
1636 doActiveEffect[3] = function(_, monsterId) 1627 doActiveEffect[3] = function(_, monsterId)
1637 for _, target in ipairs(targers) do 1628 for _, target in ipairs(targers) do
1638 if not target.lock and not target.isDead then 1629 if not target.lock and not target.isDead then
1639 - self.battle:removeEnemyById(target.id)  
1640 self:getCurMap():addNewMonsterRand(monsterId, {self:getRoom(target.roomId), self:getBlock(target.roomId, target.blockId)}) 1630 self:getCurMap():addNewMonsterRand(monsterId, {self:getRoom(target.roomId), self:getBlock(target.roomId, target.blockId)})
1641 self:backBlockChange(target.roomId, target.blockId) 1631 self:backBlockChange(target.roomId, target.blockId)
1642 self:pushBackEvent(AdvBackEventType.Monster, {id = monsterId}) 1632 self:pushBackEvent(AdvBackEventType.Monster, {id = monsterId})
src/adv/AdvBlock.lua
@@ -33,8 +33,31 @@ function Block:getEventType() @@ -33,8 +33,31 @@ function Block:getEventType()
33 return self.event and self.event.etype 33 return self.event and self.event.etype
34 end 34 end
35 35
  36 +function Block:getStageType()
  37 + return self.room:getStageType(self.blockId)
  38 +end
  39 +
36 function Block:updateEvent(event, isInit) 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 self.event = event 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 end 61 end
39 62
40 function Block:clear() 63 function Block:clear()
@@ -74,7 +97,9 @@ function Block:randomEvent() @@ -74,7 +97,9 @@ function Block:randomEvent()
74 randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster] 97 randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster]
75 --掉落 98 --掉落
76 randomFunc[AdvEventType.Drop] = function() 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 end 103 end
79 --交易 104 --交易
80 randomFunc[AdvEventType.Trader] = function() 105 randomFunc[AdvEventType.Trader] = function()
src/adv/AdvMap.lua
@@ -123,17 +123,101 @@ function Map:addNewMonsterRand(monsterId, where) @@ -123,17 +123,101 @@ function Map:addNewMonsterRand(monsterId, where)
123 end 123 end
124 124
125 local event = { 125 local event = {
126 - type = AdvEventType.Monster, 126 + etype = AdvEventType.Monster,
127 id = monsterId, 127 id = monsterId,
128 } 128 }
129 block:updateEvent(event) 129 block:updateEvent(event)
130 130
131 - local enemy = self.adv.battle:addEnemy(room, block)  
132 - enemy:triggerPassive(Passive.BORN_ONCE)  
133 -  
134 return room, block 131 return room, block
135 end 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 -- 随机翻开 num 个 以开放的房间的 地块 221 -- 随机翻开 num 个 以开放的房间的 地块
138 function Map:openBlockRand(num, isPlayer, ignoreBack) 222 function Map:openBlockRand(num, isPlayer, ignoreBack)
139 local pool = {} 223 local pool = {}
src/adv/AdvPassive.lua
@@ -479,4 +479,29 @@ function Passive:effect10(count, triggerPms) @@ -479,4 +479,29 @@ function Passive:effect10(count, triggerPms)
479 end 479 end
480 end 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 return Passive 507 return Passive
483 \ No newline at end of file 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,14 +13,15 @@ function Room:ctor(map, roomId, csvData, info, isPath, isNewRelay, mapType)
13 self.isBossRoom = false -- boss房间 --击败boss 以后重置为false 13 self.isBossRoom = false -- boss房间 --击败boss 以后重置为false
14 self.isShow = false 14 self.isShow = false
15 self.battleAfterCall = {} 15 self.battleAfterCall = {}
  16 + self.csvData = csvData
16 17
17 self.blocks = {} 18 self.blocks = {}
18 - self:loadBlocks(csvData, info, isNewRelay, mapType) 19 + self:loadBlocks(info, isNewRelay, mapType)
19 end 20 end
20 21
21 -function Room:loadBlocks(csvData, info, isNewRelay, mapType) 22 +function Room:loadBlocks(info, isNewRelay, mapType)
22 local isFirstOpen = false 23 local isFirstOpen = false
23 - for blockId, _ in pairs(csvData["blocks"]) do 24 + for blockId, _ in pairs(self.csvData["blocks"]) do
24 self.blocks[blockId] = Block.new(self, blockId, info.event[blockId], info.open == 1 or info.open[blockId], info.trap[blockId]) 25 self.blocks[blockId] = Block.new(self, blockId, info.event[blockId], info.open == 1 or info.open[blockId], info.trap[blockId])
25 if not self.isPath and self.blocks[blockId]:isBoss() then 26 if not self.isPath and self.blocks[blockId]:isBoss() then
26 self.isBossRoom = true 27 self.isBossRoom = true
@@ -47,6 +48,12 @@ function Room:loadBlocks(csvData, info, isNewRelay, mapType) @@ -47,6 +48,12 @@ function Room:loadBlocks(csvData, info, isNewRelay, mapType)
47 end 48 end
48 end 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 function Room:initBattleAfter() 57 function Room:initBattleAfter()
51 for _, callback in ipairs(self.battleAfterCall) do 58 for _, callback in ipairs(self.battleAfterCall) do
52 callback() 59 callback()