Skip to content

Commit

Permalink
Merge pull request #1623 from StarWarsFoundryVTT/wrong_xp_cost_1594
Browse files Browse the repository at this point in the history
fix(xp): characteristic cost
  • Loading branch information
wrycu authored Jul 15, 2024
2 parents 8988631 + d27f3aa commit c8eff81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Specializations no longer take forever to open ([#1593](https://github.com/StarWarsFoundryVTT/StarWarsFFG/issues/1593))
* SWA import now properly imports ranked talents ([#1572](https://github.com/StarWarsFoundryVTT/StarWarsFFG/issues/1572))
* SWA import no longer improperly matches the wrong talents in rare occasions
* Characteristic XP cost is now calculated excluding any boosts from modifiers ([#1594](https://github.com/StarWarsFoundryVTT/StarWarsFFG/issues/1594))

`1.901`
* Features:
Expand Down
19 changes: 12 additions & 7 deletions modules/actors/actor-sheet-ffg.js
Original file line number Diff line number Diff line change
Expand Up @@ -2063,37 +2063,42 @@ export class ActorSheetFFG extends ActorSheet {

_buyCharacteristicRank(characteristic) {
const characteristicValue = this.actor.system.characteristics[characteristic].value;
// this is the value without items that modify it
const characteristicCostValue = this.actor.system.attributes[characteristic].value;
if (characteristicValue >= game.settings.get("starwarsffg", "maxAttribute")) {
ui.notifications.warn(game.i18n.localize("SWFFG.Actors.Sheets.Purchase.Characteristic.Max"));
return;
}
const availableXP = this.actor.system.experience.available;
const totalXP = this.actor.system.experience.total;
const cost = (characteristicValue + 1) * 10;
const cost = (characteristicCostValue + 1) * 10;
if (cost > availableXP) {
ui.notifications.warn(game.i18n.localize("SWFFG.Actors.Sheets.Purchase.NotEnoughXP"));
return;
}
const dialog = new Dialog(
{
title: game.i18n.format("SWFFG.Actors.Sheets.Purchase.Characteristic.ConfirmTitle", {characteristic: characteristic}),
content: game.i18n.format("SWFFG.Actors.Sheets.Purchase.Characteristic.ConfirmText", {cost: cost, level: characteristicValue + 1, characteristic: characteristic}),
content: game.i18n.format("SWFFG.Actors.Sheets.Purchase.Characteristic.ConfirmText", {cost: cost, level: characteristicCostValue + 1, characteristic: characteristic}),
buttons: {
done: {
icon: '<i class="fas fa-dollar"></i>',
label: game.i18n.localize("SWFFG.Actors.Sheets.Purchase.ConfirmPurchase"),
callback: async (that) => {
// update the form because the fields are read when an update is performed
this.object.sheet.element.find(`[name="data.characteristics.${characteristic}.value"]`).val(characteristicValue + 1);
await this.object.sheet.submit({preventClose: true});
await this.object.update({
system: {
experience: {
available: availableXP - cost,
}
},
attributes: {
[characteristic]: {
value: characteristicCostValue + 1,
},
},
}
});
await xpLogSpend(game.actors.get(this.object.id), `characteristic ${characteristic} level ${characteristicValue} --> ${characteristicValue + 1}`, cost, availableXP - cost, totalXP);
await xpLogSpend(game.actors.get(this.object.id), `characteristic ${characteristic} level ${characteristicCostValue} --> ${characteristicCostValue + 1}`, cost, availableXP - cost, totalXP);
await this.render(true);
},
},
cancel: {
Expand Down

0 comments on commit c8eff81

Please sign in to comment.