Files

62 lines
1.8 KiB
Go

package content
import "fmt"
type FurnitureProfile struct {
Width float64 `json:"width" yaml:"width"`
Depth float64 `json:"depth" yaml:"depth"`
Container bool `json:"container" yaml:"container"`
}
func (f FurnitureProfile) Validate() error {
if !finiteRange(f.Width, .5, 4) || !finiteRange(f.Depth, .5, 4) {
return fmt.Errorf("invalid furniture footprint")
}
return nil
}
type HousingRules struct {
WalkSpeed float64 `yaml:"walkSpeed"`
PlayerRadius float64 `yaml:"playerRadius"`
JumpSpeed float64 `yaml:"jumpSpeed"`
Gravity float64 `yaml:"gravity"`
TableHeight float64 `yaml:"tableHeight"`
StorageHeight float64 `yaml:"storageHeight"`
RoomSize float64 `yaml:"roomSize"`
MaxFurniture int `yaml:"maxFurniture"`
MaxItems int `yaml:"maxItems"`
MaxGuests int `yaml:"maxGuests"`
KeySeconds float64 `yaml:"keySeconds"`
}
func (r HousingRules) Validate() error {
if r.WalkSpeed != 0 && (!finiteRange(r.WalkSpeed, 1, 8) || !finiteRange(r.PlayerRadius, .2, .6) || !finiteRange(r.JumpSpeed, 1, 8) || !finiteRange(r.Gravity, 10, 30) || !finiteRange(r.TableHeight, .5, 2) || !finiteRange(r.StorageHeight, .5, 2)) {
return fmt.Errorf("invalid indoor movement tuning")
}
if !finiteRange(r.RoomSize, 8, 32) || r.MaxFurniture < 1 || r.MaxFurniture > 128 || r.MaxItems < 1 || r.MaxItems > 512 || r.MaxGuests < 1 || r.MaxGuests > 128 || r.KeySeconds != 3 {
return fmt.Errorf("invalid housing rules")
}
return nil
}
func (c *Catalog) RestoreFurniture(b Balance) {
if c.HousingVersion != 0 {
return
}
c.Items = append([]ItemDefinition{}, c.Items...)
for _, v := range b.Items {
if v.Furniture == nil {
continue
}
found := false
for _, i := range c.Items {
if i.ID == v.ID {
found = true
}
}
if !found {
c.Items = append(c.Items, v)
}
}
c.HousingVersion = 1
}