Character Vault
Any Concept / Any System
Compendium
Your System Come To Life
Roll20 for Android
Streamlined for your Tablet
Roll20 for iPad
Streamlined for your Tablet

Personal tools

Building Character Sheets

From Roll20 Wiki

Revision as of 01:33, 6 July 2020 by DonutRooster (Talk | contribs)

Jump to: navigation, search

<input name="attr_version" type="hidden" value="3.0"/> <input class="monster_confirm_flag" name="attr_monster_confirm_flag" type="hidden"/> <input class="mancer_confirm_flag" name="attr_mancer_confirm_flag" type="hidden"/> <input class="licensedsheet" name="attr_licensedsheet" type="hidden"/>

 <input class="npc_toggle" name="attr_npc" type="hidden" value="0"/>
 <input class="npcspellcastingflag" name="attr_npcspellcastingflag" type="hidden"/>
 <input class="toggleflag" name="attr_rtype" type="hidden"/>

<input type="radio" class="toggle-left" name="attr_advantagetoggle" value="Template:Query=1 Template:Advantage=1 {{r2=[[@{d20}">ADVANTAGE <input type="radio" class="toggle-center" name="attr_advantagetoggle" value="Template:Query=1 Template:Normal=1 {{r2=[[0d20" checked="checked">NORMAL <input type="radio" class="toggle-right" name="attr_advantagetoggle" value="Template:Query=1 Template:Disadvantage=1 {{r2=[[@{d20}">DISADVANTAGE

 <input class="toggleflag" name="attr_wtype" type="hidden"/>
   <input class="toggle-left" name="attr_whispertoggle" type="radio" value="" checked="checked"/>PUBLIC
   <input class="toggle-right" name="attr_whispertoggle" type="radio" value="/w gm "/>TOGM
   <input class="npc_options-flag" type="checkbox" name="attr_npc_options-flag" checked="checked">y
           NPC OPTIONS
           NAME
           <input type="text" name="attr_npc_name">
           NPC TYPE
           <input type="text" name="attr_npc_type" placeholder="Medium fiend, any evil alignment" data-i18n-placeholder="npc-type-place">
           ARMOR CLASS
           <input class="num" type="text" name="attr_npc_ac" placeholder="10">
           TYPE
           <input type="text" name="attr_npc_actype" placeholder="scale mail" data-i18n-placeholder="npc-armor-place" value="">
           HIT POINTS
           <input class="num" type="text" name="attr_hp_max" placeholder="82">
           FORMULA
           <input type="text" name="attr_npc_hpformula" placeholder="11d8 + 33">
           SPEED
           <input type="text" name="attr_npc_speed" placeholder="30 ft., fly 60ft." data-i18n-placeholder="npc-speed-place">
           ATTRIBUTES
           STR
           <input class="num" type="text" name="attr_strength_base" value="10">
           DEX
           <input class="num" type="text" name="attr_dexterity_base" value="10">
           CON
           <input class="num" type="text" name="attr_constitution_base" value="10">
           INT
           <input class="num" type="text" name="attr_intelligence_base" value="10">
           WIS
           <input class="num" type="text" name="attr_wisdom_base" value="10">
           CHA
           <input class="num" type="text" name="attr_charisma_base" value="10">
           SAVES
           STR
           <input class="num" type="text" name="attr_npc_str_save_base" placeholder="0">
           DEX
           <input class="num" type="text" name="attr_npc_dex_save_base" placeholder="0">
           CON
           <input class="num" type="text" name="attr_npc_con_save_base" placeholder="0">
           INT
           <input class="num" type="text" name="attr_npc_int_save_base" placeholder="0">
           WIS
           <input class="num" type="text" name="attr_npc_wis_save_base" placeholder="0">
           CHA
           <input class="num" type="text" name="attr_npc_cha_save_base" placeholder="0">
           <input type="hidden" name="attr_npc_str_save" value="@{strength_mod}">
           <input type="hidden" name="attr_npc_dex_save" value="@{dexterity_mod}">
           <input type="hidden" name="attr_npc_con_save" value="@{constitution_mod}">
           <input type="hidden" name="attr_npc_int_save" value="@{intelligence_mod}">
           <input type="hidden" name="attr_npc_wis_save" value="@{wisdom_mod}">
           <input type="hidden" name="attr_npc_cha_save" value="@{charisma_mod}">
           SKILLS
                   ACROBATICS
                   <input class="num" type="text" name="attr_npc_acrobatics_base" placeholder="0">
                   ANIMAL HANDLING
                   <input class="num" type="text" name="attr_npc_animal_handling_base" placeholder="0">
                   ARCANA
                   <input class="num" type="text" name="attr_npc_arcana_base" placeholder="0">
                   ATHLETICS
                   <input class="num" type="text" name="attr_npc_athletics_base" placeholder="0">
                   DECEPTION
                   <input class="num" type="text" name="attr_npc_deception_base" placeholder="0">
                   HISTORY
                   <input class="num" type="text" name="attr_npc_history_base" placeholder="0">
                   INSIGHT
                   <input class="num" type="text" name="attr_npc_insight_base" placeholder="0">
                   INTIMIDATION
                   <input class="num" type="text" name="attr_npc_intimidation_base" placeholder="0">
                   INVESTIGATION
                   <input class="num" type="text" name="attr_npc_investigation_base" placeholder="0">
                   MEDICINE
                   <input class="num" type="text" name="attr_npc_medicine_base" placeholder="0">
                   NATURE
                   <input class="num" type="text" name="attr_npc_nature_base" placeholder="0">
                   PERCEPTION
                   <input class="num" type="text" name="attr_npc_perception_base" placeholder="0">
                   PERFORMANCE
                   <input class="num" type="text" name="attr_npc_performance_base" placeholder="0">
                   PERSUASION
                   <input class="num" type="text" name="attr_npc_persuasion_base" placeholder="0">
                   RELIGION
                   <input class="num" type="text" name="attr_npc_religion_base" placeholder="0">
                   SLEIGHT OF HAND
                   <input class="num" type="text" name="attr_npc_sleight_of_hand_base" placeholder="0">
                   STEALTH
                   <input class="num" type="text" name="attr_npc_stealth_base" placeholder="0">
                   SURVIVAL
                   <input class="num" type="text" name="attr_npc_survival_base" placeholder="0">
           <input type="hidden" name="attr_npc_acrobatics" value="@{dexterity_mod}">
           <input type="hidden" name="attr_npc_animal_handling" value="@{wisdom_mod}">
           <input type="hidden" name="attr_npc_arcana" value="@{intelligence_mod}">
           <input type="hidden" name="attr_npc_athletics" value="@{strength_mod}">
           <input type="hidden" name="attr_npc_deception" value="@{charisma_mod}">
           <input type="hidden" name="attr_npc_history" value="@{intelligence_mod}">
           <input type="hidden" name="attr_npc_insight" value="@{wisdom_mod}">
           <input type="hidden" name="attr_npc_intimidation" value="@{charisma_mod}">
           <input type="hidden" name="attr_npc_investigation" value="@{intelligence_mod}">
           <input type="hidden" name="attr_npc_medicine" value="@{wisdom_mod}">
           <input type="hidden" name="attr_npc_nature" value="@{intelligence_mod}">
           <input type="hidden" name="attr_npc_perception" value="@{wisdom_mod}">
           <input type="hidden" name="attr_npc_performance" value="@{charisma_mod}">
           <input type="hidden" name="attr_npc_persuasion" value="@{charisma_mod}">
           <input type="hidden" name="attr_npc_religion" value="@{intelligence_mod}">
           <input type="hidden" name="attr_npc_sleight_of_hand" value="@{dexterity_mod}">
           <input type="hidden" name="attr_npc_stealth" value="@{dexterity_mod}">
           <input type="hidden" name="attr_npc_survival" value="@{wisdom_mod}">
           DAMAGE VULNERABILITIES
           <input type="text" name="attr_npc_vulnerabilities" placeholder="fire" data-i18n-placeholder="npc-dmg-vuln-place">
           DAMAGE RESISTANCES
           <input type="text" name="attr_npc_resistances" placeholder="cold" data-i18n-placeholder="npc-dmg-res-place">
           DAMAGE IMMUNITIES
           <input type="text" name="attr_npc_immunities" placeholder="lighting, thunder" data-i18n-placeholder="npc-dmg-imm-place">
           CONDITION IMMUNITIES
           <input type="text" name="attr_npc_condition_immunities" placeholder="charmed" data-i18n-placeholder="npc-cond-imm-place">
           SENSES
           <input type="text" name="attr_npc_senses" placeholder="darkvision 120ft., passive Perception 16" data-i18n-placeholder="npc-senses-place">
           LANGUAGES
           <input type="text" name="attr_npc_languages" placeholder="Abyssal, Common, Infernal" value="—" data-i18n-placeholder="npc-langs-place">
           CHALLENGE
           <input class="num" type="text" name="attr_npc_challenge" placeholder="1">
           XP
           <input type="text" name="attr_npc_xp" placeholder="250">
           TOKEN SIZE
           <input class="text" name="attr_token_size" value="1" placeholder="1">
           <input class="npcspellcastingflag" type="checkbox" name="attr_npcspellcastingflag" value="1">
           SPELLCASTING NPC
               SPELLCASTING ABILITY
               <select name="attr_spellcasting_ability" style="margin: 0px; width: auto; padding: 0px; height: 15px;">
                   <option value="0*" data-i18n="none-u">NONE</option>
                   <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                   <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                   <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                   <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                   <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                   <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
               </select>
                   GLOBAL MAGIC ATTACK MODIFIER:
                   <input type="text" class="num" name="attr_globalmagicmod" placeholder="0" value="0">
                   MAGIC CASTER LEVEL:
                   <input type="text" class="num" name="attr_caster_level">
                   SPELL SAVE DC MOD:
                   <input type="text" class="num" name="attr_spell_dc_mod" placeholder="0" value="0">
           <input type="checkbox" name="attr_npcreactionsflag" value="1">
           HAS REACTIONS
           LEGENDARY ACTIONS:
           <input class="num" type="text" name="attr_npc_legendary_actions" value="0" placeholder="0">
           GENERAL OPTIONS
       <input type="checkbox" name="attr_npc" value="1">
           NPC
           ROLL QUERIES:
           <select name="attr_rtype">
               <option value="Template:Always=1 {{r2=[[@{d20}" data-i18n="always-adv">Always Roll Advantage</option>
               <option value="@{advantagetoggle}" data-i18n="adv-toggle">Advantage Toggle</option>
               <option value="Template:Query=1 ?{Advantage?|Normal Roll,&#123&#123normal=1&#125&#125 &#123&#123r2=[[0d20|Advantage,&#123&#123advantage=1&#125&#125 &#123&#123r2=[[@{d20}|Disadvantage,&#123&#123disadvantage=1&#125&#125 &#123&#123r2=[[@{d20}}" data-i18n="query-adv">Query Advantage</option>
               <option value="Template:Normal=1 {{r2=[[0d20" data-i18n="never-adv">Never Roll Advantage</option>
           </select>
           WHISPER ROLLS TO GM:
           <select name="attr_wtype">
               <option value="" data-i18n="never-whisper-roll">Never Whisper Rolls</option>
               <option value="@{whispertoggle}" data-i18n="toggle-roll-whisper">Whisper Toggle</option>
               <option value="?{Whisper?|Public Roll,|Whisper Roll,/w gm }" data-i18n="query-whisper-roll">Query Whisper</option>
               <option value="/w gm " data-i18n="always-whisper-roll">Always Whisper Rolls</option>
           </select>
           AUTO DAMAGE ROLL:
           <select class="dtype" name="attr_dtype">
               <option value="pick" data-i18n="never-dmg">Don't Auto Roll Damage</option>
               <option value="full" data-i18n="always-dmg">Auto Roll Damage & Crit</option>
           </select>
           NPC NAME IN ROLLS:
           <select name="attr_npc_name_flag">
               <option value="{{name=@{npc_name}}}" data-i18n="show">Show</option>
               <option value="0" data-i18n="hide">Hide</option>
           </select>
           <input type="checkbox" name="attr_init_tiebreaker" value="@{dexterity}/100">
           ADD DEX TIEBREAKER TO INITIATIVE
           <input type="checkbox" name="attr_licensedsheet" value="1">
           USE OFFICIAL D&D STYLING
           <button type="roll" name="roll_npc_init" style="width: 100%;" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{init}}} {{mod=[[[[@{initiative_bonus}]][DEX]]]}} {{r1=[[@{d20}+[[@{initiative_bonus}]][DEX] &{tracker}]]}} Template:Normal=1 Template:Type=Initiative">
               
           </button>
           
           Armor Class
           
           <input class="actype" type="hidden" name="attr_npc_actype" value="">
           
           <button type="roll" name="roll_npc_init" style="position: absolute; right: 5px; height: 30px; width: 20px;" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{init}}} {{mod=[[[[@{initiative_bonus}]][DEX]]]}} {{r1=[[@{d20}+[[@{initiative_bonus}]][DEX] &{tracker}]]}} Template:Normal=1 Template:Type=Initiative">
               t
               INIT
           </button>
           Hit Points
           
           <button type="roll" name="roll_npc_hpformula" value="@{wtype}&{template:npc} Template:Type=Hit Points Template:Normal=1 @{npc_name_flag} {{rname=^{hp}}} {{mod=@{npc_hpformula}}} {{r1=[[@{npc_hpformula}]]}} charname=@{character_name}">
               
           </button>
           Speed
           
               <button type="roll" name="roll_npc_str" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{strength}}} {{mod=[[[[@{strength_mod}]][STR]]]}} {{r1=[[@{d20}+[[@{strength_mod}]][STR]]]}} @{rtype}+[[@{strength_mod}]][STR]]]}} Template:Type=Ability">
                   STR
                   
                   <input class="negativeflag" type="hidden" name="attr_npc_str_negative" value="0">
                   
               </button>
               <button type="roll" name="roll_npc_dex" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{dexterity}}} {{mod=[[[[@{dexterity_mod}]][DEX]]]}} {{r1=[[@{d20}+[[@{dexterity_mod}]][DEX]]]}} @{rtype}+[[@{dexterity_mod}]][DEX]]]}} Template:Type=Ability">
                   DEX
                   
                   <input class="negativeflag" type="hidden" name="attr_npc_dex_negative" value="0">
                   
               </button>
               <button type="roll" name="roll_npc_con" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{constitution}}} {{mod=[[[[@{constitution_mod}]][CON]]]}} {{r1=[[@{d20}+[[@{constitution_mod}]][CON]]]}} @{rtype}+[[@{constitution_mod}]][CON]]]}} Template:Type=Ability">
                   CON
                   
                   <input class="negativeflag" type="hidden" name="attr_npc_con_negative" value="0">
                   
               </button>
               <button type="roll" name="roll_npc_int" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{intelligence}}} {{mod=[[[[@{intelligence_mod}]][INT]]]}} {{r1=[[@{d20}+[[@{intelligence_mod}]][INT]]]}} @{rtype}+[[@{intelligence_mod}]][INT]]]}} Template:Type=Ability">
                   INT
                   
                   <input class="negativeflag" type="hidden" name="attr_npc_int_negative" value="0">
                   
               </button>
               <button type="roll" name="roll_npc_wis" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{wisdom}}} {{mod=[[[[@{wisdom_mod}]][WIS]]]}} {{r1=[[@{d20}+[[@{wisdom_mod}]][WIS]]]}} @{rtype}+[[@{wisdom_mod}]][WIS]]]}} Template:Type=Ability">
                   WIS
                   
                   <input class="negativeflag" type="hidden" name="attr_npc_wis_negative" value="0">
                   
               </button>
               <button type="roll" name="roll_npc_cha" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{charisma}}} {{mod=[[[[@{charisma_mod}]][CHA]]]}} {{r1=[[@{d20}+[[@{charisma_mod}]][CHA]]]}} @{rtype}+[[@{charisma_mod}]][CHA]]]}} Template:Type=Ability">
                   CHA
                   
                   <input class="negativeflag" type="hidden" name="attr_npc_cha_negative" value="0">
                   
               </button>
       <input class="flag" type="hidden" name="attr_npc_saving_flag" value="">
           Saving Throws
           <input class="flag" type="hidden" name="attr_npc_str_save_flag" value="0">
           <button type="roll" name="roll_npc_str_save" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{strength-save}}} {{mod=[[[[@{npc_str_save}]][STR SAVE]]]}} {{r1=[[@{d20}+[[@{npc_str_save}]][STR SAVE]]]}} @{rtype}+[[@{npc_str_save}]][STR SAVE]]]}} Template:Type=Save">
               Str
               
           </button>
           <input class="flag" type="hidden" name="attr_npc_dex_save_flag" value="0">
           <button type="roll" name="roll_npc_dex_save" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{dexterity-save}}} {{mod=[[[[@{npc_dex_save}]][DEX SAVE]]]}} {{r1=[[@{d20}+[[@{npc_dex_save}]][DEX SAVE]]]}} @{rtype}+[[@{npc_dex_save}]][DEX SAVE]]]}} Template:Type=Save">
               Dex
               
           </button>
           <input class="flag" type="hidden" name="attr_npc_con_save_flag" value="0">
           <button type="roll" name="roll_npc_con_save" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{constitution-save}}} {{mod=[[[[@{npc_con_save}]][CON SAVE]]]}} {{r1=[[@{d20}+[[@{npc_con_save}]][CON SAVE]]]}} @{rtype}+[[@{npc_con_save}]][CON SAVE]]]}} Template:Type=Save">
               Con
               
           </button>
           <input class="flag" type="hidden" name="attr_npc_int_save_flag" value="0">
           <button type="roll" name="roll_npc_int_save" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{intelligence-save}}} {{mod=[[[[@{npc_int_save}]][INT SAVE]]]}} {{r1=[[@{d20}+[[@{npc_int_save}]][INT SAVE]]]}} @{rtype}+[[@{npc_int_save}]][INT SAVE]]]}} Template:Type=Save">
               Int
               
           </button>
           <input class="flag" type="hidden" name="attr_npc_wis_save_flag" value="0">
           <button type="roll" name="roll_npc_wis_save" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{wisdom-save}}} {{mod=[[[[@{npc_wis_save}]][WIS SAVE]]]}} {{r1=[[@{d20}+[[@{npc_wis_save}]][WIS SAVE]]]}} @{rtype}+[[@{npc_wis_save}]][WIS SAVE]]]}} Template:Type=Save">
               Wis
               
           </button>
           <input class="flag" type="hidden" name="attr_npc_cha_save_flag" value="0">
           <button type="roll" name="roll_npc_cha_save" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{charisma-save}}} {{mod=[[[[@{npc_cha_save}]][CHA SAVE]]]}} {{r1=[[@{d20}+[[@{npc_cha_save}]][CHA SAVE]]]}} @{rtype}+[[@{npc_cha_save}]][CHA SAVE]]]}} Template:Type=Save">
               Cha
               
           </button>
       <input class="flag" type="hidden" name="attr_npc_skills_flag" value="">
           Skills
           
               <input class="flag" type="hidden" name="attr_npc_acrobatics_flag" value="0">
               <button type="roll" name="roll_npc_acrobatics" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{acrobatics}}} {{mod=@{npc_acrobatics}}} {{r1=[[@{d20}+@{npc_acrobatics}]]}} @{rtype}+@{npc_acrobatics}]]}} Template:Type=Skill">
                   Acrobatics
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_animal_handling_flag" value="0">
               <button type="roll" name="roll_npc_animal_handling" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{animal_handling}}} {{mod=@{npc_animal_handling}}} {{r1=[[@{d20}+@{npc_animal_handling}]]}} @{rtype}+@{npc_animal_handling}]]}} Template:Type=Skill">
                   Animal Handling
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_arcana_flag" value="0">
               <button type="roll" name="roll_npc_arcana" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{arcana}}} {{mod=@{npc_arcana}}} {{r1=[[@{d20}+@{npc_arcana}]]}} @{rtype}+@{npc_arcana}]]}} Template:Type=Skill">
                   Arcana
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_athletics_flag" value="0">
               <button type="roll" name="roll_npc_athletics" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{athletics}}} {{mod=@{npc_athletics}}} {{r1=[[@{d20}+@{npc_athletics}]]}} @{rtype}+@{npc_athletics}]]}} Template:Type=Skill">
                   Athletics
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_deception_flag" value="0">
               <button type="roll" name="roll_npc_deception" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{deception}}} {{mod=@{npc_deception}}} {{r1=[[@{d20}+@{npc_deception}]]}} @{rtype}+@{npc_deception}]]}} Template:Type=Skill">
                   Deception
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_history_flag" value="0">
               <button type="roll" name="roll_npc_history" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{history}}} {{mod=@{npc_history}}} {{r1=[[@{d20}+@{npc_history}]]}} @{rtype}+@{npc_history}]]}} Template:Type=Skill">
                   History
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_insight_flag" value="0">
               <button type="roll" name="roll_npc_insight" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{insight}}} {{mod=@{npc_insight}}} {{r1=[[@{d20}+@{npc_insight}]]}} @{rtype}+@{npc_insight}]]}} Template:Type=Skill">
                   Insight
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_intimidation_flag" value="0">
               <button type="roll" name="roll_npc_intimidation" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{intimidation}}} {{mod=@{npc_intimidation}}} {{r1=[[@{d20}+@{npc_intimidation}]]}} @{rtype}+@{npc_intimidation}]]}} Template:Type=Skill">
                   Intimidation
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_investigation_flag" value="0">
               <button type="roll" name="roll_npc_investigation" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{investigation}}} {{mod=@{npc_investigation}}} {{r1=[[@{d20}+@{npc_investigation}]]}} @{rtype}+@{npc_investigation}]]}} Template:Type=Skill">
                   Investigation
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_medicine_flag" value="0">
               <button type="roll" name="roll_npc_medicine" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{medicine}}} {{mod=@{npc_medicine}}} {{r1=[[@{d20}+@{npc_medicine}]]}} @{rtype}+@{npc_medicine}]]}} Template:Type=Skill">
                   Medicine
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_nature_flag" value="0">
               <button type="roll" name="roll_npc_nature" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{nature}}} {{mod=@{npc_nature}}} {{r1=[[@{d20}+@{npc_nature}]]}} @{rtype}+@{npc_nature}]]}} Template:Type=Skill">
                   Nature
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_perception_flag" value="0">
               <button type="roll" name="roll_npc_perception" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{perception}}} {{mod=@{npc_perception}}} {{r1=[[@{d20}+@{npc_perception}]]}} @{rtype}+@{npc_perception}]]}} Template:Type=Skill">
                   Perception
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_performance_flag" value="0">
               <button type="roll" name="roll_npc_performance" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{performance}}} {{mod=@{npc_performance}}} {{r1=[[@{d20}+@{npc_performance}]]}} @{rtype}+@{npc_performance}]]}} Template:Type=Skill">
                   Performance
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_persuasion_flag" value="0">
               <button type="roll" name="roll_npc_persuasion" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{persuasion}}} {{mod=@{npc_persuasion}}} {{r1=[[@{d20}+@{npc_persuasion}]]}} @{rtype}+@{npc_persuasion}]]}} Template:Type=Skill">
                   Persuasion
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_religion_flag" value="0">
               <button type="roll" name="roll_npc_religion" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{religion}}} {{mod=@{npc_religion}}} {{r1=[[@{d20}+@{npc_religion}]]}} @{rtype}+@{npc_religion}]]}} Template:Type=Skill">
                   Religion
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_sleight_of_hand_flag" value="0">
               <button type="roll" name="roll_npc_sleight_of_hand" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{sleight_of_hand}}} {{mod=@{npc_sleight_of_hand}}} {{r1=[[@{d20}+@{npc_sleight_of_hand}]]}} @{rtype}+@{npc_sleight_of_hand}]]}} Template:Type=Skill">
                   Sleight of Hand
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_stealth_flag" value="0">
               <button type="roll" name="roll_npc_stealth" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{stealth}}} {{mod=@{npc_stealth}}} {{r1=[[@{d20}+@{npc_stealth}]]}} @{rtype}+@{npc_stealth}]]}} Template:Type=Skill">
                   Stealth
                   
               </button>
           
           
               <input class="flag" type="hidden" name="attr_npc_survival_flag" value="0">
               <button type="roll" name="roll_npc_survival" value="@{wtype}&{template:npc} @{npc_name_flag} {{rname=^{survival}}} {{mod=@{npc_survival}}} {{r1=[[@{d20}+@{npc_survival}]]}} @{rtype}+@{npc_survival}]]}} Template:Type=Skill">
                   Survival
                   
               </button>
           
       <input class="flag" type="hidden" name="attr_npc_vulnerabilities">
           Damage Vulnerabilities
           
       <input class="flag" type="hidden" name="attr_npc_resistances">
           Damage Resistances
           
       <input class="flag" type="hidden" name="attr_npc_immunities">
           Damage Immunities
           
       <input class="flag" type="hidden" name="attr_npc_condition_immunities">
           Condition Immunities
           
           Senses
           
           Languages
           
           Challenge
           
           
           <fieldset class="repeating_npctrait">
                   <input type="text" name="attr_name" placeholder="False Appearance." data-i18n-placeholder="npc-trait-name-place">
                   <textarea name="attr_desc" placeholder="If the dragon fails..." data-i18n-placeholder="npc-trait-desc-place"></textarea>
           </fieldset>
       <input class="dflag" type="hidden" name="attr_dflag" value="pick">
               Actions
           <fieldset class="repeating_npcaction">
                   <input class="npc_options-flag" type="checkbox" name="attr_npc_options-flag" checked="checked">y
                           NAME:
                           <input type="text" name="attr_name">
                           <input type="checkbox" name="attr_attack_flag" value="on">
                           ATTACK
                       <input type="hidden" class="attack_options" name="attr_attack_flag" value="0">
                           TYPE:
                           <select name="attr_attack_type">
                               <option value="Melee" data-i18n="melee">Melee</option>
                               <option value="Ranged" data-i18n="ranged">Ranged</option>
                           </select>
                           RANGE/REACH:
                           <input type="text" name="attr_attack_range" placeholder="5 ft." style="width: 100px;" data-i18n-placeholder="range-reach-place">
                           TO HIT:
                           <input type="text" name="attr_attack_tohit" value="0" placeholder="5" style="width: 30px;">
                           TARGET:
                           <input type="text" name="attr_attack_target" placeholder="One target" style="width: 100px;" data-i18n-placeholder="to-hit-place">
                       <input type="hidden" name="attr_damage_flag">
                           ON HIT:
                           <input type="text" name="attr_attack_damage" placeholder="1d10" style="width: 65px;">
                           <input type="text" name="attr_attack_damagetype" placeholder="slashing" style="width: 100px;" data-i18n-placeholder="on-hit-place">
                           <input type="hidden" name="attr_attack_crit">
                           ON HIT 2:
                           <input type="text" name="attr_attack_damage2" placeholder="2d6+5" style="width: 65px;">
                           <input type="text" name="attr_attack_damagetype2" placeholder="fire" style="width: 100px;" data-i18n-placeholder="on-hit-2-place">
                           <input type="hidden" name="attr_attack_crit2">
                           DESCRIPTION:
                           <select name="attr_show_desc">
                               <option value="@{description}" data-i18n="show">Show</option>
                               <option value=" " data-i18n="hide">Hide</option>
                           </select>
                           <textarea name="attr_description"></textarea>
                       <button class="pick" type="roll" name="roll_npc_action" value="@{rollbase}">
                               
                           <input class="attack_options" type="hidden" name="attr_attack_flag">
                                Weapon Attack: 
                               Hit: 
                           
                       </button>
                   <input type="hidden" name="attr_rollbase">
                   <button type="roll" style="display: none;" name="roll_npc_dmg" value="@{wtype}&{template:npcdmg} @{damage_flag} {{dmg1=[[@{attack_damage}+0]]}} {{dmg1type=@{attack_damagetype}}} {{dmg2=[[@{attack_damage2}+0]]}} {{dmg2type=@{attack_damagetype2}}}"></button>
                   <button type="roll" style="display: none;" name="roll_npc_crit" value="@{wtype}&{template:npcdmg} @{damage_flag} Template:Crit=1 {{dmg1=[[@{attack_damage}+0]]}} {{dmg1type=@{attack_damagetype}}} {{dmg2=[[@{attack_damage2}+0]]}} {{dmg2type=@{attack_damagetype2}}} {{crit1=[[@{attack_crit}+0]]}} {{crit2=[[@{attack_crit2}+0]]}}"></button>
           </fieldset>
       <input class="reaction_flag" type="hidden" name="attr_npcreactionsflag">
               Reactions
           <fieldset class="repeating_npcreaction">
                   <input type="text" name="attr_name" placeholder="Parry." data-i18n-placeholder="npc-repeating-name-place">
                   <textarea name="attr_desc" placeholder="The creature adds 2 to its AC against..." data-i18n-placeholder="npc-repeating-desc-place"></textarea>
           </fieldset>
       <input class="legendary_flag" type="hidden" name="attr_npc_legendary_actions" value="0">
               Legendary Actions
           <fieldset class="repeating_npcaction-l">
                   <input class="npc_options-flag" type="checkbox" name="attr_npc_options-flag" checked="checked">y
                           NAME:
                           <input type="text" name="attr_name">
                           <input type="checkbox" name="attr_attack_flag" value="on">
                           ATTACK
                       <input type="hidden" class="attack_options" name="attr_attack_flag" value="0">
                           TYPE:
                           <select name="attr_attack_type">
                               <option value="Melee" data-i18n="melee">Melee</option>
                               <option value="Ranged" data-i18n="ranged">Ranged</option>
                           </select>
                           RANGE/REACH:
                           <input type="text" name="attr_attack_range" placeholder="5 ft." style="width: 100px;" data-i18n-placeholder="range-reach-place">
                           TO HIT:
                           <input type="text" name="attr_attack_tohit" value="0" placeholder="5" style="width: 30px;">
                           TARGET:
                           <input type="text" name="attr_attack_target" placeholder="One target" style="width: 100px;" data-i18n-placeholder="to-hit-place">
                       <input type="hidden" name="attr_damage_flag">
                           ON HIT:
                           <input type="text" name="attr_attack_damage" placeholder="1d10" style="width: 65px;">
                           <input type="text" name="attr_attack_damagetype" placeholder="slashing" style="width: 100px;" data-i18n-placeholder="on-hit-place">
                           <input type="hidden" name="attr_attack_crit">
                           ON HIT 2:
                           <input type="text" name="attr_attack_damage2" placeholder="2d6+5" style="width: 65px;">
                           <input type="text" name="attr_attack_damagetype2" placeholder="fire" style="width: 100px;" data-i18n-placeholder="on-hit-2-place">
                           <input type="hidden" name="attr_attack_crit2">
                           DESCRIPTION:
                           <select name="attr_show_desc">
                               <option value="@{description}" data-i18n="show">Show</option>
                               <option value=" " data-i18n="hide">Hide</option>
                           </select>
                           <textarea name="attr_description"></textarea>
                       <button class="pick" type="roll" name="roll_npc_action" value="@{rollbase}">
                               
                           <input class="attack_options" type="hidden" name="attr_attack_flag">
                                Weapon Attack: 
                               Hit: 
                           
                       </button>
                   <input type="hidden" name="attr_rollbase">
                   <button type="roll" style="display: none;" name="roll_npc_dmg" value="@{wtype}&{template:npcdmg} @{damage_flag} {{dmg1=[[@{attack_damage}+0]]}} {{dmg1type=@{attack_damagetype}}} {{dmg2=[[@{attack_damage2}+0]]}} {{dmg2type=@{attack_damagetype2}}}"></button>
                   <button type="roll" style="display: none;" name="roll_npc_crit" value="@{wtype}&{template:npcdmg} @{damage_flag} Template:Crit=1 {{dmg1=[[@{attack_damage}+0]]}} {{dmg1type=@{attack_damagetype}}} {{dmg2=[[@{attack_damage2}+0]]}} {{dmg2type=@{attack_damagetype2}}} {{crit1=[[@{attack_crit}+0]]}} {{crit2=[[@{attack_crit2}+0]]}}"></button>
           </fieldset>
       <input class="npcspell_flag" type="hidden" name="attr_npcspell_flag">
               Spells
THIS SECTION IS DEPRECATED. PLEASE TRANSFER ANY SPELLS LISTED HERE INTO THE NEW SPELLS BY LEVEL SECTION, AVAILABLE AFTER SELECTING THE 'SPELLCASTING NPC' OPTION FROM THE NPC OPTIONS ABOVE.
               <fieldset class="repeating_spell-npc">
                       <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                               NAME:
                               <input type="text" name="attr_spellname">
                               SCHOOL:
                               <select name="attr_spellschool">
                                   <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                   <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                   <option value="divination" data-i18n="divination">Divination</option>
                                   <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                   <option value="evocation" data-i18n="evocation">Evocation</option>
                                   <option value="illusion" data-i18n="illusion">Illusion</option>
                                   <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                   <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                               </select>
                               <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                               RITUAL
                               CASTING TIME:
                               <input type="text" name="attr_spellcastingtime">
                               RANGE:
                               <input type="text" name="attr_spellrange">
                               TARGET:
                               <input type="text" name="attr_spelltarget">
                           <input type="hidden" name="attr_spellcomp">
                               COMPONENTS:
                               <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                               V
                               <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                               S
                               <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                               M
                               <input type="text" name="attr_spellcomp_materials" style="margin-left: 17px;" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                               <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                               CONCENTRATION
                               DURATION:
                               <input type="text" name="attr_spellduration">
                               INNATE:
                               <input type="text" name="attr_innate" placeholder="1/day" value="">
                               OUTPUT:
                               <select name="attr_spelloutput">
                                   <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                   <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                               </select>
                           <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                   SPELL ATTACK:
                                   <select name="attr_spellattack">
                                       <option value="None" data-i18n="none">None</option>
                                       <option value="Melee" data-i18n="melee">Melee</option>
                                       <option value="Melee" data-i18n="ranged">Ranged</option>
                                   </select>
                                   DAMAGE:
                                   <input type="text" name="attr_spelldamage" style="width: 50px;">
                                   TYPE:
                                   <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                   DAMAGE2:
                                   <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                   HEALING:
                                   <input type="text" name="attr_spellhealing" style="width: 45px;">
                                   <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                   ADD ABILITY MOD TO DAMAGE OR HEALING
                                   SAVING THROW:
                                   <select name="attr_spellsave">
                                       <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                       <option value="Strength" data-i18n="str-u">STR</option>
                                       <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                       <option value="Constitution" data-i18n="con-u">CON</option>
                                       <option value="Intelligence" data-i18n="int-u">INT</option>
                                       <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                       <option value="Charisma" data-i18n="cha-u">CHA</option>
                                   </select>
                                   EFFECT:
                                   <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="npc-atk-effect-place">
                                   HIGHER LVL CAST DMG:
                                   <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                   <select name="attr_spellhldietype">
                                       <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                       <option value="d4">d4</option>
                                       <option value="d6">d6</option>
                                       <option value="d8">d8</option>
                                       <option value="d10">d10</option>
                                       <option value="d12">d12</option>
                                       <option value="d20">d20</option>
                                   </select>
                                   +
                                   <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                   INCLUDE SPELL DESCRIPTION IN ATTACK:
                                   <select name="attr_includedesc">
                                       <option value="on" data-i18n="on">On</option>
                                       <option value="off" selected="selected" data-i18n="off">Off</option>
                                   </select>
                               DESCRIPTION:
                               <textarea name="attr_spelldescription"></textarea>
                               AT HIGHER LEVELS:
                               <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                           <input type="hidden" name="attr_spellattackid">
                           <input type="hidden" name="attr_spelllevel">
                           <input type="hidden" name="attr_rollbase">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output}">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               <input type="hidden" name="attr_spellprepared">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           R
                           C
               </fieldset>
   <input class="tab-button core" name="attr_tab" type="radio" value="core" checked="checked"/>CORE
   <input class="tab-button bio" name="attr_tab" type="radio" value="bio"/>BIO
   <input class="tab-button spells" name="attr_tab" type="radio" value="spells"/>SPELLS
   <input class="tab-button options" name="attr_tab" type="radio" value="options"/>y
           <img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/srd5_360.png" style="padding-bottom: 5px;" alt="SRD5 by Roll20">
           <input type="text" name="attr_character_name" style="width: 100%;">
           CHARACTER NAME
       <input class="options-flag" type="checkbox" name="attr_options-class-selection" checked="checked">y
               CLASS:
               <input type="hidden" name="attr_custom_class" class="sheet-flag">
               <select class="hiding class" name="attr_class">
                   <option value="" data-i18n="choose">Choose</option>
                   <option value="Artificer" data-i18n="artificer">Artificer</option>
                   <option value="Barbarian" data-i18n="barbarian">Barbarian</option>
                   <option value="Bard" data-i18n="bard">Bard</option>
                   <option value="Cleric" data-i18n="cleric">Cleric</option>
                   <option value="Druid" data-i18n="druid">Druid</option>
                   <option value="Fighter" data-i18n="fighter">Fighter</option>
                   <option value="Monk" data-i18n="monk">Monk</option>
                   <option value="Paladin" data-i18n="paladin">Paladin</option>
                   <option value="Ranger" data-i18n="ranger">Ranger</option>
                   <option value="Rogue" data-i18n="rogue">Rogue</option>
                   <option value="Sorcerer" data-i18n="sorcerer">Sorcerer</option>
                   <option value="Warlock" data-i18n="warlock">Warlock</option>
                   <option value="Wizard" data-i18n="wizard">Wizard</option>
               </select>
               <input type="text" class="showing" name="attr_cust_classname" style="width: 90px;">
               SUBCLASS:
               <input type="text" name="attr_subclass">
               LEVEL:
               <input type="number" class="class-level" style="width: 40px" name="attr_base_level" value="1">
               RACE:
               <input type="text" name="attr_race">
               SUBRACE:
               <input type="text" name="attr_subrace">
                   <input type="text" name="attr_class_display" class="sheet-class-display sheet-no_events">
                   CLASS & LEVEL
                   <input type="text" name="attr_background" style="width: 182px;">
                   BACKGROUND
                   <input type="text" name="attr_race_display" class="sheet-no_events">
                   RACE
                   <input type="text" name="attr_alignment">
                   ALIGNMENT
                   <input type="text" name="attr_experience">
                   EXPERIENCE POINTS
                   <input class="sheet-showleveler" type="hidden" name="attr_showleveler" value="0">
                   <button class="sheet-levelerbutton" type="action" name="act_launch_lvl+mancer" style="padding: 0px; position: absolute; top: -10px; right: 0px;" title="Charactermancer Level Up"><img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/CharactermancerIcon200px.png" style="height: 18px; width: 18px; max-width: inherit;" alt="Wand & Hammer logo of Charactermancer"></button>
                   <button type="roll" name="roll_strength" value="@{wtype}&{template:simple} {{rname=^{strength-u}}} {{mod=@{strength_mod}@{jack_bonus}}} {{r1=[[@{d20}+@{strength_mod}@{jack_attr}[STR]]]}} @{rtype}+@{strength_mod}@{jack_attr}[STR]]]}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="strength-u">STRENGTH</button>
                   0
                       <input class="baseattr" type="text" name="attr_strength_base" title="@{strength}" value="10">
                       <input type="hidden" name="attr_strength" value="10">
                       <input class="attr-flag" type="hidden" name="attr_strength_flag" value="0">
                       
                   <button type="roll" name="roll_dexterity" value="@{wtype}&{template:simple} {{rname=^{dexterity-u}}} {{mod=@{dexterity_mod}@{jack_bonus}}} {{r1=[[@{d20}+@{dexterity_mod}@{jack_attr}[DEX]]]}} @{rtype}+@{dexterity_mod}@{jack_attr}[DEX]]]}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="dexterity-u">DEXTERITY</button>
                   0
                       <input class="baseattr" type="text" name="attr_dexterity_base" title="@{dexterity}" value="10">
                       <input type="hidden" name="attr_dexterity" value="10">
                       <input class="attr-flag" type="hidden" name="attr_dexterity_flag" value="0">
                       
                   <button type="roll" name="roll_constitution" value="@{wtype}&{template:simple} {{rname=^{constitution-u}}} {{mod=@{constitution_mod}@{jack_bonus}}} {{r1=[[@{d20}+@{constitution_mod}@{jack_attr}[CON]]]}} @{rtype}+@{constitution_mod}@{jack_attr}[CON]]]}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="constitution-u">CONSTITUTION</button>
                   0
                       <input class="baseattr" type="text" name="attr_constitution_base" title="@{constitution}" value="10">
                       <input type="hidden" name="attr_constitution" value="10">
                       <input class="attr-flag" type="hidden" name="attr_constitution_flag" value="0">
                       
                   <button type="roll" name="roll_intelligence" value="@{wtype}&{template:simple} {{rname=^{intelligence-u}}} {{mod=@{intelligence_mod}@{jack_bonus}}} {{r1=[[@{d20}+@{intelligence_mod}@{jack_attr}[INT]]]}} @{rtype}+@{intelligence_mod}@{jack_attr}[INT]]]}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="intelligence-u">INTELLIGENCE</button>
                   0
                       <input class="baseattr" type="text" name="attr_intelligence_base" title="@{intelligence}" value="10">
                       <input type="hidden" name="attr_intelligence" value="10">
                       <input class="attr-flag" type="hidden" name="attr_intelligence_flag" value="0">
                       
                   <button type="roll" name="roll_wisdom" value="@{wtype}&{template:simple} {{rname=^{wisdom-u}}} {{mod=@{wisdom_mod}@{jack_bonus}}} {{r1=[[@{d20}+@{wisdom_mod}@{jack_attr}[WIS]]]}} @{rtype}+@{wisdom_mod}@{jack_attr}[WIS]]]}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="wisdom-u">WISDOM</button>
                   0
                       <input class="baseattr" type="text" name="attr_wisdom_base" title="@{wisdom}" value="10">
                       <input type="hidden" name="attr_wisdom" value="10">
                       <input class="attr-flag" type="hidden" name="attr_wisdom_flag" value="0">
                       
                   <button type="roll" name="roll_charisma" value="@{wtype}&{template:simple} {{rname=^{charisma-u}}} {{mod=@{charisma_mod}@{jack_bonus}}} {{r1=[[@{d20}+@{charisma_mod}@{jack_attr}[CHA]]]}} @{rtype}+@{charisma_mod}@{jack_attr}[CHA]]]}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="charisma-u">CHARISMA</button>
                   0
                       <input class="baseattr" type="text" name="attr_charisma_base" title="@{charisma}" value="10">
                       <input type="hidden" name="attr_charisma" value="10">
                       <input class="attr-flag" type="hidden" name="attr_charisma_flag" value="0">
                       
                       <input type="checkbox" name="attr_inspiration">
                       INSPIRATION
                       
                       PROFICIENCY BONUS
                       <input type="checkbox" name="attr_strength_save_prof" title="@{strength_save_prof}" value="(@{pb})">
                       0
                       <button type="roll" name="roll_strength_save" value="@{wtype}&{template:simple} {{rname=^{strength-save-u}}} {{mod=@{strength_save_bonus}}} {{r1=[[@{d20}+@{strength_save_bonus}@{pbd_safe}]]}} @{rtype}+@{strength_save_bonus}@{pbd_safe}]]}} {{global=@{global_save_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="strength">Strength</button>
                       <input type="checkbox" name="attr_dexterity_save_prof" title="@{dexterity_save_prof}" value="(@{pb})">
                       0
                       <button type="roll" name="roll_dexterity_save" value="@{wtype}&{template:simple} {{rname=^{dexterity-save-u}}} {{mod=@{dexterity_save_bonus}}} {{r1=[[@{d20}+@{dexterity_save_bonus}@{pbd_safe}]]}} @{rtype}+@{dexterity_save_bonus}@{pbd_safe}]]}} {{global=@{global_save_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="dexterity">Dexterity</button>
                       <input type="checkbox" name="attr_constitution_save_prof" title="@{constitution_save_prof}" value="(@{pb})">
                       0
                       <button type="roll" name="roll_constitution_save" value="@{wtype}&{template:simple} {{rname=^{constitution-save-u}}} {{mod=@{constitution_save_bonus}}} {{r1=[[@{d20}+@{constitution_save_bonus}@{pbd_safe}]]}} @{rtype}+@{constitution_save_bonus}@{pbd_safe}]]}} {{global=@{global_save_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="constitution">Constitution</button>
                       <input type="checkbox" name="attr_intelligence_save_prof" title="@{intelligence_save_prof}" value="(@{pb})">
                       0
                       <button type="roll" name="roll_intelligence_save" value="@{wtype}&{template:simple} {{rname=^{intelligence-save-u}}} {{mod=@{intelligence_save_bonus}}} {{r1=[[@{d20}+@{intelligence_save_bonus}@{pbd_safe}]]}} @{rtype}+@{intelligence_save_bonus}@{pbd_safe}]]}} {{global=@{global_save_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="intelligence">Intelligence</button>
                       <input type="checkbox" name="attr_wisdom_save_prof" title="@{wisdom_save_prof}" value="(@{pb})">
                       0
                       <button type="roll" name="roll_wisdom_save" value="@{wtype}&{template:simple} {{rname=^{wisdom-save-u}}} {{mod=@{wisdom_save_bonus}}} {{r1=[[@{d20}+@{wisdom_save_bonus}@{pbd_safe}]]}} @{rtype}+@{wisdom_save_bonus}@{pbd_safe}]]}} {{global=@{global_save_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="wisdom">Wisdom</button>
                       <input type="checkbox" name="attr_charisma_save_prof" title="@{charisma_save_prof}" value="(@{pb})">
                       0
                       <button type="roll" name="roll_charisma_save" value="@{wtype}&{template:simple} {{rname=^{charisma-save-u}}} {{mod=@{charisma_save_bonus}}} {{r1=[[@{d20}+@{charisma_save_bonus}@{pbd_safe}]]}} @{rtype}+@{charisma_save_bonus}@{pbd_safe}]]}} {{global=@{global_save_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="charisma">Charisma</button>
                   <input type="hidden" class="toggleflag" name="attr_global_save_mod_flag">
                       SAVING THROWS
                           <input type="checkbox" name="attr_acrobatics_prof" title="@{acrobatics_prof}" value="(@{pb}*@{acrobatics_type})">
                           0
                           <button type="roll" name="roll_acrobatics" value="@{wtype}&{template:simple} {{rname=^{acrobatics-u}}} {{mod=@{acrobatics_bonus}}} {{r1=[[@{d20}+@{acrobatics_bonus}@{pbd_safe}]]}} @{rtype}+@{acrobatics_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="acrobatics-core">Acrobatics (Dex)</button>
                           <input type="checkbox" name="attr_animal_handling_prof" title="@{animal_handling_prof}" value="(@{pb}*@{animal_handling_type})">
                           0
                           <button type='roll' name='roll_animal_handling' value='@{wtype}&{template:simple} {{rname=^{animal_handling-u}}} {{mod=@{animal_handling_bonus}}} {{r1=[[@{d20}+@{animal_handling_bonus}@{pbd_safe}]]}} @{rtype}+@{animal_handling_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='animal_handling-core'>Animal Handling (Wis)</button>
                           <input type="checkbox" name="attr_arcana_prof" title="@{arcana_prof}" value="(@{pb}*@{arcana_type})">
                           0
                           <button type='roll' name='roll_arcana' value='@{wtype}&{template:simple} {{rname=^{arcana-u}}} {{mod=@{arcana_bonus}}} {{r1=[[@{d20}+@{arcana_bonus}@{pbd_safe}]]}} @{rtype}+@{arcana_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='arcana-core'>Arcana (Int)</button>
                           <input type="checkbox" name="attr_athletics_prof" title="@{athletics_prof}" value="(@{pb}*@{athletics_type})">
                           0
                           <button type='roll' name='roll_athletics' value='@{wtype}&{template:simple} {{rname=^{athletics-u}}} {{mod=@{athletics_bonus}}} {{r1=[[@{d20}+@{athletics_bonus}@{pbd_safe}]]}} @{rtype}+@{athletics_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='athletics-core'>Athletics (Str)</button>
                           <input type="checkbox" name="attr_deception_prof" title="@{deception_prof}" value="(@{pb}*@{deception_type})">
                           0
                           <button type='roll' name='roll_deception' value='@{wtype}&{template:simple} {{rname=^{deception-u}}} {{mod=@{deception_bonus}}} {{r1=[[@{d20}+@{deception_bonus}@{pbd_safe}]]}} @{rtype}+@{deception_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='deception-core'>Deception (Cha)</button>
                           <input type="checkbox" name="attr_history_prof" title="@{history_prof}" value="(@{pb}*@{history_type})">
                           0
                           <button type='roll' name='roll_history' value='@{wtype}&{template:simple} {{rname=^{history-u}}} {{mod=@{history_bonus}}} {{r1=[[@{d20}+@{history_bonus}@{pbd_safe}]]}} @{rtype}+@{history_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='history-core'>History (Int)</button>
                           <input type="checkbox" name="attr_insight_prof" title="@{insight_prof}" value="(@{pb}*@{insight_type})">
                           0
                           <button type='roll' name='roll_insight' value='@{wtype}&{template:simple} {{rname=^{insight-u}}} {{mod=@{insight_bonus}}} {{r1=[[@{d20}+@{insight_bonus}@{pbd_safe}]]}} @{rtype}+@{insight_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='insight-core'>Insight (Wis)</button>
                           <input type="checkbox" name="attr_intimidation_prof" title="@{intimidation_prof}" value="(@{pb}*@{intimidation_type})">
                           0
                           <button type='roll' name='roll_intimidation' value='@{wtype}&{template:simple} {{rname=^{intimidation-u}}} {{mod=@{intimidation_bonus}}} {{r1=[[@{d20}+@{intimidation_bonus}@{pbd_safe}]]}} @{rtype}+@{intimidation_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='intimidation-core'>Intimidation (Cha)</button>
                           <input type="checkbox" name="attr_investigation_prof" title="@{investigation_prof}" value="(@{pb}*@{investigation_type})">
                           0
                           <button type='roll' name='roll_investigation' value='@{wtype}&{template:simple} {{rname=^{investigation-u}}} {{mod=@{investigation_bonus}}} {{r1=[[@{d20}+@{investigation_bonus}@{pbd_safe}]]}} @{rtype}+@{investigation_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='investigation-core'>Investigation (Int)</button>
                           <input type="checkbox" name="attr_medicine_prof" title="@{medicine_prof}" value="(@{pb}*@{medicine_type})">
                           0
                           <button type='roll' name='roll_medicine' value='@{wtype}&{template:simple} {{rname=^{medicine-u}}} {{mod=@{medicine_bonus}}} {{r1=[[@{d20}+@{medicine_bonus}@{pbd_safe}]]}} @{rtype}+@{medicine_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='medicine-core'>Medicine (Wis)</button>
                           <input type="checkbox" name="attr_nature_prof" title="@{nature_prof}" value="(@{pb}*@{nature_type})">
                           0
                           <button type='roll' name='roll_nature' value='@{wtype}&{template:simple} {{rname=^{nature-u}}} {{mod=@{nature_bonus}}} {{r1=[[@{d20}+@{nature_bonus}@{pbd_safe}]]}} @{rtype}+@{nature_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='nature-core'>Nature (Int)</button>
                           <input type="checkbox" name="attr_perception_prof" title="@{perception_prof}" value="(@{pb}*@{perception_type})">
                           0
                           <button type='roll' name='roll_perception' value='@{wtype}&{template:simple} {{rname=^{perception-u}}} {{mod=@{perception_bonus}}} {{r1=[[@{d20}+@{perception_bonus}@{pbd_safe}]]}} @{rtype}+@{perception_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='perception-core'>Perception (Wis)</button>
                           <input type="checkbox" name="attr_performance_prof" title="@{performance_prof}" value="(@{pb}*@{performance_type})">
                           0
                           <button type='roll' name='roll_performance' value='@{wtype}&{template:simple} {{rname=^{performance-u}}} {{mod=@{performance_bonus}}} {{r1=[[@{d20}+@{performance_bonus}@{pbd_safe}]]}} @{rtype}+@{performance_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='performance-core'>Performance (Cha)</button>
                           <input type="checkbox" name="attr_persuasion_prof" title="@{persuasion_prof}" value="(@{pb}*@{persuasion_type})">
                           0
                           <button type='roll' name='roll_persuasion' value='@{wtype}&{template:simple} {{rname=^{persuasion-u}}} {{mod=@{persuasion_bonus}}} {{r1=[[@{d20}+@{persuasion_bonus}@{pbd_safe}]]}} @{rtype}+@{persuasion_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='persuasion-core'>Persuasion (Wis)</button>
                           <input type="checkbox" name="attr_religion_prof" title="@{religion_prof}" value="(@{pb}*@{religion_type})">
                           0
                           <button type='roll' name='roll_religion' value='@{wtype}&{template:simple} {{rname=^{religion-u}}} {{mod=@{religion_bonus}}} {{r1=[[@{d20}+@{religion_bonus}@{pbd_safe}]]}} @{rtype}+@{religion_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='religion-core'>Religion (Int)</button>
                           <input type="checkbox" name="attr_sleight_of_hand_prof" title="@{sleight_of_hand_prof}" value="(@{pb}*@{sleight_of_hand_type})">
                           0
                           <button type='roll' name='roll_sleight_of_hand' value='@{wtype}&{template:simple} {{rname=^{sleight_of_hand-u}}} {{mod=@{sleight_of_hand_bonus}}} {{r1=[[@{d20}+@{sleight_of_hand_bonus}@{pbd_safe}]]}} @{rtype}+@{sleight_of_hand_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='sleight_of_hand-core'>Sleight of Hand (Dex)</button>
                           <input type="checkbox" name="attr_stealth_prof" title="@{stealth_prof}" value="(@{pb}*@{stealth_type})">
                           0
                           <button type='roll' name='roll_stealth' value='@{wtype}&{template:simple} {{rname=^{stealth-u}}} {{mod=@{stealth_bonus}}} {{r1=[[@{d20}+@{stealth_bonus}@{pbd_safe}]]}} @{rtype}+@{stealth_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='stealth-core'>Stealth (Dex)</button>
                           <input type="checkbox" name="attr_survival_prof" title="@{survival_prof}" value="(@{pb}*@{survival_type})">
                           0
                           <button type='roll' name='roll_survival' value='@{wtype}&{template:simple} {{rname=^{survival-u}}} {{mod=@{survival_bonus}}} {{r1=[[@{d20}+@{survival_bonus}@{pbd_safe}]]}} @{rtype}+@{survival_bonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}' data-i18n='survival-core'>Survival (Wis)</button>
                       SKILLS
                   
                   PASSIVE WISDOM (PERCEPTION)
                   TOOL
                   PRO
                   ATTRIBUTE
                <fieldset class="repeating_tool">
                       <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                               NAME:
                               <input type="text" name="attr_toolname" style="width: 120px;">
                               PROFICIENCY BONUS:
                               <select name="attr_toolbonus_base">
                                   <option value="(@{pb})" selected="selected" data-i18n="prof-u">PROFICIENT</option>
                                   <option value="(@{pb}*2)" data-i18n="expertise-u">EXPERTISE</option>
                                   <option value="(floor(@{pb}/2))" data-i18n="jack-of-all-u">JACK OF ALL TRADES</option>
                               </select>
                               ATTRIBUTE:
                               <select name="attr_toolattr_base">
                                   <option value="@{strength_mod}" selected="selected" data-i18n="strength-u">STRENGTH</option>
                                   <option value="@{dexterity_mod}" data-i18n="dexterity-u">DEXTERITY</option>
                                   <option value="@{constitution_mod}" data-i18n="constitution-u">CONSTITUTION</option>
                                   <option value="@{intelligence_mod}" data-i18n="intelligence-u">INTELLIGENCE</option>
                                   <option value="@{wisdom_mod}" data-i18n="wisdom-u">WISDOM</option>
                                   <option value="@{charisma_mod}" data-i18n="charisma-u">CHARISMA</option>
                                   <option value="?{Attribute?|Strength,@{strength_mod}|Dexterity,@{dexterity_mod}|Constitution,@{constitution_mod}|Intelligence,@{intelligence_mod}|Wisdom,@{wisdom_mod}|Charisma,@{charisma_mod}}" data-i18n="query-attr-u">QUERY ATTRIBUTE</option>
                               </select>
                               MODS:
                               <input type="text" class="num" name="attr_tool_mod" title="@{tool_mod}" value="0">
                           <button type="roll" name="roll_tool" value="@{wtype}&{template:simple} {{rname=@{toolname}}} {{mod=@{toolbonus}}} {{r1=[[@{d20}+@{toolbonus}@{pbd_safe}]]}} @{rtype}+@{toolbonus}@{pbd_safe}]]}} {{global=@{global_skill_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                               
                               <input type="text" name="attr_toolbonus_display" style="width: 40px; text-align: center;">
                               <input type="hidden" name="attr_toolbonus">
                               <input type="text" name="attr_toolattr" style="width: 80px;">
                           </button>
               </fieldset>
               <input type="hidden" class="toggleflag" name="attr_global_skill_mod_flag">
                   TOOL PROFICIENCIES & CUSTOM SKILLS
               <input type="hidden" class="inventoryflag" name="attr_simpleproficencies" value="complex">
               <textarea class="sheet-simple" name="attr_other_proficiencies_and_languages" style="min-height: 91px; height: 91px;"></textarea>
                       TYPE
                       PROFICIENCY
                   <fieldset class="repeating_proficiencies">
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   TYPE:
                                   <select name="attr_prof_type">
                                       <option selected="selected" data-i18n="lang-u">LANGUAGE</option>
                                       <option data-i18n="weapon-u">WEAPON</option>
                                       <option data-i18n="armor-u">ARMOR</option>
                                       <option data-i18n="other-u">OTHER</option>
                                   </select>
                                   PROFICIENCY:
                                   <input type="text" name="attr_name" style="width: 165px;" placeholder="Elven, Dwarven, and Common">
                               <button type="roll" name="roll_output" value="@{wtype}&{template:traits} @{charname_output} {{name=@{prof_type} PROFICIENCY}} {{description=@{name}}} {{licensedsheet=@{licensedsheet}}}">
                                   
                                   
                               </button>
                   </fieldset>
                   OTHER PROFICIENCIES & LANGUAGES
                   <input type="text" name="attr_ac" title="@{ac}">
                   ARMOR CLASS
                   
                   <button type="roll" name="roll_initiative" value="@{wtype}&{template:simple} {{rname=^{init-u}}} {{mod=@{initiative_bonus}}} {{r1=[[@{initiative_style}+@{initiative_bonus}@{pbd_safe}[INIT] &{tracker}]]}} Template:Normal=1 @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="init-u">INITIATIVE</button>
                   <input type="text" name="attr_speed" title="@{speed}">
                   SPEED
                   Hit Point Maximum
                   <input type="text" name="attr_hp_max" title="@{hp_max}">
               <input type="number" name="attr_hp" title="@{hp}">
               CURRENT HIT POINTS
               <input type="number" name="attr_hp_temp" title="@{hp_temp}">
               TEMPORARY HIT POINTS
                       Total
                       <input type="text" name="attr_hit_dice_max" title="@{hit_dice_max}">
                   <input type="number" name="attr_hit_dice" title="@{hit_dice}" style="margin-bottom: -6px;">
                   <button type="roll" name="roll_hit_dice" value="@{wtype}&{template:simple} {{rname=^{hit-dice-u}}} {{mod=D@{hitdie_final}+[[@{constitution_mod}[CON]]]}} {{r1=[[1d@{hitdie_final}+[[@{constitution_mod}]][CON]]]}} Template:Normal=1 @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="hit-dice-u">HIT DICE</button>
                       SUCCESSES
                       <input type="checkbox" name="attr_deathsave_succ1">
                       <input type="checkbox" name="attr_deathsave_succ2">
                       <input type="checkbox" name="attr_deathsave_succ3">
                       FAILURES
                       <input type="checkbox" name="attr_deathsave_fail1">
                       <input type="checkbox" name="attr_deathsave_fail2">
                       <input type="checkbox" name="attr_deathsave_fail3">
                   <button type="roll" name="roll_death_save" style="margin-top: 6px;" value="@{wtype}&{template:simple} {{rname=^{death-save-u}}} {{mod=@{death_save_bonus}}} {{r1=[[@{d20}+@{death_save_bonus}[MOD]@{globalsavingthrowbonus}]]}} Template:Normal=1 {{global=@{global_save_mod}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}" data-i18n="death-saves-u">DEATH SAVES</button>
           <input type="hidden" class="exhaustion-toggle" name="attr_exhaustion_toggle" value="0">
               <input type="number" name="attr_exhaustion_level" step="1" min="0" max="6">
                   
                   
                   
                   
                   
                   
               EXHAUSTION LEVEL
           <input type="hidden" class="ammoflag" name="attr_ammotracking">
                   NAME
                   ATK
                   DAMAGE/TYPE
               <fieldset class="repeating_attack">
                       <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                               NAME:
                               <input type="text" name="attr_atkname">
                               <input type="checkbox" name="attr_atkflag" value="Template:Attack=1" checked="checked">
                               ATTACK:
                               <select name="attr_atkattr_base">
                                   <option value="@{strength_mod}" selected="selected" data-i18n="str-u">STR</option>
                                   <option value="@{dexterity_mod}" data-i18n="dex-u">DEX</option>
                                   <option value="@{constitution_mod}" data-i18n="con-u">CON</option>
                                   <option value="@{intelligence_mod}" data-i18n="int-u">INT</option>
                                   <option value="@{wisdom_mod}" data-i18n="wis-u">WIS</option>
                                   <option value="@{charisma_mod}" data-i18n="cha-u">CHA</option>
                                   <option value="spell" data-i18n="spell-u">SPELL</option>
                                   <option value="0">-</option>
                               </select>
                               +
                               <input type="text" class="num" name="attr_atkmod" placeholder="0">
                               +
                               <input type="checkbox" name="attr_atkprofflag" value="(@{pb})" checked="checked" style="margin-left: 3px;">
                               PROFICIENT
                               RANGE:
                               <input type="text" name="attr_atkrange" placeholder="Self (60-foot cone)" style="width: 170px;" data-i18n-placeholder="range-place">
                               MAGIC BONUS:
                               <input type="text" class="num" name="attr_atkmagic" placeholder="0">
                               CRIT RANGE:
                               <input type="text" class="num" name="attr_atkcritrange" value="20" placeholder="20">
                               <input type="checkbox" name="attr_dmgflag" value="Template:Damage=1 Template:Dmg1flag=1" checked="checked">
                               DAMAGE:
                               <input type="text" name="attr_dmgbase" placeholder="1d6" style="width: 50px;">
                               +
                               <select name="attr_dmgattr">
                                   <option value="@{strength_mod}" selected="selected" data-i18n="str-u">STR</option>
                                   <option value="@{dexterity_mod}" data-i18n="dex-u">DEX</option>
                                   <option value="@{constitution_mod}" data-i18n="con-u">CON</option>
                                   <option value="@{intelligence_mod}" data-i18n="int-u">INT</option>
                                   <option value="@{wisdom_mod}" data-i18n="wis-u">WIS</option>
                                   <option value="@{charisma_mod}" data-i18n="cha-u">CHA</option>
                                   <option value="spell" data-i18n="spell-u">SPELL</option>
                                   <option value="0">-</option>
                               </select>
                               +
                               <input type="text" class="num" name="attr_dmgmod" placeholder="0">
                               TYPE:
                               <input type="text" name="attr_dmgtype" placeholder="Slashing" style="width: 50px;" data-i18n-placeholder="dmg-type-place">
                               CRIT:
                               <input type="text" name="attr_dmgcustcrit" placeholder="1d6" style="width: 80px;">
                               <input type="checkbox" name="attr_dmg2flag" value="Template:Damage=1 Template:Dmg2flag=1">
                               DAMAGE2:
                               <input type="text" name="attr_dmg2base" placeholder="1d6" style="width: 50px;">
                               +
                               <select name="attr_dmg2attr">
                                   <option value="@{strength_mod}" data-i18n="str-u">STR</option>
                                   <option value="@{dexterity_mod}" data-i18n="dex-u">DEX</option>
                                   <option value="@{constitution_mod}" data-i18n="con-u">CON</option>
                                   <option value="@{intelligence_mod}" data-i18n="int-u">INT</option>
                                   <option value="@{wisdom_mod}" data-i18n="wis-u">WIS</option>
                                   <option value="@{charisma_mod}" data-i18n="cha-u">CHA</option>
                                   <option value="spell" data-i18n="spell-u">SPELL</option>
                                   <option value="0" selected="selected">-</option>
                               </select>
                               +
                               <input type="text" class="num" name="attr_dmg2mod" placeholder="0">
                               TYPE:
                               <input type="text" name="attr_dmg2type" placeholder="Slashing" style="width: 50px;" data-i18n-placeholder="dmg-type-place">
                               CRIT:
                               <input type="text" name="attr_dmg2custcrit" placeholder="1d6" style="width: 80px;">
                               <input type="checkbox" name="attr_saveflag" value="Template:Save=1 {{saveattr=@{saveattr}}} {{savedesc=@{saveeffect}}} {{savedc=[[[[@{savedc}]][SAVE]]]}}">
                               SAVING THROW:
                               <select name="attr_saveattr">
                                   <option value="Strength" selected="selected" data-i18n="str-u">STR</option>
                                   <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                   <option value="Constitution" data-i18n="con-u">CON</option>
                                   <option value="Intelligence" data-i18n="int-u">INT</option>
                                   <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                   <option value="Charisma" data-i18n="cha-u">CHA</option>
                               </select>
                               VS DC:
                               <select name="attr_savedc">
                                   <option value="(@{spell_save_dc})" selected="selected" data-i18n="spell-u">SPELL</option>
                                   <option value="(@{strength_mod}+8+@{spell_dc_mod}+@{pb})" data-i18n="str-u">STR</option>
                                   <option value="(@{dexterity_mod}+8+@{spell_dc_mod}+@{pb})" data-i18n="dex-u">DEX</option>
                                   <option value="(@{constitution_mod}+8+@{spell_dc_mod}+@{pb})" data-i18n="con-u">CON</option>
                                   <option value="(@{intelligence_mod}+8+@{spell_dc_mod}+@{pb})" data-i18n="int-u">INT</option>
                                   <option value="(@{wisdom_mod}+8+@{spell_dc_mod}+@{pb})" data-i18n="wis-u">WIS</option>
                                   <option value="(@{charisma_mod}+8+@{spell_dc_mod}+@{pb})" data-i18n="cha-u">CHA</option>
                                   <option value="(@{saveflat})" data-i18n="flat-u">FLAT</option>
                               </select>
                               <input class="flatflag" type="hidden" name="attr_savedc">
                               <input class="num flat" type="text" name="attr_saveflat" placeholder="10" value="10">
                               SAVE EFFECT:
                               <input type="text" name="attr_saveeffect" placeholder="half damage" style="width: 160px;" data-i18n-placeholder="save-effect-place">
                               AMMUNITION:
                               <input type="text" name="attr_ammo" placeholder="Arrows" style="width: 160px;" data-i18n-placeholder="ammunition-place">
                               DESCRIPTION:
                               <textarea name="attr_atk_desc" placeholder="Up to 2 creatures within 5 feet" data-i18n-placeholder="description-place"></textarea>
                           <button type="roll" name="roll_attack" value="@{rollbase}">
                               
                               <input type="text" name="attr_atkbonus" style="width: 40px; text-align: center;" value="">
                               <input type="text" name="attr_atkdmgtype" style="width: 90px;" value="">
                           </button>
                   <input type="hidden" name="attr_rollbase">
                   <input type="hidden" name="attr_rollbase_dmg">
                   <input type="hidden" name="attr_rollbase_crit">
                   <input type="hidden" name="attr_hldmg">
                   <input type="hidden" name="attr_spelllevel">
                   <input type="hidden" name="attr_itemid">
                   <input type="hidden" name="attr_spellid">
                   <input type="hidden" name="attr_spell_innate">
                   <input type="hidden" name="attr_versatile_alt">
                   <button type="roll" name="roll_attack_dmg" style="display: none;" value="@{rollbase_dmg}"></button>
                   <button type="roll" name="roll_attack_crit" style="display: none;" value="@{rollbase_crit}"></button>
               </fieldset>
               <input type="hidden" class="toggleflag" name="attr_global_attack_mod_flag">
               <input type="hidden" class="toggleflag" name="attr_global_damage_mod_flag">
               ATTACKS & SPELLCASTING
           <input type="hidden" class="toggleflag" name="attr_global_ac_mod_flag">
                       CP
                       <input type="text" name="attr_cp" title="@{cp}">
                       SP
                       <input type="text" name="attr_sp" title="@{sp}">
                       EP
                       <input type="text" name="attr_ep" title="@{ep}">
                       GP
                       <input type="text" name="attr_gp" title="@{gp}">
                       PP
                       <input type="text" name="attr_pp" title="@{pp}">
               <input type="hidden" class="inventoryflag" name="attr_simpleinventory" value="complex">
               <textarea class="simple" name="attr_equipment"></textarea>
                   <input type="hidden" class="warningflag" name="attr_armorwarningflag">
                       
                           <label><input type="checkbox" name="attr_armorwarningflag" value="hide">*</label>
                           
                               WARNING - MULTIPLE SETS OF ARMOR OR SHIELDS HAVE BEEN ADDED AND AC IS NOT CORRECTLY CALCULATED. UNEQUIP THE ARMOR PIECE FROM THE ITEM DETAILS.
                           
                       
                   <input type="hidden" class="warningflag" name="attr_customacwarningflag">
                       
                           <label><input type="checkbox" name="attr_customacwarningflag" value="hide">*</label>
                           
                               ATTENTION - YOUR CUSTOM AC CALCULATION IS NOT BEING USED AS YOU HAVE ARMOR EQUIPPED. IF YOU WANT TO USE YOUR CUSTOM AC, UNEQUIP THE ARMOR PIECE FROM THE ITEM DETAILS.
                           
                       
                       *
                       ITEM NAME
                       <img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/weight_lbs.png" style="width: 15px; margin-bottom: -3px;" alt="Weight symbol">
                   <fieldset class="repeating_inventory">
                       <input type="hidden" class="equippedflag" name="attr_equipped">
                           <input class="weight" type="text" name="attr_itemcount" value="1">
                           <input class="name" type="text" name="attr_itemname">
                           <input class="weight" type="text" name="attr_itemweight">
                           <input class="inventorysubflag" type="checkbox" name="attr_inventorysubflag">i
                               <input class="equipped" type="checkbox" name="attr_equipped" value="1" checked="checked">
                               EQUIPPED
                               <input class="equipped" type="checkbox" name="attr_useasresource" value="1">
                               USE AS A RESOURCE
                               <input class="equipped" type="checkbox" name="attr_hasattack" value="1">
                               HAS AN ATTACK
                               PROP:
                               <input class="subfield" type="text" name="attr_itemproperties">
                               MODS:
                               <input class="subfield" type="text" name="attr_itemmodifiers">
                               <textarea class="subtextarea" name="attr_itemcontent"></textarea>
                           <input type="hidden" name="attr_itemattackid">
                           <input type="hidden" name="attr_itemresourceid">
                   </fieldset>
                       TOTAL WEIGHT
                       <input type="text" name="attr_weighttotal" value="0">
                       <input type="hidden" class="encumberance" name="attr_encumberance">
                       IMMOBILE
                       HEAVILY ENCUMBERED
                       ENCUMBERED
                       OVER CARRYING CAPACITY
               EQUIPMENT
               <input class="options-flag" type="checkbox" name="attr_options-flag-personality" checked="checked">y
                   <textarea name="attr_personality_traits" style="min-height: 50px; height: 50px;"></textarea>
                   
               PERSONALITY TRAITS
               <input class="options-flag" type="checkbox" name="attr_options-flag-ideals" checked="checked">y
                   <textarea name="attr_ideals"></textarea>
                   
               IDEALS
               <input class="options-flag" type="checkbox" name="attr_options-flag-bonds" checked="checked">y
                   <textarea name="attr_bonds"></textarea>
                   
               BONDS
               <input class="options-flag" type="checkbox" name="attr_options-flag-flaws" checked="checked">y
                   <textarea name="attr_flaws" style="min-height: 46px; height: 46px;"></textarea>
                   
               FLAWS
                           Total
                           <input type="text" name="attr_class_resource_max" title="@{class_resource_max}">
                       <input type="number" name="attr_class_resource" title="@{class_resource}" style="margin-bottom: -6px;">
                       <input type="text" class="label" name="attr_class_resource_name" title="@{class_resource_name}" placeholder="CLASS RESOURCE" data-i18n-placeholder="class-resource-u">
                           Total
                           <input type="text" name="attr_other_resource_max" title="@{other_resource_max}">
                       <input type="number" name="attr_other_resource" title="@{other_resource}" style="margin-bottom: -6px;">
                       <input type="text" class="label" name="attr_other_resource_name" title="@{other_resource_name}" placeholder="OTHER RESOURCE" data-i18n-placeholder="other-resource-u">
                       <input type="hidden" name="attr_other_resource_itemid">
               <fieldset class="repeating_resource">
                               Total
                               <input type="text" name="attr_resource_left_max" title="@{repeating_resource_left_max}">
                           <input type="number" name="attr_resource_left" title="@{repeating_resource_left}" style="margin-bottom: -6px;">
                           <input type="text" class="label" name="attr_resource_left_name" title="@{repeating_resource_left_name}" placeholder="OTHER RESOURCE" data-i18n-placeholder="other-resource-u">
                           <input type="hidden" name="attr_resource_left_itemid">
                               Total
                               <input type="text" name="attr_resource_right_max" title="@{repeating_resource_right_max}">
                           <input type="number" name="attr_resource_right" title="@{repeating_resource_right}" style="margin-bottom: -6px;">
                           <input type="text" class="label" name="attr_resource_right_name" title="@{repeating_resource_right_name}" placeholder="OTHER RESOURCE" data-i18n-placeholder="other-resource-u">
                           <input type="hidden" name="attr_resource_right_itemid">
               </fieldset>
               <input type="hidden" class="inventoryflag" name="attr_simpletraits" value="complex">
               <textarea class="sheet-simple" name="attr_features_and_traits" style="min-height: 461px; height: 461px;"></textarea>
                   <fieldset class="repeating_traits">
                           <button type="roll" name="roll_output" class="output" value="@{wtype}&{template:traits} @{charname_output} {{name=@{name}}} {{source=@{source}: @{source_type}}} {{description=@{description}}} {{licensedsheet=@{licensedsheet}}}">w</button>
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                           <input class="display-flag" type="checkbox" name="attr_display_flag">
                                   NAME:
                                   <input type="text" name="attr_name" style="width: 120px;">
                                   SOURCE:
                                   <select name="attr_source">
                                       <option selected="selected" data-i18n="racial">Racial</option>
                                       <option data-i18n="class">Class</option>
                                       <option data-i18n="feat">Feat</option>
                                       <option data-i18n="background">Background</option>
                                       <option data-i18n="other">Other</option>
                                   </select>
                                   SOURCE TYPE:
                                   <input type="text" name="attr_source_type" style="width: 160px;" placeholder="Dwarf/Fighter/4th Level">
                                   <textarea name="attr_description" style="min-height: 200px; height: 200px;"></textarea>
                               
                               
                                   : 
                               
                               
                   </fieldset>
               FEATURES & TRAITS
           <input type="hidden" class="missing-info-flag" name="attr_missing_info">
               i Looking for missing data?
               Your data is in the simple version that can be re-enabled from the Settings(gear) tab of the character sheet. Under GENERAL OPTIONS and then FEATS & TRAITS. Set the section to be 'Simple'.
           <img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/srd5_360.png" style="padding-bottom: 5px;" alt="SRD5 by Roll20">
           <input type="text" name="attr_character_name" style="width: 100%;">
           CHARACTER NAME
                   <input type="text" name="attr_age" style="width: 120px;">
                   AGE
                   <input type="text" name="attr_size" style="width: 120px;">
                   SIZE
                   <input type="text" name="attr_height" style="width: 120px;">
                   HEIGHT
                   <input type="text" name="attr_weight" style="width: 120px;">
                   WEIGHT
                   <input type="text" name="attr_eyes" style="width: 160px;">
                   EYES
                   <input type="text" name="attr_skin" style="width: 160px;">
                   SKIN
                   <input type="text" name="attr_hair" style="width: 160px;">
                   HAIR
               <textarea name="attr_character_appearance" style="min-height: 300px; height: 300px;"></textarea>
               CHARACTER APPEARANCE
               <textarea name="attr_character_backstory" style="min-height: 623px; height: 623px;"></textarea>
               CHARACTER BACKSTORY
               <textarea name="attr_allies_and_organizations" style="min-height: 288px; height: 300px;"></textarea>
               ALLIES & ORGANIZATIONS
               <textarea name="attr_additional_feature_and_traits" style="min-height: 289px; height: 300px;"></textarea>
               ADDITIONAL FEATURES & TRAITS
               <textarea name="attr_treasure" style="min-height: 300px; height: 300px;"></textarea>
               TREASURE
           <img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/srd5_360.png" style="padding-bottom: 5px;" alt="SRD5e by Roll20">
           <input type="text" name="attr_character_name" style="width: 100%;">
           CHARACTER NAME
               <select name="attr_spellcasting_ability">
                   <option value="0*" data-i18n="none-u">NONE</option>
                   <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                   <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                   <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                   <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                   <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                   <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
               </select>
               SPELLCASTING ABILITY
               
               SPELL SAVE DC
               
               SPELL ATTACK BONUS
   <input type="hidden" class="spellicon_flag" name="attr_spellicon_flag" value="all">
                   0
                   CANTRIPS
               <fieldset class="repeating_spell-cantrip">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="cantrip">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
           
               SLOTS TOTAL
               SLOTS REMAINING
           
                   1
                   
                   <input type="number" name="attr_lvl1_slots_expended" value="0">
               <fieldset class="repeating_spell-1">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="1">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   2
                   
                   <input type="number" name="attr_lvl2_slots_expended" value="0">
               <fieldset class="repeating_spell-2">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="2">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   3
                   
                   <input type="number" name="attr_lvl3_slots_expended" value="0">
               <fieldset class="repeating_spell-3">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="3">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   4
                   
                   <input type="number" name="attr_lvl4_slots_expended" value="0">
               <fieldset class="repeating_spell-4">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="4">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   5
                   
                   <input type="number" name="attr_lvl5_slots_expended" value="0">
               <fieldset class="repeating_spell-5">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="5">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   6
                   
                   <input type="number" name="attr_lvl6_slots_expended" value="0">
               <fieldset class="repeating_spell-6">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="6">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   7
                   
                   <input type="number" name="attr_lvl7_slots_expended" value="0">
               <fieldset class="repeating_spell-7">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="7">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   8
                   
                   <input type="number" name="attr_lvl8_slots_expended" value="0">
               <fieldset class="repeating_spell-8">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="8">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
                   9
                   
                   <input type="number" name="attr_lvl9_slots_expended" value="0">
               <fieldset class="repeating_spell-9">
                           <input type="hidden" name="attr_rollcontent" value="@{wtype}&{template:spell} {{level=@{spellschool} @{spelllevel}}}  {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}">
                           <input type="checkbox" name="attr_spellprepared" value="1" class="sheet-prep-box">
                           <button class="spellcard" type="roll" name="roll_spell" value="@{rollcontent}">
                               
                               <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                           </button>
                           <input type="hidden" class="spellritual" name="attr_spellritual" value="0">
                           <input type="hidden" class="spellconcentration" name="attr_spellconcentration" value="0">
                           <input type="hidden" class="v" name="attr_spellcomp_v" value="Template:V=1">
                           <input type="hidden" class="s" name="attr_spellcomp_s" value="Template:S=1">
                           <input type="hidden" class="m" name="attr_spellcomp_m" value="Template:M=1">
                           R
                           C
                           
                               V
                               S
                               M
                           
                       <input class="details-flag" type="checkbox" name="attr_details-flag" checked="checked">i
                           <input class="options-flag" type="checkbox" name="attr_options-flag" checked="checked">y
                                   NAME:
                                   <input type="text" name="attr_spellname">
                                   SCHOOL:
                                   <select name="attr_spellschool">
                                       <option value="abjuration" data-i18n="abjuration">Abjuration</option>
                                       <option value="conjuration" data-i18n="conjuration">Conjuration</option>
                                       <option value="divination" data-i18n="divination">Divination</option>
                                       <option value="enchantment" data-i18n="enchantment">Enchantment</option>
                                       <option value="evocation" data-i18n="evocation">Evocation</option>
                                       <option value="illusion" data-i18n="illusion">Illusion</option>
                                       <option value="necromancy" data-i18n="necromancy">Necromancy</option>
                                       <option value="transmutation" data-i18n="transmutation">Transmutation</option>
                                   </select>
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   RITUAL
                                   CASTING TIME:
                                   <input type="text" name="attr_spellcastingtime">
                                   RANGE:
                                   <input type="text" name="attr_spellrange">
                                   TARGET:
                                   <input type="text" name="attr_spelltarget">
                               <input type="hidden" name="attr_spellcomp">
                                   COMPONENTS:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">
                                   V
                                   <input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">
                                   S
                                   <input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">
                                   M
                                   <input type="text" name="attr_spellcomp_materials" placeholder="ruby dust worth 50gp" data-i18n-placeholder="ruby-dust-place">
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   CONCENTRATION
                                   DURATION:
                                   <input type="text" name="attr_spellduration">
                                   SPELLCASTING ABILITY
                                   <select name="attr_spell_ability">
                                       <option value="0*" data-i18n="none-u">NONE</option>
                                       <option value="spell" data-i18n="spell-u">SPELL</option>
                                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                                   </select>
                                   INNATE:
                                   <input type="text" name="attr_innate" placeholder="1/day" value="">
                                   OUTPUT:
                                   <select name="attr_spelloutput">
                                       <option value="SPELLCARD" data-i18n="spellcard-u">SPELLCARD</option>
                                       <option value="ATTACK" data-i18n="attack-u">ATTACK</option>
                                   </select>
                               <input type="hidden" class="spellattackinfoflag" name="attr_spelloutput">
                                       SPELL ATTACK:
                                       <select name="attr_spellattack">
                                           <option value="None" data-i18n="none">None</option>
                                           <option value="Melee" data-i18n="melee">Melee</option>
                                           <option value="Ranged" data-i18n="ranged">Ranged</option>
                                       </select>
                                       DAMAGE:
                                       <input type="text" name="attr_spelldamage" style="width: 50px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype" style="width: 103px;">
                                       DAMAGE2:
                                       <input type="text" name="attr_spelldamage2" style="width: 45px;">
                                       TYPE:
                                       <input type="text" name="attr_spelldamagetype2" style="width: 103px;">
                                       HEALING:
                                       <input type="text" name="attr_spellhealing" style="width: 45px;">
                                       <input type="checkbox" name="attr_spelldmgmod" value="Yes">
                                       ADD ABILITY MOD TO DAMAGE OR HEALING
                                       SAVING THROW:
                                       <select name="attr_spellsave">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="Strength" data-i18n="str-u">STR</option>
                                           <option value="Dexterity" data-i18n="dex-u">DEX</option>
                                           <option value="Constitution" data-i18n="con-u">CON</option>
                                           <option value="Intelligence" data-i18n="int-u">INT</option>
                                           <option value="Wisdom" data-i18n="wis-u">WIS</option>
                                           <option value="Charisma" data-i18n="cha-u">CHA</option>
                                       </select>
                                       EFFECT:
                                       <input type="text" name="attr_spellsavesuccess" style="width: 78px;" placeholder="Half damage" data-i18n-placeholder="half-dmg-place">
                                       HIGHER LVL CAST DMG:
                                       <input type="text" name="attr_spellhldie" placeholder="1" style="width: 15px; text-align: right;">
                                       <select name="attr_spellhldietype">
                                           <option value="" selected="selected" data-i18n="none-u">NONE</option>
                                           <option value="d4">d4</option>
                                           <option value="d6">d6</option>
                                           <option value="d8">d8</option>
                                           <option value="d10">d10</option>
                                           <option value="d12">d12</option>
                                           <option value="d20">d20</option>
                                       </select>
                                       +
                                       <input type="text" name="attr_spellhlbonus" placeholder="0" style="width: 15px; text-align: center;">
                                       INCLUDE SPELL DESCRIPTION IN ATTACK:
                                       <select name="attr_includedesc">
                                           <option value="off" selected="selected" data-i18n="off">Off</option>
                                           <option value="partial" data-i18n="partial">Partial</option>
                                           <option value="on" data-i18n="on">On</option>
                                       </select>
                                   DESCRIPTION:
                                   <textarea name="attr_spelldescription"></textarea>
                                   AT HIGHER LEVELS:
                                   <textarea name="attr_spellathigherlevels" style="height: 36px; min-height: 36px;"></textarea>
                                   CLASS:
                                   <input type="text" name="attr_spellclass" style="width: 45px;">
                                   TYPE:
                                   <input type="text" name="attr_spellsource" style="width: 45px;">
                               <input type="hidden" name="attr_spellattackid">
                               <input type="hidden" name="attr_spelllevel" value="9">
                               <label class="options-done">
                                   <input type="checkbox" name="attr_options-flag" checked="checked">
                                   Done
                               </label>
                               
                                   <input class="innate_flag" type="hidden" name="attr_innate" value="">
                               
                                   
                                   
                                   <input type="checkbox" name="attr_spellritual" value="Template:Ritual=1">
                                   (ritual)
                                   Casting Time:
                                   
                                   Range:
                                   
                                   Target:
                                   
                                   Components:
                                   <input type="checkbox" name="attr_spellcomp_v" value="Template:V=1" checked="checked">V<input type="checkbox" name="attr_spellcomp_s" value="Template:S=1" checked="checked">S<input type="checkbox" name="attr_spellcomp_m" value="Template:M=1" checked="checked">M
                                   <input type="hidden" name="attr_spellcomp_materials" value="">
                                   ()
                                   Duration:
                                   <input type="checkbox" name="attr_spellconcentration" value="Template:Concentration=1">
                                   Concentration
                                   
                                   Description:
                                   
                               <input type="hidden" name="attr_spellathigherlevels" value="">
                                   At Higher Levels
                                   
               </fieldset>
           <img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/srd5_360.png" style="padding-bottom: 5px;" alt="SRD5e by Roll20">
           <input type="text" name="attr_character_name" style="width: 100%;">
           CHARACTER NAME
       <input class="options-flag" type="checkbox" name="attr_options-class-selection" checked="checked">y
               CLASS:
               <input type="hidden" name="attr_custom_class" class="sheet-flag">
               <select class="hiding class" name="attr_class">
                   <option value="" data-i18n="choose">Choose</option>
                   <option value="Artificer" data-i18n="artificer">Artificer</option>
                   <option value="Barbarian" data-i18n="barbarian">Barbarian</option>
                   <option value="Bard" data-i18n="bard">Bard</option>
                   <option value="Cleric" data-i18n="cleric">Cleric</option>
                   <option value="Druid" data-i18n="druid">Druid</option>
                   <option value="Fighter" data-i18n="fighter">Fighter</option>
                   <option value="Monk" data-i18n="monk">Monk</option>
                   <option value="Paladin" data-i18n="paladin">Paladin</option>
                   <option value="Ranger" data-i18n="ranger">Ranger</option>
                   <option value="Rogue" data-i18n="rogue">Rogue</option>
                   <option value="Sorcerer" data-i18n="sorcerer">Sorcerer</option>
                   <option value="Warlock" data-i18n="warlock">Warlock</option>
                   <option value="Wizard" data-i18n="wizard">Wizard</option>
               </select>
               <input type="text" class="showing" name="attr_cust_classname" style="width: 90px;">
               SUBCLASS:
               <input type="text" name="attr_subclass">
               LEVEL:
               <input type="number" class="class-level" style="width: 40px" name="attr_base_level" value="1">
               RACE:
               <input type="text" name="attr_race">
               SUBRACE:
               <input type="text" name="attr_subrace">
                   <input type="text" name="attr_class_display" class="sheet-class-display sheet-no_events">
                   CLASS & LEVEL
                   <input type="text" name="attr_background" style="width: 182px;">
                   BACKGROUND
                   <input type="text" name="attr_race_display" class="sheet-no_events">
                   RACE
                   <input type="text" name="attr_alignment">
                   ALIGNMENT
                   <input type="text" name="attr_experience">
                   EXPERIENCE POINTS
                   <input class="sheet-showleveler" type="hidden" name="attr_showleveler" value="0">
                   <button class="sheet-levelerbutton" type="action" name="act_launch_lvl+mancer" style="padding: 0px; position: absolute; top: -10px; right: 0px;" title="Charactermancer Level Up"><img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/CharactermancerIcon200px.png" style="height: 18px; width: 18px; max-width: inherit;" alt="Wand & Hammer of Charactermancer"></button>
                   HIT DIE:
                   <select name="attr_hitdietype">
                       <option value="4">D4</option>
                       <option value="6">D6</option>
                       <option value="8">D8</option>
                       <option value="10">D10</option>
                       <option value="12">D12</option>
                   </select>
                   CARRYING CAPACITY MODIFIER:
                   <input type="text" class="num" name="attr_carrying_capacity_mod" placeholder="*2">
                   GLOBAL MAGIC ATTACK MODIFIER:
                   <input type="text" class="num" name="attr_globalmagicmod" placeholder="0" value="0">
                   MAGIC CASTER LEVEL:
                   <input type="text" class="num" name="attr_caster_level">
                   SPELL SAVE DC MOD:
                   <input type="text" class="num" name="attr_spell_dc_mod" placeholder="0" value="0">
                   SPELL ICONS:
                   <select name="attr_spellicon_flag">
                       <option value="all" data-i18n="show_all">Show All</option>
                       <option value="cp" data-i18n="cr_only">C&R Only</option>
                       <option value="none" data-i18n="none">None</option>
                   </select>
                   <input type="checkbox" name="attr_halflingluck_flag" value="1">
                   HALFLING LUCK
                   <input type="checkbox" name="attr_arcane_fighter" value="1">
                   ARCANE FIGHTER
                   <input type="checkbox" name="attr_arcane_rogue" value="1">
                   ARCANE ROGUE
                   CLASS OPTIONS ()
                   <input type="checkbox" name="attr_multiclass1_flag" value="1">
                   2ND CLASS:
                   <select name="attr_multiclass1" style="width: 64px;">
                       <option value="Artificer" data-i18n="artificer">Artificer</option>
                       <option value="Barbarian" data-i18n="barbarian">Barbarian</option>
                       <option value="Bard" data-i18n="bard">Bard</option>
                       <option value="Cleric" data-i18n="cleric">Cleric</option>
                       <option value="Druid" data-i18n="druid">Druid</option>
                       <option value="Fighter" data-i18n="fighter">Fighter</option>
                       <option value="Monk" data-i18n="monk">Monk</option>
                       <option value="Paladin" data-i18n="paladin">Paladin</option>
                       <option value="Ranger" data-i18n="ranger">Ranger</option>
                       <option value="Rogue" data-i18n="rogue">Rogue</option>
                       <option value="Sorcerer" data-i18n="sorcerer">Sorcerer</option>
                       <option value="Warlock" data-i18n="warlock">Warlock</option>
                       <option value="Wizard" data-i18n="wizard">Wizard</option>
                   </select>
                   LEVEL:
                   <input type="text" name="attr_multiclass1_lvl" value="1" style="width: 28px; text-align: center;">
                   SUBCLASS:
                   <input type="text" name="attr_multiclass1_subclass">
                   <input type="checkbox" name="attr_multiclass2_flag" value="1">
                   3RD CLASS:
                   <select name="attr_multiclass2" style="width: 64px;">
                       <option value="Artificer" data-i18n="artificer">Artificer</option>
                       <option value="Barbarian" data-i18n="barbarian">Barbarian</option>
                       <option value="Bard" data-i18n="bard">Bard</option>
                       <option value="Cleric" data-i18n="cleric">Cleric</option>
                       <option value="Druid" data-i18n="druid">Druid</option>
                       <option value="Fighter" data-i18n="fighter">Fighter</option>
                       <option value="Monk" data-i18n="monk">Monk</option>
                       <option value="Paladin" data-i18n="paladin">Paladin</option>
                       <option value="Ranger" data-i18n="ranger">Ranger</option>
                       <option value="Rogue" data-i18n="rogue">Rogue</option>
                       <option value="Sorcerer" data-i18n="sorcerer">Sorcerer</option>
                       <option value="Warlock" data-i18n="warlock">Warlock</option>
                       <option value="Wizard" data-i18n="wizard">Wizard</option>
                   </select>
                   LEVEL:
                   <input type="text" name="attr_multiclass2_lvl" value="1" style="width: 28px; text-align: center;">
                   SUBCLASS:
                   <input type="text" name="attr_multiclass2_subclass">
                   <input type="checkbox" name="attr_multiclass3_flag" value="1">
                   4TH CLASS:
                   <select name="attr_multiclass3" style="width: 64px;">
                       <option value="Artificer" data-i18n="artificer">Artificer</option>
                       <option value="Barbarian" data-i18n="barbarian">Barbarian</option>
                       <option value="Bard" data-i18n="bard">Bard</option>
                       <option value="Cleric" data-i18n="cleric">Cleric</option>
                       <option value="Druid" data-i18n="druid">Druid</option>
                       <option value="Fighter" data-i18n="fighter">Fighter</option>
                       <option value="Monk" data-i18n="monk">Monk</option>
                       <option value="Paladin" data-i18n="paladin">Paladin</option>
                       <option value="Ranger" data-i18n="ranger">Ranger</option>
                       <option value="Rogue" data-i18n="rogue">Rogue</option>
                       <option value="Sorcerer" data-i18n="sorcerer">Sorcerer</option>
                       <option value="Warlock" data-i18n="warlock">Warlock</option>
                       <option value="Wizard" data-i18n="wizard">Wizard</option>
                   </select>
                   LEVEL:
                   <input type="text" name="attr_multiclass3_lvl" value="1" style="width: 28px; text-align: center;">
                   SUBCLASS:
                   <input type="text" name="attr_multiclass3_subclass">
                   MULTICLASS OPTIONS
                   <input type="checkbox" name="attr_custom_class" value="1">
                   USE CUSTOM CLASS
                   CLASS NAME:
                   <input type="text" name="attr_cust_classname">
                   HIT DIE:
                   <select name="attr_cust_hitdietype">
                       <option value="4">D4</option>
                       <option value="6">D6</option>
                       <option value="8">D8</option>
                       <option value="10">D10</option>
                       <option value="12">D12</option>
                   </select>
                   SPELLCASTING ABILITY:
                   <select name="attr_cust_spellcasting_ability">
                       <option value="0*" data-i18n="none-u">NONE</option>
                       <option value="@{strength_mod}+" data-i18n="strength-u">STRENGTH</option>
                       <option value="@{dexterity_mod}+" data-i18n="dexterity-u">DEXTERITY</option>
                       <option value="@{constitution_mod}+" data-i18n="constitution-u">CONSTITUTION</option>
                       <option value="@{intelligence_mod}+" data-i18n="intelligence-u">INTELLIGENCE</option>
                       <option value="@{wisdom_mod}+" data-i18n="wisdom-u">WISDOM</option>
                       <option value="@{charisma_mod}+" data-i18n="charisma-u">CHARISMA</option>
                   </select>
                   SPELL SLOTS:
                   <select name="attr_cust_spellslots">
                       <option value="none" data-i18n="none-u">NONE</option>
                       <option value="full" data-i18n="spell-full-u">FULL (Cleric, Druid, Wizard)</option>
                       <option value="half" data-i18n="spell-half-u">HALF (Artificer, Paladin, Ranger)</option>
                       <option value="third" data-i18n="spell-third-u">THIRD (Arcane Fighter/Rogue)</option>
                   </select>
                   SAVES
                   <input type="checkbox" name="attr_cust_strength_save_prof" value="(@{pb})">
                   Strength
                   <input type="checkbox" name="attr_cust_dexterity_save_prof" value="(@{pb})">
                   Dexterity
                   <input type="checkbox" name="attr_cust_constitution_save_prof" value="(@{pb})">
                   Constitution
                   <input type="checkbox" name="attr_cust_intelligence_save_prof" value="(@{pb})">
                   Intelligence
                   <input type="checkbox" name="attr_cust_wisdom_save_prof" value="(@{pb})">
                   Wisdom
                   <input type="checkbox" name="attr_cust_charisma_save_prof" value="(@{pb})">
                   Charisma
                   CUSTOM CLASS OPTIONS
                       LEVEL1 +
                       <input type="text" class="num" name="attr_lvl1_slots_mod" value="0" placeholder="0" title="@{lvl1_slots_mod}">
                       LEVEL2 +
                       <input type="text" class="num" name="attr_lvl2_slots_mod" value="0" placeholder="0" title="@{lvl2_slots_mod}">
                       LEVEL3 +
                       <input type="text" class="num" name="attr_lvl3_slots_mod" value="0" placeholder="0" title="@{lvl3_slots_mod}">
                       LEVEL4 +
                       <input type="text" class="num" name="attr_lvl4_slots_mod" value="0" placeholder="0" title="@{lvl4_slots_mod}">
                       LEVEL5 +
                       <input type="text" class="num" name="attr_lvl5_slots_mod" value="0" placeholder="0" title="@{lvl5_slots_mod}">
                       LEVEL6 +
                       <input type="text" class="num" name="attr_lvl6_slots_mod" value="0" placeholder="0" title="@{lvl6_slots_mod}">
                       LEVEL7 +
                       <input type="text" class="num" name="attr_lvl7_slots_mod" value="0" placeholder="0" title="@{lvl7_slots_mod}">
                       LEVEL8 +
                       <input type="text" class="num" name="attr_lvl8_slots_mod" value="0" placeholder="0" title="@{lvl8_slots_mod}">
                       LEVEL9 +
                       <input type="text" class="num" name="attr_lvl9_slots_mod" value="0" placeholder="0" title="@{lvl9_slots_mod}">
                   SPELL SLOT MODIFIERS
                   STRENGTH
                   +<input type="text" class="num" name="attr_strength_bonus" value="0" placeholder="0" title="@{strength_bonus}">
                   DEXTERITY
                   +<input type="text" class="num" name="attr_dexterity_bonus" value="0" placeholder="0" title="@{dexterity_bonus}">
                   CONSTITUTION
                   +<input type="text" class="num" name="attr_constitution_bonus" value="0" placeholder="0" title="@{constitution_bonus}">
                   INTELLIGENCE
                   +<input type="text" class="num" name="attr_intelligence_bonus" value="0" placeholder="0" title="@{intelligence_bonus}">
                   WISDOM
                   +<input type="text" class="num" name="attr_wisdom_bonus" value="0" placeholder="0" title="@{wisdom_bonus}">
                   CHARISMA
                   +<input type="text" class="num" name="attr_charisma_bonus" value="0" placeholder="0" title="@{charisma_bonus}">
                   INITIATIVE MODIFIER:
                   <input type="text" class="num" name="attr_initmod" placeholder="0" value="0">
                   INITIATIVE STYLE:
                   <select name="attr_initiative_style">
                       <option value="@{d20}" selected="selected" data-i18n="norm">Normal</option>
                       <option value="{@{d20},@{d20}}kh1" data-i18n="adv">Advantage</option>
                       <option value="{@{d20},@{d20}}kl1" data-i18n="disadv">Disadvantage</option>
                   </select>
                   <input type="checkbox" name="attr_init_tiebreaker" value="@{dexterity}/100">
                   ADD DEX TIEBREAKER TO INITIATIVE
                   ARMOR CLASS TRACKING:
                   <select name="attr_custom_ac_flag">
                       <option value="0" selected="selected" data-i18n="automatic">Automatic</option>
                       <option value="1" data-i18n="custom">Custom</option>
                       <option value="2" data-i18n="off">Off</option>
                   </select>
               <input class="toggleflag" type="hidden" name="attr_custom_ac_flag">
                   HP MODIFIERS:
               <fieldset class="repeating_hpmod">
                       LEVELS:
                       <select name="attr_levels">
                           <option value="total" selected="selected" data-i18n="total-level-u">TOTAL LEVEL</option>
                           <option value="base" data-i18n="main-class-level-u">MAIN CLASS LEVEL</option>
                           <option value="multiclass1" data-i18n="class-2-level-u">CLASS 2 LEVEL</option>
                           <option value="multiclass2" data-i18n="class-3-level-u">CLASS 3 LEVEL</option>
                           <option value="multiclass3" data-i18n="class-4-level-u">CLASS 4 LEVEL</option>
                       </select>
SOURCE: <input type="text" name="attr_source"> MOD: <input type="text" name="attr_mod" class="num">
               </fieldset>
                   ATTRIBUTE OPTIONS
                   Strength Save
                   +<input type="text" class="num" name="attr_strength_save_mod" value="0" placeholder="0" title="@{strength_save_mod}">
                   Dexterity Save
                   +<input type="text" class="num" name="attr_dexterity_save_mod" value="0" placeholder="0" title="@{dexterity_save_mod}">
                   Constitution Save
                   +<input type="text" class="num" name="attr_constitution_save_mod" value="0" placeholder="0" title="@{constitution_save_mod}">
                   Intelligence Save
                   +<input type="text" class="num" name="attr_intelligence_save_mod" value="0" placeholder="0" title="@{intelligence_save_mod}">
                   Wisdom Save
                   +<input type="text" class="num" name="attr_wisdom_save_mod" value="0" placeholder="0" title="@{wisdom_save_mod}">
                   Charisma Save
                   +<input type="text" class="num" name="attr_charisma_save_mod" value="0" placeholder="0" title="@{charisma_save_mod}">
                   DEATH SAVE MODIFIER:
                   <input type="text" class="num" name="attr_death_save_mod" placeholder="0" value="0">
                   GLOBAL SAVING THROW MODIFIER:
                   <input type="text" class="num" name="attr_globalsavemod" placeholder="0" value="0">
                   SAVE OPTIONS
                       <select name="attr_acrobatics_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Acrobatics (Dex)
                       +<input type="text" class="num" name="attr_acrobatics_flat" value="0" placeholder="0" title="@{acrobatics_flat}">
                       <select name="attr_animal_handling_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Animal Handling (Wis)
                       +<input type="text" class="num" name="attr_animal_handling_flat" value="0" placeholder="0" title="@{animal_handling_flat}">
                       <select name="attr_arcana_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Arcana (Int)
                       +<input type="text" class="num" name="attr_arcana_flat" value="0" placeholder="0" title="@{arcana_flat}">
                       <select name="attr_athletics_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Athletics (Str)
                       +<input type="text" class="num" name="attr_athletics_flat" value="0" placeholder="0" title="@{athletics_flat}">
                       <select name="attr_deception_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Deception (Cha)
                       +<input type="text" class="num" name="attr_deception_flat" value="0" placeholder="0" title="@{deception_flat}">
                       <select name="attr_history_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       History (Int)
                       +<input type="text" class="num" name="attr_history_flat" value="0" placeholder="0" title="@{history_flat}">
                       <select name="attr_insight_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Insight (Wis)
                       +<input type="text" class="num" name="attr_insight_flat" value="0" placeholder="0" title="@{insight_flat}">
                       <select name="attr_intimidation_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Intimidation (Cha)
                       +<input type="text" class="num" name="attr_intimidation_flat" value="0" placeholder="0" title="@{intimidation_flat}">
                       <select name="attr_investigation_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Investigation (Int)
                       +<input type="text" class="num" name="attr_investigation_flat" value="0" placeholder="0" title="@{investigation_flat}">
                       <select name="attr_medicine_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Medicine (Wis)
                       +<input type="text" class="num" name="attr_medicine_flat" value="0" placeholder="0" title="@{medicine_flat}">
                       <select name="attr_nature_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Nature (Int)
                       +<input type="text" class="num" name="attr_nature_flat" value="0" placeholder="0" title="@{nature_flat}">
                       <select name="attr_perception_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Perception (Wis)
                       +<input type="text" class="num" name="attr_perception_flat" value="0" placeholder="0" title="@{perception_flat}">
                       <select name="attr_performance_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Performance (Cha)
                       +<input type="text" class="num" name="attr_performance_flat" value="0" placeholder="0" title="@{performance_flat}">
                       <select name="attr_persuasion_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Persuasion (Cha)
                       +<input type="text" class="num" name="attr_persuasion_flat" value="0" placeholder="0" title="@{persuasion_flat}">
                       <select name="attr_religion_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Religion (Int)
                       +<input type="text" class="num" name="attr_religion_flat" value="0" placeholder="0" title="@{religion_flat}">
                       <select name="attr_sleight_of_hand_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Sleight of Hand (Dex)
                       +<input type="text" class="num" name="attr_sleight_of_hand_flat" value="0" placeholder="0" title="@{sleight_of_hand_flat}">
                       <select name="attr_stealth_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Stealth (Dex)
                       +<input type="text" class="num" name="attr_stealth_flat" value="0" placeholder="0" title="@{stealth_flat}">
                       <select name="attr_survival_type"><option value="1" selected="selected" data-i18n="normal">Normal</option><option value="2" data-i18n="expirtise">Expertise</option></select>
                       Survival (Wis)
                       +<input type="text" class="num" name="attr_survival_flat" value="0" placeholder="0" title="@{survival_flat}">
                   <input type="checkbox" name="attr_jack_of_all_trades" value="@{jack}">
                   JACK OF ALL TRADES
                   PASSIVE PERCEPTION MODIFIER:
                   <input type="text" class="num" name="attr_passiveperceptionmod" placeholder="0" value="0">
                   SKILL OPTIONS
                   v
                   
                   <input type="checkbox" name="attr_npc" value="1">
                   NPC
                   ROLL QUERIES:
                   <select name="attr_rtype">
                       <option value="Template:Always=1 {{r2=[[@{d20}" data-i18n="always-roll-adv">Always Roll Advantage</option>
                       <option value="@{advantagetoggle}" data-i18n="toggle-roll-adv">Advantage Toggle</option>
                       <option value="Template:Query=1 ?{Advantage?|Normal Roll,&#123&#123normal=1&#125&#125 &#123&#123r2=[[0d20|Advantage,&#123&#123advantage=1&#125&#125 &#123&#123r2=[[@{d20}|Disadvantage,&#123&#123disadvantage=1&#125&#125 &#123&#123r2=[[@{d20}}" data-i18n="query-roll-adv">Query Advantage</option>
                       <option value="Template:Normal=1 {{r2=[[0d20" data-i18n="never-roll-adv">Never Roll Advantage</option>
                   </select>
                   WHISPER ROLLS TO GM:
                   <select name="attr_wtype">
                       <option value="" data-i18n="never-whisper-roll">Never Whisper Rolls</option>
                       <option value="@{whispertoggle}" data-i18n="toggle-roll-whisper">Whisper Toggle</option>
                       <option value="?{Whisper?|Public Roll,|Whisper Roll,/w gm }" data-i18n="query-whisper-roll">Query Whisper</option>
                       <option value="/w gm " data-i18n="always-whisper-roll">Always Whisper Rolls</option>
                   </select>
                   AUTO DAMAGE ROLL:
                   <select class="dtype" name="attr_dtype">
                       <option value="pick" data-i18n="never-roll-dmg">Don't Auto Roll Damage</option>
                       <option value="full" data-i18n="always-roll-dmg">Auto Roll Damage & Crit</option>
                   </select>
                   CORE DIE ROLL:
                   <input type="text" name="attr_core_die" value="1d20" placeholder="1d20" title="@{core_die}">
                   PROFICIENCY BONUS:
                   <select class="dtype" name="attr_pb_type">
                       <option value="level" data-i18n="by-level">By Level (Default)</option>
                       <option value="die" data-i18n="prof-die">Proficency Die (DMG)</option>
                       <option value="custom" data-i18n="custom">Custom</option>
                   </select>
                   <input type="hidden" name="attr_pb_type">
                   <input class="pb_custom" type="text" style="float:right;" name="attr_pb_custom" placeholder="2d10">
                   <input type="checkbox" name="attr_global_save_mod_flag" value="1">
                   SHOW GLOBAL SAVE MODIFIER FIELD
                   <input type="checkbox" name="attr_global_skill_mod_flag" value="1">
                   SHOW GLOBAL SKILL MODIFIER FIELD
                   <input type="checkbox" name="attr_global_attack_mod_flag" value="1">
                   SHOW GLOBAL ATTACK MODIFIER FIELD
                   <input type="checkbox" name="attr_global_damage_mod_flag" value="1">
                   SHOW GLOBAL DAMAGE MODIFIER FIELD
                   <input type="checkbox" name="attr_global_ac_mod_flag" value="1">
                   SHOW GLOBAL AC MODIFIER FIELD
                   ADD CHARACTER NAME TO TEMPLATES:
                   <select class="dtype" name="attr_charname_output">
                       <option value="{{charname=@{character_name}}}" data-i18n="on">On</option>
                       <option value="charname=@{character_name}" selected="selected" data-i18n="off">Off</option>
                   </select>
                   LEVEL CALCULATIONS:
                   <select class="dtype" name="attr_level_calculations">
                       <option value="on" selected="selected" data-i18n="on">On</option>
                       <option value="off" data-i18n="off">Off</option>
                   </select>
                   ENCUMBRANCE:
                   <select name="attr_encumberance_setting">
                       <option value="off" data-i18n="simple">Simple</option>
                       <option value="on" data-i18n="variant-phb">Variant (PHB p176)</option>
                       <option value="disabled" data-i18n="off">Off</option>
                   </select>
                   INVENTORY:
                   <select name="attr_simpleinventory">
                       <option value="complex" data-i18n="compendium-compatible">Compendium Compatible</option>
                       <option value="simple" data-i18n="simple">Simple</option>
                   </select>
                   FEATURES AND TRAITS:
                   <select name="attr_simpletraits">
                       <option value="complex" data-i18n="compendium-compatible">Compendium Compatible</option>
                       <option value="simple" data-i18n="simple">Simple</option>
                   </select>
                   PROFICENCIES AND LANGUAGES:
                   <select name="attr_simpleproficencies">
                       <option value="complex" data-i18n="compendium-compatible">Compendium Compatible</option>
                       <option value="simple" data-i18n="simple">Simple</option>
                   </select>
                   AMMO TRACKING:
                   <select name="attr_ammotracking">
                       <option value="on" data-i18n="on">On</option>
                       <option value="off" selected="selected" data-i18n="off">Off</option>
                   </select>
                   (API REQUIRED)
                   SHOW EXHAUSTION TRACKING:
                   <select name="attr_exhaustion_toggle">
                       <option value="1" data-i18n="on">On</option>
                       <option value="0" data-i18n="off" selected="selected">Off</option>
                   </select>
                   <input type="checkbox" name="attr_licensedsheet" value="1">
                   USE OFFICIAL D&D STYLING
                   GENERAL OPTIONS
               <input type="hidden" class="warningflag" name="attr_leveler_warningflag">
                   
                       <label><input type="checkbox" name="attr_leveler_warningflag" value="hide">*</label>
                       
                           ATTENTION - YOU CANNOT LAUNCH THE CHARACTERMANCER LEVEL UP UNTIL YOU HAVE A CLASS, LEVEL, AND HP SET FOR LEVEL ONE. PLEASE RUN THE CHARACTERMANCER CREATOR FIRST. THE LEVEL UP TOOL DOESN'T WORK WITH CUSTOM CLASSES OR IF THE MULTICLASS OPTIONS ARE SET UP INCORRECTLY.
                       
                   
                   <button type="action" name="act_relaunch_lvl1mancer" style="padding: 0px;"><img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/CharactermancerIcon200px.png" style="height: 32px; width: 32px" alt="Wand & Hammer of Charactermancer"></button>LAUNCH LEVEL 1 CHARACTERMANCER (CANNOT BE UNDONE)
                   <button type="action" name="act_launch_lvl+mancer" style="padding: 0px;"><img src="https://raw.githubusercontent.com/Roll20/roll20-character-sheets/master/5th%20Edition%20OGL%20by%20Roll20/images/CharactermancerIcon200px.png" style="height: 32px; width: 32px" alt="Wand & Hammer of Charactermancer"></button>LAUNCH LEVEL+ CHARACTERMANCER
                   CHARACTERMANCER OPTIONS
 <input accept="Category" name="attr_drop_category" type="hidden"/>
 <input accept="Name" name="attr_drop_name" type="hidden"/>
 <input accept="data" name="attr_drop_data" type="hidden"/>
 <input accept="Content" name="attr_drop_content" type="hidden"/>
<input type="hidden" name="attr_d20" value="1d20">

<input type="hidden" name="attr_level" value="1"> <input type="hidden" name="attr_pb" value="2"> <input type="hidden" name="attr_pbd_safe" value=""> <input type="hidden" name="attr_jack" value="1"> <input type="hidden" name="attr_jack_attr" value=""> <input type="hidden" name="attr_jack_bonus" value=""> <input type="hidden" name="attr_passive_wisdom" value="10"> <input type="hidden" name="attr_hitdie_final" value=""> <input type="hidden" name="attr_globalsavingthrowbonus" value=""> <input type="hidden" name="attr_death_save_bonus" value="0"> <input type="hidden" name="attr_initiative_bonus" value="0"> <input type="hidden" name="attr_spell_save_dc" value="0"> <input type="hidden" name="attr_spell_attack_bonus" value="0"> <input type="hidden" name="attr_spell_attack_mod" value="0"> <input type="hidden" name="attr_npc_legendary_actions_desc" value=""> <input type="hidden" name="attr_global_damage_mod_crit" value="0"> <input type="hidden" name="attr_global_damage_mod_roll" value="0"> <input type="hidden" name="attr_global_damage_mod_type" value=""> <input type="hidden" name="attr_global_attack_mod" value=""> <input type="hidden" name="attr_global_save_mod" value=""> <input type="hidden" name="attr_global_skill_mod" value="">

<input type="hidden" name="attr_exhaustion_1" value=""> <input type="hidden" name="attr_exhaustion_2" value=""> <input type="hidden" name="attr_exhaustion_3" value=""> <input type="hidden" name="attr_exhaustion_4" value=""> <input type="hidden" name="attr_exhaustion_5" value=""> <input type="hidden" name="attr_exhaustion_6" value="">

<input type="hidden" name="attr_strength_mod" value="0"> <input type="hidden" name="attr_dexterity_mod" value="0"> <input type="hidden" name="attr_constitution_mod" value="0"> <input type="hidden" name="attr_intelligence_mod" value="0"> <input type="hidden" name="attr_wisdom_mod" value="0"> <input type="hidden" name="attr_charisma_mod" value="0">

<input type="hidden" name="attr_strength_save_bonus" value="0"> <input type="hidden" name="attr_dexterity_save_bonus" value="0"> <input type="hidden" name="attr_constitution_save_bonus" value="0"> <input type="hidden" name="attr_intelligence_save_bonus" value="0"> <input type="hidden" name="attr_wisdom_save_bonus" value="0"> <input type="hidden" name="attr_charisma_save_bonus" value="0">

<input type="hidden" name="attr_strength_maximum" value="20"> <input type="hidden" name="attr_dexterity_maximum" value="20"> <input type="hidden" name="attr_constitution_maximum" value="20"> <input type="hidden" name="attr_intelligence_maximum" value="20"> <input type="hidden" name="attr_wisdom_maximum" value="20"> <input type="hidden" name="attr_charisma_maximum" value="20">

<input type='hidden' name='attr_acrobatics_bonus' value='0'> <input type='hidden' name='attr_animal_handling_bonus' value='0'> <input type='hidden' name='attr_arcana_bonus' value='0'> <input type='hidden' name='attr_athletics_bonus' value='0'> <input type='hidden' name='attr_deception_bonus' value='0'> <input type='hidden' name='attr_history_bonus' value='0'> <input type='hidden' name='attr_insight_bonus' value='0'> <input type='hidden' name='attr_intimidation_bonus' value='0'> <input type='hidden' name='attr_investigation_bonus' value='0'> <input type='hidden' name='attr_medicine_bonus' value='0'> <input type='hidden' name='attr_nature_bonus' value='0'> <input type='hidden' name='attr_perception_bonus' value='0'> <input type='hidden' name='attr_performance_bonus' value='0'> <input type='hidden' name='attr_persuasion_bonus' value='0'> <input type='hidden' name='attr_religion_bonus' value='0'> <input type='hidden' name='attr_sleight_of_hand_bonus' value='0'> <input type='hidden' name='attr_stealth_bonus' value='0'> <input type='hidden' name='attr_survival_bonus' value='0'>

<input type='hidden' name='attr_lvl1_slots_total' value='0'> <input type='hidden' name='attr_lvl2_slots_total' value='0'> <input type='hidden' name='attr_lvl3_slots_total' value='0'> <input type='hidden' name='attr_lvl4_slots_total' value='0'> <input type='hidden' name='attr_lvl5_slots_total' value='0'> <input type='hidden' name='attr_lvl6_slots_total' value='0'> <input type='hidden' name='attr_lvl7_slots_total' value='0'> <input type='hidden' name='attr_lvl8_slots_total' value='0'> <input type='hidden' name='attr_lvl9_slots_total' value='0'>

<input type='hidden' name='attr_l1mancer_status' value=> <input type='hidden' name='attr_lpmancer_status' value=>

ACCEPTING DROP FROM COMPENDIUM
   Are you sure you want to turn this character into a ?
           <input class="yes" type="checkbox" name="attr_confirm">Yes
           <input class="cancel" type="checkbox" name="attr_cancel">Cancel
   How do  you want to create this character?
           <input class="yes" type="checkbox" style="width:130px;" name="attr_mancer_confirm">Use the Charactermancer
           <input class="yes" style="width:80px;" type="checkbox" name="attr_mancer_npc">Create an NPC
           <input class="yes" type="checkbox" style="width:90px;" name="attr_mancer_cancel">Edit sheet direclty


<rolltemplate class="sheet-rolltemplate-simple">
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-atk">
               {{#always}}
               Template:/always
               {{#normal}}
               Template:/normal
               {{#advantage}}
                   {{#rollLess() r1 r2}}
                   Template:/rollLess() r1 r2
                   {{#rollTotal() r1 r2}}
                   Template:/rollTotal() r1 r2
                   {{#rollGreater() r1 r2}}
                   Template:/rollGreater() r1 r2
               Template:/advantage
               {{#disadvantage}}
                   {{#rollLess() r1 r2}}
                   Template:/rollLess() r1 r2
                   {{#rollTotal() r1 r2}}
                   Template:/rollTotal() r1 r2
                   {{#rollGreater() r1 r2}}
                   Template:/rollGreater() r1 r2
               Template:/disadvantage
           {{#range}}
           Template:/range
               {{#normal}}
                   {{#rollWasCrit() r1}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r1
                   {{#^rollWasCrit() r1}}Template:Rname{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/^rollWasCrit() r1
               Template:/normal
               {{#always}}
                   {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                   {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                   {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                   {{#^rollWasCrit() r1}}{{#^rollWasCrit() r2}}Template:Rname{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/^rollWasCrit() r2Template:/^rollWasCrit() r1
               Template:/always
               {{#advantage}}
                   {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                   {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                   {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                   {{#^rollWasCrit() r1}}{{#^rollWasCrit() r2}}Template:Rname{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/^rollWasCrit() r2Template:/^rollWasCrit() r1
               Template:/advantage
               {{#disadvantage}}
                   {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:Rnamec{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                   {{#rollTotal() r1 r2}}{{#^rollWasCrit() r1}}Template:Rname{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/^rollWasCrit() r1Template:/rollTotal() r1 r2
                   {{#rollLess() r1 r2}}Template:Rname{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollLess() r1 r2
                   {{#rollGreater() r1 r2}}Template:Rname{{#innate}}, Template:InnateTemplate:/innate (Template:Mod)Template:/rollGreater() r1 r2
               Template:/disadvantage
           {{#charname}}
           Template:/charname
       {{#desc}}
       Template:/desc
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-dmg">
       {{#save}}
           {{#attack}}
           Template:/attack
           Template:^attack
       Template:/save
       Template:^attack
           {{#desc}}
           Template:/desc
       Template:/attack
       {{#globaldamage}}
           {{#^rollTotal() globaldamage 0}}
           Template:/^rollTotal() globaldamage 0
       Template:/globaldamage
       {{#hldmg}}
           {{#^rollTotal() hldmg 0}}
           Template:/^rollTotal() hldmg 0
       Template:/hldmg
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-atkdmg">
       {{#attack}}
                   {{#always}}
                   Template:/always
                   {{#normal}}
                   Template:/normal
                   {{#advantage}}
                       {{#rollLess() r1 r2}}
                       Template:/rollLess() r1 r2
                       {{#rollTotal() r1 r2}}
                       Template:/rollTotal() r1 r2
                       {{#rollGreater() r1 r2}}
                       Template:/rollGreater() r1 r2
                   Template:/advantage
                   {{#disadvantage}}
                       {{#rollLess() r1 r2}}
                       Template:/rollLess() r1 r2
                       {{#rollTotal() r1 r2}}
                       Template:/rollTotal() r1 r2
                       {{#rollGreater() r1 r2}}
                       Template:/rollGreater() r1 r2
                   Template:/disadvantage
               {{#range}}
               Template:/range
               {{#charname}}
               Template:/charname
       Template:/attack
       {{#save}}
           {{#attack}}
           Template:/attack
           Template:^attack
       Template:/save
       {{#desc}}
       Template:/desc
       {{#globaldamage}}
           {{#^rollTotal() globaldamage 0}}
           Template:/^rollTotal() globaldamage 0
       Template:/globaldamage
       {{#hldmg}}
           {{#^rollTotal() hldmg 0}}
                   
                       Template:Hldmg
                       {{#attack}}
                           {{#normal}}
                               {{#rollWasCrit() r1}} + Template:HldmgcritTemplate:/rollWasCrit() r1
                           Template:/normal
                           {{#always}}
                               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}} + Template:HldmgcritTemplate:/rollWasCrit() r2Template:/rollLess() r1 r2
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:HldmgcritTemplate:/rollWasCrit() r1Template:/rollTotal() r1 r2
                               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}} + Template:HldmgcritTemplate:/rollWasCrit() r1Template:/rollGreater() r1 r2
                           Template:/always
                           {{#advantage}}
                               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}} + Template:HldmgcritTemplate:/rollWasCrit() r2Template:/rollLess() r1 r2
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:HldmgcritTemplate:/rollWasCrit() r1Template:/rollTotal() r1 r2
                               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}} + Template:HldmgcritTemplate:/rollWasCrit() r1Template:/rollGreater() r1 r2
                           Template:/advantage
                           {{#disadvantage}}
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:HldmgcritTemplate:/rollWasCrit() r1Template:/rollTotal() r1 r2
                           Template:/disadvantage
                       Template:/attack
                   
                   Template:Dmg1type
                       Higher Level Cast
           Template:/^rollTotal() hldmg 0
       Template:/hldmg
       {{#damage}}
                   {{#dmg1flag}}
                       Template:^dmg2flag
                               
                                   Template:Dmg1
                                   {{#attack}}
                                       {{#normal}}
                                           {{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1
                                       Template:/normal
                                       {{#always}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit1Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/always
                                       {{#advantage}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit1Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/advantage
                                       {{#disadvantage}}
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                       Template:/disadvantage
                                   Template:/attack
                               
                               Template:Dmg1type
                       Template:/dmg2flag
                   Template:/dmg1flag
                   {{#dmg2flag}}
                       Template:^dmg1flag
                               
                                   Template:Dmg2
                                   {{#attack}}
                                       {{#normal}}
                                           {{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1
                                       Template:/normal
                                       {{#always}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit2Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/always
                                       {{#advantage}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit2Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/advantage
                                       {{#disadvantage}}
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                       Template:/disadvantage
                                   Template:/attack
                               
                               Template:Dmg2type
                       Template:/dmg1flag
                   Template:/dmg2flag
                   {{#dmg1flag}}
                       {{#dmg2flag}}
                               
                                   Template:Dmg1
                                   {{#attack}}
                                       {{#normal}}
                                           {{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1
                                       Template:/normal
                                       {{#always}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit1Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/always
                                       {{#advantage}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit1Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/advantage
                                       {{#disadvantage}}
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                       Template:/disadvantage
                                   Template:/attack
                               
                               Template:Dmg1type
                               
                                   Template:Dmg2
                                   {{#attack}}
                                       {{#normal}}
                                           {{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1
                                       Template:/normal
                                       {{#always}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit2Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/always
                                       {{#advantage}}
                                           {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}+ Template:Crit2Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                           {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                                       Template:/advantage
                                       {{#disadvantage}}
                                           {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}+ Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                                       Template:/disadvantage
                                   Template:/attack
                               
                               Template:Dmg2type
                       Template:/dmg2flag
                   Template:/dmg1flag
               Template:^attack
                   {{#range}}
                   Template:/range
                   {{#charname}}
                   Template:/charname
               Template:/attack
       Template:/damage
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-desc">
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-spell">
           {{#castingtime}}
               Casting Time: Template:Castingtime
           Template:/castingtime
           {{#range}}
           Template:/range
           {{#target}}
               Target: Template:Target
           Template:/target
           {{#duration}}
               Duration: {{#concentration}}Concentration Template:/concentrationTemplate:Duration
           Template:/duration
           {{#description}}
           Template:/description
           {{#athigherlevels}}
               At Higher Levels. Template:Athigherlevels
           Template:/athigherlevels
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-traits">
       {{#source}}
       Template:/source
       {{#description}}
       Template:/description
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-npc">
       {{#name}}
       Template:/name
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-npcatk">
           {{#normal}}
               {{#rollWasCrit() r1}}Template:RnamecTemplate:/rollWasCrit() r1
               {{#^rollWasCrit() r1}}Template:RnameTemplate:/^rollWasCrit() r1
           Template:/normal
           {{#always}}
               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}Template:RnamecTemplate:/rollWasCrit() r2Template:/rollLess() r1 r2
               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:RnamecTemplate:/rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}Template:RnamecTemplate:/rollWasCrit() r1Template:/rollGreater() r1 r2
               {{#^rollWasCrit() r1}}{{#^rollWasCrit() r2}}Template:RnameTemplate:/^rollWasCrit() r2Template:/^rollWasCrit() r1
           Template:/always
           {{#advantage}}
               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}Template:RnamecTemplate:/rollWasCrit() r2Template:/rollLess() r1 r2
               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:RnamecTemplate:/rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}Template:RnamecTemplate:/rollWasCrit() r1Template:/rollGreater() r1 r2
               {{#^rollWasCrit() r1}}{{#^rollWasCrit() r2}}Template:RnameTemplate:/^rollWasCrit() r2Template:/^rollWasCrit() r1
           Template:/advantage
           {{#disadvantage}}
               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:RnamecTemplate:/rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollTotal() r1 r2}}{{#^rollWasCrit() r1}}Template:RnameTemplate:/^rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollLess() r1 r2}}Template:RnameTemplate:/rollLess() r1 r2
               {{#rollGreater() r1 r2}}Template:RnamecTemplate:/rollGreater() r1 r2
           Template:/disadvantage
       {{#name}}
       Template:/name
           {{#normal}}
               {{#rollWasCrit() r1}}Template:Typec: Template:/rollWasCrit() r1
               {{#^rollWasCrit() r1}}Template:Type: Template:/^rollWasCrit() r1
           Template:/normal
           {{#always}}
               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}Template:Typec: Template:/rollWasCrit() r2Template:/rollLess() r1 r2
               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:Typec: Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}Template:Typec: Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
               {{#^rollWasCrit() r1}}{{#^rollWasCrit() r2}}Template:Type: Template:/^rollWasCrit() r2Template:/^rollWasCrit() r1
           Template:/always
           {{#advantage}}
               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}}[[[:Template:Typec]]: Template:/rollWasCrit() r2Template:/rollLess() r1 r2
               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:Typec: Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}}Template:Typec: Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
               {{#^rollWasCrit() r1}}{{#^rollWasCrit() r2}}Template:Type: Template:/^rollWasCrit() r2Template:/^rollWasCrit() r1
           Template:/advantage
           {{#disadvantage}}
               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}}Template:Typec: Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollTotal() r1 r2}}{{#^rollWasCrit() r1}}Template:Type: Template:/^rollWasCrit() r1Template:/rollTotal() r1 r2
               {{#rollLess() r1 r2}}Template:Type: Template:/rollLess() r1 r2
               {{#rollGreater() r1 r2}}Template:Typec: Template:/rollGreater() r1 r2
           Template:/disadvantage
           {{#normal}}
               Template:R1
           Template:/normal
           {{#always}}
               Template:R1 | Template:R2
           Template:/always
           {{#advantage}}
               {{#rollLess() r1 r2}}
                   Template:R1 | Template:R2
               Template:/rollLess() r1 r2
               {{#rollTotal() r1 r2}}
                   Template:R1 | Template:R2
               Template:/rollTotal() r1 r2
               {{#rollGreater() r1 r2}}
                   Template:R1 | Template:R2
               Template:/rollGreater() r1 r2
           Template:/advantage
           {{#disadvantage}}
               {{#rollLess() r1 r2}}
                   Template:R1 | Template:R2
               Template:/rollLess() r1 r2
               {{#rollTotal() r1 r2}}
                   Template:R1 | Template:R2
               Template:/rollTotal() r1 r2
               {{#rollGreater() r1 r2}}
                   Template:R1 | Template:R2
               Template:/rollGreater() r1 r2
           Template:/disadvantage
       {{#description}}
       Template:/description
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-npcdmg">
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-npcaction">
           {{#name}}
           Template:/name
           {{#attack}}
                   {{#normal}}
                       Attack: Template:R1
                   Template:/normal
                   {{#always}}
                       Attack: Template:R1 | Template:R2
                   Template:/always
                   {{#advantage}}
                       {{#rollLess() r1 r2}}
                           Attack: Template:R1 | Template:R2
                       Template:/rollLess() r1 r2
                       {{#rollTotal() r1 r2}}
                           Attack: Template:R1 | Template:R2
                       Template:/rollTotal() r1 r2
                       {{#rollGreater() r1 r2}}
                           Attack: Template:R1 | Template:R2
                       Template:/rollGreater() r1 r2
                   Template:/advantage
                   {{#disadvantage}}
                       {{#rollLess() r1 r2}}
                           Attack: Template:R1 | Template:R2
                       Template:/rollLess() r1 r2
                       {{#rollTotal() r1 r2}}
                           Attack: Template:R1 | Template:R2
                       Template:/rollTotal() r1 r2
                       {{#rollGreater() r1 r2}}
                           Attack: Template:R1 | Template:R2
                       Template:/rollGreater() r1 r2
                   Template:/disadvantage
           Template:/attack
           {{#description}}
               Template:Description
           Template:/description
           {{#damage}}
                   Damage: 
                   
                       {{#dmg1flag}}
                           Template:Dmg1
                           {{#normal}}
                               {{#rollWasCrit() r1}} + Template:Crit1Template:/rollWasCrit() r1
                           Template:/normal
                           {{#always}}
                               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}} + Template:Crit1Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit1Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                           Template:/always
                           {{#advantage}}
                               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}} + Template:Crit1Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit1Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                           Template:/advantage
                           {{#disadvantage}}
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit1Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                           Template:/disadvantage
                           Template:Dmg1type
                       Template:/dmg1flag
                       {{#dmg1flag}}{{#dmg2flag}}+Template:/dmg2flagTemplate:/dmg1flag
                       {{#dmg2flag}}
                           Template:Dmg2
                           {{#normal}}
                               {{#rollWasCrit() r1}} + Template:Crit2Template:/rollWasCrit() r1
                           Template:/normal
                           {{#always}}
                               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}} + Template:Crit2Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit2Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                           Template:/always
                           {{#advantage}}
                               {{#rollLess() r1 r2}}{{#rollWasCrit() r2}} + Template:Crit2Template:/rollWasCrit() r2Template:/rollLess() r1 r2
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                               {{#rollGreater() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit2Template:/rollWasCrit() r1Template:/rollGreater() r1 r2
                           Template:/advantage
                           {{#disadvantage}}
                               {{#rollTotal() r1 r2}}{{#rollWasCrit() r1}} + Template:Crit2Template:/rollWasCrit() r1Template:/rollTotal() r1 r2
                           Template:/disadvantage
                           Template:Dmg2type
                       Template:/dmg2flag
                   
           Template:/damage
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-mancerroll">
           {{#r1}}
                   Roll 1: 
                   Template:R1
           Template:/r1
           {{#r2}}
                   Roll 2: 
                   Template:R2
           Template:/r2
           {{#r3}}
                   Roll 3: 
                   Template:R3
           Template:/r3
           {{#r4}}
                   Roll 4: 
                   Template:R4
           Template:/r4
           {{#r5}}
                   Roll 5: 
                   Template:R5
           Template:/r5
           {{#r6}}
                   Roll 6: 
                   Template:R6
           Template:/r6
   </rolltemplate>
   <rolltemplate class="sheet-rolltemplate-mancerhproll">
           {{#a1}}
               Average: Template:A1
           Template:/a1
           {{#r1}}
               Roll 1: Template:R1
           Template:/r1
           {{#r2}}
                   Roll 2: Template:R2
           Template:/r2
           {{#r3}}
                   Roll 3: Template:R3
           Template:/r3
           {{#r4}}
                   Roll 4: Template:R4
           Template:/r4
           {{#r5}}
                   Roll 5: Template:R5
           Template:/r5
           {{#r6}}
                   Roll 6: Template:R6
           Template:/r6
           {{#r7}}
                   Roll 7: Template:R7
           Template:/r7
           {{#r8}}
                   Roll 8: Template:R8
           Template:/r8
           {{#r9}}
                   Roll 9: Template:R9
           Template:/r9
           {{#r10}}
                   Roll 10: Template:R10
           Template:/r10
           {{#r11}}
                   Roll 11: Template:R11
           Template:/r11
                       {{#r12}}
                   Roll 12: Template:R12
           Template:/r12
           {{#r13}}
                   Roll 13: Template:R13
           Template:/r13
           {{#r14}}
                   Roll 14: Template:R14
           Template:/r14
           {{#r15}}
                   Roll 15: Template:R15
           Template:/r15
           {{#r16}}
                   Roll 16: Template:R16
           Template:/r16
           {{#r17}}
                   Roll 17: Template:R17
           Template:/r17
           {{#r18}}
                   Roll 18: Template:R18
           Template:/r18
           {{#r19}}
                   Roll 19: Template:R19
           Template:/r19
           {{#r20}}
                   Roll 20: Template:R20
           Template:/r20
   </rolltemplate>

<script type="text/worker">

     on("sheet:opened", function(eventinfo) {
       versioning(function() {
           var getInfo = function(sections, callback, results) {
               results =  results || {};
               if(sections.length > 0) {
                   var section = sections.pop();
                   getSectionIDs(section, function(ids) {
                       results[section] = ids;
                       getInfo(sections, callback, results);
                   });
               } else {
                   callback(results);
               }
           }
           var spellSections = ["spell-cantrip"];
           for(var x=1; x<=9; x++) {
               spellSections.push("spell-" + x);
           }
           getInfo(spellSections, function(results) {
               var getList = ["character_id"];
               _.each(results, function(sectionids, sectionname) {
                   _.each(sectionids, function(spellid) {
                       getList.push("repeating_" + sectionname + "_" + spellid + "_rollcontent");
                   });
               });
               getAttrs(getList, function(attrs) {
                   var set = {};
                   _.each(attrs, function(data, name) {
                       if(data.length === 68 && data.split("|")[0].substr(2) !== attrs["character_id"]) {
                           set[name] = "%{" + attrs["character_id"] + data.substr(22);
                       }
                   });
                   setAttrs(set, function() {
                       if(eventinfo.sourceType === "sheetworker") {
                           setAttrs({l1mancer_status: "completed"})
                       }
                       else {
                           check_l1_mancer();
                           check_lp_mancer();
                       };
                   });
               });
           });
       });
   });
   //Start of Compendium Drops
   on("sheet:compendium-drop", function() {
       getAttrs(["hp_max","npc_senses","token_size","cd_bar1_v","cd_bar1_m","cd_bar1_l","cd_bar2_v","cd_bar2_m","cd_bar2_l","cd_bar3_v","cd_bar3_m","cd_bar3_l"], function(v) {
           var default_attr = {};
           default_attr["width"] = 70;
           default_attr["height"] = 70;
           if(v["npc_senses"].toLowerCase().match(/(darkvision|blindsight|tremorsense|truesight)/)) {
               default_attr["light_radius"] = Math.max.apply(Math, v["npc_senses"].match(/\d+/g));
           }
           if(v["token_size"]) {
               var squarelength = 70;
               if(v["token_size"].toString().indexOf(",") > -1) {
                   var setwidth = !isNaN(v["token_size"].split(",")[0]) ? v["token_size"].split(",")[0] : 1;
                   var setheight = !isNaN(v["token_size"].split(",")[1]) ? v["token_size"].split(",")[1] : 1;
                   default_attr["width"] = setwidth * squarelength;
                   default_attr["height"] = setheight * squarelength;
               }
               else {
                   default_attr["width"] = squarelength * v["token_size"]
                   default_attr["height"] = squarelength * v["token_size"]
               };
           }
           var getList = {};
           for(x = 1; x<=3; x++) {
               _.each(["v", "m"], function(letter) {
                   var keyname = "cd_bar" + x + "_" + letter;
                   if(v[keyname] != undefined && isNaN(v[keyname])) {
                       getList[keyname] = v[keyname];
                   }
               });
           }
           getAttrs(_.values(getList), function(values) {
               _.each(_.keys(getList), function(keyname) {
                   v[keyname] = values[getList[keyname]] == undefined ? "" : values[getList[keyname]];
               });
               if(v["cd_bar1_l"]) {
                   default_attr["bar1_link"] = v["cd_bar1_l"];
               }
               else if(v["cd_bar1_v"] || v["cd_bar1_m"]) {
                   if(v["cd_bar1_v"]) {
                       default_attr["bar1_value"] = v["cd_bar1_v"];
                   }
                   if(v["cd_bar1_m"]) {
                       default_attr["bar1_max"] = v["cd_bar1_m"];
                   }
               }
               else {
                   default_attr["bar1_value"] = v["hp_max"];
                   default_attr["bar1_max"] = v["hp_max"];
               }
               if(v["cd_bar2_l"]) {
                   default_attr["bar2_link"] = v["cd_bar2_l"];
               }
               else if(v["cd_bar2_v"] || v["cd_bar2_m"]) {
                   if(v["cd_bar2_v"]) {
                       default_attr["bar2_value"] = v["cd_bar2_v"];
                   }
                   if(v["cd_bar2_m"]) {
                       default_attr["bar2_max"] = v["cd_bar2_m"];
                   }
               }
               else {
                   default_attr["bar2_link"] = "npc_ac";
               }
               if(v["cd_bar3_l"]) {
                   default_attr["bar3_link"] = v["cd_bar3_l"];
               }
               else if(v["cd_bar3_v"] || v["cd_bar3_m"]) {
                   if(v["cd_bar3_v"]) {
                       default_attr["bar3_value"] = v["cd_bar3_v"];
                   }
                   if(v["cd_bar3_m"]) {
                       default_attr["bar3_max"] = v["cd_bar3_m"];
                   }
               }
               setDefaultToken(default_attr);
           });
       });
   });
   ['strength','dexterity','constitution','intelligence','wisdom','charisma'].forEach(attr => {
       on(`change:${attr}_base change:${attr}_bonus`, function() {
           update_attr(`${attr}`);
       });
   });
   ['strength','dexterity','constitution','intelligence','wisdom','charisma'].forEach(attr => {
       on(`change:${attr}`, function() {
           update_mod(`${attr}`);
           const cap = attr.charAt(0).toUpperCase() + attr.slice(1);
           check_customac(cap);
           (attr === "strength") ? update_weight() : false;
           (attr === "dexterity") ? update_initiative() : false;
       });
   });
   ['strength','dexterity','constitution','intelligence','wisdom','charisma'].forEach(attr => {
       on(`change:${attr}_mod`, function() {
           update_save(`${attr}`);
           update_attacks(`${attr}`);
           update_tool(`${attr}`);
           update_spell_info(`${attr}`);
           switch(`${attr}`) {
               case "strength":
                   update_skills(["athletics"]);
                   break;
               case "dexterity":
                   update_skills(["acrobatics", "sleight_of_hand", "stealth"]);
                   update_ac();
                   update_initiative();
                   break;
               case "intelligence":
                   update_skills(["arcana", "history", "investigation", "nature", "religion"]);
                   break;
               case "wisdom":
                   update_skills(["animal_handling", "insight", "medicine", "perception", "survival"]);
                   break;
               case "charisma":
                   update_skills(["deception", "intimidation", "performance", "persuasion"]);
                   break;
               default:
                   false;
           }
       });
   });
   ['strength','dexterity','constitution','intelligence','wisdom','charisma'].forEach(attr => {
       on(`change:${attr}_save_prof change:${attr}_save_mod`, function(eventinfo) {
           if(eventinfo.sourceType === "sheetworker") {return;};
           update_save(`${attr}`);
       });
   });
   on("change:globalsavemod", function(eventinfo) {
       if(eventinfo.sourceType === "sheetworker") {return;};
       update_all_saves();
   });
   on("change:death_save_mod", function(eventinfo) {
       if(eventinfo.sourceType === "sheetworker") {return;};
       update_save("death");
   });
   ['acrobatics','animal_handling','arcana','athletics','deception','history','insight','intimidation','investigation',
   'medicine','nature','perception','performance','persuasion','religion','sleight_of_hand','stealth','survival'].forEach(attr => {
       on(`change:${attr}_prof change:${attr}_type change:${attr}_flat`, function(eventinfo) {
           if(eventinfo.sourceType === "sheetworker") {return;};
           update_skills([`${attr}`]);
       });
   });
   on("change:repeating_tool:toolname change:repeating_tool:toolbonus_base change:repeating_tool:toolattr_base change:repeating_tool:tool_mod", function(eventinfo) {
       if(eventinfo.sourceType === "sheetworker") {
           return;
       }
       var tool_id = eventinfo.sourceAttribute.substring(15, 35);
       update_tool(tool_id);
   });
   on("change:repeating_attack:atkname change:repeating_attack:atkflag change:repeating_attack:atkattr_base change:repeating_attack:atkmod change:repeating_attack:atkmagic change:repeating_attack:atkprofflag change:repeating_attack:dmgflag change:repeating_attack:dmgbase change:repeating_attack:dmgattr change:repeating_attack:dmgmod change:repeating_attack:dmgtype change:repeating_attack:dmg2flag change:repeating_attack:dmg2base change:repeating_attack:dmg2attr change:repeating_attack:dmg2mod change:repeating_attack:dmg2type change:repeating_attack:saveflag change:repeating_attack:savedc change:repeating_attack:saveflat change:repeating_attack:dmgcustcrit change:repeating_attack:dmg2custcrit change:repeating_attack:ammo change:repeating_attack:saveattr change:repeating_attack:atkrange", function(eventinfo) {
       if(eventinfo.sourceType === "sheetworker") {
           return;
       }
       var source = eventinfo.sourceAttribute.substr(38);
       var attackid = eventinfo.sourceAttribute.substring(17, 37);
       if(source == "atkattr_base" || source == "savedc") {
           getAttrs(["repeating_attack_spellid", "repeating_attack_spelllevel"], function(v) {
               set = {};
               if(v.repeating_attack_spellid && v.repeating_attack_spellid != "" && v.repeating_attack_spelllevel && v.repeating_attack_spelllevel != "") {
                   var newVal = eventinfo.newValue == "spell" ? "spell" : _.last(eventinfo.newValue.split("_")[0].split("{"));
                   set["repeating_attack_atkattr_base"] = newVal == "spell" ? "spell" : "@{" + newVal + "_mod}";
                   set["repeating_attack_savedc"] = newVal == "spell" ? "spell" : "(@{" + newVal + "_mod}+8+@{pb})";
                   set["repeating_spell-" + v.repeating_attack_spelllevel + "_" + v.repeating_attack_spellid + "_spell_ability"] = newVal == "spell" ? "spell" : "@{" + newVal + "_mod}+";
               }
               setAttrs(set, function() {
                   update_attacks(attackid);
               });
           });
       } else {
           update_attacks(attackid);
       }
   });
   on("change:repeating_damagemod remove:repeating_damagemod", function(eventinfo) {
       update_globaldamage();
   });
   on("change:global_damage_mod_flag", function(eventinfo) {
       getSectionIDs("damagemod", function(ids) {
           var update = {};
           if(eventinfo.newValue === "1") {
               if(!ids || ids.length === 0) {
                   var rowid = generateRowID();
                   update[`repeating_damagemod_${rowid}_global_damage_active_flag`] = "1";
               }
           } else {
               _.each(ids, function(rowid) {
                   update[`repeating_damagemod_${rowid}_global_damage_active_flag`] = "0";
               });
           }
           setAttrs(update);
       });
   });
   on("change:exhaustion_toggle", function(eventinfo) {
       if(eventinfo.newValue !== "0") {
           getAttrs(["exhaustion_level"], function(attrs) {
               if(!attrs.exhaustion_level || attrs.exhaustion_level === "") {
                   var update = {};
                   update.exhaustion_level = "0";
                   setAttrs(update);
               }
           });
       }
   });
   on("change:exhaustion_level", function(eventinfo) {
       const newValue = parseInt(eventinfo.newValue) || 0, previousValue = parseInt(eventinfo.previousValue) || 0;
       let update = {};
      if (newValue === 0) {
           //If exhaustion is 0 the reset exhaustion_1 to "No Effect" and blank the other spans
           for(let i = 2; i <= 6; i++) { update[`exhaustion_${i}`] = ""}
           update[`exhaustion_1`] = "• " + getTranslationByKey(`exhaustion-0`)
       } else if (newValue > previousValue) {
           //If exhaustion increase then add text to the spans
           for(let i = previousValue; i <= newValue; i++)
           {update[`exhaustion_${i}`] = "• " + getTranslationByKey(`exhaustion-${i}`)}
       } else {
           //If exhaustion decrease remove text from spans
           for(let i = newValue + 1; i <= previousValue; i++) {update[`exhaustion_${i}`] = ""}
       };
       setAttrs(update, {silent: true});
   });
   on("change:race change:subrace", function(eventinfo) {
       update_race_display();
   });
   on("change:drop_category", function(eventinfo) {
       if(eventinfo.newValue === "Monsters") {
           getAttrs(["class","race","speed","hp"], function(v) {
               if(v["class"] != "" || v["race"] != "" || v["speed"] != "" || v["hp"] != "") {
                   setAttrs({monster_confirm_flag: 1});
               }
               else {
                   handle_drop(eventinfo.newValue);
               }
           });
       }
       else {
           handle_drop(eventinfo.newValue);
       }
   });
   on(`change:repeating_inventory:hasattack`, function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {return;};
       const itemid = eventinfo.sourceAttribute.substring(20, 40);
       getAttrs([`repeating_inventory_${itemid}_itemattackid`], function(v) {
           const hasattack = eventinfo.newValue, itemattackid = v[`repeating_inventory_${itemid}_itemattackid`];
           (hasattack == 1) ? create_attack_from_item(itemid) : remove_attack(itemattackid);
       });
   });
   on(`change:repeating_inventory:useasresource`, function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {return;};
       const itemid = eventinfo.sourceAttribute.substring(20, 40);
       getAttrs([`repeating_inventory_${itemid}_itemresourceid`], function(v) {
           const useasresource = eventinfo.newValue, itemresourceid = v[`repeating_inventory_${itemid}_itemresourceid`];
           (useasresource == 1) ? create_resource_from_item(itemid) : remove_resource(itemresourceid);
       });
   });
   on("change:repeating_inventory:itemname change:repeating_inventory:itemproperties change:repeating_inventory:itemmodifiers change:repeating_inventory:itemcount", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       var itemid = eventinfo.sourceAttribute.substring(20, 40);
       getAttrs(["repeating_inventory_" + itemid + "_itemattackid", "repeating_inventory_" + itemid + "_itemresourceid"], function(v) {
           var attackid = v["repeating_inventory_" + itemid + "_itemattackid"];
           var resourceid = v["repeating_inventory_" + itemid + "_itemresourceid"];
           if(attackid) {
               update_attack_from_item(itemid, attackid);
           }
           if(resourceid) {
               update_resource_from_item(itemid, resourceid);
           }
       });
   });
   ['other_resource','repeating_resource:resource_left','repeating_resource:resource_right'].forEach(attr => {
       on(`change:${attr} change:${attr}_name`, (eventinfo) => {
           if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {return;}
           const resourceid = (eventinfo.sourceAttribute.includes("_name")) ? eventinfo.sourceAttribute.slice(0, -5) : eventinfo.sourceAttribute;
           getAttrs([`${resourceid}_itemid`], (v) => {
               const value = eventinfo.newValue;
               //Update repeating_inventory if an itemid is associated with a resource
               if (v[`${resourceid}_itemid`] && v[`${resourceid}_itemid`] != "") {
                   const itemid = v[`${resourceid}_itemid`];
                   let update = {};
                   if (eventinfo.sourceAttribute.includes("_name")) {
                       update[`repeating_inventory_${itemid}_itemname`]  = eventinfo.newValue;
                   } else {
                       update[`repeating_inventory_${itemid}_itemcount`] = eventinfo.newValue;
                   };
                   setAttrs(update, {silent: true}, () => {update_weight()});
               };
           });
       });
   });
   on("change:repeating_inventory:itemweight change:repeating_inventory:itemcount change:cp change:sp change:ep change:gp change:pp change:encumberance_setting change:size change:carrying_capacity_mod", function() {
       update_weight();
   });
   on("change:repeating_inventory:itemmodifiers change:repeating_inventory:equipped", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       var itemid = eventinfo.sourceAttribute.substring(20, 40);
       getAttrs(["repeating_inventory_" + itemid + "_itemmodifiers"], function(v) {
           if(v["repeating_inventory_" + itemid + "_itemmodifiers"]) {
               check_itemmodifiers(v["repeating_inventory_" + itemid + "_itemmodifiers"], eventinfo.previousValue);
           };
       });
   });
   on("change:custom_ac_flag change:custom_ac_base change:custom_ac_part1 change:custom_ac_part2 change:custom_ac_shield", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       update_ac();
   });
  ['spell-cantrip','spell-1','spell-2','spell-3','spell-4','spell-5','spell-6','spell-7','spell-8','spell-9'].forEach(attr => {
       on(`change:repeating_${attr}:includedesc change:repeating_${attr}:innate change:repeating_${attr}:spell_ability change:repeating_${attr}:spell_updateflag change:repeating_${attr}:spellathigherlevels change:repeating_${attr}:spellattack change:repeating_${attr}:spelldamage change:repeating_${attr}:spelldamage2 change:repeating_${attr}:spelldamagetype change:repeating_${attr}:spelldamagetype2 change:repeating_${attr}:spelldescription change:repeating_${attr}:spelldmgmod change:repeating_${attr}:spellhealing change:repeating_${attr}:spellhlbonus change:repeating_${attr}:spellhldie change:repeating_${attr}:spellhldietype change:repeating_${attr}:spellname change:repeating_${attr}:spellprepared change:repeating_${attr}:spellrange change:repeating_${attr}:spellsave change:repeating_${attr}:spellsavesuccess change:repeating_${attr}:spelltarget change:repeating_${attr}:spell_damage_progression`, (eventinfo) => {
           if (eventinfo.sourceType && eventinfo.sourceType === "sheetworker") { return; }
           const spellid = eventinfo.sourceAttribute.split("_")[2], repeating_source = `repeating_${attr}_${spellid}`;
           getAttrs([`${repeating_source}_spellattackid`], (v) => {
               var attackid = v[`${repeating_source}_spellattackid`];
               var lvl      = attr.split("spell-")[1];
               if(attackid && lvl && spellid) {
                   update_attack_from_spell(lvl, spellid, attackid)
               }
           });
       });
   });
   ['spell-cantrip','spell-1','spell-2','spell-3','spell-4','spell-5','spell-6','spell-7','spell-8','spell-9'].forEach(attr => {
       on(`change:repeating_${attr}:spelloutput`, (eventinfo) => {
           if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {return;}
           const spellid = eventinfo.sourceAttribute.split("_")[2], repeating_source = `repeating_${attr}_${spellid}`;
           getAttrs([`${repeating_source}_spellattackid`, `${repeating_source}_spelllevel`, `${repeating_source}_spellathigherlevels`, "character_id"], function(v) {
               const attackid     = v[repeating_source + "_spellattackid"];
               const higherlevels = v[repeating_source + "_spellathigherlevels"];
               const spelloutput  = eventinfo.newValue;
               let lvl            = v[repeating_source + "_spelllevel"];
               if (spelloutput && spelloutput === "ATTACK") {
                   create_attack_from_spell(lvl, spellid, v["character_id"]);
               } else if (spelloutput && spelloutput === "SPELLCARD" && attackid && attackid != "") {
                   let lvl = parseInt(v[repeating_source + "_spelllevel"], 10);
                   remove_attack(attackid);
                   update_spelloutput(higherlevels, lvl, repeating_source, spelloutput, licensedsheet);
               }
           });
       });
   });
   ['spell-cantrip','spell-1','spell-2','spell-3','spell-4','spell-5','spell-6','spell-7','spell-8','spell-9'].forEach(attr => {
       on(`change:repeating_${attr}:spellathigherlevels`, (eventinfo) => {
           if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {return;}
           const spellid = eventinfo.sourceAttribute.split("_")[2], repeating_source = `repeating_${attr}_${spellid}`;
           getAttrs([`${repeating_source}_spelllevel`, `${repeating_source}_spelloutput`], function(v) {
               const higherlevels = eventinfo.newValue;
               const lvl          = parseInt(v[repeating_source + "_spelllevel"], 10);
               const spelloutput  = v[repeating_source + "_spelloutput"];
               if (spelloutput && spelloutput === "SPELLCARD") {
                   update_spelloutput(higherlevels, lvl, repeating_source, spelloutput, licensedsheet);
               }
           });
       });
   });
   const update_spelloutput = (higherlevels, lvl, repeating_source, spelloutput, licensedsheet)  => {
       let spelllevel = "@{spelllevel}";
       let update = {};
       if (higherlevels) {
           for(i = 0; i < 10-lvl; i++) {
               let tot = parseInt(i, 10) + parseInt(lvl, 10);
               spelllevel = spelllevel + "|Level " + tot + "," + tot;
           }
           spelllevel = `?{Cast at what level? ${spelllevel}}`;
       }
       update[repeating_source + "_rollcontent"] = `@{wtype}&{template:spell} {{level=@{spellschool} ${spelllevel}}} {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
       setAttrs(update, {silent: true});
   };
   on("change:class change:custom_class change:cust_classname change:cust_hitdietype change:cust_spellcasting_ability change:cust_spellslots change:cust_strength_save_prof change:cust_dexterity_save_prof change:cust_constitution_save_prof change:cust_intelligence_save_prof change:cust_wisdom_save_prof change:cust_charisma_save_prof change:subclass change:multiclass1 change:multiclass1_subclass change:multiclass2 change:multiclass2_subclass change:multiclass3 change:multiclass3_subclass" , function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       update_class();
   });
   on("change:base_level change:multiclass1_flag change:multiclass1 change:multiclass1_lvl change:multiclass2_flag change:multiclass2 change:multiclass2_lvl change:multiclass3_flag change:multiclass3 change:multiclass3_lvl change:arcane_fighter change:arcane_rogue", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       set_level();
   });
   on("change:level_calculations change:caster_level change:lvl1_slots_mod change:lvl2_slots_mod change:lvl3_slots_mod change:lvl4_slots_mod change:lvl5_slots_mod change:lvl6_slots_mod change:lvl7_slots_mod change:lvl8_slots_mod change:lvl9_slots_mod", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       getAttrs(["level_calculations"], function(v) {
           if(!v["level_calculations"] || v["level_calculations"] == "on") {
               update_spell_slots();
           };
       });
   });
   on("change:caster_level", function(eventinfo) {
       getAttrs(["caster_level","npc"], function(v) {
           var casterlvl = v["caster_level"] && !isNaN(parseInt(v["caster_level"], 10)) ? parseInt(v["caster_level"], 10) : 0;
           if(v["npc"] && v["npc"] == 1 && casterlvl > 0) {
               setAttrs({level: casterlvl})
           };
       });
   });
   on("change:pb_type change:pb_custom", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       update_pb();
   });
   on("change:dtype", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       update_attacks("all");
       update_npc_action("all");
   });
   on("change:jack_of_all_trades", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       update_jack_attr();
       update_all_ability_checks();
   });
   on("change:initmod change:init_tiebreaker", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       update_initiative();
   });
   on("change:spellcasting_ability change:spell_dc_mod change:globalmagicmod", function(eventinfo) {
       if(eventinfo.sourceType && eventinfo.sourceType === "sheetworker") {
           return;
       }
       update_spell_info();
   });
   on("change:npc_challenge", function() {
       update_challenge();
   });
   on("change:npc_str_save_base change:npc_dex_save_base change:npc_con_save_base change:npc_int_save_base change:npc_wis_save_base change:npc_cha_save_base", function(eventinfo) {
       update_npc_saves();
   });
   on("change:npc_acrobatics_base change:npc_animal_handling_base change:npc_arcana_base change:npc_athletics_base change:npc_deception_base change:npc_history_base change:npc_insight_base change:npc_intimidation_base change:npc_investigation_base change:npc_medicine_base change:npc_nature_base change:npc_perception_base change:npc_performance_base change:npc_persuasion_base change:npc_religion_base change:npc_sleight_of_hand_base change:npc_stealth_base change:npc_survival_base", function(eventinfo) {
       update_npc_skills();
   });
   on("change:repeating_npcaction:attack_flag change:repeating_npcaction:attack_type change:repeating_npcaction:attack_range change:repeating_npcaction:attack_target change:repeating_npcaction:attack_tohit change:repeating_npcaction:attack_damage change:repeating_npcaction:attack_damagetype change:repeating_npcaction:attack_damage2 change:repeating_npcaction:attack_damagetype2 change:repeating_npcaction-l:attack_flag change:repeating_npcaction-l:attack_type change:repeating_npcaction-l:attack_range change:repeating_npcaction-l:attack_target change:repeating_npcaction-l:attack_tohit change:repeating_npcaction-l:attack_damage change:repeating_npcaction-l:attack_damagetype change:repeating_npcaction-l:attack_damage2 change:repeating_npcaction-l:attack_damagetype2 change:repeating_npcaction:show_desc change:repeating_npcaction-l:show_desc change:repeating_npcaction:description change:repeating_npcaction-l:description", function(eventinfo) {
       const actionid  = eventinfo.sourceAttribute.split("_")[2];
       const legendary = eventinfo.sourceAttribute.includes("npcaction-l") ? true : false;
       update_npc_action(actionid, legendary);
   });
   on("change:core_die change:halflingluck_flag", function() {
       getAttrs(["core_die","halflingluck_flag"], function(v) {
           core = v.core_die && v.core_die != "" ? v.core_die : "1d20";
           luck = v.halflingluck_flag && v.halflingluck_flag === "1" ? "ro<1" : "";
           update = {};
           update["d20"] = core + luck;
           if(!v.core_die || v.core_die === "") {
               update["core_die"] = "1d20";
           }
           setAttrs(update);
       });
   });
   [`ac`,`attack`,'save','skill',].forEach(attr => {
       on(`change:global_${attr}_mod_flag`, (eventinfo) => {
           const mod = (attr === "attack") ? "tohitmod" : `${attr}mod`;
           if(eventinfo.newValue === "1") {
               const firstAttr       = (attr === "ac")  ? "val" : "roll";
               const firstAttrValue  = (attr === "ac")  ? 1 : "1d4";
               const secondAttrValue = (attr === "ac")  ? "Defense" : (attr === "skill") ? "GUIDANCE" : "BLESS";
               getSectionIDs(mod, (ids) => {
                   if(!ids || ids.length === 0) {
                       var update = {};
                       var rowid = generateRowID();
                       update[`repeating_${mod}_${rowid}_global_${attr}_${firstAttr}`]= `${firstAttrValue}`;
                       update[`repeating_${mod}_${rowid}_global_${attr}_name`]        = `${secondAttrValue}`;
                       update[`repeating_${mod}_${rowid}_global_${attr}_active_flag`] = "1";
                       setAttrs(update);
                   }
               });
           } else {
               getSectionIDs(mod, function(ids) {
                   var update = {};
                   var rowid = generateRowID();
                   _.each(ids, function(rowid) {
                       update[`repeating_${mod}_${rowid}_global_${attr}_active_flag`] = "0";
                   });
                   setAttrs(update);
               });
           }
       });
   });
   on("change:repeating_skillmod remove:repeating_skillmod", function(eventinfo) {
       update_globalskills();
   });
   on("change:repeating_savemod remove:repeating_savemod", function(eventinfo) {
       update_globalsaves();
   });
   on("change:repeating_tohitmod remove:repeating_tohitmod", function(eventinfo) {
       update_globalattack();
   });
   on("change:repeating_acmod remove:repeating_acmod", function(eventinfo) {
       update_ac();
   });
   on("change:confirm", function(eventinfo) {
       setAttrs({monster_confirm_flag: ""});
       getAttrs(["drop_category"], function(v) {
           if(v["drop_category"]) {
               handle_drop(v["drop_category"]);
           }
       });
   });
   on("change:cancel", function(eventinfo) {
       setAttrs({monster_confirm_flag: ""});
       var update = {};
       update["drop_category"] = "";
       update["drop_name"] = "";
       update["drop_data"] = "";
       update["drop_content"] = "";
       setAttrs(update, {silent: true});
   });
   on("change:mancer_confirm", function(eventinfo) {
       setAttrs({mancer_confirm_flag: "", charactermancer_step: "l1-welcome"}, function() {
           check_l1_mancer();
       });
   });
   on("change:mancer_cancel", function(eventinfo) {
       setAttrs({mancer_confirm_flag: "", l1mancer_status: "completed"}, function() {
           check_l1_mancer();
       });
   });
   on("change:mancer_npc", function(eventinfo) {
       setAttrs({mancer_confirm_flag: "", l1mancer_status: "completed", npc: "1"}, function() {
           check_l1_mancer();
       });
   });
   on("change:passiveperceptionmod", function(eventinfo) {
       update_passive_perception();
   });
   on("remove:repeating_inventory", function(eventinfo) {
       var itemid = eventinfo.sourceAttribute.substring(20, 40);
       var attackids = eventinfo.removedInfo && eventinfo.removedInfo["repeating_inventory_" + itemid + "_itemattackid"] ? eventinfo.removedInfo["repeating_inventory_" + itemid + "_itemattackid"] : undefined;
       var resourceid = eventinfo.removedInfo && eventinfo.removedInfo["repeating_inventory_" + itemid + "_itemresourceid"] ? eventinfo.removedInfo["repeating_inventory_" + itemid + "_itemresourceid"] : undefined;
       if(attackids) {
           _.each(attackids.split(","), function(value) { remove_attack(value); });
       }
       if(resourceid) {
           remove_resource(resourceid);
       }
       if(eventinfo.removedInfo && eventinfo.removedInfo["repeating_inventory_" + itemid + "_itemmodifiers"]) {
           check_itemmodifiers(eventinfo.removedInfo["repeating_inventory_" + itemid + "_itemmodifiers"]);
       }
       update_weight();
   });
   on("remove:repeating_attack", function(eventinfo) {
       var attackid = eventinfo.sourceAttribute.substring(17, 37);
       var itemid = eventinfo.removedInfo["repeating_attack_" + attackid + "_itemid"];
       var spellid = eventinfo.removedInfo["repeating_attack_" + attackid + "_spellid"];
       var spelllvl = eventinfo.removedInfo["repeating_attack_" + attackid + "_spelllevel"];
       if(itemid) {
           getAttrs(["repeating_inventory_" + itemid + "_hasattack"], function(v) {
               if(v["repeating_inventory_" + itemid + "_hasattack"] && v["repeating_inventory_" + itemid + "_hasattack"] == 1) {
                   var update = {};
                   update["repeating_inventory_" + itemid + "_itemattackid"] = "";
                   update["repeating_inventory_" + itemid + "_hasattack"] = 0;
                   setAttrs(update, {silent: true});
               }
           });
       };
       if(spellid && spelllvl) {
           getAttrs(["repeating_spell-" + spelllvl + "_" + spellid + "_spelloutput"], function(v) {
               if(v["repeating_spell-" + spelllvl + "_" + spellid + "_spelloutput"] && v["repeating_spell-" + spelllvl + "_" + spellid + "_spelloutput"] == "ATTACK") {
                   var update = {};
                   update["repeating_spell-" + spelllvl + "_" + spellid + "_spellattackid"] = "";
                   update["repeating_spell-" + spelllvl + "_" + spellid + "_spelloutput"] = "SPELLCARD";
                   setAttrs(update, {silent: true});
               }
           });
       };
   });
   on("remove:repeating_resource", function(eventinfo) {
       const resourceid = eventinfo.sourceAttribute.substring(19, 39);
       let update       = {};
       _.each(['left','right'], (side) => {
           const itemid = eventinfo.removedInfo[`repeating_resource_${resourceid}_resource_${side}_itemid`];
           if (itemid) {
               update[`repeating_inventory_${itemid}_useasresource`] = 0;
               update[`repeating_inventory_${itemid}_itemresourceid`] = "";
           };
       });
       setAttrs(update, {silent: true});
   });
   on("remove:repeating_spell-cantrip remove:repeating_spell-1 remove:repeating_spell-2 remove:repeating_spell-3 remove:repeating_spell-4 remove:repeating_spell-5 remove:repeating_spell-6 remove:repeating_spell-7 remove:repeating_spell-8 remove:repeating_spell-9", function(eventinfo) {
       var attackid = eventinfo.removedInfo[eventinfo.sourceAttribute + "_spellattackid"];
       if(attackid) {
           remove_attack(attackid);
       }
   });
   on("clicked:relaunch_lvl1mancer", function(eventinfo) {
       getAttrs(["l1mancer_status"], function(v) {
           if(v["l1mancer_status"] === "completed") {
               setAttrs({l1mancer_status: "relaunch"});
           }
           check_l1_mancer();
       });
   });
   on("clicked:launch_lvl+mancer", function(eventinfo) {
       getAttrs(["class", "level", "hp_max", "custom_class","multiclass1_flag", "multiclass2_flag", "multiclass3_flag", "multiclass1", "multiclass2", "multiclass3"], function(v) {
           var throw_warning = false;
           var class_array = [v["class"]];
           if(!v["class"] || !v["hp_max"] || isNaN(parseInt(v["hp_max"], 10)) || !v["level"] || isNaN(parseInt(v["level"], 10)) || parseInt(v["level"], 10) < 1 || (v["multiclass2_flag"] == 1 && v["multiclass1_flag"] == 0) || (v["multiclass3_flag"] == 1 && v["multiclass2_flag"] == 0) ) {
               throw_warning = true;
           };
           if(v["multiclass1_flag"] == 1) {class_array.push(v["multiclass1"])};
           if(v["multiclass2_flag"] == 1) {class_array.push(v["multiclass2"])};
           if(v["multiclass3_flag"] == 1) {class_array.push(v["multiclass3"])};
           // Check to see if there are any duplicate multiclasses
           if((new Set(class_array)).size !== class_array.length) {
               throw_warning = true;
           };
           if(throw_warning === true) {
               setAttrs({leveler_warningflag: "show"});
               return;
           };
           setAttrs({lpmancer_status: "active"}, function() {
               startCharactermancer("lp-welcome");
           });
       });
   });
   on("change:experience", function(eventinfo) {
       update_leveler_display();
   });
   var update_attr = function(attr) {
       var update = {};
       var attr_fields = [attr + "_base",attr + "_bonus"];
       getSectionIDs("repeating_inventory", function(idarray) {
           _.each(idarray, function(currentID, i) {
               attr_fields.push("repeating_inventory_" + currentID + "_equipped");
               attr_fields.push("repeating_inventory_" + currentID + "_itemmodifiers");
           });
           getAttrs(attr_fields, function(v) {
               var base = v[attr + "_base"] && !isNaN(parseInt(v[attr + "_base"], 10)) ? parseInt(v[attr + "_base"], 10) : 10;
               var bonus = v[attr + "_bonus"] && !isNaN(parseInt(v[attr + "_bonus"], 10)) ? parseInt(v[attr + "_bonus"], 10) : 0;
               var item_base = 0;
               var item_bonus = 0;
               _.each(idarray, function(currentID) {
                   if((!v["repeating_inventory_" + currentID + "_equipped"] || v["repeating_inventory_" + currentID + "_equipped"] === "1") && v["repeating_inventory_" + currentID + "_itemmodifiers"] && v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().indexOf(attr > -1)) {
                       var mods = v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().split(",");
                       _.each(mods, function(mod) {
                           if(mod.indexOf(attr) > -1 && mod.indexOf("save") === -1) {
                               if(mod.indexOf(":") > -1) {
                                   var new_base = !isNaN(parseInt(mod.replace(/[^0-9]/g, ""), 10)) ? parseInt(mod.replace(/[^0-9]/g, ""), 10) : false;
                                   item_base = new_base && new_base > item_base ? new_base : item_base;
                               }
                               else if(mod.indexOf("-") > -1) {
                                   var new_mod = !isNaN(parseInt(mod.replace(/[^0-9]/g, ""), 10)) ? parseInt(mod.replace(/[^0-9]/g, ""), 10) : false;
                                   item_bonus = new_mod ? item_bonus - new_mod : item_bonus;
                               }
                               else {
                                   var new_mod = !isNaN(parseInt(mod.replace(/[^0-9]/g, ""), 10)) ? parseInt(mod.replace(/[^0-9]/g, ""), 10) : false;
                                   item_bonus = new_mod ? item_bonus + new_mod : item_bonus;
                               }
                           };
                       });
                   }
               });
               update[attr + "_flag"] = bonus > 0 || item_bonus > 0 || item_base > base ? 1 : 0;
               base = base > item_base ? base : item_base;
               update[attr] = base + bonus + item_bonus;
               setAttrs(update);
           });
       });
   };
   var update_mod = function (attr) {
       getAttrs([attr], function(v) {
           var attr_abr = attr.substring(0,3);
           var finalattr = v[attr] && isNaN(v[attr]) === false ? Math.floor((parseInt(v[attr], 10) - 10) / 2) : 0;
           var update = {};
           update[attr + "_mod"] = finalattr;
           update["npc_" + attr_abr + "_negative"] = v[attr] && !isNaN(v[attr]) && parseInt(v[attr], 10) < 10 ? 1 : 0;
           setAttrs(update);
       });
   };
   var update_save = function (attr) {
       var save_attrs = [attr + "_mod", attr + "_save_prof", attr + "_save_mod","pb","globalsavemod","pb_type"];
       getSectionIDs("repeating_inventory", function(idarray) {
           _.each(idarray, function(currentID, i) {
               save_attrs.push("repeating_inventory_" + currentID + "_equipped");
               save_attrs.push("repeating_inventory_" + currentID + "_itemmodifiers");
           });
           getAttrs(save_attrs, function(v) {
               var attr_mod = v[attr + "_mod"] ? parseInt(v[attr + "_mod"], 10) : 0;
               var prof = v[attr + "_save_prof"] && v[attr + "_save_prof"] != 0 && !isNaN(v["pb"]) ? parseInt(v["pb"], 10) : 0;
               var save_mod = v[attr + "_save_mod"] && !isNaN(parseInt(v[attr + "_save_mod"], 10)) ? parseInt(v[attr + "_save_mod"], 10) : 0;
               var global = v["globalsavemod"] && !isNaN(v["globalsavemod"]) ? parseInt(v["globalsavemod"], 10) : 0;
               var items = 0;
               _.each(idarray, function(currentID) {
                   if(v["repeating_inventory_" + currentID + "_equipped"] && v["repeating_inventory_" + currentID + "_equipped"] === "1" && v["repeating_inventory_" + currentID + "_itemmodifiers"] && (v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().indexOf("saving throws") > -1 || v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().indexOf(attr + " save") > -1)) {
                       var mods = v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().split(",");
                       _.each(mods, function(mod) {
                           if(mod.indexOf(attr + " save") > -1) {
                               var substr = mod.slice(mod.lastIndexOf(attr + " save") + attr.length + " save".length);
                               var bonus = substr && substr.length > 0 && !isNaN(parseInt(substr,10)) ? parseInt(substr,10) : 0;
                           }
                           else if(mod.indexOf("saving throws") > -1) {
                               var substr = mod.slice(mod.lastIndexOf("saving throws") + "saving throws".length);
                               var bonus = substr && substr.length > 0 && !isNaN(parseInt(substr,10)) ? parseInt(substr,10) : 0;
                           };
                           if(bonus && bonus != 0) {
                               items = items + bonus;
                           };
                       });
                   }
               });
               var total = attr_mod + prof + save_mod + global + items;
               if(v["pb_type"] && v["pb_type"] === "die" && v[attr + "_save_prof"] != 0 && attr != "death") {
                   total = total + "+" + v["pb"];
               };
               var update = {};
               update[attr + "_save_bonus"] = total;
               setAttrs(update, {silent: true});
           });
       });
   };
   var update_all_saves = function() {
       update_save("strength");
       update_save("dexterity");
       update_save("constitution");
       update_save("intelligence");
       update_save("wisdom");
       update_save("charisma");
       update_save("death");
   };
   var update_all_ability_checks = function(){
       update_initiative();
       update_skills(["athletics", "acrobatics", "sleight_of_hand", "stealth", "arcana", "history", "investigation", "nature", "religion", "animal_handling", "insight", "medicine", "perception", "survival","deception", "intimidation", "performance", "persuasion"]);
   };
   var update_skills = function (skills_array) {
       var skill_parent = {athletics: "strength", acrobatics: "dexterity", sleight_of_hand: "dexterity", stealth: "dexterity", arcana: "intelligence", history: "intelligence", investigation: "intelligence", nature: "intelligence", religion: "intelligence", animal_handling: "wisdom", insight: "wisdom", medicine: "wisdom", perception: "wisdom", survival: "wisdom", deception: "charisma", intimidation: "charisma", performance: "charisma", persuasion: "charisma"};
       var attrs_to_get = ["pb","pb_type","jack_of_all_trades","jack"];
       var update = {};
       var callbacks = [];
       if(skills_array.indexOf("perception") > -1) {
           callbacks.push( function() {update_passive_perception();} )
       };
       _.each(skills_array, function(s) {
           if(skill_parent[s] && attrs_to_get.indexOf(skill_parent[s]) === -1) {attrs_to_get.push(skill_parent[s] + "_mod")};
           attrs_to_get.push(s + "_prof");
           attrs_to_get.push(s + "_type");
           attrs_to_get.push(s + "_flat");
       });
       getSectionIDs("repeating_inventory", function(idarray) {
           _.each(idarray, function(currentID, i) {
               attrs_to_get.push("repeating_inventory_" + currentID + "_equipped");
               attrs_to_get.push("repeating_inventory_" + currentID + "_itemmodifiers");
           });
           getAttrs(attrs_to_get, function(v) {
               console.log("UPDATING SKILLS");
               _.each(skills_array, function(s) {
                   var attr_mod = v[skill_parent[s] + "_mod"] ? parseInt(v[skill_parent[s] + "_mod"], 10) : 0;
                   var prof = v[s + "_prof"] != 0 && !isNaN(v["pb"]) ? parseInt(v["pb"], 10) : 0;
                   var flat = v[s + "_flat"] && !isNaN(parseInt(v[s + "_flat"], 10)) ? parseInt(v[s + "_flat"], 10) : 0;
                   var type = v[s + "_type"] && !isNaN(parseInt(v[s + "_type"], 10)) ? parseInt(v[s + "_type"], 10) : 1;
                   var jack = v["jack_of_all_trades"] && v["jack_of_all_trades"] != 0 && v["jack"] ? v["jack"] : 0;
                   var item_bonus = 0;
                   _.each(idarray, function(currentID) {
                       if(v["repeating_inventory_" + currentID + "_equipped"] && v["repeating_inventory_" + currentID + "_equipped"] === "1" && v["repeating_inventory_" + currentID + "_itemmodifiers"] && (v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().replace(/ /g,"_").indexOf(s) > -1 || v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().indexOf("ability checks") > -1)) {
                           var mods = v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().split(",");
                           _.each(mods, function(mod) {
                               if(mod.replace(/ /g,"_").indexOf(s) > -1 || mod.indexOf("ability checks") > -1) {
                                   if(mod.indexOf("-") > -1) {
                                       var new_mod = !isNaN(parseInt(mod.replace(/[^0-9]/g, ""), 10)) ? parseInt(mod.replace(/[^0-9]/g, ""), 10) : false;
                                       item_bonus = new_mod ? item_bonus - new_mod : item_bonus;
                                   }
                                   else {
                                       var new_mod = !isNaN(parseInt(mod.replace(/[^0-9]/g, ""), 10)) ? parseInt(mod.replace(/[^0-9]/g, ""), 10) : false;
                                       item_bonus = new_mod ? item_bonus + new_mod : item_bonus;
                                   }
                               };
                           });
                       };
                   });
                   var total = attr_mod + flat + item_bonus;
                   if(v["pb_type"] && v["pb_type"] === "die") {
                       if(v[s + "_prof"] != 0) {
                           type === 1 ? "" : "2"
                           total = total + "+" + type + v["pb"];
                       }
                       else if(v[s + "_prof"] == 0 && jack != 0) {
                           total = total + "+" + jack;
                       };
                   }
                   else {
                       if(v[s + "_prof"] != 0) {
                           total = total + (prof * type);
                       }
                       else if(v[s + "_prof"] == 0 && jack != 0) {
                           total = total + parseInt(jack, 10);
                       };
                   };
                   update[s + "_bonus"] = total;
               });
               setAttrs(update, {silent: true}, function() {callbacks.forEach(function(callback) {callback(); })} );
           });
       });
   };
   var update_tool = function(tool_id) {
       //D&D 5e Mancer: Land Vehicles proficiency does not drop with Marine background (UC748)
       //Added a test to check for an undefined tool_id so to prevent similar errors.
       //By Miguel Peres
       if(typeof tool_id == "undefined") return;
       if(tool_id.substring(0,1) === "-" && tool_id.length === 20) {
           do_update_tool([tool_id]);
       }
       else if(tool_id === "all") {
           getSectionIDs("repeating_tool", function(idarray) {
               do_update_tool(idarray);
           });
       }
       else {
           getSectionIDs("repeating_tool", function(idarray) {
               var tool_attribs = [];
               _.each(idarray, function(id) {
                   tool_attribs.push("repeating_tool_" + id + "_toolattr_base");
               });
               getAttrs(tool_attribs, function(v) {
                   var attr_tool_ids = [];
                   _.each(idarray, function(id) {
                       if(v["repeating_tool_" + id + "_toolattr_base"] && v["repeating_tool_" + id + "_toolattr_base"].indexOf(tool_id) > -1) {
                           attr_tool_ids.push(id);
                       }
                   });
                   if(attr_tool_ids.length > 0) {
                       do_update_tool(attr_tool_ids);
                   }
               });
           });
       };
   };
   var do_update_tool = function(tool_array) {
       var tool_attribs = ["pb","pb_type","jack","strength_mod","dexterity_mod","constitution_mod","intelligence_mod","wisdom_mod","charisma_mod"];
       var update = {};
       _.each(tool_array, function(tool_id) {
           tool_attribs.push("repeating_tool_" + tool_id + "_toolbonus_base");
           tool_attribs.push("repeating_tool_" + tool_id + "_tool_mod");
           tool_attribs.push("repeating_tool_" + tool_id + "_toolattr_base");
       });
       getAttrs(tool_attribs, function(v) {
           _.each(tool_array, function(tool_id) {
               console.log("UPDATING TOOL: " + tool_id);
               var query = false;
               if(v["repeating_tool_" + tool_id + "_toolattr_base"] && v["repeating_tool_" + tool_id + "_toolattr_base"].substring(0,2) === "?{") {
                   update["repeating_tool_" + tool_id + "_toolattr"] = "QUERY";
                   var mod = "?{Attribute?|Strength,@{strength_mod}|Dexterity,@{dexterity_mod}|Constitution,@{constitution_mod}|Intelligence,@{intelligence_mod}|Wisdom,@{wisdom_mod}|Charisma,@{charisma_mod}}";
                   if(v["repeating_tool_" + tool_id + "_tool_mod"]) {
                       mod = mod + "+" + v["repeating_tool_" + tool_id + "_tool_mod"];
                   }
                   query = true;
               } else {
                   var attr = v["repeating_tool_" + tool_id + "_toolattr_base"].substring(0, v["repeating_tool_" + tool_id + "_toolattr_base"].length - 5).substr(2);
                   var attr_mod = v[attr + "_mod"] ? parseInt(v[attr + "_mod"], 10) : 0;
                   var tool_mod = v["repeating_tool_" + tool_id + "_tool_mod"] && !isNaN(parseInt(v["repeating_tool_" + tool_id + "_tool_mod"], 10)) ? parseInt(v["repeating_tool_" + tool_id + "_tool_mod"], 10) : 0;
                   var mod = attr_mod + tool_mod;
                   update["repeating_tool_" + tool_id + "_toolattr"] = attr.toUpperCase();
                   if(v["repeating_tool_" + tool_id + "_tool_mod"] && v["repeating_tool_" + tool_id + "_tool_mod"].indexOf("@{") > -1) {
                       update["repeating_tool_" + tool_id + "_toolbonus"] = update["repeating_tool_" + tool_id + "_toolbonus"] + "+" + v["repeating_tool_" + tool_id + "_tool_mod"];
                   }
                   if(!v["repeating_tool_" + tool_id + "_tool_mod"]) {
                       update["repeating_tool_" + tool_id + "_tool_mod"] = 0;
                   }
               };
               if(v["pb_type"] && v["pb_type"] === "die" ) {
                   if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(@{pb})") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + "+" + v.pb}
                   else if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(@{pb}*2)") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + "+2" + v.pb}
                   else if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(floor(@{pb}/2))") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + "+" + v.jack};
               }
               else if(v["repeating_tool_" + tool_id + "_toolattr_base"] && v["repeating_tool_" + tool_id + "_toolattr_base"].substring(0,2) === "?{") {
                   if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(@{pb})") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + "+" + parseInt(v.pb, 10)}
                   else if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(@{pb}*2)") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + "+" + (parseInt(v.pb, 10)*2)}
                   else if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(floor(@{pb}/2))") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + "+" + parseInt(v.jack, 10)};
               }
               else {
                   if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(@{pb})") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + parseInt(v.pb, 10)}
                   else if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(@{pb}*2)") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + (parseInt(v.pb, 10)*2)}
                   else if(v["repeating_tool_" + tool_id + "_toolbonus_base"] === "(floor(@{pb}/2))") {update["repeating_tool_" + tool_id + "_toolbonus"] = mod + parseInt(v.jack, 10)};
               };
               if(query) {
                   update["repeating_tool_" + tool_id + "_toolbonus_display"] = "?";
               }
               else {
                   update["repeating_tool_" + tool_id + "_toolbonus_display"] = update["repeating_tool_" + tool_id + "_toolbonus"];
               };
           });
           setAttrs(update, {silent: true});
       });
   };
   var get_repeating_data = function(callback) {
       var getallrepeating = function(getobj, thiscallback, attrlist) {
           attrlist = attrlist || [];
           var thisget = getobj.pop();
           getSectionIDs(thisget.name, function(ids) {
               _.each(ids, function(sectionId) {
                   _.each(thisget.list, function(attr) {
                       attrlist.push("repeating_" + thisget.name + "_" + sectionId + "_" + attr);
                   });
               });
               if(getobj.length > 0) {
                   getallrepeating(getobj, thiscallback, attrlist);
               } else {
                   getAttrs(attrlist, function(vals) {
                       thiscallback(vals);
                   });
               };
           });
       };
       var getList = [
           {name: "proficiencies", list: ["name"]},
           {name: "tool", list: ["toolname", "toolattr_base"]},
           {name: "traits", list: ["name", "source", "source_type"]},
           {name: "resource", list: ["resource_left_name", "resource_right_name"]},
           {name: "spell-cantrip", list: ["spellname", "spellattackid", "spellsource", "spellattackid"]},
           {name: "savemod", list: ["global_save_name"]},
           {name: "tohitmod", list: ["global_attack_name"]},
           {name: "damagemod", list: ["global_damage_name"]},
           {name: "acmod", list: ["global_ac_name"]},
           {name: "skillmod", list: ["global_skill_name"]},
           {name: "attack", list: ["atkname", "spellid"]},
           {name: "hpmod", list: ["levels", "source", "mod"]}
       ];
       for(var x=1; x<=9; x++) {
           getList.push({ name: "spell-" + x, list: ["spellname", "spellattackid", "spellsource", "spellattackid"] });
       }
       var repeating = {prof_names: [], traits: []};
       _.each(getList, function(section) {
           if(!["proficiencies", "traits"].includes(section.name)) {
               repeating[section.name] = {};
           }
       });
       getallrepeating(getList, function(vals) {
           var traitstemp = {};
           _.each(vals, function(value, name) {
               if(name.split("_")[1] == "proficiencies") {
                   repeating.prof_names.push(value.toLowerCase());
               } else if(name.split("_")[1] == "tool") {
                   repeating.tool[name.split("_")[2]] = repeating.tool[name.split("_")[2]] || {};
                   let attr = _.last(name.split("_"));
                   repeating.tool[name.split("_")[2]][attr] = value.toLowerCase();
                   if(attr == "toolname") repeating.prof_names.push(value.toLowerCase());
               } else if (name.split("_")[1] == "traits") {
                   traitstemp[name.split("_")[2]] = traitstemp[name.split("_")[2]] ? traitstemp[name.split("_")[2]] : {};
                   traitstemp[name.split("_")[2]][_.last(name.split("_"))] = value;
               } else if (name.split("_")[1] == "resource") {
                   repeating.resource[name.split("_")[2]] = repeating.resource[name.split("_")[2]] || {};
                   repeating.resource[name.split("_")[2]][name.split("_")[4]] = value;
               } else if (name.split("_")[1] == "hpmod") {
                   repeating.hpmod[name.split("_")[2]] = repeating.hpmod[name.split("_")[2]] || {};
                   repeating.hpmod[name.split("_")[2]][name.split("_")[3]] = value;
               } else if (name.split("_")[1].split("-")[0] == "spell") {
                   repeating[name.split("_")[1]][name.split("_")[2]] = repeating[name.split("_")[1]][name.split("_")[2]] || {};
                   repeating[name.split("_")[1]][name.split("_")[2]][name.split("_")[3]] = value;
               } else if (name.split("_")[1] == "attack") {
                   repeating[name.split("_")[1]][name.split("_")[2]] = repeating[name.split("_")[1]][name.split("_")[2]] || {};
                   repeating[name.split("_")[1]][name.split("_")[2]][name.split("_")[3]] = value;
               } else {
                   repeating[name.split("_")[1]][name.split("_")[2]] = value;
               }
           });
           _.each(traitstemp, function(v, k) {
               var trait = _.clone(v);
               trait.id = k;
               repeating.traits.push(trait);
           });
           callback(repeating);
       });
   };
   var handle_drop = function(category, eventinfo) {
       getAttrs(["speed", "drop_name", "drop_data", "drop_content", "character_id", "npc_legendary_actions", "strength_mod", "dexterity_mod", "npc", "base_level", "strength_base", "dexterity_base", "constitution_base", "wisdom_base", "intelligence_base", "charisma_base", "class_resource_name", "other_resource_name", "multiclass1_lvl", "multiclass2_lvl", "multiclass3_lvl"], function(v) {
           var pagedata = {};
           try {
               pagedata = JSON.parse(v.drop_data);
           } catch(e) {
               pagedata = v.drop_data;
           }
           var page = {
               name: v.drop_name,
               data: pagedata,
               content: v.drop_content
           };
           var category = page.data["Category"];
           get_repeating_data(function(repeating) {
               var results = processDrop(page, v, repeating);
               setAttrs(results.update, {silent: true}, function() {results.callbacks.forEach(function(callback) {callback(); })} );
           });
       });
   };
   var processDrop = function(page, currentData, repeating, looped) {
       var jsonparse = function(data) {
           var result = {};
           try {
               result = JSON.parse(data);
           } catch(e) {
               result = data;
           }
           return result;
       };
       var modStringToAttrib = function(modString) {
           var finalAttrib = "";
           if (modString == "FIN") {
               if (parseInt(currentData.strength_base) > parseInt(currentData.dexterity_base)) {
                   finalAttrib = "@{strength_mod}";
               } else {
                   finalAttrib = "@{dexterity_mod}";
               }
           } else {
               switch(modString) {
                   case "STR":
                       finalAttrib = "@{strength_mod}";
                       break;
                   case "DEX":
                       finalAttrib = "@{dexterity_mod}";
                       break;
                   case "CON":
                       finalAttrib = "@{constitution_mod}";
                       break;
                   case "WIS":
                       finalAttrib = "@{wisdom_mod}";
                       break;
                   case "INT":
                       finalAttrib = "@{intelligence_mod}";
                       break;
                   case "CHA":
                       finalAttrib = "@{charisma_mod}";
                       break;
               }
           }
           return finalAttrib;
       };
       var numUses = function(uses_string) {
           uses_string = parseValues(uses_string);
           var terms = uses_string.split("+");
           var total = 0;
           _.each(terms, function(term) {
               total += parseInt(term);
           });
           return uses_string === "" || uses_string === "-" ? uses_string : total;
       };
       var parseValues = function(uses_string) {
           var attribs = ["strength", "dexterity", "constitution", "wisdom", "intelligence", "charisma"];
           uses_string = uses_string ? uses_string.toLowerCase() : "";
           _.each(attribs, function(attrib) {
               var attribMod = Math.floor((parseInt(currentData[attrib + "_base"]) - 10) / 2);
               if (attribMod < 0 || isNaN(attribMod)) attribMod = 0;
               uses_string = uses_string.replace(attrib, attribMod);
           });
           uses_string = uses_string.replace(/half_level/g, Math.floor(classlevel/2));
           return uses_string.replace(/level/g, classlevel);
       };//
       var category = page.data["Category"];
       var callbacks = [];
       var update = {};
       var id = generateRowID();
       var blobs = {};
       var classlevel = currentData.base_level ? parseInt(currentData.base_level) : 1;
       repeating.traits = repeating.traits ? repeating.traits : [];
       update["drop_category"] = "";
       update["drop_name"] = "";
       update["drop_data"] = "";
       update["drop_content"] = "";
       if(category === "Items") {
           console.log(`%c ITEM: ${page.name} dropped`, "color: purple; font-size: 14px;");
           if(currentData.npc === "0") {
               update["tab"] = "core";
               if(page.name) {update[`repeating_inventory_${id}_itemname`]               = page.name};
               if(page.data["itemcount"]) {update[`repeating_inventory_${id}_itemcount`] = page.data["itemcount"]};
               ["Properties", "Weight"].forEach((attr) => {
                   if (page.data[`${attr}`]) {
                       update[`repeating_inventory_${id}_item${attr.toLowerCase()}`] = page.data[`${attr}`]
                   };
               });
               if(page.content) {update[`repeating_inventory_${id}_itemcontent`] = page.content};
               if(!page.data["Item Type"] || page.data["Item Type"] == "") {page.data["Item Type"] = category};
               var mods = "Item Type: " + page.data["Item Type"];
               if(page.data["AC"] && page.data["AC"] != "") {
                   mods += ", AC: " + page.data["AC"];
                   if(!looped) {
                       callbacks.push(() => {update_ac();} )
                   }
               };
               ["Damage", "Damage Type", "Secondary Damage", "Secondary Damage Type", "Alternate Damage", "Alternate Damage Type", "Alternate Secondary Damage", "Alternate Secondary Damage Type", "Range"].forEach((attr) => {
                   if (page.data[`${attr}`] && page.data[`${attr}`] != "") {
                       mods += `, ${attr}: ${page.data[`${attr}`]}`
                   };
               });
               if(page.data["Modifiers"] && page.data["Modifiers"] != "") { mods += `, ${page.data["Modifiers"]}` };
               update[`repeating_inventory_${id}_itemmodifiers`] = mods;
               if(page.data["Item Type"].indexOf("Weapon") > -1) {
                   update[`repeating_inventory_${id}_hasattack`] = 1;
                   callbacks.push(() => {
                       (page.data["Alternate Damage"] && page.data["Alternate Damage"] !== "") ? create_attack_from_item(id, {versatile: true}) : create_attack_from_item(id);
                   });
               } else if(page.data["Item Type"].indexOf("Ammunition") > -1) {
                   update[`repeating_inventory_${id}_useasresource`] = 1;
                   callbacks.push(() => { create_resource_from_item(id); });
               };
               if(page.data["Modifiers"]) {
                   callbacks.push(() => { check_itemmodifiers(page.data["Modifiers"]); });
               };
               if(!looped) {
                   callbacks.push(() => { update_weight(); });
               }
           } else {
               if(page.data["Item Type"] && page.data["Item Type"].toLowerCase().includes("weapon")) {
                   const type       = (page.data["Item Type"]) ? page.data["Item Type"].toLowerCase().split(" ")[0] : " ";
                   const properties = (page.data["Properties"]) ? page.data["Properties"].toLowerCase() : undefined;
                   const make_npc_attack_from_item = (rowid, options) => {
                       update[`repeating_npcaction_${rowid}_npc_options-flag`] = "0";
                       update[`repeating_npcaction_${rowid}_attack_flag`]      = "on";
                       if(page.name) {
                           update[`repeating_npcaction_${rowid}_name`] = page.name;
                           if (options && options.versatile) {
                               update[`repeating_npcaction_${rowid}_name`] += " (" + (options.versatile === 1 ? "One-Handed" : "Two-Handed") + ")";
                           } else if (options && options.thrown) {
                               update[`repeating_npcaction_${rowid}_name`] += " (Thrown)";
                           };
                       };
                       if(page.content) { update[`repeating_npcaction_${rowid}_description`] = page.content; }
                       update[`repeating_npcaction_${rowid}_attack_display_flag`] = "Template:Attack=1";
                       update[`repeating_npcaction_${rowid}_attack_options`]      = "Template:Attack=1";
                       update[`repeating_npcaction_${rowid}_attack_type`]         = page.data["Item Type"];
                       update[`repeating_npcaction_${rowid}_attack_target`]       = "one target";


                       update[`repeating_npcaction_${rowid}_attack_range`] =
                           (page.data["Range"] && page.data["Range"] != "" && (!properties.includes("thrown") || (options && options.thrown))) ? page.data["Range"] :
                           (page.data["Properties"] && properties.includes("range")) ? "10 ft" :
                           "5 ft";
                       const weapon_attr_mod = (type.includes("ranged") || (properties && properties.includes("finesse") && currentData.dexterity_mod > currentData.strength_mod)) ? currentData.dexterity_mod : currentData.strength_mod;
                       update[`repeating_npcaction_${rowid}_attack_tohit`] = weapon_attr_mod;
                       const dmgArray = (options && options.versatile === 2) ?
                           ["Alternate Damage", "Alternate Damage Type", "Alternate Secondary Damage", "Alternate Secondary Damage Type"] :
                           ["Damage", "Damage Type", "Secondary Damage", "Secondary Damage Type"];
                       dmgArray.forEach((attr) => {
                           if (page.data[`${attr}`]) {
                               // _attack_damage adds the weapon mod
                               const ending = (dmgArray.indexOf(`${attr}`) === 0) ? `+${weapon_attr_mod}` : "";
                               //Remove Alternate for the attribute name. Then check for Secondary and remote it while adding 2.
                               let attrEdit = (attr.includes("Alternate") && attr.includes("Secondary")) ? attr.slice(20) + "2" : (attr.includes("Alternate") || attr.includes("Secondary")) ? attr.slice(10) : attr;
                               //Lower case everything and remove spaces
                               let name = attrEdit.toLowerCase().replace(" ", "");
                               //Set all the necessary attack attributes
                               update[`repeating_npcaction_${rowid}_attack_${name}`] = page.data[`${attr}`] + [`${ending}`];
                           };
                       });
                       if(page.data["Modifiers"]) {
                           if(type === "melee" || type === "ranged") {
                               //+1 Weapons should be in the format of "Melee Attacks +1, Melee Damage +1"
                               const split = (page.data["Modifiers"].includes(",")) ? page.data["Modifiers"].split(", ") : page.data["Modifiers"];
                               split.forEach((attr) => {
                                   const name = attr.toLowerCase();
                                   if (name.includes("attacks")) {
                                       update[`repeating_npcaction_${rowid}_attack_tohit`] = +update[`repeating_npcaction_${rowid}_attack_tohit`] + name.split("attacks ")[1];
                                   } else if (name.includes("damage")) {
                                       update[`repeating_npcaction_${rowid}_attack_damage`] += name.split("damage ")[1];
                                   } else {
                                       console.log(`%c ${page.name} modifiers format did not include damage or attacks`, "color:orange;");
                                   };
                               });
                           };
                       };
                   };
                   const versatile = (properties && properties.includes("versatile")) ? 1 : undefined;
                   make_npc_attack_from_item(id, {versatile: versatile});
                   if (properties && properties.includes("thrown")) {
                      make_npc_attack_from_item(generateRowID(), {thrown: true});
                   }
                   if (versatile && page.data["Alternate Damage"]) {
                       make_npc_attack_from_item(generateRowID(), {versatile: 2})
                   }
                   if (page.data["Modifiers"]) {
                       callbacks.push(() => { check_itemmodifiers(page.data["Modifiers"]);  }, () => { update_npc_action("all"); });
                   } else {
                       callbacks.push(() => { update_npc_action("all"); });
                   };
               }
           }
       };
       if(category === "Spells") {
           console.log(`%c SPELL: ${page.name} dropped`, "color: purple; font-weight:14px;");
           let existing = {};
           var lvl = page.data["Level"] && page.data["Level"] > 0 ? page.data["Level"] : "cantrip";
           if (repeating[`spell-${lvl}`]) {
               _.each(repeating[`spell-${lvl}`], (spell, spellid) => {
                   if (spell.spellname.toLowerCase() === page.name.toLowerCase()) {
                       id       = spellid;
                       existing = spell;
                   };
               });
           }
           update[`repeating_spell-${lvl}_${id}_spelllevel`] = lvl;
           update[`repeating_spell-${lvl}_${id}_spell_ability`] = (page.data["spellcasting_ability"]) ? `@{${page.data["spellcasting_ability"].toLowerCase()}_mod}+` : "spell";
           (page.name) ? update[`repeating_spell-${lvl}_${id}_spellname`] = page.name : false;
           ["spellclass", "spellsource", "data-description"].forEach((attr) => {
               const suffix = (attr.includes("description")) ? "spelldescription" : attr;
               (page.data[`${attr}`]) ? update[`repeating_spell-${lvl}_${id}_${suffix}`] = page.data[`${attr}`] : false;
           });
          ["Add Casting Modifier", "Casting Time", "Concentration", "Damage Type", "Damage", "Duration", "Healing", "Material", "Range", "Ritual", "Save", "Save Success", "School", "Secondary Damage", "Secondary Damage Type", "Target"].forEach((attr) => {
               if(page.data[`${attr}`]) {
                   //Adjust the array entry to match the attribute name in the HTML
                   const name           = (attr === "Add Casting Modifier") ? "dmgmod" : (attr === "Material") ? `comp_materials` : (attr.includes("Secondary Damage")) ? attr.split("Secondary ")[0] + "2" : attr;
                   const spellattribute = name.toLowerCase().replace(" ", "");
                   //Concentration, Ritual, and School are exceptions to norm
                   const updateValue = (attr === "Concentration" || attr === "Ritual") ? `{{${spellattribute}=1}}` : (attr === "School") ? page.data["School"].toLowerCase() : page.data[`${attr}`];
                   update[`repeating_spell-${lvl}_${id}_spell${spellattribute}`] = updateValue;
               };
           });
          ["Higher Spell Slot Bonus", "Higher Spell Slot Desc", "Higher Spell Slot Dice", "Higher Spell Slot Die"].forEach((attr) => {
               if (page.data[`${attr}`]) {
                   const spellattribute = (attr.includes("Bonus")) ? "hlbonus" : (attr.includes("Desc")) ? "athigherlevels" : (attr.includes("Dice")) ? "hldie" : "hldietype";
                   update[`repeating_spell-${lvl}_${id}_spell${spellattribute}`] = page.data[`${attr}`];
               };
           });
           if(page.data["Components"]) {
               ["v", "s", "m"].forEach((comp) => {
                   if(page.data["Components"].toLowerCase().indexOf(comp) === -1) {update[`repeating_spell-${lvl}_${id}_spellcomp_${comp}`] = "0"};
               });
           };
           if (page.data["Spell Attack"]) {
               update[`repeating_spell-${lvl}_${id}_spellattack`] = page.data[`Spell Attack`];
           };
           if(page.data["Damage"] || page.data["Healing"]) {
               update["repeating_spell-" + lvl + "_" + id + "_spelloutput"] = "ATTACK";
               if(!existing.spellattackid) callbacks.push( function() {create_attack_from_spell(lvl, id, currentData.character_id);});
           }
           else if(page.data["Higher Spell Slot Desc"] && page.data["Higher Spell Slot Desc"] != "") {
               var spelllevel = "?{Cast at what level?";
               for(i = 0; i < 10-lvl; i++) {
                   spelllevel = spelllevel + "|Level " + (parseInt(i, 10) + parseInt(lvl, 10)) + "," + (parseInt(i, 10) + parseInt(lvl, 10));
               };
               spelllevel = spelllevel + "}";
               update[`repeating_spell-${lvl}_${id}_rollcontent`] = `@{wtype}&{template:spell} {{level=@{spellschool} ${spelllevel}}} {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
           };
           if(page.data["data-Cantrip Scaling"] && lvl == "cantrip") {update[`repeating_spell-${lvl}_${id}_spell_damage_progression`] = "Cantrip " + page.data["data-Cantrip Scaling"].charAt(0).toUpperCase() + page.data["data-Cantrip Scaling"].slice(1);};
           update[`repeating_spell-${lvl}_${id}_options-flag`] = "0";
       };
       if(category === "Monsters") {
           console.log(`%c MONSTERS: ${page.name} dropped`, "color: purple; font-weight:14px;");
           update["npc"] = "1";
           update["npc_options-flag"] = "0";
           update["licensedsheet"] = "1";
           if(page.name && page.name != "") {update["npc_name"] = page.name};
           //ABILITY SCORES
           const npcAbilites = ["strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"];
           npcAbilites.forEach((ability) => {
               const abbreviation = ability.slice(0, 3).toUpperCase();
               update[`${ability}_base`] = (page.data[`${abbreviation}`]) ? page.data[`${abbreviation}`] : "";
               callbacks.push(() => {
                   update_attr(`${ability}`);
               });
           });
           const npcExtras = ["Condition Immunities", "Immunities", "Languages", "Resistances", "Speed", "Token Size", "Vulnerabilities"];
           npcExtras.forEach((attr) => {
               //console.log(`%c MONSTERS Drop: ${attr}`, "color:cornflowerblue;");
               const prefixExtra = (attr === "Token Size") ? "" : "npc_";
               let nameExtra     = (attr.includes(" ")) ? attr.replace(" ", "_").toLowerCase() : attr.toLowerCase();
               update[`${prefixExtra}${nameExtra}`] = (page.data[`${attr}`]) ? page.data[`${attr}`] : "";
           });
           //CHALLENGE RATING
           if(page.data["Challenge Rating"] && page.data["Challenge Rating"] != "") {
               callbacks.push( function() {update_challenge();} );
               update["npc_challenge"] = page.data["Challenge Rating"];
           } else {
               update["npc_challenge"] = "";
           };
           //XP
           if(page.data["data-XP"]) { update["npc_xp"] = page.data["data-XP"].toString().replace(",","");  };
           //SIZE, TYPE, ALIGNMENT
           var type = "";
           if(page.data["Size"]) {      type = page.data["Size"] };
           if(page.data["Type"]) {      type = (type.length > 0) ? type + " " + page.data["Type"].toLowerCase() : page.data["Type"].toLowerCase(); };
           if(page.data["Alignment"]) { type = (type.length > 0) ? type + ", " + page.data["Alignment"] : page.data["Alignment"]; };
           update["npc_type"] = type;
           ["AC", "HP"].forEach((achp) => {
               //console.log(`%c MONSTERS Drop: AC & HP ${achp}`, "color:cornflowerblue;");
               const array = (achp === "AC") ? ["npc_ac", "npc_actype"] : ["hp_max", "npc_hpformula"];
               if (page.data[`${achp}`] && page.data[`${achp}`].toString().indexOf("(") > -1)  {
                   update[`${array[0]}`] = page.data[`${achp}`].toString().split(" (")[0];
                   update[`${array[1]}`] = page.data[`${achp}`].toString().split(" (")[1].slice(0, -1);
               } else {
                   update[`${array[0]}`] = (page.data[`${achp}`]) ? page.data[`${achp}`] : "";
                   update[`${array[1]}`] = "";
               };
           });
           var senses = page.data["Senses"] ? page.data["Senses"] : "";
           if(page.data["Passive Perception"]) {
               senses = (senses.length > 0) ? senses + ", passive Perception " + page.data["Passive Perception"] : "passive Perception " + page.data["Passive Perception"];
           }
           update["npc_senses"] = senses;
           //SAVES & SKILLS
           const npcSavesSkills = ["str_save", "dex_save", "con_save", "int_save", "wis_save", "cha_save",'acrobatics','animal_handling','arcana','athletics','deception','history','insight','intimidation','investigation','medicine','nature','perception','performance','persuasion','religion','sleight_of_hand','stealth','survival'];
           npcSavesSkills.forEach((attr) => {
               update[`npc_${attr}_base`] = "";
           });
           ["Saving Throws", "Skills"].forEach((attr) => {
               //console.log(`%c MONSTERS Drop: Saving Throws & Skills: ${attr}`, "color:cornflowerblue;");
               const array = (page.data[`${attr}`]) ? page.data[`${attr}`].split(", ") : [];
               _.each(array, (entry) => {
                   const kv        = (entry.indexOf("-") > -1) ? entry.split(" ") : entry.split(" +");
                   const attribute = (attr === "Saving Throws") ? kv[0].toLowerCase() + "_save" : kv[0].toLowerCase().split(' ').join('_');
                   update[`npc_${attribute}_base`] = parseInt(kv[1], 10);
               });
               (attr === "Saving Throws") ? callbacks.push(() => {update_npc_saves();} ) : callbacks.push(() => {update_npc_skills();} );
           });
           const npcRepeating = ['npcaction-l', 'npcreaction', 'npcaction', 'npctrait'];
           _.each(npcRepeating, (section) => {
               getSectionIDs(`repeating_${section}`, (idarray) => {
                   _.each(idarray, (currentID, i) => {
                       removeRepeatingRow(`repeating_${section}_${currentID}`);
                   });
               });
           });
           // ACTIONS, LEGENDARY ACTIONS, REACTIONS, TRAITS
           var contentarray = page.content;
           if (page.data["data-Legendary Actions"]) {
               const actionCount = (page.data["data-LANum"]) ? page.data["data-LANum"] : 3;
               update["npc_legendary_actions"] = (page.data["data-LANum"]) ? page.data["data-LANum"] : 3;
               if (page.data["Legendary Actions Desc"]) {
                   update["npc_legendary_actions_desc"] = page.data["Legendary Actions Desc"];
               } else {
                   update["npc_legendary_actions_desc"] = `The ${page.name} can take ${actionCount}, choosing from the options below. Only one legendary option can be used at a time and only at the end of another creature's turn. The ${page.name} regains spent legendary actions at the start of its turn.`;
               };
           };
           // ACTIONS & LEGENDARY ACTIONS
           ["Actions", "Legendary Actions"].forEach((attr) => {
               if (page.data[`data-${attr}`]) {
                   const npcaction = (attr === "Actions") ? "npcaction" : "npcaction-l";
                   let actionsobj = {};
                   jsonparse(page.data[`data-${attr}`]).forEach((val) => { actionsobj[val.Name] = val; });
                   _.each(actionsobj, (action, name) => {
                       newrowid = generateRowID();
                       update[`repeating_${npcaction}_${newrowid}_npc_options-flag`] = "0";
                       update[`repeating_${npcaction}_${newrowid}_name`]             = name;
                       (action["Desc"]) ? update[`repeating_${npcaction}_${newrowid}_description`] = action["Desc"] : false;
                       if(action["Type Attack"]) {
                           update[`repeating_${npcaction}_${newrowid}_attack_display_flag`] = "Template:Attack=1";
                           update[`repeating_${npcaction}_${newrowid}_attack_flag`]         = "on";
                           update[`repeating_${npcaction}_${newrowid}_attack_options`]      = "Template:Attack=1";
                           ["Damage Type", "Damage", "Hit Bonus", "Reach", "Target", "Type"].forEach((attr) => {
                               if(action[`${attr}`]) {
                                   const attributeName = (attr === "Hit Bonus") ? "tohit" : (attr === "Reach") ? "range" : attr.toLowerCase().replace(" ", "");
                                   update[`repeating_${npcaction}_${newrowid}_attack_${attributeName}`] = action[`${attr}`];
                               };
                           });
                           if(action["Damage 2"] && action["Damage 2 Type"]) {
                               update[`repeating_${npcaction}_${newrowid}_attack_damage2`]     = action["Damage 2"];
                               update[`repeating_${npcaction}_${newrowid}_attack_damagetype2`] = action["Damage 2 Type"];
                           }
                       }
                   });
                   (attr === "Actions") ? callbacks.push(() => {update_npc_action("all");} ) : false;
               } else if(contentarray && contentarray.indexOf(`${attr}`) > -1) {
                   console.log(`%c ${attr} was not found for ${page.name}`, "color: orange;");
               };
           });
           //REACTIONS
           if (page.data["data-Reactions"]) {
               update["npcreactionsflag"] = 1;
               let reactionsobj = {};
              jsonparse(page.data["data-Reactions"]).forEach((val) => { reactionsobj[val.Name] = val.Desc; });
               _.each(reactionsobj, (desc, name) => {
                   newrowid = generateRowID();
                   update[`repeating_npcreaction_${newrowid}_name`] = name + ".";
                   if(desc.substring(0,2) === ": " || encodeURI(desc.substring(0,2)) === ":%C2%A0") {
                       desc = desc.substring(2);
                   };
                   update[`repeating_npcreaction_${newrowid}_desc`] = desc.trim();
               });
           } else if(contentarray && contentarray.indexOf("Reactions") > -1) {
               console.log(`%c Reactions was not found for ${page.name}`, "color: orange;");
           };
           //TRAITS
           if (page.data["data-Traits"]) {
               //console.log(`%c MONSTERS Drop: NPC Traits`, "color:cornflowerblue;");
               let traitsobj     = {};
               jsonparse(page.data["data-Traits"]).forEach((val) => {
                   traitsobj[val.Name] = (val.Name && val.Desc) ? val.Desc : "";
                   if (val.Name && val.Desc) {
                       traitsobj[val.Name] = val.Desc;
                   } else if (val.Name) {
                       traitsobj[val.Name] = "";
                   } else {
                       console.log(`%c Traits JSON is lacking a Name key`, "color: orange;")
                   };
               });
               _.each(traitsobj, (desc, name) => {
                   newrowid = generateRowID();
                   update[`repeating_npctrait_${newrowid}_name`] = name + ".";
                   if(desc.substring(0,2) === ": " || encodeURI(desc.substring(0,2)) === ":%C2%A0") {
                       desc = desc.substring(2);
                   }
                   update[`repeating_npctrait_${newrowid}_desc`] = desc.trim();
                   // SPELLCASTING NPCS
                   if(name === "Spellcasting") {
                       var lvl = parseInt(desc.substring(desc.indexOf("-level")-4, desc.indexOf("-level")-2).trim(), 10);
                       lvl = !isNaN(lvl) ? lvl : 1;
                       var ability = desc.match(/casting ability is (.*?) /);
                           ability = ability && ability.length > 1 ? ability[1] : false;
                           ability = ability ? "@{" + ability.toLowerCase() + "_mod}+" : "0*";
                       update["base_level"]           = lvl;
                       update["caster_level"]         = lvl;
                       update["class"]                = "Wizard";
                       update["level"]                = lvl;
                       update["npcspellcastingflag"]  = 1;
                       update["spellcasting_ability"] = ability;
                       callbacks.push(() => {update_pb();} );
                       callbacks.push(() => {update_spell_slots();} );
                   }
                   //Githzerai in MToF have (Psionics)
                   if (name.includes("Innate Spellcasting")) {
                       const ability = (page.data["Spellcasting Ability"]) ? `@{${page.data["Spellcasting Ability"].toLowerCase()}_mod}+` : "0*";
                       update["npcspellcastingflag"]  = 1;
                       update["spellcasting_ability"] = ability;
                   };
               });
           } else if(contentarray && contentarray.indexOf("Traits") > -1) {
               console.log(`%c Traits was not found for ${page.name}`, "color: orange;");
           };
           //Spells
           if (page.data["data-Spells"]) {
               let spellsobj = [];
               //Put together a list of spells to get from the Comepndium
               ["spells", "innate"].forEach((type) => {
                   let spellList = jsonparse(page.data["data-Spells"])[`${type}`];
                   if (spellList) {
                       Object.keys(spellList).map((objectKey, index) => {
                           spellList[objectKey].forEach((spell) => {
                               spellsobj.push(spell);
                           });
                       });
                   };
               });
               getCompendiumPage(spellsobj, (compendiumPages) => {
                   compendiumPages = removeDuplicatedPageData(compendiumPages);
                   const spellData = (compendiumPages.length === undefined || compendiumPages.length === 1) ? [compendiumPages] : compendiumPages;
                   const innate = (jsonparse(page.data["data-Spells"])[`innate`]) ? jsonparse(page.data["data-Spells"])[`innate`] : false;
                   let existing = {};
                   let update   = [], callbacks = [];
                  spellData.forEach((page) => {
                       const spell        = page.data;
                       const lvl          = spell["Level"] && spell["Level"] > 0 ? spell["Level"] : "cantrip";
                       const newrowid     = generateRowID();
                       const repeatingRow = `repeating_spell-${lvl}_${newrowid}`;
                       update[`${repeatingRow}_spelllevel`]               = lvl;
                       update[`${repeatingRow}_spell_ability`]            = (update["spellcasting_ability"]) ? update["spellcasting_ability"] : "spell";
                       (spell.Name) ? update[`${repeatingRow}_spellname`] = spell.Name : console.log(`%c ${JSON.stringify(page.name)} is incorrect. Update compendium data.`, "color: orange;");
                       update[`${repeatingRow}_spelloutput`]              = (page.data["Damage"] || page.data["Healing"]) ? "ATTACK" : "SPELLCARD";
                       ["spellclass", "spellsource", "data-description"].forEach((attr) => {
                           const suffix = (attr.includes("description")) ? "spelldescription" : attr;
                           (spell[`${attr}`]) ? update[`${repeatingRow}_${suffix}`] = spell[`${attr}`] : false;
                       });
                       ["Add Casting Modifier", "Casting Time", "Concentration", "Damage Type", "Damage", "Duration", "Healing", "Material", "Range", "Ritual", "Save", "Save Success", "School", "Secondary Damage", "Secondary Damage Type", "Spell Attack", "Target"].forEach((attr) => {
                           if (spell[`${attr}`]) {
                               //Adjust the array entry to match the attribute name in the HTML
                               const name =
                                   (attr === "Add Casting Modifier") ? "dmgmod" :
                                   (attr === "Material") ? `comp_materials` :
                                   (attr === "Spell Attack") ? `attack` :
                                   (attr.includes("Secondary Damage")) ? attr.split("Secondary ")[0] + "2" :
                                   attr;
                               const spellattribute = name.toLowerCase().replace(" ", "");
                               //Concentration, Ritual, and School are exceptions to norm
                               const updateValue =
                                   (attr === "Concentration" || attr === "Ritual") ? `{{${spellattribute}=1}}` :
                                   (attr === "School") ? spell["School"].toLowerCase() :
                                   spell[`${attr}`];
                               update[`${repeatingRow}_spell${spellattribute}`] = updateValue;
                           };
                       });
                      ["Higher Spell Slot Bonus", "Higher Spell Slot Desc", "Higher Spell Slot Dice", "Higher Spell Slot Die"].forEach((attr) => {
                           if (spell[`${attr}`]) {
                               const spellattribute = (attr.includes("Bonus")) ? "hlbonus" : (attr.includes("Desc")) ? "athigherlevels" : (attr.includes("Dice")) ? "hldie" : "hldietype";
                               update[`${repeatingRow}_spell${spellattribute}`] = spell[`${attr}`];
                           };
                       });
                       if (spell["Components"]) {
                           ["v", "s", "m"].forEach((comp) => {
                               if (spell["Components"].toLowerCase().indexOf(comp) === -1) {update[`${repeatingRow}_spellcomp_${comp}`] = "0"};
                           });
                       };
                       if(page.data["Damage"] || page.data["Healing"]) {
                           //This needs to run the create_attack_from_spell
                           callbacks.push(() => { create_attack_from_spell(lvl, newrowid, currentData.character_id); });
                       } else if (page.data["Higher Spell Slot Desc"] && page.data["Higher Spell Slot Desc"] != "") {
                           //This needs to run the update_spelloutput
                       };
                       if (spell["data-Cantrip Scaling"] && lvl == "cantrip") {
                           update[`${repeatingRow}_spell_damage_progression`] = "Cantrip " + spell["data-Cantrip Scaling"].charAt(0).toUpperCase() + spell["data-Cantrip Scaling"].slice(1);
                       };
                       if (innate) {
                           const spellName = (spell.Name).toLowerCase();
                           //Search each keys in INNATE to see if spell name === one of the Values
                           Object.keys(innate).map((objectKey, index) => {
                               innate[objectKey].forEach((spell) => {
                                   (spell === spellName) ? update[`${repeatingRow}_innate`] = objectKey : false;
                               });
                           });
                       };
                       update[`${repeatingRow}_options-flag`] = "0";
                   });
                   setAttrs(update, {silent: true}, () => {
                       callbacks.forEach((callback) => {
                           callback();
                       })
                   });
                   return {
                       callbacks: callbacks
                   };
               });
           };
       };
       if(category === "Feats") {
           update["tab"] = "core";
           var match = {name: page.name};
           var existing = _.findWhere(repeating.traits, match);
           var newrowid = generateRowID();
           if(existing) {
               newrowid        = existing.id;
               existing.name   = page.name;
               existing.source = "Feat";
               existing.type   = page.data["Properties"] ? page.data["Properties"] : "";
           } else {
               var newtrait    = {};
               newtrait.id     = newrowid;
               newtrait.name   = page.name;
               newtrait.source = "Feat";
               newtrait.type   = page.data["Properties"] ? page.data["Properties"] : "";
               repeating.traits.push(newtrait);
           }
           if(page.name) {update[`repeating_traits_${newrowid}_name`]           = page.name};
           if(page.content) {update[`repeating_traits_${newrowid}_description`] = page.content};
           update[`repeating_traits_${newrowid}_source`]       = "Feat";
           update[`repeating_traits_${newrowid}_source_type`]  = page.data["Properties"] ? page.data["Properties"] : "";
           update[`repeating_traits_${newrowid}_options-flag`] = "0";
           update[`repeating_traits_${newrowid}_display_flag`] = "on";
       };
       if(category === "Proficiencies") {
           var newrowid = generateRowID();
           var type = page.data["Type"] || "";
           if (type.toLowerCase() === "language" || type.toLowerCase() === "armor" || type.toLowerCase() === "weapon" || type.toLowerCase() === "other") {
               if( repeating.prof_names.indexOf(page.name.toLowerCase()) == -1 ) {
                   update[`repeating_proficiencies_${newrowid}_prof_type`]    = type.replace("custom", "").toUpperCase();
                   update[`repeating_proficiencies_${newrowid}_name`]         = page.name;
                   update[`repeating_proficiencies_${newrowid}_options-flag`] = 0;
                   repeating.prof_names.push(page.name.toLowerCase());
               };
           } else if(type.toLowerCase() === "tool" || type.toLowerCase() === "skillcustom") {
               let existing = {};
               _.each(repeating.tool, (tool, id) => {
                   if(tool.toolname == page.name.toLowerCase()) {
                       newrowid = id;
                       existing = tool;
                   }
               });
               if(!existing.toolname) repeating.tool[newrowid] = {toolname: page.name.toLowerCase()}
               update[`repeating_tool_${newrowid}_toolname`] = page.name;
               if(!existing.base) update[`repeating_tool_${newrowid}_toolattr_base`] = "?{Attribute?|Strength,@{strength_mod}|Dexterity,@{dexterity_mod}|Constitution,@{constitution_mod}|Intelligence,@{intelligence_mod}|Wisdom,@{wisdom_mod}|Charisma,@{charisma_mod}}";
               update[`repeating_tool_${newrowid}_options-flag`] = 0;
               if(page.data["toolbonus_base"]) update[`repeating_tool_${newrowid}_toolbonus_base`] = "(@{pb}*2)";
               repeating.prof_names.push(page.name.toLowerCase());
               callbacks.push( function() {update_tool(newrowid);} );
           }
           if(type.toLowerCase() === "skill") {
               var skill_string = page.name.toLowerCase().replace(/ /g, '_');
               update[`${skill_string}_prof`] = `(@{pb}*@{${skill_string}_type})`;
           };
       };
       if(category === "Classes") {
           update["tab"] = "core";
           if(page.data.multiclass) {
               if(page.name && page.name !== "") { update[page.data.multiclass] = page.name; }
               update[page.data.multiclass + "_flag"] = "1";
               classlevel = parseInt(currentData[page.data.multiclass + "_lvl"]);
           } else {
               if(page.name && page.name !== "") { update["class"] = page.name; }
               if(page.data["Hit Die"] && page.data["Hit Die"] !== "") {
                   update["base_level"]   = currentData.base_level ? currentData.base_level : "1";
                   update["hit_dice_max"] = update["base_level"] + page.data["Hit Die"];
                   update["hit_dice"]     = update["base_level"];
               }
               if(page.data["Spellcasting Ability"] && page.data["Spellcasting Ability"] !== "") {
                   update["spellcasting_ability"] = "@{" + page.data["Spellcasting Ability"].toLowerCase() + "_mod}+";
               }
           }
           if(page.data["data-Saving Throws"] && !page.data.multiclass) {
               var saves = jsonparse(page.data["data-Saving Throws"]);
               _.each(saves, function(value) {
                   update[value.toLowerCase() + "_save_prof"] = "(@{pb})";
               });
           }
           if(!looped) {
               callbacks.push(update_class);
           }
       };
       if(category === "Subclasses") {
           if(page.data.multiclass) {
               if(page.name && page.name !== "") { update[page.data.multiclass + "_subclass"] = page.name; }
               classlevel = parseInt(currentData[page.data.multiclass + "_lvl"]);
           } else {
               if(page.name && page.name !== "") { update["subclass"] = page.name; };
           }
           if(page.data["Spellcasting Ability"]) {
               if(page.data.Class == "Fighter") {
                   update["arcane_fighter"] = "1";
               } else if(page.data.Class == "Rogue") {
                   update["arcane_rogue"] = "1";
               }
           }
           if(!looped) {
               callbacks.push(update_class);
           };
       };
       if(category === "Races" || category === "Subraces") {
           update["tab"] = "core";
           if(category === "Races") {
               update["race"] = page.name;
               if (page.name == "Halfling") {
                   update["halflingluck_flag"] = "1";
               }
           }
           else {
               update["subrace"] = page.name;
           };
           if(page.data["Speed"]) {update["speed"] = page.data["Speed"]};
           if(page.data["Size"]) {update["size"] = page.data["Size"]};
           if(!looped) {
               callbacks.push(update_race_display);
           }
       };
       if(category === "Backgrounds") {
           update["tab"] = "core";
           if(page.name && page.name !== "") { update["background"] = page.name; };
       };
       if(page.data.theseblobs) {
           _.each(page.data.theseblobs, function(blobname) {
               if(page.data.blobs[blobname]) blobs[blobname] = page.data.blobs[blobname];
           });
       } else {
           blobs = filterBlobs(page.data.blobs, {"Level": "1"});
       }
       _.each(blobs, function(blob, blobname) {
           if(blob["Traits"]) {
               var traitsource = "";
               switch (category) {
                   case "Races":
                   case "Subraces":
                       traitsource = "Racial";
                       break;
                   case "Classes":
                   case "Subclasses":
                       traitsource = "Class";
                       break;
                   default:
                       traitsource = "Background";
               }
               var trait_array = jsonparse(blob["Traits"]);
               if(trait_array && trait_array.length) {
                   _.each(trait_array, function(trait) {
                       if(!trait.Input) {
                           var match = {name: trait["Name"], type: page.name};
                           if(trait["Replace"]) {
                               match = {name: trait["Replace"]};
                           }
                           var existing = _.findWhere(repeating.traits, match);
                           if(existing) {
                               newrowid = existing.id;
                               existing.name = trait["Name"];
                               existing.source = traitsource;
                               existing.type = page.name;
                           } else {
                               var newtrait = {};
                               newrowid = generateRowID();
                               newtrait.id = newrowid;
                               newtrait.name = trait["Name"];
                               newtrait.source = traitsource;
                               newtrait.type = page.name;
                               repeating.traits.push(newtrait);
                           }
                           update["repeating_traits_" + newrowid + "_name"] = trait["Name"].replace(/Template:Input/g, "");
                           update["repeating_traits_" + newrowid + "_description"] = trait["Desc"] ? trait["Desc"].replace(/Template:Input/g, "") : "";
                           update["repeating_traits_" + newrowid + "_source"] = removeExpansionInfo(traitsource);
                           update["repeating_traits_" + newrowid + "_source_type"] = page.name ?  removeExpansionInfo(page.name) : "";
                           update["repeating_traits_" + newrowid + "_options-flag"] = 0;
                           update["repeating_traits_" + newrowid + "_display_flag"] = "on";
                       }
                   });
               };
           };
           if(blob["Language Proficiency"] || blob["Weapon Proficiency"] || blob["Armor Proficiency"] || blob["Tool Proficiency"]) {
               if(blob["Language Proficiency"]) {
                   var lang_array = jsonparse(blob["Language Proficiency"]);
                   if(lang_array["Proficiencies"] && lang_array["Proficiencies"].length) {
                       _.each(lang_array["Proficiencies"], function(prof) {
                           if( repeating.prof_names.indexOf(prof.toLowerCase()) == -1 ) {
                               newrowid = generateRowID();
                               update["repeating_proficiencies_" + newrowid + "_prof_type"] = "LANGUAGE";
                               update["repeating_proficiencies_" + newrowid + "_name"] = prof;
                               update["repeating_proficiencies_" + newrowid + "_options-flag"] = 0;
                               repeating.prof_names.push(prof.toLowerCase());
                           }
                       });
                   }
               };
               if(blob["Weapon Proficiency"]) {
                   var weap_array = jsonparse(blob["Weapon Proficiency"]);
                   if(weap_array["Proficiencies"] && weap_array["Proficiencies"].length) {
                       _.each(weap_array["Proficiencies"], function(prof) {
                           if( repeating.prof_names.indexOf(prof.toLowerCase()) == -1 ) {
                               newrowid = generateRowID();
                               update["repeating_proficiencies_" + newrowid + "_prof_type"] = "WEAPON";
                               update["repeating_proficiencies_" + newrowid + "_name"] = prof;
                               update["repeating_proficiencies_" + newrowid + "_options-flag"] = 0;
                               repeating.prof_names.push(prof.toLowerCase());
                           }
                       });
                   }
               };
               if(blob["Armor Proficiency"]) {
                   var armor_array = jsonparse(blob["Armor Proficiency"]);
                   if(armor_array["Proficiencies"] && armor_array["Proficiencies"].length) {
                       _.each(armor_array["Proficiencies"], function(prof) {
                           if( repeating.prof_names.indexOf(prof.toLowerCase()) == -1 ) {
                               newrowid = generateRowID();
                               update["repeating_proficiencies_" + newrowid + "_prof_type"] = "ARMOR";
                               update["repeating_proficiencies_" + newrowid + "_name"] = prof;
                               update["repeating_proficiencies_" + newrowid + "_options-flag"] = 0;
                               repeating.prof_names.push(prof.toLowerCase());
                           }
                       });
                   }
               };
               if(blob["Tool Proficiency"]) {
                   var tool_array = jsonparse(blob["Tool Proficiency"]);
                   if(tool_array["Proficiencies"] && tool_array["Proficiencies"].length) {
                       _.each(tool_array["Proficiencies"], function(prof) {
                           //D&D 5e Mancer: Land Vehicles proficiency does not drop with Marine background (UC748)
                           //Generating ID that was coming empty for not existing rows.
                           //By Miguel Peres
                           let newrowid = generateRowID();
                           let existing = {};
                           _.each(repeating.tool, function(tool, id) {
                               if(tool.toolname == prof.toLowerCase()) {
                                   newrowid = id;
                                   existing = tool;
                               }
                           });
                           if(!existing.toolname) repeating.tool[newrowid] = {toolname: prof.toLowerCase()}
                           update["repeating_tool_" + newrowid + "_toolname"] = prof;
                           if(!existing.base) update["repeating_tool_" + newrowid + "_toolattr_base"] = "?{Attribute?|Strength,@{strength_mod}|Dexterity,@{dexterity_mod}|Constitution,@{constitution_mod}|Intelligence,@{intelligence_mod}|Wisdom,@{wisdom_mod}|Charisma,@{charisma_mod}}";
                           update["repeating_tool_" + newrowid + "_options-flag"] = 0;
                           repeating.prof_names.push(page.name.toLowerCase());
                           callbacks.push( function() {update_tool(newrowid);} );
                       });
                   }
               };
           };
           if(blob["Skill Proficiency"]) {
               var skill_array = jsonparse(blob["Skill Proficiency"]);
               if(skill_array["Proficiencies"] && skill_array["Proficiencies"].length) {
                    _.each(skill_array["Proficiencies"], function(prof) {
                       var skill_string = prof.toLowerCase().replace(/ /g, '_');
                       update[skill_string + "_prof"] = "(@{pb}*@{" + skill_string + "_type})";
                   });
               };
           };
           if(blob["Actions"]) {
               var actionsobj = {};
               jsonparse(blob["Actions"]).forEach(function(val) { actionsobj[val.Name] = val; });
               _.each(actionsobj, function(action, name) {
                   newrowid = generateRowID();
                   _.each(repeating.attack, function(atk, atkid) {
                       if(atk.atkname === name) newrowid = atkid;
                   });
                   update["repeating_attack_" + newrowid + "_options-flag"] = "0";
                   update["repeating_attack_" + newrowid + "_atkname"] = name;
                   if(action["Desc"]) {
                       update["repeating_attack_" + newrowid + "_atk_desc"] = action["Desc"];
                   }
                   if(action["Type Attack"]) {
                       if (action["Type"] == "Spell") {
                           update["repeating_attack_" + newrowid + "_atkflag"] = "0";
                           update["repeating_attack_" + newrowid + "_attack_options"] = "";
                           update["repeating_attack_" + newrowid + "_saveflag"] = "Template:Save=1 {{saveattr=@{saveattr}}} {{savedesc=@{saveeffect}}} {{savedc=[[[[@{savedc}]][SAVE]]]}}"
                       } else {
                           update["repeating_attack_" + newrowid + "_attack_flag"] = "on";
                           update["repeating_attack_" + newrowid + "_atkflag"] = "Template:Attack=1";
                           update["repeating_attack_" + newrowid + "_attack_options"] = "Template:Attack=1";
                       }
                       if(action["Reach"]) { update["repeating_attack_" + newrowid + "_atkrange"] = action["Reach"]; }
                       if(action["Damage"]) { update["repeating_attack_" + newrowid + "_dmgbase"] = action["Damage"]; }
                       if(action["Damage Type"]) { update["repeating_attack_" + newrowid + "_dmgtype"] = action["Damage Type"]; }
                       if (action["Modifier"]) {
                           update["repeating_attack_" + newrowid + "_dmgattr"] = modStringToAttrib(action["Modifier"]);
                           update["repeating_attack_" + newrowid + "_atkattr_base"] = modStringToAttrib(action["Modifier"]);
                       } else {
                           update["repeating_attack_" + newrowid + "_dmgattr"] = "0";
                       }
                       if (action["Save"]) { update["repeating_attack_" + newrowid + "_saveattr"] = action["Save"] }
                       if (action["Save DC"]) { update["repeating_attack_" + newrowid + "_savedc"] = "(" + modStringToAttrib(action["Save DC"]) + "+8+@{pb})" }
                       if (action["Save Effect"]) { update["repeating_attack_" + newrowid + "_saveeffect"] = action["Save Effect"] }
                       if(action["Damage 2"] && action["Damage 2 Type"]) {
                           update["repeating_attack_" + newrowid + "_dmg2flag"] = "Template:Damage=1 Template:Dmg2flag=1";
                           update["repeating_attack_" + newrowid + "_atk_dmg2base"] = action["Damage 2"];
                           update["repeating_attack_" + newrowid + "_attack_damagetype2"] = action["Damage 2 Type"];
                           if (action["Modifier 2"]) {
                               update["repeating_attack_" + newrowid + "_dmg2attr"] = modStringToAttrib(action["Modifier 2"]);
                           } else {
                               update["repeating_attack_" + newrowid + "_dmgattr"] = "0";
                           }
                       }
                   }
               });
           };
           if(blob["Global Damage"]) {
               var dmgmod = jsonparse(blob["Global Damage"]);
               var id = generateRowID();
               _.each(repeating.damagemod, function(name, rowid) {
                   if(name.toLowerCase() === dmgmod["Name"].toLowerCase()) id = rowid;
               });
               update["repeating_damagemod_" + id + "_global_damage_name"] = `${dmgmod["Name"]}`;
               update["repeating_damagemod_" + id + "_global_damage_damage"] = `${parseValues(dmgmod["Damage"])}`;
               if(dmgmod["Active"] == "true") update["repeating_damagemod_" + id + "_global_damage_active_flag"] = "1";
               update["repeating_damagemod_" + id + "_options-flag"] = "0";
               update["repeating_damagemod_" + id + "_global_damage_type"] = dmgmod["Type"] ? dmgmod["Type"] : dmgmod["Name"];
               update["global_damage_mod_flag"] = "1";
               repeating.damagemod[id] = dmgmod["Name"];
           };
           if(blob["Resources"]) {
               var resources = jsonparse(blob["Resources"]);
               _.each(resources, function(value) {
                   var section = "";
                   if(currentData["class_resource_name"] == "" || currentData["class_resource_name"] == value["Name"]) {
                       section = "class_resource";
                   } else if (currentData["other_resource_name"] == "" || currentData["other_resource_name"] == value["Name"]) {
                       section = "other_resource";
                   } else {
                       _.each(repeating.resource, function(resource, id) {
                           if(resource.left == "" && section == "" || resource.left == value["Name"]) {
                               section = "repeating_resource_" + id + "_resource_left";
                           }
                           if(resource.right == "" && section == "" || resource.right == value["Name"]) {
                               section = "repeating_resource_" + id + "_resource_right";
                           }
                       })
                   }
                   if(section === "") {
                       var id = generateRowID();
                       section = "repeating_resource_" + id + "_resource_left";
                       repeating.resource[id] = {left: value["Name"], right: ""};
                   }
                   update[section + "_name"] = value["Name"];
                   if(value["Uses"]) update[section] = numUses(value["Uses"]);
                   update[section + "_max"] = value["Max"] ? numUses(value["Max"]) : numUses(value["Uses"]);
               });
           };
           if(blob["Custom AC"]) {
               var customac = jsonparse(blob["Custom AC"]);
               update["custom_ac_flag"] = "1";
               update["custom_ac_base"] = customac.Base;
               update["custom_ac_part1"] = customac["Attribute 1"];
               update["custom_ac_part2"] = customac["Attribute 2"] ? customac["Attribute 2"] : "";
               update["custom_ac_shield"] = customac.Shields;
               if(!looped) {
                   callbacks.push( function() {update_ac();} )
               }
           };
           if(blob["Hit Points Per Level"]) {
               var id = generateRowID();
               update["repeating_hpmod_" + id + "_mod"] = blob["Hit Points Per Level"];
               update["repeating_hpmod_" + id + "_source"] = page.name ? page.name : "Subclass";
               if(category === "Races" || category === "Subraces") {
                   update["repeating_hpmod_" + id + "_levels"] = "total";
               } else {
                   update["repeating_hpmod_" + id + "_levels"] = "base";
               }
           };
           if(blob["Global AC Mod"]) {
               var globalac = jsonparse(blob["Global AC Mod"]);
               var id = generateRowID();
               _.each(repeating.acmod, function(name, rowid) {
                   if(name.toLowerCase() === globalac["Name"].toLowerCase()) id = rowid;
               });
               update["repeating_acmod_" + id + "_global_ac_val"] = globalac.Bonus;
               if(globalac["Active"] !== "false") update["repeating_acmod_" + id + "_global_ac_active_flag"] = "1";
               update["repeating_acmod_" + id + "_options-flag"] = "0";
               update["repeating_acmod_" + id + "_global_ac_name"] = globalac.Name;
               update["global_ac_mod_flag"] = "1";
           };
           if(blob["Global Save"]) {
               var globalsave = jsonparse(blob["Global Save Mod"]);
               var id = generateRowID();
               _.each(repeating.savemod, function(name, rowid) {
                   if(name.toLowerCase() === globalsave["Name"].toLowerCase()) id = rowid;
               });
               update["repeating_savemod_" + id + "_global_save_roll"] = globalsave.Bonus;
               if(globalsave["Active"] !== "false") update["repeating_savemod_" + id + "_global_save_active_flag"] = "1";
               update["repeating_savemod_" + id + "_options-flag"] = "0";
               update["repeating_savemod_" + id + "_global_save_name"] = globalsave.Name;
               update["global_save_mod_flag"] = "1";
           }
           if(blob["Global Attack"]) {
               var globalattack = jsonparse(blob["Global Attack"]);
               var id = generateRowID();
               _.each(repeating.tohitmod, function(name, rowid) {
                   if(name.toLowerCase() === globalattack["Name"].toLowerCase()) id = rowid;
               });
               update["repeating_tohitmod_" + id + "_global_attack_rollstring"] = `${globalattack["Bonus"]}[${globalattack["Name"]}]`;
               if(globalattack["Active"] !== "false") update["repeating_tohitmod_" + id + "_global_attack_active_flag"] = "1";
               update["repeating_tohitmod_" + id + "_options-flag"] = "0";
               update["global_attack_mod_flag"] = "1";
           };
           if(blob["Initiative"]) {
               if(blob["Initiative"].toLowerCase() === "advantage") {
                   update["initiative_style"] = "{@{d20},@{d20}}kh1";
               } else if (blob["Initiative"].toLowerCase() === "disadvantage") {
                   update["initiative_style"] = "{@{d20},@{d20}}kl1";
               } else {
                   update.initmod = numUses(blob["Initiative"]);
               }
           };
           if(blob["Carry Multiplier"]) {
               update["carrying_capacity_mod"] = "*" + blob["Carry Multiplier"];
           };
           if(blob["Speed"]) {
               if(blob["Speed"][0] === "+") {
                   let prevspeed = update["speed"] || currentData["speed"];
                   prevspeed = prevspeed && !isNaN(parseInt(prevspeed)) ? parseInt(prevspeed) : 0;
                   update["speed"] = prevspeed + parseInt(blob["Speed"]);
               } else {
                   update["speed"] = parseInt(blob["Speed"]);
               }
           };
           if(blob["Jack of All Trades"]) {
               update["jack_of_all_trades"] = "@{jack}";
           };
           if(blob["Saving Throws"]) {
               var saves = jsonparse(blob["Saving Throws"]);
               _.each(saves, function(value) {
                   update[value.toLowerCase() + "_save_prof"] = "(@{pb})";
               });
           };
           if(blob["Custom Spells"]) {
               let spells = jsonparse(blob["Custom Spells"]);
               _.each(spells, function(spell) {
                   var lvl = spell["Level"] && spell["Level"] > 0 ? spell["Level"] : "cantrip";
                   let id = generateRowID();
                   if(repeating["spell-" + lvl]) {
                       _.each(repeating["spell-" + lvl], function(spell, spellid) {
                           if(spell.spellname.toLowerCase() === page.name.toLowerCase()) {
                               id = spellid;
                           }
                       });
                   }
                   update["repeating_spell-" + lvl + "_" + id + "_spelllevel"] = lvl;
                   if(spell["spellcasting_ability"]) {
                       update["repeating_spell-" + lvl + "_" + id + "_spell_ability"] = "@{" + spell["spellcasting_ability"].toLowerCase() + "_mod}+";;
                   } else {
                       update["repeating_spell-" + lvl + "_" + id + "_spell_ability"] = "spell";
                   }
                   if(spell["spellclass"]) {
                       update["repeating_spell-" + lvl + "_" + id + "_spellclass"] = spell["spellclass"];
                   }
                   if(spell["spellsource"]) {
                       update["repeating_spell-" + lvl + "_" + id + "_spellsource"] = spell["spellsource"];
                   }
                   update["repeating_spell-" + lvl + "_" + id + "_spellname"] = spell.Name;
                   if(spell["Ritual"]) {update["repeating_spell-" + lvl + "_" + id + "_spellritual"] = "Template:Ritual=1"};
                   if(spell["School"]) {update["repeating_spell-" + lvl + "_" + id + "_spellschool"] = spell["School"].toLowerCase()};
                   if(spell["Casting Time"]) {update["repeating_spell-" + lvl + "_" + id + "_spellcastingtime"] = spell["Casting Time"]};
                   if(spell["Range"]) {update["repeating_spell-" + lvl + "_" + id + "_spellrange"] = spell["Range"]};
                   if(spell["Target"]) {update["repeating_spell-" + lvl + "_" + id + "_spelltarget"] = spell["Target"]};
                   if(spell["Components"]) {
                       if(spell["Components"].toLowerCase().indexOf("v") === -1) {update["repeating_spell-" + lvl + "_" + id + "_spellcomp_v"] = "0"};
                       if(spell["Components"].toLowerCase().indexOf("s") === -1) {update["repeating_spell-" + lvl + "_" + id + "_spellcomp_s"] = "0"};
                       if(spell["Components"].toLowerCase().indexOf("m") === -1) {update["repeating_spell-" + lvl + "_" + id + "_spellcomp_m"] = "0"};
                   };
                   if(spell["Material"]) {update["repeating_spell-" + lvl + "_" + id + "_spellcomp_materials"] = spell["Material"]};
                   if(spell["Concentration"]) {update["repeating_spell-" + lvl + "_" + id + "_spellconcentration"] = "Template:Concentration=1"};
                   if(spell["Duration"]) {update["repeating_spell-" + lvl + "_" + id + "_spellduration"] = spell["Duration"]};
                   if(spell["Damage"] || spell["Healing"]) {
                       update["repeating_spell-" + lvl + "_" + id + "_spelloutput"] = "ATTACK";
                       callbacks.push( function() {create_attack_from_spell(lvl, id, currentData.character_id);} );
                   }
                   else if(spell["Higher Spell Slot Desc"] && spell["Higher Spell Slot Desc"] != "") {
                       var spelllevel = "?{Cast at what level?";
                       for(i = 0; i < 10-lvl; i++) {
                           spelllevel = spelllevel + "|Level " + (parseInt(i, 10) + parseInt(lvl, 10)) + "," + (parseInt(i, 10) + parseInt(lvl, 10));
                       }
                       spelllevel = spelllevel + "}";
                       update["repeating_spell-" + lvl + "_" + id + "_rollcontent"] = `@{wtype}&{template:spell} {{level=@{spellschool} ${spelllevel}}} {{name=@{spellname}}} {{castingtime=@{spellcastingtime}}} {{range=@{spellrange}}} {{target=@{spelltarget}}} @{spellcomp_v} @{spellcomp_s} @{spellcomp_m} {{material=@{spellcomp_materials}}} {{duration=@{spellduration}}} {{description=@{spelldescription}}} {{athigherlevels=@{spellathigherlevels}}} @{spellritual} {{innate=@{innate}}} @{spellconcentration} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
                   };
                   if(spell["Spell Attack"]) {update["repeating_spell-" + lvl + "_" + id + "_spellattack"] = spell["Spell Attack"]};
                   if(spell["Damage"]) {update["repeating_spell-" + lvl + "_" + id + "_spelldamage"] = spell["Damage"]};
                   if(spell["Damage Type"]) {update["repeating_spell-" + lvl + "_" + id + "_spelldamagetype"] = spell["Damage Type"]};
                   if(spell["Secondary Damage"]) {update["repeating_spell-" + lvl + "_" + id + "_spelldamage2"] = spell["Secondary Damage"]};
                   if(spell["Secondary Damage Type"]) {update["repeating_spell-" + lvl + "_" + id + "_spelldamagetype2"] = spell["Secondary Damage Type"]};
                   if(spell["Healing"]) {update["repeating_spell-" + lvl + "_" + id + "_spellhealing"] = spell["Healing"];};
                   if(spell["Add Casting Modifier"]) {update["repeating_spell-" + lvl + "_" + id + "_spelldmgmod"] = spell["Add Casting Modifier"]};
                   if(spell["Save"]) {update["repeating_spell-" + lvl + "_" + id + "_spellsave"] = spell["Save"]};
                   if(spell["Save Success"]) {update["repeating_spell-" + lvl + "_" + id + "_spellsavesuccess"] = spell["Save Success"]};
                   if(spell["Higher Spell Slot Dice"]) {update["repeating_spell-" + lvl + "_" + id + "_spellhldie"] = spell["Higher Spell Slot Dice"]};
                   if(spell["Higher Spell Slot Die"]) {update["repeating_spell-" + lvl + "_" + id + "_spellhldietype"] = spell["Higher Spell Slot Die"]};
                   if(spell["Higher Spell Slot Bonus"]) {update["repeating_spell-" + lvl + "_" + id + "_spellhlbonus"] = spell["Higher Spell Slot Bonus"]};
                   if(spell["Higher Spell Slot Desc"]) {update["repeating_spell-" + lvl + "_" + id + "_spellathigherlevels"] = spell["Higher Spell Slot Desc"]};
                   if(spell["data-Cantrip Scaling"] && lvl == "cantrip") {update["repeating_spell-" + lvl + "_" + id + "_spell_damage_progression"] = "Cantrip " + spell["data-Cantrip Scaling"].charAt(0).toUpperCase() + spell["data-Cantrip Scaling"].slice(1);};
                   if(spell["data-description"]) { update["repeating_spell-" + lvl + "_" + id + "_spelldescription"] = spell["data-description"]};
                   update["repeating_spell-" + lvl + "_" + id + "_options-flag"] = "0";
               })
           };
           if(blob["Global Save Mod"]) {
               update["globalsavemod"] = numUses(blob["Global Save Mod"]);
           };
           if(blob["Proficiency Bonus"]) {
               var bonus = jsonparse(blob["Proficiency Bonus"]);
               _.each(bonus, function(value, prof) {
                   update[prof.replace(/ /g, "_").toLowerCase() + "_flat"] = numUses(value);
               });
           };
           /**/
       });
       return {
           update: update,
           repeating: repeating,
           callbacks: callbacks
       };
   };
   var check_itemmodifiers = function(modifiers, previousValue) {
       var mods = modifiers.toLowerCase().split(",");
       if(previousValue) {
           prevmods = previousValue.toLowerCase().split(",");
           mods = _.union(mods, prevmods);
       };
       _.each(mods, function(mod) {
           if(mod.indexOf("ac:") > -1 || mod.indexOf("ac +") > -1 || mod.indexOf("ac -") > -1) {update_ac();};
           if(mod.indexOf("spell") > -1) {update_spell_info();};
           if(mod.indexOf("saving throws") > -1) {update_all_saves();};
           if(mod.indexOf("strength save") > -1) {update_save("strength");} else if(mod.indexOf("strength") > -1) {update_attr("strength");};
           if(mod.indexOf("dexterity save") > -1) {update_save("dexterity");} else if(mod.indexOf("dexterity") > -1) {update_attr("dexterity");};
           if(mod.indexOf("constitution save") > -1) {update_save("constitution");} else if(mod.indexOf("constitution") > -1) {update_attr("constitution");};
           if(mod.indexOf("intelligence save") > -1) {update_save("intelligence");} else if(mod.indexOf("intelligence") > -1) {update_attr("intelligence");};
           if(mod.indexOf("wisdom save") > -1) {update_save("wisdom");} else if(mod.indexOf("wisdom") > -1) {update_attr("wisdom");};
           if(mod.indexOf("charisma save") > -1) {update_save("charisma");} else if(mod.indexOf("charisma") > -1) {update_attr("charisma");};
           if(mod.indexOf("ability checks") > -1) {update_all_ability_checks();};
           if(mod.indexOf("acrobatics") > -1) {update_skills(["acrobatics"]);};
           if(mod.indexOf("animal handling") > -1) {update_skills(["animal_handling"]);};
           if(mod.indexOf("arcana") > -1) {update_skills(["arcana"]);};
           if(mod.indexOf("athletics") > -1) {update_skills(["athletics"]);};
           if(mod.indexOf("deception") > -1) {update_skills(["deception"]);};
           if(mod.indexOf("history") > -1) {update_skills(["history"]);};
           if(mod.indexOf("insight") > -1) {update_skills(["insight"]);};
           if(mod.indexOf("intimidation") > -1) {update_skills(["intimidation"]);};
           if(mod.indexOf("investigation") > -1) {update_skills(["investigation"]);};
           if(mod.indexOf("medicine") > -1) {update_skills(["medicine"]);};
           if(mod.indexOf("nature") > -1) {update_skills(["nature"]);};
           if(mod.indexOf("perception") > -1) {update_skills(["perception"]);};
           if(mod.indexOf("performance") > -1) {update_skills(["performance"]);};
           if(mod.indexOf("persuasion") > -1) {update_skills(["persuasion"]);};
           if(mod.indexOf("religion") > -1) {update_skills(["religion"]);};
           if(mod.indexOf("sleight of hand") > -1) {update_skills(["sleight_of_hand"]);};
           if(mod.indexOf("stealth") > -1) {update_skills(["stealth"]);};
           if(mod.indexOf("survival") > -1) {update_skills(["survival"]);};
       });
   };
   var create_attack_from_item = function(itemid, options) {
       var update = {};
       var newrowid = generateRowID();
       update["repeating_inventory_" + itemid + "_itemattackid"] = newrowid;
       if(options && options.versatile) {
           var newrowid2 = generateRowID();
           update["repeating_inventory_" + itemid + "_itemattackid"] += "," + newrowid2;
           setAttrs(update, {}, function() {
               update_attack_from_item(itemid, newrowid, {newattack: true, versatile: "primary"});
               update_attack_from_item(itemid, newrowid2, {newattack: true, versatile: "secondary"});
           });
       }
       else {
           setAttrs(update, {}, update_attack_from_item(itemid, newrowid, {newattack: true}));
       }
   };
   var update_attack_from_item = function(itemid, attackid, options) {
       getAttrs(["repeating_inventory_" + itemid + "_itemname","repeating_inventory_" + itemid + "_itemproperties","repeating_inventory_" + itemid + "_itemmodifiers", "strength", "dexterity"], function(v) {
           var update = {}; var itemtype; var damage; var damagetype; var damage2; var damagetype2; var attackmod; var damagemod; var range;
           var alt = {};
           if(options && options.newattack) {
               update["repeating_attack_" + attackid + "_options-flag"] = "0";
               update["repeating_attack_" + attackid + "_itemid"] = itemid;
           }
           if(v["repeating_inventory_" + itemid + "_itemmodifiers"] && v["repeating_inventory_" + itemid + "_itemmodifiers"] != "") {
               var mods = v["repeating_inventory_" + itemid + "_itemmodifiers"].split(",");
               _.each(mods, function(mod) {
                   if(mod.indexOf("Item Type:") > -1) {itemtype = mod.split(":")[1].trim()}
                   else if(mod.indexOf("Alternate Secondary Damage Type:") > -1) {alt.damagetype2 = mod.split(":")[1].trim();}
                   else if(mod.indexOf("Alternate Secondary Damage:") > -1) {alt.damage2 = mod.split(":")[1].trim();}
                   else if(mod.indexOf("Alternate Damage Type:") > -1) {alt.damagetype = mod.split(":")[1].trim();}
                   else if(mod.indexOf("Alternate Damage:") > -1) {alt.damage = mod.split(":")[1].trim();}
                   else if(mod.indexOf("Secondary Damage Type:") > -1) {damagetype2 = mod.split(":")[1].trim()}
                   else if(mod.indexOf("Secondary Damage:") > -1) {damage2 = mod.split(":")[1].trim()}
                   else if(mod.indexOf("Damage Type:") > -1) {damagetype = mod.split(":")[1].trim()}
                   else if(mod.indexOf("Damage:") > -1) {damage = mod.split(":")[1].trim()}
                   else if(mod.indexOf("Range:") > -1) {range = mod.split(":")[1].trim()}
                   else if(mod.indexOf(" Attacks ") > -1) {attackmod = mod.split(" Attacks ")[1].trim()}
                   else if(mod.indexOf(" Damage ") > -1) {damagemod = mod.split(" Damage ")[1].trim()}
               });
           }
           if(v["repeating_inventory_" + itemid + "_itemname"] && v["repeating_inventory_" + itemid + "_itemname"] != "") {
               update["repeating_attack_" + attackid + "_atkname"] = v["repeating_inventory_" + itemid + "_itemname"];
               if(options && options.versatile === "primary") {
                   update["repeating_attack_" + attackid + "_atkname"] += " (One-Handed)";
               } else if(options && options.versatile === "secondary") {
                   update["repeating_attack_" + attackid + "_atkname"] += " (Two-Handed)";
               }
           }
           if(options && options.versatile === "secondary") {
               if(alt.damage) {
                   update["repeating_attack_" + attackid + "_dmgbase"] = alt.damage;
               }
               if(alt.damagetype) {
                   update["repeating_attack_" + attackid + "_dmgtype"] = alt.damagetype;
               }
               if(alt.damage2) {
                   update["repeating_attack_" + attackid + "_dmg2base"] = alt.damage2;
                   update["repeating_attack_" + attackid + "_dmg2attr"] = 0;
                   update["repeating_attack_" + attackid + "_dmg2flag"] = "Template:Damage=1 Template:Dmg2flag=1";
               }
               if(alt.damagetype2) {
                   update["repeating_attack_" + attackid + "_dmg2type"] = alt.damagetype2;
               }
               update["repeating_attack_" + attackid + "_versatile_alt"] = "1";
           }
           else {
               if(damage) {
                   update["repeating_attack_" + attackid + "_dmgbase"] = damage;
               }
               if(damagetype) {
                   update["repeating_attack_" + attackid + "_dmgtype"] = damagetype;
               }
               if(damage2) {
                   update["repeating_attack_" + attackid + "_dmg2base"] = damage2;
                   update["repeating_attack_" + attackid + "_dmg2attr"] = 0;
                   update["repeating_attack_" + attackid + "_dmg2flag"] = "Template:Damage=1 Template:Dmg2flag=1";
               }
               if(damagetype2) {
                   update["repeating_attack_" + attackid + "_dmg2type"] = damagetype2;
               }
           }
           if(range) {
               update["repeating_attack_" + attackid + "_atkrange"] = range;
           }
           var finesse = v["repeating_inventory_" + itemid + "_itemproperties"] && /finesse/i.test(v["repeating_inventory_" + itemid + "_itemproperties"]);
           if( (itemtype && itemtype.indexOf("Ranged") > -1) || (finesse && +v.dexterity > +v.strength)) {
               update["repeating_attack_" + attackid + "_atkattr_base"] = "@{dexterity_mod}";
               update["repeating_attack_" + attackid + "_dmgattr"] = "@{dexterity_mod}";
           }
           else {
               update["repeating_attack_" + attackid + "_atkattr_base"] = "@{strength_mod}";
               update["repeating_attack_" + attackid + "_dmgattr"] = "@{strength_mod}";
           }
           if(attackmod && damagemod && attackmod == damagemod) {
               update["repeating_attack_" + attackid + "_atkmagic"] = parseInt(attackmod, 10);
               update["repeating_attack_" + attackid + "_atkmod"] = "";
               update["repeating_attack_" + attackid + "_dmgmod"] = "";
           }
           else {
               if(attackmod) {
                   update["repeating_attack_" + attackid + "_atkmod"] = parseInt(attackmod, 10);
               }
               if(damagemod) {
                   update["repeating_attack_" + attackid + "_dmgmod"] = parseInt(damagemod, 10);
               }
               update["repeating_attack_" + attackid + "_atkmagic"] = "";
           }
           var callback = function() {update_attacks(attackid, "item")};
           setAttrs(update, {silent: true}, callback);
       });
   };
   const create_resource_from_item = (itemid) => {
       const newrowid = generateRowID();
       let update     = {};
       getAttrs(["other_resource_name"], (v) => {
           //Use other_resource if it is empty
           if (!v.other_resource_name || v.other_resource_name == "") {
               update[`repeating_inventory_${itemid}_itemresourceid`] = "other_resource";
               setAttrs(update, {}, update_resource_from_item(itemid, "other_resource", true));
           //If other_resource is populated look through the repeating sections for an empty spot
           } else {
               getSectionIDs(`repeating_resource`, (idarray) => {
                   if (idarray.length == 0) {
                       update[`repeating_inventory_${itemid}_itemresourceid`] = `${newrowid}_resource_left`;
                       setAttrs(update, {}, update_resource_from_item(itemid, `${newrowid}_resource_left`, true));
                   } else {
                       let array = [];
                       _.each(idarray, (currentID, i) => {
                           ["left", "right"].forEach(side => {
                               array.push(`repeating_resource_${currentID}_resource_${side}`);
                               array.push(`repeating_resource_${currentID}_resource_${side}_name`);
                               array.push(`repeating_resource_${currentID}_resource_${side}_max`);
                           });
                       });
                       getAttrs(array, (y) => {
                           let existing = false;
                          _.each(idarray, (currentID, i) => {
                               ["left", "right"].forEach(side => {
                                   const Name  = y[`repeating_resource_${currentID}_resource_${side}_name`] || false;
                                   const Value = y[`repeating_resource_${currentID}_resource_${side}`] || false;
                                   const Max   = y[`repeating_resource_${currentID}_resource_${side}_max`] || false;
                                   //If Name, Value, & Max are empty and existing === false then populate a resource there
                                   if ((!Name && !Value && !Max) && existing === false) {
                                       update[`repeating_inventory_${itemid}_itemresourceid`] = `${currentID}_resource_${side}`;
                                       setAttrs(update, {}, update_resource_from_item(itemid, `${currentID}_resource_${side}`, true));
                                       existing = true;
                                   };
                               });
                           });
                          //If nothing is empty then generatae a new row
                           if(!existing) {
                               update[`repeating_inventory_${itemid}_itemresourceid`] = `${newrowid}_resource_left`;
                               setAttrs(update, {}, update_resource_from_item(itemid, `${newrowid}_resource_left`, true));
                           };
                       });
                   };
               });
           };
       });
   };
   var update_resource_from_item = function(itemid, resourceid, newresource) {
       getAttrs(["repeating_inventory_" + itemid + "_itemname","repeating_inventory_" + itemid + "_itemcount"], function(v) {
           var update = {}; var id;
           if(resourceid && resourceid == "other_resource") {
               id = resourceid;
           }
           else {
               id = "repeating_resource_" + resourceid;
           };
           if(newresource) {
               update[id + "_itemid"] = itemid;
           } ;
           if(!v["repeating_inventory_" + itemid + "_itemname"]) {
               update["repeating_inventory_" + itemid + "_useasresource"] = 0;
               update["repeating_inventory_" + itemid + "_itemresourceid"] = "";
               remove_resource(resourceid);
           };
           if(v["repeating_inventory_" + itemid + "_itemname"] && v["repeating_inventory_" + itemid + "_itemname"] != "") {
               update[id + "_name"] = v["repeating_inventory_" + itemid + "_itemname"];
           };
           if(v["repeating_inventory_" + itemid + "_itemcount"] && v["repeating_inventory_" + itemid + "_itemcount"] != "") {
               update[id] = v["repeating_inventory_" + itemid + "_itemcount"];
           };
           setAttrs(update, {silent: true});
       });
   };


   const create_attack_from_spell = function(lvl, spellid, character_id) {
       let update   = {};
       const newrowid = generateRowID();
       update[`repeating_spell-${lvl}_${spellid}_spellattackid`] = newrowid;
       update[`repeating_spell-${lvl}_${spellid}_rollcontent`] = `%{${character_id}|repeating_attack_${newrowid}_attack}`;
       setAttrs(update, {}, update_attack_from_spell(lvl, spellid, newrowid, true));
   }
   const update_attack_from_spell = (lvl, spellid, attackid, newattack) => {
       const repeating_spell  = `repeating_spell-${lvl}_${spellid}`;
       const repeating_attack = `repeating_attack_${attackid}`;
       getAttrs([`${repeating_spell}_spellname`, `${repeating_spell}_spellrange`, `${repeating_spell}_spelltarget`, `${repeating_spell}_spellattack`, `${repeating_spell}_spelldamage`, `${repeating_spell}_spelldamage2`,`${repeating_spell}_spelldamagetype`,`${repeating_spell}_spelldamagetype2`,`${repeating_spell}_spellhealing`,`${repeating_spell}_spelldmgmod`,`${repeating_spell}_spellsave`,`${repeating_spell}_spellsavesuccess`,`${repeating_spell}_spellhldie`,`${repeating_spell}_spellhldietype`,`${repeating_spell}_spellhlbonus`,`${repeating_spell}_spelllevel`,`${repeating_spell}_includedesc`,`${repeating_spell}_spelldescription`,`${repeating_spell}_spellathigherlevels`,`${repeating_spell}_spell_damage_progression`,`${repeating_spell}_innate`,`${repeating_spell}_spell_ability`,"spellcasting_ability"], (v) => {
           let update = {};
           let description = "";
           const spellAbility = (v[`${repeating_spell}_spell_ability`] != "spell") ? v[`${repeating_spell}_spell_ability`].slice(0, -1) : "spell";
           update[`${repeating_attack}_atkattr_base`] = spellAbility;
           if (newattack) {
               update[`${repeating_attack}_options-flag`] = "0";
               update[`${repeating_attack}_spellid`]      = spellid;
               update[`${repeating_attack}_spelllevel`]   = lvl;
           }
           if (v[`${repeating_spell}_spell_ability`] == "spell") {
               update[`${repeating_attack}_savedc`] = "(@{spell_save_dc})";
           } else if (v[`${repeating_spell}_spell_ability`]) {
               update[`${repeating_attack}_savedc`] = `(${spellAbility}+8+@{spell_dc_mod}+@{pb})`;
           }
           if (v[`${repeating_spell}_spellname`] && v[`${repeating_spell}_spellname`] != "") {
               update[`${repeating_attack}_atkname`] = v[`${repeating_spell}_spellname`];
           }
           update[`${repeating_attack}_atkflag`] = (!v[`${repeating_spell}_spellattack`] || v[`${repeating_spell}_spellattack`] === "None") ? "0" : "Template:Attack=1";
           if (v[`${repeating_spell}_spellattack`] || !v[`${repeating_spell}_spellattack`] === "None") {
               description = description + v[`${repeating_spell}_spellattack`] + " Spell Attack. ";
           };
           if (v[`${repeating_spell}_spelldamage`] && v[`${repeating_spell}_spelldamage`] != "") {
               update[`${repeating_attack}_dmgbase`] =
                   (v[`${repeating_spell}_spell_damage_progression`] && v[`${repeating_spell}_spell_damage_progression`] === "Cantrip Dice") ? "[[round((@{level} + 1) / 6 + 0.5)]]" + v[`${repeating_spell}_spelldamage`].substring(1) :
                   v[`${repeating_spell}_spelldamage`];
           };
           update[`${repeating_attack}_dmgflag`] = (v[`${repeating_spell}_spelldamage`] && v[`${repeating_spell}_spelldamage`] != "") ? "Template:Damage=1 Template:Dmg1flag=1" : "0";
           update[`${repeating_attack}_dmgattr`] = (v[`${repeating_spell}_spelldmgmod`] && v[`${repeating_spell}_spelldmgmod`] === "Yes") ? spellAbility : "0";
           update[`${repeating_attack}_dmgtype`] = (v[`${repeating_spell}_spelldamagetype`]) ? v[`${repeating_spell}_spelldamagetype`] : "";
           update[`${repeating_attack}_dmg2base`] = (v[`${repeating_spell}_spelldamage2`]) ? v[`${repeating_spell}_spelldamage2`] : "";
           update[`${repeating_attack}_dmg2attr`] = "0";
           update[`${repeating_attack}_dmg2flag`] = (v[`${repeating_spell}_spelldamage2`]) ? "Template:Damage=1 Template:Dmg2flag=1" : 0;
           update[`${repeating_attack}_dmg2type`] = (v[`${repeating_spell}_spelldamagetype2`]) ? v[`${repeating_spell}_spelldamagetype2`] : "";
           update[`${repeating_attack}_atkrange`] = (v[`${repeating_spell}_spellrange`]) ? v[`${repeating_spell}_spellrange`] : "";
           update[`${repeating_attack}_saveflag`] = (v[`${repeating_spell}_spellsave`]) ? "Template:Save=1 {{saveattr=@{saveattr}}} {{savedesc=@{saveeffect}}} {{savedc=[[[[@{savedc}]][SAVE]]]}}" : "0";
           update[`${repeating_attack}_saveeffect`] = (v[`${repeating_spell}_spellsavesuccess`]) ? v[`${repeating_spell}_spellsavesuccess`] : "";
           if(v[`${repeating_spell}_spellsave`]) {
               update[`${repeating_attack}_saveattr`] = v[`${repeating_spell}_spellsave`];
           };
           if(v[`${repeating_spell}_spellhldie`] && v[`${repeating_spell}_spellhldie`] != "" && v[`${repeating_spell}_spellhldietype`] && v[`${repeating_spell}_spellhldietype`] != "") {
               let bonus = "";
               const spelllevel = v[`${repeating_spell}_spelllevel`];
               let query = "?{Cast at what level?";
               for(i = 0; i < 10-spelllevel; i++) {
                   query = query + "|Level " + (parseInt(i, 10) + parseInt(spelllevel, 10)) + "," + i;
               }
               query = query + "}";
               if(v[`${repeating_spell}_spellhlbonus`] && v[`${repeating_spell}_spellhlbonus`] != "") {
                   bonus = "+(" + v[`${repeating_spell}_spellhlbonus`] + "*" + query + ")";
               }
               update[`${repeating_attack}_hldmg`] = `{{hldmg=[[(${v[`${repeating_spell}_spellhldie`]}*${query})${v[`${repeating_spell}_spellhldietype`]}${bonus}]]}}`;
           } else {
               update[`${repeating_attack}_hldmg`] = "";
           }
           if (v[`${repeating_spell}_spellhealing`] && v[`${repeating_spell}_spellhealing`] != "") {
               if(!v[`${repeating_spell}_spelldamage`] || v[`${repeating_spell}_spelldamage`] === "") {
                   update[`${repeating_attack}_dmgbase`] = v[`${repeating_spell}_spellhealing`];
                   update[`${repeating_attack}_dmgflag`] = "Template:Damage=1 Template:Dmg1flag=1";
                   update[`${repeating_attack}_dmgtype`] = "Healing";
               } else if (!v[`${repeating_spell}_spelldamage2`] || v[`${repeating_spell}_spelldamage2`] === "") {
                   update[`${repeating_attack}_dmg2base`] = v[`${repeating_spell}_spellhealing`];
                   update[`${repeating_attack}_dmg2flag`] = "Template:Damage=1 Template:Dmg2flag=1";
                   update[`${repeating_attack}_dmg2type`] = "Healing";
               }
           }
           update[`${repeating_attack}_spell_innate`] = (v[`${repeating_spell}_innate`]) ? v[`${repeating_spell}_innate`] : "";
           if(v[`${repeating_spell}_spelltarget`]) {
               description = description + v[`${repeating_spell}_spelltarget`] + ". ";
           }
           if(v[`${repeating_spell}_includedesc`] && v[`${repeating_spell}_includedesc`] === "on") {
               description = v[`${repeating_spell}_spelldescription`];
               if(v[`${repeating_spell}_spellathigherlevels`] && v[`${repeating_spell}_spellathigherlevels`] != "") {
                   description = description + "\n\nAt Higher Levels: " + v[`${repeating_spell}_spellathigherlevels`];
               }
           } else if(v[`${repeating_spell}_includedesc`] && v[`${repeating_spell}_includedesc`] === "off") {
               description = "";
           };
           update[`${repeating_attack}_atk_desc`] = description;
           var callback = () => {update_attacks(attackid, "spell")};
           setAttrs(update, {silent: true}, callback);
       });
   };
   const update_attacks = (update_id, source) => {
       if (update_id.substring(0,1) === "-" && update_id.length === 20) {
           do_update_attack([update_id], source);
       } else if (["strength","dexterity","constitution","intelligence","wisdom","charisma","spells","all"].indexOf(update_id) > -1) {
           getSectionIDs("repeating_attack", (idarray) => {
               if (update_id === "all") {
                   do_update_attack(idarray);
               } else if (update_id === "spells") {
                   let attack_attribs = [];
                   _.each(idarray, (id) => {
                       attack_attribs.push(`repeating_attack_${id}_spellid`, `repeating_attack_${id}_spelllevel`);
                   });
                   getAttrs(attack_attribs, (v) => {
                       const filteredIds = _.filter(idarray, (id) => {
                           return v[`repeating_attack_${id}_spellid`] && v[`repeating_attack_${id}_spellid`] != "";
                       });
                       let spell_attacks = {};
                       _.each(filteredIds, (attack_id) => {
                           spell_attacks[attack_id] = {
                               spell_id: v[`repeating_attack_${attack_id}_spellid`],
                               spell_lvl: v[`repeating_attack_${attack_id}_spelllevel`]
                           };
                       });
                       _.each(spell_attacks, (data, attack_id) => { update_attack_from_spell(data.spell_lvl, data.spell_id, attack_id); });
                   });
               } else {
                   let attack_attribs = ["spellcasting_ability"];
                   _.each(idarray, (id) => {
                       attack_attribs.push(`repeating_attack_${id}_atkattr_base`);
                       attack_attribs.push(`repeating_attack_${id}_dmgattr`);
                       attack_attribs.push(`repeating_attack_${id}_dmg2attr`);
                       attack_attribs.push(`repeating_attack_${id}_savedc`);
                   });
                   getAttrs(attack_attribs, (v) => {
                       let attr_attack_ids = [];
                       _.each(idarray, (id) => {
                           if ((v[`repeating_attack_${id}_atkattr_base`] && v[`repeating_attack_${id}_atkattr_base`].indexOf(update_id) > -1) || (v[`repeating_attack_${id}_dmgattr`] && v[`repeating_attack_${id}_dmgattr`].indexOf(update_id) > -1) || (v[`repeating_attack_${id}_dmg2attr`] && v[`repeating_attack_${id}_dmg2attr`].indexOf(update_id) > -1) || (v[`repeating_attack_${id}_savedc`] && v[`repeating_attack_${id}_savedc`].indexOf(update_id) > -1) || (v[`repeating_attack_${id}_savedc`] && v[`repeating_attack_${id}_savedc`] === "(@{spell_save_dc})" && v["spellcasting_ability"] && v["spellcasting_ability"].indexOf(update_id) > -1)) {
                               attr_attack_ids.push(id);
                           }
                       });
                       if (attr_attack_ids.length > 0) {
                           do_update_attack(attr_attack_ids);
                       }
                   });
               };
           });
       };
   };
   const do_update_attack = (attack_array, source) => {
       let attack_attribs = ["level","d20","pb","pb_type","pbd_safe","dtype","globalmagicmod","strength_mod","dexterity_mod","constitution_mod","intelligence_mod","wisdom_mod","charisma_mod","spellcasting_ability","spell_save_dc","spell_attack_mod", "spell_dc_mod", "global_damage_mod_roll", "global_damage_mod_crit"];
       _.each(attack_array, (attackid) => {
           ["atkflag","atkname","atkattr_base","atkmod","atkprofflag","atkmagic","dmgflag","dmgbase","dmgattr","dmgmod","dmgtype","dmg2flag","dmg2base","dmg2attr","dmg2mod","dmg2type","dmgcustcrit","dmg2custcrit","saveflag","savedc","saveeffect","saveflat","hldmg","spellid","spelllevel","atkrange","itemid","ammo",].forEach((attr) => {
               attack_attribs.push(`repeating_attack_${attackid}_${attr}`)
           });
       });
       getAttrs(attack_attribs, (v) => {
           _.each(attack_array, (attackid) => {
               const repeating_attack = `repeating_attack_${attackid}`;
               let callbacks          = [];
               let update             = {};
               let hbonus             = "";
               let hdmg1              = "";
               let hdmg2              = "";
               let dmg                = "";
               let dmg2               = "";
               let rollbase           = "";
               let spellattack        = false;
               let magicattackmod     = 0;
               let magicsavemod       = 0;
               let atkattr_abrev      = "";
               let dmgattr_abrev      = "";
               let dmg2attr_abrev     = "";
               //PROFICIENCY BONUS select in Settings.
               const pbd_safe = v["pbd_safe"] || "";
               //HIGHER LVL CAST DMG found in Spells for spells like Fireball
               const hldmgcrit = (v[`${repeating_attack}_hldmg`] && v[`${repeating_attack}_hldmg`] != "") ? v[`${repeating_attack}_hldmg`].slice(0, 7) + "crit" + v[`${repeating_attack}_hldmg`].slice(7) : "";
               if (v[`${repeating_attack}_spellid`] && v[`${repeating_attack}_spellid`] != "") {
                   spellattack    = true;
                   //GLOBAL MAGIC ATTACK MODIFIER in Settings
                   magicattackmod = parseInt(v["spell_attack_mod"],10) || 0;
                   //SPELL SAVE DC MOD in Settings
                   magicsavemod   = parseInt(v["spell_dc_mod"],10) || 0;
               };
               //ATTACK select inside settings for the repeating attack
               if (!v[`${repeating_attack}_atkattr_base`] || v[`${repeating_attack}_atkattr_base`] === "0") {
                   atkattr_base = 0
               } else if (v[`${repeating_attack}_atkattr_base`] && v[`${repeating_attack}_atkattr_base`] === "spell") {
                   atkattr_base  = parseInt(v[v["spellcasting_ability"].substring(2, v["spellcasting_ability"].length - 2)], 10);
                   atkattr_abrev = v["spellcasting_ability"].substring(2, 5).toUpperCase();
               } else {
                   atkattr_base = parseInt(v[v[`${repeating_attack}_atkattr_base`].substring(2, v[`${repeating_attack}_atkattr_base`].length - 1)], 10);
                   atkattr_abrev = v[`${repeating_attack}_atkattr_base`].substring(2, 5).toUpperCase();
               };
               //DAMAGE 1 ability select inside settings for the repeating attack
               if (!v[`${repeating_attack}_dmgattr`] || v[`${repeating_attack}_dmgattr`] === "0") {
                   dmgattr = 0;
               } else if (v[`${repeating_attack}_dmgattr`] && v[`${repeating_attack}_dmgattr`] === "spell") {
                   dmgattr = parseInt(v[v["spellcasting_ability"].substring(2, v["spellcasting_ability"].length - 2)], 10);
                   dmgattr_abrev = v["spellcasting_ability"].substring(2, 5).toUpperCase();
               } else {
                   dmgattr = parseInt(v[v[`${repeating_attack}_dmgattr`].substring(2, v[`${repeating_attack}_dmgattr`].length - 1)], 10);
                   dmgattr_abrev = v[`${repeating_attack}_dmgattr`].substring(2, 5).toUpperCase();
               };
               //DAMAGE 2 ability select inside settings for the repeating attack
               if (!v[`${repeating_attack}_dmg2attr`] || v[`${repeating_attack}_dmg2attr`] === "0") {
                   dmg2attr = 0;
               } else if (v[`${repeating_attack}_dmg2attr`] && v[`${repeating_attack}_dmg2attr`] === "spell") {
                   dmg2attr = parseInt(v[v["spellcasting_ability"].substring(2, v["spellcasting_ability"].length - 2)], 10);
                   dmg2attr_abrev = v["spellcasting_ability"].substring(2, 5).toUpperCase();
               } else {
                   dmg2attr = parseInt(v[v[`${repeating_attack}_dmg2attr`].substring(2, v[`${repeating_attack}_dmg2attr`].length - 1)], 10);
                   dmg2attr_abrev =v[`${repeating_attack}_dmg2attr`].substring(2, 5).toUpperCase();
               };
               //DAMAGE first input inside settings for the repeating attack
               const dmgbase  = v[`${repeating_attack}_dmgbase`] || 0;
               const dmg2base = v[`${repeating_attack}_dmg2base`] || 0;
               //DAMAGE 1 second input inside settings for the repeating attack
               const dmgmod  = parseInt(v[`${repeating_attack}_dmgmod`],10) || 0;
               //DAMAGE 2 second input inside settings for the repeating attack
               const dmg2mod = parseInt(v[`${repeating_attack}_dmg2mod`],10) || 0;
               //DAMAGE 1 TYPE input inside settings for the repeating attack
               const dmgtype  = v[`${repeating_attack}_dmgtype`] || "";
               //DAMAGE 2 TYPE input inside settings for the repeating attack
               const dmg2type = v[`${repeating_attack}_dmg2type`] || "";
               //PROFICIENT flag inside settings for the repeating attack && PROFICIENCY BONUS from Settings
               const atkprofflag = v[`${repeating_attack}_atkprofflag`] || 0;
               const pb          = (atkprofflag != 0 && v.pb) ? v.pb : 0;
               //ATTACK input inside settings for the repeating attack
               const atkmod = parseInt(v[`${repeating_attack}_atkmod`],10) || 0;
               //MAGIC BONUS input inside settings for the repeating attack
               const atkmag = parseInt(v[`${repeating_attack}_atkmagic`],10) || 0;
               //used in _atkdmgtype display
               const dmgmag = (isNaN(atkmag) === false && atkmag != 0 && ((v[`${repeating_attack}_dmgflag`] && v[`${repeating_attack}_dmgflag`] != 0) || (v[`${repeating_attack}_dmg2flag`] && v[`${repeating_attack}_dmg2flag`] != 0))) ? `+ ${atkmag} Magic Bonus` : "";
              //ATTACK checkbox inside settings for the repeating attack
               const atkflag = v[`${repeating_attack}_atkflag`] || 0;
               if (atkflag != 0) {
                   bonus_mod  = atkattr_base + atkmod + atkmag + magicattackmod;
                   plus_minus = (bonus_mod > -1) ? "+" : "";
                   //pb_type is PROFICIENCY BONUS select in Settings
                   if (v["pb_type"] && v["pb_type"] === "die") {
                       bonus  = `${bonus_mod}+${pb}`;
                   } else {
                       bonus_mod  = bonus_mod + parseInt(pb, 10);
                       bonus      = plus_minus + bonus_mod;
                   };
               //SAVING THROW checkbox inside settings for the repeating attack
               } else if (v[`${repeating_attack}_saveflag`] && v[`${repeating_attack}_saveflag`] != 0) {
                   const saveDC = v[`${repeating_attack}_savedc`] || "";
                   //SAVING THROW VS DC select "Spell" inside settings for the repeating attack
                   if (!saveDC || saveDC === "(@{spell_save_dc})") {
                       const tempdc = v["spell_save_dc"];
                       bonus = "DC" + tempdc;
                   //SAVING THROW VS DC select "FLAT" inside settings for the repeating attack
                   } else if (saveDC === "(@{saveflat})") {
                       const tempdc = parseInt(v[`${repeating_attack}_saveflat`]) || 0;
                       bonus = "DC" + tempdc;
                   //SAVING THROW VS DC select ability score inside settings for the repeating attack
                   } else {
                       const savedcattr = v[`${repeating_attack}_savedc`].split("_mod")[0].slice(3);
                       const safe_pb    = v["pb_type"] && v["pb_type"] === "die" ? parseInt(pb.substring(1), 10) / 2 : parseInt(pb,10);
                       const safe_attr  = v[`${savedcattr}_mod`] ? parseInt(v[`${savedcattr}_mod`],10) : 0;
                       const tempdc     = 8 + safe_attr + safe_pb + magicsavemod;
                       bonus = "DC" + tempdc;
                   };
               } else {
                   bonus = "-";
               }
               //DAMAGE checkbox inside settings for the repeating attack
               const dmgflag1 = v[`${repeating_attack}_dmgflag`] || 0;
               const dmgflag2 = v[`${repeating_attack}_dmg2flag`] || 0;
               if (dmgflag1 != 0) {
                   if (spellattack === true && dmgbase.indexOf("[[round((@{level} + 1) / 6 + 0.5)]]") > -1) {
                       // SPECIAL CANTRIP DAMAGE
                       dmgdiestring = Math.round(((parseInt(v["level"], 10) + 1) / 6) + 0.5).toString();
                       dmg = dmgdiestring + dmgbase.substring(dmgbase.lastIndexOf("d"));
                       //select & input to the right of damage
                       if (dmgattr + dmgmod != 0) {
                           dmg += `+${(dmgattr + dmgmod)}`;
                       }
                       dmg += ` ${dmgtype}`;
                   } else {
                       if (dmgbase === 0 && (dmgattr + dmgmod === 0)) {
                           dmg = 0;
                       }
                       if (dmgbase != 0) {
                           dmg = dmgbase;
                       }
                       if (dmgbase != 0 && (dmgattr + dmgmod != 0)) {
                           dmg = (dmgattr + dmgmod > 0) ? dmg + "+" : dmg;
                       }
                       if (dmgattr + dmgmod != 0) {
                           dmg = dmg + (dmgattr + dmgmod);
                       }
                       dmg = dmg + " " + dmgtype;
                   }
               };
               if (dmgflag2 != 0) {
                   if (dmg2base === 0 && (dmg2attr + dmg2mod === 0)) {
                       dmg2 = 0;
                   }
                   if (dmg2base != 0) {
                       dmg2 = dmg2base;
                   }
                   if (dmg2base != 0 && (dmg2attr + dmg2mod != 0)) {
                       dmg2 = (dmg2attr + dmg2mod > 0) ? dmg2 + "+" : dmg2;
                   }
                   if (dmg2attr + dmg2mod != 0) {
                       dmg2 = dmg2 + (dmg2attr + dmg2mod);
                   }
                   dmg2 = dmg2 + " " + dmg2type;
               };
               update[`${repeating_attack}_atkdmgtype`] = (dmgflag1 != 0 && dmgflag2 != 0) ? `${dmg} + ${dmg2}${dmgmag} `:`${dmg}${dmg2}${dmgmag} `;
               //Build ROLL TEMPLATE with below variables
               //ATTACK checkbox inside settings for the repeating attack
               if (atkflag != 0) {
                   if (atkattr_base   != 0) {hbonus += ` + ${atkattr_base}[${atkattr_abrev}]`};
                   if (atkmod         != 0) {hbonus += ` + ${atkmod}[MOD]`};
                   if (pb             != 0) {hbonus += ` + ${pb}${pbd_safe}[PROF]`};
                   if (atkmag         != 0) {hbonus += ` + ${atkmag}[MAGIC]`};
                   if (magicattackmod != 0) {hbonus += ` + ${magicattackmod}[SPELLATK]`};
               }
               //DAMAGE 1 checkbox inside settings for the repeating attack
               if (dmgflag1 != 0) {
                   hdmg1 += dmgbase;
                   if (dmgattr != 0) {hdmg1 += ` + ${dmgattr}[${dmgattr_abrev}]`};
                   if (dmgmod  != 0) {hdmg1 += ` + ${dmgmod}[MOD]`};
                   if (atkmag  != 0) {hdmg1 += ` + ${atkmag}[MAGIC]`};
               } else {
                   hdmg1 += "0";
               }
               //DAMAGE 2 checkbox inside settings for the repeating attack
               if (dmgflag2 != 0) {
                   hdmg2 += dmg2base
                   if (dmg2attr != 0) {hdmg2 += ` + ${dmg2attr}[${dmg2attr_abrev}]`};
                   if (dmg2mod  != 0) {hdmg2 += ` + ${dmg2mod}[MOD]`};
               } else {
                   hdmg2 += "0";
               }
               //CRIT input inside settings for the repeating attack
               let crit1 = v[`${repeating_attack}_dmgcustcrit`] || 0;
               let crit2 = v[`${repeating_attack}_dmg2custcrit`] || 0;
               crit1 = (crit1 != 0) ? v[`${repeating_attack}_dmgcustcrit`] : dmgbase;
               crit2 = (crit2 != 0) ? v[`${repeating_attack}_dmg2custcrit`] : dmg2base;
               r1    = (atkflag != 0) ? "@{d20}" : "0d20";
               r2    = (atkflag != 0) ? "@{rtype}" : "{{r2=[[0d20";
               //set in the GLOBAL DAMAGE MODIFIER section
               let globaldamage = `[[${v.global_damage_mod_roll || 0}]]`;
               let globaldamagecrit = `[[${v.global_damage_mod_crit || 0}]]`;
               //Assamble Roll Templates
               if (v.dtype === "full") {
                   rollbase = `@{wtype}&{template:atkdmg} {{mod=@{atkbonus}}} {{rname=@{atkname}}} {{r1=[[${r1}cs>@{atkcritrange}${hbonus}]]}} ${r2}cs>@{atkcritrange}${hbonus}]]}} @{atkflag} {{range=@{atkrange}}} @{dmgflag} {{dmg1=[[${hdmg1}]]}} {{dmg1type=${dmgtype}}} @{dmg2flag} {{dmg2=[[${hdmg2}]]}} {{dmg2type=${dmg2type}}} {{crit1=[[${crit1}[CRIT]]]}} {{crit2=[[${crit2}[CRIT]]]}} @{saveflag} {{desc=@{atk_desc}}} @{hldmg} ${hldmgcrit} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} {{globalattack=@{global_attack_mod}}} {{globaldamage=${globaldamage}}} {{globaldamagecrit=${globaldamagecrit}}} {{globaldamagetype=@{global_damage_mod_type}}} ammo=@{ammo} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
               } else if (atkflag != 0) {
                   rollbase = `@{wtype}&{template:atk} {{mod=@{atkbonus}}} {{rname=[@{atkname}](~repeating_attack_attack_dmg)}} {{rnamec=[@{atkname}](~repeating_attack_attack_crit)}} {{r1=[[${r1}cs>@{atkcritrange}${hbonus}]]}} ${r2}cs>@{atkcritrange}${hbonus}]]}} {{range=@{atkrange}}} {{desc=@{atk_desc}}} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} {{globalattack=@{global_attack_mod}}} ammo=@{ammo} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
               } else if (dmgflag1 != 0) {
                   rollbase = `@{wtype}&{template:dmg} {{rname=@{atkname}}} @{atkflag} {{range=@{atkrange}}} @{dmgflag} {{dmg1=[[${hdmg1}]]}} {{dmg1type=${dmgtype}}} @{dmg2flag} {{dmg2=[[${hdmg2}]]}} {{dmg2type=${dmg2type}}} @{saveflag} {{desc=@{atk_desc}}} @{hldmg} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} {{globaldamage=${globaldamage}}} {{globaldamagetype=@{global_damage_mod_type}}} ammo=@{ammo} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
               } else {
                   rollbase = `@{wtype}&{template:dmg} {{rname=@{atkname}}} @{atkflag} {{range=@{atkrange}}} @{saveflag} {{desc=@{atk_desc}}} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} ammo=@{ammo} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
               }
               update[`${repeating_attack}_rollbase_dmg`]  = `@{wtype}&{template:dmg} {{rname=@{atkname}}} @{atkflag} {{range=@{atkrange}}} @{dmgflag} {{dmg1=[[${hdmg1}]]}} {{dmg1type=${dmgtype}}} @{dmg2flag} {{dmg2=[[${hdmg2}]]}} {{dmg2type=${dmg2type}}} @{saveflag} {{desc=@{atk_desc}}} @{hldmg} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} {{globaldamage=${globaldamage}}} {{globaldamagetype=@{global_damage_mod_type}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
               update[`${repeating_attack}_rollbase_crit`] = `@{wtype}&{template:dmg} Template:Crit=1 {{rname=@{atkname}}} @{atkflag} {{range=@{atkrange}}} @{dmgflag} {{dmg1=[[${hdmg1}]]}} {{dmg1type=${dmgtype}}} @{dmg2flag} {{dmg2=[[${hdmg2}]]}} {{dmg2type=${dmg2type}}} {{crit1=[[${crit1}]]}} {{crit2=[[${crit2}]]}} @{saveflag} {{desc=@{atk_desc}}} @{hldmg} ${hldmgcrit} {{spelllevel=@{spelllevel}}} {{innate=@{spell_innate}}} {{globaldamage=${globaldamage}}} {{globaldamagecrit=${globaldamagecrit}}} {{globaldamagetype=@{global_damage_mod_type}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
               update[`${repeating_attack}_atkbonus`]      = bonus;
               update[`${repeating_attack}_rollbase`]      = rollbase;
               if (v[`${repeating_attack}_spellid`] && v[`${repeating_attack}_spellid`] != "" && (!source || source && source != "spell") && v[`${repeating_attack}_spellid`].length == 20) {
                   const spellid = v[`${repeating_attack}_spellid`];
                   const lvl     = v[`${repeating_attack}_spelllevel`];
                   callbacks.push(() => {
                       update_spell_from_attack(lvl, spellid, attackid);
                   });
               }
               if (v[`${repeating_attack}_itemid`] && v[`${repeating_attack}_itemid`] != "" && (!source || source && source != "item")) {
                   const itemid = v[`${repeating_attack}_itemid`];
                   callbacks.push(() => {
                       update_item_from_attack(itemid, attackid);
                   });
               }
               setAttrs(update, {silent: true}, () => {
                   callbacks.forEach((callback) => {
                       callback();
                   });
               });
           });
       });
   };
   //Update spells in the attack section
   const update_spell_from_attack = (lvl, spellid, attackid) => {
       const repeating_attack = `repeating_attack_${attackid}`;
       const repeating_spell = `repeating_spell-${lvl}_${spellid}`;
       let update = {};
       getAttrs([`${repeating_attack}_atkname`, `${repeating_attack}_atkrange`, `${repeating_attack}_atkflag`, `${repeating_attack}_atkattr_base`, `${repeating_attack}_dmgbase`, `${repeating_attack}_dmgtype`, `${repeating_attack}_dmg2base`, `${repeating_attack}_dmg2type`, `${repeating_attack}_saveflag`, `${repeating_attack}_saveattr`, `${repeating_attack}_saveeffect`], (v) => {
           update[`${repeating_spell}_spellname`]        = v[`${repeating_attack}_atkname`];
           update[`${repeating_spell}_spellrange`]       = v[`${repeating_attack}_atkrange`] || "";
           update[`${repeating_spell}_spellsavesuccess`] = v[`${repeating_attack}_saveeffect`] || "";
           if (v[`${repeating_attack}_dmgtype`] && v[`${repeating_attack}_dmgtype`].toLowerCase() == "healing") {
               if (v[`${repeating_attack}_dmgbase`] && v[`${repeating_attack}_dmgbase`] != "") {
                   update[`${repeating_spell}_spellhealing`] = v[`${repeating_attack}_dmgbase`];
               }
           } else {
               if (v[`${repeating_attack}_dmgbase`] && v[`${repeating_attack}_dmgbase`] != "" && v[`${repeating_attack}_dmgbase`].indexOf("[[round((@{level} + 1) / 6 + 0.5)]]") === -1) {
                   update[`${repeating_spell}_spelldamage`] = v[`${repeating_attack}_dmgbase`];
               } else if (!v[`${repeating_attack}_dmgbase`] || v[`${repeating_attack}_dmgbase`] === "") {
                   update[`${repeating_spell}_spelldamage`] = "";
               }
               update[`${repeating_spell}_spelldamagetype`] = v[`${repeating_attack}_dmgtype`] || "";
           };
           if (v[`${repeating_attack}_dmg2type`] && v[`${repeating_attack}_dmg2type`].toLowerCase() === "healing") {
               if (v[`${repeating_attack}_dmgbase`] && v[`${repeating_attack}_dmgbase`] != "") {
                   update[`${repeating_spell}_spellhealing`] = v[`${repeating_attack}_dmgbase`];
               }
           } else {
               update[`${repeating_spell}_spelldamage2`] = v[`${repeating_attack}_dmg2base`] || "";
               update[`${repeating_spell}_spelldamagetype2`] = v[`${repeating_attack}_dmg2type`] || "";
           };
           //SAVING THROW checkbox inside settings for the repeating attack
           update[`${repeating_spell}_spellsave`] =  (v[`${repeating_attack}_saveflag`] && v[`${repeating_attack}_saveflag`] != "0") ? v[`${repeating_attack}_saveattr`] : "";
           setAttrs(update, {silent: true});
       });
   };
   var update_item_from_attack = function(itemid, attackid) {
       getAttrs(["repeating_attack_" + attackid + "_atkname", "repeating_attack_" + attackid + "_dmgbase", "repeating_attack_" + attackid + "_dmg2base", "repeating_attack_" + attackid + "_dmgtype", "repeating_attack_" + attackid + "_dmg2type", "repeating_attack_" + attackid + "_atkrange", "repeating_attack_" + attackid + "_atkmod", "repeating_attack_" + attackid + "_dmgmod", "repeating_inventory_" + itemid + "_itemmodifiers", "repeating_attack_" + attackid + "_versatile_alt", "repeating_inventory_" + itemid + "_itemproperties", "repeating_attack_" + attackid + "_atkmagic"], function(v) {
           var update = {};
           var mods = v["repeating_inventory_" + itemid + "_itemmodifiers"];
           var damage = v["repeating_attack_" + attackid + "_dmgbase"] ? v["repeating_attack_" + attackid + "_dmgbase"] : 0;
           var damage2 = v["repeating_attack_" + attackid + "_dmg2base"] ? v["repeating_attack_" + attackid + "_dmg2base"] : 0;
           var damagetype = v["repeating_attack_" + attackid + "_dmgtype"] ? v["repeating_attack_" + attackid + "_dmgtype"] : 0;
           var damagetype2 = v["repeating_attack_" + attackid + "_dmg2type"] ? v["repeating_attack_" + attackid + "_dmg2type"] : 0;
           var range = v["repeating_attack_" + attackid + "_atkrange"] ? v["repeating_attack_" + attackid + "_atkrange"] : 0;
           var attackmod = v["repeating_attack_" + attackid + "_atkmod"] ? v["repeating_attack_" + attackid + "_atkmod"] : 0;
           var damagemod = v["repeating_attack_" + attackid + "_dmgmod"] ? v["repeating_attack_" + attackid + "_dmgmod"] : 0;
           var magicmod = v["repeating_attack_" + attackid + "_atkmagic"] ? v["repeating_attack_" + attackid + "_atkmagic"] : 0;
           var atktype = "";
           var altprefix = v["repeating_attack_" + attackid + "_versatile_alt"] === "1" ? "Alternate " : "";
           if(/Alternate Damage:/i.test(v["repeating_inventory_" + itemid + "_itemmodifiers"])) {
               update["repeating_inventory_" + itemid + "_itemname"] = v["repeating_attack_" + attackid + "_atkname"].replace(/\s*(?:\(One-Handed\)|\(Two-Handed\))/, "");
           } else {
               update["repeating_inventory_" + itemid + "_itemname"] = v["repeating_attack_" + attackid + "_atkname"];
           }
           var attack_type_regex = /(?:^|,)\s*Item Type: (Melee|Ranged) Weapon(?:,|$)/i;
           var attack_type_results = attack_type_regex.exec(v["repeating_inventory_" + itemid + "_itemmodifiers"]);
           atktype = attack_type_results ? attack_type_results[1] : "";
           if(mods) {
               mods = mods.split(",");
           } else {
               mods = [];
           }
           var damage_regex = new RegExp("^\\s*" + altprefix + "Damage:\\s*(.+)$", "i");
           var damage_found = false;
           for(var i = 0; i < mods.length; i++) {
               if(damage_found = damage_regex.exec(mods[i])) {
                   if(damage !== 0) {
                       mods[i] = mods[i].replace(damage_found[1], damage);
                   } else {
                       mods.splice(i, 1);
                   }
                   break;
               }
           }
           if(!damage_found && damage !== 0) {
               mods.push(altprefix + "Damage: " + damage);
           }
           var damage2_regex = new RegExp("^\\s*" + altprefix + "Secondary Damage:\\s*(.+)$", "i");
           var damage2_found = false;
           for(var i = 0; i < mods.length; i++) {
               if(damage2_found = damage2_regex.exec(mods[i])) {
                   if(damage2 !== 0) {
                       mods[i] = mods[i].replace(damage2_found[1], damage2);
                   } else {
                       mods.splice(i, 1);
                   }
                   break;
               }
           }
           if(!damage2_found && damage2 !== 0) {
               mods.push(altprefix + "Secondary Damage: " + damage2);
           }
           var dmgtype_regex = new RegExp("^\\s*" + altprefix + "Damage Type:\\s*(.+)$", "i");
           var dmgtype_found = false;
           for(var i = 0; i < mods.length; i++) {
               if(dmgtype_found = dmgtype_regex.exec(mods[i])) {
                   if(damagetype !== 0) {
                       mods[i] = mods[i].replace(dmgtype_found[1], damagetype);
                   } else {
                       mods.splice(i, 1);
                   }
                   break;
               }
           }
           if(!dmgtype_found && damagetype !== 0) {
               mods.push(altprefix + "Damage Type: " + damagetype);
           }
           var dmgtype2_regex = new RegExp("^\\s*" + altprefix + "Secondary Damage Type:\\s*(.+)$", "i");
           var dmgtype2_found = false;
           for(var i = 0; i < mods.length; i++) {
               if(dmgtype2_found = dmgtype2_regex.exec(mods[i])) {
                   if(damagetype2 !== 0) {
                       mods[i] = mods[i].replace(dmgtype_found[1], damagetype);
                   } else {
                       mods.splice(i, 1);
                   }
                   break;
               }
           }
           if(!dmgtype2_found && damagetype2 !== 0) {
               mods.push(altprefix + "Secondary Damage Type: " + damagetype2);
           }
           var range_found = false;
           for(var i = 0; i < mods.length; i++) {
               if(range_found = /^\s*Range:\s*(.+)$/i.exec(mods[i])) {
                   if(range !== 0) {
                       mods[i] = mods[i].replace(range_found[1], range);
                   } else {
                       mods.splice(i, 1);
                   }
                   break;
               }
           }
           if(!range_found && range !== 0) {
               mods.push("Range: " + range);
           }
           var attackmod_regex = new RegExp("^\\s*(?:" + (atktype !== "" ? atktype + "|" : "") + "Weapon) Attacks \\+?(.+)$", "i");
           var attackmod_found = false;
           for(var i = 0; i < mods.length; i++) {
               if(attackmod_found = attackmod_regex.exec(mods[i])) {
                   if(magicmod !== 0 || attackmod !== 0) {
                       mods[i] = mods[i].replace(attackmod_found[1], magicmod !== 0 ? magicmod : attackmod);
                   } else {
                       mods.splice(i, 1);
                   }
                   break;
               }
           }
           if(!attackmod_found && (magicmod !== 0 || attackmod !== 0)) {
               var properties = v["repeating_inventory_" + itemid + "_itemproperties"];
               if(properties && /Thrown/i.test(properties)) {
                   mods.push("Weapon Attacks: " + (magicmod !== 0 ? magicmod : attackmod));
               }
               else {
                   mods.push(atktype + " Attacks: " + (magicmod !== 0 ? magicmod : attackmod));
               }
           }
           var damagemod_regex = new RegExp("^\\s*(?:" + (atktype !== "" ? atktype + "|" : "") + "Weapon) Damage \\+?(.+)$", "i");
           var damagemod_found = false;
           for(var i = 0; i < mods.length; i++) {
               if(damagemod_found = damagemod_regex.exec(mods[i])) {
                   if(magicmod !== 0 || damagemod !== 0) {
                       mods[i] = mods[i].replace(damagemod_found[1], magicmod !== 0 ? magicmod : attackmod);
                   } else {
                       mods.splice(i, 1);
                   }
                   break;
               }
           }
           if(!damagemod_found && (magicmod !== 0 || damagemod !== 0)) {
               var properties = v["repeating_inventory_" + itemid + "_itemproperties"];
               if(properties && /Thrown/i.test(properties)) {
                   mods.push("Weapon Damage: " + (magicmod !== 0 ? magicmod : damagemod));
               }
               else {
                   mods.push(atktype + " Damage: " + (magicmod !== 0 ? magicmod : damagemod));
               }
           }
           update["repeating_inventory_" + itemid + "_itemmodifiers"] = mods.join(",");
           setAttrs(update, {silent: true});
       });
   };
   var remove_attack = function(attackid) {
       removeRepeatingRow("repeating_attack_" + attackid);
   };
   const remove_resource = (id) => {
       const attr = (id === "other_resource") ? id : `repeating_resource_${id}_itemid`;
       let update = {};
       getAttrs([`${attr}`], (v) => {
           const itemid = v[`${attr}`];
           //Uncheck Use As A Resource in inventory for an item if its resource row is deleted
           if (itemid) {
               update[`repeating_inventory_${itemid}_useasresource`]  = 0;
               update[`repeating_inventory_${itemid}_itemresourceid`] = "";
           };
           if (id == "other_resource") {
               update["other_resource"]        = "";
               update["other_resource_name"]   = "";
               update["other_resource_itemid"] = "";
               setAttrs(update, {silent: true});
           } else {
               const currentID = id.replace("repeating_resource_", "").substring(0,20);
               const side  = (id.includes("left")) ? `right` : `left`;
               //Get the inputs for the opposite side to see if they are empty.
               //If they are empty delete the entire row. Otherwise set the side that was the source of this event to empty strings
               getAttrs([`repeating_resource_${currentID}_resource_${side}`, `repeating_resource_${currentID}_resource_${side}_name`, `repeating_resource_${currentID}_resource_${side}_max`], (v) => {
                   const Name  = v[`repeating_resource_${currentID}_resource_${side}_name`] || false;
                   const Value = v[`repeating_resource_${currentID}_resource_${side}`] || false;
                   const Max   = v[`repeating_resource_${currentID}_resource_${side}_max`] || false;
                   if (!Name && !Value && !Max) {
                       removeRepeatingRow(`repeating_resource_${currentID}`);
                   } else {
                       update[`repeating_resource_${id}`]        = "";
                       update[`repeating_resource_${id}_name`]   = "";
                       update[`repeating_resource_${id}_max`]    = "";
                       update[`repeating_resource_${id}_itemid`] = "";
                   };
                   setAttrs(update, {silent: true});
               });
           };
       });
   };
   const update_weight = function() {
       let update = {};
       let wtotal = 0;
       let weight_attrs = ["cp","sp","ep","gp","pp","encumberance_setting","strength","size","carrying_capacity_mod"];
       getSectionIDs("repeating_inventory", (idarray) => {
           _.each(idarray, (currentID, i) => {
               weight_attrs.push(`repeating_inventory_${currentID}_itemweight`);
               weight_attrs.push(`repeating_inventory_${currentID}_itemcount`);
           });
           getAttrs(weight_attrs, (v) => {
               let coinWeight = 0;
               ["cp", "sp", "ep", "gp", "pp"].forEach((type)=> {
                   coinWeight += (isNaN(parseInt(v[`${type}`], 10)) === false) ? parseInt(v[`${type}`], 10) : 0;
               });
               wtotal = wtotal + ((coinWeight) / 50);
               _.each(idarray, (currentID, i) => {
                   if (v[`repeating_inventory_${currentID}_itemweight`] && isNaN(parseInt(v[`repeating_inventory_${currentID}_itemweight`], 10)) === false) {
                       count = v[`repeating_inventory_${currentID}_itemcount`] && isNaN(parseFloat(v[`repeating_inventory_${currentID}_itemcount`])) === false ? parseFloat(v[`repeating_inventory_${currentID}_itemcount`]) : 1;
                       wtotal = wtotal + (parseFloat(v[`repeating_inventory_${currentID}_itemweight`]) * count);
                   }
               });
               update["weighttotal"] = wtotal;
               const str_base = parseInt(v.strength, 10);
               let size_multiplier = 1;
               if (v["size"] && v["size"] != "") {
                   const size = v["size"].toLowerCase().trim();
                   size_multiplier =
                       (size === "tiny") ? .5 : (size === "large") ? 2 : (size === "huge") ? 4 : (size === "gargantuan") ? 8 : size_multiplier;
               };
               let str = str_base*size_multiplier;
               // Parse the carrying capacitiy modificator if any
               if (v.carrying_capacity_mod) {
                   const operator = v.carrying_capacity_mod.substring(0,1);
                   const value    = v.carrying_capacity_mod.substring(1);
                   if(["*","x","+","-"].indexOf(operator) > -1 && isNaN(parseFloat(value,10)) === false) {
                       str =
                           (operator === "*" || operator == "x") ? str*parseFloat(value,10) :
                           (operator === "+") ? str+parseFloat(value,10) :
                           (operator === "-") ? str-parseFloat(value,10) :
                           str;
                   }
               }
               if (!v.encumberance_setting || v.encumberance_setting === "off") {
                   update["encumberance"] = (wtotal > str*15) ? "OVER CARRYING CAPACITY" : " ";
               } else if (v.encumberance_setting === "on") {
                   update["encumberance"] =
                       (wtotal > str*15) ? "IMMOBILE" :
                       (wtotal > str*10) ? "HEAVILY ENCUMBERED" :
                       (wtotal > str*5)  ? "ENCUMBERED" :
                       " ";
               } else {
                   update["encumberance"] = " ";
               }
               setAttrs(update, {silent: true});
           });
       });
   };
   var update_ac = function() {
       getAttrs(["custom_ac_flag"], function(v) {
           if(v.custom_ac_flag === "2") {
               return;
           }
           else {
               var update = {};
               var ac_attrs = ["simpleinventory","custom_ac_base","custom_ac_part1","custom_ac_part2","strength_mod","dexterity_mod","constitution_mod","intelligence_mod","wisdom_mod","charisma_mod", "custom_ac_shield"];
               getSectionIDs("repeating_acmod", function(acidarray) {
                   _.each(acidarray, function(currentID, i) {
                       ac_attrs.push("repeating_acmod_" + currentID + "_global_ac_val");
                       ac_attrs.push("repeating_acmod_" + currentID + "_global_ac_active_flag");
                   });
                   getSectionIDs("repeating_inventory", function(idarray) {
                       _.each(idarray, function(currentID, i) {
                           ac_attrs.push("repeating_inventory_" + currentID + "_equipped");
                           ac_attrs.push("repeating_inventory_" + currentID + "_itemmodifiers");
                       });
                       getAttrs(ac_attrs, function(b) {
                           var custom_total = 0;
                           if(v.custom_ac_flag === "1") {
                               var base = isNaN(parseInt(b.custom_ac_base, 10)) === false ? parseInt(b.custom_ac_base, 10) : 10;
                               var part1attr = b.custom_ac_part1.toLowerCase();
                               var part2attr = b.custom_ac_part2.toLowerCase();
                               var part1 = part1attr === "none" ? 0 : parseInt(b[part1attr + "_mod"], 10);
                               var part2 = part2attr === "none" ? 0 : parseInt(b[part2attr + "_mod"], 10);
                               custom_total = base + part1 + part2;
                           }
                           var globalacmod = 0;
                           _.each(acidarray, function(currentID, i) {
                               if(b["repeating_acmod_" + currentID + "_global_ac_active_flag"] == "1") {
                                   globalacmod += parseInt(b["repeating_acmod_" + currentID + "_global_ac_val"], 10);
                               }
                           });
                           var dexmod = +b["dexterity_mod"];
                           var total = 10 + dexmod;
                           var armorcount = 0;
                           var shieldcount = 0;
                           var armoritems = [];
                           if(b.simpleinventory === "complex") {
                               _.each(idarray, function(currentID, i) {
                                   if(b["repeating_inventory_" + currentID + "_equipped"] && b["repeating_inventory_" + currentID + "_equipped"] === "1" && b["repeating_inventory_" + currentID + "_itemmodifiers"] && b["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().indexOf("ac") > -1) {
                                       var mods = b["repeating_inventory_" + currentID + "_itemmodifiers"].split(",");
                                       var ac = 0;
                                       var type = "mod";
                                       _.each(mods, function(mod) {
                                           if(mod.substring(0,10) === "Item Type:") {
                                               type = mod.substring(11, mod.length).trim().toLowerCase();
                                           }
                                           if(mod.toLowerCase().indexOf("ac:") > -1 || mod.toLowerCase().indexOf("ac +") > -1 || mod.toLowerCase().indexOf("ac+") > -1) {
                                               var regex = mod.replace(/[^0-9]/g, "");
                                               var bonus = regex && regex.length > 0 && isNaN(parseInt(regex,10)) === false ? parseInt(regex,10) : 0;
                                               ac = ac + bonus;
                                           }
                                           if(mod.toLowerCase().indexOf("ac -") > -1 || mod.toLowerCase().indexOf("ac-") > -1) {
                                               var regex = mod.replace(/[^0-9]/g, "");
                                               var bonus = regex && regex.length > 0 && isNaN(parseInt(regex,10)) === false ? parseInt(regex,10) : 0;
                                               ac = ac - bonus;
                                           }
                                       });
                                       armoritems.push({type: type, ac: ac});
                                   }
                               });
                               armorcount = armoritems.filter(function(item){ return item["type"].indexOf("armor") > -1 }).length;
                               shieldcount = armoritems.filter(function(item){ return item["type"].indexOf("shield") > -1 }).length;
                               var base = dexmod;
                               var armorac = 10;
                               var shieldac = 0;
                               var modac = 0;
                               _.each(armoritems, function(item) {
                                   if(item["type"].indexOf("light armor") > -1) {
                                       armorac = item["ac"];
                                       base = dexmod;
                                   }
                                   else if(item["type"].indexOf("medium armor") > -1) {
                                       armorac = item["ac"];
                                       base = Math.min(dexmod, 2);
                                   }
                                   else if(item["type"].indexOf("heavy armor") > -1) {
                                       armorac = item["ac"];
                                       base = 0;
                                   }
                                   else if(item["type"].indexOf("shield") > -1) {
                                       shieldac = item["ac"];
                                   }
                                   else {
                                       modac = modac + item["ac"]
                                   }
                               });
                               total = base + armorac + shieldac + modac;
                           };
                           update["armorwarningflag"] = "hide";
                           update["customacwarningflag"] = "hide";
                           if(armorcount > 1 || shieldcount > 1) {
                               update["armorwarningflag"] = "show";
                           }
                           update["ac"] = total + globalacmod;
                           if(custom_total > 0) {
                               if(armorcount > 0 || (shieldcount > 0 && b.custom_ac_shield != "yes")) {
                                   update["customacwarningflag"] = "show";
                               }
                               else {
                                   update["ac"] = b.custom_ac_shield == "yes" ? custom_total + shieldac + globalacmod + modac : custom_total + globalacmod + modac;
                               }
                           }
                           setAttrs(update, {silent: true});
                       });
                   });
               });
           };
       });
   };
   var check_customac = function(attr) {
       getAttrs(["custom_ac_flag","custom_ac_part1","custom_ac_part2"], function(v) {
           if(v["custom_ac_flag"] && v["custom_ac_flag"] === "1" && ((v["custom_ac_part1"] && v["custom_ac_part1"] === attr) || (v["custom_ac_part2"] && v["custom_ac_part2"] === attr))) {
               update_ac();
           }
       });
   };
   const update_initiative = () => {
       const attrs_to_get = ["dexterity","dexterity_mod","initmod","jack_of_all_trades","jack","init_tiebreaker","pb_type"];
       getSectionIDs("repeating_inventory", (idarray) => {
           _.each(idarray, (currentID) => {
               attrs_to_get.push(`repeating_inventory_${currentID}_equipped`);
               attrs_to_get.push(`repeating_inventory_${currentID}_itemmodifiers`);
           });
           getAttrs(attrs_to_get, (v) => {
               let update = {};
               let final_init = parseInt(v["dexterity_mod"], 10);
               if (v["initmod"] && !isNaN(parseInt(v["initmod"], 10))) {
                   final_init = final_init + parseInt(v["initmod"], 10);
               }
               if (v["init_tiebreaker"] && v["init_tiebreaker"] != 0) {
                   final_init = final_init + (parseInt(v["dexterity"], 10)/100);
               }
               if (v["jack_of_all_trades"] && v["jack_of_all_trades"] != 0) {
                   if (v["pb_type"] && v["pb_type"] === "die" && v["jack"]) {
                       final_init = final_init + "+" + v["jack"];
                   } else if (v["jack"] && !isNaN(parseInt(v["jack"], 10))) {
                       final_init = final_init + parseInt(v["jack"], 10);
                   }
               }
               _.each(idarray, (currentID) => {
                   if (v[`repeating_inventory_${currentID}_equipped`] && v[`repeating_inventory_${currentID}_equipped`] === "1" && v[`repeating_inventory_${currentID}_itemmodifiers`] && v[`repeating_inventory_${currentID}_itemmodifiers`].toLowerCase().indexOf("ability checks") > -1) {
                       const mods = v[`repeating_inventory_${currentID}_itemmodifiers`].toLowerCase().split(",");
                       _.each(mods, (mod) => {
                           if (mod.indexOf("ability checks") > -1) {
                               const new_mod = !isNaN(parseInt(mod.replace(/[^0-9]/g, ""), 10)) ? parseInt(mod.replace(/[^0-9]/g, ""), 10) : false;
                               final_init = (mod.indexOf("-") > -1 && new_mod) ? final_init - new_mod : (new_mod) ? final_init + new_mod  : final_init;
                           }
                       });
                   }
               });
               if (final_init % 1 != 0) {
                   final_init = parseFloat(final_init.toPrecision(12)); // ROUNDING ERROR BUGFIX
               }
               update["initiative_bonus"] = final_init;
               setAttrs(update, {silent: true});
           });
       });
   };
   const update_class = () => {
       getAttrs(["class", "base_level","custom_class","cust_hitdietype","cust_spellcasting_ability","cust_strength_save_prof","cust_dexterity_save_prof","cust_constitution_save_prof","cust_intelligence_save_prof","cust_wisdom_save_prof","cust_charisma_save_prof", "npc"], (v) => {
           if (v.npc && v.npc == "1") { return; }
           const abilites = ["Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma"];
           //Custom Classes
           if (v.custom_class && v.custom_class != "0") {
               update = {};
               update["hitdietype"] = v.cust_hitdietype;
               update["spellcasting_ability"] = v.cust_spellcasting_ability;
               abilites.forEach((save) => {
                   const ability = save.toLowerCase();
                   update[`${ability}_save_prof`] = v[`cust_${ability}_save_prof`];
               });
               setAttrs(update, {silent: true});
           //If "Choose" has been selected in the select
           } else if (v.class === "") {
               update = {};
               update["hitdietype"] = 6;
               update["spellcasting_ability"] = "0*";
               abilites.forEach((save) => {
                   const ability = save.toLowerCase();
                   update[`${ability}_save_prof`] = 0;
               });
               setAttrs(update, {silent: true});
           //Standard classes can pull their data from the Comependium
           } else {
               getCompendiumPage(v.class, (pages) => {
                   pages = removeDuplicatedPageData(pages);
                   update = {};
                   const classPages = (Array.isArray(pages)) ? pages : [pages];
                   classPages.forEach((classData) => {
                       if (classData.data && 'Category' in classData.data && classData.data[`Category`] === "Classes") {
                           update["hitdietype"]           = classData.data["Hit Die"].slice(1);
                           update["spellcasting_ability"] = (classData.data["Spellcasting Ability"]) ? `@{${classData.data["Spellcasting Ability"].toLowerCase()}_mod}+` : "0*";
                           abilites.forEach((save) => {
                               const ability = save.toLowerCase();
                               update[`${ability}_save_prof`] = (classData.data["data-Saving Throws"].indexOf(`${save}`) > -1) ? "(@{pb})" : 0;
                               update_save(ability);;
                           });
                       };
                       setAttrs(update, {silent: true});
                       //Update Spell info to change or remove casting attributes in Spells
                       update_spell_info();
                   });
               });
           };
       });
       set_level();
   };
   const set_level = function() {
       getAttrs(["base_level","multiclass1_flag","multiclass2_flag","multiclass3_flag","multiclass1_lvl","multiclass2_lvl","multiclass3_lvl","class","multiclass1","multiclass2","multiclass3", "arcane_fighter", "arcane_rogue", "custom_class", "cust_spellslots", "cust_classname", "level_calculations", "class", "subclass", "multiclass1_subclass","multiclass2_subclass","multiclass3_subclass"], (v) => {
           let update        = {};
           let callbacks     = [];
           const multiclass  = (v[`multiclass1_flag`] && v[`multiclass1_flag`] === "1") || (v.multiclass2_flag && v.multiclass2_flag === "1") || (v.multiclass3_flag && v.multiclass3_flag === "1") ? true : false;
           const finalclass  = (v[`custom_class`] && v[`custom_class`] != "0") ? v[`cust_spellslots`] : v[`class`];
           let finallevel    = (v[`base_level`] && v[`base_level`] > 0) ? parseInt(v.base_level,10) : 1;
           const charclass   = (v[`custom_class`] && v[`custom_class`] != "0") ? v[`cust_classname`] : v[`class`];
           let hitdie_final  = (multiclass) ? `?{Hit Die Class|${charclass},@{hitdietype}` : "@{hitdietype}";
           const subclass    = (v[`subclass`]) ? v[`subclass`] + " " : "";
           let class_display = `${subclass}${charclass} ${finallevel}`;
           // This nested array is used to determine the overall spellcasting level for the character.
           var classes = [ [finalclass.toLowerCase(), v[`base_level`]] ];
           ["multiclass1", "multiclass2", "multiclass3"].forEach((multiclass) => {
                if (v[`${multiclass}_flag`] && v[`${multiclass}_flag`] === "1") {
                   const multiclasslevel = (v[`${multiclass}_lvl`] && v[`${multiclass}_lvl`] > 0) ? parseInt(v[`${multiclass}_lvl`], 10) : 1;
                   const subclass = (v[`${multiclass}_subclass`]) ? v[`${multiclass}_subclass`] + " " : "";
                   finallevel = finallevel + multiclasslevel;
                   hitdie_final = `${hitdie_final}|` + v[`${multiclass}`].charAt(0).toUpperCase() + v[`${multiclass}`].slice(1) + "," + checkHitDie(v[`${multiclass}`]);
                   classes.push([ v[`${multiclass}`], multiclasslevel ]);
                   class_display = `${class_display}, ${subclass}` + v[`${multiclass}`] + ` ${multiclasslevel}`;
               };
           });
           const casterlevel = checkCasterLevel(classes, v[`arcane_fighter`], v[`arcane_rogue`]);
           update["hitdie_final"]  = (multiclass) ? `${hitdie_final}}` : hitdie_final;
           update["level"]         = finallevel;
           update["caster_level"]  = casterlevel;
           update["class_display"] = class_display;
           if(!v["level_calculations"] || v["level_calculations"] === "on") {
               update["hit_dice_max"] = finallevel;
               callbacks.push(() => {update_spell_slots();} );
           }
           callbacks.push(() => {update_pb();} );
           callbacks.push(() => {update_leveler_display();} );
           setAttrs(update, {silent: true},() => {callbacks.forEach((callback) => {callback(); })} );
       });
   };
   var isMultiCaster = function(classes, arcane_fighter, arcane_rogue) {
       var singlecaster = false;
       var multicaster = false;
       _.each(classes, function(multiclass) {
           var caster = getCasterType(multiclass[0], multiclass[1], arcane_fighter, arcane_rogue) > 0;
           if(caster && singlecaster) {
               multicaster = true;
           } else if(caster) {
               singlecaster = true;
           }
       });
       return multicaster;
   };
   var getCasterType = function(class_string, levels, arcane_fighter, arcane_rogue) {
       var full = ["bard","cleric","druid","sorcerer","wizard","full"];
       var half = ["artificer","paladin","ranger","half"];
       class_string = class_string.toLowerCase();
       if(full.indexOf(class_string) != -1) {
           return 1;
       } else if(half.indexOf(class_string) != -1) {
           if(class_string === "artificer" && levels == 1) return 1;
           return (levels == 1) ? 0 : (1/2);
       } else if(class_string === "third" || (class_string === "fighter" && arcane_fighter === "1") || (class_string === "rogue" && arcane_rogue === "1")) {
           return (levels == 1 || levels == 2) ? 0 : (1/3);
       } else {
           return 0;
       }
   };
   var checkCasterLevel = function(classes, arcane_fighter, arcane_rogue) {
       console.log("CHECKING CASTER LEVEL");
       var multicaster = isMultiCaster(classes, arcane_fighter, arcane_rogue);
       var totalcasterlevel = 0;
       _.each(classes, function(multiclass) {
           var casterlevel = parseInt(multiclass[1], 10) * getCasterType(multiclass[0], multiclass[1], arcane_fighter, arcane_rogue);
           // Characters with multiple spellcasting classes round down the casting level for that class
           // Character with a single spellcasting class round up the casting level
           totalcasterlevel = totalcasterlevel + (multicaster ? Math.floor(casterlevel) : Math.ceil(casterlevel));
       });
       return totalcasterlevel;
   };
   var checkHitDie = function(class_string) {
       var d10class = ["fighter","paladin","ranger"];
       var d8class = ["artificer","bard","cleric","druid","monk","rogue","warlock"];
       var d6class = ["sorcerer","wizard"];
       class_string = class_string.toLowerCase();
       if(class_string === "barbarian") {return "12"}
       else if (d10class.indexOf(class_string) != -1) {return "10"}
       else if (d8class.indexOf(class_string) != -1) {return "8"}
       else if (d6class.indexOf(class_string) != -1) {return "6"}
       else {return "0"};
   };
   var update_leveler_display = function () {
       getAttrs(["experience","level"], function(v) {
           let lvl = 0;
           let exp = 0;
           let update = {};
           update["showleveler"] = 0;
           if(v["level"] && !isNaN(parseInt(v["level"], 10)) && parseInt(v["level"], 10) > 0) {
               lvl = parseInt(v["level"], 10);
           }
           if(v["experience"] && !isNaN(parseInt(v["experience"], 10)) && parseInt(v["experience"], 10) > 0) {
               exp = parseInt(v["experience"], 10);
           }
           if(lvl > 0 && exp > 0) {
               if((lvl === 1 && exp >= 300) || (lvl === 2 && exp >= 900) || (lvl === 3 && exp >= 2700) || (lvl === 4 && exp >= 6500) || (lvl === 5 && exp >= 14000) || (lvl === 6 && exp >= 23000) || (lvl === 7 && exp >= 34000) || (lvl === 8 && exp >= 48000) || (lvl === 9 && exp >= 64000) || (lvl === 10 && exp >= 85000) || (lvl === 11 && exp >= 100000) || (lvl === 12 && exp >= 120000) || (lvl === 13 && exp >= 140000) || (lvl === 14 && exp >= 165000) || (lvl === 15 && exp >= 195000) || (lvl === 16 && exp >= 225000) || (lvl === 17 && exp >= 265000) || (lvl === 18 && exp >= 305000) || (lvl === 19 && exp >= 355000)) {
                   update["showleveler"] = 1;
               };
           };
           setAttrs(update, {silent: true});
       });
   };
   var update_spell_slots = function() {
       getAttrs(["lvl1_slots_mod","lvl2_slots_mod","lvl3_slots_mod","lvl4_slots_mod","lvl5_slots_mod","lvl6_slots_mod","lvl7_slots_mod","lvl8_slots_mod","lvl9_slots_mod","caster_level"], function(v) {
           var update = {};
           var lvl = v["caster_level"] && !isNaN(parseInt(v["caster_level"], 10)) ? parseInt(v["caster_level"], 10) : 0;
           var l1 = v["lvl1_slots_mod"] && !isNaN(parseInt(v["lvl1_slots_mod"], 10)) ? parseInt(v["lvl1_slots_mod"], 10) : 0;
           var l2 = v["lvl2_slots_mod"] && !isNaN(parseInt(v["lvl2_slots_mod"], 10)) ? parseInt(v["lvl2_slots_mod"], 10) : 0;
           var l3 = v["lvl3_slots_mod"] && !isNaN(parseInt(v["lvl3_slots_mod"], 10)) ? parseInt(v["lvl3_slots_mod"], 10) : 0;
           var l4 = v["lvl4_slots_mod"] && !isNaN(parseInt(v["lvl4_slots_mod"], 10)) ? parseInt(v["lvl4_slots_mod"], 10) : 0;
           var l5 = v["lvl5_slots_mod"] && !isNaN(parseInt(v["lvl5_slots_mod"], 10)) ? parseInt(v["lvl5_slots_mod"], 10) : 0;
           var l6 = v["lvl6_slots_mod"] && !isNaN(parseInt(v["lvl6_slots_mod"], 10)) ? parseInt(v["lvl6_slots_mod"], 10) : 0;
           var l7 = v["lvl7_slots_mod"] && !isNaN(parseInt(v["lvl7_slots_mod"], 10)) ? parseInt(v["lvl7_slots_mod"], 10) : 0;
           var l8 = v["lvl8_slots_mod"] && !isNaN(parseInt(v["lvl8_slots_mod"], 10)) ? parseInt(v["lvl8_slots_mod"], 10) : 0;
           var l9 = v["lvl9_slots_mod"] && !isNaN(parseInt(v["lvl9_slots_mod"], 10)) ? parseInt(v["lvl9_slots_mod"], 10) : 0;
           if(lvl > 0) {
               l1 = l1 + Math.min((lvl + 1),4);
               if(lvl < 3) {l2 = l2 + 0;} else if(lvl === 3) {l2 = l2 + 2;} else {l2 = l2 + 3;};
               if(lvl < 5) {l3 = l3 + 0;} else if(lvl === 5) {l3 = l3 + 2;} else {l3 = l3 + 3;};
               if(lvl < 7) {l4 = l4 + 0;} else if(lvl === 7) {l4 = l4 + 1;} else if(lvl === 8) {l4 = l4 + 2;} else {l4 = l4 + 3;};
               if(lvl < 9) {l5 = l5 + 0;} else if(lvl === 9) {l5 = l5 + 1;} else if(lvl < 18) {l5 = l5 + 2;} else {l5 = l5 + 3;};
               if(lvl < 11) {l6 = l6 + 0;} else if(lvl < 19) {l6 = l6 + 1;} else {l6 = l6 + 2;};
               if(lvl < 13) {l7 = l7 + 0;} else if(lvl < 20) {l7 = l7 + 1;} else {l7 = l7 + 2;};
               if(lvl < 15) {l8 = l8 + 0;} else {l8 = l8 + 1;};
               if(lvl < 17) {l9 = l9 + 0;} else {l9 = l9 + 1;};
           };
           update["lvl1_slots_total"] = l1;
           update["lvl2_slots_total"] = l2;
           update["lvl3_slots_total"] = l3;
           update["lvl4_slots_total"] = l4;
           update["lvl5_slots_total"] = l5;
           update["lvl6_slots_total"] = l6;
           update["lvl7_slots_total"] = l7;
           update["lvl8_slots_total"] = l8;
           update["lvl9_slots_total"] = l9;
           setAttrs(update, {silent: true});
       });
   };
   var update_pb = function() {
       callbacks = [];
       getAttrs(["level","pb_type","pb_custom"], function(v) {
           var update = {};
           var pb = 2;
           var lvl = parseInt(v["level"],10);
           if(lvl < 5) {pb = "2"} else if(lvl < 9) {pb = "3"} else if(lvl < 13) {pb = "4"} else if(lvl < 17) {pb = "5"} else {pb = "6"}
           var jack = Math.floor(pb/2);
           if(v["pb_type"] === "die") {
               update["jack"] = "d" + pb;
               update["pb"] = "d" + pb*2;
               update["pbd_safe"] = "cs0cf0";
           }
           else if(v["pb_type"] === "custom" && v["pb_custom"] && v["pb_custom"] != "") {
               update["pb"] = v["pb_custom"]
               update["jack"] = !isNaN(parseInt(v["pb_custom"],10)) ? Math.floor(parseInt(v["pb_custom"],10)/2) : jack;
               update["pbd_safe"] = "";
           }
           else {
               update["pb"] = pb;
               update["jack"] = jack;
               update["pbd_safe"] = "";
           };
           callbacks.push( function() {update_attacks("all");} );
           callbacks.push( function() {update_spell_info();} );
           callbacks.push( function() {update_jack_attr();} );
           callbacks.push( function() {update_initiative();} );
           callbacks.push( function() {update_tool("all");} );
           callbacks.push( function() {update_all_saves();} );
           callbacks.push( function() {update_skills(["athletics", "acrobatics", "sleight_of_hand", "stealth", "arcana", "history", "investigation", "nature", "religion", "animal_handling", "insight", "medicine", "perception", "survival","deception", "intimidation", "performance", "persuasion"]);} );
           setAttrs(update, {silent: true}, function() {callbacks.forEach(function(callback) {callback(); })} );
       });
   };
   var update_jack_attr = function() {
       var update = {};
       getAttrs(["jack_of_all_trades","jack"], function(v) {
           if(v["jack_of_all_trades"] && v["jack_of_all_trades"] != 0) {
               update["jack_bonus"] = "+" + v["jack"];
               update["jack_attr"] = "+" + v["jack"] + "@{pbd_safe}";
           }
           else {
               update["jack_bonus"] = "";
               update["jack_attr"] = "";
           }
           setAttrs(update, {silent: true});
       });
   };
   var update_spell_info = function(attr) {
       var update = {};
       getAttrs(["spellcasting_ability","spell_dc_mod","globalmagicmod","strength_mod","dexterity_mod","constitution_mod","intelligence_mod","wisdom_mod","charisma_mod"], function(v) {
           if(attr && v["spellcasting_ability"] && v["spellcasting_ability"].indexOf(attr) === -1) {
               return
           };
           if(!v["spellcasting_ability"] || (v["spellcasting_ability"] && v["spellcasting_ability"] === "0*")) {
               update["spell_attack_bonus"] = "0";
               update["spell_save_dc"] = "0";
               var callback = function() {update_attacks("spells")};
               setAttrs(update, {silent: true}, callback);
               return
           };
           var attr = attr ? attr : "";
           console.log("UPDATING SPELL INFO: " + attr);
           var ability = parseInt(v[v["spellcasting_ability"].substring(2,v["spellcasting_ability"].length-2)],10);
           var spell_mod = v["globalmagicmod"] && !isNaN(parseInt(v["globalmagicmod"], 10)) ? parseInt(v["globalmagicmod"], 10) : 0;
           var atk = v["globalmagicmod"] && !isNaN(parseInt(v["globalmagicmod"], 10)) ? ability + parseInt(v["globalmagicmod"], 10) : ability;
           var dc = v["spell_dc_mod"] && !isNaN(parseInt(v["spell_dc_mod"], 10)) ? 8 + ability + parseInt(v["spell_dc_mod"], 10) : 8 + ability;
           var itemfields = ["pb_type","pb"];
           getSectionIDs("repeating_inventory", function(idarray) {
               _.each(idarray, function(currentID, i) {
                   itemfields.push("repeating_inventory_" + currentID + "_equipped");
                   itemfields.push("repeating_inventory_" + currentID + "_itemmodifiers");
               });
               getAttrs(itemfields, function(v) {
                   _.each(idarray, function(currentID) {
                       if((!v["repeating_inventory_" + currentID + "_equipped"] || v["repeating_inventory_" + currentID + "_equipped"] === "1") && v["repeating_inventory_" + currentID + "_itemmodifiers"] && v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().indexOf("spell" > -1)) {
                           var mods = v["repeating_inventory_" + currentID + "_itemmodifiers"].toLowerCase().split(",");
                           _.each(mods, function(mod) {
                               if(mod.indexOf("spell attack") > -1) {
                                   var substr = mod.slice(mod.lastIndexOf("spell attack") + "spell attack".length);
                                   atk = substr && substr.length > 0 && !isNaN(parseInt(substr,10)) ? atk + parseInt(substr,10) : atk;
                                   spell_mod = substr && substr.length > 0 && !isNaN(parseInt(substr,10)) ? spell_mod + parseInt(substr,10) : spell_mod;
                               };
                               if(mod.indexOf("spell dc") > -1) {
                                   var substr = mod.slice(mod.lastIndexOf("spell dc") + "spell dc".length);
                                   dc = substr && substr.length > 0 && !isNaN(parseInt(substr,10)) ? dc + parseInt(substr,10) : dc;
                               };
                           });
                       };
                   });
                   if(v["pb_type"] && v["pb_type"] === "die") {
                       atk = atk + "+" + v["pb"];
                       //Fixing Spell DC when using type Die
                       //By Miguel
                       //Used to be equals to: dc + parseInt(v["pb"].substring(1), 10) / 2
                       dc = dc + "+" + v["pb"];
                   }
                   else {
                       atk = parseInt(atk, 10) + parseInt(v["pb"], 10);
                       dc = parseInt(dc, 10) + parseInt(v["pb"], 10);
                   };
                   update["spell_attack_mod"] = spell_mod;
                   update["spell_attack_bonus"] = atk;
                   update["spell_save_dc"] = dc;
                   var callback = function() {update_attacks("spells")};
                   setAttrs(update, {silent: true}, callback);
               });
           });
       });
   };
   var update_passive_perception = function() {
       getAttrs(["pb_type","passiveperceptionmod","perception_bonus"], function(v) {
           var passive_perception = 10;
           var mod = !isNaN(parseInt(v["passiveperceptionmod"],10)) ? parseInt(v["passiveperceptionmod"],10) : 0;
           var bonus = !isNaN(parseInt(v["perception_bonus"],10)) ? parseInt(v["perception_bonus"],10) : 0;
           if(v["pb_type"] && v["pb_type"] === "die" && v["perception_bonus"] && isNaN(v["perception_bonus"]) && v["perception_bonus"].indexOf("+") > -1) {
               var pieces = v["perception_bonus"].split(/\+|d/);
               var base = !isNaN(parseInt(pieces[0],10)) ? parseInt(pieces[0],10) : 0;
               var num_dice = !isNaN(parseInt(pieces[1],10)) ? parseInt(pieces[1],10) : 1;
               var half_pb_die = !isNaN(parseInt(pieces[2],10)) ? parseInt(pieces[2],10)/2 : 2;
               bonus = base + (num_dice * half_pb_die);
           }
           passive_perception = passive_perception + bonus + mod;
           setAttrs({passive_wisdom: passive_perception})
       });
   };
   var update_race_display = function() {
       getAttrs(["race", "subrace"], function(v) {
           var final_race = "";
           final_race = v.subrace ? v.subrace : v.race;
           if(v.race.toLowerCase() === "dragonborn") { final_race = v.race; };
           setAttrs({race_display: final_race});
       });
   };
   var organize_section_proficiencies = function() {
       getSectionIDs("proficiencies", function(ids) {
           var attribs = ["_reporder_repeating_proficiencies"];
           _.each(ids, function(id) {
               attribs.push("repeating_proficiencies_" + id + "_prof_type");
               attribs.push("repeating_proficiencies_" + id + "_name");
           });
           getAttrs(attribs, function(v) {
               var final_array = _(ids).chain().sortBy(function(id) {
                   return v["repeating_proficiencies_" + id + "_name"];
               }).sortBy(function(id) {
                   return v["repeating_proficiencies_" + id + "_prof_type"];
               }).value();
               _.each(final_array, function(id) {
               });
               if(final_array && final_array.length > 0) {
                   setSectionOrder("proficiencies", final_array);
               };
           });
       });
   };
   const update_challenge = () => {
       getAttrs(["npc_challenge"], (v) => {
           let update = {};
           const challengeRatingsXP = { '0':'10', '1/8':'25', '1/4':'50', '1/2':'100', '1':'200', '2':'450', '3':'700', '4':'1100', '5':'1800', '6':'2300', '7':'2900', '8':'3900', '9':'5000', '10':'5900', '11':'7200', '12':'8400', '13':'10000', '14':'11500', '15':'13000', '16':'15000', '17':'18000', '18':'20000', '19':'22000', '20':'25000', '21':'33000', '22':'41000', '23':'50000', '24':'62000', '25':'75000', '26':'90000', '27':'105000', '28':'120000', '29':'135000', '30':'155000'
           };
           const xp = parseInt(challengeRatingsXP[v.npc_challenge]) || 0;
           const pb = xp <= 1100 ? 2 : xp <= 3900 ? 3 : xp <= 8400 ? 4 : xp <= 15000 ? 5 : xp <= 25000 ? 6 : xp <= 62000 ? 7 : xp <= 120000 ? 8 : xp <= 155000 ? 9 : 0;
           update["npc_xp"] = xp;
           update["pb_custom"] = pb;
           update["pb_type"] = "custom";
           setAttrs(update, {silent: true}, function() {update_pb()});
       });
   };
   
   const update_npc_saves = () => {
       const list = ["npc_str_save_base","npc_dex_save_base","npc_con_save_base","npc_int_save_base","npc_wis_save_base","npc_cha_save_base"];
       const type = "save";
       update_npc_lists(list, type);
   };
   const update_npc_skills = () => {
       const list = ["npc_acrobatics_base","npc_animal_handling_base","npc_arcana_base","npc_athletics_base","npc_deception_base","npc_history_base","npc_insight_base","npc_intimidation_base","npc_investigation_base","npc_medicine_base","npc_nature_base","npc_perception_base","npc_performance_base","npc_persuasion_base","npc_religion_base","npc_sleight_of_hand_base","npc_stealth_base","npc_survival_base"];
       const type = "skills";
       update_npc_lists(list, type);
   };
   const update_npc_lists = (list, type) => {
       getAttrs(list, function(v) {
           let update    = {};
           let last_save = 0;
           let npc_flag  = 0;
           _.each(list.reverse(), (base) => {
               const attr   = base.slice(4, -5); //Remove npc_ and _base
               let item     = parseInt(v[`${base}`], 10);
               // CSS will add comma :after 2 & 4 and +/- :before
               // 1 = Positive Number, 2 = Last Number, 3 = Negative Number, 4 = Last Negative Number
               if (v[`${base}`] && !isNaN(item) || v[`${base}`] === 0) {
                   if (last_save === 0) {
                       last_save = 1;
                       item_flag = item < 0 ? 4 : 2;
                   } else {
                       item_flag = item < 0 ? 3 : 1;
                   }
               } else {
                   item_flag = 0;
                   item      = "";
               };
               update[`npc_${attr}_flag`] = item_flag;
               update[`npc_${attr}`]      = item;
               npc_flag += item_flag;
           });
           const flagAttr = (type === "save") ? "saving" : type;
           update[`npc_${flagAttr}_flag`] = (npc_flag === 0) ? "" : npc_flag;
           setAttrs(update, {silent: true});
       });
   };
   var update_npc_action = function(update_id, legendary) {
       if(update_id.substring(0,1) === "-" && update_id.length === 20) {
           do_update_npc_action([update_id], legendary);
       }
       else if(update_id === "all") {
           var legendary_array = [];
           var actions_array = [];
           getSectionIDs("repeating_npcaction-l", function(idarray) {
               legendary_array = idarray;
               if(legendary_array.length > 0) {
                   do_update_npc_action(legendary_array, true);
               }
               getSectionIDs("repeating_npcaction", function(idarray) {
                   actions_array = idarray.filter(function(i) {return legendary_array.indexOf(i) < 0;});
                   if(actions_array.length > 0) {
                       do_update_npc_action(actions_array, false);
                   };
               });
           });
       };
   };
   var do_update_npc_action = function(action_array, legendary) {
       var repvar = legendary ? "repeating_npcaction-l_" : "repeating_npcaction_";
       var action_attribs = ["dtype"];
       _.each(action_array, function(actionid) {
           action_attribs.push(repvar + actionid + "_attack_flag");
           action_attribs.push(repvar + actionid + "_attack_type");
           action_attribs.push(repvar + actionid + "_attack_range");
           action_attribs.push(repvar + actionid + "_attack_target");
           action_attribs.push(repvar + actionid + "_attack_tohit");
           action_attribs.push(repvar + actionid + "_attack_damage");
           action_attribs.push(repvar + actionid + "_attack_damagetype");
           action_attribs.push(repvar + actionid + "_attack_damage2");
           action_attribs.push(repvar + actionid + "_attack_damagetype2");
       });
       getAttrs(action_attribs, function(v) {
           _.each(action_array, function(actionid) {
               console.log("UPDATING NPC ACTION: " + actionid);
               var callbacks = [];
               var update = {};
               var onhit = "";
               var damage_flag = "";
               var range = "";
               var attack_flag = v[repvar + actionid + "_attack_flag"] && v[repvar + actionid + "_attack_flag"] != "0" ? "Template:Attack=1" : "";
               var tohit = v[repvar + actionid + "_attack_tohit"] && isNaN(parseInt(v[repvar + actionid + "_attack_tohit"], 10)) === false ? parseInt(v[repvar + actionid + "_attack_tohit"], 10) : 0;
               if(v[repvar + actionid + "_attack_type"] && v[repvar + actionid + "_attack_range"]) {
                   if(v[repvar + actionid + "_attack_type"] === "Melee") {var rangetype = "Reach";} else {var rangetype = "Range";};
                   range = ", " + rangetype + " " + v[repvar + actionid + "_attack_range"];
               }
               var target = v[repvar + actionid + "_attack_target"] && v[repvar + actionid + "_attack_target"] != "" ? ", " + v[repvar + actionid + "_attack_target"] : ""
               var attack_tohitrange = "+" + tohit + range + target;
               var dmg1 = v[repvar + actionid + "_attack_damage"] && v[repvar + actionid + "_attack_damage"] != "" ? v[repvar + actionid + "_attack_damage"] : "";
               var dmg1type = v[repvar + actionid + "_attack_damagetype"] && v[repvar + actionid + "_attack_damagetype"] != "" ? " " + v[repvar + actionid + "_attack_damagetype"] : "";
               var dmg2 = v[repvar + actionid + "_attack_damage2"] && v[repvar + actionid + "_attack_damage2"] != "" ? v[repvar + actionid + "_attack_damage2"] : "";
               var dmg2type = v[repvar + actionid + "_attack_damagetype2"] && v[repvar + actionid + "_attack_damagetype2"] != "" ? " " + v[repvar + actionid + "_attack_damagetype2"] : "";
               var dmgspacer = dmg1 != "" && dmg2 != "" ? " plus " : "";
               var parsed_dmg1 = parse_roll_string(dmg1);
               var parsed_dmg2 = parse_roll_string(dmg2);
               if(dmg1 != "") {
                   onhit = onhit + parsed_dmg1.avg + " (" + dmg1 + ")" + dmg1type + " damage";
               };
               dmgspacer = dmg1 != "" && dmg2 != "" ? " plus " : "";
               onhit = onhit + dmgspacer;
               if(dmg2 != "") {
                   onhit = onhit + parsed_dmg2.avg + " (" + dmg2 + ")" + dmg2type + " damage";
               };
               if(dmg1 != "" || dmg2 != "") {damage_flag = damage_flag + "Template:Damage=1 "};
               if(dmg1 != "") {damage_flag = damage_flag + "Template:Dmg1flag=1 "};
               if(dmg2 != "") {damage_flag = damage_flag + "Template:Dmg2flag=1 "};
               var crit1 = "";
               if(parsed_dmg1.rolls.length > 0){
                   parsed_dmg1.rolls.forEach(function(value) {
                       crit1 += parsed_dmg1.array[value] + "+";
                   });
                   crit1 = crit1.substring(0, crit1.length - 1);
               }
               var crit2 = "";
               if(parsed_dmg2.rolls.length > 0){
                   parsed_dmg2.rolls.forEach(function(value) {
                       crit2 += parsed_dmg2.array[value] + "+";
                   });
                   crit2 = crit2.substring(0, crit2.length - 1);
               }
               var rollbase = "";
               if(v.dtype === "full") {
                   rollbase = `@{wtype}&{template:npcaction} ${attack_flag} @{damage_flag} @{npc_name_flag} {{rname=@{name}}} {{r1=[[@{d20}+(@{attack_tohit}+0)]]}} @{rtype}+(@{attack_tohit}+0)]]}} {{dmg1=[[@{attack_damage}+0]]}} {{dmg1type=@{attack_damagetype}}} {{dmg2=[[@{attack_damage2}+0]]}} {{dmg2type=@{attack_damagetype2}}} {{crit1=[[@{attack_crit}+0]]}} {{crit2=[[@{attack_crit2}+0]]}} {{description=@{show_desc}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
               }
               else if(v[repvar + actionid + "_attack_flag"] && v[repvar + actionid + "_attack_flag"] != "0") {
                   if(legendary) {
                       rollbase = `@{wtype}&{template:npcatk} ${attack_flag} @{damage_flag} @{npc_name_flag} {{rname=[@{name}](~repeating_npcaction-l_npc_dmg)}} {{rnamec=[@{name}](~repeating_npcaction-l_npc_crit)}} {{type=[Attack](~repeating_npcaction-l_npc_dmg)}} {{typec=[Attack](~repeating_npcaction-l_npc_crit)}} {{r1=[[@{d20}+(@{attack_tohit}+0)]]}} @{rtype}+(@{attack_tohit}+0)]]}} {{description=@{show_desc}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}`
                   }
                   else {
                       rollbase = `@{wtype}&{template:npcatk} ${attack_flag} @{damage_flag} @{npc_name_flag} {{rname=[@{name}](~repeating_npcaction_npc_dmg)}} {{rnamec=[@{name}](~repeating_npcaction_npc_crit)}} {{type=[Attack](~repeating_npcaction_npc_dmg)}} {{typec=[Attack](~repeating_npcaction_npc_crit)}} {{r1=[[@{d20}+(@{attack_tohit}+0)]]}} @{rtype}+(@{attack_tohit}+0)]]}} {{description=@{show_desc}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}`;
                   }
               }
               else if(dmg1 || dmg2) {
                   rollbase = `@{wtype}&{template:npcdmg} @{damage_flag} {{dmg1=[[@{attack_damage}+0]]}} {{dmg1type=@{attack_damagetype}}} {{dmg2=[[@{attack_damage2}+0]]}} {{dmg2type=@{attack_damagetype2}}} {{crit1=[[@{attack_crit}+0]]}} {{crit2=[[@{attack_crit2}+0]]}} @{charname_output} {{licensedsheet=@{licensedsheet}}}`
               }
               else {
                   rollbase = `@{wtype}&{template:npcaction} @{npc_name_flag} {{rname=@{name}}} {{description=@{show_desc}}} @{charname_output} {{licensedsheet=@{licensedsheet}}}`
               }
               update[repvar + actionid + "_attack_tohitrange"] = attack_tohitrange;
               update[repvar + actionid + "_attack_onhit"] = onhit;
               update[repvar + actionid + "_damage_flag"] = damage_flag;
               update[repvar + actionid + "_attack_crit"] = crit1;
               update[repvar + actionid + "_attack_crit2"] = crit2;
               update[repvar + actionid + "_rollbase"] = rollbase;
               setAttrs(update, {silent: true});
           });
       });
   };
   var parse_roll_string = function(rollstring) {
       var out = {array: [], avg: 0, rolls: []};
       if(!rollstring || rollstring === "") {
           return out;
       }
       var rs_regex_initial = /(\-?\d+(?:d\d+)?)/ig;
       var rs_regex_repeating = /([\+\-])(\-?\d+(?:d\d+)?)/ig;
       var rs_nospace = rollstring.replace(/\s/g, );
       var rs_initial = rs_regex_initial.exec(rs_nospace);
       if(rs_initial) {
           out.array.push(rs_initial[1]);
           rs_regex_repeating.lastIndex = rs_regex_initial.lastIndex;
           var rs_repeating;
           while(rs_repeating = rs_regex_repeating.exec(rs_nospace)) {
               out.array.push(rs_repeating[1], rs_repeating[2]);
           }
       }
       var add = true;
       var dice_regex = /(\d+)d(\d+)/i;
       var dice;
       out.array.forEach(function(value, index, array) {
           if(value === "+") {
               add = true;
           } else if(value === "-") {
               add = false;
           } else if(dice = dice_regex.exec(value)){
               // this value is a die roll
               var dice_avg = Math.floor(+dice[1] * (+dice[2] / 2 + 0.5));
               out.avg += add ? dice_avg : -dice_avg;
               out.rolls.push(index);
           } else {
               // this value is a number
               out.avg += add ? +value : -+value;
           }
       })
       return out;
   };
   var get_class_level = function(class_name, callback) {
       getAttrs(["class", "base_level", "multiclass1_flag", "multiclass1", "multiclass1_lvl", "multiclass2_flag", "multiclass2", "multiclass2_lvl", "multiclass3_flag", "multiclass3", "multiclass3_lvl"], function(attrs) {
           var regex = new RegExp(class_name, "i");
           if(regex.test(attrs["class"])) {
               callback(attrs.base_level);
           } else if(attrs.multiclass1_flag && attrs.multiclass1_flag !== "0" && regex.test(attrs.multiclass1)) {
               callback(attrs.multiclass1_lvl);
           } else if(attrs.multiclass2_flag && attrs.multiclass2_flag !== "0" && regex.test(attrs.multiclass2)) {
               callback(attrs.multiclass2_lvl);
           } else if(attrs.multiclass3_flag && attrs.multiclass3_flag !== "0" && regex.test(attrs.multiclass3)) {
               callback(attrs.multiclass3_lvl);
           } else {
               callback("0");
           }
       });
   };
   var update_globaldamage = function(callback) {
       getSectionIDs("damagemod", function(ids) {
           if(ids) {
               var fields = {};
               var attr_name_list = [];
               ids.forEach(function(id) {
                   fields[id] = {};
                   attr_name_list.push(`repeating_damagemod_${id}_global_damage_active_flag`, `repeating_damagemod_${id}_global_damage_name`, `repeating_damagemod_${id}_global_damage_damage`, `repeating_damagemod_${id}_global_damage_type`);
               });
               getAttrs(attr_name_list, function(attrs) {
                   var regex = /^repeating_damagemod_(.+)_global_damage_(active_flag|name|damage|type)$/;
                   _.each(attrs, function(obj, name) {
                       var r = regex.exec(name);
                       if(r) {
                           fields[r[1]][r[2]] = obj;
                       };
                   });
                   var update = {global_damage_mod_roll: "", global_damage_mod_crit: "", global_damage_mod_type: ""};
                   console.log("GLOBALDAMAGE");
                   _.each(fields, function(element) {
                       if(element.active_flag != "0") {
                           if(element.name && element.name !== "") { update["global_damage_mod_roll"] += element.damage + '[' + element.name + ']' + "+"; }
                           if(element.type && element.type !== "") { update["global_damage_mod_type"] += element.type + "/"; }
                       }
                   });
                   update["global_damage_mod_roll"] = update["global_damage_mod_roll"].replace(/\+(?=$)/, );
                   update["global_damage_mod_type"] = update["global_damage_mod_type"].replace(/\/(?=$)/, );
                   // Remove any non-roll damage modifiers from the global damage modifier for the crit rolls
                   // Will also remove any labels attached to these non-roll damage modifiers
                   update["global_damage_mod_crit"] = update["global_damage_mod_roll"].replace(/(?:[+\-*\/%]|\*\*|^)\s*\d+(?:\[.*?])?(?!d\d+)/gi, )
                       // If what was just replace removed the first damage modifier, remove any now precending plus signs
                       .replace(/(?:^\+)/i, );
                   setAttrs(update, {silent:true}, function() {
                       update_attacks("all");
                       if(typeof callback == "function") callback();
                   });
               });
           }
       });
   };
   var update_globalattack = function(callback) {
       getSectionIDs("tohitmod", function(ids) {
           if(ids) {
               var fields = {};
               var attr_name_list = [];
               ids.forEach(function(id) {
                   fields[id] = {};
                   attr_name_list.push(`repeating_tohitmod_${id}_global_attack_active_flag`, `repeating_tohitmod_${id}_global_attack_roll`, `repeating_tohitmod_${id}_global_attack_name`);
               });
               getAttrs(attr_name_list, function(attrs) {
                   var regex = /^repeating_tohitmod_(.+)_global_attack_(active_flag|roll|name)$/;
                   _.each(attrs, function(obj, name) {
                       var r = regex.exec(name);
                       if(r) {
                           fields[r[1]][r[2]] = obj;
                       }
                   });
                   var update = {global_attack_mod: ""};
                   console.log("GLOBALATTACK");
                   _.each(fields, function(element) {
                       if(element.active_flag != "0") {
                           if(element.roll && element.roll !== "") { update["global_attack_mod"] += element.roll + "[" + element.name + "]" + "+"; }
                       }
                   });
                   if(update["global_attack_mod"] !== "") {
                       update["global_attack_mod"] = "[[" + update["global_attack_mod"].replace(/\+(?=$)/, ) + "]]";
                   }
                   setAttrs(update, {silent:true}, function() {
                       if(typeof callback == "function") callback();
                   });
               });
           }
       });
   };
   var update_globalsaves = function(callback) {
       getSectionIDs("savemod", function(ids) {
           if(ids) {
               var fields = {};
               var attr_name_list = [];
               ids.forEach(function(id) {
                   fields[id] = {};
                   attr_name_list.push(`repeating_savemod_${id}_global_save_active_flag`, `repeating_savemod_${id}_global_save_roll`, `repeating_savemod_${id}_global_save_name`);
               });
               getAttrs(attr_name_list, function(attrs) {
                   var regex = /^repeating_savemod_(.+)_global_save_(active_flag|roll|name)$/;
                   _.each(attrs, function(obj, name) {
                       var r = regex.exec(name);
                       if(r) {
                           fields[r[1]][r[2]] = obj;
                       }
                   });
                   var update = {global_save_mod: ""};
                   console.log("GLOBAL SAVES");
                   _.each(fields, function(element) {
                       if(element.active_flag != "0") {
                           if(element.roll && element.roll !== "") { update["global_save_mod"] += element.roll + "[" + element.name + "]" + "+"; }
                       }
                   });
                   if(update["global_save_mod"] !== "") {
                       update["global_save_mod"] = "[[" + update["global_save_mod"].replace(/\+(?=$)/, ) + "]]";
                   }
                   setAttrs(update, {silent:true}, function() {
                       if(typeof callback == "function") callback();
                   });
               });
           }
       });
   };
   var update_globalskills = function(callback) {
       getSectionIDs("skillmod", function(ids) {
           if(ids) {
               var fields = {};
               var attr_name_list = [];
               ids.forEach(function(id) {
                   fields[id] = {};
                   attr_name_list.push(`repeating_skillmod_${id}_global_skill_active_flag`, `repeating_skillmod_${id}_global_skill_roll`, `repeating_skillmod_${id}_global_skill_name`);
               });
               getAttrs(attr_name_list, function(attrs) {
                   var regex = /^repeating_skillmod_(.+)_global_skill_(active_flag|roll|name)$/;
                   _.each(attrs, function(obj, name) {
                       var r = regex.exec(name);
                       if(r) {
                           fields[r[1]][r[2]] = obj;
                       }
                   });
                   var update = {global_skill_mod: ""};
                   console.log("GLOBAL SKILLS");
                   _.each(fields, function(element) {
                       if(element.active_flag != "0") {
                           if(element.roll && element.roll !== "") { update["global_skill_mod"] += element.roll + "[" + element.name + "]" + "+"; }
                       }
                   });
                   if(update["global_skill_mod"] !== "") {
                       update["global_skill_mod"] = "[[" + update["global_skill_mod"].replace(/\+(?=$)/, ) + "]]";
                   }
                   setAttrs(update, {silent:true}, function() {
                       if(typeof callback == "function") callback();
                   });
               });
           }
       });
   };
   var check_l1_mancer = function() {
       getAttrs(["class", "base_level", "strength_base","dexterity_base","constitution_base","intelligence_base","wisdom_base","charisma_base","l1mancer_status","version","charactermancer_step"], function(v) {
           if(!v["version"] || parseFloat(v["version"]) < 2.2) {
               return;
           }
           if(v["l1mancer_status"] && v["l1mancer_status"] === "completed") {
               return;
           }
           if(v["charactermancer_step"] && v["charactermancer_step"].split("-")[0] == "l1") {
               startCharactermancer(v["charactermancer_step"]);
           }
           else {
               if(v["l1mancer_status"] && v["l1mancer_status"] === "relaunch") {
                   startCharactermancer("l1-welcome");
               } else {
                   setAttrs({mancer_confirm_flag: 1});
               }
           }
       });
   };
   var check_lp_mancer = function() {
       getAttrs(["class", "base_level", "strength_base","dexterity_base","constitution_base","intelligence_base","wisdom_base","charisma_base","l1mancer_status", "lpmancer_status","version","charactermancer_step"], function(v) {
           if(v["lpmancer_status"] === "active" && v["charactermancer_step"] && v["charactermancer_step"].split("-")[0] == "lp") {
               startCharactermancer(v["charactermancer_step"]);
           }
       });
   };
   on("mancer:cancel", function(eventinfo) {
       if(!eventinfo["value"]) {return;};
       var update = {};
       if(eventinfo["value"] === "l1-welcome" || eventinfo["value"] === "l1-cancel") {
           update["l1mancer_status"] = "completed";
           update["charactermancer_step"] = "l1-welcome";
           deleteCharmancerData(["l1-welcome","l1-race","l1-class","l1-abilities","l1-background","l1-equipment","l1-spells","l1-summary"]);
       }
       else if(eventinfo["value"].substring(0,3) === "l1-") {
           update["l1mancer_status"] = eventinfo["value"];
       }
       else if(eventinfo["value"] === "lp-welcome" || eventinfo["value"] === "lp-cancel") {
           update["lpmancer_status"] = "";
           update["charactermancer_step"] = "";
           deleteCharmancerData(["lp-welcome", "lp-levels", "lp-choices", "lp-asi", "lp-spells","lp-summary"]);
       }
       else if(eventinfo["value"].substring(0,3) === "lp-") {
           update["charactermancer_step"] = "";
           update["lpmancer_status"] = "";
       };
       setAttrs(update);
   });
   on("change:licensedsheet", function(eventinfo) {
       //debugger
   });
   /* on("sheet:opened", function(eventinfo) {
       getAttrs([licensedsheet], function(v) {
           debugger
       });
   }); */
     var v2_old_values_check = function() {
       // update_attacks("all");
       var update = {};
       var attrs = ["simpletraits","features_and_traits","initiative_bonus","npc","character_id"];
       getSectionIDs("repeating_spell-npc", function(idarray) {
           _.each(idarray, function(id) {
               attrs.push("repeating_spell-npc_" + id + "_rollcontent");
           });
           getAttrs(attrs, function(v) {
               if(v["npc"] && v["npc"] == 1 && (!v["initiative_bonus"] || v["initiative_bonus"] == 0)) {
                   update_initiative();
               }
               var spellflag = idarray && idarray.length > 0 ? 1 : 0;
               var missing = v["features_and_traits"] && v["simpletraits"] === "complex" ? 1 : 0;
               update["npcspell_flag"] = spellflag;
               update["missing_info"] = missing;
               _.each(idarray, function(id) {
                   var content = v["repeating_spell-npc_" + id + "_rollcontent"];
                   if(content.substring(0,3) === "%{-" && content.substring(22,41) === "|repeating_attack_-" && content.substring(60,68) === "_attack}") {
                       var thisid = content.substring(2,21);
                       if(thisid != v["character_id"]) {
                           update["repeating_spell-npc_" + id + "_rollcontent"] = content.substring(0,2) + v["character_id"] + content.substring(22,68);
                       }
                   }
               });
               setAttrs(update);
           });
       });
   };
   var clear_npc_spell_attacks = function(complete) {
       getSectionIDs("repeating_attack", function(attack_ids) {
           var getList = [];
           var done = false;
           _.each(attack_ids, function(id) {
               getList.push(`repeating_attack_${id}_spellid`);
           });
           getAttrs(getList, function(v) {
               _.each(attack_ids, function(id) {
                   if (v[`repeating_attack_${id}_spellid`] && v[`repeating_attack_${id}_spellid`].indexOf("npc_") != -1) {
                       removeRepeatingRow(`repeating_attack_${id}`);
                   }
               });
               complete();
           });
       });
   }
   var upgrade_to_2_0 = function(doneupdating) {
       getAttrs(["npc","strength","dexterity","constitution","intelligence","wisdom","charisma","strength_base","dexterity_base","constitution_base","intelligence_base","wisdom_base","charisma_base","deathsavemod","death_save_mod","npc_str_save","npc_dex_save","npc_con_save","npc_int_save","npc_wis_save","npc_cha_save","npc_str_save_base","npc_dex_save_base","npc_con_save_base","npc_int_save_base","npc_wis_save_base","npc_cha_save_base","npc_acrobatics_base", "npc_animal_handling_base", "npc_arcana_base", "npc_athletics_base", "npc_deception_base", "npc_history_base", "npc_insight_base", "npc_intimidation_base", "npc_investigation_base", "npc_medicine_base", "npc_nature_base", "npc_perception_base", "npc_performance_base", "npc_persuasion_base", "npc_religion_base", "npc_sleight_of_hand_base", "npc_stealth_base", "npc_survival_base", "npc_acrobatics", "npc_animal_handling", "npc_arcana", "npc_athletics", "npc_deception", "npc_history", "npc_insight", "npc_intimidation", "npc_investigation", "npc_medicine", "npc_nature", "npc_perception", "npc_performance", "npc_persuasion", "npc_religion", "npc_sleight_of_hand", "npc_stealth", "npc_survival"], function(v) {
           var update = {};
           var stats = ["strength","dexterity","constitution","intelligence","wisdom","charisma"];
           var npc_stats = ["npc_str_save","npc_dex_save","npc_con_save","npc_int_save","npc_wis_save","npc_cha_save","npc_acrobatics", "npc_animal_handling", "npc_arcana", "npc_athletics", "npc_deception", "npc_history", "npc_insight", "npc_intimidation", "npc_investigation", "npc_medicine", "npc_nature", "npc_perception", "npc_performance", "npc_persuasion", "npc_religion", "npc_sleight_of_hand", "npc_stealth", "npc_survival"];
           _.each(stats, function(attr) {
               if(v[attr] && v[attr] != "10" && v[attr + "_base"] == "10") {
                   update[attr + "_base"] = v[attr];
               }
           });
           _.each(npc_stats, function(attr) {
               if(v[attr] && !isNaN(v[attr]) && v[attr + "_base"] == "") {
                   update[attr + "_base"] = v[attr];
               }
           });
           if(v["deathsavemod"] && v["deathsavemod"] != "0" && v["death_save_mod"] === "0") {v["death_save_mod"] = v["deathsavemod"];};
           if(v["npc"] && v["npc"] == "1") {
               var callback = function() {
                   update_attr("all");
                   update_mod("strength");
                   update_mod("dexterity");
                   update_mod("constitution");
                   update_mod("intelligence");
                   update_mod("wisdom");
                   update_mod("charisma");
                   update_npc_action("all");
                   update_npc_saves();
                   update_npc_skills();
                   update_initiative();
               }
           }
           else {
               var callback = function() {
                   update_attr("all");
                   update_mod("strength");
                   update_mod("dexterity");
                   update_mod("constitution");
                   update_mod("intelligence");
                   update_mod("wisdom");
                   update_mod("charisma");
                   update_all_saves();
                   update_skills(["athletics", "acrobatics", "sleight_of_hand", "stealth", "arcana", "history", "investigation", "nature", "religion", "animal_handling", "insight", "medicine", "perception", "survival","deception", "intimidation", "performance", "persuasion"]);
                   update_tool("all")
                   update_attacks("all");
                   update_pb();
                   update_jack_attr();
                   update_initiative();
                   update_weight();
                   update_spell_info();
                   update_ac();
               }
           }
           setAttrs(update, {silent: true}, callback);
           doneupdating();
       });
   };
   var upgrade_to_2_1 = function(doneupdating) {
       v2_old_values_check();
       doneupdating();
   };
   var upgrade_to_2_2 = function(doneupdating) {
       setAttrs({l1mancer_status: "completed"}, function(eventinfo) {
           setAttrs({"options-class-selection":"0"});
           console.log("Preprocessed v2.2 upgrade");
           update_tool("all");
           update_attacks("all");
           update_class();
           update_race_display();
           doneupdating();
       });
   };
   var upgrade_to_2_3 = function(doneupdating) {
       getSectionIDs("damagemod", function(ids) {
           var update = {};
           _.each(ids, function(rowid) {
               update[`repeating_damagemod_${rowid}_options-flag`] = "0";
           });
           getSectionIDs("tohitmod", function(ids) {
               _.each(ids, function(rowid) {
                   update[`repeating_tohitmod_${rowid}_options-flag`] = "0";
               });
               setAttrs(update);
               doneupdating();
           });
       });
   };
   var upgrade_to_2_4 = function(doneupdating) {
       clear_npc_spell_attacks(function() {
           update_globalskills(function() {
               update_globalsaves(function() {
                   update_globalattack(function() {
                       update_globaldamage(function() {
                           getAttrs(["npc", "npcspellcastingflag", "spellcasting_ability", "caster_level", "level_calculations"], function(v) {
                               if(v.npc == "1" && v.npcspellcastingflag == "1") {
                                   getSectionIDs("npctrait", function(secIds) {
                                       var getList = [];
                                       _.each(secIds, function(x) {
                                           getList.push("repeating_npctrait_" + x + "_name");
                                           getList.push("repeating_npctrait_" + x + "_desc");
                                       });
                                       getAttrs(getList, function(traits) {
                                           var update = {};
                                           if(v.spellcasting_ability == "0*" || v.caster_level == "0") {
                                               var spellSec = "";
                                               if (v.spellcasting_ability == "0*") {
                                                   update.spellcasting_ability = "@{intelligence_mod}+";
                                               }
                                               _.each(secIds, function(traitId) {
                                                   if(traits["repeating_npctrait_" + traitId + "_name"].toLowerCase().includes("spellcasting.")) spellSec = traitId;
                                               });
                                               if(spellSec  != "") {
                                                   var spellcasting = traits["repeating_npctrait_" + spellSec + "_desc"].toLowerCase();
                                                   if (v.spellcasting_ability == "0*") {
                                                       var lastIndex = 9999;
                                                       _.each(["intelligence", "wisdom", "charisma"], function(ability) {
                                                           var found = spellcasting.indexOf(ability);
                                                           if(found > -1 && found < lastIndex) {
                                                               lastIndex = found;
                                                               update.spellcasting_ability = "@{" + ability + "_mod}+";
                                                           }
                                                       });
                                                   }
                                                   if (v.caster_level == "0") {
                                                       var foundLevelidx = spellcasting.search(/(\d|\d\d)(st|nd|rd|th)/);
                                                       if (foundLevelidx) {
                                                           var level = parseInt(spellcasting.substring(foundLevelidx, foundLevelidx+4));
                                                           console.log(`Found spellcasting level ${level} in trait, setting caster_level...`);
                                                           update.caster_level = level;
                                                       }
                                                   }
                                               }
                                           }
                                           setAttrs(update, function() {
                                               // Recalculate spell slots in case NPC level was restored
                                               if(!v["level_calculations"] || v["level_calculations"] == "on") {
                                                   update_spell_slots();
                                               };
                                               // Set all spells without a given modifier to 'spell'
                                               var spgetList = [];
                                               getSectionIDs("spell-cantrip", function(secIds0) {
                                                   _.each(secIds0, function(x) {
                                                       spgetList.push("repeating_spell-cantrip_" + x + "_spell_ability");
                                                   });
                                                   getSectionIDs("spell-1", function(secIds1) {
                                                       _.each(secIds1, function(x) {
                                                           spgetList.push("repeating_spell-1_" + x + "_spell_ability");
                                                       });
                                                       getSectionIDs("spell-2", function(secIds2) {
                                                           _.each(secIds2, function(x) {
                                                               spgetList.push("repeating_spell-2_" + x + "_spell_ability");
                                                           });
                                                           getSectionIDs("spell-3", function(secIds3) {
                                                               _.each(secIds3, function(x) {
                                                                   spgetList.push("repeating_spell-3_" + x + "_spell_ability");
                                                               });
                                                               getSectionIDs("spell-4", function(secIds4) {
                                                                   _.each(secIds4, function(x) {
                                                                       spgetList.push("repeating_spell-4_" + x + "_spell_ability");
                                                                   });
                                                                   getSectionIDs("spell-5", function(secIds5) {
                                                                       _.each(secIds5, function(x) {
                                                                           spgetList.push("repeating_spell-5_" + x + "_spell_ability");
                                                                       });
                                                                       getSectionIDs("spell-6", function(secIds6) {
                                                                           _.each(secIds6, function(x) {
                                                                               spgetList.push("repeating_spell-6_" + x + "_spell_ability");
                                                                           });
                                                                           getSectionIDs("spell-7", function(secIds7) {
                                                                               _.each(secIds7, function(x) {
                                                                                   spgetList.push("repeating_spell-7_" + x + "_spell_ability");
                                                                               });
                                                                               getSectionIDs("spell-8", function(secIds8) {
                                                                                   _.each(secIds8, function(x) {
                                                                                       spgetList.push("repeating_spell-8_" + x + "_spell_ability");
                                                                                   });
                                                                                   getSectionIDs("spell-9", function(secIds9) {
                                                                                       _.each(secIds9, function(x) {
                                                                                           spgetList.push("repeating_spell-9_" + x + "_spell_ability");
                                                                                       });
                                                                                       getAttrs(spgetList, function(spellAbilities) {
                                                                                           spupdate = {};
                                                                                           _.each(spellAbilities, function(ability, attributeName) {
                                                                                               if (ability == "0*") {
                                                                                                   console.log("UPDATING SPELL: " + attributeName);
                                                                                                   spupdate[attributeName] = "spell";
                                                                                               }
                                                                                           });
                                                                                           setAttrs(spupdate, function() {
                                                                                               update_attacks("spells");
                                                                                               update_challenge();
                                                                                               doneupdating();
                                                                                           });
                                                                                       });
                                                                                   });
                                                                               });
                                                                           });
                                                                       });
                                                                   });
                                                               });
                                                           });
                                                       });
                                                   });
                                               });
                                           });
                                       });
                                   });
                               } else if(v.npc != "1") {
                                   doneupdating();
                               } else {
                                   doneupdating();
                               }
                           });
                       });
                   });
               });
           });
       });
   };
   var upgrade_to_2_5 = function(doneupdating) {
       getAttrs(["globalacmod"], function(v) {
           var update = {};
           if(v.globalacmod && v.globalacmod != "0") {
               var rowid = generateRowID();
               update[`repeating_acmod_${rowid}_global_ac_val`] = parseInt(v.globalacmod);
               update[`repeating_acmod_${rowid}_global_ac_name`] = "GLOBAL ARMOR CLASS MODIFIER";
               update[`repeating_acmod_${rowid}_global_ac_active_flag`] = "1";
               update[`repeating_acmod_${rowid}_options-flag`] = "0";
               update["global_ac_mod_flag"] = "1";
           }
           setAttrs(update, {silent: true}, function() {
               update_ac();
               doneupdating();
           });
       });
   };
   var upgrade_to_2_6 = function(doneupdating) {
       getSectionIDs("hpmod", function(ids) {
           var getArray = [];
           _.each(ids, function(sectionid) {
               getArray.push("repeating_hpmod_" + sectionid + "_source");
           });
           getAttrs(getArray, function(v) {
               _.each(v, function(val, key) {
                   if(val === "CON") removeRepeatingRow("repeating_hpmod_" + key.split("_")[2]);
               });
               doneupdating();
           });
       });
   };
   var upgrade_to_2_7 = function(doneupdating) {
       getSectionIDs("damagemod", function(ids) {
           console.log("Version 2.7 UPGRADE");
           let getArray = [];
           ids.forEach(sectionid => {
               getArray.push(`repeating_damagemod_${sectionid}_global_damage_rollstring`);
               getArray.push(`repeating_damagemod_${sectionid}_global_damage_type`);
           });
           getSectionIDs("savemod", function(ids) {
               _.each(ids, (sectionid) => {
                   getArray.push(`repeating_savemod_${sectionid}_global_save_rollstring`);
               });
               getSectionIDs("tohitmod", function(ids) {
                   _.each(ids, (sectionid) => {
                       getArray.push(`repeating_tohitmod_${sectionid}_global_attack_rollstring`);
                   });
                   getSectionIDs("skillmod", function(ids) {
                       _.each(ids, (sectionid) => {
                           getArray.push(`repeating_skillmod_${sectionid}_global_skill_rollstring`);
                       });
                       getAttrs(getArray, function(v) {
                           let set = {};
                           _.each(v, (value, attr) => {
                               if(_.last(attr.split("_")) === "rollstring") {
                                   const section = attr.slice(0, -10);
                                   const brackets = value.split('['), roll = brackets[0];
                                   let name = brackets[1] ? brackets[1].slice(0, -1) : "";
                                   if(attr.split("_")[1] == "damagemod") {
                                       name = name ? name : v[`${section}type`];
                                       set[`${section}damage`] = roll;
                                   } else {
                                       set[`${section}roll`] = roll;
                                   }
                                   set[`${section}name`] = name;
                               }
                           });
                           setAttrs(set);
                           doneupdating();
                       });
                   });
               });
           });
       });
   };
   var no_version_bugfix = function(doneupdating) {
       getAttrs(["npc","class"], function(v) {
           if(v["npc"] && v["npc"] != "0" || v["class"] && v["class"] != "") {
               setAttrs({version: "2.1"});
           }
           else {
               setAttrs({version: "2.3"}, {silent: true});
           }
       });
       doneupdating();
   };
   var versioning = function(finished) {
       getAttrs(["version"], function(v) {
           const version = parseFloat(v["version"]) || 0.0;
           if(version >=  "2.7") {
               setAttrs({version: "2.7"}, function(){
                   finished();
               });
               console.log("5th Edition OGL by Roll20 v" + v["version"]);
               return;
           }
           else if(!version || version === "") {
               console.log("NO VERSION FOUND");
               no_version_bugfix(function() {
                   versioning(finished);
               });
           }
           else if(version >= "2.6") {
               console.log("UPGRADING TO v2.7");
               upgrade_to_2_7(function() {
                   setAttrs({version: "2.7"}, function() {
                       versioning(finished);
                   });
               });
           }
           else if(version >= "2.5") {
               console.log("UPGRADING TO v2.6");
               upgrade_to_2_6(function() {
                   setAttrs({version: "2.6"}, function() {
                       versioning(finished);
                   });
               });
           }
           else if(version >= "2.4") {
               console.log("UPGRADING TO v2.5");
               upgrade_to_2_5(function() {
                   setAttrs({version: "2.5"}, function() {
                       versioning(finished);
                   });
               });
           }
           else if(version >= "2.3") {
               console.log("UPGRADING TO v2.4");
               upgrade_to_2_4(function() {
                   setAttrs({version: "2.4"}, function() {
                       versioning(finished);
                   });
               });
           }
           else if(version >= "2.2") {
               console.log("UPGRADING TO v2.3");
               upgrade_to_2_3(function() {
                   setAttrs({version: "2.3"}, function() {
                       versioning(finished);
                   });
               });
           }
           else if(version >= "2.1") {
               console.log("UPGRADING TO v2.2");
               upgrade_to_2_2(function() {
                   setAttrs({version: "2.2"}, function() {
                       versioning(finished);
                   });
               });
           }
           else if(version >= "2.0") {
               console.log("UPGRADING TO v2.1");
               upgrade_to_2_1(function() {
                   setAttrs({version: "2.1"}, function() {
                       versioning(finished);
                   });
               });
           }
           else {
               console.log("UPGRADING TO v2.0");
               upgrade_to_2_0(function() {
                   setAttrs({version: "2.0"}, function() {
                       versioning(finished);
                   });
               });
           };
       });
   };
   /*********************************************************************/
   /*********************************************************************/
   /******                                                         ******/
   /******                 CHARACTERMANCER WORKERS                 ******/
   /******                                                         ******/
   /*********************************************************************/
   /*********************************************************************/
   var proficiencyList = ["Weapon", "Armor", "Skill", "Tool", "Language"];
   var abilityList = ["Strength", "Dexterity", "Constitution", "Intelligence", "Wisdom", "Charisma"];
   var changeListeners = "mancerchange:race_ability_choice1 mancerchange:race_ability_choice2 mancerchange:subrace_ability_choice1 mancerchange:subrace_ability_choice2 mancerchange:custom_hit_die mancerchange:feat_ability_choice";
   var proficiencyNum = 4;
   var customListeners = "";
   _.each(abilityList, function(ability){
       changeListeners += " mancerchange:race_custom_" + ability.toLowerCase();
       changeListeners += " mancerchange:subrace_custom_" + ability.toLowerCase();
   });
   /* HELPER FUNCTIONS */
   var recalcData = function(data) {
       //Sets all the text in the top bar, returns ability information
       var update = {"hit_points": "-"};
       var allAbilities = {race: {}, subrace: {}, feat: {}};
       var disableAbilities = {race: [], subrace: [], feat: []};
       var allProficiencies = {};
       var toSet = {};
       var mancerdata = data || getCharmancerData();
       var additionalHP = 0;
       if(mancerdata["l1-class"] && mancerdata["l1-class"].data.class && mancerdata["l1-class"].data.class["Suggested Abilities"]) {
           update["class_suggested_abilities"] = mancerdata["l1-class"].data.class["Suggested Abilities"];
           showChoices(["class_suggested_abilities_container"]);
       } else {
           update["class_suggested_abilities"] = "";
           hideChoices(["class_suggested_abilities_container"]);
       }
       if(mancerdata["l1-class"] && mancerdata["l1-class"].data.class && mancerdata["l1-class"].data.class["Spellcasting Ability"]) {
           update["class_spellcasting_ability"] = mancerdata["l1-class"].data.class["Spellcasting Ability"];
           showChoices(["class_spellcasting_ability_container"]);
       } else {
           update["class_spellcasting_ability"] = "";
           hideChoices(["class_spellcasting_ability_container"]);
       }
       _.each(mancerdata, function(page){
           _.each(page.values, function(value, name) {
               if(name.search("ability") !== -1) {
                   var choiceSection = name.split("_")[0];
                   if(page.data[choiceSection] && page.data[choiceSection]["data-Ability Score Choice"]) {
                       var increase = 1;
                       if(typeof page.data[choiceSection]["data-Ability Score Choice"] == "string") {
                           increase = parseInt( _.last( page.data[choiceSection]["data-Ability Score Choice"].split("+") ) );
                       }
                       allAbilities[choiceSection] = allAbilities[choiceSection] || {};
                       allAbilities[choiceSection][value.toLowerCase()] = increase;
                       disableAbilities[choiceSection] = disableAbilities[choiceSection] || [];
                       disableAbilities[choiceSection].push(value);
                   }
               }
           });
           _.each(page.data, function(pagedata, increaseSection) {
               if(pagedata["data-Ability Score Increase"]) {
                   _.each(pagedata["data-Ability Score Increase"], function(amount, ability) {
                       allAbilities[increaseSection] = allAbilities[increaseSection] || {};
                       allAbilities[increaseSection][ability.toLowerCase()] = amount;
                       disableAbilities[increaseSection] = disableAbilities[increaseSection] || [];
                       disableAbilities[increaseSection].push(ability.toLowerCase());
                   });
               }
               //TODO: Investigate if additional hitpoits at first level could be calculated and interted at this point
               //By Miguel
               if(pagedata["data-HP per level"]) {
                   additionalHP += pagedata["data-HP per level"];
               }
           });
       });
       if(mancerdata["l1-race"] && mancerdata["l1-race"].values.race == "Rules:Races") {
           _.each(abilityList, function(ability){
               var custom = mancerdata["l1-race"].values["race_custom_" + ability.toLowerCase()] || false;
               if(custom) {
                   allAbilities.race[ability.toLowerCase()] = parseInt(custom);
               }
           });
       }
       if(mancerdata["l1-race"] && mancerdata["l1-race"].values.subrace == "Rules:Races") {
           _.each(abilityList, function(ability){
               var custom = mancerdata["l1-race"].values["subrace_custom_" + ability.toLowerCase()] || false;
               if(custom) {
                   allAbilities.subrace[ability.toLowerCase()] = parseInt(custom);
               }
           });
       }
       var abilityTotals = {};
       _.each(allAbilities, function(abilities) {
           _.each(abilities, function(amount, ability) {
               abilityTotals[ability] = abilityTotals[ability] || {bonus: 0};
               abilityTotals[ability].bonus += parseInt(amount);
           });
       });
       _.each(abilityList, function(upperAbility) {
           var ability = upperAbility.toLowerCase();
           abilityTotals[ability] = abilityTotals[ability] || {bonus: 0, mod: 0};
           if(mancerdata["l1-abilities"] && mancerdata["l1-abilities"].values[ability]) {
               abilityTotals[ability].base = parseInt( mancerdata["l1-abilities"].values[ability].split("~")[0] );
           } else {
               abilityTotals[ability].base = 0;
           }
           abilityTotals[ability].total = abilityTotals[ability].bonus + abilityTotals[ability].base;
           abilityTotals[ability].mod = Math.floor((abilityTotals[ability].total - 10)/2);
           update[ability + "_total"] = abilityTotals[ability].total == 0 ? "-" : abilityTotals[ability].total;
       });
       allAbilities.totals = abilityTotals;
       if(mancerdata["l1-class"] && (mancerdata["l1-class"].data.class || mancerdata["l1-class"].values["custom_hit_die"])) {
           var basehp = mancerdata["l1-class"].data.class ? mancerdata["l1-class"].data.class["Hit Die"] : mancerdata["l1-class"].values["custom_hit_die"];
           var conmod = abilityTotals.constitution.base > 0 ? abilityTotals.constitution.mod : 0;
           //Calculating additional hitpoints at first level from things like Draconic Bloodline ad Hill Dwarf
           //By Miguel
           let additionalHitPointsFromClassAndRaceAtFirstLevel = getAdditionalHitPointsFromClassAndRaceAtFirstLevel(getRelevantBlobs(mancerdata, '1', 'l1'));
           allAbilities.hp = parseInt(basehp.replace("d", "")) + additionalHitPointsFromClassAndRaceAtFirstLevel + additionalHP + conmod;
           update["hit_points"] = allAbilities.hp;
       }
       if(!data) {
           _.each(disableAbilities, function(disable, disablesection) {
               disableCharmancerOptions(disablesection + "_ability_choice1", disable);
               disableCharmancerOptions(disablesection + "_ability_choice2", disable);
           });
           setCharmancerText(update);
           setAttrs(toSet);
       }
       return allAbilities;
   };
   var getProficiencies = function(data, currentSlide, blobs) {
       //Disables taken proficiency choices, returns proficiency info
       var auto = {};
       var allProficiencies = {"Weapon": [], "Armor": [], "Skill": [], "Tool": [], "Language": [], "Expertise": []};
       var toSet = {};
       var mancerdata = data || getCharmancerData();
       var thismancer = currentSlide && currentSlide != "finish" ? currentSlide.split("-")[0] : "l1";
       if(!blobs) {
           blobs = thismancer == "l1" ? blobs = getRelevantBlobs(mancerdata, "1", "l1") : blobs = getAllLpBlobs(data, true);
       }
       if(thismancer !== "l1") allProficiencies = data["lp-welcome"].values["previous_proficiencies"] ? JSON.parse(data["lp-welcome"].values["previous_proficiencies"]) : allProficiencies;
       currentSlide = currentSlide == "lp-finish" ? "finish" : currentSlide;
       //For this first part, we're only concerned with choices that have already been made
       //Get all of the "automatic" proficiencies
       _.each(blobs.sorted, function(blobarray, section) {
           _.each(blobarray, function(blob) {
               _.each(proficiencyList, function(prof) {
                   if(blob[prof + " Proficiency"]) {
                       var json = JSON.parse(blob[prof + " Proficiency"]);
                       if(json.Proficiencies) {
                           auto[section] = auto[section] ? auto[section].concat(json.Proficiencies) : json.Proficiencies;
                           allProficiencies[prof] = allProficiencies[prof].concat(json.Proficiencies);
                       }
                   }
               });
               if(blob.Expertise) {
                   var json = JSON.parse(blob.Expertise);
                   if(json.Proficiencies) {
                       allProficiencies.Expertise = allProficiencies.Expertise.concat(json.Proficiencies);
                   }
               }
           });
       });
       //Gather all of the chosen proficiencies
       _.each(mancerdata, function(slide, slidename) {
           if(slidename.split("-")[0] == thismancer) {
               _.each(proficiencyList, function(prof) {
                   _.each(slide.values, function(value, name) {
                       if(name.split("_")[3] == prof.toLowerCase() && name.split("_")[4] == "choice") {
                           if(value != "custom") allProficiencies[prof].push(value.split(":")[1]);
                       }
                   });
               });
               //Get a list of chosen expertise
               _.each(slide.values, function(value, name) {
                   if(name.substr(-16) == "expertise_choice") {
                       allProficiencies.Expertise.push(value.split(":")[1]);
                   }
               });
           }
       });
       //Gather proficiencies from custom choices
       _.each(mancerdata, function(slide, slidename) {
           if(slidename.split("-")[0] == thismancer) {
               _.each(slide.values, function(value, name) {
                   if(name.substr(-18) == "proficiency_choice") {
                       if(value != "custom") allProficiencies[slide.values[name.replace("choice", "type")]].push(value.split(":")[1]);
                   }
               });
           }
       });
       //If the expertise choice is from the "known" list, make sure the choice is still available
       //Reset to "" if not available. Don't do this if we're applying changes
       if(currentSlide != "finish") {
           _.each(mancerdata, function(slide, slidename) {
               if(slidename.split("-")[0] == thismancer) {
                   _.each(slide.values, function(value, name) {
                       if(name.substr(-16) == "expertise_choice" && slide.values[name.replace("choice", "info")]) {
                           if(!(allProficiencies.Skill.includes(value.split(":")[1]) || allProficiencies.Tool.includes(value.split(":")[1]))) {
                               toSet[name] = "";
                           }
                       }
                   });
               }
           });
           setAttrs(toSet);
       }
       if(currentSlide && currentSlide != "finish") {
           //Now we need to know all of the selects, even if a choice hasn't been made
           //Getting a list of all the relevant selects
           var repsecs = {"Weapon": [], "Armor": [], "Skill": [], "Tool": [], "Language": []};
           var repexp = [];
           _.each(mancerdata[currentSlide].repeating, function(id) {
               _.each(proficiencyList, function(prof) {
                   if(_.last(id.split("_")) == prof.toLowerCase()) repsecs[prof].push(id);
               });
               if(_.last(id.split("_")) == "expertise") repexp.push(id);
               if(_.last(id.split("_")) == "proficiency") {
                   if (mancerdata[currentSlide].values[id + "_type"]) repsecs[mancerdata[currentSlide].values[id + "_type"]].push(id);
               }
           })
           //Disable already chosen proficiencies
           _.each(proficiencyList, function(prof) {
               _.each(repsecs[prof], function(id) {
                   disableCharmancerOptions(id + "_choice", allProficiencies[prof], {category: "Proficiencies"});
               });
           });
           //Disable already chosen expertise, rebuild options if choice is from "known" list
           _.each(repexp, function(id) {
               if(mancerdata[currentSlide].values[id + "_info"]) {
                   var choices = allProficiencies.Skill;
                   var options = JSON.parse(mancerdata[currentSlide].values[id + "_info"]);
                   var settings = {category: "Proficiencies", disable: allProficiencies.Expertise, silent: true};
                   options.shift();
                   settings.add = options;
                   setCharmancerOptions(id + "_choice", choices, settings);
               } else {
                   disableCharmancerOptions(id + "_choice", allProficiencies.Expertise, {category: "Proficiencies"});
               }
           });
       };
       _.each(allProficiencies, function(section, name) {
           allProficiencies[name] = _.without(section, "");
       });
       return({auto: auto, all: allProficiencies});
   };
   var handleAbilities = function(data, section) {
       var showList = [];
       if(data["data-Ability Score Increase"]) {
           showList.push(section + "_abilities");
       }
       if(data["data-Ability Score Choice"]) {
           showList.push(section + "_abilities");
           showList.push(section + "_ability_choice1");
           if(data["data-Ability Score Choice"].split("+")[0] == "2") {
               showList.push(section + "_ability_choice2");
           }
       };
       return showList;
   };
   var knownSpells = function(data) {
       var mancerdata = data ? data : getCharmancerData();
       var allSpells = {
           race: false,
           class: false,
           known: [],
           all: [],
           errors: {class: [], race: []}
       };
       var stats = recalcData(data); //since this can get called in the finish step, make sure it doesn't call setAttrs()
       var racename = getName("race", mancerdata, true);
       var subracename = getName("subrace", mancerdata, true);
       var classname = getName("class", mancerdata, true);
       var subclassname = getName("subclass", mancerdata, true);
       var classAbility = mancerdata["l1-class"] && mancerdata["l1-class"].data.class && mancerdata["l1-class"].data.class["Spellcasting Ability"] ? mancerdata["l1-class"].data.class["Spellcasting Ability"] : "";
       var expandedList = {};
       var additionalList = {};
       var blobs = getRelevantBlobs(mancerdata, "1", "l1");
       //First look through all Blobs for any blob.Spells
       _.each(blobs.all, function(blob) {
           if(blob.Spells) {
               var spells = JSON.parse(blob.Spells);
               //Examine each spell to determine if it is "Extended List". "Extended List" adds to the classes spell list.
               //Ravnica Guilds backgrounds such as Dimir Operative are examples of this
               _.each(spells, function(spell) {
                   if(spell["Expanded List"]) {
                       expandedList[spell.Level] = expandedList[spell.Level] ? expandedList[spell.Level].concat(spell["Expanded List"]) : spell["Expanded List"];
                   }
               });
           }
       });
       //Look through blobs.sorted.
       _.each(blobs.sorted, function(sectionblobs, section) {
           //Subclass needs to be changed to class.
           var parentsection = section.replace("sub", "");
           additionalList[parentsection] = additionalList[parentsection] || []
           //Examine eaach blob for "Additional Spell List"
           _.each(sectionblobs, function(blob) {
               if(blob["Additional Spell List"]) {
                   additionalList[parentsection].push(blob["Additional Spell List"]);
               }
           });
       });
       //Process spell data from blobs
       _.each(blobs.sorted, function(sectionblobs, section) {
           var parentsection = section.replace("sub", "");
           _.each(sectionblobs, function(blob) {
               //Looks through the blobs for Spells attribute
               //class.Spells contains the information for how many spells are choosen at each level & Prepared spells to be selected based on ability modifer + 1
               //[subclass, background, race}.Spells will contain KNOWN, CHOSEN, or EXPANDED LIST for extra spells granted by these sections
               if(blob.Spells) {
                   var spells = JSON.parse(blob.Spells);
                   allSpells[parentsection] = allSpells[parentsection] || {known: [], choices: []}
                   _.each(spells, function(spell) {
                       var numSpells = 0;
                       expandedList[spell.Level] = expandedList[spell.Level] || [];
                       //class.Spells will contain Prepared and Choose.
                       //These are used to populate the number of selects needed for each spell lists on the Spells slide
                       if(spell.Prepared) {
                           numSpells = Math.max(stats.totals[spell.Prepared.split("+")[0].toLowerCase()].mod, 0) + parseInt(spell.Prepared.split("+")[1]);
                       }
                       if(spell.Choose) {
                           numSpells = parseInt(spell.Choose);
                       }
                       //If Spells are to be Chosen or Prepared add them to a class list, expand the list, and set the Ability modifier & Level
                       if(numSpells > 0) {
                           _.times(numSpells, function(n) {
                               var thisspell = {Level: parseInt(spell.Level)};
                               thisspell.List = spell.List ? spell.List : classname;
                               thisspell.AddList = additionalList[parentsection];
                               thisspell.Ability = spell.Ability ? spell.Ability : classAbility;
                               if(parentsection == "class") thisspell["Expanded List"] = expandedList[spell.Level];
                               allSpells[parentsection].choices.push(thisspell);
                           });
                       }
                       //Add any spells that are already known from sections such as Forge Domain Cleric starts with identify & searing smite
                       _.each(spell.Known, function(known) {
                           var thisspell = {Name: known, Level: parseInt(spell.Level)};
                           thisspell.Ability = spell.Ability ? spell.Ability : classAbility;
                           thisspell.Source = parentsection;
                           allSpells[parentsection].known.push(thisspell);
                           allSpells.known.push(known);
                           allSpells.all.push(thisspell);
                       });
                   });
               }
           });
       });
       //Collect custom race/subrace spells
       if(mancerdata["l1-race"] && mancerdata["l1-race"].values.custom_race_spell_ability) {
           var raceAbility = mancerdata["l1-race"].values.custom_race_spell_ability;
           var numSpells = mancerdata["l1-race"].values.custom_race_spell_number;
           var spellList = mancerdata["l1-race"].values.custom_race_spell_list;
           if(spellList) {
               allSpells.race = allSpells.race || {known: [], choices: []}
               for(var x=1; x<=numSpells; x++) {
                   var thisSpell = {
                       Ability: raceAbility,
                       Level: 0,
                       List: spellList
                   };
                   allSpells.race.choices.push(thisSpell);
               }
           } else {
               allSpells.errors.race.push("custom_race_spell_list");
           }
       }
       //Collect custom class spells
       if(mancerdata["l1-class"] && mancerdata["l1-class"].values.custom_class_spell_ability) {
           var customAbility = mancerdata["l1-class"].values.custom_class_spell_ability;
           var customList = mancerdata["l1-class"].values.custom_class_spell_list;
           var customSpells = {"0": mancerdata["l1-class"].values.custom_class_cantrip_number, "1": mancerdata["l1-class"].values.custom_class_spell_number};
           if(customList && (customSpells["0"] > 0 || customSpells["1"] > 0)) {
               allSpells.class = allSpells.class || {known: [], choices: []}
               _.each(customSpells, function(number, level) {
                   for(var x=1; x<=number; x++) {
                       var thisSpell = {
                           Ability: customAbility,
                           Level: level,
                           List: customList
                       };
                       allSpells.class.choices.push(thisSpell);
                   }
               });
           } else {
               allSpells.errors.class.push("custom_class_spell_list");
               allSpells.errors.class.push("custom_class_spell_number");
           }
       }
       //Collect custom subclass spells
       if(mancerdata["l1-class"] && mancerdata["l1-class"].values.subclass == "Rules:Classes") {
           var customSpells = {"0": mancerdata["l1-class"].values.custom_subclass_cantrip_number, "1": mancerdata["l1-class"].values.custom_subclass_spell_number};
           if(customSpells["0"] > 0 || customSpells["1"] > 0) {
               allSpells.class = allSpells.class || {known: [], choices: []}
               _.each(customSpells, function(number, level) {
                   var customList = classname.toLowerCase();
                   if(level == "0" && mancerdata["l1-class"].values.custom_subclass_cantrip_list) customList = mancerdata["l1-class"].values.custom_subclass_cantrip_list;
                   if(level == "1" && mancerdata["l1-class"].values.custom_subclass_spell_list) customList = mancerdata["l1-class"].values.custom_subclass_spell_list;
                   for(var x=1; x<=number; x++) {
                       var thisSpell = {
                           Ability: classAbility,
                           Level: level,
                           List: customList
                       };
                       allSpells.class.choices.push(thisSpell);
                   }
               });
           }
       }
       //Collect data from choices
       if(mancerdata["l1-spells"]) {
           _.each(mancerdata["l1-spells"].repeating, function(id) {
               if(mancerdata["l1-spells"].values[id + "_choice"]) {
                   var thisspell = {Name: mancerdata["l1-spells"].values[id + "_choice"].substring(7)};
                   thisspell.Ability = mancerdata["l1-spells"].values[id + "_info"] ? mancerdata["l1-spells"].values[id + "_info"] : classAbility;
                   if(mancerdata["l1-spells"].values[id + "_custom"]) thisspell.Source = mancerdata["l1-spells"].values[id + "_custom"];
                   allSpells.known.push(thisspell.Name);
                   allSpells.all.push(thisspell);
               };
           });
       }
       return allSpells;
   };
   var cleanEquipment = function(equipment) {
       var current_string = "(";
       var hasDouble = false;
       var firstItem = true;
       _.each(equipment, function(item) {
           if (item.search("~DBL") != -1) {
               hasDouble = true;
               item.replace("~DBL","");
           }
           item = item.replace(/"Item Type":(.|)Weapon.*\b/g, "Any Weapon");
           item = item.replace(/Subtype:(.|)Martial.*\b("|)/g, "Any Martial Weapon");
           item = item.replace(/Subtype:(.|)Simple.*\b("|)/g, "Any Simple Weapon");
           item = item.replace(/Subtype:(.|)Artisan's Tools.*\b("|)/g, "A Set of Artisan's Tools");
           item = item.replace(/Subtype:(.|)Gaming Set.*\b("|)/g, "A Gaming Set");
           item = item.replace(/Subtype:(.|)Musical Instrument.*\b("|)/g, "A Musical Instrument");
           if (!firstItem) current_string += " or ";
           current_string += item;
           firstItem = false;
       });
       current_string += ")";
       if (hasDouble) {
           current_string = "two of " + current_string;
       }
       return current_string.replace(/,/g, ", ");
   };
   const removeExpansionInfo = function(text) {
     return text.replace(/\??expansion\=([0-9]+)?/gi, "");
   };
   var removeDuplicatedPageData = function(data) {
      if(!Array.isArray(data)) return data;
      const getPageName = function(item) {
        let category = "";
        if("data" in item && "Category" in item.data) category += item.data["Category"] + ": ";
        return category+item.name;
      }
      let seen = {};
      return data.filter(function(item) {
          let pageName = getPageName(item);
          return seen.hasOwnProperty(pageName) ? false : (seen[pageName] = true);
      })
  };
   var getName = function(request, data, custom) {
       data = data || getCharmancerData();
       var section = request.replace("sub", "");
       var result = "";
       var customString = custom ? "custom" : "";
       if( data["l1-" + section] && data["l1-" + section].values[request] ) {
           result = data["l1-" + section].values[request + "_name"] || data["l1-" + section].values[request];
       }
       result = result.split(":")[0] == "Rules" || result.split(":")[0] == "CategoryIndex" ? customString : result;
       //Removing expansion name from result
       result = removeExpansionInfo(result);
       return _.last(result.split(":"));
   };
   var getGainedSpells = function() {
     let gainedSpells = [];
     const data = getCharmancerData();
     if("lp-spells" in data && "values" in data["lp-spells"]) {
       Object.keys(data["lp-spells"].values).forEach(key => {
         let found = false;
         if(key.indexOf("_checked") === -1) return;
         let spellNameKey = key.replace("_checked", "_name");
         let spellName = data["lp-spells"].values[spellNameKey];
         if(data["lp-welcome"].values.spellinfo) {
           let previousSpells = JSON.parse(data["lp-welcome"].values.spellinfo);
           Object.keys(previousSpells).forEach(spell => {
             if(previousSpells[spell].spellname === spellName) found = true;
           });
         }
         if(!found) gainedSpells.push(spellName);
       });
     }
     return gainedSpells;
   };
   var getGainedFeatures = function() {
     const data = getCharmancerData();
     if(!"lp-levels" in data) return;
     let gainedFeatures = [];
     for(let charclass=1; charclass<=4; charclass++) {
       let levelsGained = data["lp-levels"].values["class"+ charclass +"_addlevel"] || 0;
       if(levelsGained === 0) continue; //No leves gained in this class,  just skip to the next one.
       //Now lets get the features got from each class at LP;
       levelsGained = parseInt(levelsGained);
       let currentLevel = parseInt(data["lp-levels"].values["class"+ charclass +"_currentlevel"]);
       Object.keys(data["lp-levels"].data["class"+charclass].blobs).forEach(feature => {
         let featureLevel = parseInt(data["lp-levels"].data["class"+charclass].blobs[feature]["Level"]);
         if(featureLevel > currentLevel && featureLevel <= (currentLevel+levelsGained)) {
           let sanitizedFeatureName = feature.replace(/\(.+\)/g,"");
           sanitizedFeatureName = sanitizedFeatureName.replace(/ - .+/g,"").trim();
           if("Group" in data["lp-levels"].data["class"+charclass].blobs[feature]) return;
           if("Choice" in data["lp-levels"].data["class"+charclass].blobs[feature]) {
             Object.keys(data["lp-choices"].values).forEach(info => {
               if(data["lp-choices"].values[info] === feature) {
                 let choice = info.replace("_info", "_choice");
                 if(choice in data["lp-choices"].values) {
                   let choiceName = data["lp-choices"].values[choice].replace("Blob:", "");
                   if(gainedFeatures.indexOf(choiceName) === -1) gainedFeatures.push(choiceName);
                 }
               }
             });
           } else {
             if(gainedFeatures.indexOf(sanitizedFeatureName) === -1) gainedFeatures.push(sanitizedFeatureName);
           }
         }
       });
     }
     return gainedFeatures;
   };
   var filterBlobs = function(blobs, filters) {
       var remove = filters.multiclass ? "no" : "yes";
       var results = {};
       delete filters.multiclass;
       delete filters.slide;
       _.each(blobs, function(blob, name) {
           var match = true;
           if(blob.Group && !filters.Group && !filters.name) match = false;
           _.each(filters, function(v, k) {
               if(k == "name") {
                   if(name != v) match = false;
               } else if(v[0] === "<" && !isNaN(parseInt(v.substring(1)))) {
                   let blobval = isNaN(parseInt(blob[k])) ? 0 : parseInt(blob[k]);
                   if(blobval > parseInt(v.substring(1))) match = false;
               } else {
                   if(blob[k] != v) match = false;
               }
           });
           if(match && name.split("(")[0].toLowerCase() != "spell slots") results[name] = blob;
       });
       _.each(results, function(blob, name) {
           if(blob.Multiclass == remove) {
               delete results[name];
           }
       });
       return results;
   };
   var handleBlobs = function(blobs, options) {
       //Old parameters: (blobs, filters, section, element, thisblob)
       //Function to get blob parameter for Spell Pickers like Magical Secrets
       //By Miguel
       const getBlobDescription = function(blob) {
         if("Description" in blob) {
           return blob.Description;
         }
         else if("Traits" in blob) {
           traits = JSON.parse(blob.Traits)[0];
           if("Desc" in traits) return traits.Desc;
         }
         return "";
       }
       const handleProficiencies = function(data, subsection) {
           if(!data) {
               return;
           }
           subsection = subsection ? subsection : element
           _.each(proficiencyList, function(prof) {
               if(data[prof + " Proficiency"]) {
                   addRepeatingSection(subsection, "row", function(rowid) {
                       var json = JSON.parse(data[prof + " Proficiency"]);
                       if(!json.Hidden) {
                           var repupdate = {};
                           repupdate[rowid + " label span"] = json.Title ? json.Title : getTranslationByKey(prof.toLowerCase() + "-proficiencies");
                           if(json.Desc) {
                               repupdate[rowid + " label p"] = json.Desc;
                               if(json.Proficiencies) {
                                   repupdate[rowid + " label p"] += "
" + json.Proficiencies.join(", "); } } else if(json.Proficiencies) { repupdate[rowid + " label p"] = json.Proficiencies.join(", "); } setCharmancerText(repupdate); } _.each(json.Choice, function(v) { addRepeatingSection(rowid + " label", "choose", section + "_" + prof.toLowerCase(), function(id) { var choices = ""; var settings = {category: "Proficiencies", disable: profdata.all[prof]}; if(prof == "Language") { var customupdate = {}; customupdate[id + " select"] = '<option value="" data-i18n="choose"></option><option class="custom" value="custom" data-i18n="custom"></option>'; setCharmancerText(customupdate); } if(Array.isArray(v)) { if(v[0].split(":").length > 1) { choices = "Category:Proficiencies \"Type:" + prof + "\" " + v.shift(); settings.add = v; } else if (v[0] == "all") { v.shift(); choices = "Category:Proficiencies \"Type:" + prof + "\""; settings.add = v; } else { choices = v; } } else { choices = "Category:Proficiencies \"Type:" + prof + "\""; if(v != "all" && v != "any") { console.log("MISSED THE ALL CHECK") console.log(v); choices += " " + v; } } setCharmancerOptions(id + "_choice", choices, settings); }); }); }); } }); if(data.Expertise) { addRepeatingSection(subsection, "row", function(rowid) { var json = JSON.parse(data.Expertise); if(json.Title) { var repupdate = {}; repupdate[rowid + " label span"] = json.Title; setCharmancerText(repupdate); } _.each(json.Choice, function(v) { addRepeatingSection(rowid + " label", "choose", section + "_expertise", function(id) { var choices = ""; var settings = {category: "Proficiencies", disable: profdata.all.Expertise}; if(v[0].split(":").length > 1) { choices = "Category:Proficiencies \"Type:" + prof + "\" " + v.shift(); settings.add = v; } else if (v[0] == "KNOWN") { var info = {}; info[id + "_info"] = JSON.stringify(v); setAttrs(info); v.shift(); choices = profdata.all.Skill; settings.add = v; } else { choices = v; } setCharmancerOptions(id + "_choice", choices, settings); }); }); }); } }; const handleTraits = function(blob, subsection, name) { var traits = JSON.parse(blob.Traits); subsection = subsection ? subsection : element; _.each(traits, function(trait) { if(trait["Input Spells"]) { addRepeatingSection(subsection, "utilityrow", function(rowid) { let repupdate = {}; let set = {}; repupdate[`${rowid} label span .sheet-title`] = trait.Name.split("{{")[0]; if(!trait.Hide) repupdate[`${rowid} label p`] = trait.Desc; repupdate[`${rowid} button`] = trait["Input Spells"].ButtonText; set[`${rowid}_info`] = JSON.stringify(trait["Input Spells"]); set[`${rowid}_type`] = "trait"; set[`${rowid}_blob`] = name; set[`${rowid}_parent`] = options.parent; set[`${rowid}_title`] = trait.Name; set[`${rowid}_desc`] = trait.Desc; setCharmancerText(repupdate); setAttrs(set); }); } else if(!trait.Hide) { addRepeatingSection(subsection, "row", function(rowid) { let repupdate = {}; if(trait.Input) { //Fixing custom data in inputs not being remembered when switching tabs (UC809) //By Miguel const data = getCharmancerData(); //The function below looks for valyes through all Mancer data that match a input rowid: const getPreviousInputValue = function(data, rowid) { let parsedId = rowid.match(/-.+_/g)[0]; for(let attribute in data) { if(!("values" in data[attribute])) continue; for (let key in data[attribute].values){ if(data[attribute].values.hasOwnProperty(key) && key.indexOf("_input") > -1 && key.indexOf(parsedId) > -1) { return data[attribute].values[key]; } } } return ""; } const previousValue = getPreviousInputValue(data, rowid); repupdate[`${rowid} label span`] = `<input type="text" name="comp_${rowid}_trait_input" value="${previousValue}">`; repupdate[`${rowid} label span`] += `<input type="hidden" name="comp_${rowid}_trait_name" value="${(trait.Name ? trait.Name : "")}">`; repupdate[`${rowid} label span`] += `<input type="hidden" name="comp_${rowid}_trait_desc" value="${(trait.Desc ? trait.Desc : "")}">`; repupdate[`${rowid} label span`] += `<input type="hidden" name="comp_${rowid}_trait_section" value="${section}">`; } else { repupdate[`${rowid} label span`] = trait.Name;
repupdate[`${rowid} label p`] = blob.Prerequisite ? "

" + blob.Prerequisite + "

" : "";
                           //Fixing undefined when selecting Ranger Favored Enemy and Land (UC809)
                           //By Miguel
                           repupdate[`${rowid} label p`] += (trait.Desc ? trait.Desc : "");
                       }
                       setCharmancerText(repupdate);
                       handleProficiencies(blob, rowid);
                   });
               };
           });
       };
       const mancerdata = getCharmancerData();
       let filters = options.filters || {};
       let section = options.section || undefined;
       let thisblob = options.thisblob || undefined;
       let element = options.element ? options.element : section + "_holder";
       let sorted = {choices: {}, traits: {}, other: {}, spells: {}};
       let profdata = getProficiencies(mancerdata, options.slide);
       let filtered = {};
       if(thisblob) {
           filtered[thisblob] = blobs[thisblob];
       } else {
           filtered = filterBlobs(blobs, filters);
       }
       _.each(filtered, function(blob, name) {
           if(name.split(" ")[0] == "Proficiencies") {
               sorted.proficiencies = blob;
           } else if (blob["Pick Spells"]) {
               sorted.spells[name] = blob;
           } else if(blob.Choice) {
               sorted.choices[name] = blob;
           } else if(blob.Traits) {
               sorted.traits[name] = blob;
           } else {
               sorted.other[name] = blob;
           }
       });
       handleProficiencies(sorted.proficiencies);
       _.each(sorted.choices, function(blob, name) {
           addRepeatingSection(element, "row", function(rowid) {
               var title = blob.Title ? blob.Title : name;
               var choice = blob.Choice;
               var settings = {};
               let choicenum = blob["Choice Number"] ? parseInt(blob["Choice Number"]) : 1;
               if(blob.Choice.split(":")[0] == "Blob") {
                   choice = Object.keys(filterBlobs(blobs, {Group: blob.Choice.split(":")[1], Level: ("<" + (options.maxlevel || blob.Level))})).sort();
                   settings.category = "Blob";
               }
               var repupdate = {};
               repupdate[rowid + " label span"] = title;
               if(blob.Description) {
                   repupdate[rowid + " label p"] = blob.Description;
               }
               setCharmancerText(repupdate);
               if(section.indexOf("-") === -1) {
                 let match = /[0-9]+$/.exec(section);
                 if(match) {
                   section = [section.slice(0, match.index), "-", section.slice(match.index)].join();
                   section += "--" + blob.Level;
                 }
               }
               for(let x=1; x<=choicenum; x++) {
                   addRepeatingSection(rowid + " label", "choose", section + "_feature", function(id) {
                       var info = {};
                       info[id + "_info"] = title;
                       setAttrs(info);
                       setCharmancerOptions(id + "_choice", choice, settings, function() {
                           if(mancerdata[options.slide].values[id + "_choice"] && mancerdata[options.slide].values[id + "_choice"].split(":")[0] == "Blob") {
                               handleBlobs(blobs, {
                                   filters: {name: mancerdata[options.slide].values[id + "_choice"].split(":")[1]},
                                   section: section,
                                   element: id + " span",
                                   slide: options.slide,
                                   parent: options.parent
                               });
                           }
                       });
                   });
               }
               handleProficiencies(blob, rowid);
           });
       });
       _.each(sorted.spells, function(blob, name) {
           addRepeatingSection(element, "row", function(rowid) {
               let title = blob.Title ? blob.Title : name;
               let spells = JSON.parse(blob["Pick Spells"]);
               let settings = {};
               let repupdate = {};
               repupdate[rowid + ">label>span"] = title;
               //This used to check for blob.Description which does not exist for Spell Pickers
               //In such case the description is located at blob.Traits.Desc
               //By Miguel
               let description = getBlobDescription(blob);
               if(description.length > 0) {
                   repupdate[rowid + ">label>p"] = description;
               }
               _.each(spells, function(spell) {
                   addRepeatingSection(rowid, "utilityrow", function(rowid) {
                       let repupdate = {};
                       let set = {};
                       repupdate[`${rowid} button`] = spell.ButtonText;
                       set[`${rowid}_info`] = JSON.stringify(spell);
                       set[`${rowid}_type`] = "pick";
                       set[`${rowid}_parent`] = options.parent;
                       set[`${rowid}_blob`] = name;
                       setCharmancerText(repupdate);
                       setAttrs(set);
                   });
               })
               setCharmancerText(repupdate);
               handleProficiencies(blob, rowid);
           });
       });
       _.each(sorted.other, function(blob, name) {
           if(blob.Title || blob.Description) {
               addRepeatingSection(element, "row", function(rowid) {
                   var title = blob.Title ? blob.Title : name;
                   var repupdate = {};
                   repupdate[rowid + " label span"] = "" + title;
repupdate[`${rowid} label p`] = blob.Prerequisite ? "

" + blob.Prerequisite + "

" : "";
                   if(blob.Description) repupdate[rowid + " label p"] += blob.Description;
                   setCharmancerText(repupdate);
                   handleProficiencies(blob, rowid);
               });
           } else {
               handleProficiencies(blob);
           }
       });
       _.each(sorted.traits, function(blob, name) {
           var traitsObj = JSON.parse(blob.Traits);
           var title = blob.Title ? blob.Title : name;
           if(blob.Description || traitsObj.length > 1) {
               addRepeatingSection(element, "row", function(rowid) {
                   if(blob.Description || blob.Title) {
                       var repupdate = {};
                       repupdate[rowid + " label span"] = "" + title;
                       if(blob.Description) repupdate[rowid + " label p"] = "" + blob.Description;
                       setCharmancerText(repupdate);
                   }
                   handleTraits(blob, rowid, name);
                   handleProficiencies(blob, rowid);
               });
           } else {
               handleTraits(blob, undefined, name);
           }
       });
   };
   var addCustomSections = function(section) {
       var lower = section.toLowerCase();
       var page = "l1-" + lower.replace("sub", "");
       var mancerdata = getCharmancerData()[page];
       var repids = [];
       var total = 0;
       var current = 0;
       var traits = [];
       var profs = [];
       console.log(mancerdata);
       _.each(mancerdata.repeating, function(repid) {
           if(_.last(repid.split("_")) == "trait") {
               if(mancerdata.values[repid + "_name"] || mancerdata.values[repid + "_desc"]) {
                   var thistrait = {};
                   thistrait.name = mancerdata.values[repid + "_name"] ? mancerdata.values[repid + "_name"] : "";
                   thistrait.desc = mancerdata.values[repid + "_desc"] ? mancerdata.values[repid + "_desc"] : "";
                   traits.push(thistrait);
                   total++;
               }
           }
           if(_.last(repid.split("_")) == "proficiency") {
               if(mancerdata.values[repid + "_type"]) {
                   var thisprof = {};
                   thisprof.type = mancerdata.values[repid + "_type"];
                   thisprof.choice = mancerdata.values[repid + "_choice"] ? mancerdata.values[repid + "_choice"] : "";
                   profs.push(thisprof);
                   total++;
               }
           }
       });
       if(traits.length == 0) {
           traits.push({name: "", desc: ""});
           total++;
       }
       if(profs.length == 0) {
           profs.push({type: "", choice: ""});
           total ++;
       }
       addRepeatingSection(lower + "_holder", "row", "customrow", function(rowid) {
           var toset = {};
           toset[rowid + " label span"] = "Proficiencies";
           repids.push(rowid);
           setCharmancerText(toset);
           _.each(profs, function(prof) {
               addRepeatingSection(rowid, "custom-proficiency", "custom_" + lower + "_proficiency", function(id) {
                   var toset = {};
                   if(prof.type != "") toset[id + "_type"] = prof.type;
                   if(prof.choice != "") toset[id + "_choice"] = prof.choice;
                   setAttrs(toset);
                   current++;
                   repids.push(id);
                   if(current >= total) clearRepeating(repids, page, "customrow");
               });
           });
       });
       addRepeatingSection(lower + "_holder", "row", "customrow", function(rowid) {
           var toset = {};
           toset[rowid + " label span"] = "Custom " + section + " Features";
           repids.push(rowid);
           setCharmancerText(toset);
           _.each(traits, function(trait) {
               addRepeatingSection(rowid, "custom-trait", "custom_" + lower + "_trait", function(id) {
                   var toset = {};
                   if(trait.name != "") toset[id + "_name"] = trait.name;
                   if(trait.desc != "") toset[id + "_desc"] = trait.desc;
                   //update[id + " span"] = trait.name;
                   setAttrs(toset);
                   current++;
                   repids.push(id);
                   if(current >= total) clearRepeating(repids, page, "customrow");
               });
           });
       });
   }
   var clearRepeating = function(repids, page, match) {
       //This function removes all repeating sections that aren't in the repids array (except for the topbar).
       //The optional third argument will only remove certain types of repeating sections
       var mancerdata = getCharmancerData();
       _.each(mancerdata[page].repeating, function(repid) {
           if(_.last(repid.split("_")) != "topbar" && !repids.includes(repid) && (!match || match && repid.includes(match))) clearRepeatingSectionById(repid);
       });
   }
   //This function should be used to read additional hit points gained at first level by things like Draconic Bloodline or Hill Dwarf. Can be possbily be used in the future for Tough feat(?)
   //By Miguel
   var getAdditionalHitPointsFromClassAndRaceAtFirstLevel = function(blobs) {
     let additionalHP = 0;
     blobs.all.map(blob => {
        if("Hit Points Per Level" in blob) {
          additionalHP += parseInt(blob["Hit Points Per Level"]);
        }
     });
     return additionalHP;
   };
   var getRelevantBlobs = function(mancerdata, level, section) {
       var results = [];
       var sorted = {};
       var names = {};
       level = level ? "" + level : "1";
       _.each(mancerdata, function(slide, slidename) {
           if(slidename.split("-")[0] == section) {
               _.each(slide.data, function(data, section) {
                   if(data.blobs) {
                       var levelblobs = _.extend(filterBlobs(data.blobs, {"Level": level}), filterBlobs(data.blobs, {"Level": "every"}));
                       sorted[section] = [];
                       names[section] = [];
                       _.each(levelblobs, function(blob, blobname) {
                           results.push(blob);
                           sorted[section].push(blob);
                           names[section].push(blobname);
                       });
                   };
               });
               _.each(slide.values, function(value, name) {
                   if((value + "").split(":")[0] == "Blob") {
                       var section = name.split("_")[2];
                       var blobs = slide.data[section] && slide.data[section].blobs ? slide.data[section].blobs : [];
                       _.each(filterBlobs(blobs, {"name":value.split(":")[1]}), function(blob, blobname) {
                           results.push(blob);
                           sorted[section] = sorted[section] ? sorted[section] : [];
                           sorted[section].push(blob);
                           names[section] = names[section] ? names[section] : [];
                           names[section].push(blobname);
                       });
                   };
               });
           }
       });
       return {all: results, sorted: sorted, names: names};
   };
   var costOfScore = function(score) {
       if (isNaN(score) || score == 8) {
           return 0;
       }
       var cost = 0;
       if (score > 8) {
           if (score < 14) {
               cost = score - 8;
           } else if (score == 14) {
               cost = 7;
           } else if (score == 15) {
               cost = 9;
           } else {  // Score should never be higher, but let's cover our bases.
               cost = 11;
           }
       }
       return cost;
   };
   var recalcPoints = function() {
       data = getCharmancerData();
       var attribs = ["strength","dexterity","constitution","intelligence","wisdom","charisma"];
       var maxPoints = 27;
       var scores = {};
       _.each(attribs, function(attrib) {
           scores[attrib] = parseInt(data["l1-abilities"].values[attrib]);
           if (isNaN(scores[attrib])) {
               scores[attrib] = 8;
           }
       });
       var pointsAvailable = maxPoints;
       // Decrement points based on selected attribs
       _.each(scores, function(score) {
           if (!isNaN(score)) {
               var cost = costOfScore(score);
               pointsAvailable -= cost;
           }
       });
       // Disable options if points are below a threshold.
       if (pointsAvailable < 9) {
           var choicesToDisable = ["15","14","13","12","11","10","9"];
           _.each(attribs, function(attrib) {
               var toDisableForThisAttrib = []
               _.each(choicesToDisable, function(choice) {
                   if (scores[attrib] <= Number(choice) && (costOfScore(scores[attrib]) + pointsAvailable < costOfScore(Number(choice)))) {
                       toDisableForThisAttrib.push(choice);
                   }
               });
               disableCharmancerOptions(attrib, toDisableForThisAttrib);
           });
       } else {
           _.each(attribs, function(attrib) {
               disableCharmancerOptions(attrib, []);
           });
       }
       _.each(attribs, function(attrib) {
           setCharmancerText({"points_available_display":String(pointsAvailable)});
       });
       return String(pointsAvailable);
   };
   var setRollButton = function(name, data, title, hold) {
       getAttrs(["licensedsheet"], function(v) {
           var set = {};
           var holdstring = hold ? "r" + hold : "";
           title = title || name.split("_")[1];
           title = title[0].toUpperCase() + title.substring(1);
           const licensedsheet      = (v.licensedsheet && v.licensedsheet === "1") ? "licensedsheet" : "";
           if(title == "Personality") title += " Trait";
           var roll = `@{wtype}&{template:mancerroll} {{title=${title}}} {{c1=[[1d${data.length + holdstring}]]}} {{licensedsheet=${licensedsheet}}}`;
           _.each(data, function(trait, x) {
               roll += ' Template:Option' + (x+1) + '=' + trait + '';
           });
           set["roll_" + name + "_roll"] = roll;
           if(!hold) {
               set[name + "_array"] = JSON.stringify({name: title, array: data});
           }
           setAttrs(set);
       });
   };
   /* MAIN CHOICE HANDLING */
   on("mancerchange:race", function(eventinfo) {
       var mancerdata = getCharmancerData();
       getProficiencies(mancerdata, eventinfo.currentStep);
       changeCompendiumPage("sheet-race-info", eventinfo.newValue);
       hideChoices();
       var reset = {};
       if(!(eventinfo.newValue === "" || eventinfo.newValue === undefined)) {
           showChoices(["race_options"]);
       }
       recalcData();
       if(eventinfo.sourceType == "player") {
           reset = {race_ability_choice1: "", race_ability_choice2: "", subrace_ability_choice1: "", subrace_ability_choice2: "", subrace: "", race_name: "", subrace_name: ""};
           _.each(abilityList, function(ability){
               reset["race_custom_" + ability.toLowerCase()] = 0;
               reset["subrace_custom_" + ability.toLowerCase()] = 0;
               reset[ability.toLowerCase() + "_save"] = "";
           });
           reset["custom_race_spell_ability"] = "";
           reset["custom_race_spell_number"] = "1";
           reset["custom_race_spell_list"] = "";
           reset["race_name"] = "";
           reset["subrace_name"] = "";
           reset["has_subrace"] = "";
           clearRepeatingSections("race_holder");
           clearRepeatingSections("subrace_holder");
       }
       if(eventinfo.newValue === "Rules:Races") {
           //Clears saved data for this field
           getCompendiumPage("");
           setAttrs(reset, function() {
               var update = {"race_text": ""};
               var options = eventinfo.sourceType == "player" ? {selected: ""} : {};
               showChoices(["custom_race"]);
               setCharmancerText(update);
               addCustomSections("Race");
               deleteCharmancerData(["l1-feat"]);
           });
       } else {
           getCompendiumPage(eventinfo.newValue, function(p) {
               p = removeDuplicatedPageData(p);
               setAttrs(reset, function() {
                   mancerdata = getCharmancerData();
                   var update = {};
                   var showList = ["race_always", "race_traits"];
                   var possibles = ["race_size", "race_speed", "race_ability_score", "race_traits"];
                   var data = p["data"];
                   _.each(proficiencyList, function(type){
                       possibles.push("race_" + type.toLowerCase() + "s");
                   });
                   _.each(possibles, function(key) {
                       update[key] = "";
                   });
                   if(data["Size"]) {update["race_size"] = data["Size"];};
                   if(data["Speed"]) {update["race_speed"] = data["Speed"];};
                   showList = showList.concat(handleAbilities(data, "race"));
                   if(data["data-Ability Score Increase"]) {
                       var abilityText = [];
                       var json = JSON.parse(data["data-Ability Score Increase"]);
                       _.each(json, function(increase, ability) {
                           abilityText.push(ability + " +" + increase);
                       });
                       update["race_ability_score"] = abilityText.join(", ");
                   }
                   handleBlobs(data.blobs, {filters: {"Level": "1"}, section: "race", slide: "l1-race"});
                   setCharmancerText(update);
                   var race_name = eventinfo.newValue && eventinfo.newValue.split(":").length > 1 && eventinfo.newValue.split(":")[0] === "Races" ? eventinfo.newValue.split(":")[1] : false;
                   race_name = removeExpansionInfo(race_name);
                   if(race_name) {
                       var subOptions = {show_source: true};
                       if(eventinfo.sourceType != "player") {
                           subOptions.silent = true;
                       } else {
                           subOptions.selected = "";
                       }
                       setCharmancerOptions("subrace","Category:Subraces data-Parent:" + race_name, subOptions, function(values) {
                           if (values.length) {
                               setAttrs({"has_subrace": "true"});
                               showChoices(["subrace"]);
                           }
                       });
                   }
                   else {
                       hideChoices(["subrace"]);
                   }
                   showChoices(showList);
                   recalcData();
               });
           });
       }
   });
   on("mancerchange:subrace", function(eventinfo) {
       var mancerdata = getCharmancerData();
       getProficiencies(mancerdata, eventinfo.currentStep);
       changeCompendiumPage("sheet-race-info", eventinfo.newValue);
       var initHide = ["subrace_possible", "custom_trait_2", "custom_trait_3", "custom_trait_4"];
       var reset = {};
       if(eventinfo.newValue === "" || eventinfo.newValue === undefined) {
           initHide.push("subrace_options");
       }
       else {
           showChoices(["subrace_options"]);
       }
       hideChoices(initHide);
       recalcData();
       if(eventinfo.sourceType == "player") {
           reset = {subrace_ability_choice1: "", subrace_ability_choice2: "", subrace_name: ""};
           _.each(abilityList, function(ability){
               reset["race_custom_" + ability.toLowerCase()] = 0;
               reset["subrace_custom_" + ability.toLowerCase()] = 0;
           });
           reset["custom_race_spell_ability"] = "";
           reset["custom_race_spell_number"] = "1";
           reset["custom_race_spell_list"] = "";
           reset["subrace_name"] = "";
           clearRepeatingSections("subrace_holder");
       }
       if(eventinfo.newValue === "Rules:Races") {
           //Clears saved data for this field
           getCompendiumPage("");
           setAttrs(reset, function() {
               var update = {"subrace_text": ""};
               var options = eventinfo.sourceType == "player" ? {selected: ""} : {};
               showChoices(["custom_subrace"]);
               setCharmancerText(update);
               addCustomSections("Subrace");
               deleteCharmancerData(["l1-feat"]);
           });
       } else {
           hideChoices(["custom_subrace"]);
           getCompendiumPage(eventinfo.newValue, function(p) {
               p = removeDuplicatedPageData(p);
               var update = {};
               var showList = ["subrace_choices"];
               var possibles = ["subrace_speed", "subrace_ability_score"];
               var data = p["data"];
               _.each(possibles, function(key) {
                   update[key] = "";
               });
               if(!data["data-Feats"]) deleteCharmancerData(["l1-feat"], function() {recalcData();});
               if(data["Speed"]) {
                   update["subrace_speed"] = data["Speed"];
                   showList.push("subrace_speed_row");
               };
               showList = showList.concat(handleAbilities(data, "subrace"));
               if(data["data-Ability Score Increase"]) {
                   var abilityText = [];
                   var json = JSON.parse(data["data-Ability Score Increase"]);
                   _.each(json, function(increase, ability) {
                       abilityText.push(ability + " +" + increase);
                   });
                   update["subrace_ability_score"] = abilityText.join(", ");
               }
               handleBlobs(data.blobs, {filters: {"Level": "1"}, section: "subrace", slide: "l1-race"});
               setCharmancerText(update);
               showChoices(showList);
               setAttrs(reset);
               recalcData();
           });
       }
   });
   on("mancerchange:class", function(eventinfo) {
       var mancerdata = getCharmancerData();
       getProficiencies(mancerdata, eventinfo.currentStep);
       changeCompendiumPage("sheet-class-info", eventinfo.newValue);
       hideChoices();
       var initHide = ["class_possible", "subclass_choices"];
       var reset = {};
       if(!(eventinfo.newValue === "" || eventinfo.newValue === undefined)) {
           showChoices(["classes_options"]);
       }
       var current = recalcData();
       if(eventinfo.sourceType == "player") {
           reset = {subclass: ""};
           _.each(abilityList, function(ability){
               reset[ability.toLowerCase() + "_save"] = "";
           });
           reset["custom_class_spell_ability"] = "";
           reset["custom_class_cantrip_number"] = "0";
           reset["custom_class_spell_number"] = "0";
           reset["custom_class_spell_list"] = "";
           reset["custom_hit_die"] = "";
           reset["class_name"] = "";
           reset["subclass_name"] = "";
           reset["class_equipment_choice1"] = "";
           reset["class_equipment_choice2"] = "";
           reset["class_equipment_choice3"] = "";
           reset["class_equipment_choice4"] = "";
           clearRepeatingSections("class_holder");
           clearRepeatingSections("subclass_holder");
       }
       if(eventinfo.newValue === "Rules:Classes") {
           //Clears saved data for this field
           getCompendiumPage("");
           setAttrs(reset, function() {
               var update = {"class_text": "", "custom_feature_name": "Class Features"};
               var options = eventinfo.sourceType == "player" ? {selected: ""} : {}
               showChoices(["custom_class"]);
               update["custom_feature_name"] = "Custom Class Features";
               setCharmancerText(update);
               addCustomSections("Class");
           });
       } else {
           getCompendiumPage(eventinfo.newValue, function(p) {
               p = removeDuplicatedPageData(p);
               var update = {};
               var showList = [];
               var data = p["data"];
               var hideList = [];
               handleBlobs(data.blobs, {filters: {"Level": "1"}, section: "class", slide: "l1-class"});
               var class_name = eventinfo.newValue && eventinfo.newValue.split(":").length > 1 && eventinfo.newValue.split(":")[0] === "Classes" ? eventinfo.newValue.split(":")[1] : false;
               class_name = removeExpansionInfo(class_name);
               if(class_name && data["data-Subclass Level"] == 1) {
                   var subOptions = {show_source: true};
                   if(eventinfo.sourceType != "player") {
                       subOptions.silent = true;
                   } else {
                       subOptions.selected = "";
                   }
                   update["subclass_prompt"] = "Choose a " + data["Subclass Name"];
                   setCharmancerOptions("subclass","Category:Subclasses data-Parent:" + class_name, subOptions, function(values) {
                       if (values.length) showChoices(["subclass"]);
                   });
               }
               else {
                   hideList.push("subclass");
               }
               if (data["data-Equipment"]) {
                   showList.push("class_equipment_row");
                   var equipment_string = "";
                   var json = JSON.parse(data["data-Equipment"]);
                   if(json["default"]) {
                       equipment_string += json["default"].join(", ");
                   }
                   for (var i = 1; i < 5; i++) {
                       if(json[i]) {
                           if (!json["default"].length && i == 1) {
                               equipment_string += "";
                           } else {
                               equipment_string += " and ";
                           }
                           equipment_string += cleanEquipment(json[i]);
                       }
                   };
                   update["class_standard_equipment"] = equipment_string;
               }
               setCharmancerText(update);
               showChoices(showList);
               hideChoices(hideList);
               recalcData();
               setAttrs(reset);
           });
       }
   });
   on("mancerchange:subclass", function(eventinfo) {
       var mancerdata = getCharmancerData();
       getProficiencies(mancerdata, eventinfo.currentStep);
       changeCompendiumPage("sheet-class-info", eventinfo.newValue);
       var initHide = ["subclass_possible"];
       var reset = {};
       if(eventinfo.newValue === "" || eventinfo.newValue === undefined) {
           initHide.push("subclass_options");
           initHide.push("custom_subclass");
       }
       else {
           showChoices(["subclass_options"]);
           if(eventinfo.newValue === "Rules:Classes") {
               showChoices(["custom_subclass"]);
           }
           else {
               initHide.push("custom_subclass");
           }
       }
       hideChoices(initHide);
       var current = recalcData();
       if(eventinfo.sourceType == "player") {
           reset["custom_class_spell_ability"] = "";
           reset["custom_class_cantrip_number"] = "0";
           reset["custom_class_spell_number"] = "0";
           reset["custom_class_spell_list"] = "";
           reset["custom_subclass_cantrip_number"] = "0";
           reset["custom_subclass_cantrip_list"] = "";
           reset["custom_subclass_spell_number"] = "0";
           reset["custom_subclass_spell_list"] = "";
           reset["subclass_name"] = "";
           clearRepeatingSections("subclass_holder");
       }
       if(eventinfo.newValue === "Rules:Classes") {
           //Clears saved data for this field
           getCompendiumPage("");
           setAttrs(reset, function() {
               var mancerdata = getCharmancerData();
               var options = eventinfo.sourceType == "player" ? {selected: ""} : {};
               var subclassname = mancerdata["l1-class"].data.class["Subclass Name"];
               showChoices(["custom_subclass"]);
               if(mancerdata["l1-class"].data.class && mancerdata["l1-class"].data.class["Spellcasting Ability"]) {
                   showChoices(["custom_additional_spells"]);
               } else {
                   showChoices(["custom_class_spells"]);
               }
               addCustomSections("Subclass");
           });
       } else {
           hideChoices(["custom_subclass"]);
           getCompendiumPage(eventinfo.newValue, function(p) {
               p = removeDuplicatedPageData(p);
               var data = p["data"];
               handleBlobs(data.blobs, {filters: {"Level": "1"}, section: "subclass", slide: "l1-class"});
               recalcData();
               setAttrs(reset);
           });
       }
   });
   on("mancerchange:background", function(eventinfo) {
       var mancerdata = getCharmancerData();
       getProficiencies(mancerdata, eventinfo.currentStep);
       changeCompendiumPage("sheet-background-info", eventinfo.newValue);
       var initHide = ["background_possible", "custom_background"];
       var reset = {};
       if(eventinfo.newValue === "" || eventinfo.newValue === undefined) {
           initHide.push("backgrounds_options");
       }
       else {
           showChoices(["backgrounds_options"]);
       }
       hideChoices(initHide);
       var current = recalcData();
       if(eventinfo.sourceType == "player") {
           reset = {};
           reset["background_detail_choice"] = "";
           reset["background_personality_choice1"] = "";
           reset["background_personality_choice2"] = "";
           reset["background_ideal_choice"] = "";
           reset["background_bond_choice"] = "";
           reset["background_flaw_choice"] = "";
           reset["custom_background_trait_name"] = "";
           reset["custom_background_trait_desc"] = "";
           clearRepeatingSections("background_holder");
       }
       if(eventinfo.newValue === "Rules:Backgrounds") {
           //Clears saved data for this field
           getCompendiumPage("");
           setAttrs(reset, function() {
               var update = {"background_text": ""};
               var options = eventinfo.sourceType == "player" ? {selected: ""} : {}
               hideChoices(["standardbg"]);
               showChoices(["custom_background"]);
               setCharmancerText(update);
               addCustomSections("Background");
           });
       } else {
           getCompendiumPage(eventinfo.newValue, function(p) {
               p = removeDuplicatedPageData(p);
               var update = {};
               var showList = ["standardbg"];
               var possibles = ["background_feature"];
               var data = p["data"];
               var hideList = [];
               _.each(proficiencyList, function(type){
                   possibles.push("background_" + type.toLowerCase() + "s");
               });
               _.each(possibles, function(key) {
                   update[key] = "";
               });
               handleBlobs(data.blobs, {filters: {"Level": "1"}, section: "background", slide: "l1-background"});
               if (data["data-Background Choices"] && data["data-Background Choices"] != "") {
                   showList.push("background_detail_choice_row");
                   var choices = JSON.parse(data["data-Background Choices"]);
                   showList.push("background_detail_choice");
                   setCharmancerOptions("background_detail_choice", choices, {}, function(opts) {
                       setRollButton("background_detail_choice", opts, data["data-Background Choice Name"]);
                   });
                   update["background_detail_choice_name"] = data["data-Background Choice Name"];
               }
               if(eventinfo.sourceType == "player") {
                   reset["background_detail_choice"] = "";
               }
               if (data["data-Personality Traits"]) {
                   showList.push("background_personality_row");
                   var choices = JSON.parse(data["data-Personality Traits"]);
                   setCharmancerOptions("background_personality_choice1", choices, {}, function(opts) {
                       setRollButton("background_personality_choice1", opts);
                   });
                   setCharmancerOptions("background_personality_choice2", choices, {}, function(opts) {
                       setRollButton("background_personality_choice2", opts);
                   });
                   showList.push("background_personality_choice1");
                   showList.push("background_personality_choice2");
               }
               if (data["data-Ideals"]) {
                   var choices = JSON.parse(data["data-Ideals"]);
                   setCharmancerOptions("background_ideal_choice", choices, {}, function(opts) {
                       setRollButton("background_ideal_choice", opts);
                   });
                   showList.push("background_ideal_choice");
               }
               if (data["data-Bonds"]) {
                   var choices = JSON.parse(data["data-Bonds"]);
                   setCharmancerOptions("background_bond_choice", choices, {}, function(opts) {
                       setRollButton("background_bond_choice", opts);
                   });
                   showList.push("background_bond_choice");
               }
               if (data["data-Flaws"]) {
                   var choices = JSON.parse(data["data-Flaws"]);
                   setCharmancerOptions("background_flaw_choice", choices, {}, function(data) {
                       setRollButton("background_flaw_choice", data);
                   });
                   showList.push("background_flaw_choice");
               }
               if(eventinfo.so