Example:
|
public static StaticAbility cantAttach(final GameEntity target, final Card card, boolean checkSBA) { |
|
// CantTarget static abilities |
|
for (final Card ca : target.getGame().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES)) { |
|
for (final StaticAbility stAb : ca.getStaticAbilities()) { |
|
if (!stAb.checkConditions(StaticAbilityMode.CantAttach)) { |
|
continue; |
|
} |
|
|
|
if (applyCantAttachAbility(stAb, card, target, checkSBA)) { |
|
return stAb; |
|
} |
|
} |
|
} |
most of the uses in these Static classes return a boolean if some static ability gets triggered by it
(in some cases, like this one, it returns the first one that does trigger it)
So shouldn't it be possible to make a helper version that uses stream of it?
Like this part is nearly identical in most versions (+some use extra LKI, but these can be added)
target.getGame().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES).stream().flatMap(c -> c.getStaticAbilities().stream())
And then use anyMatch/filter with a Predicate like this?
stAb -> stAb.checkConditions(StaticAbilityMode.CantAttach) && applyCantAttachAbility(stAb, card, target, checkSBA)
Maybe do the Mode check in a filter first?
Example:
forge/forge-game/src/main/java/forge/game/staticability/StaticAbilityCantAttach.java
Lines 9 to 21 in 5972acb
most of the uses in these Static classes return a boolean if some static ability gets triggered by it
(in some cases, like this one, it returns the first one that does trigger it)
So shouldn't it be possible to make a helper version that uses stream of it?
Like this part is nearly identical in most versions (+some use extra LKI, but these can be added)
target.getGame().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES).stream().flatMap(c -> c.getStaticAbilities().stream())And then use
anyMatch/filterwith aPredicatelike this?stAb -> stAb.checkConditions(StaticAbilityMode.CantAttach) && applyCantAttachAbility(stAb, card, target, checkSBA)Maybe do the Mode check in a
filterfirst?