use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.
the class VeteranWarleaderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Choice abilityChoice = new ChoiceImpl();
abilityChoice.setMessage("Choose an ability to add");
Set<String> abilities = new HashSet<>();
abilities.add(FirstStrikeAbility.getInstance().getRule());
abilities.add(VigilanceAbility.getInstance().getRule());
abilities.add(TrampleAbility.getInstance().getRule());
abilityChoice.setChoices(abilities);
if (!controller.choose(Outcome.AddAbility, abilityChoice, game)) {
return false;
}
String chosen = abilityChoice.getChoice();
Ability ability = null;
if (FirstStrikeAbility.getInstance().getRule().equals(chosen)) {
ability = FirstStrikeAbility.getInstance();
} else if (VigilanceAbility.getInstance().getRule().equals(chosen)) {
ability = VigilanceAbility.getInstance();
} else if (TrampleAbility.getInstance().getRule().equals(chosen)) {
ability = TrampleAbility.getInstance();
}
if (ability != null) {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen: " + chosen);
ContinuousEffect effect = new GainAbilitySourceEffect(ability, Duration.EndOfTurn);
game.addEffect(effect, source);
return true;
}
}
return false;
}
use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.
the class JeweledSpiritEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChoiceColorOrArtifact choice = new ChoiceColorOrArtifact();
if (controller != null && controller.choose(outcome, choice, game)) {
FilterCard protectionFilter = new FilterCard();
if (choice.isArtifactSelected()) {
protectionFilter.add(CardType.ARTIFACT.getPredicate());
} else {
protectionFilter.add(new ColorPredicate(choice.getColor()));
}
protectionFilter.setMessage(choice.getChoice());
ProtectionAbility protectionAbility = new ProtectionAbility(protectionFilter);
ContinuousEffect effect = new GainAbilitySourceEffect(protectionAbility, Duration.EndOfTurn);
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.
the class SungoldSentinelEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
ChoiceColor choice = new ChoiceColor(true);
player.choose(outcome, choice, game);
Ability ability = HexproofBaseAbility.getFirstFromColor(choice.getColor());
game.addEffect(new GainAbilitySourceEffect(ability, Duration.EndOfTurn), source);
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new ColorPredicate(choice.getColor()));
game.addEffect(new CantBeBlockedByAllSourceEffect(filter, Duration.EndOfTurn), source);
return true;
}
use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.
the class TemurSabertoothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
if (controller.chooseUse(outcome, "Return another creature to hand?", source, game) && controller.chooseTarget(outcome, target, source, game)) {
Permanent toHand = game.getPermanent(target.getFirstTarget());
if (toHand != null) {
controller.moveCards(toHand, Zone.HAND, source, game);
}
game.addEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn), source);
}
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainAbilitySourceEffect in project mage by magefree.
the class ThunderousOratorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Ability> abilities = new ArrayList<>();
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
abilities.add(new MenaceAbility());
}
game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), source.getSourceId(), game).stream().filter(Objects::nonNull).map(p -> p.getAbilities(game)).flatMap(Collection::stream).filter(keywords::contains).distinct().forEach(abilities::add);
if (abilities.isEmpty()) {
return false;
}
for (Ability ability : abilities) {
game.addEffect(new GainAbilitySourceEffect(ability, Duration.EndOfTurn), source);
}
return true;
}
Aggregations