Blame view

src/adv/AdvPassive.lua 6.98 KB
46fac6f1   zhouahaihai   酱料
1
2
3
4
5
  local Passive = class("Passive")
  
  -- 每回合触发的使用 afterRound
  -- 其他触发的使用 triggerPassive 
  
02c4de8d   zhouahaihai   增加 固有技
6
7
  Passive.BORN_ONCE = 1 -- 自身出生(翻开所在格子)触发
  Passive.ROOM_SHOW = 2 --自身所在房间被展示时,触发1次 
46fac6f1   zhouahaihai   酱料
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  Passive.HURT_PERCENT_SELF = 3 --自身,每损失N%生命值,触发1次
  Passive.HURT_PERCENT_TEAM = 4 --队友,每损失N%生命值,触发1次
  Passive.HP_LOW_SELF = 5 --自身生命值<N%时,每回合触发
  Passive.HP_LOW_TEAM = 6 --敌人生命值<N%时,每回合触发
  Passive.HP_UP_SELF = 7 --自身生命值>N%时,每回合触发
  Passive.HP_UP_TEAM = 8 --敌人生命值>N%时,每回合触发
  Passive.SELF_ATK = 9 --自身攻击N次后,触发1次
  Passive.SELF_HURT = 10 --自身受击N次后,触发1次
  Passive.TEAM_ATK = 11 --队友攻击N次后,触发1次
  Passive.TEAM_HURT = 12 --队友受击N次后,触发1次
  Passive.MONSTER_COUNT_UP = 13  --场上存在N个以上怪物,每回合触发
  Passive.MONSTER_COUNT_LOW = 14  --场上存在N个以下怪物,每回合触发
  Passive.SELF_DEAD = 15 --自身死亡后,触发1次
  Passive.TEAM_DEAD = 16 --队友死亡后,触发1次
  Passive.TARGET_SKILL = 17 --目标每使用N次技能,触发1次
  Passive.TEAM_SKILL = 18 --队友每使用N次技能,触发1次
02c4de8d   zhouahaihai   增加 固有技
24
  
46fac6f1   zhouahaihai   酱料
25
26
  
  -- 不同的开启条件
02c4de8d   zhouahaihai   增加 固有技
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
74
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
110
111
112
113
114
115
  local PassiveCondFactory = {}
  PassiveCondFactory[Passive.HURT_PERCENT_SELF] = function(_Passive)
  	_Passive._trigger = function(self, params)
  		local value = params.value or 1
  		self.rv = math.floor(self.rv + value)
  		if self.rv >= self.passiveData.value then
  			self.rv = self.rv % self.passiveData.value  -- 取余
  			return true
  		end
  	end
  	_Passive._initDB = function(self, data)
  		self.rv = data.rv or 0
  	end
  	_Passive._getDB = function(self)
  		return {rv = self.rv}
  	end
  end
  
  PassiveCondFactory[Passive.HURT_PERCENT_TEAM] = PassiveCondFactory[Passive.HURT_PERCENT_SELF]  --逻辑相同
  PassiveCondFactory[Passive.SELF_ATK] = PassiveCondFactory[Passive.HURT_PERCENT_SELF]  --逻辑相同
  PassiveCondFactory[Passive.SELF_HURT] = PassiveCondFactory[Passive.HURT_PERCENT_SELF]  --逻辑相同
  PassiveCondFactory[Passive.TEAM_ATK] = PassiveCondFactory[Passive.HURT_PERCENT_SELF]  --逻辑相同
  PassiveCondFactory[Passive.TEAM_HURT] = PassiveCondFactory[Passive.HURT_PERCENT_SELF]  --逻辑相同
  PassiveCondFactory[Passive.TARGET_SKILL] = PassiveCondFactory[Passive.HURT_PERCENT_SELF]  --逻辑相同
  PassiveCondFactory[Passive.TEAM_SKILL] = PassiveCondFactory[Passive.HURT_PERCENT_SELF]  --逻辑相同
  
  PassiveCondFactory[Passive.ROOM_SHOW] = function(_Passive)
  	_Passive._trigger = function(self, params)
  		local roomId = params.roomId
  		if self.roomId == roomId then
  			return true
  		end
  	end
  end
  
  PassiveCondFactory[Passive.HP_LOW_SELF] = function(_Passive)
  	_Passive._afterRound = function(self)
  		if self.owner.hp / self.owner.hpMax * 100 < self.passiveData.value then
  			self:trigger(Passive.HP_LOW_SELF)
  		end
  	end
  end
  
  PassiveCondFactory[Passive.HP_LOW_TEAM] = function(_Passive)
  	_Passive._afterRound = function(self)
  		for _, player in ipairs(self.owner:getTeam(2)) do
  			if player.hp / player.hpMax * 100 < self.passiveData.value then
  				self:trigger(Passive.HP_LOW_TEAM, {trigger = player})
  			end
  		end
  	end
  end
  
  PassiveCondFactory[Passive.HP_UP_SELF] = function(_Passive)
  	_Passive._afterRound = function(self)
  		if self.owner.hp / self.owner.hpMax * 100 > self.passiveData.value then
  			self:trigger(Passive.HP_UP_SELF)
  		end
  	end
  end
  
  PassiveCondFactory[Passive.HP_UP_TEAM] = function(_Passive)
  	_Passive._afterRound = function(self)
  		for _, player in ipairs(self.owner:getTeam(2)) do
  			if player.hp / player.hpMax * 100 > self.passiveData.value then
  				self:trigger(Passive.HP_UP_TEAM, {trigger = player})
  			end
  		end
  	end
  end
  
  PassiveCondFactory[Passive.MONSTER_COUNT_UP] = function(_Passive)
  	_Passive._afterRound = function(self)
  		local monsters = self.owner.battle.player:getTeam(2)
  		if #monsters > self.passiveData.value then
  			self:trigger(Passive.MONSTER_COUNT_UP)
  		end
  	end
  end
  
  PassiveCondFactory[Passive.MONSTER_COUNT_LOW] = function(_Passive)
  	_Passive._afterRound = function(self)
  		local monsters = self.owner.battle.player:getTeam(2)
  		if #monsters < self.passiveData.value then
  			self:trigger(Passive.MONSTER_COUNT_LOW)
  		end
  	end
  end
  
46fac6f1   zhouahaihai   酱料
116
117
118
119
120
121
122
123
124
  
  function Passive:ctor(owner, data)
  	self.owner = owner
  	self.id = data.id
  	self.level = data.level or 1
  	self.passiveData = csvdb["adv_skill_passiveCsv"][self.id][self.level]
  	self.isDel = false
  	self.round = data.round or 0	--触发剩余回合数
  	self.count = data.count or 0	--触发剩余次数
02c4de8d   zhouahaihai   增加 固有技
125
126
127
128
129
  	if PassiveCondFactory[self.passiveData.condition] then
  		PassiveCondFactory[self.passiveData.condition](self)
  	end
  	if self._initDB then
  		self:_initDB(data)
46fac6f1   zhouahaihai   酱料
130
131
132
133
134
135
136
137
  	end
  end
  
  function Passive:getCondType()
  	return self.passiveData.condition, self.passiveData.value
  end
  
  function Passive:effect()
02c4de8d   zhouahaihai   增加 固有技
138
139
  	if math.randomInt(1, 100) <= self.passiveData.chance and self["effect" .. self.passiveData.effect] then
  		self["effect" .. self.passiveData.effect](self) 
46fac6f1   zhouahaihai   酱料
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
  	end
  	--次数为 -1 一局只能触发一次,触发过后删掉就可以
  	if self.count == -1 then
  		self.isDel = true
  	end
  	if self.count > 0 then
  		self.count = self.count - 1
  		self.round = self.passiveData.space
  	end
  end
  
  function Passive:afterRound()
  	if self.isDel or self.owner.isDead then return end
  	if self._afterRound then
  		self:_afterRound()  --有的触发自己检测在这里检查
  	end
  	if self.round > 0 then  --回合触发的
  		self.round = self.round - 1
  		if self.round == 0 then
  			self:effect()
  		end
  	end
  end
  
  -- 正在触发中
  function  Passive:isActive( )
  	return self.count > 0 or self.round > 0
  end
  
  function Passive:trigger(condType, params) --触发检查
02c4de8d   zhouahaihai   增加 固有技
170
171
  	params = params or {}
  	if self.isDel or self.owner.isDead then return end
46fac6f1   zhouahaihai   酱料
172
  	if self:getCondType() ~= condType then return end
02c4de8d   zhouahaihai   增加 固有技
173
  	if self.owner.lock and self.passiveData.effect ~= 3 then return end -- 锁定的只能触发翻开自己格子的固有技
46fac6f1   zhouahaihai   酱料
174
  	if self:isActive() then return end
36c30c5c   zhouahaihai   冒险
175
  	if self._trigger then
02c4de8d   zhouahaihai   增加 固有技
176
  		if not self:_trigger(params) then return end  --检查
36c30c5c   zhouahaihai   冒险
177
  	end
46fac6f1   zhouahaihai   酱料
178
179
180
181
  	self.round = self.passiveData.delay --首次
  	self.count = self.passiveData.count --次数
  	-- 没有延迟就直接触发
  	if self.round == 0 then
02c4de8d   zhouahaihai   增加 固有技
182
  		self:effect(params.trigger)
46fac6f1   zhouahaihai   酱料
183
184
185
186
187
188
189
190
191
192
193
194
  	end
  end
  
  function Passive:getDB()
  	local db = {}
  	if self._getDB then
  		db = self:_getDB()
  	end
  	db.id = self.id
  	db.level = self.level
  	db.round = self.round
  	db.count = self.count
36c30c5c   zhouahaihai   冒险
195
  	return db
46fac6f1   zhouahaihai   酱料
196
  end
02c4de8d   zhouahaihai   增加 固有技
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
  
  --默认=0=使用技能,
  function Passive:effect0()
  	self.owner:releaseSkill(self.passiveData.effectValue)
  end
  --1=自身获得buff
  function Passive:effect1()
  	self.owner:addBuff(self.passiveData.effectValue)
  end
  --2=触发目标获得buff
  function Passive:effect2(trigger)
  	if trigger then
  		trigger:addBuff(self.passiveData.effectValue)
  	end
  end
  --3=翻开自己所在格子,
  function Passive:effect3()
  	self.owner.battle.adv:openBlock(self.owner.roomId, self.owner.blockId)
  end
  --4=逃跑
  function Passive:effect4()
  	self.owner.isDead = true --跑了
  	self.owner.battle.adv:enemyDead(self.owner.roomId,self.owner.blockId, true)
  end
  
  
46fac6f1   zhouahaihai   酱料
223
  return Passive