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.
 
 
 
 

159 lines
4.5 KiB

package tables
import (
"mazeratsgen/internal/data"
"mazeratsgen/internal/dice"
"mazeratsgen/internal/helpers"
"strings"
)
type TreasureTable struct {
Roller *dice.Roller
}
type Potion struct {
Effect string
Ingredients []string
OnFailure string
}
func (t *TreasureTable) GenTreasure() string {
treasureTable := TreasureTable{Roller: t.Roller}
trait := treasureTable.TreasureTrait(t.Roller.TableRoll())
item := treasureTable.TreasureItem(t.Roller.TableRoll())
return trait + " " + item
}
func (t *TreasureTable) PotionTemplate() string {
return strings.TrimSpace(`
Effect: {{.Effect}}
Ingredients:
{{- range $ingredient := .Ingredients}}
{{$ingredient}}
{{- end}}
Failure: {{.OnFailure}}
`)
}
func (t *TreasureTable) GenPotion() Potion {
magicTable := MagicTable{Roller: t.Roller}
treasureTable := TreasureTable{Roller: t.Roller}
var onFailure string
onFailRoll, _ := t.Roller.Roll("1d2")
if onFailRoll[0] == 1 {
onFailure = magicTable.Mutation(t.Roller.TableRoll())
} else {
onFailure = magicTable.Insanity(t.Roller.TableRoll())
}
ingredientRoll, _ := t.Roller.Roll("1d3")
return Potion{
Effect: treasureTable.PotionBase(t.Roller.TableRoll()),
OnFailure: onFailure,
Ingredients: helpers.GenUniqueItems(ingredientRoll[0], treasureTable.MagicalIngredient, t.Roller.Seed),
}
}
func (t TreasureTable) PotionBase(roll [2]int) string {
monTable := MonsterTable{Roller: t.Roller}
magicTable := MagicTable{Roller: t.Roller}
switch roll {
case [2]int{1, 1}:
roll, _ := t.Roller.Roll("1d6")
return monTable.Base(roll[0]) + " Form"
case [2]int{1, 5}:
roll, _ := t.Roller.Roll("1d6")
return "Control " + magicTable.Element(roll[0])
case [2]int{2, 5}:
roll, _ := t.Roller.Roll("1d6")
return magicTable.Element(roll[0]) + " Form"
case [2]int{3, 5}:
return magicTable.Insanity(t.Roller.TableRoll())
case [2]int{4, 1}:
return t.TreasureItem(t.Roller.TableRoll()) + " Form"
case [2]int{4, 4}:
return monTable.Ability(t.Roller.TableRoll())
case [2]int{4, 5}:
return monTable.Feature(t.Roller.TableRoll())
case [2]int{4, 6}:
return monTable.Trait(t.Roller.TableRoll())
case [2]int{5, 1}:
return magicTable.Mutation(t.Roller.TableRoll())
case [2]int{5, 3}:
return magicTable.Spell(t.Roller.TableRoll())
default:
return data.Tables.Treasure.Potions[roll[0]-1][roll[1]-1]
}
}
func (t TreasureTable) MiscItem(roll [2]int) string {
return data.Tables.Treasure.MiscItems[roll[0]-1][roll[1]-1]
}
func (t TreasureTable) WornItem(roll [2]int) string {
return data.Tables.Treasure.WornItems[roll[0]-1][roll[1]-1]
}
func (t TreasureTable) WeaponItem(roll [2]int) string {
return data.Tables.Treasure.WeaponItems[roll[0]-1][roll[1]-1]
}
func (t TreasureTable) BookSubject(roll [2]int) string {
return data.Tables.Treasure.BookSubjects[roll[0]-1][roll[1]-1]
}
func (t TreasureTable) ToolItem(roll [2]int) string {
return data.Tables.Treasure.ToolItems[roll[0]-1][roll[1]-1]
}
func (t TreasureTable) MagicalIngredient(roll [2]int) string {
monTable := MonsterTable{Roller: t.Roller}
wildTable := WildTable{Roller: t.Roller}
magicTable := MagicTable{Roller: t.Roller}
treasureTable := TreasureTable{Roller: t.Roller}
switch roll {
case [2]int{1, 2}:
baseRoll, _ := t.Roller.Roll("1d6")
return monTable.Base(baseRoll[0])
case [2]int{1, 5}:
return t.BookSubject(t.Roller.TableRoll()) + " page"
case [2]int{2, 5}:
return wildTable.EdiblePlant(t.Roller.TableRoll())
case [2]int{4, 2}:
return monTable.Feature(t.Roller.TableRoll())
case [2]int{4, 5}:
return magicTable.PhysicalElement(t.Roller.TableRoll())
case [2]int{4, 6}:
return wildTable.PoisonousPlant(t.Roller.TableRoll())
case [2]int{5, 1}:
return treasureTable.PotionBase(t.Roller.TableRoll())
case [2]int{6, 3}:
return treasureTable.ValuableMaterial(t.Roller.TableRoll())
default:
return data.Tables.Treasure.MagicalIngredients[roll[0]-1][roll[1]-1]
}
}
func (t TreasureTable) TreasureItem(roll [2]int) string {
return data.Tables.Treasure.TreasureItems[roll[0]-1][roll[1]-1]
}
func (t TreasureTable) TreasureTrait(roll [2]int) string {
magicTable := MagicTable{Roller: t.Roller}
switch roll {
case [2]int{2, 6}:
effectRoll, _ := t.Roller.Roll("1d6")
return magicTable.Effect(effectRoll[0])
case [2]int{3, 1}:
effectRoll, _ := t.Roller.Roll("1d6")
return magicTable.Effect(effectRoll[0])
default:
return data.Tables.Treasure.TreasureItems[roll[0]-1][roll[1]-1]
}
}
func (t TreasureTable) ValuableMaterial(roll [2]int) string {
return data.Tables.Treasure.ValuableMaterials[roll[0]-1][roll[1]-1]
}