New source found from dndbeyond.com
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user