Merge branch 'v1.5-stress-vente-post' into 'v1.5'

Correction stress sans monter de niveau, vente de conteneurs et montrer

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!304
This commit is contained in:
Leratier Bretonnien 2021-12-12 09:35:14 +00:00
commit a6ae9ff939
11 changed files with 60 additions and 126 deletions

View File

@ -56,15 +56,15 @@ export class RdDActorCreatureSheet extends RdDActorSheet {
if (!this.options.editable) return;
// On competence change
html.find('.creature-carac').change((event) => {
html.find('.creature-carac').change(async event => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence(compName, "carac_value", parseInt(event.target.value));
});
html.find('.creature-niveau').change((event) => {
html.find('.creature-niveau').change(async event => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence(compName, "niveau", parseInt(event.target.value));
});
html.find('.creature-dommages').change((event) => {
html.find('.creature-dommages').change(async event => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence(compName, "dommages", parseInt(event.target.value));
});

View File

@ -69,59 +69,59 @@ export class RdDActorEntiteSheet extends ActorSheet {
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
const li = $(ev.currentTarget).parents(".item");
html.find('.item-edit').click(event => {
const li = $(event.currentTarget).parents(".item");
const item = this.actor.getEmbeddedDocument('Item', li.data("itemId"));
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
const li = $(ev.currentTarget).parents(".item");
html.find('.item-delete').click(event => {
const li = $(event.currentTarget).parents(".item");
this.actor.deleteEmbeddedDocuments('Item', [li.data("itemId")]);
li.slideUp(200, () => this.render(false));
});
// Roll Carac
html.find('.carac-label a').click((event) => {
html.find('.carac-label a').click(async event => {
let caracName = event.currentTarget.attributes.name.value;
this.actor.rollCarac( caracName.toLowerCase() );
});
// On competence change
html.find('.creature-carac').change((event) => {
html.find('.creature-carac').change(async event => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "carac_value", parseInt(event.target.value) );
} );
html.find('.creature-niveau').change((event) => {
html.find('.creature-niveau').change(async event => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "niveau", parseInt(event.target.value) );
} );
html.find('.creature-dommages').change((event) => {
html.find('.creature-dommages').change(async event => {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCreatureCompetence( compName, "dommages", parseInt(event.target.value) );
} );
// Roll Skill
html.find('.competence-label a').click((event) => {
html.find('.competence-label a').click(async event => {
let compName = event.currentTarget.text;
this.actor.rollCompetence( compName );
});
html.find('.endurance-plus').click((event) => {
html.find('.endurance-plus').click(event => {
this.actor.santeIncDec("endurance", 1);
this.render(true);
});
html.find('.endurance-moins').click((event) => {
html.find('.endurance-moins').click(event => {
this.actor.santeIncDec("endurance", -1);
this.render(true);
});
html.find('.encaisser-direct').click(ev => {
html.find('.encaisser-direct').click(event => {
this.actor.encaisser();
});
html.find('.remise-a-neuf').click(ev => {
html.find('.remise-a-neuf').click(event => {
if (game.user.isGM) {
this.actor.remiseANeuf();
}

View File

@ -188,6 +188,11 @@ export class RdDActorSheet extends ActorSheet {
const item = RdDSheetUtility.getItem(event, this.actor);
item?.proposerVente();
});
html.find('.item-montrer').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
item?.postItem();
});
html.find('.item-action').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
this.actor.actionItem(item);

View File

@ -103,12 +103,12 @@ export class RdDActorVehiculeSheet extends ActorSheet {
if (!this.options.editable) return;
// Update Inventory Item
html.find('.item-edit').click(ev => {
html.find('.item-edit').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
item.sheet.render(true);
});
// Delete Inventory Item
html.find('.item-delete').click(ev => {
html.find('.item-delete').click(async event => {
const li = RdDSheetUtility.getEventElement(event);
RdDUtility.confirmerSuppression(this, li);
});

View File

@ -936,15 +936,15 @@ export class RdDActor extends Actor {
return;
}
const xpUtilise = Math.min(stressTransforme, xpRequis);
const stressTransformeRestant = Math.max(0, stressTransforme - xpUtilise);
const gainNiveau = xpUtilise >= xpRequis ? 1 : 0;
await this.update({ "data.compteurs.experience.value": stressTransformeRestant });
const nouveauNiveau = niveau + gainNiveau;
const nouveauXp = gainNiveau > 0 ? Math.max(compData.data.xp - xpRequis, 0) : (compData.data.xp + xpUtilise);
await competence.update({
"data.xp": Math.max(compData.data.xp - xpRequis, 0),
"data.xp": nouveauXp,
"data.niveau": nouveauNiveau,
});
const stressTransformeRestant = Math.max(0, stressTransforme - xpUtilise);
await this.update({ "data.compteurs.experience.value": stressTransformeRestant });
this.updateExperienceLog('Dépense stress', xpUtilise, `Stress en ${competence.name} ${gainNiveau ? "pour passer à " + nouveauNiveau : ""}`);
}
@ -3711,7 +3711,7 @@ export class RdDActor extends Actor {
}
const itemVendu = Misc.data(vendeur?.getObjet(itemId));
if (itemVendu) {
if (isItemEmpilable ? itemVendu.data.quantite < achat.quantiteTotal : achat.choix.nombreLots != 1) {
if (isItemEmpilable ? (itemVendu.data.quantite < achat.quantiteTotal) : (achat.choix.nombreLots != 1)) {
await acheteur?.ajouterDeniers(coutDeniers);
ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a plus assez de ${vente.item.name} !`);
return;

View File

@ -5,6 +5,7 @@ export class DialogItemVente extends Dialog {
static async create(item, callback) {
const itemData = Misc.data(item);
const quantite = item.isConteneur() ? 1 : itemData.data.quantite;
const venteData = {
item: itemData,
alias: item.actor?.name ?? game.user.name,
@ -13,9 +14,9 @@ export class DialogItemVente extends Dialog {
prixUnitaire: itemData.data.cout,
prixLot: itemData.data.cout,
tailleLot: 1,
quantiteNbLots: itemData.data.quantite,
quantiteMaxLots: itemData.data.quantite,
quantiteMax: itemData.data.quantite,
quantiteNbLots: quantite,
quantiteMaxLots: quantite,
quantiteMax: quantite ,
quantiteIllimite: !item.isOwned,
isOwned: item.isOwned,
};

View File

@ -30,23 +30,20 @@ export class RdDItemSheet extends ItemSheet {
/* -------------------------------------------- */
_getHeaderButtons() {
let buttons = super._getHeaderButtons();
const videSiConteneur = this.object.isConteneur() ? this.object.isVide() : true;
// 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!
if ("cout" in Misc.templateData(this.object) && videSiConteneur) {
if ("cout" in Misc.templateData(this.object) && this.object.isVideOuNonConteneur()) {
buttons.unshift({
class: "post",
class: "vendre",
icon: "fas fa-comments-dollar",
onclick: ev => this.item.proposerVente()
});
}
else {
buttons.unshift({
class: "post",
icon: "fas fa-comment",
onclick: ev => this.item.postItem()
});
}
buttons.unshift({
class: "montrer",
icon: "fas fa-comment",
onclick: ev => this.item.postItem()
});
return buttons
}
@ -203,6 +200,10 @@ export class RdDItemSheet extends ItemSheet {
const item = RdDSheetUtility.getItem(event, this.actor);
item?.proposerVente();
});
html.find('.item-montrer').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
item?.postItem();
});
html.find('.item-action').click(async event => {
const item = RdDSheetUtility.getItem(event, this.actor);
this.actor.actionItem(item, async () => itemSheetDialog.render(true));

View File

@ -63,8 +63,16 @@ export class RdDItem extends Item {
return Misc.data(this).type == 'conteneur';
}
isVide() {
return this.isConteneur() && (Misc.templateData(this).contenu ?? []).length == 0;
isConteneurNonVide() {
return this.isConteneur() && (Misc.templateData(this).contenu?.length ?? 0) > 0;
}
isConteneurVide() {
return this.isConteneur() && (Misc.templateData(this).contenu?.length ?? 0) == 0;
}
isVideOuNonConteneur() {
return !this.isConteneur() || (Misc.templateData(this).contenu?.length ?? 0) == 0;
}
isAlcool() {
@ -143,7 +151,7 @@ export class RdDItem extends Item {
getActionPrincipale(options = { warnIfNot: true }) {
const itemData = Misc.data(this);
if (itemData.type != 'conteneur' && (itemData.data.quantite ?? 0) <= 0) {
if (!this.isConteneur() && (itemData.data.quantite ?? 0) <= 0) {
if (options.warnIfNot) {
ui.notifications.warn(`Vous n'avez plus de ${itemData.name}.`);
}
@ -217,6 +225,10 @@ export class RdDItem extends Item {
async proposerVente() {
console.log(this);
if (this.isConteneurNonVide()) {
ui.notifications.warn(`Votre ${this.name} n'est pas vide, pas possible de le donner ou le vendre`);
return;
}
const dialog = await DialogItemVente.create(this, (vente) => this._onProposerVente(vente))
dialog.render(true);
}
@ -250,70 +262,6 @@ export class RdDItem extends Item {
if (this.actor) {
chatData.actor = { id: this.actor.id };
}
//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) {
chatData.data.cout_deniers = Math.floor(chatData.data.cout * 100);
dialogResult = await new Promise((resolve, reject) => {
new Dialog({
content:
`<p>Modifier la quantité?</p>
<div class="form-group">
<label> Quantité</label>
<input name="quantity" type="text" value="1"/>
</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é & Prix",
buttons: {
post: {
label: "Soumettre",
callback: (dlg) => {
resolve([Number(dlg.find('[name="quantity"]').val()), Number(dlg.find('[name="price"]').val())])
}
},
}
}).render(true)
})
}
let quantiteEnvoi = this.isOwned ? Math.min(dialogResult[0], chatData.data.quantite) : dialogResult[0];
const prixTotal = dialogResult[1];
if (quantiteEnvoi > 0) {
if (this.isOwned) {
if (chatData.data.quantite == 0) {
quantiteEnvoi = -1
}
else if (quantiteEnvoi > chatData.data.quantite) {
quantiteEnvoi = chatData.data.quantite;
ui.notifications.notify(`Impossible de poster plus que ce que vous avez. La quantité à été réduite à ${quantiteEnvoi}.`)
}
if (quantiteEnvoi > 0) {
this.diminuerQuantite(quantiteEnvoi);
}
}
}
if (chatData.hasPrice) {
if (quantiteEnvoi > 0)
chatData.postQuantity = Number(quantiteEnvoi);
if (prixTotal >= 0) {
chatData.postPrice = prixTotal;
chatData.data.cout_deniers = Math.floor(prixTotal * 100); // Mise à jour cout en deniers
}
chatData.finalPrice = Number(chatData.postPrice) * Number(chatData.postQuantity);
chatData.data.cout_deniers_total = chatData.data.cout_deniers * Number(chatData.postQuantity);
chatData.data.quantite = chatData.postQuantity;
console.log("POST : ", chatData.finalPrice, chatData.data.cout_deniers_total, chatData.postQuantity);
}
// JSON object for easy creation
chatData.jsondata = JSON.stringify(
{

View File

@ -5,7 +5,7 @@ export class RdDTMRRencontreDialog extends Dialog {
constructor(html, tmrApp, rencontre, postRencontre) {
const dialogConf = {
title: "Rencontre en TMR!",
content: "Vous recontrez un " + rencontre.name + " de force " + rencontre.force + "<br>",
content: "Vous rencontrez un " + rencontre.name + " de force " + rencontre.force + "<br>",
buttons: {
derober: { icon: '<i class="fas fa-check"></i>', label: "Se dérober", callback: () => { this.onButtonFuir(() => tmrApp.derober()); } },
refouler: { icon: '<i class="fas fa-check"></i>', label: "Refouler", callback: () => this.onButtonAction(() => tmrApp.refouler()) },

View File

@ -24,6 +24,7 @@
&nbsp;
<a class="item-control item-vendre" title="Vendre ou donner"><i class="fas fa-comments-dollar"></i></a>
{{/if}}
<a class="item-control item-montrer" title="Montrer"><i class="fas fa-comment"></i></a>
{{#if item.data.actionPrincipale}}
<a class="item-name item-action">{{item.data.actionPrincipale}}</a>
{{/if}}

View File

@ -9,28 +9,6 @@
{{#each properties as |property p|}}
<span>{{{property}}}</span><br>
{{/each}}
{{#if (or postQuantity postPrice)}}
<span>
{{#if postQuantity}}
<b>Quantité: </b> <span class="postQuantity">{{postQuantity}}</span>
{{/if}}
{{#if postPrice}}
<b>Prix: </b> <span class="postPrice">{{postPrice}} Sols</span>
{{/if}}
</span><br>
{{/if}}
<span>
<b>Prix Total: </b> <span class="postPrice">{{finalPrice}} Sols</span><br>
</span>
</p>
{{#if hasPrice}}
<span class="chat-card-button-area">
<a class='payer-button chat-card-button market-button'
data-jsondata='{{jsondata}}'
{{#if actor.id}}data-actor-id='{{actor.id}}'{{/if}}
data-somme-denier="{{data.cout_deniers_total}}" data-quantite="{{data.quantite}}">Payer</a>
</span>
{{/if}}
</div>