~ extra damage for swarm attack based on removed attacks
~ in another script we add a custom tag to all attacks we removed
~ first we put all the extra damages into one long string with % as separator
~ then we grab the first piece of the string and compare
~ run this at Validation/90000 to make sure all extra damages have been applied
~
~ BUILD MASTER STRING
~
var master as string
var cur as string
foreach pick in hero from BaseNatWep where "Custom.TagAttk"
cur = eachpick.field[wDamExtra].text
if (empty(cur) = 0) then
master &= cur & "%"
endif
nexteach
~ now strip potential leading characters for each extra damage
master = replace(master," plus ","",0)
master = replace(master,"plus ","",0)
master = replace(master," +","",0)
master = replace(master," -","",0)
master = replace(master," and ","",0)
~ we now have our master string in the variable master
~ debug master
~
~ STRIP DUPLICATES
~
~ set up while loop for stripping duplicates
var cur_pos as number
var srch_str as string
var cur_str as string
var build_str as string
~ move master -> cur_str for debugging purposes
~ debug master
cur_str = master
cur_pos = pos(master,"%")
while (cur_pos <> -1)
~ strip any leading separators
while (cur_pos = 0)
cur_str = mid(cur_str,1,length(cur_str))
cur_pos = pos(cur_str,"%")
loop
~ cur_pos now has the position of the separator
~ since pos is 0 based, cur_pos is the length of
~ the search string we want
~ build up new string from srch_str
srch_str = mid(cur_str,0,cur_pos)
cur_str = replace(cur_str,srch_str,"",0)
build_str &= srch_str & "%"
~ find position of out next separator for next time around the loop
~ when we cannot find any separators any more we exit the loop
cur_pos = pos(cur_str,"%")
loop
~ remove trailing separators
var sep_pos as number
var len as number
sep_pos = lastpos(build_str,"%")
len = length(build_str) - 1
while (sep_pos = len)
if (sep_pos >= 0) then
build_str = mid(build_str,0,sep_pos - 1)
endif
len = length(build_str)
sep_pos = lastpos(build_str,"%")
loop
~ get out if we have an empty string
doneif (empty(build_str) <> 0)
~
~ MAKE NEW EXTRA DAMAGE STRING
~
~ now build up new extra damage string
~ dam_str will hold the final result
var dam_str as string
dam_str = build_str
~ we determine if we insert a comma or 'and' by using
~ lastpos and pos. If lastpos = pos we put in an 'and'
~ otherwise we put in a comma
var lst as number
var fst as number
var tst as number
lst = lastpos(dam_str,"%")
fst = pos(dam_str,"%")
while (fst > 0)
tst = lst - fst
if (tst <> 0) then
dam_str = replace(dam_str,"%",", ",1)
else
dam_str = replace(dam_str,"%"," and ",1)
endif
lst = lastpos(dam_str,"%")
fst = pos(dam_str,"%")
loop
~ add leading plus for extra damage string
dam_str = " plus " & dam_str