use of mage.ObjectColor in project mage by magefree.
the class ProtectionChosenColorTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
if (target != null) {
ChoiceColor colorChoice = new ChoiceColor();
if (!controller.choose(Outcome.Benefit, colorChoice, game)) {
return false;
}
game.informPlayers(target.getName() + ": " + controller.getLogName() + " has chosen " + colorChoice.getChoice());
game.getState().setValue(target.getId() + "_color", colorChoice.getColor());
ObjectColor protectColor = (ObjectColor) game.getState().getValue(target.getId() + "_color");
if (protectColor != null) {
ContinuousEffect effect = new ProtectionChosenColorTargetEffect();
game.addEffect(effect, source);
ObjectColor color = target.getColor(game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (!permanent.getId().equals(target.getId()) && permanent.getColor(game).shares(color)) {
game.getState().setValue(permanent.getId() + "_color", colorChoice.getColor());
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
}
return false;
}
use of mage.ObjectColor in project mage by magefree.
the class ManaCanBeSpentAsAnyColorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ObjectColor colorless = new ObjectColor();
// permaments
for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
perm.getColor(game).setColor(colorless);
}
List<Card> affectedCards = new ArrayList<>();
// spells
for (MageObject object : game.getStack()) {
if (object instanceof Spell) {
game.getState().getCreateMageObjectAttribute(object, game).getColor().setColor(colorless);
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().setColor(colorless);
// mdf cards
if (card instanceof ModalDoubleFacesCard) {
ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
}
// split cards
if (card instanceof SplitCard) {
SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
}
// double faces cards
if (card.getSecondCardFace() != null) {
game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
}
});
return true;
}
return false;
}
use of mage.ObjectColor in project mage by magefree.
the class MostCommonColorCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent[] colorFilters = new FilterPermanent[6];
int i = 0;
for (ObjectColor color : ObjectColor.getAllColors()) {
colorFilters[i] = new FilterPermanent();
colorFilters[i].add(new ColorPredicate(color));
if (predicate != null) {
colorFilters[i].add(predicate);
}
i++;
}
int[] colorCounts = new int[6];
i = 0;
for (ObjectColor color : ObjectColor.getAllColors()) {
colorFilters[i].add(new ColorPredicate(color));
colorCounts[i] = game.getBattlefield().count(colorFilters[i], source.getId(), source.getControllerId(), game);
i++;
}
int max = 0;
for (i = 0; i < 5; i++) {
if (colorCounts[i] > max) {
max = colorCounts[i] * 1;
}
}
i = 0;
ObjectColor commonest = new ObjectColor();
for (ObjectColor color : ObjectColor.getAllColors()) {
if (colorCounts[i] == max) {
commonest.addColor(color);
}
i++;
}
if (compareColor.shares(commonest)) {
if (isMono) {
return !commonest.isMulticolored();
} else {
return true;
}
}
return false;
}
use of mage.ObjectColor in project mage by magefree.
the class MorphAbility method setPermanentToFaceDownCreature.
public static void setPermanentToFaceDownCreature(MageObject mageObject, Game game) {
mageObject.getPower().modifyBaseValue(2);
mageObject.getToughness().modifyBaseValue(2);
mageObject.getAbilities().clear();
mageObject.getColor(game).setColor(new ObjectColor());
mageObject.setName("");
mageObject.removeAllCardTypes(game);
mageObject.addCardType(game, CardType.CREATURE);
mageObject.removeAllSubTypes(game);
mageObject.getSuperType().clear();
mageObject.getManaCost().clear();
if (mageObject instanceof Permanent) {
((Permanent) mageObject).setExpansionSetCode("");
((Permanent) mageObject).setRarity(Rarity.SPECIAL);
}
}
use of mage.ObjectColor in project mage by magefree.
the class CommandersPlateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Permanent permanent = null;
if (affectedObjectsSet) {
permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent == null) {
discard();
return true;
}
} else {
Permanent equipment = game.getPermanent(source.getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
permanent = game.getPermanentOrLKIBattlefield(equipment.getAttachedTo());
}
}
Set<UUID> commanders = game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER, false);
if (commanders.isEmpty()) {
return false;
}
ObjectColor color = new ObjectColor("WUBRG");
for (UUID commanderId : commanders) {
Card card = game.getCard(commanderId);
if (card == null) {
continue;
}
FilterMana identity = card.getColorIdentity();
if (identity.isWhite()) {
color.setWhite(false);
}
if (identity.isBlue()) {
color.setBlue(false);
}
if (identity.isBlack()) {
color.setBlack(false);
}
if (identity.isRed()) {
color.setRed(false);
}
if (identity.isGreen()) {
color.setGreen(false);
}
}
if (permanent != null) {
permanent.addAbility(ProtectionAbility.from(color), source.getSourceId(), game);
}
return true;
}
Aggregations