world

package
v0.0.0-...-1047d84 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2019 License: ISC Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//North Represents north.
	North int = iota
	//NorthWest Represents north-west.
	NorthWest
	//West Represents west.
	West
	//SouthWest Represents south-west.
	SouthWest
	//South represents south.
	South
	//SouthEast represents south-east
	SouthEast
	//East Represents east.
	East
	//NorthEast Represents north-east.
	NorthEast
	//MaxX Width of the game
	MaxX = 944
	//MaxY Height of the game
	MaxY = 3776
)
View Source
const (
	//PlaneGround Represents the value for the ground-level plane
	PlaneGround int = iota
	//PlaneSecond Represents the value for the second-story plane
	PlaneSecond
	//PlaneThird Represents the value for the third-story plane
	PlaneThird
	//PlaneBasement Represents the value for the basement plane
	PlaneBasement
)
View Source
const (
	//RegionSize Represents the size of the region
	RegionSize = 48
	//HorizontalPlanes Represents how many columns of regions there are
	HorizontalPlanes = MaxX/RegionSize + 1
	//VerticalPlanes Represents how many rows of regions there are
	VerticalPlanes = MaxY/RegionSize + 1
	//LowerBound Represents a dividing line in the exact middle of a region
	LowerBound = RegionSize / 2
)

Variables

View Source
var DeathSpot = NewLocation(0, 0)

DeathSpot The spot where mobs go to die.

View Source
var LogWarning = log.New(os.Stdout, "[WARNING] ", log.Ltime|log.Lshortfile)

LogWarning Log interface for warnings.

Functions

func AddNpc

func AddNpc(n *NPC)

AddNpc Add a NPC to the region.

func AddObject

func AddObject(o *Object)

AddObject Add an object to the region.

func AddPlayer

func AddPlayer(p *Player)

AddPlayer Add a player to the region.

func ParseDirection

func ParseDirection(s string) int

ParseDirection Tries to parse the direction indicated in s. If it can not match any direction, returns the zero-value for direction: north.

func RemoveNpc

func RemoveNpc(p *Player)

RemoveNpc Remove a NPC from the region.

func RemoveObject

func RemoveObject(o *Object)

RemoveObject Remove an object from the region.

func RemovePlayer

func RemovePlayer(p *Player)

RemovePlayer Remove a player from the region.

func ReplaceObject

func ReplaceObject(old *Object, newID int)

ReplaceObject Replaces old with a new game object with all of the same characteristics, except it's ID set to newID.

func WithinWorld

func WithinWorld(x, y int) bool

WithinWorld Returns true if the tile at x,y is within world boundaries, false otherwise.

Types

type AppearanceTable

type AppearanceTable struct {
	Head   int
	Body   int
	Male   bool
	Hair   int
	Top    int
	Bottom int
	Skin   int
}

AppearanceTable Represents a mobs appearance.

func NewAppearanceTable

func NewAppearanceTable(head, body int, male bool, hair, top, bottom, skin int) *AppearanceTable

NewAppearanceTable Returns a reference to a new appearance table with specified parameters

type AttrList

type AttrList map[string]interface{}

AttrList A type alias for a map of strings to empty interfaces, to hold generic mob information for easy serialization and to provide dynamic insertion/deletion of new mob properties easily

type AttributeList

type AttributeList struct {
	Set  map[string]interface{}
	Lock sync.RWMutex
}

AttributeList A concurrency-safe collection data type for storing misc. variables by a descriptive name.

func (*AttributeList) Range

func (attributes *AttributeList) Range(fn func(string, interface{}))

Range Runs fn(key, value) for every entry in this attribute list.

func (*AttributeList) SetVar

func (attributes *AttributeList) SetVar(name string, value interface{})

SetVar Sets the attribute mapped at name to value in the attribute map.

func (*AttributeList) UnsetVar

func (attributes *AttributeList) UnsetVar(name string)

UnsetVar Removes the attribute with the key `name` from this attribute set.

func (*AttributeList) VarBool

func (attributes *AttributeList) VarBool(name string, zero bool) bool

VarBool If there is an attribute assigned to the specified name, returns it. Otherwise, returns zero

func (*AttributeList) VarInt

func (attributes *AttributeList) VarInt(name string, zero int) int

VarInt If there is an attribute assigned to the specified name, returns it. Otherwise, returns zero

func (*AttributeList) VarLong

func (attributes *AttributeList) VarLong(name string, zero uint64) uint64

VarLong If there is an attribute assigned to the specified name, returns it. Otherwise, returns zero

type Entity

type Entity struct {
	Location
	Index int
}

Entity A stationary scene entity within the game world.

func (*Entity) AtCoords

func (e *Entity) AtCoords(x, y int) bool

AtCoords Returns true if the entity is at the specified coordinates, otherwise returns false

func (*Entity) AtLocation

func (e *Entity) AtLocation(location *Location) bool

AtLocation Returns true if the entity is at the specified location, otherwise returns false

type GroundItem

type GroundItem struct {
	Item
	Entity
}

GroundItem Represents a single ground item within the game.

type Inventory

type Inventory struct {
	List     []*Item
	Capacity int
}

Inventory Represents an inventory of items in the game.

func (*Inventory) Put

func (i *Inventory) Put(id int, qty int) int

Put Puts an item into the inventory with the specified id and quantity, and returns its index.

func (*Inventory) Remove

func (i *Inventory) Remove(index int) bool

Remove Removes item at index from this inventory.

type Item

type Item struct {
	ID     int
	Amount int
	Index  int
}

Item Represents a single item in the game.

type List

type List struct {
	List []interface{}
	// contains filtered or unexported fields
}

List Represents a list of scene entities.

func (*List) Add

func (l *List) Add(e interface{})

Add Add an entity to the list.

func (*List) Contains

func (l *List) Contains(e interface{}) bool

Contains Returns true if e is an element of l, otherwise returns false.

func (*List) NearbyNPCs

func (l *List) NearbyNPCs(p *Player) []*NPC

NearbyNPCs Might remove

func (*List) NearbyObjects

func (l *List) NearbyObjects(p *Player) []*Object

NearbyObjects Might remove

func (*List) NearbyPlayers

func (l *List) NearbyPlayers(p *Player) []*Player

NearbyPlayers Might remove

func (*List) Remove

func (l *List) Remove(e interface{})

Remove Removes Entity e from List l.

func (*List) RemovingObjects

func (l *List) RemovingObjects(p *Player) []*Object

RemovingObjects Might remove

func (*List) RemovingPlayers

func (l *List) RemovingPlayers(p *Player) []*Player

RemovingPlayers Might remove

type Location

type Location struct {
	X, Y int
	// contains filtered or unexported fields
}

Location A tile in the game world.

func NewLocation

func NewLocation(x, y int) *Location

NewLocation Returns a reference to a new instance of the Location data structure.

func (*Location) Above

func (l *Location) Above() Location

Above Returns the location directly above this one, if any. Otherwise, if we are on the top floor, returns itself.

func (*Location) Below

func (l *Location) Below() Location

Below Returns the location directly below this one, if any. Otherwise, if we are on the bottom floor, returns itself.

func (*Location) DeltaX

func (l *Location) DeltaX(other *Location) (deltaX int)

DeltaX Returns the difference between this locations X coord and the other locations X coord

func (*Location) DeltaY

func (l *Location) DeltaY(other *Location) (deltaY int)

DeltaY Returns the difference between this locations Y coord and the other locations Y coord

func (*Location) Equals

func (l *Location) Equals(o interface{}) bool

Equals Returns true if this location points to the same location as o

func (*Location) LongestDelta

func (l *Location) LongestDelta(other *Location) int

LongestDelta Returns the largest difference in coordinates between receiver and other

func (*Location) Plane

func (l *Location) Plane() int

Plane Calculates and returns the plane that this location is on.

func (*Location) PlaneY

func (l *Location) PlaneY(up bool) int

PlaneY Updates the location's Y coordinate, going up by one plane if up is true, else going down by one plane. Valid planes: ground=0, 2nd story=1, 3rd story=2, basement=3

func (*Location) String

func (l *Location) String() string

String Returns a string representation of the location

func (*Location) WithinRange

func (l *Location) WithinRange(other *Location, radius int) bool

WithinRange Returns true if the other location is within radius tiles of the receiver location, otherwise false.

func (*Location) WithinWorld

func (l *Location) WithinWorld() bool

WithinWorld Returns true if the tile at x,y is within world boundaries, false otherwise.

type Mob

type Mob struct {
	Entity
	State      MobState
	Skillset   *SkillTable
	Path       *Pathway
	PathLock   sync.RWMutex
	TransAttrs *AttributeList
}

Mob Represents a mobile entity within the game world.

func (*Mob) Busy

func (m *Mob) Busy() bool

Busy Returns true if this mobs state is anything other than idle. otherwise returns false.

func (*Mob) Direction

func (m *Mob) Direction() int

Direction Returns the mobs direction.

func (*Mob) FinishedPath

func (m *Mob) FinishedPath() bool

FinishedPath Returns true if the mobs path is nil, the paths current waypoint exceeds the number of waypoints available, or the next tile in the path is not a valid location, implying that we have reached our destination.

func (*Mob) ResetPath

func (m *Mob) ResetPath()

ResetPath Sets the mobs path to nil, to stop the traversal of the path instantly

func (*Mob) SetCoords

func (m *Mob) SetCoords(x, y int)

SetCoords Sets the mobs locations coordinates.

func (*Mob) SetDirection

func (m *Mob) SetDirection(direction int)

SetDirection Sets the mobs direction.

func (*Mob) SetLocation

func (m *Mob) SetLocation(location *Location)

SetLocation Sets the mobs location.

func (*Mob) SetPath

func (m *Mob) SetPath(path *Pathway)

SetPath Sets the mob's current pathway to path. If path is nil, effectively resets the mobs path.

func (*Mob) TraversePath

func (m *Mob) TraversePath()

TraversePath If the mob has a path, calling this method will change the mobs location to the next location described by said Path data structure. This should be called no more than once per game tick.

func (*Mob) UpdateDirection

func (m *Mob) UpdateDirection(destX, destY int)

UpdateDirection Updates the direction the mob is facing based on where the mob is trying to move, and where the mob is currently at.

type MobState

type MobState uint8

MobState Mob state.

const (
	//MSIdle The default MobState, means doing nothing.
	MSIdle MobState = iota
	//MSWalking The mob is walking.
	MSWalking
	//MSBanking The mob is banking.
	MSBanking
	//MSChatting The mob is chatting with a NPC
	MSChatting
	//MSMenuChoosing The mob is in a query menu
	MSMenuChoosing
	//MSTrading The mob is negotiating a trade.
	MSTrading
	//MSDueling The mob is negotiating a duel.
	MSDueling
	//MSFighting The mob is fighting.
	MSFighting
	//MSBatching The mob is performing a skill that repeats itself an arbitrary number of times.
	MSBatching
	//MSSleeping The mob is using a bed or sleeping bag, and trying to solve a CAPTCHA
	MSSleeping
)

type NPC

type NPC struct {
	Mob
	ID int
}

NPC Represents a single non-playable character within the game world.

type Object

type Object struct {
	ID        int
	Direction int
	Boundary  bool
	Entity
}

Object Represents a game object in the world.

func GetAllObjects

func GetAllObjects() (list []*Object)

GetAllObjects Returns a slice containing all objects in the game world.

func GetObject

func GetObject(x, y int) *Object

GetObject If there is an object at these coordinates, returns it. Otherwise, returns nil.

func NewObject

func NewObject(id, direction, x, y int, boundary bool) *Object

NewObject Returns a reference to a new instance of a game object.

func (*Object) Equals

func (o *Object) Equals(o1 interface{}) bool

Equals Returns true if o1 is an object reference with identical characteristics to o.

type Pathway

type Pathway struct {
	StartX, StartY  int
	WaypointsX      []int
	WaypointsY      []int
	CurrentWaypoint int
}

Pathway Represents a path for a mobile entity to traverse across the virtual world.

func NewPathway

func NewPathway(destX, destY int) *Pathway

NewPathway returns a new Pathway pointing to the specified coordinates. Must be a straight line from starting tile.

func NewPathwayComplete

func NewPathwayComplete(destX, destY int, waypointsX, waypointsY []int) *Pathway

NewPathwayComplete returns a new Pathway with the specified variables. destX and destY are a straight line, and waypoints define turns from that point.

func NewPathwayFromLocation

func NewPathwayFromLocation(l *Location) *Pathway

NewPathwayFromLocation returns a new Pathway pointing to the specified location. Must be a straight line from starting location.

func (*Pathway) NextTile

func (p *Pathway) NextTile(startX, startY int) *Location

NextTile Returns the next tile for the mob to move to in the pathway.

func (*Pathway) Start

func (p *Pathway) Start() *Location

Start Returns the location of the start of the path

func (*Pathway) Waypoint

func (p *Pathway) Waypoint(w int) *Location

Waypoint Returns the locattion of the specified waypoint

type Player

type Player struct {
	Username         string
	UserBase37       uint64
	Password         string
	FriendList       map[uint64]bool
	IgnoreList       []uint64
	LocalPlayers     *List
	LocalNPCs        *List
	LocalObjects     *List
	Updating         bool
	Appearances      []int
	DatabaseIndex    int
	Rank             int
	Appearance       *AppearanceTable
	AppearanceTicket int
	KnownAppearances map[int]int
	Attributes       *AttributeList
	Items            *Inventory
	Mob
}

Player Represents a single player.

func NewPlayer

func NewPlayer() *Player

NewPlayer Returns a reference to a new player.

func (*Player) AimPoints

func (p *Player) AimPoints() int

AimPoints Returns the players aim points

func (*Player) ArmourPoints

func (p *Player) ArmourPoints() int

ArmourPoints Returns the players armour points.

func (*Player) ChatBlocked

func (p *Player) ChatBlocked() bool

ChatBlocked Returns true if public chat is blocked for this player.

func (*Player) DuelBlocked

func (p *Player) DuelBlocked() bool

DuelBlocked Returns true if duel requests are blocked for this player.

func (*Player) EnterDoor

func (player *Player) EnterDoor(door *Object, dest *Location)

EnterDoor Replaces door object with an open door, sleeps for one second, and returns the closed door.

func (*Player) Fatigue

func (p *Player) Fatigue() int

Fatigue Returns the players current fatigue.

func (*Player) FightMode

func (p *Player) FightMode() int

FightMode Returns the players current fight mode.

func (*Player) FollowIndex

func (p *Player) FollowIndex() int

FollowIndex Returns the index of the mob we are following, or -1 if we aren't following anyone.

func (*Player) FollowRadius

func (p *Player) FollowRadius() int

FollowRadius Returns the radius within which we should follow whatever mob we are following, or -1 if we aren't following anyone.

func (*Player) FriendBlocked

func (p *Player) FriendBlocked() bool

FriendBlocked Returns true if private chat is blocked for this player.

func (*Player) Friends

func (p *Player) Friends(other uint64) bool

Friends Returns true if specified username is in our friend list.

func (*Player) GetClientSetting

func (p *Player) GetClientSetting(id int) bool

GetClientSetting Looks up the client setting with the specified ID, and returns it. If it can't be found, returns false.

func (*Player) Ignoring

func (p *Player) Ignoring(hash uint64) bool

Ignoring Returns true if specified username is in our ignore list.

func (*Player) IsFollowing

func (p *Player) IsFollowing() bool

IsFollowing Returns true if the player is following another mob, otherwise false.

func (*Player) MagicPoints

func (p *Player) MagicPoints() int

MagicPoints Returns the players magic points

func (*Player) NearbyObjects

func (p *Player) NearbyObjects() (objects []*Object)

NearbyObjects Returns nearby objects.

func (*Player) NearbyPlayers

func (p *Player) NearbyPlayers() (players []*Player)

NearbyPlayers Returns nearby players.

func (*Player) NewNPCs

func (p *Player) NewNPCs() (npcs []*NPC)

NewNPCs Returns nearby NPCs that this player is unaware of.

func (*Player) NewObjects

func (p *Player) NewObjects() (objects []*Object)

NewObjects Returns nearby objects that this player is unaware of.

func (*Player) NewPlayers

func (p *Player) NewPlayers() (players []*Player)

NewPlayers Returns nearby players that this player is unaware of.

func (*Player) PowerPoints

func (p *Player) PowerPoints() int

PowerPoints Returns the players power points.

func (*Player) PrayerPoints

func (p *Player) PrayerPoints() int

PrayerPoints Returns the players prayer points

func (*Player) RangedPoints

func (p *Player) RangedPoints() int

RangedPoints Returns the players ranged points.

func (*Player) Reconnecting

func (p *Player) Reconnecting() bool

Reconnecting Returns true if the player is reconnecting, false otherwise.

func (*Player) ResetFollowing

func (p *Player) ResetFollowing()

ResetFollowing Resets the transient attribute for storing the server index of the player we want to follow.

func (*Player) RunDistancedAction

func (p *Player) RunDistancedAction(dest *Location, action func())

RunDistancedAction Creates a distanced action belonging to this player, that runs action once the player arrives at dest, or cancels if we become busy, or we become unreasonably far from dest.

func (*Player) ServerSeed

func (p *Player) ServerSeed() uint64

ServerSeed Returns the seed for the ISAAC cipher provided by the server for this player, if set, otherwise returns 0

func (*Player) SetAimPoints

func (p *Player) SetAimPoints(i int)

SetAimPoints Sets the players aim points to i.

func (*Player) SetArmourPoints

func (p *Player) SetArmourPoints(i int)

SetArmourPoints Sets the players armour points to i.

func (*Player) SetClientSetting

func (p *Player) SetClientSetting(id int, flag bool)

SetClientSetting Sets the specified client setting to flag.

func (*Player) SetCoords

func (p *Player) SetCoords(x, y int)

SetCoords Sets the mobs locations coordinates.

func (*Player) SetFatigue

func (p *Player) SetFatigue(i int)

SetFatigue Sets the players current fatigue to i.

func (*Player) SetFightMode

func (p *Player) SetFightMode(i int)

SetFightMode Sets the players fightmode to i. 0=all,1=attack,2=defense,3=strength

func (*Player) SetFollowing

func (p *Player) SetFollowing(index int)

SetFollowing Sets the transient attribute for storing the server index of the player we want to follow to index.

func (*Player) SetLocation

func (p *Player) SetLocation(location *Location)

SetLocation Sets the mobs location.

func (*Player) SetMagicPoints

func (p *Player) SetMagicPoints(i int)

SetMagicPoints Sets the players magic points to i

func (*Player) SetPowerPoints

func (p *Player) SetPowerPoints(i int)

SetPowerPoints Sets the players power points to i

func (*Player) SetPrayerPoints

func (p *Player) SetPrayerPoints(i int)

SetPrayerPoints Sets the players prayer points to i

func (*Player) SetPrivacySettings

func (p *Player) SetPrivacySettings(chatBlocked, friendBlocked, tradeBlocked, duelBlocked bool)

SetPrivacySettings Sets privacy settings to specified values.

func (*Player) SetRangedPoints

func (p *Player) SetRangedPoints(i int)

SetRangedPoints Sets the players ranged points tp i.

func (*Player) SetReconnecting

func (p *Player) SetReconnecting(flag bool)

SetReconnecting Sets the player's reconnection status to flag.

func (*Player) SetServerSeed

func (p *Player) SetServerSeed(seed uint64)

SetServerSeed Sets the player's stored server seed to seed for later comparison to ensure we decrypted the login block properly and the player received the proper seed.

func (*Player) Teleport

func (p *Player) Teleport(x, y int)

Teleport Moves the player to x,y and sets a flag to remove said player from the local players list of every nearby player.

func (*Player) TradeBlocked

func (p *Player) TradeBlocked() bool

TradeBlocked Returns true if trade requests are blocked for this player.

type Region

type Region struct {
	Players *List
	NPCs    *List
	Objects *List
}

Region Represents a 48x48 section of map. The purpose of this is to keep track of entities in the entire world without having to allocate tiles individually, which would make search algorithms slower and utilizes a great deal of memory.

func GetRegion

func GetRegion(x, y int) *Region

GetRegion Returns the region that corresponds with the given coordinates. If it does not exist yet, it will allocate a new onr and store it for the lifetime of the application in the regions map.

func GetRegionFromLocation

func GetRegionFromLocation(loc *Location) *Region

GetRegionFromLocation Returns the region that corresponds with the given location. If it does not exist yet, it will allocate a new onr and store it for the lifetime of the application in the regions map.

func SurroundingRegions

func SurroundingRegions(x, y int) (regions [4]*Region)

SurroundingRegions Returns the regions surrounding the given coordinates. It wil

type SkillTable

type SkillTable struct {
	Current    [18]int
	Maximum    [18]int
	Experience [18]int
}

SkillTable Represents a skill table for a mob.

func (*SkillTable) CombatLevel

func (s *SkillTable) CombatLevel() int

CombatLevel Calculates and returns the combat level for this skill table.

Jump to

Keyboard shortcuts

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