Files
DivaCode/internal/companion/mood.go

80 lines
1.3 KiB
Go

package companion
import (
"math/rand"
"sync"
"time"
"git.db123.ir/db123/divacode/pkg/types"
)
type MoodEngine struct {
mu sync.Mutex
current types.Mood
updatedAt time.Time
energy float64
}
func NewMoodEngine() *MoodEngine {
return &MoodEngine{
current: types.MoodNeutral,
updatedAt: time.Now(),
energy: 1.0,
}
}
func (m *MoodEngine) Current() types.Mood {
m.mu.Lock()
defer m.mu.Unlock()
return m.current
}
func (m *MoodEngine) Set(mood types.Mood) {
m.mu.Lock()
defer m.mu.Unlock()
m.current = mood
m.updatedAt = time.Now()
}
func (m *MoodEngine) DeriveFromInteraction(success bool, topicIntensity float64) types.Mood {
m.mu.Lock()
defer m.mu.Unlock()
m.energy -= 0.05
if m.energy < 0 {
m.energy = 0
}
if !success {
m.current = types.MoodAnnoyed
} else if topicIntensity > 0.7 {
if rand.Float64() > 0.5 {
m.current = types.MoodCurious
} else {
m.current = types.MoodPlayful
}
} else if m.energy < 0.3 {
m.current = types.MoodTired
} else {
m.current = types.MoodNeutral
}
m.updatedAt = time.Now()
return m.current
}
func (m *MoodEngine) Recharge() {
m.mu.Lock()
defer m.mu.Unlock()
m.energy += 0.1
if m.energy > 1.0 {
m.energy = 1.0
}
}
func (m *MoodEngine) Energy() float64 {
m.mu.Lock()
defer m.mu.Unlock()
return m.energy
}