Adversary Attack

This commit is contained in:
Dapoolp 2025-06-24 21:28:49 +02:00
parent 5a8aed73d2
commit 2981aab917
19 changed files with 269 additions and 499 deletions

View file

@ -2,6 +2,7 @@ import DamageSelectionDialog from '../../applications/damageSelectionDialog.mjs'
import CostSelectionDialog from '../../applications/costSelectionDialog.mjs';
import { abilities } from '../../config/actorConfig.mjs';
import { DHActionDiceData, DHDamageData, DHDamageField } from './actionDice.mjs';
import DhpActor from '../../documents/actor.mjs';
const fields = foundry.data.fields;
@ -87,7 +88,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
choices: SYSTEM.GENERAL.range,
required: false,
blank: true,
initial: null
// initial: null
}),
...this.defineExtraSchema()
};
@ -99,7 +100,8 @@ export class DHBaseAction extends foundry.abstract.DataModel {
roll: new fields.SchemaField({
type: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.GENERAL.rollTypes }),
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 }),
bonus: 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 }),
@ -150,7 +152,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
}
get actor() {
return this.item?.actor;
return this.item instanceof DhpActor ? this.item : this.item?.actor;
}
get chatTemplate() {
@ -197,6 +199,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
source: {
item: this.item._id,
action: this._id
// action: this
},
type: this.type,
hasDamage: !!this.damage?.parts?.length,
@ -229,25 +232,25 @@ export class DHBaseAction extends foundry.abstract.DataModel {
this.spendCost(config.costs.values);
this.spendUses(config.uses);
// console.log(config)
return config;
}
/* ROLL */
hasRoll() {
return this.roll?.type && this.roll?.trait;
// return this.roll?.type && this.roll?.trait;
return this.roll?.type;
}
async proceedRoll(config) {
if (!this.hasRoll()) return config;
const modifierValue = this.actor.system.traits[this.roll.trait].value;
// const modifierValue = this.actor.system.traits[this.roll.trait].value;
config = {
...config,
roll: {
modifiers: [],
trait: this.roll?.trait,
label: game.i18n.localize(abilities[this.roll.trait].label),
// label: game.i18n.localize(abilities[this.roll.trait].label),
label: 'Attack',
type: this.actionType,
difficulty: this.roll?.difficulty
}
@ -347,7 +350,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
name: actor.actor.name,
img: actor.actor.img,
difficulty: actor.actor.system.difficulty,
evasion: actor.actor.system.evasion?.value
evasion: actor.actor.system.evasion?.total
}
}
/* TARGET */
@ -363,7 +366,6 @@ export class DHBaseAction extends foundry.abstract.DataModel {
async applyEffects(event, data, force=false) {
if(!this.effects?.length || !data.system.targets.length) return;
data.system.targets.forEach(async (token) => {
// console.log(token, force)
if(!token.hit && !force) return;
this.effects.forEach(async (e) => {
const actor = canvas.tokens.get(token.id)?.actor,
@ -417,7 +419,7 @@ export class DHDamageAction extends DHBaseAction {
async rollDamage(event, data) {
let formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
if (!formula || formula == '') return;
let roll = { formula: formula, total: formula },
bonusDamage = [];
@ -427,7 +429,7 @@ export class DHDamageAction extends DHBaseAction {
formula,
targets: (data.system?.targets ?? data.targets).map(x => ({ id: x.id, name: x.name, img: x.img, hit: true }))
}
roll = CONFIG.Dice.daggerheart.DamageRoll.build(config)
}
}
@ -479,7 +481,6 @@ export class DHHealingAction extends DHBaseAction {
}
async rollHealing(event, data) {
console.log(event, data)
let formula = this.healing.value.getFormula(this.actor);
if (!formula || formula == '') return;

View file

@ -11,6 +11,7 @@ export class DHActionDiceData extends foundry.abstract.DataModel {
initial: 'proficiency',
label: 'Multiplier'
}),
flatMultiplier : new fields.NumberField({ nullable: true, initial: 1, label: 'Flat Multiplier' }),
dice: new fields.StringField({ choices: SYSTEM.GENERAL.diceTypes, initial: 'd6', label: 'Formula' }),
bonus: new fields.NumberField({ nullable: true, initial: null, label: 'Bonus' }),
custom: new fields.SchemaField({
@ -21,9 +22,10 @@ export class DHActionDiceData extends foundry.abstract.DataModel {
}
getFormula(actor) {
const multiplier = this.multiplier === 'flat' ? this.flatMultiplier : actor.system[this.multiplier]?.total;
return this.custom.enabled
? this.custom.formula
: `${actor.system[this.multiplier]?.total ?? 1}${this.dice}${this.bonus ? (this.bonus < 0 ? ` - ${Math.abs(this.bonus)}` : ` + ${this.bonus}`) : ''}`;
: `${multiplier ?? 1}${this.dice}${this.bonus ? (this.bonus < 0 ? ` - ${Math.abs(this.bonus)}` : ` + ${this.bonus}`) : ''}`;
}
}

View file

@ -1,3 +1,6 @@
import DhpItem from '../../documents/item.mjs';
import ActionField from '../fields/actionField.mjs';
import DHWeapon from '../item/weapon.mjs';
import BaseDataActor from './base.mjs';
const resourceField = () =>
@ -39,7 +42,7 @@ export default class DhpAdversary extends BaseDataActor {
hitPoints: resourceField(),
stress: resourceField()
}),
attack: new fields.SchemaField({
/* attack: new fields.SchemaField({
name: new fields.StringField({}),
modifier: new fields.NumberField({ required: true, integer: true, initial: 0 }),
range: new fields.StringField({
@ -55,6 +58,43 @@ export default class DhpAdversary extends BaseDataActor {
initial: SYSTEM.GENERAL.damageTypes.physical.id
})
})
}), */
/* attack: new fields.EmbeddedDocumentField(DhpItem,
{
// type: 'weapon'
// initial: new DhpItem(
// {
// name: 'Attack',
// type: 'weapon'
// },
// {
// parent: this.parent,
// parentCollection: 'items'
// }
// )
// initial: {type: 'weapon'}
}
), */
attack: new ActionField({
initial: {
name: 'Attack',
_id: foundry.utils.randomID(),
systemPath: 'attack',
type: 'attack',
range: 'melee',
target: {
type: 'any',
amount: 1
},
roll: {
type: 'weapon'
},
damage: {
parts: [{
multiplier: 'flat'
}]
}
}
}),
experiences: new fields.TypedObjectField(
new fields.SchemaField({
@ -65,4 +105,21 @@ export default class DhpAdversary extends BaseDataActor {
/* Features waiting on pseudo-document data model addition */
};
}
prepareBaseData() {
// console.log(this.attack)
/* if(!this.attack) {
this.attack = new DhpItem(
{
name: 'Attack',
type: 'weapon',
_id: foundry.utils.randomID()
},
{
parent: this.parent,
parentCollection: 'items'
}
)
} */
}
}

View file

@ -1,23 +1,13 @@
import DhpActor from "../../documents/actor.mjs";
import ActionField from "../fields/actionField.mjs";
export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
title: new fields.StringField(),
origin: new fields.StringField({ required: true }),
dice: new fields.DataField(),
roll: new fields.DataField(),
modifiers: new fields.ArrayField(
new fields.SchemaField({
value: new fields.NumberField({ integer: true }),
label: new fields.StringField({})
})
),
advantageState: new fields.BooleanField({ nullable: true, initial: null }),
advantage: new fields.SchemaField({
dice: new fields.StringField({}),
value: new fields.NumberField({ integer: true })
}),
targets: new fields.ArrayField(
new fields.SchemaField({
id: new fields.StringField({}),
@ -29,24 +19,13 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel {
})
),
hasDamage: new fields.BooleanField({ initial: false }),
hasHealing: new fields.BooleanField({ initial: false }),
hasEffect: new fields.BooleanField({ initial: false }),
/* damage: new fields.SchemaField(
{
value: new fields.StringField({}),
type: new fields.StringField({ choices: Object.keys(SYSTEM.GENERAL.damageTypes), integer: false })
},
{ nullable: true, initial: null }
), */
action: new fields.SchemaField({
itemId: new fields.StringField(),
actionId: new fields.StringField()
source: new fields.SchemaField({
actor: new fields.StringField(),
item: new fields.StringField(),
action: new fields.StringField()
})
};
}
prepareDerivedData() {
this.targets.forEach(target => {
target.hit = target.difficulty ? this.total >= target.difficulty : this.total >= target.evasion;
});
}
}

View file

@ -1,11 +1,4 @@
import { DualityRollColor } from '../settings/Appearance.mjs';
const fields = foundry.data.fields;
const diceField = () =>
new fields.SchemaField({
dice: new fields.StringField({}),
value: new fields.NumberField({ integer: true })
});
export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
static dualityResult = {
@ -17,18 +10,7 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
static defineSchema() {
return {
title: new fields.StringField(),
/* origin: new fields.StringField({ required: true }), */
roll: new fields.DataField({}),
/* modifiers: new fields.ArrayField(
new fields.SchemaField({
value: new fields.NumberField({ integer: true }),
label: new fields.StringField({})
})
), */
/* hope: diceField(),
fear: diceField(),
advantageState: new fields.BooleanField({ nullable: true, initial: null }), */
/* advantage: diceField(), */
targets: new fields.ArrayField(
new fields.SchemaField({
id: new fields.StringField({}),
@ -49,47 +31,4 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
})
};
}
/* get diceTotal() {
return this.hope.value + this.fear.value;
}
get modifierTotal() {
const total = this.modifiers.reduce((acc, x) => acc + x.value, 0);
return {
value: total,
label: total > 0 ? `+${total}` : total < 0 ? `${total}` : ''
};
}
get dualityResult() {
return this.hope.value > this.fear.value
? this.constructor.dualityResult.hope
: this.fear.value > this.hope.value
? this.constructor.dualityResult.fear
: this.constructor.dualityResult.critical;
}
get totalLabel() {
const label =
this.hope.value > this.fear.value
? 'DAGGERHEART.General.Hope'
: this.fear.value > this.hope.value
? 'DAGGERHEART.General.Fear'
: 'DAGGERHEART.General.CriticalSuccess';
return game.i18n.localize(label);
}
get colorful() {
return (
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.appearance).dualityColorScheme ===
DualityRollColor.colorful.value
);
}
prepareDerivedData() {
this.hope.discarded = this.hope.value < this.fear.value;
this.fear.discarded = this.fear.value < this.hope.value;
} */
}