-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Setting up snailrace core * feat: More work on core * feat: Untested Snailrace Core Package * feat: Base renderer for snailrace state * feat: Attempting to allow people to join via application command * feat: Snailrace Join a hosted Race working * feat: Snailrace Place a Quickbet * feat: Snailrace Racing working * feat: Racing finished, payouts, cancelled races and tweaked track display. Almost ready to be merged. * feat: Altered Race Mechanics and Trading Cards Implemented * refactor: Moved common snail usage const to the App file * fix: The use card returns a specific error when there is no usages left
- Loading branch information
Showing
28 changed files
with
2,226 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package blackjackApp | ||
package blackjack_app | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package blackjackApp | ||
package blackjack_app | ||
|
||
import ( | ||
"github.com/aussiebroadwan/tony/pkg/blackjack" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package snailrace_app | ||
|
||
import ( | ||
"github.com/aussiebroadwan/tony/framework" | ||
"github.com/aussiebroadwan/tony/pkg/snailrace" | ||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
const CommonSnailUsage = 25 | ||
|
||
func RegisterSnailraceApp(bot *framework.Bot) framework.Route { | ||
return framework.NewRoute(bot, "snailrace", | ||
// snailrace | ||
&Snailrace{}, // [NOP] | ||
|
||
framework.NewRoute(bot, "host", &SnailraceHostSubCommand{}), | ||
framework.NewRoute(bot, "bet", &SnailraceBetSubCommand{}), | ||
) | ||
} | ||
|
||
type Snailrace struct { | ||
framework.ApplicationCommand | ||
framework.ApplicationMountable | ||
} | ||
|
||
func (s Snailrace) GetType() framework.AppType { | ||
return framework.AppTypeCommand | framework.AppTypeMountable | ||
} | ||
|
||
func (s Snailrace) OnMount(ctx framework.MountContext) { | ||
snailrace.SetupSnailraceDB(ctx.Database()) | ||
} | ||
|
||
func (s Snailrace) GetDefinition() *discordgo.ApplicationCommand { | ||
return &discordgo.ApplicationCommand{ | ||
Name: "snailrace", | ||
Description: "Let's race snails!", | ||
Options: []*discordgo.ApplicationCommandOption{ | ||
{ | ||
Type: discordgo.ApplicationCommandOptionSubCommand, | ||
Name: "host", | ||
Description: "Host a snailrace", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (s Snailrace) OnCommand(ctx framework.CommandContext) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aussiebroadwan/tony/pkg/snailrace" | ||
"github.com/bwmarrin/discordgo" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// bettingMessage generates the message and componenets required for the | ||
// betting stage of a race. | ||
func bettingMessage(state snailrace.RaceState) (string, []discordgo.MessageComponent) { | ||
description := fmt.Sprintf( | ||
"Bets are now open to everyone, do you feel lucky? To place a quick bet you can select the snail via the drop down. \n\n```\nRace ID: %s\nStarting: %s\n\nEntrants:\n", | ||
state.Race.Id, | ||
state.Race.StartAt.Format(time.DateTime), | ||
) | ||
|
||
menuOptions := make([]discordgo.SelectMenuOption, len(state.Snails)) | ||
for index, snail := range state.Snails { | ||
logrus.Infof("Calculating odds for snail %s, race_pool %d, pool %d", snail.Name, state.Race.Pool, state.Race.Snails[index].Pool) | ||
odds := snailrace.CalculateOdds(state.Race.Pool, state.Race.Snails[index].Pool) | ||
description += fmt.Sprintf("[%d]: %s @ %.02f\n", index, snail.Name, odds) | ||
|
||
menuOptions[index] = discordgo.SelectMenuOption{ | ||
Label: fmt.Sprintf("%s @ %.02f", snail.Name, odds), | ||
Value: fmt.Sprintf("%d", index), | ||
Default: false, | ||
} | ||
} | ||
description += "```" | ||
|
||
return description, []discordgo.MessageComponent{ | ||
discordgo.SelectMenu{ | ||
CustomID: "snailrace.bet:win_request:" + state.Race.Id, | ||
Placeholder: "Select a Quickbet", | ||
Options: menuOptions, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package render | ||
|
||
import ( | ||
"github.com/aussiebroadwan/tony/pkg/snailrace" | ||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func cancelledMessage(state snailrace.RaceState) (string, []discordgo.MessageComponent) { | ||
|
||
description := "Race has been cancelled due to not enough players.\n" | ||
|
||
return description, []discordgo.MessageComponent{ | ||
discordgo.Button{ | ||
Label: "Concluded", | ||
Disabled: true, | ||
Style: discordgo.SuccessButton, | ||
CustomID: "snailrace.host:" + state.Race.Id, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aussiebroadwan/tony/pkg/snailrace" | ||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func finishedMessage(state snailrace.RaceState, creditUser func(string, int64)) (string, []discordgo.MessageComponent) { | ||
|
||
description := fmt.Sprintf("```\nRace ID: %s\n\n%s\n", state.Race.Id, buildTrack(state)) | ||
entrants := "Results:\n" | ||
|
||
// Display the results | ||
for index, snail := range state.Snails { | ||
entrants += fmt.Sprintf("[%d]: %s ", index, snail.Name) | ||
if place, ok := state.Place[index]; ok { | ||
switch place { | ||
case 1: | ||
entrants += "🥇" | ||
case 2: | ||
entrants += "🥈" | ||
case 3: | ||
entrants += "🥉" | ||
} | ||
} | ||
entrants += "\n" | ||
} | ||
description += entrants + "```" | ||
|
||
// Payout the winners | ||
for _, userBet := range state.Race.UserBets { | ||
if place, ok := state.Place[userBet.SnailIndex]; ok { | ||
if place == 1 { | ||
odds := snailrace.CalculateOdds(state.Race.Pool, state.Race.Snails[userBet.SnailIndex].Pool) | ||
win := int64(float64(userBet.Amount) * odds) | ||
creditUser(userBet.UserId, win) | ||
} | ||
} | ||
} | ||
|
||
return description, []discordgo.MessageComponent{ | ||
discordgo.Button{ | ||
Label: "Concluded", | ||
Disabled: true, | ||
Style: discordgo.SuccessButton, | ||
CustomID: "snailrace.host:" + state.Race.Id, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aussiebroadwan/tony/pkg/snailrace" | ||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
// joinMessage generates the join stage message and components. | ||
func joinMessage(state snailrace.RaceState) (string, []discordgo.MessageComponent) { | ||
description := fmt.Sprintf( | ||
"A new race has been hosted!\n\nRace ID: `%s`\nStarting: `%s`\n\n"+ | ||
"Click the `Join` button to join with your own snail.\n\n", | ||
state.Race.Id, | ||
state.Race.StartAt.Format(time.DateTime), | ||
) | ||
|
||
if len(state.Snails) == 0 { | ||
description += "> No snails have joined yet\n" | ||
} else { | ||
description += "**Entrants:**\n" | ||
for _, snail := range state.Snails { | ||
description += fmt.Sprintf("- %s <@%s>\n", snail.Name, snail.OwnerId) | ||
} | ||
} | ||
|
||
return description, []discordgo.MessageComponent{ | ||
discordgo.Button{ | ||
Label: "Join", | ||
Style: discordgo.SuccessButton, | ||
CustomID: "snailrace.host:join_request:" + state.Race.Id, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aussiebroadwan/tony/pkg/snailrace" | ||
"github.com/bwmarrin/discordgo" | ||
) | ||
|
||
func raceMessage(state snailrace.RaceState) (string, []discordgo.MessageComponent) { | ||
|
||
description := fmt.Sprintf("```\nRace ID: %s\n\n%s\n", state.Race.Id, buildTrack(state)) | ||
entrants := "Entrants:\n" | ||
|
||
for index, snail := range state.Snails { | ||
odds := snailrace.CalculateOdds(state.Race.Pool, state.Race.Snails[index].Pool) | ||
entrants += fmt.Sprintf("[%d]: %s @ %.02f\n", index, snail.Name, odds) | ||
} | ||
description += entrants + "```" | ||
|
||
return description, []discordgo.MessageComponent{ | ||
discordgo.Button{ | ||
Label: "Racing", | ||
Disabled: true, | ||
Style: discordgo.SuccessButton, | ||
CustomID: "snailrace.host:" + state.Race.Id, | ||
}, | ||
} | ||
} |
Oops, something went wrong.