-
Notifications
You must be signed in to change notification settings - Fork 782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Don't Merge] Fix ability copying effects #12912
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,7 +441,15 @@ public Ability addAbility(Ability ability, UUID sourceId, Game game, boolean fro | |
// other abilities -- any amount of instances | ||
if (!abilities.containsKey(ability.getId())) { | ||
Ability copyAbility = ability.copy(); | ||
copyAbility.newId(); // needed so that source can get an ability multiple times (e.g. Raging Ravine) | ||
|
||
// needed so that source can get an ability multiple times (e.g. Raging Ravine) | ||
// Deterministic to allow repeated ability copies to have same UUID | ||
// (see https://github.com/magefree/mage/issues/10372) | ||
long msb = ability.getId().getMostSignificantBits() + getId().getMostSignificantBits() + 1; | ||
long lsb = ability.getId().getLeastSignificantBits() + getId().getMostSignificantBits() + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain how you came up with this algorithm? Why "+1"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I will add a test that verifies that the propaganda copying is fixed, once i land on a solution that works and survives scrutiny.
In theory, it should (or more accurately, it will). I'll try removing that workaround and seeing if it still works as intended once i get the generalized solution complete.
I might change it to an XOR. The +1 was a change i made on a hunch that didn't work out, and the MSB/LSB mixup is a genuine issue it seems. This is all going to need to be moved to CardUtil anyways, so this is pending some refactoring. |
||
copyAbility.newId(new UUID(msb, lsb)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For info: all non mtg code must be extracted to helper function like CardUtil, no needs to msb/lsb/whatever in game engine. There are already existing |
||
// copyAbility.newId(); | ||
|
||
copyAbility.setControllerId(controllerId); | ||
copyAbility.setSourceId(objectId); | ||
// triggered abilities must be added to the state().triggers | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds buggy/bad or not fully researched. MTG rules allow PT < 0 in the middle of the effects calculations. Xmage uses same logic -- permanent will die from negative PT in state base actions (e.g. on next game cycle), not in the middle of the calculation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also xmage uses time based effect's order like paper rules (due effects adding timestamp). Maybe it can be bugged with dependency effects (if some effect depend on another then it must be applied later). Example: effect that checking card type must be applied after effect that change card type. Search for
dependencyTypes
anddependendToTypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The death doesn't happen in the middle of a calculation, it happens after the continuous effects were applied in the "wrong" order (massive quotes on "wrong" here because the order shouldn't matter). The problem is that there are both "set toughness to 0" and "set toughness to 5" effects ok the same sublayer affecting the same creature, resulting in what cosmetically could be compared to a race condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll check this out. Maybe my understanding of effects on the same sublayer is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See details in rule 613.8:
XMage support it but it require to manual setup (see
DependencyType
usage), so only few popular use cases implemented. Rare or new effects/combo can be miss.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "set toughness to 5" effect should systematically always apply after the "set toughness to 0" effect (by timestamp) even with both in layer 7b. If that can't be easily fixed, then there's no good reason for the "set toughness to 0" effect to be here at all in this specific card application.
(Maybe there are underlying issues with dependencies but that's not directly related.)