Blame view

src/adv/AdvPlayer.lua 20.5 KB
46fac6f1   zhouahaihai   酱料
1
2
  -- 角色
  local Buff = require "adv.AdvBuff"
1b8336a6   suhongyang   skill逻辑与player分开
3
  local Skill = require "adv.AdvSkill"
46fac6f1   zhouahaihai   酱料
4
5
6
7
8
9
10
11
  local Passive = require "adv.AdvPassive"
  
  local BaseObject = class("BaseObject")
  function BaseObject:ctor(battle)
  	self.battle = battle
  	self.hpMax = 0
  	self.hp = 0
  	self.atk = 0
e996b82a   zhouahaihai   冒险增加防御属性
12
  	self.def = 0
46fac6f1   zhouahaihai   酱料
13
14
15
16
  	self.aType = 0 --攻击类型
  	self.lock = nil
  	self.passives = {} --固有技能
  	self.buffs = {} --buff
42f2d1d3   suhongyang   战斗内技能序列逻辑
17
  	self.skillOrder = {} --战斗内技能序列
46fac6f1   zhouahaihai   酱料
18
  	self.isDead = false
46fac6f1   zhouahaihai   酱料
19
20
21
22
23
  end
  --初始化角色
  function BaseObject:initData(data)
  	self.hpMax = data.hpMax or data.hp
  	self.hp = data.hp
46fac6f1   zhouahaihai   酱料
24
25
26
27
  	--可变化的值
  	self.atk = data.atk
  	self.miss = data.miss
  	self.hit = data.hit
e996b82a   zhouahaihai   冒险增加防御属性
28
  	self.def = data.def
46fac6f1   zhouahaihai   酱料
29
30
31
32
  	--基础值记录
  	self._atk = data._atk or self.atk
  	self._miss = data._miss or self.miss
  	self._hit = data._hit or self.hit
e996b82a   zhouahaihai   冒险增加防御属性
33
  	self._def = data._def or self.def
ccbafe67   zhouhaihai   冒险神器和buff
34
  	self._hpMax = data._hpMax or self.hpMax
46fac6f1   zhouahaihai   酱料
35
36
37
38
  end
  -- 角色初始化完以后才是 技能和被动技能  方便初始化 buff 的 释放对象
  function BaseObject:initAfter(data)
  	for _, passive in ipairs(data.passives or {}) do
36c30c5c   zhouahaihai   冒险
39
  		table.insert(self.passives, Passive.new(self, passive))
46fac6f1   zhouahaihai   酱料
40
41
42
43
44
45
  	end
  	for _, buff in ipairs(data.buffs or {}) do
  		table.insert(self.buffs, Buff.load(self, buff))
  	end
  end
  
a734980c   suhongyang   冒险战斗数据打完以前不存储
46
47
48
49
50
51
52
  function BaseObject:reset(data)
  	self.passives = {}
  	self.buffs = {}
  	self:initData(data)
  	self:initAfter(data)
  end
  
35e2e3c4   zhouhaihai   优化 gm advt 增加感知b...
53
54
55
56
57
58
59
60
61
  function BaseObject:afterRound(roundType)
  	if roundType == "passive" then
  		for _, passive in ipairs(self.passives) do
  			passive:afterRound(self)
  		end
  	elseif roundType == "buff" then
  		for _, buff in ipairs(self.buffs) do
  			buff:afterRound()
  		end
46fac6f1   zhouahaihai   酱料
62
63
64
  	end
  end
  
46fac6f1   zhouahaihai   酱料
65
66
67
  function BaseObject:clearRound()
  	for i = #self.passives, 1, -1 do
  		if self.passives[i].isDel then
46fac6f1   zhouahaihai   酱料
68
69
70
71
72
  			table.remove(self.passives, i)
  		end
  	end
  	for i = #self.buffs, 1, -1 do
  		if self.buffs[i].isDel then
b71a8190   zhouhaihai   动态改变 一些buff
73
  			local buff = self.buffs[i]
46fac6f1   zhouahaihai   酱料
74
  			table.remove(self.buffs, i)
b71a8190   zhouhaihai   动态改变 一些buff
75
76
77
78
  			buff:endBuff()
  			if self.attrChangeCondBuffCheck then
  				self:attrChangeCondBuffCheck(2, buff.id)
  			end
46fac6f1   zhouahaihai   酱料
79
80
81
82
83
84
85
86
  		end
  	end
  end
  function BaseObject:clear()
  	self.buffs = {}
  	self.passives = {}
  end
  
23a38f47   suhongyang   new passives effect
87
88
  function BaseObject:addPassive(params)
  	local skillId = params.id
3b0526d2   zhouhaihai   冒险demo
89
  	local skillData = csvdb["adv_map_passiveCsv"][skillId]
23a38f47   suhongyang   new passives effect
90
91
92
  	if not skillData then return end
  	local level = params.level or 1
  	if not skillData[level] then return end
7b2dc17c   zhouhaihai   地图 层 buff passive
93
94
95
  
  	if self:getPassiveById(skillId) then return end -- 被动技不能重复
  
23a38f47   suhongyang   new passives effect
96
  	table.insert(self.passives, Passive.new(self, { id = skillId, level = level }))
23a38f47   suhongyang   new passives effect
97
98
  end
  
7b2dc17c   zhouhaihai   地图 层 buff passive
99
100
101
102
103
104
105
106
  function BaseObject:getPassiveById(bId)
  	for idx, passive in ipairs(self.passives) do
  		if passive.id == bId then
  			return passive
  		end
  	end
  end
  
4f0a5fae   zhouhaihai   营养剂
107
108
109
110
111
112
  function BaseObject:getPassiveIdx(passive)
  	for idx, passive_ in ipairs(self.passives) do
  		if passive_ == passive then
  			return idx
  		end
  	end
c2e42a2d   zhouhaihai   避免删除
113
  	return 999
4f0a5fae   zhouhaihai   营养剂
114
115
116
  end
  
  function BaseObject:getDisablePassiveCount()
06245e45   zhouhaihai   bug 被动技
117
  	local count, bc = 0, 0
4f0a5fae   zhouhaihai   营养剂
118
119
120
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and buff:getType() == Buff.DISABLE_BUFF then
  			count = count + buff:effect()
06245e45   zhouhaihai   bug 被动技
121
  			bc = bc + 1
4f0a5fae   zhouhaihai   营养剂
122
123
  		end
  	end
06245e45   zhouhaihai   bug 被动技
124
  	return count, bc
4f0a5fae   zhouhaihai   营养剂
125
126
  end
  
46fac6f1   zhouahaihai   酱料
127
  function BaseObject:addBuff(buffId, releaser)
3b0526d2   zhouhaihai   冒险demo
128
  	local buffData = csvdb["adv_map_buffCsv"][buffId]
46fac6f1   zhouahaihai   酱料
129
130
  	if not buffData then return end
  	for _, buff in ipairs(self.buffs) do
7c55db1f   suhongyang   Buff逻辑完善,buff生效次数...
131
  		if not buff.isDel and (buff:getType() == Buff.CLEAR_BUFF or buff:getType() == Buff.IMMNUE_BUFF) then
ccbafe67   zhouhaihai   冒险神器和buff
132
  			if buff:canEffect(buffId) then
7c55db1f   suhongyang   Buff逻辑完善,buff生效次数...
133
  				buff:effect()
46fac6f1   zhouahaihai   酱料
134
135
136
137
  				return
  			end
  		end
  	end
ccbafe67   zhouhaihai   冒险神器和buff
138
139
140
141
142
143
144
145
146
  	local oldBuff = self:getBuffById(buffId)
  	if oldBuff then
  		if not oldBuff:checkKeep() then return end
  		oldBuff:overlay(releaser, {}) -- 叠加
  	else
  		-- 不能保持的buff 也加不上去
  		if not Buff.checkKeep({
  			owner = self,
  			buffData = buffData,
8781e103   zhouhaihai   冒险 bug
147
  			releaseId = releaser and releaser.monsterId or nil
ccbafe67   zhouhaihai   冒险神器和buff
148
  		}) then return end
b71a8190   zhouhaihai   动态改变 一些buff
149
150
151
  		local buff = Buff.create(self, releaser, {id = buffId})
  		table.insert(self.buffs, buff)
  		buff:createAfter()
ccbafe67   zhouhaihai   冒险神器和buff
152
  	end
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
153
  	self:triggerPassive(Passive.GET_BUFF, {buffId = buffId})
c5d9338f   zhouhaihai   通用方法 异常
154
  	return true
46fac6f1   zhouahaihai   酱料
155
156
  end
  
ccbafe67   zhouhaihai   冒险神器和buff
157
158
159
160
161
162
163
164
  function BaseObject:getBuffById(bId)
  	for idx, buff in ipairs(self.buffs) do
  		if buff.id == bId then
  			return buff
  		end
  	end
  end
  
916096ed   zhouhaihai   神器效果
165
  function BaseObject:delBuffById(bId)
ccbafe67   zhouhaihai   冒险神器和buff
166
167
  	for idx, buff in ipairs(self.buffs) do
  		if buff.id == bId then
ccbafe67   zhouhaihai   冒险神器和buff
168
  			table.remove(self.buffs, idx)
b71a8190   zhouhaihai   动态改变 一些buff
169
170
171
172
  			buff:endBuff()
  			if self.attrChangeCondBuffCheck then
  				self:attrChangeCondBuffCheck(2, bId)
  			end
916096ed   zhouhaihai   神器效果
173
174
175
176
177
178
  			return buff
  		end
  	end
  end
  
  function BaseObject:delPassiveById(pId)
ccbafe67   zhouhaihai   冒险神器和buff
179
180
  	for idx, passive in ipairs(self.passives) do
  		if passive.id == pId then
ccbafe67   zhouhaihai   冒险神器和buff
181
  			table.remove(self.passives, idx)
916096ed   zhouhaihai   神器效果
182
183
184
185
186
  			return passive
  		end
  	end
  end
  
46fac6f1   zhouahaihai   酱料
187
188
189
  function BaseObject:hadBuff(bType)
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and buff:getType() == bType then
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
190
  			return buff
46fac6f1   zhouahaihai   酱料
191
192
193
194
  		end
  	end
  end
  
1cb78a24   suhongyang   passive的筛选
195
196
197
  function BaseObject:hadBuffById(bId)
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and buff.id == bId then
7828ffd0   zhouhaihai   冒险 连续选择点 和 地图因子
198
  			return buff
1cb78a24   suhongyang   passive的筛选
199
200
201
202
  		end
  	end
  end
  
916096ed   zhouhaihai   神器效果
203
  
46fac6f1   zhouahaihai   酱料
204
  -- 通用的buff 效果汇总  -- 0 固定 1百分比  两种分类
ccbafe67   zhouhaihai   冒险神器和buff
205
  function BaseObject:getCommonBuffEffect(bType, otherCond)
46fac6f1   zhouahaihai   酱料
206
207
208
  	local effect, count = {[0] = 0, [1] = 0}, 0
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and buff:getType() == bType then
ccbafe67   zhouhaihai   冒险神器和buff
209
210
  			local cType, value, cond = buff:effect()
  			if cType and (not otherCond or otherCond == cond) then
4ae223df   zhouahaihai   Buff bug
211
  				effect[cType] = effect[cType] + value
46fac6f1   zhouahaihai   酱料
212
213
214
215
  				count = count + 1
  			end
  		end
  	end
4ae223df   zhouahaihai   Buff bug
216
  	effect[1] = effect[1] / 100
46fac6f1   zhouahaihai   酱料
217
218
219
  	return effect, count --效果 和生效的buff 个数
  end
  --伤害反弹
ccbafe67   zhouhaihai   冒险神器和buff
220
  function BaseObject:getBackHurtBuff()
46fac6f1   zhouahaihai   酱料
221
222
223
  	local effect = {[0] = 0, [1] = 0}
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and buff:getType() == Buff.BACK_HURT then
ccbafe67   zhouhaihai   冒险神器和buff
224
  			local cType, value = buff:effect()  --  aType 0 全部  1 普通攻击
46fac6f1   zhouahaihai   酱料
225
  			if cType then
ccbafe67   zhouhaihai   冒险神器和buff
226
  				effect[cType] = effect[cType] + value
46fac6f1   zhouahaihai   酱料
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
  			end
  		end
  	end
  	return effect
  end
  
  --释放者伤害变化
  function BaseObject:getHurtChange()
  	local change = self:getCommonBuffEffect(Buff.HURT_CHANGE)
  	return change
  end
  --受伤者受伤变化
  function BaseObject:getInjuredChange()
  	local change = self:getCommonBuffEffect(Buff.INJURED_CHANGE)
  	return change
  end
ccbafe67   zhouhaihai   冒险神器和buff
243
244
245
246
247
248
249
250
  -- 奖励道具变化
  function BaseObject:getRewardChange(itemId)
  	local change = self:getCommonBuffEffect(Buff.ITEM_GET_UP, itemId)
  	return change
  end
  
  -- buff 增益 检疫
  function BaseObject:getBuffEffectChange(classify)
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
251
252
253
254
255
  	local classifys = classify:toArray(true, " ")
  	local had = {}
  	for _, one in pairs(classifys) do
  		had[one] = 1
  	end
ccbafe67   zhouhaihai   冒险神器和buff
256
257
  	local effect = 0
  	for _, buff in ipairs(self.buffs) do
1654ab82   zhouhaihai   bug
258
  		if not buff.isDel and buff:getType() == Buff.Buff_EFFECT_CHANGE then
ccbafe67   zhouhaihai   冒险神器和buff
259
  			local cType, value = buff:effect()
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
260
  			if cType and had[cType] then
ccbafe67   zhouhaihai   冒险神器和buff
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  				effect = effect + value
  			end
  		end
  	end
  	effect = effect / 100
  	return effect
  end
  
  function BaseObject:getAttrBuffChange(attr)
  	local AttrBuff = {
  		[Buff.ATTR_CHANGE] = 1,
  		[Buff.ATTR_CHANGE_COND] = 1,
  	}
  	local effect, count = {[0] = 0, [1] = 0}, 0
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and AttrBuff[buff:getType()] then
  			local cType, value, attrName = buff:effect()
  			if cType and attr == attrName then
  				effect[cType] = effect[cType] + value
  				count = count + 1
  			end
  		end
  	end
  	effect[1] = effect[1] / 100
  	return effect, count
  end
46fac6f1   zhouahaihai   酱料
287
288
  --重新计算属性
  function BaseObject:reSetAttr(field)
36c30c5c   zhouahaihai   冒险
289
  	local old = self[field]
46fac6f1   zhouahaihai   酱料
290
  	self[field] = self["_" .. field] --重置一下
ccbafe67   zhouhaihai   冒险神器和buff
291
  	local effect = self:getAttrBuffChange(field)
e10edb5f   zhouahaihai   冒险事件新
292
  	self[field] = math.ceil((self[field] + effect[0]) * (1 + effect[1]))
36c30c5c   zhouahaihai   冒险
293
  	local delta = self[field] - old
46fac6f1   zhouahaihai   酱料
294
295
  end
  
ccbafe67   zhouhaihai   冒险神器和buff
296
297
298
299
300
301
302
303
304
305
306
  -- 重新计算 血量上限
  function BaseObject:reSetHpMax()
  	self.hpMax = self._hpMax
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and buff:getType() == Buff.HP_MAX_CHANGE then
  			local cv = buff:effect()
  			if cv then
  				self.hpMax = self.hpMax + cv
  			end
  		end
  	end
98761edc   zhouhaihai   buff 补充
307
  	local effect = self:getAttrBuffChange("hp")
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
308
  	self.hpMax = (self.hpMax + effect[0]) * (1 + effect[1])
98761edc   zhouhaihai   buff 补充
309
  	self.hpMax = math.ceil(math.max(1, self.hpMax))
ccbafe67   zhouhaihai   冒险神器和buff
310
311
312
  	self.hp = math.min(self.hpMax, self.hp)
  end
  
46fac6f1   zhouahaihai   酱料
313
314
315
316
317
318
319
320
321
  --计算打出伤害加成后的值 
  function BaseObject:getHurtValue(value)
  	value = value or self.atk
  	local hurtChange = self:getHurtChange()
  	return math.max(0, (value + hurtChange[0]) * (1 + hurtChange[1]))
  end
  --计算自己伤害减免后的值
  function BaseObject:getInjuredValue(value)
  	local injuredChange = self:getInjuredChange()
2c04fed9   zhouhaihai   修改减伤公式
322
  	return math.max(0, (value - self.def + injuredChange[0]) * (1 + injuredChange[1]))
46fac6f1   zhouahaihai   酱料
323
324
  end
  
ae9a74b5   suhongyang   返回miss,快速战斗逻辑
325
  --最终伤害 = [ (敌方攻击 - 己方防御) * (1+伤害增加百分比-伤害减少百分比)*(1+受伤增加百分比-受伤减少百分比)+(伤害增加固定值-伤害增加固定值+受伤增加固定值-受伤增加固定值)]*(1+侍宠百分比)-侍宠固定值
53e8037e   zhouhaihai   任务
326
  -- params   -- hurtType  1 普攻伤害  2 buff伤害  3 反弹伤害  4 真实伤害  5 客户端发回来的伤害  --直接作用 6 buff伤害(真实)
46fac6f1   zhouahaihai   酱料
327
328
329
  --进入这个方法之前计算好释放者加成的伤害
  function BaseObject:hurt(value, releaser, params)
  	params = params or {}
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
330
331
332
  
  	if params.hurtType and (params.hurtType == 2 or params.hurtType == 6) then
  		self:triggerPassive(Passive.SELF_HURT, {trigger = releaser, buffId = params.buffId})
02c4de8d   zhouahaihai   增加 固有技
333
  		for _, team in ipairs(self:getTeam(1, true)) do
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
334
  			team:triggerPassive(Passive.TEAM_HURT, {trigger = releaser, buffId = params.buffId})
02c4de8d   zhouahaihai   增加 固有技
335
  		end
46fac6f1   zhouahaihai   酱料
336
  	end
d3da3368   zhouhaihai   冒险地图被动技, buff 神器
337
  
53e8037e   zhouhaihai   任务
338
  	if params.hurtType ~= 5 and params.hurtType ~= 6 then
12f7b52c   zhouhaihai   冒险战斗
339
340
  		if not params.hurtType or params.hurtType ~= 4 then
  			value = self:getInjuredValue(value) --减伤计算
46fac6f1   zhouahaihai   酱料
341
  		end
12f7b52c   zhouhaihai   冒险战斗
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
  		if value == 0 then return end
  
  		-- 舍身和恃宠
  		local team = self:getTeam(1)
  		local transfer = {}
  		local absorb = {}
  		for _, one in ipairs(team) do
  			local change1, count1 = one:getCommonBuffEffect(Buff.INJURED_CHANGE)
  			local change2, count2 = one:getCommonBuffEffect(Buff.HURT_ABSORB)
  			if count1 > 0 then
  				table.insert(transfer, {one, change1, count1})
  			end
  			if count2 > 0 then
  				table.insert(absorb, {one, change2, count2})
  			end
46fac6f1   zhouahaihai   酱料
357
  		end
12f7b52c   zhouhaihai   冒险战斗
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
  		if #absorb == 1 then --舍身优先级高  --舍身生效
  			if absorb[1][1] ~= self then --舍身的人不是自己才有效
  				local absorbV = (value - absorb[1][2][0]) * absorb[1][2][1] + absorb[1][2][0]  --固定值先生效
  				value = value - absorbV
  				absorb[1][1]:hurt(absorbV, releaser, params)
  			end
  		else
  			if #transfer == 1 and transfer[1][1] == self and #team > 1 then --侍宠 生效  
  				local transferValue = (value - transfer[1][2][0])* transfer[1][2][1] + transfer[1][2][0] --固定值先生效
  				value = value - transferValue
  				local oneValue = transferValue / (#team - 1)
  				for _, one in ipairs(team) do
  					if one ~= self then
  						one:hurt(oneValue, releaser, params)
  					end
46fac6f1   zhouahaihai   酱料
373
374
375
376
377
  				end
  			end
  		end
  	end
  
e10edb5f   zhouahaihai   冒险事件新
378
  	value = math.max(0, math.ceil(value))
46fac6f1   zhouahaihai   酱料
379
380
  	if value == 0 then return end
  	-- 反弹伤害
12f7b52c   zhouhaihai   冒险战斗
381
  	if params.hurtType ~= 3 and params.hurtType ~= 5 and releaser and not releaser.isDead then
ccbafe67   zhouhaihai   冒险神器和buff
382
  		local backEffect = self:getBackHurtBuff()
46fac6f1   zhouahaihai   酱料
383
384
385
386
387
  		local backValue = math.max(0, value * backEffect[1] + backEffect[0])
  		releaser:hurt(backValue, releaser, {hurtType = 3})
  	end
  
  	--受伤了~
d232676a   zhouhaihai   功能解锁 冒险返回
388
389
390
391
  	if self:is("Player") and params.hurtType ~= 5 then
  		self.battle.adv:pushBackEvent(AdvBackEventType.HpChange, {change = -value})
  	end
  
d27a2b20   zhouhaihai   怪受伤 更新地块
392
393
394
395
396
  	if params.hurtType ~= 5 then -- 非客户端发回的伤害  返回更新地块
  		if self.roomId and self.blockId then
  			self.battle.adv:backBlockChange(self.roomId, self.blockId)
  		end
  	end
46fac6f1   zhouahaihai   酱料
397
  	self.hp = math.max(0, self.hp - value)
b0fe1817   zhouahaihai   冒险分数
398
  
46fac6f1   zhouahaihai   酱料
399
  	if self.hp == 0 then
02c4de8d   zhouahaihai   增加 固有技
400
401
402
403
404
  		self:triggerPassive(Passive.SELF_DEAD)
  		for _, team in ipairs(self:getTeam(1, true)) do
  			team:triggerPassive(Passive.TEAM_DEAD)
  		end
  
53e8037e   zhouhaihai   任务
405
  		if (params.hurtType == 6 or params.hurtType == 2) and self ~= self.battle.player then
b176d7d3   zhouhaihai   冒险成就
406
407
  			self.battle.adv:checkAchievement(self.battle.adv.AchievType.KillByBuff, 1, params.buffId)
  		end
d95bc647   zhouhaihai   冒险被动技
408
  		self.isDead = true
46fac6f1   zhouahaihai   酱料
409
  	end
02c4de8d   zhouahaihai   增加 固有技
410
411
412
413
  	self:triggerPassive(Passive.HURT_PERCENT_SELF, {value = value / self.hpMax})
  	for _, team in ipairs(self:getTeam(1, true)) do
  		team:triggerPassive(Passive.HURT_PERCENT_TEAM, {value = value / self.hpMax})
  	end
46fac6f1   zhouahaihai   酱料
414
415
416
417
  end
  --恢复
  function BaseObject:recover(value, releaser, params)
  	params = params or {}
e10edb5f   zhouahaihai   冒险事件新
418
  	value = math.max(0, math.ceil(value))
4500c9b8   zhouhaihai   满了不飘字
419
  	local old = self.hp
46fac6f1   zhouahaihai   酱料
420
  	self.hp = math.min(self.hpMax, self.hp + value)
4500c9b8   zhouhaihai   满了不飘字
421
  	local change = self.hp - old
59acc11e   zhouhaihai   赛季更新
422
  	if self:is("Player") then
4500c9b8   zhouhaihai   满了不飘字
423
424
425
  		if change > 0 then
  			self.battle.adv:pushBackEvent(AdvBackEventType.HpChange, {change = value})
  		end
59acc11e   zhouhaihai   赛季更新
426
  	end
46fac6f1   zhouahaihai   酱料
427
428
  end
  
42f2d1d3   suhongyang   战斗内技能序列逻辑
429
430
431
432
433
  function BaseObject:addSpecialSkill(skillId, skillLevel, target)
  	local skillData = {id = skillId, level = skillLevel, target = target}
  	table.insert(self.skillOrder, skillData)
  end
  
d27ad5e0   suhongyang   使用营养技
434
  function BaseObject:releaseSkill(skillId, target)
36c30c5c   zhouahaihai   冒险
435
  	if self:hadBuff(Buff.CANT_SKILL) then return end -- 针对 怪物
d27ad5e0   suhongyang   使用营养技
436
  	local skill = Skill.new(self, {id = skillId, target = target})
36c30c5c   zhouahaihai   冒险
437
  	--返回客户端
1b8336a6   suhongyang   skill逻辑与player分开
438
  	for _, target in ipairs(skill:getTargets()) do
81032a9c   zhouhaihai   抽奖
439
  		self.battle.adv:backSkill(self.monsterId, skillId, target.id)
36c30c5c   zhouahaihai   冒险
440
  	end
1b8336a6   suhongyang   skill逻辑与player分开
441
  	skill:doEffect()
02c4de8d   zhouahaihai   增加 固有技
442
443
444
445
446
447
  	for _, team in ipairs(self:getTeam(2)) do
  		team:triggerPassive(Passive.TARGET_SKILL)
  	end
  	for _, team in ipairs(self:getTeam(1, true)) do
  		team:triggerPassive(Passive.TEAM_SKILL)
  	end
46fac6f1   zhouahaihai   酱料
448
449
450
  end
  
  --0 全部  1 我方  2 敌方
53e8037e   zhouhaihai   任务
451
  function BaseObject:getTeam(nType, noSelf, mapIdx, includeLock)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
452
  	mapIdx = mapIdx or self.battle.adv:getCurMapIdx()
46fac6f1   zhouahaihai   酱料
453
454
455
456
457
458
459
460
461
462
  	nType = nType or 0
  	local team = {}
  	local function addPlayer()
  		if not noSelf or self.battle.player ~= self then
  			if not self.battle.player.isDead then
  				table.insert(team, self.battle.player)
  			end
  		end
  	end
  	local function addEnemy()
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
463
  		for _, enemy in pairs(self.battle.enemys[mapIdx]) do
46fac6f1   zhouahaihai   酱料
464
  			if not noSelf or enemy ~= self then 
53e8037e   zhouhaihai   任务
465
  				if not enemy.isDead and (includeLock or not enemy.lock) then -- 已经翻开的
46fac6f1   zhouahaihai   酱料
466
467
468
469
470
471
472
473
474
  					table.insert(team, enemy)
  				end
  			end
  		end
  	end
  	if nType == 0 then
  		addPlayer()
  		addEnemy()
  	elseif nType == 1 then
b594a026   suhongyang   Fix bug
475
  		if not self.monsterId then --玩家
46fac6f1   zhouahaihai   酱料
476
477
478
479
480
  			addPlayer()
  		else
  			addEnemy()
  		end
  	elseif nType == 2 then
b594a026   suhongyang   Fix bug
481
  		if not self.monsterId then --玩家
46fac6f1   zhouahaihai   酱料
482
483
484
485
486
487
488
489
490
491
  			addEnemy()
  		else
  			addPlayer()
  		end
  	end
  	return team
  end
  
  function BaseObject:getDB()
  	local db = {}
46fac6f1   zhouahaihai   酱料
492
  	db.hp = self.hp
ccbafe67   zhouhaihai   冒险神器和buff
493
  	local baseAttr = {"atk", "miss", "hit", "def", "hpMax"}
46fac6f1   zhouahaihai   酱料
494
495
496
497
498
499
500
501
  	for _, field in pairs(baseAttr) do
  		db[field] = self[field]
  		db["_"..field] = self["_" .. field]
  	end
  	db.passives = {}
  	for _, passive in ipairs(self.passives) do
  		table.insert(db.passives, passive:getDB())
  	end
4ae223df   zhouahaihai   Buff bug
502
  	db.buffs = {}
46fac6f1   zhouahaihai   酱料
503
504
505
506
507
508
509
  	for _, buff in ipairs(self.buffs) do
  		table.insert(db.buffs, buff:getDB())
  	end
  	return db
  end
  
  function BaseObject:triggerPassive(condType, params)
02c4de8d   zhouahaihai   增加 固有技
510
511
512
513
  	if self.isDead then return end
  	for _, passive in ipairs(self.passives) do
  		passive:trigger(condType, params) --检查触发
  	end
46fac6f1   zhouahaihai   酱料
514
515
  end
  
3b0526d2   zhouhaihai   冒险demo
516
517
518
  function BaseObject:changeSp()
  end
  
d232676a   zhouhaihai   功能解锁 冒险返回
519
520
521
522
  function BaseObject:is(what)
  	return self["is" .. what] and self["is" .. what](self)
  end
  
46fac6f1   zhouahaihai   酱料
523
  local Enemy = class("Enemy", BaseObject)
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
524
  function Enemy:ctor(battle, mId, monsterId, roomId, blockId, lock, enemy, mapIdx)
46fac6f1   zhouahaihai   酱料
525
  	Enemy.super.ctor(self, battle)
36c30c5c   zhouahaihai   冒险
526
527
  	self.id = mId
  	self.monsterId = monsterId  --数据id
46fac6f1   zhouahaihai   酱料
528
529
530
  	self.roomId = roomId
  	self.blockId = blockId
  	self.lock = lock
43babcff   zhouhaihai   优化冒险结构 增加夹层功能
531
  	self.mapIdx = mapIdx
46fac6f1   zhouahaihai   酱料
532
533
  	self:initData(enemy)
  end
a0834e49   zhouhaihai   增加潜行 功能
534
  function Enemy:unlock()
46fac6f1   zhouahaihai   酱料
535
536
537
  	self.lock = nil
  end
  
d232676a   zhouhaihai   功能解锁 冒险返回
538
539
540
541
  function Enemy:isEnemy()
  	return true
  end
  
7b2dc17c   zhouhaihai   地图 层 buff passive
542
543
544
545
  function Enemy:kill()
  	self:hurt(self.hp, self.battle.player, {hurtType = 5})
  end
  
46fac6f1   zhouahaihai   酱料
546
547
548
549
550
551
  local Player = class("Player", BaseObject)
  function Player:ctor(battle, data)
  	Player.super.ctor(self, battle)
  	self:initData(data)
  end
  
b53593b5   zhouhaihai   羁绊加成
552
553
  function Player:initData(data)
  	Player.super.initData(self, data)
386ca58e   zhouhaihai   优化log
554
  	self.level = data.level or 1  --level 每增加1级  属性增长 growth * baseAttr
ccbafe67   zhouhaihai   冒险神器和buff
555
  	self.growth = data.growth
b53593b5   zhouhaihai   羁绊加成
556
  	self.exp = data.exp or 0
3b0526d2   zhouhaihai   冒险demo
557
  	self.sp = data.sp or 100
ccbafe67   zhouhaihai   冒险神器和buff
558
559
  	self.spMax = data.spMax or 100
  	self._spMax = data._spMax or 100
b53593b5   zhouhaihai   羁绊加成
560
561
562
  end
  
  function Player:addExp(value)
4f0a5fae   zhouhaihai   营养剂
563
564
565
566
  	-- buff 经验加成
  	local up = self:getCommonBuffEffect(Buff.EXP_UP)
  	value = math.ceil((value + up[0]) * (1 + up[1]))
  
51718558   zhouhaihai   中继层初始经验
567
  	if value <= 0 then return end
6732f756   zhouhaihai   玩家升级
568
569
570
571
572
573
574
575
576
577
578
  	local newExp = self.exp + value
  	local level = self.level
  	if level >= #csvdb["adv_levelCsv"] then return end
  	while true do
  		local curData = csvdb["adv_levelCsv"][level]
  		if newExp < curData.exp then break end
  		level = level + 1
  		newExp = newExp - curData.exp
  		if level >= #csvdb["adv_levelCsv"] then break end
  	end
  	local delta = level - self.level
56484297   zhouhaihai   冒险消息
579
580
581
  
  	self.battle.adv:pushBackEvent(AdvBackEventType.Exp, {delta = value})
  
6732f756   zhouhaihai   玩家升级
582
  	if delta > 0 then
8781e103   zhouhaihai   冒险 bug
583
  		for attr, _ in pairs(AdvAttsEnum) do
d232676a   zhouhaihai   功能解锁 冒险返回
584
  			self:addBaseAttr(attr, self.growth[attr] * delta, 0, true)
6732f756   zhouhaihai   玩家升级
585
  		end
81032a9c   zhouhaihai   抽奖
586
  		self.battle.adv:pushBackEvent(AdvBackEventType.Level, {level = level, delta = delta})
6732f756   zhouhaihai   玩家升级
587
588
589
  	end
  	self.level = level
  	self.exp = newExp
85ded242   zhouhaihai   丰富返回事件
590
  	return value
b53593b5   zhouhaihai   羁绊加成
591
  end
1ffc16b9   zhouhaihai   冒险 选择点和 建筑
592
  --vtype 0/1 值/%
d232676a   zhouhaihai   功能解锁 冒险返回
593
  function Player:addBaseAttr(attr, value, vtype, ignoreBack)
1ffc16b9   zhouhaihai   冒险 选择点和 建筑
594
595
596
  	local attrName = attr
  	if attr == "hp" then
  		attrName = "hpMax"
e1679483   zhouhaihai   bug
597
  	elseif attr == "sp" then
1ffc16b9   zhouhaihai   冒险 选择点和 建筑
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
  		attrName = "spMax"
  	end
  	local baseName = "_" .. attrName
  	if not self[baseName] then return end
  	local oldV = self[baseName]
  
  	local change = value
  	if vtype == 1 then
  		change = oldV * value / 100
  	end
  	self[baseName] = self[baseName] + change
  	if attr == "hp" then
  		self.hp = self.hp + change
  		self:reSetHpMax()
  	elseif attr == "sp" then
  		self.sp = self.sp + change
  		self:reSetSpMax()
  	else
  		self:reSetAttr(attr)
  	end
d232676a   zhouhaihai   功能解锁 冒险返回
618
619
620
621
  
  	if not ignoreBack then
  		self.battle.adv:pushBackEvent(AdvBackEventType.BaseAttrChange, {type = AdvAttsEnum[attr] or 0, change = change})
  	end
1ffc16b9   zhouhaihai   冒险 选择点和 建筑
622
  end
b53593b5   zhouhaihai   羁绊加成
623
  
3b0526d2   zhouhaihai   冒险demo
624
625
  --cType 0 or nil  值  1 百分比
  function Player:changeSp(value, cType)
85ded242   zhouhaihai   丰富返回事件
626
  	local oldSp = self.sp
3b0526d2   zhouhaihai   冒险demo
627
  	cType = cType or 0
cac28f5f   zhouhaihai   魔力改变
628
  	local change = 0
3b0526d2   zhouhaihai   冒险demo
629
  	if cType == 0 then
cac28f5f   zhouhaihai   魔力改变
630
  		change = value
3b0526d2   zhouhaihai   冒险demo
631
  	elseif cType == 1 then
cac28f5f   zhouhaihai   魔力改变
632
  		change = self.sp * value / 100
3b0526d2   zhouhaihai   冒险demo
633
  	end
cac28f5f   zhouhaihai   魔力改变
634
635
636
  	self.sp = math.floor(math.min(self.spMax, math.max(0, self.sp + change)))
  	if change ~= 0 then
  		self.battle.adv:pushBackEvent(AdvBackEventType.SpChange, {change = math.floor(change)})
81032a9c   zhouhaihai   抽奖
637
  	end
3b0526d2   zhouhaihai   冒险demo
638
639
  end
  
ccbafe67   zhouhaihai   冒险神器和buff
640
  -- 重新计算 魔法上限
3df73a9e   zhouhaihai   复兴奖励
641
  function Player:reSetSpMax()
ccbafe67   zhouhaihai   冒险神器和buff
642
643
644
645
646
647
648
  	self.spMax = self._spMax
  	local change = self:getCommonBuffEffect(Buff.SP_MAX_CHANGE)
  	self.spMax = math.ceil((self.spMax + change[0]) * (1 + change[1]))
  	self.spMax = math.max(1, self.spMax)
  	self.sp = math.min(self.spMax, self.sp)
  end
  
e90b4d20   zhouhaihai   战斗buff
649
650
651
  --战斗结束了扣战斗buff次数
  function Player:effectBattleBuff()
  	for _, buff in ipairs(self.buffs) do
b176d7d3   zhouhaihai   冒险成就
652
  		if not buff.isDel and (buff:getType() == Buff.BATTLE_BUFF or buff:getType() == Buff.BATTLE_PASSIVE) then
e90b4d20   zhouhaihai   战斗buff
653
654
655
656
  			buff:effect()
  		end
  	end
  end
3b0526d2   zhouhaihai   冒险demo
657
  
596ac19f   zhouhaihai   buff
658
  function Player:afterLayer()
7b2dc17c   zhouhaihai   地图 层 buff passive
659
660
661
662
663
  	for _, passive in ipairs(self.passives) do
  		if not passive.isDel then
  			passive:afterLayer()
  		end
  	end
596ac19f   zhouhaihai   buff
664
665
666
667
668
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel then
  			buff:afterLayer()
  		end
  	end	
7b2dc17c   zhouhaihai   地图 层 buff passive
669
670
  
  	self:clearRound()
596ac19f   zhouhaihai   buff
671
672
  end
  
e852b350   zhouhaihai   冒险成就类型增加
673
  function Player:addBuff(buffId, releaser)
c5d9338f   zhouhaihai   通用方法 异常
674
675
676
677
  	local status = Player.super.addBuff(self, buffId, releaser)
  	if  status then
  		self.battle.player:attrChangeCondBuffCheck(2, buffId)
  		self.battle.adv:checkAchievement(self.battle.adv.AchievType.GetBuff, 1, buffId)
d232676a   zhouhaihai   功能解锁 冒险返回
678
  		self.battle.adv:pushBackEvent(AdvBackEventType.Buff, {buffId = buffId})
c5d9338f   zhouhaihai   通用方法 异常
679
680
  	end
  	return status
e852b350   zhouhaihai   冒险成就类型增加
681
682
  end
  
b71a8190   zhouhaihai   动态改变 一些buff
683
684
685
686
687
688
689
690
691
692
693
  function Player:attrChangeCondBuffCheck(etype, cond)
  	local effect = {}
  	for _, buff in ipairs(self.buffs) do
  		if not buff.isDel and (buff:getType() == Buff.ATTR_CHANGE_COND) then
  			local _et, _attr, _co = buff:getEffectBy()
  			if etype == _et and (not _co or _co == cond) then
  				effect[_attr] = 1
  			end
  			
  		end
  	end
b71a8190   zhouhaihai   动态改变 一些buff
694
695
696
697
698
699
700
701
702
  	for attrName, _ in pairs(effect) do
  		if attrName == "hp" then
  			self:reSetHpMax()
  		else
  			self:reSetAttr(attrName)
  		end
  	end
  end
  
d232676a   zhouhaihai   功能解锁 冒险返回
703
704
705
706
  function Player:isPlayer()
  	return true
  end
  
b53593b5   zhouhaihai   羁绊加成
707
708
  function Player:getDB()
  	local db = Player.super.getDB(self)
ccbafe67   zhouhaihai   冒险神器和buff
709
  	for _ , field in pairs({"level", "exp", "growth", "sp", "spMax"}) do
b53593b5   zhouhaihai   羁绊加成
710
711
  		db[field] = self[field]
  	end
ccbafe67   zhouhaihai   冒险神器和buff
712
  	db["_spMax"] = self._spMax
b53593b5   zhouhaihai   羁绊加成
713
714
715
  	return db
  end
  
9687f887   zhouhaihai   建筑被动
716
717
718
719
720
721
  -- 建筑 拥有被动技  
  local Build = class("Build", BaseObject)
  
  function Build:ctor(battle, id, roomId, blockId, lock, build, mapIdx)
  	Enemy.super.ctor(self, battle)
  	self.id = id
9687f887   zhouhaihai   建筑被动
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
  	self.roomId = roomId
  	self.blockId = blockId
  	self.lock = lock
  	self.mapIdx = mapIdx
  	self:initData(build)
  end
  
  function Build:initData(data)
  end
  
  function Build:addBuff(buffId, releaser)
  end
  
  function Build:hurt()
  end
  
d232676a   zhouhaihai   功能解锁 冒险返回
738
739
740
  function Build:isBuild()
  	return true
  end
9687f887   zhouhaihai   建筑被动
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
  --0 全部  1 怪物  2 玩家  
  function Build:getTeam(nType, noSelf, mapIdx, includeLock)
  	noSelf = false  -- 不管怎么都取不到自己
  	mapIdx = mapIdx or self.battle.adv:getCurMapIdx()
  	nType = nType or 0
  	local team = {}
  	local function addPlayer()
  		if not noSelf or self.battle.player ~= self then
  			if not self.battle.player.isDead then
  				table.insert(team, self.battle.player)
  			end
  		end
  	end
  	local function addEnemy()
  		for _, enemy in pairs(self.battle.enemys[mapIdx]) do
  			if not noSelf or enemy ~= self then 
  				if not enemy.isDead and (includeLock or not enemy.lock) then -- 已经翻开的
  					table.insert(team, enemy)
  				end
  			end
  		end
  	end
  	if nType == 0 then
  		addPlayer()
  		addEnemy()
  	elseif nType == 1 then
  		addEnemy()
  	elseif nType == 2 then
  		addPlayer()
  	end
  	return team
  end
26aeaf48   zhouhaihai   bug
773
  function Build:unlock()
9687f887   zhouhaihai   建筑被动
774
775
776
  	self.lock = nil
  end
  
26aeaf48   zhouhaihai   bug
777
  function Build:getDB()
9687f887   zhouhaihai   建筑被动
778
779
780
781
782
783
784
  	local db = {}
  	db.passives = {}
  	for _, passive in ipairs(self.passives) do
  		table.insert(db.passives, passive:getDB())
  	end
  	return db
  end
3b0526d2   zhouhaihai   冒险demo
785
786
  
  
26aeaf48   zhouhaihai   bug
787
  return table.pack(Player, Enemy, Build)