[TDM] Implement Cori-Steel Cutter

This commit is contained in:
theelk801 2025-03-24 10:19:56 -04:00
parent 9f5e583566
commit 8e767c4942
3 changed files with 88 additions and 6 deletions

View file

@ -1,27 +1,37 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token;
import java.util.Optional;
/**
* @author weirddan455
*/
public class CreateTokenAttachSourceEffect extends CreateTokenEffect {
private final boolean optional;
public CreateTokenAttachSourceEffect(Token token) {
this(token, ", then");
}
public CreateTokenAttachSourceEffect(Token token, String innerConcat) {
this(token, innerConcat, false);
}
public CreateTokenAttachSourceEffect(Token token, String innerConcat, boolean optional) {
super(token);
staticText = staticText.concat(innerConcat + " attach {this} to it");
this.optional = optional;
staticText = staticText.concat(innerConcat + (optional ? " you may" : "") + " attach {this} to it");
}
private CreateTokenAttachSourceEffect(final CreateTokenAttachSourceEffect effect) {
super(effect);
this.optional = effect.optional;
}
@Override
@ -32,11 +42,22 @@ public class CreateTokenAttachSourceEffect extends CreateTokenEffect {
@Override
public boolean apply(Game game, Ability source) {
super.apply(game, source);
Permanent token = game.getPermanent(this.getLastAddedTokenIds().stream().findFirst().orElse(null));
if (token != null) {
token.addAttachment(source.getSourceId(), source, game);
return true;
Permanent token = this
.getLastAddedTokenIds()
.stream()
.findFirst()
.map(game::getPermanent)
.orElse(null);
if (token == null || optional
&& !Optional
.ofNullable(game.getPlayer(source.getControllerId()))
.map(player -> player.chooseUse(
Outcome.BoostCreature, "Attach the equipment to the token?", source, game
))
.orElse(false)) {
return false;
}
return false;
token.addAttachment(source.getSourceId(), source, game);
return true;
}
}