Documentation
¶
Index ¶
- Constants
- Variables
- func GetHandValue(hand *bj.Hand, hidden bool) string
- func SetDB(d *mongo.MongoDB)
- func Start()
- type Action
- type ChipManager
- type Config
- type Game
- func (g *Game) DealInitialCards() error
- func (g *Game) Dealer() *bj.Dealer
- func (g *Game) DealerPlay() error
- func (g *Game) EndRound()
- func (g *Game) EvaluateHand(hand *bj.Hand) bj.GameResult
- func (g *Game) GetActivePlayer() *bj.Player
- func (g *Game) GetPlayer(memberID string) *bj.Player
- func (g *Game) IsDealingHands() bool
- func (g *Game) IsStartingRound() bool
- func (g *Game) IsWaitingForPlayers() bool
- func (g *Game) Lock()
- func (g *Game) NotStarted() bool
- func (g *Game) PayoutResults()
- func (g *Game) PlayerActionRequest(memberID string, action Action) error
- func (g *Game) PlayerDoubleDown(player *bj.Player) error
- func (g *Game) PlayerHit(player *bj.Player) error
- func (g *Game) PlayerSplit(player *bj.Player) error
- func (g *Game) PlayerStand(player *bj.Player) error
- func (g *Game) PlayerSurrender(player *bj.Player) error
- func (g *Game) Players() []*bj.Player
- func (g *Game) Round() int
- func (g *Game) SecondsBeforeStart() int
- func (g *Game) SetState(state GameState)
- func (g *Game) StartNewRound() error
- func (g *Game) Unlock()
- type GameState
- type Member
- type Plugin
- func (plugin *Plugin) GetAdminHelp() []string
- func (plugin *Plugin) GetCommandHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)
- func (plugin *Plugin) GetCommands() []*discordgo.ApplicationCommand
- func (plugin *Plugin) GetComponentHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)
- func (plugin *Plugin) GetHelp() []string
- func (plugin *Plugin) GetName() string
- func (plugin *Plugin) Initialize(b *discord.Bot, d *mongo.MongoDB)
- func (plugin *Plugin) Status() discord.PluginStatus
- func (plugin *Plugin) Stop()
- type Symbols
Constants ¶
const (
CONFIG_FILE_NAME = "config"
)
const (
PluginName = "blackjack"
)
Variables ¶
var ( ErrAllPlayersBusted = errors.New("all players have busted. The dealer wins.") ErrCannotDoubleDown = errors.New("you cannot double down on this hand.") ErrCannotSplit = errors.New("you cannot split this hand.") ErrCannotSurrender = errors.New("you cannot surrender this hand.") ErrGameActive = errors.New("the game has already started.") ErrGameFull = errors.New("the game is already full.") ErrGameNotStarted = errors.New("the blackjack game has not started yet. Please wait for the game to start before joining.") ErrGameStarted = errors.New("an active blackjack game already exists.") ErrNoActiveGame = errors.New("there is no active blackjack game. Please start a new game to play.") ErrNotActivePlayer = errors.New("you are not the active player.") ErrPlayerAlreadyInGame = errors.New("you already joined the game.") ErrPlayerNotFound = errors.New("player not found in the game.") )
Functions ¶
func GetHandValue ¶
GetHandValue returns a string representation of the hand value using the provided symbols.
Types ¶
type ChipManager ¶
type ChipManager struct {
// contains filtered or unexported fields
}
ChipManager manages the chips for a blackjack player using a bank account.
func NewChipManager ¶
func NewChipManager(game *Game, memberID string) *ChipManager
NewChipManager returns a new ChipManager for the given guild and member.
func (*ChipManager) AddChips ¶
func (c *ChipManager) AddChips(amount int)
AddChips adds the specified amount of chips to the player's account.
func (*ChipManager) DeductChips ¶
func (c *ChipManager) DeductChips(amount int) error
DeductChips deducts the specified amount of chips from the player's account.
func (*ChipManager) GetChips ¶
func (c *ChipManager) GetChips() int
GetChips returns the current number of chips the player has.
func (*ChipManager) HasEnoughChips ¶
func (c *ChipManager) HasEnoughChips(amount int) bool
HasEnoughChips checks if the player has enough chips for the specified amount.
func (*ChipManager) SetChips ¶
func (c *ChipManager) SetChips(amount int)
SetChips sets the number of chips the player has. This is a no-op since chips are managed via the bank account.
type Config ¶
type Config struct {
ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
GuildID string `json:"guild_id" bson:"guild_id"`
MaxPlayers int `json:"max_players" bson:"max_players"`
Decks int `json:"decks" bson:"decks"`
BetAmount int `json:"bet_amount" bson:"bet_amount"`
DelayBetweenGames time.Duration `json:"delay_between_games" bson:"delay_between_games"`
WaitForPlayers time.Duration `json:"wait_for_players" bson:"wait_for_players"`
PlayerTimeout time.Duration `json:"player_timeout" bson:"player_timeout"`
ShowPlayerTurn time.Duration `json:"show_player_turn" bson:"show_player_turn"`
ShowDealerTurn time.Duration `json:"show_dealer_turn" bson:"show_dealer_turn"`
PayoutPercent int `json:"payout_percent" bson:"payout_percent"`
SinglePlayerMode bool `json:"single_player_mode" bson:"single_player_mode"`
}
Config holds the configuration settings for the blackjack game.
type Game ¶
type Game struct {
// contains filtered or unexported fields
}
Game represents a blackjack game for a specific guild.
func GetGame ¶
GetGame retrieves the blackjack game for the specified guild. If no game exists, a new one is created.
func (*Game) DealInitialCards ¶
DealInitialCards deals the initial cards to all players and the dealer.
func (*Game) DealerPlay ¶
DealerPlay processes the dealer's play according to blackjack rules.
func (*Game) EndRound ¶
func (g *Game) EndRound()
EndRound ends the current round of blackjack for the guild, removing all players from the game.
func (*Game) EvaluateHand ¶
func (g *Game) EvaluateHand(hand *bj.Hand) bj.GameResult
EvaluateHand evaluates the result of a specific hand for a player.
func (*Game) GetActivePlayer ¶
GetACtivePlayer retrieves the currently active player in the blackjack game.
func (*Game) IsDealingHands ¶
IsDealingHands returns whether the blackjack game is currently dealing initial hands to players.
func (*Game) IsStartingRound ¶
IsStartingRound returns whether the blackjack game is in the process of starting a new round, which occurs after the initial hands have been dealt and before player turns begin.
func (*Game) IsWaitingForPlayers ¶
IsWaitingForPlayers returns whether the blackjack game is waiting for players to join.
func (*Game) NotStarted ¶
NotStarted returns whether the blackjack game has not yet started.
func (*Game) PayoutResults ¶
func (g *Game) PayoutResults()
PayoutResults pays out the results of the blackjack game.
func (*Game) PlayerActionRequest ¶
PlayerActionRequest processes a request from a player to take an action, ensuring that the player is active and the game is in progress.
func (*Game) PlayerDoubleDown ¶
PlayerDoubleDown processes a double down hit action for the specified player.
func (*Game) PlayerSplit ¶
PlayerSplit processes a split action for the specified player.
func (*Game) PlayerStand ¶
PlayerStand processes a stand action for the specified player.
func (*Game) PlayerSurrender ¶
PlayerSurrender processes a surrender action for the specified player.
func (*Game) SecondsBeforeStart ¶
SecondsBeforeStart returns the number of seconds remaining to wait for players before starting the game. If the wait time has elapsed, it returns 0.
func (*Game) StartNewRound ¶
StartNewRound starts a new round of blackjack in the game.
type GameState ¶
type GameState int
const ( NotStarted GameState WaitingForPlayers StartingRound DealingHands )
type Member ¶
type Member struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
GuildID string `json:"guild_id" bson:"guild_id"`
MemberID string `json:"member_id" bson:"member_id"`
RoundsPlayed int `json:"rounds_played" bson:"rounds_played"`
HandsPlayed int `json:"hands_played" bson:"hands_played"`
Wins int `json:"wins" bson:"wins"`
Losses int `json:"losses" bson:"losses"`
Pushes int `json:"pushes" bson:"pushes"`
Blackjacks int `json:"blackjacks" bson:"blackjacks"`
Splits int `json:"splits" bson:"splits"`
Surrenders int `json:"surrenders" bson:"surrenders"`
CreditsBet int `json:"credits_bet" bson:"credits_bet"`
CreditsWon int `json:"credits_won" bson:"credits_won"`
CreditsLost int `json:"credits_lost" bson:"credits_lost"`
LastPlayed time.Time `json:"last_played" bson:"last_played"`
}
Member represents a member's statistics for the blackjack game.
func GetMember ¶
GetMember retrieves the member statistics for a specific guild and user. If the member does not exist, a new member is created and returned.
func (*Member) RoundPlayed ¶
RoundPlayed updates the member statistics based on the results of a played round.
type Plugin ¶
type Plugin struct{}
Plugin is the plugin for the slots system used by the bot
func (*Plugin) GetAdminHelp ¶
GetAdminHelp returns the admin help for the slots system
func (*Plugin) GetCommandHandlers ¶
func (plugin *Plugin) GetCommandHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)
GetCommandHandlers returns the command handlers for the slots system
func (*Plugin) GetCommands ¶
func (plugin *Plugin) GetCommands() []*discordgo.ApplicationCommand
GetCommands returns the commands for the slots system
func (*Plugin) GetComponentHandlers ¶
func (plugin *Plugin) GetComponentHandlers() map[string]func(*discordgo.Session, *discordgo.InteractionCreate)
GetComponentHandlers returns the component handlers for the slots system
func (*Plugin) Initialize ¶
Initialize saves the Discord bot to be used by the slots system
func (*Plugin) Status ¶
func (plugin *Plugin) Status() discord.PluginStatus
Status returns the status of the heist game. This is used to determine if the plugin is running or not.