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 {
|
|
|
|
|
2021-01-20 09:45:38 +00:00
|
|
|
/** @override */
|
|
|
|
static async create(data, options={}) {
|
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
data.prototypeToken = data.prototypeToken || {};
|
2021-01-20 09:45:38 +00:00
|
|
|
|
|
|
|
// For Crew and Character set the Token to sync with charsheet.
|
|
|
|
switch (data.type) {
|
|
|
|
case 'character':
|
|
|
|
case 'crew':
|
2021-05-25 10:27:40 +00:00
|
|
|
case '\uD83D\uDD5B clock':
|
2022-09-03 15:44:26 +00:00
|
|
|
data.prototypeToken.actorLink = true;
|
2021-01-20 09:45:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.create(data, options);
|
|
|
|
}
|
2020-05-25 16:00:53 +00:00
|
|
|
|
|
|
|
/** @override */
|
|
|
|
getRollData() {
|
2022-09-03 15:44:26 +00:00
|
|
|
const rollData = super.getRollData();
|
2020-05-25 16:00:53 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
rollData.dice_amount = this.getAttributeDiceToThrow();
|
2020-05-25 16:00:53 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
return rollData;
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/**
|
|
|
|
* Calculate Attribute Dice to throw.
|
|
|
|
*/
|
|
|
|
getAttributeDiceToThrow() {
|
|
|
|
|
|
|
|
// Calculate Dice to throw.
|
|
|
|
let dice_amount = {};
|
2022-12-31 10:17:17 +00:00
|
|
|
dice_amount['BITD.Vice'] = 4;
|
|
|
|
|
|
|
|
for (var attribute_name in this.system.attributes) {
|
2021-05-25 10:27:40 +00:00
|
|
|
dice_amount[attribute_name] = 0;
|
2022-12-31 10:17:17 +00:00
|
|
|
for (var skill_name in this.system.attributes[attribute_name].skills) {
|
2022-09-03 15:44:26 +00:00
|
|
|
dice_amount[skill_name] = parseInt(this.system.attributes[attribute_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) {
|
2021-05-25 10:27:40 +00:00
|
|
|
dice_amount[attribute_name]++;
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-31 10:17:17 +00:00
|
|
|
// Vice dice roll uses lowest attribute dice amount
|
|
|
|
if (dice_amount[attribute_name] < dice_amount['BITD.Vice'] ) {
|
|
|
|
dice_amount['BITD.Vice'] = dice_amount[attribute_name];
|
|
|
|
}
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2022-12-31 10:17:17 +00:00
|
|
|
let attribute_label = BladesHelpers.getRollLabel(attribute_name);
|
2020-08-05 13:20:52 +00:00
|
|
|
|
2022-09-03 15:44:26 +00:00
|
|
|
let 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>
|
2021-04-22 10:30:56 +00:00
|
|
|
</div>`;
|
|
|
|
if (BladesHelpers.isAttributeAction(attribute_name)) {
|
|
|
|
content += `
|
2020-08-01 10:03:56 +00:00
|
|
|
<div class="form-group">
|
2021-04-22 10:30:56 +00:00
|
|
|
<label>${game.i18n.localize('BITD.Position')}:</label>
|
|
|
|
<select id="pos" name="pos">
|
|
|
|
<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>
|
|
|
|
</select>
|
2020-08-01 10:03:56 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-group">
|
2021-04-22 10:30:56 +00:00
|
|
|
<label>${game.i18n.localize('BITD.Effect')}:</label>
|
|
|
|
<select id="fx" name="fx">
|
|
|
|
<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>
|
|
|
|
</select>
|
|
|
|
</div>`;
|
2022-07-01 19:33:21 +00:00
|
|
|
} else {
|
2021-04-22 10:30:56 +00:00
|
|
|
content += `
|
|
|
|
<input id="pos" name="pos" type="hidden" value="">
|
|
|
|
<input id="fx" name="fx" type="hidden" value="">`;
|
2022-07-01 19:33:21 +00:00
|
|
|
}
|
2021-04-22 10:30:56 +00:00
|
|
|
content += `
|
2022-07-01 19:31:19 +00:00
|
|
|
<div className="form-group">
|
|
|
|
<label>${game.i18n.localize('BITD.Notes')}:</label>
|
|
|
|
<input id="note" name="note" type="text" value="">
|
|
|
|
</div><br/>
|
2020-05-25 16:00:53 +00:00
|
|
|
</form>
|
2021-04-22 10:30:56 +00:00
|
|
|
`;
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2021-04-22 10:30:56 +00:00
|
|
|
new Dialog({
|
|
|
|
title: `${game.i18n.localize('BITD.Roll')} ${game.i18n.localize(attribute_label)}`,
|
|
|
|
content: content,
|
2020-05-25 16:00:53 +00:00
|
|
|
buttons: {
|
|
|
|
yes: {
|
|
|
|
icon: "<i class='fas fa-check'></i>",
|
2020-08-05 13:20:52 +00:00
|
|
|
label: game.i18n.localize('BITD.Roll'),
|
2021-05-25 10:27:40 +00:00
|
|
|
callback: async (html) => {
|
2020-05-25 16:00:53 +00:00
|
|
|
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;
|
2022-07-01 19:31:19 +00:00
|
|
|
let note = html.find('[name="note"]')[0].value;
|
|
|
|
await this.rollAttribute(attribute_name, modifier, position, effect, note);
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2022-07-01 19:31:19 +00:00
|
|
|
async rollAttribute(attribute_name = "", additional_dice_amount = 0, position, effect, note) {
|
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;
|
|
|
|
|
2022-12-31 10:17:17 +00:00
|
|
|
await bladesRoll(dice_amount, attribute_name, position, effect, note, this.system.stress.value);
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create <options> for available actions
|
|
|
|
* which can be performed.
|
|
|
|
*/
|
|
|
|
createListOfActions() {
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
let text, attribute, skill;
|
2022-09-03 15:44:26 +00:00
|
|
|
let attributes = this.system.attributes;
|
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
for ( attribute in attributes ) {
|
2022-09-03 15:44:26 +00:00
|
|
|
|
|
|
|
const skills = attributes[attribute].skills;
|
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
text += `<optgroup label="${attribute} Actions">`;
|
|
|
|
text += `<option value="${attribute}">${attribute} (Resist)</option>`;
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
for ( skill in skills ) {
|
|
|
|
text += `<option value="${skill}">${skill}</option>`;
|
|
|
|
}
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
text += `</optgroup>`;
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
return text;
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates <options> modifiers for dice roll.
|
|
|
|
*
|
|
|
|
* @param {int} rs
|
|
|
|
* Min die modifier
|
2022-09-03 15:44:26 +00:00
|
|
|
* @param {int} re
|
2020-05-25 16:00:53 +00:00
|
|
|
* Max die modifier
|
|
|
|
* @param {int} s
|
|
|
|
* Selected die
|
|
|
|
*/
|
|
|
|
createListOfDiceMods(rs, re, s) {
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
var text = ``;
|
|
|
|
var i = 0;
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
if ( s == "" ) {
|
|
|
|
s = 0;
|
|
|
|
}
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
for ( i = rs; i <= re; i++ ) {
|
|
|
|
var plus = "";
|
|
|
|
if ( i >= 0 ) { plus = "+" };
|
|
|
|
text += `<option value="${i}"`;
|
|
|
|
if ( i == s ) {
|
|
|
|
text += ` selected`;
|
|
|
|
}
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
text += `>${plus}${i}d</option>`;
|
|
|
|
}
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
return text;
|
2022-09-03 15:44:26 +00:00
|
|
|
|
2020-05-25 16:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
}
|