Skip to content

Commit

Permalink
pet, command: improvements to pet mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrtronium committed Jan 5, 2025
1 parent 20d5a21 commit e784f76
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
19 changes: 5 additions & 14 deletions command/tamagotchi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]{
Expand All @@ -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?"
Expand Down
26 changes: 19 additions & 7 deletions pet/pet.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pet

import (
"math/rand/v2"
"sync"
"time"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pet/pet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit e784f76

Please sign in to comment.