Skip to content

Commit

Permalink
fix: Support for cascade skills (only Animals so far, will add for al…
Browse files Browse the repository at this point in the history
…l soon)

Changed default characteristic to 7 (average)
  • Loading branch information
xdy committed Aug 22, 2020
1 parent ec3914d commit b21ea51
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/module/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function registerHandlebarsHelpers():void {
});

Handlebars.registerHelper('checkPsi', function (characteristic) {
if (!game.user.isGM && characteristic.shortlabel === 'PSI' && characteristic.value === 0) {
if (!game.user.isGM && characteristic.shortLabel === 'PSI' && characteristic.value === 0) {
return false;
}
return true;
Expand Down
54 changes: 44 additions & 10 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,43 @@ export class TwodsixActorSheet extends ActorSheet {
const data = actorData.data;
const matchingSkill = data.skills[skillName];
const maxSkillLevel = game.settings.get('twodsix', 'maxSkillLevel');
if (matchingSkill && !matchingSkill.trained) {
this.actor.update({[`data.skills.${skillName}.value`]: 0})
this.actor.update({[`data.skills.${skillName}.trained`]: true})
} else if (matchingSkill && matchingSkill.value < maxSkillLevel) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value + 1})

if (matchingSkill) {
if (TwodsixActorSheet.isChildSkill(matchingSkill)) {
if (this.parentSkillIsTrained(matchingSkill) && matchingSkill.value < maxSkillLevel) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value + 1})
}
} else if (!matchingSkill.trained) {
this.actor.update({[`data.skills.${skillName}.value`]: 0})
this.actor.update({[`data.skills.${skillName}.trained`]: true})
if (matchingSkill.hasChildren) {
this.processChildren(data, skillName, 0, true);
}
} else if (!matchingSkill.hasChildren && matchingSkill.value < maxSkillLevel) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value + 1})
}
}
}

private processChildren(data:any, skillName:string, level:number, trained:boolean) {
for (const [key, value] of Object.entries(data.skills)) {
if (key.startsWith(skillName + "-")) {
this.actor.update({[`data.skills.${key}.value`]: level})
this.actor.update({[`data.skills.${key}.trained`]: trained})
console.log(`${key}: ${value["label"]}`);
}
}
}

private static isChildSkill(matchingSkill:any) {
return matchingSkill.childOf === "";
}

private parentSkillIsTrained(matchingSkill:any) {
const parent = this.actor.data.data.skills[matchingSkill.childOf];
return parent.trained && matchingSkill.childOf === parent.label;
}

/**
* Handle skill downgrade
* @param {Event} event The originating click event
Expand All @@ -206,11 +235,16 @@ export class TwodsixActorSheet extends ActorSheet {
const actorData = this.actor.data;
const data = actorData.data;
const matchingSkill = data.skills[skillName];
if (matchingSkill && matchingSkill.trained && data.skills[skillName].value == 0) {
this.actor.update({[`data.skills.${skillName}.value`]: -3})
this.actor.update({[`data.skills.${skillName}.trained`]: false})
} else if (matchingSkill && matchingSkill.trained) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value - 1})
if (matchingSkill) {
if (matchingSkill.trained && data.skills[skillName].value === 0) {
this.actor.update({[`data.skills.${skillName}.value`]: -3})
this.actor.update({[`data.skills.${skillName}.trained`]: false})
if (matchingSkill.hasChildren) {
this.processChildren(data, skillName, -3, false);
}
} else if (matchingSkill.trained) {
this.actor.update({[`data.skills.${skillName}.value`]: data.skills[skillName].value - 1})
}
}
}
}
Expand Down
56 changes: 37 additions & 19 deletions static/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"traveller"
],
"traveller": {
"name": "name",
"name": "",
"homeWorld": "",
"species": "",
"age": {
Expand All @@ -23,46 +23,46 @@
"bio": "",
"characteristics": {
"strength": {
"value": 0,
"value": 7,
"damage": 0,
"label": "Strength",
"shortlabel": "STR"
"shortLabel": "STR"
},
"dexterity": {
"value": 0,
"value": 7,
"damage": 0,
"label": "Dexterity",
"shortlabel": "DEX"
"shortLabel": "DEX"
},
"endurance": {
"value": 0,
"value": 7,
"damage": 0,
"label": "Endurance",
"shortlabel": "END"
"shortLabel": "END"
},
"intellect": {
"value": 0,
"value": 7,
"damage": 0,
"label": "Intellect",
"shortlabel": "INT"
"shortLabel": "INT"
},
"education": {
"value": 0,
"value": 7,
"damage": 0,
"label": "Education",
"shortlabel": "EDU"
"shortLabel": "EDU"
},
"social": {
"value": 0,
"value": 7,
"damage": 0,
"label": "Social",
"shortlabel": "SOC"
"shortLabel": "SOC"
},
"psionics": {
"value": 0,
"value": 7,
"damage": 0,
"label": "Psionics",
"shortlabel": "PSI"
"shortLabel": "PSI"
}
},
"jackOfAllTrades": {
Expand All @@ -82,29 +82,47 @@
"trained": false,
"characteristic": "strength"
},
"animals": {
"label": "Animals",
"value": -3,
"trained": false,
"characteristic": "strength",
"hasChildren": true
},
"animals-handling": {
"label": "Animals (Handling)",
"value": -3,
"trained": false,
"characteristic": "strength"
"characteristic": "strength",
"childOf": "animals"
},
"animals-training": {
"label": "Animals (Training)",
"value": -3,
"trained": false,
"characteristic": "strength"
"characteristic": "strength",
"childOf": "animals"
},
"animals-veterinary": {
"label": "Animals (Veterinary)",
"value": -3,
"trained": false,
"characteristic": "strength"
"characteristic": "strength",
"childOf": "animals"
},
"art": {
"label": "Art (Performer)",
"value": -3,
"trained": false,
"characteristic": "strength",
"hasChildren": true
},
"art-performer": {
"label": "Art (Performer)",
"value": -3,
"trained": false,
"characteristic": "strength"
"characteristic": "strength",
"childOf": "art"
},
"art-holography": {
"label": "Art (Holography)",
Expand Down
15 changes: 8 additions & 7 deletions static/templates/actors/actor-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,56 @@

<div class="character-characteristics">
<div class="stat str">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.strength.mod}}">STR <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll attribute"/></span>
<span class="stat-name">STR
<img class="rollable" data-roll="2d6+{{data.characteristics.strength.mod}}" src="./systems/twodsix/assets/d6-icon.svg" data-label="{{data.characteristics.strength.shortLabel}}" alt="roll strength"/></span>
<span class="stat-ability"><input type="number" min="0" name="data.characteristics.strength.value" data-label="data.characteristics.strength.value" value="{{data.characteristics.strength.value}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
<span class="stat-modifier"><input readonly type="text" value="{{numberFormat data.characteristics.strength.mod decimals=0 sign=true}}"/></span>
<span class="stat-damage"><input type="number" max="{{data.characteristics.strength.value}}" min="0" name="data.characteristics.strength.damage" value="{{data.characteristics.strength.damage}}" placeholder="0" data-dtype="Number"
onClick="this.select();"/></span>
</div>
<div class="stat dex">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.dexterity.mod}}">DEX <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll attribute"/></span>
<span class="stat-name">DEX <img class="rollable" data-roll="2d6+{{data.characteristics.dexterity.mod}}" src="./systems/twodsix/assets/d6-icon.svg" data-label="{{data.characteristics.dexterity.shortLabel}}" alt="roll dexterity"/></span>
<span class="stat-ability"><input type="number" min="0" name="data.characteristics.dexterity.value" data-label="data.characteristics.dexterity.value" value="{{data.characteristics.dexterity.value}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
<span class="stat-modifier"><input readonly type="text" value="{{numberFormat data.characteristics.dexterity.mod decimals=0 sign=true}}"/></span>
<span class="stat-damage"><input type="number" max="{{data.characteristics.dexterity.value}}" min="0" name="data.characteristics.dexterity.damage" value="{{data.characteristics.dexterity.damage}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
</div>
<div class="stat end">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.endurance.mod}}">END <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll attribute"/></span>
<span class="stat-name">END <img class="rollable" data-roll="2d6+{{data.characteristics.endurance.mod}}" src="./systems/twodsix/assets/d6-icon.svg" data-label="{{data.characteristics.endurance.shortLabel}}" alt="roll endurance"/></span>
<span class="stat-ability"><input type="number" min="0" name="data.characteristics.endurance.value" data-label="data.characteristics.endurance.value" value="{{data.characteristics.endurance.value}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
<span class="stat-modifier"><input readonly type="text" value="{{numberFormat data.characteristics.endurance.mod decimals=0 sign=true}}"/></span>
<span class="stat-damage"><input type="number" max="{{data.characteristics.endurance.value}}" min="0" name="data.characteristics.endurance.damage" value="{{data.characteristics.endurance.damage}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
</div>
<div class="stat int">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.intellect.mod}}">INT <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll attribute"/></span>
<span class="stat-name">INT <img class="rollable" data-roll="2d6+{{data.characteristics.intellect.mod}}" src="./systems/twodsix/assets/d6-icon.svg" data-label="{{data.characteristics.intellect.shortLabel}}" alt="roll intellect"/></span>
<span class="stat-ability"><input type="number" min="0" name="data.characteristics.intellect.value" data-label="data.characteristics.intellect.value" value="{{data.characteristics.intellect.value}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
<span class="stat-modifier"><input readonly type="text" value="{{numberFormat data.characteristics.intellect.mod decimals=0 sign=true}}"/></span>
<span class="stat-damage"><input type="number" max="{{data.characteristics.intellect.value}}" min="0" name="data.characteristics.intellect.damage" value="{{data.characteristics.intellect.damage}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
</div>
<div class="stat edu">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.education.mod}}">EDU <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll attribute"/></span>
<span class="stat-name">EDU <img class="rollable" data-roll="2d6+{{data.characteristics.education.mod}}" src="./systems/twodsix/assets/d6-icon.svg" data-label="{{data.characteristics.education.shortLabel}}" alt="roll education"/></span>
<span class="stat-ability"><input type="number" min="0" name="data.characteristics.education.value" data-label="data.characteristics.education.value" value="{{data.characteristics.education.value}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
<span class="stat-modifier"><input readonly type="text" value="{{numberFormat data.characteristics.education.mod decimals=0 sign=true}}"/></span>
<span class="stat-damage"><input type="number" max="{{data.characteristics.education.value}}" min="0" name="data.characteristics.education.damage" value="{{data.characteristics.education.damage}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
</div>
<div class="stat soc">
<span class="stat-name rollable" data-roll="2d6+{{data.characteristics.social.mod}}">SOC <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll attribute"/></span>
<span class="stat-name">SOC <img class="rollable" data-roll="2d6+{{data.characteristics.social.mod}}" src="./systems/twodsix/assets/d6-icon.svg" data-label="{{data.characteristics.social.shortLabel}}" alt="roll social"/></span>
<span class="stat-ability"><input type="number" min="0" name="data.characteristics.social.value" data-label="data.characteristics.social.value" value="{{data.characteristics.social.value}}" placeholder="0" data-dtype="Number"
onClick="this.select();"/></span>
<span class="stat-modifier"><input readonly type="text" value="{{numberFormat data.characteristics.social.mod decimals=0 sign=true}}"/></span>
<span class="stat-damage"><input type="number" max="{{data.characteristics.social.value}}" min="0" name="data.characteristics.social.damage" value="{{data.characteristics.social.damage}}" placeholder="0" data-dtype="Number"
onClick="this.select();"/></span>
</div>
<div class="special psi">
<span class="special-name rollable" data-roll="2d6+{{data.characteristics.psionics.mod}}">PSI <img src="./systems/twodsix/assets/d6-icon.svg" alt="roll attribute"/></span>
<span class="special-name">PSI <img class="rollable" data-roll="2d6+{{data.psionics.strength.mod}}" src="./systems/twodsix/assets/d6-icon.svg" data-label="{{data.characteristics.psionics.shortLabel}}" alt="roll psionics"/></span>
<span class="special-ability"><input type="number" min="0" name="data.characteristics.psionics.value" data-label="data.characteristics.psionics.value" value="{{data.characteristics.psionics.value}}" placeholder="0"
data-dtype="Number" onClick="this.select();"/></span>
<span class="special-damage"><input type="number" max="{{data.characteristics.psionics.value}}" min="0" name="data.characteristics.psionics.damage" value="{{data.characteristics.psionics.damage}}" placeholder="0"
Expand Down

0 comments on commit b21ea51

Please sign in to comment.