Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { isLimitedUseContract } from './utils';
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getName(limitedUse) {
|
||||
return limitedUse.name;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getResetType(limitedUse) {
|
||||
return limitedUse.resetType;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getOperator(limitedUse) {
|
||||
return limitedUse.operator;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getInitialMaxUses(limitedUse) {
|
||||
var _a;
|
||||
return (_a = limitedUse.maxUses) !== null && _a !== void 0 ? _a : 0;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getNumberUsed(limitedUse) {
|
||||
return limitedUse.numberUsed;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getMinNumberConsumed(limitedUse) {
|
||||
var _a;
|
||||
const definitionMin = (_a = limitedUse.minNumberConsumed) !== null && _a !== void 0 ? _a : getMaxNumberConsumed(limitedUse);
|
||||
return Math.max(1, definitionMin);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getMaxNumberConsumed(limitedUse) {
|
||||
return limitedUse.maxNumberConsumed;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getStatModifierUsesId(limitedUse) {
|
||||
if (isLimitedUseContract(limitedUse)) {
|
||||
return limitedUse.statModifierUsesId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getResetTypeName(limitedUse) {
|
||||
return limitedUse.resetType;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getResetTypeDescription(limitedUse) {
|
||||
return limitedUse.resetTypeDescription;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getUseProficiencyBonus(limitedUse) {
|
||||
return limitedUse.useProficiencyBonus;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function getProficiencyBonusOperator(limitedUse) {
|
||||
return limitedUse.proficiencyBonusOperator;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
export var LimitedUseResetTypeEnum;
|
||||
(function (LimitedUseResetTypeEnum) {
|
||||
LimitedUseResetTypeEnum[LimitedUseResetTypeEnum["SHORT_REST"] = 1] = "SHORT_REST";
|
||||
LimitedUseResetTypeEnum[LimitedUseResetTypeEnum["LONG_REST"] = 2] = "LONG_REST";
|
||||
LimitedUseResetTypeEnum[LimitedUseResetTypeEnum["DAWN"] = 3] = "DAWN";
|
||||
LimitedUseResetTypeEnum[LimitedUseResetTypeEnum["OTHER"] = 4] = "OTHER";
|
||||
})(LimitedUseResetTypeEnum || (LimitedUseResetTypeEnum = {}));
|
||||
export var LimitedUseResetTypeNameEnum;
|
||||
(function (LimitedUseResetTypeNameEnum) {
|
||||
LimitedUseResetTypeNameEnum["SHORT_REST"] = "Short Rest";
|
||||
LimitedUseResetTypeNameEnum["LONG_REST"] = "Long Rest";
|
||||
LimitedUseResetTypeNameEnum["DAWN"] = "Dawn";
|
||||
LimitedUseResetTypeNameEnum["OTHER"] = "Other";
|
||||
})(LimitedUseResetTypeNameEnum || (LimitedUseResetTypeNameEnum = {}));
|
||||
export var EntityLimitedUseScaleOperatorEnum;
|
||||
(function (EntityLimitedUseScaleOperatorEnum) {
|
||||
EntityLimitedUseScaleOperatorEnum[EntityLimitedUseScaleOperatorEnum["ADDITION"] = 1] = "ADDITION";
|
||||
EntityLimitedUseScaleOperatorEnum[EntityLimitedUseScaleOperatorEnum["MULTIPLICATION"] = 2] = "MULTIPLICATION";
|
||||
})(EntityLimitedUseScaleOperatorEnum || (EntityLimitedUseScaleOperatorEnum = {}));
|
||||
@@ -0,0 +1,85 @@
|
||||
import { AbilityAccessors } from '../Ability';
|
||||
import { RuleDataAccessors } from '../RuleData';
|
||||
import { getInitialMaxUses, getNumberUsed, getOperator, getStatModifierUsesId, getUseProficiencyBonus, getProficiencyBonusOperator, } from './accessors';
|
||||
import { EntityLimitedUseScaleOperatorEnum } from './constants';
|
||||
import { isLimitedUseContract } from './utils';
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
* @param abilityLookup
|
||||
* @param ruleData
|
||||
* @param proficiencyBonus
|
||||
*/
|
||||
export function deriveMaxUses(limitedUse, abilityLookup, ruleData, proficiencyBonus) {
|
||||
let initialMaxUses = getInitialMaxUses(limitedUse);
|
||||
let minimumUses = RuleDataAccessors.getMinimumLimitedUseMaxUse(ruleData);
|
||||
const statModifierUsesId = getStatModifierUsesId(limitedUse);
|
||||
let scaledMaxUses = 0;
|
||||
// If we are using a stat modifier
|
||||
if (statModifierUsesId) {
|
||||
const ability = abilityLookup[statModifierUsesId];
|
||||
const abilityModifier = AbilityAccessors.getModifier(ability);
|
||||
if (abilityModifier !== null) {
|
||||
scaledMaxUses = abilityModifier;
|
||||
// If it uses the multiplication operator, the min uses is the multiplier, there is no
|
||||
// fixed value anymore since it is the multiplier now
|
||||
if (isLimitedUseContract(limitedUse) &&
|
||||
getOperator(limitedUse) === EntityLimitedUseScaleOperatorEnum.MULTIPLICATION) {
|
||||
scaledMaxUses *= initialMaxUses;
|
||||
minimumUses = initialMaxUses;
|
||||
initialMaxUses = 0;
|
||||
}
|
||||
}
|
||||
// If proficiency bonus flag is turned on
|
||||
if (isLimitedUseContract(limitedUse) && getUseProficiencyBonus(limitedUse)) {
|
||||
// If we are multiplying the proficiency bonus
|
||||
if (getProficiencyBonusOperator(limitedUse) === EntityLimitedUseScaleOperatorEnum.MULTIPLICATION) {
|
||||
// If we need to add the initial bonus, do that now before we reset it
|
||||
// for the multiplication math
|
||||
if (getOperator(limitedUse) === EntityLimitedUseScaleOperatorEnum.ADDITION) {
|
||||
scaledMaxUses += initialMaxUses;
|
||||
}
|
||||
scaledMaxUses *= proficiencyBonus;
|
||||
minimumUses = initialMaxUses;
|
||||
initialMaxUses = 0;
|
||||
}
|
||||
else {
|
||||
// then we are adding the proficiency bonus
|
||||
scaledMaxUses += proficiencyBonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Not using stat modifier, check for proficiency bonus use
|
||||
if (isLimitedUseContract(limitedUse) && getUseProficiencyBonus(limitedUse)) {
|
||||
// If proficiency bonus flag is turned on
|
||||
if (getProficiencyBonusOperator(limitedUse) === EntityLimitedUseScaleOperatorEnum.MULTIPLICATION) {
|
||||
scaledMaxUses = initialMaxUses * proficiencyBonus;
|
||||
minimumUses = initialMaxUses;
|
||||
initialMaxUses = 0;
|
||||
}
|
||||
else {
|
||||
// Add proficiency bonus
|
||||
scaledMaxUses += proficiencyBonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Math.max(minimumUses, initialMaxUses + scaledMaxUses);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
* @param abilityLookup
|
||||
* @param ruleData
|
||||
*/
|
||||
export function deriveHasUsesAvailable(limitedUse, abilityLookup, ruleData, proficiencyBonus) {
|
||||
if (!limitedUse) {
|
||||
return true;
|
||||
}
|
||||
const maxUses = deriveMaxUses(limitedUse, abilityLookup, ruleData, proficiencyBonus);
|
||||
const numberUsed = getNumberUsed(limitedUse);
|
||||
if (numberUsed < maxUses) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as LimitedUseAccessors from './accessors';
|
||||
import * as LimitedUseConstants from './constants';
|
||||
import * as LimitedUseDerivers from './derivers';
|
||||
import * as LimitedUseRenderers from './renderers';
|
||||
import * as LimitedUseUtils from './utils';
|
||||
export * from './constants';
|
||||
export { LimitedUseAccessors, LimitedUseDerivers, LimitedUseRenderers, LimitedUseUtils };
|
||||
export default Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, LimitedUseAccessors), LimitedUseConstants), LimitedUseDerivers), LimitedUseRenderers), LimitedUseUtils);
|
||||
@@ -0,0 +1,20 @@
|
||||
import { LimitedUseResetTypeEnum } from './constants';
|
||||
/**
|
||||
*
|
||||
* @param resetType
|
||||
*/
|
||||
export function renderLimitedUseResetAbbreviation(resetType) {
|
||||
switch (resetType) {
|
||||
case LimitedUseResetTypeEnum.LONG_REST:
|
||||
return 'LR';
|
||||
case LimitedUseResetTypeEnum.SHORT_REST:
|
||||
return 'SR';
|
||||
case LimitedUseResetTypeEnum.DAWN:
|
||||
return 'D';
|
||||
case LimitedUseResetTypeEnum.OTHER:
|
||||
return 'O';
|
||||
default:
|
||||
// not implemented
|
||||
}
|
||||
return '';
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { LimitedUseResetTypeEnum } from './constants';
|
||||
/**
|
||||
*
|
||||
* @param limitedUse
|
||||
*/
|
||||
export function isLimitedUseContract(limitedUse) {
|
||||
return limitedUse.statModifierUsesId !== undefined;
|
||||
}
|
||||
export function getResetTypeIdByName(name) {
|
||||
if (name !== null && LimitedUseResetTypeEnum[name]) {
|
||||
return LimitedUseResetTypeEnum[name];
|
||||
}
|
||||
return LimitedUseResetTypeEnum.OTHER;
|
||||
}
|
||||
Reference in New Issue
Block a user