Skip to content

Commit e784f76

Browse files
committed
pet, command: improvements to pet mode
1 parent 20d5a21 commit e784f76

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

command/tamagotchi.go

+5-14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ var hungerys = pick.New([]pick.Case[string]{
1919
})
2020

2121
var cleanies = pick.New([]pick.Case[string]{
22-
{E: "need to clean the", W: 15},
23-
{E: "kinda messy in the", W: 15},
24-
{E: "lil stinky in the", W: 5},
22+
{E: "need to clean up", W: 15},
23+
{E: "kinda messy around here", W: 15},
24+
{E: "lil stinky", W: 5},
2525
})
2626

2727
var socials = pick.New([]pick.Case[string]{
@@ -44,18 +44,9 @@ func satmsg(sat pet.Satisfaction) (connective, state string) {
4444
case sat.Fed:
4545
m := hungerys.Pick(rand.Uint32())
4646
return ", but", m + " 🥺👉👈 tell me to eat?"
47-
case sat.Bed:
47+
case sat.Bed, sat.Kitche, sat.Living, sat.Bath:
4848
m := cleanies.Pick(rand.Uint32())
49-
return ", but", m + " bedroom 🥺👉👈 help me clean?"
50-
case sat.Kitche:
51-
m := cleanies.Pick(rand.Uint32())
52-
return ", but", m + " kitchen 🥺👉👈 help me clean?"
53-
case sat.Living:
54-
m := cleanies.Pick(rand.Uint32())
55-
return ", but", m + " living room 🥺👉👈 help me clean?"
56-
case sat.Bath:
57-
m := cleanies.Pick(rand.Uint32())
58-
return ", but", m + " bathroom 🥺👉👈 help me clean?"
49+
return ", but", m + " 🥺👉👈 help me clean?"
5950
case sat.Pats:
6051
m := socials.Pick(rand.Uint32())
6152
return ", but", m + " 🥺👉👈 give pats?"

pet/pet.go

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pet
22

33
import (
4+
"math/rand/v2"
45
"sync"
56
"time"
67
)
@@ -104,21 +105,27 @@ func (r Room) String() string {
104105
func (s *Status) Clean(asof time.Time) (Room, Satisfaction) {
105106
s.mu.Lock()
106107
defer s.mu.Unlock()
107-
type pair struct {
108+
type cleanup struct {
108109
room Room
109110
tm *time.Time
111+
add time.Duration
110112
}
111-
ck := []pair{
112-
{Bedroom, &s.bed},
113-
{Kitchen, &s.kitche},
114-
{Living, &s.living},
115-
{Bathroom, &s.bath},
113+
ck := []cleanup{
114+
{Bedroom, &s.bed, 100 * time.Hour},
115+
{Bedroom, &s.bed, 120 * time.Hour},
116+
{Kitchen, &s.kitche, 30 * time.Hour},
117+
{Kitchen, &s.kitche, 50 * time.Hour},
118+
{Living, &s.living, 156 * time.Hour},
119+
{Living, &s.living, 176 * time.Hour},
120+
{Bathroom, &s.bath, 80 * time.Hour},
121+
{Bathroom, &s.bath, 100 * time.Hour},
116122
}
123+
rand.Shuffle(len(ck), func(i, j int) { ck[i], ck[j] = ck[j], ck[i] })
117124
for _, c := range ck {
118125
if asof.Before(*c.tm) {
119126
continue
120127
}
121-
*c.tm = asof.Add(40 * time.Hour)
128+
*c.tm = asof.Add(c.add)
122129
return c.room, s.satLocked(asof)
123130
}
124131
return AllClean, s.satLocked(asof)
@@ -128,9 +135,14 @@ func (s *Status) Clean(asof time.Time) (Room, Satisfaction) {
128135
// love is interpreted as a number of minutes for which the pet will feel loved
129136
// with this pat. If the resulting time expires before its existing love, it
130137
// has no effect.
138+
// If all the pet's other needs are met, but not pat, the pat becomes stronger.
131139
func (s *Status) Pat(asof time.Time, love int) Satisfaction {
132140
s.mu.Lock()
133141
defer s.mu.Unlock()
142+
r := s.satLocked(asof)
143+
if r == (Satisfaction{Fed: true, Bed: true, Kitche: true, Living: true, Bath: true, Pats: false}) {
144+
love *= 2
145+
}
134146
sat := asof.Add(time.Duration(love) * time.Minute)
135147
if s.pats.Before(sat) {
136148
s.pats = sat

pet/pet_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestClean(t *testing.T) {
7373
if sat != (pet.Satisfaction{Bed: true, Kitche: true, Living: true, Bath: true}) {
7474
t.Errorf("wrong satisfied after cleaning: got %+v, want all rooms true", sat)
7575
}
76-
r, _ = s.Clean(now.Add(40*time.Hour + 1))
76+
r, _ = s.Clean(now.Add(50*time.Hour + 1))
7777
if r == pet.AllClean {
7878
t.Errorf("didn't clean after clean expired")
7979
}

0 commit comments

Comments
 (0)