2020-05-10 18:44:20 +00:00
|
|
|
package tins2020
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Herbarium struct {
|
|
|
|
flowers map[string]FlowerDescriptor
|
|
|
|
order []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHerbarium() Herbarium {
|
2020-05-11 01:09:01 +00:00
|
|
|
h := Herbarium{map[string]FlowerDescriptor{}, nil}
|
|
|
|
h.Reset()
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Herbarium) Reset() {
|
|
|
|
h.flowers = map[string]FlowerDescriptor{}
|
|
|
|
h.order = nil
|
|
|
|
|
|
|
|
h.Add("anemone", FlowerDescriptor{
|
|
|
|
Name: "Anemone",
|
|
|
|
Description: "A very generic flower that thrives in a temperate climate.",
|
|
|
|
IconTemplate: "flower-anemone-%s",
|
|
|
|
BuyPrice: 10,
|
|
|
|
SellPrice: 3,
|
|
|
|
Traits: NewAnemoneTraits(),
|
|
|
|
Unlocked: true,
|
|
|
|
})
|
|
|
|
h.Add("loosestrife", FlowerDescriptor{
|
|
|
|
Name: "Loosestrife",
|
|
|
|
Description: "A simple flower that will spread in temperate and wet climates.",
|
|
|
|
IconTemplate: "flower-loosestrife-%s",
|
|
|
|
BuyPrice: 100,
|
|
|
|
SellPrice: 20,
|
|
|
|
Traits: NewLoosestrifeTraits(),
|
2020-05-12 07:11:27 +00:00
|
|
|
Unlocked: false,
|
2020-05-11 01:09:01 +00:00
|
|
|
})
|
|
|
|
h.Add("coneflower", FlowerDescriptor{
|
|
|
|
Name: "Coneflower",
|
|
|
|
Description: "A beautifull flower that can withstand hotter climates.",
|
|
|
|
IconTemplate: "flower-coneflower-%s",
|
|
|
|
BuyPrice: 500,
|
|
|
|
SellPrice: 100,
|
|
|
|
Traits: NewConeflowerTraits(),
|
2020-05-12 07:11:27 +00:00
|
|
|
Unlocked: false,
|
2020-05-11 01:09:01 +00:00
|
|
|
})
|
|
|
|
h.Add("tulip", FlowerDescriptor{
|
|
|
|
Name: "Tulip",
|
|
|
|
Description: "A lovely flower that prefers a bit humid and colder climates.",
|
|
|
|
IconTemplate: "flower-tulip-%s",
|
|
|
|
BuyPrice: 20000,
|
|
|
|
SellPrice: 5000,
|
|
|
|
Traits: NewTulipTraits(),
|
2020-05-12 07:11:27 +00:00
|
|
|
Unlocked: false,
|
2020-05-11 01:09:01 +00:00
|
|
|
})
|
|
|
|
h.Add("ajuga", FlowerDescriptor{
|
|
|
|
Name: "Ajuga",
|
|
|
|
Description: "A flower that is resitant to cold climates and spreads very easily.",
|
|
|
|
IconTemplate: "flower-ajuga-%s",
|
|
|
|
BuyPrice: 100000,
|
|
|
|
SellPrice: 10000,
|
|
|
|
Traits: NewAjugaTraits(),
|
2020-05-12 07:11:27 +00:00
|
|
|
Unlocked: false,
|
2020-05-11 01:09:01 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Herbarium) Update(id string, update func(*FlowerDescriptor)) {
|
|
|
|
flower, ok := h.flowers[id]
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
update(&flower)
|
|
|
|
h.flowers[id] = flower
|
2020-05-10 18:44:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type FlowerDescriptor struct {
|
2020-05-10 21:00:19 +00:00
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
BuyPrice int
|
|
|
|
SellPrice int
|
|
|
|
|
2020-05-10 18:44:20 +00:00
|
|
|
Unlocked bool
|
|
|
|
IconTemplate IconTemplate
|
|
|
|
Traits FlowerTraits
|
|
|
|
}
|
|
|
|
|
|
|
|
type IconTemplate string
|
|
|
|
|
|
|
|
func (t IconTemplate) Disabled() string { return t.Fmt("disabled") }
|
|
|
|
|
|
|
|
func (t IconTemplate) Fmt(s string) string { return fmt.Sprintf(string(t), s) }
|
|
|
|
|
|
|
|
func (t IconTemplate) Variant(i int) string { return t.Fmt(strconv.Itoa(i)) }
|
|
|
|
|
|
|
|
func (h *Herbarium) Add(id string, desc FlowerDescriptor) {
|
|
|
|
h.flowers[id] = desc
|
|
|
|
h.order = append(h.order, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Herbarium) Find(id string) (FlowerDescriptor, bool) {
|
|
|
|
flower, ok := h.flowers[id]
|
|
|
|
return flower, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Herbarium) Flowers() []string { return h.order }
|
2020-05-11 01:09:01 +00:00
|
|
|
|
|
|
|
func (h *Herbarium) IsUnlocked(id string) bool {
|
|
|
|
flower, ok := h.flowers[id]
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return flower.Unlocked
|
|
|
|
}
|
2020-05-12 07:11:27 +00:00
|
|
|
|
|
|
|
func (h *Herbarium) NextFlowerToUnlock() (string, FlowerDescriptor, int) {
|
|
|
|
var previous *FlowerDescriptor
|
|
|
|
for _, id := range h.Flowers() {
|
|
|
|
flower, _ := h.Find(id)
|
|
|
|
if !flower.Unlocked {
|
|
|
|
if previous == nil {
|
|
|
|
return "", FlowerDescriptor{}, 0
|
|
|
|
}
|
|
|
|
return id, flower, previous.BuyPrice * 2
|
|
|
|
}
|
|
|
|
previous = &flower
|
|
|
|
}
|
|
|
|
return "", FlowerDescriptor{}, 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Herbarium) UnlockNext() {
|
|
|
|
// id, flower, _ := h.NextFlowerToUnlock()
|
|
|
|
// if flower == nil {
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
|
|
|
|
// flower.Unlocked = true
|
|
|
|
// h.flowers[flower]
|
|
|
|
}
|