From 483e6549f6bf8b6acd3bee1cc9f77a12405372bb Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Fri, 20 Oct 2017 02:01:09 +0200 Subject: [PATCH] Cleaned up code, fixed NullPointerException --- .../src/mage/cards/m/MasterWarcraft.java | 57 +++++-------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/Mage.Sets/src/mage/cards/m/MasterWarcraft.java b/Mage.Sets/src/mage/cards/m/MasterWarcraft.java index 23c5a7a503a..7bac5394538 100644 --- a/Mage.Sets/src/mage/cards/m/MasterWarcraft.java +++ b/Mage.Sets/src/mage/cards/m/MasterWarcraft.java @@ -39,6 +39,7 @@ import mage.abilities.effects.RequirementEffect; import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect; +import mage.abilities.effects.common.combat.CantAttackTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; @@ -145,12 +146,21 @@ class MasterWarcraftChooseAttackersEffect extends ContinuousRuleModifyingEffectI game.addEffect(effect, source); game.informPlayers(controller.getLogName() + " has decided that " + permanent.getLogName() + " attacks this combat if able"); - // All other creatures can't attack + // All other creatures can't attack (unless they must attack) } else { - RestrictionEffect effect = new MasterWarcraftCantAttackRestrictionEffect(); - effect.setText(""); - effect.setTargetPointer(new FixedTarget(permanent.getId())); - game.addEffect(effect, source); + boolean hasToAttack = false; + for (Map.Entry> entry : game.getContinuousEffects().getApplicableRequirementEffects(permanent, false, game).entrySet()) { + RequirementEffect effect2 = entry.getKey(); + if (effect2.mustAttack(game)) { + hasToAttack = true; + } + } + if (!hasToAttack) { + RestrictionEffect effect = new CantAttackTargetEffect(Duration.EndOfCombat); + effect.setText(""); + effect.setTargetPointer(new FixedTarget(permanent.getId())); + game.addEffect(effect, source); + } } } } @@ -159,43 +169,6 @@ class MasterWarcraftChooseAttackersEffect extends ContinuousRuleModifyingEffectI } } -class MasterWarcraftCantAttackRestrictionEffect extends RestrictionEffect { - - MasterWarcraftCantAttackRestrictionEffect() { - super(Duration.EndOfCombat); - } - - MasterWarcraftCantAttackRestrictionEffect(final MasterWarcraftCantAttackRestrictionEffect effect) { - super(effect); - } - - @Override - public MasterWarcraftCantAttackRestrictionEffect copy() { - return new MasterWarcraftCantAttackRestrictionEffect(this); - } - - @Override - public boolean applies(Permanent permanent, Ability source, Game game) { - return this.getTargetPointer().getFirst(game, source).equals(permanent.getId()); - } - - @Override - public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { - for (Map.Entry> entry : game.getContinuousEffects().getApplicableRequirementEffects(attacker, false, game).entrySet()) { - RequirementEffect effect = entry.getKey(); - if (effect.mustAttack(game)) { - return true; - } - } - return false; - } - - @Override - public String getText(Mode mode) { - return "Unless {this} must attack, {this} can't attack."; - } -} - class MasterWarcraftChooseBlockersEffect extends ContinuousRuleModifyingEffectImpl { public MasterWarcraftChooseBlockersEffect() {