use of mage.ObjectColor in project mage by magefree.
the class ExpansionSet method validateCommonColors.
protected boolean validateCommonColors(List<Card> booster) {
List<ObjectColor> commonColors = booster.stream().filter(card -> card.getRarity() == Rarity.COMMON).map(ExpansionSet::getColorForValidate).collect(Collectors.toList());
// for multicolor sets, count not just the colors present at common,
// but also the number of color combinations (guilds/shards/wedges)
// e.g. a booster with three UB commons, three RW commons and four G commons
// has all five colors but isn't "balanced"
ObjectColor colorsRepresented = new ObjectColor();
Set<ObjectColor> colorCombinations = new HashSet<>();
int colorlessCountPlusOne = 1;
for (ObjectColor color : commonColors) {
colorCombinations.add(color);
int colorCount = color.getColorCount();
if (colorCount == 0) {
++colorlessCountPlusOne;
} else if (colorCount > 1 && !hasOnlyMulticolorCards) {
// to prevent biasing toward multicolor over monocolor cards,
// count them as one of their colors chosen at random
List<ObjectColor> multiColor = color.getColors();
colorsRepresented.addColor(multiColor.get(RandomUtil.nextInt(multiColor.size())));
} else {
colorsRepresented.addColor(color);
}
}
int colors = Math.min(colorsRepresented.getColorCount(), colorCombinations.size());
// ("all but one" adds some leeway for sets with small boosters)
if (colors >= Math.min(5, commonColors.size() - colorlessCountPlusOne))
return true;
// otherwise, if booster is missing more than one color, reject it
if (colors < 4)
return false;
// for Torment and Judgment, always accept boosters with four out of five colors
if (hasUnbalancedColors)
return true;
// if a common was replaced by a special card, increase the chance to accept four colors
if (commonColors.size() < numBoosterCommon)
++colorlessCountPlusOne;
// otherwise, stochiastically treat each colorless card as 1/5 of a card of the missing color
return (RandomUtil.nextDouble() > Math.pow(0.8, colorlessCountPlusOne));
}
use of mage.ObjectColor in project mage by magefree.
the class AnyColorPermanentTypesManaEffect method getManaTypes.
private Mana getManaTypes(Game game, Ability source) {
Mana types = new Mana();
if (game == null || game.getPhase() == null) {
return types;
}
if (inManaTypeCalculation) {
return types;
}
inManaTypeCalculation = true;
ObjectColor permanentColor;
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
for (Permanent permanent : permanents) {
permanentColor = permanent.getColor(game);
if (permanentColor.isColorless()) {
types.add(Mana.ColorlessMana(1));
} else {
List<ObjectColor> permanentColors = permanent.getColor(game).getColors();
for (ObjectColor color : permanentColors) {
types.add(new Mana(color.getOneColoredManaSymbol()));
}
}
}
inManaTypeCalculation = false;
return types;
}
use of mage.ObjectColor in project mage by magefree.
the class GeneralTazriColorCount method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
int count = 0;
boolean black = false;
boolean red = false;
boolean white = false;
boolean green = false;
boolean blue = false;
for (Permanent creature : game.getBattlefield().getAllActivePermanents(filter, sourceAbility.getControllerId(), game)) {
ObjectColor color = creature.getColor(game);
black |= color.isBlack();
red |= color.isRed();
white |= color.isWhite();
green |= color.isGreen();
blue |= color.isBlue();
}
count += black ? 1 : 0;
count += red ? 1 : 0;
count += white ? 1 : 0;
count += green ? 1 : 0;
count += blue ? 1 : 0;
return count;
}
use of mage.ObjectColor in project mage by magefree.
the class MindExtractionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(source.getFirstTarget());
if (controller == null || player == null) {
return false;
}
Permanent sacrificedCreature = null;
for (Cost cost : source.getCosts()) {
if (!(cost instanceof SacrificeTargetCost)) {
continue;
}
SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
for (Permanent permanent : sacCost.getPermanents()) {
sacrificedCreature = permanent;
break;
}
}
if (sacrificedCreature == null) {
return false;
}
ObjectColor color = sacrificedCreature.getColor(game);
Cards cards = new CardsImpl(player.getHand());
if (cards.isEmpty()) {
return true;
}
player.revealCards(source, cards, game);
if (color.isColorless()) {
return true;
}
Cards toDiscard = new CardsImpl();
cards.getCards(game).stream().filter(card -> card.getColor(game).shares(color)).forEach(toDiscard::add);
player.discard(toDiscard, false, source, game);
return true;
}
use of mage.ObjectColor in project mage by magefree.
the class PaintersServantEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
if (color == null) {
return false;
}
// permanents
for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
perm.getColor(game).addColor(color);
}
List<Card> affectedCards = new ArrayList<>();
// stack
for (MageObject object : game.getStack()) {
if (object instanceof Spell) {
game.getState().getCreateMageObjectAttribute(object, game).getColor().addColor(color);
Card card = ((Spell) object).getCard();
affectedCards.add(card);
}
}
// exile
affectedCards.addAll(game.getExile().getAllCardsByRange(game, controller.getId()));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
// command
affectedCards.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY));
// hand
affectedCards.addAll(player.getHand().getCards(game));
// library
affectedCards.addAll(player.getLibrary().getCards(game));
// graveyard
affectedCards.addAll(player.getGraveyard().getCards(game));
}
// apply colors to all cards
affectedCards.forEach(card -> {
game.getState().getCreateMageObjectAttribute(card, game).getColor().addColor(color);
// mdf cards
if (card instanceof ModalDoubleFacesCard) {
ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color);
}
// split cards
if (card instanceof SplitCard) {
SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().addColor(color);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().addColor(color);
}
// double faces cards
if (card.getSecondCardFace() != null) {
game.getState().getCreateMageObjectAttribute(card.getSecondCardFace(), game).getColor().addColor(color);
}
});
return true;
}
return false;
}
Aggregations