2020-11-28 19:12:19 +01:00
|
|
|
export default class KHHooks {
|
|
|
|
static async onCreateActor(actor, options, userId) {
|
|
|
|
if (actor.data.type == "character") {
|
2020-11-30 06:23:35 +01:00
|
|
|
// Load Skills Compendium skills
|
|
|
|
let skillIndex;
|
|
|
|
let actorbaseSkills;
|
|
|
|
|
|
|
|
if(game.settings.get("kopparhavet", "gameSystem") === "hjaltarnas-tid") {
|
2020-12-01 17:30:39 +01:00
|
|
|
// Set currency name
|
|
|
|
actor.update({ "data.currency.shekel.label": "CURRENCY.SILVER" });
|
|
|
|
|
2020-11-30 06:23:35 +01:00
|
|
|
actorbaseSkills = CONFIG.KH.baseSkillsHT
|
2021-07-28 13:08:19 +02:00
|
|
|
skillIndex = await game.packs.get("kopparhavet.skills-ht").getDocuments();
|
2020-11-30 06:23:35 +01:00
|
|
|
} else {
|
|
|
|
actorbaseSkills = CONFIG.KH.baseSkills;
|
2021-07-28 13:08:19 +02:00
|
|
|
skillIndex = await game.packs.get("kopparhavet.skills").getDocuments();
|
2020-11-30 06:23:35 +01:00
|
|
|
}
|
2020-11-28 19:12:19 +01:00
|
|
|
|
|
|
|
// Check if skill already exists by some chance
|
|
|
|
const existingSkills = actor.items.filter((i) => i.type === ItemType.Skill).map((i) => i.name);
|
|
|
|
const skillsToAdd = actorbaseSkills.filter((s) => !existingSkills.includes(s));
|
|
|
|
|
|
|
|
// Filter skillIndex array to include only skills for Actor Type.
|
|
|
|
let _skillsList = skillIndex.filter((i) => skillsToAdd.includes(i.data.name));
|
|
|
|
|
2021-07-28 13:08:19 +02:00
|
|
|
let _sl = [];
|
|
|
|
_skillsList.forEach((s) => {
|
|
|
|
//s.data._source.data["creatureType"] = actor.data.type;
|
|
|
|
//s.data._source.data["coreSkill"] = true;
|
|
|
|
_sl.push(s.data);
|
|
|
|
});
|
|
|
|
|
|
|
|
await actor.createEmbeddedDocuments("Item", _sl);
|
|
|
|
//await actor.createEmbeddedDocuments("Item", [_skillsList.toObject()]);
|
2020-11-28 19:12:19 +01:00
|
|
|
} else {
|
|
|
|
setTimeout(async function () {
|
|
|
|
await actor.sheet.render(true);
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|