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())); |
|
} |
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.
mage/Mage/src/main/java/mage/game/permanent/PermanentImpl.java
Lines 464 to 469 in e3e948e
mage/Mage/src/main/java/mage/game/permanent/PermanentImpl.java
Lines 479 to 483 in e3e948e
mage/Mage/src/main/java/mage/game/permanent/PermanentImpl.java
Lines 499 to 500 in e3e948e
TriggeredAbilities has a method for removing all abilities from a particular source. But not currently a way to remove an arbitrary ability.
mage/Mage/src/main/java/mage/abilities/TriggeredAbilities.java
Lines 320 to 322 in e3e948e