public TriggeredAbilities copy() { return new TriggeredAbilities(this); }
/** * Adds a by sourceId gained triggered ability * * @param ability - the gained ability * @param sourceId - the source that assigned the ability * @param attachedTo - the object that gained the ability */ public void add(TriggeredAbility ability, UUID sourceId, MageObject attachedTo) { if (sourceId == null) { add(ability, attachedTo); } else if (attachedTo == null) { this.put(ability.getId() + "_" + sourceId, ability); } else { this.add(ability, attachedTo); List<UUID> uuidList = new LinkedList<>(); uuidList.add(sourceId); // if the object that gained the ability moves zone, also then the triggered ability must be removed uuidList.add(attachedTo.getId()); sources.put(getKey(ability, attachedTo), uuidList); } }
public void checkStateTriggers(Game game) { for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext();) { TriggeredAbility ability = it.next(); if (ability instanceof StateTriggeredAbility && ((StateTriggeredAbility) ability).canTrigger(game)) { checkTrigger(ability, null, game); } } }
public TriggeredAbilities(final TriggeredAbilities abilities) { for (Map.Entry<String, TriggeredAbility> entry : abilities.entrySet()) { this.put(entry.getKey(), entry.getValue().copy()); } for (Map.Entry<String, List<UUID>> entry : abilities.sources.entrySet()) { sources.put(entry.getKey(), entry.getValue()); } }
public void addAbility(Ability ability, MageObject attachedTo) { if (ability instanceof StaticAbility) { for (UUID modeId : ability.getModes().getSelectedModes()) { Mode mode = ability.getModes().get(modeId); for (Effect effect : mode.getEffects()) { if (effect instanceof ContinuousEffect) { addEffect((ContinuousEffect) effect, ability); } } } } else if (ability instanceof TriggeredAbility) { this.triggers.add((TriggeredAbility) ability, attachedTo); } }
state.getTriggers().checkStateTriggers(this); for (UUID playerId : state.getPlayerList(state.getActivePlayerId())) { Player player = getPlayer(playerId);
public boolean isGainedAbility(TriggeredAbility abilityToCheck, MageObject attachedTo) { return sources.containsKey(getKey(abilityToCheck, attachedTo)); }
public void handleEvent(GameEvent event, Game game) { watchers.watch(event, game); delayed.checkTriggers(event, game); triggers.checkTriggers(event, game); }
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()))); }
public void clear() { battlefield.clear(); effects.clear(); triggers.clear(); delayed.clear(); triggered.clear(); stack.clear(); exile.clear(); command.clear(); designations.clear(); seenPlanes.clear(); isPlaneChase = false; revealed.clear(); lookedAt.clear(); turnNum = 0; stepNum = 0; extraTurn = false; legendaryRuleActive = true; gameOver = false; specialActions.clear(); cardState.clear(); combat.clear(); turnMods.clear(); watchers.clear(); values.clear(); zones.clear(); simultaneousEvents.clear(); copiedCards.clear(); permanentOrderNumber = 0; }
this.triggered.add(trigger.copy()); this.triggers = state.triggers.copy(); this.delayed = state.delayed.copy(); this.specialActions = state.specialActions.copy();
if (permanent != null) { if (permanent.isFaceDown(game) && !isGainedAbility(ability, permanent) // the face down creature got the ability from an effect => so it should work
this.triggers.add((TriggeredAbility) ability, sourceId, attachedTo);
game.getState().getTriggers().checkStateTriggers(game);
public void checkTriggers(GameEvent event, Game game) { for (Iterator<TriggeredAbility> it = this.values().iterator(); it.hasNext();) { TriggeredAbility ability = it.next(); if (ability.checkEventType(event, game)) { checkTrigger(ability, event, game); } } }
public GameState() { players = new Players(); playerList = new PlayerList(); turn = new Turn(); stack = new SpellStack(); command = new Command(); exile = new Exile(); revealed = new Revealed(); battlefield = new Battlefield(); effects = new ContinuousEffects(); triggers = new TriggeredAbilities(); delayed = new DelayedTriggeredAbilities(); specialActions = new SpecialActions(); combat = new Combat(); turnMods = new TurnMods(); watchers = new Watchers(); applyEffectsCounter = 0; }