use of mage.ObjectColor in project mage by magefree.
the class CallToArmsStateTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
UUID playerId = (UUID) game.getState().getValue(source.getSourceId() + ChooseOpponentEffect.VALUE_KEY);
if (permanent != null) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
Condition condition = new MostCommonColorCondition(color, true, new ControllerIdPredicate(playerId));
if (condition.apply(game, source)) {
Effect effect = new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter, false);
return effect.apply(game, source);
}
}
}
return false;
}
use of mage.ObjectColor in project mage by magefree.
the class CallToArmsStateTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent permanent = game.getPermanent(getSourceId());
UUID playerId = (UUID) game.getState().getValue(getSourceId() + ChooseOpponentEffect.VALUE_KEY);
if (permanent != null) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
Condition condition = new MostCommonColorCondition(color, true, new ControllerIdPredicate(playerId));
return !condition.apply(game, this);
}
}
return false;
}
use of mage.ObjectColor in project mage by magefree.
the class ChromeMoxManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Permanent permanent = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (permanent != null && player != null) {
List<UUID> imprinted = permanent.getImprinted();
if (imprinted != null && !imprinted.isEmpty()) {
Card imprintedCard = game.getCard(imprinted.get(0));
if (imprintedCard != null) {
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick a mana color");
ObjectColor color = imprintedCard.getColor(game);
if (color.isBlack()) {
choice.getChoices().add("Black");
}
if (color.isRed()) {
choice.getChoices().add("Red");
}
if (color.isBlue()) {
choice.getChoices().add("Blue");
}
if (color.isGreen()) {
choice.getChoices().add("Green");
}
if (color.isWhite()) {
choice.getChoices().add("White");
}
if (!choice.getChoices().isEmpty()) {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
return mana;
}
}
switch(choice.getChoice()) {
case "Black":
// player.getManaPool().addMana(Mana.BlackMana(1), game, source);
mana.add(Mana.BlackMana(1));
break;
case "Blue":
// player.getManaPool().addMana(Mana.BlueMana(1), game, source);
mana.add(Mana.BlueMana(1));
break;
case "Red":
// player.getManaPool().addMana(Mana.RedMana(1), game, source);
mana.add(Mana.RedMana(1));
break;
case "Green":
// player.getManaPool().addMana(Mana.GreenMana(1), game, source);
mana.add(Mana.GreenMana(1));
break;
case "White":
// player.getManaPool().addMana(Mana.WhiteMana(1), game, source);
mana.add(Mana.WhiteMana(1));
break;
default:
break;
}
}
}
}
}
return mana;
}
use of mage.ObjectColor in project mage by magefree.
the class GrindstoneEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (targetPlayer != null) {
int possibleIterations = targetPlayer.getLibrary().size() / 2;
int iteration = 0;
boolean colorShared;
do {
iteration++;
if (iteration > possibleIterations + 20) {
// 801.16. If the game somehow enters a "loop" of mandatory actions, repeating a sequence of events
// with no way to stop, the game is a draw for each player who controls an object that's involved in
// that loop, as well as for each player within the range of influence of any of those players. They
// leave the game. All remaining players continue to play the game.
game.setDraw(source.getControllerId());
return true;
}
colorShared = false;
List<Card> cards = targetPlayer.millCards(2, source, game).getCards(game).stream().collect(Collectors.toList());
if (cards.size() < 2) {
break;
}
for (int i = 0; i < cards.size(); i++) {
if (colorShared) {
break;
}
ObjectColor color1 = cards.get(i).getColor(game);
if (color1.isColorless()) {
continue;
}
for (int j = 0; j < cards.size(); j++) {
if (i >= j) {
continue;
}
ObjectColor color2 = cards.get(j).getColor(game);
if (color1.shares(color2)) {
colorShared = true;
break;
}
}
}
} while (colorShared);
return true;
}
return false;
}
use of mage.ObjectColor in project mage by magefree.
the class HeraldicBannerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return false;
}
ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
if (color == null) {
return false;
}
for (Permanent perm : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (perm.getColor(game).contains(color)) {
perm.addPower(1);
}
}
return true;
}
Aggregations