mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
Cleaned up code, fixed NullPointerException
This commit is contained in:
parent
3558899033
commit
483e6549f6
1 changed files with 15 additions and 42 deletions
|
|
@ -39,6 +39,7 @@ import mage.abilities.effects.RequirementEffect;
|
||||||
import mage.abilities.effects.RestrictionEffect;
|
import mage.abilities.effects.RestrictionEffect;
|
||||||
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
|
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
|
||||||
import mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect;
|
import mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect;
|
||||||
|
import mage.abilities.effects.common.combat.CantAttackTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
|
|
@ -145,12 +146,21 @@ class MasterWarcraftChooseAttackersEffect extends ContinuousRuleModifyingEffectI
|
||||||
game.addEffect(effect, source);
|
game.addEffect(effect, source);
|
||||||
game.informPlayers(controller.getLogName() + " has decided that " + permanent.getLogName() + " attacks this combat if able");
|
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 {
|
} else {
|
||||||
RestrictionEffect effect = new MasterWarcraftCantAttackRestrictionEffect();
|
boolean hasToAttack = false;
|
||||||
effect.setText("");
|
for (Map.Entry<RequirementEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRequirementEffects(permanent, false, game).entrySet()) {
|
||||||
effect.setTargetPointer(new FixedTarget(permanent.getId()));
|
RequirementEffect effect2 = entry.getKey();
|
||||||
game.addEffect(effect, source);
|
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<RequirementEffect, Set<Ability>> 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 {
|
class MasterWarcraftChooseBlockersEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
|
|
||||||
public MasterWarcraftChooseBlockersEffect() {
|
public MasterWarcraftChooseBlockersEffect() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue