use of mage.abilities.Ability in project mage by magefree.
the class SparkFiendUpkeepEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int roll = controller.rollDice(outcome, source, game, 6, 2, 0).stream().mapToInt(x -> x).sum();
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject instanceof Permanent) {
Permanent sourcePermanent = (Permanent) mageObject;
if (roll == 2 || roll == 3 || roll == 12) {
// sacrifice
sourcePermanent.sacrifice(source, game);
} else if (roll == 7 || roll == 11) {
// don't roll again
game.getState().setValue("SparkFiend" + source.getSourceId().toString(), 0);
// might apply if this ability was copied
sourcePermanent.addInfo("roll counter", CardUtil.addToolTipMarkTags(""), game);
} else {
// note that total
game.getState().setValue("SparkFiend" + source.getSourceId().toString(), roll);
sourcePermanent.addInfo("roll counter", CardUtil.addToolTipMarkTags("Noted roll: " + roll), game);
}
}
return true;
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class TakenoSamuraiGeneralEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (this.affectedObjectsSet) {
for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
// filter may not be used again, because object can have changed filter relevant attributes but still geets boost
Permanent permanent = it.next().getPermanent(game);
if (permanent != null) {
for (Ability ability : permanent.getAbilities()) {
if (ability instanceof BushidoAbility) {
int value = ((BushidoAbility) ability).getValue(source, game, this);
permanent.addPower(value);
permanent.addToughness(value);
}
}
} else {
// no longer on the battlefield, remove reference to object
it.remove();
}
}
} else {
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
if (!perm.getId().equals(source.getSourceId())) {
for (Ability ability : perm.getAbilities()) {
if (ability instanceof BushidoAbility) {
int value = ((BushidoAbility) ability).getValue(source, game, this);
perm.addPower(value);
perm.addToughness(value);
}
}
}
}
}
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class VesuvanDoppelgangerCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = game.getPermanentEntering(source.getSourceId());
}
final Permanent sourcePermanent = permanent;
if (controller != null && sourcePermanent != null) {
Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
target.setRequired(true);
if (source instanceof SimpleStaticAbility) {
target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
target.setRequired(false);
target.setNotTarget(true);
}
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent != null) {
game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
blueprint.getColor().setColor(sourcePermanent.getColor(game));
blueprint.getAbilities().add(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new VesuvanDoppelgangerCopyEffect(), TargetController.YOU, true, false, rule2));
return true;
}
});
return true;
}
}
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class ViashinoBeyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
TargetOpponent targetDefender = new TargetOpponent();
if (controller != null) {
game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game).stream().filter((permanent) -> (filter.match(permanent, source.getSourceId(), source.getControllerId(), game))).forEachOrdered((permanent) -> {
if (game.getOpponents(controller.getId()).size() > 1) {
controller.choose(outcome.Benefit, targetDefender, source.getSourceId(), game);
} else {
targetDefender.add(game.getOpponents(controller.getId()).iterator().next(), game);
}
if (permanent.canAttack(targetDefender.getFirstTarget(), game)) {
controller.declareAttacker(permanent.getId(), targetDefender.getFirstTarget(), game, false);
}
});
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class WordOfCommandTestFlashEffect method checkPlayability.
private boolean checkPlayability(Card card, Player targetPlayer, Game game, Ability source) {
// check for card playability
boolean canPlay = false;
if (card.isLand(game)) {
// we can't use getPlayableObjects(game) in here because it disallows playing lands outside the main step // TODO: replace to getPlayable() checks with disable step condition?
if (targetPlayer.canPlayLand() && game.getActivePlayerId().equals(targetPlayer.getId())) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof PlayLandAbility) {
if (!game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability, targetPlayer.getId()), ability, game, true)) {
canPlay = true;
}
}
}
}
} else {
// Word of Command allows the chosen card to be played "as if it had flash" so we need to invoke such effect to bypass the check
AsThoughEffectImpl effect2 = new WordOfCommandTestFlashEffect();
game.addEffect(effect2, source);
if (targetPlayer.getPlayableObjects(game, Zone.HAND).containsObject(card.getId())) {
canPlay = true;
}
for (AsThoughEffect eff : game.getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.CAST_AS_INSTANT, game)) {
if (eff instanceof WordOfCommandTestFlashEffect) {
eff.discard();
break;
}
}
}
return canPlay;
}
Aggregations