TriggeredAbility ability = triggeredAbility.copy(); MageObject sourceObject = ability.getSourceObject(game); if (sourceObject != null) { sourceObject.adjustTargets(ability, game); if (ability.canChooseTarget(game)) { if (ability.isUsesStack()) { game.getStack().push(new StackAbility(ability, playerId)); if (ability.activate(game, false)) { if ((ability.isUsesStack() || ability.getRuleVisible()) && !game.isSimulation()) { game.informPlayers(ability.getGameLogMessage(game)); if (!ability.isUsesStack()) { ability.resolve(game); } else { game.fireEvent(new GameEvent(EventType.TRIGGERED_ABILITY, ability.getId(), ability.getSourceId(), ability.getControllerId())); restoreState(bookmark, triggeredAbility.getRule(), game); // why restore is needed here? (to remove the triggered ability from the stack) return false;
@Override public void addEffect(Effect effect) { ability.addEffect(effect); }
@Override public void addWatcher(Watcher watcher) { super.addWatcher(watcher); for (TriggeredAbility ability : triggeredAbilities) { ability.addWatcher(watcher); } }
@Override public boolean checkTrigger(GameEvent event, Game game) { boolean toRet = false; for (int i = 0; i < triggeredAbilities.length; i++) { TriggeredAbility ability = triggeredAbilities[i]; if (ability.checkEventType(event, game) && ability.checkTrigger(event, game)) { triggeringAbilities.add(i); toRet = true; } } return toRet; }
@Override public boolean checkTrigger(GameEvent event, Game game) { ability.setSourceId(this.getSourceId()); ability.setControllerId(this.getControllerId()); return ability.checkTrigger(event, game); }
MageObject object = game.getObject(ability.getSourceId()); if (ability.isInUseableZone(game, object, event)) { if (event == null || !game.getContinuousEffects().preventedByRuleModification(event, ability, game, false)) { if (object != null) { boolean controllerSet = false; if (ability.getZone() != Zone.COMMAND && event != null && ability.isLeavesTheBattlefieldTrigger() && game.getLKI().get(Zone.BATTLEFIELD) != null && game.getLKI().get(Zone.BATTLEFIELD).containsKey(ability.getSourceId())) { Permanent permanent = (Permanent) game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD, ability.getSourceObjectZoneChangeCounter() - 1); if (permanent != null) { if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) { // the ability is declared to work also face down ability.setControllerId(permanent.getControllerId()); ability.setControllerId(((Permanent) object).getControllerId()); } else if (object instanceof Spell) { ability.setControllerId(((Spell) object).getControllerId()); if (ability.checkTrigger(event, game)) { NumberOfTriggersEvent numberOfTriggersEvent = new NumberOfTriggersEvent(ability.getControllerId(), ability.getSourceId(), event); if (!game.replaceEvent(numberOfTriggersEvent)) { for (int i = 0; i < numberOfTriggersEvent.getAmount(); i++) { ability.trigger(game, ability.getControllerId());
if (ability.getControllerId() == null) { String sourceName = "no sourceId"; if (ability.getSourceId() != null) { MageObject mageObject = getObject(ability.getSourceId()); if (mageObject != null) { sourceName = mageObject.getName(); logger.fatal("Added triggered ability without controller: " + sourceName + " rule: " + ability.getRule()); return; Ability manaAbiltiy = ability.copy(); if (manaAbiltiy.getSourceObjectZoneChangeCounter() == 0) { manaAbiltiy.setSourceObjectZoneChangeCounter(getState().getZoneChangeCounter(ability.getSourceId())); TriggeredAbility newAbility = ability.copy(); newAbility.newId(); if (newAbility.getSourceObjectZoneChangeCounter() == 0) { newAbility.setSourceObjectZoneChangeCounter(getState().getZoneChangeCounter(ability.getSourceId()));
public ConditionalTriggeredAbility(final ConditionalTriggeredAbility triggered) { super(triggered); this.ability = triggered.ability.copy(); this.condition = triggered.condition; this.abilityText = triggered.abilityText; }
TriggeredAbility abilityOrderLast = null; for (TriggeredAbility ability : abilities) { if (triggerAutoOrderAbilityFirst.contains(ability.getOriginalId())) { return ability; MageObject object = game.getObject(ability.getSourceId()); String rule = ability.getRule(object != null ? object.getName() : null); if (triggerAutoOrderNameFirst.contains(rule)) { return ability; if (triggerAutoOrderAbilityLast.contains(ability.getOriginalId())) { abilityOrderLast = ability; continue; if (response.getUUID() != null) { for (TriggeredAbility ability : abilitiesWithNoOrderSet) { if (ability.getId().equals(response.getUUID()) || (!macroTriggeredSelectionFlag && ability.getSourceId().equals(response.getUUID()))) { if (recordingMacro) { PlayerResponse tResponse = new PlayerResponse(); tResponse.setUUID(ability.getSourceId()); actionQueueSaved.add(tResponse); logger.debug("Adding Triggered Ability Source: " + tResponse);
public MightMakesRight(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{5}{R}"); // At the beginning of combat on your turn, if you control each creature on the battlefield with the greatest power, gain control // of target creature an opponent controls until end of turn. Untap that creature. It gains haste until end of turn. TriggeredAbility gainControlAbility = new BeginningOfCombatTriggeredAbility(new GainControlTargetEffect(Duration.EndOfTurn), TargetController.YOU, false); gainControlAbility.addEffect(new UntapTargetEffect()); gainControlAbility.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn)); gainControlAbility.addTarget(new TargetCreaturePermanent(filter)); Ability conditionalAbility = new ConditionalInterveningIfTriggeredAbility(gainControlAbility, ControlsEachCreatureWithGreatestPowerCondition.instance, ruleText); this.addAbility(conditionalAbility); }
UUID originalId = null; for (TriggeredAbility ability : game.getState().getTriggered(getId())) { if (ability.getId().equals(abilityId)) { originalId = ability.getOriginalId(); break;
@Override public String getRule() { if (abilityText == null || abilityText.isEmpty()) { return ability.getRule(); } return abilityText; }
@Override public boolean applies(GameEvent event, Ability source, Game game) { Ability ability = (Ability) getValue("targetAbility"); if (ability != null && ability.getAbilityType() == AbilityType.TRIGGERED) { Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget(); if (permanent != null && permanent.isCreature()) { return (((TriggeredAbility) ability).checkTrigger(event, game)); } } return false; }
private String getKey(TriggeredAbility ability, MageObject target) { String key = ability.getId() + "_"; if (target != null) { key += target.getId(); } return key; }
public void removeAbilitiesOfNonExistingSources(Game game) { // e.g. Token that had triggered abilities entrySet().removeIf(entry -> game.getObject(entry.getValue().getSourceId()) == null && game.getState().getDesignations().stream().noneMatch(designation -> designation.getId().equals(entry.getValue().getSourceId()))); }
@Override public boolean triggerAbility(TriggeredAbility source, Game game) { if (source != null && source.canChooseTarget(game)) { Ability ability; List<Ability> options = getPlayableOptions(source, game);
public ConditionalInterveningIfTriggeredAbility(final ConditionalInterveningIfTriggeredAbility triggered) { super(triggered); this.ability = triggered.ability.copy(); this.condition = triggered.condition; this.abilityText = triggered.abilityText; }
public BrinkOfMadness(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{B}{B}"); // At the beginning of your upkeep, if you have no cards in hand, sacrifice Brink of Madness and target opponent discards their hand. TriggeredAbility ability = new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new SacrificeSourceEffect(), TargetController.YOU, false); ability.addEffect(new BrinkOfMadnessEffect()); ability.addTarget(new TargetOpponent()); CardsInHandCondition contition = new CardsInHandCondition(ComparisonType.EQUAL_TO, 0); this.addAbility(new ConditionalInterveningIfTriggeredAbility(ability, contition, "At the beginning of your upkeep, if you have no cards in hand, sacrifice {this} and target opponent discards their hand.")); }
@Override public boolean checkTrigger(GameEvent event, Game game) { ability.setSourceId(this.getSourceId()); ability.setControllerId(this.getControllerId()); return ability.checkTrigger(event, game) && condition.apply(game, this); }
@Override public String getRule() { if (abilityText == null || abilityText.isEmpty()) { return ability.getRule(); } return abilityText; }