53 lines
1.3 KiB
Go
53 lines
1.3 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 {
|
|
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 !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
|
|
}
|