diff --git a/command/tamagotchi.go b/command/tamagotchi.go index 161d80e..93f481b 100644 --- a/command/tamagotchi.go +++ b/command/tamagotchi.go @@ -19,9 +19,9 @@ var hungerys = pick.New([]pick.Case[string]{ }) var cleanies = pick.New([]pick.Case[string]{ - {E: "need to clean the", W: 15}, - {E: "kinda messy in the", W: 15}, - {E: "lil stinky in the", W: 5}, + {E: "need to clean up", W: 15}, + {E: "kinda messy around here", W: 15}, + {E: "lil stinky", W: 5}, }) var socials = pick.New([]pick.Case[string]{ @@ -44,18 +44,9 @@ func satmsg(sat pet.Satisfaction) (connective, state string) { case sat.Fed: m := hungerys.Pick(rand.Uint32()) return ", but", m + " πŸ₯ΊπŸ‘‰πŸ‘ˆ tell me to eat?" - case sat.Bed: + case sat.Bed, sat.Kitche, sat.Living, sat.Bath: m := cleanies.Pick(rand.Uint32()) - return ", but", m + " bedroom πŸ₯ΊπŸ‘‰πŸ‘ˆ help me clean?" - case sat.Kitche: - m := cleanies.Pick(rand.Uint32()) - return ", but", m + " kitchen πŸ₯ΊπŸ‘‰πŸ‘ˆ help me clean?" - case sat.Living: - m := cleanies.Pick(rand.Uint32()) - return ", but", m + " living room πŸ₯ΊπŸ‘‰πŸ‘ˆ help me clean?" - case sat.Bath: - m := cleanies.Pick(rand.Uint32()) - return ", but", m + " bathroom πŸ₯ΊπŸ‘‰πŸ‘ˆ help me clean?" + return ", but", m + " πŸ₯ΊπŸ‘‰πŸ‘ˆ help me clean?" case sat.Pats: m := socials.Pick(rand.Uint32()) return ", but", m + " πŸ₯ΊπŸ‘‰πŸ‘ˆ give pats?" diff --git a/pet/pet.go b/pet/pet.go index 1ecfe05..65c4025 100644 --- a/pet/pet.go +++ b/pet/pet.go @@ -1,6 +1,7 @@ package pet import ( + "math/rand/v2" "sync" "time" ) @@ -104,21 +105,27 @@ func (r Room) String() string { func (s *Status) Clean(asof time.Time) (Room, Satisfaction) { s.mu.Lock() defer s.mu.Unlock() - type pair struct { + type cleanup struct { room Room tm *time.Time + add time.Duration } - ck := []pair{ - {Bedroom, &s.bed}, - {Kitchen, &s.kitche}, - {Living, &s.living}, - {Bathroom, &s.bath}, + ck := []cleanup{ + {Bedroom, &s.bed, 100 * time.Hour}, + {Bedroom, &s.bed, 120 * time.Hour}, + {Kitchen, &s.kitche, 30 * time.Hour}, + {Kitchen, &s.kitche, 50 * time.Hour}, + {Living, &s.living, 156 * time.Hour}, + {Living, &s.living, 176 * time.Hour}, + {Bathroom, &s.bath, 80 * time.Hour}, + {Bathroom, &s.bath, 100 * time.Hour}, } + rand.Shuffle(len(ck), func(i, j int) { ck[i], ck[j] = ck[j], ck[i] }) for _, c := range ck { if asof.Before(*c.tm) { continue } - *c.tm = asof.Add(40 * time.Hour) + *c.tm = asof.Add(c.add) return c.room, s.satLocked(asof) } return AllClean, s.satLocked(asof) @@ -128,9 +135,14 @@ func (s *Status) Clean(asof time.Time) (Room, Satisfaction) { // love is interpreted as a number of minutes for which the pet will feel loved // with this pat. If the resulting time expires before its existing love, it // has no effect. +// If all the pet's other needs are met, but not pat, the pat becomes stronger. func (s *Status) Pat(asof time.Time, love int) Satisfaction { s.mu.Lock() defer s.mu.Unlock() + r := s.satLocked(asof) + if r == (Satisfaction{Fed: true, Bed: true, Kitche: true, Living: true, Bath: true, Pats: false}) { + love *= 2 + } sat := asof.Add(time.Duration(love) * time.Minute) if s.pats.Before(sat) { s.pats = sat diff --git a/pet/pet_test.go b/pet/pet_test.go index 02de33c..d4bfb19 100644 --- a/pet/pet_test.go +++ b/pet/pet_test.go @@ -73,7 +73,7 @@ func TestClean(t *testing.T) { if sat != (pet.Satisfaction{Bed: true, Kitche: true, Living: true, Bath: true}) { t.Errorf("wrong satisfied after cleaning: got %+v, want all rooms true", sat) } - r, _ = s.Clean(now.Add(40*time.Hour + 1)) + r, _ = s.Clean(now.Add(50*time.Hour + 1)) if r == pet.AllClean { t.Errorf("didn't clean after clean expired") }