use of mage.abilities.Mode in project mage by magefree.
the class EmissaryOfGrudgesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
if (controller == null || stackObject == null || !stackObject.isControlledBy(ChooseSecretOpponentEffect.getChosenPlayer(source, game))) {
return false;
}
// find if it targets you or a permanent you control
boolean targetsYouOrAPermanentYouControl = false;
for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
Mode mode = stackObject.getStackAbility().getModes().get(modeId);
for (Target target : mode.getTargets()) {
for (UUID targetId : target.getTargets()) {
if (source.isControlledBy(targetId)) {
targetsYouOrAPermanentYouControl = true;
}
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && source.isControlledBy(permanent.getControllerId())) {
targetsYouOrAPermanentYouControl = true;
}
}
}
}
if (targetsYouOrAPermanentYouControl) {
return stackObject.chooseNewTargets(game, source.getControllerId(), false, false, null);
}
return false;
}
use of mage.abilities.Mode in project mage by magefree.
the class FeatherTheRedeemedEffect method checkSpell.
private boolean checkSpell(Spell spell, Game game) {
if (spell == null) {
return false;
}
SpellAbility sa = spell.getSpellAbility();
for (UUID modeId : sa.getModes().getSelectedModes()) {
Mode mode = sa.getModes().get(modeId);
for (Target target : mode.getTargets()) {
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && permanent.isCreature(game) && permanent.isControlledBy(getControllerId())) {
this.getEffects().clear();
this.addEffect(new FeatherTheRedeemedEffect(new MageObjectReference(spell, game)));
return true;
}
}
}
for (Effect effect : mode.getEffects()) {
for (UUID targetId : effect.getTargetPointer().getTargets(game, sa)) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && permanent.isCreature(game) && permanent.isControlledBy(getControllerId())) {
this.getEffects().clear();
this.addEffect(new FeatherTheRedeemedEffect(new MageObjectReference(spell, game)));
return true;
}
}
}
}
return false;
}
use of mage.abilities.Mode in project mage by magefree.
the class GuileSonicSoldierEffect method makeAbility.
private static final ReflexiveTriggeredAbility makeAbility() {
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(4), false);
ability.addTarget(new TargetAnyTarget());
Mode mode = new Mode(new GainAbilitySourceEffect(LifelinkAbility.getInstance(), Duration.EndOfTurn).setText("{this} gains lifelink"));
mode.addEffect(new GainAbilitySourceEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn).setText("and indestructible until end of turn"));
ability.withFirstModeFlavorWord("Sonic Boom").addMode(mode.withFlavorWord("Flash Kick"));
return ability;
}
use of mage.abilities.Mode in project mage by magefree.
the class MeddleEffect method checkTarget.
private static final boolean checkTarget(Game game, Ability source) {
StackObject stackObject = game.getState().getStack().getStackObject(source.getFirstTarget());
if (stackObject == null) {
return false;
}
int numberOfTargets = 0;
for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
Mode mode = stackObject.getStackAbility().getModes().get(modeId);
for (Target target : mode.getTargets()) {
for (UUID targetId : target.getTargets()) {
if (numberOfTargets++ > 1) {
return false;
}
Permanent permanent = game.getPermanent(targetId);
if (permanent == null || !permanent.isCreature(game)) {
return false;
}
}
}
}
return numberOfTargets == 1;
}
use of mage.abilities.Mode in project mage by magefree.
the class RadiantPerformerEffect method prepareCopiesWithTargets.
@Override
protected List<MageObjectReferencePredicate> prepareCopiesWithTargets(StackObject stackObject, Player player, Ability source, Game game) {
List<MageObjectReferencePredicate> predicates = new ArrayList<>();
Ability ability = stackObject instanceof Spell ? ((Spell) stackObject).getSpellAbility() : (StackAbility) stackObject;
UUID targeted = ability == null ? null : ability.getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).findAny().orElse(null);
game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT, player.getId(), source.getSourceId(), game).stream().filter(Objects::nonNull).filter(p -> !p.equals(game.getPermanent(targeted))).filter(p -> stackObject.canTarget(game, p.getId())).map(p -> new MageObjectReference(p, game)).map(MageObjectReferencePredicate::new).forEach(predicates::add);
game.getState().getPlayersInRange(source.getControllerId(), game).stream().filter(uuid -> !uuid.equals(targeted)).filter(uuid -> stackObject.canTarget(game, uuid)).map(MageObjectReference::new).map(MageObjectReferencePredicate::new).forEach(predicates::add);
return predicates;
}
Aggregations