initial attempt for using ActiveEffects and applying item base stats

This commit is contained in:
Johannes Loher 2020-10-30 00:48:06 +01:00
parent abeb9d8b24
commit 27487c5bae
6 changed files with 106 additions and 62 deletions

View file

@ -24,6 +24,7 @@ export class DS4ActorSheet extends ActorSheet {
for (let attr of Object.values(data.data.attributes)) {
attr.isCheckbox = attr.dtype === "Boolean";
}
console.log(data);
return data;
}

View file

@ -3,35 +3,36 @@
* @extends {Actor}
*/
export class DS4Actor extends Actor {
/**
* Augment the basic actor data with additional dynamic data.
*/
prepareData() {
super.prepareData();
const actorData = this.data;
const data = actorData.data;
const flags = actorData.flags;
// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
if (actorData.type === 'character') this._prepareCharacterData(actorData);
/** @override */
prepareDerivedData() {
const data = this.data;
this._prepareCombatValues(data);
}
/**
* Prepare Character type specific data
*/
_prepareCharacterData(actorData) {
const data = actorData.data;
_prepareCombatValues(data) {
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
setProperty(
data,
"data.combatValues.hitPoints.max",
data.data.attributes.body.initial + data.data.traits.constitution.initial + 10 + hitPointsModifier
);
// Make modifications to data here. For example:
// Loop through ability scores, and add their modifiers to our sheet output.
for (let [key, ability] of Object.entries(data.abilities)) {
// Calculate the modifier using d20 rules.
ability.mod = Math.floor((ability.value - 10) / 2);
}
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
setProperty(
data,
"data.combatValues.defense.value",
data.data.attributes.body.initial +
data.data.traits.constitution.initial +
this._getArmorValue() +
defenseModifier
);
}
_getArmorValue() {
return this.data.items
.filter((item) => ["armor", "shield"].includes(item.type))
.filter((item) => item.data.equipped)
.map((item) => item.data.armorValue)
.reduce((a, b) => a + b, 0);
}
}

View file

@ -47,9 +47,41 @@ export class DS4ItemSheet extends ItemSheet {
activateListeners(html) {
super.activateListeners(html);
// Everything below here is only needed if the sheet is editable
if (!this.options.editable) return;
// Roll handlers, click handlers, etc. would go here.
html.find(".effect-create").click(this._onEffectCreate.bind(this));
html.find(".effect-edit").click((ev) => {
const li = $(ev.currentTarget).parents(".effect");
console.log(li.data("effectId"));
const effect = this.item.effects.get(li.data("effectId"));
effect.sheet.render(true);
});
html.find(".effect-delete").click(async (ev) => {
const li = $(ev.currentTarget).parents(".effect");
await this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId"));
});
}
/**
* Handle creating a new ActiveEffect for the item using initial data defined in the HTML dataset
* @param {Event} event The originating click event
* @private
*/
async _onEffectCreate(event) {
event.preventDefault();
const label = `New Effect`;
const createData = {
label: label,
changes: [],
duration: {},
transfer: true,
};
const effect = ActiveEffect.create(createData, this.item);
return effect.create();
}
}

View file

@ -1,46 +1,38 @@
{
"Actor": {
"types": ["character"],
"templates": {
"base": {
"health": {
"value": 10,
"min": 0,
"max": 10
},
"power": {
"value": 5,
"min": 0,
"max": 5
}
}
},
"templates": {},
"character": {
"templates": ["base"],
"biography": "",
"templates": [],
"attributes": {
"level": {
"value": 1
"body": {
"initial": 8
},
"mobility": {
"initial": 0
},
"mind": {
"initial": 0
}
},
"abilities": {
"str": {
"value": 10
"traits": {
"strength": {
"initial": 4
},
"dex": {
"value": 10
"constitution": {
"initial": 0
},
"con": {
"value": 10
"agility": {
"initial": 0
},
"int": {
"value": 10
"dexterity": {
"initial": 0
},
"wis": {
"value": 10
"intellect": {
"initial": 0
},
"cha": {
"value": 10
"aura": {
"initial": 0
}
}
}

View file

@ -65,7 +65,7 @@
<div class="item-image"></div>
<div class="item-name">Name</div>
<div class="item-controls">
<a class="item-control item-create" title="Create item" data-type="item"><i class="fas fa-plus"></i> Add item</a>
<a class="item-control item-create" title="Create item" data-type="weapon"><i class="fas fa-plus"></i> Add item</a>
</div>
</li>
{{#each actor.items as |item id|}}

View file

@ -21,7 +21,25 @@
{{!-- Attributes Tab --}}
<div class="tab details" data-group="primary" data-tab="details">
{{!-- As you add new fields, add them in here! --}}
<ol class="effects-list">
<li class="effect flexrow effect-header">
<div class="effect-image"></div>
<div class="effect-name">Name</div>
<div class="effect-controls">
<a class="effect-control effect-create" title="Create Effect"><i
class="fas fa-plus"></i> Add effect</a>
</div>
</li>
{{#each item.effects as |effect id|}}
<li class="effect flexrow" data-effect-id="{{effect._id}}">
<h4 class="effect-name">{{effect.label}}</h4>
<div class="effect-controls">
<a class="effect-control effect-edit" title="Edit Effect"><i class="fas fa-edit"></i></a>
<a class="effect-control effect-delete" title="Delete Effect"><i class="fas fa-trash"></i></a>
</div>
</li>
{{/each}}
</ol>
</div>
</section>
</form>