Skip to content

Commit

Permalink
Finalize Games
Browse files Browse the repository at this point in the history
  • Loading branch information
alxjrvs committed Sep 25, 2024
1 parent 5d5a231 commit fb24fbf
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 166 deletions.
33 changes: 33 additions & 0 deletions src/games/Blades/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { roll as baseRoll } from '~src/roll'
import { RollResult } from './types'

function judgeResult(sortedRolls: number[]): RollResult {
const sixes = sortedRolls.filter((r) => r === 6).length
if (sixes >= 2) {
return RollResult.CRITICAL
}

switch (sortedRolls[0]) {
case 6:
return RollResult.SUCCESS
case 5:
case 4:
return RollResult.PARTIAL
default:
return RollResult.FAILURE
}
}

function roll(count: number): [RollResult, number[]] {
const rollResult = baseRoll({
sides: 6,
quantity: count
})
const rolls = rollResult.rawResult.flat().sort((a, b) => a - b)

return [judgeResult(rolls), rolls]
}

import * as types from './types'

export default { roll, judgeResult, ...types }
2 changes: 1 addition & 1 deletion src/games/InTheDark/types.ts → src/games/Blades/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum InTheDarkRollResult {
export enum RollResult {
CRITICAL = 'critical',
SUCCESS = 'success',
PARTIAL = 'partial',
Expand Down
11 changes: 6 additions & 5 deletions src/games/5E/index.ts → src/games/DnD5E/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { roll as baseRoll } from '~src/roll'
import { RollMods5E } from './type'
import { RollMods } from './type'

function roll(bonus: number = 0, mod: RollMods5E): number {
const isAdvantage = RollMods5E.Advantage === mod
const isDisadvantage = RollMods5E.Disadvantage === mod
function roll(bonus: number = 0, mod: RollMods): number {
const isAdvantage = RollMods.Advantage === mod
const isDisadvantage = RollMods.Disadvantage === mod
const rollResult = baseRoll({
sides: 20,
quantity: isAdvantage || isDisadvantage ? 2 : 1,
Expand All @@ -16,5 +16,6 @@ function roll(bonus: number = 0, mod: RollMods5E): number {

return rollResult.total
}
import * as types from './type'

export default { roll, RollMods5E }
export default { roll, ...types }
2 changes: 1 addition & 1 deletion src/games/5E/type.ts → src/games/DnD5E/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum RollMods5E {
export enum RollMods {
Advantage = 'advantage',
Disadvantage = 'disadvantage'
}
31 changes: 0 additions & 31 deletions src/games/InTheDark/index.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/games/SU/index.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/games/SalvageUnion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { RollTables } from './tables'
import { CoreMechanic, Entry, Table } from './types'
import { roll as baseRoll } from '~src/roll'

function interpretRelt(relt: number): CoreMechanic {
switch (true) {
case relt === 20:
return CoreMechanic.nailedIt
case relt >= 11 && relt <= 19:
return CoreMechanic.ccess
case relt >= 6 && relt <= 10:
return CoreMechanic.toughChoice
case relt >= 2 && relt <= 5:
return CoreMechanic.failure
default:
return CoreMechanic.cascadeFailure
}
}

function roll(tableKey: Table = Table.coreMechanic): [Entry, number] {
const { total } = baseRoll(20)
return [RollTables[tableKey][interpretRelt(total)], total]
}

import * as types from './types'
import * as tables from './tables'

export default { interpretRelt, roll, ...tables, ...types }
Loading

0 comments on commit fb24fbf

Please sign in to comment.