has

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package has provides interfaces for Attributes. All interfaces defined in this package should use either standard Go types or other interfaces. This package should not import other packages, especially the attr package. This helps in avoiding cyclic imports.

For each interface defined in the has package there is usually a default implementation of it in the attr package with the same name. For example has.Inventory has the implementation attr.Inventory.

This package does not use the 'er' naming convention for interfaces such as Reader and Writer. It uses the actual attribute names such as Name and Description. This makes sense for WolfMUD when attributes are qualified with the has package name: has.Name, has.Description, has.Inventory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v0.0.6

type Action interface {
	Attribute

	// Action causes the parent Thing to schedule an action message.
	Action()

	// Resume a suspended Action event.
	Resume()

	// Suspend a queued Action event.
	Suspend()

	// Abort cancels any outstanding action events.
	Abort()
}

Action provides information on how often a Thing should emit action messages.

The default implementation is the attr.Action type.

type Alias

type Alias interface {
	Attribute

	// HasAlias returns true if the alias passed is a valid alias, otherwise
	// false.
	HasAlias(alias string) (found bool)

	// HasQualifier returns true if the qualifier passed is a valid qualifier,
	// otherwise false.
	HasQualifier(qualifier string) (found bool)

	// HasQualifierForAlias returns true if the qualifier passed is a valid
	// qualifier bound to the specified alias, otherwise false.
	HasQualifierForAlias(alias, qualifier string) (found bool)

	// Aliases returns all of the aliases as a []string or am empty slice if
	// there are no aliases.
	Aliases() []string

	// Qualifiers returns all of the qualifiers as a []string or am empty slice
	// if there are no qualifiers.
	Qualifiers() []string
}

Alias provides aliases that can be used to refer to a Thing.

Its default implementation is the attr.Alias type.

type Attribute

type Attribute interface {

	// Attributes need to be able to marshal and unmarshal themselves. Marshaler
	// has no default implementation and should be implemented by each Attribute.
	Marshaler

	// Found returns false if the receiver is nil otherwise true. Found has no
	// default implementation and should be implemented by each Attribute as it
	// is based on the receiver type.
	Found() bool

	// Parent returns the Thing to which the Attribute has been added.
	Parent() Thing

	// SetParent sets the Thing to which the Attribute has been added.
	SetParent(Thing)

	// Copy produces another, possibly inexact, instance of an Attribute. The
	// differences may be due to unique IDs, locks and other data that should not
	// be copied between instances.
	//
	// NOTE: The default implementation attr.Attribute does NOT implement Copy.
	// See main interface comments and attr.Attribute.
	Copy() Attribute

	// Free releases resources used by an attribute. It main use is to
	// disentangle cyclic pointers to assist in garbage collection. Attributes
	// that implement their own Free method should also call Attribute.Free.
	Free()

	// Is returns true if the queried attribute can implement the passed
	// attribute, else false.
	Is(Attribute) bool

	// Dump adds information to the passed Node for debugging. The returned Node
	// indicates where addition information may be added.
	Dump(*tree.Node) *tree.Node
}

Attribute provides a minimal, common interface for implementing any type of Attribute. The interface provides a way for an Attribute to associate itself with the parent Thing it is being added to - or disassociate if removed. This allows any Attribute to access its parent Thing or other Attribute associated with the parent Thing.

Its default implementation is the attr.Attribute type. For the different attributes available see the attr package.

NOTE: the default implementation attr.Attribute does NOT provide a default Copy implementation. Each attribute must implement its own Copy method. This is due to the fact that other attributes will know best how to create copies based on their own implementation.

type Barrier added in v0.0.12

type Barrier interface {
	Attribute

	// Allowed returns a slice of aliases allowed to pass through the barrier.
	Allowed() []string

	// Denied returns a slice of aliases not allowed to pass through the barrier.
	Denied() []string
}

Barrier provides a way of conditionally vetoing movement in a given direction based on aliases. The barrier may be invisible or invisible and interactive or non-interactive depending on the Thing the attribute is attached to.

type Body added in v0.0.16

type Body interface {
	Attribute

	// Wield returns true if the Wieldable is successfully wielded else false. If
	// successfully wielded Body slots will be allocated to the Wieldable and the
	// slots marked as 'wielding', on failure no slots are allocated.
	Wield(Wieldable) bool

	// Wear returns true if the Wearable is successfully worn else false. If
	// successfully worn Body slots will be allocated to the Wearable and the
	// slots marked as 'wearing', on failure no slots are allocated.
	Wear(Wearable) bool

	// Hold returns true if the Holdable is successfully held else false. If
	// successfully held Body slots will be allocated to the Holdable and the
	// slots marked as 'holding', on failure no slots are allocated.
	Hold(Holdable) bool

	// Remove the passed Thing from all Body slots allocated to it. Cleared Body
	// slots will also have the usage flags cleared.
	Remove(Thing)

	// RemoveAll frees up all available Body slots and stops using any Thing that
	// are currently in use.
	RemoveAll()

	// Wielding returns a unique slice of Things currently being wielded by the
	// Body or an empty slice.
	Wielding() []Thing

	// Wearing returns a unique slice of Things currently being worn on the Body
	// or an empty slice.
	Wearing() []Thing

	// Holding returns a unique slice of Things currently being held by the Body
	// or an empty slice.
	Holding() []Thing

	// Using returns true if passed Thing is allocated to any Body slot, else
	// false.
	Using(Thing) bool

	// Usage returns a string describing how the passed Thing is being used. For
	// example 'wielding' if the Thing is being wielded. If the passed Thing is
	// not currently being used an empty string is returned.
	Usage(Thing) string

	// UsedBy returns a slice of unique Things, even if allocated to more than
	// one slot, that are using the given slot references.
	UsedBy(refs []string) []Thing

	// Has returns true if the Body has all of the slots specified by the passed
	// refs, else false. Missing slots should never match.
	Has(refs []string) bool
}

Body represents the body (and which slots are available) of a player or mobile so that Things can be used - held, worn, wielded, etc.

Its default implementation is the attr.Body type.

type Cleanup added in v0.0.5

type Cleanup interface {
	Attribute

	// Cleanup causes the parent Thing to be scheduled for clean up.
	Cleanup()

	// Resume a suspended Cleanup event.
	Resume()

	// Suspend a queued Cleanup event.
	Suspend()

	// Abort cancels any outstanding clean up events.
	Abort()

	// Active returns true if any of the Inventories the parent Thing is in
	// already have a clean up scheduled, otherwise false.
	Active() bool
}

Cleanup provides information on how often a Thing should be cleaned up when left laying around.

The default implementation is the attr.Cleanup type.

type Description

type Description interface {
	Attribute

	// Description returns the descriptive text for the attribute.
	Description() string
}

Description provides descriptive text for a Thing.

Its default implementation is the attr.Description type.

type Door added in v0.0.4

type Door interface {
	Attribute

	// Open is used to change the state of a Door to open.
	Open()

	// Opened returns true if the state of a Door is open, otherwise false.
	Opened() bool

	// Close is used to change the state of a Door to closed.
	Close()

	// Closed returns true if the state of a Door is closed, otherwise false.
	Closed() bool

	// Direction returns the direction the door is blocking when closed. The
	// return values match the constants defined in attr.Exits.
	Direction() byte

	// OtherSide creates the opposing side of a Door.
	OtherSide()
}

Door provides a way of blocking travel in a specified direction when closed. A Door can also be used to implement door-like items such as a gate, a panel or a bookcase.

Its default implementation is the attr.Door type.

type Exits

type Exits interface {
	Attribute

	// AutoLink links two opposing exits. Autolink links the passed Inventory to
	// the receiver's exit for the given direction. It then links the passed
	// Inventory's Exits to the receiver's Inventory in the opposite direction.
	AutoLink(direction byte, to Inventory)

	// AutoUnlink unlinks two opposing exits. Autounlink unlinks the receiver's
	// exit for the given direction. It then unlinks the passed Inventory's Exits
	// in the opposite direction.
	AutoUnlink(direction byte)

	// LeadsTo returns the Inventory of the location reached by taking the exit
	// in the given direction. If the exit does not leads nowhere nil returned.
	LeadsTo(direction byte) Inventory

	// Link links the receiver's exit for the given direction to the passed
	// Inventory.
	Link(direction byte, to Inventory)

	// List returns a string describing the exits available for the receiver.
	List() string

	// NormalizeDirection takes a direction name such as 'North', 'north',
	// 'NoRtH' or 'N' and returns the direction's index. If the name cannot be
	// normalized a non-nil error will be returned.
	NormalizeDirection(name string) (byte, error)

	// Surrounding returns a slice of Inventory, one Inventory for each location
	// reachable via the receiver's Exits. If no locations are reachable an empty
	// slice is returned.
	Surrounding() []Inventory

	// ToName takes a direction index and returns the long lowercased name such
	// as 'north' or 'northwest'.
	ToName(direction byte) string

	// Unlink unlinks the Inventory from the receiver for the given direction.
	Unlink(direction byte)

	// Within returns all location Inventories within the given number of moves
	// from the given from Inventory. The inventories are returned as a slice of
	// Inventory slices. The first slice index represents the number of moves.
	// This indexes a slice that contains all locations within that number of
	// moves. The first index, representing 0 moves, is always the current
	// location.
	Within(moves int, from Inventory) [][]Inventory
}

Exits coordinate linkages and movement between location Inventory attributes.

Its default implementation is the attr.Exits type.

type Gender added in v0.0.9

type Gender interface {
	Attribute

	// Gender returns a string representing a Thing's gender such as "Male",
	// "Female" or a non-specific "It".
	Gender() string
}

Gender represents the gender of a Thing.

Its default implementation is the attr.Gender type.

type Health added in v0.0.16

type Health interface {
	Attribute

	// State returns the current and maximum health points.
	State() (current, maximum int)

	// Adjust increases or decreses the current health points by the given amount.
	// The new value will be a minimum of 0 and capped at the health maximum.
	Adjust(int)

	// AutoUpdate enables or disables the automatic regeneration of current
	// health points.
	AutoUpdate(bool)

	// Prompt returns the current health if brief is true else current health and
	// maximum health as 'current/maximum' if false.
	Prompt(PromptStyle) []byte
}

Health represents the state of health of a Thing.

Its default implementation is the attr.Health type.

type Holdable added in v0.0.16

type Holdable interface {
	Attribute
	Slotable

	// Method to distinguish between Holdable, Wearable and Wieldable interfaces.
	IsHoldable() bool
}

Holdable represents the Body slots required to be able to hold a Thing. Any Thing with a Holdable attribute can be held providing the specified Body slots are available.

Its default implementation is the attr.Holdable type.

type Holding added in v0.0.17

type Holding interface {
	Attribute

	// Held returns a list of Thing references for Things that are currently
	// held.
	Held() []string
}

Holding represents the Things that a Thing is holding. That is the Things that are allocated to a Body attribute and have a usage of holding.

The default implementation is the attr.Holding type.

type Inventory

type Inventory interface {
	Attribute
	sync.Locker

	// Players returns a []Thing representing the players of the Inventory.
	Players() []Thing

	// Contents returns a []Thing representing the contents of the Inventory.
	Contents() []Thing

	// Narratives returns a []Thing representing the narratives of the Inventory.
	Narratives() []Thing

	// Everything returns a []Thing representing the narratives and contents of
	// the inventory.
	Everything() []Thing

	// Crowded returns true if the Inventory is considered crowded otherwise
	// false. Definition of crowded is implementation dependant.
	Crowded() bool

	// Occupied returns true if there is at least one player in the Inventory.
	Occupied() bool

	// Empty returns true if the Inventory is empty else false. What empty means
	// is up to the individual Inventory implementation. It may mean that the
	// Inventory is really empty or it may mean that there is nothing available
	// to be removed for example.
	Empty() bool

	// List returns a textual description of the Inventory content.
	List() string

	// LockID returns the unique locking ID for an Inventory.
	LockID() uint64

	// Search returns the first Thing in an Inventory that has a matching Alias.
	// If there are no matches nil is returned.
	Search(alias string) Thing

	// SearchDisabled returns the first disabled Thing in an Inventory that has a
	// matching alias. If there are no matches returns nil.
	SearchDisabled(alias string) Thing

	// SearchByRef returns the first Thing in an Inventory that has a matching
	// reference. If there are no matches returns nil.
	SearchByRef(ref string) Thing

	// Move removes a Thing from the receiver Inventory and places it into the
	// passed Inventory.
	Move(Thing, Inventory)

	// Carried return true if putting an item in an Inventory results in it being
	// carried by a player, otherwise false.
	Carried() bool

	// Outermost returns the top level inventory in an Inventory hierarchy.
	Outermost() Inventory

	// Disabled returns a slice of Thing for items that are out of play (disabled).
	Disabled() []Thing

	// Add puts a Thing into an Inventory and marks it as being initially out of
	// play (disabled).
	Add(Thing)

	// Remove takes a disabled Thing out of an Inventory.
	Remove(Thing)

	// Disable marks a Thing in an Inventory as being out of play.
	Disable(Thing)

	// Enable marks a Thing in an Inventory as being in play.
	Enable(Thing)
}

Inventory are used to implement containers that can contain any type of Thing.

Its default implementation is the attr.Inventory type.

type Locate

type Locate interface {
	Attribute

	// Origin returns the initial starting Inventory that a Thing is placed into.
	Origin() Inventory

	// SetOrigin is used to specify the initial starting Inventory that a Thing
	// is placed into.
	SetOrigin(Inventory)

	// SetWhere is used to set the current Inventory.
	SetWhere(Inventory)

	// Where returns the Inventory currently set.
	Where() Inventory
}

Locate is used by any Thing that needs to know where it is. Locate has a reference to the Inventory that contains the parent Thing of this attribute. When using the default attr.Inventory type this reference is kept up to date automatically as the Thing is moved from Inventory to Inventory. Remember: A location in WolfMUD can be any Thing with an Inventory Attribute, not just conventional 'rooms'.

Its default implementation is the attr.Locate type.

type Marshaler

type Marshaler interface {

	// Unmarshal takes the []byte and returns an Attribute for the []byte data.
	// If the returned Attribute is an untyped nil it should be ignored.
	Unmarshal([]byte) Attribute

	// Marshal returns a tag and []byte that represents an Attribute.
	Marshal() (tag string, data []byte)
}

Marshaler provides the ability to marshal and unmarshal fields for a .wrj (WolfMUD Record Jar) file to and from Attributes. It should be implemnted by all Attribute types.

type Name

type Name interface {
	Attribute

	// Name returns the short name for a Thing. If the name cannot be returned
	// the preset can be used as a default.
	Name(preset string) string

	// TheName returns the short name for a Thing, but with any leading "A ",
	// "An " or "Some " changed to "The ".
	TheName(preset string) string
}

Name provides a short textual name for a Thing. Short names are usually of the form 'a bag', 'an apple', 'some rocks'.

Its default implementation is the attr.Name type.

type Narrative

type Narrative interface {
	Attribute

	// ImplementsNarrative is a marker until we have a fuller implementation of
	// Narrative and we don't accidentally fulfil another interface.
	ImplementsNarrative()
}

Narrative is used to mark a Thing as being for narrative purposes. Any Thing can be a Narrative by adding a Narrative attribute.

Its default implementation is the attr.Narrative type.

type OnAction added in v0.0.6

type OnAction interface {
	Attribute

	// ActionText returns an action message for a Thing.
	ActionText() string
}

OnAction provides action messages for a Thing.

Its default implementation is the attr.OnAction type.

type OnCleanup added in v0.0.6

type OnCleanup interface {
	Attribute

	// CleanupText returns the clean up message for a Thing.
	CleanupText() string
}

OnCleanup provides a clean up message for a Thing.

Its default implementation is the attr.OnCleanup type.

type OnReset added in v0.0.6

type OnReset interface {
	Attribute

	// ResetText returns the reset or respawn message for a Thing.
	ResetText() string
}

OnReset provides a reset or respawn message for a Thing.

Its default implementation is the attr.OnReset type.

type Player

type Player interface {
	Attribute

	// Player should implement a standard Write method to send data back to the
	// associated client.
	io.Writer

	// SetPromptStyle is used to set the current prompt style and returns the
	// previous prompt style. This is so the previous prompt style can be
	// restored if required later on.
	SetPromptStyle(new PromptStyle) (old PromptStyle)
}

Player is used to represent an actual player.

Its default implementation is the attr.Player type.

type PromptStyle

type PromptStyle int
const (
	StyleNone PromptStyle = iota
	StyleBrief
	StyleShort
	StyleLong
)

type Reset added in v0.0.5

type Reset interface {
	Attribute

	// Reset causes the parent Thing to be scheduled for a reset.
	Reset()

	// Resume a suspended Reset event.
	Resume()

	// Suspend a queued Reset event.
	Suspend()

	// Abort cancels any outstanding reset events.
	Abort()

	// Wait returns true if the Thing should wait for it's Inventory items to
	// reset before it resets, else false.
	Wait() bool

	// Spawn returns a non-spawnable copy of the parent Thing and schedules the
	// original to be respawned.
	Spawn() Thing

	// Spawnable returns true if the parent Thing is spawnable else false.
	Spawnable() bool

	// Spawned flags the Thing as being a spawned item.
	//
	// TODO(diddymus): This shouldn't be exposed in the interface and will be
	// removed in the attribute reorganisation.
	Spawned()

	// IsSpawned returns true if the Thing has been spawned else false.
	IsSpawned() bool

	// Unique returns true if item is considered unique else false.
	Unique() bool
}

Reset provides information on how often a Thing should reset and whether the Thing is respawned when picked up or not.

The default implementation is the attr.Reset type.

type Slotable added in v0.0.16

type Slotable interface {

	// Parent returns the Thing to which the Attribute has been added.
	Parent() Thing

	// Slots returns the Body slot references required to use a Thing. The
	// returned slice should not be modified, even temporally.
	Slots() []string
}

Slotable applies to any Thing that can be used (held, worn, wielded, etc.) in one or more Body slots.

Slotable does not have a separate, default implementation and is not a standalone attribute that can be Marshaled/Unmarshaled like other attributes.

type Start

type Start interface {
	Attribute

	// Pick returns an Inventory for a starting location. The location is picked
	// at random from all of the registered starting locations.
	Pick() Inventory
}

Start is used to mark a Thing as being a starting location.

Its default implementation is the attr.Start type.

type Thing

type Thing interface {

	// Add is used to add one or more Attribute to a Thing.
	Add(...Attribute)

	// FindAttr returns the first Attribute implementing the passed attribute or
	// the passed attribute if no matches found.
	FindAttr(Attribute) Attribute

	// FindAttrs returns all Attributes implementing the passed attribute or
	// a nil slice if no matches found.
	FindAttrs(cmp Attribute) []Attribute

	// LoadHooks calls any loadHook methods on attributes of a Thing, and
	// recursively into any Inventory - depth first, providing a hook into the
	// post-unmarshaling process of a Thing.
	LoadHooks()

	// ResetHooks calls any resetHook methods on attributes of a Thing, and
	// recursively into any Inventory - depth first, providing a hook into the
	// reset process of a Thing.
	ResetHooks()

	// SaveHooks calls any saveHook methods on attributes of a Thing, and
	// recursively into any Inventory - depth first, providing a hook into the
	// pre-marshaling process of a Thing.
	SaveHooks()

	// Dump adds information to the passed Node for debugging. The returned Node
	// indicates where addition information can be added.
	Dump(*tree.Node) *tree.Node

	// DumpToLog calls Dump on a Thing and writes the information to the log.
	DumpToLog(string)

	// Remove is used to remove one or more Attribute from a Thing.
	Remove(...Attribute)

	// Free is used to clean-up/release references to all Attribute for a Thing.
	Free()

	// Free returns true if Free has been called on the Thing, else false.
	Freed() bool

	// Copy returns a copy of a Thing, with attributes. The copy may be inexact
	// due to unique IDs, locks and other data that should not be copied between
	// instances. The copy is not recursive and does not include the content of
	// Inventory.
	Copy() Thing

	// DeepCopy returns a copy of a Thing, with attributes, and recursing into
	// Inventory. The copy may be inexact due to unique IDs, locks and other data
	// that should not be copied between instances.
	DeepCopy() Thing

	// SetOrigins updates the origin for the Thing to its containing Inventory and
	// recursivly sets the origins for the content of a Thing's Inventory if it has
	// one.
	SetOrigins()

	// Collectable returns true if a Thing can be kept by a player, otherwise
	// returns false.
	Collectable() bool

	// UID returns the unique identifier for a Thing or an empty string if the
	// unique ID is unavailable.
	UID() string

	// Mark a Thing as no longer being unique.
	NotUnique()

	// Ref returns the reference the Thing had when unmarshaled.
	Ref() string
}

Thing is used to create everything and anything in a WolfMUD world. In WolfMUD everything is created by creating a Thing and adding Attributes to it. Attribute define the behaviour and characteristics of specific Things. Attributes may be added and removed at runtime to dynamically affect a Thing.

Its default implementation is the attr.Thing type. For the different attributes available see the attr package.

type Veto

type Veto interface {

	// Dump adds information to the passed Node for debugging. The returned Node
	// indicates where addition information may be added.
	Dump(*tree.Node) *tree.Node

	// Command returns the command as an uppercased string that this Veto is for.
	Command() string

	// Message returns the details of why the associated command was vetoed.
	Message() string
}

Veto provides a way for a specific command to be vetoed for a specific Thing. Each Veto can veto a single command and provide a message detailing why the command was vetoed. Veto should be added to a Vetoes attribute for a Thing.

Its default implementation is the attr.Veto type.

type Vetoes

type Vetoes interface {
	Attribute

	// Check compares the passed commands, issued by the given actor, with any
	// registered Veto commands. If a command for a Thing is vetoed the first
	// matching Veto found is returned. If no matching Veto are found nil is
	// returned.
	Check(actor Thing, cmd ...string) Veto
}

Vetoes represent one or more Veto allowing commands to be vetoed for a Thing. Multiple Veto can be added to veto multiple commands for different reasons.

Its default implementation is the attr.Vetoes type.

type Wearable added in v0.0.16

type Wearable interface {
	Attribute
	Slotable

	// Method to distinguish between Holdable, Wearable and Wieldable interfaces.
	IsWearable() bool
}

Wearable represents the Body slots required to be able to wear a Thing. Any Thing with a Wearable attribute is wearable providing the specified Body slots are available.

Its default implementation is the attr.Wearable type.

type Wearing added in v0.0.17

type Wearing interface {
	Attribute

	// Held returns a list of Thing references for Things that are currently
	// held.
	Worn() []string
}

Wearing represents the Things that a Thing is wearing. That is the Things that are allocated to a Body attribute and have a usage of wearing.

The default implementation is the attr.Wearing type.

type Wieldable added in v0.0.16

type Wieldable interface {
	Attribute
	Slotable

	// Method to distinguish between Holdable, Wearable and Wieldable interfaces.
	IsWieldable() bool
}

Wieldable represents the Body slots required to be able to wield a Thing. Any Thing with a Wieldable attribute is wieldable providing the specified Body slots are available.

Its default implementation is the attr.Wieldable type.

type Wielding added in v0.0.17

type Wielding interface {
	Attribute

	// Wielded returns a list of Thing references for Things that are currently
	// wielded.
	Wielded() []string
}

Wielding represents the Things that a Thing is wielding. That is the Things that are allocated to a Body attribute and have a usage of wielding.

The default implementation is the attr.Wielding type.

type Writing

type Writing interface {
	Attribute

	// Writing returns the text for what has been written.
	Writing() string
}

Writing allows text to be added to any Thing that can then be read to reveal what is written.

Its default implementation is the attr.Writing type.

Jump to

Keyboard shortcuts

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