Working on 0.8.x
- Xp spent curriculum/total for titles
This commit is contained in:
@@ -111,25 +111,24 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
|
||||
sheetData.items
|
||||
.filter((item) => ["peculiarity", "technique", "advancement"].includes(item.type))
|
||||
.forEach((item) => {
|
||||
let xp = parseInt(item.data.xp_used) || 0;
|
||||
sheetData.data.data.xp_spent = parseInt(sheetData.data.data.xp_spent) + xp;
|
||||
|
||||
// if not in curriculum, xp spent /2 for this item
|
||||
if (!item.data.in_curriculum && xp > 0) {
|
||||
xp = Math.ceil(xp / 2);
|
||||
}
|
||||
const { xp_used_total, xp_used } = game.l5r5e.HelpersL5r5e.getItemsXpCost(item);
|
||||
sheetData.data.data.xp_spent += xp_used_total;
|
||||
|
||||
const rank = Math.max(0, item.data.bought_at_rank);
|
||||
if (!adv[rank]) {
|
||||
adv[rank] = {
|
||||
rank: rank,
|
||||
spent: 0,
|
||||
spent: {
|
||||
total: 0,
|
||||
curriculum: 0,
|
||||
},
|
||||
goal: CONFIG.l5r5e.xp.costPerRank[rank] || null,
|
||||
list: [],
|
||||
};
|
||||
}
|
||||
adv[rank].list.push(item);
|
||||
adv[rank].spent = adv[rank].spent + xp;
|
||||
adv[rank].spent.total += xp_used_total;
|
||||
adv[rank].spent.curriculum += xp_used;
|
||||
});
|
||||
sheetData.data.advancementsListByRank = adv;
|
||||
}
|
||||
@@ -146,15 +145,14 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
|
||||
// Sort by rank desc
|
||||
sheetData.data.advancementsOthers.sort((a, b) => (b.data.rank || 0) - (a.data.rank || 0));
|
||||
|
||||
// Total xp spent
|
||||
// Total xp spent in curriculum & total
|
||||
sheetData.data.advancementsOthersTotalXp = sheetData.data.advancementsOthers.reduce(
|
||||
(acc, item) => acc + (item.data.xp_used || 0),
|
||||
(acc, item) => acc + parseInt(item.data.xp_used_total || item.data.xp_used || 0),
|
||||
0
|
||||
);
|
||||
|
||||
// Update the total spent
|
||||
sheetData.data.data.xp_spent =
|
||||
parseInt(sheetData.data.data.xp_spent) + sheetData.data.advancementsOthersTotalXp;
|
||||
sheetData.data.data.xp_spent += sheetData.data.advancementsOthersTotalXp;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -331,4 +331,34 @@ export class HelpersL5r5e {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the Xp cost for cursus and total
|
||||
* @param {ItemL5r5e|ItemL5r5e[]} itemsList Item Data
|
||||
* @return {{xp_used_total: number, xp_used: number}}
|
||||
*/
|
||||
static getItemsXpCost(itemsList) {
|
||||
let xp_used = 0;
|
||||
let xp_used_total = 0;
|
||||
|
||||
if (!Array.isArray(itemsList)) {
|
||||
itemsList = [itemsList];
|
||||
}
|
||||
|
||||
itemsList.forEach((item) => {
|
||||
let xp = parseInt(item.data.xp_used_total || item.data.xp_used || 0);
|
||||
|
||||
// Full price
|
||||
xp_used_total += xp;
|
||||
|
||||
// if not in curriculum, xp spent /2 for this item
|
||||
if (!item.data.in_curriculum && xp > 0) {
|
||||
xp = Math.ceil(xp / 2);
|
||||
}
|
||||
|
||||
// Halved or full
|
||||
xp_used += xp;
|
||||
});
|
||||
return { xp_used, xp_used_total };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,10 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
|
||||
// Prepare OwnedItems
|
||||
sheetData.data.embedItemsList = this._prepareEmbedItems(sheetData.data.data.items);
|
||||
|
||||
// Automatically compute the xp cost
|
||||
sheetData.data.data.xp_used = sheetData.data.embedItemsList.reduce(
|
||||
(acc, item) => acc + (+item.data.xp_used || 0),
|
||||
0
|
||||
);
|
||||
// Automatically compute the total xp cost (full price) and XP in title (cursus, some halved prices)
|
||||
const { xp_used_total, xp_used } = game.l5r5e.HelpersL5r5e.getItemsXpCost(sheetData.data.embedItemsList);
|
||||
sheetData.data.data.xp_used_total = xp_used_total;
|
||||
sheetData.data.data.xp_used = xp_used;
|
||||
|
||||
return sheetData;
|
||||
}
|
||||
@@ -91,10 +90,11 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
|
||||
return;
|
||||
}
|
||||
|
||||
// *** Items : add, edit, delete ***
|
||||
// *** Sub-Items management ***
|
||||
html.find(".item-add").on("click", this._addSubItem.bind(this));
|
||||
html.find(`.item-edit`).on("click", this._editSubItem.bind(this));
|
||||
html.find(`.item-delete`).on("click", this._deleteSubItem.bind(this));
|
||||
html.find(`.item-curriculum`).on("click", this._switchSubItemCurriculum.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,6 +104,9 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
|
||||
* @private
|
||||
*/
|
||||
async _addSubItem(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
// Show Dialog
|
||||
const selectedType = await game.l5r5e.HelpersL5r5e.showSubItemDialog(["advancement", "technique"]);
|
||||
if (!selectedType) {
|
||||
@@ -125,4 +128,25 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e {
|
||||
item.sheet.render(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toogle the curriculum for this embed item
|
||||
* @param {Event} event
|
||||
* @return {Promise<void>}
|
||||
* @private
|
||||
*/
|
||||
async _switchSubItemCurriculum(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const itemId = $(event.currentTarget).data("item-id");
|
||||
const item = this.document.getEmbedItem(itemId);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Switch the state and update
|
||||
item.data.data.in_curriculum = !item.data.data.in_curriculum;
|
||||
return this.document.updateEmbedItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user