Build playable Aeternalis foundation and GitOps deployment pipeline
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
|
||||
"go.yaml.in/yaml/v3"
|
||||
)
|
||||
|
||||
//go:embed balance.yaml
|
||||
var balance []byte
|
||||
|
||||
type Recipe struct {
|
||||
Inputs map[string]int64 `yaml:"inputs"`
|
||||
Outputs map[string]int64 `yaml:"outputs"`
|
||||
}
|
||||
|
||||
type Balance struct {
|
||||
Version int `yaml:"version"`
|
||||
TickHz int `yaml:"tickHz"`
|
||||
SnapshotHz int `yaml:"snapshotHz"`
|
||||
ChunkSize float64 `yaml:"chunkSize"`
|
||||
TerrainResolution int `yaml:"terrainResolution"`
|
||||
WorldRadius float64 `yaml:"worldRadius"`
|
||||
MaxPlayers int `yaml:"maxPlayers"`
|
||||
SpawnSeparation float64 `yaml:"spawnSeparation"`
|
||||
SeasonSeconds float64 `yaml:"seasonSeconds"`
|
||||
CollapseSeconds float64 `yaml:"collapseSeconds"`
|
||||
DailyPlaySeconds float64 `yaml:"dailyPlaySeconds"`
|
||||
PlayerHp float64 `yaml:"playerHp"`
|
||||
PlayerSpeed float64 `yaml:"playerSpeed"`
|
||||
AttackRange float64 `yaml:"attackRange"`
|
||||
AttackCooldown float64 `yaml:"attackCooldown"`
|
||||
PlayerDamage float64 `yaml:"playerDamage"`
|
||||
SpearDamage float64 `yaml:"spearDamage"`
|
||||
GatherRange float64 `yaml:"gatherRange"`
|
||||
GatherCooldown float64 `yaml:"gatherCooldown"`
|
||||
BossHp float64 `yaml:"bossHp"`
|
||||
BossDamage float64 `yaml:"bossDamage"`
|
||||
BossRange float64 `yaml:"bossRange"`
|
||||
BossCooldown float64 `yaml:"bossCooldown"`
|
||||
StormDamagePerSecond float64 `yaml:"stormDamagePerSecond"`
|
||||
MobHp float64 `yaml:"mobHp"`
|
||||
MobDamage float64 `yaml:"mobDamage"`
|
||||
MobSpeed float64 `yaml:"mobSpeed"`
|
||||
MobAggroRange float64 `yaml:"mobAggroRange"`
|
||||
MobAttackRange float64 `yaml:"mobAttackRange"`
|
||||
MobCooldown float64 `yaml:"mobCooldown"`
|
||||
MobRespawnSeconds float64 `yaml:"mobRespawnSeconds"`
|
||||
MobScalePerDay float64 `yaml:"mobScalePerDay"`
|
||||
ResourcesPerChunk int `yaml:"resourcesPerChunk"`
|
||||
ResourceRespawnSeconds float64 `yaml:"resourceRespawnSeconds"`
|
||||
SkillXpPerAction int64 `yaml:"skillXpPerAction"`
|
||||
StartingKit map[string]int64 `yaml:"startingKit"`
|
||||
Recipes map[string]Recipe `yaml:"recipes"`
|
||||
BandageHealing float64 `yaml:"bandageHealing"`
|
||||
}
|
||||
|
||||
func Load() (Balance, error) { return Parse(balance) }
|
||||
func Parse(data []byte) (Balance, error) {
|
||||
var b Balance
|
||||
d := yaml.NewDecoder(bytes.NewReader(data))
|
||||
d.KnownFields(true)
|
||||
if err := d.Decode(&b); err != nil {
|
||||
return b, err
|
||||
}
|
||||
return b, b.Validate()
|
||||
}
|
||||
func (b Balance) Validate() error {
|
||||
v := reflect.ValueOf(b)
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
f := v.Field(i)
|
||||
n := float64(1)
|
||||
switch f.Kind() {
|
||||
case reflect.Int, reflect.Int64:
|
||||
n = float64(f.Int())
|
||||
case reflect.Float64:
|
||||
n = f.Float()
|
||||
}
|
||||
if n <= 0 || math.IsNaN(n) || math.IsInf(n, 0) {
|
||||
return fmt.Errorf("%s must be finite and positive", v.Type().Field(i).Name)
|
||||
}
|
||||
}
|
||||
if b.TickHz > 60 || b.SnapshotHz > b.TickHz || b.TickHz%b.SnapshotHz != 0 || b.TerrainResolution > 64 || b.ResourcesPerChunk > 128 || b.MaxPlayers > 2000 || b.WorldRadius < b.ChunkSize*2 {
|
||||
return fmt.Errorf("invalid capacity, terrain, or tick configuration")
|
||||
}
|
||||
known := map[string]bool{"knife": true, "axe": true, "flint_and_steel": true, "fishing_pole": true, "wood": true, "ore": true, "herb": true, "spear": true, "bandage": true}
|
||||
check := func(items map[string]int64) error {
|
||||
if len(items) == 0 {
|
||||
return fmt.Errorf("empty item list")
|
||||
}
|
||||
for k, n := range items {
|
||||
if !known[k] || n < 1 || n > 1000 {
|
||||
return fmt.Errorf("invalid item %q quantity %d", k, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := check(b.StartingKit); err != nil {
|
||||
return err
|
||||
}
|
||||
for name, r := range b.Recipes {
|
||||
if !known[name] {
|
||||
return fmt.Errorf("unknown recipe %q", name)
|
||||
}
|
||||
if err := check(r.Inputs); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := check(r.Outputs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user