[DOM] Added Shield of the Realm.

This commit is contained in:
LevelX2 2018-04-18 15:18:23 +02:00
parent 3daa66f396
commit 26ce05b42d
5 changed files with 115 additions and 29 deletions

View file

@ -25,11 +25,11 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.PreventionEffectImpl;
import mage.constants.AttachmentType;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.DamageEvent;
@ -40,49 +40,65 @@ import mage.game.permanent.Permanent;
*
* @author LevelX2
*/
public class PreventAllDamageToAttachedEffect extends PreventionEffectImpl {
public class PreventDamageToAttachedEffect extends PreventionEffectImpl {
private final String attachedDescription;
protected AttachmentType attachmentType;
public PreventAllDamageToAttachedEffect(Duration duration, String attachedDescription, boolean combatOnly) {
super(duration, Integer.MAX_VALUE, false);
this.attachedDescription = attachedDescription;
public PreventDamageToAttachedEffect(Duration duration, AttachmentType attachmentType, boolean combatOnly) {
this(duration, attachmentType, Integer.MAX_VALUE, combatOnly);
}
public PreventDamageToAttachedEffect(Duration duration, AttachmentType attachmentType, int amountToPrevent, boolean combatOnly) {
super(duration, Integer.MAX_VALUE, false, false);
this.attachmentType = attachmentType;
staticText = setText();
}
public PreventAllDamageToAttachedEffect(final PreventAllDamageToAttachedEffect effect) {
public PreventDamageToAttachedEffect(final PreventDamageToAttachedEffect effect) {
super(effect);
this.attachedDescription = effect.attachedDescription;
this.attachmentType = effect.attachmentType;
}
@Override
public PreventAllDamageToAttachedEffect copy() {
return new PreventAllDamageToAttachedEffect(this);
public PreventDamageToAttachedEffect copy() {
return new PreventDamageToAttachedEffect(this);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
if (!onlyCombat || ((DamageEvent)event).isCombatDamage()) {
if (!onlyCombat || ((DamageEvent) event).isCombatDamage()) {
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment != null
if (attachment != null
&& attachment.getAttachedTo() != null) {
if (event.getTargetId().equals(attachment.getAttachedTo())) {
return true;
}
}
}
}
}
return false;
}
private String setText() {
StringBuilder sb = new StringBuilder("Prevent all ");
if (onlyCombat) {
sb.append("combat ");
StringBuilder sb = new StringBuilder();
if (amountToPrevent == Integer.MAX_VALUE) {
sb.append("prevent all ");
if (onlyCombat) {
sb.append("combat ");
}
sb.append("damage that would be dealt to ");
sb.append(attachmentType.toString()).append(" creature");
} else {
sb.append("If a source would deal ");
if (onlyCombat) {
sb.append("combat ");
}
sb.append("damage to ");
sb.append(attachmentType.toString());
sb.append("creature, prevent ").append(amountToPrevent);;
sb.append("of that damage");
}
sb.append("damage that would be dealt to ");
sb.append(attachedDescription);
return sb.toString();
}
}