mirror of
https://github.com/Nighthawk42/roll20-character-sheets.git
synced 2026-09-06 07:02:28 +00:00
Updated repeating skills when a Close Combat rating is changed it updates the roll button for Weapons->Melee
This commit is contained in:
@@ -20,7 +20,9 @@ Change Log
|
||||
2021-01-11 - 2021-01-15
|
||||
Updated repeating items formatting
|
||||
Updated repeating items to make specialization and expertise buttons 15 characters if the actual display name is greater than 15
|
||||
|
||||
2021-01-16 - 2021-02-06
|
||||
Revamped Weapons->Melee to remove unused fields (Reach, AP, etc) and add range blocks and Specialization and Expertise checkboxes.
|
||||
Added functionality so if Close Combat skill rating is changed it updates the dice roller for melee weapons.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -836,11 +836,11 @@
|
||||
</div>
|
||||
<fieldset class="repeating_melee">
|
||||
<input name="attr_dicepool" type="hidden" value="0"/>
|
||||
<input name="attr_rating" type="hidden" value="0" />
|
||||
<input title="@{repeating_melee_${x}_rating}" name="attr_rating" type="hidden" value="0" />
|
||||
<input name="attr_skill" type="hidden" value=""/>
|
||||
<input class="flag-primary" name="attr_primary" type="hidden" value=""/>
|
||||
<input class="flag-primary" name="attr_additional" type="hidden" value=""/>
|
||||
<button name="roll_melee_weapon" type="roll" value="@{gm_toggle} &{template:rolls}{{mod=[[@{modifiers_toggle}]]}}{{wound=[[@{wounds_toggle}]]}}{{edge=[[@{edge_toggle}]]}}{{header=@{weapon}}}{{base=^{agility}}}{{dice=[[((@{rating}+@{spec}+@{expert}+@{dicepool_modifier}+@{agility})+@{wounds_toggle}+@{modifiers_toggle}+@{edge_toggle})d6>5@{explode_toggle}]]}}{{desc=DV @{damage}, Skill: @{skill}, other: @{Close Combat}, @{rating}, @{spec}, @{expert}}}"><span name="attr_weapon"></span></button>
|
||||
<button name="roll_melee_weapon" type="roll" value="@{gm_toggle} &{template:rolls}{{mod=[[@{modifiers_toggle}]]}}{{wound=[[@{wounds_toggle}]]}}{{edge=[[@{edge_toggle}]]}}{{header=@{weapon}}}{{base=^{agility}}}{{dice=[[((@{rating}+@{spec}+@{expert}+@{dicepool_modifier}+@{agility})+@{wounds_toggle}+@{modifiers_toggle}+@{edge_toggle})d6>5@{explode_toggle}]]}}{{desc=DV @{damage}, Skill: @{skill}, Close Combat: @{Close Combat}, Rating: @{rating}, Spec: @{spec}, Expert: @{expert}}}"><span name="attr_weapon"></span></button>
|
||||
<span class="center" name="attr_damage"></span>
|
||||
<span class="center" name="attr_close"></span>
|
||||
<span class="center" name="attr_near"></span>
|
||||
@@ -3100,7 +3100,8 @@
|
||||
|
||||
//Sheet workers
|
||||
on("sheet:opened", function() {
|
||||
console.log(`%c Shadowrun 6th World`, "color: blue; font-weight:bold");
|
||||
const version = '0.2';
|
||||
console.log(`%c Shadowrun 6th World v`+version, "color: blue; font-weight:bold");
|
||||
});
|
||||
|
||||
|
||||
@@ -3773,201 +3774,216 @@ on("change:repeating_skills", (eventinfo) => {
|
||||
});
|
||||
|
||||
|
||||
//REFACTORED Skills
|
||||
['repeating_skills','repeating_active','repeating_knowledge','repeating_language'].forEach(field => {
|
||||
on(`change:${field}`, (eventinfo) => {
|
||||
const source = eventinfo.sourceAttribute;
|
||||
const type = eventinfo.sourceType;
|
||||
//REFACTORED Skills
|
||||
['repeating_skills','repeating_active','repeating_knowledge','repeating_language'].forEach(field => {
|
||||
on(`change:${field}`, (eventinfo) => {
|
||||
const source = eventinfo.sourceAttribute;
|
||||
const type = eventinfo.sourceType;
|
||||
|
||||
if (source.includes("rating")) {
|
||||
getAttrs([`${field}_rating`, `${field}_rating_modifier`, `${field}_name`], (v) => {
|
||||
const bas = parseInt(v[`${field}_rating`]) || 0;
|
||||
const mod = parseInt(v[`${field}_rating_modifier`]) || 0;
|
||||
const tot = bas + mod;
|
||||
const skill = v[`${field}_name`] || '';
|
||||
if (source.includes("rating")) {
|
||||
getAttrs([`${field}_rating`, `${field}_rating_modifier`, `${field}_name`], (v) => {
|
||||
const bas = parseInt(v[`${field}_rating`]) || 0;
|
||||
const mod = parseInt(v[`${field}_rating_modifier`]) || 0;
|
||||
const tot = bas + mod;
|
||||
const skill = v[`${field}_name`] || '';
|
||||
|
||||
setAttrs({
|
||||
[`${field}_dicepool`]: tot,
|
||||
[`${field}_rating`]: bas,
|
||||
[`${field}_display_rating`]: (mod === 0) ? bas : `${bas} (${tot})`,
|
||||
[skill]: bas
|
||||
});
|
||||
});
|
||||
} else if (source.includes("attribute") && type === "player") {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const attribute = v[`${source}`].slice(2, -1);
|
||||
const translation = getTranslationByKey(`${attribute}`);
|
||||
setAttrs({
|
||||
[`${field}_display_attribute`]: translation
|
||||
});
|
||||
});
|
||||
} else if (source.includes("limit") && type === "player") {
|
||||
// const limit = eventinfo.newValue.slice(2, -1);
|
||||
// if (eventinfo.newValue === "none") {
|
||||
// setAttrs({
|
||||
// [`${field}_display_limit`]: ""
|
||||
// });
|
||||
// } else {
|
||||
// const translation = getTranslationByKey(`${limit}`);
|
||||
// setAttrs({
|
||||
// [`${field}_display_limit`]: `${translation} ${eventinfo.newValue}`
|
||||
// });
|
||||
// }
|
||||
} else if (source.includes("spec") && type === "player") {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const bas = v[`${source}`];
|
||||
const size = bas.length;
|
||||
let display = (size >= 0 && size <= 15) ? `${bas}` : "(" + bas.slice(0, 15) + "...)";
|
||||
setAttrs({
|
||||
[`${field}_display_spec`]: display
|
||||
getSectionIDs("melee", function(ids) {
|
||||
for(var i = 0; i < ids.length; i++) {
|
||||
let skillIdName = "repeating_melee_" + ids[i] + "_skill";
|
||||
let skillRating = "repeating_melee_" + ids[i] + "_rating";
|
||||
getAttrs([skillIdName], (v2) => {
|
||||
if(v2[skillIdName] == v[`${field}_name`]) {
|
||||
setAttrs({
|
||||
[skillRating]: bas
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if (source.includes("expert") && type === "player") {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const bas = v[`${source}`];
|
||||
const size = bas.length;
|
||||
let display = (size >= 0 && size <= 15) ? `${bas}` : "(" + bas.slice(0, 15) + "...)";
|
||||
setAttrs({
|
||||
[`${field}_display_expert`]: display
|
||||
});
|
||||
});
|
||||
} else if (source.includes("skill")) {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const bas = v[`${source}`];
|
||||
const size = bas.length;
|
||||
let display = (size > 0 && size <= 20) ? bas : (size > 20 ) ? bas.slice(0, 20) + "..." : " ";
|
||||
setAttrs({
|
||||
[`${field}_display`]: display
|
||||
});
|
||||
});
|
||||
} else if (source.includes("dicepool")) {
|
||||
getAttrs([`${source}`, `${field}_skill`], (v) => {
|
||||
const skill = v[`${field}_skill`];
|
||||
let lowercase = skill.toLowerCase();
|
||||
let removeGroup = (lowercase.includes("group")) ? lowercase.slice(0, -6) : lowercase;
|
||||
let skillSet = (removeGroup.includes(" ")) ? removeGroup.replace(/ /g,"") : removeGroup;
|
||||
setAttrs({
|
||||
[`${skillSet}`]: v[`${source}`]
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log(`Change to ${field} did not set attr`);
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Setting the Default attribute name for default skill
|
||||
on("change:default_attribute", (eventinfo) => {
|
||||
getAttrs(["default_display"], (v) => {
|
||||
const display = (v.default_display);
|
||||
let update = {};
|
||||
|
||||
//This sets a hidden input with the Attribute name so the roll template can use it to indicate what attribute was rolled
|
||||
const attribute = eventinfo.newValue.slice(2, -1);
|
||||
const translation = getTranslationByKey(`${attribute}`);
|
||||
if (translation != display) {
|
||||
setAttrs({
|
||||
default_display: translation
|
||||
});
|
||||
};
|
||||
setAttrs({
|
||||
[`${field}_dicepool`]: tot,
|
||||
[`${field}_rating`]: bas,
|
||||
[`${field}_display_rating`]: (mod === 0) ? bas : `${bas} (${tot})`,
|
||||
[skill]: bas
|
||||
});
|
||||
});
|
||||
} else if (source.includes("attribute") && type === "player") {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const attribute = v[`${source}`].slice(2, -1);
|
||||
const translation = getTranslationByKey(`${attribute}`);
|
||||
setAttrs({
|
||||
[`${field}_display_attribute`]: translation
|
||||
});
|
||||
});
|
||||
} else if (source.includes("spec") && type === "player") {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const bas = v[`${source}`];
|
||||
const size = bas.length;
|
||||
let display = (size >= 0 && size <= 15) ? `${bas}` : "(" + bas.slice(0, 15) + "...)";
|
||||
setAttrs({
|
||||
[`${field}_display_spec`]: display
|
||||
});
|
||||
});
|
||||
} else if (source.includes("expert") && type === "player") {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const bas = v[`${source}`];
|
||||
const size = bas.length;
|
||||
let display = (size >= 0 && size <= 15) ? `${bas}` : "(" + bas.slice(0, 15) + "...)";
|
||||
setAttrs({
|
||||
[`${field}_display_expert`]: display
|
||||
});
|
||||
});
|
||||
} else if (source.includes("skill")) {
|
||||
getAttrs([`${source}`], (v) => {
|
||||
const bas = v[`${source}`];
|
||||
const size = bas.length;
|
||||
let display = (size > 0 && size <= 20) ? bas : (size > 20 ) ? bas.slice(0, 20) + "..." : " ";
|
||||
setAttrs({
|
||||
[`${field}_display`]: display
|
||||
});
|
||||
});
|
||||
} else if (source.includes("dicepool")) {
|
||||
getAttrs([`${source}`, `${field}_skill`], (v) => {
|
||||
const skill = v[`${field}_skill`];
|
||||
let lowercase = skill.toLowerCase();
|
||||
let removeGroup = (lowercase.includes("group")) ? lowercase.slice(0, -6) : lowercase;
|
||||
let skillSet = (removeGroup.includes(" ")) ? removeGroup.replace(/ /g,"") : removeGroup;
|
||||
setAttrs({
|
||||
[`${skillSet}`]: v[`${source}`]
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log(`Change to ${field} did not set attr`);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//Setting the Default attribute name for default skill
|
||||
//on("change:default_attribute", (eventinfo) => {
|
||||
// getAttrs(["default_display"], (v) => {
|
||||
// const display = (v.default_display);
|
||||
// let update = {};
|
||||
|
||||
// //This sets a hidden input with the Attribute name so the roll template can use it to indicate what attribute was rolled
|
||||
// const attribute = eventinfo.newValue.slice(2, -1);
|
||||
// const translation = getTranslationByKey(`${attribute}`);
|
||||
// if (translation != display) {
|
||||
// setAttrs({
|
||||
// default_display: translation
|
||||
// });
|
||||
// };
|
||||
// });
|
||||
//});
|
||||
|
||||
|
||||
|
||||
//REFACTORED Range & MELEE UPDATES
|
||||
['repeating_range','repeating_melee'].forEach(weap => {
|
||||
on(`change:${weap}`, (eventInfo) => {
|
||||
const source = eventInfo.sourceAttribute;
|
||||
const newV = eventInfo.newValue;
|
||||
const type = weap.slice(-5);
|
||||
console.log(`${weap}` + ' changed!');
|
||||
console.log(source);
|
||||
console.log(weap);
|
||||
getAttrs([`${weap}_dicepool_modifier`, `${weap}_spec`, `${weap}_expert`, `${weap}_skill`], (v) => {
|
||||
const mod = parseInt(v[`${weap}_dicepool_modifier`]) || 0;
|
||||
const spec = parseInt(v[`${weap}_spec`]) || 0;
|
||||
const expert = parseInt(v[`${weap}_expert`]) || 0;
|
||||
const skill = v[`${weap}_skill`] || '';
|
||||
|
||||
getAttrs([`${skill}`], (s) => {
|
||||
console.log('rating: ' + s[`${skill}`]);
|
||||
rating = s[`${skill}`];
|
||||
|
||||
const tot = mod + spec + expert + rating;
|
||||
console.log('tot: ' + tot);
|
||||
setAttrs({
|
||||
[`${weap}_rating`]: s[`${skill}`],
|
||||
[`${weap}_dicepool`]: tot
|
||||
});
|
||||
});
|
||||
console.log('rating: ' + rating);
|
||||
|
||||
// const tot = mod + spec + expert + rating;
|
||||
//console.log('tot: ' + tot);
|
||||
// setAttrs({
|
||||
// [`${weap}_dicepool`]: tot
|
||||
// });
|
||||
});
|
||||
|
||||
if (source.includes('primary')) {
|
||||
if (newV === 'primary') {
|
||||
//Shared attributes names.
|
||||
let array = ["dicepool", "weapon", "damage", "skill", "rating", "close", "near", "medium", "far", "extreme", "spec", "expert"];
|
||||
|
||||
//REFACTORED Range & MELEE UPDATES
|
||||
['repeating_range','repeating_melee'].forEach(weap => {
|
||||
on(`change:${weap}`, (eventInfo) => {
|
||||
const source = eventInfo.sourceAttribute;
|
||||
const newV = eventInfo.newValue;
|
||||
const type = weap.slice(-5);
|
||||
//Add the range or melee specific ones
|
||||
if(type === "range") {
|
||||
array.push("ammo", "ammo_max", "mode");
|
||||
}
|
||||
|
||||
getAttrs([`${weap}_dicepool_modifier`, `${weap}_spec`, `${weap}_skill`], (v) => {
|
||||
const mod = parseInt(v[`${weap}_dicepool_modifier`]) || 0;
|
||||
const spec = parseInt(v[`${weap}_spec`]) || 0;
|
||||
const tot = mod + spec;
|
||||
const skill = v[`${weap}_skill`] || '';
|
||||
//Add the repeating section to the begining of each attribute
|
||||
let attrs = [];
|
||||
for(var i=0; i < array.length; i++) {
|
||||
attrs.push(`${weap}_` + array[i]);
|
||||
};
|
||||
|
||||
getAttrs([`${skill}`], (s) => {
|
||||
setAttrs({
|
||||
[`${weap}_rating`]: s[`${skill}`]
|
||||
});
|
||||
});
|
||||
getAttrs(attrs, (v) => {
|
||||
let update = {};
|
||||
//Primary weapon name does not follow the naming scheme.
|
||||
update[`primary_${type}_weapon`] = v[`${weap}_weapon`];
|
||||
|
||||
|
||||
setAttrs({
|
||||
[`${weap}_dicepool`]: tot
|
||||
});
|
||||
});
|
||||
|
||||
if (source.includes('primary')) {
|
||||
if (newV === 'primary') {
|
||||
//Shared attributes names.
|
||||
let array = ["dicepool", "weapon", "damage", "skill", "rating", "close", "near", "medium", "far", "extreme", "spec", "expert"];
|
||||
|
||||
//Add the range or melee specific ones
|
||||
if(type === "range") {
|
||||
array.push("ammo", "ammo_max", "mode");
|
||||
}
|
||||
|
||||
//Add the repeating section to the begining of each attribute
|
||||
let attrs = [];
|
||||
for(var i=0; i < array.length; i++) {
|
||||
attrs.push(`${weap}_` + array[i]);
|
||||
};
|
||||
|
||||
getAttrs(attrs, (v) => {
|
||||
let update = {};
|
||||
//Primary weapon name does not follow the naming scheme.
|
||||
update[`primary_${type}_weapon`] = v[`${weap}_weapon`];
|
||||
|
||||
_.each(array, (value) => {
|
||||
if (value != undefined || value != "weapon") {
|
||||
update[`primary_${type}_weapon_${value}`] = (value === "ammo_max") ? v[`${weap}_ammo`] : v[`${weap}_${value}`];
|
||||
};
|
||||
});
|
||||
|
||||
setAttrs(update);
|
||||
});
|
||||
|
||||
//Set the other repeating_weapon primary flags to 0 aka unchecked
|
||||
getSectionIDs(`${weap}`, function(ids) {
|
||||
let IDs = [];
|
||||
let update = {};
|
||||
|
||||
for(var i=0; i < ids.length; i++) {
|
||||
IDs.push(`${weap}_` + ids[i] + "_primary");
|
||||
};
|
||||
|
||||
IDs.forEach(id => {
|
||||
if (id != source) {
|
||||
update[`${id}`] = 0;
|
||||
};
|
||||
});
|
||||
|
||||
setAttrs(update);
|
||||
});
|
||||
};
|
||||
} else if (source.includes('dicepool') || source.includes('weapon') || source.includes('damage') || source.includes('acc') || source.includes('ap') || source.includes('skill') || source.includes('reach') || source.includes('ammo') || source.includes('mode') || source.includes('recoil')) {
|
||||
getAttrs([`${weap}_primary`, `${source}`], (v) => {
|
||||
if (v[`${weap}_primary`] === 'primary') {
|
||||
let update = {};
|
||||
//This whole process needs refactored in the future. Its working for now.
|
||||
if (source.includes('ammo')) {
|
||||
update[`primary_${type}_weapon_ammo`] = v[`${source}`];
|
||||
update[`primary_${type}_weapon_ammo_max`] = v[`${source}`];
|
||||
} else {
|
||||
console.log(eventInfo);
|
||||
};
|
||||
|
||||
setAttrs(update);
|
||||
_.each(array, (value) => {
|
||||
if (value != undefined || value != "weapon") {
|
||||
update[`primary_${type}_weapon_${value}`] = (value === "ammo_max") ? v[`${weap}_ammo`] : v[`${weap}_${value}`];
|
||||
};
|
||||
});
|
||||
} else {
|
||||
console.log("Change was not relevant.");
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
setAttrs(update);
|
||||
});
|
||||
|
||||
//Set the other repeating_weapon primary flags to 0 aka unchecked
|
||||
getSectionIDs(`${weap}`, function(ids) {
|
||||
let IDs = [];
|
||||
let update = {};
|
||||
|
||||
for(var i=0; i < ids.length; i++) {
|
||||
IDs.push(`${weap}_` + ids[i] + "_primary");
|
||||
};
|
||||
|
||||
IDs.forEach(id => {
|
||||
if (id != source) {
|
||||
update[`${id}`] = 0;
|
||||
};
|
||||
});
|
||||
|
||||
setAttrs(update);
|
||||
});
|
||||
};
|
||||
} else if (source.includes('dicepool') || source.includes('weapon') || source.includes('damage') || source.includes('skill') || source.includes('rating') || source.includes('ammo') || source.includes('mode')) {
|
||||
getAttrs([`${weap}_primary`, `${source}`], (v) => {
|
||||
if (v[`${weap}_primary`] === 'primary') {
|
||||
let update = {};
|
||||
//This whole process needs refactored in the future. Its working for now.
|
||||
if (source.includes('ammo')) {
|
||||
update[`primary_${type}_weapon_ammo`] = v[`${source}`];
|
||||
update[`primary_${type}_weapon_ammo_max`] = v[`${source}`];
|
||||
} else {
|
||||
console.log(eventInfo);
|
||||
};
|
||||
|
||||
setAttrs(update);
|
||||
};
|
||||
});
|
||||
} else {
|
||||
console.log("Change was not relevant.");
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
//PC SPELLS/PREPS/RITUALS
|
||||
['repeating_spell','repeating_preps','repeating_ritual'].forEach(field => {
|
||||
|
||||
Reference in New Issue
Block a user