Skip to content

Commit

Permalink
Merge pull request #425 from scottbenton/fix/stat-roll-negative-momentum
Browse files Browse the repository at this point in the history
fix(stat roll): Cancelling out the action die when negative momentum …
scottbenton authored May 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents bd9d5e5 + 70d1570 commit 9036b9b
Showing 6 changed files with 71 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
- Added the ability to delete Rolls from the log (AnnB)
- Added ability for GMs to remove other players and their characters from campaigns
- Added the ability for users to view completed campaign & character tracks and clocks
- Added missing rule for cancelling out the action die when your negative momentum matches your action die.

### Bug Fixes

Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@ export interface DieRerollDialogProps {
export function DieRerollDialog(props: DieRerollDialogProps) {
const { open, handleClose, roll, rollId } = props;

const momentum = useStore(
(store) => store.characters.currentCharacter.currentCharacter?.momentum ?? 0
);

const { info } = useSnackbar();
const updateRoll = useStore((store) => store.gameLog.updateRoll);
const [loading, setLoading] = useState(false);
@@ -35,9 +39,12 @@ export function DieRerollDialog(props: DieRerollDialogProps) {
const [challenge1, setChallenge1] = useState(roll.challenge1);
const [challenge2, setChallenge2] = useState(roll.challenge2);

const matchedNegativeMomentum = momentum < 0 && Math.abs(momentum) === action;
const actionTotal = Math.min(
10,
action + (roll.modifier ?? 0) + (roll.adds ?? 0)
(matchedNegativeMomentum ? 0 : action) +
(roll.modifier ?? 0) +
(roll.adds ?? 0)
);

let result: ROLL_RESULT = ROLL_RESULT.WEAK_HIT;
@@ -53,6 +60,7 @@ export function DieRerollDialog(props: DieRerollDialogProps) {
challenge1,
challenge2,
result,
matchedNegativeMomentum,
};

const handleRoll = (
Original file line number Diff line number Diff line change
@@ -48,9 +48,12 @@ export function RollDisplay(props: RollDisplayProps) {
modifier: roll.modifier,
adds: roll.adds,
rollTotal:
roll.action + (roll.modifier ?? 0) + (roll.adds ?? 0),
(roll.matchedNegativeMomentum ? 0 : roll.action) +
(roll.modifier ?? 0) +
(roll.adds ?? 0),
}}
crossOutD6={!!roll.momentumBurned}
crossOutD6Value={roll.matchedNegativeMomentum}
d10Results={[roll.challenge1, roll.challenge2]}
fixedResult={
roll.momentumBurned
@@ -64,6 +67,9 @@ export function RollDisplay(props: RollDisplayProps) {
extras={[
...(roll.challenge1 === roll.challenge2 ? ["Match"] : []),
...(roll.action === 1 ? ["One on the action die"] : []),
...(roll.matchedNegativeMomentum
? ["Matched negative momentum"]
: []),
]}
/>
</RollContainer>
Original file line number Diff line number Diff line change
@@ -15,10 +15,18 @@ export interface RollValuesProps {
value: string | number;
};
crossOutD6?: boolean;
crossOutD6Value?: boolean;
isExpanded: boolean;
}
export function RollValues(props: RollValuesProps) {
const { d10Results, d6Result, crossOutD6, fixedResult, isExpanded } = props;
const {
d10Results,
d6Result,
crossOutD6,
crossOutD6Value,
fixedResult,
isExpanded,
} = props;

if (!isExpanded) {
return null;
@@ -47,7 +55,7 @@ export function RollValues(props: RollValuesProps) {
<Typography ml={1} color={(theme) => theme.palette.grey[200]}>
<Box
component={"span"}
sx={
sx={[
d6Result.action === 1
? {
borderRadius: 1,
@@ -56,11 +64,17 @@ export function RollValues(props: RollValuesProps) {
borderStyle: "solid",
px: 0.5,
}
: {}
}
: {},
crossOutD6Value
? {
textDecoration: "line-through",
}
: {},
]}
>
{d6Result.action}
</Box>
{crossOutD6Value ? " (0)" : ""}
{d6Result.modifier ? ` + ${d6Result.modifier}` : ""}

{d6Result.adds ? ` + ${d6Result.adds}` : ""}
45 changes: 35 additions & 10 deletions src/stores/appState/useRoller.ts
Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@ export function useRoller() {
const addRollToLog = useStore((store) => store.gameLog.addRoll);

const newOracles = useStore((store) => store.rules.oracleMaps.allOraclesMap);
const momentum = useStore(
(store) => store.characters.currentCharacter.currentCharacter?.momentum ?? 0
);

const { allCustomOracleMap, customOracleCategories } = useCustomOracles();
const combinedOracleCategories = useMemo(() => {
@@ -60,7 +63,15 @@ export function useRoller() {
const challenge2 = getRoll(10);
const action = getRoll(6);

const actionTotal = Math.min(10, action + (modifier ?? 0) + (adds ?? 0));
let matchedNegativeMomentum = false;
if (momentum < 0 && Math.abs(momentum) === action) {
matchedNegativeMomentum = true;
}

const actionTotal = Math.min(
10,
(matchedNegativeMomentum ? 0 : action) + (modifier ?? 0) + (adds ?? 0)
);

let result: ROLL_RESULT = ROLL_RESULT.WEAK_HIT;
if (actionTotal > challenge1 && actionTotal > challenge2) {
@@ -81,6 +92,7 @@ export function useRoller() {
characterId,
uid,
gmsOnly: false,
matchedNegativeMomentum,
};

if (adds) {
@@ -101,17 +113,29 @@ export function useRoller() {
.catch(() => {});

if (showSnackbar) {
let announcement = `Rolled ${
moveName ? moveName + " using stat " + label : label
}.`;
if (matchedNegativeMomentum) {
announcement += ` On your action die you rolled a ${
action === 10 ? "max of 10" : action
}, which matched your momentum of ${momentum}, so your action die got cancelled out. Your modifiers are ${modifier}${
adds ? " plus " + adds + " adds" : ""
} for a total of ${actionTotal}.`;
} else {
announcement += ` On your action die you rolled a ${
action === 10 ? "max of 10" : action
} plus ${modifier}${
adds ? " plus " + adds + " adds" : ""
} for a total of ${actionTotal}.`;
}

announcement += ` On your challenge die you rolled a ${challenge1} and a ${challenge2}, for a ${getRollResultLabel(
result
)}`;
announce(
verboseScreenReaderRolls
? `Rolled ${
moveName ? moveName + " using stat " + label : label
}. On your action die you rolled a ${
action === 10 ? "max of 10" : action
} plus ${modifier}${
adds ? " plus " + adds + " adds" : ""
} for a total of ${actionTotal}. On your challenge die you rolled a ${challenge1} and a ${challenge2}, for a ${getRollResultLabel(
result
)}`
? announcement
: `Rolled ${
moveName ? moveName + "using stat" + label : label
}. Your action die had a total of ${actionTotal} against ${challenge1} and ${challenge2}, for a ${getRollResultLabel(
@@ -130,6 +154,7 @@ export function useRoller() {
characterId,
uid,
verboseScreenReaderRolls,
momentum,
]
);

1 change: 1 addition & 0 deletions src/types/DieRolls.type.ts
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ export interface StatRoll extends BaseRoll {
modifier?: number;
adds?: number;
result: ROLL_RESULT;
matchedNegativeMomentum?: boolean;
momentumBurned?: number;
}

0 comments on commit 9036b9b

Please sign in to comment.