life

package
v0.99.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package life is Flowbot's solo gamified productivity module.

Index

Constants

View Source
const Name = "life"

Name is the module registry key.

Variables

This section is empty.

Functions

func OnService

func OnService(fn func(*Service))

OnService registers a listener invoked whenever the Life service instance is assigned.

func ParseRewardCooldownHours

func ParseRewardCooldownHours(raw string) (int, error)

ParseRewardCooldownHours parses optional cooldown hours (empty → 0).

func ParseRewardPrice

func ParseRewardPrice(raw string) (int, error)

ParseRewardPrice parses a form price string into a positive int.

func Register

func Register()

Register registers the life module.

Types

type AchievementView

type AchievementView struct {
	Flag         string
	Name         string
	Description  string
	Unlocked     bool
	UnlockedAt   *time.Time
	ShowProgress bool
	Current      int
	Target       int
	Retired      bool
}

AchievementView is one memorial achievement row for the UI.

type ActionInput

type ActionInput struct {
	TaskType           string
	IsRepeatable       bool
	TrackingMode       string
	RepeatTrigger      string
	SuggestedCadence   string
	IsIdentityBuilding bool
	Reason             string
	Difficulty         string
	BaseExp            int
	BaseGold           int
	DependencyFlags    []string
}

ActionInput captures the structured fields used to classify an action node.

type ActionLogView

type ActionLogView struct {
	Flag       string
	SourceType string
	QuestFlag  string
	QuestTitle string
	GainedExp  int
	GainedGold int
	Dice       float64
	HasDice    bool
	Dropped    bool
	CreatedAt  time.Time
}

ActionLogView is one audit row for the UI.

type CharacterView

type CharacterView struct {
	Profile         *gen.LifeProfile
	Characteristics []*gen.LifeCharacteristic
	Skills          []*gen.LifeSkill
	Slots           *gen.LifeEquippedSlots
	Buffs           pkglife.BuffTotals
	Goals           []*gen.LifeGoal
	PlanTree        []*PlanNodeView
}

CharacterView is the character / identity aggregate (also feeds Goals, Plan, Quests).

type CompleteResult

type CompleteResult struct {
	Quest              *gen.LifeQuest
	GainedExp          int
	GainedGold         int
	Dropped            bool
	ItemName           string
	ItemFlag           string
	ItemRarity         string
	Dice               float64
	PityForced         bool
	NewlyUnlocked      []UnlockedAchievement
	ProfileLevelBefore int
	ProfileLevelAfter  int
	SkillName          string
	SkillLevelBefore   int
	SkillLevelAfter    int
}

CompleteResult is returned to the UI after completion.

type CreateRewardInput

type CreateRewardInput struct {
	Name          string
	Notes         string
	Price         int
	CooldownHours int
}

CreateRewardInput is the write-set for creating or updating a reward.

type GoalView

type GoalView struct {
	Flag      string
	Title     string
	Category  string
	Status    string
	AreaFlag  string
	AreaTitle string
}

GoalView is a UI-ready goal row with optional Area parent labels resolved.

func MapGoalViews

func MapGoalViews(goals []*gen.LifeGoal) []GoalView

MapGoalViews maps goal entities to view rows, resolving Area parents within the slice.

type InventoryItem

type InventoryItem struct {
	Inv   *gen.LifeInventory
	Equip *gen.LifeEquipment
}

InventoryItem pairs inventory with equipment template.

type InventoryPage

type InventoryPage struct {
	Items    []InventoryItem
	Equipped []InventoryItem
	Slots    *gen.LifeEquippedSlots
	Total    int
}

InventoryPage is one backpack page plus currently equipped items for the board.

type PlanNodeView

type PlanNodeView struct {
	Node     *gen.LifePlanNode
	Action   *gen.LifeActionSpec
	Children []*PlanNodeView
}

PlanNodeView is one rendered tree node with optional action metadata.

type QuestAdjudicationView

type QuestAdjudicationView struct {
	Flag               string
	Status             string
	Verdict            string
	Reason             string
	SuggestedExp       int
	SuggestedGold      int
	SuggestedNextSteps []string
	CreatedAt          time.Time
}

QuestAdjudicationView is the latest AI ruling for one quest.

type QuestDMView

type QuestDMView struct {
	Quest        *gen.LifeQuest
	Evidence     []QuestEvidenceView
	Adjudication *QuestAdjudicationView
	DropChance   float64
}

QuestDMView bundles a pending quest with its evidence and latest ruling.

type QuestEvidenceView

type QuestEvidenceView struct {
	Flag       string
	SourceType string
	Content    string
	SourceURL  string
	Summary    string
	CreatedAt  time.Time
}

QuestEvidenceView is one quest evidence item for the UI.

type RedemptionView

type RedemptionView struct {
	Flag       string
	RewardName string
	PricePaid  int
	RedeemedAt string
}

RedemptionView is one redemption history row for the Rewards UI.

type RewardView

type RewardView struct {
	Flag           string
	Name           string
	Notes          string
	Price          int
	CooldownHours  int
	Active         bool
	OnCooldown     bool
	CooldownEndsAt string
	CanAfford      bool
	LastRedeemedAt string
}

RewardView is one catalog reward for the Rewards UI.

type RewardsPage

type RewardsPage struct {
	Gold             int
	Active           []RewardView
	Inactive         []RewardView
	Redemptions      []RedemptionView
	InactiveTotal    int
	RedemptionsTotal int
}

RewardsPage is the full Rewards page model.

type Service

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

Service orchestrates Life use cases for the web UI.

func ActiveService

func ActiveService() *Service

ActiveService returns the module service for web injection.

func NewService

func NewService(ls *store.LifeStore) *Service

NewService constructs a Life service.

func (*Service) AdjudicateQuest

func (s *Service) AdjudicateQuest(ctx context.Context, userID, questFlag string) (*QuestAdjudicationView, error)

AdjudicateQuest asks the Life DM for a suggested quest ruling.

func (*Service) ApplyQuestAdjudication

func (s *Service) ApplyQuestAdjudication(ctx context.Context, userID, questFlag, adjudicationFlag string) error

ApplyQuestAdjudication accepts a suggested ruling and applies its effect.

func (*Service) BuildSkillTree

func (s *Service) BuildSkillTree(ctx context.Context, userID string) (*SkillTreeView, error)

BuildSkillTree builds the read-only controlled skill tree for the Life UI.

func (*Service) CheckInHabit

func (s *Service) CheckInHabit(ctx context.Context, userID, nodeFlag string, at time.Time) error

CheckInHabit writes one daily habit check-in.

func (*Service) CompleteActionOccurrence

func (s *Service) CompleteActionOccurrence(ctx context.Context, userID, occurrenceFlag string) error

CompleteActionOccurrence marks an execution occurrence completed and grants rewards.

func (*Service) CompleteQuest

func (s *Service) CompleteQuest(ctx context.Context, userID, questFlag string) (*CompleteResult, error)

CompleteQuest runs cascade + loot + action log in one store transaction.

func (*Service) ConfirmHabitAction

func (s *Service) ConfirmHabitAction(ctx context.Context, userID, nodeFlag string) error

ConfirmHabitAction marks a habit candidate as confirmed.

func (*Service) CreateGoal

func (s *Service) CreateGoal(ctx context.Context, userID, title, category, areaFlag string) (*gen.LifeGoal, error)

CreateGoal creates an Active PARA goal. areaFlag optionally links Project/Resource to an Active Area.

func (*Service) CreatePlanNode

func (s *Service) CreatePlanNode(ctx context.Context, userID, parentFlag, nodeType, title, description string, action *ActionInput) (*PlanNodeView, error)

CreatePlanNode creates one plan node under an optional parent.

func (*Service) CreateQuestFromPrompt

func (s *Service) CreateQuestFromPrompt(ctx context.Context, userID, prompt, goalFlag string) (*gen.LifeQuest, *lifecap.QuestEvaluation, float64, error)

CreateQuestFromPrompt evaluates and persists a quest. goalFlag is optional; when set, the quest is linked to that active goal.

func (*Service) CreateReward

func (s *Service) CreateReward(ctx context.Context, userID string, in CreateRewardInput) (*gen.LifeReward, error)

CreateReward creates a player-defined reward.

func (*Service) DeactivateReward

func (s *Service) DeactivateReward(ctx context.Context, userID, rewardFlag string) error

DeactivateReward soft-deletes a reward (active=false).

func (*Service) DeleteGoal

func (s *Service) DeleteGoal(ctx context.Context, userID, goalFlag string) error

DeleteGoal removes a goal by flag. Deleting an Area clears child area_id links first.

func (*Service) DismissQuest

func (s *Service) DismissQuest(ctx context.Context, userID, questFlag string) error

DismissQuest removes a pending quest without rust or completion-rate penalty.

func (*Service) EnsureProfile

func (s *Service) EnsureProfile(ctx context.Context, userID, nickname, defaultClass string) (*gen.LifeProfile, error)

EnsureProfile creates the profile graph for a user if needed.

func (*Service) Equip

func (s *Service) Equip(ctx context.Context, userID, inventoryFlag string) error

Equip wears an inventory item into its slot.

func (*Service) FailQuest

func (s *Service) FailQuest(ctx context.Context, userID, questFlag string) error

FailQuest marks a pending quest failed and applies 24h equipment rust.

func (*Service) GetCharacter

func (s *Service) GetCharacter(ctx context.Context, userID string) (*CharacterView, error)

GetCharacter loads character aggregates.

func (*Service) GetStatsPage

func (s *Service) GetStatsPage(ctx context.Context, userID, timezoneName string) (*pkglife.StatsPage, error)

GetStatsPage builds the Life stats dashboard for the given IANA timezone. Invalid or empty timezoneName falls back to UTC.

func (*Service) ImportGoalBreakdown

func (s *Service) ImportGoalBreakdown(ctx context.Context, userID string, suggestion *lifecap.GoalBreakdownSuggestion) error

ImportGoalBreakdown persists a suggestion tree as plan nodes.

func (*Service) ListAchievements

func (s *Service) ListAchievements(ctx context.Context, userID string) ([]AchievementView, error)

ListAchievements returns catalog rows with progress and unlock state for the user.

func (*Service) ListActionLogs

func (s *Service) ListActionLogs(ctx context.Context, userID string, limit int) ([]ActionLogView, error)

ListActionLogs returns recent completion audit rows for the user.

func (*Service) ListActionLogsPage

func (s *Service) ListActionLogsPage(ctx context.Context, userID string, page, perPage int) ([]ActionLogView, int, error)

ListActionLogsPage returns one page of completion audit rows and the total count.

func (*Service) ListCompletedQuestsPage

func (s *Service) ListCompletedQuestsPage(ctx context.Context, userID string, page, perPage int) ([]*gen.LifeQuest, int, error)

ListCompletedQuestsPage returns one page of completed quests and the total count.

func (*Service) ListHabitCheckins

func (s *Service) ListHabitCheckins(ctx context.Context, userID, nodeFlag string, from, to time.Time) ([]*gen.LifeHabitCheckin, error)

ListHabitCheckins returns check-ins in a date range.

func (*Service) ListInventory

func (s *Service) ListInventory(ctx context.Context, userID string) ([]InventoryItem, *gen.LifeEquippedSlots, error)

ListInventory returns inventory with templates.

func (*Service) ListInventoryPage

func (s *Service) ListInventoryPage(ctx context.Context, userID string, page, perPage int) (*InventoryPage, error)

ListInventoryPage returns one backpack page, equipped items, slots, and total count. A non-positive perPage returns the full backpack on page 1.

func (*Service) ListPendingQuestDMViews

func (s *Service) ListPendingQuestDMViews(ctx context.Context, userID string) ([]QuestDMView, error)

ListPendingQuestDMViews returns pending quests with evidence and latest rulings.

func (*Service) ListPlanTree

func (s *Service) ListPlanTree(ctx context.Context, userID string) ([]*PlanNodeView, error)

ListPlanTree returns the profile planning tree.

func (*Service) ListQuests

func (s *Service) ListQuests(ctx context.Context, userID, status string) ([]*gen.LifeQuest, error)

ListQuests lists quests for the user.

func (*Service) ListRewardsPage

func (s *Service) ListRewardsPage(ctx context.Context, userID string, redemptionsPage, inactivePage, perPage int) (*RewardsPage, error)

ListRewardsPage returns gold, active rewards, and paged inactive/redemption lists.

func (*Service) ListTodayActions

func (s *Service) ListTodayActions(ctx context.Context, userID string) (*TodayBoardView, error)

ListTodayActions syncs recurring actions and returns today's action/habit board.

func (*Service) PreviewDropChance

func (s *Service) PreviewDropChance(ctx context.Context, userID, questFlag string) (float64, error)

PreviewDropChance returns the effective drop chance for a pending quest.

func (*Service) PreviewGoalBreakdown

func (s *Service) PreviewGoalBreakdown(ctx context.Context, userID, rootTitle, description string) (*lifecap.GoalBreakdownSuggestion, error)

PreviewGoalBreakdown asks the life capability for a suggested tree.

func (*Service) ProcessPendingLore

func (s *Service) ProcessPendingLore(ctx context.Context) (int, error)

ProcessPendingLore consumes lore outbox rows.

func (*Service) RedeemReward

func (s *Service) RedeemReward(ctx context.Context, userID, rewardFlag string) error

RedeemReward deducts gold and records a redemption in one transaction.

func (*Service) RestoreReward

func (s *Service) RestoreReward(ctx context.Context, userID, rewardFlag string) error

RestoreReward reactivates a soft-deleted reward.

func (*Service) SetClassType

func (s *Service) SetClassType(ctx context.Context, userID, classType string) error

SetClassType updates class.

func (*Service) SetGoalStatus

func (s *Service) SetGoalStatus(ctx context.Context, userID, goalFlag, status string) error

SetGoalStatus updates a goal status by flag.

func (*Service) SkipActionOccurrence

func (s *Service) SkipActionOccurrence(ctx context.Context, userID, occurrenceFlag string) error

SkipActionOccurrence marks a pending occurrence skipped.

func (*Service) SubmitQuestEvidence

func (s *Service) SubmitQuestEvidence(ctx context.Context, userID, questFlag, sourceType, content, sourceURL string) (*QuestEvidenceView, error)

SubmitQuestEvidence stores a new evidence item for a pending quest.

func (*Service) Unequip

func (s *Service) Unequip(ctx context.Context, userID, slotField string) error

Unequip clears a named slot field.

func (*Service) UpdateGoal

func (s *Service) UpdateGoal(ctx context.Context, userID, goalFlag, title, category, areaFlag string) error

UpdateGoal updates title, category, and optional Area parent for a goal by flag.

func (*Service) UpdateReward

func (s *Service) UpdateReward(ctx context.Context, userID, rewardFlag string, in CreateRewardInput) error

UpdateReward updates name/notes/price/cooldown for a reward by flag.

type SkillTreeEvidenceView

type SkillTreeEvidenceView struct {
	Title      string
	SourceType string
	Detail     string
	OccurredAt time.Time
	WindowDays int
}

SkillTreeEvidenceView is one recent practice record linked to a tree node.

type SkillTreeNodeView

type SkillTreeNodeView struct {
	Key            string
	Title          string
	Subtitle       string
	Characteristic string
	Children       []*SkillTreeNodeView
	PracticeCount  int
	SkillCount     int
	LastActivityAt *time.Time
	Status         string
	Evidence       []SkillTreeEvidenceView
	// contains filtered or unexported fields
}

SkillTreeNodeView is one node in the controlled skills tree.

type SkillTreeView

type SkillTreeView struct {
	Roots            []*SkillTreeNodeView
	DefaultSelected  string
	ActiveNodeCount  int
	TrackedNodeCount int
}

SkillTreeView is the aggregated skills page model.

type TodayActionView

type TodayActionView struct {
	Occurrence *gen.LifeActionOccurrence
	Node       *gen.LifePlanNode
	Spec       *gen.LifeActionSpec
}

TodayActionView is one pending action occurrence with definition metadata.

type TodayBoardView

type TodayBoardView struct {
	Actions []TodayActionView
	Habits  []TodayHabitView
}

TodayBoardView is the execution board rendered on the quests page.

type TodayHabitView

type TodayHabitView struct {
	Node      *gen.LifePlanNode
	Spec      *gen.LifeActionSpec
	Checkin   *gen.LifeHabitCheckin
	CheckedIn bool
}

TodayHabitView is one habit plus today's check-in state.

type UnlockedAchievement

type UnlockedAchievement struct {
	Flag string
	Name string
}

UnlockedAchievement is one memorial unlock surfaced to the UI.

Jump to

Keyboard shortcuts

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