#124 : Les creatures peuvent avoir de l'equipement
This commit is contained in:
parent
9e3b2a557f
commit
a432ed6d32
@ -6,9 +6,10 @@
|
|||||||
|
|
||||||
import { HtmlUtility } from "./html-utility.js";
|
import { HtmlUtility } from "./html-utility.js";
|
||||||
import { RdDUtility } from "./rdd-utility.js";
|
import { RdDUtility } from "./rdd-utility.js";
|
||||||
|
import { RdDActorSheet } from "./actor-sheet.js";
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
export class RdDActorCreatureSheet extends ActorSheet {
|
export class RdDActorCreatureSheet extends RdDActorSheet {
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
static get defaultOptions() {
|
static get defaultOptions() {
|
||||||
@ -26,6 +27,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getData() {
|
getData() {
|
||||||
let data = super.getData();
|
let data = super.getData();
|
||||||
|
console.log("Creature : ", data);
|
||||||
|
|
||||||
data.itemsByType = {};
|
data.itemsByType = {};
|
||||||
for (const item of data.items) {
|
for (const item of data.items) {
|
||||||
@ -49,16 +51,20 @@ export class RdDActorCreatureSheet extends ActorSheet {
|
|||||||
|
|
||||||
data.data.competencecreature = data.itemsByType["competencecreature"];
|
data.data.competencecreature = data.itemsByType["competencecreature"];
|
||||||
|
|
||||||
|
this.actor.computeEncombrementTotalEtMalusArmure();
|
||||||
RdDUtility.filterItemsPerTypeForSheet(data );
|
RdDUtility.filterItemsPerTypeForSheet(data );
|
||||||
RdDUtility.buildArbreDeConteneur( this, data );
|
RdDUtility.buildArbreDeConteneur( this, data );
|
||||||
|
data.data.encTotal = this.actor.encTotal;
|
||||||
|
data.data.isGM = game.user.isGM;
|
||||||
|
|
||||||
|
console.log("Creature : ", this.objetVersConteneur , data);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async _onDrop(event) {
|
prepareCreatureData( ) {
|
||||||
RdDUtility.processItemDropEvent(this, event);
|
|
||||||
super._onDrop(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -160,8 +166,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
|
|||||||
this.actor.remiseANeuf();
|
this.actor.remiseANeuf();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
@ -174,9 +179,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
_updateObject(event, formData) {
|
_updateObject(event, formData) {
|
||||||
// Update the Actor
|
// Update the Actor
|
||||||
|
@ -56,7 +56,7 @@ export class RdDActorHumanoideSheet extends ActorSheet {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async _onDrop(event) {
|
async _onDrop(event) {
|
||||||
RdDUtility.processItemDropEvent(this, event);
|
await RdDUtility.processItemDropEvent(this.actor, event);
|
||||||
super._onDrop(event);
|
super._onDrop(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
getData() {
|
getData() {
|
||||||
let data = super.getData();
|
let data = super.getData();
|
||||||
|
if ( data.actor.type == 'creature' || data.actor.type == 'humanoide') return data; // Shortcut
|
||||||
|
|
||||||
data.data.editCaracComp = this.options.editCaracComp;
|
data.data.editCaracComp = this.options.editCaracComp;
|
||||||
data.data.montrerCompetencesNiveauBase = this.options.montrerCompetencesNiveauBase;
|
data.data.montrerCompetencesNiveauBase = this.options.montrerCompetencesNiveauBase;
|
||||||
@ -137,25 +138,10 @@ export class RdDActorSheet extends ActorSheet {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
|
||||||
async processItemDropEvent( event) {
|
|
||||||
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
|
||||||
let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop
|
|
||||||
if ( dropID ) { // Dropped over an item !!!
|
|
||||||
let objetId = dragData.id || dragData.data._id;
|
|
||||||
if ( this.objetVersConteneur[objetId] != dropID && objetId != dropID) {
|
|
||||||
if ( this.actor.validateConteneur(objetId, dropID) && this.actor.testConteneurCapacite(objetId, dropID) ) {
|
|
||||||
await this.actor.enleverDeConteneur(objetId, this.objetVersConteneur[objetId]);
|
|
||||||
await this.actor.ajouterAConteneur(objetId, dropID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.actor.computeEncombrementTotalEtMalusArmure();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async _onDrop(event) {
|
async _onDrop(event) {
|
||||||
await this.processItemDropEvent(event);
|
await RdDUtility.processItemDropEvent(this, event);
|
||||||
super._onDrop(event);
|
super._onDrop(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,13 @@ export class RdDActor extends Actor {
|
|||||||
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
// Make separate methods for each Actor type (character, npc, etc.) to keep
|
||||||
// things organized.
|
// things organized.
|
||||||
if (actorData.type === 'personnage') this._prepareCharacterData(actorData);
|
if (actorData.type === 'personnage') this._prepareCharacterData(actorData);
|
||||||
if (actorData.type === 'creature') this.computeEtatGeneral(actorData);
|
if (actorData.type === 'creature') this.prepareCreatureData(actorData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
prepareCreatureData(actorData) {
|
||||||
|
this.computeEncombrementTotalEtMalusArmure();
|
||||||
|
this.computeEtatGeneral();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
@ -755,7 +761,7 @@ export class RdDActor extends Actor {
|
|||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async computeEncombrementTotalEtMalusArmure( ) {
|
async computeEncombrementTotalEtMalusArmure( ) {
|
||||||
let encTotal = 0;
|
let encTotal = 0;
|
||||||
let malusArmureData = duplicate(this.data.data.attributs.malusarmure);
|
let malusArmureData = (this.data.data.attributs.malusarmure) ? duplicate(this.data.data.attributs.malusarmure) : {};
|
||||||
let newMalusArmure = 0;
|
let newMalusArmure = 0;
|
||||||
for (const item of this.data.items) {
|
for (const item of this.data.items) {
|
||||||
if ( item.type == 'armure' && item.data.equipe ) { // Armure équipée, intégration du malus armure total
|
if ( item.type == 'armure' && item.data.equipe ) { // Armure équipée, intégration du malus armure total
|
||||||
@ -775,9 +781,10 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
// Mise à jour valeur totale et états
|
// Mise à jour valeur totale et états
|
||||||
this.encTotal = encTotal;
|
this.encTotal = encTotal;
|
||||||
|
console.log("Enco total : ", this.encTotal);
|
||||||
this.detectSurEncombrement();
|
this.detectSurEncombrement();
|
||||||
// Mise à jour éventuelle du malus armure
|
// Mise à jour éventuelle du malus armure
|
||||||
if (newMalusArmure != malusArmureData.value) {
|
if (this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) {
|
||||||
malusArmureData.value = newMalusArmure;
|
malusArmureData.value = newMalusArmure;
|
||||||
await this.update( {"data.attributs.malusarmure": malusArmureData } );
|
await this.update( {"data.attributs.malusarmure": malusArmureData } );
|
||||||
}
|
}
|
||||||
|
@ -276,6 +276,22 @@ export class RdDUtility {
|
|||||||
data.data.objets = data.data.conteneurs.concat(data.data.materiel).concat(data.data.armes).concat(data.data.armures).concat(data.data.munitions).concat(data.data.livres).concat(data.data.potions).concat(data.data.herbes).concat(data.data.ingredients);
|
data.data.objets = data.data.conteneurs.concat(data.data.materiel).concat(data.data.armes).concat(data.data.armures).concat(data.data.munitions).concat(data.data.livres).concat(data.data.potions).concat(data.data.herbes).concat(data.data.ingredients);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
static async processItemDropEvent( actorSheet, event) {
|
||||||
|
let dragData = JSON.parse(event.dataTransfer.getData("text/plain"));
|
||||||
|
let dropID = $(event.target).parents(".item").attr("data-item-id"); // Only relevant if container drop
|
||||||
|
if ( dropID ) { // Dropped over an item !!!
|
||||||
|
let objetId = dragData.id || dragData.data._id;
|
||||||
|
if ( actorSheet.objetVersConteneur[objetId] != dropID && objetId != dropID) {
|
||||||
|
if ( actorSheet.actor.validateConteneur(objetId, dropID) && actorSheet.actor.testConteneurCapacite(objetId, dropID) ) {
|
||||||
|
await actorSheet.actor.enleverDeConteneur(objetId, actorSheet.objetVersConteneur[objetId]);
|
||||||
|
await actorSheet.actor.ajouterAConteneur(objetId, dropID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actorSheet.actor.computeEncombrementTotalEtMalusArmure();
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static buildArbreDeConteneur( actorSheet, data ) {
|
static buildArbreDeConteneur( actorSheet, data ) {
|
||||||
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)
|
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)
|
||||||
|
@ -200,4 +200,3 @@
|
|||||||
{"_id":"zQWlnUsd8bPySujd","name":"Aiguille à coudre","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"objet","data":{"description":"","quantite":1,"encombrement":0.01,"equipe":false,"resistance":0,"qualite":0,"cout":0.1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/aiguille.webp","effects":[]}
|
{"_id":"zQWlnUsd8bPySujd","name":"Aiguille à coudre","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"objet","data":{"description":"","quantite":1,"encombrement":0.01,"equipe":false,"resistance":0,"qualite":0,"cout":0.1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/aiguille.webp","effects":[]}
|
||||||
{"_id":"zYI8mDiysWtmsSyy","name":"Carquois","permission":{"default":0,"jOzRscDxoXZWpGS6":3},"type":"conteneur","data":{"description":"","capacite":2,"encombrement":0.1,"equipe":false,"qualite":0,"cout":0.5},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/carquois.webp","effects":[]}
|
{"_id":"zYI8mDiysWtmsSyy","name":"Carquois","permission":{"default":0,"jOzRscDxoXZWpGS6":3},"type":"conteneur","data":{"description":"","capacite":2,"encombrement":0.1,"equipe":false,"qualite":0,"cout":0.5},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/carquois.webp","effects":[]}
|
||||||
{"_id":"zlDa1vwmls6Uf4pt","name":"Bourse de cuir","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"conteneur","data":{"description":"","capacite":0.5,"encombrement":0.01,"equipe":false,"qualite":0,"contenu":[],"cout":0.1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/bourse.webp","effects":[]}
|
{"_id":"zlDa1vwmls6Uf4pt","name":"Bourse de cuir","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"conteneur","data":{"description":"","capacite":0.5,"encombrement":0.01,"equipe":false,"qualite":0,"contenu":[],"cout":0.1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/bourse.webp","effects":[]}
|
||||||
{"_id":"XlKp5BvZX8A03fUg","name":"Sac à dos de cuir","permission":{"default":0,"rYShh2P1DNavdoBD":3},"type":"conteneur","data":{"description":"","capacite":25,"encombrement":0.4,"equipe":false,"qualite":0,"contenu":[],"cout":1},"flags":{},"img":"systems/foundryvtt-reve-de-dragon/icons/objets/sac_a_dos.webp","effects":[]}
|
|
||||||
|
@ -185,19 +185,27 @@
|
|||||||
|
|
||||||
{{!-- Equipment Tab --}}
|
{{!-- Equipment Tab --}}
|
||||||
<div class="tab items" data-group="primary" data-tab="items">
|
<div class="tab items" data-group="primary" data-tab="items">
|
||||||
<span cass=item-name>Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}}</span>
|
<span class="item-name">Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}} <b>{{data.surEncombrementMessage}}</b></span> -
|
||||||
<hr>
|
<span class="item-name"><a id="creer-un-objet">Créer un objet</a></span>
|
||||||
<span cass=item-name>Porté sur soi</span>
|
{{#if data.isGM}}
|
||||||
<ol class="item-list alterne-list">
|
<span class="item-name"> - <a id="nettoyer-conteneurs">Vider tout les conteneurs</a></span>
|
||||||
|
{{/if}}
|
||||||
|
<ul class="item-list alterne-list">
|
||||||
|
<li class="competence-header flexrow">
|
||||||
|
<span class="competence-title competence-label">Nom</span>
|
||||||
|
<span class="competence-title competence-label">Q.</span>
|
||||||
|
<span class="competence-title competence-value">Enc.</span>
|
||||||
|
<span class="competence-title competence-value">Equiper</span>
|
||||||
|
<span class="competence-title competence-value">Editer/Suppr.</span>
|
||||||
|
</li>
|
||||||
{{#each data.objets as |item id|}}
|
{{#each data.objets as |item id|}}
|
||||||
{{#unless item.estContenu}}
|
{{#unless item.estContenu}}
|
||||||
{{#if (ne item.type 'conteneur')}}
|
{{#if (ne item.type 'conteneur')}}
|
||||||
<li class="item flexrow list-item" data-item-id="{{item._id}}">
|
<li class="item flexrow list-item" data-item-id="{{item._id}}">
|
||||||
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
|
||||||
<h4 class="item-name">{{item.name}}</h4>
|
<span class="item-name">{{item.name}}</span>
|
||||||
{{#if item.data.quantite}}
|
<span class="item-quantite">{{item.data.quantite}}</span>
|
||||||
<h4 class="item-quantite">{{item.data.quantite}}</h4>
|
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
|
||||||
{{/if}}
|
|
||||||
<div class="item-controls">
|
<div 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-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-edit" title="Editer"><i class="fas fa-edit"></i></a>
|
||||||
@ -210,6 +218,7 @@
|
|||||||
{{#each data.conteneurs as |conteneur id|}}
|
{{#each data.conteneurs as |conteneur id|}}
|
||||||
{{buildConteneur this}}
|
{{buildConteneur this}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{!-- Biography Tab --}}
|
{{!-- Biography Tab --}}
|
||||||
|
Loading…
Reference in New Issue
Block a user