Skip to content

Commit

Permalink
Fixed hint for 0 bonus
Browse files Browse the repository at this point in the history
  • Loading branch information
dmrickey committed Oct 9, 2024
1 parent 7bf756d commit 28e8dc8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
23 changes: 22 additions & 1 deletion src/bonuses/fortune-handler.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MODULE_NAME } from '../consts.mjs';
import { countBFlags } from '../util/flag-helpers.mjs';
import { LocalHookHandler, customGlobalHooks, localHooks } from '../util/hooks.mjs';
import { registerItemHint } from '../util/item-hints.mjs';
import { localize } from '../util/localize.mjs';
Expand Down Expand Up @@ -35,6 +34,28 @@ const skillMisfortune = 'misfortune-skill';
*/
let fortuneHintLookup = {};

/**
* Counts the amount of items that have a given boolean flags
* @param {EmbeddedCollection<ItemPF>} items
* @param {string[]} flags
* @returns {{[key: string]: number}} - the count of items that have the given boolean flags
*/
const countBFlags = (items, ...flags) => {
const count = Object.fromEntries(flags.map((flag) => [flag, 0]));

(items || []).forEach((/** @type {ItemPF} */item) => {
if (!item.isActive) return;

flags.forEach((flag) => {
if (item.hasItemBooleanFlag(flag)) {
count[flag]++;
}
});
});

return count;
}

Hooks.once('ready', () => {
fortuneHintLookup = {
// @ts-ignore - because I typed Abilities too strongly and ignoring here is easier
Expand Down
13 changes: 7 additions & 6 deletions src/targeted/bonuses/attack-bonus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { FormulaCacheHelper } from "../../util/flag-helpers.mjs";
import { signed } from "../../util/to-signed-string.mjs";
import { BaseBonus } from "./base-bonus.mjs";

/**
* @extends BaseBonus
*/
/** @extends BaseBonus */
export class AttackBonus extends BaseBonus {
/**
* @override
Expand All @@ -14,8 +12,8 @@ export class AttackBonus extends BaseBonus {
static get sourceKey() { return 'attack'; }

/**
* @inheritdoc
* @override
* @inheritdoc
* @returns {string}
*/
static get journal() { return 'Compendium.ckl-roll-bonuses.roll-bonuses-documentation.JournalEntry.FrG2K3YAM1jdSxcC.JournalEntryPage.PiyJbkTuzKHugPSk#attack'; }
Expand All @@ -28,10 +26,13 @@ export class AttackBonus extends BaseBonus {
*/
static getHints(source) {
const formula = FormulaCacheHelper.getModuleFlagFormula(source, this.key)[this.key];
const roll = RollPF.create(formula + '');
const value = this.#getAttackBonus(source);
if (!value && !formula) return;

const roll = RollPF.create((formula + '') || '0');

return roll.isDeterministic
? [`${signed(roll.evaluate({ async: false }).total)}`]
? [`${signed(value)}`]
: [`${formula}`];
}

Expand Down
13 changes: 9 additions & 4 deletions src/targeted/bonuses/effective-size.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ import { localize } from '../../util/localize.mjs';
import { signed } from '../../util/to-signed-string.mjs';
import { BaseBonus } from './base-bonus.mjs';

/** @extends BaseBonus */
export class EffectiveSizeBonus extends BaseBonus {
/**
* @inheritdoc
* @override
* @inheritdoc
*/
static get sourceKey() { return 'effective-size'; }

/**
* @override
* @inheritdoc
* @returns {string}
*/
static get journal() { return 'Compendium.ckl-roll-bonuses.roll-bonuses-documentation.JournalEntry.FrG2K3YAM1jdSxcC.JournalEntryPage.PiyJbkTuzKHugPSk#effective-size'; }

/**
* @override
* @inheritdoc
* @param {ItemPF} source
* @returns {Nullable<string[]>}
*/
static getHints(source) {
const formula = FormulaCacheHelper.getModuleFlagFormula(source, this.key)[this.key];
const size = this.#getCachedSizeBonus(source);
if (!size) return;
if (!size && !formula) return;

const formula = FormulaCacheHelper.getModuleFlagFormula(source, this.key)[this.key];
const roll = RollPF.create(formula + '');
const roll = RollPF.create((formula + '') || '0');
const mod = roll.isDeterministic
? signed(size)
: formula;
Expand All @@ -37,6 +40,7 @@ export class EffectiveSizeBonus extends BaseBonus {

/**
* @override
* @inheritdoc
* @param {ItemPF} target
* @returns {Nullable<ItemConditional>}
*/
Expand All @@ -50,6 +54,7 @@ export class EffectiveSizeBonus extends BaseBonus {

/**
* @override
* @inheritdoc
* @param {object} options
* @param {ActorPF | null} options.actor
* @param {HTMLElement} options.html
Expand Down

0 comments on commit 28e8dc8

Please sign in to comment.