use of mage.ObjectColor in project mage by magefree.
the class ConvokeEffect method getManaOptions.
@Override
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
ManaOptions options = new ManaOptions();
FilterControlledCreaturePermanent filterBasic = new FilterControlledCreaturePermanent();
// each creature can give {1} or color mana
game.getBattlefield().getActivePermanents(filterBasic, source.getControllerId(), source.getSourceId(), game).stream().filter(permanent -> !permanent.isTapped()).forEach(permanent -> {
ManaOptions permMana = new ManaOptions();
permMana.add(Mana.GenericMana(1));
for (ObjectColor color : permanent.getColor(game).getColors()) {
if (color.isBlack())
permMana.add(Mana.BlackMana(1));
if (color.isBlue())
permMana.add(Mana.BlueMana(1));
if (color.isGreen())
permMana.add(Mana.GreenMana(1));
if (color.isRed())
permMana.add(Mana.RedMana(1));
if (color.isWhite())
permMana.add(Mana.WhiteMana(1));
}
options.addMana(permMana);
});
options.removeDuplicated();
return options;
}
use of mage.ObjectColor in project mage by magefree.
the class BecomesColorOrColorsEnchantedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (enchantment == null) {
return false;
}
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
StringBuilder sb = new StringBuilder();
if (controller == null || permanent == null) {
return false;
}
for (int i = 0; i < 5; i++) {
if (i > 0) {
if (!controller.chooseUse(Outcome.Neutral, "Choose another color?", source, game)) {
break;
}
}
ChoiceColor choiceColor = new ChoiceColor();
if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
return false;
}
if (!game.isSimulation()) {
game.informPlayers(permanent.getName() + ": " + controller.getLogName() + " has chosen " + choiceColor.getChoice());
}
if (choiceColor.getColor().isBlack()) {
sb.append('B');
} else if (choiceColor.getColor().isBlue()) {
sb.append('U');
} else if (choiceColor.getColor().isRed()) {
sb.append('R');
} else if (choiceColor.getColor().isGreen()) {
sb.append('G');
} else if (choiceColor.getColor().isWhite()) {
sb.append('W');
}
}
String colors = new String(sb);
ObjectColor chosenColors = new ObjectColor(colors);
ContinuousEffect effect = new BecomesColorTargetEffect(chosenColors, Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
return true;
}
use of mage.ObjectColor in project mage by magefree.
the class EmptyShrineKannushiProtectionAbility method canTarget.
@Override
public boolean canTarget(MageObject source, Game game) {
ObjectColor color = new ObjectColor();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerId)) {
ObjectColor permanentColor = permanent.getColor(game);
if (permanentColor.isColorless()) {
continue;
}
if (permanentColor.isBlack()) {
color.setBlack(true);
}
if (permanentColor.isBlue()) {
color.setBlue(true);
}
if (permanentColor.isGreen()) {
color.setGreen(true);
}
if (permanentColor.isRed()) {
color.setRed(true);
}
if (permanentColor.isWhite()) {
color.setWhite(true);
}
}
List<Predicate<MageObject>> colorPredicates = new ArrayList<>();
if (color.isBlack()) {
colorPredicates.add(new ColorPredicate(ObjectColor.BLACK));
}
if (color.isBlue()) {
colorPredicates.add(new ColorPredicate(ObjectColor.BLUE));
}
if (color.isGreen()) {
colorPredicates.add(new ColorPredicate(ObjectColor.GREEN));
}
if (color.isRed()) {
colorPredicates.add(new ColorPredicate(ObjectColor.RED));
}
if (color.isWhite()) {
colorPredicates.add(new ColorPredicate(ObjectColor.WHITE));
}
Filter protectionFilter = new FilterObject("the colors of permanents you control");
protectionFilter.add(Predicates.or(colorPredicates));
this.filter = protectionFilter;
return super.canTarget(source, game);
}
use of mage.ObjectColor in project mage by magefree.
the class GauntletOfPowerManaEffect2 method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
TappedForManaEvent mEvent = (TappedForManaEvent) event;
Permanent permanent = mEvent.getPermanent();
if (permanent == null || !permanent.isLand() || !permanent.isBasic()) {
return false;
}
ObjectColor color = (ObjectColor) game.getState().getValue(getSourceId() + "_color");
if (color == null) {
return false;
}
Mana mana = mEvent.getMana();
if ((!color.isBlack() || mana.getBlack() < 1) && (!color.isBlue() || mana.getBlue() < 1) && (!color.isGreen() || mana.getGreen() < 1) && (!color.isWhite() || mana.getWhite() < 1) && (!color.isRed() || mana.getRed() < 1)) {
return false;
}
getEffects().setValue("mana", mEvent.getMana());
getEffects().setTargetPointer(new FixedTarget(permanent, game));
return true;
}
use of mage.ObjectColor in project mage by magefree.
the class TabletOfTheGuildsGainLifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
if (you != null) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
ObjectColor color1 = new ObjectColor((String) game.getState().getValue(source.getSourceId() + "_color1"));
ObjectColor color2 = new ObjectColor((String) game.getState().getValue(source.getSourceId() + "_color2"));
int amount = 0;
if (spell.getColor(game).contains(color1)) {
++amount;
}
if (spell.getColor(game).contains(color2)) {
++amount;
}
if (amount > 0) {
you.gainLife(amount, game, source);
return true;
}
}
}
return false;
}
Aggregations