pets

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenPetName    = `{petname}`
	TokenDamage     = `{damage}`
	TokenTargetName = `{targetname}`
)

Variables

This section is empty.

Functions

func CreatePetSpec added in v0.9.8

func CreatePetSpec(p *Pet) error

CreatePetSpec registers a new pet type. Returns an error if the type already exists.

func DeletePetSpec added in v0.9.8

func DeletePetSpec(petType string) error

DeletePetSpec removes a pet type from disk and the in-memory cache.

func GetAllPetSpecs added in v0.9.8

func GetAllPetSpecs() map[string]Pet

GetAllPetSpecs returns a copy of every loaded pet type keyed by type ID.

func GetMemoryUsage added in v0.9.8

func GetMemoryUsage() map[string]util.MemoryResult

func LoadDataFiles

func LoadDataFiles()

file self loads due to init()

func SavePetScript added in v0.9.8

func SavePetScript(petType string, content string) error

SavePetScript writes (or removes) the JavaScript script file for a pet type.

func SavePetSpec added in v0.9.8

func SavePetSpec(p *Pet) error

SavePetSpec validates, persists a pet spec to disk, and updates the in-memory cache.

Types

type AbilityDisplay added in v0.9.8

type AbilityDisplay struct {
	LevelGranted int
	Active       bool
	CombatChance int
	DiceRoll     string
	DiceCount    int
	SideCount    int
	StatMods     map[string]int
	BuffNames    []string
	Capacity     int
}

type CombatMessages added in v0.9.8

type CombatMessages struct {
	// ToOwner is sent to the player who owns the pet.
	ToOwner string `yaml:"toowner,omitempty" json:"toowner,omitempty"`
	// ToTarget is sent to the player being attacked (if the target is a player).
	ToTarget string `yaml:"totarget,omitempty" json:"totarget,omitempty"`
	// ToRoom is sent to everyone else in the room observing the attack.
	ToRoom string `yaml:"toroom,omitempty" json:"toroom,omitempty"`
	// Miss is sent to the pet owner when the pet's attack misses.
	Miss string `yaml:"miss,omitempty" json:"miss,omitempty"`
}

CombatMessages holds optional custom attack message templates for a pet. Each field is a Go text/template-style string supporting the tokens:

{petname}    - replaced with the pet's display name (may contain ANSI tags)
{damage}     - replaced with the integer damage dealt (plain text)
{targetname} - replaced with the target's formatted name (may contain ANSI tags)

All four fields are optional. When a field is empty the combat system falls back to the built-in default message for that slot.

func DefaultCombatMessages added in v0.9.8

func DefaultCombatMessages(targetType string) CombatMessages

DefaultCombatMessages returns the built-in fallback messages used when a pet type does not define its own. targetType is the ANSI fg colour prefix for the target (e.g. "mob" or "user").

func (CombatMessages) ApplyTokens added in v0.9.8

func (cm CombatMessages) ApplyTokens(s, petName string, damage int, targetName string) string

ApplyTokens replaces all recognised tokens in s and returns the result. petName and targetName may contain ANSI markup; damage is plain text.

func (CombatMessages) IsEmpty added in v0.9.8

func (cm CombatMessages) IsEmpty() bool

IsEmpty returns true when no custom messages are defined.

type Food

type Food int

func (*Food) Add

func (f *Food) Add()

func (*Food) Remove

func (f *Food) Remove()

func (Food) String

func (f Food) String() string

type Pet

type Pet struct {
	Name             string       `yaml:"name,omitempty"`             // Name of the pet (player provided hopefully)
	NameStyle        string       `yaml:"namestyle,omitempty"`        // Optional color pattern to apply
	Type             string       `yaml:"type"`                       // type of pet
	RoundActChance   int          `yaml:"roundactchance,omitempty"`   // 0-100 chance per round to fire PetAct script
	Food             Food         `yaml:"food,omitempty"`             // how much food the pet has
	Level            int          `yaml:"level,omitempty"`            // Pet level (1-10)
	LastMealRound    uint8        `yaml:"lastmealround,omitempty"`    // When the pet was last fed
	LastLevelCheck   string       `yaml:"lastlevelcheck,omitempty"`   // "{year}.{day}" of last daily tick
	Abilities        []PetAbility `yaml:"abilities,omitempty"`        // Refreshed from definition file on Validate()
	Items            []items.Item `yaml:"items,omitempty"`            // Items held by this pet
	MissingCountdown int          `yaml:"missingcountdown,omitempty"` // When non-zero, pet is absent
	// contains filtered or unexported fields
}

func GetPetCopy

func GetPetCopy(petId string) Pet

func (*Pet) CheckDailyTick added in v0.9.8

func (p *Pet) CheckDailyTick() (int, bool)

CheckDailyTick returns (levelChange, needsValidate) if a new day has passed. Returns (0, false) if no tick is needed.

func (*Pet) DailyLevelCheck added in v0.9.8

func (p *Pet) DailyLevelCheck() int

func (*Pet) DecrementMissing added in v0.9.8

func (p *Pet) DecrementMissing() bool

DecrementMissing decrements the missing countdown by one. Returns true if the countdown just reached zero (pet is returning this round).

func (*Pet) DisplayName

func (p *Pet) DisplayName() string

func (*Pet) Exists

func (p *Pet) Exists() bool

func (*Pet) Filename

func (p *Pet) Filename() string

func (*Pet) Filepath

func (p *Pet) Filepath() string

func (*Pet) FindItem

func (p *Pet) FindItem(itemName string) (items.Item, bool)

func (*Pet) GetAbilityDisplays added in v0.9.8

func (p *Pet) GetAbilityDisplays() []AbilityDisplay

func (*Pet) GetBuffs

func (p *Pet) GetBuffs() []int

func (*Pet) GetCombatMessages added in v0.9.8

func (p *Pet) GetCombatMessages(targetType string) CombatMessages

GetCombatMessages returns the effective combat messages for the current ability level. Any empty slot in the ability's AttackMessages is filled in from the built-in defaults. targetType is the ANSI fg colour prefix (e.g. "mob" or "user") used when building the default fallback strings.

func (*Pet) GetCurrentAbility added in v0.9.8

func (p *Pet) GetCurrentAbility() *PetAbility

func (*Pet) GetCurrentAbilityDisplay added in v0.9.8

func (p *Pet) GetCurrentAbilityDisplay() *AbilityDisplay

func (*Pet) GetCurrentDayKey added in v0.9.8

func (p *Pet) GetCurrentDayKey() string

func (*Pet) GetDiceRoll

func (p *Pet) GetDiceRoll() (attacks int, dCount int, dSides int, bonus int, buffOnCrit []int)

func (*Pet) GetEffectiveBuffs added in v0.9.8

func (p *Pet) GetEffectiveBuffs() []int

func (*Pet) GetEffectiveCapacity added in v0.9.8

func (p *Pet) GetEffectiveCapacity() int

func (*Pet) GetEffectiveDamage added in v0.9.8

func (p *Pet) GetEffectiveDamage() (int, items.Damage)

func (*Pet) GetEffectiveStatMods added in v0.9.8

func (p *Pet) GetEffectiveStatMods() statmods.StatMods

func (*Pet) GetScript added in v0.9.8

func (p *Pet) GetScript() string

func (*Pet) GetScriptPath added in v0.9.8

func (p *Pet) GetScriptPath() string

func (*Pet) GoMissing added in v0.9.8

func (p *Pet) GoMissing(rounds int)

GoMissing sets the missing countdown to the given number of rounds. A value of zero clears the missing state immediately.

func (*Pet) HasScript added in v0.9.8

func (p *Pet) HasScript() bool

func (*Pet) Id

func (p *Pet) Id() string

func (*Pet) IsMissing added in v0.9.8

func (p *Pet) IsMissing() bool

IsMissing returns true when the pet is temporarily absent.

func (*Pet) LevelChange added in v0.9.8

func (p *Pet) LevelChange(delta int) (oldLevel int, newLevel int, changed bool)

func (*Pet) RemoveItem

func (p *Pet) RemoveItem(i items.Item) bool

func (*Pet) Save

func (p *Pet) Save() error

func (*Pet) StatMod

func (p *Pet) StatMod(statName string) int

func (*Pet) StoreItem

func (p *Pet) StoreItem(i items.Item) bool

func (*Pet) Validate

func (p *Pet) Validate() error

type PetAbility added in v0.9.8

type PetAbility struct {
	LevelGranted   int               `yaml:"levelgranted,omitempty"`
	CombatChance   int               `yaml:"combatchance,omitempty"` // odds (out of 100) that it will join in this round of combat
	Damage         items.Damage      `yaml:"damage,omitempty"`
	AttackMessages CombatMessages    `yaml:"attackmessages,omitempty"` // Optional custom combat messages for this ability level
	StatMods       statmods.StatMods `yaml:"statmods,omitempty"`
	BuffIds        []int             `yaml:"buffids,omitempty"`
	Capacity       int               `yaml:"capacity,omitempty"`
}

Jump to

Keyboard shortcuts

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