Skip to content

Commit

Permalink
Merge branch 'New1eUpdates_AutoDamage' into New1eUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
vince-roll20 committed Nov 26, 2024
2 parents 3da78cd + dd5c45b commit 4fa9c0b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 67 deletions.
4 changes: 2 additions & 2 deletions ADnD_1E_Revised/1ESheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -2324,9 +2324,8 @@ details[open].thac0-box {
display: grid;
grid-template-columns: auto minmax(8em, 1fr) 3fr 8em;
grid-template-rows: 1.5em 2em;
margin: -1.85em 0 -0.5em auto;
margin: 0 auto 0 auto;
position: relative;
top: -0.75em;
width: 75%;
z-index: 1;
}
Expand Down Expand Up @@ -3707,6 +3706,7 @@ details[open].thac0-box {
color: initial;
cursor: pointer;
display: inline-block;
font-family: var(--font-buttons1);
font-size: var(--text-med);
font-weight: normal;
margin: 0 2px 2px 2px;
Expand Down
89 changes: 65 additions & 24 deletions ADnD_1E_Revised/1ESheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ <h5 class="right two-columns">
<span class="left">
<span>v<span name="attr_sheet_version">
</span>
<span class="right"> • 11/24/24'</span>
<span class="right"> • 11/25/24'</span>
</h5>
<ul>
<li>Added an option in the Sheet settings to auto-roll weapon damage regardless of the attack roll.</li>
<li>
<span>Updated some of the sheet's font settings.</span><br>
<details style="max-width:98%;">
Expand Down Expand Up @@ -4504,6 +4505,10 @@ <h4>Misc. Options:</h4>
<span>Use THAC0:</span>
<input type="checkbox" name="attr_toggle_to_hit_table" value="1" />
</label>
<label title="@{toggle_auto_damage} | Auto roll damage regardless of the attack roll.">
<span>Auto Roll Damage:</span>
<input type="checkbox" name="attr_toggle_auto_damage" value="1" />
</label>
<label title="@{toggle_critdamage} | Use crit damage rolls on natural 20. Defaults to weapon damage x2. Crit damage handling can be adjusted per attack.">
<span>Use Crit Damage:</span>
<input type="checkbox" name="attr_toggle_critdamage" value="1" />
Expand Down Expand Up @@ -4808,7 +4813,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#crit}}
{{#damagevsSMchatmenu}}{{#damagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{damagevsSMchatmenu}}{{damagevsLchatmenu}}
</span>
</span>
Expand All @@ -4821,7 +4826,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#^rollWasCrit() attack1}}
{{#damagevsSMchatmenu}}{{#damagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{damagevsSMchatmenu}}{{damagevsLchatmenu}}
</span>
</span>
Expand All @@ -4830,7 +4835,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#rollWasCrit() attack1}}
{{#critdamagevsSMchatmenu}}{{#critdamagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{critdamagevsSMchatmenu}}{{critdamagevsLchatmenu}}
</span>
</span>
Expand All @@ -4856,7 +4861,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#^rollWasCrit() attack2}}
{{#damagevsSMchatmenu}}{{#damagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{damagevsSMchatmenu}}{{damagevsLchatmenu}}
</span>
</span>
Expand All @@ -4865,7 +4870,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#rollWasCrit() attack2}}
{{#critdamagevsSMchatmenu}}{{#critdamagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{critdamagevsSMchatmenu}}{{critdamagevsLchatmenu}}
</span>
</span>
Expand All @@ -4891,7 +4896,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#^rollWasCrit() attack3}}
{{#damagevsSMchatmenu}}{{#damagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{damagevsSMchatmenu}}{{damagevsLchatmenu}}
</span>
</span>
Expand All @@ -4900,7 +4905,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#rollWasCrit() attack3}}
{{#critdamagevsSMchatmenu}}{{#critdamagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{critdamagevsSMchatmenu}}{{critdamagevsLchatmenu}}
</span>
</span>
Expand All @@ -4926,7 +4931,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#^rollWasCrit() attack4}}
{{#damagevsSMchatmenu}}{{#damagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{damagevsSMchatmenu}}{{damagevsLchatmenu}}
</span>
</span>
Expand All @@ -4935,7 +4940,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
{{#rollWasCrit() attack4}}
{{#critdamagevsSMchatmenu}}{{#critdamagevsLchatmenu}}
<span class="sheet-row">
<span class="sheet-span-two sheet-center">
<span class="sheet-span-two sheet-center sheet-tcat">
{{critdamagevsSMchatmenu}}{{critdamagevsLchatmenu}}
</span>
</span>
Expand Down Expand Up @@ -5435,7 +5440,6 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
};

// during version updates, we need to check that an attribute exists and is not equal to its default, before updating it.
// changed != to !== ie eslint suggestion
const doUpdate = (stat, def = 0) => typeof stat !== 'undefined' && stat !== def;

// handles regex for testing and replacing macrotext attributes
Expand Down Expand Up @@ -5481,7 +5485,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
return generated;
};

// Validate input for illegal characters
// Validate character name for illegal characters
on('change:character_name', (eventInfo) => {
// clog(`Change Detected:${eventInfo.sourceAttribute}`);
getAttrs(['character_name'], (v) => {
Expand Down Expand Up @@ -5677,7 +5681,7 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
'armorother6_mod',
];

// use in getSectionIds to separate repeating attribute names
// used in getSectionIds to separate a repeating attribute names into 3 components
const section_attribute = (section, id, field) => `repeating_${section}_${id}_${field}`;

// VERSIONATOR example
Expand Down Expand Up @@ -9692,24 +9696,49 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
calcAC(recalc);
});

// Creates the chat menu buttons or auto rolls damage with the attack based on settings
damageMacro = (id) => {
const output = {};
output[`repeating_weapon_${id}_weapon_damagesmallmedium_chat_menu`] = `[Roll Damage](~@{character_id}|repeating_weapon_${id}_weapon_damagesmallmedium_roll)`;
output[`repeating_weapon_${id}_weapon_damagelarge_chat_menu`] = `[Roll Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_damagelarge_roll)`;
output[`repeating_weapon_${id}_weapon_damagesmallmedium_npc_chat_menu`] = `[Damage](~@{character_id}|repeating_weapon_${id}_weapon_damagesmallmedium_npc_roll)`;
output[`repeating_weapon_${id}_weapon_damagelarge_npc_chat_menu`] = `[Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_damagelarge_npc_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagesmallmedium_chat_menu`] = `[Roll Damage](~@{character_id}|repeating_weapon_${id}_weapon_critdamagesmallmedium_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagelarge_chat_menu`] = `[Roll Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_critdamagelarge_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagesmallmedium_npc_chat_menu`] = `[Damage](~@{character_id}|repeating_weapon_${id}_weapon_critdamagesmallmedium_npc_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagelarge_npc_chat_menu`] = `[Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_critdamagelarge_npc_roll)`;
setAttrs(output, {silent: true});
getAttrs(['toggle_auto_damage'], (v) => {
const output = {};
const autoDamage = +v.toggle_auto_damage;
clog(`auto damage toggle:${autoDamage}`);
// NOTE: these macros substitute the damage rolls for the chatmenu buttons directly to support crit logic
const damageSmallMedium = `Damage vs S/M [[ (@{repeating_weapon_${id}_weapon_damagesmallmedium}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]`;
const damageLarge = ` vs LG [[ (@{repeating_weapon_${id}_weapon_damagelarge}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]`;
const damageSmallMediumNpc = `Damage vs S/M [[ (@{repeating_weapon_${id}_weapon_damagesmallmedium}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]`;
const damageLargeNPC = ` vs LG [[ (@{repeating_weapon_${id}_weapon_damagelarge}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]`;
const damageSmallMediumCrit = `Damage vs S/M [[ (@{repeating_weapon_${id}_weapon_critdamagesmallmedium}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]`;
const damageLargeCrit = ` vs LG [[ (@{repeating_weapon_${id}_weapon_critdamagelarge}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]`;
const damageSmallMediumNpcCrit = `Damage vs S/M [[ (@{repeating_weapon_${id}_weapon_critdamagesmallmedium}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]}}`;
const damageLargeNpcCrit = ` vs LG [[ (@{repeating_weapon_${id}_weapon_critdamagelarge}) * @{repeating_weapon_${id}_weapon_backstab_mult}[MULT] + ( @{repeating_weapon_${id}_weapon_attackdmgbonus}[DMG_BON] ) + ( @{repeating_weapon_${id}_weapon_magicbonus}[MAG_BON] ) + ( ?{Damage Modifier?|0}[MISC_MOD] ) ]]`;
if (autoDamage === 0) {
output[`repeating_weapon_${id}_weapon_damagesmallmedium_chat_menu`] = `[Roll Damage](~@{character_id}|repeating_weapon_${id}_weapon_damagesmallmedium_roll)`;
output[`repeating_weapon_${id}_weapon_damagelarge_chat_menu`] = `[Roll Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_damagelarge_roll)`;
output[`repeating_weapon_${id}_weapon_damagesmallmedium_npc_chat_menu`] = `[Damage](~@{character_id}|repeating_weapon_${id}_weapon_damagesmallmedium_npc_roll)`;
output[`repeating_weapon_${id}_weapon_damagelarge_npc_chat_menu`] = `[Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_damagelarge_npc_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagesmallmedium_chat_menu`] = `[Roll Damage](~@{character_id}|repeating_weapon_${id}_weapon_critdamagesmallmedium_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagelarge_chat_menu`] = `[Roll Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_critdamagelarge_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagesmallmedium_npc_chat_menu`] = `[Damage](~@{character_id}|repeating_weapon_${id}_weapon_critdamagesmallmedium_npc_roll)`;
output[`repeating_weapon_${id}_weapon_critdamagelarge_npc_chat_menu`] = `[Damage vs LG](~@{character_id}|repeating_weapon_${id}_weapon_critdamagelarge_npc_roll)`;
} else {
output[`repeating_weapon_${id}_weapon_damagesmallmedium_chat_menu`] = damageSmallMedium;
output[`repeating_weapon_${id}_weapon_damagelarge_chat_menu`] = damageLarge;
output[`repeating_weapon_${id}_weapon_damagesmallmedium_npc_chat_menu`] = damageSmallMediumNpc;
output[`repeating_weapon_${id}_weapon_damagelarge_npc_chat_menu`] = damageLargeNPC;
output[`repeating_weapon_${id}_weapon_critdamagesmallmedium_chat_menu`] = damageSmallMediumCrit;
output[`repeating_weapon_${id}_weapon_critdamagelarge_chat_menu`] = damageLargeCrit;
output[`repeating_weapon_${id}_weapon_critdamagesmallmedium_npc_chat_menu`] = damageSmallMediumNpcCrit;
output[`repeating_weapon_${id}_weapon_critdamagelarge_npc_chat_menu`] = damageLargeNpcCrit;
}
setAttrs(output, {silent: true});
});
};

// Ensures Chat Menu Buttons have updated Damage Rolls
on(
'change:repeating_weapon:weapon_name change:repeating_weapon:weapon_damagesmallmedium change:repeating_weapon:weapon_damagelarge change:repeating_weapon:weapon_critdamagesmallmedium change:repeating_weapon:weapon_critdamagelarge change:repeating_weapon:weapon_attackdmgbonus change:repeating_weapon:weapon_critdamage_flag',
(eventInfo) => {
// clog(`Change Detected:${eventInfo.sourceAttribute}`);
clog(`Change Detected:${eventInfo.sourceAttribute}`);
const id = eventInfo.sourceAttribute.split('_')[2];
damageMacro(id);
},
Expand All @@ -9733,6 +9762,18 @@ <h4 style="grid-row: 1/3; justify-self: left;">ADVANCED Options:</h4>
});
});

on('change:toggle_auto_damage change:toggle_critdamage', (eventInfo) => {
clog(`Change Detected:${eventInfo.sourceAttribute}`);
getSectionIDs('repeating_weapon', (idArray) => {
const fields = [];
getAttrs(fields, (v) => {
idArray.forEach((id) => {
damageMacro(id);
});
});
});
});

function setWeapons(id) {
const output = {};
const fields = [
Expand Down
Loading

0 comments on commit 4fa9c0b

Please sign in to comment.