These are my Components and scripts at the moment:
Code:
Eval Script from the Mechanic applied to the actor:
<eval phase="Traits" priority="149" index="5" name="Prepare First Copy"><![CDATA[var myString as string
myString = "!Helper.SpcDisable & !Helper.SpcReplace"
foreach pick in hero from xCopyTracker where myString sortas CopyTrack
~ if we are a pick with the DomainCopy tag, then we have a selection
~ possible, but if no selection is made, then we are an independant copy
if (eachpick.tagis[Helper.DomainCopy] <> 0) then
~ if we have chosen a selection, the component is no longer a MultiCopy
if (eachpick.tagis[User.HasChosen] <> 0) then
perform eachpick.assign[Helper.ChosenCopy]
else
perform eachpick.assign[Helper.MultiCopy]
endif
endif
~For things which are multiple copies, each independant,
~all of them are "first" copies.
if (eachpick.tagis[Helper.MultiCopy] <> 0) then
perform eachpick.assign[Helper.FirstCopy]
else
~add the first active thing we found to our quick list - if quickadd
~returns nonzero, we were the first version, so add the "first copy" tag
~to ourselves.
~NOTE: at this point, we'll assume that the first copy is the only copy -
~the OnlyCopy tag is deleted in the "Determine First Copy" script if
~there's more than one.
if (eachpick.quickadd <> 0) then
perform eachpick.assign[Helper.FirstCopy]
perform eachpick.assign[Helper.OnlyCopy]
perform eachpick.quickadd
endif
endif
nexteach
]]></eval>
Component with the xCount and xIndex fields
<component
id="xCopyTracker"
name="Multiple COpy Helper">
<!-- Selection Tag Expressions -->
<field
id="xIndex"
name="Index of Copy"
type="derived"
defvalue="0">
</field>
<field
id="xCount"
name="Number of Copies"
type="derived"
defvalue="0">
</field>
<!-- Track whether the first copy -->
<eval index="1" phase="Traits" priority="155" name="Determine First Copy"><![CDATA[
doneif (tagis[Helper.FirstCopy] <> 0)
~if we're not the first copy of a special ability, we need to set up a
~redirection to the actual first copy. That means whenever another pick
~does a "hero.child[x]" to find pick x, they always arrive at the first
~copy. This allows the first copy to be determined at every evaluation,
~and the first copy is then the one used to display the totals for the
~ability, even if it's added in multiple places (e.g. sneak attack, which
~can be added by multiple classes). The first copy is the one in the
~quickfind list, so retrieve it.
perform quickfind.setfocus
~if we found a copy to set our focus to, we're a secondary copy of this
~ability, delete the Helper.OnlyCopy tag from the first (primary) copy.
~That means the Helper.OnlyCopy tag will only be left on those picks that
~are the only copy of their things.
if (state.isfocus <> 0) then
perform focus.redirect
perform assign[Helper.SpecUp]
perform focus.delete[Helper.OnlyCopy]
endif
]]></eval>
<eval index="2" phase="Traits" priority="200" name="Calc xIndex, xCount"><![CDATA[
~we only need to run this if we're not the only copy
~if we aren't the only copy, we need to search the rest of our copies and get information
if (tagis[Helper.OnlyCopy] = 0) then
~only run these for the first copy
if (tagis[Helper.FirstCopy] <> 0) then
var searchexpr as string
searchexpr = "thingid." & this.idstring
var index as number
index = 1
foreach pick in hero from xCopyTracker where searchexpr sortas CopyTrack
~assign this thing the current index value, then increment the index for the next thing
eachpick.field[xIndex].value = index
index += 1
field[xCount].value += 1
nexteach
else
field[xCount].value += 1
endif
else
~xIndex and xCount = 1
field[xIndex].value = 1
field[xCount].value = 1
endif
]]></eval>
</component>
<!-- Define a sortset that lists abilities in index order. -->
<sortset
id="CopyTrack"
name="Framework abilities in order">
<sortkey isfield="yes" id="domDomain" isascend="yes"/>
<sortkey isfield="yes" id="xIndex" isascend="yes"/>
</sortset>