[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

@ -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;
}
}