magefree / magefree/mage

Self-replacement effects and 616 - Interaction of Replacement effects are not fully supported (part of blood moon problem?)

Open
#13,062 2 comments 0 reactions 0 assignees View on GitHub
bug refactoring
Dominant language
Java
Stars
2.4k
Forks
940
Avg merge
2d 12h
Merged PRs (30d)
160

Description

Found some strange and non-used code in `EnterEventType`:
* `EnterEventType.SELF` -> `EventType.ENTERS_THE_BATTLEFIELD_SELF` - only Bestow ability used it
* `EnterEventType.CONTROL` -> `EventType.ENTERS_THE_BATTLEFIELD_CONTROL` - never used
* `EnterEventType.COPY` -> `EventType.ENTERS_THE_BATTLEFIELD_COPY` - never used
* `EnterEventType.OTHER` -> `EventType.ENTERS_THE_BATTLEFIELD` -- all around

That's enters logic was introduced for multiple [[Metallic Mimic]] bug in #2765 to support **self-replacement** effects from rules 616.1a:
> 616.1a
> If any of the replacement and/or prevention effects are self-replacement effects (see rule 614.15), one of them must be chosen. If not, proceed to rule 616.1b.
> 614.15
> Some replacement effects are not continuous effects. Rather, they are an effect of a resolving spell or ability that replace part or all of that spell or ability’s own effect(s). Such effects are called self-replacement effects. The text creating a self-replacement effect is usually part of the ability whose effect is being replaced, but the text can be a separate ability, particularly when preceded by an ability word. When applying replacement effects to an event, self-replacement effects are applied before other replacement effects.

![shot_241110_134233](https://github.com/user-attachments/assets/daaebd54-aa56-4359-b2e7-b92be82eba37)

If you replace self-event by `EventType.ENTERS_THE_BATTLEFIELD` in Bestow then no failed tests found, so it's useless?

Current problems:
1. Looks like self-replacement effects are not fully supported in all cards -- it works as normal effects in current version (e.g. user will see choose dialog). Potential bug from Riot ability due miss self-replacement logic: #6413
2. Control modification effects not fully supported? No code usage for `EnterEventType.CONTROL` or `EventType.ENTERS_THE_BATTLEFIELD_CONTROL`:
> 616.1b
> If any of the replacement and/or prevention effects would modify under whose control an object would enter the battlefield, one of them must be chosen. If not, proceed to rule 616.1c.
3. Copy replacement effects not fully supported? No code usage for `EnterEventType.COPY` or `EventType.COPY`:
> 616.1c
> If any of the replacement and/or prevention effects would cause an object to become a copy of another object as it enters the battlefield, one of them must be chosen. If not, proceed to [rule 616.1d](http://www.mtg.ru/rules/616-1d.html#616.1d).
4. It's also interesting note for "616. Interaction of Replacement and/or Prevention Effects" -- if you look above to 616.1b and 616.1c then can see the diff order from continues effects (layers logic):
* Continues must use copy first (layer 1), then control (layer 2);
* Replacement must use control effect first (616.1b), then copy (616.1c);
* Maybe related to bugs like #12475 with etb as copy [[Urza's Saga]] and [[Echoing Deeps]], e.g. it can be the real reason of the "blood moon" problem (#4202) in some use cases;

TODO:
* Need research of `EnterEventType` and 616 rules support. Is it easy to implement in all related cards (use diff ENTERS_THE_BATTLEFIELD events due effect's logic - self, copy, control or other -- ~300 cards/abilities)? I think on good implementation it can fix many reported "blood moon" problems.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing EnterEventType and EventType usage, especially the Bestow implementation introduced for #2765, then compare the behavior with rules 614.15 and 616.1a–c. Review the related cases in #6413, #12475, and #4202 and identify affected cards or abilities; done means self-, control-, and copy-replacement effects are selected in the correct order with coverage for the related cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.