2020-05-25 16:00:53 +00:00
|
|
|
import { bladesRoll } from "./blades-roll.js";
|
2020-08-05 13:20:52 +00:00
|
|
|
import { BladesHelpers } from "./blades-helpers.js";
|
2020-05-25 16:00:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the basic Actor
|
|
|
|
* @extends {Actor}
|
|
|
|
*/
|
|
|
|
export class BladesActor extends Actor {
|
|
|
|
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
getRollData() {
|
|
|
|
const data = super.getRollData();
|
|
|
|
|
|
|
|
data.dice_amount = this.getAttributeDiceToThrow();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Calculate Attribute Dice to throw.
|
|
|
|
*/
|
|
|
|
getAttributeDiceToThrow() {
|
|
|
|
|
|
|
|
// Calculate Dice to throw.
|
|
|
|
let dice_amount = {};
|
|
|
|
for (var attibute_name in this.data.data.attributes) {
|
|
|
|
dice_amount[attibute_name] = 0;
|
|
|
|
for (var skill_name in this.data.data.attributes[attibute_name].skills) {
|
2020-08-04 12:39:31 +00:00
|
|
|
dice_amount[skill_name] = parseInt(this.data.data.attributes[attibute_name].skills[skill_name]['value'][0])
|
2020-05-25 16:00:53 +00:00
|
|
|
|
|
|
|
// We add a +1d for every skill higher than 0.
|
|
|
|
if (dice_amount[skill_name] > 0) {
|
|
|
|
dice_amount[attibute_name]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return dice_amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
rollAttributePopup(attribute_name) {
|
2020-08-05 13:20:52 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
// const roll = new Roll("1d20 + @abilities.wis.mod", actor.getRollData());
|
2020-08-05 13:20:52 +00:00
|
|
|
let attribute_label = BladesHelpers.getAttributeLabel(attribute_name);
|
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
new Dialog({
|
2020-08-05 13:20:52 +00:00
|
|
|
title: `${game.i18n.localize('BITD.Roll')} ${game.i18n.localize(attribute_label)}`,
|
2020-05-25 16:00:53 +00:00
|
|
|
content: `
|
2020-08-05 13:20:52 +00:00
|
|
|
<h2>${game.i18n.localize('BITD.Roll')} ${game.i18n.localize(attribute_label)}</h2>
|
2020-05-25 16:00:53 +00:00
|
|
|
<form>
|
|
|
|
<div class="form-group">
|
2020-08-04 12:39:31 +00:00
|
|
|
<label>${game.i18n.localize('BITD.Modifier')}:</label>
|
2020-05-25 16:00:53 +00:00
|
|
|
<select id="mod" name="mod">
|
|
|
|
${this.createListOfDiceMods(-3,+3,0)}
|
|
|
|
</select>
|
2020-08-01 10:03:56 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2020-08-04 12:39:31 +00:00
|
|
|
<label>${game.i18n.localize('BITD.Position')}:</label>
|
2020-08-01 10:03:56 +00:00
|
|
|
<select id="pos" name="pos">
|
2020-08-04 12:39:31 +00:00
|
|
|
<option value="controlled">${game.i18n.localize('BITD.PositionControlled')}</option>
|
|
|
|
<option value="risky" selected>${game.i18n.localize('BITD.PositionRisky')}</option>
|
|
|
|
<option value="desperate">${game.i18n.localize('BITD.PositionDesperate')}</option>
|
2020-08-01 10:03:56 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2020-08-04 12:39:31 +00:00
|
|
|
<label>${game.i18n.localize('BITD.Effect')}:</label>
|
2020-08-01 10:03:56 +00:00
|
|
|
<select id="fx" name="fx">
|
2020-08-04 12:39:31 +00:00
|
|
|
<option value="limited">${game.i18n.localize('BITD.EffectLimited')}</option>
|
|
|
|
<option value="standard" selected>${game.i18n.localize('BITD.EffectStandard')}</option>
|
|
|
|
<option value="great">${game.i18n.localize('BITD.EffectGreat')}</option>
|
2020-08-01 10:03:56 +00:00
|
|
|
</select>
|
2020-05-25 16:00:53 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
`,
|
|
|
|
buttons: {
|
|
|
|
yes: {
|
|
|
|
icon: "<i class='fas fa-check'></i>",
|
2020-08-05 13:20:52 +00:00
|
|
|
label: game.i18n.localize('BITD.Roll'),
|
2020-05-25 16:00:53 +00:00
|
|
|
callback: (html) => {
|
|
|
|
let modifier = parseInt(html.find('[name="mod"]')[0].value);
|
2020-08-01 10:03:56 +00:00
|
|
|
let position = html.find('[name="pos"]')[0].value;
|
|
|
|
let effect = html.find('[name="fx"]')[0].value;
|
|
|
|
this.rollAttribute(attribute_name, modifier, position, effect);
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
no: {
|
|
|
|
icon: "<i class='fas fa-times'></i>",
|
2020-08-05 13:20:52 +00:00
|
|
|
label: game.i18n.localize('Close'),
|
2020-05-25 16:00:53 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
default: "yes",
|
|
|
|
}).render(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2020-08-01 10:03:56 +00:00
|
|
|
rollAttribute(attribute_name = "", additional_dice_amount = 0, position, effect) {
|
2020-05-25 16:00:53 +00:00
|
|
|
|
|
|
|
let dice_amount = 0;
|
|
|
|
if (attribute_name !== "") {
|
|
|
|
let roll_data = this.getRollData();
|
|
|
|
dice_amount += roll_data.dice_amount[attribute_name];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dice_amount = 1;
|
|
|
|
}
|
|
|
|
dice_amount += additional_dice_amount;
|
|
|
|
|
2020-08-01 10:03:56 +00:00
|
|
|
bladesRoll(dice_amount, attribute_name, position, effect);
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create <options> for available actions
|
|
|
|
* which can be performed.
|
|
|
|
*/
|
|
|
|
createListOfActions() {
|
|
|
|
|
|
|
|
let text, attribute, skill;
|
|
|
|
let attributes = this.data.data.attributes;
|
|
|
|
|
|
|
|
for ( attribute in attributes ) {
|
|
|
|
|
|
|
|
var skills = attributes[attribute].skills;
|
|
|
|
|
|
|
|
text += `<optgroup label="${attribute} Actions">`;
|
|
|
|
text += `<option value="${attribute}">${attribute} (Resist)</option>`;
|
|
|
|
|
|
|
|
for ( skill in skills ) {
|
|
|
|
text += `<option value="${skill}">${skill}</option>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
text += `</optgroup>`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates <options> modifiers for dice roll.
|
|
|
|
*
|
|
|
|
* @param {int} rs
|
|
|
|
* Min die modifier
|
|
|
|
* @param {int} re
|
|
|
|
* Max die modifier
|
|
|
|
* @param {int} s
|
|
|
|
* Selected die
|
|
|
|
*/
|
|
|
|
createListOfDiceMods(rs, re, s) {
|
|
|
|
|
|
|
|
var text = ``;
|
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
if ( s == "" ) {
|
|
|
|
s = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i = rs; i <= re; i++ ) {
|
|
|
|
var plus = "";
|
|
|
|
if ( i >= 0 ) { plus = "+" };
|
|
|
|
text += `<option value="${i}"`;
|
|
|
|
if ( i == s ) {
|
|
|
|
text += ` selected`;
|
|
|
|
}
|
|
|
|
|
|
|
|
text += `>${plus}${i}d</option>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
}
|