Documentation
¶
Index ¶
- Constants
- Variables
- type BaseObject
- type Combatant
- func (c *Combatant) GetFlags() uint64
- func (c *Combatant) GetStat(statDefObj any) (*Stat, error)
- func (c *Combatant) GetStats() []*Stat
- func (c *Combatant) GetType() ObjectType
- func (c *Combatant) HasEffect(effectDefObj any) bool
- func (c *Combatant) HasFlag(flag any) bool
- func (c *Combatant) IsActive() bool
- func (c *Combatant) Reset()
- func (c *Combatant) SetActive(active bool)
- func (c *Combatant) SetEffect(effectDefObj any, sourceObj any, potency int) error
- func (c *Combatant) SetFlag(flag any, on bool)
- func (c *Combatant) String() string
- type Context
- func (c *Context) EmitEvent(event event.Event) error
- func (c *Context) EmitTrigger(triggerDefObj any, sourceObj any) error
- func (c *Context) GetCombatant(obj any) (*Combatant, error)
- func (c *Context) GetCombatantWithStat(stat *Stat) (*Combatant, error)
- func (c *Context) GetCombatants() []*Combatant
- func (c *Context) GetEffectDef(obj any) (*EffectDef, error)
- func (c *Context) GetFlagByName(name string) uint64
- func (c *Context) GetFlags() map[string]uint64
- func (c *Context) GetObject(obj any) (Object, error)
- func (c *Context) GetObjectByID(ID int) (Object, error)
- func (c *Context) GetObjectByIDAndType(ID int, objType ObjectType) (Object, error)
- func (c *Context) GetObjectByName(name string) (Object, error)
- func (c *Context) GetObjectByNameAndType(name string, objType ObjectType) (Object, error)
- func (c *Context) GetObjectByType(obj any, objType ObjectType) (Object, error)
- func (c *Context) GetStatDef(obj any) (*StatDef, error)
- func (c *Context) GetStatDefs() []*StatDef
- func (c *Context) GetTick() int
- func (c *Context) GetTriggerDef(obj any) (*TriggerDef, error)
- func (c *Context) HookEvents(hook event.Hook)
- func (c *Context) NewCombatant() *Combatant
- func (c *Context) NewEffectDef(name string, create func() Effect) *EffectDef
- func (c *Context) NewFlag(name string) uint64
- func (c *Context) NewLuaEffect(script io.Reader) (*EffectDef, error)
- func (c *Context) NewStatDef(name string, min, max int) *StatDef
- func (c *Context) NewTriggerDef(name string) *TriggerDef
- func (c *Context) ProcessEvent(evt event.Event) error
- func (c *Context) Tick() int
- type Effect
- type EffectContext
- type EffectDef
- type Object
- type ObjectType
- type Stat
- type StatDef
- type TriggerDef
Constants ¶
const ( ObjectTypeStatDef = iota ObjectTypeEffectDef ObjectTypeTriggerDef ObjectTypeCombatant ObjectTypeUnknown ObjectTypeError )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type BaseObject ¶
type BaseObject struct {
// contains filtered or unexported fields
}
BaseObject is a base struct for all objects.
type Combatant ¶
type Combatant struct {
BaseObject
// contains filtered or unexported fields
}
Combatant is an entity that can interact with other combatants.
func (*Combatant) GetType ¶
func (c *Combatant) GetType() ObjectType
func (*Combatant) Reset ¶
func (c *Combatant) Reset()
Reset resets the combatant's stats to their base values.
func (*Combatant) SetEffect ¶
SetEffect adds an effect to the combatant. The same effect can be applied multiple times from different sources. Potency is the power of the effect. A potency of zero removes the effect.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is the main object of NBattle.
func (*Context) EmitTrigger ¶
EmitTrigger emits a trigger event from the given source.
func (*Context) GetCombatant ¶
GetCombatant retrieves a combatant from an unknown variable.
func (*Context) GetCombatantWithStat ¶
GetCombatantWithStat retrieves a combatant by a stat that has been assigned to it.
func (*Context) GetCombatants ¶
GetCombatants retrieves all combatants.
func (*Context) GetEffectDef ¶
GetEffectDef retrieves an effect definition from an unknown variable.
func (*Context) GetFlagByName ¶
GetFlagByName retrieves a flag by its name.
func (*Context) GetObject ¶
GetObject retrieves an object from an unknown type value (ID, name, or map containing ID).
func (*Context) GetObjectByID ¶
GetObjectByID retrieves an object by its ID.
func (*Context) GetObjectByIDAndType ¶
func (c *Context) GetObjectByIDAndType(ID int, objType ObjectType) (Object, error)
GetObjecGetObjectByIDAndTypetByID retrieves an object by its ID and type.
func (*Context) GetObjectByName ¶
GetObjectByName retrieves an object by its name.
func (*Context) GetObjectByNameAndType ¶
func (c *Context) GetObjectByNameAndType(name string, objType ObjectType) (Object, error)
GetObjectByNameAndType retrieves an object by its name and type.
func (*Context) GetObjectByType ¶
func (c *Context) GetObjectByType(obj any, objType ObjectType) (Object, error)
GetObject retrieves an object from an unknown type value (ID, name, or map containing ID).
func (*Context) GetStatDef ¶
GetStatDef retrieves a stat definition from an unknown variable.
func (*Context) GetStatDefs ¶
GetStatDefs retrieves all stat definitions.
func (*Context) GetTriggerDef ¶
func (c *Context) GetTriggerDef(obj any) (*TriggerDef, error)
GetTriggerDef retrieves a trigger definition from an unknown variable.
func (*Context) HookEvents ¶
HookEvents adds a new event hook.
func (*Context) NewCombatant ¶
NewCombatant creates a new combatant.
func (*Context) NewEffectDef ¶
NewEffectDef creates a new effect definition.
func (*Context) NewLuaEffect ¶
NewEffect creates a new EffectDef from a Lua script.
func (*Context) NewStatDef ¶
NewStatDef creates a new stat definition.
func (*Context) NewTriggerDef ¶
func (c *Context) NewTriggerDef(name string) *TriggerDef
NewTriggerDef creates a new trigger definition.
func (*Context) ProcessEvent ¶
ProcessEvent processes an event from another context.
type Effect ¶
type Effect interface {
OnAdd(ctx *Context, effect *EffectContext) // OnAdd is called when the effect is first applied to a combatant.
OnRemove(ctx *Context, effect *EffectContext) // OnRemove is called when the effect is removed from a combatant.
OnEvent(ctx *Context, effect *EffectContext, event event.Event) // OnEvent is called whenever an outside event is emitted.
}
Effect is an interface for effects.
type EffectContext ¶
EffectCtx is the context for an effect that has been applied to a specific combatant.
func (*EffectContext) String ¶
func (e *EffectContext) String() string
type EffectDef ¶
type EffectDef struct {
BaseObject
// contains filtered or unexported fields
}
EffectDef is a definition of an effect. An effect can be applied to combatants and used to dynamically alter the combatant's stats.
func (*EffectDef) GetType ¶
func (d *EffectDef) GetType() ObjectType
type Object ¶
type Object interface {
GetID() int // Get the object's unique ID.
GetType() ObjectType // Get the object's type.
String() string // Get the string representation of the object.
}
Object is an interface for all objects managed by NBattle.
type ObjectType ¶
type ObjectType int
func (ObjectType) String ¶
func (o ObjectType) String() string
type Stat ¶
type Stat struct {
// contains filtered or unexported fields
}
Stat represents a single integer value that can be applied to a combatant. It represents the combatant's combat ability in one specific way (such as strength or intelegence). A stat can have mods applied to it that are temporary alterations applied by effects. Mods are a mapping of the effect definition ID that applied it and the ammount to offset the base stat value by.
type StatDef ¶
type StatDef struct {
BaseObject
// contains filtered or unexported fields
}
StatDef is a definition of a stat that can be applied to a combatant.
func (*StatDef) GetType ¶
func (s *StatDef) GetType() ObjectType
type TriggerDef ¶
type TriggerDef struct {
BaseObject
// contains filtered or unexported fields
}
TriggerDef is a definition of a custom event that can be triggered by an effect.
func (*TriggerDef) GetName ¶
func (d *TriggerDef) GetName() string
func (*TriggerDef) GetType ¶
func (d *TriggerDef) GetType() ObjectType
func (*TriggerDef) String ¶
func (s *TriggerDef) String() string