Gestion des quantites et de l'argent

This commit is contained in:
2022-12-03 23:57:30 +01:00
parent 5ab6b99ef6
commit 5dde9ac72f
9 changed files with 134 additions and 14 deletions

View File

@ -48,6 +48,9 @@ export class HawkmoonActorSheet extends ActorSheet {
profils: duplicate(this.actor.getProfils() || {}),
combat: this.actor.getCombatValues(),
equipements: duplicate(this.actor.getEquipments()),
monnaies: duplicate(this.actor.getMonnaies()),
richesse: this.actor.computeRichesse(),
valeurEquipement: this.actor.computeValeurEquipement(),
initiative: this.actor.getFlag("world", "last-initiative") || -1,
description: await TextEditor.enrichHTML(this.object.system.biodata.description, {async: true}),
habitat: await TextEditor.enrichHTML(this.object.system.biodata.habitat, {async: true}),
@ -112,15 +115,12 @@ export class HawkmoonActorSheet extends ActorSheet {
let value = Number($(event.currentTarget).data("adversite-value"))
this.actor.incDecAdversite(adv, value)
})
html.find('.quantity-minus').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.incDecQuantity( li.data("item-id"), -1 );
} );
html.find('.quantity-plus').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.incDecQuantity( li.data("item-id"), +1 );
} );
html.find('.quantity-modify').click(event => {
const li = $(event.currentTarget).parents(".item")
const value = Number($(event.currentTarget).data("quantite-value"))
this.actor.incDecQuantity( li.data("item-id"), value );
})
html.find('.roll-initiative').click((event) => {
this.actor.rollAttribut("pre", true)

View File

@ -116,6 +116,10 @@ export class HawkmoonActor extends Actor {
getEquipments() {
return this.items.filter(item => item.type == "equipement")
}
/* ----------------------- --------------------- */
getMonnaies() {
return this.items.filter(item => item.type == "monnaie")
}
/* -------------------------------------------- */
getArmors() {
return this.items.filter(item => item.type == "protection")
@ -427,12 +431,36 @@ export class HawkmoonActor extends Actor {
async incDecQuantity(objetId, incDec = 0) {
let objetQ = this.items.get(objetId)
if (objetQ) {
let newQ = objetQ.system.quantity + incDec
let newQ = objetQ.system.quantite + incDec
newQ = Math.max(newQ, 0)
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantity': newQ }]); // pdates one EmbeddedEntity
const updated = await this.updateEmbeddedDocuments('Item', [{ _id: objetQ.id, 'system.quantite': newQ }]); // pdates one EmbeddedEntity
}
}
/* -------------------------------------------- */
computeRichesse() {
let valueSC = 0
for(let monnaie of this.items) {
if (monnaie.type == "monnaie") {
valueSC += Number(monnaie.system.prixsc) * Number(monnaie.system.quantite)
}
}
return HawkmoonUtility.computeMonnaieDetails( valueSC)
}
/* -------------------------------------------- */
computeValeurEquipement() {
let valueSC = 0
for(let equip of this.items) {
if (equip.type == "equipement" || equip.type == "arme" || equip.type == "protection") {
valueSC += Number(equip.system.prixsc) * Number(equip.system.quantite ?? 1)
valueSC += (Number(equip.system.prixca) * Number(equip.system.quantite ?? 1)) * 20
valueSC += (Number(equip.system.prixpo) * Number(equip.system.quantite ?? 1)) * 400
}
}
return HawkmoonUtility.computeMonnaieDetails( valueSC)
}
/* -------------------------------------------- */
getCompetence(compId) {
return this.items.get(compId)

View File

@ -305,6 +305,16 @@ export class HawkmoonUtility {
}
}
/* -------------------------------------------- */
static computeMonnaieDetails(valueSC) {
let po = Math.floor(valueSC / 400)
let pa = Math.floor((valueSC - (po*400)) / 20)
let sc = valueSC - (po*400) - (pa*20)
return {
po: po, pa: pa, sc: sc, valueSC: valueSC
}
}
/* -------------------------------------------- */
static computeResult(rollData) {
rollData.diceResult = rollData.roll.terms[0].results[0].result