attr

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: 19 Imported by: 0

Documentation

Overview

Package attr (attributes) implements all of the functionality for objects in a WolfMUD world. All objects are instances of the Thing type. To these instances various attributes are added depending on the functionality required. The functionality of an object may be changed at runtime by adding or removing attributes.

A Thing can be searched for specific Attribute types using finders. All finders return a typed nil in the event of the specific Attribute type not being found. Returning a typed nil such as (*Alias)(nil) allows the finder to be chained to any other methods taking the a pointer to the Attribute type as a receiver. For example:

if attr.FindAlias(t).HasAlias("test") {
	// do something...
}

If you need to check specifically if the finder returns nil, compare the returned value to the typed nil:

if a := attr.FindAlias(t); a == (*Alias)(nil) {
	// do something...
}

Or if available use the Found method:

if !attr.FindAlias(t).Found() {
	// do something...
}

All methods that take a pointer to an Attribute as a receiver are expected to be able to handle a nil receiver unless otherwise stated.

All typed nils should be of the same type as the default implementation for the type. For example the has.Alias interface has attr.Alias as the default implementation, therefore the typed nil should also be of type *Alias.

While it may seem unusual to return a typed nil it simplifies and reduces a lot of code in WolfMUD.

Index

Constants

View Source
const (
	North byte = iota
	Northeast
	East
	Southeast
	South
	Southwest
	West
	Northwest
	Up
	Down
)

Constants for direction indexes. These can be used for the Link, AutoLink, Unlink and AutoUnlink methods. If these constants are modified probably need to update the Return function as well.

View Source
const (
	It byte = iota
	Male
	Female
)

Constants for gender indexes.

Variables

View Source
var ThingCount chan uint64

ThingCount is a channel storing the current number of Things. The value should only be incremented by NewThing and decremented by Free. ThingCount is a channel so that the value can be updated concurrently and shared with e.g. the stats package.

Functions

func FindAction added in v0.0.6

func FindAction(t has.Thing) has.Action

FindAction searches the attributes of the specified Thing for attributes that implement has.Action returning the first match it finds or a *Action typed nil otherwise.

func FindAlias

func FindAlias(t has.Thing) has.Alias

FindAlias searches the attributes of the specified Thing for attributes that implement has.Alias returning the first match it finds or a *Alias typed nil otherwise.

func FindAllDescription

func FindAllDescription(t has.Thing) (matches []has.Description)

FindAllDescription searches the attributes of the specified Thing for attributes that implement has.Description returning all that match. If no matches are found an empty slice will be returned.

func FindAllVetoes added in v0.0.12

func FindAllVetoes(t has.Thing) (matches []has.Vetoes)

FindAllVetoes searches the attributes of the specified Thing for attributes that implement has.Vetoes returning all that match. If no matches are found an empty slice will be returned.

func FindBarrier added in v0.0.12

func FindBarrier(t has.Thing) has.Barrier

FindBarrier searches the attributes of the specified Thing for attributes that implement has.Barrier returning the first match it finds or a *Barrier typed nil otherwise.

func FindBody added in v0.0.16

func FindBody(t has.Thing) has.Body

FindBody searches the attributes of the specified Thing for attributes that implement has.Body returning the first match it finds or a *Body typed nil otherwise.

func FindCleanup added in v0.0.5

func FindCleanup(t has.Thing) has.Cleanup

FindCleanup searches the attributes of the specified Thing for attributes that implement has.Cleanup returning the first match it finds or a *Cleanup typed nil otherwise.

func FindDoor added in v0.0.4

func FindDoor(t has.Thing) has.Door

FindDoor searches the attributes of the specified Thing for attributes that implement has.Door returning the first match it finds or a *Door typed nil otherwise.

func FindExits

func FindExits(t has.Thing) has.Exits

FindExits searches the attributes of the specified Thing for attributes that implement has.Exits returning the first match it finds or a *Exits typed nil otherwise.

func FindGender added in v0.0.9

func FindGender(t has.Thing) has.Gender

FindGender searches the attributes of the specified Thing for attributes that implement has.Gender returning the first match it finds or a *Gender typed nil otherwise.

func FindHealth added in v0.0.16

func FindHealth(t has.Thing) has.Health

FindHealth searches the attributes of the specified Thing for attributes that implement has.Health returning the first match it finds or a *Health typed nil otherwise.

func FindHoldable added in v0.0.16

func FindHoldable(t has.Thing) has.Holdable

FindHoldable searches the attributes of the specified Thing for attributes that implement has.Holdable returning the first match it finds.

If not match is found and the Thing is not a player or mobile, does not have a Body attribute, then a default Holdable with a single 'HAND' slot will be returned.

If the Thing is a player or mobile, has a Body attribute, then a *Holdable typed nil will be returned.

func FindHolding added in v0.0.17

func FindHolding(t has.Thing) has.Holding

FindHolding searches the attributes of the specified Thing for attributes that implement has.Holding returning the first match it finds or a *Holding typed nil otherwise.

func FindInventory

func FindInventory(t has.Thing) has.Inventory

FindInventory searches the attributes of the specified Thing for attributes that implement has.Inventory returning the first match it finds or a *Inventory typed nil otherwise.

func FindLocate

func FindLocate(t has.Thing) has.Locate

FindLocate searches the attributes of the specified Thing for attributes that implement has.Locate returning the first match it finds or a *Locate typed nil otherwise.

func FindName

func FindName(t has.Thing) has.Name

FindName searches the attributes of the specified Thing for attributes that implement has.Name returning the first match it finds or a *Name typed nil otherwise.

func FindNarrative

func FindNarrative(t has.Thing) has.Narrative

FindNarrative searches the attributes of the specified Thing for attributes that implement has.Narrative returning the first match it finds or a *Narrative typed nil otherwise.

func FindOnAction added in v0.0.6

func FindOnAction(t has.Thing) has.OnAction

FindOnAction searches the attributes of the specified Thing for attributes that implement has.OnAction returning the first match it finds or a *OnAction typed nil otherwise.

func FindOnCleanup added in v0.0.6

func FindOnCleanup(t has.Thing) has.OnCleanup

FindOnCleanup searches the attributes of the specified Thing for attributes that implement has.OnCleanup returning the first match it finds or a *OnCleanup typed nil otherwise.

func FindOnReset added in v0.0.6

func FindOnReset(t has.Thing) has.OnReset

FindOnReset searches the attributes of the specified Thing for attributes that implement has.OnReset returning the first match it finds or a *OnReset typed nil otherwise.

func FindPlayer

func FindPlayer(t has.Thing) has.Player

FindPlayer searches the attributes of the specified Thing for attributes that implement has.Player returning the first match it finds or a *Player typed nil otherwise.

func FindReset added in v0.0.5

func FindReset(t has.Thing) has.Reset

FindReset searches the attributes of the specified Thing for attributes that implement has.Reset returning the first match it finds or a *Reset typed nil otherwise.

func FindStart

func FindStart(t has.Thing) has.Start

FindStart searches the attributes of the specified Thing for attributes that implement has.Start returning the first match it finds or a *Start typed nil otherwise.

func FindWearable added in v0.0.16

func FindWearable(t has.Thing) has.Wearable

FindWearable searches the attributes of the specified Thing for attributes that implement has.Wearable returning the first match it finds or a *Wearable typed nil otherwise.

func FindWearing added in v0.0.17

func FindWearing(t has.Thing) has.Wearing

FindWearing searches the attributes of the specified Thing for attributes that implement has.Wearing returning the first match it finds or a *Wearing typed nil otherwise.

func FindWieldable added in v0.0.16

func FindWieldable(t has.Thing) has.Wieldable

FindWieldable searches the attributes of the specified Thing for attributes that implement has.Wieldable returning the first match it finds or a *Wieldable typed nil otherwise.

func FindWielding added in v0.0.17

func FindWielding(t has.Thing) has.Wielding

FindWielding searches the attributes of the specified Thing for attributes that implement has.Wielding returning the first match it finds or a *Wielding typed nil otherwise.

func FindWriting

func FindWriting(t has.Thing) has.Writing

FindWriting searches the attributes of the specified Thing for attributes that implement has.Writing returning the first match it finds or a *Writing typed nil otherwise.

func Return

func Return(direction byte) byte

Return calculates the opposite/return direction for the direction given. This is handy for calculating things like normal exits where if you go north you return by going back south. It is also useful for implementing ranged weapons, thrown weapons and spells. For example if you fire a bow west the person will see the arrow come from the east (from their perspective).

Types

type Action added in v0.0.6

type Action struct {
	Attribute

	event.Cancel
	// contains filtered or unexported fields
}

Action implements an Attribute to display random action messages. Messages are specified via an OnAction Attribute. Action schedules a $action command to display a message everytime the event fires. The period when Action fires is between Action.after and Action.after+Action.jitter. An Action event can be cancelled by calling Action.Abort or by closing the Action.Cancel channel.

func NewAction added in v0.0.6

func NewAction(after time.Duration, jitter time.Duration) *Action

NewAction returns a new Action attribute initialised with the passed after and jitter durations. The after and jitter Duration set the delay period to between after and after+jitter for when a Thing performs an action.

func (*Action) Abort added in v0.0.6

func (a *Action) Abort()

Abort a queued Action event, or do nothing if event not queued.

func (*Action) Action added in v0.0.6

func (a *Action) Action()

Action schedules an Action event. If the Action event is already queued it will be cancelled and a new one queued.

func (*Action) Copy added in v0.0.6

func (a *Action) Copy() has.Attribute

Copy returns a copy of the Action receiver. If the Action event is currently queued it will be suspended in the returned copy.

func (*Action) Dump added in v0.0.6

func (a *Action) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Action) Found added in v0.0.6

func (a *Action) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Action) Free added in v0.0.6

func (a *Action) Free()

Free makes sure references are nil'ed and queued events aborted when the Action attribute is freed.

func (*Action) Is added in v0.0.16

func (*Action) Is(a has.Attribute) bool

Is returns true if passed attribute implements an action else false.

func (*Action) Marshal added in v0.0.9

func (a *Action) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Action) Pending added in v0.0.14

func (a *Action) Pending() bool

Pending returns true if there is an Action event pending, else false. Use with caution as this could introduce a race between checking the state and acting on it as the event could fire between the two actions.

func (*Action) Resume added in v0.0.16

func (a *Action) Resume()

Resume a suspended Action event, or do nothing if event not suspended.

func (*Action) Suspend added in v0.0.16

func (a *Action) Suspend()

Suspend a queued Action event, or do nothing if event not queued.

func (*Action) Unmarshal added in v0.0.6

func (*Action) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Action attribute.

type Alias

type Alias struct {
	Attribute
	// contains filtered or unexported fields
}

Alias implements an attribute for referring to a Thing. An alias is a single word used to refer to things. Things may have more than one alias. For example a sword may have the aliases 'SWORD' and 'SHORTSWORD'. Given these aliases a player may use commands such as:

GET SWORD
EXAMINE SHORTSWORD
DROP SHORTSWORD

Every Alias attribute that has a parent Thing set will have a unique ID equal to the result of calling Alias.Parent().UID(). Therefore a specific, unique Thing can be found by unique ID using, for example, Alias.HasAlias(Thing.UID()) or Inventory.Search(Thing.UID()).

NOTE: It is important to switch to the unique alias whenever possible, especially when scripting, so that the correct Thing is used for commands. This avoids picking the wrong Thing when a given alias identifies multiple Things. For example if we have a respawnable runestone and we get and drop the runestone it will be registered for cleanup. However if we just use the alias 'RUNESTONE' either the dropped or respawned runestone could be cleaned up. If the respawned runestone is cleaned up we could end up in a loop respawning and cleaning up the wrong runestone. Using the unique alias of the dropped runestone avoids this situation.

As well as an alias a Thing may have one or more qualifiers. A qualifier can be used to specify a Thing more specifically. For example:

GET LONG SWORD
GET SHORT SWORD

Here the qualifiers are 'LONG' and 'SHORT'. Qualifiers are defined by prefixing an alias with a plus '+' symbol. For example:

Aliases: +LONG SWORD
Aliases: +SHORT SWORD

A qualifier can be bound to a specific alias by following the qualifier with a colon ':' and the alias to bind it to. For example:

Aliases: +WOODEN +SHORT:SWORD SHORTSWORD

This binds the qualifier 'SHORT' to the alias 'SWORD'. The following would then be valid:

GET WOODEN SWORD
GET WOODEN SHORT SWORD
GET SHORT WOODEN SWORD
GET WOODEN SHORTSWORD
GET SWORD
GET SHORTSWORD

The following would not be validi as 'SHORT' is only bound to 'SWORD' and not 'SHORTSWORD':

GET SHORT SHORTSWORD

func NewAlias

func NewAlias(aliases ...string) *Alias

NewAlias returns a new Alias attribute initialised with the specified aliases and qualifiers. Qualifiers are specified by prefixing an alias with a plus '+' symbol. The specified aliases and qualifiers are automatically uppercased when stored. A unique alias using the parent Thing.UID will be added automatically.

func (*Alias) Aliases

func (a *Alias) Aliases() (aliases []string)

Aliases returns a []string of all the aliases for an Alias attribute. If there are no aliases an empty slice will be returned.

func (*Alias) Copy added in v0.0.4

func (a *Alias) Copy() has.Attribute

Copy returns a copy of the Alias receiver.

func (*Alias) Dump

func (a *Alias) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Alias) Found

func (a *Alias) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Alias) HasAlias

func (a *Alias) HasAlias(alias string) (found bool)

HasAlias checks the passed string for a matching alias. Returns true if a match is found otherwise false.

func (*Alias) HasQualifier added in v0.0.14

func (a *Alias) HasQualifier(qualifier string) (found bool)

HasQualifier checks the passed string for a matching qualifier. Returns true if a match is found otherwise false.

func (*Alias) HasQualifierForAlias added in v0.0.14

func (a *Alias) HasQualifierForAlias(alias, qualifier string) (found bool)

HasQualifierForAlias checks the passed string for a matching qualifier for a specific alias. Returns true if a match is found otherwise false. An alias can be bound to a qualifier using the syntax "+qualifier:alias".

func (*Alias) Is added in v0.0.16

func (*Alias) Is(a has.Attribute) bool

Is returns true if passed attribute implements an alias else false.

func (*Alias) Marshal added in v0.0.9

func (a *Alias) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Alias) Qualifiers added in v0.0.14

func (a *Alias) Qualifiers() (qualifiers []string)

Qualifiers returns a []string of all the qualifiers for an Alias attribute. If there are no qualifiers an empty slice will be returned.

func (*Alias) SetParent added in v0.0.5

func (a *Alias) SetParent(t has.Thing)

SetParent overrides the default Attribute.SetParent in order to set a unique alias based on the parent Thing unique ID. The alias will be equal to the value returned by calling Alias.Parent().UID(). When the parent for the attribute changes the old unique identifier is removed (if there is one) and the new unique alias added before setting the new parent.

func (*Alias) Unmarshal

func (*Alias) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Alias attribute.

type Attribute

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

Attribute implements a stub for other attributes. Any types providing attributes can embed this type instead of implementing their own Parent and SetParent methods. Updating and querying the parent is concurrent safe.

NOTE: 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.

func (*Attribute) Free added in v0.0.5

func (a *Attribute) Free()

Free makes sure references are nil'ed when the Attribute is freed. Other attributes should override Free to release their own references and resources. Attributes that implement their own Free method should also call Attribute.Free.

func (*Attribute) Parent

func (a *Attribute) Parent() has.Thing

Parent returns the Thing that the Attribute has been added to.

func (*Attribute) SetParent

func (a *Attribute) SetParent(t has.Thing)

SetParent is used to set the Thing that the Attribute has been added to. If it is not currently added to a Thing nil is returned. This method is automatically called by the Thing Add method.

type Barrier added in v0.0.12

type Barrier struct {
	Attribute
	// contains filtered or unexported fields
}

Barrier implements an attribute for conditionally vetoing movement in a given direction. The barrier may be invisible or invisible and interactive or non-interactive depending on the Thing the attribute is attached to. A Barrier has two lists of aliases: those allowed to pass through the barrier and those not allowed to pass through the barrier. The allowed aliases are checked before those in the denied list. For example:

b := NewBarrier(East, []string{"GUARD"}, []{"NPC"})

This would define a barrier preventing all mobiles with an alias of "NPC" from going east, unless they also has an alias of "GUARD". In this respect "NPC" is acting as a group alias, and can be applied to all mobiles that are considered non-player characters. If a mobile (or player) does not match an alias in the denied list they are allowed to pass through.

func NewBarrier added in v0.0.12

func NewBarrier(direction byte, allow []string, deny []string) *Barrier

NewBarrier returns a new Barrier attribute. The direction is the conditionally blocked exit's direction. The allow and deny slices are lists of aliases that decide if movement in the given direction is vetoed or not.

func (*Barrier) Allowed added in v0.0.12

func (b *Barrier) Allowed() (aliases []string)

Allowed returns a string slice of aliases that can unconditionally pass through the barrier.

func (*Barrier) Check added in v0.0.12

func (b *Barrier) Check(actor has.Thing, cmd ...string) has.Veto

Check will veto passing through a Barrier dynamically based on the command (direction) given and the aliases of the actor wishing to pass through the Barrier. If an alias of the actor matches a denied alias we veto movement, unless overridden by a matching allowed alias. Otherwise we don't veto.

func (*Barrier) Copy added in v0.0.12

func (b *Barrier) Copy() has.Attribute

Copy returns a copy of the Barrier receiver.

func (*Barrier) Denied added in v0.0.12

func (b *Barrier) Denied() (aliases []string)

Denied returns a string slice of aliases that can cannot pass through the barrier, unless overridden unconditionally by allowed aliases.

func (*Barrier) Dump added in v0.0.12

func (b *Barrier) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Barrier) Found added in v0.0.12

func (b *Barrier) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Barrier) Is added in v0.0.16

func (*Barrier) Is(a has.Attribute) bool

Is returns true if passed attribute implements a barrier else false.

func (*Barrier) Marshal added in v0.0.12

func (b *Barrier) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Barrier) Unmarshal added in v0.0.12

func (*Barrier) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Barrier attribute.

type Body added in v0.0.16

type Body struct {
	Attribute
	// contains filtered or unexported fields
}

Body implements an attribute representing the body of a Thing which in turn represents the body slots available for holding, wearing and wielding items.

NOTE: A Body attribute and its associated slots are not automatically kept in sync with a player's or mobile's Inventory. Should an item be removed or discarded the Body should also be updated, if needed, to reflect the change. At the moment this mainly effects the DROP and PUT commands. The QUIT command also needs to update the Body when non-collectable items are disposed of. The JUNK command is currently vetoed to stop accidental junking of in use items - if that changes the JUNK command will also need to update the Body.

TODO(diddymus): Currently there is no relationship specified between body slots. For example, if a hand is missing then the fingers and thumb should also be missing but this is not handled automatically yet.

BUG(diddymus): If there are multiple slots with the same name available, for example two HAND slots, only one will be reported. For example if you are holding a knife and dagger and try to wield a sword it will report one of:

  • You cannot wield the sword while also using a knife.
  • You cannot wield the sword while also using a dagger.

Message depends on order of usage. Ideally this should report:

  • You cannot wield the sword while also using a knife and a dagger.

Maybe that should be 'a knife OR a dagger'? If you try to wield a two handed staff the message is correct:

  • You cannot wield the staff while also using a knife and a dagger.

I think the fix for this is to make UsedBy smarter.

func NewBody added in v0.0.16

func NewBody(refs ...string) *Body

NewBody returns a Body attribute initialised with the slots specified by refs. The refs should contain the name of the slots to be made available for wearing, wielding or holding items. For example:

NewBody("HEAD", "TORSO", "ARM", "HAND", "ARM", "HAND", "LEG", "LEG")

There are no restrictions on how detailed body composition is - if you want to define 10 fingers, 10 toes, eyebrows etc you can! The only 'rule' is that the slot references used for a body must match the references used by the Wearable and Wieldable attributes defined on items.

If a body part is missing, for example a hand was cut off, it should be represented with a leading exclamation mark '!'. This then provides the possibility of regaining the body part through various means such as magic, prothetics or growing it back. For example:

NewBody("HEAD", "TORSO", "ARM", "!HAND", "ARM", "HAND", "LEG", "LEG")

Without this record of a missing body part there is no way of knowing it was originally there in the first place.

func (*Body) Copy added in v0.0.16

func (b *Body) Copy() has.Attribute

Copy returns a copy of the Body receiver including all of the slots and their current usage.

func (*Body) Dump added in v0.0.16

func (b *Body) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Body) Found added in v0.0.16

func (b *Body) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Body) Free added in v0.0.16

func (b *Body) Free()

Free makes sure Body slots are nil'ed when the Body attribute is freed.

func (*Body) Has added in v0.0.16

func (b *Body) Has(refs []string) bool

Has returns true if the Body has all of the slots specified by the passed refs else false. Has does not check if the slots are used or not, only if they are available.

func (*Body) Hold added in v0.0.16

func (b *Body) Hold(h has.Holdable) 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.

func (*Body) Holding added in v0.0.16

func (b *Body) Holding() []has.Thing

Holding returns a unique slice of Things, even if they take up more than one Body slot, currently being held by the Body. If nothing is being held an empty slice will be returned.

func (*Body) Is added in v0.0.16

func (*Body) Is(a has.Attribute) bool

Is returns true if passed attribute implements a body else false.

func (*Body) Marshal added in v0.0.16

func (b *Body) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Body) Remove added in v0.0.16

func (b *Body) Remove(t has.Thing)

Remove the passed Thing from all Body slots allocated to it. Cleared Body slots will also have their usage cleared.

func (*Body) RemoveAll added in v0.0.17

func (b *Body) RemoveAll()

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

func (*Body) Unmarshal added in v0.0.16

func (*Body) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Body attribute.

func (*Body) Usage added in v0.0.16

func (b *Body) Usage(t has.Thing) string

Usage returns a string describing the Body slot usage for the passed Thing. For example 'wielding' if the Thing is being wielded. If the passed Thing is not currently allocated to any Body slots an empty string will be returned.

func (*Body) UsedBy added in v0.0.16

func (b *Body) UsedBy(refs []string) (usedBy []has.Thing)

UsedBy returns a slice of unique Things, even if they are allocated to more than one slot, that are using the given slot references.

func (*Body) Using added in v0.0.16

func (b *Body) Using(t has.Thing) bool

Using returns true if at least one Body slot is allocated to the passed Thing else false.

func (*Body) Wear added in v0.0.16

func (b *Body) Wear(w has.Wearable) 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.

func (*Body) Wearing added in v0.0.16

func (b *Body) Wearing() []has.Thing

Wearing returns a unique slice of Things, even if they take up more than one Body slot, currently being worn on the Body. If nothing is being worn an empty slice will be returned.

func (*Body) Wield added in v0.0.16

func (b *Body) Wield(w has.Wieldable) bool

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.

func (*Body) Wielding added in v0.0.16

func (b *Body) Wielding() []has.Thing

Wielding returns a unique slice of Things, even if they take up more than one Body slot, currently being wielded by the Body. If nothing is being wielded an empty slice will be returned.

type Cleanup added in v0.0.5

type Cleanup struct {
	Attribute

	event.Cancel
	// contains filtered or unexported fields
}

Cleanup implements an Attribute for disposing of Things left laying around in the game world. When an item is dropped it will be cleaned up after a delay period has elapsed. Otherwise the world would get cluttered with items.

The delay period is between Cleanup.after and Cleanup.after+Cleanup.jitter. If a Thing is being cleaned up and is in its delay period the Cleanup.Cancel channel will be non-nil and the clean up may be aborted by closing the channel or by calling Cleanup.Abort which will cancel clean up requests recursively for a Thing.

SPECIFICS

If an item is put into any Inventory and the item ends up not being carried by a player - either in their Inventory or in a container in their Inventory - and the receiving inventory has no parent Inventory that are already scheduled for clean up then the item is scheduled for a clean up. If the item has an Inventory (a container) the contents do not need to be scheduled for clean up recursively as everything will be cleaned up when the item itself is cleaned up. This is also why we don't schedule a clean up when putting an item in an Inventory where a parent Inventory is scheduled for a clean up already.

If an item is removed from any Inventory any pending clean ups are cancelled. If the item has an Inventory its content - checked recursively - will have any pending clean ups cancelled. If we don't cancel pending clean ups recursively then putting an item into a container and then picking the container up would result in the item still being scheduled for a clean up, resulting in the item disappearing from the container.

func NewCleanup added in v0.0.5

func NewCleanup(after time.Duration, jitter time.Duration) *Cleanup

NewCleanup returns a new Cleanup attribute initialised with the passed after and jitter durations. The after and jitter Duration set the delay period to between after and after+jitter for when a Thing is cleaned up after being dropped.

func (*Cleanup) Abort added in v0.0.5

func (c *Cleanup) Abort()

Abort causes an outstanding clean up event to be cancelled for the parent Thing. If the Thing has an Inventory Abort is called on the contents recursively. If we don't do this putting an item into a container and then picking the container up would result in the item still being scheduled for a clean up and disappearing from the container.

func (*Cleanup) Active added in v0.0.5

func (c *Cleanup) Active() bool

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

func (*Cleanup) Cleanup added in v0.0.5

func (c *Cleanup) Cleanup()

Cleanup schedules a Cleanup event. If the Cleanup event is already queued it will be cancelled and a new one queued.

func (*Cleanup) Copy added in v0.0.5

func (c *Cleanup) Copy() has.Attribute

Copy returns a copy of the Cleanup receiver. If the Cleanup event is currently queued it will be suspended in the returned copy.

func (*Cleanup) Dump added in v0.0.5

func (c *Cleanup) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Cleanup) Found added in v0.0.5

func (c *Cleanup) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Cleanup) Free added in v0.0.5

func (c *Cleanup) Free()

Free makes sure references are nil'ed and queued events aborted when the Cleanup attribute is freed.

func (*Cleanup) Is added in v0.0.16

func (*Cleanup) Is(a has.Attribute) bool

Is returns true if passed attribute implements a cleanup else false.

func (*Cleanup) Marshal added in v0.0.9

func (c *Cleanup) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Cleanup) Pending added in v0.0.14

func (c *Cleanup) Pending() bool

Pending returns true if there is a Clean up event pending, else false. Use with caution as this could introduce a race between checking the state and acting on it as the event could fire between the two actions.

func (*Cleanup) Resume added in v0.0.16

func (c *Cleanup) Resume()

Resume a suspended Cleanup event, or do nothing if event not suspended.

func (*Cleanup) Suspend added in v0.0.16

func (c *Cleanup) Suspend()

Suspend a queued Cleanup event, or do nothing if event not queued.

func (*Cleanup) Unmarshal added in v0.0.5

func (*Cleanup) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Cleanup attribute.

type Description

type Description struct {
	Attribute
	// contains filtered or unexported fields
}

Description implements an attribute for describing Things. Things can have multiple descriptions or other attributes that implement the has.Description interface to add additional information to descriptions.

func NewDescription

func NewDescription(description string) *Description

NewDescription returns a new Description attribute initialised with the specified description.

func (*Description) Copy added in v0.0.4

func (d *Description) Copy() has.Attribute

Copy returns a copy of the Description receiver.

func (*Description) Description

func (d *Description) Description() string

Description returns the descriptive string of the attribute.

func (*Description) Dump

func (d *Description) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Description) Found

func (d *Description) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Description) Is added in v0.0.16

func (*Description) Is(a has.Attribute) bool

Is returns true if passed attribute implements a description else false.

func (*Description) Marshal added in v0.0.9

func (d *Description) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Description) Unmarshal

func (*Description) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Description attribute.

type Door added in v0.0.4

type Door struct {
	Attribute
	// contains filtered or unexported fields
}

Door implements an attribute for blocking exits. Doors are the most common way of blocking an exit but this attribute may relate to gates, grills, bookcases and other such obstacles.

A complete working door consists of two Thing each with a Door attribute. One is the original door and the other is the 'other side'. The original Door is added to the location with the exit to be blocked, the 'other side' is added to the location the exit to be blocked leads to. Taking the tavern entrance in data/zones/zinara.wrj as an example:

 _________________________________________
|L3                  |L5                  |
|    Tavern          #   Between Tavern   |
     Entrance        #   & Bakery
                     #
     (Door)          #   ('Other Side')
|                    #                    |   # = a door
|__                __|__                __|

Here we have locations L3 (Tavern Entrance) and L5 (Between Tavern * Bakery). Between them is the Tavern door. It is defined as:

%%
      Ref: L3N1
Narrative:
     Name: the tavern door
  Aliases: DOOR
     Door: EXIT→E RESET→1m JITTER→1m

This is a sturdy wooden door with a simple latch.
%%

This adds a Thing representing the door to L3 and blocks the exit going east (EXIT→E) to L5. During zone loading and Unmarshaling OtherSide is called on the original door Thing. This creates another Thing used for the 'Other Side'. It is added to the location found by taking the exit the original door is blocking, in this case we are blocking the east exit which leads to L5. The 'Other Side' is added to L5 and is setup to block the returning exit, in this case west - back to L3. Now in L3 if we do 'EXAMINE DOOR' we are examining the original, in L5 we are examining the 'Other Side' which appears to be the same door. Because the original and 'Other Side' share state be can also issue 'OPEN DOOR' or 'CLOSE DOOR' in either L3 or L5.

When the door is not in it's initial state it will reset after a delay of between 1 and 2 minutes. That is, sometime between delay and delay+jitter.

If delay and jitter are both zero the door will not reset automatically.

NOTE: For now a Door attribute should only be added to a Thing with a Narrative attribute that is placed at a location. Adding a Door attribute to a location directly or to a moveable object will result in odd - possibly interesting - behaviour.

func NewDoor added in v0.0.4

func NewDoor(direction byte, open bool, reset, jitter time.Duration) *Door

NewDoor returns a new Door attribute. The direction is the direction the door blocks - specified as per attr.Exit constants. Open specifies whether the door is initially open (true) or closed (false). The reset is the duration to wait before resetting the door to its initial state - open or closed as specified by open. The jitter is a random amount of time to add to the reset delay. Adding jitter means the Door will reset with an actual delay of between delay and delay+jitter.

This actually only creates one side of a door. To create the 'other side' of the door Door.OtherSide should be called.

func (*Door) Check added in v0.0.4

func (d *Door) Check(actor has.Thing, cmd ...string) has.Veto

Check will veto passing through a Door dynamically based on the command (direction) given and the current state of the Door - open or closed.

func (*Door) Close added in v0.0.4

func (d *Door) Close()

Close changes a Door state from open to closed. If there is a pending event to close the door it will be cancelled. If the door should automatically open again an event to "OPEN <door>" will be queued. If the door is already closed calling Close does nothing.

func (*Door) Closed added in v0.0.4

func (d *Door) Closed() bool

Closed returns true if the door is currently closed else false.

func (*Door) Copy added in v0.0.4

func (d *Door) Copy() has.Attribute

Copy returns a copy of the Door receiver. Copy will only copy a specific Door not an original and 'other side' pair - they have to be copied separately if required.

func (*Door) Description added in v0.0.4

func (d *Door) Description() string

func (*Door) Direction added in v0.0.4

func (d *Door) Direction() byte

Direction returns the direction of the exit being blocked. The returned value matches the constants defined in attr.Exits.

func (*Door) Dump added in v0.0.4

func (d *Door) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Door) Found added in v0.0.4

func (d *Door) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Door) Free added in v0.0.5

func (d *Door) Free()

Free makes sure references are nil'ed and channels closed when the Door attribute is freed.

func (*Door) Is added in v0.0.16

func (*Door) Is(a has.Attribute) bool

Is returns true if passed attribute implements a door else false.

func (*Door) Marshal added in v0.0.9

func (d *Door) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Door) Open added in v0.0.4

func (d *Door) Open()

Open changes a Door state from closed to open. If there is a pending event to open the door it will be cancelled. If the door should automatically close again an event to "CLOSE <door>" will be queued. If the door is already open calling Open does nothing.

func (*Door) Opened added in v0.0.4

func (d *Door) Opened() bool

Opened returns true if the door is currently open else false.

func (*Door) OtherSide added in v0.0.4

func (d *Door) OtherSide()

OtherSide creates the 'other side' of a Door and places it in the World. The 'other side' will be placed in the Inventory found by following the exit that is being blocked by the original Door. Creating the 'other side' will fail if:

  • The original Door attribute has not been added to a Thing
  • The parent Thing of the original Door is not in an Inventory (e.g. location)
  • The parent Thing of the Inventory the parent Thing of the Door is in has no Exits
  • There is no exit in the direction the door is supposed to be blocking

For more details see the attr.Door type.

func (*Door) Unmarshal added in v0.0.4

func (*Door) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Door attribute.

type Exits

type Exits struct {
	Attribute
	// contains filtered or unexported fields
}

Exits implements an attribute describing exits for the eight compass points north, northeast, east, southeast, south, southwest, west and northwest as well as the directions up and down and where they lead to. Exits are usually in pairs, for example one north and one back south. You can have one way exits or return exits that do not lead back to where you came from.

func NewExits

func NewExits() *Exits

NewExits returns a new Exits attribute with no exits set. Exits should be added to the attribute using the Link and AutoLink methods. The reason exits cannot be set during initialisation like most other attributes is that all 'locations' have to be setup before they can all be linked together.

func (e *Exits) AutoLink(direction byte, to has.Inventory)

AutoLink links the given exit, calculates the opposite return exit and links that automatically as well - as long as the parent Thing of the to Inventory has an Exits attribute.

func (e *Exits) AutoUnlink(direction byte)

AutoUnlink unlinks the given exit, calculates the opposite return exit and unlinks that automatically as well.

BUG(diddymus): Does not check that exit A links to B and B links back to A. For example a maze may have an exit going North from A to B but going South from B takes you to C instead of back to A as would be expected!

func (*Exits) Copy added in v0.0.4

func (e *Exits) Copy() has.Attribute

Copy returns a copy of the Exits receiver.

func (*Exits) Dump

func (e *Exits) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Exits) Found

func (e *Exits) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Exits) Free added in v0.0.5

func (e *Exits) Free()

Free makes sure references are nil'ed when the Exits attribute is freed.

func (*Exits) Is added in v0.0.16

func (*Exits) Is(a has.Attribute) bool

Is returns true if passed attribute implements exits else false.

func (*Exits) LeadsTo

func (e *Exits) LeadsTo(direction byte) has.Inventory

LeadsTo returns the Inventory of the location found by taking a specific exit. If a particular direction leads nowhere nil will be returned.

func (e *Exits) Link(direction byte, to has.Inventory)

Link links the given exit direction to the given Inventory. If the given direction was already linked the exit will be overwritten - in effect the same as unlinking the exit first and then relinking it.

func (*Exits) List

func (e *Exits) List() string

List will return a string listing the exits you can see. For example:

You can see exits east, southeast and south.

func (*Exits) Marshal added in v0.0.9

func (e *Exits) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Exits) NormalizeDirection

func (*Exits) NormalizeDirection(name string) (direction byte, err error)

NormalizeDirection takes a long or short variant of a direction name in any case and returns the direction.

So 'N', 'NORTH', 'n', 'north', 'North' and 'NoRtH' all return the constant NORTH which is 0.

If the direction name given cannot be normalized, maybe because it is invalid, a non-nil error will be returned.

func (*Exits) Surrounding

func (e *Exits) Surrounding() []has.Inventory

Surrounding returns an Inventory slice of all locations immediatly reachable from the current location. The cuurent location is specified by the receiver. If there are no immediatly reachable locations an empty slice will be returned.

func (*Exits) ToName

func (*Exits) ToName(direction byte) (name string)

ToName returns the lowercased long name of a direction or an empty string if the direction is invalid.

func (e *Exits) Unlink(direction byte)

Unlink sets the exit for the given direction to nil. It does not matter if the given direction was not linked in the first place.

func (*Exits) Unmarshal

func (*Exits) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Exits attribute.

func (*Exits) Within

func (e *Exits) Within(moves int, from has.Inventory) (locations [][]has.Inventory)

Within returns all of the locations within the given number of moves from the location specified by from Inventory. It is 3D and will follow up and down exits as well. The locations 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.

Assume the following map of the Tavern and surrounding locations:

 ____________________________________________________________
|1             |3             |5              |6             |
|  Fireplace       Entrance     Between           Bakery     |
|                               Tavern/Bakery                |
|__                         __|__           __|______________|
|2              4             |7              |8             |
|  Common Room     Bar        | Street outside    Pawn Shop  |
|                             | Pawn Shop                    |
|______________|______________|__           __|______________|
               |10            |9              |
               |   Outside      Fountain      |
               |   Armourer     Square        |
               |______________|_______________|

If we are at location 7 on the map then Within(2) will return all locations within 2 moves:

 [][]has.Inventory{
	[]has.Inventory{ 7 },					// Within 0 moves of location 7
	[]has.Inventory{ 5, 8, 9 },   // Within 1 move of location 7
	[]has.Inventory{ 6, 3, 10 },  // Within 2 moves of location 7
 }

The above numbers e.g. 5,8,9 refer to the map locations. In reality they would actually be references to has.Inventory interface types.

If there are no Inventories reachable at a given number of moves the slice indexed with have zero length.

See cmd/sneeze.go for an example of using the Within method.

type Gender added in v0.0.9

type Gender struct {
	Attribute
	// contains filtered or unexported fields
}

Gender implements an attribute for specifying the gender of a Thing. If a Thing does not have a specific gender attribute the gender will be the non-specific 'It'.

func NewGender added in v0.0.9

func NewGender(gender string) *Gender

NewGender returns a gender attribute initialised to the specified gender. The gender can be specified using an upper, lower or title cased string. An upper or lower case 'M' or 'F' is also understood. If the gender specified is not valid the gender will default to a non-specific 'It'.

func (*Gender) Copy added in v0.0.9

func (g *Gender) Copy() has.Attribute

Copy returns a copy of the Gender receiver.

func (*Gender) Dump added in v0.0.9

func (g *Gender) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Gender) Found added in v0.0.9

func (g *Gender) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Gender) Gender added in v0.0.9

func (g *Gender) Gender() string

Gender returns the gender stored in the attribute as a title-cased string. If the receiver is nil a non-specific "It" will be returned.

func (*Gender) Is added in v0.0.16

func (*Gender) Is(a has.Attribute) bool

Is returns true if passed attribute implements gender else false.

func (*Gender) Marshal added in v0.0.9

func (g *Gender) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Gender) Unmarshal added in v0.0.9

func (*Gender) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Gender attribute.

type Health added in v0.0.16

type Health struct {
	Attribute
	// contains filtered or unexported fields
}

Health implements an attribute representing either the state of health of a Thing or health bonuses/penalities to be applied to a Thing. If the Health attribute is on a Player or Mobile then the values are absolute and represent current and maximum health levels of the Player or Mobile. If the Health attribute is on anything else the values are relative modifiers applied to a Player or Mobile when the Thing is used, worn, wielded, eaten, drunk or otherwise applied.

func NewHealth added in v0.0.16

func NewHealth(current, maximum, regens int, frequency int64) *Health

NewHealth returns a new Health attribute. If the Health attribute is added to a Player the current, maximum, regens and frequency (in seconds) values are absolute values representing the base values of the Player. Otherwise the values are relative and modify a Player's base values when applicable.

The frequency is how often (in seconds) health regenerates. So a value of 10 is every 10 seconds while a value of 90 is every 1 minute 30 seconds. Smaller values increase the number of updates while larger values decrease the number of updates - for a given period of time.

For example a ring of healing may have frequency=-5 and regens=+2 to increase the frequency the Player regenerates health and increase the amount they regenerate - so the Player regenerates more health quicker - but the effects only apply when the ring is being worn by the Player.

func (*Health) Adjust added in v0.0.16

func (h *Health) Adjust(amount 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.

func (*Health) AutoUpdate added in v0.0.16

func (h *Health) AutoUpdate(enable bool)

AutoUpdate enables or disables the automatic regeneration of the current health points.

func (*Health) Copy added in v0.0.16

func (h *Health) Copy() has.Attribute

Copy returns a copy of the Health receiver.

func (*Health) Dump added in v0.0.16

func (h *Health) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Health) Found added in v0.0.16

func (n *Health) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Health) Is added in v0.0.16

func (*Health) Is(a has.Attribute) bool

Is returns true if passed attribute implements Health else false.

func (*Health) Marshal added in v0.0.16

func (h *Health) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Health) Prompt added in v0.0.16

func (h *Health) Prompt(style has.PromptStyle) (prompt []byte)

Prompt returns Health information appropriate for the prompt style. The information may contain the current health and maximum health.

If the current health is included it is colour coded based on the percentage of maximum health:

 Green: > 75%
Yellow: 25%-75%
   Red: < 25%

The current health is also left padded with spaces, if needed, so that when the number of digits change the prompt does not jump around.

func (*Health) State added in v0.0.16

func (h *Health) State() (current, maximum int)

State returns the current and maximum health points.

func (*Health) Unmarshal added in v0.0.16

func (*Health) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Health attribute.

type Holdable added in v0.0.16

type Holdable struct {
	Attribute
	// contains filtered or unexported fields
}

Holdable implements an attribute for specifying body slots required when holding a Thing. Holdable will veto the JUNK command so that items being held are not accidentally junked and disposed of.

Unlike Wieldable and Wearable types any Thing that is not a player or mobile, does not have a Body attribute, is always Holdable in one hand.

This can be overridden by adding a specific Holdable attribute - for example if two hands are required to hold the Thing:

Holdable: HAND→2

Or if you want to be able to hold a small animal in one hand:

Holdable: HAND

If an item should not be holdable at all the HOLD command can be vetoed.

func NewHoldable added in v0.0.16

func NewHoldable(slots ...string) *Holdable

NewHoldable returns a new Holdable attribute initialised with the passed Body slot references. Any Thing with a Holdable attribute can be held by a player or mobile provided they have the specified Body slots available.

func (*Holdable) Check added in v0.0.16

func (h *Holdable) Check(actor has.Thing, cmd ...string) has.Veto

Check will veto the JUNK command if the Thing is currently held.

func (*Holdable) Copy added in v0.0.16

func (h *Holdable) Copy() has.Attribute

Copy returns a copy of the Holdable receiver.

func (*Holdable) Dump added in v0.0.16

func (h *Holdable) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Holdable) Found added in v0.0.16

func (h *Holdable) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Holdable) Is added in v0.0.16

func (*Holdable) Is(a has.Attribute) bool

Is returns true if passed attribute implements a holdable item else false.

func (*Holdable) IsHoldable added in v0.0.16

func (h *Holdable) IsHoldable() bool

IsHoldable returns true.

func (*Holdable) Marshal added in v0.0.16

func (h *Holdable) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Holdable) Slots added in v0.0.16

func (w *Holdable) Slots() []string

Slots returns the Body slot references that need to be available to hold the Thing. The returned slice should not be modified.

func (*Holdable) Unmarshal added in v0.0.16

func (*Holdable) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Holdable attribute.

type Holding added in v0.0.17

type Holding struct {
	Attribute
	// contains filtered or unexported fields
}

Holding implements an attribute representing items that are being held by a Thing.

BUG(diddymus): At the moment the Holding attribute only represents the initial state of items being held when a Thing is unmarshaled - it is not dynamically updated as items are held and removed.

func NewHolding added in v0.0.17

func NewHolding(ref ...string) *Holding

NewHolding returns a Holding attribute initialised with the passed references. The references should be those returned by Thing.Ref(), which are normally the content of the Ref field from the record jar the Thing was loaded from.

func (*Holding) Copy added in v0.0.17

func (h *Holding) Copy() has.Attribute

Copy returns a copy of the Holding receiver.

func (*Holding) Dump added in v0.0.17

func (h *Holding) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Holding) Found added in v0.0.17

func (h *Holding) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Holding) Held added in v0.0.17

func (h *Holding) Held() []string

Held returns a string slice of Thing references for items that are being held.

func (*Holding) Is added in v0.0.17

func (*Holding) Is(a has.Attribute) bool

Is returns true if passed attribute implements holding else false.

func (*Holding) Marshal added in v0.0.17

func (h *Holding) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Holding) Unmarshal added in v0.0.17

func (*Holding) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Holding attribute.

type Inventory

type Inventory struct {
	Attribute

	internal.BRL
	// contains filtered or unexported fields
}

Inventory implements an attribute for container inventories. The most common container usage is for locations and rooms as well as actual containers like bags, boxes and inventories for players and mobiles. WolfMUD does not actually define a specific type for locations. Locations are simply Things that have an Exits attribute.

Any Thing added to an Inventory will automatically be assigned a Locate attribute. A locate attribute is simply a back reference to the Inventory a Thing is in. This enables a Thing to work out where it is.

A Thing in an Inventory may be disabled and taken out of play or enabled and put back into play. A disabled Thing is inaccessible to players but is still covered by the Inventory lock. This is so that any Thing can always be covered by a lock in an Inventory. An example usage of disabling/enabling a Thing is when an item is cleaned up and needs to be reset. In this case the clean up event triggering would cause the Thing to be moved to its origin Inventory and then disabling the Thing would cause it to go out of play. When the reset event triggers the Thing would be enabled and brought back into play.

BUG(diddymus): Inventory capacity is not implemented yet.

func NewInventory

func NewInventory(t ...has.Thing) *Inventory

NewInventory returns a new Inventory attribute initialised with the specified Things as initial contents. All of the Thing added will be enabled and in play - although the Thing itself may not be enabled and in play.

func (*Inventory) Add

func (i *Inventory) Add(t has.Thing)

Add puts a Thing into an Inventory marking at as being initially out of play. The Locate attribute of the Thing will be updated to reference the Inventory the Thing is put into. If the Thing does not have a Locate attribute one will be added. The Thing may be enabled and put in play by calling Enable.

func (*Inventory) Carried added in v0.0.5

func (i *Inventory) Carried() bool

Carried returns true if putting an item into the Inventory would result in it being carried by a player, otherwise false. The Inventory can be the player's actual Inventory or the Inventory of a container (checked recursively) in the player's inventory.

TODO: Need to check for players or mobiles

func (*Inventory) Contents

func (i *Inventory) Contents() (l []has.Thing)

Contents returns a list of items in an Inventory. The items may be indirectly manipulated through the slice. Items should be added to, or removed from the Inventory using the Add and Remove methods.

See also the Players, Narratives and Everything methods.

func (*Inventory) Copy added in v0.0.4

func (i *Inventory) Copy() has.Attribute

Copy returns a copy of the Inventory receiver. The copy will be made recursively copying the complete content of the Inventory as well.

NOTE: There are no checks made for cyclic references which could send us into infinite recursion. However cyclic references should be prevented by the zone loader. See zones.isParent function.

func (*Inventory) Crowded

func (i *Inventory) Crowded() (crowded bool)

Crowded tests to see if an Inventory has so many players in it that it is considered crowded. If the Inventory is considered crowded true is returned otherwise false. An Inventory is considered crowded if there are more than config.Inventory.CrowdSize players in it.

func (*Inventory) Disable added in v0.0.7

func (i *Inventory) Disable(t has.Thing)

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

func (*Inventory) Disabled added in v0.0.7

func (i *Inventory) Disabled() (l []has.Thing)

func (*Inventory) Dump

func (i *Inventory) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Inventory) Empty

func (i *Inventory) Empty() bool

Empty returns true if there are no non-Narrative items else false.

func (*Inventory) Enable added in v0.0.7

func (i *Inventory) Enable(t has.Thing)

Enabled marks a Thing in an Inventory as being in play.

func (*Inventory) Everything added in v0.0.12

func (i *Inventory) Everything() (l []has.Thing)

Everything returns a list of all Players, Content and Narratives in an Inventory. The items may be indirectly manipulated through the slice. Items should be added to, or removed from the Inventory using the Add and Remove methods.

See also the Players, Contents and Narratives methods.

func (*Inventory) Found

func (i *Inventory) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Inventory) Free added in v0.0.5

func (i *Inventory) Free()

Free recursively calls Free on all of it's content when the Inventory attribute is freed.

func (*Inventory) Is added in v0.0.16

func (*Inventory) Is(a has.Attribute) bool

Is returns true if passed attribute implements an inventory else false.

func (*Inventory) List

func (i *Inventory) List() string

List returns a string describing the non-narrative contents of an Inventory. The layout of the description returned is dependant on the number of items. If the Inventory is empty and the Parent Thing has a narrative attribute we return nothing. Otherwise if the Inventory is empty we return:

It is empty.

A single item only we return:

It contains xxx.

For multiple items we return:

It contains:
	Item
	Item
	Item
	...

If the inventory cannot be listed an empty string will be returned.

func (*Inventory) Marshal added in v0.0.9

func (i *Inventory) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Inventory) Move added in v0.0.5

func (i *Inventory) Move(t has.Thing, where has.Inventory)

Move removes an enabled Thing from the receiver Inventory and puts it into the 'where' Inventory. After the move the Thing's Locate attribute will be updated to reflect the new Inventory it is in.

func (*Inventory) Narratives added in v0.0.4

func (i *Inventory) Narratives() (l []has.Thing)

Narratives returns a list of narrative items in an Inventory. The items may be indirectly manipulated through the slice. Items should be added to, or removed from the Inventory using the Add and Remove methods.

See also the Players, Contents and Everything methods.

func (*Inventory) Occupied added in v0.0.14

func (i *Inventory) Occupied() bool

Occupied returns true if there is at least one player in the Inventory.

func (*Inventory) Outermost added in v0.0.7

func (i *Inventory) Outermost() has.Inventory

Outermost returns the top level inventory in an Inventory hierarchy.

func (*Inventory) Players added in v0.0.6

func (i *Inventory) Players() (l []has.Thing)

Players returns a list of Players in an Inventory. The players may be indirectly manipulated through the slice. Players should be added to, or removed from the Inventory using the Add and Remove methods.

See also the Contents, Narratives and Everything methods.

func (*Inventory) Remove

func (i *Inventory) Remove(t has.Thing)

Remove takes a disabled Thing out of an Inventory.

NOTE: Once the Thing is removed it will no longer be under a lock. Ideally once a Thing is removed Thing.Free should be called to release the Thing for garbage collection.

func (*Inventory) Search

func (i *Inventory) Search(alias string) has.Thing

Search returns the first Inventory Thing that matches the alias passed. If no matches are found nil is returned.

func (*Inventory) SearchByRef added in v0.0.17

func (i *Inventory) SearchByRef(ref string) has.Thing

SearchByRef returns the first Inventory Thing that matches the reference passed. If no matches are found returns nil.

func (*Inventory) SearchDisabled added in v0.0.17

func (i *Inventory) SearchDisabled(alias string) has.Thing

SearchDisabled returns the first disabled Inventory Thing that matches the alias passed. If no matches are found nil is returned.

func (*Inventory) Unmarshal

func (*Inventory) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Inventory attribute.

type Locate

type Locate struct {
	Attribute
	// contains filtered or unexported fields
}

Locate implements an attribute that refers to the Inventory of where something is. When a Thing is added to an Inventory a Locate attribute will be added automatically if the Thing does not already have one. When a Thing is added to or removed from an Inventory the Locate.SetWhere method is called to update the reference. See inventory.Add for more details. Locate also records the initial starting position or origin of a Thing. Concurrent access of a Locate attribute is safe.

func NewLocate

func NewLocate(i has.Inventory) *Locate

NewLocate returns a new Locate attribute initialised to refer to the passed Inventory. Passing nil is a valid reference and is usually treated as being nowhere.

func (*Locate) Copy added in v0.0.4

func (l *Locate) Copy() has.Attribute

Copy returns a copy of the Locate receiver.

func (*Locate) Dump

func (l *Locate) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Locate) Found

func (l *Locate) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Locate) Free added in v0.0.5

func (l *Locate) Free()

Free makes sure references are nil'ed when the Locate attribute is freed.

func (*Locate) Is added in v0.0.16

func (*Locate) Is(a has.Attribute) bool

Is returns true if passed attribute implements locate else false.

func (*Locate) Marshal added in v0.0.9

func (*Locate) Marshal() (string, []byte)

Marshal returns a tag and []byte that represents the receiver. In this case we return empty values as the Locate attribute is not persisted.

func (*Locate) Origin added in v0.0.5

func (l *Locate) Origin() (origin has.Inventory)

Origin return the initial starting Inventory that a Thing is placed into.

func (*Locate) SetOrigin added in v0.0.5

func (l *Locate) SetOrigin(i has.Inventory)

SetOrigin is use to specify the initial starting Inventory that a Thing is placed into.

func (*Locate) SetWhere

func (l *Locate) SetWhere(i has.Inventory)

SetWhere is used to set the Inventory containing the parent Thing. Passing nil is a valid reference and is usually treated as being nowhere. The current reference can be retrieved by calling Where.

NOTE: This is called automatically by the Inventory Add and Remove methods.

func (*Locate) Unmarshal

func (*Locate) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Locate attribute. At the moment Locate attributes are created internally so return an untyped nil so we get ignored.

func (*Locate) Where

func (l *Locate) Where() (where has.Inventory)

Where returns the Inventory the parent Thing is in. Returning nil is a valid reference and is usually treated as being nowhere. The current Inventory is set by calling SetWhere.

type Name

type Name struct {
	Attribute
	// contains filtered or unexported fields
}

Name implements an attribute for giving a Thing a short name. The name should generally start with 'a', 'an' or 'some' except for proper names. For example: an apple, some apples, an orange, Diddymus.

func NewName

func NewName(n string) *Name

Name implements an attribute for naming Things. It is used when referring to or listing Things. For example if there is a sword it could have the name of 'a sword'. Then manipulating it you could see the following messages:

You see a sword here.
You pick up a sword.
You examine a sword.
You start to wield a sword.

Messages such as the examples would typically be general messages with a placeholder for the name of the Thing. For example:

You see %s here.
You pick up %s.
You examine %s.
You start to wield %s.

It is therefore important to take this into consideration when choosing names for Things.

func (*Name) Copy added in v0.0.4

func (n *Name) Copy() has.Attribute

Copy returns a copy of the Name receiver.

func (*Name) Dump

func (n *Name) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Name) Found

func (n *Name) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Name) Is added in v0.0.16

func (*Name) Is(a has.Attribute) bool

Is returns true if passed attribute implements a name else false.

func (*Name) Marshal added in v0.0.9

func (n *Name) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Name) Name

func (n *Name) Name(preset string) string

Name returns the name stored in the attribute. If the receiver is nil or the name is an empty string the specified preset will be returned instead. This allows for a generic preset name such as someone, something or somewhere to be returned for things without names.

func (*Name) TheName added in v0.0.12

func (n *Name) TheName(preset string) string

TheName returns the name stored in the attribute, as per Name, but with the leading "A ", "An " or "Some " changed to "The ". The case of the 't' in 'the' is the same as the case of word replaced. For example:

     A frog -> The frog
     a frog -> the frog
   An apple -> The apple
   an apple -> the apple
Some apples -> The apples
some apples -> the apples

func (*Name) Unmarshal

func (*Name) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Name attribute.

type Narrative

type Narrative struct {
	Attribute
}

Narrative implements an attribute to mark non-removable content. It allows creators to cater to the more discerning adventurer by providing content that is not spoon fed to them. Narrative content is usually mentioned or discoverable from text descriptions. For example:

You are in the corner of a common room in the Dragon's Breath tavern. There
is a fire burning away merrily in an ornate fireplace giving comfort to
weary travellers. Shadows flicker around the room, changing light to
darkness and back again. To the south the common room extends and east the
common room leads to the tavern entrance.

From such a description it would be reasonable for someone to want to example the fireplace although there would be no "You see a fireplace here." when listing the items at the location. Should someone try to examine the fireplace they are rewarded with:

This is a very ornate fireplace carved from marble. Either side a dragon
curls downward until the head is below the fire looking upward, giving the
impression that they are breathing fire.

While anything that can normally be put into an inventory can be put into a narrative, nothing should be directly removable. However everything in a narrative still works as expected - readable things are still readable and containers can have things put in them as well as removed. As an example consider this brief description:

You are standing next to a small fish pond. Paths lead off north, south and
west deeper into the gardens.

Examining the pond - in this case a simple inventory - reveals its content:

This is a small fish pond. It contains a fish of gold.

Taking the fish from the pond and examining it reveals:

This is a small fish made from solid gold.

A much more satisfying reward for being curious :)

NOTE: At the moment narrative content should not be removeable for the simple reason that descriptions are mostly static - for now(?). So removing something would therefore invalidate the descriptive text.

func NewNarrative

func NewNarrative() *Narrative

NewNarrative returns a new Narrative attribute.

func (*Narrative) Copy added in v0.0.4

func (n *Narrative) Copy() has.Attribute

Copy returns a copy of the Narrative receiver.

func (*Narrative) Dump

func (n *Narrative) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Narrative) Found

func (n *Narrative) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Narrative) ImplementsNarrative

func (*Narrative) ImplementsNarrative()

ImplementsNarrative is a marker method so that we can specifically identify a Narrative.

func (*Narrative) Is added in v0.0.16

func (*Narrative) Is(a has.Attribute) bool

Is returns true if passed attribute implements a narrative else false.

func (*Narrative) Marshal added in v0.0.9

func (n *Narrative) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Narrative) Unmarshal

func (*Narrative) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Narrative attribute.

type OnAction added in v0.0.6

type OnAction struct {
	Attribute
	// contains filtered or unexported fields
}

OnAction implements an attribute to provide action messages for a Thing.

func NewOnAction added in v0.0.6

func NewOnAction(actions []string) *OnAction

NewOnAction returns a new OnAction attribute initialised with the specified messages.

func (*OnAction) ActionText added in v0.0.6

func (oa *OnAction) ActionText() string

ActionText returns a random action message for a Thing. The message is chosen from the list of messages available.

func (*OnAction) Copy added in v0.0.6

func (oa *OnAction) Copy() has.Attribute

Copy returns a copy of the OnAction receiver.

func (*OnAction) Dump added in v0.0.6

func (oa *OnAction) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*OnAction) Found added in v0.0.6

func (oa *OnAction) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*OnAction) Is added in v0.0.16

func (*OnAction) Is(a has.Attribute) bool

Is returns true if passed attribute implements an 'on action' else false.

func (*OnAction) Marshal added in v0.0.9

func (oa *OnAction) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*OnAction) Unmarshal added in v0.0.6

func (*OnAction) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new OnAction attribute.

type OnCleanup added in v0.0.6

type OnCleanup struct {
	Attribute
	// contains filtered or unexported fields
}

OnCleanup implements an attribute to provide a clean up message for a Thing.

func NewOnCleanup added in v0.0.6

func NewOnCleanup(text string) *OnCleanup

NewOnCleanup returns a new OnCleanup attribute initialised with the specified message.

func (*OnCleanup) CleanupText added in v0.0.6

func (oc *OnCleanup) CleanupText() string

CleanupText returns the clean up message to be used for a Thing.

func (*OnCleanup) Copy added in v0.0.6

func (oc *OnCleanup) Copy() has.Attribute

Copy returns a copy of the OnCleanup receiver.

func (*OnCleanup) Dump added in v0.0.6

func (oc *OnCleanup) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*OnCleanup) Found added in v0.0.6

func (oc *OnCleanup) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*OnCleanup) Is added in v0.0.16

func (*OnCleanup) Is(a has.Attribute) bool

Is returns true if passed attribute implements an 'on cleanup' else false.

func (*OnCleanup) Marshal added in v0.0.9

func (oc *OnCleanup) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*OnCleanup) Unmarshal added in v0.0.6

func (*OnCleanup) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new OnCleanup attribute.

type OnReset added in v0.0.6

type OnReset struct {
	Attribute
	// contains filtered or unexported fields
}

OnReset implements an attribute to provide a reset or respawn message for a Thing.

func NewOnReset added in v0.0.6

func NewOnReset(text string) *OnReset

NewOnReset returns a new OnReset attribute initialised with the specified message.

func (*OnReset) Copy added in v0.0.6

func (or *OnReset) Copy() has.Attribute

Copy returns a copy of the OnReset receiver.

func (*OnReset) Dump added in v0.0.6

func (or *OnReset) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*OnReset) Found added in v0.0.6

func (or *OnReset) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*OnReset) Is added in v0.0.16

func (*OnReset) Is(a has.Attribute) bool

Is returns true if passed attribute implements an 'on reset' else false.

func (*OnReset) Marshal added in v0.0.9

func (or *OnReset) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*OnReset) ResetText added in v0.0.6

func (or *OnReset) ResetText() string

ResetText returns the reset or respawn message to be used for a Thing.

func (*OnReset) Unmarshal added in v0.0.6

func (*OnReset) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new OnReset attribute.

type Player

type Player struct {
	Attribute
	io.Writer
	has.PromptStyle
	// contains filtered or unexported fields
}

Player implements an attribute for associating a Thing with a Writer used to return data to the associated client.

func NewPlayer

func NewPlayer(w io.Writer) *Player

NewPlayer returns a new Player attribute initialised with the specified Writer which is used to send data back to the associated client.

func (*Player) Account added in v0.0.9

func (p *Player) Account() *account

Account returns the account information for a player. This can be used to Marshal, Unmarshal or set a player's account information.

func (*Player) Check added in v0.0.6

func (p *Player) Check(actor has.Thing, cmds ...string) has.Veto

Check will always veto a player being junked and trying to use player as a container.

func (*Player) Copy added in v0.0.4

func (p *Player) Copy() has.Attribute

Copy returns a copy of the Player receiver.

NOTE: The copy will use the same io.Writer as the original.

func (*Player) Dump

func (p *Player) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Player) Found

func (p *Player) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Player) Free added in v0.0.5

func (p *Player) Free()

Free makes sure references are nil'ed when the Player attribute is freed.

func (*Player) Is added in v0.0.16

func (*Player) Is(a has.Attribute) bool

Is returns true if passed attribute implements a player else false.

func (*Player) Marshal added in v0.0.9

func (*Player) Marshal() (string, []byte)

Marshal returns a tag and []byte that represents the receiver. In this case we return empty values as the Player attribute is not persisted.

func (*Player) SetPromptStyle

func (p *Player) SetPromptStyle(new has.PromptStyle) (old has.PromptStyle)

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.

func (*Player) Unmarshal

func (*Player) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Player attribute. At the moment Player attributes are created internally so return an untyped nil so we get ignored.

func (*Player) Write

func (p *Player) Write(b []byte) (n int, err error)

Write appends the current prompt to a copy of the passed []byte and writes the resulting []byte to the Player.

type Reset added in v0.0.5

type Reset struct {
	Attribute

	event.Cancel
	// contains filtered or unexported fields
}

Reset implements an Attribute for resetting or respawning Things in the game world. When a Thing is disposed of in the game world it may need to be reset and placed back into the game world at it's initial starting position after a delay period has elapsed. Otherwise the world quickly becomes empty with little for players to do. Some Thing's may respawn instead of resetting. When a Thing respawns another copy of the Thing is placed into the game world after a period of time when the Thing is taken. For both cases the delay period will be between Reset.after and Reset.after+Reset.jitter. If a Thing is being reset/respawned and is in its delay period the Reset.Cancel channel will be non-nil and the reset/respawn may be aborted by closing the channel. If Reset.spawn is true the Thing is respawnable otherwise it is resettable. Items that should just be removed when disposed of should not have a Reset attribute.

func NewReset added in v0.0.5

func NewReset(after, jitter time.Duration, spawn, wait bool) *Reset

Reset implements an attribute for resetting or respawning Things and putting them back into the game world. The after and jitter Duration set the delay period to between after and after+jitter for when a Thing is reset or respawned. If spawn is true the Thing will respawn otherwise it will reset. If wait is true the Thing will wait until child inventory Thing are ready to reset before resetting.

func (*Reset) Abort added in v0.0.8

func (r *Reset) Abort()

Abort a queued Reset event, or do nothing if event not queued.

func (*Reset) Copy added in v0.0.5

func (r *Reset) Copy() has.Attribute

Copy returns a copy of the Reset receiver. If the Reset event is currently queued it will be suspended in the returned copy.

func (*Reset) Dump added in v0.0.5

func (r *Reset) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Reset) Found added in v0.0.5

func (r *Reset) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Reset) Free added in v0.0.5

func (r *Reset) Free()

Free makes sure references are nil'ed and queued events aborted when the Reset attribute is freed.

func (*Reset) Is added in v0.0.16

func (*Reset) Is(a has.Attribute) bool

Is returns true if passed attribute implements a reset else false.

func (*Reset) IsSpawned added in v0.0.16

func (r *Reset) IsSpawned() bool

IsSpawned returns true if the Thing has been spawned else false.

func (*Reset) Marshal added in v0.0.9

func (r *Reset) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Reset) Pending added in v0.0.14

func (r *Reset) Pending() bool

Pending returns true if there is a Reset event pending, else false. Use with caution as this could introduce a race between checking the state and acting on it as the event could fire between the two actions.

func (*Reset) Reset added in v0.0.5

func (r *Reset) Reset()

Reset schedules a Reset event. If the Reset event is already queued it will be cancelled and a new one queued.

func (*Reset) Resume added in v0.0.16

func (r *Reset) Resume()

Resume a suspended Reset event, or do nothing if event not suspended.

func (*Reset) Spawn added in v0.0.5

func (r *Reset) Spawn() has.Thing

Spawn returns a non-spawnable copy of a spawnable Thing and schedules the original Thing to reset if Reset.spawn is true. Otherwise it returns nil.

If a new item is spawned then the Inventory of the original is processed. Unique and non-spawnable items are moved from the original to the copy. Copies of spawnable content are made and the original spawnable content is disabled and a reset scheduled. This processing is recursive.

func (*Reset) Spawnable added in v0.0.16

func (r *Reset) Spawnable() bool

Spawnable returns true if the parent Thing is spawnable else false.

func (*Reset) Spawned added in v0.0.16

func (r *Reset) Spawned()

Spawned flags the Thing as being a spawned item.

func (*Reset) Suspend added in v0.0.16

func (r *Reset) Suspend()

Suspend a queued Reset event, or do nothing if event not queued.

func (*Reset) Unique added in v0.0.16

func (r *Reset) Unique() bool

Unique returns true if item is considered unique else false. For an item to be unique it must be resetable and must not be spawnable.

NOTE: An item without a reset is technically not unique as it is the byproduct of an item spawning and hence a copy of that item.

func (*Reset) Unmarshal added in v0.0.5

func (*Reset) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Reset attribute.

func (*Reset) Wait added in v0.0.17

func (r *Reset) Wait() bool

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

type Start

type Start struct {
	Attribute
}

Start implements an attribute for tagging a Thing as a starting location.

func NewStart

func NewStart() *Start

NewStart returns a new Start attribute. When a new Start attribute is created it is also registered automatically.

TODO: Implement starting locations that are only usable by specific players. For example only dwarves should start in the dwarven home, or thieves in the thieves guild.

func (*Start) Copy added in v0.0.4

func (s *Start) Copy() has.Attribute

Copy returns a copy of the Start receiver.

func (*Start) Dump

func (s *Start) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Start) Found

func (s *Start) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Start) Free added in v0.0.13

func (s *Start) Free()

Free deregisters the Start attribute when it is freed.

func (*Start) Is added in v0.0.16

func (*Start) Is(a has.Attribute) bool

Is returns true if passed attribute implements a starting location else false.

func (*Start) Marshal added in v0.0.9

func (*Start) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Start) Pick

func (*Start) Pick() has.Inventory

Pick returns the Inventory of a randomly selected starting location.

func (*Start) Unmarshal

func (*Start) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Start attribute.

type Thing

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

Thing is a container for Attributes. Everything in WolfMUD is constructed by creating a Thing and then adding Attributes to it which implement specific functionality. Concurrent access to a Thing is safe.

func NewThing

func NewThing(a ...has.Attribute) *Thing

NewThing returns a new Thing initialised with the specified Attributes. Attributes can also be dynamically modified using Add and Remove methods. If Debug.Things is true a message will be written to the log indicating a new Thing has been created. A finalizer will also be registered to write a message when the thing is garbage collected.

func (*Thing) Add

func (t *Thing) Add(a ...has.Attribute)

Add is used to add the passed Attributes to a Thing. When an Attribute is added its parent is set to reference the Thing it was added to. This allows an Attribute to find and query the parent Thing about other Attributes the Thing may have.

func (*Thing) Collectable added in v0.0.9

func (t *Thing) Collectable() bool

Collectable returns true if a Thing can be kept by a player, otherwise returns false. This is a helper routine so that the definition of what is considered collectable can be easily changed.

func (*Thing) Copy added in v0.0.4

func (t *Thing) Copy() has.Thing

Copy returns a copy of the Thing receiver. Associated Attributes will be copied. However, the copy is not recursive and will not copy the content of Inventory. To make a copy that includes Inventory content the DeepCopy method should be used instead.

BUG(diddymus): This method specifically checks for a *attr.Inventory, which is currently the only implementation of has.Inventory - if this changes this method will need updating.

func (*Thing) DeepCopy added in v0.0.16

func (t *Thing) DeepCopy() has.Thing

DeepCopy returns a copy of the Thing receiver recursing into Inventory. The copy will be made recursively copying all associated Attribute and Thing. To make a non-recursive copy (excluding Inventory content) the Copy method should be used instead.

func (*Thing) Dump

func (t *Thing) Dump(node *tree.Node) *tree.Node

Dump adds Thing information to the passed tree.Node for debugging and returns the new node. A new branch is created on the node which is passed to each of the Thing's attributes to add their information. This may continue recursivly as in the case of containers.

NOTE: Care should be take if debugging Thing itself (Add, Remove, Free) as Dump will acquire a read lock on the rwmutex.

func (*Thing) DumpToLog added in v0.0.16

func (t *Thing) DumpToLog(label string)

DumpToLog is a convenience method for dumping the current state of a Thing to the log. The information is annotated with the file and line number where the dump was taken and specified label.

NOTE: Care should be take if debugging Thing itself (Add, Remove, Free) as Dump will acquire a read lock on the rwmutex.

func (*Thing) FindAttr added in v0.0.16

func (t *Thing) FindAttr(cmp has.Attribute) has.Attribute

FindAttr searches the attributes of the Thing for attributes that implement the passed Attribute cmp returning the first match it finds or cmp otherwise. The comparison is performed by calling cmp.Is on the attributes of the Thing. It is usual for cmp to be a typed nil attribute and for the returned attribute to be converted to the general has interface type for cmp. For an example see the attr.FindName function.

func (*Thing) FindAttrs added in v0.0.16

func (t *Thing) FindAttrs(cmp has.Attribute) (attrs []has.Attribute)

FindAttrs searches the attributes of the Thing for attributes that implement the passed Attribute cmp returning a slice of all the matches it finds or a nil slice otherwise. The comparison is performed by calling cmp.Is on the attributes of the Thing. It is usual for cmp to be a typed nil attribute and for the returned attribute to be converted to the general has interface type for cmp. For an example see the attr.FindAllDescription function.

func (*Thing) Free added in v0.0.5

func (t *Thing) Free()

Free is used to clean-up/release references to all Attribute for a Thing. When a Thing is finished with calling Free helps the garbage collector to reclaim objects. It can also help to break cyclic references that could prevent garbage collection.

func (*Thing) Freed added in v0.0.16

func (t *Thing) Freed() (b bool)

Freed returns true if Free has been called on the Thing, else false.

func (*Thing) LoadHooks added in v0.0.17

func (t *Thing) LoadHooks()

LoadHooks calls any loadHook methods on Thing attributes providing a hook into the post-unmarshaling process of a Thing just before the Thing is enabled. Any Inventory of the Thing are processed recursivly, depth first. The loadHook can call Parent and reference other attributes which cannot be done during unmarshaling.

func (*Thing) Marshal added in v0.0.9

func (t *Thing) Marshal() recordjar.Record

Marshal marshals a Thing to a recordjar record containing all of the Attribute details.

func (*Thing) NotUnique added in v0.0.9

func (t *Thing) NotUnique()

NotUnique marks a Thing as no longer being unique and clears the Thing's UID. It also decrements ThingCount by one to account for the fact that calling Free will no longer decrement ThingCount for multiple references of this Thing. Calling NotUnique on a Thing more than once is safe.

You almost never, ever, want to call this function! The only time this should be used is when creating temporary stores - such as when loading zones or players.

func (*Thing) Ref added in v0.0.17

func (t *Thing) Ref() string

Ref returns the value of the REF field found when unmarshaling the Thing. The value is not unique, if a Thing is copied the copy will have the same reference as the original. The reference may be the empty string.

func (*Thing) Remove

func (t *Thing) Remove(a ...has.Attribute)

Remove is used to remove the passed Attributes from a Thing. There is no indication if an Attribute cannot actually be removed. When an Attribute is removed its parent is set to nil. When an Attribute is removed and is no longer required the Attribute's Free method should be called.

func (*Thing) ResetHooks added in v0.0.17

func (t *Thing) ResetHooks()

ResetHooks calls any resetHook methods on Thing attributes providing a hook into the reset process of a Thing just before the Thing is enabled. Any Inventory of the Thing are processed recursivly, depth first.

func (*Thing) SaveHooks added in v0.0.17

func (t *Thing) SaveHooks()

SaveHooks calls any saveHook methods on Thing attributes providing a hook into the pre-marshaling process of a Thing just before the Thing is marshaled. Any Inventory of the Thing are processed recursivly, depth first.

func (*Thing) SetOrigins added in v0.0.5

func (t *Thing) SetOrigins()

SetOrigins checks the passed Thing, and any Inventory content recursively, for a Reset attribute. Any Thing found with a Reset attribute will then have its origin set to that of the Thing's parent Inventory.

func (*Thing) String added in v0.0.6

func (t *Thing) String() string

String causes a Thing to implement the Stringer interface so that a Thing can print information about itself. The format of the string is:

<address> <type> - uid: <unique ID>

0xc420108630 *attr.Thing - uid: #UID-6M

func (*Thing) UID added in v0.0.5

func (t *Thing) UID() string

UID returns the unique identifier for a specific Thing or an empty string if the unique ID is unavailable. The unique ID should be automatically assigned to any Thing created by calling NewThing or Copy.

func (*Thing) Unmarshal

func (t *Thing) Unmarshal(recno int, record recordjar.Record)

Unmarshal unmarshals a Thing from a recordjar record containing all of the Attribute to be added. The recno is the record number in the recordjar for this record. It is passed so that we can give informative messages if errors are found. If the record number is not known -1 should be passed instead.

type Things added in v0.0.13

type Things []*Thing

Things is a type of slice *Thing. It allows methods to be defined directly on the slice. This allows the methods to range over the slice instead of ranging over the slice in multiple places calling the method.

func (*Things) Free added in v0.0.13

func (t *Things) Free()

Free invokes Thing.Free on each of the *Thing elements in the receiver. After the call all elements of the receiver will be removed resulting in an empty slice.

type Veto

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

Veto implements a veto for a specific command. Veto need to be added to a Vetoes list using NewVetoes.

func NewVeto

func NewVeto(cmd string, msg string) *Veto

NewVeto returns a new Veto attribute initialised for the specified command with the specified message text. The command is a normal command such as GET and DROP and will automatically be uppercased. The message text should indicate why the command was vetoed such as "You can't drop the sword. It seems to be cursed". Referring to specific items - such as the sword in the example - is valid as a Veto is for a specific known Thing.

func (*Veto) Command

func (v *Veto) Command() string

Command returns the command associated with the Veto.

func (*Veto) Dump

func (v *Veto) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Veto) Message

func (v *Veto) Message() string

Message returns the message associated with the Veto.

type Vetoes

type Vetoes struct {
	Attribute
	// contains filtered or unexported fields
}

Vetoes implement an attribute for lists of Veto preventing commands for a Thing that would otherwise be valid. For example you could Veto the drop command if a very sticky item is picked up :)

func NewVetoes

func NewVetoes(veto ...has.Veto) *Vetoes

NewVetoes returns a new Vetoes attribute initialised with the specified Vetos.

func (*Vetoes) Check

func (v *Vetoes) Check(actor has.Thing, cmd ...string) has.Veto

Check checks if any of the passed commands, issued by the passed actor, are vetoed. The first matching Veto found is returned otherwise nil is returned.

func (*Vetoes) Copy added in v0.0.4

func (v *Vetoes) Copy() has.Attribute

Copy returns a copy of the Vetoes receiver.

func (*Vetoes) Dump

func (v *Vetoes) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Vetoes) Found

func (v *Vetoes) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Vetoes) Free added in v0.0.5

func (v *Vetoes) Free()

Free makes sure references are nil'ed when the Vetoes attribute is freed.

func (*Vetoes) Is added in v0.0.16

func (*Vetoes) Is(a has.Attribute) bool

Is returns true if passed attribute implements vetoes else false.

func (*Vetoes) Marshal added in v0.0.9

func (v *Vetoes) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Vetoes) Unmarshal

func (*Vetoes) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Vetoes attribute.

type Wearable added in v0.0.16

type Wearable struct {
	Attribute
	// contains filtered or unexported fields
}

Wearable implements an attribute for specifying body slots required when wearing a Thing. Wearable will veto the JUNK command so that items being worn are not accidentally junked and disposed of.

func NewWearable added in v0.0.16

func NewWearable(slots ...string) *Wearable

NewWearable returns a new Wearable attribute initialised with the passed Body slot references. Any Thing with a Wearable attribute can be worn by a player or mobile provided they have the specified Body slots available.

func (*Wearable) Check added in v0.0.16

func (w *Wearable) Check(actor has.Thing, cmd ...string) has.Veto

Check will veto the JUNK command if the Thing is currently worn.

func (*Wearable) Copy added in v0.0.16

func (w *Wearable) Copy() has.Attribute

Copy returns a copy of the Wearable receiver.

func (*Wearable) Dump added in v0.0.16

func (w *Wearable) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Wearable) Found added in v0.0.16

func (w *Wearable) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Wearable) Is added in v0.0.16

func (*Wearable) Is(a has.Attribute) bool

Is returns true if passed attribute implements a wearable item else false.

func (*Wearable) IsWearable added in v0.0.16

func (w *Wearable) IsWearable() bool

IsWearable return true

func (*Wearable) Marshal added in v0.0.16

func (w *Wearable) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Wearable) Slots added in v0.0.16

func (w *Wearable) Slots() []string

Slots returns the Body slot references that need to be available to wear the Thing. The returned slice should not be modified.

func (*Wearable) Unmarshal added in v0.0.16

func (*Wearable) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Wearable attribute.

type Wearing added in v0.0.17

type Wearing struct {
	Attribute
	// contains filtered or unexported fields
}

Wearing implements an attribute representing items that are being worn by a Thing.

BUG(diddymus): At the moment the Wearing attribute only represents the initial state of items being worn when a Thing is unmarshaled - it is not dynamically updated as items are worn and removed.

func NewWearing added in v0.0.17

func NewWearing(ref ...string) *Wearing

NewWearing returns a Wearing attribute initialised with the passed references. The references should be those returned by Thing.Ref(), which are normally the content of the Ref field from the record jar the Thing was loaded from.

func (*Wearing) Copy added in v0.0.17

func (w *Wearing) Copy() has.Attribute

Copy returns a copy of the Wearing receiver.

func (*Wearing) Dump added in v0.0.17

func (w *Wearing) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Wearing) Found added in v0.0.17

func (w *Wearing) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Wearing) Is added in v0.0.17

func (*Wearing) Is(a has.Attribute) bool

Is returns true if passed attribute implements wearing else false.

func (*Wearing) Marshal added in v0.0.17

func (w *Wearing) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Wearing) Unmarshal added in v0.0.17

func (*Wearing) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Wearing attribute.

func (*Wearing) Worn added in v0.0.17

func (w *Wearing) Worn() []string

Worn returns a string slice of Thing references for items that are being worn.

type Wieldable added in v0.0.16

type Wieldable struct {
	Attribute
	// contains filtered or unexported fields
}

Wieldable implements an attribute for specifying body slots required when wielding a Thing. Wieldable will veto the JUNK command so that items being wielded are not accidentally junked and disposed of.

func NewWieldable added in v0.0.16

func NewWieldable(slots ...string) *Wieldable

NewWieldable returns a new Wieldable attribute initialised with the passed Body slot references. Any Thing with a Wieldable attribute can be wielded by a player or mobile provided they have the specified Body slots available.

func (*Wieldable) Check added in v0.0.16

func (w *Wieldable) Check(actor has.Thing, cmd ...string) has.Veto

Check will veto the JUNK command if the Thing is currently wielded.

func (*Wieldable) Copy added in v0.0.16

func (w *Wieldable) Copy() has.Attribute

Copy returns a copy of the Wieldable receiver.

func (*Wieldable) Dump added in v0.0.16

func (w *Wieldable) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Wieldable) Found added in v0.0.16

func (w *Wieldable) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Wieldable) Is added in v0.0.16

func (*Wieldable) Is(a has.Attribute) bool

Is returns true if passed attribute implements a wieldable item else false.

func (*Wieldable) IsWieldable added in v0.0.16

func (w *Wieldable) IsWieldable() bool

IsWieldable returns true.

func (*Wieldable) Marshal added in v0.0.16

func (w *Wieldable) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Wieldable) Slots added in v0.0.16

func (w *Wieldable) Slots() []string

Slots returns the Body slot references that need to be available to wield the Thing. The returned slice should not be modified.

func (*Wieldable) Unmarshal added in v0.0.16

func (*Wieldable) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Wieldable attribute.

type Wielding added in v0.0.17

type Wielding struct {
	Attribute
	// contains filtered or unexported fields
}

Wielding implements an attribute representing items that are being wielded by a Thing.

BUG(diddymus): At the moment the Wielding attribute only represents the initial state of items being wielded when a Thing is unmarshaled - it is not dynamically updated as items are wielded and removed.

func NewWielding added in v0.0.17

func NewWielding(ref ...string) *Wielding

NewWielding returns a Wielding attribute initialised with the passed references. The references should be those returned by Thing.Ref(), which are normally the content of the Ref field from the record jar the Thing was loaded from.

func (*Wielding) Copy added in v0.0.17

func (w *Wielding) Copy() has.Attribute

Copy returns a copy of the Wielding receiver.

func (*Wielding) Dump added in v0.0.17

func (w *Wielding) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Wielding) Found added in v0.0.17

func (w *Wielding) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Wielding) Is added in v0.0.17

func (*Wielding) Is(a has.Attribute) bool

Is returns true if passed attribute implements wielding else false.

func (*Wielding) Marshal added in v0.0.17

func (w *Wielding) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Wielding) Unmarshal added in v0.0.17

func (*Wielding) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Wielding attribute.

func (*Wielding) Wielded added in v0.0.17

func (w *Wielding) Wielded() []string

Wielded returns a string slice of Thing references for items that are being wielded.

type Writing

type Writing struct {
	Attribute
	// contains filtered or unexported fields
}

Writing implements an attribute that allows for writing to be put onto any Thing so that it can be read.

TODO: Writing currently assumes the text is written onto a Thing. However it could also be carved, burnt, painted, etc. onto a Thing. It also assumes the text is in a common language known to all. If language were implemented we could write in common, elvish, dwarfish, ancient runes, secret code or anything else with the text only being readable by those who know the relevant language. See also the Writing Description method.

func NewWriting

func NewWriting(w string) *Writing

NewWriting returns a new Writing attribute initialised with the specified writing/text.

func (*Writing) Copy added in v0.0.4

func (w *Writing) Copy() has.Attribute

Copy returns a copy of the Writing receiver.

func (*Writing) Description

func (w *Writing) Description() string

Description automatically adds the specified text to the description of a Thing that has a has.Writing attribute.

FIXME: This should return a message based on the type of writing: runes, painting, carving etc. See also TODO for the Writing type.

func (*Writing) Dump

func (w *Writing) Dump(node *tree.Node) *tree.Node

Dump adds attribute information to the passed tree.Node for debugging.

func (*Writing) Found

func (w *Writing) Found() bool

Found returns false if the receiver is nil otherwise true.

func (*Writing) Is added in v0.0.16

func (*Writing) Is(a has.Attribute) bool

Is returns true if passed attribute implements writing else false.

func (*Writing) Marshal added in v0.0.9

func (w *Writing) Marshal() (tag string, data []byte)

Marshal returns a tag and []byte that represents the receiver.

func (*Writing) Unmarshal

func (*Writing) Unmarshal(data []byte) has.Attribute

Unmarshal is used to turn the passed data into a new Writing attribute.

func (*Writing) Writing

func (w *Writing) Writing() (writing string)

Writing returns the text that has been written.

Notes

Bugs

  • Aliases are expected be single words only, otherwise they probably won't work correctly and cause all sorts of weird problems and behaviour.

  • If there are multiple slots with the same name available, for example two HAND slots, only one will be reported. For example if you are holding a knife and dagger and try to wield a sword it will report one of:

    • You cannot wield the sword while also using a knife.
    • You cannot wield the sword while also using a dagger.

    Message depends on order of usage. Ideally this should report:

    • You cannot wield the sword while also using a knife and a dagger.

    Maybe that should be 'a knife OR a dagger'? If you try to wield a two handed staff the message is correct:

    • You cannot wield the staff while also using a knife and a dagger.

    I think the fix for this is to make UsedBy smarter.

  • Does not check that exit A links to B and B links back to A. For example a maze may have an exit going North from A to B but going South from B takes you to C instead of back to A as would be expected!

  • At the moment the Holding attribute only represents the initial state of items being held when a Thing is unmarshaled - it is not dynamically updated as items are held and removed.

  • Inventory capacity is not implemented yet.

  • This method specifically checks for a *attr.Inventory, which is currently the only implementation of has.Inventory - if this changes this method will need updating.

  • At the moment the Wearing attribute only represents the initial state of items being worn when a Thing is unmarshaled - it is not dynamically updated as items are worn and removed.

  • At the moment the Wielding attribute only represents the initial state of items being wielded when a Thing is unmarshaled - it is not dynamically updated as items are wielded and removed.

Directories

Path Synopsis
Package ordering provides a list for ordering Attributes when they are marshaled.
Package ordering provides a list for ordering Attributes when they are marshaled.

Jump to

Keyboard shortcuts

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