diff --git a/README.md b/README.md
index 27148d7..8dee455 100644
--- a/README.md
+++ b/README.md
@@ -98,3 +98,9 @@ localisation. Les résistances cochées se cumulent et retirent chacune deux DMG
par point. Une protection cochée ne compte que si son intégrité est supérieure
à zéro ; le calcul retire alors sa Protection ainsi que la Force finale du
défenseur sélectionné.
+
+Le menu Protection de **Subir** permet d'utiliser les protections cochées ou la
+protection d'une localisation fixe/personnalisée. Pour l'AB, les résistances
+retirent un point par point et seule la première protection valide de la liste
+Combat s'applique, sans la Force ; ordonnez donc les protections de haut en bas
+selon leur ordre d'impact.
diff --git a/build/build-info.json b/build/build-info.json
index 82913c8..82764ca 100644
--- a/build/build-info.json
+++ b/build/build-info.json
@@ -4,5 +4,5 @@
"max_tier_exclusive": 5,
"techniques": 232,
"skills": 26,
- "content_hash": "190eaeab27cc"
+ "content_hash": "c4b53c0a8188"
}
diff --git a/build/ravenous.html b/build/ravenous.html
index e064ece..66d1ec6 100644
--- a/build/ravenous.html
+++ b/build/ravenous.html
@@ -97,6 +97,9 @@
@@ -420,7 +423,8 @@
{{#damagecalc}}DMG {{computed::damage}}
{{/damagecalc}}
{{#damage}}{{^damagecalc}}DMG {{damage}}
{{/damagecalc}}{{/damage}}
{{#damagebreakdown}}Calcul : {{computed::incoming_damage}} − {{computed::resistance_reduction}} (resist) − {{computed::protection_reduction}} (armor) = {{computed::damage}}
{{/damagebreakdown}}
- {{#breakdamage}}AB {{breakdamage}}
{{/breakdamage}}
+ {{#abcalc}}AB subi {{computed::break_damage}}
Calcul AB : {{computed::incoming_break}} − {{computed::break_resistance}} (resist) − {{computed::break_protection}} (first armor) = {{computed::break_damage}}
{{/abcalc}}
+ {{#breakdamage}}{{^abcalc}}AB {{breakdamage}}
{{/abcalc}}{{/breakdamage}}
{{#thresholds}}Défenses {{thresholds}}
{{/thresholds}}
{{#buttons}}{{buttons}}
{{/buttons}}
{{#cost}}Coût {{cost}}
{{/cost}}
@@ -443,6 +447,14 @@ const attackDamage = (attack, defenseSuccesses = 0) => {
return {finalSuccesses, damage};
};
const DAMAGE_RESISTANCES = ["slash","pierce","blunt","fire","earth","wood","magma","water","wind","ice","lightning","abyssal","celestial"];
+const FIXED_LOCATIONS = [["Tête","head"],["Torse","torso"],["Bras gauche","left_arm"],["Bras droit","right_arm"],["Jambe gauche","left_leg"],["Jambe droite","right_leg"]];
+const PACK_FACTOR = 10000;
+const safeQueryLabel = value => String(value || "Localisation").replace(/[|,}]/g, " ");
+const packedProtection = (protection, hasIntegrity, force) => {
+ const effectiveProtection = hasIntegrity ? Math.max(0, Math.round(number(protection))) : 0;
+ const mitigation = hasIntegrity ? effectiveProtection + Math.max(0, Math.round(number(force))) : 0;
+ return mitigation * PACK_FACTOR + effectiveProtection;
+};
const recalculateDamageResistances = () => {
const attrs = DAMAGE_RESISTANCES.flatMap(type => [`resist_${type}`, `damage_apply_${type}`]);
@@ -455,12 +467,36 @@ const recalculateDamageResistances = () => {
const recalculateProtections = () => getSectionIDs("protections", ids => {
const attrs = ids.flatMap(id => [`repeating_protections_${id}_active`,`repeating_protections_${id}_integrity`,`repeating_protections_${id}_protection`]);
getAttrs(attrs, values => {
- let total = 0; let count = 0;
+ let total = 0; let count = 0; let firstProtection = 0;
ids.forEach(id => {
const prefix = `repeating_protections_${id}_`;
- if (values[prefix+"active"] === "1" && number(values[prefix+"integrity"]) > 0) { total += number(values[prefix+"protection"]); count += 1; }
+ if (values[prefix+"active"] === "1" && number(values[prefix+"integrity"]) > 0) {
+ const protection = number(values[prefix+"protection"]);
+ total += protection;
+ if (count === 0) firstProtection = protection;
+ count += 1;
+ }
});
- setAttrs({active_protection_total:total, active_protection_count:count}, {silent:true});
+ getAttrs(["force_total"], character => {
+ const mitigation = count > 0 ? total + number(character.force_total) : 0;
+ setAttrs({active_protection_total:total, active_protection_count:count, active_first_protection:firstProtection, active_mitigation_total:mitigation}, {silent:true}, recalculateDamageLocations);
+ });
+ });
+});
+
+const recalculateDamageLocations = () => getSectionIDs("locations", ids => {
+ const fixedAttrs = ["force_total","active_mitigation_total","active_first_protection", ...FIXED_LOCATIONS.flatMap(([,key]) => [`${key}_protection`,`${key}_armor`])];
+ const customAttrs = ids.flatMap(id => [`repeating_locations_${id}_name`,`repeating_locations_${id}_protection`,`repeating_locations_${id}_armor`]);
+ getAttrs([...fixedAttrs,...customAttrs], values => {
+ const force = number(values.force_total);
+ const selectedPacked = Math.round(number(values.active_mitigation_total)) * PACK_FACTOR + Math.max(0, Math.round(number(values.active_first_protection)));
+ const options = [`Sélection actuelle,${selectedPacked}`];
+ FIXED_LOCATIONS.forEach(([label,key]) => options.push(`${label},${packedProtection(values[`${key}_protection`], number(values[`${key}_armor`]) > 0, force)}`));
+ ids.forEach(id => {
+ const prefix = `repeating_locations_${id}_`;
+ options.push(`${safeQueryLabel(values[prefix+"name"])},${packedProtection(values[prefix+"protection"], number(values[prefix+"armor"]) > 0, force)}`);
+ });
+ setAttrs({damage_location_query:`?{Protection|${options.join("|")}}`}, {silent:true});
});
});
@@ -530,15 +566,19 @@ on("clicked:repeating_attacks:damage", event => {
on("clicked:repeating_attacks:take_damage", event => {
const prefix = event.sourceAttribute.replace(/take_damage$/, "");
getAttrs([prefix+"name",prefix+"base_damage",prefix+"damage_per_success",prefix+"break_damage",prefix+"rmax"], values => {
- const command = `&{template:ravenous} {{title=Subir · ${templateText(values[prefix+"name"] || "Attaque")}}} {{subtitle=@{selected|character_name}}} {{damagecalc=1}} {{damagebreakdown=1}} {{remaining=[[?{Succès restants|1}]]}} {{selected_resistance=[[@{selected|damage_resistance_total}]]}} {{selected_protection=[[@{selected|active_protection_total}]]}} {{selected_protection_count=[[@{selected|active_protection_count}]]}} {{selected_strength=[[@{selected|force_total}]]}} {{finalsuccesses=[[0]]}} {{incoming_damage=[[0]]}} {{resistance_reduction=[[0]]}} {{protection_reduction=[[0]]}} {{damage=[[0]]}} {{breakdamage=${number(values[prefix+"break_damage"])}}}`;
+ const command = `&{template:ravenous} {{title=Subir · ${templateText(values[prefix+"name"] || "Attaque")}}} {{subtitle=@{selected|character_name}}} {{damagecalc=1}} {{damagebreakdown=1}} {{abcalc=1}} {{remaining=[[?{Succès restants|1}]]}} {{selected_resistance=[[@{selected|damage_resistance_total}]]}} {{location_protection=[[@{selected|damage_location_query}]]}} {{finalsuccesses=[[0]]}} {{incoming_damage=[[0]]}} {{resistance_reduction=[[0]]}} {{protection_reduction=[[0]]}} {{damage=[[0]]}} {{incoming_break=[[0]]}} {{break_resistance=[[0]]}} {{break_protection=[[0]]}} {{break_damage=[[0]]}}`;
startRoll(`@{selected|roll_whisper}${command}`, results => {
const remaining = Math.max(0, Math.floor(results.results.remaining.result));
const finalSuccesses = Math.min(remaining, Math.max(0, Math.floor(number(values[prefix+"rmax"]))));
const incoming = finalSuccesses > 0 ? number(values[prefix+"base_damage"]) + (finalSuccesses - 1) * number(values[prefix+"damage_per_success"]) : 0;
const resistanceReduction = results.results.selected_resistance.result * 2;
- const hasProtection = results.results.selected_protection_count.result > 0;
- const protectionReduction = hasProtection ? results.results.selected_protection.result + results.results.selected_strength.result : 0;
- finishRoll(results.rollId, {finalsuccesses:finalSuccesses, incoming_damage:incoming, resistance_reduction:resistanceReduction, protection_reduction:protectionReduction, damage:Math.max(0, incoming - resistanceReduction - protectionReduction)});
+ const packed = Math.max(0, Math.round(results.results.location_protection.result));
+ const protectionReduction = Math.floor(packed / PACK_FACTOR);
+ const firstProtection = packed % PACK_FACTOR;
+ const incomingBreak = Math.max(0, number(values[prefix+"break_damage"]));
+ const breakResistance = Math.max(0, results.results.selected_resistance.result);
+ const breakDamage = Math.max(0, Math.min(incomingBreak, incomingBreak - breakResistance - firstProtection));
+ finishRoll(results.rollId, {finalsuccesses:finalSuccesses, incoming_damage:incoming, resistance_reduction:resistanceReduction, protection_reduction:protectionReduction, damage:Math.max(0, incoming - resistanceReduction - protectionReduction), incoming_break:incomingBreak, break_resistance:breakResistance, break_protection:firstProtection, break_damage:breakDamage});
});
});
});
@@ -567,7 +607,7 @@ const recalculate = () => {
update.toxicite_max = 8 + stage + number(values.toxicite_max_modifier);
update.satiete_max = 6 + Math.floor(stage / 2) + number(values.satiete_max_modifier);
update.actions_max = 4 + number(values.actions_max_modifier);
- setAttrs(update, {silent: true}, () => { recalculateSkills(); recalculateCustomSkills(); });
+ setAttrs(update, {silent: true}, () => { recalculateSkills(); recalculateCustomSkills(); recalculateProtections(); });
});
};
@@ -602,7 +642,8 @@ const recalculateCustomSkills = () => getSectionIDs("customskills", ids => {
on("sheet:opened change:force change:agilite change:perception change:intelligence change:volonte change:psy change:chance change:charisme change:stage change:force_manual change:agilite_manual change:perception_manual change:intelligence_manual change:volonte_manual change:psy_manual change:chance_manual change:charisme_manual change:torque_modifier change:speed_modifier change:half_speed_modifier change:run_speed_modifier change:swim_speed_modifier change:fly_speed_modifier change:hp_modifier change:jauge_max_modifier change:fatigue_max_modifier change:toxicite_max_modifier change:satiete_max_modifier change:actions_max_modifier", recalculate);
on("sheet:opened change:secret_rolls", () => getAttrs(["secret_rolls"], values => setAttrs({roll_whisper:values.secret_rolls === "1" ? "/w gm " : ""}, {silent:true})));
on(`sheet:opened ${DAMAGE_RESISTANCES.flatMap(type => [`change:resist_${type}`,`change:damage_apply_${type}`]).join(" ")}`, recalculateDamageResistances);
-on("sheet:opened change:repeating_protections", recalculateProtections);
+on("sheet:opened change:repeating_protections change:_reporder_repeating_protections", recalculateProtections);
+on(`sheet:opened change:repeating_locations ${FIXED_LOCATIONS.flatMap(([,key]) => [`change:${key}_protection`,`change:${key}_armor`]).join(" ")}`, recalculateDamageLocations);
on("clicked:clear_damage_resistances", () => {
const update = {};
DAMAGE_RESISTANCES.forEach(type => update[`damage_apply_${type}`] = "0");
diff --git a/src/ravenous.html b/src/ravenous.html
index 6c8a343..8361694 100644
--- a/src/ravenous.html
+++ b/src/ravenous.html
@@ -97,6 +97,9 @@
Résistance cumulée 0 Protection active 0 Tout décocher
+
+
+
@@ -209,7 +212,8 @@
{{#damagecalc}}DMG {{computed::damage}}
{{/damagecalc}}
{{#damage}}{{^damagecalc}}DMG {{damage}}
{{/damagecalc}}{{/damage}}
{{#damagebreakdown}}Calcul : {{computed::incoming_damage}} − {{computed::resistance_reduction}} (resist) − {{computed::protection_reduction}} (armor) = {{computed::damage}}
{{/damagebreakdown}}
- {{#breakdamage}}AB {{breakdamage}}
{{/breakdamage}}
+ {{#abcalc}}AB subi {{computed::break_damage}}
Calcul AB : {{computed::incoming_break}} − {{computed::break_resistance}} (resist) − {{computed::break_protection}} (first armor) = {{computed::break_damage}}
{{/abcalc}}
+ {{#breakdamage}}{{^abcalc}}AB {{breakdamage}}
{{/abcalc}}{{/breakdamage}}
{{#thresholds}}Défenses {{thresholds}}
{{/thresholds}}
{{#buttons}}{{buttons}}
{{/buttons}}
{{#cost}}Coût {{cost}}
{{/cost}}
@@ -232,6 +236,14 @@ const attackDamage = (attack, defenseSuccesses = 0) => {
return {finalSuccesses, damage};
};
const DAMAGE_RESISTANCES = ["slash","pierce","blunt","fire","earth","wood","magma","water","wind","ice","lightning","abyssal","celestial"];
+const FIXED_LOCATIONS = [["Tête","head"],["Torse","torso"],["Bras gauche","left_arm"],["Bras droit","right_arm"],["Jambe gauche","left_leg"],["Jambe droite","right_leg"]];
+const PACK_FACTOR = 10000;
+const safeQueryLabel = value => String(value || "Localisation").replace(/[|,}]/g, " ");
+const packedProtection = (protection, hasIntegrity, force) => {
+ const effectiveProtection = hasIntegrity ? Math.max(0, Math.round(number(protection))) : 0;
+ const mitigation = hasIntegrity ? effectiveProtection + Math.max(0, Math.round(number(force))) : 0;
+ return mitigation * PACK_FACTOR + effectiveProtection;
+};
const recalculateDamageResistances = () => {
const attrs = DAMAGE_RESISTANCES.flatMap(type => [`resist_${type}`, `damage_apply_${type}`]);
@@ -244,12 +256,36 @@ const recalculateDamageResistances = () => {
const recalculateProtections = () => getSectionIDs("protections", ids => {
const attrs = ids.flatMap(id => [`repeating_protections_${id}_active`,`repeating_protections_${id}_integrity`,`repeating_protections_${id}_protection`]);
getAttrs(attrs, values => {
- let total = 0; let count = 0;
+ let total = 0; let count = 0; let firstProtection = 0;
ids.forEach(id => {
const prefix = `repeating_protections_${id}_`;
- if (values[prefix+"active"] === "1" && number(values[prefix+"integrity"]) > 0) { total += number(values[prefix+"protection"]); count += 1; }
+ if (values[prefix+"active"] === "1" && number(values[prefix+"integrity"]) > 0) {
+ const protection = number(values[prefix+"protection"]);
+ total += protection;
+ if (count === 0) firstProtection = protection;
+ count += 1;
+ }
});
- setAttrs({active_protection_total:total, active_protection_count:count}, {silent:true});
+ getAttrs(["force_total"], character => {
+ const mitigation = count > 0 ? total + number(character.force_total) : 0;
+ setAttrs({active_protection_total:total, active_protection_count:count, active_first_protection:firstProtection, active_mitigation_total:mitigation}, {silent:true}, recalculateDamageLocations);
+ });
+ });
+});
+
+const recalculateDamageLocations = () => getSectionIDs("locations", ids => {
+ const fixedAttrs = ["force_total","active_mitigation_total","active_first_protection", ...FIXED_LOCATIONS.flatMap(([,key]) => [`${key}_protection`,`${key}_armor`])];
+ const customAttrs = ids.flatMap(id => [`repeating_locations_${id}_name`,`repeating_locations_${id}_protection`,`repeating_locations_${id}_armor`]);
+ getAttrs([...fixedAttrs,...customAttrs], values => {
+ const force = number(values.force_total);
+ const selectedPacked = Math.round(number(values.active_mitigation_total)) * PACK_FACTOR + Math.max(0, Math.round(number(values.active_first_protection)));
+ const options = [`Sélection actuelle,${selectedPacked}`];
+ FIXED_LOCATIONS.forEach(([label,key]) => options.push(`${label},${packedProtection(values[`${key}_protection`], number(values[`${key}_armor`]) > 0, force)}`));
+ ids.forEach(id => {
+ const prefix = `repeating_locations_${id}_`;
+ options.push(`${safeQueryLabel(values[prefix+"name"])},${packedProtection(values[prefix+"protection"], number(values[prefix+"armor"]) > 0, force)}`);
+ });
+ setAttrs({damage_location_query:`?{Protection|${options.join("|")}}`}, {silent:true});
});
});
@@ -319,15 +355,19 @@ on("clicked:repeating_attacks:damage", event => {
on("clicked:repeating_attacks:take_damage", event => {
const prefix = event.sourceAttribute.replace(/take_damage$/, "");
getAttrs([prefix+"name",prefix+"base_damage",prefix+"damage_per_success",prefix+"break_damage",prefix+"rmax"], values => {
- const command = `&{template:ravenous} {{title=Subir · ${templateText(values[prefix+"name"] || "Attaque")}}} {{subtitle=@{selected|character_name}}} {{damagecalc=1}} {{damagebreakdown=1}} {{remaining=[[?{Succès restants|1}]]}} {{selected_resistance=[[@{selected|damage_resistance_total}]]}} {{selected_protection=[[@{selected|active_protection_total}]]}} {{selected_protection_count=[[@{selected|active_protection_count}]]}} {{selected_strength=[[@{selected|force_total}]]}} {{finalsuccesses=[[0]]}} {{incoming_damage=[[0]]}} {{resistance_reduction=[[0]]}} {{protection_reduction=[[0]]}} {{damage=[[0]]}} {{breakdamage=${number(values[prefix+"break_damage"])}}}`;
+ const command = `&{template:ravenous} {{title=Subir · ${templateText(values[prefix+"name"] || "Attaque")}}} {{subtitle=@{selected|character_name}}} {{damagecalc=1}} {{damagebreakdown=1}} {{abcalc=1}} {{remaining=[[?{Succès restants|1}]]}} {{selected_resistance=[[@{selected|damage_resistance_total}]]}} {{location_protection=[[@{selected|damage_location_query}]]}} {{finalsuccesses=[[0]]}} {{incoming_damage=[[0]]}} {{resistance_reduction=[[0]]}} {{protection_reduction=[[0]]}} {{damage=[[0]]}} {{incoming_break=[[0]]}} {{break_resistance=[[0]]}} {{break_protection=[[0]]}} {{break_damage=[[0]]}}`;
startRoll(`@{selected|roll_whisper}${command}`, results => {
const remaining = Math.max(0, Math.floor(results.results.remaining.result));
const finalSuccesses = Math.min(remaining, Math.max(0, Math.floor(number(values[prefix+"rmax"]))));
const incoming = finalSuccesses > 0 ? number(values[prefix+"base_damage"]) + (finalSuccesses - 1) * number(values[prefix+"damage_per_success"]) : 0;
const resistanceReduction = results.results.selected_resistance.result * 2;
- const hasProtection = results.results.selected_protection_count.result > 0;
- const protectionReduction = hasProtection ? results.results.selected_protection.result + results.results.selected_strength.result : 0;
- finishRoll(results.rollId, {finalsuccesses:finalSuccesses, incoming_damage:incoming, resistance_reduction:resistanceReduction, protection_reduction:protectionReduction, damage:Math.max(0, incoming - resistanceReduction - protectionReduction)});
+ const packed = Math.max(0, Math.round(results.results.location_protection.result));
+ const protectionReduction = Math.floor(packed / PACK_FACTOR);
+ const firstProtection = packed % PACK_FACTOR;
+ const incomingBreak = Math.max(0, number(values[prefix+"break_damage"]));
+ const breakResistance = Math.max(0, results.results.selected_resistance.result);
+ const breakDamage = Math.max(0, Math.min(incomingBreak, incomingBreak - breakResistance - firstProtection));
+ finishRoll(results.rollId, {finalsuccesses:finalSuccesses, incoming_damage:incoming, resistance_reduction:resistanceReduction, protection_reduction:protectionReduction, damage:Math.max(0, incoming - resistanceReduction - protectionReduction), incoming_break:incomingBreak, break_resistance:breakResistance, break_protection:firstProtection, break_damage:breakDamage});
});
});
});
@@ -356,7 +396,7 @@ const recalculate = () => {
update.toxicite_max = 8 + stage + number(values.toxicite_max_modifier);
update.satiete_max = 6 + Math.floor(stage / 2) + number(values.satiete_max_modifier);
update.actions_max = 4 + number(values.actions_max_modifier);
- setAttrs(update, {silent: true}, () => { recalculateSkills(); recalculateCustomSkills(); });
+ setAttrs(update, {silent: true}, () => { recalculateSkills(); recalculateCustomSkills(); recalculateProtections(); });
});
};
@@ -391,7 +431,8 @@ const recalculateCustomSkills = () => getSectionIDs("customskills", ids => {
on("sheet:opened change:force change:agilite change:perception change:intelligence change:volonte change:psy change:chance change:charisme change:stage change:force_manual change:agilite_manual change:perception_manual change:intelligence_manual change:volonte_manual change:psy_manual change:chance_manual change:charisme_manual change:torque_modifier change:speed_modifier change:half_speed_modifier change:run_speed_modifier change:swim_speed_modifier change:fly_speed_modifier change:hp_modifier change:jauge_max_modifier change:fatigue_max_modifier change:toxicite_max_modifier change:satiete_max_modifier change:actions_max_modifier", recalculate);
on("sheet:opened change:secret_rolls", () => getAttrs(["secret_rolls"], values => setAttrs({roll_whisper:values.secret_rolls === "1" ? "/w gm " : ""}, {silent:true})));
on(`sheet:opened ${DAMAGE_RESISTANCES.flatMap(type => [`change:resist_${type}`,`change:damage_apply_${type}`]).join(" ")}`, recalculateDamageResistances);
-on("sheet:opened change:repeating_protections", recalculateProtections);
+on("sheet:opened change:repeating_protections change:_reporder_repeating_protections", recalculateProtections);
+on(`sheet:opened change:repeating_locations ${FIXED_LOCATIONS.flatMap(([,key]) => [`change:${key}_protection`,`change:${key}_armor`]).join(" ")}`, recalculateDamageLocations);
on("clicked:clear_damage_resistances", () => {
const update = {};
DAMAGE_RESISTANCES.forEach(type => update[`damage_apply_${type}`] = "0");
diff --git a/tests/test_build.py b/tests/test_build.py
index f80efd9..e589403 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -102,6 +102,11 @@ class BuildTests(unittest.TestCase):
self.assertIn('name="attr_secret_rolls"', sheet)
self.assertIn('values.secret_rolls === "1" ? "/w gm " : ""', sheet)
self.assertIn("@{selected|roll_whisper}", sheet)
+ self.assertIn("active_first_protection", sheet)
+ self.assertIn("damage_location_query", sheet)
+ self.assertIn("repeating_locations_${id}_name", sheet)
+ self.assertIn("incomingBreak - breakResistance - firstProtection", sheet)
+ self.assertNotIn("{{break_damage=[[0]]}}}", sheet)
def test_techniques_are_chat_activatable_and_typst_free(self):
sheet = (ROOT / "build/ravenous.html").read_text()