Multipliers

This commit is contained in:
Joseph Ferano 2022-04-19 14:04:40 +07:00
parent cc0d20e91a
commit 5b1124e5e0

View File

@ -128,11 +128,20 @@ let slotEmojiNames =
"alcohol"
"anonmask" |]
let PlayPrice = 5<GBT>
let PlayPricex1 = 5<GBT>
let PlayPricex2 = 10<GBT>
let PlayPricex3 = 20<GBT>
let sleepTime = 1500
let mutable guildEmojis : Map<string, DiscordEmoji> option = None
let mutable anyEmoji : DiscordEmoji option = None
let embedButtons =
let button1 = DiscordButtonComponent(ButtonStyle.Success, $"spin-1x", $"Spin 1x - {PlayPricex1} $GBT") :> DiscordComponent
let button2 = DiscordButtonComponent(ButtonStyle.Success, $"spin-2x", $"Spin 2x - {PlayPricex2} $GBT") :> DiscordComponent
let button3 = DiscordButtonComponent(ButtonStyle.Success, $"spin-3x", $"Spin 3x - {PlayPricex3} $GBT") :> DiscordComponent
let button4 = DiscordButtonComponent(ButtonStyle.Primary, $"prizes", $"Show Prizes") :> DiscordComponent
[| button1 ; button2 ; button3 ; button4 |]
let getJackpotAmount () =
GuildEnvironment.connectionString
|> Sql.connect
@ -146,78 +155,6 @@ let incrementJackpot amount =
|> Sql.query "UPDATE item SET stock = stock + @amount WHERE symbol = 'JACKPOT'"
|> Sql.executeNonQueryAsync
let spinEmojis (results : SlotSymbol array) (ctx : IDiscordContext) =
async {
let itx = ctx.GetInteraction()
let builder = DiscordFollowupMessageBuilder()
builder.Content <- "Spinning!"
builder.IsEphemeral <- true
let! followUp = itx.CreateFollowupMessageAsync(builder) |> Async.AwaitTask
match guildEmojis with
| Some emojis ->
let e1 = Formatter.Emoji(emojis.[results.[0].emojiName])
let e2 = Formatter.Emoji(emojis.[results.[1].emojiName])
let e3 = Formatter.Emoji(emojis.[results.[2].emojiName])
do! Async.Sleep sleepTime
let content = $"{e1}"
let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(content)) |> Async.AwaitTask
do! Async.Sleep sleepTime
let content = $"{e1}{e2}"
let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(content)) |> Async.AwaitTask
do! Async.Sleep sleepTime
let content = $"{e1}{e2}{e3}"
let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(content)) |> Async.AwaitTask
return ()
| None -> return ()
}
let spin spinType (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async {
let random = Random(Guid.NewGuid().GetHashCode())
let symbols = [| reel1.[random.Next(0, reel1.Length)] ; reel2.[random.Next(0, reel2.Length)] ; reel3.[random.Next(0, reel3.Length)] |]
let prize =
prizeTable
|> Array.tryPick (fun (s1,s2,s3,prize) ->
match s1 , s2 , s3 with
| Symbol s1' , Symbol s2' , Symbol s3' when s1'.index = symbols.[0].index && s2'.index = symbols.[1].index && s3'.index = symbols.[2].index -> Some prize
| Symbol s1' , Symbol s2' , Any when s1'.index = symbols.[0].index && s2'.index = symbols.[1].index -> Some prize
| Symbol s1' , Any , Any when s1'.index = symbols.[0].index -> Some prize
| _ -> None)
match spinType with
| "Emojis" -> do! spinEmojis symbols ctx
// | "Files" -> do! spinFiles symbols ctx
| _ -> ()
do! Async.Sleep 2000
let builder = DiscordFollowupMessageBuilder()
builder.IsEphemeral <- true
let embed4 = DiscordEmbedBuilder()
embed4.Title <- "Results"
match prize with
| Some (Money amount) ->
do! DbService.updatePlayerCurrency amount player |> Async.Ignore
embed4.ImageUrl <- "https://s7.gifyu.com/images/youwin.png"
embed4.Description <- $"You win **{amount}** GBT!"
| Some (Jackpot) ->
embed4.ImageUrl <- "https://s7.gifyu.com/images/jackpot2ac30c9823f6a91c.png"
embed4.Description <- $"YOU HIT THE JACKPOT!!!"
| None ->
do! DbService.updatePlayerCurrency -PlayPrice player |> Async.Ignore
do! incrementJackpot PlayPrice |> Async.AwaitTask |> Async.Ignore
embed4.Description <- $"Better luck next time! You paid {PlayPrice} $GBT"
let button1 = DiscordButtonComponent(ButtonStyle.Success, $"spin", $"Spin Again {PlayPrice} $GBT") :> DiscordComponent
let button2 = DiscordButtonComponent(ButtonStyle.Success, $"prizes", $"Show Prizes") :> DiscordComponent
builder.AddComponents [| button1 ; button2 |] |> ignore
builder.AddEmbed(embed4) |> ignore
do! ctx.FollowUp(builder) |> Async.AwaitTask |> Async.Ignore
return ()
})
let handlePrizeTable (ctx : IDiscordContext) =
task {
do! Messaging.defer ctx
@ -251,11 +188,85 @@ let handlePrizeTable (ctx : IDiscordContext) =
| _ , _ -> return ()
} :> Task
let spinEmojis (results : SlotSymbol array) (ctx : IDiscordContext) =
async {
let itx = ctx.GetInteraction()
let builder = DiscordFollowupMessageBuilder()
builder.Content <- "Spinning!"
builder.IsEphemeral <- true
let! followUp = itx.CreateFollowupMessageAsync(builder) |> Async.AwaitTask
match guildEmojis with
| Some emojis ->
let e1 = Formatter.Emoji(emojis.[results.[0].emojiName])
let e2 = Formatter.Emoji(emojis.[results.[1].emojiName])
let e3 = Formatter.Emoji(emojis.[results.[2].emojiName])
do! Async.Sleep sleepTime
let content = $"{e1}"
let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(content)) |> Async.AwaitTask
do! Async.Sleep sleepTime
let content = $"{e1}{e2}"
let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(content)) |> Async.AwaitTask
do! Async.Sleep sleepTime
let content = $"{e1}{e2}{e3}"
let! _ = itx.EditFollowupMessageAsync(followUp.Id, DiscordWebhookBuilder().WithContent(content)) |> Async.AwaitTask
return ()
| None -> return ()
}
let spin multiplier (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async {
let random = Random(Guid.NewGuid().GetHashCode())
let symbols = [| reel1.[random.Next(0, reel1.Length)] ; reel2.[random.Next(0, reel2.Length)] ; reel3.[random.Next(0, reel3.Length)] |]
let prize =
prizeTable
|> Array.tryPick (fun (s1,s2,s3,prize) ->
match s1 , s2 , s3 with
| Symbol s1' , Symbol s2' , Symbol s3' when s1'.index = symbols.[0].index && s2'.index = symbols.[1].index && s3'.index = symbols.[2].index -> Some prize
| Symbol s1' , Symbol s2' , Any when s1'.index = symbols.[0].index && s2'.index = symbols.[1].index -> Some prize
| Symbol s1' , Any , Any when s1'.index = symbols.[0].index -> Some prize
| _ -> None)
do! spinEmojis symbols ctx
do! Async.Sleep 2000
let builder = DiscordFollowupMessageBuilder()
builder.IsEphemeral <- true
let embed4 = DiscordEmbedBuilder()
embed4.Title <- "Results"
match prize with
| Some (Money amount) ->
do! DbService.updatePlayerCurrency (amount * multiplier) player |> Async.Ignore
embed4.ImageUrl <- "https://s7.gifyu.com/images/youwin.png"
embed4.Description <- $"You win **{amount}** GBT!"
| Some (Jackpot) ->
embed4.ImageUrl <- "https://s7.gifyu.com/images/jackpot2ac30c9823f6a91c.png"
embed4.Description <- $"YOU HIT THE JACKPOT!!!"
| None ->
let playAmount =
match multiplier with
| 0 -> PlayPricex1
| 1 -> PlayPricex2
| _ -> PlayPricex3
do! DbService.updatePlayerCurrency -playAmount player |> Async.Ignore
do! incrementJackpot PlayPricex1 |> Async.AwaitTask |> Async.Ignore
embed4.Description <- $"Better luck next time! You paid {playAmount} $GBT"
builder.AddComponents embedButtons |> ignore
builder.AddEmbed(embed4) |> ignore
do! ctx.FollowUp(builder) |> Async.AwaitTask |> Async.Ignore
return ()
})
let handleButton (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
let ctx = DiscordEventContext event
task {
match event.Id with
| "spin" -> do! spin "Emojis" ctx
| "spin-1x" -> do! spin 1 ctx
| "spin-2x" -> do! spin 2 ctx
| "spin-3x" -> do! spin 3 ctx
| "prizes" -> do! handlePrizeTable ctx
| _ ->
printfn "Wrong Spin ID"
@ -284,14 +295,12 @@ let sendInitialEmbed (ctx : IDiscordContext) =
let builder = DiscordMessageBuilder()
let embed = DiscordEmbedBuilder()
embed.Title <- "Degenz Slot Machine"
embed.Description <- "Hello I am an embed"
embed.ImageUrl <- "https://i.kym-cdn.com/photos/images/original/001/169/608/a43.gif"
embed.Description <- "Want to try your luck?"
embed.ImageUrl <- "https://s7.gifyu.com/images/ezgif.com-gif-maker-241e68d2027b0efd54.gif"
builder.AddEmbed(embed) |> ignore
let button1 = DiscordButtonComponent(ButtonStyle.Success, $"spin", $"Spin {PlayPrice} $GBT") :> DiscordComponent
let button2 = DiscordButtonComponent(ButtonStyle.Success, $"prizes", $"Show Prizes") :> DiscordComponent
builder.AddComponents [| button1 ; button2 |] |> ignore
builder.AddComponents embedButtons |> ignore
do! GuildEnvironment.botClientSlots.Value.SendMessageAsync(channel, builder)
|> Async.AwaitTask
|> Async.Ignore