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: 6 Imported by: 0

Documentation

Overview

Package life provides pure formulas for Flowbot Life (cascade, loot, buffs, achievements).

Index

Constants

View Source
const (
	// AchievementKindFirst is a one-shot memorial (threshold treated as 1).
	AchievementKindFirst = "first"
	// AchievementKindCount is a cumulative memorial with visible progress.
	AchievementKindCount = "count"
)
View Source
const (
	GoalCategoryProject  = "Project"
	GoalCategoryArea     = "Area"
	GoalCategoryResource = "Resource"
)

PARA goal categories (life_goals.category).

View Source
const (
	GoalStatusActive    = "Active"
	GoalStatusPaused    = "Paused"
	GoalStatusCompleted = "Completed"
)

Goal lifecycle statuses (life_goals.status).

View Source
const (
	// SoftHPMax is the soft HP ceiling used by the character HUD.
	SoftHPMax = 1000
	// SoftHPHeartCount is how many heart segments the HUD shows.
	SoftHPHeartCount = 10
)
View Source
const DefaultPityThreshold = 10

DefaultPityThreshold is the miss count that forces a drop.

View Source
const RustDuration = 24 * time.Hour

RustDuration is how long equipped gear stays tarnished after a failed quest.

View Source
const StatsOtherBucket = "Other"

StatsOtherBucket is the growth chart label for unattributed EXP.

View Source
const StatsWindowDays = 30

StatsWindowDays is the fixed analytics window length.

Variables

View Source
var DefaultCharacteristics = []struct {
	Code string
	Name string
}{
	{Code: "INT", Name: "Intelligence"},
	{Code: "PHY", Name: "Physique"},
	{Code: "WIL", Name: "Willpower"},
	{Code: "CHA", Name: "Charisma"},
	{Code: "CRE", Name: "Creativity"},
	{Code: "FIN", Name: "Financial"},
	{Code: "WRI", Name: "Writing"},
	{Code: "FOC", Name: "Focus"},
}

DefaultCharacteristics are seeded on EnsureProfile (and backfilled for older profiles).

Functions

func AchievementConditionKey

func AchievementConditionKey(questType, difficulty string) string

AchievementConditionKey builds the progress key for optional type/difficulty filters. Empty questType or difficulty means "any" (*).

func AchievementKeysForCompletion

func AchievementKeysForCompletion(questType, difficulty string) []string

AchievementKeysForCompletion returns every progress key bumped by one quest completion.

func AchievementShowsProgress

func AchievementShowsProgress(def AchievementDef) bool

AchievementShowsProgress reports whether the UI should show N/M for this definition.

func BlendCompletionRate

func BlendCompletionRate(rate float64, success bool) float64

BlendCompletionRate applies a 90/10 exponential blend after a quest outcome.

func DefaultRewards

func DefaultRewards(diff string) (fear, exp, gold int, tier string)

DefaultRewards returns fear, exp, gold, and drop tier for a difficulty code. Everyday tiers (E–S) grow ~1.5x with gold near exp/3; SS/SSS jump harder for boss-tier payoff (C still anchors ~4 completions to ExpToNextLevel(1)=100).

func ExpToNextLevel

func ExpToNextLevel(level int) int64

ExpToNextLevel returns exp required to advance from the given level.

func IsTarnished

func IsTarnished(until *time.Time, now time.Time) bool

IsTarnished reports whether rust is still active at now.

func MergeBuffs

func MergeBuffs(template, instance map[string]any) map[string]float64

MergeBuffs merges template and instance buff maps (instance wins on key clash).

func NeedsInstanceLore

func NeedsInstanceLore(questType, difficulty string) bool

NeedsInstanceLore reports whether a drop should enqueue memorial lore generation.

func NormalizeDifficulty

func NormalizeDifficulty(raw string) string

NormalizeDifficulty coerces a raw difficulty label to a known tier.

func PreviewDropChance

func PreviewDropChance(in LootInput) float64

PreviewDropChance returns the effective drop threshold without rolling.

func RewardCooldownEndsAt

func RewardCooldownEndsAt(lastRedeemed *time.Time, cooldownHours int, now time.Time) *time.Time

RewardCooldownEndsAt returns when the cooldown expires, or nil if not on cooldown.

func RewardOnCooldown

func RewardOnCooldown(lastRedeemed *time.Time, cooldownHours int, now time.Time) bool

RewardOnCooldown reports whether a reward cannot be redeemed yet. cooldownHours <= 0 or a nil lastRedeemed means not on cooldown.

func RollUnit

func RollUnit() (float64, error)

RollUnit returns a cryptographically strong unit interval in [0,1).

func SkillTreeWindowDays

func SkillTreeWindowDays(cadence string) int

SkillTreeWindowDays maps a cadence hint to an activity window length in days.

func SlotField

func SlotField(slotType string) string

SlotField maps slot_type to equipped_slots column name.

func SoftHPFromWillpower

func SoftHPFromWillpower(wilLevel int, wilExp, wilNeed int64, profileLevel int) (current, maxHP int)

SoftHPFromWillpower derives a soft HP pool from Willpower (or profile level fallback).

func SourceTypeLabel

func SourceTypeLabel(sourceType string) string

SourceTypeLabel returns a concise label for one audit / skill-tree source.

func StatsWindowBounds

func StatsWindowBounds(now time.Time, loc *time.Location, days int) (start, endExclusive time.Time)

StatsWindowBounds returns [start, endExclusive) for the last days calendar days in loc, ending at the start of tomorrow relative to now.

func TaskTypeLabel

func TaskTypeLabel(taskType string) string

TaskTypeLabel returns a concise label for one plan action type.

Types

type AchievementDef

type AchievementDef struct {
	Flag        string
	Name        string
	Description string
	Active      bool
	Kind        string
	QuestType   string
	Difficulty  string
	Threshold   int
	SortOrder   int
}

AchievementDef is one catalog achievement definition (pure data).

type AchievementEvalInput

type AchievementEvalInput struct {
	QuestType  string
	Difficulty string
	Catalog    []AchievementDef
	Progress   map[string]int
	Unlocked   map[string]struct{}
}

AchievementEvalInput is the pure input for evaluating unlocks after a quest completion.

type AchievementEvalResult

type AchievementEvalResult struct {
	ProgressAfter map[string]int
	NewlyUnlocked []AchievementDef
}

AchievementEvalResult is the progress deltas and newly unlocked definitions.

func EvaluateAchievements

func EvaluateAchievements(in AchievementEvalInput) AchievementEvalResult

EvaluateAchievements bumps matching condition keys and returns new unlocks.

type BuffTotals

type BuffTotals struct {
	Stats    map[string]float64
	DropRate float64
	GoldMult float64
}

BuffTotals aggregates equipped item buffs.

func SumEquippedBuffs

func SumEquippedBuffs(items []map[string]float64) BuffTotals

SumEquippedBuffs sums float buffs from multiple items.

type CascadeInput

type CascadeInput struct {
	BaseExp                  int
	BaseGold                 int
	Skill                    StatSnapshot
	Characteristic           StatSnapshot
	Profile                  StatSnapshot
	ProfileGold              int
	ExpToCharacteristicRatio float64
}

CascadeInput is the reward applied when a quest completes.

type CascadeResult

type CascadeResult struct {
	Skill          StatSnapshot
	Characteristic StatSnapshot
	Profile        StatSnapshot
	ProfileGold    int
	GainedExp      int
	GainedGold     int
}

CascadeResult is the post-cascade state and gained totals.

func ApplyCascade

func ApplyCascade(in CascadeInput) CascadeResult

ApplyCascade distributes quest rewards into skill, characteristic, and profile snapshots.

type LootInput

type LootInput struct {
	BaseDropChance   float64
	ProfileBonus     float64
	EquippedDropRate float64
	PityCount        int
	PityThreshold    int
	Roll             float64 // [0,1); if < 0, caller should set via RollUnit
	PoolSize         int
}

LootInput drives a single drop roll.

type LootResult

type LootResult struct {
	Dropped    bool
	ForcedPity bool
	Roll       float64
	Threshold  float64
	PoolIndex  int
	NextPity   int
}

LootResult is the outcome of a loot roll.

func ResolveLoot

func ResolveLoot(in LootInput) LootResult

ResolveLoot decides whether an item drops and which pool index.

type StatSnapshot

type StatSnapshot struct {
	Level      int
	CurrentExp int64
}

StatSnapshot is mutable progress for cascade application.

type StatsActionEvent

type StatsActionEvent struct {
	At                 time.Time
	GainedExp          int
	GainedGold         int
	Dropped            bool
	CharacteristicCode string // empty → Other
}

StatsActionEvent is one action-log row for stats aggregation.

type StatsInput

type StatsInput struct {
	Actions      []StatsActionEvent
	Quests       []StatsQuestCompletion
	Redemptions  []StatsRedemptionEvent
	Unlocks      []StatsUnlockEvent
	Location     *time.Location
	Now          time.Time
	TimezoneName string
}

StatsInput is the raw event set for BuildStatsPage.

type StatsPage

type StatsPage struct {
	Timezone           string
	DayLabels          []string
	Completions        int
	TotalExp           int
	GoldInTotal        int
	GoldOutTotal       int
	GoldNet            int
	ActivityCounts     []int
	ActivityExp        []int
	GrowthLabels       []string
	GrowthValues       []int
	QuestTypeLabels    []string
	QuestTypeValues    []int
	GoldIn             []int
	GoldOut            []int
	Drops              []int
	AchievementUnlocks int
	HasActivity        bool
	WindowStart        time.Time
	WindowEndExclusive time.Time
}

StatsPage is the aggregated Life stats dashboard model.

func BuildStatsPage

func BuildStatsPage(in StatsInput) StatsPage

BuildStatsPage aggregates action / quest / redemption / unlock events into chart series.

type StatsQuestCompletion

type StatsQuestCompletion struct {
	CompletedAt time.Time
	Type        string
}

StatsQuestCompletion is one completed quest for type breakdown.

type StatsRedemptionEvent

type StatsRedemptionEvent struct {
	At        time.Time
	PricePaid int
}

StatsRedemptionEvent is one reward redemption for gold outflow.

type StatsUnlockEvent

type StatsUnlockEvent struct {
	At time.Time
}

StatsUnlockEvent is one achievement unlock in the window.

Jump to

Keyboard shortcuts

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