Blame view

src/adv/AdvBattle.lua 16.5 KB
26aeaf48   zhouhaihai   bug
1
  local Player, Enemy, Build = table.unpack(require "adv.AdvPlayer")
46fac6f1   zhouahaihai   酱料
2
  local Buff = require "adv.AdvBuff"
32bca13b   zhouahaihai   bug
3
  local Passive = require "adv.AdvPassive"
36c30c5c   zhouahaihai   冒险
4
  local Battle = class("Battle")
46fac6f1   zhouahaihai   酱料
5
6
7
  function Battle:ctor(adv)
  	self.adv = adv
  	self.player = nil --玩家
02c4de8d   zhouahaihai   增加 固有技
8
  	self.isNewPlayer = false
46fac6f1   zhouahaihai   酱料
9
  	self.enemys = {} --怪
9687f887   zhouhaihai   建筑被动
10
  	self.builds = {} -- 建筑
a80fee7c   zhouhaihai   光环
11
  	self.auras = {} -- 光环
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
12
  	self.cachePassiveEvent = {}
46fac6f1   zhouahaihai   酱料
13
14
15
  	self:initPlayer()
  	self:initEnemys()
  	self:initAfter()
02c4de8d   zhouahaihai   增加 固有技
16
17
  	if self.isNewPlayer then
  		self.player:triggerPassive(Passive.BORN_ONCE)
02c4de8d   zhouahaihai   增加 固有技
18
  	end
46fac6f1   zhouahaihai   酱料
19
20
  end
  
78dcacb6   zhouhaihai   夹层 后处理 没做
21
22
23
24
  function Battle:initAfter(mapIdx)
  	if not mapIdx then
  		self.player:initAfter(self.adv.owner:getProperty("advTeam").player)
  	end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
25
  	for idx, mapEnemys in pairs(self.enemys) do
78dcacb6   zhouhaihai   夹层 后处理 没做
26
27
28
29
  		if not mapIdx or idx == mapIdx then
  			for _, enemy in ipairs(mapEnemys) do
  				enemy:initAfter(self.adv:getBlock(enemy.roomId, enemy.blockId, idx).event.enemy)
  			end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
30
  		end
9687f887   zhouhaihai   建筑被动
31
32
  	end	
  	for idx, mapBuilds in pairs(self.builds) do
78dcacb6   zhouhaihai   夹层 后处理 没做
33
34
35
36
  		if not mapIdx or idx == mapIdx then
  			for _, build in ipairs(mapBuilds) do
  				build:initAfter(self.adv:getBlock(build.roomId, build.blockId, idx).event.build)
  			end
9687f887   zhouhaihai   建筑被动
37
  		end
46fac6f1   zhouahaihai   酱料
38
  	end
46fac6f1   zhouahaihai   酱料
39
  end
b53593b5   zhouhaihai   羁绊加成
40
41
42
43
44
45
46
47
48
  --[[
  队伍总属性 = 基础属性 + 等级 × 成长率 	
  	基础属性:	固定属性,与章节、队伍够成、养成无关,由策划给出	
  	等级:	根据进入时的关卡,获得一个【初始等级】;消灭怪物获得经验后,累计N点会提升等级	
  	羁绊加成:	加成条件与“战斗”相同,加成目标改为【冒险队】	
  			
  	成长率:	由【队伍总生存力】决定	
  			成长率 =(总生存力 / 80^0.52 + INT(总角色等级 / 50* 1
  --]]
46fac6f1   zhouahaihai   酱料
49
  
6b5c9206   zhouhaihai   冒险资助升级属性奖励
50
51
52
53
54
55
56
57
58
59
60
61
  local function getAdvLvAttrUp(upAttrs, attrName, baseAttr)
  	-- 1=冒险队属性;1=点数/百分比=属性枚举=参数;属性枚举(1=生命上限/2=魔法上限/3=攻击/4=防御);点数/百分比(0=点数/1=百分比)
  	local Enem = {
  		hp = 1,
  		sp = 2,
  		atk = 3,
  		def = 4,
  	}
  	if not Enem[attrName] then return baseAttr end
  	return baseAttr + (upAttrs[Enem[attrName]] or 0)
  end
  
46fac6f1   zhouahaihai   酱料
62
  function Battle:initPlayer()
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
63
  	local advTeam = self.adv.owner:getProperty("advTeam")
3ecbe553   zhouhaihai   没有编队
64
  	if not advTeam.heros or not next(advTeam.heros) then return end
bfd33de5   zhouhaihai   队长技
65
  	local leaderPassive = {}
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
66
67
  	local player = advTeam.player
  	if not player then
565b0ad0   zhouhaihai   bug
68
  		local advAddAttrs = self.adv.owner:getAdvLvAddAttrs()
6b5c9206   zhouhaihai   冒险资助升级属性奖励
69
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
70
  		player = {}
a95b35ce   zhouhaihai   删除等级
71
72
73
74
75
76
77
78
  		-- player.level = 1
  		-- if self.adv.level ~= 1 then
  		-- 	local relayData = self.adv:isHaveRelay()
  		-- 	if relayData then
  		-- 		player.level = relayData.level
  		-- 	end
  		-- end
  		-- player.exp = 0
6b5c9206   zhouhaihai   冒险资助升级属性奖励
79
  		player.sp = getAdvLvAttrUp(advAddAttrs, "sp", 100)
9fe9f3d1   zhouhaihai   sp 加上限
80
  		player.spMax = player.sp
a95b35ce   zhouhaihai   删除等级
81
  		-- player.growth = {}
46fac6f1   zhouahaihai   酱料
82
  		player.passives = {}
ccbafe67   zhouhaihai   冒险神器和buff
83
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
84
  		for slot, heroId in pairs(advTeam.heros) do
bfd33de5   zhouhaihai   队长技
85
86
87
88
89
90
91
  			if heroId == advTeam.leader or heroId == advTeam.leader2 then
  				local hero = self.adv.owner.heros[heroId]
  				if hero then
  					local unit = csvdb["unitCsv"][self.adv.owner.heros[heroId]:getProperty("type")]
  					if unit.advCaptain ~= 0 then
  						table.insert(player.passives, {id = unit.advCaptain, level = 1})
  					end
46fac6f1   zhouahaihai   酱料
92
93
94
  				end
  			end
  		end
ccbafe67   zhouhaihai   冒险神器和buff
95
96
  
  		local attrs = self.adv.owner:getTeamBattleInfo(advTeam).heros
6b5c9206   zhouhaihai   冒险资助升级属性奖励
97
98
  
  
ccbafe67   zhouhaihai   冒险神器和buff
99
100
101
  		for attrName, _ in pairs(AdvAttsEnum) do
  			for _, hero in pairs(attrs) do
  				player[attrName] = (player[attrName] or 0) + hero[attrName]
b53593b5   zhouhaihai   羁绊加成
102
  			end
6dc482bb   zhouhaihai   中继层完成, 新增两个冒险物品使用效果
103
  			player[attrName] = getAdvLvAttrUp(advAddAttrs, attrName, player[attrName]) * (globalCsv.adv_battle_attr_ratio[attrName] or 1)
a95b35ce   zhouhaihai   删除等级
104
105
  			-- player.growth[attrName] = player[attrName] * (globalCsv.adv_battle_attr_growth_ratio[attrName] or 1)
  			-- player[attrName] = player[attrName] + player.growth[attrName] * (player.level - 1)
b53593b5   zhouhaihai   羁绊加成
106
  		end
ccbafe67   zhouhaihai   冒险神器和buff
107
  
1b35c0a2   zhouhaihai   冒险
108
  		player.hpMax = player.hp or 0
02c4de8d   zhouahaihai   增加 固有技
109
  		self.isNewPlayer = true
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
110
  		advTeam.player = player
46fac6f1   zhouahaihai   酱料
111
  	end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
112
  	self.player = Player.new(self, player)
46fac6f1   zhouahaihai   酱料
113
114
115
  end
  
  function Battle:initEnemys()
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
116
117
118
119
120
  	for idx, map in pairs(self.adv.maps) do
  		self:initMapEnemys(idx)
  	end
  end
  
78dcacb6   zhouhaihai   夹层 后处理 没做
121
122
  -- after 是否是 后创建的夹层
  function Battle:initMapEnemys(mapIdx, after)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
123
  	self.enemys[mapIdx] = {}
50fddc3f   zhouhaihai   bug
124
  	self.builds[mapIdx] = {}
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
125
126
127
128
  	local map = self.adv.maps[mapIdx]
  	if map then
  		for _, room in pairs(map.rooms) do
  			for _, block in pairs(room.blocks) do
7b2dc17c   zhouhaihai   地图 层 buff passive
129
  				self:addEnemy(room, block, mapIdx, true)	
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
130
131
132
  			end
  		end
  	end
78dcacb6   zhouhaihai   夹层 后处理 没做
133
134
135
  	if after then
  		self:initAfter(mapIdx)
  	end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
136
137
138
139
140
  	if self.cachePassiveEvent[mapIdx] then
  		for _, passiveC in ipairs(self.cachePassiveEvent or {}) do
  			for _, enemy in ipairs(self.enemys[mapIdx]) do
  				enemy:triggerPassive(passiveC[1], passiveC[2])
  			end
9687f887   zhouhaihai   建筑被动
141
142
143
144
  
  			for _, build in ipairs(self.builds[mapIdx]) do
  				build:triggerPassive(passiveC[1], passiveC[2])
  			end
46fac6f1   zhouahaihai   酱料
145
146
  		end
  	end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
147
  	self.cachePassiveEvent[mapIdx] = nil
46fac6f1   zhouahaihai   酱料
148
149
  end
  
7b2dc17c   zhouhaihai   地图 层 buff passive
150
  function Battle:addEnemy(room, block, mapIdx, init)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
151
152
  	mapIdx = mapIdx or self.adv:getCurMapIdx()
  
7b2dc17c   zhouhaihai   地图 层 buff passive
153
  	local isNew, player, data
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
154
  	if block:isMonster() then
46fac6f1   zhouahaihai   酱料
155
156
157
  		if not block.event.enemy then
  			local enemyCsv = csvdb["event_monsterCsv"][block.event.id]
  			local enemy = {}
eee37c88   zhouhaihai   楼层数据
158
159
160
161
  			local curFloorData = self.adv:getCurFloorData() or {}
  			for attrName, _ in pairs(AdvAttsEnum) do
  				enemy[attrName] = enemyCsv[attrName] * curFloorData[attrName]
  			end
46fac6f1   zhouahaihai   酱料
162
  			enemy.passives = {}
de3b786f   zhouhaihai   字段换名字
163
  			for _, id in ipairs(enemyCsv.mapPassive:toArray(true, "=")) do
46fac6f1   zhouahaihai   酱料
164
165
166
  				table.insert(enemy.passives, {id = id})
  			end
  			block.event.enemy = enemy
7b2dc17c   zhouhaihai   地图 层 buff passive
167
  			isNew = true
46fac6f1   zhouahaihai   酱料
168
  		end
a0834e49   zhouhaihai   增加潜行 功能
169
170
171
172
  		if not block.event.mId then
  			block.event.mId = self.adv.lastEnemyId
  			self.adv.lastEnemyId = self.adv.lastEnemyId + 1
  		end
7b2dc17c   zhouhaihai   地图 层 buff passive
173
174
  		data = block.event.enemy
  		player = Enemy.new(self, block.event.mId, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.enemy, mapIdx)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
175
  		table.insert(self.enemys[mapIdx], player)
9687f887   zhouhaihai   建筑被动
176
177
  	elseif block:isBuild() then
  		if not block.event.build then
53b7e3b5   zhouhaihai   bug
178
  			local buildCsv = csvdb["event_buildingCsv"][block.event.id]
9687f887   zhouhaihai   建筑被动
179
180
181
182
183
184
  			local build = {}
  			build.passives = {}
  			for _, id in ipairs(buildCsv.passive:toArray(true, "=")) do
  				table.insert(build.passives, {id = id})
  			end
  			block.event.build = build
7b2dc17c   zhouhaihai   地图 层 buff passive
185
  			isNew = true
9687f887   zhouhaihai   建筑被动
186
  		end
7b2dc17c   zhouhaihai   地图 层 buff passive
187
188
  		data = block.event.build
  		player = Build.new(self, block.event.id, room.roomId, block.blockId, not block.isOpen, block.event.build, mapIdx)
9687f887   zhouhaihai   建筑被动
189
  		table.insert(self.builds[mapIdx], player)
46fac6f1   zhouahaihai   酱料
190
  	end 
7b2dc17c   zhouhaihai   地图 层 buff passive
191
192
193
194
195
196
197
198
199
200
201
  	if not init then
  		player:initAfter(data)
  
  		-- 游戏中新创建的 加上地图 floor 效果
  		if isNew then
  			local passives, buffs = self:getMapEffect(2, true, mapIdx)
  			for _, passive in ipairs(passives) do
  				player:addPassive({id = passive})
  			end
  
  			for _, buff in ipairs(buffs) do
a80fee7c   zhouhaihai   光环
202
  				player:addBuff(buff)
7b2dc17c   zhouhaihai   地图 层 buff passive
203
  			end
a80fee7c   zhouhaihai   光环
204
205
  			-- 新生成的怪 加上 已有的光环buff
  			player:checkAuraBuff(self:checkDiffAuraBuff({}, self:getAurasByMap()))
7b2dc17c   zhouhaihai   地图 层 buff passive
206
207
208
  		end
  	end
  	return player
46fac6f1   zhouahaihai   酱料
209
210
  end
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
211
212
213
  function Battle:getEnemy(roomId, blockId, mapIdx)
  	mapIdx = mapIdx or self.adv:getCurMapIdx()
  	for _, enemy in ipairs(self.enemys[mapIdx] or {}) do
36c30c5c   zhouahaihai   冒险
214
  		if enemy.roomId == roomId and enemy.blockId == blockId then
46fac6f1   zhouahaihai   酱料
215
216
217
218
219
  			return enemy
  		end
  	end
  end
  
9687f887   zhouhaihai   建筑被动
220
221
222
223
224
225
226
  function Battle:getBuild(roomId, blockId, mapIdx)
  	mapIdx = mapIdx or self.adv:getCurMapIdx()
  	for _, build in ipairs(self.builds[mapIdx] or {}) do
  		if build.roomId == roomId and build.blockId == blockId then
  			return build
  		end
  	end
d4720dfd   zhouhaihai   bug
227
  end
9687f887   zhouhaihai   建筑被动
228
  
46fac6f1   zhouahaihai   酱料
229
  function Battle:getEnemyById(id)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
230
231
232
233
234
  	for idx, mapEnemys in pairs(self.enemys) do
  		for _, enemy in ipairs(mapEnemys) do
  			if enemy.id == id then
  				return enemy
  			end
46fac6f1   zhouahaihai   酱料
235
236
237
  		end
  	end
  end
39a6e08b   suhongyang   冒险战斗内逻辑调整
238
239
240
  
  function Battle:getRBByEnemyId(enemyId)
  	local enemy = self:getEnemyById(enemyId)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
241
  	return enemy.roomId, enemy.blockId, enemy.mapIdx
39a6e08b   suhongyang   冒险战斗内逻辑调整
242
243
  end
  
39a6e08b   suhongyang   冒险战斗内逻辑调整
244
  
46fac6f1   zhouahaihai   酱料
245
  --触发全员被动技能
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
246
247
  function Battle:triggerPassive(condType, params, mapIdx)
  	mapIdx = mapIdx or self.adv:getCurMapIdx()
02c4de8d   zhouahaihai   增加 固有技
248
  	self.player:triggerPassive(condType, params)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
249
250
251
252
253
254
255
256
  	if not self.enemys[mapIdx] then
  		-- 缓存一下
  		self.cachePassiveEvent[mapIdx] = self.cachePassiveEvent[mapIdx] or {}
  		table.insert(self.cachePassiveEvent[mapIdx], {condType, params})
  	else
  		for _, enemy in ipairs(self.enemys[mapIdx]) do
  			enemy:triggerPassive(condType, params)
  		end
9687f887   zhouhaihai   建筑被动
257
258
259
  		for _, build in ipairs(self.builds[mapIdx]) do
  			build:triggerPassive(condType, params)
  		end
02c4de8d   zhouahaihai   增加 固有技
260
  	end
46fac6f1   zhouahaihai   酱料
261
262
  end
  
4f0a5fae   zhouhaihai   营养剂
263
264
265
266
267
268
269
270
271
272
273
  -- 只是从战斗中移除  从地图中移除 在外面操作
  function Battle:removeEnemyById(id)
  	local mapIdx = self.adv:getCurMapIdx()
  	for i = #self.enemys[mapIdx], 1, -1 do
  		if self.enemys[mapIdx][i].id == id then
  			local enemy = table.remove(self.enemys[mapIdx], i)
  			enemy:clear()
  			break
  		end
  	end
  end
c8c957e4   zhouhaihai   必要时删除建筑
274
275
276
277
278
279
280
281
282
283
284
  -- 只是从战斗中移除  从地图中移除 在外面操作
  function Battle:removeBuildByPos(roomId, blockId)
  	local mapIdx = self.adv:getCurMapIdx()
  	for i = #self.builds[mapIdx], 1, -1 do
  		if self.builds[mapIdx][i].roomId == roomId and self.builds[mapIdx][i].blockId == blockId then
  			local build = table.remove(self.builds[mapIdx], i)
  			build:clear()
  			break
  		end
  	end
  end
4f0a5fae   zhouhaihai   营养剂
285
  
46fac6f1   zhouahaihai   酱料
286
287
  --回合
  function Battle:afterRound()
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
288
  	local mapIdx = self.adv:getCurMapIdx()
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
289
  
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
290
  	table.sort(self.enemys[mapIdx], function(e1, e2)
46fac6f1   zhouahaihai   酱料
291
292
  		return e1.id < e2.id
  	end)
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
293
  
8fc7d1bc   zhouhaihai   buff 回合问题
294
295
296
297
298
299
300
301
302
  
  	self.player:afterRound("buffBefore")
  	for _, enemy in ipairs(self.enemys[mapIdx]) do
  		enemy:afterRound("buffBefore")
  	end
  	for _, build in ipairs(self.builds[mapIdx]) do
  		build:afterRound("buffBefore")
  	end
  
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
303
  	self.player:afterRound("passive")
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
304
  	for _, enemy in ipairs(self.enemys[mapIdx]) do
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
305
  		enemy:afterRound("passive")
46fac6f1   zhouahaihai   酱料
306
  	end
a35f71ee   zhouhaihai   afterRound build
307
  	for _, build in ipairs(self.builds[mapIdx]) do
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
308
309
310
  		build:afterRound("passive")
  	end
  
8fc7d1bc   zhouhaihai   buff 回合问题
311
  	self.player:afterRound("buffAfter")
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
312
  	for _, enemy in ipairs(self.enemys[mapIdx]) do
8fc7d1bc   zhouhaihai   buff 回合问题
313
  		enemy:afterRound("buffAfter")
a35f71ee   zhouhaihai   afterRound build
314
  	end
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
315
  	for _, build in ipairs(self.builds[mapIdx]) do
8fc7d1bc   zhouhaihai   buff 回合问题
316
  		build:afterRound("buffAfter")
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
317
318
  	end
  
3ec5de90   zhouhaihai   光环 bug
319
320
321
  	self.player:triggerPassive(Passive.AFTER_ROUND)
  
  	self:checkAura()
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
322
  
3ec5de90   zhouhaihai   光环 bug
323
324
325
326
327
328
  	self:clearRound()
  
  	if self.player.isDead then
  		self.adv:over(false, nil, -2)
  	end
  end
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
329
  
3ec5de90   zhouhaihai   光环 bug
330
331
  function Battle:clearRound()
  	local mapIdx = self.adv:getCurMapIdx()
46fac6f1   zhouahaihai   酱料
332
  	self.player:clearRound()
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
333
  	for _, enemy in ipairs(self.enemys[mapIdx]) do
46fac6f1   zhouahaihai   酱料
334
335
  		enemy:clearRound()
  	end
9687f887   zhouhaihai   建筑被动
336
337
338
  	for _, build in ipairs(self.builds[mapIdx]) do
  		build:clearRound()
  	end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
339
340
  	for i = #self.enemys[mapIdx], 1, -1 do
  		if self.enemys[mapIdx][i].isDead then
4faef572   zhouhaihai   冒险任务,冒险扫荡, 冒险中继
341
  			local enemy = table.remove(self.enemys[mapIdx], i)
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
342
343
  			self.adv:enemyDead(enemy, enemy.isDead == 1)
  			enemy:clear()
46fac6f1   zhouahaihai   酱料
344
345
  		end
  	end
9687f887   zhouhaihai   建筑被动
346
347
348
  	for i = #self.builds[mapIdx], 1, -1 do
  		if self.builds[mapIdx][i].isDead then
  			local build = table.remove(self.builds[mapIdx], i)
22ef22a5   zhouhaihai   移除建筑
349
350
351
352
353
354
355
356
357
  			
  			local room = self.adv:getCurMap().rooms[build.roomId]
  			if room then
  				local block = room.blocks[build.blockId]
  				if block then
  					block:clear()
  					self.adv:backBlockChange(build.roomId, build.blockId)
  				end
  			end
9687f887   zhouhaihai   建筑被动
358
359
360
  			build:clear()
  		end
  	end
46fac6f1   zhouahaihai   酱料
361
362
  end
  
e459a5fc   suhongyang   战斗回合检查同步以及回合数据缓存
363
  
12f7b52c   zhouhaihai   冒险战斗
364
365
366
367
  function Battle:battleBegin(roomId, blockId, params)
  	local enemy = self:getEnemy(roomId, blockId)
  	if not enemy then return end
  	local player = params.player
92d7d6ac   zhouhaihai   加一些数据保护
368
  	if not player then return end
8cfb25d7   zhouhaihai   传递 敌人信息
369
  	local penemy = params.enemy or {hp = 0}
36875ec5   zhouhaihai   宝藏怪
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
  	if player.hp ~= 0 then
  		if penemy.hp <= 0 then
  			enemy:kill()
  			self.adv.owner:checkTaskEnter("AdvBattleWin", {id = self.adv.chapterId})
  		else
  			-- 处理一下怪物
  			if penemy.hp > enemy.hp then
  				enemy:recover(penemy.hp - enemy.hp)
  			else
  				enemy:hurt(math.max(0, math.ceil(enemy.hp - penemy.hp)), self.player, {hurtType = 5}) --战斗血量只会变少
  			end
  			if penemy.escape and penemy.escape == 0 then
  				enemy.isDead = 1
  			end
  		end
  	end
12f7b52c   zhouhaihai   冒险战斗
386
387
  	-- 玩家没死就是怪死了
  	if player.hp > 0 then
e90b4d20   zhouhaihai   战斗buff
388
  		self.player:effectBattleBuff()
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
389
390
391
  		if params.bySkill then
  			self.player:triggerPassive(Passive.SKILL_KILL)
  		end
12f7b52c   zhouhaihai   冒险战斗
392
  	end
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
393
  	if player.hp > self.player.hp then
36875ec5   zhouhaihai   宝藏怪
394
  		self.player:recover(player.hp - self.player.hp)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
395
396
397
398
399
  	else
  		self.player:hurt(math.max(0, math.ceil(self.player.hp - player.hp)), enemy, {hurtType = 5}) --战斗血量只会变少
  	end
  	
  	self.player:changeSp(math.floor(player.sp - self.player.sp) , 0) --战斗魔力只会变少
12f7b52c   zhouhaihai   冒险战斗
400
401
402
  end
  
  
7b2dc17c   zhouhaihai   地图 层 buff passive
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
  function Battle:getMapEffect(ctype, ilayer, mapIdx)
  	mapIdx = mapIdx or self.adv:getCurMapIdx()
  	local mapData = self.adv.maps[mapIdx]:getMapInfoCsv() or {}
  	local floorData = self.adv:getCurFloorData() or {}
  
  	local passives = {}
  	local buffs = {}
  
  	for _type, temp in ipairs({mapData, floorData}) do
  		for _, one in ipairs((temp.passive or ""):toTableArray(true)) do
  			passives[one[1]] = passives[one[1]] or {}
  			if ilayer and one[1] == 1 and _type == 2 then
  			else
  				table.insert(passives[one[1]], one[2])
  			end
  		end
  		for _, one in ipairs((temp.buff or ""):toTableArray(true)) do
  			buffs[one[1]] = buffs[one[1]] or {}
  			if ilayer and one[1] == 1 and _type == 2 then
  			else
  				table.insert(buffs[one[1]], one[2])
  			end
  		end
  	end
  	if ctype then
  		passives = passives[ctype] or {}
  		buffs = buffs[ctype] or {}
  	end
  	return passives, buffs
  end
  -- 夹层玩家 不重复加 floor
  function Battle:initMapEffect(ilayer)
  	local passives, buffs = self:getMapEffect(nil, ilayer)
  	local mapIdx = self.adv:getCurMapIdx()
  
  	for _, passive in ipairs(passives[1] or {}) do
  		self.player:addPassive({id = passive})
  	end
  
  	for _, passive in ipairs(passives[2] or {}) do
  		for _, enemy in ipairs(self.enemys[mapIdx]) do
  			enemy:addPassive({id = passive})
  		end
  	end
  
  	for _, buff in ipairs(buffs[1] or {}) do
6838209b   zhouhaihai   增加buff
449
  		self.player:addBuff(buff)
7b2dc17c   zhouhaihai   地图 层 buff passive
450
451
452
453
454
455
456
457
458
459
  	end
  
  	for _, buff in ipairs(buffs[2] or {}) do
  		for _, enemy in ipairs(self.enemys[mapIdx]) do
  			enemy:addBuff(buff)
  		end
  	end
  end
  
  
a80fee7c   zhouhaihai   光环
460
461
462
463
464
465
  -- 夹层 进入退出 接口 清理玩家身上的老光环 添加新的光环
  function Battle:iLayerChange(oldMapIdx)
  	local auras = self:getActiveAuras()
  	local playerBuffs = self:checkDiffAuraBuff(self:getAurasByMap(oldMapIdx), auras)
  	local enemyBuffs = self:checkDiffAuraBuff(self:getAurasByMap(), auras)
  	self.player:checkAuraBuff(playerBuffs)
9b59590a   zhouhaihai   全部有的怪都处理
466
  	for _, enemy in ipairs(self.enemys[self.adv:getCurMapIdx()]) do
a80fee7c   zhouhaihai   光环
467
468
469
  		enemy:checkAuraBuff(enemyBuffs)
  	end
  	self:setMapAuras(auras)
3ec5de90   zhouhaihai   光环 bug
470
  	self:clearRound()
a80fee7c   zhouhaihai   光环
471
472
473
474
475
476
  end
  
  -- 新的 关卡 关闭旧的战斗模块 清理 玩家身上的光环效果
  function Battle:overBattle()
  	local buffs = self:checkDiffAuraBuff(self:getAurasByMap(), {})
  	self.player:checkAuraBuff(buffs)
3ec5de90   zhouhaihai   光环 bug
477
  	self:clearRound()
a80fee7c   zhouhaihai   光环
478
479
480
481
482
483
484
  	self.adv.owner:getProperty("advTeam").player = self.player:getDB()  -- 临时缓存住 battle 的player
  end
  
  -- 初始化 新的 关卡
  function Battle:newBattle()
  	local auras = self:getActiveAuras()
  	local buffs = self:checkDiffAuraBuff({}, auras)
3ec5de90   zhouhaihai   光环 bug
485
  	self.player:checkAuraBuff(buffs)
9b59590a   zhouhaihai   全部有的怪都处理
486
  	for _, enemy in ipairs(self.enemys[self.adv:getCurMapIdx()]) do
3ec5de90   zhouhaihai   光环 bug
487
488
  		enemy:checkAuraBuff(buffs)
  	end
a80fee7c   zhouhaihai   光环
489
490
491
  	self:setMapAuras(auras)
  end
  
400f1f91   zhouhaihai   auras
492
493
494
495
  function Battle:loadBattle(info)
  	self.auras = info.auras or {}
  end
  
a80fee7c   zhouhaihai   光环
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
  -- 过了回合 检查光环
  function Battle:checkAura()
  	local auras = self:getActiveAuras()
  	local buffs = self:checkDiffAuraBuff(self:getAurasByMap(), auras)
  	self.player:checkAuraBuff(buffs)
  	for _, enemy in pairs(self.player:getTeam(2)) do
  		enemy:checkAuraBuff(buffs)
  	end
  	self:setMapAuras(auras)
  end
  
  -- 查找差异buff
  function Battle:checkDiffAuraBuff(oldAuras, newAuras)
  	local auras = {}
  	for aurasId , count in pairs(oldAuras) do
  		auras[aurasId] = -count
  	end
  	for aurasId , count in pairs(newAuras) do
  		auras[aurasId] = (auras[aurasId] or 0) + count
  	end
3ec5de90   zhouhaihai   光环 bug
516
  
a80fee7c   zhouhaihai   光环
517
518
519
520
521
522
523
524
525
526
527
528
529
530
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
  	local buffs = {}
  	for aurasId , count in pairs(auras) do
  		local auraData = csvdb["adv_map_haloCsv"][aurasId]
  		if auraData then
  			for _, effect in ipairs(auraData.effect:toTableArray(true)) do
  				temp = buffs
  				for i = 1, #effect do
  					temp[effect[i]] = temp[effect[i]] or {}
  					temp = temp[effect[i]]
  				end
  				temp.count = (temp.count or 0) + count
  				if newAuras[aurasId] then
  					-- 加上 未消失标记
  					temp.exist = true
  				end
  			end
  		end
  	end
  	return buffs
  end
  
  -- 获取所有生效的 光环
  function Battle:getActiveAuras()
  	local auras = {}
  	for _, one in pairs(self.player:getAuras()) do
  		auras[one] = (auras[one] or 0) + 1
  	end
  	for _, enemy in pairs(self.player:getTeam(2)) do
  		for _, one in pairs(enemy:getAuras()) do
  			auras[one] = (auras[one] or 0) + 1
  		end
  	end
  	for _, build in pairs(self:getBuilds()) do
  		for _, one in pairs(build:getAuras()) do
  			auras[one] = (auras[one] or 0) + 1
  		end
  	end
  	return auras
  end
  
  function Battle:setMapAuras(auras)
  	 self.auras[self.adv:getCurMapIdx()] = auras
  end
  
  function Battle:getAurasByMap(mapIdx)
  	mapIdx = mapIdx or self.adv:getCurMapIdx()
  	local auras = self.auras[mapIdx] or {}
  	return auras
  end
  
  function Battle:getBuilds()
  	local team = {}
  	for _, build in pairs(self.builds[self.adv:getCurMapIdx()]) do
  		if not build.isDead and not build.lock then -- 已经翻开的
  			table.insert(team, build)
  		end
  	end
  	return team
  end
  
  
46fac6f1   zhouahaihai   酱料
578
  --写入数据
a80fee7c   zhouhaihai   光环
579
  function Battle:saveDB(advInfo)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
580
581
582
583
584
585
586
  	for idx, mapEnemys in pairs(self.enemys) do
  		for _, enemy in ipairs(mapEnemys) do
  			local block = self.adv:getBlock(enemy.roomId, enemy.blockId, idx)
  			if block and block:isMonster() then
  				block.event.enemy = enemy:getDB()
  			end
  		end
46fac6f1   zhouahaihai   酱料
587
  	end
6d2df562   zhouhaihai   保存建筑信息
588
589
590
591
592
593
594
595
  	for idx, mapBuilds in pairs(self.builds) do
  		for _, build in ipairs(mapBuilds) do
  			local block = self.adv:getBlock(build.roomId, build.blockId, idx)
  			if block and block:isBuild() then
  				block.event.build = build:getDB()
  			end
  		end
  	end
a80fee7c   zhouhaihai   光环
596
  	advInfo.auras = self.auras
46fac6f1   zhouahaihai   酱料
597
598
  end
  
36c30c5c   zhouahaihai   冒险
599
  return Battle