forked from public/foundryvtt-reve-de-dragon
88 Gestion argent/commerce
This commit is contained in:
@ -98,35 +98,35 @@ export class RdDActor extends Actor {
|
||||
/**
|
||||
* Prepare Character type specific data
|
||||
*/
|
||||
_prepareCharacterData(actorData) {
|
||||
async _prepareCharacterData(actorData) {
|
||||
// Initialize empty items
|
||||
RdDUtility.computeCarac(actorData.data);
|
||||
this.computeEncombrementTotalEtMalusArmure();
|
||||
this.computeEtatGeneral();
|
||||
this.checkMonnaiePresence();
|
||||
await this.checkMonnaiePresence();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas.
|
||||
async checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas.
|
||||
let piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1);
|
||||
if (!piece) {
|
||||
let piece = RdDUtility.createMonnaie("Etain (1 denier)", 1);
|
||||
this.createOwnedItem( piece );
|
||||
let piece = RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp" );
|
||||
const updated = await this.createOwnedItem( piece );
|
||||
}
|
||||
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10);
|
||||
if (!piece) {
|
||||
let piece = RdDUtility.createMonnaie("Bronze (10 deniers)", 10);
|
||||
this.createOwnedItem( piece );
|
||||
let piece = RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp");
|
||||
const updated = await this.createOwnedItem( piece );
|
||||
}
|
||||
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100);
|
||||
if (!piece) {
|
||||
let piece = RdDUtility.createMonnaie("Argent (1 sol)", 100);
|
||||
this.createOwnedItem( piece );
|
||||
let piece = RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp");
|
||||
const updated = await this.createOwnedItem( piece );
|
||||
}
|
||||
piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000);
|
||||
if (!piece) {
|
||||
let piece = RdDUtility.createMonnaie("Or (10 sols)", 1000);
|
||||
this.createOwnedItem( piece );
|
||||
let piece = RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp");
|
||||
const updated = await this.createOwnedItem( piece );
|
||||
}
|
||||
}
|
||||
|
||||
@ -2147,7 +2147,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
payerDenier( sumDenier ) {
|
||||
async payerDenier( sumDenier, dataObj ) {
|
||||
sumDenier = Number(sumDenier);
|
||||
let denierDisponible = 0;
|
||||
let monnaie = this.data.items.filter( item => item.type =='monnaie');
|
||||
@ -2155,16 +2155,27 @@ export class RdDActor extends Actor {
|
||||
denierDisponible += piece.data.valeur_deniers * Number(piece.data.quantite);
|
||||
}
|
||||
console.log("DENIER", game.user.character, sumDenier, denierDisponible);
|
||||
|
||||
let msg = "";
|
||||
if ( denierDisponible >= sumDenier) {
|
||||
denierDisponible -= sumDenier;
|
||||
this.optimizeArgent(denierDisponible);
|
||||
msg = `Vous avez payé <strong>${sumDenier} Deniers</strong>, qui ont été soustraits de votre argent.`;
|
||||
} else {
|
||||
let message = {
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs( this.name ),
|
||||
content : "Vous n'avez pas assez d'argent pour paye cette somme !"
|
||||
};
|
||||
ChatMessage.create( message );
|
||||
msg = "Vous n'avez pas assez d'argent pour paye cette somme !";
|
||||
}
|
||||
|
||||
if ( dataObj ) {
|
||||
dataObj.payload.data.cout = sumDenier / 100; // Mise à jour du prix en sols , avec le prix acheté
|
||||
await this.createOwnedItem( dataObj.payload );
|
||||
msg += `<br>Et l'objet <strong>${dataObj.payload.name}</strong> a été ajouté à votre inventaire.`;
|
||||
}
|
||||
|
||||
let message = {
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs( this.name ),
|
||||
content : msg
|
||||
};
|
||||
ChatMessage.create( message );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
307
module/item-rdd.js
Normal file
307
module/item-rdd.js
Normal file
@ -0,0 +1,307 @@
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDItem extends Item {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async postItem() {
|
||||
console.log(this);
|
||||
const properties = this[`_${this.data.type}ChatData`]();
|
||||
let chatData = duplicate(this.data);
|
||||
chatData["properties"] = properties
|
||||
|
||||
//Check if the posted item should have availability/pay buttons
|
||||
chatData.hasPrice = "cout" in chatData.data;
|
||||
chatData.data.cout_deniers = 0;
|
||||
|
||||
let dialogResult = [-1, -1]; // dialogResult[0] = quantité, dialogResult[1] = prix
|
||||
if (chatData.hasPrice )
|
||||
{
|
||||
let sols = chatData.data.cout;
|
||||
chatData.data.cout_deniers = Math.floor(sols * 100);
|
||||
dialogResult = await new Promise( (resolve, reject) => {new Dialog({
|
||||
content :
|
||||
`<p hidden>Modifier la quantité?</p>
|
||||
<div hidden class="form-group">
|
||||
<label> Quantité</label>
|
||||
<input name="quantity" type="text" placeholder="Ne rien mettre pour quantité infinie"/>
|
||||
</div>
|
||||
<p>Modifier la prix?</p>
|
||||
<div class="form-group">
|
||||
<label> Prix en Sols</label>
|
||||
<input name="price" type="text" value="${chatData.data.cout}"/>
|
||||
</div>
|
||||
`,
|
||||
title : "Quantité",
|
||||
buttons : {
|
||||
post : {
|
||||
label : "Soumettre",
|
||||
callback: (dlg) => {
|
||||
resolve( [ dlg.find('[name="quantity"]').val(), dlg.find('[name="price"]').val() ] )
|
||||
}
|
||||
},
|
||||
}
|
||||
}).render(true)
|
||||
})
|
||||
}
|
||||
|
||||
if (dialogResult[0] > 0)
|
||||
{
|
||||
if (this.isOwned)
|
||||
{
|
||||
if (this.data.data.quantite == 0)
|
||||
dialogResult[0] = -1
|
||||
else if (this.data.data.quantite < dialogResult[0])
|
||||
{
|
||||
dialogResult[0] = this.data.data.quantite
|
||||
ui.notifications.notify(`Impossible de poster plus que ce que vous avez. La quantité à été réduite à ${dialogResult[0]}.`)
|
||||
this.update({"data.quantite" : 0})
|
||||
}
|
||||
else {
|
||||
ui.notifications.notify(`Quantité réduite par ${dialogResult[0]}.`)
|
||||
this.update({"data.quantite" : this.data.data.quantite - dialogResult[0]})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dialogResult[0] > 0)
|
||||
chatData.postQuantity = dialogResult[0];
|
||||
if (dialogResult[1] > 0) {
|
||||
chatData.postPrice = dialogResult[1];
|
||||
chatData.data.cout_deniers = Math.floor(dialogResult[1] * 100); // Mise à jour cout en deniers
|
||||
}
|
||||
// Don't post any image for the item (which would leave a large gap) if the default image is used
|
||||
if (chatData.img.includes("/blank.png"))
|
||||
chatData.img = null;
|
||||
|
||||
// JSON object for easy creation
|
||||
chatData.jsondata = JSON.stringify(
|
||||
{
|
||||
compendium : "postedItem",
|
||||
payload: this.data,
|
||||
});
|
||||
|
||||
renderTemplate('systems/foundryvtt-reve-de-dragon/templates/post-item.html', chatData).then(html => {
|
||||
let chatOptions = RdDUtility.chatDataSetup(html);
|
||||
ChatMessage.create(chatOptions)
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_objetChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Encombrement</b>: ${data.encombrement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_armeChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Compétence</b>: ${data.competence}`,
|
||||
`<b>Dommages</b>: ${data.dommages}`,
|
||||
`<b>Force minimum</b>: ${data.force}`,
|
||||
`<b>Resistance</b>: ${data.resistance}`,
|
||||
`<b>Encombrement</b>: ${data.encombrement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_conteneurChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Capacité</b>: ${data.capacite} Enc.`,
|
||||
`<b>Encombrement</b>: ${data.encombrement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_munitionChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Encombrement</b>: ${data.encombrement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_armureChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Protection</b>: ${data.protection}`,
|
||||
`<b>Détérioration</b>: ${data.deterioration}`,
|
||||
`<b>Malus armure</b>: ${data.malus}`,
|
||||
`<b>Encombrement</b>: ${data.encombrement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_competenceChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Catégorie</b>: ${data.categorie}`,
|
||||
`<b>Niveau</b>: ${data.niveau}`,
|
||||
`<b>Caractéristique par défaut</b>: ${data.carac_defaut}`,
|
||||
`<b>XP</b>: ${data.xp}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_competencecreatureChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Catégorie</b>: ${data.categorie}`,
|
||||
`<b>Niveau</b>: ${data.niveau}`,
|
||||
`<b>Caractéristique</b>: ${data.carac_value}`,
|
||||
`<b>XP</b>: ${data.xp}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_sortChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Draconic</b>: ${data.draconic}`,
|
||||
`<b>Difficulté</b>: ${data.difficulte}`,
|
||||
`<b>Case TMR</b>: ${data.caseTMR}`,
|
||||
`<b>Points de Rêve</b>: ${data.ptreve}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_herbeChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Milieu</b>: ${data.milieu}`,
|
||||
`<b>Rareté</b>: ${data.rarete}`,
|
||||
`<b>Catégorie</b>: ${data.categorie}`,
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_ingredientChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Milieu</b>: ${data.milieu}`,
|
||||
`<b>Rareté</b>: ${data.rarete}`,
|
||||
`<b>Catégorie</b>: ${data.categorie}`,
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_tacheChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Caractéristique</b>: ${data.carac}`,
|
||||
`<b>Compétence</b>: ${data.competence}`,
|
||||
`<b>Périodicité</b>: ${data.periodicite}`,
|
||||
`<b>Fatigue</b>: ${data.fatigue}`,
|
||||
`<b>Difficulté</b>: ${data.difficulte}`,
|
||||
`<b>Points de Tâche</b>: ${data.points_de_tache}`,
|
||||
`<b>Points de Tâche atteints</b>: ${data.points_de_tache_courant}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_livreChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Compétence</b>: ${data.competence}`,
|
||||
`<b>Auteur</b>: ${data.auteur}`,
|
||||
`<b>Difficulté</b>: ${data.difficulte}`,
|
||||
`<b>Points de Tâche</b>: ${data.points_de_tache}`,
|
||||
`<b>Encombrement</b>: ${data.encombrement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_potionChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Rareté</b>: ${data.rarete}`,
|
||||
`<b>Catégorie</b>: ${data.categorie}`,
|
||||
`<b>Encombrement</b>: ${data.encombrement}`,
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_queueChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Refoulement</b>: ${data.refoulement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_ombreChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Refoulement</b>: ${data.refoulement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_souffleChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [];
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_teteChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [];
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_tarotChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Concept</b>: ${data.concept}`,
|
||||
`<b>Aspect</b>: ${data.aspect}`,
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_nombreastralChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Valeur</b>: ${data.value}`,
|
||||
`<b>Jour</b>: ${data.jourlabel}`,
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_monnaieChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Valeur en Deniers</b>: ${data.valeur_deniers}`,
|
||||
`<b>Encombrement</b>: ${data.encombrement}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_meditationChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Thème</b>: ${data.theme}`,
|
||||
`<b>Compétence</b>: ${data.competence}`,
|
||||
`<b>Support</b>: ${data.support}`,
|
||||
`<b>Heure</b>: ${data.heure}`,
|
||||
`<b>Purification</b>: ${data.purification}`,
|
||||
`<b>Vêture</b>: ${data.veture}`,
|
||||
`<b>Comportement</b>: ${data.comportement}`,
|
||||
`<b>Case TMR</b>: ${data.tmr}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
_casetmrChatData() {
|
||||
const data = duplicate(this.data.data);
|
||||
let properties = [
|
||||
`<b>Coordonnée</b>: ${data.coord}`,
|
||||
`<b>Spécificité</b>: ${data.specific}`
|
||||
]
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { RdDItemSort } from "./item-sort.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { RdDItem } from "./item-rdd.js";
|
||||
|
||||
/**
|
||||
* Extend the basic ItemSheet with some very simple modifications
|
||||
@ -19,7 +20,20 @@ export class RdDItemSheet extends ItemSheet {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_getHeaderButtons() {
|
||||
let buttons = super._getHeaderButtons();
|
||||
// Add "Post to chat" button
|
||||
// We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry!
|
||||
buttons.unshift(
|
||||
{
|
||||
class: "post",
|
||||
icon: "fas fa-comment",
|
||||
onclick: ev => new RdDItem(this.item.data).postItem()
|
||||
})
|
||||
return buttons
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** @override */
|
||||
setPosition(options={}) {
|
||||
const position = super.setPosition(options);
|
||||
|
@ -195,7 +195,9 @@ export class RdDUtility {
|
||||
'systems/foundryvtt-reve-de-dragon/templates/editor-notes-mj.html',
|
||||
// HUD
|
||||
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html',
|
||||
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html'
|
||||
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html',
|
||||
// POST
|
||||
'systems/foundryvtt-reve-de-dragon/templates/post-item.html'
|
||||
];
|
||||
|
||||
return loadTemplates(templatePaths);
|
||||
@ -886,14 +888,23 @@ export class RdDUtility {
|
||||
// Gestion du bouton payer
|
||||
html.on("click", '#payer-button', event => {
|
||||
let sumdenier = event.currentTarget.attributes['data-somme-denier'].value;
|
||||
if (game.user.character )
|
||||
game.user.character.payerDenier(sumdenier);
|
||||
let jsondata = event.currentTarget.attributes['data-jsondata'].value
|
||||
let objData
|
||||
if ( jsondata)
|
||||
objData = JSON.parse(jsondata)
|
||||
console.log("Demande payr : ", objData);
|
||||
if (game.user.character ) {
|
||||
game.user.character.payerDenier(sumdenier, objData);
|
||||
} else {
|
||||
let msgPayer = "Vous devez avoir un acteur relié pour effectuer le paiement";
|
||||
ChatMessage.create( { content: msgPayer, whisper: [game.user] } );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static createMonnaie( name, valeur_deniers, enc = 0.01) {
|
||||
let piece = { name: name, type: 'monnaie', _id: randomID(),
|
||||
static createMonnaie( name, valeur_deniers, img = "", enc = 0.01) {
|
||||
let piece = { name: name, type: 'monnaie', _id: randomID(), img: img,
|
||||
data: {
|
||||
quantite: 0,
|
||||
valeur_deniers: valeur_deniers,
|
||||
@ -921,7 +932,28 @@ export class RdDUtility {
|
||||
|
||||
let sumtotald = sumd + (sums*100);
|
||||
let msgPayer = "La somme de "+sums+" Sols et "+sumd+" Deniers est à payer, cliquer sur le lien ci-dessous si besoin.<br>";
|
||||
msgPayer += "<a id='payer-button' data-somme-denier='"+sumtotald+"'>Payer</a>"
|
||||
msgPayer += "<a id='payer-button' class='chat-card-button' data-somme-denier='"+sumtotald+"'>Payer</a>"
|
||||
ChatMessage.create( { content: msgPayer } );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static chatDataSetup(content, modeOverride, isRoll = false, forceWhisper) {
|
||||
let chatData = {
|
||||
user: game.user._id,
|
||||
rollMode: modeOverride || game.settings.get("core", "rollMode"),
|
||||
content: content
|
||||
};
|
||||
|
||||
if (["gmroll", "blindroll"].includes(chatData.rollMode)) chatData["whisper"] = ChatMessage.getWhisperRecipients("GM").map(u => u.id);
|
||||
if (chatData.rollMode === "blindroll") chatData["blind"] = true;
|
||||
else if (chatData.rollMode === "selfroll") chatData["whisper"] = [game.user];
|
||||
|
||||
if (forceWhisper) { // Final force !
|
||||
chatData["speaker"] = ChatMessage.getSpeaker();
|
||||
chatData["whisper"] = ChatMessage.getWhisperRecipients(forceWhisper);
|
||||
}
|
||||
|
||||
return chatData;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user