structs

package
v0.0.0-...-5abb9c5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Code generated by generator, DO NOT EDIT.

Index

Constants

View Source
const (
	WoundLevelLight    int32 = iota // Light scratch, minimal bleeding
	WoundLevelModerate              // Moderate wound, steady bleeding
	WoundLevelHeavy                 // Heavy wound, serious bleeding
	WoundLevelCritical              // Critical wound, life-threatening bleeding
)

WoundLevel constants define bleeding severity.

View Source
const MinValue = 1e-9

MinValue is the floor value for skill rolls to prevent -Inf and division by zero.

Variables

This section is empty.

Functions

func Clone

func Clone[T any, S Serializable[T]](t *T) (*T, error)

func DefaultBodyConfigs

func DefaultBodyConfigs() map[string]BodyConfig

DefaultBodyConfigs returns the built-in body configurations.

func DefaultDamageTypes

func DefaultDamageTypes() map[string]DamageTypeConfig

DefaultDamageTypes returns the built-in damage type configurations.

func SkillsKey

func SkillsKey(skills map[string]bool) string

SkillsKey returns a canonical string key for a set of skills. Skills are sorted alphabetically and comma-joined (e.g., "awareness,senses"). Used for looking up ChallengeDurations and seeding deterministic RNG.

func UpdateState

func UpdateState[T any](obj *Object, update func(*T) error) error

UpdateState atomically reads, modifies, and writes the object's state as a typed value. The state is deserialized into T, passed to the update function, and serialized back. The object is locked during the entire operation.

func WithLock

func WithLock(f func() error, objs ...*Object) error

WithLock locks the given objects in consistent order, runs f, then unlocks.

Types

type AnyCall

type AnyCall struct {
	Name    string
	Tag     string
	Content any
}

func (*AnyCall) Call

func (a *AnyCall) Call() (*Call, error)

type AnyEvent

type AnyEvent struct {
	At     Timestamp
	Object string
	Caller Caller
	Key    string
}

func (*AnyEvent) Event

func (a *AnyEvent) Event() (*Event, error)

type BodyConfig

type BodyConfig struct {
	// Parts maps body part ID to its configuration.
	// Example: "head", "torso", "leftArm", "rightArm", "leftLeg", "rightLeg"
	Parts map[string]BodyPartConfig
}

BodyConfig defines a body type (humanoid, quadruped, etc.).

type BodyPartConfig

type BodyPartConfig struct {
	// HealthFraction is the fraction of the object's MaxHealth this part has.
	// Normalized at runtime so exact values don't matter, only ratios.
	// Example: torso=0.4, head=0.15, each arm=0.1, each leg=0.125
	HealthFraction float64

	// HitWeight determines how likely this part is to be hit.
	// Normalized at runtime. Severed parts are excluded from calculations.
	HitWeight float64

	// Vital means 0 health = unconscious, severed = death.
	// Typically true for head, torso.
	Vital bool

	// Central means severing produces "cut in half" message instead of "X cut off".
	// Typically true for torso.
	Central bool

	// SeverThreshold is the multiplier for severing check.
	// Severing occurs when: (overkill * damageType.SeverMult) > (partMaxHealth * SeverThreshold)
	// Higher = harder to sever. 0 = cannot be severed.
	SeverThreshold float64

	// CanBleed determines if wounds to this part cause bleeding.
	CanBleed bool

	// CanWield determines if this part can hold weapons/items.
	CanWield bool

	// CanWear determines if this part can wear armor/clothing.
	CanWear bool
}

BodyPartConfig defines the properties of a body part in a BodyConfig.

type BodyPartState

type BodyPartState struct {
	Health  float32
	Severed bool
}

Struct - BodyPartState

func (*BodyPartState) Marshal

func (bodyPartState *BodyPartState) Marshal(b []byte)

Marshal - BodyPartState

func (*BodyPartState) MarshalPlain

func (bodyPartState *BodyPartState) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - BodyPartState

func (*BodyPartState) Size

func (bodyPartState *BodyPartState) Size() int

Size - BodyPartState

func (*BodyPartState) SizePlain

func (bodyPartState *BodyPartState) SizePlain() (s int)

SizePlain - BodyPartState

func (*BodyPartState) Unmarshal

func (bodyPartState *BodyPartState) Unmarshal(b []byte) (err error)

Unmarshal - BodyPartState

func (*BodyPartState) UnmarshalPlain

func (bodyPartState *BodyPartState) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - BodyPartState

type Call

type Call struct {
	Name    string
	Message string
	Tag     string
}

Struct - Call

func (*Call) Call

func (c *Call) Call() (*Call, error)

func (*Call) Marshal

func (call *Call) Marshal(b []byte)

Marshal - Call

func (*Call) MarshalPlain

func (call *Call) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Call

func (*Call) Size

func (call *Call) Size() int

Size - Call

func (*Call) SizePlain

func (call *Call) SizePlain() (s int)

SizePlain - Call

func (*Call) Unmarshal

func (call *Call) Unmarshal(b []byte) (err error)

Unmarshal - Call

func (*Call) UnmarshalPlain

func (call *Call) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Call

type Caller

type Caller interface {
	Call() (*Call, error)
}

type Challenge

type Challenge struct {
	Skills  map[string]bool
	Level   float32
	Message string
}

Struct - Challenge

func (*Challenge) Check

func (c *Challenge) Check(ctx Context, challenger *Object, targetID string, rng *rand.Rand) float64

Check tests the challenger's skills against this challenge's difficulty. Returns positive for success (score = 10 * log10(yourRoll / challengeRoll)), negative for failure. Uses uniform roll comparison - both sides roll in [0, 10^(level/10)]. If rng is nil, generates one internally using multiSkillRng. If rng is provided, uses it (allows CheckWithDetails to continue the sequence for blame). Updates skill state (LastUsedAt, LastBase) and applies learning if enabled. IMPORTANT: Caller must hold write access to the challenger (modifies Skills).

func (*Challenge) CheckWithDetails

func (c *Challenge) CheckWithDetails(ctx Context, challenger *Object, targetID string) (float64, string)

CheckWithDetails is like Check but also returns the name of a blamed skill on failure. Blame is probabilistic, weighted by inverse effective level (weaker skills blamed more often).

func (*Challenge) HasChallenge

func (c *Challenge) HasChallenge() bool

HasChallenge returns true if the challenge has any skills defined.

func (*Challenge) Marshal

func (challenge *Challenge) Marshal(b []byte)

Marshal - Challenge

func (*Challenge) MarshalPlain

func (challenge *Challenge) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Challenge

func (Challenge) Merge

func (c Challenge) Merge(other Challenge) Challenge

Merge combines two challenges by unioning their Skills and adding their Levels. If c has no skills, returns other. If other has no skills, returns c.

func (*Challenge) Size

func (challenge *Challenge) Size() int

Size - Challenge

func (*Challenge) SizePlain

func (challenge *Challenge) SizePlain() (s int)

SizePlain - Challenge

func (*Challenge) Unmarshal

func (challenge *Challenge) Unmarshal(b []byte) (err error)

Unmarshal - Challenge

func (*Challenge) UnmarshalPlain

func (challenge *Challenge) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Challenge

type Content

type Content map[string]*Object

func (Content) Short

func (c Content) Short() []string

func (Content) Sorted

func (c Content) Sorted() iter.Seq2[string, *Object]

type Context

type Context interface {
	context.Context
	Now() time.Time // Game time (may differ from wall clock)
	ServerConfig() *ServerConfig
}

Context provides game-time and configuration access for skill operations. Game time pauses when the server is down, so skills don't decay/recharge during maintenance. The implementation lives in the game package.

type DamageResult

type DamageResult struct {
	// Died is true if central health reached 0.
	Died bool

	// Incapacitated is true if a vital body part reached 0 health.
	Incapacitated bool

	// Severance is non-nil if the body part was severed.
	Severance *Severance

	// WoundInflicted is the bleeding wound created by this damage (if any).
	// Nil if no wound was created (damage too low or damage type doesn't bleed).
	WoundInflicted *Wound
}

DamageResult describes the consequences of damage application. Only contains information the caller couldn't derive themselves.

type DamageTypeConfig

type DamageTypeConfig struct {
	// SeverMult is the multiplier for severing checks.
	// 0 = cannot sever (e.g., poison), higher = easier to sever.
	SeverMult float64

	// BleedingMult is the multiplier for bleeding checks.
	// 0 = cannot cause bleeding (e.g., fire cauterizes), higher = more bleeding.
	BleedingMult float64
}

DamageTypeConfig defines properties of a damage type.

type DeepNeighbourhood

type DeepNeighbourhood struct {
	Location   *Location
	Neighbours map[string]*Location
}

func (*DeepNeighbourhood) All

func (n *DeepNeighbourhood) All() iter.Seq[*Object]

func (*DeepNeighbourhood) Describe

func (n *DeepNeighbourhood) Describe() string

func (*DeepNeighbourhood) Detections

func (n *DeepNeighbourhood) Detections(ctx Context, target *Object) iter.Seq2[*Detection, error]

Detections yields all objects that can perceive the target, including via exits. Sensory events travel from source (n.Location) to observers in neighbours. TransmitChallenge on the source→neighbour exit is added to the target's description challenge. The perspective is set to the observer→source exit (or unknown if no return exit).

func (*DeepNeighbourhood) Filter

func (n *DeepNeighbourhood) Filter(ctx Context, viewer *Object) (*DeepNeighbourhood, error)

Filter returns a copy with only what the viewer can perceive.

func (*DeepNeighbourhood) Observers

func (n *DeepNeighbourhood) Observers(ctx Context, targetID string, baseChallenge Challenge) iter.Seq[*Observation]

Observers yields observations for all objects that can perceive targetID. For observers in the same location, Challenge = baseChallenge. For observers in neighbouring locations, Challenge = baseChallenge merged with exit.TransmitChallenge. Perspective indicates where the observation is from (here, via exit, or unknown).

type Description

type Description struct {
	MapIcon   int32
	Short     string
	Unique    bool
	Long      string
	Tags      []string
	Challenge Challenge
}

Struct - Description

func (*Description) Marshal

func (description *Description) Marshal(b []byte)

Marshal - Description

func (*Description) MarshalPlain

func (description *Description) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Description

func (*Description) Size

func (description *Description) Size() int

Size - Description

func (*Description) SizePlain

func (description *Description) SizePlain() (s int)

SizePlain - Description

func (*Description) Unmarshal

func (description *Description) Unmarshal(b []byte) (err error)

Unmarshal - Description

func (*Description) UnmarshalPlain

func (description *Description) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Description

type Descriptions

type Descriptions []Description

func (Descriptions) Detect

func (d Descriptions) Detect(ctx Context, viewer *Object, targetID string) []Description

Detect returns all descriptions the viewer can perceive. This includes descriptions with no challenge (always visible) and descriptions where the viewer overcomes the challenge. Returns nil if no descriptions are visible.

func (Descriptions) Long

func (d Descriptions) Long() string

Long returns the concatenated Long texts from all descriptions. Empty Long texts are skipped, and non-empty texts are separated by a space.

func (Descriptions) Matches

func (d Descriptions) Matches(pattern string) bool

type Detection

type Detection struct {
	Subject     *Object     // The observer
	Object      *Object     // What the observer perceives (filtered by challenges)
	Perspective Perspective // Where the event came from (observer's perspective)
}

type Event

type Event struct {
	At         uint64
	Object     string
	Call       Call
	Key        string
	IntervalID string
}

Struct - Event

func (*Event) CreateKey

func (e *Event) CreateKey()

CreateKey generates a unique, sortable key combining timestamp and counter.

func (*Event) Event

func (e *Event) Event() (*Event, error)

func (*Event) Marshal

func (event *Event) Marshal(b []byte)

Marshal - Event

func (*Event) MarshalPlain

func (event *Event) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Event

func (*Event) Size

func (event *Event) Size() int

Size - Event

func (*Event) SizePlain

func (event *Event) SizePlain() (s int)

SizePlain - Event

func (*Event) Unmarshal

func (event *Event) Unmarshal(b []byte) (err error)

Unmarshal - Event

func (*Event) UnmarshalPlain

func (event *Event) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Event

type Eventer

type Eventer interface {
	Event() (*Event, error)
}

type Exit

type Exit struct {
	Descriptions      []Description
	UseChallenge      Challenge
	TransmitChallenge Challenge
	Tags              []string
	Destination       string
}

Struct - Exit

func (*Exit) Marshal

func (exit *Exit) Marshal(b []byte)

Marshal - Exit

func (*Exit) MarshalPlain

func (exit *Exit) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Exit

func (*Exit) Name

func (e *Exit) Name() string

func (*Exit) Size

func (exit *Exit) Size() int

Size - Exit

func (*Exit) SizePlain

func (exit *Exit) SizePlain() (s int)

SizePlain - Exit

func (*Exit) Unmarshal

func (exit *Exit) Unmarshal(b []byte) (err error)

Unmarshal - Exit

func (*Exit) UnmarshalPlain

func (exit *Exit) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Exit

type Exits

type Exits []Exit

func (Exits) Short

func (e Exits) Short() string

type Interval

type Interval struct {
	ObjectID     string
	IntervalID   string
	IntervalMS   int64
	EventName    string
	EventData    string
	NextFireTime int64
}

Struct - Interval

func (*Interval) Marshal

func (interval *Interval) Marshal(b []byte)

Marshal - Interval

func (*Interval) MarshalPlain

func (interval *Interval) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Interval

func (*Interval) Size

func (interval *Interval) Size() int

Size - Interval

func (*Interval) SizePlain

func (interval *Interval) SizePlain() (s int)

SizePlain - Interval

func (*Interval) Unmarshal

func (interval *Interval) Unmarshal(b []byte) (err error)

Unmarshal - Interval

func (*Interval) UnmarshalPlain

func (interval *Interval) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Interval

type Location

type Location struct {
	Container *Object
	Content   Content
}

func (*Location) AddDescriptionChallenge

func (l *Location) AddDescriptionChallenge(added Challenge) (*Location, error)

func (*Location) All

func (l *Location) All() iter.Seq[*Object]

func (*Location) Describe

func (l *Location) Describe() string

func (*Location) Detections

func (l *Location) Detections(ctx Context, target *Object, perspective Perspective) iter.Seq2[*Detection, error]

Detections yields each object that can perceive the target and how it appears to them. The perspective describes where the event came from (from the observer's point of view). The target should have all challenges applied via AddDescriptionChallenges before calling. Typically this includes TransmitChallenges from exits when observing through an exit.

func (*Location) Filter

func (l *Location) Filter(ctx Context, viewer *Object) (*Location, error)

func (*Location) Identify

func (l *Location) Identify(s string) (*Object, error)

Identify finds an object by pattern match. Supports "N.pattern" to select Nth match.

func (*Location) Observers

func (l *Location) Observers(ctx Context, targetID string, challenge Challenge) iter.Seq[*Object]

Observers yields each object in the location that passes the given challenge. Objects with the same ID as targetID are excluded (you can't observe yourself).

type LocationEmit

type LocationEmit struct {
	Data        any
	Perspective Perspective
}

LocationEmit is the content of events emitted via emitToLocation. It wraps the original data with perspective information.

type Movement

type Movement struct {
	Verb   string
	Active bool
}

Struct - Movement

func (*Movement) Marshal

func (movement *Movement) Marshal(b []byte)

Marshal - Movement

func (*Movement) MarshalPlain

func (movement *Movement) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Movement

func (*Movement) Size

func (movement *Movement) Size() int

Size - Movement

func (*Movement) SizePlain

func (movement *Movement) SizePlain() (s int)

SizePlain - Movement

func (*Movement) Unmarshal

func (movement *Movement) Unmarshal(b []byte) (err error)

Unmarshal - Movement

func (*Movement) UnmarshalPlain

func (movement *Movement) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Movement

type Neighbourhood

type Neighbourhood struct {
	Location   *Object
	Neighbours map[string]*Object
}

func (*Neighbourhood) Describe

func (n *Neighbourhood) Describe() string

type Object

type Object struct {
	// Unsafe permits direct unsynchronized access to the underlying data.
	// Use Get*/Set* methods for thread-safe access, or Lock()/RLock() when accessing Unsafe directly.
	Unsafe     *ObjectDO
	PostUnlock PostUnlockObject `faker:"-" json:"-"`
	// contains filtered or unexported fields
}

func MakeObject

func MakeObject(ctx context.Context) (*Object, error)

func (*Object) AddDescriptionChallenge

func (o *Object) AddDescriptionChallenge(added Challenge) (*Object, error)

AddDescriptionChallenge returns a copy with added difficulty on all descriptions. The added challenge is merged into each description's existing challenge.

func (*Object) BodyPartsInitialized

func (o *Object) BodyPartsInitialized() bool

BodyPartsInitialized returns true if body parts have been initialized.

func (*Object) CanCombat

func (o *Object) CanCombat() bool

CanCombat returns true if the object can participate in combat. Combat requires BodyConfigID to be set and MaxHealth > 0.

func (*Object) ClearBodyType

func (o *Object) ClearBodyType()

ClearBodyType removes the body type and all body parts, making the object non-combatant. Use this to convert a combat object back to a prop. This method is thread-safe.

func (*Object) Describe

func (v *Object) Describe() string

func (*Object) EffectiveSkills

func (o *Object) EffectiveSkills(ctx Context, skills map[string]bool) float64

EffectiveSkills computes the mean effective level for a set of skills. For each skill: applies forgetting (persisted to Practical), folds recharge into effective. Returns the arithmetic mean of all effective values. IMPORTANT: Must be called immediately before Roll since Roll updates LastUsedAt. IMPORTANT: Caller must hold write access to the object (modifies Skills).

func (*Object) Filter

func (o *Object) Filter(ctx Context, viewer *Object) (*Object, error)

Filter returns a copy with only descriptions and exits the viewer can perceive. Multiple descriptions may be included if the viewer overcomes challenges for multiple descriptions.

func (*Object) FindExit

func (o *Object) FindExit(destination string) *Exit

FindExit returns a pointer to a copy of the exit leading to destination, or nil if not found. The returned pointer is heap-allocated and safe to store beyond the Object's lifetime.

func (*Object) GetBodyConfigID

func (v *Object) GetBodyConfigID() string

func (*Object) GetBodyParts

func (v *Object) GetBodyParts() map[string]BodyPartState

func (*Object) GetCallbacks

func (v *Object) GetCallbacks() map[string]map[string]bool

func (*Object) GetContent

func (v *Object) GetContent() map[string]bool

func (*Object) GetDescriptions

func (v *Object) GetDescriptions() []Description

func (*Object) GetExits

func (v *Object) GetExits() []Exit

func (*Object) GetHealth

func (v *Object) GetHealth() float32

func (*Object) GetId

func (v *Object) GetId() string

func (*Object) GetLearning

func (v *Object) GetLearning() bool

func (*Object) GetLocation

func (v *Object) GetLocation() string

func (*Object) GetMaxHealth

func (v *Object) GetMaxHealth() float32

func (*Object) GetMovement

func (v *Object) GetMovement() Movement

func (*Object) GetSkills

func (v *Object) GetSkills() map[string]Skill

func (*Object) GetSourceModTime

func (v *Object) GetSourceModTime() int64

func (*Object) GetSourcePath

func (v *Object) GetSourcePath() string

func (*Object) GetState

func (v *Object) GetState() string

func (*Object) GetStatusEffects

func (v *Object) GetStatusEffects() []StatusEffect

func (*Object) GetWounds

func (v *Object) GetWounds() []Wound

func (*Object) HasCallback

func (o *Object) HasCallback(name string, tag string) bool

func (*Object) Indef

func (o *Object) Indef() string

Indef returns the object's name with an indefinite article ("a"/"an"), unless the object is unique (proper noun), in which case just the name.

func (*Object) IsAlive

func (o *Object) IsAlive() bool

IsAlive returns true if the object has positive health. Only meaningful for objects that CanCombat(). For non-combat objects (where CanCombat() returns false), this will typically return false since Health defaults to 0.

func (*Object) JSLock

func (v *Object) JSLock()

func (*Object) JSUnlock

func (v *Object) JSUnlock()

func (*Object) Lock

func (v *Object) Lock()

func (*Object) Marshal

func (v *Object) Marshal(b []byte)

func (*Object) MarshalJSON

func (v *Object) MarshalJSON() ([]byte, error)

func (*Object) Name

func (o *Object) Name() string

func (*Object) RLock

func (v *Object) RLock()

func (*Object) RUnlock

func (v *Object) RUnlock()

func (*Object) Roll

func (o *Object) Roll(ctx Context, skills map[string]bool, target string, precomputedEffective, opposingEffective float64, rng *rand.Rand) float64

Roll generates a uniform roll and handles side effects. Returns a value in [MinValue, 10^(precomputedEffective/10)] for comparison. Updates LastUsedAt, LastBase for all skills and applies learning if object has Learning enabled. If rng is nil, generates one internally using multiSkillRng. If rng is provided, uses it (for static challenges needing multiple rolls from same sequence). IMPORTANT: Caller must hold write access to the object (modifies Skills).

func (*Object) SelectBodyPart

func (o *Object) SelectBodyPart(ctx Context, rng *rand.Rand) (string, error)

SelectBodyPart selects a random body part weighted by HitWeight. Severed parts are excluded from selection. Returns the selected body part ID, or error if no valid parts exist. This method is thread-safe.

func (*Object) SetBodyConfigID

func (v *Object) SetBodyConfigID(p string)

func (*Object) SetBodyParts

func (v *Object) SetBodyParts(p map[string]BodyPartState)

func (*Object) SetBodyType

func (o *Object) SetBodyType(ctx Context, bodyConfigID string, maxHealth float32) error

SetBodyType sets the body type, max health, and initializes body parts. This clears any existing body parts and reinitializes them from the config. Health is set to maxHealth (full health on body type change). Use this from JS via setBodyType("humanoid", 100) in created event handlers. Returns an error if the body config is not found. This method is thread-safe.

func (*Object) SetCallbacks

func (v *Object) SetCallbacks(p map[string]map[string]bool)

func (*Object) SetContent

func (v *Object) SetContent(p map[string]bool)

func (*Object) SetDescriptions

func (v *Object) SetDescriptions(p []Description)

func (*Object) SetExits

func (v *Object) SetExits(p []Exit)

func (*Object) SetHealth

func (v *Object) SetHealth(p float32)

func (*Object) SetId

func (v *Object) SetId(p string)

func (*Object) SetLearning

func (v *Object) SetLearning(p bool)

func (*Object) SetLocation

func (v *Object) SetLocation(p string)

func (*Object) SetMaxHealth

func (v *Object) SetMaxHealth(p float32)

func (*Object) SetMovement

func (v *Object) SetMovement(p Movement)

func (*Object) SetPostUnlock

func (v *Object) SetPostUnlock(p func(*Object))

func (*Object) SetSkills

func (v *Object) SetSkills(p map[string]Skill)

func (*Object) SetSourceModTime

func (v *Object) SetSourceModTime(p int64)

func (*Object) SetSourcePath

func (v *Object) SetSourcePath(p string)

func (*Object) SetState

func (v *Object) SetState(p string)

func (*Object) SetStatusEffects

func (v *Object) SetStatusEffects(p []StatusEffect)

func (*Object) SetWounds

func (v *Object) SetWounds(p []Wound)

func (*Object) Size

func (v *Object) Size() int

func (*Object) TakeDamage

func (o *Object) TakeDamage(ctx Context, bodyPartID string, damage float32, damageType string, at Timestamp) (*DamageResult, error)

TakeDamage applies damage to a specific body part and central health. Returns a DamageResult describing the consequences.

Design: - Body part damage = central damage (same amount) - Returns error if body part is already severed - May cause bleeding (adds to Wounds slice) - May cause severing if overkill exceeds threshold - When severing: removes wounds from that part, adds critical wound to central part

Parameters: - ctx: Context for accessing ServerConfig - bodyPartID: Which body part was hit - damage: Final damage amount (after armor/blocking; caller handles reduction) - damageType: Type of damage (e.g., "slashing", "piercing") - at: Timestamp when damage was applied (for wound tracking)

This method is thread-safe.

func (*Object) TotalBleedingLevel

func (o *Object) TotalBleedingLevel() int32

TotalBleedingLevel returns the sum of all wound levels. This method is thread-safe.

func (*Object) Unique

func (o *Object) Unique() bool

func (*Object) Unlock

func (v *Object) Unlock()

func (*Object) Unmarshal

func (v *Object) Unmarshal(b []byte) error

func (*Object) UnmarshalJSON

func (v *Object) UnmarshalJSON(data []byte) error

func (*Object) UnsafeShallowCopy

func (v *Object) UnsafeShallowCopy() *Object

type ObjectDO

type ObjectDO struct {
	Id            string
	State         string
	SourcePath    string
	SourceModTime int64
	Location      string
	Content       map[string]bool
	Callbacks     map[string]map[string]bool
	Descriptions  []Description
	Exits         []Exit
	Learning      bool
	Skills        map[string]Skill
	Movement      Movement
	Health        float32
	MaxHealth     float32
	BodyConfigID  string
	BodyParts     map[string]BodyPartState
	StatusEffects []StatusEffect
	Wounds        []Wound
}

Struct - ObjectDO

func (*ObjectDO) Marshal

func (objectDO *ObjectDO) Marshal(b []byte)

Marshal - ObjectDO

func (*ObjectDO) MarshalPlain

func (objectDO *ObjectDO) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - ObjectDO

func (*ObjectDO) PostUnmarshal

func (o *ObjectDO) PostUnmarshal()

PostUnmarshal initializes nil map fields on an ObjectDO to empty maps. Called automatically by Object.Unmarshal via PostUnmarshaler interface.

func (*ObjectDO) Size

func (objectDO *ObjectDO) Size() int

Size - ObjectDO

func (*ObjectDO) SizePlain

func (objectDO *ObjectDO) SizePlain() (s int)

SizePlain - ObjectDO

func (*ObjectDO) Unmarshal

func (objectDO *ObjectDO) Unmarshal(b []byte) (err error)

Unmarshal - ObjectDO

func (*ObjectDO) UnmarshalPlain

func (objectDO *ObjectDO) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - ObjectDO

type Objects

type Objects []*Object

func (Objects) Len

func (o Objects) Len() int

func (Objects) Less

func (o Objects) Less(i, j int) bool

func (Objects) Lock

func (o Objects) Lock()

Lock sorts objects by ID then locks them in order to prevent deadlocks.

func (Objects) Swap

func (o Objects) Swap(i, j int)

func (Objects) Unlock

func (o Objects) Unlock()

type Observation

type Observation struct {
	Subject     *Object     // The observer
	Challenge   Challenge   // Combined challenge: baseChallenge merged with TransmitChallenge for neighbours
	Perspective Perspective // Where the event came from (observer's perspective)
}

Observation represents an observer and the challenge they overcame to perceive.

type Perspective

type Perspective struct {
	Here bool
	Exit *Exit
}

Perspective describes a location from an observer's point of view. Here=true, Exit=nil: observer's current room Here=false, Exit!=nil: via that exit Here=false, Exit=nil: from an unknown direction (no return exit found)

type PostUnlockObject

type PostUnlockObject func(*Object)

type PostUnmarshaler

type PostUnmarshaler interface {
	PostUnmarshal()
}

type Serializable

type Serializable[T any] interface {
	Marshal([]byte)
	Unmarshal([]byte) error
	Size() int
	*T
}

type ServerConfig

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

ServerConfig holds server-wide configuration with thread-safe access. All fields are private and accessed via getters/setters that handle locking.

func NewServerConfig

func NewServerConfig() *ServerConfig

NewServerConfig creates a new ServerConfig with initialized maps.

func (*ServerConfig) DeleteSkillConfig

func (c *ServerConfig) DeleteSkillConfig(name string)

DeleteSkillConfig removes a skill config.

func (*ServerConfig) GetBodyConfig

func (c *ServerConfig) GetBodyConfig(name string) (BodyConfig, bool)

GetBodyConfig returns the body config for a type, or an empty config if not found.

func (*ServerConfig) GetChallengeDuration

func (c *ServerConfig) GetChallengeDuration(skillsKey string) SkillDuration

GetChallengeDuration returns the duration for a skill combination, or 0 if not found. The key should be generated by SkillsKey().

func (*ServerConfig) GetDamageType

func (c *ServerConfig) GetDamageType(name string) (DamageTypeConfig, bool)

GetDamageType returns the damage type config, or an empty config if not found.

func (*ServerConfig) GetSkillConfig

func (c *ServerConfig) GetSkillConfig(name string) SkillConfig

GetSkillConfig returns the config for a skill, merging with defaults. Always returns a valid config - unconfigured skills get DefaultSkillConfig().

func (*ServerConfig) GetSpawn

func (c *ServerConfig) GetSpawn() string

GetSpawn returns the spawn container ID.

func (*ServerConfig) MarshalJSON

func (c *ServerConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for ServerConfig.

func (*ServerConfig) ReplaceSkillConfigs

func (c *ServerConfig) ReplaceSkillConfigs(configs map[string]SkillConfig)

ReplaceSkillConfigs replaces all skill configs atomically. Makes a defensive copy of the provided map.

func (*ServerConfig) SetBodyConfig

func (c *ServerConfig) SetBodyConfig(name string, cfg BodyConfig)

SetBodyConfig sets a body config.

func (*ServerConfig) SetChallengeDuration

func (c *ServerConfig) SetChallengeDuration(skillsKey string, duration SkillDuration)

SetChallengeDuration sets the duration for a skill combination.

func (*ServerConfig) SetDamageType

func (c *ServerConfig) SetDamageType(name string, cfg DamageTypeConfig)

SetDamageType sets a damage type config.

func (*ServerConfig) SetSkillConfig

func (c *ServerConfig) SetSkillConfig(name string, cfg SkillConfig)

SetSkillConfig sets a skill config.

func (*ServerConfig) SetSpawn

func (c *ServerConfig) SetSpawn(container string)

SetSpawn sets the spawn container ID.

func (*ServerConfig) SkillConfigsSnapshot

func (c *ServerConfig) SkillConfigsSnapshot() map[string]SkillConfig

SkillConfigsSnapshot returns a copy of all skill configs for serialization. Always returns a non-nil map (empty if no configs) so callers can iterate safely.

func (*ServerConfig) UnmarshalJSON

func (c *ServerConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for ServerConfig.

type Severance

type Severance struct {
	// Wound on the central body part from the stump bleeding.
	// Nil if the severed part couldn't bleed (CanBleed=false).
	Wound *Wound
}

Severance describes a severed body part and any resulting wound.

type Skill

type Skill struct {
	Name        string
	Theoretical float32
	Practical   float32
	LastUsedAt  uint64
	LastBase    float32
}

Struct - Skill

func (*Skill) Marshal

func (skill *Skill) Marshal(b []byte)

Marshal - Skill

func (*Skill) MarshalPlain

func (skill *Skill) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Skill

func (*Skill) Size

func (skill *Skill) Size() int

Size - Skill

func (*Skill) SizePlain

func (skill *Skill) SizePlain() (s int)

SizePlain - Skill

func (*Skill) Unmarshal

func (skill *Skill) Unmarshal(b []byte) (err error)

Unmarshal - Skill

func (*Skill) UnmarshalPlain

func (skill *Skill) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Skill

type SkillConfig

type SkillConfig struct {
	// Time for a skill to be fully ready for reuse.
	Recharge SkillDuration
	// Multiplier for success chance when immediately reused.
	Reuse float64
	// Time for skill to be forgotten down to 50% of theoretical level.
	Forget SkillDuration
}

func DefaultSkillConfig

func DefaultSkillConfig() SkillConfig

DefaultSkillConfig returns the default configuration for unconfigured skills. - Recharge: 0 (no cooldown) - Forget: 2 months (skills decay without practice) - Reuse: 0 (no carryover of depleted state)

type SkillDuration

type SkillDuration float64

func Duration

func Duration(d time.Duration) SkillDuration

func (SkillDuration) Duration

func (s SkillDuration) Duration() time.Duration

func (SkillDuration) Nanoseconds

func (s SkillDuration) Nanoseconds() int64

type Snapshottable

type Snapshottable[T any] interface {
	Serializable[T]
	Lock()
	Unlock()
	RLock()
	RUnlock()
	SetPostUnlock(func(t *T))
	GetId() string
	Describe() string
	UnsafeShallowCopy() *T
}

type StatusEffect

type StatusEffect struct {
	Id         string
	ConfigID   string
	AppliedAt  uint64
	ExpiresAt  uint64
	LastTickAt uint64
}

Struct - StatusEffect

func (*StatusEffect) Marshal

func (statusEffect *StatusEffect) Marshal(b []byte)

Marshal - StatusEffect

func (*StatusEffect) MarshalPlain

func (statusEffect *StatusEffect) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - StatusEffect

func (*StatusEffect) Size

func (statusEffect *StatusEffect) Size() int

Size - StatusEffect

func (*StatusEffect) SizePlain

func (statusEffect *StatusEffect) SizePlain() (s int)

SizePlain - StatusEffect

func (*StatusEffect) Unmarshal

func (statusEffect *StatusEffect) Unmarshal(b []byte) (err error)

Unmarshal - StatusEffect

func (*StatusEffect) UnmarshalPlain

func (statusEffect *StatusEffect) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - StatusEffect

type Timestamp

type Timestamp uint64

func Stamp

func Stamp(t time.Time) Timestamp

func (Timestamp) Nanoseconds

func (t Timestamp) Nanoseconds() int64

func (Timestamp) Time

func (t Timestamp) Time() time.Time

func (Timestamp) Uint64

func (t Timestamp) Uint64() uint64

type Wound

type Wound struct {
	BodyPartID string
	Level      int32
	AppliedAt  uint64
	LastTickAt uint64
}

Struct - Wound

func (*Wound) Marshal

func (wound *Wound) Marshal(b []byte)

Marshal - Wound

func (*Wound) MarshalPlain

func (wound *Wound) MarshalPlain(tn int, b []byte) (n int)

MarshalPlain - Wound

func (*Wound) Size

func (wound *Wound) Size() int

Size - Wound

func (*Wound) SizePlain

func (wound *Wound) SizePlain() (s int)

SizePlain - Wound

func (*Wound) Unmarshal

func (wound *Wound) Unmarshal(b []byte) (err error)

Unmarshal - Wound

func (*Wound) UnmarshalPlain

func (wound *Wound) UnmarshalPlain(tn int, b []byte) (n int, err error)

UnmarshalPlain - Wound

Jump to

Keyboard shortcuts

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