store

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MapImages = map[int]image.Image{}

	MapImageKeyFmt = "m-%d"
)

Functions

This section is empty.

Types

type AbilityBurrow added in v1.2.0

type AbilityBurrow struct {
	// BurrowAt is the time in which it was burrowed.
	// It'll stay there for 15s and then the next unit
	// that steps on it it'll pop up again.
	// If in 45s no unit stept on it it'll unburrow
	// itself up
	BurrowAt   time.Time `mapstructure:"BurrowAt"`
	Unburrowed bool      `mapstructure:"Unburrowed"`
}

func (AbilityBurrow) CanUnburrow added in v1.2.0

func (ab AbilityBurrow) CanUnburrow(t time.Time) bool

func (AbilityBurrow) MustUnburrow added in v1.2.0

func (ab AbilityBurrow) MustUnburrow(t time.Time) bool

type AbilityResurrection added in v1.2.0

type AbilityResurrection struct {
	KilledAt    time.Time `mapstructure:"killed_at"`
	Resurrected bool      `mapstructure:"resurrected"`
}

func (AbilityResurrection) CanResurrect added in v1.2.0

func (ar AbilityResurrection) CanResurrect(t time.Time) bool

type AbilitySplit added in v1.2.0

type AbilitySplit struct {
	// UnitID  is the other unit
	// that belong to this Split.
	// The bounty must only be given
	// when all are dead
	UnitID string `mapstructure:"UnitID"`
}

type Line added in v1.0.3

type Line struct {
	ID     int
	Towers map[string]*Tower
	Units  map[string]*Unit

	Graph *graph.Graph

	// UpdatedAt is the last time
	// something was updated on this Line.
	// Towers added, Units added or
	// when the Units position was updated
	// the last time.
	// Used for the SyncState to know how much
	// time has passed since the last update
	// and move the Units accordingly
	// (60 moves per second pass)
	UpdatedAt time.Time
}

func (*Line) ListSortedUnits added in v1.2.0

func (l *Line) ListSortedUnits() []*Unit

type Lines added in v1.0.3

type Lines struct {
	*flux.ReduceStore
	// contains filtered or unexported fields
}

func NewLines added in v1.0.3

func NewLines(d *flux.Dispatcher, s *Store) *Lines

func (*Lines) FindCurrentPlayer added in v1.1.0

func (ls *Lines) FindCurrentPlayer() Player

func (*Lines) FindLineByID added in v1.1.0

func (ls *Lines) FindLineByID(id int) *Line

func (*Lines) FindPlayerByID added in v1.1.0

func (ls *Lines) FindPlayerByID(id string) Player

func (*Lines) FindPlayerByLineID added in v1.1.0

func (ls *Lines) FindPlayerByLineID(lid int) Player

func (*Lines) GetIncomeTimer added in v1.1.0

func (ls *Lines) GetIncomeTimer() int

func (*Lines) ListLines added in v1.1.0

func (ls *Lines) ListLines() []*Line

func (*Lines) ListPlayers added in v1.1.0

func (ls *Lines) ListPlayers() []*Player

ListPlayers returns the players list and it's meant for reading only purposes

func (*Lines) Reduce added in v1.0.3

func (ls *Lines) Reduce(state, a interface{}) interface{}

type LinesState added in v1.0.3

type LinesState struct {
	Lines   map[int]*Line
	Players map[string]*Player

	// IncomeTimer is the internal counter that goes from 15 to 0
	IncomeTimer int
}

type Lobbies added in v1.1.0

type Lobbies struct {
	*flux.ReduceStore
	// contains filtered or unexported fields
}

func NewLobbies added in v1.1.0

func NewLobbies(d *flux.Dispatcher) *Lobbies

func (*Lobbies) FindByID added in v1.1.0

func (ls *Lobbies) FindByID(id string) *Lobby

func (*Lobbies) FindCurrent added in v1.1.0

func (ls *Lobbies) FindCurrent() *Lobby

func (*Lobbies) List added in v1.1.0

func (ls *Lobbies) List() []*Lobby

func (*Lobbies) Reduce added in v1.1.0

func (ls *Lobbies) Reduce(state, a interface{}) interface{}

type LobbiesState added in v1.1.0

type LobbiesState struct {
	Lobbies map[string]*Lobby
}

type Lobby added in v1.1.0

type Lobby struct {
	ID         string
	Name       string
	MaxPlayers int
	// Players holds the usernames
	// including the owner one.
	// And the bool value represents
	// if it's a "bot" or not
	Players map[string]bool
	// The username of the owner
	Owner   string
	Current bool
}

type Map

type Map struct {
	*flux.ReduceStore
	// contains filtered or unexported fields
}

Map is a struct that holds all the information of the current map

func NewMap

func NewMap(d *flux.Dispatcher, s *Store) *Map

NewMap initializes the map

func (*Map) GetHomeCoordinates

func (m *Map) GetHomeCoordinates(lid int) (int, int)

func (*Map) GetImageKey added in v1.0.3

func (m *Map) GetImageKey() string

GetY returns the max Y value of the map

func (*Map) GetNextLineID

func (m *Map) GetNextLineID(clid int) int

GetNextLineID based on the map and max number of players it returns the next one and when it reaches the end then starts again

func (*Map) GetX

func (m *Map) GetX() int

GetX returns the max X value of the map

func (*Map) GetY

func (m *Map) GetY() int

GetY returns the max Y value of the map

func (*Map) Reduce

func (m *Map) Reduce(state, a interface{}) interface{}

type MapState

type MapState struct {
	Players int
	Image   image.Image
}

type Player

type Player struct {
	ID      string
	Name    string
	Lives   int
	LineID  int
	Income  int
	Gold    int
	Current bool
	Winner  bool

	// UnitUpdates holds the current unit level
	UnitUpdates map[string]UnitUpdate
}

func (Player) CanPlaceTower

func (p Player) CanPlaceTower(tt string) bool

func (Player) CanSummonUnit

func (p Player) CanSummonUnit(ut string) bool

func (Player) CanUpdateUnit added in v1.1.0

func (p Player) CanUpdateUnit(ut string) bool

type Store

type Store struct {
	Lines   *Lines
	Map     *Map
	Lobbies *Lobbies
	// contains filtered or unexported fields
}

func NewStore

func NewStore(d *flux.Dispatcher, l *slog.Logger) *Store

func (*Store) Dispatch

func (s *Store) Dispatch(a *action.Action)

type Tower

type Tower struct {
	utils.Object

	ID string

	Type     string
	LineID   int
	PlayerID string

	Health float64

	TargetUnitID string
	LastAttack   time.Time
}

func (*Tower) CanAttack added in v1.2.0

func (t *Tower) CanAttack(tm time.Time) bool

func (*Tower) CanAttackUnit added in v1.2.0

func (t *Tower) CanAttackUnit(u *Unit) bool

func (*Tower) CanTarget added in v1.1.0

func (t *Tower) CanTarget(env environment.Environment) bool

func (*Tower) CanUpdateTo added in v1.2.0

func (t *Tower) CanUpdateTo(tt string) bool

func (*Tower) FacetKey added in v1.0.3

func (t *Tower) FacetKey() string

type Unit

type Unit struct {
	utils.MovingObject
	AnimationCount int

	ID            string
	Type          string
	PlayerID      string
	PlayerLineID  int
	CurrentLineID int

	MaxHealth float64
	Health    float64

	MaxShield float64
	Shield    float64

	MovementSpeed float64
	Bounty        int

	// The current level of the unit from the PlayerID
	Level int

	Path     []graph.Step
	HashPath string

	// CreatedAt has the time of creation so
	// on the next SyncState will be moved just
	// the diff amount and then it'll be set to 'nil'
	// so we know it's on sync
	CreatedAt time.Time

	// Abilities stores data from the abilities that
	// the unit has and need to be kept in check, for example
	// if it's a slime which is the other unit and if it died
	// then give the bounty. Or if the unit already resurected
	// The key is an ability.Ability.String() and the value is
	// a type that is specific for the ability.
	Abilities map[string]interface{}
	Buffs     map[string]interface{}

	// If the Unit has the ability 'Attack' it'll have a
	// TargetTowerID if it has a Tower to attack
	TargetTowerID string
	LastAttack    time.Time
}

func (*Unit) AddBuff added in v1.2.0

func (u *Unit) AddBuff(b buff.Buff)

func (*Unit) AttackKey added in v1.2.0

func (u *Unit) AttackKey() string

func (*Unit) CanAttack added in v1.2.0

func (u *Unit) CanAttack(tm time.Time) bool

func (*Unit) CanBeAttacked added in v1.2.0

func (u *Unit) CanBeAttacked(t time.Time) bool

func (*Unit) CanResurrect added in v1.2.0

func (u *Unit) CanResurrect(t time.Time) bool

func (*Unit) CanUnburrow added in v1.2.0

func (u *Unit) CanUnburrow(t time.Time) bool

func (*Unit) FacesetKey added in v1.0.3

func (u *Unit) FacesetKey() string

func (*Unit) HasAbility added in v1.2.0

func (u *Unit) HasAbility(a ability.Ability) bool

func (*Unit) HasBuff added in v1.2.0

func (u *Unit) HasBuff(b buff.Buff) bool

func (*Unit) Hybrid added in v1.2.0

func (u *Unit) Hybrid(cp, op int)

func (*Unit) IdleKey added in v1.2.0

func (u *Unit) IdleKey() string

func (*Unit) MustUnburrow added in v1.2.0

func (u *Unit) MustUnburrow(t time.Time) bool

func (*Unit) RemoveBuff added in v1.2.0

func (u *Unit) RemoveBuff(b buff.Buff)

func (*Unit) Resurrect added in v1.2.0

func (u *Unit) Resurrect()

func (*Unit) TakeDamage added in v1.2.0

func (u *Unit) TakeDamage(d float64)

func (*Unit) Unburrow added in v1.2.0

func (u *Unit) Unburrow()

func (*Unit) WalkKey added in v1.2.0

func (u *Unit) WalkKey() string

func (*Unit) WasBurrowed added in v1.2.0

func (u *Unit) WasBurrowed() bool

func (*Unit) WasResurrected added in v1.2.0

func (u *Unit) WasResurrected() bool

type UnitUpdate added in v1.1.0

type UnitUpdate struct {
	// Current is the current unit
	Current unit.Stats

	// Level is the number of the unit level
	// which is basically the number of times
	// it has been updated
	Level int

	UpdateCost int

	// Is how the unit will look after the next update
	Next unit.Stats
}

Jump to

Keyboard shortcuts

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