[DFT] Implement Ketramose, the New Dawn and implement exile condition and dynamic value

This commit is contained in:
jmlundeen 2025-02-21 21:19:34 -06:00
parent e22a3ec19f
commit cbb3012b05
4 changed files with 261 additions and 0 deletions

View file

@ -0,0 +1,34 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.abilities.dynamicvalue.common.CardsInExileCount;
import mage.constants.ComparisonType;
import mage.game.Game;
public class CardsInExileCondition implements Condition
{
private final ComparisonType type;
private final int count;
private CardsInExileCount cardsInExileCount;
public CardsInExileCondition(ComparisonType type, int count)
{
this(type, count, CardsInExileCount.YOU);
}
public CardsInExileCondition(ComparisonType type, int count, CardsInExileCount cardsInExileCount)
{
this.type = type;
this.count = count;
this.cardsInExileCount = cardsInExileCount;
}
@Override
public boolean apply(Game game, Ability source)
{
int exileCards = cardsInExileCount.calculate(game, source, null);
return ComparisonType.compare(exileCards, type, count);
}
}

View file

@ -0,0 +1,110 @@
package mage.abilities.dynamicvalue.common;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.hint.Hint;
import mage.cards.Card;
import mage.constants.CardType;
import mage.game.Game;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author JayDi85
*/
public enum CardsInExileCount implements DynamicValue {
YOU("you"),
ALL("all players"),
OPPONENTS("your opponents'");
private final String message;
private final CardsInExileHint hint;
CardsInExileCount(String message) {
this.message = "The number of cards owned by " + message + " in exile";
this.hint = new CardsInExileHint(this);
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return getExileCards(game, sourceAbility)
.mapToInt(x -> 1)
.sum();
}
@Override
public CardsInExileCount copy() {
return this;
}
@Override
public String toString() {
return "X";
}
@Override
public String getMessage() {
return message;
}
public Hint getHint() {
return hint;
}
public Stream<Card> getExileCards(Game game, Ability ability) {
Collection<UUID> playerIds;
switch (this) {
case YOU:
playerIds = Collections.singletonList(ability.getControllerId());
break;
case OPPONENTS:
playerIds = game.getOpponents(ability.getControllerId());
break;
case ALL:
playerIds = game.getState().getPlayersInRange(ability.getControllerId(), game);
break;
default:
throw new IllegalArgumentException("Wrong code usage: miss implementation for " + this);
}
return playerIds.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)
.map(player -> game.getExile().getAllCards(game, player.getId()))
.flatMap(Collection::stream)
.filter(Objects::nonNull);
}
}
class CardsInExileHint implements Hint {
CardsInExileCount value;
CardsInExileHint(CardsInExileCount value) {
this.value = value;
}
private CardsInExileHint(final CardsInExileHint hint) {
this.value = hint.value;
}
@Override
public String getText(Game game, Ability ability) {
int count = value.getExileCards(game, ability)
.mapToInt(x -> 1)
.sum();
return this.value.getMessage() + ": " + count;
}
@Override
public CardsInExileHint copy() {
return new CardsInExileHint(this);
}
}