Les auberges sont des commerces #600

Merged
uberwald merged 18 commits from VincentVk/foundryvtt-reve-de-dragon:v10 into v10 2023-01-03 10:43:26 +01:00
17 changed files with 296 additions and 46 deletions
Showing only changes of commit ee42bdcf83 - Show all commits

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

BIN
icons/services/lit.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -3,6 +3,7 @@
"TypePersonnage": "Personnage", "TypePersonnage": "Personnage",
"TypeCreature": "Créature", "TypeCreature": "Créature",
"TypeEntite": "Entité de cauchemar", "TypeEntite": "Entité de cauchemar",
"TypeCommerce": "Commerce",
"TypeVehicule": "Véhicule" "TypeVehicule": "Véhicule"
}, },
"ITEM": { "ITEM": {

View File

@ -0,0 +1,68 @@
import { DialogItemAchat } from "../dialog-item-achat.js";
import { RdDItem } from "../item.js";
import { RdDSheetUtility } from "../rdd-sheet-utility.js";
import { RdDUtility } from "../rdd-utility.js";
import { RdDBaseActorSheet } from "./base-actor-sheet.js";
/**
* Extend the basic ActorSheet with some very simple modifications
* @extends {ActorSheet}
*/
export class RdDCommerceSheet extends RdDBaseActorSheet {
/** @override */
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["rdd", "sheet", "actor"],
template: "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-actor-sheet.html",
width: 600,
height: 720,
tabs: [],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: undefined }]
});
}
/* -------------------------------------------- */
/** @override */
activateListeners(html) {
super.activateListeners(html);
this.html.find('a.item-acheter').click(async event => await this.vente(this.getItem(event)));
if (!this.options.editable) return;
this.html.find('a.item-quantite-moins').click(async event => await this.getItem(event)?.quantiteIncDec(-1, { supprimerSiZero: false}));
this.html.find('a.item-quantite-plus').click(async event => await this.getItem(event)?.quantiteIncDec(1));
this.html.find('input.item-quantite').change(async event => {
const newQuantite = Math.max(0, Number.parseInt(this.html.find(event.currentTarget).val()));
await this.getItem(event)?.update({ "system.quantite": newQuantite });
})
this.html.find('input.item-cout').change(async event => {
const newCout = Math.max(0, Number(this.html.find(event.currentTarget).val()));
await this.getItem(event)?.update({ "system.cout": newCout });
})
}
async vente(item) {
const acheteur = RdDUtility.getSelectedActor();
if (!acheteur) {
ui.notifications.warn(`Pas d'acheteur sélectionné`);
return;
}
const disponible = this.actor.getQuantiteDisponible(item)
if (disponible == 0) {
ui.notifications.warn(`${this.name} n'a plus de ${item.name} en vente`);
return;
}
await DialogItemAchat.onAcheter({
item,
vendeur: this.actor,
acheteur,
quantiteIllimite: disponible == undefined,
nbLots: disponible ?? 1,
tailleLot: 1,
prixLot: item.system.cout
});
}
}

48
module/actor/commerce.js Normal file
View File

@ -0,0 +1,48 @@
import { RdDBaseActor } from "./base-actor.js";
export class RdDCommerce extends RdDBaseActor {
static get defaultIcon() {
return "systems/foundryvtt-reve-de-dragon/icons/services/commerce.webp";
}
prepareData() {
super.prepareData();
}
prepareDerivedData() {
super.prepareDerivedData();
}
canReceive(item) {
if (item.isInventaire()) {
return true;
}
return super.canReceive(item);
}
getQuantiteDisponible(item) {
return this.system.illimite ? undefined : item.getQuantite();
}
verifierFortune(cout) {
return this.system.illimite || super.verifierFortune(cout);
}
async depenserSols(cout) {
if (this.system.illimite) {
return
}
await super.depenserSols(cout)
}
async consommerNourritureAchetee(achat, vente, createdItemId) {
// ne pas consommer pour un commerce
}
async decrementerQuantiteItem(itemVendu, quantite) {
if (this.system.illimite) {
return;
}
await super.decrementerQuantiteItem(itemVendu, quantite, {supprimerSiZero: false});
}
}

View File

@ -58,7 +58,7 @@ export const defaultItemImg = {
poison: "systems/foundryvtt-reve-de-dragon/icons/maladies_venins/venin.webp", poison: "systems/foundryvtt-reve-de-dragon/icons/maladies_venins/venin.webp",
oeuvre: "systems/foundryvtt-reve-de-dragon/icons/competence_comedie.webp", oeuvre: "systems/foundryvtt-reve-de-dragon/icons/competence_comedie.webp",
nourritureboisson: "systems/foundryvtt-reve-de-dragon/icons/objets/provision_crue.webp", nourritureboisson: "systems/foundryvtt-reve-de-dragon/icons/objets/provision_crue.webp",
service: "systems/foundryvtt-reve-de-dragon/icons/items/services.webp", service: "systems/foundryvtt-reve-de-dragon/icons/services/lit.webp",
signedraconique: "systems/foundryvtt-reve-de-dragon/icons/tmr/signe_draconique.webp", signedraconique: "systems/foundryvtt-reve-de-dragon/icons/tmr/signe_draconique.webp",
gemme: "systems/foundryvtt-reve-de-dragon/icons/gemmes/almaze.webp", gemme: "systems/foundryvtt-reve-de-dragon/icons/gemmes/almaze.webp",
possession: "systems/foundryvtt-reve-de-dragon/icons/entites/possession2.webp", possession: "systems/foundryvtt-reve-de-dragon/icons/entites/possession2.webp",

View File

@ -37,6 +37,8 @@ import { RdDConteneurItemSheet } from "./item-conteneur-sheet.js";
import { RdDServiceItemSheet } from "./item-service-sheet.js"; import { RdDServiceItemSheet } from "./item-service-sheet.js";
import { RdDItemService } from "./item-service.js"; import { RdDItemService } from "./item-service.js";
import { RdDBaseActor } from "./actor/base-actor.js"; import { RdDBaseActor } from "./actor/base-actor.js";
import { RdDCommerceSheet } from "./actor/commerce-sheet.js";
import { RdDCommerce } from "./actor/commerce.js";
/** /**
* RdD system * RdD system
@ -62,6 +64,7 @@ export class SystemReveDeDragon {
entite: RdDActor, entite: RdDActor,
personnage: RdDActor, personnage: RdDActor,
vehicule: RdDActor, vehicule: RdDActor,
commerce: RdDCommerce,
} }
} }
@ -113,6 +116,7 @@ export class SystemReveDeDragon {
/* -------------------------------------------- */ /* -------------------------------------------- */
// Register sheet application classes // Register sheet application classes
Actors.unregisterSheet("core", ActorSheet); Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet(SYSTEM_RDD, RdDCommerceSheet, { types: ["commerce"], makeDefault: true });
Actors.registerSheet(SYSTEM_RDD, RdDActorSheet, { types: ["personnage"], makeDefault: true }); Actors.registerSheet(SYSTEM_RDD, RdDActorSheet, { types: ["personnage"], makeDefault: true });
Actors.registerSheet(SYSTEM_RDD, RdDActorCreatureSheet, { types: ["creature"], makeDefault: true }); Actors.registerSheet(SYSTEM_RDD, RdDActorCreatureSheet, { types: ["creature"], makeDefault: true });
Actors.registerSheet(SYSTEM_RDD, RdDActorVehiculeSheet, { types: ["vehicule"], makeDefault: true }); Actors.registerSheet(SYSTEM_RDD, RdDActorVehiculeSheet, { types: ["vehicule"], makeDefault: true });

View File

@ -170,6 +170,8 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/actor/liens-animaux.html', 'systems/foundryvtt-reve-de-dragon/templates/actor/liens-animaux.html',
'systems/foundryvtt-reve-de-dragon/templates/actor/liens-suivants.html', 'systems/foundryvtt-reve-de-dragon/templates/actor/liens-suivants.html',
'systems/foundryvtt-reve-de-dragon/templates/actor/liens-vehicules.html', 'systems/foundryvtt-reve-de-dragon/templates/actor/liens-vehicules.html',
'systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire.html',
'systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html',
//Items //Items
'systems/foundryvtt-reve-de-dragon/templates/scripts/autocomplete-script.hbs', 'systems/foundryvtt-reve-de-dragon/templates/scripts/autocomplete-script.hbs',
'systems/foundryvtt-reve-de-dragon/templates/scripts/autocomplete.hbs', 'systems/foundryvtt-reve-de-dragon/templates/scripts/autocomplete.hbs',
@ -296,7 +298,7 @@ export class RdDUtility {
Handlebars.registerHelper('apostrophe', (article, str) => Grammar.apostrophe(article, str)); Handlebars.registerHelper('apostrophe', (article, str) => Grammar.apostrophe(article, str));
Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str)); Handlebars.registerHelper('un', str => Grammar.articleIndetermine(str));
Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args)); Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args));
Handlebars.registerHelper('buildConteneur', (objet, tplItem) => { return new Handlebars.SafeString(RdDUtility.buildConteneur(objet, 1, tplItem)); }); Handlebars.registerHelper('buildConteneur', (objet, templateItem, options) => { return new Handlebars.SafeString(RdDUtility.buildConteneur(objet, 1, templateItem, options)); });
Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); }); Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); });
Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord)); Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord));
Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord));
@ -472,33 +474,34 @@ export class RdDUtility {
/** Construit la structure récursive des conteneurs, avec imbrication potentielle /** Construit la structure récursive des conteneurs, avec imbrication potentielle
* *
*/ */
static buildConteneur(objet, profondeur, tplItem) { static buildConteneur(objet, profondeur, templateItem, options) {
if (!profondeur) profondeur = 1; if (!profondeur) profondeur = 1;
if (!tplItem) tplItem = 'actor/inventaire-item.html' if (!templateItem) templateItem = 'actor/inventaire-item.html'
objet.niveau = profondeur; objet.niveau = profondeur;
const isConteneur = objet.type == 'conteneur'; const isConteneur = objet.type == 'conteneur';
const isOuvert = isConteneur && this.getAfficheContenu(objet._id); const isOuvert = isConteneur && this.getAfficheContenu(objet._id);
const isVide = isConteneur && objet.system.contenu.length == 0; const isVide = isConteneur && objet.system.contenu.length == 0;
const conteneur = Handlebars.partials[`systems/foundryvtt-reve-de-dragon/templates/${tplItem}`]({ const conteneur = Handlebars.partials[`systems/foundryvtt-reve-de-dragon/templates/${templateItem}`]({
item: objet, item: objet,
vide: isVide, vide: isVide,
ouvert: isOuvert ouvert: isOuvert,
options: options
}); });
const contenu = isConteneur ? RdDUtility.buildContenu(objet, profondeur, isOuvert, tplItem) : ''; const contenu = isConteneur ? RdDUtility.buildContenu(objet, profondeur, isOuvert, templateItem, options) : '';
return conteneur + contenu; return conteneur + contenu;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static buildContenu(objet, profondeur, afficherContenu, tplItem) { static buildContenu(objet, profondeur, afficherContenu, templateItem, options) {
if (!profondeur) profondeur = 1; if (!profondeur) profondeur = 1;
if (!tplItem) tplItem = 'actor/inventaire-item.html' if (!templateItem) templateItem = 'actor/inventaire-item.html'
objet.niveau = profondeur; objet.niveau = profondeur;
const display = afficherContenu ? 'item-display-show' : 'item-display-hide'; const display = afficherContenu ? 'item-display-show' : 'item-display-hide';
let strContenu = `<ul class='item-list alterne-list ${display} list-item-margin${Math.min(profondeur,6)}'>`; let strContenu = `<ul class='item-list alterne-list ${display} list-item-margin${Math.min(profondeur,6)}'>`;
for (let subItem of objet.subItems) { for (let subItem of objet.subItems) {
strContenu += this.buildConteneur(subItem, profondeur + 1); strContenu += this.buildConteneur(subItem, profondeur + 1, templateItem, options);
} }
return strContenu + "</ul>"; return strContenu + "</ul>";
} }

View File

@ -1,6 +1,6 @@
{ {
"Actor": { "Actor": {
"types": ["personnage", "creature", "entite", "vehicule"], "types": ["personnage", "creature", "entite", "commerce", "vehicule"],
"templates": { "templates": {
"description": { "description": {
"description": "Description ...", "description": "Description ...",
@ -554,6 +554,10 @@
}, },
"vehicule": { "vehicule": {
"templates": [ "vehicule", "description" ] "templates": [ "vehicule", "description" ]
},
"commerce":{
"templates": [ "description" ],
"illimite": false
} }
}, },
"Item": { "Item": {

View File

@ -0,0 +1,71 @@
<form class="{{cssClass}}" autocomplete="off">
{{!-- Sheet Header --}}
<header class="sheet-header">
<div class="header-fields">
<div class="flexrow">
<img class="profile-img" src="{{img}}" data-edit="img" title="{{name}}" />
<div class="flexcol">
<h1 class="charname"><input name="name" type="text" value="{{name}}" placeholder="Name" /></h1>
{{#if @root.options.isObserver}}
<div class="form-group">
<input {{@root.disabled}} class="attribute-value" type="checkbox" name="system.illimite" {{#if system.illimite}}checked{{/if}}/>
<span for="system.illimite">Quantité illimitée en vente</span>
</div>
{{/if}}
</div>
</div>
</div>
</header>
{{!-- Sheet Body --}}
<section class="sheet-body">
<div class="flexcol form-group medium-editor">
{{editor description target="system.description" button=true owner=options.owner editable=options.isOwner engine="prosemirror"}}
</div>
<hr>
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire.html"}}
{{#unless system.illimite}}
{{#if @root.options.isObserver}}
<hr>
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-monnaie.html"}}
{{/if}}
{{/unless}}
{{!--
<br>
<div class="flexcol">
<ul class="item-list alterne-list">
<li class="item flexrow list-item">
<label class="flex-grow">Service</label>
<label>Moral</label>
<label>Qualité</label>
<label>Prix (sols)</label>
<label>
{{#unless disabled}}
<a class="service-add"><i class="fas fa-plus-circle"></i></a>
{{/unless}}
</label>
</li>
{{#each system.services as |service key|}}
<li class="item flexrow list-item" data-key="{{key}}">
<input {{@root.disabled}} type="text" name="services[{{key}}].name" value="{{service.name}}" data-dtype="String" />
<input {{@root.disabled}} type="checkbox" name="services[{{key}}].system.moral" {{#if service.system.moral}}checked{{/if}} />
<input {{@root.disabled}} type="number" name="services[{{key}}].system.qualite" value="{{service.system.qualite}}" data-dtype="Number" min="-10" max="10"/>
<input {{@root.disabled}} type="number" class="input-prix" name="services[{{key}}].system.cout" value="{{numberFormat service.system.cout decimals=2 sign=false}}" data-dtype="Number" min="0" />
<div class="item-controls">
<a class="service-acheter" title="Acheter"><i class="fa-sharp fa-solid fa-coins"></i></a>
{{#unless @root.disabled}}
<a class="service-vendre" title="Proposer"><i class="fas fa-comments-dollar"></i></a>
<a class="service-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
{{/unless}}
</div>
</li>
{{/each}}
</ul>
</div>
--}}
<br>
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/editor-notes-mj.html"}}
<br>
</section>
</form>

View File

@ -0,0 +1,49 @@
{{#if (ne item.type 'monnaie')}}
<li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true">
<span class="equipement-nom {{#if (eq item.type 'conteneur')}}conteneur-name{{/if}} ">
<a{{#if (ne item.type 'conteneur')}} class="item-edit"{{/if}} >
{{#if (eq item.type 'conteneur')}}
<i class="{{~#if vide}}far fa-square
{{else if ouvert}}far fa-minus-square
{{else}}far fa-plus-square
{{/if~}}"></i>
{{/if}}
<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>
<span>{{item.name}}</span>
</a>
</span>
{{#unless @root.system.illimite}}
<span class="equipement-detail flexrow">
{{#unless (and (eq item.type 'conteneur') (not vide))}}
{{#if @root.options.isOwner}}
<a class="item-quantite-moins"><i class="fas fa-minus-square"></i></a>
{{/if}}
<input {{#unless @root.options.isOwner}}disabled{{/unless}} type="number" class="item-quantite" name="items[{{key}}].system.quantite" value="{{item.system.quantite}}" data-dtype="Number" />
{{#if @root.options.isOwner}}
<a class="item-quantite-plus"><i class="fas fa-plus-square"></i></a>
{{/if}}
{{/unless}}
</span>
{{/unless}}
<span class="equipement-detail">
{{#unless (and (eq item.type 'conteneur') (not vide))}}
<input {{#unless @root.options.isOwner}}disabled{{/unless}} type="number" class="input-prix number-x3 item-cout" name="items[{{key}}].system.cout" value="{{numberFormat item.system.cout decimals=2 sign=false}}" data-dtype="Number" />
{{/unless}}
</span>
<span class="equipement-actions item-controls">
{{#unless (and (eq item.type 'conteneur') (not vide))}}
{{#if @root.options.isOwner}}
<a class="item-edit" title="Editer"><i class="fas fa-edit"></i></a>
<a class="item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
{{#if (or @root.system.illimite (ne item.system.quantite 0))}}
<a class="item-vendre" title="Vendre"><i class="fas fa-comments-dollar"></i></a>
{{/if}}
{{/if}}
<a class="item-montrer" title="Montrer"><i class="fas fa-comment"></i></a>
{{#if (gt item.system.quantite 0)}}
<a class="item-acheter" title="Acheter"><i class="fa-regular fa-coins"></i></a>
{{/if}}
{{/unless}}
</span>
</li>
{{/if}}

View File

@ -0,0 +1,35 @@
<h4>Boutique</h4>
<span class="item-name">
{{#if options.isGM}}
<a class="chat-card-button creer-un-objet">Nouvel objet</a>
<a class="chat-card-button nettoyer-conteneurs">Tout vider</a>
{{/if}}
{{#unless @root.system.illimite}}
{{#if calc.surEncombrementMessage}}<b>{{calc.surEncombrementMessage}}</b> &hyphen;{{/if}}
Encombrement: {{numberFormat calc.encTotal decimals=2}}
{{#if (regle-optionnelle 'afficher-prix-joueurs')}}
&hyphen; Valeur: {{numberFormat calc.prixTotalEquipement decimals=2}} Sols
{{/if}}
{{/unless}}
</span>
<ul class="item-list alterne-list">
<li class="competence-header flexrow">
<span class="equipement-nom">Nom</span>
{{#unless @root.system.illimite}}
<span class="equipement-detail">Quantité</span>
{{/unless}}
<span class="equipement-detail">Prix (sols)</span>
<span class="equipement-actions">Actions</span>
</li>
{{#each objets as |item id|}}
{{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}}
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html" item=item vide=true ouvert=true options=@root.options}}
{{/if}}
{{/unless}}
{{/each}}
{{#each conteneurs as |conteneur id|}}
{{buildConteneur this 'actor/commerce-inventaire-item.html' @root.options}}
{{/each}}
</ul>

View File

@ -20,11 +20,11 @@
{{#each objets as |item id|}} {{#each objets as |item id|}}
{{#unless item.estContenu}} {{#unless item.estContenu}}
{{#if (ne item.type 'conteneur')}} {{#if (ne item.type 'conteneur')}}
{{> "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html" item=item vide=true ouvert=true }} {{> "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html" item=item vide=true ouvert=true options=@root.options}}
{{/if}} {{/if}}
{{/unless}} {{/unless}}
{{/each}} {{/each}}
{{#each conteneurs as |conteneur id|}} {{#each conteneurs as |conteneur id|}}
{{buildConteneur this}} {{buildConteneur this 'actor/inventaire-item.html' @root.options}}
{{/each}} {{/each}}
</ul> </ul>

View File

@ -5,39 +5,6 @@
<div class="flexcol form-group small-editor"> <div class="flexcol form-group small-editor">
{{editor description target="system.description" button=true owner=owner editable=(or isGM isOwner) engine="prosemirror"}} {{editor description target="system.description" button=true owner=owner editable=(or isGM isOwner) engine="prosemirror"}}
</div> </div>
{{!--
<div class="flexcol">
<ul class="item-list alterne-list">
<li class="item flexrow list-item">
<label class="flex-grow">Service</label>
<label>Moral</label>
<label>Qualité</label>
<label>Prix (sols)</label>
<label>
{{#unless disabled}}
<a class="service-add"><i class="fas fa-plus-circle"></i></a>
{{/unless}}
</label>
</li>
{{#each system.services as |service key|}}
<li class="item flexrow list-item" data-key="{{key}}">
<input {{@root.disabled}} type="text" name="services[{{key}}].name" value="{{service.name}}" data-dtype="String" />
<input {{@root.disabled}} type="checkbox" name="services[{{key}}].system.moral" {{#if service.system.moral}}checked{{/if}} />
<input {{@root.disabled}} type="number" name="services[{{key}}].system.qualite" value="{{service.system.qualite}}" data-dtype="Number" min="-10" max="10"/>
<input {{@root.disabled}} type="number" class="input-prix" name="services[{{key}}].system.cout" value="{{numberFormat service.system.cout decimals=2 sign=false}}" data-dtype="Number" min="0" />
<div class="item-controls">
<a class="service-acheter" title="Acheter"><i class="fa-sharp fa-solid fa-coins"></i></a>
{{#unless @root.disabled}}
<a class="service-vendre" title="Proposer"><i class="fas fa-comments-dollar"></i></a>
<a class="service-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
{{/unless}}
</div>
</li>
{{/each}}
</ul>
</div>
<br>
--}}
<div class="form-group"> <div class="form-group">
<input {{@root.disabled}} class="attribute-value" type="checkbox" name="system.illimite" {{#if system.illimite}}checked{{/if}}/> <input {{@root.disabled}} class="attribute-value" type="checkbox" name="system.illimite" {{#if system.illimite}}checked{{/if}}/>
<span for="system.illimite">Quantité en vente illimitée</span> <span for="system.illimite">Quantité en vente illimitée</span>