component

package
v0.0.0-...-dcd4fad Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InsufficientFuelRegex = "Ship has insufficient fuel for flight plan. You require ([0-9]+) more FUEL"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

type FlightPlan

type FlightPlan struct {
	Details FlightPlanDetails `yaml:"flightPlan"`
	Error   Error             `yaml:"error"`
}

type FlightPlanDetails

type FlightPlanDetails struct {
	ArrivesAt              string `yaml:"arrivesAt"`
	CreatedAt              string `yaml:"createdAt"`
	Departure              string `yaml:"departure"`
	Destination            string `yaml:"destination"`
	Distance               int    `yaml:"distance"`
	FuelConsumed           int    `yaml:"fuelConsumed"`
	FuelRemaining          int    `yaml:"fuelRemaining"`
	Id                     string `yaml:"id"`
	ShipId                 string `yaml:"shipId"`
	TerminatedAt           string `yaml:"terminatedAt"`
	TimeRemainingInSeconds int    `yaml:"timeRemainingInSeconds"`
}

type Marketplace

type Marketplace struct {
	Products []Product `yaml:"marketplace"`
	Error    Error     `yaml:"error"`
}

Marketplace contains the list of products that can be traded.

type Product

type Product struct {
	PricePerUnit         int    `yaml:"pricePerUnit"`
	PurchasePricePerUnit int    `yaml:"purchasePricePerUnit"`
	QuantityAvailable    int    `yaml:"quantityAvailable"`
	SellPricePerUnit     int    `yaml:"sellPricePerUnit"`
	Spread               int    `yaml:"spread"`
	Symbol               string `yaml:"symbol"`
	VolumePerUnit        int    `yaml:"volumePerUnit"`
}

Product contains the details about a tradeable product.

type Route

type Route struct {
	Route []RouteStop `yaml:"route"`
	Error Error       `yaml:"error"`
}

Route is the representation of the route file.

func ReadRouteDescription

func ReadRouteDescription(data io.Reader) (*Route, error)

ReadRouteDescription will generate the component.Route instance from the data read from YAML file.

func ReadRouteFile

func ReadRouteFile(path string) (*Route, error)

ReadRouteFile will read the YAML file with the route definition.

type RouteStop

type RouteStop struct {
	Station string         `yaml:"station"`
	Buy     map[string]int `yaml:"buy"`
	Sell    map[string]int `yaml:"sell"`
}

RouteStop is the representation of each stop, its location, what to buy and what to sell.

type Ship

type Ship struct {
	Details ShipDetails `yaml:"ship"`
	Error   Error       `yaml:"error"`
	// contains filtered or unexported fields
}

Ship contains the essential information to authenticate in the game, but also to map the response from ship details.

func NewShip

func NewShip(
	ctx context.Context, tracer trace.Tracer,
	id, connectionType, connectionString,
	topicRead string, partitionRead int,
	topicWrite string, partitionWrite int) (*Ship, error)

NewShip creates a new instance of component.Ship. func NewShip(ctx context.Context, tracer trace.Tracer, id, token string) (*Ship, error) {

func NewShipCustomProxy

func NewShipCustomProxy(ctx context.Context, tracer trace.Tracer, proxy kafka.Proxy, id string) (*Ship, error)

NewShipCustomProxy creates a new instance of component.Ship, using a provided custom web.WebProxy. func NewShipCustomProxy(ctx context.Context, tracer trace.Tracer, proxy web.Proxy, id, token string) (*Ship, error) {

func (*Ship) Buy

func (s *Ship) Buy(ctx context.Context, good string, quantity int) (*Trade, error)

Buy sends a buy order to the game.

func (*Ship) BuyAll

func (s *Ship) BuyAll(ctx context.Context, buy map[string]int, marketplace map[string]Product) error

BuyAll is wrapper to buy the products in the provided list.

func (*Ship) DoCommerce

func (s *Ship) DoCommerce(ctx context.Context, sell, buy map[string]int) error

DoCommerce places the buy and sell orders to the game.

func (*Ship) Fly

func (s *Ship) Fly(ctx context.Context, destination string) error

Fly will set the FlightPlan to a new destination, and wait until the flight is finished before returning from the method.

func (*Ship) ForceBuyFuel

func (s *Ship) ForceBuyFuel(ctx context.Context, fuel int) error

ForceBuyFuel will prioritize the purchase of fuel, selling goods if necessary.

func (*Ship) GetDetails

func (s *Ship) GetDetails(ctx context.Context) error

GetDetails will get the ship details from the game.

func (*Ship) GetFlightPlan

func (s *Ship) GetFlightPlan(ctx context.Context) (*FlightPlan, error)

GetFlightPlan retrieves current flight plan, if any.

func (*Ship) GetMarketplaceProducts

func (s *Ship) GetMarketplaceProducts(ctx context.Context) (*Marketplace, *map[string]Product, error)

GetMarketplaceProducts will fetch the products that are available to be traded in the current marketplace.

func (*Ship) NewFlightPlan

func (s *Ship) NewFlightPlan(ctx context.Context, destination string) (*FlightPlan, error)

NewFlightPlan sets a new destination for the ship to fly to.

func (*Ship) Sell

func (s *Ship) Sell(ctx context.Context, good string, quantity int) (*Trade, error)

Sell sends a sell order to the game.

func (*Ship) SellAll

func (s *Ship) SellAll(ctx context.Context, sell map[string]int, marketplace map[string]Product) error

SellAll is wrapper to sell all units of products in the provided list.

type ShipCargo

type ShipCargo struct {
	Good        string `yaml:"good"`
	Quantity    int    `yaml:"quantity"`
	TotalVolume int    `yaml:"totalVolume"`
}

ShipCargo contains the details about the products stored in the ship cargo.

type ShipDetails

type ShipDetails struct {
	Id             string      `yaml:"id"`
	FlightPlanId   string      `yaml:"flightPlanId"`
	Location       string      `yaml:"location"`
	X              int         `yaml:"x"`
	Y              int         `yaml:"y"`
	Cargo          []ShipCargo `yaml:"cargo"`
	SpaceAvailable int         `yaml:"spaceAvailable"`
	Type           string      `yaml:"type"`
	Class          string      `yaml:"class"`
	MaxCargo       int         `yaml:"maxCargo"`
	LoadingSpeed   int         `yaml:"loadingSpeed"`
	Speed          int         `yaml:"speed"`
	Manufacturer   string      `yaml:"manufacturer"`
	Plating        int         `yaml:"plating"`
	Weapons        int         `yaml:"weapons"`
}

ShipDetails is the response from the Ship Detail API.

type Trade

type Trade struct {
	Credits int        `yaml:"credits"`
	Order   TradeOrder `yaml:"order"`
	Ship    Ship       `yaml:"ship"`
	Error   Error      `yaml:"error"`
}

Trade represents a trading order (buy or sell).

type TradeOrder

type TradeOrder struct {
	Good         string `yaml:"good"`
	PricePerUnit int    `yaml:"pricePerUnit"`
	Quantity     int    `yaml:"quantity"`
	Total        int    `yaml:"total"`
}

TradingOrder contains the details (to buy or to sell) of a good in the marketplace.

Jump to

Keyboard shortcuts

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