Closed syradar closed 3 years ago
import {
getRandomInt,
getRandomT6,
getRandomT66,
getRandomT8,
} from './dice.functions'
export const generateLegend = (): string => {
const longTimeAgo = `A long time ago`
const { description, age } = timeAgo()
return [
longTimeAgo,
description,
`(${age} ES) there was a`,
getText(ADJECTIVE),
getText(WHO_OR_WHAT),
'who sought',
getText(WHO_SEARCHED_FOR),
'because of',
getText(BECAUSE),
'and traveled to',
getText(LOCATION),
'located',
getText(DISTANCE, getRandomT6),
'in a/some',
getText(TERRAIN),
'in the direction of',
`${getText(DIRECTION, getRandomT8)}.`,
'As the legend goes, it is said that he/she',
getText(WHAT_HAPPENED),
'and that at the location there is/are',
getText(ITS_TOLD_THAT),
'but also',
getText(ADJECTIVE_ADVERSARY),
`${getText(ADVERSARY)}.`,
].join(' ')
}
interface TimeAgoResult {
description: string
age: number
}
const timeAgo = (): TimeAgoResult => {
const roll = getRandomT66()
const time = TIME_AGO.find((ta) => ta.roll.includes(roll))
if (time) {
return {
description: time.text,
age: getRandomInt(time.ageRange[0], time.ageRange[1]),
}
}
return (
time ?? {
description: 'before the time of the Blood Mist',
age: 0,
}
)
}
type TimeAgo = {
roll: number[]
text: string
ageRange: [number, number]
}
const TIME_AGO: TimeAgo[] = [
{
text: 'before the Shift',
ageRange: [1100, 3000],
roll: [11, 12],
},
{
text: 'before the Blood Mist',
ageRange: [300, 1100],
roll: [13, 14, 15, 16, 21, 22, 23, 24, 25, 26],
},
{
text: 'during the Alder Wars',
ageRange: [305, 360],
roll: [31, 32, 33, 34, 35, 36, 41, 42, 43],
},
{
text: 'in the age of the Blood Mist',
ageRange: [5, 280],
roll: [44, 45, 46, 51, 52, 53, 54, 55, 56, 61, 62, 63, 64, 65, 66],
},
]
interface LegendTableItem {
roll: number[]
text: () => string
}
const getText = (
arr: LegendTableItem[],
diceFn: () => number = getRandomT66,
): string => {
const roll = diceFn()
const result = arr.find((a) => a.roll.includes(roll)) ?? {
text: () => '',
roll: [],
}
return result.text()
}
const ADJECTIVE: LegendTableItem[] = [
{ roll: [11], text: () => 'bloodthirsty' },
{ roll: [12], text: () => 'vengeful' },
{ roll: [13], text: () => 'greedy' },
{ roll: [14], text: () => 'unhappy in love' },
{ roll: [15], text: () => 'ingenious' },
{ roll: [16], text: () => 'enterprising' },
{ roll: [21], text: () => 'kind' },
{ roll: [22], text: () => 'perseverant' },
{ roll: [23, 24], text: () => 'treacherous' },
{ roll: [25, 26], text: () => 'moral' },
{ roll: [31, 32], text: () => 'skilled' },
{ roll: [33, 34], text: () => 'stingy' },
{ roll: [35, 36], text: () => 'vain' },
{ roll: [41, 42], text: () => 'wise' },
{ roll: [43, 44], text: () => 'beautiful' },
{ roll: [45, 46], text: () => 'honorable' },
{ roll: [51, 52], text: () => 'jealous' },
{ roll: [53, 54], text: () => 'cruel' },
{ roll: [55, 56], text: () => 'determined' },
{ roll: [61, 62], text: () => 'cunning' },
{ roll: [63, 64], text: () => 'scared' },
{ roll: [65, 66], text: () => 'evil' },
]
const WHO_OR_WHAT: LegendTableItem[] = [
{ roll: [11], text: () => 'elf' },
{ roll: [12], text: () => 'dwarf' },
{ roll: [13], text: () => 'peddler' },
{ roll: [14], text: () => 'smith' },
{ roll: [15], text: () => 'farmer' },
{ roll: [16], text: () => 'apprentice' },
{ roll: [21], text: () => 'druid' },
{ roll: [22], text: () => 'shepherd' },
{ roll: [23, 24], text: () => 'Raven sister' },
{ roll: [25, 26], text: () => 'Rust brother' },
{ roll: [31, 32], text: () => 'rider' },
{ roll: [33, 34], text: () => 'treasure hunter' },
{ roll: [35, 36], text: () => 'priest' },
{ roll: [41, 42], text: () => 'sorcerer' },
{ roll: [43, 44], text: () => 'robber chieftain' },
{ roll: [45, 46], text: () => 'warrior' },
{ roll: [51, 52], text: () => 'lord' },
{ roll: [53, 54], text: () => 'prince' },
{ roll: [55, 56], text: () => 'princess' },
{ roll: [61, 62], text: () => 'queen' },
{ roll: [63, 64], text: () => 'king' },
{
roll: [65, 66],
text: () => {
const roll = getRandomInt(1, 6)
switch (roll) {
case 1:
return 'unit of soldiers'
case 2:
return 'village'
case 3:
return 'cult'
case 4:
return 'band of robbers'
case 5:
return 'cabal'
case 6:
return 'monster'
default:
return 'band of robbers'
}
},
},
]
const WHO_SEARCHED_FOR: LegendTableItem[] = [
{ roll: [11, 12, 13, 14], text: () => 'a weapon' },
{ roll: [15, 16, 21, 22], text: () => 'a love' },
{ roll: [23, 24, 25, 26], text: () => 'a friend in need' },
{ roll: [31, 32, 33, 34], text: () => 'an enemy' },
{ roll: [35, 36, 41, 42], text: () => 'a treasure' },
{ roll: [43, 44, 45, 46], text: () => 'a map' },
{ roll: [51, 52, 53, 54], text: () => 'a family member' },
{ roll: [55, 56, 61, 62], text: () => 'an artifact' },
{ roll: [63, 44, 65, 66], text: () => 'a monster' },
]
const BECAUSE: LegendTableItem[] = [
{ roll: [11, 12, 13, 14], text: () => 'love' },
{ roll: [15, 16], text: () => 'friendship' },
{ roll: [21, 22, 23, 24], text: () => 'a promise' },
{ roll: [25, 26, 31, 32, 33], text: () => 'a prophecy' },
{ roll: [35, 36, 41], text: () => 'a bet' },
{ roll: [42, 43, 44, 45], text: () => 'duty' },
{ roll: [46, 51, 52], text: () => 'war' },
{ roll: [53, 54, 55], text: () => 'honor' },
{ roll: [56, 61], text: () => 'insanity' },
{ roll: [62, 63], text: () => 'dreams' },
{ roll: [64, 65, 66], text: () => 'greed' },
]
const LOCATION: LegendTableItem[] = [
{ roll: [11, 12, 13, 14, 15, 16], text: () => 'a ruin' },
{ roll: [21, 21], text: () => 'a farm' },
{ roll: [23, 24, 25, 26], text: () => 'a grave' },
{ roll: [31, 32, 33, 34], text: () => 'a tower' },
{ roll: [35, 36], text: () => 'a castle' },
{ roll: [41, 42, 43], text: () => 'a village' },
{ roll: [44, 45, 46, 51, 52, 53], text: () => 'a cave' },
{ roll: [54, 55, 56], text: () => 'a hill' },
{ roll: [61, 62, 63], text: () => 'a tree' },
{ roll: [64, 65, 66], text: () => 'a water source' },
]
const DISTANCE: LegendTableItem[] = [
{ roll: [1], text: () => 'here' },
{ roll: [2], text: () => 'close by' },
{ roll: [3], text: () => 'a day's march away' },
{ roll: [4], text: () => 'a few days off' },
{ roll: [5], text: () => 'far away' },
{ roll: [6], text: () => 'on the other side of the Forbidden Lands' },
]
const TERRAIN: LegendTableItem[] = [
{ roll: [11, 12, 13, 14], text: () => 'ruins' },
{ roll: [15, 16, 21], text: () => 'marshlands' },
{ roll: [22, 23, 24], text: () => 'quagmire' },
{ roll: [25, 26, 31, 32, 33, 34], text: () => 'plains' },
{ roll: [35, 36, 41, 42, 43, 44], text: () => 'forest' },
{ roll: [45, 46, 51, 52, 53], text: () => 'hills' },
{ roll: [54, 55, 56, 61, 62, 63], text: () => 'dark forest' },
{ roll: [64], text: () => 'lake' },
{ roll: [65, 66], text: () => 'mountains' },
]
const DIRECTION: LegendTableItem[] = [
{ roll: [1], text: () => 'North' },
{ roll: [2], text: () => 'North East' },
{ roll: [3], text: () => 'East' },
{ roll: [4], text: () => 'South East' },
{ roll: [5], text: () => 'South' },
{ roll: [6], text: () => 'South West' },
{ roll: [7], text: () => 'West' },
{ roll: [8], text: () => 'North West' },
]
const WHAT_HAPPENED: LegendTableItem[] = [
{ roll: [11, 12, 13, 14], text: () => 'was betrayed' },
{ roll: [15, 21, 22], text: () => 'was murdered' },
{ roll: [23, 24, 25, 26], text: () => 'was never seen again' },
{ roll: [31, 32, 33], text: () => 'starved to death' },
{ roll: [34, 35, 36], text: () => 'took his/her life' },
{ roll: [41, 42, 43, 44], text: () => 'died in battle' },
{ roll: [45, 46, 51, 52], text: () => 'was enchanted' },
{ roll: [53, 54, 55, 56], text: () => 'was possessed' },
{ roll: [61, 62, 63], text: () => 'came back changed' },
{ roll: [64, 65, 66], text: () => 'still searches' },
]
const ITS_TOLD_THAT: LegendTableItem[] = [
{ roll: [11, 12, 13, 14], text: () => 'gold, lots of gold' },
{ roll: [15, 16, 21, 22], text: () => 'a powerful artifact' },
{ roll: [23, 24, 25, 26], text: () => 'a suit of armor' },
{ roll: [31, 32, 33], text: () => 'a weapon' },
{ roll: [34, 35, 36], text: () => 'an invaluable book' },
{ roll: [41, 42, 43, 44], text: () => 'a large treasure' },
{ roll: [45, 45, 46, 51, 52], text: () => 'a lost war chest' },
{ roll: [53, 54, 55, 56], text: () => 'the remains of an important person' },
{ roll: [61, 62, 63], text: () => 'a dwarven artifact' },
{ roll: [64, 65, 66], text: () => 'an elven ruby' },
]
const ADJECTIVE_ADVERSARY: LegendTableItem[] = [
{ roll: [11, 12, 13, 14], text: () => 'aggressive' },
{ roll: [15, 16, 21, 22], text: () => 'bloodthirsty' },
{ roll: [23, 24, 25], text: () => 'cruel' },
{ roll: [26, 31, 32], text: () => 'horrible' },
{ roll: [33, 34], text: () => 'hungry' },
{ roll: [35, 36, 41, 42, 43], text: () => 'watchful' },
{ roll: [44, 45, 46], text: () => 'starved' },
{ roll: [51, 52, 53, 54], text: () => 'greedy' },
{ roll: [55, 56, 61], text: () => 'insane' },
{ roll: [62, 63], text: () => 'murderous' },
{ roll: [64, 65], text: () => 'manic' },
{ roll: [66], text: () => 'hunting' },
]
const ADVERSARY: LegendTableItem[] = [
{ roll: [11, 12, 13, 14], text: () => 'Wolfkin' },
{ roll: [15, 16, 21, 22], text: () => 'slave traders' },
{ roll: [23, 24, 25], text: () => 'orcs' },
{ roll: [26, 31, 32], text: () => 'ghosts' },
{ roll: [33, 34], text: () => 'saurians' },
{ roll: [35, 36, 41, 42, 43], text: () => 'Iron guards' },
{ roll: [44, 45, 46], text: () => 'undead' },
{ roll: [51, 52, 53, 54], text: () => 'robbers' },
{ roll: [55, 56, 61], text: () => 'goblins' },
{ roll: [62, 63], text: () => 'ogres' },
{ roll: [64, 65], text: () => getText(MONSTER_LIST) },
{
roll: [66],
text: () => {
const roll = getRandomInt(1, 6)
switch (roll) {
case 5:
return 'two demons'
case 6:
return `${getRandomT6()} demons`
case 1:
case 2:
case 3:
case 4:
default:
return 'one demon'
}
},
},
]
const MONSTER_LIST: LegendTableItem[] = [
{ roll: [11, 12], text: () => 'strangling vine' },
{ roll: [13, 14, 15], text: () => 'gray bear' },
{ roll: [16, 21, 22], text: () => 'nightwarg' },
{ roll: [23, 24], text: () => 'ghost' },
{ roll: [25, 26], text: () => 'ghoul' },
{ roll: [31, 32], text: () => 'skeleton' },
{ roll: [33, 34], text: () => 'restless dead' },
{ roll: [35, 36], text: () => 'wyvern' },
{ roll: [41, 42], text: () => 'harpies' },
{ roll: [43], text: () => 'minotaur' },
{ roll: [44], text: () => 'ent' },
{ roll: [45], text: () => 'abyss worm' },
{ roll: [46], text: () => 'giant squid' },
{ roll: [51], text: () => 'sea serpent' },
{ roll: [52], text: () => 'troll' },
{ roll: [53], text: () => 'death knight' },
{ roll: [54], text: () => 'insectoids' },
{ roll: [55], text: () => 'bloodling' },
{ roll: [56], text: () => 'manticore' },
{ roll: [61], text: () => 'gryphon' },
{ roll: [62], text: () => 'giant' },
{ roll: [63], text: () => 'hydra' },
{ roll: [64], text: () => 'demon' },
{ roll: [65], text: () => 'drakewyrm' },
{ roll: [66], text: () => 'dragon' },
]
:tada: This issue has been resolved in version 1.1.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket: