Weapon attack management
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
|
||||
export default class RMFRPToolsDiceRoller extends FormApplication {
|
||||
|
||||
constructor(item, actor) {
|
||||
super();
|
||||
this.item = foundry.utils.duplicate(item);
|
||||
@ -13,6 +14,18 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
|
||||
{ value: "high_open_ended", text: "High Open-Ended", selected: false },
|
||||
{ value: "low_open_ended", text: "Low Open-Ended", selected: false }
|
||||
];
|
||||
|
||||
// Process weapon case
|
||||
if (this.item.type == "skill" && this.item.system.category.includes("Weapon")) {
|
||||
let weapon = this.actor.items.find(i => i.type == "weapon" && this.item._id == i.system.skill);
|
||||
if ( !weapon ) {
|
||||
ui.notifications.error("Weapon not found for skill: " + this.item.name);
|
||||
return
|
||||
}
|
||||
this.weapon = weapon
|
||||
this.characterBonus += Number(weapon.system.weapon_bonus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
@ -27,12 +40,15 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
|
||||
}
|
||||
|
||||
getData() {
|
||||
|
||||
// Send data to the template
|
||||
return {
|
||||
itemName: this.itemName,
|
||||
characterBonus: this.characterBonus,
|
||||
selectOptions: this.rollType,
|
||||
woundsModifier: this.actor.system.modifiers.woundsModifier,
|
||||
weapon: this?.weapon,
|
||||
targetArmorClass: 1,
|
||||
config: CONFIG.rmfrp,
|
||||
difficulty: 0,
|
||||
combatSituation: 0,
|
||||
@ -87,9 +103,11 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
|
||||
let rollType = this.rollType.find(r => r.value == rollKey)?.text;
|
||||
let rollData = {
|
||||
name: this.itemName,
|
||||
weapon: this?.weapon,
|
||||
rollKey: rollKey,
|
||||
rollType: rollType,
|
||||
difficulty: Number(formData.difficulty),
|
||||
targetArmorClass: Number(formData?.targetArmorClass || 1),
|
||||
combatSituation: Number(formData?.combatSituation || 0),
|
||||
lightningModifier: Number(formData?.lightningModifier || 0),
|
||||
darknessModifier: Number(formData?.darknessModifier || 0),
|
||||
@ -143,15 +161,61 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
|
||||
Number(this.characterBonus);
|
||||
console.log(">>> Roll Data: ", rollData);
|
||||
|
||||
// Manage weapon table
|
||||
|
||||
if (this.weapon) {
|
||||
let hasFumble = false
|
||||
if ( rollData.totalRolls <= this.weapon.system.fumble_value ) {
|
||||
hasFumble = true
|
||||
}
|
||||
|
||||
let attackResult = game.rmfrp.attackTables.getAttackRollResult(this.weapon.system.attack_table, rollData.totalFinal, rollData.targetArmorClass)
|
||||
if ( !attackResult) {
|
||||
ui.notifications.error("Attack table not found: " + this.weapon.system.attack_table);
|
||||
return
|
||||
}
|
||||
if (typeof attackResult == "object") { // Why ?????
|
||||
attackResult = attackResult[String(rollData.targetArmorClass)];
|
||||
}
|
||||
console.log("Attack Result: ", attackResult);
|
||||
rollData.attackResult = attackResult;
|
||||
// Is it a a critical ?
|
||||
let critical = attackResult.match(/(\d+)(\w)?(\w)?/);
|
||||
if (critical && critical[2]) {
|
||||
if ( critical[2] === "F") {
|
||||
hasFumble = true
|
||||
} else {
|
||||
let criticalTable = this.weapon.system.critical_table
|
||||
if ( !criticalTable ) {
|
||||
ui.notifications.error("Critical table not found for weapon: " + this.weapon.name);
|
||||
return
|
||||
}
|
||||
let criticalResult = await game.rmfrp.attackTables.getCriticalResult(criticalTable, critical[2]);
|
||||
rollData.criticalResult = criticalResult;
|
||||
console.log("Critical Result: ", criticalResult);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFumble) {
|
||||
let fumbleResult = await game.rmfrp.attackTables.getFumbleRollResult(this.weapon.system.fumble_table, this.weapon.system.fumble_column)
|
||||
if ( !fumbleResult) {
|
||||
ui.notifications.error("Fumble table not found: " + this.weapon.system.attack_table);
|
||||
return
|
||||
}
|
||||
rollData.fumbleResult = fumbleResult;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Define the Chat Message Template
|
||||
let chatTemplate = "systems/fvtt-rolemaster-frp/templates/chat/chat_dice_roll.html";
|
||||
console.log("Final rollData", rollData)
|
||||
|
||||
// Pass the Data through to be used in the Chat Message
|
||||
let chatData = rollData
|
||||
// Render the Rolls to the Chat Window
|
||||
renderTemplate(chatTemplate, chatData).then((html) => {
|
||||
let chatOptions = {
|
||||
style: CONST.CHAT_MESSAGE_STYLES.ROLL,
|
||||
flavor: rollType,
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
content: html,
|
||||
|
@ -32,6 +32,8 @@ export default class RMFRPWeaponSheet extends ItemSheet {
|
||||
attackTables: game.rmfrp.attackTables.getTableDef(),
|
||||
fumbleTables: game.rmfrp.attackTables.getFumbleDef(),
|
||||
criticalTables: game.rmfrp.attackTables.getCriticalDef(),
|
||||
fumblesWeapon: game.rmfrp.attackTables.buildFumbleWeaponChoices(),
|
||||
fumblesNonWeapon: game.rmfrp.attackTables.buildFumbleNonWeaponChoices(),
|
||||
enrichedDescription: enrichedDescription
|
||||
}
|
||||
console.log("Parent", this.object)
|
||||
|
Reference in New Issue
Block a user