103 lines
4.0 KiB
Forth
103 lines
4.0 KiB
Forth
module Degenz.Thief
|
|
|
|
open System
|
|
open System.Threading.Tasks
|
|
open DSharpPlus
|
|
open DSharpPlus.Entities
|
|
open DSharpPlus.SlashCommands
|
|
open Degenz.Messaging
|
|
|
|
let getRandomStealBtnLabels () =
|
|
let rand = Random(Guid.NewGuid().GetHashCode())
|
|
let affirmative = [| "LFG" ; "YOLO" ; "IDGAF" |]
|
|
let negative = [| "NOPE" ; "IM OUT" ; "BAIL" |]
|
|
( affirmative.[rand.Next(0, 3)] , negative.[rand.Next(0, 3)] )
|
|
|
|
let chanceOfSuccessMsg = function
|
|
| amt when amt < 0.20 -> "Looking pretty bad"
|
|
| amt when amt < 0.50 -> "I mean, maybe"
|
|
| amt when amt < 0.80 -> "I think you got this"
|
|
| _ -> "Totally worth it"
|
|
|
|
let targetEvaluationMsg = function
|
|
| amt when amt < 0.20 -> "but man, they look swole."
|
|
| amt when amt < 0.50 -> "but they look a little confident"
|
|
| amt when amt < 0.80 -> "and they're looking a little nervous"
|
|
| _ -> "and they look weak af man"
|
|
|
|
let payoutChance targetBank chance = targetBank * 0.1 * (1.0 - chance)
|
|
|
|
let getStealEmbed chance (target : PlayerData) (player : PlayerData) =
|
|
let buttons =
|
|
let yes , no = getRandomStealBtnLabels ()
|
|
[ DiscordButtonComponent(ButtonStyle.Success, $"Steal-yes-{target.DiscordId}-{target.Name}-{chance}", yes)
|
|
DiscordButtonComponent(ButtonStyle.Danger, $"Steal-no", no) ]
|
|
|> Seq.cast<DiscordComponent>
|
|
let embed =
|
|
DiscordEmbedBuilder()
|
|
.AddField("Chance of Success", $"{chanceOfSuccessMsg chance}", true)
|
|
.WithDescription($"{target.Name} is coming towards you in a dark alley, {targetEvaluationMsg chance}")
|
|
.WithImageUrl("https://cdnb.artstation.com/p/assets/images/images/017/553/457/large/maarten-hof-backalley-mainshot.jpg")
|
|
.WithTitle($"Steal Money")
|
|
|
|
DiscordFollowupMessageBuilder()
|
|
.AddEmbed(embed)
|
|
.AddComponents(buttons)
|
|
.AsEphemeral(true)
|
|
|
|
|
|
let steal target (ctx : IDiscordContext) =
|
|
Game.executePlayerWithTargetAction target ctx (fun attacker defender -> async {
|
|
let winPercentage = if attacker.Stats.Strength > defender.Stats.Strength then 1.0 else 0.0
|
|
let embed = getStealEmbed winPercentage defender attacker
|
|
|
|
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
|
})
|
|
|
|
let handleSteal (ctx : IDiscordContext) =
|
|
let split = ctx.GetInteractionId().Split("-")
|
|
let answer = split.[1]
|
|
if answer = "yes" then
|
|
Game.executePlayerAction ctx (fun player -> async {
|
|
let targetId = uint64 split.[2]
|
|
let targetName = split.[3]
|
|
let chance = double split.[4]
|
|
|
|
let rand = Random(Guid.NewGuid().GetHashCode())
|
|
let result = rand.NextDouble()
|
|
|
|
if chance >= result then
|
|
let! target = DbService.tryFindPlayer targetId
|
|
do! Messaging.sendFollowUpMessage ctx $"You stole {targetName} money"
|
|
else
|
|
do! Messaging.sendFollowUpMessage ctx "You failed miserably"
|
|
|
|
return ()
|
|
})
|
|
else
|
|
async {
|
|
let builder = DiscordInteractionResponseBuilder()
|
|
builder.Content <- "I thought better of it"
|
|
do! ctx.Respond InteractionResponseType.UpdateMessage builder |> Async.AwaitTask
|
|
} |> Async.StartAsTask :> Task
|
|
|
|
|
|
type StealGame() =
|
|
inherit ApplicationCommandModule ()
|
|
|
|
let enforceChannel (ctx : IDiscordContext) (storeFn : IDiscordContext -> Task) =
|
|
match ctx.GetChannel().Id with
|
|
| id when id = GuildEnvironment.channelArmory -> storeFn ctx
|
|
| _ ->
|
|
task {
|
|
let msg = $"You must go to <#{GuildEnvironment.channelArmory}> channel to buy or sell weapons"
|
|
do! Messaging.sendSimpleResponse ctx msg
|
|
}
|
|
|
|
[<SlashCommand("steal", "Steal some money from another player, but you might go to prison if caught")>]
|
|
member this.Steal (ctx : InteractionContext, [<Option("target", "Who do you want to steal from?")>] target : DiscordUser) =
|
|
// enforceChannel (DiscordInteractionContext ctx) (steal target)
|
|
steal target (DiscordInteractionContext ctx)
|
|
|
|
|