Blame view

src/adv/AdvBlock.lua 7.13 KB
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
1
2
3
4
5
6
7
8
9
10
11
12
13
  --块类型
  local AdvCommon = require "adv.AdvCommon"
  local Passive = require "adv.AdvPassive"
  
  local Block = class("AdvBlock")
  function Block:ctor(room, blockId, event, isOpen, trapId)
  	self.room = room
  	self.blockId = blockId
  	self.col, self.row = AdvCommon.getCrById(self.blockId)
  
  	self.isOpen = isOpen and true or false
  	self.trapId = trapId
  
48962a74   zhouhaihai   路障系统提交
14
  	self:updateEvent(event, true)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
15
16
17
18
19
20
21
22
23
  end
  function Block:isBoss()
  	return self:getEventType() == AdvEventType.BOSS
  end
  
  function Block:isMonster()
  	return (self:getEventType() == AdvEventType.BOSS or self:getEventType() == AdvEventType.Monster)
  end
  
9687f887   zhouhaihai   建筑被动
24
25
26
27
  function Block:isBuild()
  	return self:getEventType() == AdvEventType.Build
  end
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
28
29
30
31
  function Block:getEventType()
  	return self.event and self.event.etype
  end
  
48962a74   zhouhaihai   路障系统提交
32
  function Block:updateEvent(event, isInit)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
33
34
35
36
37
38
  	self.event = event
  end
  
  function Block:clear()
  	if self:getEventType() == AdvEventType.Trap then 
  		self.trapId = self.event.id
44dd6cae   zhouhaihai   建筑消失删除建筑角色
39
40
41
42
43
  	elseif self:getEventType() == AdvEventType.Build then
  		local build = self.room.map.adv.battle:getBuild(self.room.roomId, self.blockId, self.room.map.mapIdx)
  		if build then
  			build.isDead = true
  		end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
44
45
46
47
  	end
  	self.event = nil
  end
  
4f0a5fae   zhouhaihai   营养剂
48
49
  
  function Block:randomEvent()
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  	local room = self.room
  	local map = room.map
  	local adv = map.adv
  	--如果翻开有数据处理在这里处理
  	local randomFunc = {}
  	--怪
  	randomFunc[AdvEventType.Monster] = function()
  		self.event.mId = adv.lastEnemyId  --给怪一个有序id 回合逻辑时使用
  		adv.lastEnemyId = adv.lastEnemyId + 1
  		local enemy = adv.battle:getEnemy(room.roomId, self.blockId, map.mapIdx)
  		if enemy then
  			enemy:unlock(self.event.mId)
  		else
  			enemy = adv.battle:addEnemy(room, self, map.mapIdx)
55f07e43   zhouhaihai   新出生的初始化
64
  			enemy:initAfter(self.event.enemy)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
65
66
  		end
  		enemy:triggerPassive(Passive.BORN_ONCE)
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
67
68
69
70
71
  
  		adv.battle.player:triggerPassive(Passive.OPEN_MONSTER, {trigger = enemy})
  		for _, monster in pairs(adv.battle.player:getTeam(2)) do
  			adv.battle.player:triggerPassive(Passive.OPEN_MONSTER, {trigger = enemy})
  		end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
72
73
74
75
76
77
78
79
80
81
82
  	end
  	randomFunc[AdvEventType.BOSS] = randomFunc[AdvEventType.Monster]
  	--掉落
  	randomFunc[AdvEventType.Drop] = function()
  		self.event.item = csvdb["event_dropCsv"][self.event.id]["range"]:randWeight(true)
  	end
  	--交易
  	randomFunc[AdvEventType.Trader] = function()
  		local data = csvdb["event_traderCsv"][self.event.id]
  		self.event.shop = {}
  		self.event.status = "" --购买次数状态  1 就是购买过了  -- 购买id就是shop索引
f8408529   zhouhaihai   冒险商店
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
  		local needDiscount = data.discount -- 需要的折扣数量
  		local curHad = {}
  		local advShop = adv.owner:getProperty("advShop")
  		local function randomGoods(range, gcount)
  			local pool = range:toTableArray(true) -- {{id, weight}, ... }
  			local function randomOneGood()
  				for i = #pool, 1, -1 do
  					local curId = pool[i][1]
  					local curData = csvdb["event_trader_goodsCsv"][curId]
  					if not curData then
  						table.remove(pool, i)
  					else
  						if curData.restrict == 1 then -- 冒险内限制
  							if curData.restrictnum <= ((adv.shopStatus[curId] or 0) + (curHad[curId] or 0)) then
  								table.remove(pool, i)
  							end
  						elseif curData.restrict == 2 then -- 角色限制
  							if curData.restrictnum <= ((advShop[curId] or 0) + (curHad[curId] or 0)) then
  								table.remove(pool, i)
  							end
  						end
  					end
  				end
  				if #pool <= 0 then
  					return false
  				end
  				local idx = math.randWeight(pool, 2)
  				local getId = pool[idx][1]
b992f1ca   zhouhaihai   bug
111
  				local getData = csvdb["event_trader_goodsCsv"][getId]
f8408529   zhouhaihai   冒险商店
112
  				if getData.restrict ~= 0 then 
aef8ca87   zhouhaihai   两个bug
113
  					curHad[getId] = (curHad[getId] or 0) + 1
f8408529   zhouhaihai   冒险商店
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  				end
  				if getData.discount ~= "" and needDiscount > 0 then
  					needDiscount = needDiscount - 1
  					table.insert(self.event.shop, {getId, getData.discount:randWeight()})
  				else
  					table.insert(self.event.shop, {getId})
  				end
  				return true
  			end
  
  			for i = 1, gcount do
  				if not randomOneGood() then
  					break
  				end
  			end
  		end
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
131
132
133
  		for i = 1, 10 do
  			local numS, rangeS = "num" .. i, "range" .. i
  			if data[numS] and data[rangeS] then
f8408529   zhouhaihai   冒险商店
134
  				randomGoods(data[rangeS], data[numS])
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
135
136
137
138
139
140
141
  			else
  				break
  			end
  		end
  	end
  	--建筑
  	randomFunc[AdvEventType.Build] = function()
9687f887   zhouhaihai   建筑被动
142
143
144
145
146
  		local build = adv.battle:getBuild(room.roomId, self.blockId, map.mapIdx)
  		if build then
  			build:unlock()
  		else
  			build = adv.battle:addEnemy(room, self, map.mapIdx)
55f07e43   zhouhaihai   新出生的初始化
147
  			build:initAfter(self.event.build)
9687f887   zhouhaihai   建筑被动
148
149
  		end
  		build:triggerPassive(Passive.BORN_ONCE)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
150
151
152
153
  	end
  
  	randomFunc[AdvEventType.Trap] = function()
  		local data = csvdb["event_trapCsv"][self.event.id]
e058aebe   zhouhaihai   修改生效位置
154
155
156
  		-- 因为一些神器效果 提前触发被动
  		adv.battle.player:triggerPassive(Passive.CLICK_TRAP)
  
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
157
  		local buffs = data.effect:toArray(true, "=")
f3c37873   zhouhaihai   block
158
  		
b9b9c757   zhouhaihai   陷阱翻开房间
159
160
  
  		local backTrap = true
f3c37873   zhouhaihai   block
161
162
163
164
165
  		if data.target == 0 then  -- 给玩家增加buff
  			for _, buffId in ipairs(buffs) do
  				adv.battle.player:addBuff(buffId)
  			end
  		elseif data.target == 1 then-- 给玩家 和 所有敌人同样增加buff
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
166
  			local enemys = adv.battle.player:getTeam(2)
f3c37873   zhouhaihai   block
167
168
169
  			for _, buffId in ipairs(buffs) do
  				adv.battle.player:addBuff(buffId)
  			end
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
170
171
172
173
174
  			for k , enemy in ipairs(enemys) do
  				for _, buffId in ipairs(buffs) do
  					enemy:addBuff(buffId)
  				end
  			end
b9b9c757   zhouhaihai   陷阱翻开房间
175
176
177
  		elseif data.target == 2 then -- 翻开房间
  			self.room.map.adv:getCurMap():openBlocksByRoom(self.room.roomId)
  			backTrap = false
f3c37873   zhouhaihai   block
178
179
  		elseif data.target == 3 then -- 翻开周围8格,并给怪物附带buff(不伤害玩家)
  			self.room.map.adv:getCurMap():openBlocksBySize(self.room.roomId, self.blockId, 2)
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
180
  		end
b9b9c757   zhouhaihai   陷阱翻开房间
181
  
f3c37873   zhouhaihai   block
182
  
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
183
184
185
186
187
188
  		if data.specialEff ~= "" then
  			local effect = data.specialEff:toArray(true, "=")
  			if effect[1] == 1 then
  				self.room.map.adv:mapItemChange(effect[2])
  			end
  		end
e058aebe   zhouhaihai   修改生效位置
189
  
b176d7d3   zhouhaihai   冒险成就
190
  		adv:checkAchievement(adv.AchievType.Trap, 1, self.event.id)
b9b9c757   zhouhaihai   陷阱翻开房间
191
192
193
  		if backTrap then
  			adv:backTrap()
  		end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
194
195
196
197
198
199
200
201
202
  		self:clear()
  	end
  
  
  	if self.event then -- 随机出具体的事件
  		if randomFunc[self:getEventType()] then
  			randomFunc[self:getEventType()]()
  		end
  	end
4f0a5fae   zhouhaihai   营养剂
203
204
  end
  
48962a74   zhouhaihai   路障系统提交
205
206
207
208
209
210
211
212
213
214
215
216
  -- 获取event 数据
  function Block:getEventData()
  	local typToCsv = {
  		[AdvEventType.Monster] = "event_monsterCsv",
  		[AdvEventType.BOSS] = "event_monsterCsv",
  		[AdvEventType.Choose] = "event_chooseCsv",
  		[AdvEventType.Drop] = "event_dropCsv",
  		[AdvEventType.Build] = "event_buildingCsv",
  		[AdvEventType.Trader] = "event_traderCsv",
  		[AdvEventType.Trap] = "event_trapCsv",
  		[AdvEventType.Click] = "event_clickCsv",
  		[AdvEventType.Layer] = "event_layerCsv",
48962a74   zhouhaihai   路障系统提交
217
218
219
220
221
222
223
224
225
226
  		[AdvEventType.LinkChoose] = "event_linkchooseCsv",
  	}
  
  	local etype = self:getEventType()
  	if not etype then return end
  	if not self.event.id then return end
  	if not typToCsv[etype] then return end
  
  	return csvdb[typToCsv[etype]][self.event.id]
  end
4f0a5fae   zhouhaihai   营养剂
227
228
229
230
231
232
233
  
  --事件有需要额外处理的部分
  function Block:open()
  	if self.isOpen then return end
  	local room = self.room
  	local map = room.map
  	local adv = map.adv
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
234
  	self.isOpen = true
c843f805   zhouhaihai   bug 栈溢出
235
  	self:randomEvent()
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
236
  	return true
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
237
238
  end
  
48962a74   zhouhaihai   路障系统提交
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
  function Block:getObstacle()
  	local data = self:getEventData()
  	if not data then return 0 end
  	return data.obstacle or 0
  end
  
  -- 是否看守周围地板
  function Block:isGuard()
  	return self.isOpen and self:getObstacle() == 2
  end
  
  -- 是否是路障
  function Block:isHinder()
  	return self.isOpen and self:getObstacle() == 1
  end
  
  -- 玩家是否经过   -- 已经翻开 并且 不是路障
  function Block:isWalk()
  	return self.isOpen and not self:isHinder()
  end
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
260
  return Block