Improving the spin flow

This commit is contained in:
Joseph Ferano 2022-01-17 15:11:05 +07:00
parent 0c1cf67bbf
commit 3d214d69a1
2 changed files with 59 additions and 35 deletions

View File

@ -114,6 +114,7 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) =
| false -> | false ->
let prize = 1.337f // LEET let prize = 1.337f // LEET
let attack = { HackType = enum<Weapon>(int weapon) ; Timestamp = DateTime.UtcNow ; Target = { Id = targetId ; Name = split.[3] } } let attack = { HackType = enum<Weapon>(int weapon) ; Timestamp = DateTime.UtcNow ; Target = { Id = targetId ; Name = split.[3] } }
// TODO: Make a single update instead of two
do! DbService.updatePlayer <| updatePlayer prize attack player do! DbService.updatePlayer <| updatePlayer prize attack player
do! DbService.updatePlayer { target with Bank = MathF.Max(target.Bank - prize, 0f)} do! DbService.updatePlayer { target with Bank = MathF.Max(target.Bank - prize, 0f)}

View File

@ -3,9 +3,10 @@ open System.Threading.Tasks
open DSharpPlus open DSharpPlus
open DSharpPlus.Entities open DSharpPlus.Entities
open DSharpPlus.SlashCommands open DSharpPlus.SlashCommands
open System.IO open DegenzGame
open DegenzGame.Shared
let slots = [| "https://i.ibb.co/pKqZdr7/cherry.png" ; "https://i.ibb.co/Mk8wQmv/lemon.jpg" ; "https://i.ibb.co/1JTFPSs/seven.png" |] let slots = [| "https://i.ibb.co/pKqZdr7/cherry.png" ; "https://i.ibb.co/JnghQsL/lemon.jpg" ; "https://i.ibb.co/1JTFPSs/seven.png" |]
type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule () type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule ()
@ -15,10 +16,22 @@ type SlotMachine() =
[<SlashCommand("spin", "Want to try your luck?")>] [<SlashCommand("spin", "Want to try your luck?")>]
member this.AttackCommand (ctx : InteractionContext) = member this.AttackCommand (ctx : InteractionContext) =
async { async {
let! playerResult = DbService.tryFindPlayer ctx.Member.Id
match playerResult with
| Some player ->
let sleepTime = 1000 let sleepTime = 1000
let random = Random(System.Guid.NewGuid().GetHashCode()) let random = Random(System.Guid.NewGuid().GetHashCode())
let results = [ random.Next(0, 3) ; random.Next(0, 3) ; random.Next(0, 3)] let results = [ random.Next(0, 3) ; random.Next(0, 3) ; random.Next(0, 3)]
let winConditions = (results.[0] = results.[1] && results.[0] = results.[2])
|| (results.[0] <> results.[1] && results.[1] <> results.[2] && results.[0] <> results.[2])
if winConditions then
do! DbService.updatePlayer { player with Bank = player.Bank + 10.0f }
else
do! DbService.updatePlayer { player with Bank = MathF.Max(player.Bank - 0.5f, 0.0f) }
do! ctx.Interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource) do! ctx.Interaction.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource)
|> Async.AwaitTask |> Async.AwaitTask
@ -47,12 +60,22 @@ type SlotMachine() =
|> Async.AwaitTask |> Async.AwaitTask
|> Async.Ignore |> Async.Ignore
if winConditions then
do! Async.Sleep sleepTime do! Async.Sleep sleepTime
let builder = DiscordFollowupMessageBuilder() let builder = DiscordFollowupMessageBuilder()
builder.Content <- "You win!" builder.Content <- "You win 10 GBT!"
do! ctx.Interaction.CreateFollowupMessageAsync(builder) do! ctx.Interaction.CreateFollowupMessageAsync(builder)
|> Async.AwaitTask |> Async.AwaitTask
|> Async.Ignore |> Async.Ignore
else
do! Async.Sleep sleepTime
let builder = DiscordFollowupMessageBuilder()
builder.Content <- "You lose 0.5 GBT! Try your luck again!"
do! ctx.Interaction.CreateFollowupMessageAsync(builder)
|> Async.AwaitTask
|> Async.Ignore
| None -> do! notYetAHackerMsg ctx
} |> Async.StartAsTask } |> Async.StartAsTask
:> Task :> Task