Add persistent destructible world structures and building kits

This commit is contained in:
dingo
2026-09-09 22:46:06 -04:00
parent c2bef2a45f
commit e80064976a
36 changed files with 932 additions and 43 deletions
+11
View File
@@ -247,3 +247,14 @@ crafting:
# Milestone 7 provisional progression and resurrection tuning.
powers: {"weapons": [{"id": "blades", "name": "Blades", "description": "Blades proficiency", "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000}, {"id": "polearms", "name": "Polearms", "description": "Polearms proficiency", "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000}], "powers": [{"id": "arc_bolt", "name": "Arc bolt", "description": "Arc bolt", "kind": "spell", "attackId": "arc_bolt", "targeting": "target", "resurrection": false, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {}, "book": true, "mana": 5, "castSeconds": 0.5, "cooldown": 2, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 10}, {"id": "mend", "name": "Mend", "description": "Mend", "kind": "spell", "attackId": "mend", "targeting": "target", "resurrection": false, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {}, "book": true, "mana": 5, "castSeconds": 0, "cooldown": 2, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 10}, {"id": "renewal", "name": "Renewal aura", "description": "Renewal aura", "kind": "spell", "attackId": "renewal_aura", "targeting": "aura", "resurrection": false, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {"mend": 2}, "book": false, "mana": 10, "castSeconds": 0, "cooldown": 10, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 10}, {"id": "revive", "name": "Resurrection", "description": "Resurrection", "kind": "spell", "attackId": "", "targeting": "target", "resurrection": true, "weapon": "", "weaponLevel": 1, "requirements": {"level": 1, "stats": {}, "titles": []}, "parents": {}, "book": true, "mana": 20, "castSeconds": 0, "cooldown": 30, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1000, "basePower": 0}, {"id": "cleave", "name": "Cleave", "description": "Cleave", "kind": "ability", "attackId": "cleave", "targeting": "target", "resurrection": false, "weapon": "blades", "weaponLevel": 2, "requirements": {"level": 1, "stats": {"strength": 2}, "titles": []}, "parents": {}, "book": false, "mana": 0, "castSeconds": 0, "cooldown": 2, "rankScaling": 0.03, "baseXp": 100, "xpPerLevel": 50, "maxLevel": 1, "basePower": 0}], "weaponXp": 10, "spellXp": 10, "revivalRange": 3, "revivalHealth": 0.25}
# Milestone 8a provisional structure limits and blueprints. Recipes are authored in Control.
building:
maxStructures: 256
range: 8
protectedRadius: 18
maxSlope: 1
definitions:
- {"id": "timber_wall", "name": "Timber wall", "description": "A persistent, destructible timber wall.", "model": "wall", "width": 4, "depth": 1, "height": 2, "hp": 250, "profession": "builder", "level": 1}
- {"id": "camp_platform", "name": "Camp platform", "description": "A persistent, destructible camp platform.", "model": "camp", "width": 4, "depth": 4, "height": 0.75, "hp": 300, "profession": "builder", "level": 1}
- {"id": "fort_block", "name": "Fort block", "description": "A persistent, destructible fort block.", "model": "fort", "width": 6, "depth": 3, "height": 3, "hp": 800, "profession": "builder", "level": 5}
+78
View File
@@ -0,0 +1,78 @@
package content
import (
"fmt"
"slices"
)
type BuildingDefinition struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Model string `json:"model" yaml:"model"`
Width float64 `json:"width" yaml:"width"`
Depth float64 `json:"depth" yaml:"depth"`
Height float64 `json:"height" yaml:"height"`
HP float64 `json:"hp" yaml:"hp"`
Profession string `json:"profession" yaml:"profession"`
Level int64 `json:"level" yaml:"level"`
}
type BuildingContent struct {
Definitions []BuildingDefinition `json:"definitions" yaml:"definitions"`
MaxStructures int `json:"maxStructures" yaml:"maxStructures"`
Range float64 `json:"range" yaml:"range"`
ProtectedRadius float64 `json:"protectedRadius" yaml:"protectedRadius"`
MaxSlope float64 `json:"maxSlope" yaml:"maxSlope"`
}
func (d BuildingDefinition) Validate() error {
if !validSetIdentity(d.ID, d.Name, d.Description) || !slices.Contains([]string{"wall", "camp", "fort"}, d.Model) || !finiteRange(d.Width, .5, 8) || !finiteRange(d.Depth, .5, 8) || !finiteRange(d.Height, .5, 6) || !finiteRange(d.HP, 1, 1000000) || d.Level < 1 || d.Level > 1000 {
return fmt.Errorf("invalid structure definition %q", d.Name)
}
return nil
}
func (c Catalog) BuildingItems() map[string]string {
out := map[string]string{}
if c.Building != nil {
for _, d := range c.Building.Definitions {
out["kit_"+d.ID] = d.Name + " kit"
}
}
return out
}
func (c Catalog) validateBuilding() error {
if c.Building == nil {
return nil
}
b := c.Building
if len(b.Definitions) > 128 || b.MaxStructures < 1 || b.MaxStructures > 512 || !finiteRange(b.Range, 2, 12) || !finiteRange(b.ProtectedRadius, 12, 100) || !finiteRange(b.MaxSlope, .1, 3) {
return fmt.Errorf("invalid building limits")
}
seen := map[string]bool{}
for _, d := range b.Definitions {
if e := d.Validate(); e != nil {
return e
}
if seen[d.ID] {
return fmt.Errorf("duplicate building identity")
}
seen[d.ID] = true
if c.Crafting == nil || !slices.ContainsFunc(c.Crafting.Professions, func(p GatheringSkill) bool { return p.ID == d.Profession }) {
return fmt.Errorf("unknown building profession")
}
for _, i := range c.Items {
if i.ID == "kit_"+d.ID {
return fmt.Errorf("equipment conflicts with structure kit")
}
}
}
return nil
}
// Existing catalogs gain the reusable structure definitions, while recipes remain
// authored separately. No publication rewrites already placed structures.
func (c *Catalog) RestoreBuilding(b Balance) {
if c.Building == nil {
c.Building = b.Building
}
}
+26
View File
@@ -0,0 +1,26 @@
package content
import "testing"
func TestBuildingKitsAndRequirements(t *testing.T) {
c, e := DefaultCatalog()
if e != nil {
t.Fatal(e)
}
c.Crafting.Recipes = append(c.Crafting.Recipes, CraftRecipe{ID: "wall_kit_recipe", Name: "Wall kit", Revision: 1, Profession: "builder", Level: 1, XP: 20, Inputs: map[string]int64{"wood": 6, "ore": 2}, Outputs: map[string]int64{"kit_timber_wall": 1}})
if e = c.Validate(); e != nil {
t.Fatal("could not author kit recipe", e)
}
d := c.Building.Definitions[0]
d.Height = -1
c.Building.Definitions[0] = d
if e = c.Validate(); e == nil {
t.Fatal("negative height allowed")
}
d.Height = 2
d.Profession = "missing"
c.Building.Definitions[0] = d
if e = c.Validate(); e == nil {
t.Fatal("missing profession allowed")
}
}
+3
View File
@@ -129,6 +129,9 @@ func (c Catalog) validateCombat() error {
attacks[a.ID] = true
}
items := map[string]bool{}
for id := range c.BuildingItems() {
items[id] = true
}
for id := range c.PowerItems() {
items[id] = true
}
+7 -3
View File
@@ -19,6 +19,7 @@ type Recipe struct {
}
type Balance struct {
Building *BuildingContent `yaml:"building"`
Powers *PowerContent `yaml:"powers"`
Crafting *CraftingContent `yaml:"crafting"`
Combat *CombatContent `yaml:"combat"`
@@ -82,10 +83,13 @@ func Parse(data []byte) (Balance, error) {
return b, b.Validate()
}
func (b Balance) Validate() error {
if err := (Catalog{Powers: b.Powers, Combat: b.Combat, Items: b.Items, Titles: b.Titles}).validatePowers(); err != nil {
if e := (Catalog{Building: b.Building, Crafting: b.Crafting, Items: b.Items}).validateBuilding(); e != nil {
return e
}
if err := (Catalog{Building: b.Building, Powers: b.Powers, Combat: b.Combat, Items: b.Items, Titles: b.Titles}).validatePowers(); err != nil {
return err
}
if err := (Catalog{Powers: b.Powers, Crafting: b.Crafting, Items: b.Items, Titles: b.Titles, Gathering: b.Gathering}).validateCrafting(); err != nil {
if err := (Catalog{Building: b.Building, Powers: b.Powers, Crafting: b.Crafting, Items: b.Items, Titles: b.Titles, Gathering: b.Gathering}).validateCrafting(); err != nil {
return err
}
if b.CombatRules != nil {
@@ -93,7 +97,7 @@ func (b Balance) Validate() error {
return err
}
}
if err := (Catalog{Powers: b.Powers, Crafting: b.Crafting, Combat: b.Combat, Items: b.Items, Gathering: b.Gathering}).validateCombat(); err != nil {
if err := (Catalog{Building: b.Building, Powers: b.Powers, Crafting: b.Crafting, Combat: b.Combat, Items: b.Items, Gathering: b.Gathering}).validateCombat(); err != nil {
return err
}
if b.Gathering != nil {
+3
View File
@@ -83,6 +83,9 @@ func SkillLevel(s GatheringSkill, xp int64) (int64, int64) {
}
func (c Catalog) StackIDs() map[string]bool {
ids := map[string]bool{}
for id := range c.BuildingItems() {
ids[id] = true
}
for id := range c.PowerItems() {
ids[id] = true
}
+5 -1
View File
@@ -49,6 +49,7 @@ type ItemDefinition struct {
Modifiers []StatModifier `json:"modifiers" yaml:"modifiers"`
}
type Catalog struct {
Building *BuildingContent `json:"building,omitempty"`
Powers *PowerContent `json:"powers,omitempty"`
Crafting *CraftingContent `json:"crafting,omitempty"`
Combat *CombatContent `json:"combat,omitempty"`
@@ -134,6 +135,9 @@ func (item ItemDefinition) Validate() error {
return ValidateModifiers(item.Modifiers)
}
func (c Catalog) Validate() error {
if e := c.validateBuilding(); e != nil {
return e
}
if err := c.validatePowers(); err != nil {
return err
}
@@ -215,5 +219,5 @@ func DefaultCatalog() (Catalog, error) {
if err != nil {
return Catalog{}, err
}
return Catalog{Powers: b.Powers, Crafting: b.Crafting, Combat: b.Combat, Gathering: b.Gathering, Version: 1, Titles: b.Titles, Items: b.Items, Stats: *b.Stats}, nil
return Catalog{Building: b.Building, Powers: b.Powers, Crafting: b.Crafting, Combat: b.Combat, Gathering: b.Gathering, Version: 1, Titles: b.Titles, Items: b.Items, Stats: *b.Stats}, nil
}