Roll pour carrière

This commit is contained in:
2021-11-01 00:28:42 +01:00
parent 1992d618a9
commit 4452f3826a
21 changed files with 7890 additions and 95 deletions

View File

@ -59,6 +59,11 @@ export class BoLActorSheet extends ActorSheet {
item.sheet.render(true);
});
html.find('.roll-career').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.rollCareer( li.data("itemId") );
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");

View File

@ -1,3 +1,6 @@
import { BoLRollDialog } from "../system/roll-dialog.js";
import { BoLUtility } from "../system/bol-utility.js";
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
@ -26,12 +29,52 @@ export class BoLActor extends Actor {
// const data = actorData.data;
//
// // Make modifications to data here. For example:
//
// // Loop through ability scores, and add their modifiers to our sheet output.
//// // Loop through ability scores, and add their modifiers to our sheet output.
// for (let [key, ability] of Object.entries(data.abilities)) {
// // Calculate the modifier using d20 rules.
// ability.mod = Math.floor((ability.value - 10) / 2);
// }
// }
/* -------------------------------------------- */
getBoons() {
return this.data.items.filter(i => i.type === "feature" && i.data.subtype === "boon");
}
/* -------------------------------------------- */
getFlaws() {
return this.data.items.filter(i => i.type === "feature" && i.data.subtype === "flaw");
}
/* -------------------------------------------- */
getCareers() {
return this.data.items.filter(i => i.type === "feature" && i.data.subtype === "career");
}
/* -------------------------------------------- */
saveRollData( rollData) {
this.currentRollData = rollData;
}
async rollCareer( careerId ) {
let career = BoLUtility.data(this.data.items.find( item => item.type == 'feature' && item.id == careerId));
if (career) {
let rollData = {
mode : "career",
actorId: this.id,
actorImg: this.img,
career : career,
rollAttribute: 'mind',
attributes : duplicate(this.data.data.attributes),
boons : this.getBoons(),
flaws : this.getFlaws(),
d6Bonus: 0,
d6Malus: 0,
rollMode: game.settings.get("core", "rollMode"),
title: `${career.name} : ${career.data.rank}`,
optionsBonusMalus: BoLUtility.buildListOptions(-8, +2),
bonusMalus: 0
}
let rollDialog = await BoLRollDialog.create( this, rollData);
rollDialog.render( true );
} else {
ui.notifications.warn("Unable to find career for actor " + this.name + " - Career ID " + careerId);
}
}
}

View File

@ -22,8 +22,8 @@ Hooks.once('init', async function () {
* @type {String}
*/
CONFIG.Combat.initiative = {
formula: "1d20",
decimals: 2
formula: "2d6+@attributes.mind.value+@aptitudes.init.value",
decimals: 0
};
// Define custom Entity classes

View File

@ -1,3 +1,5 @@
import { BoLUtility } from "../system/bol-utility.js";
/**
* Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet}
@ -29,12 +31,26 @@ export class BoLItemSheet extends ItemSheet {
/** @override */
getData() {
const item = super.getData();
console.debug("Item getData");
item.data.description = item.data.data.description;
item.data.properties = item.data.data.properties;
console.log(item.data);
return item;
const objectData = BoLUtility.data(this.object);
let itemData = foundry.utils.deepClone(BoLUtility.templateData(this.object));
let formData = {
title: this.title,
id: this.id,
type: objectData.type,
img: objectData.img,
name: objectData.name,
editable: this.isEditable,
cssClass: this.isEditable ? "editable" : "locked",
data: itemData,
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
isGM: game.user.isGM
}
console.log("ITEMDATA", formData);
this.options.editable = !(this.object.data.origin == "embeddedItem");
return formData;
}
/* -------------------------------------------- */

View File

@ -0,0 +1,186 @@
export class BoLUtility {
/* -------------------------------------------- */
static async init() {
}
/* -------------------------------------------- */
static async ready() {
}
/* -------------------------------------------- */
static templateData(it) {
return BoLUtility.data(it)?.data ?? {}
}
/* -------------------------------------------- */
static data(it) {
if (it instanceof Actor || it instanceof Item || it instanceof Combatant) {
return it.data;
}
return it;
}
/* -------------------------------------------- */
static createDirectOptionList( min, max) {
let options = {};
for(let i=min; i<=max; i++) {
options[`${i}`] = `${i}`;
}
return options;
}
/* -------------------------------------------- */
static buildListOptions(min, max) {
let options = ""
for (let i = min; i <= max; i++) {
options += `<option value="${i}">${i}</option>`
}
return options;
}
/* -------------------------------------------- */
static async showDiceSoNice(roll, rollMode) {
if (game.modules.get("dice-so-nice")?.active) {
if (game.dice3d) {
let whisper = null;
let blind = false;
rollMode = rollMode ?? game.settings.get("core", "rollMode");
switch (rollMode) {
case "blindroll": //GM only
blind = true;
case "gmroll": //GM + rolling player
whisper = this.getUsers(user => user.isGM);
break;
case "roll": //everybody
whisper = this.getUsers(user => user.active);
break;
case "selfroll":
whisper = [game.user.id];
break;
}
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
}
}
/* -------------------------------------------- */
static getUsers(filter) {
return game.users.filter(filter).map(user => user.data._id);
}
/* -------------------------------------------- */
static getWhisperRecipients(rollMode, name) {
switch (rollMode) {
case "blindroll": return this.getUsers(user => user.isGM);
case "gmroll": return this.getWhisperRecipientsAndGMs(name);
case "selfroll": return [game.user.id];
}
return undefined;
}
/* -------------------------------------------- */
static getWhisperRecipientsAndGMs(name) {
let recep1 = ChatMessage.getWhisperRecipients(name) || [];
return recep1.concat(ChatMessage.getWhisperRecipients('GM'));
}
/* -------------------------------------------- */
static blindMessageToGM(chatOptions) {
let chatGM = duplicate(chatOptions);
chatGM.whisper = this.getUsers(user => user.isGM);
chatGM.content = "Blinde message of " + game.user.name + "<br>" + chatOptions.content;
console.log("blindMessageToGM", chatGM);
game.socket.emit("system.fvtt-fragged-kingdom", { msg: "msg_gm_chat_message", data: chatGM });
}
/* -------------------------------------------- */
static createChatMessage(name, rollMode, chatOptions) {
switch (rollMode) {
case "blindroll": // GM only
if (!game.user.isGM) {
this.blindMessageToGM(chatOptions);
chatOptions.whisper = [game.user.id];
chatOptions.content = "Message only to the GM";
}
else {
chatOptions.whisper = this.getUsers(user => user.isGM);
}
break;
default:
chatOptions.whisper = this.getWhisperRecipients(rollMode, name);
break;
}
chatOptions.alias = chatOptions.alias || name;
ChatMessage.create(chatOptions);
}
/* -------------------------------------------- */
static createChatWithRollMode(name, chatOptions) {
this.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions);
}
/* -------------------------------------------- */
static async rollBoL( rollData ) {
// Dice bonus/malus selection
let nbDice = 2;
let d6BM = 0;
let mode = "";
if ( rollData.d6Malus > rollData.d6Bonus){
d6BM = rollData.d6Malus - rollData.d6Bonus;
mode = "kl2";
}
if ( rollData.d6Bonus > rollData.d6Malus){
d6BM = rollData.d6Bonus - rollData.d6Malus;
mode = "kh2";
}
nbDice += d6BM;
// Final modifier
let modifier = Number(rollData.attributes[rollData.rollAttribute].value) + Number(rollData.career.data.rank) + Number(rollData.bonusMalus);
let formula = nbDice+"d6"+mode+"+"+modifier;
console.log("Goigin to roll ", formula, rollData.attributes, rollData.rollAttribute);
let myRoll = new Roll(formula).roll( { async: false});
await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode") );
rollData.roll = myRoll;
rollData.formula = formula;
rollData.modifier = modifier;
rollData.finalScore = myRoll.total;
let actor = game.actors.get(rollData.actorId);
actor.saveRollData( rollData );
this.createChatWithRollMode( rollData.alias, {
content: await renderTemplate(`systems/bol/templates/roll/chat-generic-result.hbs`, rollData)
});
// TODO
}
/* -------------------------------------------- */
static async confirmDelete(actorSheet, li) {
let itemId = li.data("item-id");
let msgTxt = "<p>Are you sure to remove this Item ?";
let buttons = {
delete: {
icon: '<i class="fas fa-check"></i>',
label: "Yes, remove it",
callback: () => {
actorSheet.actor.deleteEmbeddedDocuments( "Item", [itemId] );
li.slideUp(200, () => actorSheet.render(false));
}
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Cancel"
}
}
msgTxt += "</p>";
let d = new Dialog({
title: "Confirm removal",
content: msgTxt,
buttons: buttons,
default: "cancel"
});
d.render(true);
}
}

View File

@ -0,0 +1,64 @@
import { BoLUtility } from "../system/bol-utility.js";
export class BoLRollDialog extends Dialog {
/* -------------------------------------------- */
static async create(actor, rollData ) {
let options = { classes: ["BoL"], width: 600, height: 320, 'z-index': 99999 };
let html = await renderTemplate(`systems/bol/templates/roll/roll-dialog-${rollData.mode}.hbs`, rollData);
return new BoLRollDialog(actor, rollData, html, options );
}
/* -------------------------------------------- */
constructor(actor, rollData, html, options, close = undefined) {
let conf = {
title: rollData.title,
content: html,
buttons: {
roll: {
icon: '<i class="fas fa-check"></i>',
label: "Roll !",
callback: () => { this.roll() }
},
cancel: {
icon: '<i class="fas fa-times"></i>',
label: "Cancel",
callback: () => { this.close() }
} },
default: "roll",
close: close
}
super(conf, options);
console.log("ROLLDATA ", rollData);
this.actor = actor;
this.rollData = rollData;
}
/* -------------------------------------------- */
roll () {
BoLUtility.rollBoL( this.rollData )
}
/* -------------------------------------------- */
activateListeners(html) {
super.activateListeners(html);
var dialog = this;
function onLoad() {
}
$(function () { onLoad(); });
html.find('#bonusMalus').change((event) => {
this.rollData.bonusMalus = Number(event.currentTarget.value);
});
html.find('#d6Bonus').change((event) => {
this.rollData.d6Bonus = Number(event.currentTarget.value);
});
html.find('#d6Malus').change((event) => {
this.rollData.d6Malus = Number(event.currentTarget.value);
});
}
}

View File

@ -7,55 +7,6 @@ export const preloadHandlebarsTemplates = async function () {
// Define template paths to load
const templatePaths = [
// ACTOR
"systems/cof/templates/actors/actor-sheet.hbs",
"systems/cof/templates/actors/loot-sheet.hbs",
"systems/cof/templates/actors/parts/actor-details.hbs",
"systems/cof/templates/actors/parts/actor-tabs.hbs",
"systems/cof/templates/actors/parts/actor-description.hbs",
"systems/cof/templates/actors/parts/capacities/actor-capacities.hbs",
"systems/cof/templates/actors/parts/capacities/actor-paths.hbs",
"systems/cof/templates/actors/parts/combat/actor-combat.hbs",
"systems/cof/templates/actors/parts/combat/actor-combat-item.hbs",
"systems/cof/templates/actors/parts/combat/encounter-combat.hbs",
"systems/cof/templates/actors/parts/details/actor-details.hbs",
"systems/cof/templates/actors/parts/details/encounter-details.hbs",
"systems/cof/templates/actors/parts/inventory/actor-inventory.hbs",
"systems/cof/templates/actors/parts/inventory/actor-inventory-item.hbs",
"systems/cof/templates/actors/parts/stats/actor-stats.hbs",
"systems/cof/templates/actors/parts/stats/encounter-stats.hbs",
"systems/cof/templates/actors/parts/stats/actor-attacks.hbs",
"systems/cof/templates/actors/parts/stats/actor-attributes.hbs",
"systems/cof/templates/actors/parts/stats/actor-recovery.hbs",
"systems/cof/templates/actors/parts/stats/actor-resources.hbs",
"systems/cof/templates/actors/parts/stats/actor-vitality.hbs",
"systems/cof/templates/actors/parts/stats/actor-defence.hbs",
"systems/cof/templates/actors/parts/stats/actor-init.hbs",
// EFFECTS
"systems/cof/templates/effects/effects.hbs",
"systems/cof/templates/effects/effects-item.hbs",
// DIALOGS
"systems/cof/templates/dialogs/parts/roll-dmg-fields.hbs",
// ITEMS PROPERTIES
"systems/cof/templates/items/parts/properties/item-properties.hbs",
// ITEMS DETAILS
"systems/cof/templates/items/parts/details/item-details.hbs",
"systems/cof/templates/items/parts/details/capacity-details.hbs",
"systems/cof/templates/items/parts/details/path-details.hbs",
"systems/cof/templates/items/parts/details/profile-details.hbs",
"systems/cof/templates/items/parts/details/ranged-details.hbs",
"systems/cof/templates/items/parts/details/species-details.hbs",
"systems/cof/templates/items/parts/details/equipment-details.hbs",
"systems/cof/templates/items/parts/details/protection-details.hbs",
"systems/cof/templates/items/parts/details/spell-details.hbs",
"systems/cof/templates/items/parts/details/weapon-details.hbs",
"systems/cof/templates/items/parts/details/usage-details.hbs",
"systems/cof/templates/items/parts/details/effects-details.hbs",
];
// Load the template parts