Add item actions, targeting, bindings, and encumbrance

This commit is contained in:
dingo
2026-09-10 20:57:36 -04:00
parent 32955eca09
commit 9b01ee38e3
38 changed files with 1297 additions and 77 deletions
+1
View File
@@ -71,6 +71,7 @@ tickHz: 20
snapshotHz: 5
chunkSize: 128
terrainResolution: 16
inventory: { stopWeightRatio: 2, slowdownExponent: 2, breakdownBase: 25, breakdownMax: 75, breakdownLevelScale: 25, recipeChance: 0.01, actionCooldown: 1 }
worldRadius: 1024
maxPlayers: 100
spawnSeparation: 48
+6
View File
@@ -19,6 +19,7 @@ type Recipe struct {
}
type Balance struct {
Inventory *InventoryRules `yaml:"inventory"`
XPCurve *XPCurve `yaml:"xpCurve"`
Housing *HousingRules `yaml:"housing"`
Building *BuildingContent `yaml:"building"`
@@ -85,6 +86,11 @@ func Parse(data []byte) (Balance, error) {
return b, b.Validate()
}
func (b Balance) Validate() error {
if b.Inventory != nil {
if e := b.Inventory.Validate(); e != nil {
return e
}
}
if b.XPCurve != nil {
if e := b.XPCurve.Validate(); e != nil {
return e
+27 -5
View File
@@ -46,10 +46,11 @@ type CraftRules struct {
Cooldown float64 `json:"cooldown" yaml:"cooldown"`
}
type CraftingContent struct {
Professions []GatheringSkill `json:"professions" yaml:"professions"`
Materials []CraftMaterial `json:"materials" yaml:"materials"`
Recipes []CraftRecipe `json:"recipes" yaml:"recipes"`
Rules CraftRules `json:"rules" yaml:"rules"`
RecipeHistory []CraftRecipe `json:"recipeHistory,omitempty" yaml:"recipeHistory"`
Professions []GatheringSkill `json:"professions" yaml:"professions"`
Materials []CraftMaterial `json:"materials" yaml:"materials"`
Recipes []CraftRecipe `json:"recipes" yaml:"recipes"`
Rules CraftRules `json:"rules" yaml:"rules"`
}
func (r CraftRules) Validate() error {
@@ -131,7 +132,7 @@ func (c Catalog) validateCrafting() error {
return nil
}
v := c.Crafting
if len(v.Professions) < 1 || len(v.Professions) > 64 || len(v.Materials) > 256 || len(v.Recipes) > 512 {
if len(v.Professions) < 1 || len(v.Professions) > 64 || len(v.Materials) > 256 || len(v.Recipes) > 512 || len(v.RecipeHistory) > 4096 {
return fmt.Errorf("invalid crafting content limits")
}
if err := v.Rules.Validate(); err != nil {
@@ -163,6 +164,27 @@ func (c Catalog) validateCrafting() error {
titles[t.ID] = true
}
ids, combinations := map[string]bool{}, map[string]bool{}
history := map[string]bool{}
for _, r := range v.RecipeHistory {
key := fmt.Sprintf("%s:%d", r.ID, r.Revision)
if history[key] {
return fmt.Errorf("duplicate archived recipe revision")
}
history[key] = true
for _, current := range v.Recipes {
if current.ID == r.ID && current.Revision <= r.Revision {
return fmt.Errorf("archived recipe must precede current revision")
}
}
copy := *v
copy.Recipes = []CraftRecipe{r}
copy.RecipeHistory = nil
catalog := c
catalog.Crafting = &copy
if err := catalog.validateCrafting(); err != nil {
return err
}
}
for _, r := range v.Recipes {
if !validSetIdentity(r.ID, r.Name, r.Description) || ids[r.ID] || r.Revision < 1 || !professions[r.Profession] || r.Level < 1 || r.Level > 1000 || r.XP < 1 || r.XP > 1000000 || len(r.Inputs) < 1 || len(r.Inputs) > 16 || len(r.Outputs) < 1 || len(r.Outputs) > 8 || len(r.Stats) > 32 || len(r.Titles) > 16 {
return fmt.Errorf("invalid crafting recipe %q", r.Name)
+5 -1
View File
@@ -40,6 +40,7 @@ type BiomeDefinition struct {
Weight int64 `json:"weight" yaml:"weight"`
}
type GatheringConsumable struct {
UseEffect *ItemUseEffect `json:"useEffect,omitempty" yaml:"useEffect"`
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
@@ -144,9 +145,12 @@ func (g GatheringContent) Validate() error {
}
}
for _, c := range g.Consumables {
if !identity(c.ID, c.Name, c.Description) || !finiteRange(c.Seconds, 1, 86400) || len(c.Modifiers) < 1 {
if !identity(c.ID, c.Name, c.Description) || !finiteRange(c.Seconds, 1, 86400) || (c.UseEffect == nil && len(c.Modifiers) < 1) {
return fmt.Errorf("invalid consumable %q", c.ID)
}
if c.UseEffect != nil && (len(c.Modifiers) != 0 || !c.UseEffect.Valid()) {
return fmt.Errorf("invalid consumable use effect")
}
if err := ValidateModifiers(c.Modifiers); err != nil {
return err
}
+29
View File
@@ -0,0 +1,29 @@
package content
import "fmt"
type ItemUseEffect struct {
Kind string `json:"kind" yaml:"kind"`
Amount float64 `json:"amount" yaml:"amount"`
}
func (e ItemUseEffect) Valid() bool {
return (e.Kind == "heal" || e.Kind == "weapon-coating") && finiteRange(e.Amount, .1, 10000)
}
type InventoryRules struct {
StopWeightRatio float64 `yaml:"stopWeightRatio"`
SlowdownExponent float64 `yaml:"slowdownExponent"`
BreakdownBase float64 `yaml:"breakdownBase"`
BreakdownMax float64 `yaml:"breakdownMax"`
BreakdownLevelScale float64 `yaml:"breakdownLevelScale"`
RecipeChance float64 `yaml:"recipeChance"`
ActionCooldown float64 `yaml:"actionCooldown"`
}
func (r InventoryRules) Validate() error {
if r.StopWeightRatio != 2 || !finiteRange(r.SlowdownExponent, 1, 4) || !finiteRange(r.BreakdownBase, 0, 100) || !finiteRange(r.BreakdownMax, r.BreakdownBase, 99) || !finiteRange(r.BreakdownLevelScale, 1, 1000) || r.RecipeChance != .01 || !finiteRange(r.ActionCooldown, .1, 30) {
return fmt.Errorf("invalid inventory rules")
}
return nil
}