Merge branch 'v1.4' into 'feature-ethylisme-refactor'

# Conflicts:
#   module/actor.js
This commit is contained in:
Raphaël Piéroni
2021-05-08 12:10:58 +00:00
13 changed files with 547 additions and 87 deletions

View File

@ -638,7 +638,8 @@ export class RdDActor extends Actor {
}
}
else {
let deRecuperation = new Roll("1dr + 7").evaluate().total;
const roll = new Roll("1dr").evaluate();
let deRecuperation = roll.total;
console.log("recuperationReve", deRecuperation);
if (deRecuperation >= 7) {
// Rêve de Dragon !
@ -962,18 +963,16 @@ export class RdDActor extends Actor {
async processDropItem(event, dragData, objetVersConteneur) {
console.log("DRAG", this.id, dragData);
const droppedItemId = dragData.id || dragData.data._id;
const itemId = dragData.id || dragData.data._id;
if (dragData.actorId && dragData.actorId != this.id) {
console.log("Moving objects", dragData);
this.moveItemsBetweenActors(droppedItemId, dragData.actorId);
this.moveItemsBetweenActors(itemId, dragData.actorId);
return false;
}
let result = true;
const destId = $(event.target).parents(".item").attr("data-item-id");
const itemId = dragData.id || dragData.data._id;
const item = this.getObjet(itemId);
if (item.isEquipement()) {
if (item?.isEquipement()) {
if (dragData.actorId == this.id) {
// rangement
const srcId = objetVersConteneur[itemId];
@ -999,8 +998,8 @@ export class RdDActor extends Actor {
}
}
}
await this.computeEncombrementTotalEtMalusArmure();
}
await this.computeEncombrementTotalEtMalusArmure();
return result;
}
/* -------------------------------------------- */
@ -1061,7 +1060,7 @@ export class RdDActor extends Actor {
async regrouperEquipementsSimilaires(item, dest) {
await dest.quantiteIncDec(Misc.templateData(item).quantite);
await this.deleteEmbeddedDocuments('Item', [item.id]);
await item.delete();
}
/* -------------------------------------------- */
@ -1471,7 +1470,7 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async santeIncDec(name, inc, options = {isCritique: false, ethylisme: false}) {
async santeIncDec(name, inc, options = { isCritique: false, ethylisme: false }) {
const sante = duplicate(Misc.templateData(this).sante);
let compteur = sante[name];
@ -1758,7 +1757,7 @@ export class RdDActor extends Actor {
return;
}
if (choix.doses > itemData.data.quantite) {
ui.notifications.warn(`Il n'y a pas assez de ${itemData.name} poour manger ${choix.doses}`)
ui.notifications.warn(`Il n'y a pas assez de ${itemData.name} pour manger ${choix.doses}`)
return;
}
const surmonteExotisme = await this.surmonterExotisme(item, choix);
@ -2963,7 +2962,7 @@ export class RdDActor extends Actor {
const perteVie = this.isEntiteCauchemar()
? { newValue: 0 }
: await this.santeIncDec("vie", - encaissement.vie);
const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, {critiques: encaissement.critiques > 0});
const perteEndurance = await this.santeIncDec("endurance", -encaissement.endurance, { critiques: encaissement.critiques > 0 });
this.computeEtatGeneral();
this.sheet.render(false);
@ -3227,9 +3226,7 @@ export class RdDActor extends Actor {
if (fortune >= depense) {
fortune -= depense;
const toActor = game.actors.get(toActorId)
if (toActor) {
toActor.ajouterDeniers(depense, this.id);
}
await toActor?.ajouterDeniers(depense, this.id);
await this.optimizeArgent(fortune);
msg = `Vous avez payé <strong>${depense} Deniers</strong>${toActor ? " à " + toActor.name : ''}, qui ont été soustraits de votre argent.`;
RdDAudio.PlayContextAudio("argent"); // Petit son
@ -3252,6 +3249,17 @@ export class RdDActor extends Actor {
ChatMessage.create(message);
}
async depenser(depense) {
depense = Number(depense);
let fortune = this.getFortune();
let reste = fortune - depense;
if (reste >= 0) {
fortune -= depense;
await this.optimizeArgent(fortune);
}
return reste;
}
async ajouterDeniers(gain, fromActorId = undefined) {
if (fromActorId && !game.user.isGM) {
RdDActor.remoteActorCall({ userId: Misc.connectedGMOrUser(), actorId: this.id, method: 'ajouterDeniers', args: [gain, fromActorId] });
@ -3265,7 +3273,7 @@ export class RdDActor extends Actor {
RdDAudio.PlayContextAudio("argent"); // Petit son
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name),
content: `Vous avez reçu <strong>${gain} Deniers</strong> ${fromActor ? " de " + fromActor.name : ''}, qui ont été ajoutés de votre argent.`
content: `Vous avez reçu <strong>${gain} Deniers</strong> ${fromActor ? " de " + fromActor.name : ''}, qui ont été ajoutés à votre argent.`
});
}
}
@ -3279,6 +3287,85 @@ export class RdDActor extends Actor {
}
}
/* -------------------------------------------- */
async achatVente(vendeurId, acheteurId, venteData, chatMessageIdVente) {
if (vendeurId == acheteurId){
ui.notifications.info("Inutile de se vendre à soi-même");
return;
}
if (!game.user.isGM) {
RdDActor.remoteActorCall({
userId: Misc.connectedGMOrUser(),
actorId: this.vendeur?.id ?? this.acheteur?.id,
method: 'achatVente', args: [vendeurId, acheteurId, venteData, chatMessageIdVente]
});
return;
}
const acheteur = acheteurId ? game.actors.get(acheteurId) : undefined;
const vendeur = vendeurId ? game.actors.get(vendeurId) : undefined;
const itemId = venteData.item._id;
const coutDeniers = Math.floor((venteData.prixTotal ?? 0) * 100);
venteData.quantiteTotal = (venteData.nombreLots ?? 1) * (venteData.tailleLot);
if (acheteur) {
let resteAcheteur = await acheteur.depenser(coutDeniers);
if (resteAcheteur < 0) {
ui.notifications.warn(`Vous n'avez pas assez d'argent pour payer ${venteData.prixTotal} sols !`);
return;
}
}
if (vendeur) {
let itemData = Misc.data(vendeur.getObjet(itemId));
// diminuer QuantiteVendeur
if ("quantite" in itemData.data ?
itemData.data.quantite < venteData.quantiteTotal : venteData.nombreLots != 1) {
// pas assez de quantite
await acheteur?.ajouterDeniers(coutDeniers);
ui.notifications.warn(`Le vendeur n'a plus assez de ${venteData.item.name} !`);
return;
}
vendeur.ajouterDeniers(coutDeniers);
let qtReste = (itemData.data.quantite ?? 1) - venteData.quantiteTotal;
if (qtReste == 0) {
vendeur.deleteEmbeddedDocuments("Item", itemId);
}
else {
vendeur.updateEmbeddedDocuments("Item", [{ _id: itemId, 'data.quantite': qtReste }]);
}
}
if (acheteur) {
// TODO: achat depuis un compendium
const achat = duplicate(Misc.data(vendeur?.getObjet(itemId) ?? game.items.get(itemId)));
achat.data.quantite = venteData.quantiteTotal;
achat._id = undefined;
// TODO: investigate bug - création marche mal...
await acheteur.createEmbeddedDocuments("Item", [achat]);
}
if (coutDeniers > 0) {
RdDAudio.PlayContextAudio("argent");
}
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name),
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-achat-item.html', venteData)
});
if (venteData.quantiteNbLots <= venteData.nombreLots) {
ChatUtility.removeChatMessageId(chatMessageIdVente);
}
else {
venteData.quantiteNbLots -= venteData.nombreLots;
venteData.jsondata = JSON.stringify(venteData.item);
let newMessageVente = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', venteData);
const messageVente = game.messages.get(chatMessageIdVente);
messageVente.update({ content: newMessageVente });
messageVente.render(true);
}
}
/* -------------------------------------------- */
async effectuerTacheAlchimie(recetteId, tacheAlchimie, texteTache) {
let recetteData = Misc.data(this.getItemOfType(recetteId, 'recettealchimique'));