converting advancement to dynamic list skills
This commit is contained in:
@@ -216,38 +216,51 @@ export class ActorL5r5e extends Actor {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _updateActorFromAdvancement(item, isAdd) {
|
async _updateActorFromAdvancement(item, isAdd) {
|
||||||
if (item && item.type === "advancement") {
|
if (!item || item.type !== "advancement") {
|
||||||
const actor = foundry.utils.duplicate(this.system);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const actorSystem = foundry.utils.duplicate(this.system);
|
||||||
const itemData = item.system;
|
const itemData = item.system;
|
||||||
if (itemData.advancement_type === "ring") {
|
if (itemData.advancement_type === "ring") {
|
||||||
// Ring
|
// Ring
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
actor.rings[itemData.ring] = Math.min(9, actor.rings[itemData.ring] + 1);
|
actorSystem.rings[itemData.ring] = Math.min(9, actorSystem.rings[itemData.ring] + 1);
|
||||||
} else {
|
} else {
|
||||||
actor.rings[itemData.ring] = Math.max(1, actor.rings[itemData.ring] - 1);
|
actorSystem.rings[itemData.ring] = Math.max(1, actorSystem.rings[itemData.ring] - 1);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Skill
|
|
||||||
const skillCatId = CONFIG.l5r5e.skills.get(itemData.skill);
|
|
||||||
if (skillCatId) {
|
|
||||||
if (isAdd) {
|
|
||||||
actor.skills[skillCatId][itemData.skill] = Math.min(
|
|
||||||
9,
|
|
||||||
actor.skills[skillCatId][itemData.skill] + 1
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
actor.skills[skillCatId][itemData.skill] = Math.max(
|
|
||||||
0,
|
|
||||||
actor.skills[skillCatId][itemData.skill] - 1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Actor
|
// Update Actor
|
||||||
await this.update({
|
await this.update({
|
||||||
system: foundry.utils.diffObject(this.system, actor),
|
system: foundry.utils.diffObject(this.system, actorSystem),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Skill
|
||||||
|
let skillItem = await fromUuid(itemData.skill); // Skill itemUuid
|
||||||
|
if (!skillItem) {
|
||||||
|
console.warn("L5R5E | Unknown skill item uuid", itemData.skill);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Out of actor item ?
|
||||||
|
if (!skillItem.actor || skillItem.actor._id !== this._id) {
|
||||||
|
const checkItem = this.items.getName(skillItem.name);
|
||||||
|
if (checkItem) {
|
||||||
|
skillItem = checkItem;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unable to find "${skillItem.name}" on this actor`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newRank = isAdd
|
||||||
|
? Math.min(9, skillItem.system.rank + 1)
|
||||||
|
: Math.max(0, skillItem.system.rank - 1);
|
||||||
|
if (skillItem.system.rank === newRank) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Item
|
||||||
|
await skillItem.update({ "system.rank": newRank });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
|
|||||||
* @param {DragEvent} event
|
* @param {DragEvent} event
|
||||||
*/
|
*/
|
||||||
async _onDrop(event) {
|
async _onDrop(event) {
|
||||||
|
try {
|
||||||
// *** Everything below here is only needed if the sheet is editable ***
|
// *** Everything below here is only needed if the sheet is editable ***
|
||||||
if (!this.isEditable || this.actor.system.soft_locked) {
|
if (!this.isEditable || this.actor.system.soft_locked) {
|
||||||
console.log("L5R5E | This sheet is not editable");
|
console.log("L5R5E | This sheet is not editable");
|
||||||
@@ -211,7 +212,7 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
case "advancement":
|
case "advancement":
|
||||||
// Specific advancements, remove 1 to selected ring/skill
|
// Specific advancements, add x to selected ring/skill
|
||||||
await this.actor.addBonus(item);
|
await this.actor.addBonus(item);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -273,6 +274,10 @@ export class BaseCharacterSheetL5r5e extends BaseSheetL5r5e {
|
|||||||
|
|
||||||
// Finally create the embed
|
// Finally create the embed
|
||||||
return this.actor.createEmbeddedDocuments("Item", [itemData]);
|
return this.actor.createEmbeddedDocuments("Item", [itemData]);
|
||||||
|
|
||||||
|
} catch (ex) {
|
||||||
|
console.warn("L5R5E |", ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ L5R5E.techniques.set("title_ability", { type: "title", displayInTypes: false });
|
|||||||
L5R5E.techniques.set("specificity", { type: "custom", displayInTypes: false });
|
L5R5E.techniques.set("specificity", { type: "custom", displayInTypes: false });
|
||||||
|
|
||||||
// *** SkillId - CategoryId ***
|
// *** SkillId - CategoryId ***
|
||||||
// TODO @deprecated hardcoded skills
|
// Hardcoded skills are still required for compatibility (migration & olds worlds)
|
||||||
L5R5E.skills = new Map();
|
L5R5E.skills = new Map();
|
||||||
L5R5E.skills.set("aesthetics", "artisan");
|
L5R5E.skills.set("aesthetics", "artisan");
|
||||||
L5R5E.skills.set("composition", "artisan");
|
L5R5E.skills.set("composition", "artisan");
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ export class HelpersL5r5e {
|
|||||||
* @return {{cat: any, id: any, label: *}[]}
|
* @return {{cat: any, id: any, label: *}[]}
|
||||||
*/
|
*/
|
||||||
static getSkillsList(useGroup = false) {
|
static getSkillsList(useGroup = false) {
|
||||||
console.warn('@deprecated hardcoded skills - helpers.getSkillsList()'); // TODO @deprecated hardcoded skills
|
console.warn('@deprecated hardcoded skills - helpers.getSkillsList() - Use getSkillsItemsList() + splitSkillByCategory() instead'); // TODO @deprecated hardcoded skills
|
||||||
|
|
||||||
if (!useGroup) {
|
if (!useGroup) {
|
||||||
return Array.from(CONFIG.l5r5e.skills).map(([id, cat]) => ({
|
return Array.from(CONFIG.l5r5e.skills).map(([id, cat]) => ({
|
||||||
|
|||||||
@@ -242,7 +242,11 @@ export class ItemL5r5e extends Item {
|
|||||||
if (addBonusToActor) {
|
if (addBonusToActor) {
|
||||||
const actor = this.actor;
|
const actor = this.actor;
|
||||||
if (item instanceof Item && actor instanceof Actor) {
|
if (item instanceof Item && actor instanceof Actor) {
|
||||||
actor.addBonus(item);
|
try {
|
||||||
|
await actor.addBonus(item);
|
||||||
|
} catch (ex) {
|
||||||
|
console.warn("L5R5E |", ex.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
|
|||||||
const sheetData = await super.getData(options);
|
const sheetData = await super.getData(options);
|
||||||
|
|
||||||
sheetData.data.subTypesList = AdvancementSheetL5r5e.types;
|
sheetData.data.subTypesList = AdvancementSheetL5r5e.types;
|
||||||
sheetData.data.skillsList = game.l5r5e.HelpersL5r5e.getSkillsList(true);
|
sheetData.data.skillsList = game.l5r5e.HelpersL5r5e.splitSkillByCategory(await game.l5r5e.HelpersL5r5e.getSkillsItemsList(this.actor));
|
||||||
|
|
||||||
return sheetData;
|
return sheetData;
|
||||||
}
|
}
|
||||||
@@ -82,33 +82,45 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
|
|||||||
let name = this.object.name;
|
let name = this.object.name;
|
||||||
let img = this.object.img;
|
let img = this.object.img;
|
||||||
|
|
||||||
|
const getLocalItemByUuid = async (uuid) => {
|
||||||
|
const item = await fromUuid(uuid);
|
||||||
|
if (!item) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (item?.actor?._id === this.actor._id) {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
return this.items.getName(item.name);
|
||||||
|
}
|
||||||
|
const skillItemNew = newChoice.skill ? (await getLocalItemByUuid(newChoice.skill)) : null;
|
||||||
|
const skillItemOld = oldChoice.skill ? (await getLocalItemByUuid(oldChoice.skill)) : null;
|
||||||
|
|
||||||
// Modify image to reflect choice
|
// Modify image to reflect choice
|
||||||
if (newChoice.ring) {
|
if (newChoice.ring) {
|
||||||
name = game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) + "+1";
|
name = game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) + "+1";
|
||||||
img = `systems/l5r5e/assets/icons/rings/${newChoice.ring}.svg`;
|
img = `systems/l5r5e/assets/icons/rings/${newChoice.ring}.svg`;
|
||||||
} else if (newChoice.skill) {
|
|
||||||
name =
|
} else if (newChoice.skill && skillItemNew) {
|
||||||
game.i18n.localize(`l5r5e.skills.${CONFIG.l5r5e.skills.get(newChoice.skill)}.${newChoice.skill}`) +
|
name = skillItemNew.name +"+1";
|
||||||
"+1";
|
|
||||||
img = `systems/l5r5e/assets/dices/default/skill_blank.svg`;
|
img = `systems/l5r5e/assets/dices/default/skill_blank.svg`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object embed in actor ?
|
// Object embed in actor ?
|
||||||
const actor = this.document.actor;
|
const actor = this.document.actor;
|
||||||
if (actor) {
|
if (actor) {
|
||||||
|
if (newChoice.skill && !skillItemNew.actor) {
|
||||||
|
ui.notifications.warn(`Unable to find "${skillItemNew?.name}" on this actor`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const actorData = foundry.utils.duplicate(actor.system);
|
const actorData = foundry.utils.duplicate(actor.system);
|
||||||
let skillCatId = null;
|
|
||||||
|
|
||||||
// Old choices
|
// Old choices
|
||||||
if (oldChoice.ring) {
|
if (oldChoice.ring) {
|
||||||
actorData.rings[oldChoice.ring] = Math.max(1, actorData.rings[oldChoice.ring] - 1);
|
actorData.rings[oldChoice.ring] = Math.max(1, actorData.rings[oldChoice.ring] - 1);
|
||||||
}
|
}
|
||||||
if (oldChoice.skill) {
|
if (oldChoice.skill && skillItemOld) {
|
||||||
skillCatId = CONFIG.l5r5e.skills.get(oldChoice.skill);
|
await skillItemOld.update({ "system.rank": Math.max(0, skillItemOld.system.rank - 1) });
|
||||||
actorData.skills[skillCatId][oldChoice.skill] = Math.max(
|
|
||||||
0,
|
|
||||||
actorData.skills[skillCatId][oldChoice.skill] - 1
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// new choices
|
// new choices
|
||||||
@@ -119,15 +131,11 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
|
|||||||
game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) +
|
game.i18n.localize(`l5r5e.rings.${newChoice.ring}`) +
|
||||||
` +1 (${actorData.rings[newChoice.ring] - 1} -> ${actorData.rings[newChoice.ring]})`;
|
` +1 (${actorData.rings[newChoice.ring] - 1} -> ${actorData.rings[newChoice.ring]})`;
|
||||||
}
|
}
|
||||||
if (newChoice.skill) {
|
if (newChoice.skill && skillItemNew) {
|
||||||
skillCatId = CONFIG.l5r5e.skills.get(newChoice.skill);
|
const newRank = Math.min(9, skillItemNew.system.rank + 1);
|
||||||
actorData.skills[skillCatId][newChoice.skill] = actorData.skills[skillCatId][newChoice.skill] + 1;
|
await skillItemNew.update({ "system.rank": newRank });
|
||||||
xp_used = actorData.skills[skillCatId][newChoice.skill] * CONFIG.l5r5e.xp.skillCostMultiplier;
|
xp_used = newRank * CONFIG.l5r5e.xp.skillCostMultiplier;
|
||||||
name =
|
name = `${skillItemNew.name} +1 (${newRank - 1} -> ${newRank})`;
|
||||||
game.i18n.localize(`l5r5e.skills.${skillCatId}.${newChoice.skill}`) +
|
|
||||||
` +1 (${actorData.skills[skillCatId][newChoice.skill] - 1} -> ${
|
|
||||||
actorData.skills[skillCatId][newChoice.skill]
|
|
||||||
})`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Actor
|
// Update Actor
|
||||||
@@ -141,7 +149,7 @@ export class AdvancementSheetL5r5e extends ItemSheetL5r5e {
|
|||||||
name: name,
|
name: name,
|
||||||
img: img,
|
img: img,
|
||||||
system: {
|
system: {
|
||||||
xp_used: xp_used,
|
xp_used,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -160,18 +160,6 @@ export class TechniqueSheetL5r5e extends ItemSheetL5r5e {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// List skill (not include in cat)
|
return [...unqCatList];
|
||||||
const unqSkillList = new Set();
|
|
||||||
skillList.forEach((s) => {
|
|
||||||
s = s?.trim();
|
|
||||||
if (!!s && CONFIG.l5r5e.skills.has(s)) {
|
|
||||||
const cat = CONFIG.l5r5e.skills.get(s);
|
|
||||||
if (!unqCatList.has(cat)) {
|
|
||||||
unqSkillList.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return [...unqCatList, ...unqSkillList];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
{{#each data.skillsList as |skills catId|}}
|
{{#each data.skillsList as |skills catId|}}
|
||||||
<optgroup label="{{localizeSkill catId 'title'}}">
|
<optgroup label="{{localizeSkill catId 'title'}}">
|
||||||
{{#each skills as |obj|}}
|
{{#each skills as |obj|}}
|
||||||
<option value="{{obj.id}}">{{obj.label}}</option>
|
<option value="{{obj.uuid}}">{{obj.name}}</option>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
Reference in New Issue
Block a user