Add terrain biomes jumping and extensible gathering professions

This commit is contained in:
dingo
2026-09-08 21:54:23 -04:00
parent 141cb9e6b2
commit df7b245ca7
34 changed files with 1895 additions and 184 deletions
+40
View File
@@ -1,4 +1,44 @@
version: 1
# Provisional milestone 3 tuning. The +20 attempt ceiling is a gameplay rule.
gatheringRules:
failureBase: 70
failurePerLevel: 1.4
failureMax: 98
destroyBase: 75
destroyPerLevel: 1
negativeChance: 65
damagePerLevel: 2
fatigueSeconds: 20
fatiguePercent: 40
jumpSpeed: 10
gravity: 24
hillHeight: 42
detailHeight: 6
gathering:
skills:
- { id: lumberjack, name: Lumberjack, description: Harvest wood., baseXp: 20, xpPerLevel: 10, maxLevel: 1000 }
- { id: herbalist, name: Herbalist, description: Harvest herbs., baseXp: 20, xpPerLevel: 10, maxLevel: 1000 }
- { id: miner, name: Miner, description: Harvest ore., baseXp: 20, xpPerLevel: 10, maxLevel: 1000 }
biomes:
- { id: forest, name: Forest, description: Wooded rolling hills., color: '#355c3a', weight: 4 }
- { id: meadow, name: Meadow, description: Open grassy valleys., color: '#65784c', weight: 3 }
- { id: highlands, name: Highlands, description: Rocky uplands., color: '#727d68', weight: 3 }
resources:
- { id: tree, name: Young tree, description: Common timber., skillId: lumberjack, model: tree, output: wood, requiredLevel: 1, amount: 1, xp: 2, seconds: 0.6, respawnSeconds: 120, density: 16, biomes: [forest, meadow, highlands] }
- { id: herb, name: Wild herbs, description: Common medicinal herbs., skillId: herbalist, model: herb, output: herb, requiredLevel: 1, amount: 1, xp: 2, seconds: 0.6, respawnSeconds: 120, density: 12, biomes: [forest, meadow, highlands] }
- { id: ore, name: Iron outcrop, description: Common ore., skillId: miner, model: ore, output: ore, requiredLevel: 1, amount: 1, xp: 2, seconds: 0.6, respawnSeconds: 120, density: 12, biomes: [forest, meadow, highlands] }
- { id: ancient_tree, name: Ancient hardwood, description: Difficult timber. Inspect the risk before gathering., skillId: lumberjack, model: tree, output: wood, requiredLevel: 15, amount: 5, xp: 12, seconds: 2, respawnSeconds: 240, density: 4, biomes: [forest] }
- { id: bitter_herb, name: Bitterroot, description: Dangerous herbs., skillId: herbalist, model: herb, output: herb, requiredLevel: 15, amount: 5, xp: 12, seconds: 2, respawnSeconds: 240, density: 4, biomes: [meadow] }
- { id: deep_ore, name: Dense iron, description: A difficult mineral seam., skillId: miner, model: ore, output: ore, requiredLevel: 15, amount: 5, xp: 12, seconds: 2, respawnSeconds: 240, density: 4, biomes: [highlands] }
consumables:
- id: gathering_tonic
name: Gatherer's tonic
description: Temporarily improves every gathering profession. Reuse refreshes duration.
seconds: 120
modifiers:
- { stat: gatheringLevel, flat: 5, percent: 0 }
- { stat: gatheringSpeed, flat: 0, percent: 20 }
- { stat: gatheringXP, flat: 0, percent: 20 }
tickHz: 20
snapshotHz: 5
chunkSize: 128
+12
View File
@@ -19,6 +19,8 @@ type Recipe struct {
}
type Balance struct {
Gathering *GatheringContent `yaml:"gathering"`
GatheringRules *GatheringRules `yaml:"gatheringRules"`
Version int `yaml:"version"`
TickHz int `yaml:"tickHz"`
SnapshotHz int `yaml:"snapshotHz"`
@@ -76,6 +78,16 @@ func Parse(data []byte) (Balance, error) {
return b, b.Validate()
}
func (b Balance) Validate() error {
if b.Gathering != nil {
if err := b.Gathering.Validate(); err != nil {
return err
}
}
if b.GatheringRules != nil {
if err := b.GatheringRules.Validate(); err != nil {
return err
}
}
if b.Stats == nil {
return fmt.Errorf("stats rules are required")
}
+150
View File
@@ -0,0 +1,150 @@
package content
import (
"fmt"
"math"
"slices"
)
// A skill is data, not an enum. All gathering professions share this curve.
type GatheringSkill struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
BaseXP int64 `json:"baseXp" yaml:"baseXp"`
XPPerLevel int64 `json:"xpPerLevel" yaml:"xpPerLevel"`
MaxLevel int64 `json:"maxLevel" yaml:"maxLevel"`
}
type ResourceDefinition struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
SkillID string `json:"skillId" yaml:"skillId"`
Model string `json:"model" yaml:"model"`
Output string `json:"output" yaml:"output"`
RequiredLevel int64 `json:"requiredLevel" yaml:"requiredLevel"`
Amount int64 `json:"amount" yaml:"amount"`
XP int64 `json:"xp" yaml:"xp"`
Seconds float64 `json:"seconds" yaml:"seconds"`
RespawnSeconds float64 `json:"respawnSeconds" yaml:"respawnSeconds"`
Density int64 `json:"density" yaml:"density"`
Biomes []string `json:"biomes" yaml:"biomes"`
}
type BiomeDefinition struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Color string `json:"color" yaml:"color"`
Weight int64 `json:"weight" yaml:"weight"`
}
type GatheringConsumable struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Seconds float64 `json:"seconds" yaml:"seconds"`
Modifiers []StatModifier `json:"modifiers" yaml:"modifiers"`
}
type GatheringContent struct {
Skills []GatheringSkill `json:"skills" yaml:"skills"`
Resources []ResourceDefinition `json:"resources" yaml:"resources"`
Biomes []BiomeDefinition `json:"biomes" yaml:"biomes"`
Consumables []GatheringConsumable `json:"consumables" yaml:"consumables"`
}
type GatheringRules struct {
FailureBase float64 `json:"failureBase" yaml:"failureBase"`
FailurePerLevel float64 `json:"failurePerLevel" yaml:"failurePerLevel"`
FailureMax float64 `json:"failureMax" yaml:"failureMax"`
DestroyBase float64 `json:"destroyBase" yaml:"destroyBase"`
DestroyPerLevel float64 `json:"destroyPerLevel" yaml:"destroyPerLevel"`
NegativeChance float64 `json:"negativeChance" yaml:"negativeChance"`
DamagePerLevel float64 `json:"damagePerLevel" yaml:"damagePerLevel"`
FatigueSeconds float64 `json:"fatigueSeconds" yaml:"fatigueSeconds"`
FatiguePercent float64 `json:"fatiguePercent" yaml:"fatiguePercent"`
JumpSpeed float64 `json:"jumpSpeed" yaml:"jumpSpeed"`
Gravity float64 `json:"gravity" yaml:"gravity"`
HillHeight float64 `json:"hillHeight" yaml:"hillHeight"`
DetailHeight float64 `json:"detailHeight" yaml:"detailHeight"`
}
var GatheringStats = []string{"gatheringLevel", "gatheringYield", "gatheringSpeed", "gatheringXP"}
func GatheringStat(key string) bool { return slices.Contains(GatheringStats, key) }
func finiteRange(v, low, high float64) bool {
return !math.IsNaN(v) && !math.IsInf(v, 0) && v >= low && v <= high
}
func (r GatheringRules) Validate() error {
for _, v := range []float64{r.FailureBase, r.FailurePerLevel, r.FailureMax, r.DestroyBase, r.DestroyPerLevel, r.NegativeChance, r.FatiguePercent} {
if !finiteRange(v, 0, 100) {
return fmt.Errorf("invalid gathering probability or fatigue")
}
}
if r.FailureMax < r.FailureBase || !finiteRange(r.DamagePerLevel, 0, 100) || !finiteRange(r.FatigueSeconds, 1, 3600) || !finiteRange(r.JumpSpeed, 1, 30) || !finiteRange(r.Gravity, 1, 100) || !finiteRange(r.HillHeight, 1, 100) || !finiteRange(r.DetailHeight, 0, 20) {
return fmt.Errorf("invalid gathering/movement rules")
}
return nil
}
func (g GatheringContent) Validate() error {
if len(g.Skills) < 1 || len(g.Skills) > 64 || len(g.Resources) > 256 || len(g.Biomes) < 1 || len(g.Biomes) > 32 || len(g.Consumables) > 256 {
return fmt.Errorf("invalid gathering content counts")
}
ids := map[string]bool{}
identity := func(id, name, desc string) bool {
if ids[id] || !validSetIdentity(id, name, desc) {
return false
}
ids[id] = true
return true
}
skills, biomes := map[string]bool{}, map[string]bool{}
for _, s := range g.Skills {
if !identity(s.ID, s.Name, s.Description) || s.BaseXP < 1 || s.BaseXP > 1000000 || s.XPPerLevel < 0 || s.XPPerLevel > 1000000 || s.MaxLevel < 2 || s.MaxLevel > 10000 {
return fmt.Errorf("invalid gathering skill %q", s.ID)
}
skills[s.ID] = true
}
for _, b := range g.Biomes {
if !identity(b.ID, b.Name, b.Description) || b.Weight < 1 || b.Weight > 100 || len(b.Color) != 7 || b.Color[0] != '#' {
return fmt.Errorf("invalid biome %q", b.ID)
}
for _, c := range b.Color[1:] {
if !slices.Contains([]rune("0123456789abcdefABCDEF"), c) {
return fmt.Errorf("invalid biome color")
}
}
biomes[b.ID] = true
}
for _, r := range g.Resources {
if !identity(r.ID, r.Name, r.Description) || !skills[r.SkillID] || !slices.Contains([]string{"tree", "ore", "herb"}, r.Model) || !slices.Contains([]string{"wood", "ore", "herb", "self"}, r.Output) || r.RequiredLevel < 1 || r.RequiredLevel > 10000 || r.Amount < 1 || r.Amount > 1000 || r.XP < 0 || r.XP > 1000000 || !finiteRange(r.Seconds, 0.1, 3600) || !finiteRange(r.RespawnSeconds, 1, 604800) || r.Density < 0 || r.Density > 32 || len(r.Biomes) < 1 || len(r.Biomes) > 32 {
return fmt.Errorf("invalid resource %q", r.ID)
}
seen := map[string]bool{}
for _, id := range r.Biomes {
if !biomes[id] || seen[id] {
return fmt.Errorf("unknown/duplicate resource biome %q", id)
}
seen[id] = true
}
}
for _, c := range g.Consumables {
if !identity(c.ID, c.Name, c.Description) || !finiteRange(c.Seconds, 1, 86400) || len(c.Modifiers) < 1 {
return fmt.Errorf("invalid consumable %q", c.ID)
}
if err := ValidateModifiers(c.Modifiers); err != nil {
return err
}
for _, m := range c.Modifiers {
if !GatheringStat(m.Stat) {
return fmt.Errorf("gathering consumables require gathering modifiers")
}
}
}
return nil
}
func (g GatheringContent) ValidateScopes(mods []StatModifier) error {
for _, m := range mods {
if m.Skill != "" && !slices.ContainsFunc(g.Skills, func(s GatheringSkill) bool { return s.ID == m.Skill }) {
return fmt.Errorf("unknown gathering skill %q", m.Skill)
}
}
return nil
}
+39 -8
View File
@@ -19,6 +19,7 @@ var StatLinks = map[string][]string{
}
type StatModifier struct {
Skill string `json:"skill,omitempty" yaml:"skill"`
Stat string `json:"stat" yaml:"stat"`
Flat float64 `json:"flat" yaml:"flat"`
Percent float64 `json:"percent" yaml:"percent"`
@@ -44,12 +45,13 @@ type ItemDefinition struct {
Modifiers []StatModifier `json:"modifiers" yaml:"modifiers"`
}
type Catalog struct {
Version int64 `json:"version"`
Titles []Title `json:"titles"`
Items []ItemDefinition `json:"items"`
Stats StatsRules `json:"stats"`
RequirementSets []RequirementSet `json:"requirementSets,omitempty"`
EffectSets []EffectSet `json:"effectSets,omitempty"`
Gathering *GatheringContent `json:"gathering,omitempty"`
Version int64 `json:"version"`
Titles []Title `json:"titles"`
Items []ItemDefinition `json:"items"`
Stats StatsRules `json:"stats"`
RequirementSets []RequirementSet `json:"requirementSets,omitempty"`
EffectSets []EffectSet `json:"effectSets,omitempty"`
}
func KnownStat(stat string) bool {
@@ -85,7 +87,7 @@ func ValidateModifiers(modifiers []StatModifier) error {
return fmt.Errorf("too many modifiers")
}
for _, m := range modifiers {
if !KnownStat(m.Stat) || math.IsNaN(m.Flat) || math.IsInf(m.Flat, 0) || math.Abs(m.Flat) > 1000000 || math.IsNaN(m.Percent) || math.IsInf(m.Percent, 0) || m.Percent < -100 || m.Percent > 10000 {
if (!KnownStat(m.Stat) && !GatheringStat(m.Stat)) || (m.Skill != "" && (!GatheringStat(m.Stat) || !titleID.MatchString(m.Skill))) || math.IsNaN(m.Flat) || math.IsInf(m.Flat, 0) || math.Abs(m.Flat) > 1000000 || math.IsNaN(m.Percent) || math.IsInf(m.Percent, 0) || m.Percent < -100 || m.Percent > 10000 {
return fmt.Errorf("invalid modifier for %q", m.Stat)
}
}
@@ -122,6 +124,35 @@ func (item ItemDefinition) Validate() error {
return ValidateModifiers(item.Modifiers)
}
func (c Catalog) Validate() error {
if c.Gathering != nil {
if err := c.Gathering.Validate(); err != nil {
return err
}
mods := []StatModifier{}
for _, i := range c.Items {
mods = append(mods, i.Modifiers...)
}
for _, t := range c.Titles {
mods = append(mods, t.Effects.Modifiers...)
}
for _, e := range c.EffectSets {
mods = append(mods, e.Modifiers...)
}
for _, v := range c.Gathering.Consumables {
mods = append(mods, v.Modifiers...)
}
if err := c.Gathering.ValidateScopes(mods); err != nil {
return err
}
for _, v := range c.Gathering.Consumables {
for _, i := range c.Items {
if v.ID == i.ID {
return fmt.Errorf("consumable/equipment identity collision")
}
}
}
}
if err := c.validateLibrary(); err != nil {
return err
}
@@ -165,5 +196,5 @@ func DefaultCatalog() (Catalog, error) {
if err != nil {
return Catalog{}, err
}
return Catalog{Version: 1, Titles: b.Titles, Items: b.Items, Stats: *b.Stats}, nil
return Catalog{Gathering: b.Gathering, Version: 1, Titles: b.Titles, Items: b.Items, Stats: *b.Stats}, nil
}