Add new common effect class for Armored Transport, etc and fix #9614

This commit is contained in:
Alex W. Jackson 2022-10-11 22:48:02 -04:00
parent 17be0c11ba
commit 4bf01249a4
25 changed files with 359 additions and 809 deletions

View file

@ -1,87 +0,0 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.PreventionEffectImpl;
import mage.constants.Duration;
import mage.filter.FilterInPlay;
import mage.filter.FilterObject;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
/**
* @author LevelX2
*/
public class PreventAllDamageByAllObjectsEffect extends PreventionEffectImpl {
private FilterObject filter;
public PreventAllDamageByAllObjectsEffect(Duration duration) {
this(null, duration, false);
}
public PreventAllDamageByAllObjectsEffect(Duration duration, boolean onlyCombat) {
this(null, duration, onlyCombat);
}
public PreventAllDamageByAllObjectsEffect(FilterObject filter, Duration duration, boolean onlyCombat) {
super(duration, Integer.MAX_VALUE, onlyCombat);
this.filter = filter;
}
private PreventAllDamageByAllObjectsEffect(final PreventAllDamageByAllObjectsEffect effect) {
super(effect);
if (effect.filter != null) {
this.filter = effect.filter.copy();
}
}
@Override
public PreventAllDamageByAllObjectsEffect copy() {
return new PreventAllDamageByAllObjectsEffect(this);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
return false;
}
DamageEvent damageEvent = (DamageEvent) event;
if (!damageEvent.isCombatDamage() && onlyCombat) {
return false;
}
if (filter == null) {
return true;
}
MageObject damageSource = game.getObject(damageEvent.getSourceId());
if (damageSource == null) {
return false;
}
if (filter instanceof FilterInPlay) {
return ((FilterInPlay) filter).match(damageSource, source.getControllerId(), source, game);
}
return filter.match(damageSource, game);
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder("Prevent all ");
if (onlyCombat) {
sb.append("combat ");
}
sb.append("damage that would be dealt");
if (duration == Duration.EndOfTurn) {
sb.append(" this turn");
}
if (filter != null) {
sb.append(" by ");
sb.append(filter.getMessage());
}
return sb.toString();
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
@ -17,7 +16,7 @@ import mage.game.permanent.Permanent;
*/
public class PreventAllDamageByAllPermanentsEffect extends PreventionEffectImpl {
private FilterPermanent filter;
protected final FilterPermanent filter;
public PreventAllDamageByAllPermanentsEffect(Duration duration) {
this(null, duration, false);
@ -30,13 +29,12 @@ public class PreventAllDamageByAllPermanentsEffect extends PreventionEffectImpl
public PreventAllDamageByAllPermanentsEffect(FilterPermanent filter, Duration duration, boolean onlyCombat) {
super(duration, Integer.MAX_VALUE, onlyCombat);
this.filter = filter;
setText();
}
public PreventAllDamageByAllPermanentsEffect(final PreventAllDamageByAllPermanentsEffect effect) {
super(effect);
if (effect.filter != null) {
this.filter = effect.filter.copy();
}
this.filter = effect.filter;
}
@Override
@ -61,11 +59,7 @@ public class PreventAllDamageByAllPermanentsEffect extends PreventionEffectImpl
return false;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
private void setText() {
StringBuilder sb = new StringBuilder("prevent all ");
if (onlyCombat) {
sb.append("combat ");
@ -78,6 +72,6 @@ public class PreventAllDamageByAllPermanentsEffect extends PreventionEffectImpl
sb.append(" by ");
sb.append(filter.getMessage());
}
return sb.toString();
staticText = sb.toString();
}
}

View file

@ -0,0 +1,54 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.constants.Duration;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
/**
*
* @author awjackson
*/
public class PreventAllDamageToSourceByPermanentsEffect extends PreventAllDamageByAllPermanentsEffect {
public PreventAllDamageToSourceByPermanentsEffect(FilterPermanent filter) {
this(filter, false);
}
public PreventAllDamageToSourceByPermanentsEffect(FilterPermanent filter, boolean onlyCombat) {
this(filter, Duration.WhileOnBattlefield, onlyCombat);
}
public PreventAllDamageToSourceByPermanentsEffect(FilterPermanent filter, Duration duration, boolean onlyCombat) {
super(filter, duration, onlyCombat);
setText();
}
public PreventAllDamageToSourceByPermanentsEffect(final PreventAllDamageToSourceByPermanentsEffect effect) {
super(effect);
}
public PreventAllDamageToSourceByPermanentsEffect copy() {
return new PreventAllDamageToSourceByPermanentsEffect(this);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return super.applies(event, source, game) && event.getTargetId().equals(source.getSourceId());
}
private void setText() {
StringBuilder sb = new StringBuilder("prevent all ");
if (onlyCombat) {
sb.append("combat ");
}
sb.append("damage that would be dealt to {this} ");
if (duration == Duration.EndOfTurn) {
sb.append("this turn ");
}
sb.append("by ");
sb.append(filter.getMessage());
staticText = sb.toString();
}
}

View file

@ -1,5 +1,3 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
@ -16,9 +14,8 @@ public class PreventAllDamageToSourceEffect extends PreventionEffectImpl {
public PreventAllDamageToSourceEffect(Duration duration) {
super(duration, Integer.MAX_VALUE, false);
//Some durations have no text
if ( duration.toString().length()>0){
staticText = "Prevent all damage that would be dealt to {this} " + duration.toString();
if (duration == Duration.EndOfTurn) {
staticText = "Prevent all damage that would be dealt to {this} this turn";
} else {
staticText = "Prevent all damage that would be dealt to {this}";
}
@ -35,12 +32,6 @@ public class PreventAllDamageToSourceEffect extends PreventionEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getSourceId())) {
return true;
}
}
return false;
return super.applies(event, source, game) && event.getTargetId().equals(source.getSourceId());
}
}

View file

@ -1,8 +1,7 @@
package mage.filter.common;
import mage.constants.CardType;
import mage.constants.SubType;
/**
*
@ -19,6 +18,12 @@ public class FilterControlledLandPermanent extends FilterControlledPermanent {
this.add(CardType.LAND.getPredicate());
}
public FilterControlledLandPermanent(SubType subtype, String name) {
super(name);
this.add(CardType.LAND.getPredicate());
this.add(subtype.getPredicate());
}
public FilterControlledLandPermanent(final FilterControlledLandPermanent filter) {
super(filter);
}
@ -27,5 +32,4 @@ public class FilterControlledLandPermanent extends FilterControlledPermanent {
public FilterControlledLandPermanent copy() {
return new FilterControlledLandPermanent(this);
}
}