Commit 1b0d767fc13361574c6157262d709ece91686180
1 parent
23a38f47
一個被動支持多種effect
Showing
1 changed file
with
35 additions
and
14 deletions
Show diff stats
src/adv/AdvPassive.lua
| @@ -122,6 +122,9 @@ function Passive:ctor(owner, data) | @@ -122,6 +122,9 @@ function Passive:ctor(owner, data) | ||
| 122 | self.isDel = false | 122 | self.isDel = false |
| 123 | self.round = data.round or 0 --触发剩余回合数 | 123 | self.round = data.round or 0 --触发剩余回合数 |
| 124 | self.count = data.count or 0 --触发剩余次数 | 124 | self.count = data.count or 0 --触发剩余次数 |
| 125 | + | ||
| 126 | + self.effects = self.passiveData.effect:toTableArray(true) | ||
| 127 | + | ||
| 125 | if PassiveCondFactory[self.passiveData.condition] then | 128 | if PassiveCondFactory[self.passiveData.condition] then |
| 126 | PassiveCondFactory[self.passiveData.condition](self) | 129 | PassiveCondFactory[self.passiveData.condition](self) |
| 127 | end | 130 | end |
| @@ -134,9 +137,28 @@ function Passive:getCondType() | @@ -134,9 +137,28 @@ function Passive:getCondType() | ||
| 134 | return self.passiveData.condition, self.passiveData.value | 137 | return self.passiveData.condition, self.passiveData.value |
| 135 | end | 138 | end |
| 136 | 139 | ||
| 137 | -function Passive:effect() | ||
| 138 | - if math.randomInt(1, 100) <= self.passiveData.chance and self["effect" .. self.passiveData.effect] then | ||
| 139 | - self["effect" .. self.passiveData.effect](self) | 140 | +function Passive:canEffect(effType, effValue) |
| 141 | + if self.owner.lock and effType ~= 3 then -- 锁定的只能触发翻开自己格子的固有技 | ||
| 142 | + return | ||
| 143 | + end | ||
| 144 | + return true | ||
| 145 | +end | ||
| 146 | + | ||
| 147 | +function Passive:effect(trigger) | ||
| 148 | + if math.randomInt(1, 100) > self.passiveData.chance then | ||
| 149 | + return | ||
| 150 | + end | ||
| 151 | + local effNum = 0 | ||
| 152 | + for _, effect in pairs(self.effects) do | ||
| 153 | + local effType = effect[1] | ||
| 154 | + local effValue = effect[2] | ||
| 155 | + if self:canEffect(effType, effValue) then | ||
| 156 | + self["effect" .. effType](self, effValue, trigger) | ||
| 157 | + effNum = effNum + 1 | ||
| 158 | + end | ||
| 159 | + end | ||
| 160 | + if effNum < 1 then | ||
| 161 | + return | ||
| 140 | end | 162 | end |
| 141 | --次数为 -1 一局只能触发一次,触发过后删掉就可以 | 163 | --次数为 -1 一局只能触发一次,触发过后删掉就可以 |
| 142 | if self.count == -1 then | 164 | if self.count == -1 then |
| @@ -170,7 +192,6 @@ function Passive:trigger(condType, params) --触发检查 | @@ -170,7 +192,6 @@ function Passive:trigger(condType, params) --触发检查 | ||
| 170 | params = params or {} | 192 | params = params or {} |
| 171 | if self.isDel or self.owner.isDead then return end | 193 | if self.isDel or self.owner.isDead then return end |
| 172 | if self:getCondType() ~= condType then return end | 194 | if self:getCondType() ~= condType then return end |
| 173 | - if self.owner.lock and self.passiveData.effect ~= 3 then return end -- 锁定的只能触发翻开自己格子的固有技 | ||
| 174 | if self:isActive() then return end | 195 | if self:isActive() then return end |
| 175 | if self._trigger then | 196 | if self._trigger then |
| 176 | if not self:_trigger(params) then return end --检查 | 197 | if not self:_trigger(params) then return end --检查 |
| @@ -196,17 +217,17 @@ function Passive:getDB() | @@ -196,17 +217,17 @@ function Passive:getDB() | ||
| 196 | end | 217 | end |
| 197 | 218 | ||
| 198 | --默认=0=使用技能, | 219 | --默认=0=使用技能, |
| 199 | -function Passive:effect0() | ||
| 200 | - self.owner:releaseSkill(self.passiveData.effectValue) | 220 | +function Passive:effect0(value) |
| 221 | + self.owner:releaseSkill(value) | ||
| 201 | end | 222 | end |
| 202 | --1=自身获得buff | 223 | --1=自身获得buff |
| 203 | -function Passive:effect1() | ||
| 204 | - self.owner:addBuff(self.passiveData.effectValue) | 224 | +function Passive:effect1(value) |
| 225 | + self.owner:addBuff(value) | ||
| 205 | end | 226 | end |
| 206 | --2=触发目标获得buff | 227 | --2=触发目标获得buff |
| 207 | -function Passive:effect2(trigger) | 228 | +function Passive:effect2(value, trigger) |
| 208 | if trigger then | 229 | if trigger then |
| 209 | - trigger:addBuff(self.passiveData.effectValue) | 230 | + trigger:addBuff(value) |
| 210 | end | 231 | end |
| 211 | end | 232 | end |
| 212 | --3=翻开自己所在格子 | 233 | --3=翻开自己所在格子 |
| @@ -219,14 +240,14 @@ function Passive:effect4() | @@ -219,14 +240,14 @@ function Passive:effect4() | ||
| 219 | self.owner.battle.adv:enemyDead(self.owner.roomId,self.owner.blockId, true) | 240 | self.owner.battle.adv:enemyDead(self.owner.roomId,self.owner.blockId, true) |
| 220 | end | 241 | end |
| 221 | --5=给随机一个敌方增加一个buff | 242 | --5=给随机一个敌方增加一个buff |
| 222 | -function Passive:effect5() | 243 | +function Passive:effect5(value) |
| 223 | local monsters = self.owner.battle.player:getTeam(2) | 244 | local monsters = self.owner.battle.player:getTeam(2) |
| 224 | local randomId = math.random( 1, #monsters ) | 245 | local randomId = math.random( 1, #monsters ) |
| 225 | - monsters[randomId]:addBuff(self.passiveData.effectValue) | 246 | + monsters[randomId]:addBuff(value) |
| 226 | end | 247 | end |
| 227 | --6=给自己加一個被動技能 | 248 | --6=给自己加一個被動技能 |
| 228 | -function Passive:effect6() | ||
| 229 | - self.owner:addPassive({id = self.passiveData.effectValue}) | 249 | +function Passive:effect6(value) |
| 250 | + self.owner:addPassive({id = value}) | ||
| 230 | end | 251 | end |
| 231 | 252 | ||
| 232 | return Passive | 253 | return Passive |
| 233 | \ No newline at end of file | 254 | \ No newline at end of file |