game

package module
v0.0.0-...-2f6c813 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultWaitingWorld *world.World

Functions

func GlobalSessionManager

func GlobalSessionManager() *internal.Map[string, *Session]

Types

type Allower

type Allower interface {
	Allow(p *player.Player) (string, bool)
}

type Config

type Config struct {
	ID            uuid.UUID
	Log           *slog.Logger
	Impl          Impl
	MapsDir       string
	PlayerHandler player.Handler
	WorldHandler  world.Handler
	PlayAgainHook func(p *player.Player)
}

func (*Config) New

func (c *Config) New() (*Game, error)

type Factory

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

Factory is a factory for games.

func (*Factory) Games

func (f *Factory) Games() iter.Seq[*Game]

Games returns available games.

func (*Factory) Join

func (f *Factory) Join(p *player.Player) (*Game, bool)

Join joins a player to a game.

func (*Factory) NewGame

func (f *Factory) NewGame() *Game

NewGame creates a new game.

type FactoryConfig

type FactoryConfig struct {
	CreateFunc func() *Game
}

FactoryConfig is a configuration for a game factory.

func (FactoryConfig) New

func (c FactoryConfig) New() *Factory

New creates a new game factory.

type Game

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

Game ...

func (*Game) End

func (g *Game) End(tx *world.Tx)

End is used to end the game.

func (*Game) ID

func (g *Game) ID() uuid.UUID

ID returns the ID of the game.

func (*Game) Impl

func (g *Game) Impl() Impl

Impl returns the implementation of the game.

func (*Game) InGame

func (g *Game) InGame(p *player.Player) bool

InGame returns whether the player passed is in the game.

func (*Game) Join

func (g *Game) Join(p *player.Player) error

Join is used to join a player to the game. If the game is not in the waiting State, an error is returned.

func (*Game) Leave

func (g *Game) Leave(p *player.Player) (bool, error)

Leave is used to remove a player from the game.

func (*Game) Load

func (g *Game) Load() error

Load ...

func (*Game) Map

func (g *Game) Map() *Map

Map returns the map that the game is currently using.

func (*Game) MapLoaded

func (g *Game) MapLoaded() bool

MapLoaded returns whether the map is loaded.

func (*Game) Messagef

func (g *Game) Messagef(tx *world.Tx, format string, args ...any)

Messagef is used to send a message to all players in the game.

func (*Game) ParticipantByXUID

func (g *Game) ParticipantByXUID(xuid string) (*Participant, bool)

ParticipantByXUID returns the participant with the XUID passed.

func (*Game) ParticipantLen

func (g *Game) ParticipantLen() int

ParticipantLen returns the amount of participants in the game.

func (*Game) Participants

func (g *Game) Participants() iter.Seq[*Participant]

Participants returns the participants in the game.

func (*Game) Players

func (g *Game) Players(tx *world.Tx, fn func(p *player.Player, par *Participant))

Players are used to iterate over all players in the game, calling the function passed for each player.

func (*Game) PlayingParticipantLen

func (g *Game) PlayingParticipantLen() int

PlayingParticipantLen returns the amount of participants in the game that are playing.

func (*Game) PlayingParticipants

func (g *Game) PlayingParticipants() iter.Seq[*Participant]

PlayingParticipants returns the participants in the game that are playing.

func (*Game) PlayingPlayers

func (g *Game) PlayingPlayers(tx *world.Tx, fn func(p *player.Player, par *Participant))

PlayingPlayers are used to iterate over all players in the game that are playing, calling the function passed for each player.

func (*Game) SetSpectator

func (g *Game) SetSpectator(p *player.Player)

SetSpectator is used to set a player to spectator mode.

func (*Game) Start

func (g *Game) Start(tx *world.Tx)

Start is used to start the game. If the game is not in the waiting State, this function does nothing.

func (*Game) State

func (g *Game) State() State

State returns the current State of the game.

func (*Game) ValidTx

func (g *Game) ValidTx(tx *world.Tx) (valid bool)

ValidTx returns whether the transaction passed is valid for the game.

type Impl

type Impl interface {
	// MaxPlayers returns the maximum amount of players that can be in the game at once.
	MaxPlayers() int
	// MinPlayers returns the minimum amount of players that are required to start the game.
	MinPlayers() int
	// WaitingDuration returns the duration that the game should wait before starting after the minimum amount of players
	// has joined.
	WaitingDuration() time.Duration
	// HandleStart is called when the game should start.
	HandleStart(tx *world.Tx)
	// HandleQuit is called when a player quits the game.
	HandleQuit(tx *world.Tx, p *Participant)
	// HandleJoin is called when a player joins the game.
	HandleJoin(tx *world.Tx, p *Participant)
	// HandleClose is called when the game is closed.
	HandleClose(tx *world.Tx)
	// HandlePlayingTick is called every tick while the game is playing.
	HandlePlayingTick(tx *world.Tx, currentTick uint64)
	// RenderWaitingScoreboard renders the scoreboard for the waiting State.
	RenderWaitingScoreboard(p *player.Player, startingIn int, participantLen int)
	// RenderFinishedScoreboard renders the scoreboard for the finished State.
	RenderFinishedScoreboard(p *player.Player, closingIn int)
	// HandleMapReady is called when the map is ready to be played.
	HandleMapReady(tx *world.Tx, m *Map)
	// Load is called when the game is loaded.
	Load()
	// HandleParticipantCreate is called when a participant is created. It should return the implementation of the participant.
	HandleParticipantCreate(par *Participant) ParticipantImpl
}

type Map

type Map struct {
	Name      string
	WorldPath string
	// contains filtered or unexported fields
}

func (*Map) CopyWorldTo

func (m *Map) CopyWorldTo(path string) error

func (*Map) UnmarshalConfig

func (m *Map) UnmarshalConfig(v any) error

type Participant

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

func (*Participant) Closed

func (par *Participant) Closed() bool

Closed returns whether the participant is closed.

func (*Participant) Impl

func (par *Participant) Impl() ParticipantImpl

Impl returns the implementation of the participant.

func (*Participant) MustPlayer

func (par *Participant) MustPlayer(tx *world.Tx) *player.Player

MustPlayer returns the player of the participant. If the participant is not a player, this function panics.

func (*Participant) Name

func (par *Participant) Name() string

Name returns the name of the participant.

func (*Participant) Player

func (par *Participant) Player(tx *world.Tx) (*player.Player, bool)

Player returns the player of the participant. If the participant is not a player, the second return value is false.

func (*Participant) State

func (par *Participant) State() ParticipantState

State returns the state of the participant.

func (*Participant) XUID

func (par *Participant) XUID() string

XUID returns the XUID of the participant.

type ParticipantImpl

type ParticipantImpl interface {
	Close() error
}

type ParticipantState

type ParticipantState uint8
const (
	ParticipantStateUnknown ParticipantState = iota
	ParticipantStatePlaying
	ParticipantStateSpectating
)

func (ParticipantState) Playing

func (state ParticipantState) Playing() bool

func (ParticipantState) Spectating

func (state ParticipantState) Spectating() bool

func (ParticipantState) Unknown

func (state ParticipantState) Unknown() bool

type PlayerHandler

type PlayerHandler struct{}

func (*PlayerHandler) HandleAttackEntity

func (ph *PlayerHandler) HandleAttackEntity(ctx *player.Context, e world.Entity, force, height *float64, critical *bool)

func (*PlayerHandler) HandleBlockBreak

func (ph *PlayerHandler) HandleBlockBreak(ctx *player.Context, pos cube.Pos, drops *[]item.Stack, xp *int)

func (*PlayerHandler) HandleBlockPick

func (ph *PlayerHandler) HandleBlockPick(ctx *player.Context, pos cube.Pos, b world.Block)

func (*PlayerHandler) HandleBlockPlace

func (ph *PlayerHandler) HandleBlockPlace(ctx *player.Context, pos cube.Pos, b world.Block)

func (*PlayerHandler) HandleChangeWorld

func (ph *PlayerHandler) HandleChangeWorld(p *player.Player, before, after *world.World)

func (*PlayerHandler) HandleChat

func (ph *PlayerHandler) HandleChat(ctx *player.Context, message *string)

func (*PlayerHandler) HandleCommandExecution

func (ph *PlayerHandler) HandleCommandExecution(ctx *player.Context, command cmd.Command, args []string)

func (*PlayerHandler) HandleDeath

func (ph *PlayerHandler) HandleDeath(p *player.Player, src world.DamageSource, keepInv *bool)

func (*PlayerHandler) HandleDiagnostics

func (ph *PlayerHandler) HandleDiagnostics(p *player.Player, d session.Diagnostics)

func (*PlayerHandler) HandleExperienceGain

func (ph *PlayerHandler) HandleExperienceGain(ctx *player.Context, amount *int)

func (*PlayerHandler) HandleFireExtinguish

func (ph *PlayerHandler) HandleFireExtinguish(ctx *player.Context, pos cube.Pos)

func (*PlayerHandler) HandleFoodLoss

func (ph *PlayerHandler) HandleFoodLoss(ctx *player.Context, from int, to *int)

func (*PlayerHandler) HandleHeal

func (ph *PlayerHandler) HandleHeal(ctx *player.Context, health *float64, src world.HealingSource)

func (*PlayerHandler) HandleHeldSlotChange

func (ph *PlayerHandler) HandleHeldSlotChange(ctx *player.Context, from, to int)

func (*PlayerHandler) HandleHurt

func (ph *PlayerHandler) HandleHurt(ctx *player.Context, damage *float64, immune bool, attackImmunity *time.Duration, src world.DamageSource)

func (*PlayerHandler) HandleItemConsume

func (ph *PlayerHandler) HandleItemConsume(ctx *player.Context, item item.Stack)

func (*PlayerHandler) HandleItemDamage

func (ph *PlayerHandler) HandleItemDamage(ctx *player.Context, i item.Stack, damage int)

func (*PlayerHandler) HandleItemDrop

func (ph *PlayerHandler) HandleItemDrop(ctx *player.Context, s item.Stack)

func (*PlayerHandler) HandleItemPickup

func (ph *PlayerHandler) HandleItemPickup(ctx *player.Context, i *item.Stack)

func (*PlayerHandler) HandleItemRelease

func (ph *PlayerHandler) HandleItemRelease(ctx *player.Context, item item.Stack, dur time.Duration)

func (*PlayerHandler) HandleItemUse

func (ph *PlayerHandler) HandleItemUse(ctx *player.Context)

func (*PlayerHandler) HandleItemUseOnBlock

func (ph *PlayerHandler) HandleItemUseOnBlock(ctx *player.Context, pos cube.Pos, face cube.Face, clickPos mgl64.Vec3)

func (*PlayerHandler) HandleItemUseOnEntity

func (ph *PlayerHandler) HandleItemUseOnEntity(ctx *player.Context, e world.Entity)

func (*PlayerHandler) HandleJump

func (ph *PlayerHandler) HandleJump(p *player.Player)

func (*PlayerHandler) HandleLecternPageTurn

func (ph *PlayerHandler) HandleLecternPageTurn(ctx *player.Context, pos cube.Pos, oldPage int, newPage *int)

func (*PlayerHandler) HandleMove

func (ph *PlayerHandler) HandleMove(ctx *player.Context, newPos mgl64.Vec3, newRot cube.Rotation)

func (*PlayerHandler) HandlePunchAir

func (ph *PlayerHandler) HandlePunchAir(ctx *player.Context)

func (*PlayerHandler) HandleQuit

func (ph *PlayerHandler) HandleQuit(p *player.Player)

func (*PlayerHandler) HandleRespawn

func (ph *PlayerHandler) HandleRespawn(p *player.Player, pos *mgl64.Vec3, w **world.World)

func (*PlayerHandler) HandleSignEdit

func (ph *PlayerHandler) HandleSignEdit(ctx *player.Context, pos cube.Pos, frontSide bool, oldText, newText string)

func (*PlayerHandler) HandleSkinChange

func (ph *PlayerHandler) HandleSkinChange(ctx *player.Context, skin *skin.Skin)

func (*PlayerHandler) HandleStartBreak

func (ph *PlayerHandler) HandleStartBreak(ctx *player.Context, pos cube.Pos)

func (*PlayerHandler) HandleTeleport

func (ph *PlayerHandler) HandleTeleport(ctx *player.Context, pos mgl64.Vec3)

func (*PlayerHandler) HandleToggleSneak

func (ph *PlayerHandler) HandleToggleSneak(ctx *player.Context, after bool)

func (*PlayerHandler) HandleToggleSprint

func (ph *PlayerHandler) HandleToggleSprint(ctx *player.Context, after bool)

func (*PlayerHandler) HandleTransfer

func (ph *PlayerHandler) HandleTransfer(ctx *player.Context, addr *net.UDPAddr)

type ResetPlayerHealSource

type ResetPlayerHealSource struct{}

func (ResetPlayerHealSource) HealingSource

func (ResetPlayerHealSource) HealingSource()

func (ResetPlayerHealSource) ResetPlayer

func (ResetPlayerHealSource) ResetPlayer()

type Session

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

func NewSession

func NewSession(p *player.Player) *Session

NewSession creates a new session for the player p.

func (*Session) Close

func (s *Session) Close()

Close closes the session.

func (*Session) EntityHandle

func (s *Session) EntityHandle() *world.EntityHandle

EntityHandle returns the entity handle of the player that the session is for.

func (*Session) Game

func (s *Session) Game() (*Game, bool)

Game returns the game that the session is in, if any.

func (*Session) Name

func (s *Session) Name() string

Name returns the name of the player that the session is for.

func (*Session) Player

func (s *Session) Player(tx *world.Tx) (*player.Player, bool)

Player returns the player that the session is for.

func (*Session) SetGame

func (s *Session) SetGame(g *Game)

SetGame sets the game that the session is in.

func (*Session) XUID

func (s *Session) XUID() string

XUID returns the XUID of the player that the session is for.

type SetterGame

type SetterGame interface {
	// SetGame sets the game that the player is in.
	SetGame(g *Game)
}

type State

type State uint8
const (
	StateUnknown State = iota
	StateWaiting
	StatePlaying
	StateFinished
)

func (State) Finished

func (state State) Finished() bool

func (State) Playing

func (state State) Playing() bool

func (State) Unknown

func (state State) Unknown() bool

func (State) Waiting

func (state State) Waiting() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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