Senior Member
Join Date: Dec 2011
Posts: 100
November 28th, 2016, 07:33 PM
|
ok, I thought I'd put this little bit of code ( for certain definitions of little) up for those more skilled with coding to look at and see if they could find a better way of doing everything so that it would not be quite as intensive.
Note that this is rather ugly so those of you who are code-aphobic, you may want to look away.
As it stands, I'm thinking I may need to create separate specials to run the code for the sake of space and timing, but that could end up drastically increasing the number of foreach statements and therefore processing requirements.
Code:
~ If we're not enabled, get out now
doneif (field[pIsOn].value = 0)
~ If we're not epic, lets stop this now
doneif (herofield[tTotLevel].value < 21)
~ for the easy part, lets add the epic tag to our hero
perform hero.assign[Hero.Epic]
~ now the hard part, identifying our bonuses before epic.
~ first we are going to set up a bunch of veriables we can reference later
var LevCnt as number
var totHD as number
var bBAB as number
var bFort as number
var bRef as number
var bWill as number
var Class0 as number
var c0BAB as number
var c0Fort as number
var c0Ref as number
var c0Will as number
var Class1 as number
var c1BAB as number
var c1Fort as number
var c1Ref as number
var c1Will as number
var Class2 as number
var c2BAB as number
var c2Fort as number
var c2Ref as number
var c2Will as number
var Class3 as number
var c3BAB as number
var c3Fort as number
var c3Ref as number
var c3Will as number
var Class4 as number
var c4BAB as number
var c4Fort as number
var c4Ref as number
var c4Will as number
var Class5 as number
var c5BAB as number
var c5Fort as number
var c5Ref as number
var c5Will as number
~ at this time HL still limits us to 5 classes + 1 Race so I will stop here
var epcLev as number
var epcAtk as number
var epcSave as number
~ now we will start looking at our classes/races/templates and try to retrieve information
foreach pick on hero where (field[cIndex].value < 20)
~ don't do anything if we have already reached a epic
if (LevCnt < 20) then
~ We need to identify what is at each index so we can get the information we need
if (tagcount[Component.BaseRace] <> 0) then
~ If it is a race at this index then we can pull the specific values from the race
bBAB += eachpick.field[rAttack].value
bFort += eachpick.field[rFort].value
bRef += eachpick.field[rRef].value
bWill += eachpick.field[rWill].value
~ For now I am using the totHD and LevCnt to help me keep track of our progress and so we can stop the foreach if we reach epic early.
totHD += eachpick.field[rHitDice].value
LevCnt += eachpick.field[cLevelAdj].value
endif
~ if it is not a race we need to know if it is a class or a template
elseif (tagcount[Component.BaseClass] <> 0) then
~ HL calculates the BAB and saves based on number of total levels in a given class. So we will have to figure out how many levels our hero has of each class before going epic so we can calculate it later.
~ from what I can find, HL only supports up to 5 classes + 1 racial for a total of 6 class tags in total
if (eachpick.field[cHelpIndex].value = 0) then
Class0 += 1
elseif (eachpick.field[cHelpIndex].value = 1) then
Class1 += 1
elseif (eachpick.field[cHelpIndex].value = 2) then
Class2 += 1
elseif (eachpick.field[cHelpIndex].value = 3) then
Class3 += 1
elseif (eachpick.field[cHelpIndex].value = 4) then
Class4 += 1
elseif (eachpick.field[cHelpIndex].value = 5) then
Class5 += 1
endif
~ again, we want to add to our totals here so we will know when to stop the foreach
totHD += 1
LevCnt += 1
~ The other major option is templates. Many add level adjustments, and some add to our HD or base saves
elseif (tagcount[Component.BaseTemp] <> 0) then
~ much like races, the relevant bonuses can be pulled straight from fields on the pick.
bBAB += eachpick.field[tmAttack].value
bFort += eachpick.field[tmFort].value
bRef += eachpick.field[tmRef].value
bWill += eachpick.field[tmWill].value
~ For now I am using the totHD and LevCnt to help me keep track of our progress and so we can stop the foreach if we reach epic early.
totHD += eachpick.field[tmHitDice].value
LevCnt += eachpick.field[cLevelAdj].value
endif
endif
endif
nexteach
~ now to start our class calculations
~ we will start with the FIRST class space
if (Class0 > 0) then
foreach pick on hero where (field[cClsIndex].value = 0)
~ calculate our BAB bonus from this class
~ if we have good bab in the class then calculate our bonus as equal our level in class
if (eachpick.tagcount[cAttack.Good] <> 0) then
c0BAB = Class0
~ if we do not have good BAB, check if we have medium and calculate our bonus as 3/4 class
elseif (eachpick.tagcount[cAttack.Medium] <> 0) then
c0BAB = round((Class0 * 3)/4,0,-1)
~ if we do not have good or medium BAB, check if we have Poor bab and calculate our bonus as 1/2 class
elseif (eachpick.tagcount[cAttack.Poor] <> 0) then
c0BAB = round(Class0 /2,0,-1)
~ if we do not have good, medium, or poor BAB tags we may be a race or template and have already gathered the BAB above
else c0BAB = 0
endif
~ next we will start on the Fort save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cFort.Good] <> 0 then
c0Fort = 2 + round(Class0/2,0,-1)
~ if we do not have a good tag then check if we have a poor Fort
elseif (eachpick.tagcount[cFort.Poor] <> 0) then
c0Fort = round(Class0/3,0,-1)
~ if we do not have a good or poor Fort tag we may be a race or template and have already gathered the bonus above
else c0Fort = 0
endif
~ next we will start on the Reflex save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cRef.Good] <> 0 then
c0Ref = 2 + round(Class0/2,0,-1)
~ if we do not have a good tag then check if we have a poor Reflex
elseif (eachpick.tagcount[cRef.Poor] <> 0) then
c0Ref = round(Class0/3,0,-1)
~ if we do not have a good or poor Reflex tag we may be a race or template and have already gathered the bonus above
else c0Ref = 0
endif
~ next we will start on the Will save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cWill.Good] <> 0 then
c0Will = 2 + round(Class0/2,0,-1)
~ if we do not have a good tag then check if we have a poor Will
elseif (eachpick.tagcount[cWill.Poor] <> 0) then
c0Will = round(Class0/3,0,-1)
~ if we do not have a good or poor Will tag we may be a race or template and have already gathered the bonus above
else c0Will = 0
endif
nexteach
endif
~ now we move on to the next index
~ start looking at our SECOND class space
if (Class1 > 0) then
foreach pick on hero where (field[cClsIndex].value = 1)
~ calculate our BAB bonus from this class
~ if we have good bab in the class then calculate our bonus as equal our level in class
if (eachpick.tagcount[cAttack.Good] <> 0) then
c1BAB = Class1
~ if we do not have good BAB, check if we have medium and calculate our bonus as 3/4 class
elseif (eachpick.tagcount[cAttack.Medium] <> 0) then
c1BAB = round((Class1 * 3)/4,0,-1)
~ if we do not have good or medium BAB, check if we have Poor bab and calculate our bonus as 1/2 class
elseif (eachpick.tagcount[cAttack.Poor] <> 0) then
c1BAB = round(Class1 /2,0,-1)
~ if we do not have good, medium, or poor BAB tags we may be a race or template and have already gathered the BAB above
else c1BAB = 0
endif
~ next we will start on the Fort save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cFort.Good] <> 0 then
c1Fort = 2 + round(Class1/2,0,-1)
~ if we do not have a good tag then check if we have a poor Fort
elseif (eachpick.tagcount[cFort.Poor] <> 0) then
c1Fort = round(Class1/3,0,-1)
~ if we do not have a good or poor Fort tag we may be a race or template and have already gathered the bonus above
else c1Fort = 0
endif
~ next we will start on the Reflex save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cRef.Good] <> 0 then
c1Ref = 2 + round(Class1/2,0,-1)
~ if we do not have a good tag then check if we have a poor Reflex
elseif (eachpick.tagcount[cRef.Poor] <> 0) then
c1Ref = round(Class1/3,0,-1)
~ if we do not have a good or poor Reflex tag we may be a race or template and have already gathered the bonus above
else c1Ref = 0
endif
~ next we will start on the Will save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cWill.Good] <> 0 then
c1Will = 2 + round(Class1/2,0,-1)
~ if we do not have a good tag then check if we have a poor Will
elseif (eachpick.tagcount[cWill.Poor] <> 0) then
c1Will = round(Class1/3,0,-1)
~ if we do not have a good or poor Will tag we may be a race or template and have already gathered the bonus above
else c1Will = 0
endif
nexteach
endif
~ now we move on to our THIRD class space
if (Class2 > 0) then
foreach pick on hero where (field[cClsIndex].value = 2)
~ calculate our BAB bonus from this class
~ if we have good bab in the class then calculate our bonus as equal our level in class
if (eachpick.tagcount[cAttack.Good] <> 0) then
c2BAB = Class2
~ if we do not have good BAB, check if we have medium and calculate our bonus as 3/4 class
elseif (eachpick.tagcount[cAttack.Medium] <> 0) then
c2BAB = round((Class2 * 3)/4,0,-1)
~ if we do not have good or medium BAB, check if we have Poor bab and calculate our bonus as 1/2 class
elseif (eachpick.tagcount[cAttack.Poor] <> 0) then
c2BAB = round(Class2 /2,0,-1)
~ if we do not have good, medium, or poor BAB tags we may be a race or template and have already gathered the BAB above
else c2BAB = 0
endif
~ next we will start on the Fort save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cFort.Good] <> 0 then
c2Fort = 2 + round(Class2/2,0,-1)
~ if we do not have a good tag then check if we have a poor Fort
elseif (eachpick.tagcount[cFort.Poor] <> 0) then
c2Fort = round(Class2/3,0,-1)
~ if we do not have a good or poor Fort tag we may be a race or template and have already gathered the bonus above
else c2Fort = 0
endif
~ next we will start on the Reflex save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cRef.Good] <> 0 then
c2Ref = 2 + round(Class2/2,0,-1)
~ if we do not have a good tag then check if we have a poor Reflex
elseif (eachpick.tagcount[cRef.Poor] <> 0) then
c2Ref = round(Class2/3,0,-1)
~ if we do not have a good or poor Reflex tag we may be a race or template and have already gathered the bonus above
else c2Ref = 0
endif
~ next we will start on the Will save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cWill.Good] <> 0 then
c2Will = 2 + round(Class2/2,0,-1)
~ if we do not have a good tag then check if we have a poor Will
elseif (eachpick.tagcount[cWill.Poor] <> 0) then
c2Will = round(Class2/3,0,-1)
~ if we do not have a good or poor Will tag we may be a race or template and have already gathered the bonus above
else c2Will = 0
endif
nexteach
endif
~ now we move on to our FOURTH class space
if (Class3 > 0) then
foreach pick on hero where (field[cClsIndex].value = 3)
~ calculate our BAB bonus from this class
~ if we have good bab in the class then calculate our bonus as equal our level in class
if (eachpick.tagcount[cAttack.Good] <> 0) then
c3BAB = Class3
~ if we do not have good BAB, check if we have medium and calculate our bonus as 3/4 class
elseif (eachpick.tagcount[cAttack.Medium] <> 0) then
c3BAB = round((Class3 * 3)/4,0,-1)
~ if we do not have good or medium BAB, check if we have Poor bab and calculat our bonus as 1/2 class
elseif (eachpick.tagcount[cAttack.Poor] <> 0) then
c3BAB = round(Class3 /2,0,-1)
~ if we do not have good, medium, or poor BAB tags we may be a race or template and have already gathered the BAB above
else c3BAB = 0
endif
~ next we will start on the Fort save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cFort.Good] <> 0 then
c3Fort = 2 + round(Class3/2,0,-1)
~ if we do not have a good tag then check if we have a poor Fort
elseif (eachpick.tagcount[cFort.Poor] <> 0) then
c3Fort = round(Class3/3,0,-1)
~ if we do not have a good or poor Fort tag we may be a race or template and have already gathered the bonus above
else c3Fort = 0
endif
~ next we will start on the Reflex save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cRef.Good] <> 0 then
c3Ref = 2 + round(Class3/2,0,-1)
~ if we do not have a good tag then check if we have a poor Reflex
elseif (eachpick.tagcount[cRef.Poor] <> 0) then
c3Ref = round(Class3/3,0,-1)
~ if we do not have a good or poor Reflex tag we may be a race or template and have already gathered the bonus above
else c3Ref = 0
endif
~ next we will start on the Will save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cWill.Good] <> 0 then
c3Will = 2 + round(Class3/2,0,-1)
~ if we do not have a good tag then check if we have a poor Will
elseif (eachpick.tagcount[cWill.Poor] <> 0) then
c3Will = round(Class3/3,0,-1)
~ if we do not have a good or poor Will tag we may be a race or template and have already gathered the bonus above
else c3Will = 0
endif
nexteach
endif
~ now we move on to our FIFTH class space
if (Class4 > 0) then
foreach pick on hero where (field[cClsIndex].value = 4)
~ calculate our BAB bonus from this class
~ if we have good bab in the class then calculate our bonus as equal our level in class
if (eachpick.tagcount[cAttack.Good] <> 0) then
c4BAB = Class4
~ if we do not have good BAB, check if we have medium and calculate our bonus as 3/4 class
elseif (eachpick.tagcount[cAttack.Medium] <> 0) then
c4BAB = round((Class4 * 3)/4,0,-1)
~ if we do not have good or medium BAB, check if we have Poor bab and calculate our bonus as 1/2 class
elseif (eachpick.tagcount[cAttack.Poor] <> 0) then
c4BAB = round(Class4 /2,0,-1)
~ if we do not have good, medium, or poor BAB tags we may be a race or template and have already gathered the BAB above
else c4BAB = 0
endif
~ next we will start on the Fort save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cFort.Good] <> 0 then
c4Fort = 2 + round(Class4/2,0,-1)
~ if we do not have a good tag then check if we have a poor Fort
elseif (eachpick.tagcount[cFort.Poor] <> 0) then
c4Fort = round(Class4/3,0,-1)
~ if we do not have a good or poor Fort tag we may be a race or template and have already gathered the bonus above
else c4Fort = 0
endif
~ next we will start on the Reflex save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cRef.Good] <> 0 then
c4Ref = 2 + round(Class4/2,0,-1)
~ if we do not have a good tag then check if we have a poor Reflex
elseif (eachpick.tagcount[cRef.Poor] <> 0) then
c4Ref = round(Class4/3,0,-1)
~ if we do not have a good or poor Reflex tag we may be a race or template and have already gathered the bonus above
else c4Ref = 0
endif
~ next we will start on the Will save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cWill.Good] <> 0 then
c4Will = 2 + round(Class4/2,0,-1)
~ if we do not have a good tag then check if we have a poor Will
elseif (eachpick.tagcount[cWill.Poor] <> 0) then
c4Will = round(Class4/3,0,-1)
~ if we do not have a good or poor Will tag we may be a race or template and have already gathered the bonus above
else c4Will = 0
endif
nexteach
endif
~ now we move on to our SIXTH class space
if (Class5 > 0) then
foreach pick on hero where (field[cClsIndex].value = 5)
~ calculate our BAB bonus from this class
~ if we have good bab in the class then calculate our bonus as equal our level in class
if (eachpick.tagcount[cAttack.Good] <> 0) then
c5BAB = Class5
~ if we do not have good BAB, check if we have medium and calculate our bonus as 3/4 class
elseif (eachpick.tagcount[cAttack.Medium] <> 0) then
c5BAB = round((Class5 * 3)/4,0,-1)
~ if we do not have good or medium BAB, check if we have Poor bab and calculate our bonus as 1/2 class
elseif (eachpick.tagcount[cAttack.Poor] <> 0) then
c5BAB = round(Class5 /2,0,-1)
~ if we do not have good, medium, or poor BAB tags we may be a race or template and have already gathered the BAB above
else c5BAB = 0
endif
~ next we will start on the Fort save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cFort.Good] <> 0 then
c5Fort = 2 + round(Class5/2,0,-1)
~ if we do not have a good tag then check if we have a poor Fort
elseif (eachpick.tagcount[cFort.Poor] <> 0) then
c5Fort = round(Class5/3,0,-1)
~ if we do not have a good or poor Fort tag we may be a race or template and have already gathered the bonus above
else c5Fort = 0
endif
~ next we will start on the Reflex save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cRef.Good] <> 0 then
c5Ref = 2 + round(Class5/2,0,-1)
~ if we do not have a good tag then check if we have a poor Reflex
elseif (eachpick.tagcount[cRef.Poor] <> 0) then
c5Ref = round(Class5/3,0,-1)
~ if we do not have a good or poor Reflex tag we may be a race or template and have already gathered the bonus above
else c5Ref = 0
endif
~ next we will start on the Will save
~ if we have a good save, calculate our bonus
if (eachpick.tagcount[cWill.Good] <> 0 then
c5Will = 2 + round(Class5/2,0,-1)
~ if we do not have a good tag then check if we have a poor Will
elseif (eachpick.tagcount[cWill.Poor] <> 0) then
c5Will = round(Class5/3,0,-1)
~ if we do not have a good or poor Will tag we may be a race or template and have already gathered the bonus above
else c5Will = 0
endif
nexteach
endif
~ hopefully, if we have done everything correct so far we can calculate our total pre-epic base attack and saves
bBAB = bBAB + c0BAB + c1BAB + c2BAB + c3BAB + c4BAB + c5BAB
bFort = bFort + c0Fort + c1Fort + c2Fort + c3Fort + c4Fort + c5Fort
bRef = bRef + c0Ref + c1Ref + c2Ref + c3Ref + c4Ref + c5Ref
bWill = bWill + c0Will + c1Will + c2Will + c3Will + c4Will + c5Will
~ now the easy part
epcLev = herofield[tTotLevel].value - 20
epcAtk = round(epcLev/2,0,1)
epcSave = round(epcLev/2,0,-1)
~ ok, we have our pre epic bonuses and our post epic bonuses, now to put them in the right places
hero.child[Attack].field[tAtkBase].value = bBAB
hero.child[Attack].field[tAtkEpic].value = epcAtk
hero.child[vFort].field[vBase].value = bFort + epcSave
hero.child[vRef].field[vBase].value = bRef + epcSave
hero.child[vWill].field[vBase].value = bWill + epcSave
|