Commit c8ade4f6a6ac8b537abee08f99eea0d34564e8fd
1 parent
4eadc2ab
被动筛选逻辑
Showing
1 changed file
with
74 additions
and
8 deletions
Show diff stats
src/adv/AdvPassive.lua
| 1 | +local Filter = class("Filter") | |
| 2 | + | |
| 3 | +Filter.HP_UP_WITH_EQUAL = 1 -- 血量>=value% | |
| 4 | + | |
| 5 | +local FilterFactory = {} | |
| 6 | +FilterFactory[Filter.HP_UP_WITH_EQUAL] = function (_Filter) | |
| 7 | + _Filter._execute = function (self, target) | |
| 8 | + return target.hp >= self.value * target.hpMax / 100 | |
| 9 | + end | |
| 10 | +end | |
| 11 | + | |
| 12 | +function Filter:ctor(params) | |
| 13 | + self.owner = params.owner | |
| 14 | + self.skill = params.skill | |
| 15 | + self.fType = params.fType -- 筛选类型 | |
| 16 | + self.oType = params.oType -- 主体类型 0:owner 1:trigger 2:releaser | |
| 17 | + self.value = params.value -- 筛选值 | |
| 18 | + | |
| 19 | + if FilterFactory[self.fType] then | |
| 20 | + FilterFactory[self.fType](self) | |
| 21 | + end | |
| 22 | +end | |
| 23 | + | |
| 24 | +function Filter:getTarget(params) | |
| 25 | + local target | |
| 26 | + if self.oType == 0 then | |
| 27 | + target = self.owner | |
| 28 | + end | |
| 29 | + if self.oType == 1 and params.trigger then | |
| 30 | + target = params.trigger | |
| 31 | + end | |
| 32 | + if self.oType == 2 and params.releaser then | |
| 33 | + target = params.releaser | |
| 34 | + end | |
| 35 | + return target | |
| 36 | +end | |
| 37 | + | |
| 38 | +function Filter:execute(params) | |
| 39 | + local target = self:getTarget(params) | |
| 40 | + if not target then | |
| 41 | + return | |
| 42 | + end | |
| 43 | + if self:_execute(target) then | |
| 44 | + return self:_execute(target) | |
| 45 | + end | |
| 46 | +end | |
| 47 | + | |
| 48 | +-->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| 1 | 49 | local Passive = class("Passive") |
| 2 | 50 | |
| 3 | 51 | -- 每回合触发的使用 afterRound |
| ... | ... | @@ -124,19 +172,30 @@ function Passive:ctor(owner, data) |
| 124 | 172 | self.count = data.count or 0 --触发剩余次数 |
| 125 | 173 | |
| 126 | 174 | self.effects = self.passiveData.effect:toTableArray(true) |
| 175 | + self.filters = {} | |
| 127 | 176 | |
| 128 | 177 | if PassiveCondFactory[self.passiveData.condition] then |
| 129 | 178 | PassiveCondFactory[self.passiveData.condition](self) |
| 130 | 179 | end |
| 180 | + self:initFilter() | |
| 131 | 181 | if self._initDB then |
| 132 | 182 | self:_initDB(data) |
| 133 | 183 | end |
| 134 | 184 | end |
| 135 | 185 | |
| 186 | +function Passive:initFilter() | |
| 187 | + local filterList = self.passiveData.filter:toTableArray(true) | |
| 188 | + for _, fParams in ipairs(filterList) do | |
| 189 | + local filter = Filter.new({owner = self.owner, skill = self, oType = fParams[1], fType = fParams[2], value = fParams[3] }) | |
| 190 | + table.insert(self.filters, filter) | |
| 191 | + end | |
| 192 | +end | |
| 193 | + | |
| 136 | 194 | function Passive:getCondType() |
| 137 | 195 | return self.passiveData.condition, self.passiveData.value |
| 138 | 196 | end |
| 139 | 197 | |
| 198 | +-- effect 生效篩選 | |
| 140 | 199 | function Passive:canEffect(effType, effValue) |
| 141 | 200 | if self.owner.lock and effType ~= 3 then -- 锁定的只能触发翻开自己格子的固有技 |
| 142 | 201 | return |
| ... | ... | @@ -145,21 +204,13 @@ function Passive:canEffect(effType, effValue) |
| 145 | 204 | end |
| 146 | 205 | |
| 147 | 206 | function Passive:effect(trigger) |
| 148 | - if math.randomInt(1, 100) > self.passiveData.chance then | |
| 149 | - return | |
| 150 | - end | |
| 151 | - local effNum = 0 | |
| 152 | 207 | for _, effect in pairs(self.effects) do |
| 153 | 208 | local effType = effect[1] |
| 154 | 209 | local effValue = effect[2] |
| 155 | 210 | if self:canEffect(effType, effValue) then |
| 156 | 211 | self["effect" .. effType](self, effValue, trigger) |
| 157 | - effNum = effNum + 1 | |
| 158 | 212 | end |
| 159 | 213 | end |
| 160 | - if effNum < 1 then | |
| 161 | - return | |
| 162 | - end | |
| 163 | 214 | --次数为 -1 一局只能触发一次,触发过后删掉就可以 |
| 164 | 215 | if self.count == -1 then |
| 165 | 216 | self.isDel = true |
| ... | ... | @@ -196,6 +247,12 @@ function Passive:trigger(condType, params) --触发检查 |
| 196 | 247 | if self._trigger then |
| 197 | 248 | if not self:_trigger(params) then return end --检查 |
| 198 | 249 | end |
| 250 | + if not self:filter(params) then | |
| 251 | + return | |
| 252 | + end | |
| 253 | + if math.randomInt(1, 100) > self.passiveData.chance then | |
| 254 | + return | |
| 255 | + end | |
| 199 | 256 | self.round = self.passiveData.delay --首次 |
| 200 | 257 | self.count = self.passiveData.count --次数 |
| 201 | 258 | -- 没有延迟就直接触发 |
| ... | ... | @@ -204,6 +261,15 @@ function Passive:trigger(condType, params) --触发检查 |
| 204 | 261 | end |
| 205 | 262 | end |
| 206 | 263 | |
| 264 | +function Passive:filter(params) | |
| 265 | + for _, filter in ipairs(self.filters) do | |
| 266 | + if not filter:execute(params) then | |
| 267 | + return | |
| 268 | + end | |
| 269 | + end | |
| 270 | + return true | |
| 271 | +end | |
| 272 | + | |
| 207 | 273 | function Passive:getDB() |
| 208 | 274 | local db = {} |
| 209 | 275 | if self._getDB then | ... | ... |