Skip to content

Need to remove triggers from game state when removing an ability from a permanent #14902

@xenohedron

Description

@xenohedron

Existing TODO originally noted in #6585

When adding an ability to a permanent, if it's a triggered ability, it also gets added directly to the game state. This is necessary for triggering correctly when leaving the battlefield. However, the code that removes abilities from permanents doesn't account for this, but needs to. I noticed this very clearly with my mutate implementation in #14900 . While the workaround there was very simple, it's probably better to fix the underlying discrepancy if possible.

// triggered abilities must be added to the state().triggers
// still as long as the prev. permanent is known to the LKI (e.g. Showstopper) so gained dies triggered ability will trigger
if (game != null) {
// game is null in cards viewer window (MageBook)
game.getState().addAbility(copyAbility, sourceId, this);
}

@Override
public void removeAllAbilities(UUID sourceId, Game game) {
// TODO: what about triggered abilities? See addAbility above -- triggers adds to GameState
abilities.clear();
}

// TODO: what about triggered abilities? See addAbility above -- triggers adds to GameState
toRemove.forEach(r -> abilities.remove(r));

TriggeredAbilities has a method for removing all abilities from a particular source. But not currently a way to remove an arbitrary ability.

public void removeAbilitiesOfSource(UUID sourceId) {
keySet().removeIf(key -> key.endsWith(sourceId.toString()));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enginerefactoringDevelopers topics about code and programming

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions