mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
replaced various instances of instanceof lambda functions with
This commit is contained in:
parent
26ef55c1bc
commit
26ae7b7281
21 changed files with 37 additions and 46 deletions
|
@ -110,7 +110,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
|
||||
// deck legality cards selection
|
||||
Arrays.stream(deckLegalityDisplay.getComponents())
|
||||
.filter(c -> c instanceof LegalityLabel)
|
||||
.filter(LegalityLabel.class::isInstance)
|
||||
.forEach(c -> {
|
||||
c.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
|
|
@ -542,7 +542,7 @@ public class CardView extends SimpleCardView {
|
|||
} else if (spell.getCard() != null) {
|
||||
SplitCard wholeCard = ((SplitCardHalf) spell.getCard()).getParentCard();
|
||||
Abilities<Ability> aftermathHalfAbilities = wholeCard.getRightHalfCard().getAbilities(game);
|
||||
if (aftermathHalfAbilities.stream().anyMatch(halfAbility -> halfAbility instanceof AftermathAbility)) {
|
||||
if (aftermathHalfAbilities.stream().anyMatch(AftermathAbility.class::isInstance)) {
|
||||
if (ty == SpellAbilityType.SPLIT_RIGHT) {
|
||||
artRect = ArtRect.AFTERMATH_BOTTOM;
|
||||
} else {
|
||||
|
|
|
@ -57,10 +57,10 @@ public class Brawl extends Constructed {
|
|||
Iterator<Card> iter = deck.getSideboard().iterator();
|
||||
Card card1 = iter.next();
|
||||
Card card2 = iter.next();
|
||||
if (card1.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
|
||||
if (card1.getAbilities().stream().anyMatch(CompanionAbility.class::isInstance)) {
|
||||
companion = card1;
|
||||
brawler = card2;
|
||||
} else if (card2.getAbilities().stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
|
||||
} else if (card2.getAbilities().stream().anyMatch(CompanionAbility.class::isInstance)) {
|
||||
companion = card2;
|
||||
brawler = card1;
|
||||
} else {
|
||||
|
|
|
@ -1482,7 +1482,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
// can't see lands as playable and must know the reason (if they click on land then they get that message)
|
||||
if (abilityToCast.getAbilityType() == AbilityType.SPELL) {
|
||||
Spell spell = game.getStack().getSpell(abilityToCast.getSourceId());
|
||||
boolean haveManaAbilities = object.getAbilities().stream().anyMatch(a -> a instanceof ManaAbility);
|
||||
boolean haveManaAbilities = object.getAbilities().stream().anyMatch(ManaAbility.class::isInstance);
|
||||
if (spell != null && !spell.isResolving() && haveManaAbilities) {
|
||||
switch (spell.getCurrentActivatingManaAbilitiesStep()) {
|
||||
// if you used special mana ability like convoke then normal mana abilities will be restricted to use, see Convoke for details
|
||||
|
|
|
@ -67,7 +67,7 @@ class KadenasSilencerEffect extends OneShotEffect {
|
|||
Set<UUID> opps = game.getOpponents(source.getControllerId());
|
||||
game.getStack()
|
||||
.stream()
|
||||
.filter(stackObject -> stackObject instanceof Ability)
|
||||
.filter(Ability.class::isInstance)
|
||||
.filter(stackObject -> opps.contains(stackObject.getControllerId()))
|
||||
.forEach(stackObject -> game.getStack().counter(stackObject.getId(), source, game));
|
||||
return true;
|
||||
|
|
|
@ -117,11 +117,11 @@ class MandateOfPeaceEndCombatEffect extends OneShotEffect {
|
|||
combat.endCombat(game);
|
||||
if (!game.getStack().isEmpty()) {
|
||||
game.getStack().stream()
|
||||
.filter(stackObject -> stackObject instanceof Spell)
|
||||
.filter(Spell.class::isInstance)
|
||||
.forEach(stackObject -> ((Spell) stackObject).moveToExile(null, "", null, game));
|
||||
|
||||
game.getStack().stream()
|
||||
.filter(stackObject -> stackObject instanceof Ability)
|
||||
.filter(Ability.class::isInstance)
|
||||
.forEach(stackObject -> game.getStack().remove(stackObject, game));
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.w;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
|
@ -12,30 +10,26 @@ import mage.abilities.keyword.DashAbility;
|
|||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.CostModificationType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class Warbringer extends CardImpl {
|
||||
|
||||
public Warbringer(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{R}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}");
|
||||
this.subtype.add(SubType.ORC);
|
||||
this.subtype.add(SubType.BERSERKER);
|
||||
this.power = new MageInt(3);
|
||||
this.toughness = new MageInt(3);
|
||||
|
||||
// Dash costs you pay cost {2} less (as long as this creature is on the battlefield).
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new WarbringerSpellsCostReductionEffect()));
|
||||
this.addAbility(new SimpleStaticAbility(new WarbringerSpellsCostReductionEffect()));
|
||||
|
||||
// Dash {2}{R}
|
||||
this.addAbility(new DashAbility(this, "{2}{R}"));
|
||||
|
@ -70,18 +64,15 @@ class WarbringerSpellsCostReductionEffect extends CostModificationEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean applies(Ability abilityToModify, Ability source, Game game) {
|
||||
if (abilityToModify instanceof SpellAbility
|
||||
&& abilityToModify.isControlledBy(source.getControllerId())) {
|
||||
if (game != null && game.inCheckPlayableState()) {
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
return card.getAbilities(game).stream().anyMatch(a -> a instanceof DashAbility);
|
||||
}
|
||||
} else {
|
||||
return DashedCondition.instance.apply(game, abilityToModify);
|
||||
}
|
||||
if (!(abilityToModify instanceof SpellAbility)
|
||||
|| !abilityToModify.isControlledBy(source.getControllerId())) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
if (game == null || !game.inCheckPlayableState()) {
|
||||
return DashedCondition.instance.apply(game, abilityToModify);
|
||||
}
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
return card != null && card.getAbilities(game).stream().anyMatch(DashAbility.class::isInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -617,7 +617,7 @@ public class FlashbackTest extends CardTestPlayerBase {
|
|||
checkPlayableAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flashback {1}{U}", true);
|
||||
runCode("test", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
|
||||
long flashbackCount = player.getPlayable(game, true).stream()
|
||||
.filter(ability -> ability instanceof FlashbackAbility)
|
||||
.filter(FlashbackAbility.class::isInstance)
|
||||
.count();
|
||||
Assert.assertEquals("must have only two playable abilities without duplicates", 2, flashbackCount);
|
||||
});
|
||||
|
|
|
@ -37,7 +37,7 @@ public class GainAbilitiesTest extends CardTestPlayerBase {
|
|||
|
||||
Permanent permanent = getPermanent("Balduvian Bears");
|
||||
Assert.assertEquals("must have only 1 singleton ability instance from two attachments",
|
||||
1, permanent.getAbilities(currentGame).stream().filter(a -> a instanceof VigilanceAbility).count());
|
||||
1, permanent.getAbilities(currentGame).stream().filter(VigilanceAbility.class::isInstance).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -63,7 +63,7 @@ public class GainAbilitiesTest extends CardTestPlayerBase {
|
|||
Permanent permanent = getPermanent("Balduvian Bears");
|
||||
Assert.assertEquals("must have 2 dynamic ability instances from two attachments",
|
||||
2, permanent.getAbilities(currentGame).stream().filter(
|
||||
a -> a.getEffects().stream().anyMatch(e -> e instanceof DrawCardSourceControllerEffect)
|
||||
a -> a.getEffects().stream().anyMatch(DrawCardSourceControllerEffect.class::isInstance)
|
||||
).count());
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class GainMenaceAbilityAsSingletonTest extends CardTestPlayerBase {
|
|||
|
||||
Permanent permanent = getPermanent("Minotaur", playerA);
|
||||
Assert.assertEquals("must have only 1 Menace instance", 1, permanent.getAbilities(currentGame).stream()
|
||||
.filter(a -> a instanceof MenaceAbility).count());
|
||||
.filter(MenaceAbility.class::isInstance).count());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -353,7 +353,7 @@ public class BoosterGenerationTest extends MageTestBase {
|
|||
fail("Booster can't have more than three snow lands");
|
||||
}
|
||||
|
||||
long mdfcCount = booster.stream().filter(card -> card instanceof ModalDoubleFacesCard).count();
|
||||
long mdfcCount = booster.stream().filter(ModalDoubleFacesCard.class::isInstance).count();
|
||||
assertTrue("Booster can't have more than one MDFC", mdfcCount < 2);
|
||||
|
||||
foundMDFC |= mdfcCount > 0;
|
||||
|
|
|
@ -18,7 +18,7 @@ public enum BuybackCondition implements Condition {
|
|||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
return card.getAbilities(game).stream()
|
||||
.filter(a -> a instanceof BuybackAbility)
|
||||
.filter(BuybackAbility.class::isInstance)
|
||||
.anyMatch(a -> ((BuybackAbility) a).isBuybackActivated(game));
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,7 @@ public enum DashedCondition implements Condition {
|
|||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
return card.getAbilities(game).stream()
|
||||
.filter(a -> a instanceof DashAbility)
|
||||
.filter(DashAbility.class::isInstance)
|
||||
.anyMatch(d -> ((DashAbility) d).isActivated(source, game));
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public enum EvokedCondition implements Condition {
|
|||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
return card.getAbilities(game).stream()
|
||||
.filter(ab -> ab instanceof EvokeAbility)
|
||||
.filter(EvokeAbility.class::isInstance)
|
||||
.anyMatch(evoke -> ((EvokeAbility) evoke).isActivated(source, game));
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -140,7 +140,7 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
|
|||
if (alternativeCostsToCheck.canPay(ability, ability, ability.getControllerId(), game)
|
||||
&& player.chooseUse(Outcome.Benefit, costChoiceText, this, game)) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
ability.getManaCostsToPay().removeIf(manaCost -> manaCost instanceof VariableCost);
|
||||
ability.getManaCostsToPay().removeIf(VariableCost.class::isInstance);
|
||||
CardUtil.reduceCost((SpellAbility) ability, ability.getManaCosts());
|
||||
|
||||
} else {
|
||||
|
|
|
@ -418,7 +418,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
|
|||
// extraPredicates from some filters is player related, you don't need it here
|
||||
List<Predicate> list = new ArrayList<>();
|
||||
Predicates.collectAllComponents(filter.getPredicates(), list);
|
||||
if (list.stream().anyMatch(p -> p instanceof SubType.SubTypePredicate)) {
|
||||
if (list.stream().anyMatch(SubType.SubTypePredicate.class::isInstance)) {
|
||||
this.addDependedToType(DependencyType.AddingCreatureType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ class CipherStoreEffect extends OneShotEffect {
|
|||
Card copyCard = game.copyCard(cipherCard, source, controller.getId());
|
||||
SpellAbility ability = copyCard.getSpellAbility();
|
||||
// remove the cipher effect from the copy
|
||||
ability.getEffects().removeIf(effect -> effect instanceof CipherEffect);
|
||||
ability.getEffects().removeIf(CipherEffect.class::isInstance);
|
||||
controller.cast(ability, game, true, new ApprovingObject(source, game));
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class CastAsThoughItHadFlashAllEffect extends AsThoughEffectImpl {
|
|||
if (card != null) {
|
||||
//Allow lands with morph to be played at instant speed
|
||||
if (card.isLand(game)) {
|
||||
boolean morphAbility = card.getAbilities().stream().anyMatch(ability -> ability instanceof MorphAbility);
|
||||
boolean morphAbility = card.getAbilities().stream().anyMatch(MorphAbility.class::isInstance);
|
||||
if (morphAbility) {
|
||||
Card cardCopy = card.copy();
|
||||
cardCopy.removeAllCardTypes(game);
|
||||
|
|
|
@ -34,7 +34,7 @@ public class FlankingAbility extends TriggeredAbilityImpl {
|
|||
Permanent permanent = game.getPermanent(event.getSourceId());
|
||||
if (permanent != null) {
|
||||
boolean hasFlankingAbility
|
||||
= permanent.getAbilities().stream().anyMatch(ability -> ability instanceof FlankingAbility);
|
||||
= permanent.getAbilities().stream().anyMatch(FlankingAbility.class::isInstance);
|
||||
|
||||
if (!hasFlankingAbility) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
|
|
|
@ -95,7 +95,7 @@ public class FilterCard extends FilterObject<Card> {
|
|||
// card filter can't contain controller predicate (only permanents on battlefield have controller)
|
||||
List<Predicate> list = new ArrayList<>();
|
||||
Predicates.collectAllComponents(predicate, list);
|
||||
if (list.stream().anyMatch(p -> p instanceof TargetController.ControllerPredicate)) {
|
||||
if (list.stream().anyMatch(TargetController.ControllerPredicate.class::isInstance)) {
|
||||
throw new IllegalArgumentException("Card filter doesn't support controller predicate");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3706,7 +3706,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
ManaOptions manaFull = availableMana.copy();
|
||||
if (ability instanceof SpellAbility) {
|
||||
for (AlternateManaPaymentAbility altAbility : CardUtil.getAbilities(object, game).stream()
|
||||
.filter(a -> a instanceof AlternateManaPaymentAbility)
|
||||
.filter(AlternateManaPaymentAbility.class::isInstance)
|
||||
.map(a -> (AlternateManaPaymentAbility) a)
|
||||
.collect(Collectors.toList())) {
|
||||
ManaOptions manaSpecial = altAbility.getManaOptions(ability, game, ability.getManaCostsToPay());
|
||||
|
@ -3739,7 +3739,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
if (ability instanceof AlternativeSourceCosts && object != null && !(object instanceof Permanent)) {
|
||||
ActivatedAbility playAbility = null;
|
||||
if (object.isLand(game)) {
|
||||
playAbility = (PlayLandAbility) CardUtil.getAbilities(object, game).stream().filter(a -> a instanceof PlayLandAbility).findFirst().orElse(null);
|
||||
playAbility = (PlayLandAbility) CardUtil.getAbilities(object, game).stream().filter(PlayLandAbility.class::isInstance).findFirst().orElse(null);
|
||||
} else if (object instanceof Card) {
|
||||
playAbility = ((Card) object).getSpellAbility();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue