New source found from dndbeyond.com

This commit is contained in:
2026-07-08 01:00:09 -07:00
parent 9a983a6d7b
commit dcefa0d2f2
2865 changed files with 222467 additions and 49053 deletions
@@ -1,7 +1,11 @@
import { orderBy } from "lodash";
import { Constants } from "@dndbeyond/character-rules-engine/es";
import { DiceOperation, DieTerm, RollRequest } from "@dndbeyond/dice";
import { DiceOperations } from "@dndbeyond/pocket-dimension-dice/enums";
import {
RollDicePayload,
DiceNotationSet,
} from "@dndbeyond/pocket-dimension-dice/types";
interface Hack__OrderableDieValueInfo {
idx: number;
@@ -15,14 +19,14 @@ interface Hack__OrderableDieValueInfo {
* @param rollRequestResult
*/
export function hack__generateDiceRollResultTermLookup(
rollRequestResult: RollRequest
): Record<number, DieTerm> {
const hack__diceRollResultTermLookup: Record<number, DieTerm> = {};
rollRequestResult: RollDicePayload["data"]
): Record<number, DiceNotationSet> {
const hack__diceRollResultTermLookup: Record<number, DiceNotationSet> = {};
let dieCurrentIdx: number = 0;
rollRequestResult.rolls[0].diceNotation.set.forEach((dieTerm) => {
dieTerm.dice.forEach((die) => {
hack__diceRollResultTermLookup[dieCurrentIdx] = dieTerm;
rollRequestResult.rolls[0].diceNotation.set.forEach((diceNotationSet) => {
diceNotationSet?.dice.forEach(() => {
hack__diceRollResultTermLookup[dieCurrentIdx] = diceNotationSet;
dieCurrentIdx++;
});
});
@@ -37,7 +41,7 @@ export function hack__generateDiceRollResultTermLookup(
* @param rollRequestResult
*/
export function hack__generateDiceRollResultValueExcludeTypeLookup(
rollRequestResult: RollRequest
rollRequestResult: RollDicePayload["data"]
): Record<number, Constants.DiceRollExcludeTypeEnum> {
const hack__diceRollResultValueExcludeTypeLookup: Record<
number,
@@ -50,48 +54,52 @@ export function hack__generateDiceRollResultValueExcludeTypeLookup(
let dieGroupStartIdx: number = 0;
rollRequestResult.rolls[0].diceNotation.set.forEach((dieTerm) => {
let diceCount = dieTerm.count;
rollRequestResult.rolls[0].diceNotation.set.forEach((diceNotationSet) => {
let diceCount = diceNotationSet?.count;
//determine sortOrder based on dieTerm.operation
let sortOrder: "asc" | "desc" | null = null;
switch (dieTerm.operation) {
case DiceOperation.Min:
switch (diceNotationSet?.operation) {
case DiceOperations.Min:
sortOrder = "asc";
break;
case DiceOperation.Max:
case DiceOperations.Max:
default:
sortOrder = "desc";
}
let dieTermResults =
let results =
rollResult?.values.slice(
dieGroupStartIdx,
dieGroupStartIdx + diceCount
dieGroupStartIdx + (diceCount ?? 0)
) ?? [];
let hack__orderableDieValueInfos: Array<Hack__OrderableDieValueInfo> =
dieTermResults.map((value, idx) => ({
results.map((value, idx) => ({
idx: dieGroupStartIdx + idx,
value,
}));
let orderedDieTermResults = orderBy(
let orderedResults = orderBy(
hack__orderableDieValueInfos,
(valueInfo) => valueInfo.value,
sortOrder
);
//build-up hack__diceRollResultValueExcludeTypeLookup
orderedDieTermResults.slice(0, dieTerm.operand).forEach((dieTermResult) => {
hack__diceRollResultValueExcludeTypeLookup[dieTermResult.idx] =
Constants.DiceRollExcludeTypeEnum.ALL;
});
orderedDieTermResults.slice(dieTerm.operand).forEach((dieTermResult) => {
hack__diceRollResultValueExcludeTypeLookup[dieTermResult.idx] =
Constants.DiceRollExcludeTypeEnum.NONE;
});
orderedResults
.slice(0, diceNotationSet?.operand)
.forEach((diceNotationSet) => {
hack__diceRollResultValueExcludeTypeLookup[diceNotationSet.idx] =
Constants.DiceRollExcludeTypeEnum.ALL;
});
orderedResults
.slice(diceNotationSet?.operand)
.forEach((diceNotationSet) => {
hack__diceRollResultValueExcludeTypeLookup[diceNotationSet.idx] =
Constants.DiceRollExcludeTypeEnum.NONE;
});
//move diceGroupStartIdx
dieGroupStartIdx += diceCount;
dieGroupStartIdx += diceCount ?? 0;
});
return hack__diceRollResultValueExcludeTypeLookup;
@@ -5,13 +5,12 @@ import {
HelperUtils,
} from "@dndbeyond/character-rules-engine/es";
import {
DiceEvent,
Dice,
RollRequest,
RollType,
RollKind,
DiceNotation,
} from "@dndbeyond/dice";
RollKinds,
RollTypes,
} from "@dndbeyond/pocket-dimension-dice/constants";
import { parseDiceNotation } from "@dndbeyond/pocket-dimension-dice/helpers/parseDiceNotation";
import { toDiceNotationString } from "@dndbeyond/pocket-dimension-dice/helpers/toDiceNotationString";
import { RollDicePayload } from "@dndbeyond/pocket-dimension-dice/types";
import { DiceComponentUtils, TypeScriptUtils } from "../index";
import {
@@ -19,45 +18,12 @@ import {
hack__generateDiceRollResultValueExcludeTypeLookup,
} from "./hacks";
/**
* Adds an event listener that sets the state variable isCriticalHit to false when a roll is performed
* that is not this component's to-hit roll
*
* Note: Move this to a hook if the components go classless
*/
export function setupResetCritStateOnRoll(
rollAction: string,
rollNode: React.ReactNode
): (eventData: any) => void {
let handler = _handler.bind(undefined, rollAction, rollNode);
Dice.addEventListener(DiceEvent.ROLL, handler);
return handler;
}
export function _handler(
rollAction: string,
rollNode: React.PureComponent<any, any>,
result: RollRequest
): void {
let shouldResetCritState =
// A multi-roll was performed
result.rolls.length !== 1 ||
// A roll from another action was performed
rollAction != result.action ||
// This didn't have a to-hit roll, and we already know it is this same action
result.rolls.find((r) => r.rollType != RollType.ToHit);
if (shouldResetCritState) {
rollNode?.setState({ isCriticalHit: false });
}
}
/**
* Checks for a critical hit
*/
export function isCriticalRoll(result: RollRequest): boolean {
export function isCriticalRoll(result: RollDicePayload["data"]): boolean {
// Does this roll have a to-hit roll?
const hitRoll = result.rolls.find((r) => r.rollType == RollType.ToHit);
const hitRoll = result.rolls.find((r) => r.rollType == RollTypes.ToHit);
if (hitRoll) {
const minRollForCrit: number = 20;
let numCritRolls: number =
@@ -65,10 +31,10 @@ export function isCriticalRoll(result: RollRequest): boolean {
let critRoll: boolean = false;
switch (hitRoll.rollKind) {
case RollKind.Disadvantage:
case RollKinds.Disadvantage:
critRoll = numCritRolls >= 2;
break;
case RollKind.Advantage:
case RollKinds.Advantage:
default:
critRoll = numCritRolls > 0;
break;
@@ -97,12 +63,16 @@ export function getDamageDiceNotation(
return DiceUtils.renderDice(damage);
}
let dn = DiceNotation.parseDiceNotation(DiceUtils.renderDice(damage));
let dn = parseDiceNotation(DiceUtils.renderDice(damage));
for (let i = 0; i < dn.set.length; i++) {
// Double the dice on each term
dn.set[i].count *= 2;
if (dn.set[i]) {
dn.set[i]!.count *= 2;
}
}
return dn.toDiceNotationString();
return toDiceNotationString(dn.set, dn.constant);
}
/**
@@ -119,7 +89,7 @@ export function getDieTypeValue(dieType: string): number {
* @param rollRequestResult
*/
export function generateRollValueContracts(
rollRequestResult: RollRequest
rollRequestResult: RollDicePayload["data"]
): Array<RollValueContract> | null {
//these hacks make it easier to grab the data from the dice api until the api is updated
const hack__diceRollResultTermLookup =