Refactor: Condition.apply needs a GameEvent parameter
- Dominant language
- Java
- Stars
- 2.4k
- Forks
- 940
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 160
Description
Cards like [[Resourceful Defense]] have an intervening if-clause which needs to look at the permanent that is leaving the battlefield in order to verify if the condition for the triggered ability is met.
As currentling implemented `Condition`'s `.apply()` only takes in a `Game` parameter, and I don't see how to get access to the event information which is causing the condition to go off. `GameState` has a `simultaneousEvents` variable which would store the events, but it's cleared before each event is individually handled:
https://github.com/magefree/mage/blob/94dc91d8e19a395770b091e87d9e2c79260d09b8/Mage/src/main/java/mage/game/GameState.java#L783-L795
The current alternative is to create a custom triggered ability, e.g. [[The Ozolith]]:
https://github.com/magefree/mage/blob/f6be167aeb0fa61840f4efa893d901bf80039be6/Mage.Sets/src/mage/cards/t/TheOzolith.java#L61-L94
These kinds of implementations could be simplified to use common abilities if the `Condition` has a was of looking at the event that is setting off the triggered ability.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading Condition.apply and the GameState simultaneousEvents handling around the linked lines, then compare the custom triggered ability in Mage.Sets/src/mage/cards/t/TheOzolith.java. Determine how a condition can access the triggering GameEvent without relying on cleared state; done means the affected custom abilities can use the common condition mechanism and relevant behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- game-dev
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100