initial attempt for using ActiveEffects and applying item base stats
This commit is contained in:
parent
abeb9d8b24
commit
27487c5bae
6 changed files with 106 additions and 62 deletions
|
@ -24,6 +24,7 @@ export class DS4ActorSheet extends ActorSheet {
|
||||||
for (let attr of Object.values(data.data.attributes)) {
|
for (let attr of Object.values(data.data.attributes)) {
|
||||||
attr.isCheckbox = attr.dtype === "Boolean";
|
attr.isCheckbox = attr.dtype === "Boolean";
|
||||||
}
|
}
|
||||||
|
console.log(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,35 +3,36 @@
|
||||||
* @extends {Actor}
|
* @extends {Actor}
|
||||||
*/
|
*/
|
||||||
export class DS4Actor extends Actor {
|
export class DS4Actor extends Actor {
|
||||||
|
/** @override */
|
||||||
/**
|
prepareDerivedData() {
|
||||||
* Augment the basic actor data with additional dynamic data.
|
const data = this.data;
|
||||||
*/
|
this._prepareCombatValues(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
_prepareCombatValues(data) {
|
||||||
* Prepare Character type specific data
|
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
|
||||||
*/
|
setProperty(
|
||||||
_prepareCharacterData(actorData) {
|
data,
|
||||||
const data = actorData.data;
|
"data.combatValues.hitPoints.max",
|
||||||
|
data.data.attributes.body.initial + data.data.traits.constitution.initial + 10 + hitPointsModifier
|
||||||
|
);
|
||||||
|
|
||||||
// Make modifications to data here. For example:
|
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
|
||||||
|
setProperty(
|
||||||
// Loop through ability scores, and add their modifiers to our sheet output.
|
data,
|
||||||
for (let [key, ability] of Object.entries(data.abilities)) {
|
"data.combatValues.defense.value",
|
||||||
// Calculate the modifier using d20 rules.
|
data.data.attributes.body.initial +
|
||||||
ability.mod = Math.floor((ability.value - 10) / 2);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -47,9 +47,41 @@ export class DS4ItemSheet extends ItemSheet {
|
||||||
activateListeners(html) {
|
activateListeners(html) {
|
||||||
super.activateListeners(html);
|
super.activateListeners(html);
|
||||||
|
|
||||||
// Everything below here is only needed if the sheet is editable
|
|
||||||
if (!this.options.editable) return;
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,38 @@
|
||||||
{
|
{
|
||||||
"Actor": {
|
"Actor": {
|
||||||
"types": ["character"],
|
"types": ["character"],
|
||||||
"templates": {
|
"templates": {},
|
||||||
"base": {
|
|
||||||
"health": {
|
|
||||||
"value": 10,
|
|
||||||
"min": 0,
|
|
||||||
"max": 10
|
|
||||||
},
|
|
||||||
"power": {
|
|
||||||
"value": 5,
|
|
||||||
"min": 0,
|
|
||||||
"max": 5
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"character": {
|
"character": {
|
||||||
"templates": ["base"],
|
"templates": [],
|
||||||
"biography": "",
|
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"level": {
|
"body": {
|
||||||
"value": 1
|
"initial": 8
|
||||||
|
},
|
||||||
|
"mobility": {
|
||||||
|
"initial": 0
|
||||||
|
},
|
||||||
|
"mind": {
|
||||||
|
"initial": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"abilities": {
|
"traits": {
|
||||||
"str": {
|
"strength": {
|
||||||
"value": 10
|
"initial": 4
|
||||||
},
|
},
|
||||||
"dex": {
|
"constitution": {
|
||||||
"value": 10
|
"initial": 0
|
||||||
},
|
},
|
||||||
"con": {
|
"agility": {
|
||||||
"value": 10
|
"initial": 0
|
||||||
},
|
},
|
||||||
"int": {
|
"dexterity": {
|
||||||
"value": 10
|
"initial": 0
|
||||||
},
|
},
|
||||||
"wis": {
|
"intellect": {
|
||||||
"value": 10
|
"initial": 0
|
||||||
},
|
},
|
||||||
"cha": {
|
"aura": {
|
||||||
"value": 10
|
"initial": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
<div class="item-image"></div>
|
<div class="item-image"></div>
|
||||||
<div class="item-name">Name</div>
|
<div class="item-name">Name</div>
|
||||||
<div class="item-controls">
|
<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>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{{#each actor.items as |item id|}}
|
{{#each actor.items as |item id|}}
|
||||||
|
|
|
@ -21,7 +21,25 @@
|
||||||
|
|
||||||
{{!-- Attributes Tab --}}
|
{{!-- Attributes Tab --}}
|
||||||
<div class="tab details" data-group="primary" data-tab="details">
|
<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>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</form>
|
</form>
|
Loading…
Reference in a new issue