ENH: Weapon damage first draft

master
U~man 2020-07-04 23:56:01 +02:00
parent c0efa40725
commit 44c33d397e
4 changed files with 97 additions and 38 deletions

View File

@ -88,6 +88,7 @@
"OSE.InitiativeShort": "INIT",
"OSE.Attacks": "Attacks Usable per Round",
"OSE.AttacksShort": "ATT",
"OSE.Damage": "Damage",
"OSE.Spellcaster": "Spellcaster",
"OSE.SpokenLanguages": "Spoken Languages",

View File

@ -104,6 +104,44 @@ export class OseActor extends Actor {
});
}
rollDamage(attData, options = {}) {
const data = this.data.data;
const rollData = {
...this.data,
...{
rollData: {
type: "Damage",
stat: attData.type,
scores: data.scores
},
},
};
let dmgParts = [];
if (!attData.dmg || !game.settings.get('ose', 'variableWeaponDamage')) {
dmgParts.push("1d6");
} else {
dmgParts.push(attData.dmg);
}
// Add Str to damage
if (attData.type == 'melee') {
dmgParts.push("+", data.scores.str.mod);
}
// Damage roll
OseDice.Roll({
event: options.event,
parts: dmgParts,
data: rollData,
skipDialog: true,
speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: `${attData.label} - ${game.i18n.localize("OSE.Damage")}`,
title: `${attData.label} - ${game.i18n.localize("OSE.Damage")}`,
})
}
rollAttack(attData, options = {}) {
const rollParts = ["1d20"];
const data = this.data.data;
@ -133,7 +171,7 @@ export class OseActor extends Actor {
rollData: {
type: "Attack",
stat: attData.type,
scores: data.scores,
scores: data.scores
},
},
};
@ -145,6 +183,8 @@ export class OseActor extends Actor {
speaker: ChatMessage.getSpeaker({ actor: this }),
flavor: `${attData.label} - ${game.i18n.localize("OSE.Attack")}`,
title: `${attData.label} - ${game.i18n.localize("OSE.Attack")}`,
}).then(() => {
this.rollDamage(attData, {});
});
}

View File

@ -29,7 +29,11 @@ export class OseDice {
if (thac - roll.total > 9) {
return details;
}
details = `<div class='roll-result'><b>Hits AC ${Math.clamped(thac - roll.total,-3,9)}</b> (${thac})</div>`;
details = `<div class='roll-result'><b>Hits AC ${Math.clamped(
thac - roll.total,
-3,
9
)}</b> (${thac})</div>`;
// ADD DAMAGE ROLL
}
} else if (data.rollData.type == "Save") {
@ -60,14 +64,14 @@ export class OseDice {
return details;
}
static async sendRoll(
static async sendRoll({
parts = [],
data = {},
title = null,
flavor = null,
speaker = null,
form = null
) {
form = null,
} = {}) {
const template = "systems/ose/templates/chat/roll-attack.html";
let chatData = {
@ -80,7 +84,7 @@ export class OseDice {
flavor: flavor,
data: data,
};
// Optionally include a situational bonus
if (form !== null) data["bonus"] = form.bonus.value;
if (data["bonus"]) parts.push(data["bonus"]);
@ -92,36 +96,42 @@ export class OseDice {
rollMode = form ? form.rollMode.value : rollMode;
templateData.details = OseDice.digestResult(data, roll);
roll.render().then((r) => {
templateData.rollOSE = r;
renderTemplate(template, templateData).then((content) => {
chatData.content = content;
chatData.sound = CONFIG.sounds.dice;
if (game.dice3d) {
game.dice3d
.showForRoll(
roll,
game.user,
true,
chatData.whisper,
chatData.blind
)
.then((displayed) => ChatMessage.create(chatData));
} else {
ChatMessage.create(chatData);
}
return new Promise((resolve) => {
roll.render().then((r) => {
templateData.rollOSE = r;
renderTemplate(template, templateData).then((content) => {
chatData.content = content;
// Dice So Nice
if (game.dice3d) {
game.dice3d
.showForRoll(
roll,
game.user,
true,
chatData.whisper,
chatData.blind
)
.then((displayed) => {
ChatMessage.create(chatData);
resolve();
});
} else {
chatData.sound = CONFIG.sounds.dice;
ChatMessage.create(chatData);
resolve();
}
});
});
});
return roll;
}
// eslint-disable-next-line no-unused-vars
static async Roll({
parts = [],
data = {},
options = {},
event = null,
skipDialog = false,
speaker = null,
flavor = null,
title = null,
@ -143,14 +153,14 @@ export class OseDice {
label: game.i18n.localize("OSE.Roll"),
icon: '<i class="fas fa-dice-d20"></i>',
callback: (html) => {
roll = OseDice.sendRoll(
parts,
data,
title,
flavor,
speaker,
html[0].children[0]
);
roll = OseDice.sendRoll({
parts: parts,
data: data,
title: title,
flavor: flavor,
speaker: speaker,
form: html[0].children[0],
});
},
},
cancel: {
@ -159,7 +169,15 @@ export class OseDice {
},
};
if (!item) delete buttons.raise;
if (skipDialog) {
return OseDice.sendRoll({
parts,
data,
title,
flavor,
speaker,
});
}
const html = await renderTemplate(template, dialogData);
let roll;

View File

@ -49,9 +49,9 @@ export class OseItem extends Item {
rollWeapon() {
if (this.data.data.missile) {
this.actor.rollAttack({type: 'missile', label: this.name});
this.actor.rollAttack({type: 'missile', label: this.name, dmg: this.data.data.damage});
} else if (this.data.data.melee) {
this.actor.rollAttack({type: 'melee', label: this.name});
this.actor.rollAttack({type: 'melee', label: this.name, dmg: this.data.data.damage});
} else {
this.actor.rollAttack({type: 'raw', label: this.name});
}