use of mage.abilities.effects.Effect in project mage by magefree.
the class WithdrawEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
effect.apply(game, source);
Permanent secondCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (secondCreature != null) {
Player creatureController = game.getPlayer(secondCreature.getControllerId());
if (creatureController != null) {
Cost cost = ManaUtil.createManaCost(1, false);
if (creatureController.chooseUse(Outcome.Benefit, "Pay {1}? (Otherwise " + secondCreature.getName() + " will be returned to its owner's hand)", source, game)) {
cost.pay(source, game, source, creatureController.getId(), false);
}
if (!cost.isPaid()) {
creatureController.moveCards(secondCreature, Zone.HAND, source, game);
}
}
}
return true;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class SimulatedPlayer2 method optimizeOptions.
protected List<Ability> optimizeOptions(Game game, List<Ability> options, Ability ability) {
if (options.isEmpty()) {
return options;
}
// determine if all effects are bad or good
Iterator<Ability> iterator = options.iterator();
boolean bad = true;
boolean good = true;
// TODO: add custom outcome from ability?
for (Effect effect : ability.getEffects()) {
if (effect.getOutcome().isGood()) {
bad = false;
} else {
good = false;
}
}
if (bad) {
// remove its own creatures, player itself for bad effects with one target
while (iterator.hasNext()) {
Ability ability1 = iterator.next();
if (ability1.getTargets().size() == 1 && ability1.getTargets().get(0).getTargets().size() == 1) {
Permanent permanent = game.getPermanent(ability1.getFirstTarget());
if (permanent != null && !game.getOpponents(playerId).contains(permanent.getControllerId())) {
iterator.remove();
continue;
}
if (ability1.getFirstTarget().equals(playerId)) {
iterator.remove();
}
}
}
}
if (good) {
// remove opponent creatures and opponent for only good effects with one target
while (iterator.hasNext()) {
Ability ability1 = iterator.next();
if (ability1.getTargets().size() == 1 && ability1.getTargets().get(0).getTargets().size() == 1) {
Permanent permanent = game.getPermanent(ability1.getFirstTarget());
if (permanent != null && game.getOpponents(playerId).contains(permanent.getControllerId())) {
iterator.remove();
continue;
}
if (game.getOpponents(playerId).contains(ability1.getFirstTarget())) {
iterator.remove();
}
}
}
}
return options;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class BloodSeekerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
EntersTheBattlefieldEvent zEvent = (EntersTheBattlefieldEvent) event;
Card card = zEvent.getTarget();
if (card != null && card.isCreature(game)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
}
return true;
}
}
return false;
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class BlightningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayerOrPlaneswalkerController(source.getFirstTarget());
if (player == null) {
return false;
}
Effect effect = new DiscardTargetEffect(2);
effect.setTargetPointer(new FixedTarget(player.getId(), game));
return effect.apply(game, source);
}
use of mage.abilities.effects.Effect in project mage by magefree.
the class ClockworkBeetleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
Effect effect = new RemoveCounterTargetEffect(CounterType.P1P1.createInstance());
effect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(effect), source);
return true;
}
return false;
}
Aggregations