use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class OfferingCostReductionEffect method applies.
@Override
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
if (sourceId.equals(source.getSourceId())) {
Card card = game.getCard(sourceId);
if (card == null || !card.isOwnedBy(source.getControllerId())) {
return false;
}
// because can activate is always called twice, result from first call will be used
Object object = game.getState().getValue("offering_" + card.getId());
if (object != null && object.equals(true)) {
Object alreadyConfirmed = game.getState().getValue("offering_ok_" + card.getId());
game.getState().setValue("offering_" + card.getId(), null);
game.getState().setValue("offering_ok_" + card.getId(), null);
return alreadyConfirmed != null;
} else {
// first call -> remove previous Ids
game.getState().setValue("offering_Id_" + card.getId(), null);
}
if (game.getBattlefield().count(((OfferingAbility) source).getFilter(), source.getSourceId(), source.getControllerId(), game) > 0) {
if (game.inCheckPlayableState()) {
return true;
}
FilterControlledCreaturePermanent filter = ((OfferingAbility) source).getFilter();
Card spellToCast = game.getCard(source.getSourceId());
if (spellToCast == null) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) {
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
player.chooseTarget(Outcome.Sacrifice, target, source, game);
if (!target.isChosen()) {
return false;
}
game.getState().setValue("offering_" + card.getId(), true);
Permanent offer = game.getPermanent(target.getFirstTarget());
if (offer != null) {
UUID activationId = UUID.randomUUID();
OfferingCostReductionEffect effect = new OfferingCostReductionEffect(activationId);
effect.setTargetPointer(new FixedTarget(offer, game));
game.addEffect(effect, source);
game.getState().setValue("offering_ok_" + card.getId(), true);
game.getState().setValue("offering_Id_" + card.getId(), activationId);
game.informPlayers(player.getLogName() + " announces to offer " + offer.getLogName() + " to cast " + // No id name to prevent to offer hand card knowledge after cancel casting
GameLog.getColoredObjectName(spellToCast));
return true;
}
} else {
game.getState().setValue("offering_" + card.getId(), true);
}
}
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class HeartmenderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean applied = false;
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
if (game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) {
return true;
}
for (Permanent creature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
if (creature != null && creature.getCounters(game).getCount(counter.getName()) >= counter.getCount()) {
creature.removeCounters(counter.getName(), counter.getCount(), source, game);
game.informPlayers("Removed " + counter.getCount() + ' ' + counter.getName() + " counter from " + creature.getName());
applied = true;
}
}
return applied;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class InvokePrejudiceEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game.getOpponents(getControllerId()).contains(event.getPlayerId())) {
Spell spell = (Spell) game.getObject(event.getTargetId());
if (spell != null && spell.isCreature(game)) {
boolean creatureSharesAColor = false;
ObjectColor spellColor = spell.getColor(game);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), getControllerId(), game)) {
if (spellColor.shares(permanent.getColor(game))) {
creatureSharesAColor = true;
break;
}
}
if (!creatureSharesAColor) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}
}
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class DescendantsPathEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
if (controller.getLibrary().hasCards()) {
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
if (card.isCreature(game)) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
boolean found = false;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
if (card.shareCreatureTypes(game, permanent)) {
found = true;
break;
}
}
if (found) {
game.informPlayers(sourceObject.getLogName() + ": Found a creature that shares a creature type with the revealed card.");
if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
} else {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card.");
controller.getLibrary().putOnBottom(card, game);
}
} else {
game.informPlayers(sourceObject.getLogName() + ": No creature that shares a creature type with the revealed card.");
controller.getLibrary().putOnBottom(card, game);
}
} else {
game.informPlayers(sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom.");
controller.getLibrary().putOnBottom(card, game);
}
return true;
}
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class GoblinGoonCantBlockEffect method canAttack.
@Override
public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game, boolean canUseChooseDialogs) {
if (defenderId == null) {
return true;
}
UUID defendingPlayerId;
Player defender = game.getPlayer(defenderId);
if (defender == null) {
Permanent permanent = game.getPermanent(defenderId);
if (permanent != null) {
defendingPlayerId = permanent.getControllerId();
} else {
return false;
}
} else {
defendingPlayerId = defenderId;
}
if (defendingPlayerId != null) {
return game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defendingPlayerId, game);
} else {
return true;
}
}
Aggregations