Documentation
¶
Index ¶
- Constants
- Variables
- func IsAngle(angleCandidate string) bool
- func IsBlocktype(blocktypeCandidate string) bool
- func IsDir(dirCandidate string) bool
- func IsDistance(distanceCandidate int) bool
- func SetMapDimensions(width, height int)
- type Battle
- type BlockEntity
- type EntityResp
- type Health
- type Location
- type MapEntity
- func (me *MapEntity) GetMatrixSectionFromMapentity(width, height int, p *Player, sync bool) (gameMatrix [][]*BlockEntity)
- func (me *MapEntity) GetNewLineFromMapEntity(width int, p *Player, direction string) (gameLine [][]*BlockEntity)
- func (me *MapEntity) LeaveArea(p *Player, l Location)
- func (me *MapEntity) PInMatrix() bool
- func (me *MapEntity) PInRenderArea(l Location) NotifyGroup
- func (me *MapEntity) TryJoinAreaSynced(p *Player, l Location) (joined bool, ng NotifyGroup)
- type NotifyGroup
- type OpLimitations
- type Player
- func (p *Player) Attack(beforeRespawn func(*Player, NotifyGroup), ...) (enemyHealth int, ng NotifyGroup, err error)
- func (p *Player) Defend() (ng NotifyGroup, err error)
- func (p *Player) Environment() (blocktypeMatrix [][]string, ng NotifyGroup, err error)
- func (p *Player) GetHealth() (health int, ng NotifyGroup)
- func (p *Player) Move(dir string) (ng NotifyGroup, err error)
- func (p *Player) Radar() (playerCount int, ng NotifyGroup, err error)
- func (p *Player) Respawn() error
- func (p *Player) RespawnSynced() error
- func (p *Player) Rotate(angle string) NotifyGroup
- func (p *Player) SafeHealthSynced() int
- func (p *Player) Scout(distance int) (playerCount int, ng NotifyGroup, err error)
- func (p *Player) Spawn() error
- func (p *Player) SpawnSynced() error
- func (p *Player) Undefend() (ng NotifyGroup, err error)
- func (p *Player) Watch() (playerhealthMatrix [][]int, ng NotifyGroup, err error)
- type PlayerResp
- type ViewableMapentity
Constants ¶
const ( // DirNorth is the exported direction north DirNorth = "north" // DirEast is the exported direction north DirEast = "east" // DirSouth is the exported direction north DirSouth = "south" // DirWest is the exported direction north DirWest = "west" )
Variables ¶
var ( // ErrNoEnemy is an error if there's no enemy ErrNoEnemy = errors.New("No Enemy") // ErrOutOfMap is an error when a position is out of the map ErrOutOfMap = errors.New("Position is out of Map") // ErrNoMoveOutOfMap comes when the player wants to move out of the map ErrNoMoveOutOfMap = errors.New("Cannot move outside the map") // ErrHasResident appears when a block already has a resident and an action // should happen ErrHasResident = errors.New("Block already has a resident") // ErrAlreadyDef describes that the player already is defending ErrAlreadyDef = errors.New("Player is already defending") // ErrAlreadyUndef describes that the player is already undefending ErrAlreadyUndef = errors.New("Player is already undefending") // ErrCantMoveOFDefending means thath the player cant move because of defending ErrCantMoveOFDefending = errors.New("Player is not able to move, because of defending") )
var ( // MapWidth is the length in x-direction MapWidth = 11 // MapHeight is the length in y-direction MapHeight = 11 // HalfmapWidth is the half value of 'MapWidth' HalfmapWidth = MapWidth / 2 // HalfmapHeight is the half value of 'MapHeight' HalfmapHeight = MapHeight / 2 // RenderWidth is the visible area for a player in x-direction RenderWidth = 11 // RenderHeight is the visible area for a player in y-direction RenderHeight = 11 // HrWidth is the half value of 'RenderWidth' HrWidth = (RenderWidth - 1) / 2 // HrHeight is the half value of 'RenderHeight' HrHeight = (RenderHeight - 1) / 2 // MaxHealth is the default value of a player's character when he has // full health points MaxHealth = 100 )
Functions ¶
func IsBlocktype ¶
IsBlocktype determines whether the `blocktypeCandidate` is actually a valid blocktype
func IsDistance ¶
IsDistance determines wether the `distanceCanidate` is actually a valid distance
func SetMapDimensions ¶
func SetMapDimensions(width, height int)
SetMapDimensions sets the default map dimensions (e.g. width and health)
Types ¶
type BlockEntity ¶
BlockEntity represents a single point (block) in the map. It holds infos about it's environment and possible residents.
func (*BlockEntity) HasResident ¶
func (be *BlockEntity) HasResident() bool
HasResident reports if a player is currently in this block or not.
func (*BlockEntity) JoinArea ¶
func (be *BlockEntity) JoinArea(p *Player)
JoinArea marks the passed player as the current resident of this block.
func (*BlockEntity) LeaveArea ¶
func (be *BlockEntity) LeaveArea()
LeaveArea dismarks the player which is currently the resident of this block to be a resident.
type EntityResp ¶
type EntityResp struct {
Blocktype string `json:"bt"`
Player *PlayerResp `json:"p"`
}
EntityResp is the response value of a specific location with the values 'Blocktype' and 'Player'
type Health ¶
Health is a struct that describes the Health of a player
func (*Health) TakeDamage ¶
TakeDamage returns the health of the player after taking dmg
type Location ¶
Location represents a two-dimensional point in a matrix. It's values are zero-based. Therfore (0, 0) is the first point in the upper left.
func (*Location) AddDirection ¶
AddDirection manipulates the current location by a factor of one into the cardinal direction specified by the `dir` parameter. `dir` must be a valid direction representation. Check with `vbge.IsDir`. This function doesn't validate the resulting location. Therefore it's maybe out-of-map. Check with `(*Location).IsInMap`
func (*Location) DeepCopy ¶
DeepCopy allocates new memory and copies all the contents of the current location into the newly allocated one. Afterwards the pointer of the new struct is returned.
func (*Location) IsInMap ¶
IsInMap checks whether the location is in the map or not. Determined with `(X && Y > 0) && (X < MapWidth) && (Y < MapHeight)`
func (*Location) RelativeFrom ¶
RelativeFrom returns the relative position from the center of the Rendermapsize
type MapEntity ¶
type MapEntity struct {
Height int
Width int
Matrix [][]*BlockEntity
SyncRoot sync.Mutex
}
MapEntity describes a single map instance.
func NewMapEntity ¶
NewMapEntity allocates memory for a new map with the size specified by the `width` and `height` parameter.
func (*MapEntity) GetMatrixSectionFromMapentity ¶
func (me *MapEntity) GetMatrixSectionFromMapentity(width, height int, p *Player, sync bool) (gameMatrix [][]*BlockEntity)
GetMatrixSectionFromMapentity returns the 'viewable' matrix of a given player
func (*MapEntity) GetNewLineFromMapEntity ¶
func (me *MapEntity) GetNewLineFromMapEntity(width int, p *Player, direction string) (gameLine [][]*BlockEntity)
GetNewLineFromMapEntity is returning a 11x1 dim (RenderWidth), usually called when a player is moving
func (*MapEntity) LeaveArea ¶
LeaveArea is calling (*BlockEntity).LeaveArea() to set a location after moving to nil, so the location isn't blocked anymore.
func (*MapEntity) PInMatrix ¶
PInMatrix returns true if any player is in the matrix of the given MapEntity. If a player occurs, true is returned
func (*MapEntity) PInRenderArea ¶
func (me *MapEntity) PInRenderArea(l Location) NotifyGroup
PInRenderArea returns all the players that are inside the render area around the passend location. Result is returned as a `NotifyGroup`. This function isn't safe for concurrent use.
func (*MapEntity) TryJoinAreaSynced ¶
func (me *MapEntity) TryJoinAreaSynced(p *Player, l Location) (joined bool, ng NotifyGroup)
TryJoinAreaSynced checks whether the area passed is empty and hence joinable. If so it joins `(*BlockEntity).JoinArea` and calculates the `NotifyGroup` for this operation. This function is safe for concurrent use.
type NotifyGroup ¶
type NotifyGroup []*Player
NotifyGroup specifies a set of `*Player` that should be informed about a specific event.
type OpLimitations ¶
type OpLimitations struct {
Rotate ratelimit.Limiter
Move ratelimit.Limiter
Radar ratelimit.Limiter
Scout ratelimit.Limiter
Environment ratelimit.Limiter
Watch ratelimit.Limiter
Attack ratelimit.Limiter
Defend ratelimit.Limiter
Health ratelimit.Limiter
}
OpLimitations stores ratelimit datastructures for each callable player operation
func NewOpLimitations ¶
func NewOpLimitations() *OpLimitations
NewOpLimitations returns a new pointer to a new OpLimitation container with default time-limitations already set.
type Player ¶
type Player struct {
UserID int
GRenderID string
PicLink string
Map *MapEntity
Location *Location
WatchDir string
Health *Health
IsDefending bool
Kills int
Deaths int
Rl *OpLimitations
CharacterType string
}
Player represents a single character in the game. It collects all infos needed.
func NewDebugPlayer ¶
NewDebugPlayer returns a player that can be used for DEMO-purposes
func NewPlayerWithSpawn ¶
NewPlayerWithSpawn creates a new player and spawn the player on the map
func (*Player) Attack ¶
func (p *Player) Attack(beforeRespawn func(*Player, NotifyGroup), afterRespawn func(*Player, NotifyGroup)) (enemyHealth int, ng NotifyGroup, err error)
Attack implements https://sdk-wiki.vikebot.com/#attack
func (*Player) Defend ¶
func (p *Player) Defend() (ng NotifyGroup, err error)
Defend implements https://sdk-wiki.vikebot.com/#defend-and-undefend
func (*Player) Environment ¶
func (p *Player) Environment() (blocktypeMatrix [][]string, ng NotifyGroup, err error)
Environment implements https://sdk-wiki.vikebot.com/#environment
func (*Player) GetHealth ¶
func (p *Player) GetHealth() (health int, ng NotifyGroup)
GetHealth returns the health as an int value of a player
func (*Player) Move ¶
func (p *Player) Move(dir string) (ng NotifyGroup, err error)
Move implements https://sdk-wiki.vikebot.com/#move
func (*Player) Radar ¶
func (p *Player) Radar() (playerCount int, ng NotifyGroup, err error)
Radar implements https://sdk-wiki.vikebot.com/#radar
func (*Player) Respawn ¶
Respawn removes the player from it's current position and add calls `Spawn` to place it again.
func (*Player) RespawnSynced ¶
RespawnSynced is like `Respawn` but locks the Map
func (*Player) Rotate ¶
func (p *Player) Rotate(angle string) NotifyGroup
Rotate implements https://sdk-wiki.vikebot.com/#rotate
func (*Player) SafeHealthSynced ¶
SafeHealthSynced returns a definite state of player health
func (*Player) Scout ¶
func (p *Player) Scout(distance int) (playerCount int, ng NotifyGroup, err error)
Scout implements https://sdk-wiki.vikebot.com/#scout
func (*Player) Spawn ¶
Spawn places the player randomly on the map as long as the location doesn't already have a resident. If so Spawn will retry 20 times. If no suitable location is found an error is returned.
func (*Player) SpawnSynced ¶
SpawnSynced is like `Spawn` but locks the Map
func (*Player) Undefend ¶
func (p *Player) Undefend() (ng NotifyGroup, err error)
Undefend implements https://sdk-wiki.vikebot.com/#defend-and-undefend
func (*Player) Watch ¶
func (p *Player) Watch() (playerhealthMatrix [][]int, ng NotifyGroup, err error)
Watch implements https://sdk-wiki.vikebot.com/#watch
type PlayerResp ¶
type PlayerResp struct {
GRID string `json:"grid"`
Health int `json:"health"`
CharacterType string `json:"ct"`
WatchDir string `json:"watchdir"`
Location Location `json:"location"`
}
PlayerResp is the response value of player for vbwatch
type ViewableMapentity ¶
type ViewableMapentity struct {
Height int `json:"height"`
Witdh int `json:"width"`
Matrix [][]*EntityResp `json:"matrix"`
}
ViewableMapentity is nearly the same like 'MapEntity' but only the for a specific player visible matrix including other players and blocktypes
func GetNewLineMapentity ¶
func GetNewLineMapentity(width, userID int, game *Battle, direction string) (newLineMeViewable *ViewableMapentity, err error)
GetNewLineMapentity returns a new mapentity with a size of 1x11 or 11x1 depends on moving direction
func GetViewableMapentity ¶
func GetViewableMapentity(width, height, userID int, game *Battle, sync bool) (viewableMapentity *ViewableMapentity, err error)
GetViewableMapentity returns a Mapentity for a specific player