Ajout acteur de type vehicule/maison

This commit is contained in:
sladecraven 2021-01-10 22:12:07 +01:00
parent 6493d00aab
commit e54de9f080
9 changed files with 285 additions and 203 deletions

View File

@ -1,184 +0,0 @@
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { HtmlUtility } from "./html-utility.js";
import { RdDUtility } from "./rdd-utility.js";
/* -------------------------------------------- */
export class RdDActorHumanoideSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-humanoide-sheet.html",
width: 640,
height: 720,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac"}],
dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
});
}
/* -------------------------------------------- */
getData() {
let data = super.getData();
data.itemsByType = {};
for (const item of data.items) {
let list = data.itemsByType[item.type];
if (!list) {
list = [];
data.itemsByType[item.type] = list;
}
list.push(item);
}
// Compute current carac sum
let sum = 0;
Object.values(data.data.carac).forEach(carac => { if (!carac.derivee) { sum += parseInt(carac.value) } } );
data.data.caracSum = sum;
data.data.carac.taille.isTaille = true; // To avoid button link;
data.data.carac.chance.isChance = true; // Ajouter chance actuelle et utiliser;
data.data.blessures.resume = this.actor.computeResumeBlessure(data.data.blessures);
data.data.competencecreature = data.itemsByType["competencecreature"];
data.data.isGM = game.user.isGM;
data.data.compteurs.ethylisme.nom = RdDUtility.getNomEthylisme(data.data.compteurs.ethylisme.value);
RdDUtility.filterItemsPerTypeForSheet(data );
RdDUtility.buildArbreDeConteneur( this, data );
return data;
}
/* -------------------------------------------- */
async _onDrop(event) {
await RdDUtility.processItemDropEvent(this.actor, event);
super._onDrop(event);
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.getOwnedItem(li.data("itemId"));
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.deleteOwnedItem(li.data("itemId"));
li.slideUp(200, () => this.render(false));
});
// Blessure control
html.find('.blessure-control').click(ev => {
const li = $(ev.currentTarget).parents(".item");
let btype = li.data("blessure-type");
let index = li.data('blessure-index');
let active = $(ev.currentTarget).data('blessure-active');
//console.log(btype, index, active);
this.actor.manageBlessureFromSheet(btype, index, active).then( this.render(true) );
});
// Blessure data
html.find('.blessures-soins').change(ev => {
const li = $(ev.currentTarget).parents(".item");
let btype = li.data('blessure-type');
let index = li.data('blessure-index');
let psoins = li.find('input[name=premiers_soins]').val();
let pcomplets = li.find('input[name=soins_complets]').val();
let jours = li.find('input[name=jours]').val();
let loc = li.find('input[name=localisation]').val();
//console.log(btype, index, psoins, pcomplets, jours, loc);
this.actor.setDataBlessureFromSheet(btype, index, psoins, pcomplets, jours, loc).then( this.render(true) );
});
// Roll Carac
html.find('.carac-label a').click((event) => {
let caracName = event.currentTarget.attributes.name.value;
this.actor.rollCarac( caracName.toLowerCase() );
});
// On competence change
html.find('.creature-carac').change((event) => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "carac_value", parseInt(event.target.value) );
} );
html.find('.creature-niveau').change((event) => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "niveau", parseInt(event.target.value) );
} );
html.find('.creature-dommages').change((event) => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "dommages", parseInt(event.target.value) );
} );
// Roll Skill
html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName );
});
html.find('#vie-plus').click((event) => {
this.actor.santeIncDec("vie", 1);
this.render(true);
});
html.find('#vie-moins').click((event) => {
this.actor.santeIncDec("vie", -1);
this.render(true);
});
html.find('#endurance-plus').click((event) => {
this.actor.santeIncDec("endurance", 1);
this.render(true);
});
html.find('#endurance-moins').click((event) => {
this.actor.santeIncDec("endurance", -1);
this.render(true);
});
html.find('#encaisser-direct').click(ev => {
this.actor.encaisser()
});
html.find('#remise-a-neuf').click(ev => {
if (game.user.isGM) {
this.actor.remiseANeuf();
}
});
}
/* -------------------------------------------- */
/** @override */
setPosition(options={}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}

View File

@ -0,0 +1,111 @@
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
import { RdDUtility } from "./rdd-utility.js";
import { HtmlUtility } from "./html-utility.js";
import { RdDItem } from "./item.js";
/* -------------------------------------------- */
export class RdDActorVehiculeSheet extends ActorSheet {
/** @override */
static get defaultOptions() {
RdDUtility.initAfficheContenu();
return mergeObject(super.defaultOptions, {
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor-vehicule-sheet.html",
width: 640,
height: 720,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac"}],
dragDrop: [{dragSelector: ".item-list .item", dropSelector: null}]
});
}
/* -------------------------------------------- */
_checkNull(items) {
if (items && items.length) {
return items;
}
return [];
}
/* -------------------------------------------- */
getData() {
let data = super.getData();
data.itemsByType = RdDItem.buildItemsClassification(data.items);
RdDUtility.filterItemsPerTypeForSheet(data);
RdDUtility.buildArbreDeConteneur(this, data);
this.actor.computeEncombrementTotalEtMalusArmure();
data.data.isGM = game.user.isGM;
data.data.surEncombrementMessage = (this.encTotal > data.capacite_encombrement) ? "Sur-Encombrement!" : "";
console.log("DATA", data);
return data;
}
/* -------------------------------------------- */
async _onDrop(event) {
let toSuper = await RdDUtility.processItemDropEvent(this, event);
if ( toSuper) {
super._onDrop(event);
}
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
HtmlUtility._showControlWhen($(".gm-only"), game.user.isGM);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
const item = this.actor.getOwnedItem(li.data("itemId"));
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
this.actor.deleteOwnedItem(li.data("itemId"));
li.slideUp(200, () => this.render(false));
});
// Display info about queue
html.find('.conteneur-name a').click((event) => {
let myID = event.currentTarget.attributes['data-item-id'].value;
RdDUtility.toggleAfficheContenu(myID);
this.render(true);
});
}
/* -------------------------------------------- */
/** @override */
setPosition(options={}) {
const position = super.setPosition(options);
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
return position;
}
/* -------------------------------------------- */
/** @override */
_updateObject(event, formData) {
// Update the Actor
return this.object.update(formData);
}
}

View File

@ -53,7 +53,7 @@ export class RdDActor extends Actor {
return actor;
}
let compendiumName = "";
let compendiumName;
if (data.type == "personnage") {
compendiumName = "foundryvtt-reve-de-dragon.competences";
} else if (data.type == "creature") {
@ -61,7 +61,9 @@ export class RdDActor extends Actor {
} else if (data.type == "entite") {
compendiumName = "foundryvtt-reve-de-dragon.competences-entites";
}
data.items = RdDUtility.loadCompendium(compendiumName);
if ( compendiumName ) {
data.items = RdDUtility.loadCompendium(compendiumName);
}
// Ajout monnaie
if (data.type == "personnage") {
await RdDActor.ajouterMonnaie(data.items);
@ -90,6 +92,7 @@ export class RdDActor extends Actor {
// things organized.
if (actorData.type === 'personnage') this._prepareCharacterData(actorData);
if (actorData.type === 'creature') this.prepareCreatureData(actorData);
if (actorData.type === 'vehicule') this.prepareVehiculeData(actorData);
}
/* -------------------------------------------- */
@ -98,6 +101,11 @@ export class RdDActor extends Actor {
this.computeEtatGeneral();
}
/* -------------------------------------------- */
prepareVehiculeData( actorData ) {
this.computeEncombrementTotalEtMalusArmure();
}
/* -------------------------------------------- */
/**
* Prepare Character type specific data
@ -758,7 +766,6 @@ export class RdDActor extends Actor {
itemsList.push( {id: itemId, conteneurId: undefined }); // Init list
sourceActor.buildSubConteneurObjetList( itemId, itemsList ); // Get itemId list
let conteneurMap = {};
for (let item of itemsList) {
let copyItem = sourceActor.data.items.find( subItem => subItem._id == item.id );
@ -784,14 +791,20 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
detectSurEncombrement( ) {
let diffEnc = Number(this.encTotal) - Number(this.data.data.attributs.encombrement.value);
let maxEnc = 0;
if ( this.data.type == 'vehicule')
maxEnc = this.data.data.capacite_encombrement;
else
maxEnc = this.data.data.attributs.encombrement.value;
let diffEnc = Number(this.encTotal) - Number(maxEnc);
return Math.max(0, Math.ceil(diffEnc));
}
/* -------------------------------------------- */
async computeEncombrementTotalEtMalusArmure() {
let encTotal = 0;
let malusArmureData = (this.data.data.attributs.malusarmure) ? duplicate(this.data.data.attributs.malusarmure) : {};
let malusArmureData = (this.data.data.attributs && 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
@ -811,10 +824,10 @@ export class RdDActor extends Actor {
}
// Mise à jour valeur totale et états
this.encTotal = encTotal;
//console.log("Enco total : ", this.encTotal);
console.log("Enco total : ", this.encTotal);
this.detectSurEncombrement();
// Mise à jour éventuelle du malus armure
if (this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) {
if (this.data.data.attributs && this.data.data.attributs.malusarmure && newMalusArmure != malusArmureData.value) {
malusArmureData.value = newMalusArmure;
await this.update({ "data.attributs.malusarmure": malusArmureData });
}
@ -875,7 +888,7 @@ export class RdDActor extends Actor {
data.compteurs.surenc.value = - this.detectSurEncombrement();
}
}
/* -------------------------------------------- */
async ajouterRefoulement(value = 1) {
let ret = "none";

View File

@ -12,7 +12,7 @@ import { RdDActor } from "./actor.js";
import { RdDItemSheet } from "./item-sheet.js";
import { RdDActorSheet } from "./actor-sheet.js";
import { RdDActorCreatureSheet } from "./actor-creature-sheet.js";
//import { RdDActorHumanoideSheet } from "./actor-humanoide-sheet.js";
import { RdDActorVehiculeSheet } from "./actor-vehicule-sheet.js";
import { RdDActorEntiteSheet } from "./actor-entite-sheet.js";
import { RdDUtility } from "./rdd-utility.js";
import { TMRUtility } from "./tmr-utility.js";
@ -207,10 +207,10 @@ Hooks.once("init", async function() {
types: ["creature"],
makeDefault: true
});
/*Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorHumanoideSheet, {
types: ["humanoide"],
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorVehiculeSheet, {
types: ["vehicule"],
makeDefault: true
});*/
});
Actors.registerSheet("foundryvtt-reve-de-dragon", RdDActorEntiteSheet, {
types: ["entite"],
makeDefault: true

View File

@ -128,8 +128,8 @@ export class RdDUtility {
//Character Sheets
'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/actor-creature-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/actor-humanoide-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/actor-vehicule-sheet.html',
//Items
'systems/foundryvtt-reve-de-dragon/templates/item-competence-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/item-competencecreature-sheet.html',
@ -157,6 +157,7 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-competence.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-ingredient.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-parade.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-vehicule.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-competence.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-rarete.html',
'systems/foundryvtt-reve-de-dragon/templates/sort-draconic.html',
@ -234,7 +235,9 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static getAfficheContenu(conteneurId) {
return this.afficheContenu[conteneurId];
if ( conteneurId )
return this.afficheContenu[conteneurId];
return undefined;
}
/* -------------------------------------------- */
@ -320,7 +323,7 @@ export class RdDUtility {
//console.log("OBJ:", objet);
let str = Handlebars.partials['systems/foundryvtt-reve-de-dragon/templates/actor-inventaire-conteneur.html']({ item: objet });
if (objet.type == 'conteneur') {
//console.log("ITEM DISPLAYED", this.getAfficheContenu(objet._id) );
console.log("ITEM DISPLAYED", objet );
if (this.getAfficheContenu(objet._id)) {
str = str + "<ul class='item-list alterne-list item-display-show list-item-margin" + niveau + "'>";
} else {

View File

@ -2,10 +2,10 @@
"name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon",
"description": "Rêve de Dragon RPG for FoundryVTT",
"version": "1.2.10",
"version": "1.2.12",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.8",
"templateVersion": 80,
"templateVersion": 81,
"author": "LeRatierBretonnien",
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
"styles": ["styles/simple.css"],

View File

@ -1,6 +1,6 @@
{
"Actor": {
"types": ["personnage", "creature", "entite"],
"types": ["personnage", "creature", "entite", "vehicule"],
"templates": {
"description": {
"description": "Description ...",
@ -19,6 +19,16 @@
"beaute": 10,
"main": "droitier"
},
"vehicule": {
"categorie": "",
"resistance": 0,
"structure": 0,
"vitesse": "",
"bonus": "",
"manoeuvrabilite": "",
"equipage": 0,
"capacite_encombrement": 0
},
"entite": {
"carac": {
"taille": {
@ -528,7 +538,7 @@
"enc": 0
}
}
}
}
},
"personnage": {
"templates": [ "background", "common"]
@ -538,6 +548,9 @@
},
"entite": {
"templates": [ "entite", "description" ]
},
"vehicule": {
"templates": [ "vehicule", "description" ]
}
},
"Item": {

View File

@ -0,0 +1,119 @@
<form class="{{cssClass}}" autocomplete="off">
{{!-- Sheet Header --}}
<header class="sheet-header">
<img class="profile-img" src="{{actor.img}}" data-edit="img" title="{{actor.name}}" />
<div class="header-fields">
<div class="flexrow">
<h1 class="charname"><input name="name" type="text" value="{{actor.name}}" placeholder="Name" /></h1>
</div>
</div>
</header>
{{!-- Sheet Tab Navigation --}}
<nav class="sheet-tabs tabs" data-group="primary">
<a class="item" data-tab="carac">Caractéristiques</a>
<a class="item" data-tab="items">Contenu</a>
<a class="item" data-tab="description">Description</a>
</nav>
{{!-- Sheet Body --}}
<section class="sheet-body">
{{!-- Carac Tab --}}
<div class="tab items" data-group="primary" data-tab="carac">
<div class="grid grid-2col">
<div class="flex-group-left flexcol">
<ol class="carac-list alterne-list">
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Catégorie</span>
<select name="data.categorie" id="categorie" data-dtype="String">
{{#select data.categorie}}
{{>"systems/foundryvtt-reve-de-dragon/templates/enum-categorie-vehicule.html"}}
{{/select}}
</select>
</li>
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Résistance</span>
<input class="competence-value flexrow" type="text" name="data.resistance" value="{{data.resistance}}" data-dtype="Number" />
</li>
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Structure</span>
<input class="competence-value flexrow" type="text" name="data.structure" value="{{data.structure}}" data-dtype="Number" />
</li>
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Vitesse</span>
<input class="competence-value flexrow" type="text" name="data.vitesse" value="{{data.vitesse}}" data-dtype="String" />
</li>
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Bonus</span>
<input class="competence-value flexrow" type="text" name="data.bonus" value="{{data.bonus}}" data-dtype="String" />
</li>
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Manoeuvrabilité</span>
<input class="competence-value flexrow" type="text" name="data.manoeuvrabilite" value="{{data.manoeuvrabilite}}" data-dtype="String" />
</li>
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Equipage</span>
<input class="competence-value flexrow" type="text" name="data.equipage" value="{{data.equipage}}" data-dtype="Number" />
</li>
<li class="competence flexrow list-item" data-attribute="{{key}}">
<span class="carac-label flexrow" name="categorie">Capacité d'Encombrement</span>
<input class="competence-value flexrow" type="text" name="data.capacite_encombrement" value="{{data.capacite_encombrement}}" data-dtype="Number" />
</li>
</ol>
</div>
</div>
</div>
{{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items">
<span class="item-name">Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.capacite_encombrement}} <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}}"/>
<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>
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/if}}
{{/unless}}
{{/each}}
{{#each data.conteneurs as |conteneur id|}}
{{buildConteneur this}}
{{/each}}
</ul>
</div>
{{!-- Biography Tab --}}
<div class="tab description" data-group="primary" data-tab="description">
<div class="form-group editor">
{{editor content=data.description target="data.description" button=true owner=owner editable=editable}}
</div>
{{>"systems/foundryvtt-reve-de-dragon/templates/editor-notes-mj.html"}}
</div>
</div>
</section>
</form>

View File

@ -0,0 +1,7 @@
<option value="Bateau">Bateau</option>
<option value="Barque"> Barque</option>
<option value="Chariot">Charette/Chariot</option>
<option value="Carosse">Carosse</option>
<option value="Cariole à Bras">Cariole à bras</option>
<option value="Autre">Maison</option>
<option value="Autre">Autre</option>