Documentation
¶
Overview ¶
Code generated by generator, DO NOT EDIT.
Index ¶
- Constants
- func Clone[T any, S Serializable[T]](t *T) (*T, error)
- func DefaultBodyConfigs() map[string]BodyConfig
- func DefaultDamageTypes() map[string]DamageTypeConfig
- func SkillsKey(skills map[string]bool) string
- func UpdateState[T any](obj *Object, update func(*T) error) error
- func WithLock(f func() error, objs ...*Object) error
- type AnyCall
- type AnyEvent
- type BodyConfig
- type BodyPartConfig
- type BodyPartState
- func (bodyPartState *BodyPartState) Marshal(b []byte)
- func (bodyPartState *BodyPartState) MarshalPlain(tn int, b []byte) (n int)
- func (bodyPartState *BodyPartState) Size() int
- func (bodyPartState *BodyPartState) SizePlain() (s int)
- func (bodyPartState *BodyPartState) Unmarshal(b []byte) (err error)
- func (bodyPartState *BodyPartState) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Call
- func (c *Call) Call() (*Call, error)
- func (call *Call) Marshal(b []byte)
- func (call *Call) MarshalPlain(tn int, b []byte) (n int)
- func (call *Call) Size() int
- func (call *Call) SizePlain() (s int)
- func (call *Call) Unmarshal(b []byte) (err error)
- func (call *Call) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Caller
- type Challenge
- func (c *Challenge) Check(ctx Context, challenger *Object, targetID string, rng *rand.Rand) float64
- func (c *Challenge) CheckWithDetails(ctx Context, challenger *Object, targetID string) (float64, string)
- func (c *Challenge) HasChallenge() bool
- func (challenge *Challenge) Marshal(b []byte)
- func (challenge *Challenge) MarshalPlain(tn int, b []byte) (n int)
- func (c Challenge) Merge(other Challenge) Challenge
- func (challenge *Challenge) Size() int
- func (challenge *Challenge) SizePlain() (s int)
- func (challenge *Challenge) Unmarshal(b []byte) (err error)
- func (challenge *Challenge) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Content
- type Context
- type DamageResult
- type DamageTypeConfig
- type DeepNeighbourhood
- func (n *DeepNeighbourhood) All() iter.Seq[*Object]
- func (n *DeepNeighbourhood) Describe() string
- func (n *DeepNeighbourhood) Detections(ctx Context, target *Object) iter.Seq2[*Detection, error]
- func (n *DeepNeighbourhood) Filter(ctx Context, viewer *Object) (*DeepNeighbourhood, error)
- func (n *DeepNeighbourhood) Observers(ctx Context, targetID string, baseChallenge Challenge) iter.Seq[*Observation]
- type Description
- func (description *Description) Marshal(b []byte)
- func (description *Description) MarshalPlain(tn int, b []byte) (n int)
- func (description *Description) Size() int
- func (description *Description) SizePlain() (s int)
- func (description *Description) Unmarshal(b []byte) (err error)
- func (description *Description) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Descriptions
- type Detection
- type Event
- func (e *Event) CreateKey()
- func (e *Event) Event() (*Event, error)
- func (event *Event) Marshal(b []byte)
- func (event *Event) MarshalPlain(tn int, b []byte) (n int)
- func (event *Event) Size() int
- func (event *Event) SizePlain() (s int)
- func (event *Event) Unmarshal(b []byte) (err error)
- func (event *Event) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Eventer
- type Exit
- func (exit *Exit) Marshal(b []byte)
- func (exit *Exit) MarshalPlain(tn int, b []byte) (n int)
- func (e *Exit) Name() string
- func (exit *Exit) Size() int
- func (exit *Exit) SizePlain() (s int)
- func (exit *Exit) Unmarshal(b []byte) (err error)
- func (exit *Exit) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Exits
- type Interval
- func (interval *Interval) Marshal(b []byte)
- func (interval *Interval) MarshalPlain(tn int, b []byte) (n int)
- func (interval *Interval) Size() int
- func (interval *Interval) SizePlain() (s int)
- func (interval *Interval) Unmarshal(b []byte) (err error)
- func (interval *Interval) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Location
- func (l *Location) AddDescriptionChallenge(added Challenge) (*Location, error)
- func (l *Location) All() iter.Seq[*Object]
- func (l *Location) Describe() string
- func (l *Location) Detections(ctx Context, target *Object, perspective Perspective) iter.Seq2[*Detection, error]
- func (l *Location) Filter(ctx Context, viewer *Object) (*Location, error)
- func (l *Location) Identify(s string) (*Object, error)
- func (l *Location) Observers(ctx Context, targetID string, challenge Challenge) iter.Seq[*Object]
- type LocationEmit
- type Movement
- func (movement *Movement) Marshal(b []byte)
- func (movement *Movement) MarshalPlain(tn int, b []byte) (n int)
- func (movement *Movement) Size() int
- func (movement *Movement) SizePlain() (s int)
- func (movement *Movement) Unmarshal(b []byte) (err error)
- func (movement *Movement) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Neighbourhood
- type Object
- func (o *Object) AddDescriptionChallenge(added Challenge) (*Object, error)
- func (o *Object) BodyPartsInitialized() bool
- func (o *Object) CanCombat() bool
- func (o *Object) ClearBodyType()
- func (v *Object) Describe() string
- func (o *Object) EffectiveSkills(ctx Context, skills map[string]bool) float64
- func (o *Object) Filter(ctx Context, viewer *Object) (*Object, error)
- func (o *Object) FindExit(destination string) *Exit
- func (v *Object) GetBodyConfigID() string
- func (v *Object) GetBodyParts() map[string]BodyPartState
- func (v *Object) GetCallbacks() map[string]map[string]bool
- func (v *Object) GetContent() map[string]bool
- func (v *Object) GetDescriptions() []Description
- func (v *Object) GetExits() []Exit
- func (v *Object) GetHealth() float32
- func (v *Object) GetId() string
- func (v *Object) GetLearning() bool
- func (v *Object) GetLocation() string
- func (v *Object) GetMaxHealth() float32
- func (v *Object) GetMovement() Movement
- func (v *Object) GetSkills() map[string]Skill
- func (v *Object) GetSourceModTime() int64
- func (v *Object) GetSourcePath() string
- func (v *Object) GetState() string
- func (v *Object) GetStatusEffects() []StatusEffect
- func (v *Object) GetWounds() []Wound
- func (o *Object) HasCallback(name string, tag string) bool
- func (o *Object) Indef() string
- func (o *Object) IsAlive() bool
- func (v *Object) JSLock()
- func (v *Object) JSUnlock()
- func (v *Object) Lock()
- func (v *Object) Marshal(b []byte)
- func (v *Object) MarshalJSON() ([]byte, error)
- func (o *Object) Name() string
- func (v *Object) RLock()
- func (v *Object) RUnlock()
- func (o *Object) Roll(ctx Context, skills map[string]bool, target string, ...) float64
- func (o *Object) SelectBodyPart(ctx Context, rng *rand.Rand) (string, error)
- func (v *Object) SetBodyConfigID(p string)
- func (v *Object) SetBodyParts(p map[string]BodyPartState)
- func (o *Object) SetBodyType(ctx Context, bodyConfigID string, maxHealth float32) error
- func (v *Object) SetCallbacks(p map[string]map[string]bool)
- func (v *Object) SetContent(p map[string]bool)
- func (v *Object) SetDescriptions(p []Description)
- func (v *Object) SetExits(p []Exit)
- func (v *Object) SetHealth(p float32)
- func (v *Object) SetId(p string)
- func (v *Object) SetLearning(p bool)
- func (v *Object) SetLocation(p string)
- func (v *Object) SetMaxHealth(p float32)
- func (v *Object) SetMovement(p Movement)
- func (v *Object) SetPostUnlock(p func(*Object))
- func (v *Object) SetSkills(p map[string]Skill)
- func (v *Object) SetSourceModTime(p int64)
- func (v *Object) SetSourcePath(p string)
- func (v *Object) SetState(p string)
- func (v *Object) SetStatusEffects(p []StatusEffect)
- func (v *Object) SetWounds(p []Wound)
- func (v *Object) Size() int
- func (o *Object) TakeDamage(ctx Context, bodyPartID string, damage float32, damageType string, ...) (*DamageResult, error)
- func (o *Object) TotalBleedingLevel() int32
- func (o *Object) Unique() bool
- func (v *Object) Unlock()
- func (v *Object) Unmarshal(b []byte) error
- func (v *Object) UnmarshalJSON(data []byte) error
- func (v *Object) UnsafeShallowCopy() *Object
- type ObjectDO
- func (objectDO *ObjectDO) Marshal(b []byte)
- func (objectDO *ObjectDO) MarshalPlain(tn int, b []byte) (n int)
- func (o *ObjectDO) PostUnmarshal()
- func (objectDO *ObjectDO) Size() int
- func (objectDO *ObjectDO) SizePlain() (s int)
- func (objectDO *ObjectDO) Unmarshal(b []byte) (err error)
- func (objectDO *ObjectDO) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Objects
- type Observation
- type Perspective
- type PostUnlockObject
- type PostUnmarshaler
- type Serializable
- type ServerConfig
- func (c *ServerConfig) DeleteSkillConfig(name string)
- func (c *ServerConfig) GetBodyConfig(name string) (BodyConfig, bool)
- func (c *ServerConfig) GetChallengeDuration(skillsKey string) SkillDuration
- func (c *ServerConfig) GetDamageType(name string) (DamageTypeConfig, bool)
- func (c *ServerConfig) GetSkillConfig(name string) SkillConfig
- func (c *ServerConfig) GetSpawn() string
- func (c *ServerConfig) MarshalJSON() ([]byte, error)
- func (c *ServerConfig) ReplaceSkillConfigs(configs map[string]SkillConfig)
- func (c *ServerConfig) SetBodyConfig(name string, cfg BodyConfig)
- func (c *ServerConfig) SetChallengeDuration(skillsKey string, duration SkillDuration)
- func (c *ServerConfig) SetDamageType(name string, cfg DamageTypeConfig)
- func (c *ServerConfig) SetSkillConfig(name string, cfg SkillConfig)
- func (c *ServerConfig) SetSpawn(container string)
- func (c *ServerConfig) SkillConfigsSnapshot() map[string]SkillConfig
- func (c *ServerConfig) UnmarshalJSON(data []byte) error
- type Severance
- type Skill
- type SkillConfig
- type SkillDuration
- type Snapshottable
- type StatusEffect
- func (statusEffect *StatusEffect) Marshal(b []byte)
- func (statusEffect *StatusEffect) MarshalPlain(tn int, b []byte) (n int)
- func (statusEffect *StatusEffect) Size() int
- func (statusEffect *StatusEffect) SizePlain() (s int)
- func (statusEffect *StatusEffect) Unmarshal(b []byte) (err error)
- func (statusEffect *StatusEffect) UnmarshalPlain(tn int, b []byte) (n int, err error)
- type Timestamp
- type Wound
Constants ¶
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.
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 ¶
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 ¶
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.
Types ¶
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 ¶
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) 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 Challenge ¶
Struct - Challenge
func (*Challenge) Check ¶
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 ¶
HasChallenge returns true if the challenge has any skills defined.
func (*Challenge) MarshalPlain ¶
MarshalPlain - Challenge
func (Challenge) Merge ¶
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.
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 ¶
func (*DeepNeighbourhood) Describe ¶
func (n *DeepNeighbourhood) Describe() string
func (*DeepNeighbourhood) Detections ¶
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) 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 ¶
Struct - Event
func (*Event) CreateKey ¶
func (e *Event) CreateKey()
CreateKey generates a unique, sortable key combining timestamp and counter.
func (*Event) MarshalPlain ¶
MarshalPlain - Event
type Exit ¶
type Exit struct {
Descriptions []Description
UseChallenge Challenge
TransmitChallenge Challenge
Tags []string
Destination string
}
Struct - Exit
func (*Exit) MarshalPlain ¶
MarshalPlain - Exit
type Interval ¶
type Interval struct {
ObjectID string
IntervalID string
IntervalMS int64
EventName string
EventData string
NextFireTime int64
}
Struct - Interval
func (*Interval) MarshalPlain ¶
MarshalPlain - Interval
type Location ¶
func (*Location) AddDescriptionChallenge ¶
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.
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 ¶
Struct - Movement
func (*Movement) MarshalPlain ¶
MarshalPlain - Movement
type Neighbourhood ¶
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 (*Object) AddDescriptionChallenge ¶
AddDescriptionChallenge returns a copy with added difficulty on all descriptions. The added challenge is merged into each description's existing challenge.
func (*Object) BodyPartsInitialized ¶
BodyPartsInitialized returns true if body parts have been initialized.
func (*Object) CanCombat ¶
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) EffectiveSkills ¶
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 ¶
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 ¶
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 (*Object) GetBodyParts ¶
func (v *Object) GetBodyParts() map[string]BodyPartState
func (*Object) GetContent ¶
func (*Object) GetDescriptions ¶
func (v *Object) GetDescriptions() []Description
func (*Object) GetLearning ¶
func (*Object) GetLocation ¶
func (*Object) GetMaxHealth ¶
func (*Object) GetMovement ¶
func (*Object) GetSourceModTime ¶
func (*Object) GetSourcePath ¶
func (*Object) GetStatusEffects ¶
func (v *Object) GetStatusEffects() []StatusEffect
func (*Object) Indef ¶
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 ¶
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) MarshalJSON ¶
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 ¶
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 (*Object) SetBodyParts ¶
func (v *Object) SetBodyParts(p map[string]BodyPartState)
func (*Object) SetBodyType ¶
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) SetContent ¶
func (*Object) SetDescriptions ¶
func (v *Object) SetDescriptions(p []Description)
func (*Object) SetLearning ¶
func (*Object) SetLocation ¶
func (*Object) SetMaxHealth ¶
func (*Object) SetMovement ¶
func (*Object) SetPostUnlock ¶
func (*Object) SetSourceModTime ¶
func (*Object) SetSourcePath ¶
func (*Object) SetStatusEffects ¶
func (v *Object) SetStatusEffects(p []StatusEffect)
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 ¶
TotalBleedingLevel returns the sum of all wound levels. This method is thread-safe.
func (*Object) UnmarshalJSON ¶
func (*Object) UnsafeShallowCopy ¶
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) MarshalPlain ¶
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.
type Objects ¶
type Objects []*Object
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 ¶
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 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) MarshalPlain ¶
MarshalPlain - 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) 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