97 lines
3.3 KiB
Go
97 lines
3.3 KiB
Go
package content
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"regexp"
|
|
)
|
|
|
|
type Progression struct {
|
|
BaseXP int64 `yaml:"baseXp"`
|
|
XPPerLevel int64 `yaml:"xpPerLevel"`
|
|
StatPointsPerLevel int64 `yaml:"statPointsPerLevel"`
|
|
StaminaPerLevel int64 `yaml:"staminaPerLevel"`
|
|
VitalPointsPerChoice int64 `yaml:"vitalPointsPerChoice"`
|
|
MaxLevel int64 `yaml:"maxLevel"`
|
|
GatherXP int64 `yaml:"gatherXp"`
|
|
CraftXP int64 `yaml:"craftXp"`
|
|
MobKillXP int64 `yaml:"mobKillXp"`
|
|
BossKillXP int64 `yaml:"bossKillXp"`
|
|
}
|
|
|
|
type TitleRequirement struct {
|
|
Metric string `json:"metric" yaml:"metric"`
|
|
AtLeast int64 `json:"atLeast" yaml:"atLeast"`
|
|
}
|
|
|
|
type TitleEffects struct {
|
|
Damage float64 `json:"damage" yaml:"damage"`
|
|
MoveSpeed float64 `json:"moveSpeed" yaml:"moveSpeed"`
|
|
Modifiers []StatModifier `json:"modifiers" yaml:"modifiers"`
|
|
}
|
|
|
|
type Title struct {
|
|
ID string `json:"id" yaml:"id"`
|
|
Name string `json:"name" yaml:"name"`
|
|
Description string `json:"description" yaml:"description"`
|
|
Scope string `json:"scope" yaml:"scope"`
|
|
Requirements []TitleRequirement `json:"requirements" yaml:"requirements"`
|
|
Effects TitleEffects `json:"effects" yaml:"effects"`
|
|
}
|
|
|
|
var titleID = regexp.MustCompile(`^[a-z][a-z0-9_-]{0,63}$`)
|
|
|
|
func (b Balance) validateProgression() error {
|
|
if b.Progression == nil {
|
|
return fmt.Errorf("progression configuration is required")
|
|
}
|
|
if err := b.Progression.Validate(); err != nil {
|
|
return err
|
|
}
|
|
if len(b.Titles) > 256 {
|
|
return fmt.Errorf("too many title definitions")
|
|
}
|
|
seen := map[string]bool{}
|
|
for _, title := range b.Titles {
|
|
if !titleID.MatchString(title.ID) || seen[title.ID] || len(title.Name) < 1 || len(title.Name) > 80 || len(title.Description) > 500 {
|
|
return fmt.Errorf("invalid or duplicate title %q", title.ID)
|
|
}
|
|
seen[title.ID] = true
|
|
if title.Scope != "personal" && title.Scope != "world" && title.Scope != "global" {
|
|
return fmt.Errorf("invalid title scope %q", title.Scope)
|
|
}
|
|
if len(title.Requirements) < 1 || len(title.Requirements) > 8 {
|
|
return fmt.Errorf("title %q needs bounded requirements", title.ID)
|
|
}
|
|
for _, r := range title.Requirements {
|
|
if !ValidRequirement(r) {
|
|
return fmt.Errorf("invalid title requirement for %q", title.ID)
|
|
}
|
|
}
|
|
for _, effect := range []float64{title.Effects.Damage, title.Effects.MoveSpeed} {
|
|
if math.IsNaN(effect) || math.IsInf(effect, 0) || math.Abs(effect) > 1000 {
|
|
return fmt.Errorf("invalid title effect for %q", title.ID)
|
|
}
|
|
}
|
|
if err := ValidateModifiers(title.Effects.Modifiers); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p Progression) Validate() error {
|
|
if p.StaminaPerLevel < 1 || p.StaminaPerLevel > 1000 || p.VitalPointsPerChoice < 1 || p.VitalPointsPerChoice > 1000 {
|
|
return fmt.Errorf("invalid stamina or vital level reward")
|
|
}
|
|
if p.BaseXP < 1 || p.BaseXP > 1000000000 || p.XPPerLevel < 0 || p.XPPerLevel > 1000000000 || p.StatPointsPerLevel < 1 || p.StatPointsPerLevel > 1000 || p.MaxLevel < 2 || p.MaxLevel > 10000 {
|
|
return fmt.Errorf("invalid progression curve or stat point grant")
|
|
}
|
|
for _, xp := range []int64{p.GatherXP, p.CraftXP, p.MobKillXP, p.BossKillXP} {
|
|
if xp < 0 || xp > 1000000000 {
|
|
return fmt.Errorf("invalid progression XP reward")
|
|
}
|
|
}
|
|
return nil
|
|
}
|