@Override public boolean apply(Game game, Ability source) { if (AbilityType.SPELL == source.getAbilityType()) { MageObject object = game.getObject(source.getSourceId()); return object != null && object.getManaCost().getText().contains("X"); } else { return source.getManaCosts().getText().contains("X"); } } }
@Override public boolean applies(Ability abilityToModify, Ability source, Game game) { if (abilityToModify.getAbilityType() == AbilityType.ACTIVATED || (abilityToModify.getAbilityType() == AbilityType.MANA && (abilityToModify instanceof ActivatedAbility))) { // Activated abilities of creatures Permanent permanent = game.getPermanent(abilityToModify.getSourceId()); if (permanent != null && filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) { return true; } } return false; }
@Override public boolean canTarget(UUID id, Ability source, Game game) { // rule 114.4. A spell or ability on the stack is an illegal target for itself. if (source == null || source.getId().equals(id)) { return false; } Spell spell = game.getStack().getSpell(id); return spell != null && filter.match(spell, source.getSourceId(), source.getControllerId(), game); }
@Override public boolean applies(Ability abilityToModify, Ability source, Game game) { if (!MyTurnCondition.instance.apply(game, source)) { return false; } if (!(abilityToModify.getAbilityType() == AbilityType.SPELL) && !(abilityToModify.getAbilityType() == AbilityType.ACTIVATED)) { return false; } return game.getOpponents(source.getControllerId()).contains(abilityToModify.getControllerId()); }
@Override public void adjustTargets(Ability ability, Game game) { ability.getTargets().clear(); int xValue = ability.getManaCostsToPay().getX(); ability.addTarget(new TargetCreaturePermanent(xValue, xValue, filter, false)); } }
private void addModeOptions(List<Ability> options, Ability option, Game game) { // TODO: Support modal spells with more than one selectable mode for (Mode mode : option.getModes().values()) { Ability newOption = option.copy(); newOption.getModes().getSelectedModes().clear(); newOption.getModes().getSelectedModes().add(mode.getId()); newOption.getModes().setActiveMode(mode); if (!newOption.getTargets().getUnchosen().isEmpty()) { if (!newOption.getManaCosts().getVariableCosts().isEmpty()) { addVariableXOptions(options, newOption, 0, game); } else { addTargetOptions(options, newOption, 0, game); } } else if (!newOption.getCosts().getTargets().getUnchosen().isEmpty()) { addCostTargetOptions(options, newOption, 0, game); } else { options.add(newOption); } } }
@Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getTargetId().equals(source.getSourceId()) || event.getTargetId().equals(source.getControllerId())) { if (redirectToObject.equals(new MageObjectReference(source.getTargets().get(0).getFirstTarget(), game))) { redirectTarget = source.getTargets().get(0); return true; } } return false; }
public AbilityView(Ability ability, String sourceName, CardView sourceCard) { this.id = ability.getId(); this.name = "Ability"; this.sourceName = sourceName; this.sourceCard = sourceCard; this.rules = new ArrayList<>(); rules.add(ability.getRule()); this.power = ""; this.toughness = ""; this.loyalty = ""; this.cardTypes = EnumSet.noneOf(CardType.class); this.subTypes = new SubTypeList(); this.superTypes =EnumSet.noneOf(SuperType.class); this.color = new ObjectColor(); this.manaCost = ability.getManaCosts().getSymbols(); }
@Override public boolean apply(Game game, Ability source) { for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { if (!permanent.isLand() && permanent.getConvertedManaCost() <= source.getManaCostsToPay().getX()) { permanent.moveToZone(Zone.HAND, source.getSourceId(), game, true); } } return true; } }
@Override public boolean applies(Ability abilityToModify, Ability source, Game game) { if (abilityToModify instanceof SpellAbility) { if (abilityToModify.isControlledBy(source.getControllerId())) { Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId()); if (spell != null) { return spell.isCreature(); } } } return false; }
protected void simulateVariableCosts(Ability ability, List<Ability> options, Game game) { int numAvailable = getAvailableManaProducers(game).size() - ability.getManaCosts().convertedManaCost(); int start = 0; if (!(ability instanceof SpellAbility)) { //only use x=0 on spell abilities if (numAvailable == 0) return; else start = 1; } for (int i = start; i < numAvailable; i++) { Ability newAbility = ability.copy(); newAbility.getManaCostsToPay().add(new GenericManaCost(i)); options.add(newAbility); } }
@Override public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) { Set<UUID> possibleTargets = new HashSet<>(); for (StackObject stackObject : game.getStack()) { if (stackObject.getStackAbility().getAbilityType() == AbilityType.ACTIVATED && game.getState().getPlayersInRange(sourceControllerId, game).contains(stackObject.getStackAbility().getControllerId()) && filter.match(((StackAbility) stackObject), game)) { possibleTargets.add(stackObject.getStackAbility().getId()); } } return possibleTargets; }
/** * Only used for AIs * * @param ability * @param game * @return */ @Override public List<Ability> getPlayableOptions(Ability ability, Game game) { List<Ability> options = new ArrayList<>(); if (ability.isModal()) { addModeOptions(options, ability, game); } else if (!ability.getTargets().getUnchosen().isEmpty()) { // TODO: Handle other variable costs than mana costs if (!ability.getManaCosts().getVariableCosts().isEmpty()) { addVariableXOptions(options, ability, 0, game); } else { addTargetOptions(options, ability, 0, game); } } else if (!ability.getCosts().getTargets().getUnchosen().isEmpty()) { addCostTargetOptions(options, ability, 0, game); } return options; }
@Override public boolean applies(Ability abilityToModify, Ability source, Game game) { if (abilityToModify.getAbilityType() == AbilityType.ACTIVATED || abilityToModify.getAbilityType() == AbilityType.MANA) { Permanent rebelPermanent = game.getPermanent(abilityToModify.getSourceId()); if (rebelPermanent != null) { return filter2.match(rebelPermanent, game); } } return false; }
public StackAbility(Ability ability, UUID controllerId) { this.ability = ability; this.controllerId = controllerId; this.name = "stack ability (" + ability.getRule() + ')'; }
private void addCostTargetOptions(List<Ability> options, Ability option, int targetNum, Game game) { for (UUID targetId : option.getCosts().getTargets().get(targetNum).possibleTargets(option.getSourceId(), playerId, game)) { Ability newOption = option.copy(); newOption.getCosts().getTargets().get(targetNum).addTarget(targetId, option, game, true); if (targetNum < option.getCosts().getTargets().size() - 1) { addCostTargetOptions(options, newOption, targetNum + 1, game); } else { options.add(newOption); } } }
@Override public void adjustTargets(Ability ability, Game game) { UUID controllerId = ability.getEffects().get(0).getTargetPointer().getFirst(game, ability); if (controllerId != null) { ability.getTargets().get(0).setTargetController(controllerId); ability.getEffects().get(0).setTargetPointer(new FirstTargetPointer()); } } }
@Override public void adjustTargets(Ability ability, Game game) { for (Effect effect : ability.getEffects()) { if (effect instanceof ReturnFromGraveyardToBattlefieldTargetEffect) { int xValue = GetXValue.instance.calculate(game, ability, null); ability.getTargets().clear(); ability.addTarget(new TargetCardInYourGraveyard(xValue, xValue, new FilterCreatureCard("creature cards from your graveyard"))); } } } }
@Override public void adjustCosts(Ability ability, Game game) { if (ability.getAbilityType() == AbilityType.SPELL) { Player controller = game.getPlayer(ability.getControllerId()); if (controller != null) { if (controller.getHand().count(filter, game) > 0) { ability.addCost(new RevealTargetFromHandCost(new TargetCardInHand(0, 1, filter))); } } } }