spacetraders

package
v0.0.0-...-4de7fdf Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KnownFactions = map[string]bool{
	"COSMIC": true,
}

Functions

func SpaceTradersHandler

func SpaceTradersHandler(request bothandler.Request) string

SpaceTradersHandler is the catchall handler for SpaceTraders, to make it work within the bothandler framework

Types

type Agent

type Agent struct {
	gorm.Model
	Agent     string `gorm:"uniqueIndex"`
	Faction   string
	AuthToken string
}

type AgentData

type AgentData struct {
	AccountID       string `json:"accountId"`
	Symbol          string `json:"symbol"`
	Headquarters    string `json:"headquarters"`
	Credits         int    `json:"credits"`
	StartingFaction string `json:"startingFaction"`
}

type ChannelAgents

type ChannelAgents struct {
	gorm.Model
	Platform    string
	Channel     string
	AgentSymbol string
}

type ContractData

type ContractData struct {
	ID               string    `json:"id"`
	FactionSymbol    string    `json:"factionSymbol"`
	Type             string    `json:"type"`
	Terms            TermsData `json:"terms"`
	Accepted         bool      `json:"accepted"`
	Fulfilled        bool      `json:"fulfilled"`
	Expiration       time.Time `json:"expiration"`
	DeadlineToAccept time.Time `json:"deadlineToAccept"`
}

type CrewData

type CrewData struct {
	Current  int    `json:"current"`
	Capacity int    `json:"capacity"`
	Required int    `json:"required"`
	Rotation string `json:"rotation"`
	Morale   int    `json:"morale"`
	Wages    int    `json:"wages"`
}

type DeliverData

type DeliverData struct {
	TradeSymbol       string `json:"tradeSymbol"`
	DestinationSymbol string `json:"destinationSymbol"`
	UnitsRequired     int    `json:"unitsRequired"`
	UnitsFulfilled    int    `json:"unitsFulfilled"`
}

type ErrorResponse

type ErrorResponse struct {
	Message string      `json:"message"`
	Code    json.Number `json:"code"`
}

type Faction

type Faction struct {
	gorm.Model
	Faction      string `gorm:"uniqueIndex"`
	Name         string
	Description  string
	Headquarters string
	Traits       []Trait `gorm:"-"`
	TraitsString string  `gorm:"column:traits;type:text"`
	IsRecruiting bool    `gorm:"column:is_recruiting"`
}

func (*Faction) Fix

func (f *Faction) Fix(a *SpaceTraders)

func (*Faction) PrettyPrint

func (f *Faction) PrettyPrint() string

type FactionData

type FactionData struct {
	Symbol       string       `json:"symbol"`
	Name         string       `json:"name,omitempty"`
	Description  string       `json:"description,omitempty"`
	Headquarters string       `json:"headquarters,omitempty"`
	Traits       []TraitsData `json:"traits,omitempty"`
	IsRecruiting *bool        `json:"isRecruiting,omitempty"`
}

type FuelData

type FuelData struct {
	Current  int `json:"current"`
	Capacity int `json:"capacity"`
	Consumed struct {
		Amount    int       `json:"amount"`
		Timestamp time.Time `json:"timestamp"`
	} `json:"consumed"`
}

type InventoryData

type InventoryData any
type NavData struct {
	SystemSymbol   string    `json:"systemSymbol"`
	WaypointSymbol string    `json:"waypointSymbol"`
	Route          RouteData `json:"route"`
	Status         string    `json:"status"`
	FlightMode     string    `json:"flightMode"`
}

type PaymentData

type PaymentData struct {
	OnAccepted  int `json:"onAccepted"`
	OnFulfilled int `json:"onFulfilled"`
}

type PlatformChannel

type PlatformChannel struct {
	Platform string
	Channel  string
}

PlatformChannel maps chat channels and platforms to Agent.Symbol

type RegisterAgentRequest

type RegisterAgentRequest struct {
	Symbol  string `json:"symbol"`
	Faction string `json:"faction"`
}

type RegisterAgentResponse

type RegisterAgentResponse struct {
	Data  *RegisterAgentResponseData `json:"data"`
	Error *ErrorResponse             `json:"error,omitempty"`
}

type RegisterAgentResponseData

type RegisterAgentResponseData struct {
	Token    string        `json:"token,omitempty"`
	Agent    *AgentData    `json:"agent,omitempty"`
	Contract *ContractData `json:"contract,omitempty"`
	Faction  *FactionData  `json:"faction,omitempty"`
	Ship     *ShipData     `json:"ship,omitempty"`
}

type RequestLog

type RequestLog struct {
	gorm.Model
	Platform string `gorm:"column:platform" json:"platform"`
	Channel  string `gorm:"column:channel" json:"channel"`

	Type string `gorm:"column:type" json:"type"`
	URL  string `gorm:"column:url" json:"url"`

	Data string `gorm:"column:data" json:"data"`

	ResponseStatusCode int    `gorm:"column:response_status_code" json:"response_status_code"`
	Response           string `gorm:"column:response" json:"response"`
}

type RouteData

type RouteData struct {
	Departure     WaypointData `json:"departure"`
	Destination   WaypointData `json:"destination"`
	Arrival       time.Time    `json:"arrival"`
	DepartureTime time.Time    `json:"departureTime"`
}

type Ship

type Ship struct {
	gorm.Model
	Ship  string `gorm:"uniqueIndex" json:"symbol"`
	Owner string `gorm:"column:owner" json:"owner"`

	Data string `gorm:"column:data;type:text" json:"-"`

	Nav          NavData              `gorm:"-" json:"nav"`
	Crew         CrewData             `gorm:"-" json:"crew"`
	Fuel         FuelData             `gorm:"-" json:"fuel"`
	Frame        ShipFrameData        `gorm:"-" json:"frame"`
	Reactor      ShipReactorData      `gorm:"-" json:"reactor"`
	Engine       ShipEngineData       `gorm:"-" json:"engine"`
	Modules      []ShipModuleData     `gorm:"-" json:"modules"`
	Mounts       []ShipMountData      `gorm:"-" json:"mounts"`
	Registration ShipRegistrationData `gorm:"-" json:"registration"`
	Cargo        ShipCargoData        `gorm:"-" json:"cargo"`
}

func (*Ship) Fix

func (s *Ship) Fix(a *SpaceTraders)

func (*Ship) PrettyPrint

func (s *Ship) PrettyPrint() string

type ShipCargoData

type ShipCargoData struct {
	Capacity  int             `json:"capacity"`
	Units     int             `json:"units"`
	Inventory []InventoryData `json:"inventory"`
}

type ShipData

type ShipData struct {
	Symbol       string               `json:"symbol"`
	Nav          NavData              `json:"nav"`
	Crew         CrewData             `json:"crew"`
	Fuel         FuelData             `json:"fuel"`
	Frame        ShipFrameData        `json:"frame"`
	Reactor      ShipReactorData      `json:"reactor"`
	Engine       ShipEngineData       `json:"engine"`
	Modules      []ShipModuleData     `json:"modules"`
	Mounts       []ShipMountData      `json:"mounts"`
	Registration ShipRegistrationData `json:"registration"`
	Cargo        ShipCargoData        `json:"cargo"`
}

type ShipEngineData

type ShipEngineData struct {
	Symbol       string `json:"symbol"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	Condition    int    `json:"condition"`
	Speed        int    `json:"speed"`
	Requirements struct {
		Power int `json:"power"`
		Crew  int `json:"crew"`
	} `json:"requirements"`
}

type ShipFrameData

type ShipFrameData struct {
	Symbol         string `json:"symbol"`
	Name           string `json:"name"`
	Description    string `json:"description"`
	ModuleSlots    int    `json:"moduleSlots"`
	MountingPoints int    `json:"mountingPoints"`
	FuelCapacity   int    `json:"fuelCapacity"`
	Condition      int    `json:"condition"`
	Requirements   struct {
		Power int `json:"power"`
		Crew  int `json:"crew"`
	} `json:"requirements"`
}

type ShipModuleData

type ShipModuleData struct {
	Symbol       string `json:"symbol"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	Capacity     int    `json:"capacity,omitempty"`
	Requirements struct {
		Crew  int `json:"crew"`
		Power int `json:"power"`
		Slots int `json:"slots"`
	} `json:"requirements"`
	Range int `json:"range,omitempty"`
}

type ShipMountData

type ShipMountData struct {
	Symbol       string `json:"symbol"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	Strength     int    `json:"strength"`
	Requirements struct {
		Crew  int `json:"crew"`
		Power int `json:"power"`
	} `json:"requirements"`
	Deposits []string `json:"deposits,omitempty"`
}

type ShipReactorData

type ShipReactorData struct {
	Symbol       string `json:"symbol"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	Condition    int    `json:"condition"`
	PowerOutput  int    `json:"powerOutput"`
	Requirements struct {
		Crew int `json:"crew"`
	} `json:"requirements"`
}

type ShipRegistrationData

type ShipRegistrationData struct {
	Name          string `json:"name"`
	FactionSymbol string `json:"factionSymbol"`
	Role          string `json:"role"`
}

type SpaceTraders

type SpaceTraders struct {
	GormDB     *gorm.DB
	Rand       *rand.Rand
	HttpClient http.Client

	ActiveDev bool

	KnownFactions map[string]Faction
	KnownTraits   map[string]Trait
	KnownAgents   map[string]Agent
	KnownShips    map[string]Ship
	AgentShips    map[string]map[string]bool
	// contains filtered or unexported fields
}

func (*SpaceTraders) GetTrait

func (a *SpaceTraders) GetTrait(traitCode string) Trait

func (*SpaceTraders) LoadKnown

func (a *SpaceTraders) LoadKnown()

func (*SpaceTraders) LogRequest

func (m *SpaceTraders) LogRequest(ctx context.Context, rl *RequestLog, r *http.Request)

func (*SpaceTraders) ProcessRegisterAgentResponse

func (a *SpaceTraders) ProcessRegisterAgentResponse(ctx context.Context, pc PlatformChannel, resp *RegisterAgentResponse)

func (*SpaceTraders) RegisterAgent

func (a *SpaceTraders) RegisterAgent(ctx context.Context, pc PlatformChannel, agentRequest RegisterAgentRequest) (*RegisterAgentResponse, error)

func (*SpaceTraders) SetAgent

func (a *SpaceTraders) SetAgent(agent Agent)

func (*SpaceTraders) SetFaction

func (a *SpaceTraders) SetFaction(faction Faction)

func (*SpaceTraders) SetShip

func (a *SpaceTraders) SetShip(ship Ship)

func (*SpaceTraders) SetTrait

func (a *SpaceTraders) SetTrait(trait Trait)

type System

type System struct {
	LastUpdate time.Time
}

type SystemData

type SystemData struct {
	SystemSymbol string `json:"systemSymbol"`
	Symbol       string `json:"symbol"`
	Type         string `json:"type"`
	X            int    `json:"x"`
	Y            int    `json:"y"`
	Orbitals     []struct {
		Symbol string `json:"symbol"`
	} `json:"orbitals"`
	Traits []TraitsData `json:"traits"`
	Chart  struct {
		SubmittedBy string    `json:"submittedBy"`
		SubmittedOn time.Time `json:"submittedOn"`
	} `json:"chart"`
	Faction FactionData `json:"faction"` // Note: only Symbol given
}

type SystemResponse

type SystemResponse struct {
	Data SystemData `json:"data"`
}

type TermsData

type TermsData struct {
	Deadline time.Time     `json:"deadline"`
	Payment  PaymentData   `json:"payment"`
	Deliver  []DeliverData `json:"deliver"`
}

type Trait

type Trait struct {
	gorm.Model
	Trait       string `gorm:"uniqueIndex"`
	Description string
}

type TraitsData

type TraitsData struct {
	Symbol      string `json:"symbol"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

type Waypoint

type Waypoint struct {
}

type WaypointData

type WaypointData struct {
	Symbol       string `json:"symbol"`
	Type         string `json:"type"`
	SystemSymbol string `json:"systemSymbol"`
	X            int    `json:"x"`
	Y            int    `json:"y"`
}

Jump to

Keyboard shortcuts

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