race

package
v0.0.0-...-82a33b0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MODE = "mode"
)
View Source
const (
	RACE = "race"
)

Variables

View Source
var (
	Servers  map[string]*Server
	Track    = strings.Repeat("•   ", 20)
	TrackLen = int64(utf8.RuneCountInString(Track))
)
View Source
var (
	Modes map[string]*Mode
)

Functions

func GetAdminHelp

func GetAdminHelp() []string

GetAdminHelp returns help information about the race game for administrators.

func GetCommands

GetCommands ret urns the component handlers, command handlers, and commands for the Race game.

func GetMemberHelp

func GetMemberHelp() []string

GetMemberHelp returns help information about the race game commands for regular members.

func GetModeNames

func GetModeNames(modes map[string]*Mode) ([]string, error)

GetModeNames returns a list of available race modes.

func LoadModes

func LoadModes() map[string]*Mode

LoadModes loads the race modes.

func LoadServers

func LoadServers()

LoadServers returns all the servers for the given guilds.

func SaveServer

func SaveServer(server *Server)

SaveServer saves the race statistics for the server.

func Start

func Start(s *discordgo.Session)

Start initializes anything needed by the race game.

Types

type Bettor

type Bettor struct {
	ID       string `json:"_id" bson:"_id"`           // Member ID of the player who placed the bet
	Name     string `json:"name" bson:"name"`         // The nickname or username of the player who placed the bet
	Racer    *Racer `json:"racer" bson:"racer"`       // The racer the bet was placed on
	Bet      int    `json:"bet" bson:"bet"`           // The amount of the bet placed
	Winnings int    `json:"winnings" bson:"winnings"` // The amount won on the race
}

Bettor is a member who has placed a bet on the outcome of the race.

type Character

type Character struct {
	Emoji    string `json:"emoji" bson:"emoji"`       // The icon for the race character
	Movement string `json:"movement" bson:"movement"` // The movement for the race character
}

Character is one of the characters that may be included in a race.

type Config

type Config struct {
	BetAmount        int           `json:"bet_amount" bson:"bet_amount"`                 // The amount a player bets on the race
	Currency         string        `json:"currency" bson:"currency"`                     // Currency type used on the server
	Mode             string        `json:"mode" bson:"mode"`                             // The name of the race mode being used
	PrizeMin         int           `json:"prize_min" bson:"prize_min"`                   // The minimum prize for winning racer, multiplied by the number of racers
	PrizeMax         int           `json:"prize_max" bson:"prize_max"`                   // The maximum prize for the winning racer, multiplied by the numbe of racers
	WaitForJoin      time.Duration `json:"wait_for_join" bson:"wait_for_join"`           // Time to wait for people to join a race
	WaitForBetting   time.Duration `json:"wati_for_betting" bson:"wait_for_betting"`     // Time to wait for people to place bets
	WaitBetweenRaces time.Duration `json:"wait_between_races" bson:"wait_between_races"` // Time to wait between races
	MinRacers        int           `json:"min_racers" bson:"min_racers"`                 // Minimum number of racers required, including the bot
	MaxRacers        int           `json:"max_racers" bson:"max_racers"`                 // Maximum number of racers allowed, including the bot
}

Config is the race configuration for a given guild/server.

func NewConfig

func NewConfig() *Config

NewConfig creates a configuration for a new server. The configuration will use the default values, which may be overwritten using commands sent to the bot.

type LifetimeResults

type LifetimeResults struct {
	Win         int `json:"win" bson:"win"`                   // Number of races a player came in first
	Place       int `json:"place" bson:"place"`               // Number of races a player came in second
	Show        int `json:"show" bson:"show"`                 // Number of races a player came in third
	Losses      int `json:"loses" bson:"loses"`               // Number of races a player came in fourth or lower
	Earnings    int `json:"earnings" bson:"earnings"`         // Lifetime earnings for the player in races
	BetsPlaced  int `json:"bets_placed" bson:"bets_placed"`   // Number of bets a player has placed on races
	BetsWon     int `json:"bets_won" bson:"bets_won"`         // Number of bets a player has won
	BetEarnings int `json:"bet_earnings" bson:"bet_earnings"` // Lifetime earnings from placing bets
}

LifetimeResults keeps track of the lifetime results for a given player.

type Mode

type Mode struct {
	ID         string       `json:"_id" bson:"_id"`               // Name of the mode (e.g., "clash")
	Beginning  string       `json:"beginning" bson:"beginning"`   // The character or icon for the left-hand side of the race
	Characters []*Character `json:"characters" bson:"characters"` // The list of characters from which a racer is randomly assigned
	Ending     string       `json:"ending" bson:"ending"`         // The character or icon for the right-hand side of the race
}

Mode represents the type of characters and symbols used in the race.

func GetMode

func GetMode(modeName string) (*Mode, error)

Getode gets the specified race mode.

func (*Mode) String

func (m *Mode) String() string

String returns a string representation of the race mode.

type Player

type Player struct {
	ID       string          `json:"_id" bson:"_id"`             // ID of the player
	Name     string          `json:"name" bson:"name"`           // Nickname of the user, or username if the member doesn't have a nickname
	NumRaces int             `json:"num_races" bson:"num_races"` // Number of races the member has entered
	Results  LifetimeResults `json:"results" bson:"results"`     // Results of all previous races for the member
}

Player is a member of the guild/server who partipates in races or bets on races.

func NewPlayer

func NewPlayer(server *Server, playerID string, playerName string) *Player

NewPlayer creates a new race game player for the server.

type Race

type Race struct {
	Bets        []*Bettor                    `json:"bets" bson:"bets"`                 // Bets placed by members on the race
	Racers      []*Racer                     `json:"racers" bson:"racers"`             // Members who have entered the race
	Planned     bool                         `json:"planned" bson:"planned"`           // Waiting for members to join the race
	Started     bool                         `json:"started" bson:"started"`           // The race is now in progress
	Ended       bool                         `json:"ended" bson:"ended"`               // The race has ended
	StartTime   time.Time                    `json:"start_time" bson:"start_time"`     // Time the race will begin
	BetEndTime  time.Time                    `json:"bet_end_time" bson:"bet_end_time"` // The time betting will close
	Interaction *discordgo.InteractionCreate `json:"-" bson:"-"`                       // Interaction for the initial race start message
}

Race represents the race data for a given guild/server.

func NewRace

func NewRace(server *Server) *Race

NewRace creates a new race to be run between multiple racers

type Racer

type Racer struct {
	Player       *Player    `json:"player" bson:"player"`               // Player who is racing
	Character    *Character `json:"character" bson:"character"`         // Randomly selected character for the race
	LastMove     int64      `json:"last_move" bson:"last_move"`         // Distance moved on the last move
	LastPosition int64      `json:"last_position" bson:"last_position"` // Initialize to TrackLen
	Position     int64      `json:"position" bson:"position"`           // Initialize to TrackLen
	Speed        float64    `json:"speed" bson:"speed"`                 // Calculate at end to sort the racers
	Current      string     `json:"current" bson:"current"`             // Current position on the track
	Turn         int64      `json:"turn" bson:"turn"`                   // How many turns it took to move from the starting position to 0
	Prize        int        `json:"prize" bson:"prize"`                 // The amount of credits earned in the race
}

Racer is a player who is entered into a race.

func NewRacer

func NewRacer(player *Player, mode *Mode) *Racer

NewRacer gets a new racer for the given player

func (*Racer) Move

func (r *Racer) Move() bool

Move moves a player on the track. It returns `true` if the player moved, `false` if the player has already finished the race.

type Server

type Server struct {
	ID            string             `json:"_id" bson:"_id"`                         // Guild ID
	Config        *Config            `json:"config" bson:"config"`                   // Server-specific configuration
	GamesPlayed   int                `json:"games_played" bson:"games_played"`       // Number of race games played on the server
	Players       map[string]*Player `json:"players" bson:"players"`                 // All members who have entered a race on the server
	LastRaceEnded time.Time          `json:"last_race_ended" bson:"last_race_ended"` // Time the last race ended
	Race          *Race              `json:"-" bson:"-"`                             // The current race (don't save to the store)
	// contains filtered or unexported fields
}

Server represents a guild/server where the Race game is played

func GetServer

func GetServer(guildID string) *Server

GetServer gets a server for the given guild ID, creating a new one if necessary.

func NewServer

func NewServer(guildID string) *Server

NewServer creates a new server with the default values set and stores it in the file store.

func (*Server) GetPlayer

func (server *Server) GetPlayer(playerID string, username string, nickname string) *Player

GetPlayer returns the race game player, creating the player if one does not already exist.

func (*Server) RunRace

func (s *Server) RunRace(channelID string)

RunRace runs the race until all racers have finished.

Jump to

Keyboard shortcuts

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