game

package
v0.0.0-...-358ff03 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LISTING_FILTER_NAME = "Name"
	LISTING_FILTER_TYPE = "Type"
)

Variables

View Source
var InfoFile string

Markdown file with game information.

Functions

func Copy

func Copy[T any](src *T) *T

Creates a shallow copy of the given object.

func CopySlice

func CopySlice[T any](src []*T) []*T

Creates a shallow copy of the objects in a slice.

func ErrAttr

func ErrAttr(err error) slog.Attr

Create an error attribute for logging.

func Filter

func Filter[T any](s []T, filter func(val T) bool) []T

Filters the slice to only contain values that return true from the filter function.

func Find

func Find[T any](s []T, val T, compare func(a, b T) bool) (T, bool)

Finds a value in a slice and if found, returns it.

func MapMerge

func MapMerge[K comparable, V any](maps ...map[K]V) map[K]V

Merges all given maps into a single new map. In the case of duplicate keys, the last value merged will overwrite any previous value.

func MapValues

func MapValues[K comparable, V any](m map[K]V) []V

Copies the values of a map into a slice, ignoring the key.

Types

type Item

type Item struct {
	Resource *Resource
	Quantity int64
}

Inventory item which is a quantity of some resource.

func NewItem

func NewItem(resource *Resource, quantity int64) *Item

Create an inventory item from a market listing with given quantity.

func NewItemFromDB

func NewItemFromDB(dbItem data.Item) *Item

Map a database item to a game item.

func (*Item) ToDB

func (i *Item) ToDB() data.Item

Map game item to a database item.

type Listing

type Listing struct {
	Resource *Resource

	BuyPrice  float64
	SellPrice float64
}

Represents a listing on the market for a resource.

type ListingFilter

type ListingFilter struct {
	Property string
	Value    string
}

Filter to be used on market listings.

type LootEntry

type LootEntry struct {
	Name      string // Name of resource to provide.
	Weight    int    // Weight (or chance) for this entry in the loot table.
	CountLow  int64  // Lowest number of resource to provide if chosen.
	CountHigh int64  // Highest number of resource to provide if chosen.
}

Single entry in a loot table.

type LootTable

type LootTable []LootEntry

Loot table for calculating production of mines.

func (LootTable) CalculateLoot

func (lt LootTable) CalculateLoot() (string, int64)

Roll and return the name and quantity of loot.

type Manager

type Manager struct {
	NextUpdate time.Time
	// contains filtered or unexported fields
}

func NewManager

func NewManager(db Storage) (*Manager, error)

func (*Manager) BuyOrder

func (m *Manager) BuyOrder(playerName string, resourceName string, quantity int64) (float64, error)

func (*Manager) GetMarketStock

func (m *Manager) GetMarketStock(filters ...ListingFilter) []*Listing

func (*Manager) GetPlayer

func (m *Manager) GetPlayer(name string) (*Player, error)

func (*Manager) SellOrder

func (m *Manager) SellOrder(playerName string, resourceName string, quantity int64) (float64, error)

func (*Manager) Start

func (m *Manager) Start()

Start game engine with regular updates.

func (*Manager) Stop

func (m *Manager) Stop() error

Halt updates and stop the game engine.

type Player

type Player struct {
	Name      string
	Title     string
	Rank      int
	NetWorth  float64
	Money     float64
	Salary    float64
	Inventory []*Item
	// contains filtered or unexported fields
}

Represents a player in the game.

func NewPlayer

func NewPlayer(name string) *Player

func NewPlayerFromDB

func NewPlayerFromDB(dbPlayer data.Player) *Player

Map a database player to a game player.

func (*Player) AddResource

func (p *Player) AddResource(resource *Resource, quantity int64) error

Add or remove resource quantity from player's inventory.

func (*Player) GetResource

func (p *Player) GetResource(name string) *Item

Get resource from player's inventory.

func (*Player) ToDB

func (p *Player) ToDB() data.Player

Map game player to a database player.

type Prerequisite

type Prerequisite struct {
	Name     string
	Quantity int64
}

Prerequisite for purchasing a resource. Includes name of resource and amount to subtract from player inventory.

type Rank

type Rank struct {
	Name   string
	Salary float64
	// contains filtered or unexported fields
}

Represents a rank that a player could achieve.

type Resource

type Resource struct {
	Name string
	Type ResourceType

	// Prerequisites to purchasing a resource. If the prerequisites are all met,
	// they will be consumed from the player's inventory as part of the purchase
	// process.
	Prerequisites []Prerequisite

	// Loot table will be processed every world update. Used to generate
	// resources from mines.
	Loot LootTable
	// contains filtered or unexported fields
}

Represents a singular resource that can be obtained.

func (*Resource) CalculateNetWorth

func (r *Resource) CalculateNetWorth() float64

This will calculate and return net worth for a resource.

type ResourceType

type ResourceType string
const (
	RESOURCE_TYPE_COMMODITY ResourceType = "Commodity"
	RESOURCE_TYPE_EQUIPMENT ResourceType = "Equipment"
	RESOURCE_TYPE_LAND      ResourceType = "Land"
	RESOURCE_TYPE_EMPLOYEE  ResourceType = "Employee"
)

type Storage

type Storage interface {
	Open(conn string) error
	Close() error
	LoadPlayers() ([]data.Player, error)
	SavePlayers(players []data.Player) error
}

Jump to

Keyboard shortcuts

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