Blame view

src/adv/AdvBuff.lua 7.8 KB
46fac6f1   zhouahaihai   酱料
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  
  local Buff = class("Buff")
  
  Buff.HP_CHANGE = 1  --生命变化(每回合生效)
  Buff.HP_MAX_CHANGE = 2	--生命上限变化(状态)
  Buff.ATK_CHANGE = 3 --攻击变化(状态)
  Buff.IMMNUE_ATK = 4 -- 免疫普通攻击
  Buff.BACK_HURT = 5 -- 伤害反弹
  Buff.HURT_CHANGE = 6 -- 伤害变化
  Buff.INJURED_CHANGE = 7 -- 受伤变化
  Buff.HURT_TRANSFER = 8 -- 侍宠(转移自己受到的伤害)
  Buff.HURT_ABSORB = 9 -- 舍身(吸收他人受到的伤害)
  Buff.CANT_BACK_ATK = 10 -- 无法反击
  Buff.IMMNUE_BUFF = 11 -- 免疫buff
  Buff.CLEAR_BUFF = 12 -- 清除buff
  Buff.CANT_SKILL = 13 -- 禁止技能
  Buff.OPEN_BLOCK = 14 -- 翻开格子(每回合)
  Buff.POWER_CHANGE = 15 -- 体力变化(每回合)
  Buff.HIT_CHANGE = 16 -- 命中变化(状态)
  Buff.MISS_CHANGE = 17 -- 闪避变化(状态)
e996b82a   zhouahaihai   冒险增加防御属性
21
  Buff.DEF_CHANGE = 18 -- 防御变化(状态)
46fac6f1   zhouahaihai   酱料
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  
  --角色一些属性的变化
  local function commonAttr(_Buff, attrName)
  	_Buff._init = function(self, data) --初始化变化值
  		self.owner:reSetAttr(attrName)
  	end
  	_Buff._effectValue = function(self)
  		return self.buffData.effectValue1, self.buffData.effectValue2
  	end
  	_Buff._endBuff = function(self, data)
  		self.owner:reSetAttr(attrName)
  	end
  end
  
  local BuffFactory = {
  	[Buff.HP_CHANGE] = function(_Buff)
  		_Buff._init = function(self, data) --初始化变化值
  			self._changeV = 0
  			if self.buffData.effectValue1 == 0 then --固定值
  				self._changeV = self.buffData.effectValue2
  			elseif self.buffData.effectValue1 == 1 then
  				local baseOwner = self.buffData.effectValue4 == 1 and self.owner or self.release
  				local attrs = {[0] = "hp", [1] = "hpMax", [2] = "atk"}
4ae223df   zhouahaihai   Buff bug
45
  				self._changeV = baseOwner[attrs[self.buffData.effectValue3]] * self.buffData.effectValue2 / 100
46fac6f1   zhouahaihai   酱料
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  			end
  			if self._changeV < 0 then
  				self._changeV = -self.release:getHurtValue(-self._changeV)
  			end
  		end
  		_Buff._initDB = function(self, data) 
  			self._changeV = data.cv
  		end
  		_Buff._afterRount = function(self)
  			if self._changeV > 0 then
  				self.owner:recover(self._changeV, self.release)
  			elseif self._changeV < 0 then
  				self.owner:hurt(-self._changeV, self.release, {hurtType = 2})
  			end
  		end
  		_Buff._getDB = function(self)
  			return {cv = self._changeV}
  		end
  	end,
  
  	[Buff.HP_MAX_CHANGE] = function(_Buff)
  		_Buff._init = function(self, data) --初始化变化值
  			self._changeV = 0
  			if self.buffData.effectValue1 == 0 then --固定值
  				self._changeV = self.buffData.effectValue2
  			elseif self.buffData.effectValue1 == 1 then
  				local baseOwner = self.buffData.effectValue4 == 1 and self.owner or self.release
  				local attrs = {[0] = "hp", [1] = "hpMax", [2] = "atk"}
4ae223df   zhouahaihai   Buff bug
74
  				self._changeV = baseOwner[attrs[self.buffData.effectValue3]] * self.buffData.effectValue2 / 100
46fac6f1   zhouahaihai   酱料
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  			end
  			local old = self.owner.hpMax
  			self.owner.hpMax = math.max(1, self.owner.hpMax + self._changeV)
  			self._changeV = self.owner.hpMax - old
  			if self._changeV > 0 then
  				self.owner:recover(self._changeV, self.release)
  			elseif self._changeV < 0 then
  				self.owner:hurt(self.release:getHurtValue(-self._changeV), self.release, {hurtType = 2})
  				self.owner.hp = math.min(self.owner.hpMax, self.owner.hp)
  			end
  		end
  		_Buff._initDB = function(self, data)
  			self._changeV = data.cv
  		end
  		_Buff._endBuff = function(self, data)
  			if self._changeV then
  				self.owner.hpMax = math.max(1, self.owner.hpMax - self._changeV)
  				self.owner.hp = math.min(self.owner.hpMax, self.owner.hp)
  			end
  		end
  		_Buff._getDB = function(self)
  			return {cv = self._changeV}
  		end
  	end,
  	[Buff.ATK_CHANGE] = function(_Buff)
  		commonAttr(_Buff, "atk")
  	end,
  
  	[Buff.HIT_CHANGE] = function(_Buff)
  		commonAttr(_Buff, "hit")
  	end,
  
  	[Buff.MISS_CHANGE] = function(_Buff)
  		commonAttr(_Buff, "miss")
  	end,
e996b82a   zhouahaihai   冒险增加防御属性
110
111
112
113
  	
  	[Buff.DEF_CHANGE] = function(_Buff)
  		commonAttr(_Buff, "miss")
  	end,
46fac6f1   zhouahaihai   酱料
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  
  	[Buff.BACK_HURT] = function(_Buff)
  		_Buff._effectValue = function(self)
  			return self.buffData.effectValue1, self.buffData.effectValue2, self.buffData.effectValue3
  		end
  	end,
  
  	[Buff.HURT_CHANGE] = function(_Buff)
  		_Buff._effectValue = function(self)
  			return self.buffData.effectValue1, self.buffData.effectValue2
  		end
  	end,
  
  	[Buff.INJURED_CHANGE] = function(_Buff)
  		_Buff._effectValue = function(self)
  			return self.buffData.effectValue1, self.buffData.effectValue2
  		end
  	end,
  
  	[Buff.HURT_TRANSFER] = function(_Buff)
  		_Buff._effectValue = function(self)
  			return self.buffData.effectValue1, self.buffData.effectValue2
  		end
  	end,
  
  	[Buff.HURT_ABSORB] = function(_Buff)
  		_Buff._effectValue = function(self)
  			return self.buffData.effectValue1, self.buffData.effectValue2
  		end
  	end,
  
  	[Buff.IMMNUE_BUFF] = function(_Buff)
  		_Buff._init = function(self, data)
  			self.count = self.buffData.effectValue3
  		end
  		_Buff._effectValue = function(self)
  			return self.buffData.effectValue1, self.buffData.effectValue2
  		end
  	end,
  
  	[Buff.CLEAR_BUFF] = function(_Buff)
  		_Buff._init = function(self, data)
  			self.count = self.buffData.effectValue3
  			self:_afterRount() -- 挂上就清除一下子
  		end
  		_Buff._afterRount = function(self)
  			local cType, aim = self:effectValue()
  			for _, buff in ipairs(self.buffs) do
  				if not buff.isDel and ((cType == 0 and buff.id == aim) or (cType == 1 and buff:getGroup() == aim)) then
  					buff.isDel = true
  					self:decCount()
  				end
  			end
  		end
  		_Buff._effectValue = function(self)
  			return self.buffData.effectValue1, self.buffData.effectValue2
  		end
  	end,
  
  	[Buff.OPEN_BLOCK] = function(_Buff)
  		_Buff._afterRount = function(self)
  			self.owner.battle.adv:openBlockRand(self.buffData.effectValue1)
  		end
  	end,
  
  	[Buff.POWER_CHANGE] = function(_Buff)
  		_Buff._afterRount = function(self)
  			self.owner.battle.adv:changePower(self.buffData.effectValue2, self.buffData.effectValue1)
  		end
  	end
  }
  
  
  function Buff.create(owner, release, data)
  	local buff = Buff.new(owner, data.id)
  	buff:initNew(release, data)
  	return buff
  end
  
  function Buff.load(owner, data)
  	local buff = Buff.new(owner, data.id)
  	buff:initByDB(data)
  	return buff
  end
  
  function Buff:ctor(owner, id)
  	self.owner = owner
  	self.id = id
  	self.buffData = csvdb["adv_buffCsv"][self.id]
  	self.isDel = false
  	self.duration = 0 --剩余的回合
  	self.count = -1 -- 可生效的次数  -1 无次数限制
  
  	if BuffFactory[self.buffData.type] then
  		BuffFactory[self.buffData.type](self)
  	end
  end
  
  function Buff:initByDB(data)
  	if data.rele then
  		if data.rele == 0 then
  			self.release = self.owner.battle.player
  		else
  			self.release = self.owner.battle:getEnemyById(data.rele)
  		end
  	end
  	self.duration = data.dur
  	if data.count then
  		self.count = data.count
  	end
  
  	if self._initDB then
  		self:_initDB(data)
  	end
  end
  
  function Buff:initNew(release, data)
  	self.release = release
  	self.duration = self.buffData.duration
  	if self._init then
  		self:_init(data)
  	end
  end
  
  function Buff:afterRound()
  	if self.isDel or self.owner.isDead then return end 
46fac6f1   zhouahaihai   酱料
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
  	if self._afterRount then
  		self:_afterRount()
  	end
  
  	if self.buffData.duration ~= 0 then
  		self.duration = self.duration - 1
  		if self.duration <= 0 then
  			self.isDel = true
  		end
  	end
  end
  
  function Buff:effectValue()
  	if self._effectValue then
  		return self:_effectValue()
  	end
  end
  --删除buff 时调用
  function Buff:endBuff()
  	if self._endBuff then
  		self:_endBuff()
  	end
  end
  
  function Buff:getType()
  	return self.buffData.type
  end
  
  function Buff:decCount()
  	if self.count == -1 then return end
  	self.count = self.count - 1
  	if self.count <= 0 then
  		self.isDel = true
  	end
  end
  
  function Buff:getGroup()
  	return self.buffData.group
  end
  
  function Buff:getDB()
  	local db = {}
  	if self._getDB then
  		db = self:_getDB()
  	end
  	db.id = self.id
  	if self.release and not self.release.isDead then
  		db.rele = self.release.id or 0 --释放者的id  (0 为玩家)  (不存在 则释放者不存在或者已经死亡)
  	end
  	if self.buffData.duration ~= 0 then
  		db.dur = self.duration
  	end
  	if self.count ~= -1 then
  		db.count = self.count
  	end
  	return db
  end
  
  return Buff