Gestion des signes draconiques #455
@ -11,6 +11,7 @@ import { RdDBonus } from "./rdd-bonus.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDCombatManager } from "./rdd-combat.js";
|
||||
import { RdDCarac } from "./rdd-carac.js";
|
||||
import { RdDItem } from "./item.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDActorSheet extends ActorSheet {
|
||||
@ -183,7 +184,7 @@ export class RdDActorSheet extends ActorSheet {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async selectObjetType() {
|
||||
let typeObjets = ["objet", "arme", "armure", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "monnaie"];
|
||||
let typeObjets = RdDItem.getTypeObjetsEquipement();
|
||||
let options = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
|
||||
for (let typeName of typeObjets) {
|
||||
options += `<option value="${typeName}">${typeName}</option>`
|
||||
@ -205,7 +206,7 @@ export class RdDActorSheet extends ActorSheet {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async selectTypeOeuvre() {
|
||||
let typeOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu" ];
|
||||
let typeOeuvres = RdDItem.getTypesOeuvres();
|
||||
let options = `<span class="competence-label">Selectionnez le type d'oeuvre</span><select class="item-type">`;
|
||||
for (let typeName of typeOeuvres) {
|
||||
options += `<option value="${typeName}">${typeName}</option>`
|
||||
|
@ -240,7 +240,7 @@ export class RdDActor extends Actor {
|
||||
return Math.floor(Misc.templateData(this).prixTotalEquipement ?? 0);
|
||||
}
|
||||
getSurenc() {
|
||||
return Misc.toInt(Misc.templateData(this).compteurs.surenc?.value);
|
||||
return Misc.templateData(this).compteurs.surenc?.value ?? 0;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getCompetence(name) {
|
||||
@ -956,8 +956,9 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
detectSurEncombrement() {
|
||||
return Math.max(0, Math.ceil(Number(this.data.encTotal) - this.getEncombrementMax()));
|
||||
return Math.max(0, Math.ceil(Number(this.encTotal) - this.getEncombrementMax()));
|
||||
}
|
||||
|
||||
getEncombrementMax() {
|
||||
return (this.data.type == 'vehicule')
|
||||
? Misc.templateData(this).capacite_encombrement
|
||||
@ -980,17 +981,11 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computeEncombrement() {
|
||||
Misc.templateData(this).encTotal = this.filterItemsData(it => it.data.encombrement)
|
||||
.map(it => this._calcEncItem(it))
|
||||
const tplData = Misc.templateData(this);
|
||||
tplData.encTotal = this.filterItemsData(it => it.data.encombrement != undefined)
|
||||
.map(it => it.data.encTotal)
|
||||
.reduce(Misc.sum(), 0);
|
||||
return Misc.templateData(this).encTotal;
|
||||
}
|
||||
|
||||
_calcEncItem(it) {
|
||||
it.data.encombrement = Number(it.data.encombrement ?? 0);
|
||||
it.data.quantite = Math.min(1, Number(it.data.quantite ?? 1));
|
||||
it.data.encTotal = it.data.encombrement * it.data.quantite;
|
||||
return it.data.encTotal;
|
||||
return tplData.encTotal;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -1007,17 +1002,12 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
computePrixTotalEquipement() {
|
||||
let prixTotalEquipement = 0;
|
||||
|
||||
// prix total de l'équipement est la somme du cout de chaque équipement multiplié par sa quantité.
|
||||
for (const itemData of this.filterItemsData(it => it?.data.cout)) {
|
||||
const cout = Math.min(Number(itemData.data.cout ?? 0), 0);
|
||||
const quantite = Math.min(Number(itemData.data?.quantite ?? 1), 1);
|
||||
prixTotalEquipement += cout * quantite;
|
||||
}
|
||||
const tplData = Misc.templateData(this);
|
||||
tplData.prixTotalEquipement = this.filterItemsData(it => it.data.prixTotal)
|
||||
.map(it => it.data.prixTotal ?? 0)
|
||||
.reduce(Misc.sum(), 0);
|
||||
// Mise à jour valeur totale de l'équipement
|
||||
Misc.templateData(this).prixTotalEquipement = prixTotalEquipement;
|
||||
return prixTotalEquipement;
|
||||
return tplData.prixTotalEquipement;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -1068,7 +1058,7 @@ export class RdDActor extends Actor {
|
||||
state += Math.min(0, (actorData.data.compteurs.ethylisme?.value ?? 0));
|
||||
|
||||
actorData.data.compteurs.etat.value = state;
|
||||
if (actorData.data.compteurs && actorData.data.compteurs.surenc) {
|
||||
if (actorData.data.compteurs?.surenc) {
|
||||
actorData.data.compteurs.surenc.value = - this.detectSurEncombrement();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { RdDItemSort } from "./item-sort.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { RdDItem } from "./item-rdd.js";
|
||||
import { RdDItem } from "./item.js";
|
||||
import { RdDAlchimie } from "./rdd-alchimie.js";
|
||||
import { RdDItemCompetence } from "./item-competence.js";
|
||||
import { RdDHerbes } from "./rdd-herbes.js";
|
||||
|
@ -1,9 +1,32 @@
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
|
||||
const typesObjetsEquipement = ["objet", "arme", "armure", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "nourritureboisson"];
|
||||
const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"];
|
||||
/* -------------------------------------------- */
|
||||
export class RdDItem extends Item {
|
||||
|
||||
static getTypeObjetsEquipement() {
|
||||
return typesObjetsEquipement;
|
||||
}
|
||||
static getTypesOeuvres() {
|
||||
return typesObjetsOeuvres;
|
||||
}
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData();
|
||||
const itemData = this.data;
|
||||
const tplData = itemData.data;
|
||||
if (RdDItem.getTypeObjetsEquipement().includes(itemData.type)) {
|
||||
const quantite = itemData.type == 'conteneur' ? 1 : (tplData.quantite ?? 0);
|
||||
if (tplData.encombrement != undefined) {
|
||||
tplData.encTotal = Math.max(tplData.encombrement, 0) * quantite;
|
||||
}
|
||||
if (tplData.cout != undefined) {
|
||||
tplData.prixTotal = Math.max(tplData.cout, 0) * quantite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async postItem() {
|
||||
console.log(this);
|
||||
@ -17,13 +40,13 @@ export class RdDItem extends Item {
|
||||
chatData.data.cout_deniers = 0;
|
||||
|
||||
let dialogResult = [-1, -1]; // dialogResult[0] = quantité, dialogResult[1] = prix
|
||||
if (chatData.hasPrice )
|
||||
{
|
||||
if (chatData.hasPrice) {
|
||||
let sols = chatData.data.cout;
|
||||
chatData.data.cout_deniers = Math.floor(sols * 100);
|
||||
dialogResult = await new Promise( (resolve, reject) => {new Dialog({
|
||||
content :
|
||||
`<p>Modifier la quantité?</p>
|
||||
dialogResult = await new Promise((resolve, reject) => {
|
||||
new Dialog({
|
||||
content:
|
||||
`<p>Modifier la quantité?</p>
|
||||
<div class="form-group">
|
||||
<label> Quantité</label>
|
||||
<input name="quantity" type="text" value="1"/>
|
||||
@ -34,43 +57,40 @@ export class RdDItem extends Item {
|
||||
<input name="price" type="text" value="${chatData.data.cout}"/>
|
||||
</div>
|
||||
`,
|
||||
title : "Quantité & Prix",
|
||||
buttons : {
|
||||
post : {
|
||||
label : "Soumettre",
|
||||
title: "Quantité & Prix",
|
||||
buttons: {
|
||||
post: {
|
||||
label: "Soumettre",
|
||||
callback: (dlg) => {
|
||||
resolve( [ dlg.find('[name="quantity"]').val(), dlg.find('[name="price"]').val() ] )
|
||||
resolve([dlg.find('[name="quantity"]').val(), dlg.find('[name="price"]').val()])
|
||||
}
|
||||
},
|
||||
}
|
||||
}).render(true)
|
||||
})
|
||||
}
|
||||
|
||||
if (dialogResult[0] > 0)
|
||||
{
|
||||
if (this.isOwned)
|
||||
{
|
||||
}
|
||||
|
||||
if (dialogResult[0] > 0) {
|
||||
if (this.isOwned) {
|
||||
if (itemData.data.quantite == 0)
|
||||
dialogResult[0] = -1
|
||||
else if (itemData.data.quantite < dialogResult[0])
|
||||
{
|
||||
else if (itemData.data.quantite < dialogResult[0]) {
|
||||
dialogResult[0] = itemData.data.quantite;
|
||||
ui.notifications.notify(`Impossible de poster plus que ce que vous avez. La quantité à été réduite à ${dialogResult[0]}.`)
|
||||
this.update({"data.quantite" : 0})
|
||||
ui.notifications.notify(`Impossible de poster plus que ce que vous avez. La quantité à été réduite à ${dialogResult[0]}.`)
|
||||
this.update({ "data.quantite": 0 })
|
||||
}
|
||||
else {
|
||||
ui.notifications.notify(`Quantité réduite par ${dialogResult[0]}.`)
|
||||
this.update({"data.quantite" : itemData.data.quantite - dialogResult[0]})
|
||||
ui.notifications.notify(`Quantité réduite par ${dialogResult[0]}.`)
|
||||
this.update({ "data.quantite": itemData.data.quantite - dialogResult[0] })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( chatData.hasPrice ) {
|
||||
|
||||
if (chatData.hasPrice) {
|
||||
if (dialogResult[0] > 0)
|
||||
chatData.postQuantity = Number(dialogResult[0]);
|
||||
if (dialogResult[1] > 0) {
|
||||
chatData.postPrice = dialogResult[1];
|
||||
chatData.postPrice = dialogResult[1];
|
||||
chatData.data.cout_deniers = Math.floor(dialogResult[1] * 100); // Mise à jour cout en deniers
|
||||
}
|
||||
chatData.finalPrice = Number(chatData.postPrice) * Number(chatData.postQuantity);
|
||||
@ -81,14 +101,14 @@ export class RdDItem extends Item {
|
||||
// Don't post any image for the item (which would leave a large gap) if the default image is used
|
||||
if (chatData.img.includes("/blank.png"))
|
||||
chatData.img = null;
|
||||
|
||||
|
||||
// JSON object for easy creation
|
||||
chatData.jsondata = JSON.stringify(
|
||||
{
|
||||
compendium : "postedItem",
|
||||
payload: itemData,
|
||||
});
|
||||
|
||||
{
|
||||
compendium: "postedItem",
|
||||
payload: itemData,
|
||||
});
|
||||
|
||||
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-item.html', chatData).then(html => {
|
||||
let chatOptions = RdDUtility.chatDataSetup(html);
|
||||
ChatMessage.create(chatOptions)
|
@ -29,6 +29,7 @@ import { TMRRencontres } from "./tmr-rencontres.js";
|
||||
import { RdDHotbar } from "./rdd-hotbar-drop.js"
|
||||
import { EffetsDraconiques } from "./tmr/effets-draconiques.js";
|
||||
import { RdDHerbes } from "./rdd-herbes.js";
|
||||
import { RdDItem } from "./item.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
@ -134,6 +135,7 @@ Hooks.once("init", async function () {
|
||||
/* -------------------------------------------- */
|
||||
// Define custom Entity classes
|
||||
CONFIG.Actor.documentClass = RdDActor;
|
||||
CONFIG.Item.documentClass = RdDItem;
|
||||
CONFIG.RDD = {
|
||||
resolutionTable: RdDResolutionTable.resolutionTable,
|
||||
carac_array: RdDUtility.getCaracArray(),
|
||||
|
@ -206,7 +206,9 @@ table {border: 1px solid #7a7971;}
|
||||
.flex-shrink {
|
||||
flex: 'flex-shrink' ;
|
||||
}
|
||||
|
||||
.flex-grow {
|
||||
flex-grow : 3;
|
||||
}
|
||||
/* Styles limited to foundryvtt-reve-de-dragon sheets */
|
||||
|
||||
.foundryvtt-reve-de-dragon .sheet-header {
|
||||
|
@ -2,15 +2,17 @@
|
||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||
|
||||
{{#if (eq item.type 'conteneur')}}
|
||||
<span class="item-name conteneur-name"><a data-item-id="{{item._id}}">+{{item.name}}</a></span>
|
||||
<span class="item-name conteneur-name flex-grow"><a data-item-id="{{item._id}}">+{{item.name}}</a></span>
|
||||
{{else}}
|
||||
<span class="item-name">{{item.name}}</span>
|
||||
<span class="item-name flex-grow">{{item.name}}</span>
|
||||
{{/if}}
|
||||
|
||||
<span class="item-quantite">{{item.data.quantite}}</span>
|
||||
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
|
||||
<div class="item-controls">
|
||||
<div class="item-controls flex-grow">
|
||||
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
|
||||
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
||||
{{#if (eq item.type 'nourritureboisson')}}
|
||||
<a class="item-name item-consommer">Consommer</a>
|
||||
{{/if}}
|
||||
</div>
|
||||
</li>
|
||||
|
@ -748,23 +748,23 @@
|
||||
<ul class="item-list alterne-list">
|
||||
<li class="competence-header flexrow">
|
||||
<img class="sheet-competence-img" src="systems/foundryvtt-reve-de-dragon/icons/objets/sac_a_dos.webp" title="Equipement"/>
|
||||
<span class="competence-title competence-label">Nom</span>
|
||||
<span class="competence-title competence-label">Q.</span>
|
||||
<span class="competence-title competence-label">Enc.</span>
|
||||
<span class="competence-title competence-label">Equiper/Editer/Suppr.</span>
|
||||
<span class="competence-title flex-grow">Nom</span>
|
||||
<span class="competence-title">Q.</span>
|
||||
<span class="competence-title">Enc.</span>
|
||||
<span class="competence-title flex-grow">Equiper/Editer/Suppr.</span>
|
||||
</li>
|
||||
{{#each objets as |item id|}}
|
||||
{{#unless item.estContenu}}
|
||||
{{#if (ne item.type 'conteneur')}}
|
||||
<li class="item flexrow list-item" data-item-id="{{item._id}}">
|
||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||
<span class="item-name">{{item.name}}</span>
|
||||
<span class="item-name flex-grow">{{item.name}}</span>
|
||||
<span class="item-quantite">{{item.data.quantite}}</span>
|
||||
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
|
||||
<span class="item-controls">
|
||||
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
|
||||
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
|
||||
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
||||
<span class="item-controls flex-grow">
|
||||
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
|
||||
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
|
||||
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
|
||||
</span>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
Loading…
Reference in New Issue
Block a user