Enforce channel and add action on all robbery attempts

This commit is contained in:
Joseph Ferano 2022-02-13 20:38:57 +07:00
parent 04add71c6e
commit 18aeab599c
2 changed files with 15 additions and 10 deletions

View File

@ -19,6 +19,7 @@ let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE"
let channelTraining = getId "CHANNEL_TRAINING" let channelTraining = getId "CHANNEL_TRAINING"
let channelArmory = getId "CHANNEL_ARMORY" let channelArmory = getId "CHANNEL_ARMORY"
let channelBattle = getId "CHANNEL_BATTLE" let channelBattle = getId "CHANNEL_BATTLE"
let channelThievery = getId "CHANNEL_THIEVERY"
let botIdHackerBattle = getId "BOT_HACKER_BATTLE" let botIdHackerBattle = getId "BOT_HACKER_BATTLE"
let botIdArmory = getId "BOT_ARMORY" let botIdArmory = getId "BOT_ARMORY"
let roleTrainee = getId "ROLE_TRAINEE" let roleTrainee = getId "ROLE_TRAINEE"

View File

@ -18,7 +18,7 @@ let VictimRecovery = TimeSpan.FromHours(12)
type StealResult = type StealResult =
| Success | Success
| WentToPrison | WentToPrison
| TargetRanAway | VictimRanAway
let getRandomStealBtnLabels () = let getRandomStealBtnLabels () =
let rand = Random(Guid.NewGuid().GetHashCode()) let rand = Random(Guid.NewGuid().GetHashCode())
@ -75,7 +75,7 @@ let getResultEmbed targetName result =
"Looks like you went to prison" "Looks like you went to prison"
, $"{targetName} knows Karate and elbowed you in the nose. While unconscious, they called the cops. You're on your way to prison now... " , $"{targetName} knows Karate and elbowed you in the nose. While unconscious, they called the cops. You're on your way to prison now... "
, "https://thumbs.dreamstime.com/b/vector-pixel-art-prisoner-isolated-cartoon-vector-pixel-art-prisoner-129807237.jpg" , "https://thumbs.dreamstime.com/b/vector-pixel-art-prisoner-isolated-cartoon-vector-pixel-art-prisoner-129807237.jpg"
| TargetRanAway -> | VictimRanAway ->
"You tried to snatch their money and they ran away" "You tried to snatch their money and they ran away"
, $"{targetName} got nervous seeing a shadowy figure and ran in the opposite direction" , $"{targetName} got nervous seeing a shadowy figure and ran in the opposite direction"
, "https://i.imgur.com/NLHMvVK.jpg" , "https://i.imgur.com/NLHMvVK.jpg"
@ -140,28 +140,32 @@ let handleSteal (ctx : IDiscordContext) =
let rand = Random(Guid.NewGuid().GetHashCode()) let rand = Random(Guid.NewGuid().GetHashCode())
let result = chance >= rand.NextDouble() , rand.Next(0,3) = 0 let result = chance >= rand.NextDouble() , rand.Next(0,3) = 0
let dp = { DiscordPlayer.Id = targetId ; DiscordPlayer.Name = targetName }
let stealAction = { ActionId = StealActionId ; Type = Attack { AttackResult.Result = false ; AttackResult.Target = dp } ; Timestamp = DateTime.UtcNow }
// TODO: Send event to the hall of privacy
match result with match result with
| true , _ -> | true , _ ->
let xp = 15 let xp = 15
let embed = getResultEmbed targetName Success let embed = getResultEmbed targetName Success
embed.AddField("$GBT Stolen", string prize) |> ignore embed.AddField("$GBT Stolen", string prize) |> ignore
embed.AddField("XP Gained", $"{xp}+") |> ignore embed.AddField("XP Gained", $"{xp}") |> ignore
do! Messaging.sendFollowUpEmbed ctx (embed.Build()) do! Messaging.sendFollowUpEmbed ctx (embed.Build())
match! DbService.tryFindPlayer targetId with match! DbService.tryFindPlayer targetId with
| Some t -> | Some t ->
let action = { ActionId = VictimDefenseActionId ; Type = Defense ; Timestamp = DateTime.UtcNow } let action = { ActionId = VictimDefenseActionId ; Type = Defense ; Timestamp = DateTime.UtcNow }
do! DbService.updatePlayer { t with Bank = max (t.Bank - prize) 0<GBT> ; Actions = Array.append [| action |] t.Actions } do! DbService.updatePlayer { t with Bank = max (t.Bank - prize) 0<GBT> ; Actions = Array.append [| action |] t.Actions }
| None -> () | None -> ()
let dp = { DiscordPlayer.Id = targetId ; DiscordPlayer.Name = targetName }
let action = { ActionId = StealActionId ; Type = Attack { AttackResult.Result = true ; AttackResult.Target = dp } ; Timestamp = DateTime.UtcNow } let action = { ActionId = StealActionId ; Type = Attack { AttackResult.Result = true ; AttackResult.Target = dp } ; Timestamp = DateTime.UtcNow }
do! DbService.updatePlayer { player with Bank = player.Bank + prize ; XP = player.XP + xp ; Actions = Array.append [| action |] player.Actions } do! DbService.updatePlayer { player with Bank = player.Bank + prize ; XP = player.XP + xp ; Actions = Array.append [| action |] player.Actions }
| false , false -> | false , false ->
let embed = getResultEmbed targetName TargetRanAway let embed = getResultEmbed targetName VictimRanAway
do! DbService.updatePlayer { player with Actions = Array.append [| stealAction |] player.Actions }
do! Messaging.sendFollowUpEmbed ctx (embed.Build()) do! Messaging.sendFollowUpEmbed ctx (embed.Build())
| false , true -> | false , true ->
let embed = getResultEmbed targetName WentToPrison let embed = getResultEmbed targetName WentToPrison
do! DbService.updatePlayer { player with Actions = Array.append [| stealAction |] player.Actions }
do! Messaging.sendFollowUpEmbed ctx (embed.Build()) do! Messaging.sendFollowUpEmbed ctx (embed.Build())
do! Async.Sleep 5000 do! Async.Sleep 2000
let role = ctx.GetGuild().GetRole(GuildEnvironment.rolePrisoner) let role = ctx.GetGuild().GetRole(GuildEnvironment.rolePrisoner)
do! ctx.GetDiscordMember().GrantRoleAsync(role) |> Async.AwaitTask do! ctx.GetDiscordMember().GrantRoleAsync(role) |> Async.AwaitTask
} }
@ -185,16 +189,16 @@ type StealGame() =
let enforceChannel (ctx : IDiscordContext) (storeFn : IDiscordContext -> Task) = let enforceChannel (ctx : IDiscordContext) (storeFn : IDiscordContext -> Task) =
match ctx.GetChannel().Id with match ctx.GetChannel().Id with
| id when id = GuildEnvironment.channelArmory -> storeFn ctx | id when id = GuildEnvironment.channelThievery -> storeFn ctx
| _ -> | _ ->
task { task {
let msg = $"You must go to <#{GuildEnvironment.channelArmory}> channel to buy or sell weapons" let msg = $"You must go to <#{GuildEnvironment.channelThievery}> channel if you want to mug some unsuspecting doofs"
do! Messaging.sendSimpleResponse ctx msg do! Messaging.sendSimpleResponse ctx msg
} }
[<SlashCommand("steal", "Steal some money from another player, but you might go to prison if caught")>] [<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) = member this.Steal (ctx : InteractionContext, [<Option("target", "Who do you want to steal from?")>] target : DiscordUser) =
// enforceChannel (DiscordInteractionContext ctx) (steal target) enforceChannel (DiscordInteractionContext ctx) (steal target)
steal target (DiscordInteractionContext ctx) // steal target (DiscordInteractionContext ctx)