``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
import { DiceAdjustmentTypeEnum, UsableDiceAdjustmentTypeEnum } from './constants';
|
|
/**
|
|
*
|
|
* @param advantageAdjustments
|
|
* @param disadvantageAdjustments
|
|
*/
|
|
export function deriveUsableDiceAdjustmentType(advantageAdjustments, disadvantageAdjustments) {
|
|
const advantageCount = advantageAdjustments.length;
|
|
const disadvantageCount = disadvantageAdjustments.length;
|
|
const hasAdvantage = advantageCount > 0;
|
|
const hasDisadvantage = disadvantageCount > 0;
|
|
if (hasAdvantage && !hasDisadvantage) {
|
|
return UsableDiceAdjustmentTypeEnum.ADVANTAGE;
|
|
}
|
|
if (!hasAdvantage && hasDisadvantage) {
|
|
return UsableDiceAdjustmentTypeEnum.DISADVANTAGE;
|
|
}
|
|
if (hasAdvantage && hasDisadvantage) {
|
|
const restrictedAdvantageCount = advantageAdjustments.filter((adjustment) => adjustment.restriction).length;
|
|
const restrictedDisadvantageCount = disadvantageAdjustments.filter((adjustment) => adjustment.restriction).length;
|
|
const fullAdvantageCount = advantageCount - restrictedAdvantageCount;
|
|
const fullDisadvantageCount = disadvantageCount - restrictedDisadvantageCount;
|
|
const hasFullAdvantage = fullAdvantageCount > 0;
|
|
const hasFullDisadvantage = fullDisadvantageCount > 0;
|
|
const hasRestrictedAdvantage = restrictedAdvantageCount > 0;
|
|
const hasRestrictedDisadvantage = restrictedDisadvantageCount > 0;
|
|
// Have both full types, means it always cancels and we dont care about restrictions
|
|
if (hasFullAdvantage && hasFullDisadvantage) {
|
|
return UsableDiceAdjustmentTypeEnum.NONE;
|
|
}
|
|
// Have either restricted advantage or disadvantage, you could possible use either, or none
|
|
if (hasRestrictedAdvantage || hasRestrictedDisadvantage) {
|
|
return UsableDiceAdjustmentTypeEnum.ADVANTAGE_DISADVANTAGE;
|
|
}
|
|
}
|
|
return UsableDiceAdjustmentTypeEnum.NONE;
|
|
}
|
|
/**
|
|
*
|
|
* @param levelScale
|
|
*/
|
|
export function deriveMartialArtsDamageDie(levelScale) {
|
|
// 2025 Update: Keeping this default from previous logic where we didn't have the levelScale.
|
|
let dice = {
|
|
diceCount: 1,
|
|
diceMultiplier: null,
|
|
diceString: '',
|
|
diceValue: 4,
|
|
fixedValue: null,
|
|
};
|
|
if (levelScale.dice) {
|
|
dice = levelScale.dice;
|
|
}
|
|
return dice;
|
|
}
|
|
/**
|
|
*
|
|
* @param type
|
|
*/
|
|
export function deriveDiceAdjustmentTypeName(type) {
|
|
let name = '';
|
|
switch (type) {
|
|
case DiceAdjustmentTypeEnum.ADVANTAGE:
|
|
name = 'Advantage';
|
|
break;
|
|
case DiceAdjustmentTypeEnum.DISADVANTAGE:
|
|
name = 'Disadvantage';
|
|
break;
|
|
case DiceAdjustmentTypeEnum.BONUS:
|
|
name = 'Bonus';
|
|
break;
|
|
default:
|
|
//not implemented
|
|
}
|
|
return name;
|
|
}
|