Working On GKC along with Attachmeng

I am working on a module now, in this module, there is a Timer piece, which will send GKC to a group of Unit pieces in each turn, updating their Mana points.

This Unit group may vary each turn, for example, if some unit cast spell and consume some Mana, it needs to join this group to recover its mana points, and if some unit recover its Mana and reaches its max value, this unit will be removed from this group.

I have two plans to establish this mechanism and don’t know which one is better:

(1) Use auto-attach to all pieces with identical names in Attachment traits to bind Timer with every Unit on board, when fire GKC, using property filter to reach to units which needs to update mana points (I use some dynamic property to label which unit should be filtered out);

(2) In each term, for Timer piece, clear existing attachment list first, then attach units (which needs to update mana) to the Timer piece, after re-establishing the attachment relationship, fire GKC to Current Attachments.

So choice (1) basically will need to maintain a larger group of attachment network in which some units won’t be affected by GKC,

choice (2) will need Timer piece to re-establish attachment network each turn and this will surely cost some system overhead,

My question is from the point of performance, which choice will be better?

I know pieces with Attachment trait will maintain a internal list of pieces (like current attachment) to speed up GKC performance, but not knowing the details of this process, and whether maintain a too large attachment list will cause some setbacks or not.

Trying to group the pieces is the wrong approach. Instead of filtering the GKC, use the Math.min() function to constrain pieces to the maximum mana.

From the description, each piece has a maximum mana. The mana level can be reduced. Every so often the mana is gradually replenished up to a maximum value.

If the maximum mana is constant, use a Marker trait to define the maximum values. For this example lets call it Max_mana. If the maximum value is variable then use either a Calculated Property or a Dynamic Property instead.

Mana itself is a Dynamic Property. Define the GKC as a Key Command in the Dynamic Property, set the type to “Set the value directly” with the prompt set to {Math.min(Max_mana,Mana+1)}. This assumes mana recovers 1 unit per GKC. If the piece is at its maximum mana nothing changes, otherwise the mana increases by one. This way every piece gets the GKC, but only pieces with a reduced mana recover.