@Override public boolean mustAttack(Game game) { if (conditionState) { return effect.mustAttack(game); } else if (otherwiseEffect != null) { return otherwiseEffect.mustAttack(game); } return false; }
@Override public void init(Ability source, Game game) { super.init(source, game); if (baseCondition instanceof LockedInCondition) { condition = new FixedCondition(((LockedInCondition) baseCondition).getBaseCondition().apply(game, source)); } else { condition = baseCondition; } effect.setTargetPointer(this.targetPointer); effect.init(source, game); if (otherwiseEffect != null) { otherwiseEffect.setTargetPointer(this.targetPointer); otherwiseEffect.init(source, game); } initDone = true; }
@Override public boolean applies(Permanent permanent, Ability source, Game game) { if (!initDone) { // if simpleStaticAbility, init won't be called init(source, game); } conditionState = condition.apply(game, source); if (conditionState) { effect.setTargetPointer(this.targetPointer); return effect.applies(permanent, source,game); } else if (otherwiseEffect != null) { otherwiseEffect.setTargetPointer(this.targetPointer); return otherwiseEffect.applies(permanent, source, game); } if (!conditionState && effect.getDuration() == Duration.OneUse) { used = true; } if (!conditionState && effect.getDuration() == Duration.Custom) { this.discard(); } return false; }
public Map<RequirementEffect, Set<Ability>> getApplicableRequirementEffects(Permanent permanent, boolean playerRealted, Game game) { Map<RequirementEffect, Set<Ability>> effects = new HashMap<>(); for (RequirementEffect effect : requirementEffects) { if (playerRealted == effect.isPlayerRelated()) { Set<Ability> abilities = requirementEffects.getAbility(effect.getId()); Set<Ability> applicableAbilities = new HashSet<>(); for (Ability ability : abilities) { if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, ability instanceof MageSingleton ? permanent : null, null)) { if (effect.applies(permanent, ability, game)) { applicableAbilities.add(ability); } } } if (!applicableAbilities.isEmpty()) { effects.put(effect, abilities); } } } return effects; }
effect.setText(""); effect.setTargetPointer(new FixedTarget(permanent.getId())); game.addEffect(effect, source); game.informPlayers(controller.getLogName() + " has decided that " + permanent.getLogName() + " attacks this combat if able"); for (Map.Entry<RequirementEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRequirementEffects(permanent, false, game).entrySet()) { RequirementEffect effect2 = entry.getKey(); if (effect2.mustAttack(game)) { hasToAttack = true;
if (effect.mustAttack(game)) { mustAttack = true; for (Ability ability : entry.getValue()) { UUID defenderId = effect.mustAttackDefender(ability, game); if (defenderId != null) { if (defenders.contains(defenderId)) {
UUID toBeBlockedCreature = effect.mustBlockAttackerIfElseUnblocked(ability, game); if (toBeBlockedCreature != null) { CombatGroup toBeBlockedGroup = findGroup(toBeBlockedCreature); if (toBeBlockedGroup != null && toBeBlockedGroup.getDefendingPlayerId().equals(creature.getControllerId())) { minNumberOfBlockersMap.put(toBeBlockedCreature, effect.getMinNumberOfBlockers()); Set<UUID> potentialBlockers; if (mustBeBlockedByAtLeastX.containsKey(toBeBlockedCreature)) { if (effect.mustBlockAllAttackers(game)) { UUID toBeBlockedCreature = effect.mustBlockAttackerIfElseUnblocked(ability, game); if (toBeBlockedCreature != null) { CombatGroup toBeBlockedGroup = findGroup(toBeBlockedCreature); if (toBeBlockedGroup != null && toBeBlockedGroup.getDefendingPlayerId().equals(creature.getControllerId())) { minNumberOfBlockersMap.put(toBeBlockedCreature, effect.getMinNumberOfBlockers()); Set<UUID> potentialBlockers; if (mustBeBlockedByAtLeastX.containsKey(toBeBlockedCreature)) { if (effect.mustBlockAny(game) || effect.mustBlockAllAttackers(game)) {
@Override public void init(Ability source, Game game) { super.init(source, game); creatingPermanent = new MageObjectReference(source.getSourceId(), game); }
@Override public boolean apply(Game game, Ability source) { Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source)); if (targetPlayer != null) { ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn, targetPlayer.getId()); effect.setTargetPointer(new SecondTargetPointer()); effect.setText("Target player gains control of up to three target nonattacking creatures until end of turn"); game.addEffect(effect, source); Effect effect2 = new UntapTargetEffect(); effect2.setTargetPointer(new SecondTargetPointer()); effect2.setText("Untap those creatures"); effect2.apply(game, source); RequirementEffect effect3 = new BlocksIfAbleTargetEffect(Duration.EndOfTurn); effect3.setTargetPointer(new SecondTargetPointer()); effect3.setText("They block this turn if able"); game.addEffect(effect3, source); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player defendingPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source)); if (defendingPlayer != null) { Target target = new TargetControlledCreaturePermanent(1, 1, filter, true); if (target.choose(Outcome.Neutral, defendingPlayer.getId(), source.getSourceId(), game)) { RequirementEffect effect = new MustBeBlockedByTargetSourceEffect(); effect.setTargetPointer(new FixedTarget(target.getFirstTarget())); game.addEffect(effect, source); } return true; } return false; } }
public ConditionalRequirementEffect(final ConditionalRequirementEffect effect) { super(effect); this.effect = (RequirementEffect) effect.effect.copy(); if (effect.otherwiseEffect != null) { this.otherwiseEffect = (RequirementEffect) effect.otherwiseEffect.copy(); } this.condition = effect.condition; this.conditionState = effect.conditionState; this.baseCondition = effect.baseCondition; this.initDone = effect.initDone; }
@Override public void init(Ability source, Game game) { super.init(source, game); creatingPermanent = new MageObjectReference(source.getSourceId(), game); }
@Override public boolean apply(Game game, Ability source) { Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source)); if (opponent != null) { Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, new FilterControlledCreaturePermanent(), true); if (target.choose(Outcome.Neutral, opponent.getId(), source.getSourceId(), game)) { for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), opponent.getId(), source.getSourceId(), game)) { if (target.getTargets().contains(permanent.getId())) { RequirementEffect effect = new OracleEnVecMustAttackRequirementEffect(); effect.setTargetPointer(new FixedTarget(permanent.getId())); game.addEffect(effect, source); } else { RestrictionEffect effect = new OracleEnVecCantAttackRestrictionEffect(); effect.setTargetPointer(new FixedTarget(permanent.getId())); game.addEffect(effect, source); } } game.addDelayedTriggeredAbility(new OracleEnVecDelayedTriggeredAbility(game.getTurnNum(), target.getTargets()), source); return true; } } return false; } }
private void removeAttackerIfPossible(Game game, Permanent attacker) { for (Map.Entry entry : game.getContinuousEffects().getApplicableRequirementEffects(attacker, false, game).entrySet()) { RequirementEffect effect = (RequirementEffect) entry.getKey(); if (effect.mustAttack(game)) { if (game.getCombat().getMaxAttackers() >= game.getCombat().getCreaturesForcedToAttack().size() && game.getCombat().getDefenders().size() == 1) { return; // we can't change creatures forced to attack if only one possible defender exists and all forced creatures can attack } } } game.getCombat().removeAttacker(attacker.getId(), game); }
@Override public void init(Ability source, Game game) { super.init(source, game); if (getTargetPointer().getFirst(game, source) == null) { discard(); } else { targetPermanentReference = new MageObjectReference(getTargetPointer().getFirst(game, source), game); } }