mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Bugfix - Companion Levelup Features (#303)
* Fixed so that features gained from companion levleup are granted properly to its partner * Fixed localization error I noticed
This commit is contained in:
parent
99e41ec6f7
commit
9189a95ea3
7 changed files with 79 additions and 60 deletions
|
|
@ -5,13 +5,13 @@ import { LevelOptionType } from '../data/levelTier.mjs';
|
|||
import DHFeature from '../data/item/feature.mjs';
|
||||
|
||||
export default class DhpActor extends Actor {
|
||||
|
||||
/**
|
||||
* Return the first Actor active owner.
|
||||
*/
|
||||
get owner() {
|
||||
const user = this.hasPlayerOwner && game.users.players.find(u => this.testUserPermission(u, "OWNER") && u.active);;
|
||||
if(!user) return game.user.isGM ? game.user : null;
|
||||
const user =
|
||||
this.hasPlayerOwner && game.users.players.find(u => this.testUserPermission(u, 'OWNER') && u.active);
|
||||
if (!user) return game.user.isGM ? game.user : null;
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ export default class DhpActor extends Actor {
|
|||
return acc;
|
||||
}, {});
|
||||
|
||||
const featureIds = [];
|
||||
const features = [];
|
||||
const domainCards = [];
|
||||
const experiences = [];
|
||||
const subclassFeatureState = { class: null, multiclass: null };
|
||||
|
|
@ -74,7 +74,7 @@ export default class DhpActor extends Actor {
|
|||
const advancementCards = level.selections.filter(x => x.type === 'domainCard').map(x => x.itemUuid);
|
||||
domainCards.push(...achievementCards, ...advancementCards);
|
||||
experiences.push(...Object.keys(level.achievements.experiences));
|
||||
featureIds.push(...level.selections.flatMap(x => x.featureIds));
|
||||
features.push(...level.selections.flatMap(x => x.features));
|
||||
|
||||
const subclass = level.selections.find(x => x.type === 'subclass');
|
||||
if (subclass) {
|
||||
|
|
@ -88,8 +88,11 @@ export default class DhpActor extends Actor {
|
|||
multiclass = level.selections.find(x => x.type === 'multiclass');
|
||||
});
|
||||
|
||||
for (let featureId of featureIds) {
|
||||
this.items.get(featureId).delete();
|
||||
for (let feature of features) {
|
||||
if (feature.onPartner && !this.system.partner) continue;
|
||||
|
||||
const document = feature.onPartner ? this.system.partner : this;
|
||||
document.items.get(feature.id)?.delete();
|
||||
}
|
||||
|
||||
if (experiences.length > 0) {
|
||||
|
|
@ -153,7 +156,6 @@ export default class DhpActor extends Actor {
|
|||
}
|
||||
|
||||
async levelUp(levelupData) {
|
||||
const actions = [];
|
||||
const levelups = {};
|
||||
for (var levelKey of Object.keys(levelupData)) {
|
||||
const level = levelupData[levelKey];
|
||||
|
|
@ -237,7 +239,9 @@ export default class DhpActor extends Actor {
|
|||
...featureData,
|
||||
description: game.i18n.localize(featureData.description)
|
||||
});
|
||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
||||
|
||||
const document = featureData.toPartner && this.system.partner ? this.system.partner : this;
|
||||
const embeddedItem = await document.createEmbeddedDocuments('Item', [
|
||||
{
|
||||
...featureData,
|
||||
name: game.i18n.localize(featureData.name),
|
||||
|
|
@ -245,9 +249,13 @@ export default class DhpActor extends Actor {
|
|||
system: feature
|
||||
}
|
||||
]);
|
||||
addition.checkbox.featureIds = !addition.checkbox.featureIds
|
||||
? [embeddedItem[0].id]
|
||||
: [...addition.checkbox.featureIds, embeddedItem[0].id];
|
||||
const newFeature = {
|
||||
onPartner: Boolean(featureData.toPartner && this.system.partner),
|
||||
id: embeddedItem[0].id
|
||||
};
|
||||
addition.checkbox.features = !addition.checkbox.features
|
||||
? [newFeature]
|
||||
: [...addition.checkbox.features, newFeature];
|
||||
}
|
||||
|
||||
selections.push(addition.checkbox);
|
||||
|
|
@ -317,7 +325,6 @@ export default class DhpActor extends Actor {
|
|||
|
||||
await this.update({
|
||||
system: {
|
||||
actions: [...this.system.actions, ...actions],
|
||||
levelData: {
|
||||
level: {
|
||||
current: this.system.levelData.level.changed
|
||||
|
|
@ -369,16 +376,16 @@ export default class DhpActor extends Actor {
|
|||
const modifier = roll.modifier !== null ? Number.parseInt(roll.modifier) : null;
|
||||
return modifier !== null
|
||||
? [
|
||||
{
|
||||
value: modifier,
|
||||
label: roll.label
|
||||
? modifier >= 0
|
||||
? `${roll.label} +${modifier}`
|
||||
: `${roll.label} ${modifier}`
|
||||
: null,
|
||||
title: roll.label
|
||||
}
|
||||
]
|
||||
{
|
||||
value: modifier,
|
||||
label: roll.label
|
||||
? modifier >= 0
|
||||
? `${roll.label} +${modifier}`
|
||||
: `${roll.label} ${modifier}`
|
||||
: null,
|
||||
title: roll.label
|
||||
}
|
||||
]
|
||||
: [];
|
||||
}
|
||||
|
||||
|
|
@ -460,7 +467,7 @@ export default class DhpActor extends Actor {
|
|||
|
||||
if (Hooks.call(`${CONFIG.DH.id}.postDamageTreshold`, this, hpDamage, damage, type) === false) return null;
|
||||
|
||||
if(!hpDamage) return;
|
||||
if (!hpDamage) return;
|
||||
|
||||
const updates = [{ value: hpDamage, type: 'hitPoints' }];
|
||||
|
||||
|
|
@ -469,8 +476,8 @@ export default class DhpActor extends Actor {
|
|||
this.system.armor &&
|
||||
this.system.armor.system.marks.value < this.system.armorScore
|
||||
) {
|
||||
const armorStackResult = await this.owner.query('armorStack', {actorId: this.uuid, damage: hpDamage});
|
||||
if(armorStackResult) {
|
||||
const armorStackResult = await this.owner.query('armorStack', { actorId: this.uuid, damage: hpDamage });
|
||||
if (armorStackResult) {
|
||||
const { modifiedDamage, armorSpent, stressSpent } = armorStackResult;
|
||||
updates.find(u => u.type === 'hitPoints').value = modifiedDamage;
|
||||
updates.push(
|
||||
|
|
@ -479,7 +486,7 @@ export default class DhpActor extends Actor {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await this.modifyResource(updates);
|
||||
|
||||
if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, damage, type) === false) return null;
|
||||
|
|
@ -493,7 +500,7 @@ export default class DhpActor extends Actor {
|
|||
async modifyResource(resources) {
|
||||
if (!resources.length) return;
|
||||
|
||||
if(resources.find(r => r.type === 'stress')) this.convertStressDamageToHP(resources);
|
||||
if (resources.find(r => r.type === 'stress')) this.convertStressDamageToHP(resources);
|
||||
let updates = { actor: { target: this, resources: {} }, armor: { target: this.system.armor, resources: {} } };
|
||||
resources.forEach(r => {
|
||||
switch (r.type) {
|
||||
|
|
@ -521,7 +528,12 @@ export default class DhpActor extends Actor {
|
|||
});
|
||||
Object.values(updates).forEach(async u => {
|
||||
if (Object.keys(u.resources).length > 0) {
|
||||
await emitAsGM(GMUpdateEvent.UpdateDocument, u.target.update.bind(u.target), u.resources, u.target.uuid);
|
||||
await emitAsGM(
|
||||
GMUpdateEvent.UpdateDocument,
|
||||
u.target.update.bind(u.target),
|
||||
u.resources,
|
||||
u.target.uuid
|
||||
);
|
||||
/* if (game.user.isGM) {
|
||||
await u.target.update(u.resources);
|
||||
} else {
|
||||
|
|
@ -540,27 +552,28 @@ export default class DhpActor extends Actor {
|
|||
|
||||
convertDamageToThreshold(damage) {
|
||||
return damage >= this.system.damageThresholds.severe
|
||||
? 3
|
||||
: damage >= this.system.damageThresholds.major
|
||||
? 2
|
||||
: damage >= this.system.damageThresholds.minor
|
||||
? 1
|
||||
: 0;
|
||||
? 3
|
||||
: damage >= this.system.damageThresholds.major
|
||||
? 2
|
||||
: damage >= this.system.damageThresholds.minor
|
||||
? 1
|
||||
: 0;
|
||||
}
|
||||
|
||||
convertStressDamageToHP(resources) {
|
||||
const stressDamage = resources.find(r => r.type === 'stress'),
|
||||
newValue = this.system.resources.stress.value + stressDamage.value;
|
||||
if(newValue <= this.system.resources.stress.maxTotal) return;
|
||||
if (newValue <= this.system.resources.stress.maxTotal) return;
|
||||
const hpDamage = resources.find(r => r.type === 'hitPoints');
|
||||
if(hpDamage) hpDamage.value++;
|
||||
else resources.push({
|
||||
type: 'hitPoints',
|
||||
value: 1
|
||||
})
|
||||
if (hpDamage) hpDamage.value++;
|
||||
else
|
||||
resources.push({
|
||||
type: 'hitPoints',
|
||||
value: 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const registerDHActorHooks = () => {
|
||||
CONFIG.queries.armorStack = DamageReductionDialog.armorStackQuery;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue