#124 : Les creatures peuvent avoir de l'equipement

This commit is contained in:
sladecraven 2021-01-08 16:57:10 +01:00
parent 9e3b2a557f
commit a432ed6d32
7 changed files with 77 additions and 57 deletions

View File

@ -6,9 +6,10 @@
import { HtmlUtility } from "./html-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 */
static get defaultOptions() {
@ -26,6 +27,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
/* -------------------------------------------- */
getData() {
let data = super.getData();
console.log("Creature : ", data);
data.itemsByType = {};
for (const item of data.items) {
@ -49,16 +51,20 @@ export class RdDActorCreatureSheet extends ActorSheet {
data.data.competencecreature = data.itemsByType["competencecreature"];
this.actor.computeEncombrementTotalEtMalusArmure();
RdDUtility.filterItemsPerTypeForSheet(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;
}
/* -------------------------------------------- */
async _onDrop(event) {
RdDUtility.processItemDropEvent(this, event);
super._onDrop(event);
prepareCreatureData( ) {
}
/* -------------------------------------------- */
@ -160,8 +166,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
this.actor.remiseANeuf();
}
});
}
}
/* -------------------------------------------- */
@ -174,9 +179,7 @@ export class RdDActorCreatureSheet extends ActorSheet {
return position;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor

View File

@ -56,7 +56,7 @@ export class RdDActorHumanoideSheet extends ActorSheet {
/* -------------------------------------------- */
async _onDrop(event) {
RdDUtility.processItemDropEvent(this, event);
await RdDUtility.processItemDropEvent(this.actor, event);
super._onDrop(event);
}

View File

@ -30,6 +30,7 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */
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.montrerCompetencesNiveauBase = this.options.montrerCompetencesNiveauBase;
@ -137,25 +138,10 @@ export class RdDActorSheet extends ActorSheet {
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) {
await this.processItemDropEvent(event);
await RdDUtility.processItemDropEvent(this, event);
super._onDrop(event);
}

View File

@ -98,7 +98,13 @@ export class RdDActor extends Actor {
// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
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( ) {
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;
for (const item of this.data.items) {
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
this.encTotal = encTotal;
console.log("Enco total : ", this.encTotal);
this.detectSurEncombrement();
// Mise à jour éventuelle du malus armure
if (newMalusArmure != malusArmureData.value) {
if (this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) {
malusArmureData.value = newMalusArmure;
await this.update( {"data.attributs.malusarmure": malusArmureData } );
}

View File

@ -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);
}
/* -------------------------------------------- */
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 ) {
actorSheet.objetVersConteneur = {}; // Table de hash locale pour recupération rapide du conteneur parent (si existant)

View File

@ -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":"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":"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":[]}

View File

@ -185,19 +185,27 @@
{{!-- Equipment Tab --}}
<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>
<hr>
<span cass=item-name>Porté sur soi</span>
<ol class="item-list alterne-list">
<span class="item-name">Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}} <b>{{data.surEncombrementMessage}}</b></span> -
<span class="item-name"><a id="creer-un-objet">Créer un objet</a></span>
{{#if data.isGM}}
<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|}}
{{#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}}"/>
<h4 class="item-name">{{item.name}}</h4>
{{#if item.data.quantite}}
<h4 class="item-quantite">{{item.data.quantite}}</h4>
{{/if}}
<span class="item-name">{{item.name}}</span>
<span class="item-quantite">{{item.data.quantite}}</span>
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
<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-edit" title="Editer"><i class="fas fa-edit"></i></a>
@ -210,6 +218,7 @@
{{#each data.conteneurs as |conteneur id|}}
{{buildConteneur this}}
{{/each}}
</ul>
</div>
{{!-- Biography Tab --}}