Documentation ¶
Index ¶
- Constants
- Variables
- func Copy[T any](src *T) *T
- func CopySlice[T any](src []*T) []*T
- func ErrAttr(err error) slog.Attr
- func Filter[T any](s []T, filter func(val T) bool) []T
- func Find[T any](s []T, val T, compare func(a, b T) bool) (T, bool)
- func MapMerge[K comparable, V any](maps ...map[K]V) map[K]V
- func MapValues[K comparable, V any](m map[K]V) []V
- type Item
- type Listing
- type ListingFilter
- type LootEntry
- type LootTable
- type Manager
- func (m *Manager) BuyOrder(playerName string, resourceName string, quantity int64) (float64, error)
- func (m *Manager) GetMarketStock(filters ...ListingFilter) []*Listing
- func (m *Manager) GetPlayer(name string) (*Player, error)
- func (m *Manager) SellOrder(playerName string, resourceName string, quantity int64) (float64, error)
- func (m *Manager) Start()
- func (m *Manager) Stop() error
- type Player
- type Prerequisite
- type Rank
- type Resource
- type ResourceType
- type Storage
Constants ¶
const ( LISTING_FILTER_NAME = "Name" LISTING_FILTER_TYPE = "Type" )
Variables ¶
var InfoFile string
Markdown file with game information.
Functions ¶
func CopySlice ¶
func CopySlice[T any](src []*T) []*T
Creates a shallow copy of the objects in a slice.
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 ¶
Inventory item which is a quantity of some resource.
type ListingFilter ¶
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 ¶
Roll and return the name and quantity of loot.
type Manager ¶
func NewManager ¶
func (*Manager) GetMarketStock ¶
func (m *Manager) GetMarketStock(filters ...ListingFilter) []*Listing
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 NewPlayerFromDB ¶
Map a database player to a game player.
func (*Player) AddResource ¶
Add or remove resource quantity from player's inventory.
func (*Player) GetResource ¶
Get resource from player's inventory.
type Prerequisite ¶
Prerequisite for purchasing a resource. Includes name of resource and amount to subtract from player inventory.
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 ¶
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" )