game

package
v0.0.0-...-d5d5497 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttributeSwoleDescription  = "Swole determines damage and health"
	AttributeZoomsDescription  = "Zooms determines speed and dodge"
	AttributeBrainsDescription = "Brains determines spell damage and ability to by-pass traps"
	AttributeFunkDescription   = "Funk determines luck and area of effect bonuses"
)

Variables

View Source
var (
	ColorSwole         = color.NRGBA{128, 32, 32, 255}
	ColorSwoleVibrant  = color.NRGBA{200, 100, 100, 255}
	ColorZooms         = color.NRGBA{128, 128, 32, 255}
	ColorZoomsVibrant  = color.NRGBA{200, 200, 100, 255}
	ColorBrains        = color.NRGBA{32, 32, 128, 255}
	ColorBrainsVibrant = color.NRGBA{100, 100, 200, 255}
	ColorFunk          = color.NRGBA{128, 32, 128, 255}
	ColorFunkVibrant   = color.NRGBA{200, 100, 200, 255}
)
View Source
var (
	ErrAlreadyOpen   = errors.New("it is already open")
	ErrAlreadyClosed = errors.New("it is already closed")
)
View Source
var (
	ErrMissingSlot  = errors.New("missing slot")
	ErrMissingSlots = errors.New("missing slots")
	ErrUsedSlots    = errors.New("used slots")
)
View Source
var (
	ErrInvalidBlockType = errors.New("invalid block type")
)
View Source
var (
	ErrOutOfBoundCell = errors.New("oob cell")
)

Functions

func NewCells

func NewCells(w, h int) (cells [][]Cell)

Types

type Appliable

type Appliable struct {
	Applied bool `msgpack:"a,omitempty"`
}

func (*Appliable) Apply

func (a *Appliable) Apply()

func (*Appliable) IsApplied

func (a *Appliable) IsApplied() bool

func (*Appliable) Unapply

func (a *Appliable) Unapply()

type Archetype

type Archetype interface {
	GetID() id.UUID
	Type() string
}

Archetype is an interface that all archetypes must implement.

func DecodeArchetype

func DecodeArchetype(bytes []byte, rootPath string) (Archetype, error)

type Armor

type Armor struct {
	Position
	Appliable
	ArchetypeID id.UUID   `msgpack:"A,omitempty"`
	Archetype   Archetype `msgpack:"-" json:"-"`
	WID         id.WID
	Container   id.WID `msgpack:"c,omitempty"` // The container of the item, if any.
}

Armor is a weapon.

func (*Armor) GetArchetype

func (a *Armor) GetArchetype() Archetype

GetArchetype returns the archetype.

func (*Armor) GetArchetypeID

func (a *Armor) GetArchetypeID() id.UUID

GetArchetypeID returns the ID of the archetype.

func (Armor) GetPosition

func (a Armor) GetPosition() Position

GetPosition returns the position of the object.

func (Armor) GetWID

func (a Armor) GetWID() id.WID

GetWID returns the WID of the object.

func (*Armor) SetArchetype

func (a *Armor) SetArchetype(archetype Archetype)

SetArchetype sets the archetype.

func (*Armor) SetPosition

func (a *Armor) SetPosition(p Position)

SetPosition sets the position of the object.

func (*Armor) SetWID

func (a *Armor) SetWID(wid id.WID)

SetWID sets the WID of the object.

func (Armor) Type

func (a Armor) Type() ObjectType

Type returns the type of the object.

type ArmorArchetype

type ArmorArchetype struct {
	ID          id.UUID
	Title       string
	Image       string
	Description string
	ArmorType   ArmorType
	MinArmor    int // Character proficiency with a weapon increases min up to max.
	MaxArmor    int
	MovePenalty int   // Penalty to movement speed.
	Slots       Slots `msgpack:"S,omitempty"`
}

ArmorArchetype is effectively a blueprint for armour.

func (ArmorArchetype) GetID

func (a ArmorArchetype) GetID() id.UUID

GetID returns the ID of the archetype.

func (ArmorArchetype) RangeString

func (a ArmorArchetype) RangeString() string

RangeString returns the armor range of the archetype.

func (ArmorArchetype) Type

func (a ArmorArchetype) Type() string

Type returns the type of the archetype.

type ArmorType

type ArmorType uint8

ArmorType is the type the armor is considered as.

const (
	ArmorTypeNone ArmorType = iota
	ArmorTypeLight
	ArmorTypeMedium
	ArmorTypeHeavy
)

func (ArmorType) Color

func (a ArmorType) Color() color.Color

Color returns the color associated with the armor type.

func (ArmorType) String

func (a ArmorType) String() string

String returns the string representation of the armor type.

func (*ArmorType) UnmarshalJSON

func (a *ArmorType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON representation of the armor type.

type Attribute

type Attribute uint8

Attribute represents a particular physical or mental ability of a character.

const (
	// AttributeSwole represents physicality
	AttributeSwole Attribute = iota
	// AttributeZooms represents speed
	AttributeZooms
	// AttributeBrains represents intelligence
	AttributeBrains
	// AttributeFunk represents the funk
	AttributeFunk
)

type AttributeLevel

type AttributeLevel float64

AttributeLevel represents the level of an attribute, with the whole number representing the level and the fractional representing the experience until the next level.

type Attributes

type Attributes struct {
	Swole  AttributeLevel `msgpack:"s,omitempty"`
	Zooms  AttributeLevel `msgpack:"z,omitempty"`
	Brains AttributeLevel `msgpack:"b,omitempty"`
	Funk   AttributeLevel `msgpack:"f,omitempty"`
}

type BlockType

type BlockType int
const (
	BlockTypeNone BlockType = iota
	BlockTypeSolid
	BlockTypeHole
	BlockTypeLiquid
)

func (*BlockType) UnmarshalJSON

func (b *BlockType) UnmarshalJSON(data []byte) error

type Blockable

type Blockable struct {
	BlockType BlockType `msgpack:"b"`
}

func (*Blockable) IsBlocked

func (b *Blockable) IsBlocked() bool

type Cell

type Cell struct {
	TileID  *id.UUID     `msgpack:"id,omitempty"` // The Tile ID of the cell.
	Blocks  MovementType `msgpack:"b,omitempty"`  // Whether the cell blocks. This should be generated from the TileID and the contained Objects.
	Objects Objects      `msgpack:"o,omitempty"`  // Non-thinking/active objects. These will generally be weapons, armor, gold, food, etc.
	// contains filtered or unexported fields
}

func (*Cell) Data

func (t *Cell) Data() interface{}

func (*Cell) Flags

func (t *Cell) Flags() gen.Flags

func (*Cell) SetData

func (t *Cell) SetData(d interface{})

func (*Cell) SetFlags

func (t *Cell) SetFlags(v gen.Flags)

func (*Cell) SetValue

func (t *Cell) SetValue(v int)

func (*Cell) Value

func (t *Cell) Value() int

type Cells

type Cells [][]Cell

func (Cells) At

func (c Cells) At(x, y int) (Cell, error)

type Character

type Character struct {
	Position
	Blockable
	Hurtable
	Damager
	Movable
	Events      []Event    `msgpack:"-" json:"-"` // Events that have happened to the character. These are only sent to the owning client.
	Desire      Desire     `msgpack:"-" json:"-"` // The current desire of the character. Used server-side.
	LastDesire  Desire     `msgpack:"-" json:"-"` // Last desire processed. Used server-side.
	WID         id.WID     // ID assigned when entering da world.
	Archetype   Archetype  `msgpack:"-" json:"-"` // Archetype of the character. This is likely a pointer.
	ArchetypeID id.UUID    `msgpack:"A,omitempty"`
	Name        string     `msgpack:"n,omitempty"`
	Level       int        `msgpack:"l,omitempty"`
	Attributes  Attributes `msgpack:"t,omitempty"`
	Slots       SlotMap    `msgpack:"-"`
	Skills      Skills     `msgpack:"-"`
	Inventory   Objects    `msgpack:"-"`
	//
	SpentActions int
}

Character represents a character. This can be a player or an NPC.

func (*Character) Apply

func (c *Character) Apply(o Object, force bool) Event

Apply applies an object from the character's inventory.

func (*Character) Drop

func (c *Character) Drop(o Object) Event

Drop removes an object from the character's inventory.

func (*Character) GetArchetype

func (c *Character) GetArchetype() Archetype

GetArchetype returns the archetype.

func (*Character) GetArchetypeID

func (c *Character) GetArchetypeID() id.UUID

GetArchetypeID returns the archetype.

func (Character) GetPosition

func (c Character) GetPosition() Position

GetPosition returns the position.

func (Character) GetWID

func (c Character) GetWID() id.WID

GetWID returns the WID.

func (*Character) InInventory

func (c *Character) InInventory(wid id.WID) bool

InInventory returns true if the character has the object in their inventory.

func (*Character) Pickup

func (c *Character) Pickup(o Object) Event

Pickup adds an object to the character's inventory.

func (*Character) SetArchetype

func (c *Character) SetArchetype(a Archetype)

SetArchetype sets the archetype.

func (*Character) SetPosition

func (c *Character) SetPosition(p Position)

SetPosition sets the position.

func (*Character) SetWID

func (c *Character) SetWID(wid id.WID)

SetWID sets the WID.

func (Character) Type

func (c Character) Type() ObjectType

Type returns "character"

func (*Character) Unapply

func (c *Character) Unapply(o Object, force bool) Event

Unapply unapplies an object from the character's inventory.

type CharacterArchetype

type CharacterArchetype struct {
	Title string  `msgpack:"t,omitempty"` // Title of the archetype. This is what is displayed to the user.
	ID    id.UUID `msgpack:"id,omitempty"`

	PlayerOnly bool // If the archetype is for players only during character creation.

	Image string `msgpack:"i,omitempty"` // Image for the archetype. Should be requested via HTTP to the resources backend.
	//
	Swole  AttributeLevel // Raw Strength + Health
	Zooms  AttributeLevel // Dex, basically
	Brains AttributeLevel // Thinkin' and spell-related
	Funk   AttributeLevel // Charm and god-related
	//Traits          []string           // Traits
	Traits          TraitList
	Slots           Slots              // Slots
	StartingObjects []id.UUID          // Starting objects
	StartingSkills  map[string]float64 // Starting skills
}

CharacterArchetype is a structure that is used to act as a "template" for creating playable characters.

func (CharacterArchetype) GetID

func (c CharacterArchetype) GetID() id.UUID

GetID returns the ID.

func (CharacterArchetype) Type

func (c CharacterArchetype) Type() string

Type returns "character"

type Damage

type Damage struct {
	Source   id.WID
	Min, Max int
	Extra    int
	Reduced  bool
	Weapon   WeaponType
}

Damage represents the damage range of an attack.

func (Damage) RangeString

func (d Damage) RangeString() string

RangeString returns a string representation of the damage range.

func (Damage) Roll

func (d Damage) Roll() int

Roll rolls the damage range and returns the result.

type DamageResult

type DamageResult struct {
	Damage int
}

DamageResult represents the result of a damage roll.

type Damager

type Damager struct {
	Damages []Damage
}

func (*Damager) CalculateFromCharacter

func (d *Damager) CalculateFromCharacter(c *Character)

func (*Damager) RollDamages

func (d *Damager) RollDamages() (results []DamageResult)

type Desire

type Desire interface {
	Type() string
}

Desire represents a desire of the client to make their character do something. These often cause Events to be sent back to the client on location updating.

type DesireApply

type DesireApply struct {
	WID   id.WID `msgpack:"wid,omitempty"`
	Apply bool   `msgpack:"a,omitempty"` // Whether to apply or unapply.
}

DesireApply represents the desire to apply or unapply a particular object.

func (DesireApply) Type

func (d DesireApply) Type() string

type DesireBash

type DesireBash struct {
	WID       id.WID        `msgpack:"wid,omitempty"`
	Direction MoveDirection `msgpack:"d,omitempty"`
}

DesireBash represents the desire to bash a particular object or direction.

func (DesireBash) Type

func (d DesireBash) Type() string

type DesireDrop

type DesireDrop struct {
	WID id.WID `msgpack:"wid,omitempty"`
}

DesireDrop represents the desire to drop a particular object.

func (DesireDrop) Type

func (d DesireDrop) Type() string

type DesireMove

type DesireMove struct {
	Direction MoveDirection `msgpack:"d,omitempty"`
}

DesireMove represents the desire to move in a cardinal direction.

func (DesireMove) Type

func (d DesireMove) Type() string

type DesireOpen

type DesireOpen struct {
	WID  id.WID `msgpack:"wid,omitempty"`
	Open bool   `msgpack:"o,omitempty"` // Whether to open or close.
}

DesireOpen represents the desire to open or close a particular object.

func (DesireOpen) Type

func (d DesireOpen) Type() string

type DesirePickup

type DesirePickup struct {
	WID id.WID `msgpack:"wid,omitempty"`
}

DesirePickup represents the desire to pick up a particular object.

func (DesirePickup) Type

func (d DesirePickup) Type() string

type DesireWrapper

type DesireWrapper struct {
	Type string             `msgpack:"t"`
	Data msgpack.RawMessage `msgpack:"d"`
}

DesireWrapper is for sending desires from the client to the server.

func (*DesireWrapper) Desire

func (w *DesireWrapper) Desire() Desire

Desire returns the desire stored in the wrapper.

type Door

type Door struct {
	Position
	Hurtable
	Lockable
	Blockable
	Openable
	ArchetypeID id.UUID   `msgpack:"A,omitempty"`
	Archetype   Archetype `msgpack:"-" json:"-"`
	WID         id.WID    // ID assigned when entering da world.
}

Door is a door.

func (Door) GetArchetype

func (o Door) GetArchetype() Archetype

GetArchetype returns the archetype of this object.

func (Door) GetArchetypeID

func (o Door) GetArchetypeID() id.UUID

GetArchetypeID returns the archetype ID of this object.

func (Door) GetPosition

func (o Door) GetPosition() Position

GetPosition returns the position of this object.

func (Door) GetWID

func (o Door) GetWID() id.WID

GetWID returns the WID of this object.

func (*Door) SetArchetype

func (o *Door) SetArchetype(a Archetype)

SetArchetype sets the archetype of this object.

func (*Door) SetPosition

func (o *Door) SetPosition(pos Position)

SetPosition sets the position of this object.

func (*Door) SetWID

func (o *Door) SetWID(wid id.WID)

SetWID sets the WID of this object.

func (Door) Type

func (o Door) Type() ObjectType

Type returns the type of this object.

type DoorArchetype

type DoorArchetype struct {
	ID        id.UUID
	Title     string    `msgpack:"T,omitempty"`
	Image     string    `msgpack:"i,omitempty"`
	BlockType BlockType `msgpack:"-"`
	Health    int       `msgpack:"-"`
	MaxHealth int       `msgpack:"-"`
}

DoorArchetype is the archetype for a door.

func (DoorArchetype) GetID

func (d DoorArchetype) GetID() id.UUID

GetID returns the ID of this archetype.

func (DoorArchetype) Type

func (d DoorArchetype) Type() string

Type returns the type of this archetype.

type Event

type Event interface {
	Type() string
}

Event is the result of something happening on the server that is to be sent to the client. This includes sounds, position information, damage dealt, and more. Many events are as the result of client-sent Desires.

type EventAdd

type EventAdd struct {
	Object Object `msgpack:"o,omitempty"`
}

EventAdd adds the provided object.

func (EventAdd) MarshalMsgpack

func (e EventAdd) MarshalMsgpack() ([]byte, error)

MarshalMsgpack marshals EventAdd into eventAdd.

func (EventAdd) Type

func (e EventAdd) Type() string

Type returns "add"

func (*EventAdd) UnmarshalMsgpack

func (e *EventAdd) UnmarshalMsgpack(b []byte) error

UnmarshalMsgpack unmarshals EventAdd from eventAdd.

type EventApply

type EventApply struct {
	Applier id.WID `msgpack:"A,omitempty"`
	WID     id.WID
	Applied bool `msgpack:"a,omitempty"`
}

EventApply notifies the client that the given item was applied or unapplied.

func (EventApply) Type

func (e EventApply) Type() string

Type returns "apply".

type EventDamages

type EventDamages struct {
	From    id.WID         `msgpack:"f,omitempty"`
	Target  id.WID         `msgpack:"t,omitempty"`
	Damages []DamageResult `msgpack:"d,omitempty"`
}

EventDamages notifies the client that the given object was damaged.

func (EventDamages) Type

func (e EventDamages) Type() string

Type returns "damage"

type EventDrop

type EventDrop struct {
	Dropper  id.WID `msgpack:"d,omitempty"`
	Position Position
	Object   Object
}

EventDrop notifies the client that the given item was dropped.

func (EventDrop) MarshalMsgpack

func (e EventDrop) MarshalMsgpack() ([]byte, error)

MarshalMsgpack marshals EventDrop into eventDrop.

func (EventDrop) Type

func (e EventDrop) Type() string

Type returns "drop"

func (*EventDrop) UnmarshalMsgpack

func (e *EventDrop) UnmarshalMsgpack(b []byte) error

UnmarshalMsgpack unmarshals EventDrop from eventDrop.

type EventHealth

type EventHealth struct {
	From   id.WID `msgpack:"f,omitempty"`
	Target id.WID `msgpack:"t,omitempty"`
	Health int    `msgpack:"h,omitempty"`
}

EventHealth notifies the client that the given object's health changed.

func (EventHealth) Type

func (e EventHealth) Type() string

Type returns "health"

type EventNotice

type EventNotice struct {
	Message string
}

EventNotice notifies the client of a generic notice.

func (EventNotice) Type

func (e EventNotice) Type() string

Type returns "notice"

type EventPickup

type EventPickup struct {
	Picker id.WID `msgpack:"p,omitempty"`
	WID    id.WID
}

EventPickup notifies the client that the given item was picked up.

func (EventPickup) Type

func (e EventPickup) Type() string

Type returns "pickup"

type EventPosition

type EventPosition struct {
	WID      id.WID
	Position `msgpack:"p,omitempty"`
}

EventPosition represents a position update of something in a world location.

func (EventPosition) Type

func (e EventPosition) Type() string

Type returns "position"

type EventRemove

type EventRemove struct {
	WID id.WID `msgpack:"wid,omitempty"`
}

EventRemove removes an object with the given WID from the current location.

func (EventRemove) Type

func (e EventRemove) Type() string

Type returns "remove"

type EventSound

type EventSound struct {
	WID          id.WID `msgpack:"wid,omitempty"`
	Position     `msgpack:"p,omitempty"`
	FromPosition Position `msgpack:"f,omitempty"`
	Message      string   `msgpack:"m,omitempty"`
}

EventSound represents a sound emitted from a location. FromX and FromY are used to modify the visual offset of the sound. This makes it so when you bump into a wall or hit an enemy, the sound effect appears between the two points.

func (EventSound) Type

func (e EventSound) Type() string

Type returns "sound"

type EventTurn

type EventTurn struct {
	Turn int `msgpack:"t,omitempty"`
}

EventTurn notifies the client that a location turn has occurred.

func (EventTurn) Type

func (e EventTurn) Type() string

Type returns "turn"

type EventWrapper

type EventWrapper struct {
	Type string             `msgpack:"t"`
	Data msgpack.RawMessage `msgpack:"d"`
}

EventWrapper is for sending desires from the client to the server.

func WrapEvent

func WrapEvent(e Event) (EventWrapper, error)

WrapEvent wraps up an event to be sent over the wire.

func (*EventWrapper) Event

func (w *EventWrapper) Event() Event

Event returns the event stored in the wrapper.

type Health

type Health struct {
	Current int `webpack:"c,omitempty"`
	Max     int `webpack:"m,omitempty"`
}

Health represents a character's health.

func (Health) String

func (h Health) String() string

String returns a string representation of the health.

type Hurtable

type Hurtable struct {
	Health    int `msgpack:"h,omitempty"`
	MaxHealth int `msgpack:"H,omitempty"`
	Downs     int `msgpack:"d,omitempty"`
	MaxDowns  int `msgpack:"D,omitempty"`
}

func (*Hurtable) CalculateFromCharacter

func (h *Hurtable) CalculateFromCharacter(c *Character)

func (*Hurtable) CalculateFromObject

func (h *Hurtable) CalculateFromObject(o Object)

func (*Hurtable) IsDead

func (h *Hurtable) IsDead() bool

func (Hurtable) String

func (h Hurtable) String() string

String returns a string representation of the health.

func (*Hurtable) TakeDamages

func (h *Hurtable) TakeDamages(damages []DamageResult)

func (*Hurtable) TakeHeal

func (h *Hurtable) TakeHeal(heal int)

type Item

type Item struct {
	Position
	ArchetypeID id.UUID   `msgpack:"A,omitempty"`
	Archetype   Archetype `msgpack:"-" json:"-"`
	WID         id.WID    // ID assigned when entering da world.
	Container   id.WID    `msgpack:"c,omitempty"` // The container of the item, if any.
	ID          id.UUID   `msgpack:"id,omitempty"`
	Name        string    `msgpack:"n,omitempty"`
}

Item represents a generic item in the world.

func (*Item) GetArchetype

func (o *Item) GetArchetype() Archetype

func (*Item) GetArchetypeID

func (o *Item) GetArchetypeID() id.UUID

func (Item) GetPosition

func (o Item) GetPosition() Position

GetPosition returns the position of the item.

func (Item) GetWID

func (o Item) GetWID() id.WID

GetWID returns the world ID of the item.

func (*Item) SetArchetype

func (o *Item) SetArchetype(a Archetype)

func (*Item) SetPosition

func (o *Item) SetPosition(p Position)

SetPosition sets the position of the item.

func (*Item) SetWID

func (o *Item) SetWID(wid id.WID)

SetWID sets the world ID of the item.

func (Item) Type

func (o Item) Type() ObjectType

Type returns "item"

type ItemArchetype

type ItemArchetype struct {
	ID    id.UUID
	Title string `msgpack:"T,omitempty"`
	Image string `msgpack:"i,omitempty"`
}

ItemArchetype is effectively a blueprint for an item.

func (ItemArchetype) GetID

func (a ItemArchetype) GetID() id.UUID

func (ItemArchetype) Type

func (a ItemArchetype) Type() string

type Location

type Location struct {
	ID      id.UUID `msgpack:"id,omitempty"`
	Cells   Cells   `msgpack:"c,omitempty"`
	Objects Objects `msgpack:"o,omitempty"`
}

func (*Location) Character

func (l *Location) Character(wid id.WID) *Character

func (*Location) Characters

func (l *Location) Characters() (chars []*Character)

func (*Location) ObjectByWID

func (l *Location) ObjectByWID(wid id.WID) Object

type Lockable

type Lockable struct {
	Locked bool `msgpack:"l"`
}

Lockable is a feature that enables locking and unlocking

func (*Lockable) IsLocked

func (l *Lockable) IsLocked() bool

IsLocked returns true if the lockable is locked

func (*Lockable) Lock

func (l *Lockable) Lock()

Lock locks the lockable

func (*Lockable) Unlock

func (l *Lockable) Unlock()

Unlock unlocks the lockable

type Movable

type Movable struct {
	Actions int `msgpack:"s"` // Amount of actions taken in a turn. This will generally be 1 for each player.
}

func (*Movable) CalculateFromCharacter

func (m *Movable) CalculateFromCharacter(c *Character)

type MoveDirection

type MoveDirection uint8
const (
	UpMoveDirection        MoveDirection = 8
	LeftMoveDirection      MoveDirection = 4
	RightMoveDirection     MoveDirection = 6
	DownMoveDirection      MoveDirection = 2
	UpLeftMoveDirection    MoveDirection = 7
	UpRightMoveDirection   MoveDirection = 9
	DownRightMoveDirection MoveDirection = 3
	DownLeftMoveDirection  MoveDirection = 1
	CenterMoveDirection    MoveDirection = 5
)

func (MoveDirection) Position

func (d MoveDirection) Position() (int, int)

type MovementType

type MovementType uint8

TODO: Replace MovementType with bitflag

const (
	MovementNone MovementType = iota
	MovementAll
	MovementWalk
	MovementSwim
	MovementHover
	MovementFly
)

type Object

type Object interface {
	Type() ObjectType
	SetWID(id.WID) // SetWID should only be called by the world.
	GetWID() id.WID
	SetPosition(Position)
	GetPosition() Position
	GetArchetypeID() id.UUID
	SetArchetype(a Archetype)
	GetArchetype() Archetype
}

Object is an interface intended for location objects. This includes players, items, and enemies.

func CreateObjectFromArchetype

func CreateObjectFromArchetype(a Archetype) Object

type ObjectType

type ObjectType string

ObjectType is a key that represents an object's type. This is used for safely marshalling/unmarshalling the Object interface.

type ObjectWrapper

type ObjectWrapper struct {
	Type ObjectType `msgpack:"t"`
	Data RawMessage `msgpack:"d"`
}

ObjectWrapper wraps an Object interface for msgpack marshal and unmarshal.

func (ObjectWrapper) Object

func (ow ObjectWrapper) Object() (Object, error)

Object returns the wrapped Object. To add additional types, they must be handled here and ObjectJSON.

func (ObjectWrapper) ObjectJSON

func (ow ObjectWrapper) ObjectJSON() (Object, error)

ObjectJSON returns the wrapped Object. To add additional types, they must be handled here and Object.

type Objects

type Objects []Object

Objects is a slice of Object interfaces. This type wrapper provides various convenience functions for accessing and modifying the slice.

func (*Objects) Add

func (o *Objects) Add(obj Object)

Add adds an Object to the slice.

func (Objects) MarshalJSON

func (o Objects) MarshalJSON() ([]byte, error)

MarshalJSON returns bytes as an ObjectsWrapper.

func (Objects) MarshalMsgpack

func (o Objects) MarshalMsgpack() ([]byte, error)

MarshalMsgpack returns bytes as an ObjectsWrapper.

func (*Objects) ObjectByWID

func (o *Objects) ObjectByWID(wid id.WID) Object

ObjectByWID returns an object by its WID.

func (*Objects) RemoveByWID

func (o *Objects) RemoveByWID(wid id.WID) Object

RemoveByWID removes a stored object by its WID.

func (*Objects) UnmarshalJSON

func (o *Objects) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the given bytes as an ObjectsWrapper and appends objects into the slice.

func (*Objects) UnmarshalMsgpack

func (o *Objects) UnmarshalMsgpack(b []byte) error

UnmarshalMsgpack unmarshals the given bytes as an ObjectsWrapper and appends objects into the slice.

type Openable

type Openable struct {
	Opened bool
}

func (*Openable) Close

func (o *Openable) Close() error

func (*Openable) IsOpened

func (o *Openable) IsOpened() bool

func (*Openable) Open

func (o *Openable) Open() error

type Position

type Position struct {
	X int `msgpack:"x,omitempty"`
	Y int `msgpack:"y,omitempty"`
}

type RawMessage

type RawMessage []byte

func (RawMessage) MarshalJSON

func (m RawMessage) MarshalJSON() ([]byte, error)

func (RawMessage) MarshalMsgpack

func (m RawMessage) MarshalMsgpack() ([]byte, error)

func (*RawMessage) UnmarshalJSON

func (m *RawMessage) UnmarshalJSON(b []byte) error

func (*RawMessage) UnmarshalMsgpack

func (m *RawMessage) UnmarshalMsgpack(b []byte) error

type Skills

type Skills map[string]float64

Skills is a mapping of skill names to a float.

type Slot

type Slot string

Slot is a slot used for equipment.

const (
	SlotNone     Slot = ""
	SlotHead     Slot = "head"
	SlotTorso    Slot = "torso"
	SlotArms     Slot = "arms"
	SlotHands    Slot = "hands"
	SlotOther    Slot = "other"
	SlotLegs     Slot = "legs"
	SlotFeet     Slot = "feet"
	SlotMainHand Slot = "main-hand"
	SlotOffHand  Slot = "off-hand"
)

type SlotMap

type SlotMap map[Slot]bool

SlotMap is a map of slots used by characters.

func (SlotMap) Apply

func (s SlotMap) Apply(slots Slots) error

Apply adds the given slots to the slot map. If any slots are missing, an error will instead be returned.

func (SlotMap) AreSlotsOpen

func (s SlotMap) AreSlotsOpen(slots Slots) error

AreSlotsOpen returns nil if all of the slots in the slot map are open. Returns ErrUsedSlots wrapping a list of used slots otherwise.

func (SlotMap) HasSlot

func (s SlotMap) HasSlot(slot Slot) bool

HasSlot returns true if the slot map has the given slot.

func (SlotMap) HasSlots

func (s SlotMap) HasSlots(slots Slots) error

HasSlots returns nil if the slot map has all of the given slots. Returns ErrMissingSlots wrapping a list of missing slots otherwise.

func (SlotMap) Unapply

func (s SlotMap) Unapply(slots Slots) error

Unapply removes the given slots from the slot map. Even if slots are missing, slots that are not missing will be removed.

type Slots

type Slots []Slot

Slots is a slice of slots used for equipment.

func (Slots) HasSlot

func (s Slots) HasSlot(slot Slot) bool

HasSlot returns true if the slice of slots has the given slot.

func (Slots) String

func (s Slots) String() string

String returns a string representation of the slice of slots, separated by " & ".

func (Slots) ToMap

func (s Slots) ToMap() SlotMap

ToMap converts the slice of slots to a map of slots.

type TileArchetype

type TileArchetype struct {
	Title string
	ID    id.UUID

	Image string // Image for the tile. It should be requested via HTTP to the resources backend.

}

TileArchetype is a structure that is used to provide the behavior and appearance of a given cell.

func (TileArchetype) GetID

func (a TileArchetype) GetID() id.UUID

func (TileArchetype) Type

func (a TileArchetype) Type() string

type Trait

type Trait interface {
	String() string
	CanApply(o Object) bool
	AdjustDamages(damages []Damage) []Damage
}

type TraitClubber

type TraitClubber struct {
}

func (TraitClubber) AdjustDamages

func (t TraitClubber) AdjustDamages(damages []Damage) []Damage

func (TraitClubber) CanApply

func (t TraitClubber) CanApply(o Object) bool

func (TraitClubber) String

func (t TraitClubber) String() string

type TraitKungFu

type TraitKungFu struct {
}

func (TraitKungFu) AdjustDamages

func (t TraitKungFu) AdjustDamages(damages []Damage) []Damage

func (TraitKungFu) CanApply

func (t TraitKungFu) CanApply(o Object) bool

func (TraitKungFu) String

func (t TraitKungFu) String() string

type TraitList

type TraitList []Trait

func (TraitList) MarshalMsgpack

func (tl TraitList) MarshalMsgpack() ([]byte, error)

func (*TraitList) ToStrings

func (tl *TraitList) ToStrings() []string

func (*TraitList) UnmarshalJSON

func (tl *TraitList) UnmarshalJSON(b []byte) error

func (*TraitList) UnmarshalMsgpack

func (tl *TraitList) UnmarshalMsgpack(b []byte) error

type Weapon

type Weapon struct {
	Position
	Appliable
	ArchetypeID id.UUID   `msgpack:"A,omitempty"`
	Archetype   Archetype `msgpack:"-" json:"-"`
	WID         id.WID
	Container   id.WID `msgpack:"c,omitempty"` // The container of the item, if any.
}

Weapon is a weapon.

func (*Weapon) GetArchetype

func (w *Weapon) GetArchetype() Archetype

GetArchetype returns the archetype.

func (*Weapon) GetArchetypeID

func (w *Weapon) GetArchetypeID() id.UUID

GetArchetypeID returns the ID of the archetype.

func (Weapon) GetPosition

func (w Weapon) GetPosition() Position

GetPosition returns the position of the item.

func (Weapon) GetWID

func (w Weapon) GetWID() id.WID

GetWID returns the WID of the item.

func (*Weapon) SetArchetype

func (w *Weapon) SetArchetype(a Archetype)

SetArchetype sets the archetype.

func (*Weapon) SetPosition

func (w *Weapon) SetPosition(p Position)

SetPosition sets the position of the item.

func (*Weapon) SetWID

func (w *Weapon) SetWID(wid id.WID)

SetWID sets the WID of the item.

func (Weapon) Type

func (w Weapon) Type() ObjectType

Type returns the type of the item.

type WeaponArchetype

type WeaponArchetype struct {
	ID                 id.UUID
	Title              string     `msgpack:"T,omitempty"`
	Image              string     `msgpack:"i,omitempty"`
	PrimaryAttribute   Attribute  `msgpack:"p,omitempty"` // Primary attribute to draw damage from.
	SecondaryAttribute Attribute  `msgpack:"s,omitempty"` // Secondary attribute to draw 50% damage from.
	Description        string     `msgpack:"d,omitempty"`
	WeaponType         WeaponType `msgpack:"w,omitempty"`
	MinDamage          int        `msgpack:"m,omitempty"` // Character proficiency with a weapon increases min up to max.
	MaxDamage          int        `msgpack:"M,omitempty"`
	Slots              Slots      `msgpack:"S,omitempty"`
}

WeaponArchetype is effectively a blueprint for a weapon.

func (WeaponArchetype) GetID

func (a WeaponArchetype) GetID() id.UUID

GetID returns the ID of the archetype.

func (WeaponArchetype) RangeString

func (a WeaponArchetype) RangeString() string

RangeString returns the string representation of the damage range.

func (WeaponArchetype) Type

func (a WeaponArchetype) Type() string

Type returns the type of the archetype.

type WeaponType

type WeaponType uint8

WeaponType is the type the weapon is considered as.

const (
	WeaponTypeNone WeaponType = iota
	WeaponTypeMelee
	WeaponTypeRange
	WeaponTypeThrown
	WeaponTypeUnarmed
)

func (WeaponType) Color

func (a WeaponType) Color() color.Color

Color returns the color associated with the weapon type.

func (WeaponType) String

func (a WeaponType) String() string

String returns the string representation of the weapon type.

func (*WeaponType) UnmarshalJSON

func (a *WeaponType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON representation of the weapon type.

type WorldInfo

type WorldInfo struct {
	Name       string
	ID         id.UUID // random UUIDv4 to identify the world.
	Private    bool
	Players    int
	MaxPlayers int
}

WorldInfo is the information of a world and is used to send worlds to clients and for clients to use to join a world.

Jump to

Keyboard shortcuts

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