model

package
v0.0.0-...-1a052b4 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2015 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastMessage

func BroadcastMessage(from *db.Character, message string)

BroadcastMessage sends a message to all users that are logged in

func CharactersIn

func CharactersIn(room *db.Room) db.CharacterList

func CreateArea

func CreateArea(name string, zone *db.Zone) (*db.Area, error)

func CreateItem

func CreateItem(name string) *db.Item

CreateItem creates an item object in the database with the given name and adds it to the model. It's up to the caller to ensure that the item actually gets put somewhere meaningful.

func CreateNpc

func CreateNpc(name string, room *db.Room) *db.NonPlayerChar

CreateNpc is a convenience function for creating a new character object that is an NPC (as opposed to an actual player-controlled character)

func CreatePlayerCharacter

func CreatePlayerCharacter(name string, parentUser *db.User, startingRoom *db.Room) *db.PlayerChar

CreatePlayerCharacter creates a new player-controlled Character object in the database and adds it to the model. A pointer to the new character object is returned.

func CreateRoom

func CreateRoom(zone *db.Zone, location db.Coordinate) (*db.Room, error)

CreateRoom creates a new Room object in the database and adds it to the model. A pointer to the new Room object is returned.

func CreateUser

func CreateUser(name string, password string) *db.User

CreateUser creates a new User object in the database and adds it to the model. A pointer to the new User object is returned.

func CreateZone

func CreateZone(name string) (*db.Zone, error)

CreateZone creates a new Zone object in the database and adds it to the model. A pointer to the new Zone object is returned.

func DeleteArea

func DeleteArea(area *db.Area)

func DeleteItem

func DeleteItem(item *db.Item)

DeleteItem removes the item associated with the given id from the model and from the database

func DeleteItemId

func DeleteItemId(itemId bson.ObjectId)

func DeleteNpc

func DeleteNpc(npc *db.NonPlayerChar)

func DeleteNpcId

func DeleteNpcId(id bson.ObjectId)

func DeleteObject

func DeleteObject(obj ds.Identifiable)

func DeletePlayerCharacter

func DeletePlayerCharacter(pc *db.PlayerChar)

DeletePlayerCharacter removes the character (either NPC or player-controlled) associated with the given id from the model and from the database

func DeletePlayerCharacterId

func DeletePlayerCharacterId(id bson.ObjectId)

func DeleteRoom

func DeleteRoom(room *db.Room)

DeleteRoom removes the given room object from the model and the database. It also disables all exits in neighboring rooms that lead to the given room.

func DeleteUser

func DeleteUser(user *db.User)

Removes the given User from the model. Removes it from the database as well.

func DeleteUserId

func DeleteUserId(userId bson.ObjectId)

func DeleteZone

func DeleteZone(zone *db.Zone)

Removes the given Zone from the model and the database

func DirectionBetween

func DirectionBetween(from, to *db.Room) db.Direction

Returns the exit direction of the given room if it is adjacent, otherwise DirectionNone

func Emote

func Emote(from *db.Character, message string)

Emote sends an emote message to all characters in the given character's room

func GetArea

func GetArea(areaId bson.ObjectId) *db.Area

func GetAreaByName

func GetAreaByName(name string) *db.Area

func GetAreas

func GetAreas(zone *db.Zone) db.Areas

func GetCharacterByName

func GetCharacterByName(name string) *db.Character

func GetItem

func GetItem(id bson.ObjectId) *db.Item

GetItem returns the Item object associated the given id

func GetItems

func GetItems(itemIds []bson.ObjectId) []*db.Item

GetItems returns the Items object associated the given ids

func GetNpc

func GetNpc(id bson.ObjectId) *db.NonPlayerChar

func GetNpcByName

func GetNpcByName(name string) *db.NonPlayerChar

func GetNpcs

func GetNpcs() db.NonPlayerCharList

func GetOnlinePlayerCharacters

func GetOnlinePlayerCharacters() []*db.PlayerChar

GetOnlinePlayerCharacters returns a list of all of the characters who are online

func GetOrCreatePlayerCharacter

func GetOrCreatePlayerCharacter(name string, parentUser *db.User, startingRoom *db.Room) *db.PlayerChar

GetOrCreatePlayerCharacter attempts to retrieve the existing user from the model by the given name. if none exists, then a new one is created. If the name matches an NPC (rather than a player) then nil will be returned.

func GetOrCreateUser

func GetOrCreateUser(name string, password string) *db.User

GetOrCreateUser attempts to retrieve the existing user from the model by the given name. if none exists, then a new one is created with the given credentials.

func GetPlayerCharacter

func GetPlayerCharacter(id bson.ObjectId) *db.PlayerChar

GetPlayerCharacter returns the Character object associated the given Id

func GetPlayerCharacterByName

func GetPlayerCharacterByName(name string) *db.PlayerChar

GetPlayerCharacaterByName searches for a character with the given name. Returns a character object, or nil if it wasn't found.

func GetRoom

func GetRoom(id bson.ObjectId) *db.Room

GetRoom returns the room object associated with the given id

func GetRoomByLocation

func GetRoomByLocation(coordinate db.Coordinate, zone *db.Zone) *db.Room

GetRoomByLocation searches for the room associated with the given coordinate in the given zone. Returns a nil room object if it was not found.

func GetRooms

func GetRooms() db.Rooms

GetRooms returns a list of all of the rooms in the entire model

func GetRoomsInZone

func GetRoomsInZone(zone *db.Zone) []*db.Room

GetRoomsInZone returns a slice containing all of the rooms that belong to the given zone

func GetUser

func GetUser(id bson.ObjectId) *db.User

GetUser returns the User object associated with the given id

func GetUserByName

func GetUserByName(username string) *db.User

GetUserByName searches for the User object with the given name. Returns a nil User if one was not found.

func GetUserCharacters

func GetUserCharacters(user *db.User) []*db.PlayerChar

GetUserCharacters returns all of the Character objects associated with the given user id

func GetUsers

func GetUsers() db.Users

GetUsers returns all of the User objects in the model

func GetZone

func GetZone(zoneId bson.ObjectId) *db.Zone

GetZone returns the zone object associated with the given id

func GetZoneByName

func GetZoneByName(name string) *db.Zone

GetZoneByName name searches for a zone with the given name

func GetZones

func GetZones() db.Zones

GetZones returns all of the zones in the model

func InCombat

func InCombat(character *database.Character) bool

func Init

func Init(session db.Session, dbName string) error

Initializes the global model object and starts up the main event loop

func ItemsIn

func ItemsIn(room *db.Room) []*db.Item

ItemsIn returns a slice containing all of the items in the given room

func Login

func Login(character *database.PlayerChar)

func Logout

func Logout(character *database.PlayerChar)

func MoveCharacter

func MoveCharacter(character *db.Character, direction db.Direction) (*db.Room, error)

MoveCharacter moves the given character in the given direction. If there is no exit in that direction, and error is returned. If there is an exit, but no room connected to it, then a room is automatically created for the character to move in to.

func MoveCharacterToLocation

func MoveCharacterToLocation(character *db.Character, zone *db.Zone, location db.Coordinate) (*db.Room, error)

MoveCharacter attempts to move the character to the given coordinates specific by location. Returns an error if there is no room to move to.

func MoveCharacterToRoom

func MoveCharacterToRoom(character *db.Character, newRoom *db.Room)

MoveCharacterTo room moves the character to the given room

func NpcsIn

func NpcsIn(room *db.Room) db.NonPlayerCharList

NpcsIn returns all of the NPC characters that are in the given room

func PlayerCharactersIn

func PlayerCharactersIn(room *db.Room, except *db.PlayerChar) db.PlayerCharList

PlayerCharactersIn returns a list of player characters that are in the given room

func Register

func Register() chan Event

func Say

func Say(from *db.Character, message string)

Say sends a message to all characters in the given character's room

func StartFight

func StartFight(attacker *database.Character, defender *database.Character)

func StopFight

func StopFight(attacker *database.Character)

func Tell

func Tell(from *db.Character, to *db.Character, message string)

Tell sends a message to the specified character

func Unregister

func Unregister(listenerToUnregsiter chan Event)

func ZoneCorners

func ZoneCorners(zone *db.Zone) (db.Coordinate, db.Coordinate)

ZoneCorners returns cordinates that indiate the highest and lowest points of the map in 3 dimensions

Types

type BroadcastEvent

type BroadcastEvent struct {
	Character *database.Character
	Message   string
}

func (BroadcastEvent) IsFor

func (self BroadcastEvent) IsFor(receiver *database.PlayerChar) bool

func (BroadcastEvent) ToString

func (self BroadcastEvent) ToString(receiver *database.Character) string

func (BroadcastEvent) Type

func (self BroadcastEvent) Type() EventType

type CombatEvent

type CombatEvent struct {
	Attacker *database.Character
	Defender *database.Character
	Damage   int
}

func (CombatEvent) IsFor

func (self CombatEvent) IsFor(receiver *database.PlayerChar) bool

func (CombatEvent) ToString

func (self CombatEvent) ToString(receiver *database.Character) string

func (CombatEvent) Type

func (self CombatEvent) Type() EventType

Combat

type CombatStartEvent

type CombatStartEvent struct {
	Attacker *database.Character
	Defender *database.Character
}

func (CombatStartEvent) IsFor

func (self CombatStartEvent) IsFor(receiver *database.PlayerChar) bool

func (CombatStartEvent) ToString

func (self CombatStartEvent) ToString(receiver *database.Character) string

func (CombatStartEvent) Type

func (self CombatStartEvent) Type() EventType

CombatStart

type CombatStopEvent

type CombatStopEvent struct {
	Attacker *database.Character
	Defender *database.Character
}

func (CombatStopEvent) IsFor

func (self CombatStopEvent) IsFor(receiver *database.PlayerChar) bool

func (CombatStopEvent) ToString

func (self CombatStopEvent) ToString(receiver *database.Character) string

func (CombatStopEvent) Type

func (self CombatStopEvent) Type() EventType

CombatStop

type CreateEvent

type CreateEvent struct {
	Object *database.DbObject
}

func (CreateEvent) IsFor

func (self CreateEvent) IsFor(receiver *database.PlayerChar) bool

func (CreateEvent) ToString

func (self CreateEvent) ToString(receiver *database.Character) string

func (CreateEvent) Type

func (self CreateEvent) Type() EventType

Create

type DestroyEvent

type DestroyEvent struct {
	Object *database.DbObject
}

func (DestroyEvent) IsFor

func (self DestroyEvent) IsFor(receiver *database.PlayerChar) bool

func (DestroyEvent) ToString

func (self DestroyEvent) ToString(receiver *database.Character) string

func (DestroyEvent) Type

func (self DestroyEvent) Type() EventType

Destroy

type EmoteEvent

type EmoteEvent struct {
	Character *database.Character
	Emote     string
}

func (EmoteEvent) IsFor

func (self EmoteEvent) IsFor(receiver *database.PlayerChar) bool

func (EmoteEvent) ToString

func (self EmoteEvent) ToString(receiver *database.Character) string

func (EmoteEvent) Type

func (self EmoteEvent) Type() EventType

Emote

type EnterEvent

type EnterEvent struct {
	Character  *database.Character
	Room       *database.Room
	SourceRoom *database.Room
}

func (EnterEvent) IsFor

func (self EnterEvent) IsFor(receiver *database.PlayerChar) bool

func (EnterEvent) ToString

func (self EnterEvent) ToString(receiver *database.Character) string

func (EnterEvent) Type

func (self EnterEvent) Type() EventType

Enter

type Event

type Event interface {
	Type() EventType
	ToString(receiver *database.Character) string
	IsFor(receiver *database.PlayerChar) bool
}

type EventType

type EventType int
const (
	CreateEventType      EventType = iota
	DestroyEventType     EventType = iota
	BroadcastEventType   EventType = iota
	SayEventType         EventType = iota
	EmoteEventType       EventType = iota
	TellEventType        EventType = iota
	EnterEventType       EventType = iota
	LeaveEventType       EventType = iota
	RoomUpdateEventType  EventType = iota
	LoginEventType       EventType = iota
	LogoutEventType      EventType = iota
	CombatStartEventType EventType = iota
	CombatStopEventType  EventType = iota
	CombatEventType      EventType = iota
	TimerEventType       EventType = iota
)

type LeaveEvent

type LeaveEvent struct {
	Character *database.Character
	Room      *database.Room
	DestRoom  *database.Room
}

func (LeaveEvent) IsFor

func (self LeaveEvent) IsFor(receiver *database.PlayerChar) bool

func (LeaveEvent) ToString

func (self LeaveEvent) ToString(receiver *database.Character) string

func (LeaveEvent) Type

func (self LeaveEvent) Type() EventType

Leave

type LoginEvent

type LoginEvent struct {
	Character *database.PlayerChar
}

func (LoginEvent) IsFor

func (self LoginEvent) IsFor(receiver *database.PlayerChar) bool

func (LoginEvent) ToString

func (self LoginEvent) ToString(receiver *database.Character) string

func (LoginEvent) Type

func (self LoginEvent) Type() EventType

Login

type LogoutEvent

type LogoutEvent struct {
	Character *database.PlayerChar
}

func (LogoutEvent) IsFor

func (self LogoutEvent) IsFor(receiver *database.PlayerChar) bool

func (LogoutEvent) ToString

func (self LogoutEvent) ToString(receiver *database.Character) string

func (LogoutEvent) Type

func (self LogoutEvent) Type() EventType

Logout

type RoomUpdateEvent

type RoomUpdateEvent struct {
	Room *database.Room
}

func (RoomUpdateEvent) IsFor

func (self RoomUpdateEvent) IsFor(receiver *database.PlayerChar) bool

func (RoomUpdateEvent) ToString

func (self RoomUpdateEvent) ToString(receiver *database.Character) string

func (RoomUpdateEvent) Type

func (self RoomUpdateEvent) Type() EventType

RoomUpdate

type SayEvent

type SayEvent struct {
	Character *database.Character
	Message   string
}

func (SayEvent) IsFor

func (self SayEvent) IsFor(receiver *database.PlayerChar) bool

func (SayEvent) ToString

func (self SayEvent) ToString(receiver *database.Character) string

func (SayEvent) Type

func (self SayEvent) Type() EventType

Say

type TellEvent

type TellEvent struct {
	From    *database.Character
	To      *database.Character
	Message string
}

func (TellEvent) IsFor

func (self TellEvent) IsFor(receiver *database.PlayerChar) bool

func (TellEvent) ToString

func (self TellEvent) ToString(receiver *database.Character) string

func (TellEvent) Type

func (self TellEvent) Type() EventType

Tell

type TimerEvent

type TimerEvent struct {
}

func (TimerEvent) IsFor

func (self TimerEvent) IsFor(receiver *database.PlayerChar) bool

func (TimerEvent) ToString

func (self TimerEvent) ToString(receiver *database.Character) string

func (TimerEvent) Type

func (self TimerEvent) Type() EventType

Timer

Jump to

Keyboard shortcuts

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