mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-15 13:11:08 +01:00
actions
This commit is contained in:
parent
4e110e30b1
commit
22497dd6af
12 changed files with 308 additions and 117 deletions
|
|
@ -531,6 +531,14 @@
|
||||||
"Stress": {
|
"Stress": {
|
||||||
"Name": "Stress",
|
"Name": "Stress",
|
||||||
"Stress": "STR"
|
"Stress": "STR"
|
||||||
|
},
|
||||||
|
"Hope": {
|
||||||
|
"Name": "Hope",
|
||||||
|
"Abbreviation": "HO"
|
||||||
|
},
|
||||||
|
"ArmorStack": {
|
||||||
|
"Name": "Armor Stack",
|
||||||
|
"Stress": "AS"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ArmorFeature": {
|
"ArmorFeature": {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
|
||||||
context.tabs = this._getTabs();
|
context.tabs = this._getTabs();
|
||||||
context.config = SYSTEM;
|
context.config = SYSTEM;
|
||||||
if (!!this.action.effects) context.effects = this.action.effects.map(e => this.action.item.effects.get(e._id));
|
if (!!this.action.effects) context.effects = this.action.effects.map(e => this.action.item.effects.get(e._id));
|
||||||
if (this.action.damage?.hasOwnProperty('includeBase')) context.hasBaseDamage = !!this.action.parent.damage;
|
if (this.action.damage?.hasOwnProperty('includeBase') && this.action.type === 'attack') context.hasBaseDamage = !!this.action.parent.damage;
|
||||||
context.getRealIndex = this.getRealIndex.bind(this);
|
context.getRealIndex = this.getRealIndex.bind(this);
|
||||||
console.log(context)
|
console.log(context)
|
||||||
return context;
|
return context;
|
||||||
|
|
|
||||||
34
module/applications/roll.mjs
Normal file
34
module/applications/roll.mjs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
|
||||||
|
export default class DHRoll extends Roll {
|
||||||
|
static async build(config={}, message={}) {
|
||||||
|
const roll = await this.buildConfigure();
|
||||||
|
await this.buildEvaluate(config, message={});
|
||||||
|
await this.buildPost(config, message={});
|
||||||
|
return roll;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async buildConfigure(config={}, message={}) {
|
||||||
|
config.hooks = [...(config.hooks ?? []), ""];
|
||||||
|
for ( const hook of config.hooks ) {
|
||||||
|
if ( Hooks.call(`dnd5e.preRoll${hook.capitalize()}`, config, message) === false ) return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async buildEvaluate(roll, config={}, message={}) {
|
||||||
|
if(config.evaluate !== false) await roll.evalutate();
|
||||||
|
}
|
||||||
|
|
||||||
|
static async buildPost(config, message) {
|
||||||
|
for ( const hook of config.hooks ) {
|
||||||
|
if ( Hooks.call(`dnd5e.postRoll${hook.capitalize()}`, config, message) === false ) return null;
|
||||||
|
}
|
||||||
|
// Create Chat Message
|
||||||
|
await this.toMessage(roll, message.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static async toMessage(roll, data) {
|
||||||
|
|
||||||
|
const cls = getDocumentClass("ChatMessage");
|
||||||
|
const msg = new cls(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,21 +4,21 @@ export const actionTypes = {
|
||||||
name: 'DAGGERHEART.Actions.Types.Attack.Name',
|
name: 'DAGGERHEART.Actions.Types.Attack.Name',
|
||||||
icon: 'fa-swords'
|
icon: 'fa-swords'
|
||||||
},
|
},
|
||||||
spellcast: {
|
// spellcast: {
|
||||||
id: 'spellcast',
|
// id: 'spellcast',
|
||||||
name: 'DAGGERHEART.Actions.Types.Spellcast.Name',
|
// name: 'DAGGERHEART.Actions.Types.Spellcast.Name',
|
||||||
icon: 'fa-book-sparkles'
|
// icon: 'fa-book-sparkles'
|
||||||
},
|
// },
|
||||||
healing: {
|
healing: {
|
||||||
id: 'healing',
|
id: 'healing',
|
||||||
name: 'DAGGERHEART.Actions.Types.Healing.Name',
|
name: 'DAGGERHEART.Actions.Types.Healing.Name',
|
||||||
icon: 'fa-kit-medical'
|
icon: 'fa-kit-medical'
|
||||||
},
|
},
|
||||||
resource: {
|
// resource: {
|
||||||
id: 'resource',
|
// id: 'resource',
|
||||||
name: 'DAGGERHEART.Actions.Types.Resource.Name',
|
// name: 'DAGGERHEART.Actions.Types.Resource.Name',
|
||||||
icon: 'fa-honey-pot'
|
// icon: 'fa-honey-pot'
|
||||||
},
|
// },
|
||||||
damage: {
|
damage: {
|
||||||
id: 'damage',
|
id: 'damage',
|
||||||
name: 'DAGGERHEART.Actions.Types.Damage.Name',
|
name: 'DAGGERHEART.Actions.Types.Damage.Name',
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,16 @@ export const healingTypes = {
|
||||||
id: 'stress',
|
id: 'stress',
|
||||||
label: 'DAGGERHEART.HealingType.Stress.Name',
|
label: 'DAGGERHEART.HealingType.Stress.Name',
|
||||||
abbreviation: 'DAGGERHEART.HealingType.Stress.Abbreviation'
|
abbreviation: 'DAGGERHEART.HealingType.Stress.Abbreviation'
|
||||||
|
},
|
||||||
|
hope: {
|
||||||
|
id: 'hope',
|
||||||
|
label: 'DAGGERHEART.HealingType.Hope.Name',
|
||||||
|
abbreviation: 'DAGGERHEART.HealingType.Hope.Abbreviation'
|
||||||
|
},
|
||||||
|
armorStack: {
|
||||||
|
id: 'armorStack',
|
||||||
|
label: 'DAGGERHEART.HealingType.ArmorStack.Name',
|
||||||
|
abbreviation: 'DAGGERHEART.HealingType.ArmorStack.Abbreviation'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,16 @@ import {
|
||||||
DHEffectAction,
|
DHEffectAction,
|
||||||
DHHealingAction,
|
DHHealingAction,
|
||||||
DHMacroAction,
|
DHMacroAction,
|
||||||
DHResourceAction,
|
// DHResourceAction,
|
||||||
DHSpellCastAction,
|
// DHSpellCastAction,
|
||||||
DHSummonAction
|
DHSummonAction
|
||||||
} from './action.mjs';
|
} from './action.mjs';
|
||||||
|
|
||||||
export const actionsTypes = {
|
export const actionsTypes = {
|
||||||
base: DHBaseAction,
|
base: DHBaseAction,
|
||||||
attack: DHAttackAction,
|
attack: DHAttackAction,
|
||||||
spellcast: DHSpellCastAction,
|
// spellcast: DHSpellCastAction,
|
||||||
resource: DHResourceAction,
|
// resource: DHResourceAction,
|
||||||
damage: DHDamageAction,
|
damage: DHDamageAction,
|
||||||
healing: DHHealingAction,
|
healing: DHHealingAction,
|
||||||
summon: DHSummonAction,
|
summon: DHSummonAction,
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ const fields = foundry.data.fields;
|
||||||
- Range Check
|
- Range Check
|
||||||
- Area of effect and measurement placement
|
- Area of effect and measurement placement
|
||||||
- Auto use costs and action
|
- Auto use costs and action
|
||||||
|
|
||||||
|
Activity Types List
|
||||||
|
- Attack => Weapon Attack, Spell Attack, etc...
|
||||||
|
- Effects => Like Attack without damage
|
||||||
|
- Damage => Like Attack without roll
|
||||||
|
- Healing
|
||||||
|
- Resource => Merge Healing & Resource ?
|
||||||
|
- Summon
|
||||||
|
- Sequencer => Trigger a list of Activities set on the item one by one
|
||||||
|
- Macro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export class DHBaseAction extends foundry.abstract.DataModel {
|
export class DHBaseAction extends foundry.abstract.DataModel {
|
||||||
|
|
@ -49,9 +59,9 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
||||||
}),
|
}),
|
||||||
range: new fields.StringField({
|
range: new fields.StringField({
|
||||||
choices: SYSTEM.GENERAL.range,
|
choices: SYSTEM.GENERAL.range,
|
||||||
required: true,
|
required: false,
|
||||||
blank: false,
|
blank: true,
|
||||||
initial: 'self'
|
initial: null
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +84,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
||||||
return 'systems/daggerheart/templates/chat/attack-roll.hbs';
|
return 'systems/daggerheart/templates/chat/attack-roll.hbs';
|
||||||
}
|
}
|
||||||
|
|
||||||
static getRollType() {
|
static getRollType(parent) {
|
||||||
return 'ability';
|
return 'ability';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,17 +93,36 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
||||||
updateSource.img ??= parent?.img ?? parent?.system?.img;
|
updateSource.img ??= parent?.img ?? parent?.system?.img;
|
||||||
if (parent?.system?.trait) {
|
if (parent?.system?.trait) {
|
||||||
updateSource['roll'] = {
|
updateSource['roll'] = {
|
||||||
type: this.getRollType(),
|
type: this.getRollType(parent),
|
||||||
trait: parent.system.trait
|
trait: parent.system.trait
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if(parent?.type === 'weapon' && !!this.schema.fields.damage) {
|
||||||
|
updateSource['damage'] = {includeBase: true};
|
||||||
|
}
|
||||||
if (parent?.system?.range) {
|
if (parent?.system?.range) {
|
||||||
updateSource['range'] = parent?.system?.range;
|
updateSource['range'] = parent?.system?.range;
|
||||||
}
|
}
|
||||||
return updateSource;
|
return updateSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
async use(event) {
|
getRollData() {
|
||||||
|
const actorData = this.actor.getRollData(false);
|
||||||
|
return {
|
||||||
|
...actorData.toObject(),
|
||||||
|
prof: actorData.proficiency?.value ?? 1,
|
||||||
|
cast: actorData.spellcast?.value ?? 1,
|
||||||
|
scale: this.cost.length ? this.cost.reduce((a,c) => {a[c.type] = c.value; return a},{}) : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async use(event, ...args) {
|
||||||
|
// throw new Error("Activity must implement a 'use' method.");
|
||||||
|
const data = {
|
||||||
|
itemUUID: this.item,
|
||||||
|
activityId: this.id
|
||||||
|
};
|
||||||
|
|
||||||
if(this.cost?.length) {
|
if(this.cost?.length) {
|
||||||
const hasCost = await this.checkCost();
|
const hasCost = await this.checkCost();
|
||||||
if(!hasCost) return ui.notifications.warn("You don't have the resources to use that action.");
|
if(!hasCost) return ui.notifications.warn("You don't have the resources to use that action.");
|
||||||
|
|
@ -104,7 +133,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
||||||
if(this.range) {
|
if(this.range) {
|
||||||
const hasRange = await this.checkRange();
|
const hasRange = await this.checkRange();
|
||||||
}
|
}
|
||||||
if (this.roll.type && this.roll.trait) {
|
if (this.roll?.type && this.roll?.trait) {
|
||||||
const modifierValue = this.actor.system.traits[this.roll.trait].value;
|
const modifierValue = this.actor.system.traits[this.roll.trait].value;
|
||||||
const config = {
|
const config = {
|
||||||
event: event,
|
event: event,
|
||||||
|
|
@ -129,8 +158,13 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
||||||
if (this.effects.length) {
|
if (this.effects.length) {
|
||||||
// Apply Active Effects. In Chat Message ?
|
// Apply Active Effects. In Chat Message ?
|
||||||
}
|
}
|
||||||
return this.actor.diceRoll(config);
|
data.roll = await this.actor.diceRoll(config);
|
||||||
}
|
}
|
||||||
|
if(this.withMessage || true) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkCost() {
|
async checkCost() {
|
||||||
|
|
@ -174,22 +208,22 @@ export class DHBaseAction extends foundry.abstract.DataModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const tmpTargetObject = () => {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
const extraDefineSchema = (field, option) => {
|
const extraDefineSchema = (field, option) => {
|
||||||
return {
|
return {
|
||||||
[field]: {
|
[field]: {
|
||||||
// damage: new fields.SchemaField({
|
// damage: new fields.SchemaField({
|
||||||
// parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData))
|
// parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData))
|
||||||
// }),
|
// }),
|
||||||
damage: new DHDamageField(option),
|
damage: new DHDamageField(),
|
||||||
roll: new fields.SchemaField({
|
roll: new fields.SchemaField({
|
||||||
type: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.GENERAL.rollTypes }),
|
type: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.GENERAL.rollTypes }),
|
||||||
trait: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.ACTOR.abilities }),
|
trait: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.ACTOR.abilities }),
|
||||||
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 })
|
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 })
|
||||||
}),
|
}),
|
||||||
|
save: new fields.SchemaField({
|
||||||
|
trait: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.ACTOR.abilities }),
|
||||||
|
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 })
|
||||||
|
}),
|
||||||
target: new fields.SchemaField({
|
target: new fields.SchemaField({
|
||||||
type: new fields.StringField({
|
type: new fields.StringField({
|
||||||
choices: SYSTEM.ACTIONS.targetTypes,
|
choices: SYSTEM.ACTIONS.targetTypes,
|
||||||
|
|
@ -207,72 +241,61 @@ const extraDefineSchema = (field, option) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export class DHAttackAction extends DHBaseAction {
|
export class DHDamageAction extends DHBaseAction {
|
||||||
static defineSchema() {
|
directDamage = true;
|
||||||
return {
|
|
||||||
...super.defineSchema(),
|
|
||||||
...extraDefineSchema('damage', true),
|
|
||||||
...extraDefineSchema('roll'),
|
|
||||||
...extraDefineSchema('target'),
|
|
||||||
...extraDefineSchema('effects')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static getRollType() {
|
|
||||||
return 'weapon';
|
|
||||||
}
|
|
||||||
|
|
||||||
prepareData() {
|
|
||||||
super.prepareData();
|
|
||||||
if (this.damage.includeBase && !!this.item?.system?.damage) {
|
|
||||||
const baseDamage = this.getParentDamage();
|
|
||||||
this.damage.parts.unshift(new DHDamageData(baseDamage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getParentDamage() {
|
|
||||||
return {
|
|
||||||
multiplier: 'proficiency',
|
|
||||||
dice: this.item?.system?.damage.value,
|
|
||||||
bonus: this.item?.system?.damage.bonus ?? 0,
|
|
||||||
type: this.item?.system?.damage.type,
|
|
||||||
base: true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Temporary until full formula parser
|
|
||||||
// getDamageFormula() {
|
|
||||||
// return this.damage.parts.map(p => p.formula).join(' + ');
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DHSpellCastAction extends DHBaseAction {
|
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
return {
|
return {
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
...extraDefineSchema('damage'),
|
...extraDefineSchema('damage'),
|
||||||
...extraDefineSchema('roll'),
|
|
||||||
...extraDefineSchema('target'),
|
...extraDefineSchema('target'),
|
||||||
...extraDefineSchema('effects')
|
...extraDefineSchema('effects')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static getRollType() {
|
async use(event, ...args) {
|
||||||
return 'spellcast';
|
const messageData = await super.use(event, args);
|
||||||
}
|
if(!this.directDamage) return;
|
||||||
}
|
const roll = await this.rollDamage();
|
||||||
|
if(!roll) return;
|
||||||
|
const cls = getDocumentClass('ChatMessage'),
|
||||||
|
msg = new cls({
|
||||||
|
user: game.user.id,
|
||||||
|
content: await foundry.applications.handlebars.renderTemplate(
|
||||||
|
this.chatTemplate,
|
||||||
|
{
|
||||||
|
...roll,
|
||||||
|
...messageData
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
export class DHDamageAction extends DHBaseAction {
|
cls.create(msg.toObject());
|
||||||
static defineSchema() {
|
}
|
||||||
|
|
||||||
|
async rollDamage() {
|
||||||
|
const formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
|
||||||
|
console.log(this, formula)
|
||||||
|
if (!formula || formula == '') return;
|
||||||
|
|
||||||
|
let roll = { formula: formula, total: formula };
|
||||||
|
if (isNaN(formula)) {
|
||||||
|
roll = await new Roll(formula, this.getRollData()).evaluate();
|
||||||
|
}
|
||||||
|
console.log(roll)
|
||||||
return {
|
return {
|
||||||
...super.defineSchema(),
|
roll: roll.formula,
|
||||||
...extraDefineSchema('damage', false),
|
total: roll.total,
|
||||||
...extraDefineSchema('target'),
|
dice: roll.dice,
|
||||||
...extraDefineSchema('effects')
|
type: this.damage.parts.map(p => p.type)
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async use(event) {
|
get chatTemplate() {
|
||||||
|
return 'systems/daggerheart/templates/chat/damage-roll.hbs';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* async use(event, ...args) {
|
||||||
const formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
|
const formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
|
||||||
if (!formula || formula == '') return;
|
if (!formula || formula == '') return;
|
||||||
|
|
||||||
|
|
@ -295,9 +318,87 @@ export class DHDamageAction extends DHBaseAction {
|
||||||
});
|
});
|
||||||
|
|
||||||
cls.create(msg.toObject());
|
cls.create(msg.toObject());
|
||||||
}
|
} */
|
||||||
|
|
||||||
|
/* async applyDamage(targets, value) {
|
||||||
|
const promises = [];
|
||||||
|
for(let t of targets) {
|
||||||
|
if(!t) continue;
|
||||||
|
promises.push(new Promise(async (resolve, reject) => {
|
||||||
|
await t.takeDamage(value, 'physical'); // Apply one instance of damage per parts ?
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return Promise.all(promises).then((values) => {
|
||||||
|
return values;
|
||||||
|
});
|
||||||
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class DHAttackAction extends DHDamageAction {
|
||||||
|
directDamage = false;
|
||||||
|
|
||||||
|
static defineSchema() {
|
||||||
|
return {
|
||||||
|
...super.defineSchema(),
|
||||||
|
...extraDefineSchema('roll'),
|
||||||
|
...extraDefineSchema('save')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static getRollType(parent) {
|
||||||
|
return parent.type === 'weapon' ? 'weapon' : 'spellcast';
|
||||||
|
}
|
||||||
|
|
||||||
|
get chatTemplate() {
|
||||||
|
return 'systems/daggerheart/templates/chat/attack-roll.hbs';
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareData() {
|
||||||
|
super.prepareData();
|
||||||
|
if (this.damage.includeBase && !!this.item?.system?.damage) {
|
||||||
|
const baseDamage = this.getParentDamage();
|
||||||
|
this.damage.parts.unshift(new DHDamageData(baseDamage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getParentDamage() {
|
||||||
|
return {
|
||||||
|
multiplier: 'proficiency',
|
||||||
|
dice: this.item?.system?.damage.value,
|
||||||
|
bonus: this.item?.system?.damage.bonus ?? 0,
|
||||||
|
type: this.item?.system?.damage.type,
|
||||||
|
base: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/* async use(event, ...args) {
|
||||||
|
|
||||||
|
} */
|
||||||
|
|
||||||
|
// Temporary until full formula parser
|
||||||
|
// getDamageFormula() {
|
||||||
|
// return this.damage.parts.map(p => p.formula).join(' + ');
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* export class DHSpellCastAction extends DHBaseAction {
|
||||||
|
static defineSchema() {
|
||||||
|
return {
|
||||||
|
...super.defineSchema(),
|
||||||
|
...extraDefineSchema('damage'),
|
||||||
|
...extraDefineSchema('roll'),
|
||||||
|
...extraDefineSchema('target'),
|
||||||
|
...extraDefineSchema('effects')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static getRollType(parent) {
|
||||||
|
return 'spellcast';
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
|
||||||
export class DHHealingAction extends DHBaseAction {
|
export class DHHealingAction extends DHBaseAction {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -317,30 +418,38 @@ export class DHHealingAction extends DHBaseAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async use(event) {
|
async use(event, ...args) {
|
||||||
|
const messageData = await super.use(event, args),
|
||||||
|
roll = await this.rollHealing(),
|
||||||
|
cls = getDocumentClass('ChatMessage'),
|
||||||
|
msg = new cls({
|
||||||
|
user: game.user.id,
|
||||||
|
content: await foundry.applications.handlebars.renderTemplate(
|
||||||
|
this.chatTemplate,
|
||||||
|
{
|
||||||
|
...roll,
|
||||||
|
...messageData
|
||||||
|
}
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
cls.create(msg.toObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
async rollHealing() {
|
||||||
const formula = this.healing.value.getFormula(this.actor);
|
const formula = this.healing.value.getFormula(this.actor);
|
||||||
if (!formula || formula == '') return;
|
if (!formula || formula == '') return;
|
||||||
|
|
||||||
// const roll = await super.use(event);
|
|
||||||
let roll = { formula: formula, total: formula };
|
let roll = { formula: formula, total: formula };
|
||||||
if (isNaN(formula)) {
|
if (isNaN(formula)) {
|
||||||
roll = await new Roll(formula).evaluate();
|
roll = await new Roll(formula, this.getRollData()).evaluate();
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
roll: roll.formula,
|
||||||
|
total: roll.total,
|
||||||
|
dice: roll.dice,
|
||||||
|
type: this.healing.type
|
||||||
}
|
}
|
||||||
|
|
||||||
const cls = getDocumentClass('ChatMessage');
|
|
||||||
const msg = new cls({
|
|
||||||
user: game.user.id,
|
|
||||||
content: await foundry.applications.handlebars.renderTemplate(
|
|
||||||
'systems/daggerheart/templates/chat/healing-roll.hbs',
|
|
||||||
{
|
|
||||||
roll: roll.formula,
|
|
||||||
total: roll.total,
|
|
||||||
type: this.healing.type
|
|
||||||
}
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
cls.create(msg.toObject());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get chatTemplate() {
|
get chatTemplate() {
|
||||||
|
|
@ -348,7 +457,7 @@ export class DHHealingAction extends DHBaseAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DHResourceAction extends DHBaseAction {
|
/* export class DHResourceAction extends DHBaseAction {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
return {
|
return {
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
|
|
@ -367,7 +476,7 @@ export class DHResourceAction extends DHBaseAction {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
export class DHSummonAction extends DHBaseAction {
|
export class DHSummonAction extends DHBaseAction {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
|
|
@ -395,7 +504,7 @@ export class DHMacroAction extends DHBaseAction {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async use(event) {
|
async use(event, ...args) {
|
||||||
const fixUUID = !this.documentUUID.includes('Macro.') ? `Macro.${this.documentUUID}` : this.documentUUID,
|
const fixUUID = !this.documentUUID.includes('Macro.') ? `Macro.${this.documentUUID}` : this.documentUUID,
|
||||||
macro = await fromUuid(fixUUID);
|
macro = await fromUuid(fixUUID);
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,17 @@ export class DHActionDiceData extends foundry.abstract.DataModel {
|
||||||
getFormula(actor) {
|
getFormula(actor) {
|
||||||
return this.custom.enabled
|
return this.custom.enabled
|
||||||
? this.custom.formula
|
? this.custom.formula
|
||||||
: `${actor.system[this.multiplier] ?? 1}${this.dice}${this.bonus ? (this.bonus < 0 ? ` - ${Math.abs(this.bonus)}` : ` + ${this.bonus}`) : ''}`;
|
: `${actor.system[this.multiplier].value ?? 1}${this.dice}${this.bonus ? (this.bonus < 0 ? ` - ${Math.abs(this.bonus)}` : ` + ${this.bonus}`) : ''}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DHDamageField extends fields.SchemaField {
|
export class DHDamageField extends fields.SchemaField {
|
||||||
constructor(hasBase, options, context = {}) {
|
constructor(options, context = {}) {
|
||||||
const damageFields = {
|
const damageFields = {
|
||||||
parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData))
|
parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData)),
|
||||||
|
includeBase: new fields.BooleanField({ initial: false })
|
||||||
};
|
};
|
||||||
if (hasBase) damageFields.includeBase = new fields.BooleanField({ initial: true });
|
// if (hasBase) damageFields.includeBase = new fields.BooleanField({ initial: true });
|
||||||
super(damageFields, options, context);
|
super(damageFields, options, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -494,8 +494,8 @@ export default class DhpActor extends Actor {
|
||||||
: damage >= this.system.damageThresholds.minor
|
: damage >= this.system.damageThresholds.minor
|
||||||
? 1
|
? 1
|
||||||
: 0;
|
: 0;
|
||||||
|
await this.modifyResource(hpDamage, type);
|
||||||
const update = {
|
/* const update = {
|
||||||
'system.resources.hitPoints.value': Math.min(
|
'system.resources.hitPoints.value': Math.min(
|
||||||
this.system.resources.hitPoints.value + hpDamage,
|
this.system.resources.hitPoints.value + hpDamage,
|
||||||
this.system.resources.hitPoints.max
|
this.system.resources.hitPoints.max
|
||||||
|
|
@ -513,10 +513,39 @@ export default class DhpActor extends Actor {
|
||||||
update: update
|
update: update
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} */
|
||||||
|
}
|
||||||
|
|
||||||
|
async modifyResource(value, type) {
|
||||||
|
let resource, target, update;
|
||||||
|
switch (type) {
|
||||||
|
case 'armorStrack':
|
||||||
|
resource = 'system.stacks.value';
|
||||||
|
target = this.armor;
|
||||||
|
update = Math.min(this.marks.value + value, this.marks.max);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
resource = `system.resources.${type}`;
|
||||||
|
target = this;
|
||||||
|
update = Math.min(this.resources[type].value + value, this.resources[type].max);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!resource || !target || !update) return;
|
||||||
|
if (game.user.isGM) {
|
||||||
|
await target.update(update);
|
||||||
|
} else {
|
||||||
|
await game.socket.emit(`system.${SYSTEM.id}`, {
|
||||||
|
action: socketEvent.GMUpdate,
|
||||||
|
data: {
|
||||||
|
action: GMUpdateEvent.UpdateDocument,
|
||||||
|
uuid: target.uuid,
|
||||||
|
update: update
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async takeHealing(healing, type) {
|
/* async takeHealing(healing, type) {
|
||||||
let update = {};
|
let update = {};
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SYSTEM.GENERAL.healingTypes.health.id:
|
case SYSTEM.GENERAL.healingTypes.health.id:
|
||||||
|
|
@ -549,7 +578,7 @@ export default class DhpActor extends Actor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
//Move to action-scope?
|
//Move to action-scope?
|
||||||
/* async useAction(action) {
|
/* async useAction(action) {
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
||||||
ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected'));
|
ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected'));
|
||||||
|
|
||||||
for (var target of targets) {
|
for (var target of targets) {
|
||||||
await target.actor.takeHealing(healing, event.currentTarget.dataset.type);
|
await target.actor.modifyResource(healing, event.currentTarget.dataset.type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
<header class="part-header flexrow">
|
<header class="part-header flexrow">
|
||||||
<span class="part-formula">{{rolls.length}}{{type}}</span>
|
<span class="part-formula">{{rolls.length}}{{type}}</span>
|
||||||
|
|
||||||
<span class="part-total">{{this.total}}</span>
|
<span class="part-total">{{total}}</span>
|
||||||
</header>
|
</header>
|
||||||
<ol class="dice-rolls">
|
<ol class="dice-rolls">
|
||||||
{{#each rolls}}
|
{{#each rolls}}
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="dice-total">{{damage.total}}</div>
|
<div class="dice-total">{{total}}</div>
|
||||||
<div class="dice-actions">
|
<div class="dice-actions">
|
||||||
<button class="damage-button" data-target-hit="true" {{#if (eq targets.length 0)}}disabled{{/if}}>{{localize "DAGGERHEART.Chat.DamageRoll.DealDamageToTargets"}}</button>
|
<button class="damage-button" data-target-hit="true" {{#if (eq targets.length 0)}}disabled{{/if}}>{{localize "DAGGERHEART.Chat.DamageRoll.DealDamageToTargets"}}</button>
|
||||||
<button class="damage-button">{{localize "DAGGERHEART.Chat.DamageRoll.DealDamage"}}</button>
|
<button class="damage-button">{{localize "DAGGERHEART.Chat.DamageRoll.DealDamage"}}</button>
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
<div class="dice-roll daggerheart chat roll">
|
<div class="dice-roll daggerheart chat roll">
|
||||||
<div class="dice-result">
|
<div class="dice-result">
|
||||||
<div class="dice-formula">{{this.roll}}</div>
|
<div class="dice-formula">{{roll}}</div>
|
||||||
<div class="dice-tooltip">
|
<div class="dice-tooltip">
|
||||||
<ol class="dice-rolls">
|
<ol class="dice-rolls">
|
||||||
{{#each dice}}
|
{{#each dice}}
|
||||||
<li class="roll die {{this.type}}">{{this.value}}</li>
|
<li class="roll die {{type}}">{{value}}</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{#each modifiers}}
|
{{#each modifiers}}
|
||||||
<li class="modifier-value">{{this}}</li>
|
<li class="modifier-value">{{this}}</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<div class="dice-total">{{this.total}}</div>
|
<div class="dice-total">{{total}}</div>
|
||||||
<div class="flexrow">
|
<div class="flexrow">
|
||||||
<button class="healing-button" data-value="{{this.total}}" data-type="{{this.type}}"><span>{{localize "DAGGERHEART.Chat.HealingRoll.Heal"}}</span></button>
|
<button class="healing-button" data-value="{{total}}" data-type="{{type}}"><span>{{localize "DAGGERHEART.Chat.HealingRoll.Heal"}}</span></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue