diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index e54f2fa..fbb20d3 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -118,39 +118,11 @@ export class VermineActor extends Actor { } _setCharacterSelfControl() { - let self_control = 0; - - for(let i in this.system.abilities){ - if (this.system.abilities[i].category == 'mental' || this.system.abilities[i].category == 'social'){ - self_control += this.system.abilities[i].value; - } - } - /// gestion de l'age - if (this.system.identity.ageType == 1){ - self_control--; - } - - this.system.attributes.self_control.max = self_control; + this.system.attributes.self_control.max = 0 + Object.values(this.system.abilities).filter(i => i.category === "mental" || i.category === "social").map((i) => i.value).reduce((acc, curr) => acc + curr, 0) + this.modFromAgeSelfControl; } _setCharacterEffort() { - let effort = 0; - - // calcul de l'effort - for(let i in this.system.abilities){ - if (this.system.abilities[i].category == 'physical' || this.system.abilities[i].category == 'manual'){ - effort += this.system.abilities[i].value; - } - } - - /// gestion de l'age - if (this.system.identity.ageType == 1){ - effort--; - } else if (this.system.identity.ageType == 3){ - effort -= 2; - } - - this.system.attributes.effort.max = effort; + this.system.attributes.effort.max = 0 + Object.values(this.system.abilities).filter(i => i.category === "physical" || i.category === "manual").map((i) => i.value).reduce((acc, curr) => acc + curr, 0) + this.modFromAgeEffort; } _setCharacterThresholds() { @@ -160,22 +132,11 @@ export class VermineActor extends Actor { this.system.majorWound.threshold = health + 3; this.system.deadlyWound.threshold = (health + 7 < 11) ? health + 7 : 10; - let lightWounds = 4; - let heavyWounds = 3; - let deadlyWounds = 2; - - if (this.system.identity.ageType == 3){ - lightWounds--; - heavyWounds--; - deadlyWounds--; - } else if (this.system.identity.ageType == 1){ - deadlyWounds--; - } - - this.system.minorWound.max = lightWounds; - this.system.majorWound.max = heavyWounds; - this.system.deadlyWound.max = deadlyWounds; + this.system.minorWound.max = 4 + this.modFromAgeWounds.l; + this.system.majorWound.max = 3 + this.modFromAgeWounds.h; + this.system.deadlyWound.max = 2 + this.modFromAgeWounds.d; } + _setAgeType(){ Object.keys(CONFIG.VERMINE.AgeTypes).forEach((type) => { @@ -185,4 +146,24 @@ export class VermineActor extends Actor { }); } + get ageType() { + return this.system.identity.ageType; + } + + get modFromAgeSelfControl() { + return this.ageType == 1 ? -1 : 0; + } + + get modFromAgeEffort() { + if (this.ageType == 1) return -1; + if (this.ageType == 3) return -2; + return 0; + } + + get modFromAgeWounds() { + if (this.ageType == 1) return {l : 0, h : 0, d: -1}; + if (this.ageType == 3) return {l : -1, h : -1, d: -1}; + return {l : 0, h : 0, d: 0}; + } + } \ No newline at end of file diff --git a/module/sheets/actor-sheet.mjs b/module/sheets/actor-sheet.mjs index 2e4470b..6d8fbdc 100644 --- a/module/sheets/actor-sheet.mjs +++ b/module/sheets/actor-sheet.mjs @@ -121,75 +121,18 @@ export class VermineActorSheet extends ActorSheet { * @return {undefined} */ _prepareCharacterItems(context) { - // Initialize containers. - const gear = []; - const traits = []; - const defenses = []; - const specialties = []; - const abilities = []; - const weapons = []; - const evolutions = []; - const traumas = []; - const backgrounds = []; - const rumors = []; - - // Iterate through items, allocating to containers - for (let i of context.items) { - i.img = i.img || DEFAULT_TOKEN; - // Append to gear. - if (i.type === 'item') { - gear.push(i); - } - else if (i.type === 'trait') { - traits.push(i); - } - else if (i.type === 'defense') { - defenses.push(i); - } - else if (i.type === 'weapon') { - weapons.push(i); - } - else if (i.type === 'specialty') { - specialties.push(i); - } - else if (i.type === 'ability') { - abilities.push(i); - } - else if (i.type === 'evolution') { - evolutions.push(i); - } - else if (i.type === 'trauma') { - traumas.push(i); - } - else if (i.type === 'background') { - backgrounds.push(i); - } - else if (i.type === 'rumor') { - rumors.push(i); - } - /* // Append to cephalie. - else if (i.type === 'spell') { - if (i.system.spellLevel != undefined) { - cephalie[i.system.spellLevel].push(i); - } - }*/ + context.gear = this.actor.itemTypes['item']; + context.weapons = this.actor.itemTypes['weapon']; + context.defenses = this.actor.itemTypes['defense']; + context.traits = this.actor.itemTypes['trait']; + context.specialties = this.actor.itemTypes['specialty']; + context.abilities = this.actor.itemTypes['ability']; + context.evolutions = this.actor.itemTypes['evolution']; + context.traumas = this.actor.itemTypes['trauma']; + context.backgrounds = this.actor.itemTypes['background']; + context.rumors = this.actor.itemTypes['rumor']; } - // Assign and return - context.gear = gear; - context.weapons = weapons; - context.defenses = defenses; - context.traits = traits; - context.specialties = specialties; - context.abilities = abilities; - context.evolutions = evolutions; - context.traumas = traumas; - context.backgrounds = backgrounds; - context.rumors = rumors; - // console.log("context", context); - } - - /** * Organize and classify Items for Npc sheets. * @@ -198,27 +141,8 @@ export class VermineActorSheet extends ActorSheet { * @return {undefined} */ _prepareNpcItems(context) { - // Initialize containers. - const gear = []; - const traits = []; - - - // Iterate through items, allocating to containers - for (let i of context.items) { - i.img = i.img || DEFAULT_TOKEN; - // Append to gear. - if (i.type === 'item') { - gear.push(i); - } - else if (i.type === 'trait') { - traits.push(i); - } - - - } - - // Assign and return - context.gear = gear; + context.gear = this.actor.itemTypes['item']; + context.traits = this.actor.itemTypes['trait']; } @@ -231,49 +155,14 @@ export class VermineActorSheet extends ActorSheet { * @return {undefined} */ _prepareGroupItems(context) { - // Initialize containers. - const gear = []; - const defenses = []; - const abilities = []; - const totem_abilities = []; - const weapons = []; - const vehicles = []; + context.gear = this.actor.itemTypes['item']; + context.weapons = this.actor.itemTypes['weapon']; + context.defenses = this.actor.itemTypes['defense']; + context.vehicles = this.actor.itemTypes['vehicle']; - // Iterate through items, allocating to containers - for (let i of context.items) { - i.img = i.img || DEFAULT_TOKEN; - // Append to gear. - if (i.type === 'item') { - gear.push(i); - } - else if (i.type === 'defense') { - defenses.push(i); - } - else if (i.type === 'weapon') { - weapons.push(i); - } - else if (i.type === 'ability') { - if (i.system.type == 'totem'){ - totem_abilities.push(i); - } else { - abilities.push(i); - } - - } - else if (i.type === 'vehicle') { - vehicles.push(i); - } + context.totem_abilities = this.actor.itemTypes['ability'].filter(i=>i.type !== 'totem'); + context.abilities = this.actor.itemTypes['ability'].filter(i=>i.type === 'totem'); - - } - - // Assign and return - context.gear = gear; - context.weapons = weapons; - context.defenses = defenses; - context.abilities = abilities; - context.totem_abilities = totem_abilities; - context.vehicles = vehicles; } /** @@ -284,29 +173,11 @@ export class VermineActorSheet extends ActorSheet { * @return {undefined} */ _prepareCreatureItems(context) { - // Initialize containers. - const gear = []; - const traits = []; - - - // Iterate through items, allocating to containers - for (let i of context.items) { - i.img = i.img || DEFAULT_TOKEN; - // Append to gear. - if (i.type === 'item') { - gear.push(i); - } - else if (i.type === 'trait') { - traits.push(i); - } - - - } - - // Assign and return - context.gear = gear; - + context.gear = this.actor.itemTypes['item']; + context.traits = this.actor.itemTypes['trait']; } + + async _onItemCreate(event) { event.preventDefault(); const header = event.currentTarget;