mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 13:32:06 -08:00
reworked alara heralds
This commit is contained in:
parent
e56264ff74
commit
01b797f494
10 changed files with 152 additions and 118 deletions
|
|
@ -103,7 +103,9 @@ public class SacrificeTargetCost extends CostImpl {
|
|||
if (target.getMinNumberOfTargets() != target.getMaxNumberOfTargets()) {
|
||||
return target.getTargetName();
|
||||
}
|
||||
if (target.getNumberOfTargets() == 1) {
|
||||
if (target.getNumberOfTargets() == 1
|
||||
|| target.getTargetName().startsWith("a ")
|
||||
|| target.getTargetName().startsWith("an ")) {
|
||||
return CardUtil.addArticle(target.getTargetName());
|
||||
}
|
||||
return CardUtil.numberToText(target.getNumberOfTargets()) + ' ' + target.getTargetName();
|
||||
|
|
|
|||
|
|
@ -4,21 +4,20 @@ import mage.abilities.dynamicvalue.RoleAssignment;
|
|||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ColorAssignment extends RoleAssignment<String> {
|
||||
|
||||
public ColorAssignment() {
|
||||
super("W", "U", "B", "R", "G");
|
||||
public ColorAssignment(String... colors) {
|
||||
super(colors);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> makeSet(Card card, Game game) {
|
||||
Set<String> strings = new HashSet<>();
|
||||
for (char c : card.getColor(game).toString().toCharArray()) {
|
||||
strings.add("" + c);
|
||||
}
|
||||
return strings;
|
||||
return Arrays.stream(card.getColor(game).toString().split(""))
|
||||
.filter(attributes::contains)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
package mage.target.common;
|
||||
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.common.ColorAssignment;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class TargetControlledCreatureEachColor extends TargetControlledPermanent {
|
||||
|
||||
private final ColorAssignment colorAssigner;
|
||||
|
||||
private static final FilterControlledPermanent makeFilter(String colors) {
|
||||
List<ObjectColor> objectColors
|
||||
= Arrays.stream(colors.split(""))
|
||||
.map(ObjectColor::new)
|
||||
.collect(Collectors.toList());
|
||||
FilterControlledPermanent filter
|
||||
= new FilterControlledCreaturePermanent(CardUtil.concatWithAnd(
|
||||
objectColors
|
||||
.stream()
|
||||
.map(ObjectColor::getDescription)
|
||||
.map(s -> CardUtil.addArticle(s) + " creature")
|
||||
.collect(Collectors.toList())
|
||||
));
|
||||
filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList())));
|
||||
return filter;
|
||||
}
|
||||
|
||||
public TargetControlledCreatureEachColor(String colors) {
|
||||
super(colors.length(), makeFilter(colors));
|
||||
colorAssigner = new ColorAssignment(colors.split(""));
|
||||
}
|
||||
|
||||
private TargetControlledCreatureEachColor(final TargetControlledCreatureEachColor target) {
|
||||
super(target);
|
||||
this.colorAssigner = target.colorAssigner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
|
||||
if (!super.canTarget(playerId, id, source, game)) {
|
||||
return false;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getTargets().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
Cards cards = new CardsImpl(this.getTargets());
|
||||
cards.add(permanent);
|
||||
return colorAssigner.getRoleCount(cards, game) >= cards.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetControlledCreatureEachColor copy() {
|
||||
return new TargetControlledCreatureEachColor(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -1338,4 +1338,27 @@ public final class CardUtil {
|
|||
// normal game
|
||||
return "T" + gameState.getTurnNum() + "." + gameState.getTurn().getStep().getType().getStepShortText();
|
||||
}
|
||||
|
||||
public static String concatWithAnd(List<String> strings) {
|
||||
switch (strings.size()) {
|
||||
case 0:
|
||||
return "";
|
||||
case 1:
|
||||
return strings.get(0);
|
||||
case 2:
|
||||
return strings.get(0) + " and " + strings.get(1);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
sb.append(strings.get(i));
|
||||
if (i == strings.size() - 1) {
|
||||
break;
|
||||
}
|
||||
sb.append(", ");
|
||||
if (i == strings.size() - 2) {
|
||||
sb.append("and ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue