Amélioration fiche d'item

This commit is contained in:
ZigmundKreud
2021-11-08 14:40:29 +01:00
parent b6ad8a846e
commit 0c24f49470
44 changed files with 1007 additions and 571 deletions

View File

@ -31,7 +31,6 @@ export class BoLActorSheet extends ActorSheet {
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.items.get(li.data("itemId"));
console.log(item);
item.sheet.render(true);
});
html.find('.roll-attribute').click(ev => {
@ -64,51 +63,17 @@ export class BoLActorSheet extends ActorSheet {
/** @override */
getData(options) {
console.debug("getData");
const actor = super.getData(options);
console.log(actor.data);
actor.data.details = actor.data.data.details;
actor.data.attributes = Object.values(actor.data.data.attributes);
actor.data.aptitudes = Object.values(actor.data.data.aptitudes);
actor.data.resources = Object.values(actor.data.data.resources);
actor.data.equipment = actor.data.items.filter(i => i.type === "item" || i.type == 'weapon' || i.type == 'armor');
actor.data.weapons = duplicate(actor.data.items.filter(i => i.type == 'weapon' ));
actor.data.armors = duplicate(actor.data.items.filter(i => i.type == 'armor' ));
actor.data.features = {
"careers" : {
"label" : "BOL.featureCategory.careers",
"ranked" : true,
"items" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "career")
},
"origins" : {
"label" : "BOL.featureCategory.origins",
"ranked" : false,
"items" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "origin")
},
"races" : {
"label" : "BOL.featureCategory.races",
"ranked" : false,
"items" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "race")
},
"boons" : {
"label" : "BOL.featureCategory.boons",
"ranked" : false,
"items" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "boon")
},
"flaws" : {
"label" : "BOL.featureCategory.flaws",
"ranked" : false,
"items" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "flaw")
},
"languages" : {
"label" : "BOL.featureCategory.languages",
"ranked" : false,
"items" : actor.data.items.filter(i => i.type === "feature" && i.data.subtype === "language")
}
const actorData = super.getData(options);
actorData.data = {
details : this.actor.details,
attributes : this.actor.attributes,
aptitudes : this.actor.aptitudes,
resources : this.actor.resources,
equipment : this.actor.equipment,
combat : this.actor.buildCombat(),
features : this.actor.buildFeatures()
};
return actor;
return actorData;
}
/* -------------------------------------------- */

View File

@ -10,9 +10,6 @@ export class BoLActor extends Actor {
/** @override */
prepareData() {
super.prepareData();
console.debug("prepareData");
const actorData = this.data;
// console.log(actorData);
// const data = actorData.data;
@ -25,12 +22,11 @@ export class BoLActor extends Actor {
}
}
// /**
// * Prepare Character type specific data
// */
/* -------------------------------------------- */
/**
* Prepare Character type specific data
*/
_prepareCharacterData(actorData) {
let newVitality = 10 + this.data.data.attributes.vigor.value;
let newVitality = 10 + this.data.data.attributes.vigor.value;
if ( newVitality != this.data.data.resources.hp.max) {
this.data.data.resources.hp.max = newVitality;
this.update( { 'data.resources.hp.max': newVitality});
@ -38,18 +34,153 @@ export class BoLActor extends Actor {
}
/* -------------------------------------------- */
getBoons() {
return this.data.items.filter(i => i.type === "feature" && i.data.subtype === "boon");
get itemData(){
return Array.from(this.data.items.values()).map(i => i.data);
}
get details() {
return this.data.data.details;
}
get attributes() {
return Object.values(this.data.data.attributes);
}
get aptitudes() {
return Object.values(this.data.data.aptitudes);
}
get resources() {
return Object.values(this.data.data.resources);
}
get boons() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "boon");
}
get flaws() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "flaw");
}
get careers() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "career");
}
get origins() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "origin");
}
get races() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "race");
}
get languages() {
return this.itemData.filter(i => i.type === "feature" && i.data.subtype === "language");
}
get features() {
return this.itemData.filter(i => i.type === "feature");
}
get equipment() {
return this.itemData.filter(i => i.type === "item");
}
get weapons() {
return this.itemData.filter(i => i.type === "item" && i.data.subtype === "weapon");
}
get armors() {
return this.itemData.filter(i => i.type === "item" && i.data.subtype === "armor" && i.data.worn === true);
}
get helms() {
return this.itemData.filter(i => i.type === "item" && i.data.subtype === "helm" && i.data.worn === true);
}
get shields() {
return this.itemData.filter(i => i.type === "item" && i.data.subtype === "shield" && i.data.worn === true);
}
get protections() {
return this.armors.concat(this.helms)
}
get melee() {
return this.weapons.filter(i => i.data.properties.melee === true && i.data.worn === true);
}
get ranged() {
return this.weapons.filter(i => i.data.properties.ranged === true && i.data.worn === true);
}
buildFeatures(){
return {
"careers": {
"label": "BOL.featureCategory.careers",
"ranked": true,
"items": this.careers
},
"origins": {
"label": "BOL.featureCategory.origins",
"ranked": false,
"items": this.origins
},
"races": {
"label": "BOL.featureCategory.races",
"ranked": false,
"items": this.races
},
"boons": {
"label": "BOL.featureCategory.boons",
"ranked": false,
"items": this.boons
},
"flaws": {
"label": "BOL.featureCategory.flaws",
"ranked": false,
"items": this.flaws
},
"languages": {
"label": "BOL.featureCategory.languages",
"ranked": false,
"items": this.languages
}
};
}
buildCombat(){
return {
"melee" : {
"label" : "BOL.combatCategory.melee",
"weapon" : true,
"protection" : false,
"blocking" : false,
"ranged" : false,
"items" : this.melee
},
"ranged" : {
"label" : "BOL.combatCategory.ranged",
"weapon" : true,
"protection" : false,
"blocking" : false,
"ranged" : true,
"items" : this.ranged
},
"protections" : {
"label" : "BOL.combatCategory.protections",
"weapon" : false,
"protection" : true,
"blocking" : false,
"ranged" : false,
"items" : this.protections
},
"shields" : {
"label" : "BOL.combatCategory.shields",
"weapon" : false,
"protection" : false,
"blocking" : true,
"ranged" : false,
"items" : this.shields
}
};
}
/* -------------------------------------------- */
getFlaws() {
return this.data.items.filter(i => i.type === "feature" && i.data.subtype === "flaw");
buildRollData(mode, title) {
return {
mode : mode,
title : title,
actorId: this.id,
actorImg: this.img,
boons : this.boons,
flaws : this.flaws,
d6Bonus: 0,
d6Malus: 0,
rollMode: game.settings.get("core", "rollMode"),
optionsBonusMalus: BoLUtility.buildListOptions(-8, +2),
bonusMalus: 0
}
}
/* -------------------------------------------- */
getCareers() {
return this.data.items.filter(i => i.type === "feature" && i.data.subtype === "career");
}
/* -------------------------------------------- */
saveRollData( rollData) {
this.currentRollData = rollData;
}
@ -61,20 +192,8 @@ export class BoLActor extends Actor {
attr = this.data.data.aptitudes[attrKey];
}
if (attr) {
let rollData = {
mode : "attribute",
actorId: this.id,
actorImg: this.img,
attribute: duplicate(attr),
boons : this.getBoons(),
flaws : this.getFlaws(),
d6Bonus: 0,
d6Malus: 0,
rollMode: game.settings.get("core", "rollMode"),
title: game.i18n.localize(attr.label),
optionsBonusMalus: BoLUtility.buildListOptions(-8, +2),
bonusMalus: 0
}
let rollData = this.buildRollData("attribute", game.i18n.localize(attr.label));
rollData.attribute = duplicate(attr);
let rollDialog = await BoLRollDialog.create( this, rollData);
rollDialog.render( true );
} else {
@ -86,22 +205,10 @@ export class BoLActor extends Actor {
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 rollData = this.buildRollData("career", `${career.name} : ${career.data.rank}`);
rollData.career = career;
rollData.rollAttribute = 'mind';
rollData.attributes = duplicate(this.data.data.attributes);
let rollDialog = await BoLRollDialog.create( this, rollData);
rollDialog.render( true );
} else {
@ -111,35 +218,24 @@ export class BoLActor extends Actor {
/* -------------------------------------------- */
async rollWeapon( weaponId ) {
let weapon = BoLUtility.data(this.data.items.find( item => item.type == 'weapon' && item.id == weaponId));
let weapon = BoLUtility.data(this.data.items.find( item => item.type == 'item' && item.id == weaponId));
if (weapon) {
let target = BoLUtility.getTarget();
if ( !target) {
ui.notifications.warn("You must have a target to attack with a Weapon");
return;
}
let objectDefender = BoLUtility.data(game.actors.get(target.data.actorId));
objectDefender = mergeObject(objectDefender, target.data.actorData);
let rollData = {
mode : "weapon",
actorId: this.id,
actorImg: this.img,
weapon : weapon,
target: target,
isRanged: BoLUtility.isRangedWeapon( weapon ),
defender: objectDefender,
boons : this.getBoons(),
flaws : this.getFlaws(),
rollAttribute: 'agility',
attributes: duplicate(this.data.data.attributes), // For damage bonus
d6Bonus: 0,
d6Malus: 0,
rollMode: game.settings.get("core", "rollMode"),
title: weapon.name,
rangeModifier: 0,
optionsBonusMalus: BoLUtility.buildListOptions(-8, +2),
bonusMalus: 0
}
// if ( !target) {
// ui.notifications.warn("You must have a target to attack with a Weapon");
// return;
// }
let objectDefender = (target) ? BoLUtility.data(game.actors.get(target.data.actorId)) : null;
objectDefender = (objectDefender) ? mergeObject(objectDefender, target.data.actorData) : null;
let rollData = this.buildRollData("weapon", weapon.name);
rollData.weapon = weapon;
rollData.target = target;
rollData.isRanged = BoLUtility.isRangedWeapon( weapon );
rollData.defender = objectDefender;
rollData.rollAttribute = 'agility';
rollData.attributes = duplicate(this.data.data.attributes); // For damage bonus
rollData.rangeModifier = 0;
if ( weapon.data.type == 'melee') {
rollData.aptitude = duplicate(this.data.data.aptitudes.melee);
} else {

View File

@ -14,7 +14,8 @@ Hooks.once('init', async function () {
game.bol = {
BoLActor,
BoLItem
BoLItem,
config:BOL
};
/**

View File

@ -31,12 +31,14 @@ export class BoLItemSheet extends ItemSheet {
/** @override */
getData() {
const objectData = BoLUtility.data(this.object);
const objectData = BoLUtility.data(this.item);
// const objectData = BoLUtility.data(this.object);
let itemData = foundry.utils.deepClone(BoLUtility.templateData(this.object));
let itemData = foundry.utils.deepClone(BoLUtility.templateData(this.item));
let formData = {
title: this.title,
id: this.id,
config: game.bol.config,
type: objectData.type,
img: objectData.img,
name: objectData.name,
@ -46,7 +48,9 @@ export class BoLItemSheet extends ItemSheet {
limited: this.object.limited,
options: this.options,
owner: this.document.isOwner,
isGM: game.user.isGM
isGM: game.user.isGM,
itemProperties : this.item.itemProperties
}
console.log("ITEMDATA", formData);
this.options.editable = !(this.object.data.origin == "embeddedItem");
@ -73,4 +77,5 @@ export class BoLItemSheet extends ItemSheet {
if (!this.options.editable) return;
// Roll handlers, click handlers, etc. would go here.
}
}

View File

@ -8,11 +8,33 @@ export class BoLItem extends Item {
*/
prepareData() {
super.prepareData();
console.debug("Item prepareData");
// console.debug("Item prepareData");
// Get the Item's data
const itemData = this.data;
console.log(itemData);
// console.log(itemData);
const actorData = this.actor ? this.actor.data : {};
const data = itemData.data;
}
get properties() {
return this.data.properties;
}
/* -------------------------------------------- */
/**
* Get the Array of item properties which are used in the small sidebar of the description tab
* @return {Array}
* @private
*/
get itemProperties() {
const props = [];
if ( this.data.type === "item" ) {
const entries = Object.entries(this.data.data.properties);
props.push(...entries.filter(e => e[1] === true).map(e => { return game.bol.config.itemProperties[e[0]] }));
}
return props.filter(p => !!p);
}
}

View File

@ -33,12 +33,13 @@ export class BoLUtility {
/* -------------------------------------------- */
static buildListOptions(min, max) {
let options = ""
let options = [];
for (let i = min; i <= max; i++) {
options += `<option value="${i}">${i}</option>`
options.push(`<option value="${i}">${i}</option>`);
}
return options;
return options.join("");
}
/* -------------------------------------------- */
static async showDiceSoNice(roll, rollMode) {
if (game.modules.get("dice-so-nice")?.active) {

View File

@ -19,7 +19,7 @@ BOL.itemCategories = {
"other" : "BOL.itemCategory.other"
}
BOL.equipmentCategory = {
BOL.equipmentCategories = {
"weapon" : "BOL.equipmentCategory.weapon",
"protection" : "BOL.equipmentCategory.protection",
"jewel" : "BOL.equipmentCategory.jewel",
@ -30,20 +30,20 @@ BOL.equipmentCategory = {
"other" : "BOL.equipmentCategory.other"
}
BOL.protectionCategory = {
BOL.protectionCategories = {
"armor" : "BOL.protectionCategory.armor",
"shield" : "BOL.protectionCategory.shield",
"helm" : "BOL.protectionCategory.helm",
"other" : "BOL.protectionCategory.other"
}
BOL.weaponCategory = {
BOL.weaponCategories = {
"melee" : "BOL.weaponCategory.melee",
"ranged" : "BOL.weaponCategory.ranged",
"other" : "BOL.weaponCategory.other"
}
BOL.itemProperty = {
BOL.itemProperties = {
"equipable" : "BOL.itemProperty.equipable",
"protection" : "BOL.itemProperty.protection",
"blocking" : "BOL.itemProperty.blocking",
@ -61,10 +61,10 @@ BOL.itemProperty = {
"ranged" : "BOL.itemProperty.ranged",
"weapon" : "BOL.itemProperty.weapon",
"reloadable" : "BOL.itemProperty.reloadable",
"worn" : "BOL.itemProperty.worn"
"worn" : "BOL.itemProperty.worn",
}
BOL.itemStat = {
BOL.itemStats = {
"quantity" : "BOL.itemStat.quantity",
"weight" : "BOL.itemStat.weight",
"price" : "BOL.itemStat.price",
@ -93,6 +93,15 @@ BOL.itemSoak = {
"value" : "BOL.itemSoak.value"
}
BOL.featureSubtypes = {
"origin" : "BOL.featureSubtypes.origin",
"race" : "BOL.featureSubtypes.race",
"career" : "BOL.featureSubtypes.career",
"boon" : "BOL.featureSubtypes.boon",
"flaw" : "BOL.featureSubtypes.flaw",
"language" : "BOL.featureSubtypes.language"
}
BOL.itemIcons = {
"item": "icons/containers/chest/chest-worn-oak-tan.webp",
"capacity": "icons/sundries/scrolls/scroll-plain-tan-red.webp",

View File

@ -5,8 +5,9 @@ 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);
let options = { classes: ["bol", "dialog"], width: 600, height: 320, 'z-index': 99999 };
// let html = await renderTemplate(`systems/bol/templates/roll/roll-dialog-${rollData.mode}.hbs`, rollData);
let html = await renderTemplate(`systems/bol/templates/roll/roll-dialog.hbs`, rollData);
return new BoLRollDialog(actor, rollData, html, options );
}

View File

@ -17,10 +17,16 @@ export const preloadHandlebarsTemplates = async function () {
"systems/bol/templates/item/parts/item-header.hbs",
"systems/bol/templates/item/parts/properties/feature-properties.hbs",
"systems/bol/templates/item/parts/properties/equipment-properties.hbs",
"systems/bol/templates/item/parts/properties/protection-properties.hbs",
"systems/bol/templates/item/parts/properties/shield-properties.hbs",
"systems/bol/templates/item/parts/properties/weapon-properties.hbs",
"systems/bol/templates/item/parts/properties/armor-properties.hbs",
"systems/bol/templates/item/parts/properties/melee-properties.hbs",
"systems/bol/templates/item/parts/properties/ranged-properties.hbs",
"systems/bol/templates/item/parts/properties/item-properties.hbs"
"systems/bol/templates/item/parts/properties/item-properties.hbs",
// DIALOGS
"systems/bol/templates/roll/parts/roll-dialog-modifiers.hbs",
"systems/bol/templates/roll/parts/roll-dialog-attribute.hbs"
];
// Load the template parts