Some progression work, and fixed start rank level to 1

This commit is contained in:
Vlyan
2020-12-26 21:55:23 +01:00
parent a0963e266e
commit 65be83dc14
10 changed files with 99 additions and 48 deletions

View File

@@ -64,25 +64,6 @@ export class BaseSheetL5r5e extends ActorSheet {
return;
}
// Check if technique is allowed for this character
if (
!game.user.isGM &&
item.data.type === "technique" &&
!this.actor.data.data.techniques[item.data.data.technique_type]
) {
new Dialog({
title: game.i18n.localize("l5r5e.techniques.title"),
content: game.i18n.localize("l5r5e.techniques.not_allowed"),
buttons: {
ok: {
label: game.i18n.localize("l5r5e.global.ok"),
icon: '<i class="fas fa-check"></i>',
},
},
}).render(true);
return;
}
// Dropped a item with same "id" as one owned, add qte instead
if (item.data.data.quantity && this.actor.data.items) {
const tmpItem = this.actor.data.items.find((e) => e.name === item.name && e.type === item.type);
@@ -104,6 +85,31 @@ export class BaseSheetL5r5e extends ActorSheet {
);
}
// Item subtype specific
switch (item.data.type) {
case "advancement":
// Modify the bought at rank to the current actor rank
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
break;
case "technique":
// Check if technique is allowed for this character
if (!game.user.isGM && !this.actor.data.data.techniques[item.data.data.technique_type]) {
new Dialog({
title: game.i18n.localize("l5r5e.techniques.title"),
content: game.i18n.localize("l5r5e.techniques.not_allowed"),
buttons: {
ok: {
label: game.i18n.localize("l5r5e.global.ok"),
icon: '<i class="fas fa-check"></i>',
},
},
}).render(true);
return;
}
break;
}
// Ok add item - Foundry override cause props
const allowed = Hooks.call("dropActorSheetData", this.actor, this, item);
if (allowed === false) {
@@ -159,6 +165,18 @@ export class BaseSheetL5r5e extends ActorSheet {
html.find(`.item-curriculum`).on("click", (event) => {
this._switchSubItemCurriculum(event);
});
html.find(`button[name=validate-curriculum]`).on("click", (event) => {
this.actor.data.data.identity.school_rank = this.actor.data.data.identity.school_rank + 1;
// Update actor
this.actor.update({
data: {
identity: {
school_rank: this.actor.data.data.identity.school_rank,
},
},
});
this.render(false);
});
}
/**
@@ -180,6 +198,12 @@ export class BaseSheetL5r5e extends ActorSheet {
type: type,
});
const item = this.actor.getOwnedItem(created._id);
// assign current school rank to the new tech
if (item.data.type === "advancement") {
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
}
item.sheet.render(true);
}

View File

@@ -39,33 +39,45 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
getData() {
const sheetData = super.getData();
// Sort Items by rank 0->6 for advancements tab
// Sort Items by rank 1->6 for advancements tab
sheetData.items.sort((a, b) => {
return (a.data.bought_at_rank || 0) - (b.data.bought_at_rank || 0);
return (a.data.bought_at_rank || 1) - (b.data.bought_at_rank || 1);
});
// Min rank = 1
this.actor.data.data.identity.school_rank = Math.max(1, this.actor.data.data.identity.school_rank);
// Xp spent only in current rank
sheetData.data.xp_spent_rank = this.getXpSpentInThisRank();
const totalXp = this._getXpSpent();
sheetData.data.xp_spent_rank = totalXp.rank;
sheetData.data.xp_spent = totalXp.total;
sheetData.data.xp_saved = sheetData.data.xp_total - sheetData.data.xp_spent;
sheetData.data.xp_goal = CONFIG.l5r5e.xpPerRank[this.actor.data.data.identity.school_rank - 1] || null;
return sheetData;
}
/**
* Return the current total xp spent for this rank
* Return the total xp spent and the current total xp spent for this rank
*/
getXpSpentInThisRank() {
const currentRank = this.actor.data.data.identity.school_rank || 0;
return this.actor.items.reduce((tot, item) => {
if (currentRank + 1 === item.data.data.rank) {
let xp = item.data.data.xp_used || 0;
_getXpSpent() {
const total = {
total: 0,
rank: 0,
};
const currentRank = this.actor.data.data.identity.school_rank;
this.actor.items.map((item) => {
let xp = item.data.data.xp_used || 0;
total.total = total.total + xp;
if (currentRank === item.data.data.rank) {
// if not in curriculum, xp spent /2 for this item
if (!item.data.data.in_curriculum && xp > 0) {
xp = Math.floor(xp / 2);
}
return tot + xp;
total.rank = total.rank + xp;
}
return tot;
}, 0);
});
return total;
}
}

View File

@@ -7,6 +7,7 @@ L5R5E.paths = {
L5R5E.stances = ["earth", "air", "water", "fire", "void"];
L5R5E.techniques = ["kata", "kiho", "invocation", "ritual", "shuji", "maho", "ninjutsu"];
L5R5E.xpPerRank = [20, 24, 32, 44, 60];
// Map SkillId - CategoryId
L5R5E.skills = new Map();