Merge pull request 'Adds Rollable Attributes' (#37) from feature/rollable-character-attributes into main
Reviewed-on: #37pull/13/head
commit
454faf8fe6
|
|
@ -43,7 +43,8 @@ export class PlayerCharacterDataModel extends foundry.abstract.TypeDataModel {
|
||||||
so: new NumberField({ required: true, integer: true }),
|
so: new NumberField({ required: true, integer: true }),
|
||||||
gilde: new StringField(),
|
gilde: new StringField(),
|
||||||
}),
|
}),
|
||||||
talente: new ArrayField ( new ForeignDocumentField(Item) ),
|
talente: new ArrayField ( new SchemaField(
|
||||||
|
{taw: new NumberField(), talent: new ForeignDocumentField(Item) })),
|
||||||
zauber: new ArrayField ( new ForeignDocumentField(Item) ),
|
zauber: new ArrayField ( new ForeignDocumentField(Item) ),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,4 +53,49 @@ export class PlayerCharacterDataModel extends foundry.abstract.TypeDataModel {
|
||||||
super._initialize(options);
|
super._initialize(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onCreate(data, options, userId) {
|
||||||
|
// prepare base talents
|
||||||
|
const talentsByName = [
|
||||||
|
"Athletik", "Klettern", "Körperbeherrschung", "Schleichen", "Schwimmen", "Selbstbeherrschung", "Sich Verstecken", "Singen", "Sinnenschärfe", "Tanzen", "Zechen",
|
||||||
|
"Menschenkenntnis", "Überreden",
|
||||||
|
"Fährtensuchen", "Orientierung", "Wildnisleben",
|
||||||
|
"Götter/Kulte", "Rechnen", "Sagen/Legenden",
|
||||||
|
"Heilkunde: Wunden", "Holzbearbeitung", "Kochen", "Lederverarbeitung", "Malen/Zeichnen", "Schneidern"
|
||||||
|
]
|
||||||
|
|
||||||
|
const talente = []
|
||||||
|
|
||||||
|
talentsByName.forEach( talentName => {
|
||||||
|
const talent = game.items.getName(talentName);
|
||||||
|
console.log(talent);
|
||||||
|
if (talent) {
|
||||||
|
talente.push({
|
||||||
|
taw: 0,
|
||||||
|
talent
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.error(`${talentName} not found in items`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// push base talents
|
||||||
|
game.actors.getName(data.name).update({system: {talente}})
|
||||||
|
|
||||||
|
const startEigenschaften = {
|
||||||
|
"mu": 10,
|
||||||
|
"kl": 10,
|
||||||
|
"in": 10,
|
||||||
|
"ch": 10,
|
||||||
|
"ff": 10,
|
||||||
|
"ge": 10,
|
||||||
|
"ko": 10,
|
||||||
|
"kk": 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
game.actors.getName(data.name).update({system: {attribute: startEigenschaften}})
|
||||||
|
super._onCreate(data, options, userId);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -7,4 +7,21 @@ export class Character extends Actor {
|
||||||
this.prepareEmbeddedDocuments();
|
this.prepareEmbeddedDocuments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRollData() {
|
||||||
|
const data = super.getRollData();
|
||||||
|
|
||||||
|
if (this.type !== 'character') return;
|
||||||
|
|
||||||
|
// Copy the ability scores to the top level, so that rolls can use
|
||||||
|
// formulas like `@str.mod + 4`.
|
||||||
|
if (data.attribute) {
|
||||||
|
for (let [k, v] of Object.entries(data.attribute)) {
|
||||||
|
data[k] = foundry.utils.deepClone(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { BaseItem } from "./base-item.mjs";
|
|
||||||
|
|
||||||
export class Skill extends BaseItem {
|
export class Skill extends Item {
|
||||||
/**
|
/**
|
||||||
* Augment the basic Item data model with additional dynamic data.
|
* Augment the basic Item data model with additional dynamic data.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import { BaseItem } from "./base-item.mjs";
|
export class Spell extends Item {
|
||||||
|
|
||||||
export class Spell extends BaseItem {
|
|
||||||
/**
|
/**
|
||||||
* Augment the basic Item data model with additional dynamic data.
|
* Augment the basic Item data model with additional dynamic data.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,63 @@ export class CharacterSheet extends ActorSheet {
|
||||||
// Add the actor's data to context.data for easier access, as well as flags.
|
// Add the actor's data to context.data for easier access, as well as flags.
|
||||||
context.system = actorData.system;
|
context.system = actorData.system;
|
||||||
context.flags = actorData.flags;
|
context.flags = actorData.flags;
|
||||||
|
context.attributes = [
|
||||||
|
{
|
||||||
|
eigenschaft: "mu",
|
||||||
|
name: "Mut",
|
||||||
|
wert: actorData.system.attribute.mu ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eigenschaft: "kl",
|
||||||
|
name: "Klugheit",
|
||||||
|
wert: actorData.system.attribute.kl ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eigenschaft: "in",
|
||||||
|
name: "Intuition",
|
||||||
|
wert: actorData.system.attribute.in ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eigenschaft: "ch",
|
||||||
|
name: "Charisma",
|
||||||
|
wert: actorData.system.attribute.ch ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eigenschaft: "ff",
|
||||||
|
name: "Fingerfertigkeit",
|
||||||
|
wert: actorData.system.attribute.ff ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eigenschaft: "ge",
|
||||||
|
name: "Geschicklichkeit",
|
||||||
|
wert: actorData.system.attribute.ge ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eigenschaft: "ko",
|
||||||
|
name: "Konstitution",
|
||||||
|
wert: actorData.system.attribute.ko ?? 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
eigenschaft: "kk",
|
||||||
|
name: "Körperkraft",
|
||||||
|
wert: actorData.system.attribute.kk ?? 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
];
|
||||||
context.skills = [];
|
context.skills = [];
|
||||||
if ( context.system.talente?.length >= 0) {
|
if ( context.system.talente?.length >= 0) {
|
||||||
context.system.talente.forEach(talent => {
|
context.system.talente.forEach(talent => {
|
||||||
const tempTalent = talent();
|
console.log(talent);
|
||||||
console.log(tempTalent.system.probe);
|
const taw = talent.taw;
|
||||||
|
const talentObjekt = game.items.get(talent.talent);
|
||||||
|
const eigenschaften = Object.values(talentObjekt.system.probe);
|
||||||
context.skills.push({
|
context.skills.push({
|
||||||
talentName: tempTalent.name,
|
talentName: talentObjekt.name,
|
||||||
probe: `ROLLDATA(${Object.values(tempTalent.system.probe).join("/")})`
|
taw: taw,
|
||||||
|
rollEigenschaft1: this.prepareEigenschaftRoll(actorData, eigenschaften[0]),
|
||||||
|
rollEigenschaft2: this.prepareEigenschaftRoll(actorData, eigenschaften[1]),
|
||||||
|
rollEigenschaft3: this.prepareEigenschaftRoll(actorData, eigenschaften[2]),
|
||||||
|
probe: `(${eigenschaften.join("/")})`
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
@ -51,9 +100,97 @@ export class CharacterSheet extends ActorSheet {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepareEigenschaftRoll(actorData, name) {
|
||||||
|
return actorData.system.attribute[name.toLowerCase()]
|
||||||
|
}
|
||||||
|
|
||||||
|
async _onTalentRoll(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const dataset = event.currentTarget.dataset;
|
||||||
|
console.log(dataset)
|
||||||
|
if (dataset.rolleigenschaft1) {
|
||||||
|
let roll1 = new Roll("3d20", this.actor.getRollData());
|
||||||
|
|
||||||
|
let evaluated1 = (await roll1.evaluate())
|
||||||
|
|
||||||
|
const dsaDieRollEvaluated = this._evaluateRoll(evaluated1.terms[0].results, {
|
||||||
|
taw: dataset.taw,
|
||||||
|
werte: [dataset.rolleigenschaft1, dataset.rolleigenschaft2, dataset.rolleigenschaft3],
|
||||||
|
})
|
||||||
|
|
||||||
|
if (dsaDieRollEvaluated.tap >= 0) { // erfolg
|
||||||
|
evaluated1.toMessage({
|
||||||
|
speaker: ChatMessage.getSpeaker({actor: this.actor}),
|
||||||
|
flavor: ` ${dsaDieRollEvaluated.meisterlich?'Meisterlich geschafft':'Geschafft'} mit ${dsaDieRollEvaluated.tap} Punkten übrig`,
|
||||||
|
rollMode: game.settings.get('core', 'rollMode'),
|
||||||
|
})
|
||||||
|
} else { // misserfolg
|
||||||
|
evaluated1.toMessage({
|
||||||
|
speaker: ChatMessage.getSpeaker({actor: this.actor}),
|
||||||
|
flavor: ` ${dsaDieRollEvaluated.meisterlich?'Gepatzt':''} mit ${Math.abs(dsaDieRollEvaluated.tap)} Punkten daneben`,
|
||||||
|
rollMode: game.settings.get('core', 'rollMode'),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_evaluateRoll(rolledDice, { taw, lowerThreshold = 1, upperThreshold = 20, countToMeisterlich = 3, countToPatzer = 3, werte = [] } ) {
|
||||||
|
let tap = taw;
|
||||||
|
let meisterlichCounter = 0;
|
||||||
|
let patzerCounter = 0;
|
||||||
|
let failCounter = 0;
|
||||||
|
|
||||||
|
rolledDice.forEach( (rolledDie, index) => {
|
||||||
|
if (tap < 0 && rolledDie.result > werte[index]) {
|
||||||
|
tap -= rolledDie.result - werte[index];
|
||||||
|
if (tap <0) { // konnte nicht vollständig ausgeglichen werden
|
||||||
|
failCounter++;
|
||||||
|
}
|
||||||
|
} else if (rolledDie.result > werte[index]) { // taw ist bereits aufgebraucht und wert kann nicht ausgeglichen werden
|
||||||
|
tap -= rolledDie.result - werte[index];
|
||||||
|
failCounter++;
|
||||||
|
}
|
||||||
|
if (rolledDie.result <= lowerThreshold) meisterlichCounter++;
|
||||||
|
if (rolledDie.result > upperThreshold) patzerCounter++;
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
tap,
|
||||||
|
meisterlich: meisterlichCounter === countToMeisterlich,
|
||||||
|
patzer: patzerCounter === countToPatzer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onAttributeRoll(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const dataset = event.currentTarget.dataset;
|
||||||
|
if (dataset.roll) {
|
||||||
|
let label = dataset.label ? `[Attribut] ${dataset.label}` : '';
|
||||||
|
let roll = new Roll(dataset.roll, this.actor.getRollData());
|
||||||
|
roll.toMessage({
|
||||||
|
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
|
||||||
|
flavor: label,
|
||||||
|
rollMode: game.settings.get('core', 'rollMode'),
|
||||||
|
});
|
||||||
|
return roll;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
activateListeners(html) {
|
activateListeners(html) {
|
||||||
super.activateListeners(html);
|
super.activateListeners(html);
|
||||||
|
|
||||||
|
html.on('click', '.attribut.rollable', (evt) => {
|
||||||
|
console.log(evt);
|
||||||
|
this._onAttributeRoll(evt);
|
||||||
|
});
|
||||||
|
|
||||||
|
html.on('click', '.talent.rollable', (evt) => {
|
||||||
|
console.log(evt);
|
||||||
|
this._onTalentRoll(evt);
|
||||||
|
});
|
||||||
|
|
||||||
// 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) return;
|
if (!this.isEditable) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
"_id": "o1nYjhmMP0Zzlcw6",
|
"_id": "o1nYjhmMP0Zzlcw6",
|
||||||
"_key": "!items!o1nYjhmMP0Zzlcw6",
|
"_key": "!items!o1nYjhmMP0Zzlcw6",
|
||||||
"type": "Skill",
|
"type": "Skill",
|
||||||
"name": "Sich verstecken",
|
"name": "Sich Verstecken",
|
||||||
"system": {
|
"system": {
|
||||||
"gruppe": "Körperlich",
|
"gruppe": "Körperlich",
|
||||||
"probe": [
|
"probe": [
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,18 @@
|
||||||
<img class="profile-img" src="{{actor.img}}" data-edit="img" title="{{actor.name}}" height="100" width="100"/>
|
<img class="profile-img" src="{{actor.img}}" data-edit="img" title="{{actor.name}}" height="100" width="100"/>
|
||||||
<div class="header-fields">
|
<div class="header-fields">
|
||||||
<h1 class="charname"><input name="name" type="text" value="{{actor.name}}" placeholder="Name"/></h1>
|
<h1 class="charname"><input name="name" type="text" value="{{actor.name}}" placeholder="Name"/></h1>
|
||||||
|
<div class="attribute">
|
||||||
|
{{#each attributes}}
|
||||||
|
<button class="attribut rollable" data-label="{{this.name}}" data-roll="1d20cs<=@{{this.eigenschaft}}">
|
||||||
|
<span class="attribut-wert">
|
||||||
|
{{this.wert}}
|
||||||
|
</span>
|
||||||
|
<span class="attribut-name">
|
||||||
|
{{this.name}}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
{{/each}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|
@ -34,9 +46,10 @@
|
||||||
<div class="tab skills" data-group="primary" data-tab="skills">
|
<div class="tab skills" data-group="primary" data-tab="skills">
|
||||||
<ul>
|
<ul>
|
||||||
{{#each skills}}
|
{{#each skills}}
|
||||||
<li><div>
|
<li><div class="talent rollable" data-taw="{{this.taw}}" data-rollEigenschaft1="{{this.rollEigenschaft1}}" data-rollEigenschaft2="{{this.rollEigenschaft2}}" data-rollEigenschaft3="{{this.rollEigenschaft3}}">
|
||||||
<b>{{this.talentName}}</b>
|
<b>{{this.talentName}}</b>
|
||||||
{{this.probe}}
|
{{this.probe}}
|
||||||
|
TAW: {{this.taw}}
|
||||||
</div></li>
|
</div></li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue