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
11 changed files with 77 additions and 313 deletions
Showing only changes of commit d4ddc4e940 - Show all commits

View File

@ -28,7 +28,7 @@
"TypeArmure": "Armure",
"TypeConteneur": "Conteneur",
"TypeNourritureboisson": "Nourriture & boisson",
"TypeService": "Services/Boutique",
"TypeService": "Service",
"TypeChant": "Chant",
"TypeDanse": "Danse",
"TypeMusique": "Musique",

View File

@ -77,7 +77,6 @@ export class RdDBaseActorSheet extends ActorSheet {
/* -------------------------------------------- */
filterItemsPerTypeForSheet(formData, itemTypes) {
formData.services = Misc.arrayOrEmpty(itemTypes['service']);
formData.recettescuisine = Misc.arrayOrEmpty(itemTypes['recettecuisine']);
formData.recettesAlchimiques = Misc.arrayOrEmpty(itemTypes['recettealchimique']);
formData.maladies = Misc.arrayOrEmpty(itemTypes['maladie']);
@ -103,9 +102,8 @@ export class RdDBaseActorSheet extends ActorSheet {
formData.oeuvres = Misc.arrayOrEmpty(itemTypes['oeuvre']);
formData.jeux = Misc.arrayOrEmpty(itemTypes['jeu']);
formData.services = Misc.arrayOrEmpty(itemTypes['service']);
formData.conteneurs = Misc.arrayOrEmpty(itemTypes['conteneur']);
formData.materiel = Misc.arrayOrEmpty(itemTypes['objet']);
formData.armes = Misc.arrayOrEmpty(itemTypes['arme']);
formData.armures = Misc.arrayOrEmpty(itemTypes['armure']);
@ -117,22 +115,12 @@ export class RdDBaseActorSheet extends ActorSheet {
formData.herbes = Misc.arrayOrEmpty(itemTypes['herbe']);
formData.nourritureboissons = Misc.arrayOrEmpty(itemTypes['nourritureboisson']);
formData.gemmes = Misc.arrayOrEmpty(itemTypes['gemme']);
formData.monnaie = Misc.arrayOrEmpty(itemTypes['monnaie']).sort(Monnaie.triValeurEntiere());
formData.objets = formData.conteneurs
.concat(formData.materiel)
.concat(formData.armes)
.concat(formData.armures)
.concat(formData.munitions)
.concat(formData.livres)
.concat(formData.potions)
.concat(formData.ingredients)
.concat(formData.herbes)
.concat(formData.faunes)
.concat(formData.monnaie)
.concat(formData.nourritureboissons)
.concat(formData.gemmes);
formData.objets = RdDItem.getItemTypesInventaire('all')
.map(t => Misc.arrayOrEmpty(itemTypes[t]))
.reduce((a, b) => a.concat(b), [])
.sort(Misc.ascending(it => it.name));
}
/* -------------------------------------------- */ /** @override */
@ -205,7 +193,7 @@ export class RdDBaseActorSheet extends ActorSheet {
/* -------------------------------------------- */
async selectObjetTypeToCreate() {
let typeObjets = RdDItem.getItemTypesInventaire();
let typeObjets = this.getTypesInventaire().sort(Misc.ascending(type => Misc.typeName('Item', type)));
let content = `<span class="competence-label">Selectionnez le type d'équipement</span><select class="item-type">`;
for (let typeName of typeObjets) {
content += `<option value="${typeName}">${Misc.typeName('Item', typeName)}</option>`
@ -225,6 +213,10 @@ export class RdDBaseActorSheet extends ActorSheet {
d.render(true);
}
getTypesInventaire() {
return RdDItem.getItemTypesInventaire();
}
/** @override */
setPosition(options = {}) {
const position = super.setPosition(options);

View File

@ -255,7 +255,7 @@ export class RdDBaseActor extends Actor {
await this.decrementerVente(vendeur, itemVendu, quantite, cout);
if (acheteur) {
await acheteur.depenserSols(cout);
let createdItemId = await acheteur.creerQuantiteItem(vente.item, quantite);
const createdItemId = await acheteur.creerQuantiteItem(vente.item, quantite);
await acheteur.consommerNourritureAchetee(achat, vente, createdItemId);
}
if (cout > 0) {
@ -309,13 +309,13 @@ export class RdDBaseActor extends Actor {
}
async decrementerQuantiteItem(item, quantite, options={supprimerSiZero: true}) {
async decrementerQuantiteItem(item, quantite, options = { supprimerSiZero: true }) {
let resteQuantite = (item.system.quantite ?? 1) - quantite;
if (resteQuantite <= 0) {
if (options.supprimerSiZero) {
await this.deleteEmbeddedDocuments("Item", [item.id]);
}
else{
else {
await this.updateEmbeddedDocuments("Item", [{ _id: item.id, 'system.quantite': 0 }]);
}
if (resteQuantite < 0) {
@ -328,16 +328,18 @@ export class RdDBaseActor extends Actor {
}
async creerQuantiteItem(item, quantite) {
const isItemEmpilable = "quantite" in item.system;
const baseItem = {
type: item.type,
img: item.img,
name: item.name,
system: mergeObject(item.system, { quantite: isItemEmpilable ? quantite : undefined })
};
const newItems = isItemEmpilable ? [baseItem] : Array.from({ length: quantite }, (_, i) => baseItem);
const items = await this.createEmbeddedDocuments("Item", newItems);
return items.length > 0 ? items[0].id : undefined;
if (this.canReceive(item)) {
const isItemEmpilable = "quantite" in item.system;
const baseItem = {
type: item.type,
img: item.img,
name: item.name,
system: mergeObject(item.system, { quantite: isItemEmpilable ? quantite : undefined })
};
const newItems = isItemEmpilable ? [baseItem] : Array.from({ length: quantite }, (_, i) => baseItem);
const items = await this.createEmbeddedDocuments("Item", newItems);
return items.length > 0 ? items[0].id : undefined;
}
}
/* -------------------------------------------- */
@ -373,7 +375,7 @@ export class RdDBaseActor extends Actor {
}
let result = true;
const item = this.getItem(itemId);
if (item?.isInventaire() && sourceActorId == targetActorId) {
if (item?.isInventaire('all') && sourceActorId == targetActorId) {
// rangement
if (srcId != destId && itemId != destId) { // déplacement de l'objet
const src = this.getItem(srcId);

View File

@ -43,6 +43,11 @@ export class RdDCommerceSheet extends RdDBaseActorSheet {
})
}
getTypesInventaire() {
return RdDItem.getItemTypesInventaire('all');
}
async vente(item) {
const acheteur = RdDUtility.getSelectedActor();
if (!acheteur) {

View File

@ -14,7 +14,7 @@ export class RdDCommerce extends RdDBaseActor {
}
canReceive(item) {
if (item.isInventaire()) {
if (item.isInventaire('all')) {
return true;
}
return super.canReceive(item);

View File

@ -1,10 +1,4 @@
import { RdDItemSheet } from "./item-sheet.js";
import { Misc } from "./misc.js";
import { RdDUtility } from "./rdd-utility.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
import { DialogItemAchat } from "./dialog-item-achat.js";
import { RdDItem } from "./item.js";
import { RdDItemService } from "./item-service.js";
export class RdDServiceItemSheet extends RdDItemSheet {
@ -18,64 +12,5 @@ export class RdDServiceItemSheet extends RdDItemSheet {
activateListeners(html) {
super.activateListeners(html);
this.html.find('a.rdd-world-content-link').click(async event => {
const itemRef = this.getItemRef(event);
game.items.get(itemRef.id)?.sheet.render(true)
});
this.html.find('a.sub-item-acheter').click(async event => {
const subItem = this.item.findRefItem(this.getItemRef(event));
await this.item.acheter(RdDUtility.getSelectedActor(), subItem);
});
if (!this.options.editable) return;
this.html.find('a.sub-item-vendre').click(async event => {
const subItem = this.item.findRefItem(this.getItemRef(event));
await this.item.vendre(subItem);
});
this.html.find('a.sub-item-delete').click(async event => {
await this.item.removeRefItem(this.getItemRef(event));
});
this.html.find('a.sub-item-quantite-moins').click(async event => await this.item.increaseRefItemQuantite(this.getItemRef(event), -1))
this.html.find('a.sub-item-quantite-plus').click(async event => await this.item.increaseRefItemQuantite(this.getItemRef(event), 1))
this.html.find('input.sub-item-quantite').change(async event => {
const newQuantite = Math.max(0, Number.parseInt(this.html.find(event.currentTarget).val()));
await this.item.updateRefItem(this.getItemRef(event), it => it.system.quantite = newQuantite);
})
this.html.find('input.sub-item-cout').change(async event => {
const newCout = Math.max(0, Number(this.html.find(event.currentTarget).val()));
await this.item.updateRefItem(this.getItemRef(event), it => it.system.cout = newCout);
})
this.html.find('a.sub-item-info-add').click(__ =>
ui.notifications.info(`Utiliser le glisser-déposer pour ajouter des objets depuis un compendium ou les objets du monde`)
);
}
async _onDropItem(event, dragData) {
let linkedItem = fromUuidSync(dragData.uuid);
const existing = this.item.system.items.find(it => it.pack == linkedItem.pack && it.id == linkedItem.id && it.type == linkedItem.type);
if (existing) {
ui.notifications.warn(`${this.item.name} contient déjà un ${existing.name}`);
return;
}
if (linkedItem.pack) {
linkedItem = await SystemCompendiums.loadDocument(linkedItem);
}
if (linkedItem.isInventaire()) {
await this.item.addRefItem(RdDItemService.createSubItem(linkedItem));
}
else {
ui.notifications.warn(`${this.item.name} ne peut pas proposer à la vente de ${Misc.typeName('Item', linkedItem.type)}: ${linkedItem.name}`);
}
}
getItemRef(event) {
const itemRow = this.html.find(event.currentTarget)?.parents('.item.service-item');
return { id: itemRow?.data("item-id"), pack: itemRow?.data("pack") ?? undefined }
}
}

View File

@ -1,141 +1,17 @@
import { DialogItemAchat } from "./dialog-item-achat.js";
import { RdDItem } from "./item.js";
import { Misc } from "./misc.js";
export class RdDItemService extends RdDItem {
static get defaultIcon() {
return "systems/foundryvtt-reve-de-dragon/icons/items/services.webp";
}
/** @override*/
getUserLevel(user) {
const level = super.getUserLevel(user);
if (level == CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE) {
// si quelqu'un a accès au lien d'un service, il peut le voir
return CONST.DOCUMENT_OWNERSHIP_LEVELS.LIMITED;
}
return level;
return "systems/foundryvtt-reve-de-dragon/icons/services/lit.webp";
}
isService() { return true; }
getChatItemTemplate() { return 'systems/foundryvtt-reve-de-dragon/templates/post-item-service.html'; }
getProprietes() { return []; }
getServiceItem(itemRef) {
if (itemRef && this.isService()) {
return this.system.items.find(it => it.id == itemRef.id && it.pack == itemRef.pack);
}
return undefined;
getProprietes() {
return [
RdDItem.propertyIfDefined('Qualité', this.system.qualite, this.system.qualite != 0),
RdDItem.propertyIfDefined('Moral', 'Situation heureuse', this.system.moral),
RdDItem.propertyIfDefined('Coût', `${this.system.cout} sols`),
];
}
getQuantiteDisponible(itemRef, max) {
if (this.system.illimite) {
return max;
}
const subItem = this.getServiceItem(itemRef);
return subItem?.system.quantite ?? 0;
}
async venteRefItem(ref, quantite, cout) {
if (this.actor) {
await this.actor.ajouterSols(cout);
}
await this.increaseRefItemQuantite(ref, -quantite);
}
async vendre(subItem) {
const item = await RdDItem.getCorrespondingItem(subItem);
const quantiteMax = this.system.illimite ? undefined : subItem.system.quantite;
await item.proposerVente(quantiteMax);
}
async acheter(acheteur, subItem) {
if (!acheteur) {
ui.notifications.warn(`Pas d'acheteur sélectionné`);
return;
}
const nbLots = this.system.illimite ? 1 : subItem.system.quantite;
if (nbLots <= 0) {
ui.notifications.warn(`${this.name} n'a plus de ${subItem.name} en vente`);
return;
}
await DialogItemAchat.onAcheter({
item: await RdDItem.getCorrespondingItem(subItem),
acheteur,
serviceSubItem: subItem,
service: this,
quantiteIllimite: this.system.illimite,
nbLots,
tailleLot: 1,
prixLot: subItem.system.cout
});
}
static createSubItem(linkedItem) {
return {
id: linkedItem.id,
pack: linkedItem.pack,
name: linkedItem.name,
img: linkedItem.img,
system: {
quantite: 1,
cout: linkedItem.system.cout ?? 0
}
};
}
static matchRefItem({ id, pack }) {
return it => it.id == id && (pack ? (it.pack == pack) : (!it.pack));
}
findRefItem(ref) {
return this.system.items.find(RdDItemService.matchRefItem(ref));
}
async increaseRefItemQuantite(ref, quantite) {
await this.updateRefItem(ref,
it => it.system.quantite = Math.max(0, it.system.quantite + quantite)
);
}
async updateRefItem(ref, update = it => { }) {
await this.updateRefItems(RdDItemService.matchRefItem(ref), update);
}
async addRefItem(newItem) {
if (!newItem.id) {
ui.notifications.warn(`${newItem?.name ?? '??'} n'a pas d'identifiant`);
return;
}
if (this.system.items.find(RdDItemService.matchRefItem(newItem))) {
ui.notifications.warn(`${newItem?.name ?? newItem.id} est déjà présent ici`);
return;
}
await this.setRefItems([...this.system.items, newItem]);
}
async removeRefItem(ref) {
await this.removeRefItems(RdDItemService.matchRefItem(ref));
}
async removeRefItems(matcher = it => false) {
await this.setRefItems(this.system.items.filter(it => !matcher(it)));
}
async updateRefItems(matcher = it => false, update = it => { }) {
const updatedList = this.system.items.map(it => {
if (matcher(it)) {
update(it);
}
return it;
});
await this.setRefItems(updatedList);
}
async setRefItems(newItems) {
await this.update({ 'system.items': newItems.sort(Misc.ascending(it => it.type + ':' + it.name)) });
}
}

View File

@ -5,14 +5,14 @@ import { RdDHerbes } from "./rdd-herbes.js";
import { RdDUtility } from "./rdd-utility.js";
import { SystemCompendiums } from "./settings/system-compendiums.js";
const typesObjetsInventaire = [
const typesInventaireMateriel = [
"arme",
"armure",
"conteneur",
"faune",
"gemme",
"herbe",
"ingredient",
"faune",
"livre",
"monnaie",
"munition",
@ -20,6 +20,11 @@ const typesObjetsInventaire = [
"objet",
"potion",
]
const typesInventaire = {
materiel: typesInventaireMateriel,
all: ['service'].concat(typesInventaireMateriel),
}
const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"]
const typesObjetsDraconiques = ["queue", "ombre", "souffle", "tete", "signedraconique", "sortreserve", "rencontre"]
const typesObjetsConnaissance = ["meditation", "recettealchimique", "sort"]
@ -97,8 +102,8 @@ export class RdDItem extends Item {
return game.items.get(itemRef.id ?? itemRef._id);
}
static getItemTypesInventaire() {
return typesObjetsInventaire
static getItemTypesInventaire(mode = 'materiel') {
return typesInventaire[mode ?? 'materiel']
}
static getTypesOeuvres() {
@ -150,8 +155,8 @@ export class RdDItem extends Item {
isCompetence() {
return typesObjetsCompetence.includes(this.type)
}
isInventaire() {
return typesObjetsInventaire.includes(this.type);
isInventaire(mode = 'materiel') {
return RdDItem.getItemTypesInventaire(mode).includes(this.type);
}
isOeuvre() {
return typesObjetsOeuvres.includes(this.type)
@ -463,7 +468,7 @@ export class RdDItem extends Item {
img: this.img,
pack: this.pack,
name: this.name,
actor : this.actor ? { id: this.actor.id } : undefined,
actor: this.actor ? { id: this.actor.id } : undefined,
system: { description: this.system.description },
properties: this.getProprietes(),
}
@ -474,9 +479,6 @@ export class RdDItem extends Item {
}
getChatItemTemplate() {
switch (this.type) {
case 'service': return 'systems/foundryvtt-reve-de-dragon/templates/post-item-service.html';
}
return 'systems/foundryvtt-reve-de-dragon/templates/post-item.html';
}

View File

@ -583,7 +583,7 @@
"encombrement": 0,
"quantite": 1,
"qualite": 0,
"cout": 0
"cout": 0.0
},
"environnement": {
"milieu": "",
@ -747,10 +747,8 @@
"prdate": 0
},
"service": {
"templates": [ "description"],
"illimite": false,
"items": [],
"services": []
"templates": [ "description", "inventaire" ],
"moral": false
},
"musique": {
"templates": [ "description" ],

View File

@ -14,14 +14,14 @@
</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 (or (eq item.type 'service') (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}}

View File

@ -2,69 +2,23 @@
{{>"systems/foundryvtt-reve-de-dragon/templates/header-item.html"}}
<section class="sheet-body">
<div class="flexcol form-group small-editor">
{{editor description target="system.description" button=true owner=owner editable=(or isGM isOwner) engine="prosemirror"}}
</div>
<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é en vente illimitée</span>
<span for="system.moral">Jet de moral en situation heureuse</span>
<input {{@root.disabled}} class="attribute-value" type="checkbox" name="system.moral" {{#if system.moral}}checked{{/if}}/>
</div>
<div class="flexcol">
<ul class="item-list alterne-list">
<li class="item flexrow list-item">
<label class="flex-grow">A vendre</label>
{{#unless system.illimite}}
<label>Quantite</label>
{{/unless}}
<label>Prix (sols)</label>
<div class="item-controls">
{{#unless disabled}}
<a class="sub-item-info-add" title="Utiliser le drag&amp;drop pour ajouter un objet dans la liste">
<i class="fa-solid fa-circle-info"></i>
</a>
{{/unless}}
</div>
</li>
{{#each system.items as |item key|}}
<li class="item flexrow list-item service-item" data-item-id="{{item.id}}" data-pack="{{item.pack}}" data-key="{{key}}">
<label class="flex-grow">
{{#if item.img}}<img class="sheet-competence-img" src="{{item.img}}" title="{{item.name}}"/>{{/if}}
{{> 'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs'
pack=item.pack id=item.id name=item.name}}
</label>
{{#unless @root.system.illimite}}
<span class="flexrow">
{{#unless @root.disabled}}
<a class="sub-item-quantite-moins"><i class="fas fa-minus-square"></i></a>
{{/unless}}
<input {{@root.disabled}} type="number" class="sub-item-quantite" name="items[{{key}}].system.quantite" value="{{item.system.quantite}}" data-dtype="Number" />
{{#unless @root.disabled}}
<a class="sub-item-quantite-plus"><i class="fas fa-plus-square"></i></a>
{{/unless}}
</span>
{{/unless}}
<span class="flexrow">
<input {{@root.disabled}} type="number" class="input-prix number-x3 sub-item-cout" name="items[{{key}}].system.cout" value="{{numberFormat item.system.cout decimals=2 sign=false}}" data-dtype="Number" />
</span>
<div class="item-controls">
<a class="sub-item-acheter" title="Acheter"><i class="fa-regular fa-coins"></i></a>
{{#unless @root.disabled}}
<a class="sub-item-vendre" title="Vendre"><i class="fas fa-comments-dollar"></i></a>
<a class="sub-item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
{{/unless}}
</div>
</li>
{{/each}}
</ul>
<div class="form-group">
<label for="system.qualite">Qualité</label>
<input class="attribute-value number-x3" type="number" name="system.qualite" value="{{system.qualite}}" data-dtype="Number"
{{#unless (isFieldInventaireModifiable type 'qualite')}}disabled{{/unless}}/>
</div>
{{#if isGM}}
<br>
<div class="flexcol">
<span><label>Description (MJ seulement): </label></span>
<div class="form-group medium-editor">
{{editor descriptionmj target="system.descriptionmj" button=true owner=owner editable=true engine="prosemirror"}}
</div>
<div class="form-group item-cout">
<label for="system.cout">Prix (sols)</label>
<input class="input-prix attribute-value number-x3" type="number" name="system.cout" value="{{numberFormat system.cout decimals=2 sign=false}}" data-dtype="Number"
{{#unless (isFieldInventaireModifiable type 'cout')}}disabled{{/unless}}/>
</div>
{{/if}}
{{>"systems/foundryvtt-reve-de-dragon/templates/partial-item-description.html"}}
</section>
</form>