Checkpoint stats equipment and control catalog implementation
This commit is contained in:
@@ -15,6 +15,7 @@ attackRange: 6
|
||||
attackCooldown: 0.7
|
||||
playerDamage: 18
|
||||
criticalMultiplier: 2
|
||||
maxYieldPerAction: 100
|
||||
spearDamage: 32
|
||||
gatherRange: 7
|
||||
gatherCooldown: 0.6
|
||||
|
||||
@@ -36,6 +36,7 @@ type Balance struct {
|
||||
AttackCooldown float64 `yaml:"attackCooldown"`
|
||||
PlayerDamage float64 `yaml:"playerDamage"`
|
||||
CriticalMultiplier float64 `yaml:"criticalMultiplier"`
|
||||
MaxYieldPerAction int64 `yaml:"maxYieldPerAction"`
|
||||
SpearDamage float64 `yaml:"spearDamage"`
|
||||
GatherRange float64 `yaml:"gatherRange"`
|
||||
GatherCooldown float64 `yaml:"gatherCooldown"`
|
||||
@@ -106,6 +107,7 @@ func (b Balance) Validate() error {
|
||||
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")
|
||||
}
|
||||
if b.MaxYieldPerAction > 1000 || b.CriticalMultiplier > 100 { return fmt.Errorf("invalid yield or critical damage tuning") }
|
||||
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 {
|
||||
|
||||
@@ -93,7 +93,9 @@ func ValidItemSlot(slot string) bool {
|
||||
return slices.Contains([]string{"helmet", "mask", "chest", "shoulders", "pants", "boots", "gloves", "earrings", "necklace", "ring", "weapon", "offhand", "cape", "bag"}, slot)
|
||||
}
|
||||
func (item ItemDefinition) Validate() error {
|
||||
if slices.Contains([]string{"axe","flint_and_steel","fishing_pole","wood","ore","herb","bandage"},item.ID){return fmt.Errorf("equipment ID conflicts with a stackable item")}
|
||||
if slices.Contains([]string{"axe", "flint_and_steel", "fishing_pole", "wood", "ore", "herb", "bandage"}, item.ID) {
|
||||
return fmt.Errorf("equipment ID conflicts with a stackable item")
|
||||
}
|
||||
if math.IsNaN(item.DropChance) || math.IsInf(item.DropChance, 0) || item.DropChance < 0 || item.DropChance > 100 {
|
||||
return fmt.Errorf("invalid drop chance")
|
||||
}
|
||||
|
||||
@@ -1,27 +1,44 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCatalogRejectsInvalidStatsAndItemRequirements(t *testing.T) {
|
||||
for name, mutate:=range map[string]func(*Catalog){
|
||||
"unknown stat":func(c *Catalog){c.Stats.Base["admin"]=1},
|
||||
"negative primary":func(c *Catalog){c.Stats.Base["constitution"]=-1},
|
||||
"nonfinite coefficient":func(c *Catalog){c.Stats.Coefficients["luck"]["criticalChance"]=math.NaN()},
|
||||
"unrelated coefficient":func(c *Catalog){delete(c.Stats.Coefficients["charisma"],"buffEffectiveness");c.Stats.Coefficients["charisma"]["healthPoints"]=1},
|
||||
"unknown modifier":func(c *Catalog){c.Titles[0].Effects.Modifiers=[]StatModifier{{Stat:"dailySeconds",Flat:100}}},
|
||||
"unsafe percentage":func(c *Catalog){c.Titles[0].Effects.Modifiers=[]StatModifier{{Stat:"strength",Percent:-101}}},
|
||||
"invalid slot":func(c *Catalog){c.Items[0].Slot="ring9"},
|
||||
"unknown title":func(c *Catalog){c.Items[0].Requirements.Titles=[]string{"missing"}},
|
||||
"duplicate item":func(c *Catalog){c.Items=append(c.Items,c.Items[0])},
|
||||
"stack collision":func(c *Catalog){c.Items[0].ID="wood"},
|
||||
"invalid drop chance":func(c *Catalog){c.Items[0].DropChance=101},
|
||||
} {
|
||||
t.Run(name,func(t *testing.T){c,err:=DefaultCatalog();if err!=nil{t.Fatal(err)};mutate(&c);if err=c.Validate();err==nil{t.Fatal("invalid catalog accepted")}})
|
||||
}
|
||||
c,err:=DefaultCatalog();if err!=nil{t.Fatal(err)}
|
||||
c.Items=append(c.Items,ItemDefinition{ID:"cursed_ring",Name:"Cursed ring",Slot:"ring",Weight:1,DropChance:2,Requirements:ItemRequirements{Level:2,Stats:map[string]float64{"constitution":3},Titles:[]string{"wayfarer"}},Modifiers:[]StatModifier{{Stat:"constitution",Flat:2,Percent:10},{Stat:"moveSpeed",Percent:-10}}})
|
||||
if err=c.Validate();err!=nil{t.Fatal(err)}
|
||||
for name, mutate := range map[string]func(*Catalog){
|
||||
"unknown stat": func(c *Catalog) { c.Stats.Base["admin"] = 1 },
|
||||
"negative primary": func(c *Catalog) { c.Stats.Base["constitution"] = -1 },
|
||||
"nonfinite coefficient": func(c *Catalog) { c.Stats.Coefficients["luck"]["criticalChance"] = math.NaN() },
|
||||
"unrelated coefficient": func(c *Catalog) {
|
||||
delete(c.Stats.Coefficients["charisma"], "buffEffectiveness")
|
||||
c.Stats.Coefficients["charisma"]["healthPoints"] = 1
|
||||
},
|
||||
"unknown modifier": func(c *Catalog) { c.Titles[0].Effects.Modifiers = []StatModifier{{Stat: "dailySeconds", Flat: 100}} },
|
||||
"unsafe percentage": func(c *Catalog) { c.Titles[0].Effects.Modifiers = []StatModifier{{Stat: "strength", Percent: -101}} },
|
||||
"invalid slot": func(c *Catalog) { c.Items[0].Slot = "ring9" },
|
||||
"unknown title": func(c *Catalog) { c.Items[0].Requirements.Titles = []string{"missing"} },
|
||||
"duplicate item": func(c *Catalog) { c.Items = append(c.Items, c.Items[0]) },
|
||||
"stack collision": func(c *Catalog) { c.Items[0].ID = "wood" },
|
||||
"invalid drop chance": func(c *Catalog) { c.Items[0].DropChance = 101 },
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
c, err := DefaultCatalog()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mutate(&c)
|
||||
if err = c.Validate(); err == nil {
|
||||
t.Fatal("invalid catalog accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
c, err := DefaultCatalog()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c.Items = append(c.Items, ItemDefinition{ID: "cursed_ring", Name: "Cursed ring", Slot: "ring", Weight: 1, DropChance: 2, Requirements: ItemRequirements{Level: 2, Stats: map[string]float64{"constitution": 3}, Titles: []string{"wayfarer"}}, Modifiers: []StatModifier{{Stat: "constitution", Flat: 2, Percent: 10}, {Stat: "moveSpeed", Percent: -10}}})
|
||||
if err = c.Validate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user