[LTC] Implement Fealty to the Realm

This commit is contained in:
theelk801 2023-06-10 12:28:29 -04:00
parent 0d6929caa8
commit a754fb672a
12 changed files with 124 additions and 55 deletions

View file

@ -40,7 +40,7 @@ public final class AssaultSuit extends CardImpl {
Effect effect = new GainAbilityAttachedEffect(HasteAbility.getInstance(), AttachmentType.EQUIPMENT);
effect.setText(", has haste");
ability.addEffect(effect);
effect = new CantAttackControllerAttachedEffect(AttachmentType.EQUIPMENT);
effect = new CantAttackControllerAttachedEffect(AttachmentType.EQUIPMENT, true);
effect.setText(", can't attack you or planeswalkers you control");
ability.addEffect(effect);
effect = new AssaultSuitCantBeSacrificed();

View file

@ -0,0 +1,91 @@
package mage.cards.f;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.BecomesMonarchSourceEffect;
import mage.abilities.effects.common.combat.AttacksIfAbleAttachedEffect;
import mage.abilities.effects.common.combat.CantAttackControllerAttachedEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class FealtyToTheRealm extends CardImpl {
public FealtyToTheRealm(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{4}{U}");
this.subtype.add(SubType.AURA);
// Enchant creature
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
this.addAbility(new EnchantAbility(auraTarget));
// When Fealty to the Realm enters the battlefield, you become the monarch.
this.addAbility(new EntersBattlefieldTriggeredAbility(new BecomesMonarchSourceEffect()));
// The monarch controls enchanted creature.
this.addAbility(new SimpleStaticAbility(new FealtyToTheRealmEffect()));
// Enchanted creature attacks each combat if able and can't attack you.
Ability ability = new SimpleStaticAbility(
new AttacksIfAbleAttachedEffect(Duration.WhileOnBattlefield, AttachmentType.AURA)
);
ability.addEffect(new CantAttackControllerAttachedEffect(AttachmentType.AURA, false));
this.addAbility(ability);
}
private FealtyToTheRealm(final FealtyToTheRealm card) {
super(card);
}
@Override
public FealtyToTheRealm copy() {
return new FealtyToTheRealm(this);
}
}
class FealtyToTheRealmEffect extends ContinuousEffectImpl {
public FealtyToTheRealmEffect() {
super(Duration.WhileOnBattlefield, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl);
staticText = "the monarch controls enchanted creature";
}
public FealtyToTheRealmEffect(final FealtyToTheRealmEffect effect) {
super(effect);
}
@Override
public FealtyToTheRealmEffect copy() {
return new FealtyToTheRealmEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent enchantment = source.getSourcePermanentIfItStillExists(game);
if (enchantment == null || game.getMonarchId() == null) {
return false;
}
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
if (permanent == null) {
return false;
}
permanent.changeControllerId(game.getMonarchId(), game, source);
return true;
}
}

View file

@ -45,7 +45,7 @@ public final class SpectralGrasp extends CardImpl {
this.addAbility(ability);
// Enchanted creature can't attack you or a planeswalker you control.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackControllerAttachedEffect(AttachmentType.AURA)));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackControllerAttachedEffect(AttachmentType.AURA, true)));
// Enchanted creature can't block creatures you control.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantBlockAttachedEffect(AttachmentType.AURA, Duration.WhileOnBattlefield, filter)));

View file

@ -44,7 +44,7 @@ public final class VowOfDuty extends CardImpl {
Effect effect = new GainAbilityAttachedEffect(VigilanceAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield);
effect.setText(", has vigilance");
ability.addEffect(effect);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA, true);
effect.setText(", and can't attack you or planeswalkers you control");
ability.addEffect(effect);
this.addAbility(ability);

View file

@ -44,7 +44,7 @@ public final class VowOfFlight extends CardImpl {
Effect effect = new GainAbilityAttachedEffect(FlyingAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield);
effect.setText(", has flying");
ability.addEffect(effect);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA, true);
effect.setText(", and can't attack you or planeswalkers you control");
ability.addEffect(effect);
this.addAbility(ability);

View file

@ -44,7 +44,7 @@ public final class VowOfLightning extends CardImpl {
Effect effect = new GainAbilityAttachedEffect(FirstStrikeAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield);
effect.setText(", has first strike");
ability.addEffect(effect);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA, true);
effect.setText(", and can't attack you or planeswalkers you control");
ability.addEffect(effect);
this.addAbility(ability);

View file

@ -44,7 +44,7 @@ public final class VowOfMalice extends CardImpl {
Effect effect = new GainAbilityAttachedEffect(IntimidateAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield);
effect.setText(", has intimidate");
ability.addEffect(effect);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA, true);
effect.setText(", and can't attack you or planeswalkers you control");
ability.addEffect(effect);
this.addAbility(ability);

View file

@ -38,7 +38,7 @@ public final class VowOfTorment extends CardImpl {
ability.addEffect(new GainAbilityAttachedEffect(
new MenaceAbility(), AttachmentType.AURA, Duration.WhileOnBattlefield
).setText(", has menace"));
ability.addEffect(new CantAttackControllerAttachedEffect(AttachmentType.AURA)
ability.addEffect(new CantAttackControllerAttachedEffect(AttachmentType.AURA, true)
.setText(", and can't attack you or planeswalkers you control. " +
"<i>(It can't be blocked except by two or more creatures.)</i>"));
this.addAbility(ability);

View file

@ -45,7 +45,7 @@ public final class VowOfWildness extends CardImpl {
Effect effect = new GainAbilityAttachedEffect(TrampleAbility.getInstance(), AttachmentType.AURA, Duration.WhileOnBattlefield);
effect.setText(", has trample");
ability.addEffect(effect);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA);
effect = new CantAttackControllerAttachedEffect(AttachmentType.AURA, true);
effect.setText(", and can't attack you or planeswalkers you control");
ability.addEffect(effect);
this.addAbility(ability);

View file

@ -81,6 +81,7 @@ public final class TalesOfMiddleEarthCommander extends ExpansionSet {
cards.add(new SetCardInfo("Faithless Looting", 215, Rarity.COMMON, mage.cards.f.FaithlessLooting.class));
cards.add(new SetCardInfo("Farhaven Elf", 243, Rarity.COMMON, mage.cards.f.FarhavenElf.class));
cards.add(new SetCardInfo("Farseek", 244, Rarity.COMMON, mage.cards.f.Farseek.class));
cards.add(new SetCardInfo("Fealty to the Realm", 21, Rarity.RARE, mage.cards.f.FealtyToTheRealm.class));
cards.add(new SetCardInfo("Feed the Swarm", 200, Rarity.COMMON, mage.cards.f.FeedTheSwarm.class));
cards.add(new SetCardInfo("Fell the Mighty", 167, Rarity.RARE, mage.cards.f.FellTheMighty.class));
cards.add(new SetCardInfo("Field of Ruin", 308, Rarity.UNCOMMON, mage.cards.f.FieldOfRuin.class));

View file

@ -13,16 +13,20 @@ import java.util.UUID;
/**
* @author LevelX2
*/
public class CantAttackControllerAttachedEffect extends RestrictionEffect {
public CantAttackControllerAttachedEffect(AttachmentType attachmentType) {
private final boolean orPlaneswalker;
public CantAttackControllerAttachedEffect(AttachmentType attachmentType, boolean orPlaneswalker) {
super(Duration.WhileOnBattlefield);
this.staticText = attachmentType.verb() + " creature can't attack you or planeswalkers you control";
this.orPlaneswalker = orPlaneswalker;
this.staticText = attachmentType.verb() + " creature can't attack you" +
(orPlaneswalker ? " or planeswalkers you control" : "");
}
public CantAttackControllerAttachedEffect(final CantAttackControllerAttachedEffect effect) {
private CantAttackControllerAttachedEffect(final CantAttackControllerAttachedEffect effect) {
super(effect);
this.orPlaneswalker = effect.orPlaneswalker;
}
@Override
@ -32,21 +36,19 @@ public class CantAttackControllerAttachedEffect extends RestrictionEffect {
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
if (defenderId == null) {
return true;
}
if (defenderId.equals(source.getControllerId())) {
if (source.isControlledBy(defenderId)) {
return false;
}
if (!orPlaneswalker) {
return true;
}
Permanent planeswalker = game.getPermanent(defenderId);
return planeswalker == null || !planeswalker.isControlledBy(source.getControllerId());
return planeswalker == null || !planeswalker.isPlaneswalker(game)
|| !planeswalker.isControlledBy(source.getControllerId());
}
@Override
public CantAttackControllerAttachedEffect copy() {
return new CantAttackControllerAttachedEffect(this);
}
}

View file

@ -8,7 +8,6 @@ import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* @author nantuko
@ -33,41 +32,17 @@ public class ControlEnchantedEffect extends ContinuousEffectImpl {
return new ControlEnchantedEffect(this);
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent enchantment = game.getPermanent(source.getSourceId());
Player controllerOfEnchantment = game.getPlayer(source.getControllerId());
if (enchantment != null
&& enchantment.getAttachedTo() != null
&& controllerOfEnchantment != null) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
if (permanent != null) {
switch (layer) {
case ControlChangingEffects_2:
if (sublayer == SubLayer.NA) {
permanent.changeControllerId(enchantment.getControllerId(), game, source);
permanent.getAbilities().forEach((ability) -> {
ability.setControllerId(enchantment.getControllerId());
});
}
break;
}
return true;
} else { //remove effect if the aura or attachedTo permanent or controller of the enchantment is null
discard();
}
}
return false;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
Permanent enchantment = source.getSourcePermanentIfItStillExists(game);
if (enchantment == null) {
return false;
}
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
if (permanent == null) {
return false;
}
permanent.changeControllerId(source.getControllerId(), game, source);
return true;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.ControlChangingEffects_2;
}
}