Add skill+weapon rolls

This commit is contained in:
2025-01-03 23:57:54 +01:00
parent 48adc5ab49
commit c7cc39886d
39 changed files with 616 additions and 333 deletions

View File

@ -90,7 +90,7 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
case "skills":
context.tab = context.tabs.skills
context.skills = doc.itemTypes.skill
context.gifts = doc.itemTypes.gifts
context.gifts = doc.itemTypes.gift
context.vulnerabilities = doc.itemTypes.vulnerability
break
case "spells":
@ -153,6 +153,33 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
}
}
getBestWeaponClassSkill(skills, rollType, multiplier = 1.0) {
let maxValue = 0
let goodSkill = skills[0]
for (let s of skills) {
if (rollType === "weapon-attack") {
if (s.system.weaponBonus.attack > maxValue) {
maxValue = Number(s.system.weaponBonus.attack)
goodSkill = s
}
}
if (rollType === "weapon-defense") {
if (s.system.weaponBonus.defense > maxValue) {
maxValue = Number(s.system.weaponBonus.defense)
goodSkill = s
}
}
if (rollType === "weapon-damage") {
if (s.system.weaponBonus.damage > maxValue) {
maxValue = Number(s.system.weaponBonus.damage)
goodSkill = s
}
}
}
goodSkill.weaponSkillModifier = maxValue * multiplier
return goodSkill
}
/**
* Handles the roll action triggered by user interaction.
*
@ -167,9 +194,9 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
* (save, resource, or damage) based on the target element's data attributes. It retrieves the
* corresponding value from the document's system and performs the roll.
*/
async _onRoll(event, target) {
if (this.isEditMode) return
console.log(event, target)
const rollType = event.target.dataset.rollType
let rollTarget
let rollKey = event.target.dataset.rollKey
@ -181,11 +208,59 @@ export default class LethalFantasyCharacterSheet extends LethalFantasyActorSheet
case "save":
rollTarget = foundry.utils.duplicate(this.document.system.saves[rollKey])
rollTarget.rollKey = rollKey
rollTarget.rollDice = event.target.dataset?.rollDice
break
case "skill":
rollTarget = this.actor.items.find((i) => i.type === "skill" && i.id === rollKey)
rollTarget.rollKey = rollKey
if (rollTarget.system.category === "weapon") {
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.rollFromWeapon"))
return
}
break
case "weapon-attack":
case "weapon-defense":
case "weapon-damage":
let weapon = this.actor.items.find((i) => i.type === "weapon" && i.id === rollKey)
let skill
let skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase() === weapon.name.toLowerCase())
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
} else {
skills = this.actor.items.filter((i) => i.type === "skill" && i.name.toLowerCase().replace(" skill", "") === weapon.name.toLowerCase())
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 1.0)
} else {
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass === weapon.system.weaponClass)
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 0.5)
} else {
skills = this.actor.items.filter((i) => i.type === "skill" && i.system.weaponClass.includes(SYSTEM.WEAPON_CATEGORIES[weapon.system.weaponClass]))
if (skills.length > 0) {
skill = this.getBestWeaponClassSkill(skills, rollType, 0.25)
} else {
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
return
}
}
}
}
if (!weapon || !skill) {
console.error("Weapon or skill not found", weapon, skill)
ui.notifications.warn(game.i18n.localize("LETHALFANTASY.Notifications.skillNotFound"))
return
}
rollTarget = skill
rollTarget.weapon = weapon
rollTarget.weaponSkillModifier = skill.weaponSkillModifier
rollTarget.rollKey = rollKey
rollTarget.combat = foundry.utils.duplicate(this.actor.system.combat)
break
case ROLL_TYPE.DAMAGE:
rollTarget = elt.dataset.itemId
break
default:
ui.notifications.error(game.i18n.localize("LETHALFANTASY.Notifications.rollTypeNotFound") + String(rollType))
break
}
await this.document.system.roll(rollType, rollTarget)

View File

@ -6,8 +6,8 @@ export const TABLES = {
"str": [
{
"value": 1,
"damage_modifier": -7,
"attack_modifier": -4,
"damage": -7,
"attack": -4,
"challenge": -9,
"aether_points": -20,
"hp": -3,
@ -17,8 +17,8 @@ export const TABLES = {
},
{
"value": 2,
"damage_modifier": -6,
"attack_modifier": -4,
"damage": -6,
"attack": -4,
"challenge": -8,
"aether_points": -20,
"hp": -2,
@ -28,8 +28,8 @@ export const TABLES = {
},
{
"value": 3,
"damage_modifier": -5,
"attack_modifier": -3,
"damage": -5,
"attack": -3,
"challenge": -7,
"aether_points": -20,
"hp": -1,
@ -39,8 +39,8 @@ export const TABLES = {
},
{
"value": 4,
"damage_modifier": -4,
"attack_modifier": -3,
"damage": -4,
"attack": -3,
"challenge": -6,
"aether_points": -20,
"hp": -1,
@ -50,8 +50,8 @@ export const TABLES = {
},
{
"value": 5,
"damage_modifier": -3,
"attack_modifier": -2,
"damage": -3,
"attack": -2,
"challenge": -5,
"aether_points": -20,
"hp": 0,
@ -61,8 +61,8 @@ export const TABLES = {
},
{
"value": 6,
"damage_modifier": -2,
"attack_modifier": -1,
"damage": -2,
"attack": -1,
"challenge": -4,
"aether_points": -10,
"hp": 0,
@ -72,8 +72,8 @@ export const TABLES = {
},
{
"value": 7,
"damage_modifier": -2,
"attack_modifier": 0,
"damage": -2,
"attack": 0,
"challenge": -3,
"aether_points": -10,
"hp": 0,
@ -83,8 +83,8 @@ export const TABLES = {
},
{
"value": 8,
"damage_modifier": -1,
"attack_modifier": 0,
"damage": -1,
"attack": 0,
"challenge": -2,
"aether_points": 0,
"hp": 0,
@ -94,8 +94,8 @@ export const TABLES = {
},
{
"value": 9,
"damage_modifier": -1,
"attack_modifier": 0,
"damage": -1,
"attack": 0,
"challenge": -1,
"aether_points": 0,
"hp": 0,
@ -105,8 +105,8 @@ export const TABLES = {
},
{
"value": 10,
"damage_modifier": 0,
"attack_modifier": 0,
"damage": 0,
"attack": 0,
"challenge": 0,
"aether_points": 0,
"hp": 0,
@ -116,8 +116,8 @@ export const TABLES = {
},
{
"value": 11,
"damage_modifier": 0,
"attack_modifier": 0,
"damage": 0,
"attack": 0,
"challenge": 0,
"aether_points": 0,
"hp": 0,
@ -127,8 +127,8 @@ export const TABLES = {
},
{
"value": 12,
"damage_modifier": 1,
"attack_modifier": 0,
"damage": 1,
"attack": 0,
"challenge": 1,
"aether_points": 0,
"hp": 0,
@ -138,8 +138,8 @@ export const TABLES = {
},
{
"value": 13,
"damage_modifier": 1,
"attack_modifier": 0,
"damage": 1,
"attack": 0,
"challenge": 2,
"aether_points": 0,
"hp": 0,
@ -149,8 +149,8 @@ export const TABLES = {
},
{
"value": 14,
"damage_modifier": 2,
"attack_modifier": 1,
"damage": 2,
"attack": 1,
"challenge": 3,
"aether_points": 0,
"hp": 1,
@ -160,8 +160,8 @@ export const TABLES = {
},
{
"value": 15,
"damage_modifier": 3,
"attack_modifier": 1,
"damage": 3,
"attack": 1,
"challenge": 4,
"aether_points": 0,
"hp": 2,
@ -171,8 +171,8 @@ export const TABLES = {
},
{
"value": 16,
"damage_modifier": 4,
"attack_modifier": 2,
"damage": 4,
"attack": 2,
"challenge": 5,
"aether_points": 0,
"hp": 3,
@ -182,8 +182,8 @@ export const TABLES = {
},
{
"value": 17,
"damage_modifier": 5,
"attack_modifier": 2,
"damage": 5,
"attack": 2,
"challenge": 6,
"aether_points": 10,
"hp": 4,
@ -193,8 +193,8 @@ export const TABLES = {
},
{
"value": 18,
"damage_modifier": 6,
"attack_modifier": 3,
"damage": 6,
"attack": 3,
"challenge": 7,
"aether_points": 20,
"hp": 5,
@ -204,8 +204,8 @@ export const TABLES = {
},
{
"value": 19,
"damage_modifier": 7,
"attack_modifier": 3,
"damage": 7,
"attack": 3,
"challenge": 8,
"aether_points": 20,
"hp": 6,
@ -215,8 +215,8 @@ export const TABLES = {
},
{
"value": 20,
"damage_modifier": 8,
"attack_modifier": 4,
"damage": 8,
"attack": 4,
"challenge": 9,
"aether_points": 30,
"hp": 7,
@ -226,8 +226,8 @@ export const TABLES = {
},
{
"value": 21,
"damage_modifier": 9,
"attack_modifier": 4,
"damage": 9,
"attack": 4,
"challenge": 10,
"aether_points": 30,
"hp": 8,
@ -237,8 +237,8 @@ export const TABLES = {
},
{
"value": 22,
"damage_modifier": 10,
"attack_modifier": 5,
"damage": 10,
"attack": 5,
"challenge": 11,
"aether_points": 40,
"hp": 9,
@ -248,8 +248,8 @@ export const TABLES = {
},
{
"value": 23,
"damage_modifier": 12,
"attack_modifier": 5,
"damage": 12,
"attack": 5,
"challenge": 12,
"aether_points": 40,
"hp": 10,
@ -259,8 +259,8 @@ export const TABLES = {
},
{
"value": 24,
"damage_modifier": 14,
"attack_modifier": 5,
"damage": 14,
"attack": 5,
"challenge": 13,
"aether_points": 50,
"hp": 11,
@ -270,8 +270,8 @@ export const TABLES = {
},
{
"value": 25,
"damage_modifier": 16,
"attack_modifier": 6,
"damage": 16,
"attack": 6,
"challenge": 14,
"aether_points": 60,
"hp": 12,
@ -736,7 +736,6 @@ export const TABLES = {
},
{
"value": 6,
"hp ": 6,
"aether_points": -20,
"pain_save": 3,
@ -746,7 +745,6 @@ export const TABLES = {
},
{
"value": 7,
"hp ": 7,
"aether_points": -15,
"pain_save": 3,
@ -939,175 +937,175 @@ export const TABLES = {
"value": 1,
"grit": -5,
"turning_casting": -4,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 2,
"grit": -4,
"turning_casting": -4,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 3,
"grit": -4,
"turning_casting": -3,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 4,
"grit": -3,
"turning_casting": 3,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 5,
"grit": -3,
"turning_casting": -2,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 6,
"grit": -2,
"turning_casting": -2,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 7,
"grit": -2,
"turning_casting": -1,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 8,
"grit": -1,
"turning_casting": -1,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 9,
"grit": -1,
"turning_casting": 0,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 10,
"grit": 0,
"turning_casting": 0,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 11,
"grit": 0,
"turning_casting": 0,
"development_points ": 0,
"development_points": 0,
"divine_miracle_bonus": 0
},
{
"value": 12,
"grit": 0,
"turning_casting": 1,
"development_points ": 1,
"development_points": 1,
"divine_miracle_bonus": 1
},
{
"value": 13,
"grit": 1,
"turning_casting": 1,
"development_points ": 2,
"development_points": 2,
"divine_miracle_bonus": 1
},
{
"value": 14,
"grit": 2,
"turning_casting": 2,
"development_points ": 4,
"development_points": 4,
"divine_miracle_bonus": 2
},
{
"value": 15,
"grit": 4,
"turning_casting": 2,
"development_points ": 6,
"development_points": 6,
"divine_miracle_bonus": 2
},
{
"value": 16,
"grit": 6,
"turning_casting": 3,
"development_points ": 7,
"development_points": 7,
"divine_miracle_bonus": 3
},
{
"value": 17,
"grit": 8,
"turning_casting": 3,
"development_points ": 8,
"development_points": 8,
"divine_miracle_bonus": 3
},
{
"value": 18,
"grit": 10,
"turning_casting": 4,
"development_points ": 9,
"development_points": 9,
"divine_miracle_bonus": 4
},
{
"value": 19,
"grit": 11,
"turning_casting": 5,
"development_points ": 10,
"development_points": 10,
"divine_miracle_bonus": 5
},
{
"value": 20,
"grit": 12,
"turning_casting": 6,
"development_points ": 11,
"development_points": 11,
"divine_miracle_bonus": 5
},
{
"value": 21,
"grit": 13,
"turning_casting": 7,
"development_points ": 12,
"development_points": 12,
"divine_miracle_bonus": 5
},
{
"value": 22,
"grit": 14,
"turning_casting": 7,
"development_points ": 13,
"development_points": 13,
"divine_miracle_bonus": 6
},
{
"value": 23,
"grit": 15,
"turning_casting": 8,
"development_points ": 14,
"development_points": 14,
"divine_miracle_bonus": 6
},
{
"value": 24,
"grit": 16,
"turning_casting": 8,
"development_points ": 15,
"development_points": 15,
"divine_miracle_bonus": 6
},
{
"value": 25,
"grit": 18,
"turning_casting": 9,
"development_points ": 16,
"development_points": 16,
"divine_miracle_bonus": 7
}
],
@ -1218,250 +1216,250 @@ export const TABLES = {
"value": 1,
"defense": -5,
"init_cap": "-",
"development_points ": 0,
"attack ": -5,
"development_points": 0,
"attack": -5,
"willpower_save": -5,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 2,
"defense": -4,
"init_cap": "-",
"development_points ": 0,
"attack ": -4,
"development_points": 0,
"attack": -4,
"willpower_save": -4,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 3,
"defense": -3,
"init_cap": "-",
"development_points ": 0,
"attack ": -3,
"development_points": 0,
"attack": -3,
"willpower_save": -3,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 4,
"defense": -3,
"init_cap": "-",
"development_points ": 0,
"attack ": -2,
"development_points": 0,
"attack": -2,
"willpower_save": -3,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 5,
"defense": -2,
"init_cap": "-",
"development_points ": 0,
"attack ": 1,
"development_points": 0,
"attack": 1,
"willpower_save": -2,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 6,
"defense": -2,
"init_cap": "-",
"development_points ": 0,
"attack ": 0,
"development_points": 0,
"attack": 0,
"willpower_save": -2,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 7,
"defense": -1,
"init_cap": "-",
"development_points ": 0,
"attack ": 0,
"development_points": 0,
"attack": 0,
"willpower_save": -1,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 8,
"defense": -1,
"init_cap": "-",
"development_points ": 0,
"attack ": 0,
"development_points": 0,
"attack": 0,
"willpower_save": -1,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 9,
"defense": -1,
"init_cap": "-",
"development_points ": 0,
"attack ": 0,
"development_points": 0,
"attack": 0,
"willpower_save": 0,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 10,
"defense": 0,
"init_cap": 18,
"development_points ": 0,
"attack ": 0,
"development_points": 0,
"attack": 0,
"willpower_save": 0,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 11,
"defense": 0,
"init_cap": 16,
"development_points ": 1,
"attack ": 0,
"development_points": 1,
"attack": 0,
"willpower_save": 0,
"divine_miracle_bonus ": 0,
"divine_miracle_bonus": 0,
"": ""
},
{
"value": 12,
"defense": 1,
"init_cap": 14,
"development_points ": 2,
"attack ": 0,
"development_points": 2,
"attack": 0,
"willpower_save": 0,
"divine_miracle_bonus ": 1,
"divine_miracle_bonus": 1,
"": ""
},
{
"value": 13,
"defense": 1,
"init_cap": 12,
"development_points ": 3,
"attack ": 0,
"development_points": 3,
"attack": 0,
"willpower_save": 1,
"divine_miracle_bonus ": 1,
"divine_miracle_bonus": 1,
"": ""
},
{
"value": 14,
"defense": 1,
"init_cap": 10,
"development_points ": 4,
"attack ": 1,
"development_points": 4,
"attack": 1,
"willpower_save": 2,
"divine_miracle_bonus ": 2,
"divine_miracle_bonus": 2,
"": ""
},
{
"value": 15,
"defense": 2,
"init_cap": 8,
"development_points ": 5,
"attack ": 1,
"development_points": 5,
"attack": 1,
"willpower_save": 3,
"divine_miracle_bonus ": 2,
"divine_miracle_bonus": 2,
"": ""
},
{
"value": 16,
"defense": 2,
"init_cap": 7,
"development_points ": 7,
"attack ": 1,
"development_points": 7,
"attack": 1,
"willpower_save": 4,
"divine_miracle_bonus ": 2,
"divine_miracle_bonus": 2,
"": ""
},
{
"value": 17,
"defense": 2,
"init_cap": 6,
"development_points ": 9,
"attack ": 1,
"development_points": 9,
"attack": 1,
"willpower_save": 5,
"divine_miracle_bonus ": 3,
"divine_miracle_bonus": 3,
"": ""
},
{
"value": 18,
"defense": 3,
"init_cap": 5,
"development_points ": 11,
"attack ": 2,
"development_points": 11,
"attack": 2,
"willpower_save": 6,
"divine_miracle_bonus ": 4,
"divine_miracle_bonus": 4,
"": ""
},
{
"value": 19,
"defense": 3,
"init_cap": 4,
"development_points ": 13,
"attack ": 2,
"development_points": 13,
"attack": 2,
"willpower_save": 7,
"divine_miracle_bonus ": 5,
"divine_miracle_bonus": 5,
"": ""
},
{
"value": 20,
"defense": 3,
"init_cap": 4,
"development_points ": 15,
"attack ": 2,
"development_points": 15,
"attack": 2,
"willpower_save": 8,
"divine_miracle_bonus ": 6,
"divine_miracle_bonus": 6,
"": ""
},
{
"value": 21,
"defense": 4,
"init_cap": 3,
"development_points ": 18,
"attack ": 2,
"development_points": 18,
"attack": 2,
"willpower_save": 9,
"divine_miracle_bonus ": 7,
"divine_miracle_bonus": 7,
"": ""
},
{
"value": 22,
"defense": 4,
"init_cap": 3,
"development_points ": 21,
"attack ": 2,
"development_points": 21,
"attack": 2,
"willpower_save": 10,
"divine_miracle_bonus ": 8,
"divine_miracle_bonus": 8,
"": ""
},
{
"value": 23,
"defense": 4,
"init_cap": 2,
"development_points ": 24,
"attack ": 3,
"development_points": 24,
"attack": 3,
"willpower_save": 11,
"divine_miracle_bonus ": 9,
"divine_miracle_bonus": 9,
"": ""
},
{
"value": 24,
"defense": 4,
"init_cap": 2,
"development_points ": 27,
"attack ": 3,
"development_points": 27,
"attack": 3,
"willpower_save": 12,
"divine_miracle_bonus ": 10,
"divine_miracle_bonus": 10,
"": ""
},
{
"value": 25,
"defense": 5,
"init_cap": 1,
"development_points ": 30,
"attack ": 4,
"development_points": 30,
"attack": 4,
"willpower_save": 13,
"divine_miracle_bonus ": 12,
"divine_miracle_bonus": 12,
"": ""
}
]

View File

@ -59,6 +59,10 @@ export const DICE_VALUES = {
"d20": "D20"
}
export const CHARACTERISTIC_ATTACK = [ "str", "int", "wis", "dex"]
export const CHARACTERISTIC_DEFENSE = [ "int", "wis", "dex" ]
export const CHARACTERISTIC_DAMAGE = [ "str" ]
export const DEFENSE_DICE_VALUES = {
"d3": "D3",
"d4": "D4",
@ -145,6 +149,10 @@ export const SYSTEM = {
WEAPON_CLASS: WEAPON.WEAPON_CLASS,
COMBAT_PROGRESSION_DICE: DICE_VALUES,
SHIELD_DEFENSE_DICE: DEFENSE_DICE_VALUES,
WEAPON_CATEGORIES: WEAPON.WEAPON_CATEGORIES,
CHARACTERISTIC_ATTACK,
CHARACTERISTIC_DEFENSE,
CHARACTERISTIC_DAMAGE,
MONEY,
ASCII,
ROLL_TYPE,

View File

@ -17,4 +17,19 @@ export const WEAPON_CLASS = {
"thrown": "LETHALFANTASY.Weapon.WeaponClass.thrown",
"polearm": "LETHALFANTASY.Weapon.WeaponClass.polearm",
"unarmed" : "LETHALFANTASY.Weapon.WeaponClass.unarmed"
}
}
export const WEAPON_CATEGORIES = {
"longblade": ["mediumblade", "shortblade"],
"shortblade": ["mediumblade", "longblade"],
"mediumblade": ["shortblade", "longblade"],
"axe": ["hammer", "mace", "flail", "bow", "sling", "thrown", "polearm"],
"hammer": ["axe", "mace", "flail", "bow", "sling", "thrown", "polearm"],
"mace": ["axe", "hammer", "flail", "bow", "sling", "thrown", "polearm"],
"flail": ["axe", "hammer", "mace", "bow", "sling", "thrown", "polearm"],
"bow": ["axe", "hammer", "mace", "flail", "sling", "thrown", "polearm"],
"sling": ["axe", "hammer", "mace", "flail", "bow", "thrown", "polearm"],
"thrown": ["axe", "hammer", "mace", "flail", "bow", "sling", "polearm"],
"polearm": ["axe", "hammer", "mace", "flail", "bow", "sling", "thrown"]
}

View File

@ -11,11 +11,15 @@ export default class LethalFantasyRoll extends Roll {
get type() {
return this.options.type
}
get titleFormula() {
return this.options.titleFormula
}
get rollName() {
return this.options.rollName
}
get target() {
return this.options.target
}
@ -83,7 +87,7 @@ export default class LethalFantasyRoll extends Roll {
get rollTotal() {
return this.options.rollTotal
}
get diceResults() {
return this.options.diceResults
}
@ -160,15 +164,44 @@ export default class LethalFantasyRoll extends Roll {
let hasModifier = true
let hasChangeDice = false
if (options.rollType === "challenge" || options.rollType === "save") {
if ( options.rollTarget.rollKey === "dying") {
options.rollName = options.rollTarget.rollKey
if (options.rollTarget.rollKey === "dying") {
dice = options.rollTarget.value
maxValue = Number(options.rollTarget.value.match(/\d+/)[0])
hasModifier = false
hasChangeDice = true
hasChangeDice = true
} else {
dice = "1D20"
maxValue = 20
}
}
} else if (options.rollType === "skill") {
options.rollName = options.rollTarget.name
dice = "1D100"
baseFormula = "D100"
maxValue = 100
hasModifier = true
hasChangeDice = false
options.rollTarget.value = options.rollTarget.system.skillTotal
} else if (options.rollType === "weapon-attack" || options.rollType === "weapon-defense") {
options.rollName = options.rollTarget.name
dice = "1D20"
baseFormula = "D20"
maxValue = 20
hasModifier = true
hasChangeDice = false
if (options.rollType === "weapon-attack") {
options.rollTarget.value = options.rollTarget.combat.attackModifier + options.rollTarget.weaponSkillModifier
options.rollTarget.charModifier = options.rollTarget.combat.attackModifier
} else {
options.rollTarget.value = options.rollTarget.combat.defenseModifier + options.rollTarget.weaponSkillModifier
options.rollTarget.charModifier = options.rollTarget.combat.defenseModifier
}
}
if (options.rollType === "save" && options.rollTarget.rollKey === "pain") {
dice = options.rollTarget.rollDice
baseFormula = options.rollTarget.rollDice
hasModifier = false
}
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
@ -188,6 +221,7 @@ export default class LethalFantasyRoll extends Roll {
let dialogContext = {
rollType: options.rollType,
rollTarget: options.rollTarget,
rollName: options.rollName,
rollModes,
hasModifier,
hasChangeDice,
@ -202,6 +236,7 @@ export default class LethalFantasyRoll extends Roll {
modifier,
targetName
}
console.log("dialogContext", dialogContext)
const content = await renderTemplate("systems/fvtt-lethal-fantasy/templates/roll-dialog.hbs", dialogContext)
const title = LethalFantasyRoll.createTitle(options.rollType, options.rollTarget)
@ -231,31 +266,38 @@ export default class LethalFantasyRoll extends Roll {
let fullModifier = 0
let titleFormula = ""
dice = rollContext.changeDice || dice
if (options.rollType === "challenge" || options.rollType === "save") {
if (hasModifier) {
let bonus = Number(options.rollTarget.value)
fullModifier = rollContext.modifier === "" ? 0 : parseInt(rollContext.modifier, 10) + bonus
if (fullModifier === 0) {
modifierFormula = "0"
} else {
let modAbs = Math.abs(fullModifier)
modifierFormula = `d${modAbs + 1} - 1`
}
let sign = fullModifier < 0 ? "-" : "+"
titleFormula = `${dice}E ${sign} ${modifierFormula}`
} else {
if (hasModifier) {
let bonus = Number(options.rollTarget.value)
fullModifier = rollContext.modifier === "" ? 0 : parseInt(rollContext.modifier, 10) + bonus
if (fullModifier === 0) {
modifierFormula = "0"
fullModifier = 0
baseFormula = `${dice}`
titleFormula = `${dice}E`
} else {
let modAbs = Math.abs(fullModifier)
modifierFormula = `d${modAbs + 1} - 1`
}
let sign = fullModifier < 0 ? "-" : "+"
titleFormula = `${dice}E ${sign} ${modifierFormula}`
} else {
modifierFormula = "0"
fullModifier = 0
baseFormula = `${dice}`
titleFormula = `${dice}E`
}
if (options.rollType === "save" && options.rollTarget.rollKey === "pain") {
baseFormula = options.rollTarget.rollDice
titleFormula = `${dice}`
modifierFormula = "0"
fullModifier = 0
}
maxValue = Number(baseFormula.match(/\d+$/)[0]) // Update the max value agains
const rollData = {
type: options.rollType,
rollType: options.rollType,
target: options.rollTarget,
rollName: options.rollName,
actorId: options.actorId,
actorName: options.actorName,
actorImage: options.actorImage,
@ -284,28 +326,22 @@ export default class LethalFantasyRoll extends Roll {
let rollTotal = -1
let diceResults = []
let resultType
if (options.rollType === "challenge" || options.rollType === "save") {
let diceResult = rollBase.dice[0].results[0].result
diceResults.push({ dice: `${dice}`, value: diceResult})
let diceSum = diceResult
while (diceResult === maxValue) {
let r = await new Roll(baseFormula).evaluate()
diceResult = r.dice[0].results[0].result
diceResults.push( {dice: `${dice}-1`, value: diceResult-1})
diceSum += (diceResult - 1)
}
if (fullModifier !== 0) {
diceResults.push({ dice: `${rollModifier.formula}`, value: rollModifier.total })
if ( fullModifier < 0) {
rollTotal = Math.max(diceSum - rollModifier.total, 0)
} else {
rollTotal = diceSum + rollModifier.total
}
let diceResult = rollBase.dice[0].results[0].result
diceResults.push({ dice: `${dice}`, value: diceResult })
let diceSum = diceResult
while (diceResult === maxValue) {
let r = await new Roll(baseFormula).evaluate()
diceResult = r.dice[0].results[0].result
diceResults.push({ dice: `${dice}-1`, value: diceResult - 1 })
diceSum += (diceResult - 1)
}
if (fullModifier !== 0) {
diceResults.push({ dice: `${rollModifier.formula}`, value: rollModifier.total })
if (fullModifier < 0) {
rollTotal = Math.max(diceSum - rollModifier.total, 0)
} else {
rollTotal = diceSum
}
} else if (options.rollType === ROLL_TYPE.RESOURCE) {
//resultType = roll.total === 1 || roll.total === 2 ? "failure" : "success"
rollTotal = diceSum + rollModifier.total
}
}
rollBase.options.resultType = resultType
@ -343,12 +379,16 @@ export default class LethalFantasyRoll extends Roll {
return `${game.i18n.localize("LETHALFANTASY.Label.titleChallenge")}`
case "save":
return `${game.i18n.localize("LETHALFANTASY.Label.titleSave")}`
case ROLL_TYPE.DAMAGE:
return `${game.i18n.localize("LETHALFANTASY.Dialog.titleDamage")} : ${target}`
case ROLL_TYPE.ATTACK:
return `${game.i18n.localize("LETHALFANTASY.Dialog.titleAttack")} : ${target}`
case "skill":
return `${game.i18n.localize("LETHALFANTASY.Label.titleSkill")}`
case "weapon-attack":
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-attack")}`
case "weapon-defense":
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-defense")}`
case "weapon-damage":
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-damage")}`
default:
return game.i18n.localize("LETHALFANTASY.Dialog.titleStandard")
return game.i18n.localize("LETHALFANTASY.Label.titleStandard")
}
}
@ -393,6 +433,7 @@ export default class LethalFantasyRoll extends Roll {
isGM: game.user.isGM,
formula: this.formula,
titleFormula: this.titleFormula,
rollName: this.rollName,
rollType: this.type,
rollTarget: this.rollTarget,
total: this.rollTotal,

View File

@ -95,11 +95,16 @@ export default class LethalFantasyCharacter extends foundry.abstract.TypeDataMod
schema.developmentPoints = new fields.SchemaField({
total: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
remaining: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
})
})
schema.spellMiraclePoints = new fields.SchemaField({
total: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
used: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
})
schema.combat = new fields.SchemaField({
attackModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
defenseModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
damageModifier: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
})
const moneyField = (label) => {
const schema = {
@ -132,7 +137,7 @@ export default class LethalFantasyCharacter extends foundry.abstract.TypeDataMod
let strDef = SYSTEM.CHARACTERISTICS_TABLES.str.find(s => s.value === this.characteristics.str.value)
this.challenges.str.value = strDef.challenge
let dexDef = SYSTEM.CHARACTERISTICS_TABLES.dex.find(s => s.value === this.characteristics.dex.value)
this.challenges.agility.value = dexDef.challenge
this.saves.dodge.value = dexDef.dodge
@ -147,8 +152,27 @@ export default class LethalFantasyCharacter extends foundry.abstract.TypeDataMod
this.saves.contagion.value = this.characteristics.con.value
this.saves.poison.value = this.characteristics.con.value
this.combat.attackModifier = 0
for (let chaKey of SYSTEM.CHARACTERISTIC_ATTACK) {
let chaDef = SYSTEM.CHARACTERISTICS_TABLES[chaKey].find(s => s.value === this.characteristics[chaKey].value)
this.combat.attackModifier += chaDef.attack
}
this.combat.defenseModifier = 0
for (let chaKey of SYSTEM.CHARACTERISTIC_DEFENSE) {
let chaDef = SYSTEM.CHARACTERISTICS_TABLES[chaKey].find(s => s.value === this.characteristics[chaKey].value)
this.combat.defenseModifier += chaDef.defense
}
this.combat.damageModifier = 0
for (let chaKey of SYSTEM.CHARACTERISTIC_DAMAGE) {
let chaDef = SYSTEM.CHARACTERISTICS_TABLES[chaKey].find(s => s.value === this.characteristics[chaKey].value)
this.combat.damageModifier += chaDef.damage
}
}
/**
* Rolls a dice for a character.
* @param {("save"|"resource|damage")} rollType The type of the roll.