#88 Gestion argent

This commit is contained in:
sladecraven 2020-12-31 00:55:02 +01:00
parent fcd4d615dd
commit 5175be2801
7 changed files with 198 additions and 17 deletions

View File

@ -479,6 +479,17 @@ export class RdDActorSheet extends ActorSheet {
this.render(true);
});
html.find('.monnaie-plus').click((event) => {
const li = $(event.currentTarget).parents(".item");
this.actor.monnaieIncDec( li.data("item-id"), 1 );
this.render(true);
});
html.find('.monnaie-moins').click((event) => {
const li = $(event.currentTarget).parents(".item");
this.actor.monnaieIncDec( li.data("item-id"), -1 );
this.render(true);
});
html.find('#vie-plus').click((event) => {
this.actor.santeIncDec("vie", 1);
this.render(true);

View File

@ -14,6 +14,7 @@ import { Grammar } from "./grammar.js";
import { RdDEncaisser } from "./rdd-roll-encaisser.js";
import { RdDCombat } from "./rdd-combat.js";
/* -------------------------------------------- */
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
* @extends {Actor}
@ -47,8 +48,6 @@ export class RdDActor extends Actor {
let compendiumName = "";
if (data.type == "personnage") {
compendiumName = "foundryvtt-reve-de-dragon.competences";
} else if (data.type == "humanoide") {
compendiumName = "foundryvtt-reve-de-dragon.competences-humanoides";
} else if (data.type == "creature") {
compendiumName = "foundryvtt-reve-de-dragon.competences-creatures";
} else if (data.type == "entite") {
@ -64,12 +63,14 @@ export class RdDActor extends Actor {
data.items.push(compItem);
}
// Ajout monnaie
if (data.type == "personnage" ) {
await RdDActor.ajouterMonnaie( data.items );
}
return super.create(data, options);
}
/* -------------------------------------------- */
/* -------------------------------------------- */
prepareData() {
super.prepareData();
@ -104,6 +105,37 @@ export class RdDActor extends Actor {
this.computeEtatGeneral();
}
/* -------------------------------------------- */
static async ajouterMonnaie( items ) {
let etain = { name: "Etain (1 denier)", type: 'monnaie', _id: randomID(),
data: {
quantite: 0,
valeur_deniers: 1,
encombrement: 0.01,
description: ""
}
}
items.push(etain);
let bronze = duplicate(etain);
bronze.id = randomID();
bronze.name = "Bronze (10 deniers)";
bronze.data.valeur_deniers = 10;
items.push(bronze);
let argent = duplicate(etain);
argent.id = randomID();
argent.name = "Argent (1 sol)";
argent.data.valeur_deniers = 100;
items.push(argent);
let or = duplicate(argent);
or.id = randomID();
or.name = "Or (10 sols)";
or.data.valeur_deniers = 1000;
items.push(or);
}
/* -------------------------------------------- */
isCreature() {
return this.data.type == 'creature' || this.data.type == 'entite';
@ -1996,7 +2028,6 @@ export class RdDActor extends Actor {
this.sheet.render(true);
}
/* -------------------------------------------- */
/** @override */
getRollData() {
@ -2004,7 +2035,6 @@ export class RdDActor extends Actor {
return data;
}
/* -------------------------------------------- */
/* -- entites -- */
/* retourne true si on peut continuer, false si on ne peut pas continuer */
@ -2075,6 +2105,73 @@ export class RdDActor extends Actor {
await this.update( {"data.sante.resonnance": resonnance});
return;
}
/* -------------------------------------------- */
async optimizeArgent( sumDenier ) {
let sols = Math.floor(sumDenier / 100);
let deniers = sumDenier - (sols*100);
let nbOr = Math.floor(sols / 10);
let nbArgent = sols - (nbOr*10);
let nbBronze = Math.floor(deniers / 10 );
let nbEtain = deniers - (nbBronze*10);
// console.log("ARGENT", nbOr, nbArgent, nbBronze, nbEtain);
let piece = this.data.items.find( item => item.type =='monnaie' && item.data.valeur_deniers == 1000);
if (piece ) {
let update = { _id: piece._id, 'data.quantite': nbOr};
const updated = await this.updateEmbeddedEntity("OwnedItem", update);
}
piece = this.data.items.find( item => item.type =='monnaie' && item.data.valeur_deniers == 100);
if (piece ) {
let update = { _id: piece._id, 'data.quantite': nbArgent};
const updated = await this.updateEmbeddedEntity("OwnedItem", update);
}
piece = this.data.items.find( item => item.type =='monnaie' && item.data.valeur_deniers == 10);
if (piece ) {
let update = { _id: piece._id, 'data.quantite': nbBronze};
const updated = await this.updateEmbeddedEntity("OwnedItem", update);
}
piece = this.data.items.find( item => item.type =='monnaie' && item.data.valeur_deniers == 1);
if (piece ) {
let update = { _id: piece._id, 'data.quantite': nbEtain};
const updated = await this.updateEmbeddedEntity("OwnedItem", update);
}
}
/* -------------------------------------------- */
payerDenier( sumDenier ) {
sumDenier = Number(sumDenier);
let denierDisponible = 0;
let monnaie = this.data.items.filter( item => item.type =='monnaie');
for ( let piece of monnaie ) {
denierDisponible += piece.data.valeur_deniers * Number(piece.data.quantite);
}
console.log("DENIER", game.user.character, sumDenier, denierDisponible);
if ( denierDisponible >= sumDenier) {
denierDisponible -= sumDenier;
this.optimizeArgent(denierDisponible);
} else {
let message = {
whisper: ChatUtility.getWhisperRecipientsAndGMs( this.name ),
content : "Vous n'avez pas assez d'argent pour paye cette somme !"
};
ChatMessage.create( message );
}
}
/* -------------------------------------------- */
async monnaieIncDec( id, value) {
let monnaie = this.data.items.find( item => item.type =='monnaie' && item._id == id );
if (monnaie ) {
monnaie.data.quantite += value;
if ( monnaie.data.quantite < 0 ) monnaie.data.quantite = 0; // Sanity check
const update = {_id: monnaie._id, 'data.quantite': monnaie.data.quantite };
const updated = await this.updateEmbeddedEntity("OwnedItem", update);
}
}
}

View File

@ -271,8 +271,7 @@ Hooks.on("preCreateToken", (scene, tokenData, options) => {
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.on("chatMessage", (html, content, msg) => {
let regExp;
regExp = /(\S+)/g;
let regExp = /(\S+)/g;
let commands = content.match(regExp);
return RdDUtility.processChatCommand( commands, content, msg );

View File

@ -164,6 +164,7 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/item-tarot-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/item-tete-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/item-ombre-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/item-monnaie-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-categorie.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html',
'systems/foundryvtt-reve-de-dragon/templates/competence-base.html',
@ -245,6 +246,7 @@ export class RdDUtility {
data.data.ombres = this.checkNull(data.itemsByType['ombre']);
data.data.tetes = this.checkNull(data.itemsByType['tete']);
data.data.taches = this.checkNull(data.itemsByType['tache']);
data.data.monnaie = this.checkNull(data.itemsByType['monnaie']);
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);
}
@ -743,7 +745,7 @@ export class RdDUtility {
return;
}
if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character.id == defenderToken.actor.data._id))) {
console.log("User is pushing message...", game.user.name);
//console.log("User is pushing message...", game.user.name);
game.system.rdd.rollDataHandler[data.attackerId] = duplicate(data.rollData);
data.whisper = [game.user];
data.blind = true;
@ -873,7 +875,7 @@ export class RdDUtility {
let actor = game.actors.get( actorId );
actor.tmrApp.forceDemiRevePosition(coord);
});
// Gestio spécifique des sorts en réserve multiples (ie têtes)
// Gestion spécifique des sorts en réserve multiples (ie têtes)
html.on("click", '#sort-reserve', event => {
let coord = event.currentTarget.attributes['data-tmr-coord'].value;
let sortId = event.currentTarget.attributes['data-sort-id'].value;
@ -881,6 +883,12 @@ export class RdDUtility {
let actor = game.actors.get( actorId );
actor.tmrApp.lancerSortEnReserve(coord, sortId);
});
// 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);
});
}
/* -------------------------------------------- */
@ -894,6 +902,27 @@ export class RdDUtility {
ChatMessage.create( msg );
}
/* -------------------------------------------- */
static afficherDemandePayer(som1, som2) {
som1 = (som1) ? som1.toLowerCase() : "0d";
som2 = (som2) ? som2.toLowerCase() : "0d";
let regExp = /(\d+)(\w+)/g;
let p1 = regExp.exec( som1);
regExp = /(\d+)(\w+)/g;
let p2 = regExp.exec( som2);
let sumd = 0;
let sums = 0;
if (p1[2] == 'd') sumd += Number(p1[1]);
if (p1[2] == 's') sums += Number(p1[1]);
if (p2[2] == 'd') sumd += Number(p2[1]);
if (p2[2] == 's') sums += Number(p2[1]);
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>"
ChatMessage.create( { content: msgPayer } );
}
/* -------------------------------------------- */
/* Manage chat commands */
static processChatCommand( commands, content, msg ) {
@ -915,11 +944,14 @@ export class RdDUtility {
}
return false
} else if (command === "/tmrr") {
TMRUtility.getRencontre(commands[1], commands[2] )
return false
TMRUtility.getRencontre(commands[1], commands[2] )
return false
} else if (command === "/tmra") {
TMRUtility.getTMRAleatoire( )
return false
TMRUtility.getTMRAleatoire( )
return false
} else if (command === "/payer") {
RdDUtility.afficherDemandePayer( commands[1], commands[2] )
return false
}
return true;

View File

@ -451,7 +451,7 @@ section.sheet-body:after {
width: 2rem;
}
#vie-plus, #vie-moins, #endurance-plus, #endurance-moins, #fatigue-plus, #fatigue-moins, #ptreve-actuel-plus, #ptreve-actuel-moins {
#vie-plus, #vie-moins, #endurance-plus, #endurance-moins, #fatigue-plus, #fatigue-moins, #ptreve-actuel-plus, #ptreve-actuel-moins, .monnaie-plus, .monnaie-moins {
display: inline-block;
width: 1.25rem;
background: rgba(30, 25, 20, 1);

View File

@ -614,6 +614,19 @@
{{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items">
<ul class="item-list alterne-list">
{{#each data.monnaie as |piece id|}}
<li class="item flexrow list-item" data-item-id="{{piece._id}}">
<span class="competence-title competence-label">{{piece.name}}</span>
<span class="competence-title competence-label">{{piece.data.quantite}}</span>
<span class="competence-title"><a class="monnaie-plus">+</a><a class="monnaie-moins">-</a></span>
<div class="item-controls">
<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>
{{/each}}
</ul>
<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>
<ul class="item-list alterne-list">

View File

@ -0,0 +1,29 @@
<form class="{{cssClass}}" autocomplete="off">
<header class="sheet-header">
<img class="profile-img" src="{{item.img}}" data-edit="img" title="{{item.name}}"/>
<div class="header-fields">
<h1 class="charname"><input name="name" type="text" value="{{item.name}}" placeholder="Name"/></h1>
</div>
</header>
{{!-- Sheet Body --}}
<section class="sheet-body">
<div class="form-group">
<label for="xp">Quantité</label>
<input class="attribute-value" type="text" name="data.quantite" value="{{data.quantite}}" data-dtype="Number"/>
</div>
<div class="form-group">
<label for="xp">Valeur en Deniers</label>
<input class="attribute-value" type="text" name="data.valeur_deniers" value="{{data.valeur_deniers}}" data-dtype="Number"/>
</div>
<div class="form-group">
<label for="xp">Encombrement</label>
<input class="attribute-value" type="text" name="data.encombrement" value="{{data.encombrement}}" data-dtype="Number"/>
</div>
<span><label>Description : </label></span>
<div class="form-group editor" style="min-height: 400px !important;">
{{editor content=data.description target="data.description" button=true owner=owner editable=editable}}
</div>
</section>
</form>