Blame view

src/adv/Adv.lua 32.3 KB
46fac6f1   zhouahaihai   酱料
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
  local Passive = require "adv.AdvPassive"
  
  -- 工具函数
  local function getIdByCr(c, r)
  	local crId = math.abs(r) + math.abs(c) * 100
  	if c < 0 then
  		crId = crId + 10000
  	end
  	if r < 0 then
  		crId = crId + 20000
  	end
  	return crId
  end
  
  local function getCrById(crId)
  	local c = math.floor(crId % 10000 / 100)
  	local r = crId % 100
  	local last = math.floor(crId / 10000)
  	if last == 3 then
  		c, r = -c, -r
  	elseif last == 1 then
  		c = -c
  	elseif last == 2 then
  		r = -r
  	end
  	return c, r
  end
  
  -----------------------------随机地图-----------------------------
  --检查 是否满足层数限制条件
  local function checkIsIn(checkValue, checkType, checkRange)
  	if not checkValue then return end
  	if checkType == 1 then
  		local limits = checkRange:toNumMap()
  		for min, max in pairs(limits) do
  			if checkValue >= min and checkValue <= max then
  				return true
  			end
  		end
  	else
  		local limit = checkRange:toArray(true, "=")
  		for _, _l in ipairs(limit) do
  			if _l == checkValue then
  				return true
  			end
  		end
  	end
  end
  
  --关卡事件库
1607a7f0   zhouahaihai   冒险事件 new
51
  local function getEventLib(chapterId, level, needEventType) -- needEventType  需要的事件
46fac6f1   zhouahaihai   酱料
52
53
54
  	local chapter = math.floor(chapterId / 100) % 100
  
  	local libsToType = {
1bd8f8ee   zhouahaihai   精英怪
55
  		["event_monsterCsv"] = {AdvEventType.Monster, AdvEventType.BOSS, AdvEventType.Monster},
46fac6f1   zhouahaihai   酱料
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  		["event_chooseCsv"] = AdvEventType.Choose,
  		["event_dropCsv"] = AdvEventType.Drop,
  		["event_buildingCsv"] = AdvEventType.Build,
  		["event_traderCsv"] = AdvEventType.Trader,
  
  	}
  	local eventLib = {}
  	for lib, eventType in pairs(libsToType) do
  		if type(eventType) == "table" then
  			for _, temp in ipairs(eventType) do
  				eventLib[temp] = {}
  			end
  		else
  			eventLib[eventType] = {}
  		end
  		if not needEventType or eventLib[needEventType] then 
  			for id, data in pairs(csvdb[lib]) do
  				if data.levelchapter == chapter then
  					if checkIsIn(level, data.leveltype, data.levellimit) then
  						if type(eventType) == "table" then
1607a7f0   zhouahaihai   冒险事件 new
76
77
  							eventLib[eventType[data.type]][data.BlockEventType] = eventLib[eventType[data.type]][data.BlockEventType] or {}
  							eventLib[eventType[data.type]][data.BlockEventType][id] = {showup = data.showup, limit = data.limit}
46fac6f1   zhouahaihai   酱料
78
  						else
1607a7f0   zhouahaihai   冒险事件 new
79
80
  							eventLib[eventType][data.BlockEventType] = eventLib[eventType][data.BlockEventType] or {}
  							eventLib[eventType][data.BlockEventType][id] = {showup = data.showup, limit = data.limit}
46fac6f1   zhouahaihai   酱料
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  						end
  					end
  				end
  			end
  			if needEventType then
  				break
  			end
  		end
  	end
  	return eventLib
  end
  
  -- 生成地图   是否可以生成地图上层判断
  local function randomAdvMap(role, chapterId, level, notNotify)
  	local chapterData = csvdb["adv_chapterCsv"][chapterId]
1607a7f0   zhouahaihai   冒险事件 new
96
97
98
99
100
101
102
103
  	if not chapterData then 
  		error("chapterId " .. chapterId .. " dont exist!")
  		return 
  	end
  	if level > chapterData.limitlevel then 
  		error("level overflow!")
  		return 
  	end
46fac6f1   zhouahaihai   酱料
104
105
106
  	--随出地图
  	local raw_pool = chapterData.mapid:toArray(true, "=")
  	local advInfo = role:getProperty("advInfo")
b0fe1817   zhouahaihai   冒险分数
107
  
46fac6f1   zhouahaihai   酱料
108
109
  	local lastMapId = advInfo.mapId  --非同一层不连续随出同一张类似的地图
  	local lastChapterId = advInfo.chapter
b0fe1817   zhouahaihai   冒险分数
110
  	local lastScore = advInfo.score or {}  -- 分数
ec87b4a5   zhouahaihai   冒险 完善
111
  	local power = advInfo.power or 100 --体力
b0fe1817   zhouahaihai   冒险分数
112
  
46fac6f1   zhouahaihai   酱料
113
114
115
116
117
118
119
120
121
  	local pool = {}
  	for _, mapId in ipairs(raw_pool) do
  		local temp = csvdb["mapCsv"][mapId]
  		if temp and (lastChapterId == chapterId or lastMapId ~= mapId) then --非同一层不连续随出同一张类似的地图
  			if checkIsIn(level, temp.leveltype, temp.levellimit) then
  				table.insert(pool, mapId)
  			end
  		end
  	end
1607a7f0   zhouahaihai   冒险事件 new
122
123
124
125
  	if not next(pool) then 
  		error("mapIds is empty!")
  		return 
  	end
46fac6f1   zhouahaihai   酱料
126
127
128
  	local mapId = pool[math.randomInt(1, #pool)]
  	--随出事件
  	local mapData = csvdb["map_" .. csvdb["mapCsv"][mapId]["path"] .. "Csv"]
1607a7f0   zhouahaihai   冒险事件 new
129
130
131
132
  	if not mapData then 
  		error("mapId " .. mapId .. " dont exist!")
  		return 
  	end
46fac6f1   zhouahaihai   酱料
133
  
46fac6f1   zhouahaihai   酱料
134
135
136
137
138
  	table.clear(advInfo)
  	advInfo.chapter = chapterId
  	advInfo.level = level
  	advInfo.mapId = mapId
  	advInfo.power = power
b0fe1817   zhouahaihai   冒险分数
139
  	advInfo.score = lastScore
46fac6f1   zhouahaihai   酱料
140
141
  	advInfo.enemyId = 1 --怪递增的索引
  	advInfo.rooms = {} -- {[roomId] = {event = {}, open = {}},} -- event 事件信息(具体信息查看randomEvent), open 是否解锁
46fac6f1   zhouahaihai   酱料
142
  	--事件随机
1607a7f0   zhouahaihai   冒险事件 new
143
  	local eventLib = getEventLib(chapterId, level)  -- 同时记录出现次数
46fac6f1   zhouahaihai   酱料
144
145
146
147
148
  	local monsterEvents = {}  --处理钥匙掉落
  	local haveBoss = false
  
  	local function randomEvent(roomId, blockId, eventType)
  		if advInfo.rooms[roomId]["event"][blockId] then return end --已经有事件了 不覆盖
1607a7f0   zhouahaihai   冒险事件 new
149
150
151
152
153
154
155
  		local etype, especial = eventType, 0
  		if eventType > 100 then   -- 特殊事件(固定)
  			etype = math.floor(eventType / 100)
  			especial = eventType % 100
  		end
  		
  		local event = {etype = etype}
46fac6f1   zhouahaihai   酱料
156
  		local randomFunc = {}
1607a7f0   zhouahaihai   冒险事件 new
157
158
159
160
161
162
163
164
165
166
167
  
  		local function randomCommon()
  			if not eventLib[etype] or not next(eventLib[etype]) or not eventLib[etype][especial] or not next(eventLib[etype][especial]) then return false end
  			event.id = math.randWeight(eventLib[etype][especial], "showup")
  			if eventLib[etype][especial][event.id].limit > 1 then
  				eventLib[etype][especial][event.id].limit = eventLib[etype][especial][event.id].limit - 1
  			elseif eventLib[etype][especial][event.id].limit == 1 then
  				eventLib[etype][especial][event.id] = nil
  			end
  		end
  
46fac6f1   zhouahaihai   酱料
168
169
170
171
  		--入口
  		randomFunc[AdvEventType.In] = function()end
  		--出口
  		randomFunc[AdvEventType.Out] = function() end
46fac6f1   zhouahaihai   酱料
172
173
  		--boss
  		randomFunc[AdvEventType.BOSS] = function()
1607a7f0   zhouahaihai   冒险事件 new
174
175
176
177
  			if haveBoss then return false end
  			if randomCommon() == false then
  				return false
  			end
46fac6f1   zhouahaihai   酱料
178
  			haveBoss = true
46fac6f1   zhouahaihai   酱料
179
180
181
  		end
  		--怪物
  		randomFunc[AdvEventType.Monster] = function()
1607a7f0   zhouahaihai   冒险事件 new
182
183
184
  			if randomCommon() == false then
  				return false
  			end
46fac6f1   zhouahaihai   酱料
185
186
  			table.insert(monsterEvents, event)
  		end
1607a7f0   zhouahaihai   冒险事件 new
187
  
46fac6f1   zhouahaihai   酱料
188
  		--选择点
1607a7f0   zhouahaihai   冒险事件 new
189
  		randomFunc[AdvEventType.Choose] = randomCommon
46fac6f1   zhouahaihai   酱料
190
  		--掉落点
1607a7f0   zhouahaihai   冒险事件 new
191
  		randomFunc[AdvEventType.Drop] = randomCommon
46fac6f1   zhouahaihai   酱料
192
  		--交易所
1607a7f0   zhouahaihai   冒险事件 new
193
  		randomFunc[AdvEventType.Trader] = randomCommon
46fac6f1   zhouahaihai   酱料
194
  		--建筑
1607a7f0   zhouahaihai   冒险事件 new
195
  		randomFunc[AdvEventType.Build] = randomCommon
46fac6f1   zhouahaihai   酱料
196
  
1607a7f0   zhouahaihai   冒险事件 new
197
198
  		if randomFunc[etype] then
  			if randomFunc[etype]() ~= false then
46fac6f1   zhouahaihai   酱料
199
200
201
202
  				advInfo.rooms[roomId]["event"][blockId] = event
  			end
  		end
  	end
46fac6f1   zhouahaihai   酱料
203
204
205
206
207
208
209
210
211
212
213
214
215
  	stagePool = {["global"] = {}}
  	for roomId, roomName in pairs(mapData["rooms"]) do
  		stagePool[roomId] = {}
  		advInfo.rooms[roomId] = {event = {}, open = {}}  -- 事件, open  open == 1 房间内地块全部开放
  		local roomData
  		if roomName == "path" then
  			roomData = mapData["path"]
  		else
  			roomName = roomName:gsub("/", "_")
  			roomData = csvdb["room_" .. roomName .. "Csv"]
  		end
  		for blockId, stageType in pairs(roomData["blocks"]) do
  			if AdvSpecialStage[stageType] then
1607a7f0   zhouahaihai   冒险事件 new
216
  				eventType = AdvEventType[AdvSpecialStage[stageType]] -- 地块固定类型
46fac6f1   zhouahaihai   酱料
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
  				randomEvent(roomId, blockId, eventType)
  			else
  				stagePool["global"][stageType] = stagePool["global"][stageType] or {}
  				stagePool[roomId][stageType] = stagePool[roomId][stageType] or {}
  				table.insert(stagePool["global"][stageType], {room = roomId, block = blockId})
  				stagePool[roomId][stageType][blockId] = 1
  			end
  		end
  	end
  	-- 全地图事件 优先级高
  	for stageType, events in pairs(mapData["events"]) do
  		for _, event in ipairs(events) do
  			local lastCount = #stagePool["global"][stageType]
  			if lastCount <= 0 then break end
  			if math.randomFloat(0, 1) <= (event["rate"] or 1) then
  				local count = math.randomInt(math.min(lastCount, event["minc"]), math.min(lastCount, event["maxc"]))
  				for i = 1, count do
  					local idx = math.randomInt(1, lastCount)
  					local cur = stagePool["global"][stageType][idx]
  					randomEvent(cur["room"], cur["block"], event["event"])
  					table.remove(stagePool["global"][stageType], idx)
  					lastCount = lastCount - 1
  					stagePool[cur["room"]][stageType][cur["block"]] = nil
  				end
  			end
  		end
  	end
  	-- 随机单个房间的事件	
  	for roomId, roomName in pairs(mapData["rooms"]) do
  		local roomData
  		if roomName == "path" then
  			roomData = mapData["path"]
  		else
  			roomName = roomName:gsub("/", "_")
  			roomData = csvdb["room_" .. roomName .. "Csv"]
  		end
  		for stageType, events in pairs(roomData["events"]) do
  			local bpool = {}
  			if stagePool[roomId][stageType] then
  				for block, _ in pairs(stagePool[roomId][stageType]) do
  					table.insert(bpool, block)
  				end
  			end
  			for _, event in ipairs(events) do
  				if #bpool <= 0 then break end
  				if math.randomFloat(0, 1) <= (event["rate"] or 1) then
  					local count = math.randomInt(math.min(#bpool, event["minc"]), math.min(#bpool, event["maxc"]))
  					for i = 1, count do
  						local idx = math.randomInt(1, #bpool)
  						randomEvent(roomId, bpool[idx], event["event"])
  						table.remove(bpool, idx)
  					end
  				end
  			end
  		end
  	end
  	if not haveBoss then
  		if not next(monsterEvents) then
  			print("这个地图没有钥匙!!! mapId : " .. mapId)
  		else
  			local event = monsterEvents[math.randomInt(1, #monsterEvents)]
1607a7f0   zhouahaihai   冒险事件 new
278
  			event.item = {ItemId.AdvKey, 1}  --掉落钥匙
46fac6f1   zhouahaihai   酱料
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
  		end
  	end
  end
  
  --块类型
  local Block = class("Block")
  function Block:ctor(blockId, event, isOpen)
  	self.blockId = blockId
  	self.col, self.row = getCrById(self.blockId)
  	self.isOpen = isOpen and true or false
  	self.event = event  -- 拿到的是引用可以直接更新
  end
  function Block:isBoss()
  	if not self.event then return end
  	return self.event["etype"] == AdvEventType.BOSS
  end
  
  --事件有需要额外处理的部分
  function Block:open(adv, room)
  	--如果翻开有数据处理在这里处理
  	local randomFunc = {}
  	--怪
  	randomFunc[AdvEventType.Monster] = function()
  		self.event.mId = adv.advInfo.enemyId  --给怪一个有序id 回合逻辑时使用
  		adv.advInfo.enemyId = adv.advInfo.enemyId + 1
36c30c5c   zhouahaihai   冒险
304
  		local enemy = adv.battle:getEnemy(room.roomId, self.blockId)
46fac6f1   zhouahaihai   酱料
305
306
307
  		if enemy then
  			enemy:unlock(self.event.mId)
  		else
02c4de8d   zhouahaihai   增加 固有技
308
  			enemy = adv.battle:addEnemy(room, self)
46fac6f1   zhouahaihai   酱料
309
  		end
02c4de8d   zhouahaihai   增加 固有技
310
  		enemy:triggerPassive(Passive.BORN_ONCE)
46fac6f1   zhouahaihai   酱料
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
  	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索引
  		for i = 1, 10 do
  			local numS, rangeS = "num" .. i, "range" .. i
  			if data[numS] and data[rangeS] then
  				for j = 1, data[numS] do
  					table.insert(self.event.shop, data[rangeS]:randWeight(true))
  				end
  			else
  				break
  			end
  		end
  	end
  	--建筑
36c30c5c   zhouahaihai   冒险
334
  	randomFunc[AdvEventType.Build] = function()
46fac6f1   zhouahaihai   酱料
335
336
337
338
339
340
341
342
  		local data = csvdb["event_buildingCsv"][self.event.id]
  		self.event.effect = data["range"]:randWeight(true) --随出建筑效果
  		if self.event.effect[1] == 1 then --获得某道具
  			local reward = csvdb["event_dropCsv"][self.event.effect[2]]["range"]:randWeight(true)
  			self.event.effect[2] = reward[1]
  			self.event.effect[3] = reward[2]
  		end
  	end
46fac6f1   zhouahaihai   酱料
343
344
345
346
347
  	if self.event then -- 随机出具体的事件
  		if randomFunc[self.event.etype] then
  			randomFunc[self.event.etype]()
  		end
  	end
36c30c5c   zhouahaihai   冒险
348
  	self.isOpen = true
46fac6f1   zhouahaihai   酱料
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
  end
  
  local Room = class("Room")
  function Room:ctor(adv, roomId, csvData, info, isPath)
  	self.roomId = roomId
  	self.col, self.row = getCrById(self.roomId)
  	self.isPath = isPath
  	self.isBossRoom = false -- boss房间   --击败boss 以后重置为false
  	self.info = info -- 拿到引用 方便更新advInfo
  	self.isShow = false
  	self.blocks = {}
  
  	for blockId, _ in pairs(csvData["blocks"]) do
  		self.blocks[blockId] = Block.new(blockId, info.event[blockId], info.open == 1 or info.open[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].event and self.blocks[blockId].event.etype == AdvEventType.In then -- 开放
  				self.isShow = true
  				self.blocks[blockId].isOpen = true
  				self.info.open[blockId] = 1
  
  				--入口房间只会在这里首次展示开放 --触发固有技
  				adv:triggerPassive(Passive.ROOM_SHOW, {roomId = self.roomId})
  			end
  		end
  	end
  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[getIdByCr(c, r)]
  end
  
  function Room:openBlock(block, adv)
  	if self.blocks[block.blockId] ~= block then return end
  	if block.isOpen == true then return end
36c30c5c   zhouahaihai   冒险
397
  	if self.isBossRoom then
46fac6f1   zhouahaihai   酱料
398
  		for _, _block in pairs(self.blocks) do
36c30c5c   zhouahaihai   冒险
399
400
401
402
403
404
405
406
407
408
  			_block:open(adv, self)
  		end
  	else
  		block:open(adv, self)
  	end
  	local allOpen = true
  	for _, _block in pairs(self.blocks) do
  		if not _block.isOpen then
  			allOpen = false
  			break
46fac6f1   zhouahaihai   酱料
409
410
411
412
413
414
415
416
417
  		end
  	end
  
  	if allOpen then
  		self.info.open = 1
  	else
  		self.info.open[block.blockId] = 1
  	end
  
b0fe1817   zhouahaihai   冒险分数
418
419
  	adv:scoreChange(AdvScoreType.Block)
  
46fac6f1   zhouahaihai   酱料
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
  	if not self.isShow then
  		self.isShow = true
  		--首次展示房间
  		adv:triggerPassive(Passive.ROOM_SHOW, {roomId = self.roomId})
  	end 
  end
  
  function Room:clearBEvent(block)
  	if self.blocks[block.blockId] ~= block then return end
  	block.event = nil
  	self.info.event[block.blockId] = nil
  end
  
  
  
  local Adv = class("Adv")
  function Adv:ctor(owner)
  	assert(owner, "Adv instance must have owner(role)")
  	self.owner = owner
  	self.advInfo = self.owner:getProperty("advInfo")  --这个变量置空使用 table.clear  
  	self.advTeam = self.owner:getProperty("advTeam")	--这个变量置空使用 table.clear  
  	self:clear()
36c30c5c   zhouahaihai   冒险
442
  	self.backEvents = {} --发给客户端的事件组
46fac6f1   zhouahaihai   酱料
443
444
445
446
447
448
449
450
451
452
453
  end
  
  -- 清空自己组织的数据
  function Adv:clear()
  	self.rooms = {}
  	self.cachePassiveEvent = {} -- 在battle 没有创建成功时 触发的被动技信息
  	self.battle = nil -- 战斗逻辑
  end
  
  --关卡通关,非层 score < 0 失败
  function Adv:over(success)
b0fe1817   zhouahaihai   冒险分数
454
455
  	local score = self:getScore()
  	local scoreInfo = self.advInfo.score
00115a7a   zhouahaihai   奖励发放
456
  	local reward
46fac6f1   zhouahaihai   酱料
457
  	if success then
46fac6f1   zhouahaihai   酱料
458
  		self.owner:updateProperty({field = "advPass", self.owner:getProperty("advPass"):setv(self.advInfo.chapter, score)})
00115a7a   zhouahaihai   奖励发放
459
  		reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap(), {})
46fac6f1   zhouahaihai   酱料
460
461
462
463
  	end
  	table.clear(self.advInfo) --清空advInfo
  	self.advTeam.player = nil --重置玩家的数据
  	self:clear()
00115a7a   zhouahaihai   奖励发放
464
  	
bedca62d   zhouahaihai   冒险
465
  	self.owner:updateProperty({field = "advItems", value = ""})
00115a7a   zhouahaihai   奖励发放
466
  
b0fe1817   zhouahaihai   冒险分数
467
  	self:backEnd(success, score, scoreInfo, reward)
46fac6f1   zhouahaihai   酱料
468
469
  end
  
ec87b4a5   zhouahaihai   冒险 完善
470
  function Adv:exit()
4b7c7c96   zhouahaihai   增加 清空 挂机 冒险gm 角色经验
471
  	self:over(false)
ec87b4a5   zhouahaihai   冒险 完善
472
473
474
  	self:saveDB()
  end
  
46fac6f1   zhouahaihai   酱料
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
  function Adv:getMapInfo()
  	if not next(self.advInfo) then return end
  	return csvdb["mapCsv"][self.advInfo.mapId]
  end
  
  function Adv:getMapData()
  	local mapInfo = self:getMapInfo()
  	if not mapInfo then return end
  	return csvdb["map_" .. self:getMapInfo()["path"] .. "Csv"]
  end
  
  function Adv:initByInfo()
  	self:clear()
  	if not next(self.advInfo) then return end --未初始化的 advInfo
  
  	local mapData = self:getMapData()
  	if not mapData then return end
  
  	for roomId, roomName in pairs(mapData["rooms"]) do
  		if roomName == "path" then
  			self.rooms[roomId] = Room.new(self, roomId, mapData["path"], self.advInfo.rooms[roomId], true)
  		else
  			roomName = roomName:gsub("/", "_")
  			self.rooms[roomId] = Room.new(self, roomId, csvdb["room_" .. roomName .. "Csv"], self.advInfo.rooms[roomId], false)
  		end
  	end
  	self:initBattle()
  	return true
  end
  
  function Adv:triggerPassive(condType, params)
  	if not self.battle then
  		table.insert(self.cachePassiveEvent, {condType, params})
  	else
  		self.battle:triggerPassive(condType, params)
  	end
  end
  
  function Adv:initBattle()
  	self.battle = require("adv.AdvBattle").new(self)
  	for _, passiveC in ipairs(self.cachePassiveEvent) do
  		self.battle:triggerPassive(passiveC[1], passiveC[2])
  	end
  	self.cachePassiveEvent = {}
  end
  
  -- 随机地图
  function Adv:initByChapter(chapterId, level, notNotify)
36c30c5c   zhouahaihai   冒险
523
  	level = level or 1
46fac6f1   zhouahaihai   酱料
524
  	randomAdvMap(self.owner, chapterId, level, notNotify)
b0fe1817   zhouahaihai   冒险分数
525
526
527
528
  	if not next(self.advInfo) then return end
  	if level > 1 then
  		self:scoreChange(AdvScoreType.Level)
  	end
46fac6f1   zhouahaihai   酱料
529
  	self:initByInfo() --初始化
36c30c5c   zhouahaihai   冒险
530
  	self.owner:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam}, notNotify)
46fac6f1   zhouahaihai   酱料
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
  end
  
  --获取,某个位置上的 room 和 block
  function Adv:getRBByPos(c, r)
  	for roomId, room in pairs(self.rooms) do
  		local block = room:getBByGPos(c, r)
  		if block then
  			return room, block
  		end
  	end
  end
  
  function Adv:getAroundBlocks(room, block)
  	local blocks = {}
  	local range = {1, -1}
  	local col, row = room:tranLtoG(block.col, block.row)
  	for _, add in ipairs(range) do
  		local rroom, rblock = self:getRBByPos(col + add, row)
  		if rroom then
  			table.insert(blocks, {rroom, rblock})
  		end
  	end
  	for _, add in ipairs(range) do
  		local rroom, rblock = self:getRBByPos(col, row + add)
  		if rroom then
  			table.insert(blocks, {rroom, rblock})
  		end
  	end
  	return blocks
  end
  
  --随机一个空的位置生成怪, 如果没有就没有	
02c4de8d   zhouahaihai   增加 固有技
563
564
565
566
567
568
569
570
571
572
573
  function Adv:addNewMonsterRand(monsterId, where)
  	local room, block
  	if where then
  		room, block = where[1], where[2]
  	else
  		local pool = {}
  		for _, room_ in pairs(self.rooms) do
  			for _, block_ in pairs(room_.blocks) do
  				if block_.isOpen and not block_.event then
  					table.insert(pool, {room_, block_})
  				end
46fac6f1   zhouahaihai   酱料
574
575
  			end
  		end
02c4de8d   zhouahaihai   增加 固有技
576
577
578
  		if not next(pool) then return end
  		local idx = math.randomInt(1, #pool)
  		room, block = pool[idx][1], pool[idx][2]
46fac6f1   zhouahaihai   酱料
579
  	end
02c4de8d   zhouahaihai   增加 固有技
580
  	
9cffb42b   zhouahaihai   抉择点 建筑
581
582
  	if not monsterId then
  		local eventLib = getEventLib(self.advInfo.chapter, self.advInfo.level, AdvEventType.Monster)
1607a7f0   zhouahaihai   冒险事件 new
583
584
  		if not next(eventLib[AdvEventType.Monster][0]) then return false end
  		monsterId = math.randWeight(eventLib[AdvEventType.Monster][0], "showup")
9cffb42b   zhouahaihai   抉择点 建筑
585
  	end
02c4de8d   zhouahaihai   增加 固有技
586
587
588
  
  	local event = {etype = AdvEventType.Monster, mId = self.advInfo.enemyId}
  	self.advInfo.enemyId = self.advInfo.enemyId + 1
9cffb42b   zhouahaihai   抉择点 建筑
589
  	event.id = monsterId
46fac6f1   zhouahaihai   酱料
590
591
  	block.event = event
  	room.info.event[block.blockId] = event
02c4de8d   zhouahaihai   增加 固有技
592
593
  	self.battle:addEnemy(room, block):triggerPassive(Passive.BORN_ONCE)
  
46fac6f1   zhouahaihai   酱料
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
  	return room, block
  end
  
  -- 随机翻开 num 个 以开放的房间的 地块
  function Adv:openBlockRand(num)
  	local pool = {}
  	for _, room in pairs(self.rooms) do
  		if room.isShow and not room.isPath then
  			for _, block in pairs(room.blocks) do
  				if not block.isOpen then
  					table.insert(pool, {room.roomId, block.blockId})
  				end
  			end
  		end
  	end
  	if #pool <= num then
  		for _, temp in ipairs(pool) do
  			self:openBlock(temp[1], temp[2])
  		end
  	else
  		for i = 1, num do
  			local idx = math.randomInt(1, #pool)
  			self:openBlock(pool[idx][1], pool[idx][2])
  			table.remove(pool, idx)
  		end
  	end
  end
  -- 打开一个地块
  function Adv:openBlock(roomId, blockId)
  	local room = self.rooms[roomId]
02c4de8d   zhouahaihai   增加 固有技
624
  	if not room then return end
46fac6f1   zhouahaihai   酱料
625
  	local block = room.blocks[blockId]
02c4de8d   zhouahaihai   增加 固有技
626
  	if not block then return end
46fac6f1   zhouahaihai   酱料
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
  	room:openBlock(block, self)
  	self:backBlockChange(roomId, blockId)
  end
  
  -- 在冒险中获得的物品都发放在冒险背包内
  function Adv:award(gift, params)
  	local tgift = {}
  	if type(gift) == "string" then
  		for _, one in pairs(gift:toTableArray(true)) do
  			tgift[one[1]] = (tgift[one[1]] or 0) + one[2]
  		end
  	else
  		tgift = gift
  	end
  	local items = self.owner:getProperty("advItems")
  	for itemId, count in pairs(tgift) do
b0fe1817   zhouahaihai   冒险分数
643
644
645
  		if count > 0 then
  			self:scoreChange(AdvScoreType.Item, {itemId, count})
  		end
46fac6f1   zhouahaihai   酱料
646
647
648
649
650
651
652
653
654
  		local origin = items:getv(itemId, 0)
  		local nums = origin + count
  		if nums <= 0 then
  			items = items:delk(itemId)
  			nums = 0
  		else
  			items = items:incrv(itemId, count)
  		end
  	end
9cffb42b   zhouahaihai   抉择点 建筑
655
  
46fac6f1   zhouahaihai   酱料
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
  	self.owner:updateProperty({field = "advItems", value = items, notNotify = params.notNotify})
  	return tgift
  end
  
  -- 消耗物品 优先冒险背包  --check 只是检查够不够
  function Adv:cost(item, params, check)
  	local items = self.owner:getProperty("advItems")
  	local less = {}
  	local advCost = {}
  	for itemId, count in pairs(item) do
  		advCost[itemId] = - math.min(items:getv(itemId, 0), count)
  		if advCost[itemId] == 0 then
  			advCost[itemId] = nil
  		end
  
  		local last = items:getv(itemId, 0) - count
  		if last < 0 then
  			less[itemId] = -last
  		end
  
  	end
  	if next(less) and not self.owner:checkItemEnough(less) then return end --不够
  	if check then return true end
  	self:award(advCost, params)
  	self.owner:costItems(less, params)
  	return true
  end
  
  --事件点击处理
  local function clickOut(self, room, block, params)
36c30c5c   zhouahaihai   冒险
686
  	if self:cost({[ItemId.AdvKey] = 1}, {}) then
46fac6f1   zhouahaihai   酱料
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
  		if self.advInfo.level >= csvdb["adv_chapterCsv"][self.advInfo.chapter].limitlevel then --关卡结束
  			self:over(true)
  		else
  			self:initByChapter(self.advInfo.chapter, self.advInfo.level + 1, true)
  			self:backNext() --下一关
  		end
  		return true
  	end
  end
  
  --战斗 普通攻击
  local function clickMonster(self, room, block, params)
  	self.battle:playerAtk(room.roomId, block.blockId)
  	return true
  end
  
  local function clickChoose(self, room, block, params)
  	local choose = params.choose
  	local chooseData = csvdb["event_chooseCsv"][block.event.id]
  	if not chooseData or not chooseData["button".. choose .."cond"] then return end
  
  	local cond = chooseData["button".. choose .."cond"]:toArray(true, "=")
  	local checkCond = {
  		-- 拥有道具
  		[1] = function()
  			if self:cost({[cond[2]] = cond[3]}, {}, true) then
  				return true
  			end
  		end,
  		-- xx角色(todo 队长)
  		[2] = function()
  			for slot, heroId in pairs(self.advTeam.heros) do
  				if self.owner.heros[heroId] then
  					if self.owner.heros[heroId]:getProperty("type") == cond[2] then
  						return true
  					end
  				end
  			end
  		end,
  		--消灭所有怪
  		[3] = function()
  			for _, room in pairs(self.rooms) do
4ae223df   zhouahaihai   Buff bug
729
  				for _, block in pairs(room.blocks) do
46fac6f1   zhouahaihai   酱料
730
731
732
733
734
735
736
737
738
739
740
741
742
743
  					if block.event and (block.event.etype == AdvEventType.BOSS or block.event.etype == AdvEventType.Monster) then
  						return
  					end
  				end
  			end
  			return true
  		end,
  		--制定属性 > 
  		[4] = function()
  			if (self.battle.player[AttsEnumEx[cond[2]]] or 0) > cond[3] then
  				return true
  			end
  		end,
  	}
9cffb42b   zhouahaihai   抉择点 建筑
744
745
  	assert(not cond[1] or checkCond[cond[1]], "error cond, event_chooseCsv id :" .. block.event.id)
  	if cond[1] and not checkCond[cond[1]]() then return end
02c4de8d   zhouahaihai   增加 固有技
746
  	local clearBlock = true
e10edb5f   zhouahaihai   冒险事件新
747
748
749
750
751
752
  	local effects = chooseData["button".. choose .."effect"]:toTableArray(true)
  	for _, effect in ipairs(effects) do
  		if effect[1] == 1 then
  			local reward = csvdb["event_dropCsv"][effect[2]]["range"]:randWeight(true)
  			effect[2] = reward[1]
  			effect[3] = reward[2]
46fac6f1   zhouahaihai   酱料
753
  		end
e10edb5f   zhouahaihai   冒险事件新
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
  
  		local doEffect = {
  			[1] = function() -- 获得某道具N个
  				self:backReward(self:award({[effect[2]] = effect[3]}, {}))
  			end,
  			[2] = function() --获得冒险buff
  				self.battle.player:addBuff(effect[2])
  			end,
  			[3] = function() --发现怪物
  				self:addNewMonsterRand(effect[2], {room, block})
  				clearBlock = false
  			end,
  			[4] = function() --无事发生
  			end
  		}
  		assert(doEffect[effect[1]], "error effect, event_chooseCsv id :" .. block.event.id)
  		doEffect[effect[1]]()
  	end
  
02c4de8d   zhouahaihai   增加 固有技
773
774
775
  	if clearBlock then
  		room:clearBEvent(block)
  	end
46fac6f1   zhouahaihai   酱料
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
  	return true
  end
  
  local function clickDrop(self, room, block, params)
  	local reward = {}
  	if not block.event.item then return end
  	local reward = self:award({[block.event.item[1]] = block.event.item[2]}, {})
  	room:clearBEvent(block)
  	self:backReward(reward)
  	return true
  end
  
  local function clickTrader(self, room, block, params)
  	local buyId = params.id
  	local traderData = csvdb["event_traderCsv"][block.event.id]
  	if not traderData then return end -- 偷偷改表了
  
  	if not block.event.shop or not block.event.shop[buyId] then return end
  	if (block.event.status or ""):getv(buyId, 0) == 1 then return end -- 买过了
  
e10edb5f   zhouahaihai   冒险事件新
796
  	if not self:cost({[traderData.type] = block.event.shop[buyId][3]}, {}) then return end --不够
46fac6f1   zhouahaihai   酱料
797
798
799
800
801
802
803
804
805
806
807
  
  	local reward = self:award({[block.event.shop[buyId][1]] = block.event.shop[buyId][2]}, {})
  	block.event.status = block.event.status:setv(buyId, 1)
  	self:backReward(reward)
  	return true
  end
  
  local function clickBuild(self, room, block, params)
  	local buildData = csvdb["event_buildingCsv"][block.event.id]
  	if not buildData then return end-- 偷偷改表了
  	if not block.event.effect then return end -- 没有效果 气人不
02c4de8d   zhouahaihai   增加 固有技
808
  	local clearBlock = true
46fac6f1   zhouahaihai   酱料
809
810
811
812
813
814
815
816
817
818
  	local effect = block.event.effect
  	--todo 效果生效
  	local doEffect = {
  		[1] = function() -- 获得某道具N个
  			self:backReward(self:award({[effect[2]] = effect[3]}, {}))
  		end,
  		[2] = function() --获得冒险buff
  			self.battle.player:addBuff(effect[2])
  		end,
  		[3] = function() --发现怪物
02c4de8d   zhouahaihai   增加 固有技
819
820
  			self:addNewMonsterRand(effect[2], {room, block})
  			clearBlock = false
46fac6f1   zhouahaihai   酱料
821
822
823
824
825
  		end,
  		[4] = function() --无事发生
  		end
  	}
  	assert(doEffect[effect[1]], "error effect, event_buildingCsv id :" .. block.event.id)
e10edb5f   zhouahaihai   冒险事件新
826
  	if not self:cost(buildData.required:toNumMap(), {}) then return end
46fac6f1   zhouahaihai   酱料
827
  	doEffect[effect[1]]()
02c4de8d   zhouahaihai   增加 固有技
828
829
830
  	if clearBlock then
  		room:clearBEvent(block)
  	end
46fac6f1   zhouahaihai   酱料
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
  	return true
  end
  
  local eventCallFunc = {
  	[AdvEventType.Out] = clickOut,
  	[AdvEventType.BOSS] = clickMonster,
  	[AdvEventType.Monster] = clickMonster,
  	[AdvEventType.Choose] = clickChoose,
  	[AdvEventType.Drop] = clickDrop,
  	[AdvEventType.Trader] = clickTrader,
  	[AdvEventType.Build] = clickBuild,
  }
  
  --点击处理 roomId, blockId 
  --params 某些事件需要的客户端传递的参数
  function Adv:clickBlock(roomId, blockId, params)
  	local room = self.rooms[roomId]
  	if not room then return end
  	local block = room.blocks[blockId]
  	if not block then return end
  
46fac6f1   zhouahaihai   酱料
852
  	local status = false
36c30c5c   zhouahaihai   冒险
853
  	local clickEvent = false
46fac6f1   zhouahaihai   酱料
854
  	if not block.isOpen then
36c30c5c   zhouahaihai   冒险
855
856
857
858
859
860
861
862
863
  		local canOpen = false  --如果未开放是否可以开放
  		local hadMonster = false -- 周围是否有解锁的怪未击败
  		for _, one in ipairs(self:getAroundBlocks(room, block)) do
  			local _room, _block = one[1], one[2]
  			if _block.isOpen then canOpen = true end
  			if _block.isOpen and _block.event and (_block.event.etype == AdvEventType.BOSS or _block.event.etype == AdvEventType.Monster) then 
  				hadMonster = true 
  			end
  		end
46fac6f1   zhouahaihai   酱料
864
865
866
867
868
  		if canOpen and not hadMonster then --开放
  			room:openBlock(block, self)
  			status = true
  		end
  	else
36c30c5c   zhouahaihai   冒险
869
  		clickEvent = true
46fac6f1   zhouahaihai   酱料
870
871
872
873
874
  		--点了空地
  		if not block.event then
  			return 
  		end
  		--可点击的事件
36c30c5c   zhouahaihai   冒险
875
  		if not room.isBossRoom or block.event.etype == AdvEventType.BOSS then
46fac6f1   zhouahaihai   酱料
876
877
878
879
880
  			if eventCallFunc[block.event.etype] then
  				status = eventCallFunc[block.event.etype](self, room, block, params)
  			end
  		end
  	end
36c30c5c   zhouahaihai   冒险
881
  	if status and (not clickEvent or (not block.event or block.event.etype ~= AdvEventType.Out)) then  --出去了就不计算回合了
46fac6f1   zhouahaihai   酱料
882
883
884
  		self:backBlockChange(roomId, blockId)
  		self:afterRound()
  	end
36c30c5c   zhouahaihai   冒险
885
  	self:saveDB()
46fac6f1   zhouahaihai   酱料
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
  	return status
  end
  
  --使用道具产生效果
  function Adv:useItem(itemId, count, target)
  	count = count or 1
  	local itemData = csvdb["adv_itemCsv"][itemId] 
  	if not itemData then return end
  	--重置数量 
  	if itemData["function"] == 0 or itemData["function"] == 2 then count = 1 end
  	if not self:cost({[itemId] = count}, {}, true) then return true end
  	--消耗
  	if itemData["function"] == 0 or itemData["function"] == 1 then 
  		self:cost({[itemId] = count}, {})
  	end
  	--生效
  	if itemData.type == 1 or itemData.type == 0 then --技能
  		self.battle.player:releaseSkill(itemData.effect, 1, target)
  	elseif itemData.type == 2 then	--掉落
  		local item = csvdb["event_dropCsv"][itemData.effect]["range"]:randWeight(true)
  		self:backReward(self:award({[item[1]] = item[2]}, {}))
  	else
  		return
  	end
  
  	self:afterRound()
36c30c5c   zhouahaihai   冒险
912
  	self:saveDB()
46fac6f1   zhouahaihai   酱料
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
  	return true
  end
  
  --使用技能
  function Adv:useSkill(skillId, target)
  	local skillLevel = nil
  	if skillId > 1000 then return end
  	for slot, heroId in pairs(self.advTeam.heros) do
  		if self.owner.heros[heroId] then
  			if csvdb["unitCsv"][self.owner.heros[heroId]:getSkinId()]["adv"] == skillId then
  				skillLevel = self.owner.heros[heroId]:getSkillLevel(4)
  				break
  			end
  		end
  	end
  	if not skillLevel then return end
  	local skillData = csvdb["adv_skillCsv"][skillId]
  	if self.advInfo.power < skillData.cost then return end
  	self.advInfo.power = self.advInfo.power - skillData.cost
  	if skillData.target:toArray(true, "=")[1] == 0 then
  		local enemy = self.battle:getEnemy(target.roomId, target.blockId)
  		if not enemy then return end
  		self.battle.player:releaseSkill(skillId, skillLevel, enemy)
  	else
  		self.battle.player:releaseSkill(skillId, skillLevel)
  	end
  	
  	self:afterRound()
36c30c5c   zhouahaihai   冒险
941
  	self:saveDB()
46fac6f1   zhouahaihai   酱料
942
943
944
945
  	return true
  end
  
  --敌人死亡
02c4de8d   zhouahaihai   增加 固有技
946
  function Adv:enemyDead(roomId, blockId, escape)
36c30c5c   zhouahaihai   冒险
947
948
  	local room = self.rooms[roomId]
  	local block = room.blocks[blockId]
46fac6f1   zhouahaihai   酱料
949
950
  	--死了以后掉东西
  	if block.event and (block.event.etype == AdvEventType.BOSS or block.event.etype == AdvEventType.Monster) then --处理死亡
36c30c5c   zhouahaihai   冒险
951
952
953
  		if block.event.etype == AdvEventType.BOSS then
  			room.isBossRoom = false
  		end
02c4de8d   zhouahaihai   增加 固有技
954
955
956
  		if escape then
  			room:clearBEvent(block)
  		else
b0fe1817   zhouahaihai   冒险分数
957
958
959
  			local monsterData = csvdb["event_monsterCsv"][block.event.id]
  			self:scoreChange(AdvScoreType.Kill, monsterData.type)
  
02c4de8d   zhouahaihai   增加 固有技
960
961
962
963
964
  			local item = block.event.item
  			if not item then
  				if block.event.etype == AdvEventType.BOSS then
  					item = {ItemId.AdvKey, 1} 
  				else
02c4de8d   zhouahaihai   增加 固有技
965
966
967
  					local dropData = csvdb["event_dropCsv"][monsterData.dropid]
  					item = dropData["range"]:randWeight(true)
  				end
46fac6f1   zhouahaihai   酱料
968
  			end
4b7c7c96   zhouahaihai   增加 清空 挂机 冒险gm 角色经验
969
970
971
972
973
974
975
  			if item[1] == 0 then
  				room:clearBEvent(block)
  			else
  				table.clear(block.event)
  				block.event.etype = AdvEventType.Drop
  				block.event.item = item
  			end
46fac6f1   zhouahaihai   酱料
976
  		end
46fac6f1   zhouahaihai   酱料
977
978
979
980
981
982
983
984
985
986
987
988
989
  	end
  	self:backBlockChange(roomId, blockId)
  end
  
  --cType 0 or nil  值  1 百分比
  function Adv:changePower(value, cType)
  	cType = cType or 0
  	if cType == 0 then
  		self.advInfo.power = self.advInfo.power + value
  	elseif cType == 1 then
  		self.advInfo.power = self.advInfo.power + self.advInfo.power * value
  	end
  	self.advInfo.power = math.floor(math.max(0, self.advInfo.power))
ec87b4a5   zhouahaihai   冒险 完善
990
  	self:pushBackEvent(AdvBackEventType.PowerChange)
46fac6f1   zhouahaihai   酱料
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
  end
  
  function Adv:pushBackEvent(btype, params)
  	table.insert(self.backEvents, {btype = btype, params = params})
  end
  
  function Adv:backReward(items)
  	self:pushBackEvent(AdvBackEventType.Reward, {items = items})
  end
  -- if is player enemyId is nil 
  --isMax 是否是改变血量上限
  function Adv:backHpChange(enemyId, change, isMax) 
  	self:pushBackEvent(AdvBackEventType.HpChange, {enemyId = enemyId, change = change, isMax = isMax})
  end
  -- if is player enemyId is nil 
  function Adv:backAtkChange(enemyId, change)
  	self:pushBackEvent(AdvBackEventType.AtkChange, {enemyId = enemyId, change = change})
  end
e996b82a   zhouahaihai   冒险增加防御属性
1009
1010
1011
1012
1013
1014
  
  -- if is player enemyId is nil 
  function Adv:backDefChange(enemyId, change)
  	self:pushBackEvent(AdvBackEventType.DefChange, {enemyId = enemyId, change = change})
  end
  
46fac6f1   zhouahaihai   酱料
1015
1016
1017
1018
1019
1020
  -- if is player enemyId is nil 
  function Adv:backBuff(enemyId, buffId, isDel)
  	self:pushBackEvent(AdvBackEventType.Buff, {enemyId = enemyId, buffId = buffId, isDel = isDel})
  end
  -- if is player enemyId is nil 
  function Adv:backSkill(enemyId, skillId, receiver)
36c30c5c   zhouahaihai   冒险
1021
  	self:pushBackEvent(AdvBackEventType.Skill, {enemyId = enemyId, skillId = skillId, receiver = receiver})
46fac6f1   zhouahaihai   酱料
1022
1023
1024
1025
1026
1027
  end
  
  function Adv:backNext()
  	self:pushBackEvent(AdvBackEventType.Next, {})
  end
  
b0fe1817   zhouahaihai   冒险分数
1028
1029
  function Adv:backEnd(success, score, scoreInfo, reward)
  	self:pushBackEvent(AdvBackEventType.End, {success = success, score = score, scoreInfo = scoreInfo, reward = reward})
46fac6f1   zhouahaihai   酱料
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
  end
  
  function Adv:backBlockChange(roomId, blockId)
  	self:pushBackEvent(AdvBackEventType.BlockChange, {roomId = roomId, blockId = blockId})
  end
  
  function Adv:backAtk(enemyId, receiver)
  	self:pushBackEvent(AdvBackEventType.Atk, {enemyId = enemyId, receiver = receiver})
  end
  
bedca62d   zhouahaihai   冒险
1040
1041
1042
1043
  function Adv:backDead(enemyId)
  	self:pushBackEvent(AdvBackEventType.Dead, {enemyId = enemyId})
  end
  
ec87b4a5   zhouahaihai   冒险 完善
1044
  
b0fe1817   zhouahaihai   冒险分数
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
  function Adv:scoreChange(scoreType, pms)
  	local cutTypes = {}
  	local score = 0
  	cutTypes[AdvScoreType.Level] = function()
  		score = globalCsv.adv_score_floor
  	end
  	cutTypes[AdvScoreType.Kill] = function()
  		local chapterData = csvdb["adv_chapterCsv"][self.advInfo.chapter]
  		score = globalCsv.adv_score_monster[pms] * chapterData["monRatio"]
  	end
  	cutTypes[AdvScoreType.Item] = function()
  		score = csvdb["itemCsv"][pms[1]].adv_score_item * pms[2]
  	end
  	cutTypes[AdvScoreType.Hurt] = function()
  		score = globalCsv.adv_score_hurt * pms
  	end
  	cutTypes[AdvScoreType.Block] = function()
  		score = globalCsv.adv_score_block
  	end
  	if cutTypes[scoreType] then
  		cutTypes[scoreType]()
  	else
  		return
  	end
  	self.advInfo.score[scoreType] = self.advInfo.score[scoreType] or 0
  	self.advInfo.score[scoreType] = self.advInfo.score[scoreType] + score
  end
  
  function Adv:getScore()
e10edb5f   zhouahaihai   冒险事件新
1074
1075
1076
1077
1078
1079
1080
1081
  	self.advInfo.score[AdvScoreType.Level] = math.floor(self.advInfo.score[AdvScoreType.Level] or 0)
  	self.advInfo.score[AdvScoreType.Block] = math.floor(self.advInfo.score[AdvScoreType.Block] or 0)
  	self.advInfo.score[AdvScoreType.Hurt] = math.max(math.floor(self.advInfo.score[AdvScoreType.Hurt] or 0),  - (self.advInfo.score[AdvScoreType.Level] + self.advInfo.score[AdvScoreType.Block]))
  	self.advInfo.score[AdvScoreType.Kill] = math.floor(self.advInfo.score[AdvScoreType.Kill] or 0)
  	self.advInfo.score[AdvScoreType.Item] = math.floor(self.advInfo.score[AdvScoreType.Item] or 0)
  
  	return self.advInfo.score[AdvScoreType.Level] + self.advInfo.score[AdvScoreType.Block] + self.advInfo.score[AdvScoreType.Hurt]
  		+ self.advInfo.score[AdvScoreType.Kill] + self.advInfo.score[AdvScoreType.Item]
b0fe1817   zhouahaihai   冒险分数
1082
1083
  end
  
46fac6f1   zhouahaihai   酱料
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
  function Adv:popBackEvents()
  	local events = self.backEvents
  	self.backEvents = {}
  	return events
  end
  
  --回合事件处理
  function Adv:afterRound()
  	if self.battle then
  		self.battle:afterRound()
  	end
  end
  
36c30c5c   zhouahaihai   冒险
1097
1098
1099
1100
1101
1102
1103
  function Adv:saveDB()
  	if self.battle then
  		self.battle:getDB()
  	end
  	self.owner:updateProperties({advInfo = self.advInfo, advTeam = self.advTeam})
  end
  
46fac6f1   zhouahaihai   酱料
1104
  return Adv