Add character levels and permanent player titles
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Progression struct {
|
||||
BaseXP int64 `yaml:"baseXp"`
|
||||
XPPerLevel int64 `yaml:"xpPerLevel"`
|
||||
StatPointsPerLevel int64 `yaml:"statPointsPerLevel"`
|
||||
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 `yaml:"metric"`
|
||||
AtLeast int64 `yaml:"atLeast"`
|
||||
}
|
||||
|
||||
type TitleEffects struct {
|
||||
Damage float64 `yaml:"damage"`
|
||||
MoveSpeed float64 `yaml:"moveSpeed"`
|
||||
}
|
||||
|
||||
type Title struct {
|
||||
ID string `yaml:"id"`
|
||||
Name string `yaml:"name"`
|
||||
Description string `yaml:"description"`
|
||||
Scope string `yaml:"scope"`
|
||||
Requirements []TitleRequirement `yaml:"requirements"`
|
||||
Effects TitleEffects `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{}
|
||||
metrics := map[string]bool{"level": true, "kills": true, "worldKills": true, "bossKills": true, "worldsSurvived": true, "gathering": true, "crafting": true, "combat": true, "deaths": true}
|
||||
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 !metrics[r.Metric] || r.AtLeast < 1 || r.AtLeast > 1000000000 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p Progression) Validate() error {
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user