Skip to content

Simplification/Unification of StaticAbility variants #10097

@Hanmac

Description

@Hanmac

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?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions