petengine

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLevel           = 10
	XPPerMinute        = 2
	XPPerCommand       = 5
	XPPerFocusSession  = 50
	XPStreakMultiplier = 25
	IdleTimeoutSec     = 300 // 5 minutes
	SaveIntervalSec    = 30

	MoodHappy   = "happy"
	MoodNeutral = "neutral"
	MoodSad     = "sad"
	MoodHungry  = "hungry"
	MoodSleepy  = "sleepy"

	StateActive      = "ACTIVE"
	StateIdle        = "IDLE"
	StateSleeping    = "SLEEPING"
	StateCelebrating = "CELEBRATING"
	StateGrabbed     = "GRABBED"
)

XP and leveling constants

Variables

This section is empty.

Functions

func CalcXPToNext

func CalcXPToNext(level int) int

CalcXPToNext returns XP needed for the next level Formula: 100 * level * 1.5

func Init

func Init()

Init initializes the pet engine (called on server startup)

func Shutdown

func Shutdown()

Shutdown gracefully stops the pet engine

Types

type AnimDef

type AnimDef struct {
	Frames []int `json:"frames"`
	FPS    int   `json:"fps"`
	Loop   bool  `json:"loop"`
}

AnimDef — animation frame definition

type CustomDialogue

type CustomDialogue struct {
	ID       string `json:"id"`
	TextVI   string `json:"textVi"`
	TextEN   string `json:"textEn"`
	Mood     string `json:"mood,omitempty"`     // show only for this mood, empty = all
	TimeFrom int    `json:"timeFrom,omitempty"` // show from this hour (0-23), 0 = anytime
	TimeTo   int    `json:"timeTo,omitempty"`
}

CustomDialogue — user-defined pet dialogue

type DialogueCategory

type DialogueCategory string

DialogueCategory represents types of dialogues

const (
	DialogueRandom  DialogueCategory = "random"
	DialogueHealth  DialogueCategory = "health"
	DialogueLevelUp DialogueCategory = "levelup"
	DialogueCustom  DialogueCategory = "custom"
)

type DialogueResponse

type DialogueResponse struct {
	Text string `json:"text"`
	Type string `json:"type"` // random, health, levelup, custom
}

DialogueResponse wraps a dialogue text with metadata

func GetDialogue

func GetDialogue(mood string, hour int, lang string) DialogueResponse

GetDialogue returns a random dialogue based on mood, hour, and language

type PetCatalogueEntry

type PetCatalogueEntry struct {
	ID              string             `json:"id"`
	Name            string             `json:"name"`
	SpriteSheet     string             `json:"spriteSheet"`
	FrameWidth      int                `json:"frameWidth"`
	FrameHeight     int                `json:"frameHeight"`
	Animations      map[string]AnimDef `json:"animations"`
	Type            string             `json:"type"` // pokemon, shimeji, custom
	DiscordAssetKey string             `json:"discordAssetKey"`
}

PetCatalogueEntry — metadata for a pet type

func GetCatalogue

func GetCatalogue() []PetCatalogueEntry

GetCatalogue returns the available pet catalogue

type PetInstance

type PetInstance struct {
	ID            string    `json:"id"`
	PetID         string    `json:"petId"`
	Name          string    `json:"name"`
	Level         int       `json:"level"`
	XP            int       `json:"xp"`
	XPToNext      int       `json:"xpToNext"`
	Progress      float64   `json:"progress"` // 0.0 - 1.0
	Mood          string    `json:"mood"`     // happy, neutral, sad, hungry, sleepy
	State         string    `json:"state"`    // ACTIVE, IDLE, SLEEPING, CELEBRATING, GRABBED
	Hunger        float64   `json:"hunger"`   // 0.0 (sated) - 1.0 (starving)
	Energy        float64   `json:"energy"`   // 0.0 (exhausted) - 1.0 (full)
	SpawnedAt     time.Time `json:"spawnedAt"`
	TotalPlaytime int64     `json:"totalPlaytime"` // seconds
}

PetInstance — the active pet being raised

func AddXP

func AddXP(amount int) (*PetInstance, error)

AddXP adds XP to the current pet

func GetCurrentPet

func GetCurrentPet() (*PetInstance, error)

GetCurrentPet returns the current pet instance

func Interact

func Interact(action string) (*PetInstance, error)

Interact handles user interaction (pet/feed)

func SelectPet

func SelectPet(petID string) (*PetInstance, error)

SelectPet creates or switches to a new pet

type PetStore

type PetStore struct {
	// contains filtered or unexported fields
}

PetStore handles persistence of pet and profile data

func GetStore

func GetStore() *PetStore

GetStore returns the global pet store singleton

func NewPetStore

func NewPetStore() *PetStore

NewPetStore creates a new pet store

func (*PetStore) AddXP

func (s *PetStore) AddXP(amount int) (*PetInstance, bool)

AddXP adds experience points and handles level ups Returns true if pet leveled up

func (*PetStore) CheckStreak

func (s *PetStore) CheckStreak()

CheckStreak checks and updates the daily streak

func (*PetStore) GetPet

func (s *PetStore) GetPet() *PetInstance

GetPet returns the current pet instance

func (*PetStore) GetProfile

func (s *PetStore) GetProfile() *PlayerProfile

GetProfile returns the player profile

func (*PetStore) IncrementCommands

func (s *PetStore) IncrementCommands()

IncrementCommands increments the total command count

func (*PetStore) Interact

func (s *PetStore) Interact(action string) *PetInstance

Interact handles user interactions (pet, feed)

func (*PetStore) Load

func (s *PetStore) Load()

Load reads pet and profile data from disk

func (*PetStore) Save

func (s *PetStore) Save() error

Save writes pet and profile data to disk

func (*PetStore) SelectPet

func (s *PetStore) SelectPet(petID string, name string) *PetInstance

SelectPet creates or switches to a new pet

func (*PetStore) SetCustomDialogues

func (s *PetStore) SetCustomDialogues(dialogues []CustomDialogue)

SetCustomDialogues saves custom dialogues

func (*PetStore) UpdateMood

func (s *PetStore) UpdateMood()

UpdateMood updates the pet's mood based on hunger, energy, and time

func (*PetStore) UpdatePlaytime

func (s *PetStore) UpdatePlaytime(seconds int64)

UpdatePlaytime adds elapsed seconds to total playtime

func (*PetStore) UpdateState

func (s *PetStore) UpdateState(state string)

UpdateState sets the pet's current state

type PlayerProfile

type PlayerProfile struct {
	ActivePetID     string           `json:"activePetId"`
	CompletedPets   []string         `json:"completedPets"`
	StreakDays      int              `json:"streakDays"`
	LastActiveDate  string           `json:"lastActiveDate"` // YYYY-MM-DD
	TotalFocusTime  int64            `json:"totalFocusTime"` // seconds
	TotalCommands   int              `json:"totalCommands"`
	Achievements    []string         `json:"achievements"`
	CustomDialogues []CustomDialogue `json:"customDialogues,omitempty"`
}

PlayerProfile — player progression data

func GetProfile

func GetProfile() (*PlayerProfile, error)

GetProfile returns the player profile

type SessionData

type SessionData struct {
	StartedAt        time.Time `json:"startedAt"`
	ActiveTime       int64     `json:"activeTime"` // seconds
	CommandCount     int       `json:"commandCount"`
	IdleSince        time.Time `json:"idleSince"`
	IsIdle           bool      `json:"isIdle"`
	CurrentProject   string    `json:"currentProject"`
	DiscordConnected bool      `json:"discordConnected"`
}

SessionData — current session (not persisted across restarts)

func GetSessionData

func GetSessionData() (*SessionData, error)

GetSessionData returns current session data

type SessionTracker

type SessionTracker struct {
	// contains filtered or unexported fields
}

SessionTracker tracks the current coding session

func GetSessionTracker

func GetSessionTracker() *SessionTracker

GetSession returns the global session tracker

func NewSessionTracker

func NewSessionTracker(store *PetStore) *SessionTracker

NewSessionTracker creates and starts a new session tracker

func (*SessionTracker) GetSession

func (st *SessionTracker) GetSession() SessionData

GetSession returns a copy of the current session data

func (*SessionTracker) OnActivity

func (st *SessionTracker) OnActivity()

OnActivity marks the session as active (user typed/interacted)

func (*SessionTracker) OnCommand

func (st *SessionTracker) OnCommand()

OnCommand is called when a terminal command is executed

func (*SessionTracker) SetDiscordConnected

func (st *SessionTracker) SetDiscordConnected(connected bool)

SetDiscordConnected updates the Discord connection status

func (*SessionTracker) SetProject

func (st *SessionTracker) SetProject(project string)

SetProject updates the current project name

func (*SessionTracker) Stop

func (st *SessionTracker) Stop()

Stop stops the session tracker

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL