Finished up work for fighters handbook integration

This commit is contained in:
Peter Bjerg Lidegaard
2021-12-07 19:27:28 +01:00
parent 57f6e388e2
commit b251e86a41
3 changed files with 304 additions and 270 deletions
+152 -135
View File
@@ -18001,7 +18001,7 @@
<tr>
<td>The Complete Fighter's Handbook</td>
<td>Weapons</td>
<td><label><input type='checkbox' name='attr_book-tcfhb' title="@{book-tcfhb}" value="The Complete Figther's Handbook"/><span></span></label></td>
<td><label><input type='checkbox' name='attr_book-tcfhb' title="@{book-tcfhb}" value="The Complete Fighter's Handbook"/><span></span></label></td>
</tr>
<tr>
<td>The Complete Wizard's Handbook</td>
@@ -32772,12 +32772,15 @@ priestSpells['primonster'] = primonster;
/* ---- Priest spells end ---- */
// --- ALL SHEET WORKERS START --- //
const sheetWorker = 'sheetworker';
const player = 'player';
const Success = 'success';
const Info = 'info';
const Warning = 'warning';
const Error = 'error';
const SHEETWORKER = 'sheetworker';
const PLAYER = 'player';
const SUCCESS = 'success';
const INFO = 'info';
const WARNING = 'warning';
const ERROR = 'error';
const BOOK_FIELDS = ['book-phb', 'book-tcfhb', 'book-tcwhb'];
on('clicked:hide-toast', function(eventInfo) {
setAttrs({
@@ -32789,10 +32792,10 @@ on('clicked:hide-toast', function(eventInfo) {
function showToast(type, title, message) {
let content
switch (type) {
case Success: content = 1; break;
case Info: content = 2; break;
case Warning: content = 3; break;
case Error: content = 4; break;
case SUCCESS: content = 1; break;
case INFO: content = 2; break;
case WARNING: content = 3; break;
case ERROR: content = 4; break;
}
setAttrs({
['toast']: 1,
@@ -32802,6 +32805,10 @@ function showToast(type, title, message) {
});
}
function isBookInactive(books, obj) {
return !Object.values(books).includes(obj['book']);
}
const squareBracketsRegex = /18\[([0-9]{1,3})]/; // Ie. 18[65]
const parenthesisRegex = /18\(([0-9]{1,3})\)/; // Ie. 18(65)
//Ability Score Parser function
@@ -33305,10 +33312,9 @@ function setupAutoFillSpellInfo(section, spellsTable, levelFunc) {
if (!spell)
return;
getAttrs(['book-phb', 'book-tcwhb'], function(values) {
let activeBooks = Object.values(values);
if (!activeBooks.includes(spell['book'])) {
showToast(Error, 'Missing Book', `The book *${spell['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`);
getAttrs(BOOK_FIELDS, function(books) {
if (isBookInactive(books, spell)) {
showToast(ERROR, 'Missing Book', `The book *${spell['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`);
return;
}
@@ -33456,7 +33462,7 @@ function setupAddPriestSpell(postfix) {
let elementalSpheres = parseSpheres(attributes.map(aField => a.S[aField]), elementalRegex);
if (primarySpheres.size < 1) {
showToast(Warning, 'No spheres found', `No valid spheres found. Please write or select some spheres`);
showToast(WARNING, 'No spheres found', `No valid spheres found. Please write or select some spheres`);
return;
}
@@ -33469,14 +33475,14 @@ function setupAddPriestSpell(postfix) {
console.log(spellsToAdd);
if (spellsToAdd.length < 1) {
showToast(Error, 'No spells found', `No spells found for the selected spheres`);
showToast(ERROR, 'No spells found', `No spells found for the selected spheres`);
return;
}
spellsToAdd = spellsToAdd.filter(spell => !knownSpells.has(spell));
console.log(spellsToAdd);
if (spellsToAdd.length < 1) {
showToast(Info, 'All spells added', `Found no more spells to add based on spheres`);
showToast(INFO, 'All spells added', `Found no more spells to add based on spheres`);
return;
}
@@ -33745,124 +33751,136 @@ on('change:nonprof-penalty', function (eventInfo) {
});
})
function getWeaponWithBonus(weaponName, isMonster) {
function setWeaponWithBonus(weaponName, setWeaponFunc, isMonster) {
if (!weaponName)
return undefined;
return;
weaponName = weaponName.toLowerCase();
let baseWeapon = weapons[weaponName];
if (baseWeapon) {
return {
...baseWeapon,
'bonus' : '0'
};
}
let match = weaponName.match(/\s*\+([0-9])+\s*/);
if (!match)
return undefined;
getAttrs(BOOK_FIELDS, function(books) {
let baseWeapon = weapons[weaponName];
if (baseWeapon) {
if (isBookInactive(books, baseWeapon)) {
showToast(ERROR, 'Missing Book', `The book *${baseWeapon['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`)
return;
}
let baseWeaponName = weaponName.replace(match[0], ' ').trim();
baseWeapon = weapons[baseWeaponName];
if (!baseWeapon)
return undefined;
let bonusString = match[1];
let bonus = parseInt(bonusString)
if (isNaN(bonus))
return undefined;
if (bonus < 1)
return {
setWeaponFunc({
...baseWeapon,
'bonus' : '0'
});
return;
}
let match = weaponName.match(/\s*\+([0-9])+\s*/);
if (!match)
return;
let baseWeaponName = weaponName.replace(match[0], ' ').trim();
baseWeapon = weapons[baseWeaponName];
if (!baseWeapon)
return;
if (isBookInactive(books, baseWeapon)) {
showToast(ERROR, 'Missing Book', `The book *${baseWeapon['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`)
return;
}
let bonusString = match[1];
let bonus = parseInt(bonusString)
if (isNaN(bonus))
return;
if (bonus < 1)
setWeaponFunc({
...baseWeapon,
'bonus' : '0'
});
return;
let weaponWithBonus = {
...baseWeapon,
'bonus' : '0'
};
let weaponWithBonus = {
...baseWeapon,
'speed' : Math.max(baseWeapon['speed'] - bonus, 0),
'bonus' : `+${bonus}`
}
if (isMonster) {
weaponWithBonus['small-medium'] += `+${bonus}`;
weaponWithBonus['large'] += `+${bonus}`;
weaponWithBonus['thac0'] = `@{monsterthac0}-${bonus}`;
}
return weaponWithBonus;
'speed' : Math.max(baseWeapon['speed'] - bonus, 0),
'bonus' : `+${bonus}`
}
if (isMonster) {
weaponWithBonus['small-medium'] += `+${bonus}`;
weaponWithBonus['large'] += `+${bonus}`;
weaponWithBonus['thac0'] = `@{monsterthac0}-${bonus}`;
}
setWeaponFunc(weaponWithBonus);
});
}
//melee hit autofill
on('change:repeating_weapons:weaponname', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
on('change:repeating_weapons:weaponname', function(eventInfo) {
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons_attackadj' : weapon['bonus'],
'repeating_weapons_range' : 'Melee',
'repeating_weapons_size' : weapon['size'],
'repeating_weapons_weapspeed' : weapon['speed'],
'repeating_weapons_weaptype-slash' : weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons_weaptype-pierce': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons_weaptype-blunt' : weapon['type'].includes('B') ? 1 : 0,
};
let weaponInfo = {
'repeating_weapons_attackadj' : weapon['bonus'],
'repeating_weapons_range' : 'Melee',
'repeating_weapons_size' : weapon['size'],
'repeating_weapons_weapspeed' : weapon['speed'],
'repeating_weapons_weaptype-slash' : weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons_weaptype-pierce': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons_weaptype-blunt' : weapon['type'].includes('B') ? 1 : 0,
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
//melee damage autofill
on('change:repeating_weapons-damage:weaponname1', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons-damage_damadj': weapon['bonus'],
'repeating_weapons-damage_damsm': weapon['small-medium'],
'repeating_weapons-damage_daml': weapon['large'],
'repeating_weapons-damage_knockdown1': weapon['knockdown'] || ''
};
let weaponInfo = {
'repeating_weapons-damage_damadj' : weapon['bonus'],
'repeating_weapons-damage_damsm' : weapon['small-medium'],
'repeating_weapons-damage_daml' : weapon['large'],
'repeating_weapons-damage_knockdown1': weapon['knockdown'] || ''
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
//range hit autofill
on('change:repeating_weapons2:weaponname2', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons2_strbonus2': weapon['strength'] ? 1 : 0,
'repeating_weapons2_attacknum2': weapon['rof'] || '',
'repeating_weapons2_attackadj2': weapon['bonus'],
'repeating_weapons2_range2': weapon['range'] || '',
'repeating_weapons2_size2': weapon['size'],
'repeating_weapons2_weapspeed2': weapon['speed'],
'repeating_weapons2_weaptype-slash2': weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons2_weaptype-pierce2': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons2_weaptype-blunt2': weapon['type'].includes('B') ? 1 : 0,
};
let weaponInfo = {
'repeating_weapons2_strbonus2' : weapon['strength'] ? 1 : 0,
'repeating_weapons2_attacknum2' : weapon['rof'] || '',
'repeating_weapons2_attackadj2' : weapon['bonus'],
'repeating_weapons2_range2' : weapon['range'] || '',
'repeating_weapons2_size2' : weapon['size'],
'repeating_weapons2_weapspeed2' : weapon['speed'],
'repeating_weapons2_weaptype-slash2' : weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons2_weaptype-pierce2': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons2_weaptype-blunt2' : weapon['type'].includes('B') ? 1 : 0,
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
//range damage autofill
on('change:repeating_ammo:ammoname', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons2_strbonus3': weapon['strength'] ? 1 : 0,
'repeating_ammo_damadj2': weapon['bonus'],
'repeating_ammo_damsm2': weapon['small-medium'],
'repeating_ammo_daml2': weapon['large'],
'repeating_weapons-damage_knockdown2': weapon['knockdown'] || ''
};
let weaponInfo = {
'repeating_weapons2_strbonus3' : weapon['strength'] ? 1 : 0,
'repeating_ammo_damadj2' : weapon['bonus'],
'repeating_ammo_damsm2' : weapon['small-medium'],
'repeating_ammo_daml2' : weapon['large'],
'repeating_weapons-damage_knockdown2': weapon['knockdown'] || ''
};
setAttrs(weaponInfo);
setAttrs(weaponInfo);
}
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
const extractQueryResult = async function(query){//Sends a message to query the user for some behavior, returns the selected option.
@@ -33935,24 +33953,23 @@ function setupFollowerWeaponsAutoFill(repeating, sections) {
sections.forEach(section => {
on(`change:${onChange}weaponnamehench${section}`, function(eventInfo) {
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let weaponInfo = {
[`${prefix}attacknumhench${section}`] : weapon['rof'] || '1',
[`${prefix}attackadjhench${section}`] : weapon['bonus'],
[`${prefix}damadjhench${section}`] : weapon['bonus'],
[`${prefix}damsmhench${section}`] : weapon['small-medium'],
[`${prefix}damlhench${section}`] : weapon['large'],
[`${prefix}rangehench${section}`] : weapon['range'] || 'Melee',
[`${prefix}weaptypehench${section}`] : weapon['type'],
[`${prefix}weapspeedhench${section}`] : weapon['speed'],
let setWeaponFunc = function (weapon) {
let weaponInfo = {
[`${prefix}attacknumhench${section}`]: weapon['rof'] || '1',
[`${prefix}attackadjhench${section}`]: weapon['bonus'],
[`${prefix}damadjhench${section}`]: weapon['bonus'],
[`${prefix}damsmhench${section}`]: weapon['small-medium'],
[`${prefix}damlhench${section}`]: weapon['large'],
[`${prefix}rangehench${section}`]: weapon['range'] || 'Melee',
[`${prefix}weaptypehench${section}`]: weapon['type'],
[`${prefix}weapspeedhench${section}`]: weapon['speed'],
};
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
})
})
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
});
}
const followerWeapons = [
@@ -33976,19 +33993,19 @@ followerWeapons.forEach(fw => {
// Monster weapons
on('change:repeating_monsterweapons:weaponname', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue, true);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
[`repeating_monsterweapons_attacknum`]: weapon['rof'] || '1',
[`repeating_monsterweapons_ThAC0`]: weapon['thac0'] || '@{monsterthac0}',
[`repeating_monsterweapons_damsm`]: weapon['small-medium'],
[`repeating_monsterweapons_daml`]: weapon['large'],
[`repeating_monsterweapons_weapspeed`]: weapon['speed'],
};
let weaponInfo = {
[`repeating_monsterweapons_attacknum`] : weapon['rof'] || '1',
[`repeating_monsterweapons_ThAC0`] : weapon['thac0'] || '@{monsterthac0}',
[`repeating_monsterweapons_damsm`] : weapon['small-medium'],
[`repeating_monsterweapons_daml`] : weapon['large'],
[`repeating_monsterweapons_weapspeed`] : weapon['speed'],
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc, true);
});
//Weapon proficiency slots
+1 -1
View File
@@ -12607,7 +12607,7 @@
<tr>
<td>The Complete Fighter's Handbook</td>
<td>Weapons</td>
<td><label><input type='checkbox' name='attr_book-tcfhb' title="@{book-tcfhb}" value="The Complete Figther's Handbook"/><span></span></label></td>
<td><label><input type='checkbox' name='attr_book-tcfhb' title="@{book-tcfhb}" value="The Complete Fighter's Handbook"/><span></span></label></td>
</tr>
<tr>
<td>The Complete Wizard's Handbook</td>
+151 -134
View File
@@ -1,10 +1,13 @@
// --- ALL SHEET WORKERS START --- //
const sheetWorker = 'sheetworker';
const player = 'player';
const Success = 'success';
const Info = 'info';
const Warning = 'warning';
const Error = 'error';
const SHEETWORKER = 'sheetworker';
const PLAYER = 'player';
const SUCCESS = 'success';
const INFO = 'info';
const WARNING = 'warning';
const ERROR = 'error';
const BOOK_FIELDS = ['book-phb', 'book-tcfhb', 'book-tcwhb'];
on('clicked:hide-toast', function(eventInfo) {
setAttrs({
@@ -16,10 +19,10 @@ on('clicked:hide-toast', function(eventInfo) {
function showToast(type, title, message) {
let content
switch (type) {
case Success: content = 1; break;
case Info: content = 2; break;
case Warning: content = 3; break;
case Error: content = 4; break;
case SUCCESS: content = 1; break;
case INFO: content = 2; break;
case WARNING: content = 3; break;
case ERROR: content = 4; break;
}
setAttrs({
['toast']: 1,
@@ -29,6 +32,10 @@ function showToast(type, title, message) {
});
}
function isBookInactive(books, obj) {
return !Object.values(books).includes(obj['book']);
}
const squareBracketsRegex = /18\[([0-9]{1,3})]/; // Ie. 18[65]
const parenthesisRegex = /18\(([0-9]{1,3})\)/; // Ie. 18(65)
//Ability Score Parser function
@@ -532,10 +539,9 @@ function setupAutoFillSpellInfo(section, spellsTable, levelFunc) {
if (!spell)
return;
getAttrs(['book-phb', 'book-tcwhb'], function(values) {
let activeBooks = Object.values(values);
if (!activeBooks.includes(spell['book'])) {
showToast(Error, 'Missing Book', `The book *${spell['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`);
getAttrs(BOOK_FIELDS, function(books) {
if (isBookInactive(books, spell)) {
showToast(ERROR, 'Missing Book', `The book *${spell['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`);
return;
}
@@ -683,7 +689,7 @@ function setupAddPriestSpell(postfix) {
let elementalSpheres = parseSpheres(attributes.map(aField => a.S[aField]), elementalRegex);
if (primarySpheres.size < 1) {
showToast(Warning, 'No spheres found', `No valid spheres found. Please write or select some spheres`);
showToast(WARNING, 'No spheres found', `No valid spheres found. Please write or select some spheres`);
return;
}
@@ -696,14 +702,14 @@ function setupAddPriestSpell(postfix) {
console.log(spellsToAdd);
if (spellsToAdd.length < 1) {
showToast(Error, 'No spells found', `No spells found for the selected spheres`);
showToast(ERROR, 'No spells found', `No spells found for the selected spheres`);
return;
}
spellsToAdd = spellsToAdd.filter(spell => !knownSpells.has(spell));
console.log(spellsToAdd);
if (spellsToAdd.length < 1) {
showToast(Info, 'All spells added', `Found no more spells to add based on spheres`);
showToast(INFO, 'All spells added', `Found no more spells to add based on spheres`);
return;
}
@@ -972,124 +978,136 @@ on('change:nonprof-penalty', function (eventInfo) {
});
})
function getWeaponWithBonus(weaponName, isMonster) {
function setWeaponWithBonus(weaponName, setWeaponFunc, isMonster) {
if (!weaponName)
return undefined;
return;
weaponName = weaponName.toLowerCase();
let baseWeapon = weapons[weaponName];
if (baseWeapon) {
return {
...baseWeapon,
'bonus' : '0'
};
}
let match = weaponName.match(/\s*\+([0-9])+\s*/);
if (!match)
return undefined;
getAttrs(BOOK_FIELDS, function(books) {
let baseWeapon = weapons[weaponName];
if (baseWeapon) {
if (isBookInactive(books, baseWeapon)) {
showToast(ERROR, 'Missing Book', `The book *${baseWeapon['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`)
return;
}
let baseWeaponName = weaponName.replace(match[0], ' ').trim();
baseWeapon = weapons[baseWeaponName];
if (!baseWeapon)
return undefined;
let bonusString = match[1];
let bonus = parseInt(bonusString)
if (isNaN(bonus))
return undefined;
if (bonus < 1)
return {
setWeaponFunc({
...baseWeapon,
'bonus' : '0'
});
return;
}
let match = weaponName.match(/\s*\+([0-9])+\s*/);
if (!match)
return;
let baseWeaponName = weaponName.replace(match[0], ' ').trim();
baseWeapon = weapons[baseWeaponName];
if (!baseWeapon)
return;
if (isBookInactive(books, baseWeapon)) {
showToast(ERROR, 'Missing Book', `The book *${baseWeapon['book']}* is currently not active on your sheet.\nGo to the *Sheet Settings* and activate the book (if your DM allows for its usage)`)
return;
}
let bonusString = match[1];
let bonus = parseInt(bonusString)
if (isNaN(bonus))
return;
if (bonus < 1)
setWeaponFunc({
...baseWeapon,
'bonus' : '0'
});
return;
let weaponWithBonus = {
...baseWeapon,
'bonus' : '0'
};
let weaponWithBonus = {
...baseWeapon,
'speed' : Math.max(baseWeapon['speed'] - bonus, 0),
'bonus' : `+${bonus}`
}
if (isMonster) {
weaponWithBonus['small-medium'] += `+${bonus}`;
weaponWithBonus['large'] += `+${bonus}`;
weaponWithBonus['thac0'] = `@{monsterthac0}-${bonus}`;
}
return weaponWithBonus;
'speed' : Math.max(baseWeapon['speed'] - bonus, 0),
'bonus' : `+${bonus}`
}
if (isMonster) {
weaponWithBonus['small-medium'] += `+${bonus}`;
weaponWithBonus['large'] += `+${bonus}`;
weaponWithBonus['thac0'] = `@{monsterthac0}-${bonus}`;
}
setWeaponFunc(weaponWithBonus);
});
}
//melee hit autofill
on('change:repeating_weapons:weaponname', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
on('change:repeating_weapons:weaponname', function(eventInfo) {
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons_attackadj' : weapon['bonus'],
'repeating_weapons_range' : 'Melee',
'repeating_weapons_size' : weapon['size'],
'repeating_weapons_weapspeed' : weapon['speed'],
'repeating_weapons_weaptype-slash' : weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons_weaptype-pierce': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons_weaptype-blunt' : weapon['type'].includes('B') ? 1 : 0,
};
let weaponInfo = {
'repeating_weapons_attackadj' : weapon['bonus'],
'repeating_weapons_range' : 'Melee',
'repeating_weapons_size' : weapon['size'],
'repeating_weapons_weapspeed' : weapon['speed'],
'repeating_weapons_weaptype-slash' : weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons_weaptype-pierce': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons_weaptype-blunt' : weapon['type'].includes('B') ? 1 : 0,
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
//melee damage autofill
on('change:repeating_weapons-damage:weaponname1', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons-damage_damadj': weapon['bonus'],
'repeating_weapons-damage_damsm': weapon['small-medium'],
'repeating_weapons-damage_daml': weapon['large'],
'repeating_weapons-damage_knockdown1': weapon['knockdown'] || ''
};
let weaponInfo = {
'repeating_weapons-damage_damadj' : weapon['bonus'],
'repeating_weapons-damage_damsm' : weapon['small-medium'],
'repeating_weapons-damage_daml' : weapon['large'],
'repeating_weapons-damage_knockdown1': weapon['knockdown'] || ''
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
//range hit autofill
on('change:repeating_weapons2:weaponname2', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons2_strbonus2': weapon['strength'] ? 1 : 0,
'repeating_weapons2_attacknum2': weapon['rof'] || '',
'repeating_weapons2_attackadj2': weapon['bonus'],
'repeating_weapons2_range2': weapon['range'] || '',
'repeating_weapons2_size2': weapon['size'],
'repeating_weapons2_weapspeed2': weapon['speed'],
'repeating_weapons2_weaptype-slash2': weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons2_weaptype-pierce2': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons2_weaptype-blunt2': weapon['type'].includes('B') ? 1 : 0,
};
let weaponInfo = {
'repeating_weapons2_strbonus2' : weapon['strength'] ? 1 : 0,
'repeating_weapons2_attacknum2' : weapon['rof'] || '',
'repeating_weapons2_attackadj2' : weapon['bonus'],
'repeating_weapons2_range2' : weapon['range'] || '',
'repeating_weapons2_size2' : weapon['size'],
'repeating_weapons2_weapspeed2' : weapon['speed'],
'repeating_weapons2_weaptype-slash2' : weapon['type'].includes('S') ? 1 : 0,
'repeating_weapons2_weaptype-pierce2': weapon['type'].includes('P') ? 1 : 0,
'repeating_weapons2_weaptype-blunt2' : weapon['type'].includes('B') ? 1 : 0,
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
//range damage autofill
on('change:repeating_ammo:ammoname', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
'repeating_weapons2_strbonus3': weapon['strength'] ? 1 : 0,
'repeating_ammo_damadj2': weapon['bonus'],
'repeating_ammo_damsm2': weapon['small-medium'],
'repeating_ammo_daml2': weapon['large'],
'repeating_weapons-damage_knockdown2': weapon['knockdown'] || ''
};
let weaponInfo = {
'repeating_weapons2_strbonus3' : weapon['strength'] ? 1 : 0,
'repeating_ammo_damadj2' : weapon['bonus'],
'repeating_ammo_damsm2' : weapon['small-medium'],
'repeating_ammo_daml2' : weapon['large'],
'repeating_weapons-damage_knockdown2': weapon['knockdown'] || ''
};
setAttrs(weaponInfo);
setAttrs(weaponInfo);
}
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
const extractQueryResult = async function(query){//Sends a message to query the user for some behavior, returns the selected option.
@@ -1162,24 +1180,23 @@ function setupFollowerWeaponsAutoFill(repeating, sections) {
sections.forEach(section => {
on(`change:${onChange}weaponnamehench${section}`, function(eventInfo) {
let weapon = getWeaponWithBonus(eventInfo.newValue);
if (weapon === undefined)
return;
let weaponInfo = {
[`${prefix}attacknumhench${section}`] : weapon['rof'] || '1',
[`${prefix}attackadjhench${section}`] : weapon['bonus'],
[`${prefix}damadjhench${section}`] : weapon['bonus'],
[`${prefix}damsmhench${section}`] : weapon['small-medium'],
[`${prefix}damlhench${section}`] : weapon['large'],
[`${prefix}rangehench${section}`] : weapon['range'] || 'Melee',
[`${prefix}weaptypehench${section}`] : weapon['type'],
[`${prefix}weapspeedhench${section}`] : weapon['speed'],
let setWeaponFunc = function (weapon) {
let weaponInfo = {
[`${prefix}attacknumhench${section}`]: weapon['rof'] || '1',
[`${prefix}attackadjhench${section}`]: weapon['bonus'],
[`${prefix}damadjhench${section}`]: weapon['bonus'],
[`${prefix}damsmhench${section}`]: weapon['small-medium'],
[`${prefix}damlhench${section}`]: weapon['large'],
[`${prefix}rangehench${section}`]: weapon['range'] || 'Melee',
[`${prefix}weaptypehench${section}`]: weapon['type'],
[`${prefix}weapspeedhench${section}`]: weapon['speed'],
};
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
})
})
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc);
});
});
}
const followerWeapons = [
@@ -1203,19 +1220,19 @@ followerWeapons.forEach(fw => {
// Monster weapons
on('change:repeating_monsterweapons:weaponname', function(eventInfo){
let weapon = getWeaponWithBonus(eventInfo.newValue, true);
if (weapon === undefined)
return;
let setWeaponFunc = function (weapon) {
let weaponInfo = {
[`repeating_monsterweapons_attacknum`]: weapon['rof'] || '1',
[`repeating_monsterweapons_ThAC0`]: weapon['thac0'] || '@{monsterthac0}',
[`repeating_monsterweapons_damsm`]: weapon['small-medium'],
[`repeating_monsterweapons_daml`]: weapon['large'],
[`repeating_monsterweapons_weapspeed`]: weapon['speed'],
};
let weaponInfo = {
[`repeating_monsterweapons_attacknum`] : weapon['rof'] || '1',
[`repeating_monsterweapons_ThAC0`] : weapon['thac0'] || '@{monsterthac0}',
[`repeating_monsterweapons_damsm`] : weapon['small-medium'],
[`repeating_monsterweapons_daml`] : weapon['large'],
[`repeating_monsterweapons_weapspeed`] : weapon['speed'],
setAttrs(weaponInfo);
};
setAttrs(weaponInfo);
setWeaponWithBonus(eventInfo.newValue, setWeaponFunc, true);
});
//Weapon proficiency slots