mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
[Feature] 687 - Companion Improvements (#1049)
* Companions can't be put into CombatState anymore. Companions now have a Action Roll button * Added handling for multiselect toggleCombat
This commit is contained in:
parent
a72d4583cd
commit
16173363d4
4 changed files with 87 additions and 1 deletions
|
|
@ -1,6 +1,9 @@
|
||||||
export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
||||||
static DEFAULT_OPTIONS = {
|
static DEFAULT_OPTIONS = {
|
||||||
classes: ['daggerheart']
|
classes: ['daggerheart'],
|
||||||
|
actions: {
|
||||||
|
combat: DHTokenHUD.#onToggleCombat
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
|
|
@ -11,8 +14,14 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static #nonCombatTypes = ['environment', 'companion'];
|
||||||
|
|
||||||
async _prepareContext(options) {
|
async _prepareContext(options) {
|
||||||
const context = await super._prepareContext(options);
|
const context = await super._prepareContext(options);
|
||||||
|
|
||||||
|
context.canToggleCombat = DHTokenHUD.#nonCombatTypes.includes(this.actor.type)
|
||||||
|
? false
|
||||||
|
: context.canToggleCombat;
|
||||||
context.systemStatusEffects = Object.keys(context.statusEffects).reduce((acc, key) => {
|
context.systemStatusEffects = Object.keys(context.statusEffects).reduce((acc, key) => {
|
||||||
const effect = context.statusEffects[key];
|
const effect = context.statusEffects[key];
|
||||||
if (effect.systemEffect) acc[key] = effect;
|
if (effect.systemEffect) acc[key] = effect;
|
||||||
|
|
@ -36,6 +45,20 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async #onToggleCombat() {
|
||||||
|
const tokens = canvas.tokens.controlled
|
||||||
|
.filter(t => !t.actor || !DHTokenHUD.#nonCombatTypes.includes(t.actor.type))
|
||||||
|
.map(t => t.document);
|
||||||
|
if (!this.object.controlled) tokens.push(this.document);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.document.inCombat) await TokenDocument.implementation.deleteCombatants(tokens);
|
||||||
|
else await TokenDocument.implementation.createCombatants(tokens);
|
||||||
|
} catch (err) {
|
||||||
|
ui.notifications.warn(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_getStatusEffectChoices() {
|
_getStatusEffectChoices() {
|
||||||
// Include all HUD-enabled status effects
|
// Include all HUD-enabled status effects
|
||||||
const choices = {};
|
const choices = {};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
|
||||||
classes: ['actor', 'companion'],
|
classes: ['actor', 'companion'],
|
||||||
position: { width: 340 },
|
position: { width: 340 },
|
||||||
actions: {
|
actions: {
|
||||||
|
actionRoll: DhCompanionSheet.#actionRoll,
|
||||||
levelManagement: DhCompanionSheet.#levelManagement
|
levelManagement: DhCompanionSheet.#levelManagement
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -45,6 +46,52 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
|
||||||
/* Application Clicks Actions */
|
/* Application Clicks Actions */
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static async #actionRoll(event) {
|
||||||
|
const partner = this.actor.system.partner;
|
||||||
|
const config = {
|
||||||
|
event,
|
||||||
|
title: `${game.i18n.localize('DAGGERHEART.GENERAL.Roll.action')}: ${this.actor.name}`,
|
||||||
|
headerTitle: `Companion ${game.i18n.localize('DAGGERHEART.GENERAL.Roll.action')}`,
|
||||||
|
roll: {
|
||||||
|
trait: partner.system.spellcastModifierTrait?.key
|
||||||
|
},
|
||||||
|
hasRoll: true,
|
||||||
|
data: partner.getRollData()
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = await partner.diceRoll(config);
|
||||||
|
this.consumeResource(result?.costs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove when Action Refactor part #2 done
|
||||||
|
async consumeResource(costs) {
|
||||||
|
if (!costs?.length) return;
|
||||||
|
|
||||||
|
const partner = this.actor.system.partner;
|
||||||
|
const usefulResources = {
|
||||||
|
...foundry.utils.deepClone(partner.system.resources),
|
||||||
|
fear: {
|
||||||
|
value: game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear),
|
||||||
|
max: game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).maxFear,
|
||||||
|
reversed: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const resources = game.system.api.fields.ActionFields.CostField.getRealCosts(costs).map(c => {
|
||||||
|
const resource = usefulResources[c.key];
|
||||||
|
return {
|
||||||
|
key: c.key,
|
||||||
|
value: (c.total ?? c.value) * (resource.isReversed ? 1 : -1),
|
||||||
|
target: resource.target,
|
||||||
|
keyIsID: resource.keyIsID
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
await partner.modifyResource(resources);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the companions level management window.
|
* Opens the companions level management window.
|
||||||
* @type {ApplicationClickAction}
|
* @type {ApplicationClickAction}
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,17 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.action-section {
|
||||||
|
display: flex;
|
||||||
|
padding: 0 10px;
|
||||||
|
margin-top: 20px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
button {
|
||||||
|
height: 40px;
|
||||||
|
width: 100%;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="action-section">
|
||||||
|
<button type="button" data-action="actionRoll">{{localize "DAGGERHEART.GENERAL.Roll.action"}}</button>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue