database

package
v0.0.0-...-9c029b6 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2017 License: MIT Imports: 13 Imported by: 9

Documentation

Index

Constants

View Source
const MinHeight = 20
View Source
const MinWidth = 60

Variables

This section is empty.

Functions

func DeleteObject

func DeleteObject(id types.Id)

func Find

func Find(t types.ObjectType, query bson.M) []bson.ObjectId

func FindAll

func FindAll(t types.ObjectType) []bson.ObjectId

func FindOne

func FindOne(t types.ObjectType, query bson.M) types.Id

func Init

func Init(session Session, dbName string)

func NewEffect

func NewEffect(name string) types.Effect

func Retrieve

func Retrieve(id types.Id, typ types.ObjectType) types.Object

func RetrieveObjects

func RetrieveObjects(t types.ObjectType, objects interface{})

Types

type Area

type Area struct {
	DbObject `bson:",inline"`
	Name     string
	ZoneId   types.Id
}

func NewArea

func NewArea(name string, zone types.Id) *Area

func (*Area) GetName

func (self *Area) GetName() string

func (*Area) GetZoneId

func (self *Area) GetZoneId() types.Id

func (*Area) SetName

func (self *Area) SetName(name string)

type Character

type Character struct {
	Container `bson:",inline"`

	RoomId    types.Id `bson:",omitempty"`
	Name      string
	HitPoints int
	Skills    utils.Set

	Strength int
	Vitality int
}

func (*Character) AddSkill

func (self *Character) AddSkill(id types.Id)

func (*Character) GetCapacity

func (self *Character) GetCapacity() int

func (*Character) GetHealth

func (self *Character) GetHealth() int

func (*Character) GetHitPoints

func (self *Character) GetHitPoints() int

func (*Character) GetName

func (self *Character) GetName() string

func (*Character) GetRoomId

func (self *Character) GetRoomId() types.Id

func (*Character) GetSkills

func (self *Character) GetSkills() []types.Id

func (*Character) GetStrength

func (self *Character) GetStrength() int

func (*Character) HasSkill

func (self *Character) HasSkill(id types.Id) bool

func (*Character) Heal

func (self *Character) Heal(hitpoints int)

func (*Character) Hit

func (self *Character) Hit(hitpoints int)

func (*Character) RemoveSkill

func (self *Character) RemoveSkill(id types.Id)

func (*Character) SetHealth

func (self *Character) SetHealth(health int)

func (*Character) SetHitPoints

func (self *Character) SetHitPoints(hitpoints int)

func (*Character) SetName

func (self *Character) SetName(name string)

func (*Character) SetRoomId

func (self *Character) SetRoomId(id types.Id)

type Collection

type Collection interface {
	Find(interface{}) Query
	FindId(interface{}) Query
	RemoveId(interface{}) error
	Remove(interface{}) error
	DropCollection() error
	UpdateId(interface{}, interface{}) error
	UpsertId(interface{}, interface{}) error
}

type Container

type Container struct {
	DbObject `bson:",inline"`
	Cash     int
	Capacity int
	Weight   int
}

func (*Container) AddCash

func (self *Container) AddCash(amount int)

func (*Container) GetCapacity

func (self *Container) GetCapacity() int

func (*Container) GetCash

func (self *Container) GetCash() int

func (*Container) RemoveCash

func (self *Container) RemoveCash(amount int)

func (*Container) SetCapacity

func (self *Container) SetCapacity(limit int)

func (*Container) SetCash

func (self *Container) SetCash(cash int)

type Database

type Database interface {
	C(string) Collection
}

type DbObject

type DbObject struct {
	Id types.Id `bson:"_id"`
	// contains filtered or unexported fields
}

func (*DbObject) Destroy

func (self *DbObject) Destroy()

func (*DbObject) GetId

func (self *DbObject) GetId() types.Id

func (*DbObject) IsDestroyed

func (self *DbObject) IsDestroyed() bool

func (*DbObject) ReadLock

func (self *DbObject) ReadLock()

func (*DbObject) ReadUnlock

func (self *DbObject) ReadUnlock()

func (*DbObject) SetId

func (self *DbObject) SetId(id types.Id)

func (*DbObject) WriteLock

func (self *DbObject) WriteLock()

func (*DbObject) WriteUnlock

func (self *DbObject) WriteUnlock()

type Effect

type Effect struct {
	DbObject `bson:",inline"`

	Type     types.EffectKind
	Name     string
	Power    int
	Cost     int
	Variance int
	Speed    int
	Time     int
}

func (*Effect) GetCost

func (self *Effect) GetCost() int

func (*Effect) GetName

func (self *Effect) GetName() string

func (*Effect) GetPower

func (self *Effect) GetPower() int

func (*Effect) GetSpeed

func (self *Effect) GetSpeed() int

func (*Effect) GetTime

func (self *Effect) GetTime() int

func (*Effect) GetType

func (self *Effect) GetType() types.EffectKind

func (*Effect) GetVariance

func (self *Effect) GetVariance() int

func (*Effect) SetCost

func (self *Effect) SetCost(cost int)

func (*Effect) SetName

func (self *Effect) SetName(name string)

func (*Effect) SetPower

func (self *Effect) SetPower(power int)

func (*Effect) SetSpeed

func (self *Effect) SetSpeed(speed int)

func (*Effect) SetTime

func (self *Effect) SetTime(speed int)

func (*Effect) SetType

func (self *Effect) SetType(effectKind types.EffectKind)

func (*Effect) SetVariance

func (self *Effect) SetVariance(variance int)

type Exit

type Exit struct {
	Locked bool
}

type Item

type Item struct {
	Container `bson:",inline"`

	TemplateId  types.Id
	Locked      bool
	ContainerId types.Id
}

func NewItem

func NewItem(templateId types.Id) *Item

func (*Item) GetCapacity

func (self *Item) GetCapacity() int

func (*Item) GetContainerId

func (self *Item) GetContainerId() types.Id

func (*Item) GetName

func (self *Item) GetName() string

func (*Item) GetTemplate

func (self *Item) GetTemplate() types.Template

func (*Item) GetTemplateId

func (self *Item) GetTemplateId() types.Id

func (*Item) GetValue

func (self *Item) GetValue() int

func (*Item) IsLocked

func (self *Item) IsLocked() bool

func (*Item) SetContainerId

func (self *Item) SetContainerId(id types.Id, from types.Id) bool

func (*Item) SetLocked

func (self *Item) SetLocked(locked bool)

type Iterator

type Iterator interface {
	All(interface{}) error
}

type MongoCollection

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

func (MongoCollection) DropCollection

func (mc MongoCollection) DropCollection() error

func (MongoCollection) Find

func (mc MongoCollection) Find(selector interface{}) Query

func (MongoCollection) FindId

func (mc MongoCollection) FindId(id interface{}) Query

func (MongoCollection) Remove

func (mc MongoCollection) Remove(selector interface{}) error

func (MongoCollection) RemoveId

func (mc MongoCollection) RemoveId(id interface{}) error

func (MongoCollection) UpdateId

func (mc MongoCollection) UpdateId(id interface{}, change interface{}) error

func (MongoCollection) UpsertId

func (mc MongoCollection) UpsertId(id interface{}, change interface{}) error

type MongoDatabase

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

func (MongoDatabase) C

func (md MongoDatabase) C(collectionName string) Collection

type MongoIterator

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

func (MongoIterator) All

func (mi MongoIterator) All(result interface{}) error

type MongoQuery

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

func (MongoQuery) Count

func (mq MongoQuery) Count() (int, error)

func (MongoQuery) Iter

func (mq MongoQuery) Iter() Iterator

func (MongoQuery) One

func (mq MongoQuery) One(result interface{}) error

type MongoSession

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

func NewMongoSession

func NewMongoSession(session *mgo.Session) *MongoSession

func (MongoSession) DB

func (ms MongoSession) DB(dbName string) Database

type Npc

type Npc struct {
	Character `bson:",inline"`

	SpawnerId types.Id `bson:",omitempty"`

	Roaming      bool
	Conversation string
}

func NewNpc

func NewNpc(name string, roomId types.Id, spawnerId types.Id) *Npc

func (*Npc) GetConversation

func (self *Npc) GetConversation() string

func (*Npc) GetRoaming

func (self *Npc) GetRoaming() bool

func (*Npc) PrettyConversation

func (self *Npc) PrettyConversation() string

func (*Npc) SetConversation

func (self *Npc) SetConversation(conversation string)

func (*Npc) SetRoaming

func (self *Npc) SetRoaming(roaming bool)

type Pc

type Pc struct {
	Character `bson:",inline"`

	UserId types.Id
	// contains filtered or unexported fields
}

func NewPc

func NewPc(name string, userId types.Id, roomId types.Id) *Pc

func (*Pc) GetUserId

func (self *Pc) GetUserId() types.Id

func (*Pc) IsOnline

func (self *Pc) IsOnline() bool

func (*Pc) SetOnline

func (self *Pc) SetOnline(online bool)

func (*Pc) SetUserId

func (self *Pc) SetUserId(id types.Id)

type Query

type Query interface {
	Count() (int, error)
	One(interface{}) error
	Iter() Iterator
}

type Room

type Room struct {
	Container `bson:",inline"`

	ZoneId      types.Id
	AreaId      types.Id `bson:",omitempty"`
	Title       string
	Description string
	Links       map[string]types.Id
	Location    types.Coordinate

	Exits map[types.Direction]*Exit
}

func NewRoom

func NewRoom(zoneId types.Id, location types.Coordinate) *Room

func (*Room) GetAreaId

func (self *Room) GetAreaId() types.Id

func (*Room) GetDescription

func (self *Room) GetDescription() string

func (*Room) GetExits

func (self *Room) GetExits() []types.Direction
func (self *Room) GetLinks() map[string]types.Id

func (*Room) GetLocation

func (self *Room) GetLocation() types.Coordinate

func (*Room) GetTitle

func (self *Room) GetTitle() string

func (*Room) GetZoneId

func (self *Room) GetZoneId() types.Id

func (*Room) HasExit

func (self *Room) HasExit(dir types.Direction) bool

func (*Room) IsLocked

func (self *Room) IsLocked(dir types.Direction) bool

func (*Room) LinkNames

func (self *Room) LinkNames() []string

func (*Room) NextLocation

func (self *Room) NextLocation(direction types.Direction) types.Coordinate
func (self *Room) RemoveLink(name string)

func (*Room) SetAreaId

func (self *Room) SetAreaId(areaId types.Id)

func (*Room) SetDescription

func (self *Room) SetDescription(description string)

func (*Room) SetExitEnabled

func (self *Room) SetExitEnabled(dir types.Direction, enabled bool)
func (self *Room) SetLink(name string, roomId types.Id)

func (*Room) SetLocation

func (self *Room) SetLocation(location types.Coordinate)

func (*Room) SetLocked

func (self *Room) SetLocked(dir types.Direction, locked bool)

func (*Room) SetTitle

func (self *Room) SetTitle(title string)

func (*Room) SetZoneId

func (self *Room) SetZoneId(zoneId types.Id)

type Session

type Session interface {
	DB(string) Database
}

type Skill

type Skill struct {
	DbObject `bson:",inline"`

	Effects utils.Set
	Name    string
}

func NewSkill

func NewSkill(name string) *Skill

func (*Skill) AddEffect

func (self *Skill) AddEffect(id types.Id)

func (*Skill) GetEffects

func (self *Skill) GetEffects() []types.Id

func (*Skill) GetName

func (self *Skill) GetName() string

func (*Skill) HasEffect

func (self *Skill) HasEffect(id types.Id) bool

func (*Skill) RemoveEffect

func (self *Skill) RemoveEffect(id types.Id)

func (*Skill) SetName

func (self *Skill) SetName(name string)

type Spawner

type Spawner struct {
	Character `bson:",inline"`

	AreaId types.Id
	Count  int
}

func NewSpawner

func NewSpawner(name string, areaId types.Id) *Spawner

func (*Spawner) GetAreaId

func (self *Spawner) GetAreaId() types.Id

func (*Spawner) GetCount

func (self *Spawner) GetCount() int

func (*Spawner) SetCount

func (self *Spawner) SetCount(count int)

type Store

type Store struct {
	Container `bson:",inline"`

	Name   string
	RoomId types.Id
}

func NewStore

func NewStore(name string, roomId types.Id) *Store

func (*Store) GetName

func (self *Store) GetName() string

func (*Store) SetName

func (self *Store) SetName(name string)

type Template

type Template struct {
	DbObject `bson:",inline"`
	Name     string
	Value    int
	Weight   int
	Capacity int
}

func NewTemplate

func NewTemplate(name string) *Template

func (*Template) GetCapacity

func (self *Template) GetCapacity() int

func (*Template) GetName

func (self *Template) GetName() string

func (*Template) GetValue

func (self *Template) GetValue() int

func (*Template) GetWeight

func (self *Template) GetWeight() int

func (*Template) SetCapacity

func (self *Template) SetCapacity(capacity int)

func (*Template) SetName

func (self *Template) SetName(name string)

func (*Template) SetValue

func (self *Template) SetValue(value int)

func (*Template) SetWeight

func (self *Template) SetWeight(weight int)

type User

type User struct {
	DbObject `bson:",inline"`

	Name      string
	ColorMode types.ColorMode
	Password  []byte
	Admin     bool
	// contains filtered or unexported fields
}

func NewUser

func NewUser(name string, password string, admin bool) *User

func (*User) GetColorMode

func (self *User) GetColorMode() types.ColorMode

func (*User) GetConnection

func (self *User) GetConnection() net.Conn

func (*User) GetInput

func (self *User) GetInput(prompt string) string

func (*User) GetName

func (self *User) GetName() string

func (*User) GetPassword

func (self *User) GetPassword() []byte

GetPassword returns the SHA1 of the user's password

func (*User) GetTerminalType

func (self *User) GetTerminalType() string

func (*User) GetWindowSize

func (self *User) GetWindowSize() (width int, height int)

func (*User) IsAdmin

func (self *User) IsAdmin() bool

func (*User) IsOnline

func (self *User) IsOnline() bool

func (*User) SetAdmin

func (self *User) SetAdmin(admin bool)

func (*User) SetColorMode

func (self *User) SetColorMode(cm types.ColorMode)

func (*User) SetConnection

func (self *User) SetConnection(conn net.Conn)

func (*User) SetName

func (self *User) SetName(name string)

func (*User) SetOnline

func (self *User) SetOnline(online bool)

func (*User) SetPassword

func (self *User) SetPassword(password string)

SetPassword SHA1 hashes the password before saving it to the database

func (*User) SetTerminalType

func (self *User) SetTerminalType(tt string)

func (*User) SetWindowSize

func (self *User) SetWindowSize(width int, height int)

func (*User) VerifyPassword

func (self *User) VerifyPassword(password string) bool

func (*User) Write

func (self *User) Write(text string)

func (*User) WriteLine

func (self *User) WriteLine(line string, a ...interface{})

type World

type World struct {
	DbObject `bson:",inline"`
	Time     time.Time
}

func NewWorld

func NewWorld() *World

func (*World) AdvanceTime

func (self *World) AdvanceTime()

func (*World) GetTime

func (self *World) GetTime() types.Time

type Zone

type Zone struct {
	DbObject `bson:",inline"`

	Name string
}

func NewZone

func NewZone(name string) *Zone

func (*Zone) GetName

func (self *Zone) GetName() string

func (*Zone) SetName

func (self *Zone) SetName(name string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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