Some automatisations on advancements

Added xp cost for technique
This commit is contained in:
Vlyan
2020-12-27 12:19:43 +01:00
parent 65be83dc14
commit c874caec1a
14 changed files with 200 additions and 44 deletions

View File

@@ -199,8 +199,9 @@ export class BaseSheetL5r5e extends ActorSheet {
});
const item = this.actor.getOwnedItem(created._id);
// assign current school rank to the new tech
if (item.data.type === "advancement") {
// assign current school rank to the new adv/tech
if (["advancement", "technique"].includes(item.data.type)) {
item.data.data.rank = this.actor.data.data.identity.school_rank;
item.data.data.bought_at_rank = this.actor.data.data.identity.school_rank;
}
@@ -230,6 +231,25 @@ export class BaseSheetL5r5e extends ActorSheet {
return;
}
// Specific advancements, remove 1 to selected ring/skill
if (tmpItem.type === "advancement") {
const actor = duplicate(this.actor.data.data);
const itmData = tmpItem.data.data;
if (itmData.advancement_type === "ring") {
// Ring
actor.rings[itmData.ring] = Math.max(1, actor.rings[itmData.ring] - 1);
} else {
// Skill
const skillCatId = CONFIG.l5r5e.skills.get(itmData.skill);
actor.skills[skillCatId][itmData.skill] = Math.max(0, actor.skills[skillCatId][itmData.skill] - 1);
}
// Update Actor
this.actor.update({
data: diffObject(this.actor.data.data, actor),
});
}
return this.actor.deleteOwnedItem(itemId);
}

View File

@@ -52,7 +52,7 @@ export class CharacterSheetL5r5e extends BaseSheetL5r5e {
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;
sheetData.data.xp_goal = CONFIG.l5r5e.xp.costPerRank[this.actor.data.data.identity.school_rank - 1] || null;
return sheetData;
}

View File

@@ -138,7 +138,7 @@ export class TwentyQuestionsDialog extends FormApplication {
}
const stepKey = $(event.target).data("step");
if (!stepKey) {
console.log("event stepKey is undefined");
console.warn("event stepKey is undefined");
return;
}
@@ -151,7 +151,7 @@ export class TwentyQuestionsDialog extends FormApplication {
(type !== "item" && item.data.type !== type) ||
(type === "item" && !["item", "weapon", "armor"].includes(item.data.type))
) {
console.log("forbidden item for this drop zone", type, item.data.type);
console.warn("forbidden item for this drop zone", type, item.data.type);
return;
}
// Add the item (step and cache)

View File

@@ -208,7 +208,7 @@ export class TwentyQuestions {
* Fill a actor data from this object
*/
async toActor(actor, itemsCache) {
const actorDatas = actor.data.data;
const actorDatas = duplicate(actor.data.data);
const formData = this.data;
// Update the actor real datas
@@ -280,7 +280,7 @@ export class TwentyQuestions {
// Update actor
actor.update({
name: (formData.step2.family + " " + formData.step19.firstname).trim(),
data: actorDatas,
data: diffObject(actor.data.data, actorDatas),
});
// TODO Tmp

View File

@@ -7,7 +7,12 @@ 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];
L5R5E.xp = {
costPerRank: [20, 24, 32, 44, 60],
ringCostMultiplier: 3,
skillCostMultiplier: 2,
techniqueCost: 3,
};
// Map SkillId - CategoryId
L5R5E.skills = new Map();

View File

@@ -7,7 +7,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
/**
* Sub Types of advancements
*/
static types = ["ring", "skill"]; // "advantage" and "technique" have theirs own xp count
static types = ["ring", "skill"]; // "peculiarity" and "technique" have theirs own xp count
/** @override */
static get defaultOptions() {
@@ -28,4 +28,110 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
return sheetData;
}
/**
* Subscribe to events from the sheet.
* @param html HTML content of the sheet.
*/
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) {
return;
}
// const currentType = this.object.data.data.advancement_type;
const currentRing = this.object.data.data.ring;
const currentSkill = this.object.data.data.skill;
html.find("#advancement_type").on("change", (event) => {
if ($(event.target).val() === "skill") {
this._updateChoice(
{
ring: currentRing,
},
{
skill: currentSkill,
}
);
} else {
this._updateChoice(
{
skill: currentSkill,
},
{
ring: currentRing,
}
);
}
});
html.find("#advancement_ring").on("change", (event) => {
this._updateChoice(
{
ring: currentRing,
},
{
ring: $(event.target).val(),
}
);
});
html.find("#advancement_skill").on("change", (event) => {
this._updateChoice(
{
skill: currentSkill,
},
{
skill: $(event.target).val(),
}
);
});
}
/**
* Update Actor and Object to the current choice
* @private
*/
_updateChoice(oldChoice, newChoice) {
let skillCatId = null;
const actor = duplicate(this.actor.data.data);
let xp_used = this.object.data.data.xp_used;
// Old choices
if (oldChoice.ring) {
actor.rings[oldChoice.ring] = Math.max(1, actor.rings[oldChoice.ring] - 1);
}
if (oldChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(oldChoice.skill);
actor.skills[skillCatId][oldChoice.skill] = Math.max(0, actor.skills[skillCatId][oldChoice.skill] - 1);
}
// new choices
if (newChoice.ring) {
actor.rings[newChoice.ring] = actor.rings[newChoice.ring] + 1;
xp_used = actor.rings[newChoice.ring] * CONFIG.l5r5e.xp.ringCostMultiplier;
}
if (newChoice.skill) {
skillCatId = CONFIG.l5r5e.skills.get(newChoice.skill);
actor.skills[skillCatId][newChoice.skill] = actor.skills[skillCatId][newChoice.skill] + 1;
xp_used = actor.skills[skillCatId][newChoice.skill] * CONFIG.l5r5e.xp.skillCostMultiplier;
}
// Update Actor
this.actor.update({
data: diffObject(this.actor.data.data, actor),
});
// Update object
this.object.update({
data: {
xp_used: xp_used,
},
});
// Re render
this.render(false);
}
}