mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
[LTC] Implement Fealty to the Realm
This commit is contained in:
parent
0d6929caa8
commit
a754fb672a
12 changed files with 124 additions and 55 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue