Working on Skills and some fixes

- Added Skills to character sheet
- Added migration to old skills
- Added icon on skills
- Added actor.isNpc
- Money out of system
This commit is contained in:
Vlyan
2023-01-08 15:12:22 +01:00
parent 1ec9e65ca5
commit 710afd9804
22 changed files with 302 additions and 145 deletions

View File

@@ -16,66 +16,96 @@ export class ActorL5r5e extends Actor {
docData.img = `${CONFIG.l5r5e.paths.assets}icons/actors/${docData.type}.svg`;
}
// Some tweak on actors prototypeToken
docData.prototypeToken = docData.prototypeToken || {};
switch (docData.type) {
case "character":
foundry.utils.mergeObject(
docData.prototypeToken,
{
// vision: true,
// dimSight: 30,
// brightSight: 0,
actorLink: true,
disposition: 1, // friendly
bar1: {
attribute: "fatigue",
},
bar2: {
attribute: "strife",
},
},
{ overwrite: false }
);
break;
// Only for new actors (New actor has no items, duplicates does)
if (!docData.items) {
// Some tweak on actors prototypeToken
docData.prototypeToken = docData.prototypeToken || {};
switch (docData.type) {
case "character":
// Load skills from core compendiums (only for pc character)
docData.items = [];
await ActorL5r5e.addSkillsFromCompendiums(docData);
case "npc":
foundry.utils.mergeObject(
docData.prototypeToken,
{
actorLink: true,
disposition: 0, // neutral
bar1: {
attribute: "fatigue",
// Set token properties
foundry.utils.mergeObject(
docData.prototypeToken,
{
// vision: true,
// dimSight: 30,
// brightSight: 0,
actorLink: true,
disposition: 1, // friendly
bar1: {
attribute: "fatigue",
},
bar2: {
attribute: "strife",
},
},
bar2: {
attribute: "strife",
},
},
{ overwrite: false }
);
break;
{ overwrite: false }
);
break;
case "army":
foundry.utils.mergeObject(
docData.prototypeToken,
{
actorLink: true,
disposition: 0, // neutral
bar1: {
attribute: "battle_readiness.casualties_strength",
case "npc":
foundry.utils.mergeObject(
docData.prototypeToken,
{
actorLink: true,
disposition: 0, // neutral
bar1: {
attribute: "fatigue",
},
bar2: {
attribute: "strife",
},
},
bar2: {
attribute: "battle_readiness.panic_discipline",
{ overwrite: false }
);
break;
case "army":
foundry.utils.mergeObject(
docData.prototypeToken,
{
actorLink: true,
disposition: 0, // neutral
bar1: {
attribute: "battle_readiness.casualties_strength",
},
bar2: {
attribute: "battle_readiness.panic_discipline",
},
},
},
{ overwrite: false }
);
break;
{ overwrite: false }
);
break;
}
}
await super.create(docData, options);
}
/**
* Add all the skills from compendiums to "items"
*/
static async addSkillsFromCompendiums(docData) {
console.log(`L5R5E | Adding skills to ${docData.name}`);
const packName = CONFIG.l5r5e.systemName + ".core-skills";
const skills = await game.l5r5e.HelpersL5r5e.loadCompendium(packName);
if (skills.length < 1) {
console.log(`L5R5E | No items found in Pack [${packName}]`);
return;
}
// Get the json data and replace the object id
skills.forEach(item => {
const tmpData = item.toObject();
tmpData._id = foundry.utils.randomID();
docData.items.push(tmpData);
});
}
/**
* Entity-specific actions that should occur when the Entity is updated
* @override
@@ -94,7 +124,7 @@ export class ActorL5r5e extends Actor {
context.pack = this.pack;
// NPC switch between types : Linked actor for Adversary, unlinked for Minion
if (!!docData["system.type"] && this.type === "npc" && docData["system.type"] !== this.system.type) {
if (!!docData["system.type"] && this.isNpc && docData["system.type"] !== this.system.type) {
docData["prototypeToken.actorLink"] = docData["system.type"] === "adversary";
}
@@ -254,12 +284,20 @@ export class ActorL5r5e extends Actor {
return this.type === "character";
}
/**
* Return true if this actor is a NPC
* @return {boolean}
*/
get isNpc() {
return this.type === "npc";
}
/**
* Return true if this actor is an Adversary
* @return {boolean}
*/
get isAdversary() {
return this.type === "npc" && this.system.type === "adversary";
return this.isNpc && this.system.type === "adversary";
}
/**
@@ -267,7 +305,7 @@ export class ActorL5r5e extends Actor {
* @return {boolean}
*/
get isMinion() {
return this.type === "npc" && this.system.type === "minion";
return this.isNpc && this.system.type === "minion";
}
/**
@@ -363,7 +401,7 @@ export class ActorL5r5e extends Actor {
if (!this.isCharacterType) {
return null;
}
return this.type === "npc" ? this.system.conflict_rank.social : this.system.identity.school_rank;
return this.isNpc ? this.system.conflict_rank.social : this.system.identity.school_rank;
}
/**
@@ -374,6 +412,6 @@ export class ActorL5r5e extends Actor {
if (!this.isCharacterType) {
return null;
}
return this.type === "npc" ? this.system.conflict_rank.martial : this.system.identity.school_rank;
return this.isNpc ? this.system.conflict_rank.martial : this.system.identity.school_rank;
}
}