Go binary/server for helping run/build sessions for the Maze Rats TTRPG
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

164 lines
4.3 KiB

package tables
import (
data "mazeratsgen/internal/data"
dice "mazeratsgen/internal/dice"
"mazeratsgen/internal/helpers"
"strings"
)
type CharacterTable struct {
Roller *dice.Roller
}
// charAbilities holds values related to character stats
type charAbilities struct {
STR int
DEX int
WIL int
}
type CharacterStats struct {
MaxHealth int `json:"max_health"`
Armor int `json:"armor"`
STR int `json:"str"`
DEX int `json:"dex"`
WIL int `json:"wil"`
}
type Character struct {
Name string `json:"name"`
Stats CharacterStats
Feature string `json:"feature"`
Weapons []string `json:"weapons"`
Items []string `json:"items"`
Appearance string `json:"appearance"`
PhysicalDetail string `json:"physical_detail"`
Background string `json:"background"`
Clothing string `json:"clothing"`
Personality string `json:"personality"`
Mannerism string `json:"mannerism"`
Seed int64
}
func (t *CharacterTable) Generate() Character {
abilityRoll, _ := t.Roller.Roll("1d6")
abilites := t.Abilities(abilityRoll[0])
classRoll, _ := t.Roller.Roll("1d2")
var class string
if classRoll[0] == 1 {
class = "Upperclass"
} else {
class = "Lowerclass"
}
genderRoll, _ := t.Roller.Roll("1d2")
var gender string
if genderRoll[0] == 1 {
gender = "Male"
} else {
gender = "Female"
}
result, _ := t.Roller.Roll("1d6")
featureRoll := result[0]
return Character{
Name: GenName(class, gender, t.Roller.Seed).FullName,
Stats: CharacterStats{
Armor: 6,
MaxHealth: t.MaxHealth(),
STR: abilites.STR,
DEX: abilites.DEX,
WIL: abilites.WIL,
},
Feature: t.Feat(featureRoll),
Weapons: helpers.GenUniqueItems(2, TreasureTable{Roller: t.Roller}.WeaponItem, t.Roller.Seed),
Items: helpers.GenUniqueItems(6, t.Item, t.Roller.Seed),
Appearance: t.Appearance(t.Roller.TableRoll()),
PhysicalDetail: t.PhysicalDetail(t.Roller.TableRoll()),
Background: t.Background(t.Roller.TableRoll()),
Clothing: t.Clothing(t.Roller.TableRoll()),
Personality: t.Personality(t.Roller.TableRoll()),
Mannerism: t.Mannerism(t.Roller.TableRoll()),
Seed: t.Roller.Seed,
}
}
func (t *CharacterTable) Template() string {
return strings.TrimSpace(`
Name: {{.Name}}
Feature: {{.Feature}}
Background: {{.Background}}
Stats:
Health: {{.Stats.MaxHealth}}
Armor: {{.Stats.Armor}} (+1 for shield, +1 for light armor, +2 for heavy armor)
STR: {{.Stats.STR}} (Used for raw power, stamina, or physical resilience)
DEX: {{.Stats.DEX}} (Used for speed, agility, or precision)
WIL: {{.Stats.WIL}} (Used for force of personality, perception, or willpower)
Appearance: {{.Appearance}}
Physical Detail: {{.PhysicalDetail}}
Clothing: {{.Clothing}}
Personality: {{.Personality}}
Mannerism: {{.Mannerism}}
Items:
{{- range $item := .Items }}
{{$item}}
{{- end}}
Seed: {{ .Seed }}
`)
}
// GenAbilities will return a STR/DEX/WIL for a character
func (t CharacterTable) Abilities(roll int) charAbilities {
stats := [6][3]int{
[3]int{2, 1, 0},
[3]int{2, 0, 1},
[3]int{1, 2, 0},
[3]int{0, 2, 1},
[3]int{1, 0, 2},
[3]int{0, 1, 2},
}
return charAbilities{
STR: stats[roll-1][0],
DEX: stats[roll-1][1],
WIL: stats[roll-1][2],
}
}
// GenMaxHealth is silly, it's always 4 for level 1 characters
func (t CharacterTable) MaxHealth() int { return 4 }
func (t CharacterTable) Feat(roll int) string {
return data.Tables.Character.Feat[roll-1]
}
func (t CharacterTable) Appearance(roll [2]int) string {
return data.Tables.Character.Appearance[roll[0]-1][roll[1]-1]
}
func (t CharacterTable) Background(roll [2]int) string {
return data.Tables.Character.Background[roll[0]-1][roll[1]-1]
}
func (t CharacterTable) Clothing(roll [2]int) string {
return data.Tables.Character.Clothing[roll[0]-1][roll[1]-1]
}
func (t CharacterTable) Item(roll [2]int) string {
return data.Tables.Character.Items[roll[0]-1][roll[1]-1]
}
func (t CharacterTable) Personality(roll [2]int) string {
return data.Tables.Character.Personality[roll[0]-1][roll[1]-1]
}
func (t CharacterTable) PhysicalDetail(roll [2]int) string {
return data.Tables.Character.PhysicalDetail[roll[0]-1][roll[1]-1]
}
func (t CharacterTable) Mannerism(roll [2]int) string {
return data.Tables.Character.Mannerism[roll[0]-1][roll[1]-1]
}