magefree / magefree/mage

Attach and unattach code must be reviewed (attachTo, unattach, addAttachment, removeAttachment)

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

Description

There are two places to store attach info (both used by cards/effects):
- inside attaching permanent: `attachedTo`;
- inside permanent with attachments list: `attachments`

1.
That fields must be synced but there are possible problems with data consistence in some use cases in theory. As example: attachment can lost `attachedTo` information on restricted `removeAttachment`:

`removeAttachment` example with too early `attachedTo` clean up:
![Image](https://github.com/user-attachments/assets/83635e75-46f7-48fe-90f6-a1a70059eaf6)

It's not lead to any bugs cause there aren't any effects that can replace/restrict `UNATTACH` events but it can be affected in the future.

2.
`addAttachment` use `attachTo`-`removeAttachment` code but it ignore bad `removeAttachment` result (same problem as number 1 above).

3.
Also usage of attach and attachment methods must be splits between game engine and cards. Attach/unattach for game engine usage only, addAttachment/removeAttachment for cards/effects.
![Image](https://github.com/user-attachments/assets/eee6781b-98cc-48af-a4b1-958ac16d7c5d)
![Image](https://github.com/user-attachments/assets/74f7cd5c-f6d2-4601-88c0-d9ed360ff6df)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating attachTo, unattach, addAttachment, and removeAttachment, then trace their use by the game engine and by cards/effects. Review how attachedTo and attachments are updated, including restricted removeAttachment results; done means the storage stays consistent and the engine/card method responsibilities are clearly separated.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.