Basically, the fix changes this:
Code: Select all
[H, IF( active ):
oldTMS = if( json.get( newTMS, 0 ) == "",
json.set( newTMS, 0, modSet ),
json.append( newTMS, modSet)
);
oldTMS = if( idxMS == -1,
newTMS,
json.remove( newTMS, abs( idxMS ) )
)
]
Code: Select all
[H, if( active ), code: {
[H: oldTMS = json.append(newTMS,modSet)]
};{
[H, if(idxMS == -1): oldTMS = newTMS; oldTMS = json.remove(newTMS,idxMS)]
}]
...Patch: subCalcMod...
Code: Select all
@@ @subCalcMod [H: gTok = "Lib:GlobalsSRDPF" ] [H: tToken = json.get( macro.args, "tokenID" ) ] [H: active = json.get( macro.args, "active" ) ] [H: modSet = json.get( macro.args, "setID" ) ] [H: param = json.get( macro.args, "param" ) ] [H: presetVars = json.get( macro.args, "presetVars" ) ] [H: tclvl = json.get( macro.args, "casterlevel" ) ] [H, IF(tclvl != ""): BardLevel = tclvl; "" ] [H, IF(tclvl != ""): Bard_Level = tclvl; "" ] [H, IF(tclvl != ""): Caster_Level = tclvl; "" ] [H, IF(tclvl != ""): CasterLevel = tclvl; "" ] [H, IF(tclvl != ""): Cleric_Level = tclvl; "" ] [H, IF(tclvl != ""): ClericLevel = tclvl; "" ] [H, IF(tclvl != ""): Paladin_Level = tclvl; "" ] [H, IF(tclvl != ""): PaladinLevel = tclvl; "" ] [H, IF(tclvl != ""): BarbarianLevel = tclvl; "" ] [H, IF(tclvl != ""): Barbarian_Level = tclvl; "" ] [H, IF(tclvl != ""): Monk_Level = tclvl; "" ] [H, IF(tclvl != ""): MonkLevel = tclvl; "" ] [H, IF(tclvl != ""): WitchLevel = tclvl; "" ] [H, IF(tclvl != ""): Witch_Level = tclvl; "" ] [H: switchToken( tToken ) ] [H, IF( !json.isEmpty( presetVars ) ): varsFromStrProp( json.toStrProp( presetVars ) ) ] [H: jTM = json.merge( getLibProperty( "TempModToggleSets", gTok ), BonusTypedItems ) ] [H: aTMS = json.get( PrivateJSON, "ActiveTempModSets" ) ] [H: aTMS = if( json.type( aTMS ) == "UNKNOWN", "[]", aTMS ) ] [H: aItems = json.get( PrivateJSON, "ActiveItems" ) ] [H: aItems = if( json.type( aItems ) == "UNKNOWN", "[]", aItems ) ] [H: newTMS = json.unique( json.merge( aTMS, aItems ) ) ] [H: nTMSlen = json.length( newTMS ) ] [H: tSpeed = Speed ] [H: Base = json.get(tSpeed, "base")] [H: Climb = json.get(tSpeed, "climb")] [H: Swim = json.get(tSpeed, "swim")] [H: Burrow = json.get(tSpeed, "burrow")] [H: Fly = json.get(tSpeed, "fly")] [H: tStatCheckMod = StatCheckMod ] [H: StrengthCheckMod = json.get(tStatCheckMod, "StrengthCheckMod")] [H: DexterityCheckMod = json.get(tStatCheckMod, "DexterityCheckMod")] [H: ConstitutionCheckMod = json.get(tStatCheckMod, "ConstitutionCheckMod")] [H: IntelligenceCheckMod = json.get(tStatCheckMod, "IntelligenceCheckMod")] [H: WisdomCheckMod = json.get(tStatCheckMod, "WisdomCheckMod")] [H: CharismaCheckMod = json.get(tStatCheckMod, "CharismaCheckMod")] [H: tDRERMod = DRERMod ] [H: DR_All = json.get(tDRERMod, "DR_All")] [H: DR_Adamantine = json.get(tDRERMod, "DR_Adamantine")] [H: DR_ColdIron = json.get(tDRERMod, "DR_ColdIron")] [H: DR_Epic = json.get(tDRERMod, "DR_Epic")] [H: DR_Magic = json.get(tDRERMod, "DR_Magic")] [H: DR_Silver = json.get(tDRERMod, "DR_Silver")] [H: DR_Bludgeoning = json.get(tDRERMod, "DR_Bludgeoning")] [H: DR_Piercing = json.get(tDRERMod, "DR_Piercing")] [H: DR_Slashing = json.get(tDRERMod, "DR_Slashing")] [H: DR_Chaos = json.get(tDRERMod, "DR_Chaos")] [H: DR_Evil = json.get(tDRERMod, "DR_Evil")] [H: DR_Good = json.get(tDRERMod, "DR_Good")] [H: DR_Law = json.get(tDRERMod, "DR_Law")] [H: ER_Acid = json.get(tDRERMod, "ER_Acid")] [H: ER_Cold = json.get(tDRERMod, "ER_Cold")] [H: ER_Electricity = json.get(tDRERMod, "ER_Electricity")] [H: ER_Fire = json.get(tDRERMod, "ER_Fire")] [H: ER_Sonic = json.get(tDRERMod, "ER_Sonic")] [H: idxMS = json.indexOf( newTMS, modSet ) ] [H: '<!-- Fixed if statement from function to roll -->'] [H, if( active ), code: { [H: oldTMS = json.append(newTMS,modSet)] };{ [H, if(idxMS == -1): oldTMS = newTMS; oldTMS = json.remove(newTMS,idxMS)] }] [H: wTMS = if( active, oldTMS, newTMS ) ] [H: tList = table( "SysVars", json.get( table( "SysVars", 0 ), "modTypeList" ) ) ] [H: tAddStackList = table( "SysVars", json.get( table( "SysVars", 0 ), "modAddStackList" ) ) ] [H: asA = "" ] [H, FOREACH( p, tAddStackList ): asA = listAppend( asA, listFind( tList, p ) ) ] [H: nbA = "[]" ] [H, FOREACH( t, tList ): nbA = json.append( nbA, 0 ) ] [H: obA = nbA ] [H: npA = nbA ] [H: opA = nbA ] [H: jPTM = json.get( PrivateJSON, "CustomModSetValues" ) ] [H, IF( json.type( jPTM ) != "OBJECT" ): jPTM = "{}" ] [H, FOREACH( ms, wTMS ), CODE: { [ activeTM = if( listContains( json.toList( oldTMS ), ms ) > 0, 1, 0 ) ] [ tSet = json.get( jTM, ms ) ] [IF( json.isEmpty( tSet ) ): tjMods = "{}"; tjMods = json.get( tSet, "mods" ) ] [ tjMod = json.get( tjMods, param ) ] [IF( json.type( tjMod ) == "OBJECT" && !json.isEmpty( tjMod ) ): v = json.get( tjMod, "v" ); v = 0 ] [ hasGlobalMod = if( getFindCount( strfind( v, "(globalMod)" ) ) > 0, 1, 0 ) ] [IF( !isNumber( v ) && ( activeTM || active ) ), CODE: { [ jPMS = json.get( jPTM, ms ) ] [ tjPMods = json.get( jPMS, "mods" ) ] [ v = json.get( json.get( tjPMods, param ), "v" ) ] [IF( !isNumber( v ) ): v = 0 ] [IF( ms == modSet ): jPTM = json.set( jPTM, ms, json.set( jPMS, "f", 0 ) ) ] [IF( ms == modSet ): PrivateJSON = json.set( PrivateJSON, "CustomModSetValues", jPTM ) ] }] [IF( !isNumber( v ) && !active && ( ms == modSet ) ), CODE: { [ vo = decode( replaceStr( encode(v), "%22", "%60" ) ) ] [IF( json.isEmpty( jPTM ) ): jPMS = "{}"; jPMS = json.get( jPTM, ms ) ] [IF( json.isEmpty( jPMS ) ): tjPMods = "{}"; tjPMods = json.get( jPMS, "mods" ) ] [ globalMod = 0 ] [ fresh = 0 ] [IF( !json.isEmpty( jPMS ) ): fresh = json.get( jPMS, "f" ) ] [IF( hasGlobalMod && fresh ): globalMod = json.get( json.get( tjPMods, "globalMod" ), "v" ) ] [IF( hasGlobalMod && json.isEmpty( globalMod ) ): globalMod = json.get( json.get( tjMods, "globalMod" ), "v" ) ] [IF( json.isEmpty( jPMS ) || !fresh ): ttip = json.get( json.get( jTM, ms ), "tip" ); ttip = json.get( jPMS, "tip" ) ] [ hasMACRO = if( getFindCount( strfind( v, "(MACRO)" ) ) > 0, 1, 0 ) ] [IF( hasMACRO ): tgM = evalMacro( v ) ] [IF( hasMACRO ): v = macro.return; v = eval( "" + v ) ] [ vtip = decode( replaceStr( encode( " " + v ), "%22", "%60" ) ) ] [ ntip = replaceStr( ttip, vo + "</t", vtip + "</t" ) ] [IF( json.isEmpty( tjPMods ) ): tjPMod = "{}"; tjPMod = json.get( tjPMods, param ) ] [ jPTM = json.set( jPTM, ms, json.set( jPMS, "mods", json.set( tjPMods, param, json.set( tjPMod, "v", v ) ), "f", 1, "tip", ntip ) ) ] [ PrivateJSON = json.set( PrivateJSON, "CustomModSetValues", jPTM ) ] }] [IF( param != "globalMod" ), CODE: { [ penalty = if( v >= 0, 0, 1 ) ] [IF( json.type( tjMod ) == "OBJECT" && !json.isEmpty( tjMod ) ): t = json.get( tjMod, "t" ); t = 0 ] [ obV = json.get( obA, t ) ] [ opV = json.get( opA, t ) ] [ nbV = json.get( nbA, t ) ] [ npV = json.get( npA, t ) ] [ addT = listContains( asA, t ) ] [IF( modSet != ms || active ): oV = if( addT > 0, v + if( penalty, opV, obV ), if( penalty, min( v, opV ), max( v, obV ) ) ); oV = if( penalty, opV, obV ) ] [IF( penalty ): opA = json.set( opA, t, oV ); obA = json.set( obA, t, oV ) ] [IF( modSet != ms || !active ): cV = if( addT > 0, v + if( penalty, npV, nbV ), if( penalty, min( v, npV ), max( v, nbV ) ) ); cV = if( penalty, npV, nbV ) ] [IF( penalty ): npA = json.set( npA, t, cV ); nbA = json.set( nbA, t, cV ) ] }; {}] }] [H: oldMSTotal = 0 ] [H: newMSTotal = 0 ] [H, IF( param != "globalMod" ), CODE: { [H: i = 0 ] [H, FOREACH( t, tList ), CODE: { [ newMSTotal = newMSTotal + json.get( npA, i ) + json.get( nbA, i ) ] [ oldMSTotal = oldMSTotal + json.get( opA, i ) + json.get( obA, i ) ] [ i = i + 1 ] }] }; {}] [H: macro.return = json.set( json.set( "{}", "oldMSTotal", oldMSTotal ), "newMSTotal", newMSTotal ) ] !!
...Patch: subModToggle...
Code: Select all
@@ @subModToggle @PROPS@ fontColor=black ; autoExecute=true ; fontSize=1.00em ; sortBy=30 ; color=pink ; playerEditable=false ; applyToSelected=false ; group=Utility Mods ; tooltip= ; minWidth= ; [H: tToken = json.get( macro.args, "tokenID" ) ] [H: tmID = json.get( macro.args, "setID" ) ] [H: tmType = json.get( macro.args, "setType" ) ] [H: presetVars = json.get( macro.args, "presetVars" ) ] [H: tclvl = json.get( macro.args, "casterlevel" ) ] [H: gTok = "Lib:GlobalsSRDPF" ] [H: jTM = getLibProperty( "TempModToggleSets", gTok ) ] [H: modDRERFieldList = table( "SysVars", json.get( table( "SysVars", 0 ), "modDRERFieldList" ) ) ] [H: modStatCheckFieldList = table( "SysVars", json.get( table( "SysVars", 0 ), "modStatCheckFieldList" ) ) ] [H: modList = table( "SysVars", json.get( table( "SysVars", 0 ), "modFieldList" ) ) ] [H: modArmorFieldList = table( "SysVars", json.get( table( "SysVars", 0 ), "modArmorFieldList" ) ) ] [H: modSpeedFieldList = table( "SysVars", json.get( table( "SysVars", 0 ), "modSpeedFieldList" ) ) ] [H: statesList = getTokenStates() ] [H: modAddStackList = table( "SysVars", json.get( table( "SysVars", 0 ), "modAddStackList" ) ) ] [H: output = ""] [H: globalMod = 0 ] [H: switchToken( tToken ) ] [H, MACRO( "subBaselineArmor@this" ): json.set( "{}", "tokenID", tToken ) ] [H: jTM = json.merge( jTM, BonusTypedItems ) ] [H: tjMods = json.get( json.get( jTM, tmID ), "mods" ) ] [H: state = json.get( json.get( jTM, tmID ), "state" ) ] [H: tmacro = json.get( json.get( jTM, tmID ), "macro" ) ] [H: tDieHard = getStrProp(Feats, "DieHard")] [H: tDieHard = if(tDieHard == "", 0, tDieHard)] [H: Armor = getStrProp(ArmorClass, "Armor")] [H: ArmorACP = getStrProp(ArmorClass, "ArmorACP")] [H: Shield = getStrProp(ArmorClass, "Shield")] [H: MaxDex = getStrProp(ArmorClass, "MaxDex")] [H: Natural = getStrProp(ArmorClass, "Natural")] [H: Deflection = getStrProp(ArmorClass, "Deflection")] [H: Dodge = getStrProp(ArmorClass, "Dodge")] [H: ACMod = getStrProp(ArmorClass, "ACMod")] [H: ACMod = if( ACMod == "", 0, ACMod )] [H: ArmorMod = getStrProp(ArmorClass, "ArmorMod")] [H: ArmorMod = if( ArmorMod == "", 0, ArmorMod )] [H: ShieldMod = getStrProp(ArmorClass, "ShieldMod")] [H: ShieldMod = if( ShieldMod == "", 0, ShieldMod )] [H: NaturalMod = getStrProp(ArmorClass, "NaturalMod")] [H: NaturalMod = if( NaturalMod == "", 0, NaturalMod )] [H: tSpeed = SpeedMod ] [H: Base = json.get(tSpeed, "base")] [H: Climb = json.get(tSpeed, "climb")] [H: Swim = json.get(tSpeed, "swim")] [H: Burrow = json.get(tSpeed, "burrow")] [H: Fly = json.get(tSpeed, "fly")] [H: tStatCheckMod = StatCheckMod ] [H: StrengthCheckMod = json.get(tStatCheckMod, "StrengthCheckMod")] [H: DexterityCheckMod = json.get(tStatCheckMod, "DexterityCheckMod")] [H: ConstitutionCheckMod = json.get(tStatCheckMod, "ConstitutionCheckMod")] [H: IntelligenceCheckMod = json.get(tStatCheckMod, "IntelligenceCheckMod")] [H: WisdomCheckMod = json.get(tStatCheckMod, "WisdomCheckMod")] [H: CharismaCheckMod = json.get(tStatCheckMod, "CharismaCheckMod")] [H: tDRERMod = DRERMod ] [H: DR_All = json.get(tDRERMod, "DR_All")] [H: DR_Adamantine = json.get(tDRERMod, "DR_Adamantine")] [H: DR_ColdIron = json.get(tDRERMod, "DR_ColdIron")] [H: DR_Epic = json.get(tDRERMod, "DR_Epic")] [H: DR_Magic = json.get(tDRERMod, "DR_Magic")] [H: DR_Silver = json.get(tDRERMod, "DR_Silver")] [H: DR_Bludgeoning = json.get(tDRERMod, "DR_Bludgeoning")] [H: DR_Piercing = json.get(tDRERMod, "DR_Piercing")] [H: DR_Slashing = json.get(tDRERMod, "DR_Slashing")] [H: DR_Chaos = json.get(tDRERMod, "DR_Chaos")] [H: DR_Evil = json.get(tDRERMod, "DR_Evil")] [H: DR_Good = json.get(tDRERMod, "DR_Good")] [H: DR_Law = json.get(tDRERMod, "DR_Law")] [H: ER_Acid = json.get(tDRERMod, "ER_Acid")] [H: ER_Cold = json.get(tDRERMod, "ER_Cold")] [H: ER_Electricity = json.get(tDRERMod, "ER_Electricity")] [H: ER_Fire = json.get(tDRERMod, "ER_Fire")] [H: ER_Sonic = json.get(tDRERMod, "ER_Sonic")] [H: SR_SR = json.get(tDRERMod, "SR_SR")] [H: aTMS = json.toList( json.get( PrivateJSON, "ActiveTempModSets" ) ) ] [H: aItems = json.toList( json.get( PrivateJSON, "ActiveItems" ) ) ] [H: activeTM = if( listContains( aTMS, tmID ) > 0 && tmType == 0, 1, 0 ) ] [H, IF( tmType == 0 ): aTMS = if( activeTM, listDelete( aTMS, listFind( aTMS, tmID ) ), listAppend( aTMS, tmID ) ) ] [H: activeItem = if( listContains( aItems, tmID ) > 0 && tmType == 1, 1, 0 ) ] [H, IF( tmType == 1 ): aItems = if( activeItem, listDelete( aItems, listFind( aItems, tmID ) ), listAppend( aItems, tmID ) ) ] [H: '<!-- Problem with putting empty string in array -->'] [H, if(json.isEmpty(aTMS)): aTMSj = "[]"; aTMSj = json.fromList(aTMS)] [H, if(json.isEmpty(aItems)): aItemsj = "[]"; aItemsj = json.fromList(aItems)] [H: PrivateJSON = json.set( PrivateJSON, "ActiveTempModSets", aTMSj, "ActiveItems", aItemsj)] [H: active = if( activeTM || activeItem, 1, 0 ) ] [H: tHP = HP ] [H: tDamage = HPmax - HP] [H, FOREACH( m, json.fields( tjMods ) ), CODE: { [ isModField = if( listContains( modList, m ) > 0, 1, 0 ) ] [ isArmor = if( listContains( modArmorFieldList, m ) > 0, 1, 0 ) ] [ isSpeed = if( listContains( modSpeedFieldList, m ) > 0, 1, 0 ) ] [ isStatCheckMod = if( listContains( modStatCheckFieldList, m ) > 0, 1, 0 ) ] [ isDRERMod = if( listContains( modDRERFieldList, m ) > 0, 1, 0 ) ] [ tm = eval( "" + m ) ] [MACRO( "subCalcMod@this" ): json.set( "{}", "tokenID", tToken, "setID", tmID, "param", m, "active", active, "presetVars", presetVars, "casterlevel", tclvl ) ] [ newMSTotal = json.get( macro.return, "newMSTotal" ) ] [ oldMSTotal = json.get( macro.return, "oldMSTotal" ) ] [IF( isModField ): setProperty( m, tm - oldMSTotal + newMSTotal ) ] [IF( isArmor ): ArmorClass = setStrProp( ArmorClass, m, if( listContains( modAddStackList, m ) > 0 || matches( m, ".*Mod" ), tm - oldMSTotal + newMSTotal, newMSTotal ) ) ] [IF( isSpeed ): SpeedMod = json.set( SpeedMod, lower( m ), ( tm - oldMSTotal + newMSTotal ) ) ] [IF( isStatCheckMod ): StatCheckMod = json.set( StatCheckMod, m, ( tm - oldMSTotal + newMSTotal ) ) ] [IF( isDRERMod ): DRERMod = json.set( DRERMod, m, ( tm - oldMSTotal + newMSTotal ) ) ] }] [H: tACP = 0 ] [H: tmaxdex = 50 ] [H: tencumbered = 0 ] [H: tdesc = "" ] [H, IF( tmType == 1 ), FOREACH( i, aItems ), CODE: { [ jI = json.get( BonusTypedItems, i ) ] [ tACP = tACP + json.get( jI, "acp" ) ] [ tmaxdex = min( tmaxdex, json.get( jI, "maxdex" ) ) ] [ tencumbered = max( tencumbered, json.get( jI, "encumbered" ) ) ] [ tnote = json.get( jI, "note" ) ] [ armorDesc = if( json.contains( json.get( jI, "mods" ), "Armor" ) || json.contains( json.get( jI, "mods" ), "Shield" ), 1, 0 ) ] [IF( tnote != "" && armorDesc ): tdesc = listAppend( tdesc, tnote ) ] }] [H, IF( tmType == 1 ): ArmorClass = setStrProp( ArmorClass, "ArmorACP", tACP ) ] [H, IF( tmType == 1 ): ArmorClass = setStrProp( ArmorClass, "MaxDex", tmaxdex ) ] [H, IF( tmType == 1 ): ArmorClass = setStrProp( ArmorClass, "Description", tdesc ) ] [H, IF( tmType == 1 ): SpeedMod = json.set( SpeedMod, "encumbered", tencumbered ) ] [H, IF( listContains( statesList, state ) > 0 ): setState( state, !active ) ] [R,S,G, IF( tmacro != ""), MACRO( tmacro ): json.set( "{}", "token", tToken, "active", active, "casterlevel", tclvl ) ] [H: HP = HPmax - tDamage] [H: HPChange = HP - tHP] [H: state.Unconscious = if( ( ( (HP + HPtemp) < 0 ) || ( HPNonLethalDMG > (HP + HPtemp) ) ) && !tDieHard, 1, if((HPChange > 0) && ((HP + HPtemp) >= 0) && ((HP + HPtemp) >= HPNonLethalDMG), 0, state.Unconscious))] [H, MACRO("subUpdateHPStatesBars@this"): "Token=" + tToken] [H, MACRO("subRecalcAC@this"): "Token=" + tToken] [H, MACRO("subRecalcMovement@this"): "Token=" + tToken] [H, MACRO("subRecalcDR@this"): json.set( "{}", "Token", tToken ) ] [H: output = output + "<b>" + token.name + "</b> -- " + if( active, "<font color='red'>REMOVING</font>: ", "<font color='green'>APPLYING</font>: " ) + "<i>" + tmID + "</i><br>"] [H: macro.return = output ] !!