AdvRoom.lua
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
-- 房间
local AdvCommon = require "adv.AdvCommon"
local Block = require "adv.AdvBlock"
local Passive = require "adv.AdvPassive"
local Room = class("AdvRoom")
function Room:ctor(map, roomId, csvData, info, isPath, isNewRelay, mapType)
self.map = map
self.roomId = roomId
self.col, self.row = AdvCommon.getCrById(self.roomId)
self.isPath = isPath
self.isBossRoom = false -- boss房间 --击败boss 以后重置为false
self.isShow = false
self.battleAfterCall = {}
self.csvData = csvData
self.blocks = {}
self:loadBlocks(info, isNewRelay, mapType)
end
function Room:loadBlocks(info, isNewRelay, mapType)
local isFirstOpen = false
for blockId, _ in pairs(self.csvData["blocks"]) do
self.blocks[blockId] = Block.new(self, blockId, info.event[blockId], info.open == 1 or info.open[blockId], info.trap[blockId])
if not self.isPath and self.blocks[blockId]:isBoss() then
self.isBossRoom = true
end
if self.blocks[blockId].isOpen then
self.isShow = true
else
if self.blocks[blockId]:getEventType() == AdvEventType.In or self.blocks[blockId]:getEventType() == AdvEventType.InOut then -- 开放
self.isShow = true
self.blocks[blockId].isOpen = true
isFirstOpen = true
end
end
end
--中继层全部开放 boss 房间 开启所有的地块
if (self.map.adv.isRelay and not isNewRelay) or (self.isBossRoom and self.isShow and isFirstOpen) or (isFirstOpen and mapType == 1) then
table.insert(self.battleAfterCall, function()
for _, block in pairs(self.blocks) do
self:openBlock(block)
end
end)
end
if isFirstOpen then
table.insert(self.battleAfterCall, function()
--入口房间只会在这里首次展示开放 --触发固有技
self.map.adv:triggerPassive(Passive.ROOM_SHOW, {roomId = self.roomId})
end)
end
end
function Room:getStageType(blockId)
if not self.blocks[blockId] then return end
if not self.csvData["blocks"][blockId] then return end
return self.csvData["blocks"][blockId]
end
function Room:initBattleAfter()
for _, callback in ipairs(self.battleAfterCall) do
callback()
end
self.battleAfterCall = {}
end
function Room:getDB()
local room = {event = {}, open = {}, trap = {}}
local allOpen = true
for blockId, block in pairs(self.blocks) do
room["event"][blockId] = block.event
room["open"][blockId] = block.isOpen and 1 or nil
if not block.isOpen then
allOpen = false
end
room["trap"][blockId] = block.trapId
end
if allOpen then
room["open"] = 1
end
return room
end
function Room:openBlock(block)
if self.blocks[block.blockId] ~= block then return end
if block.isOpen == true then return end
if self.isBossRoom then
for _, _block in pairs(self.blocks) do
_block:open()
end
else
block:open()
end
if not self.isShow then
self.isShow = true
--首次展示房间
self.map.adv:triggerPassive(Passive.ROOM_SHOW, {roomId = self.roomId})
end
return true
end
function Room:tranGToL(c, r)
return c - self.col, r - self.row
end
function Room:tranLtoG(c, r)
return c + self.col, r + self.row
end
function Room:getBByGPos(c, r)
local c, r = self:tranGToL(c, r)
return self.blocks[AdvCommon.getIdByCr(c, r)]
end
return Room