Reorder things, and remove explicit modules, remove unused opens

This commit is contained in:
Joseph Ferano 2022-02-26 21:50:14 +07:00
parent c45f1c6ca6
commit 9659656e4a
13 changed files with 32 additions and 41 deletions

View File

@ -13,11 +13,11 @@
<Content Include="paket.references" /> <Content Include="paket.references" />
<Compile Include="Prelude.fs" /> <Compile Include="Prelude.fs" />
<Compile Include="GuildEnvironment.fs" /> <Compile Include="GuildEnvironment.fs" />
<Compile Include="GameTypes.fs" />
<Compile Include="Messaging.fs" /> <Compile Include="Messaging.fs" />
<Compile Include="GameTypes.fs" />
<Compile Include="GameHelpers.fs" />
<Compile Include="DbService.fs" /> <Compile Include="DbService.fs" />
<Compile Include="PlayerInteractions.fs" /> <Compile Include="PlayerInteractions.fs" />
<Compile Include="GameHelpers.fs" />
<Compile Include="XP.fs" /> <Compile Include="XP.fs" />
<Compile Include="Embeds.fs" /> <Compile Include="Embeds.fs" />
<Compile Include="Games\SlotMachine.fs" /> <Compile Include="Games\SlotMachine.fs" />

View File

@ -1,8 +1,6 @@
module Degenz.DbService module Degenz.DbService
open System.Security.Cryptography.X509Certificates open Degenz
open Degenz.Types
open System open System
open Npgsql.FSharp open Npgsql.FSharp

View File

@ -1,7 +1,6 @@
module Degenz.Embeds module Degenz.Embeds
open System open System
open DSharpPlus
open Degenz.Messaging open Degenz.Messaging
open Degenz.Types open Degenz.Types
open DSharpPlus.Entities open DSharpPlus.Entities
@ -45,7 +44,7 @@ let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerDat
| Hacking h -> h.HackId = item.Id && h.IsInstigator | Hacking h -> h.HackId = item.Id && h.IsInstigator
| Shielding id -> id = item.Id | Shielding id -> id = item.Id
| _ -> false) | _ -> false)
let btnColor = Game.getClassButtonColor item.Class let btnColor = WeaponClass.getClassButtonColor item.Class
match action , ignoreCooldown with match action , ignoreCooldown with
| None , _ | Some _ , true -> | None , _ | Some _ , true ->
DiscordButtonComponent(btnColor, $"{actionId}-{item.Id}-{buttonInfo}-{player.Name}", $"{item.Name}") DiscordButtonComponent(btnColor, $"{actionId}-{item.Id}-{buttonInfo}-{player.Name}", $"{item.Name}")
@ -64,7 +63,7 @@ let pickDefense actionId player isTrainer =
for s in Player.getShields player |> Array.sortBy (fun i -> i.Power) do for s in Player.getShields player |> Array.sortBy (fun i -> i.Power) do
let hours = TimeSpan.FromMinutes(int s.Cooldown).TotalHours let hours = TimeSpan.FromMinutes(int s.Cooldown).TotalHours
let against = Game.getGoodAgainst(s.Class) |> snd let against = WeaponClass.getGoodAgainst(s.Class) |> snd
embed.AddField(s.Name, $"Active {hours} hours\nDefeats {against}", true) |> ignore embed.AddField(s.Name, $"Active {hours} hours\nDefeats {against}", true) |> ignore
DiscordFollowupMessageBuilder() DiscordFollowupMessageBuilder()
@ -132,19 +131,19 @@ let getBuyItemsEmbed (player : PlayerData) (itemType : ItemType) (store : Item a
| _ -> | _ ->
embed embed
// .AddField($"Defensive Strength |", string item.Power, true) // .AddField($"Defensive Strength |", string item.Power, true)
.AddField($"Strong against |", Game.getGoodAgainst item.Class |> snd |> string, true) .AddField($"Strong against |", WeaponClass.getGoodAgainst item.Class |> snd |> string, true)
.AddField("Active For |", $"{TimeSpan.FromMinutes(int item.Cooldown).Hours} hours", true) .AddField("Active For |", $"{TimeSpan.FromMinutes(int item.Cooldown).Hours} hours", true)
.WithThumbnail(getShieldIcon (enum<ShieldId>(item.Id))) .WithThumbnail(getShieldIcon (enum<ShieldId>(item.Id)))
|> ignore |> ignore
embed embed
.AddField("Price 💰", (if item.Price = 0<GBT> then "Free" else $"{item.Price} $GBT"), true) .AddField("Price 💰", (if item.Price = 0<GBT> then "Free" else $"{item.Price} $GBT"), true)
.WithColor(Game.getClassEmbedColor item.Class) .WithColor(WeaponClass.getClassEmbedColor item.Class)
.WithTitle($"{item.Name}") .WithTitle($"{item.Name}")
|> ignore |> ignore
let button = let button =
if player.Inventory |> Array.exists (fun i -> i.Id = item.Id) if player.Inventory |> Array.exists (fun i -> i.Id = item.Id)
then DiscordButtonComponent(Game.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Own {item.Name}", true) then DiscordButtonComponent(WeaponClass.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Own {item.Name}", true)
else DiscordButtonComponent(Game.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Buy {item.Name}") else DiscordButtonComponent(WeaponClass.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Buy {item.Name}")
embed.Build() , button :> DiscordComponent) embed.Build() , button :> DiscordComponent)
|> Array.unzip |> Array.unzip
@ -165,9 +164,9 @@ let getSellEmbed (itemType : ItemType) (player : PlayerData) =
embed embed
.AddField("Sell For 💰", $"{item.Price} $GBT", true) .AddField("Sell For 💰", $"{item.Price} $GBT", true)
.WithTitle($"{item.Name}") .WithTitle($"{item.Name}")
.WithColor(Game.getClassEmbedColor item.Class) .WithColor(WeaponClass.getClassEmbedColor item.Class)
|> ignore |> ignore
let button = DiscordButtonComponent(Game.getClassButtonColor item.Class, $"Sell-{item.Id}", $"Sell {item.Name}") let button = DiscordButtonComponent(WeaponClass.getClassButtonColor item.Class, $"Sell-{item.Id}", $"Sell {item.Name}")
embed.Build() , button :> DiscordComponent) embed.Build() , button :> DiscordComponent)
|> Array.unzip |> Array.unzip

View File

@ -16,6 +16,7 @@ module Armory =
let getItem itemId = battleItems |> Array.find (fun w -> w.Id = itemId) let getItem itemId = battleItems |> Array.find (fun w -> w.Id = itemId)
module WeaponClass = module WeaponClass =
// TODO: Find a different place to put this
let SameTargetAttackCooldown = System.TimeSpan.FromHours(1) let SameTargetAttackCooldown = System.TimeSpan.FromHours(1)
let getClassButtonColor = function let getClassButtonColor = function

View File

@ -1,12 +1,6 @@
namespace Degenz namespace Degenz
open System open System
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.Entities
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Newtonsoft.Json
[<Microsoft.FSharp.Core.AutoOpen>] [<Microsoft.FSharp.Core.AutoOpen>]
module Types = module Types =

View File

@ -8,6 +8,7 @@ open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands open DSharpPlus.SlashCommands
open Degenz open Degenz
open Degenz.Messaging open Degenz.Messaging
open Degenz.PlayerInteractions
let checkPlayerIsAttackingThemselves defender attacker = let checkPlayerIsAttackingThemselves defender attacker =
match attacker.DiscordId = defender.DiscordId with match attacker.DiscordId = defender.DiscordId with
@ -95,7 +96,7 @@ let updateCombatants successfulHack (attacker : PlayerData) (defender : PlayerDa
} }
{ Type = Hacking hackEvent { Type = Hacking hackEvent
Timestamp = DateTime.UtcNow Timestamp = DateTime.UtcNow
Cooldown = if isDefenderEvent then int Game.SameTargetAttackCooldown.TotalMinutes * 1<mins> else hack.Cooldown } Cooldown = if isDefenderEvent then int WeaponClass.SameTargetAttackCooldown.TotalMinutes * 1<mins> else hack.Cooldown }
[ DbService.updatePlayer GuildEnvironment.pgDb <| updatePlayer prize (event false) attacker [ DbService.updatePlayer GuildEnvironment.pgDb <| updatePlayer prize (event false) attacker
DbService.updatePlayer GuildEnvironment.pgDb <| updatePlayer -prize (event true) defender DbService.updatePlayer GuildEnvironment.pgDb <| updatePlayer -prize (event true) defender
@ -136,7 +137,7 @@ let failedHack (ctx : IDiscordContext) attacker defender hack =
} }
let hack (target : DiscordUser) (ctx : IDiscordContext) = let hack (target : DiscordUser) (ctx : IDiscordContext) =
PlayerInteractions.executePlayerActionWithTarget target ctx (fun attacker defender -> async { executePlayerActionWithTarget target ctx (fun attacker defender -> async {
do! attacker do! attacker
|> Player.removeExpiredActions |> Player.removeExpiredActions
|> checkAlreadyHackedTarget defender |> checkAlreadyHackedTarget defender
@ -151,7 +152,7 @@ let hack (target : DiscordUser) (ctx : IDiscordContext) =
}) })
let handleAttack (ctx : IDiscordContext) = let handleAttack (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun attacker -> async { executePlayerAction ctx (fun attacker -> async {
let tokens = ctx.GetInteractionId().Split("-") let tokens = ctx.GetInteractionId().Split("-")
let hackId = int tokens.[1] let hackId = int tokens.[1]
let hack = Armory.getItem hackId let hack = Armory.getItem hackId
@ -176,7 +177,7 @@ let handleAttack (ctx : IDiscordContext) =
}) })
let defend (ctx : IDiscordContext) = let defend (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
if Player.getShields player |> Array.length > 0 then if Player.getShields player |> Array.length > 0 then
let p = Player.removeExpiredActions player let p = Player.removeExpiredActions player
let embed = Embeds.pickDefense "Defend" p false let embed = Embeds.pickDefense "Defend" p false
@ -187,7 +188,7 @@ let defend (ctx : IDiscordContext) =
}) })
let handleDefense (ctx : IDiscordContext) = let handleDefense (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
let tokens = ctx.GetInteractionId().Split("-") let tokens = ctx.GetInteractionId().Split("-")
let shieldId = int tokens.[1] let shieldId = int tokens.[1]
let shield = Armory.getItem shieldId let shield = Armory.getItem shieldId
@ -218,7 +219,7 @@ let handleDefense (ctx : IDiscordContext) =
}) })
let arsenal (ctx : IDiscordContext) = let arsenal (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
let updatedPlayer = Player.removeExpiredActions player let updatedPlayer = Player.removeExpiredActions player
let builder = DiscordFollowupMessageBuilder() let builder = DiscordFollowupMessageBuilder()
let embed = DiscordEmbedBuilder() let embed = DiscordEmbedBuilder()

View File

@ -1,6 +1,5 @@
module Degenz.RockPaperScissors module Degenz.RockPaperScissors
open System
open System.Threading.Tasks open System.Threading.Tasks
open DSharpPlus open DSharpPlus
open DSharpPlus.Entities open DSharpPlus.Entities

View File

@ -1,7 +1,6 @@
module Degenz.SlotMachine module Degenz.SlotMachine
open System open System
open System.Threading.Tasks
open DSharpPlus open DSharpPlus
open DSharpPlus.Entities open DSharpPlus.Entities
open DSharpPlus.SlashCommands open DSharpPlus.SlashCommands

View File

@ -7,6 +7,7 @@ open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands open DSharpPlus.SlashCommands
open Degenz open Degenz
open Degenz.Messaging open Degenz.Messaging
open Degenz.PlayerInteractions
let checkHasSufficientFunds (item : Item) player = let checkHasSufficientFunds (item : Item) player =
if player.Bank - item.Price >= 0<GBT> if player.Bank - item.Price >= 0<GBT>
@ -29,13 +30,13 @@ let checkHasItemsInArsenal itemType player =
else Error $"You currently have no {itemType}s in your arsenal to sell!" else Error $"You currently have no {itemType}s in your arsenal to sell!"
let buy itemType (ctx : IDiscordContext) = let buy itemType (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
let itemStore = Embeds.getBuyItemsEmbed player itemType Armory.battleItems let itemStore = Embeds.getBuyItemsEmbed player itemType Armory.battleItems
do! ctx.FollowUp itemStore |> Async.AwaitTask do! ctx.FollowUp itemStore |> Async.AwaitTask
}) })
let sell itemType (ctx : IDiscordContext) = let sell itemType (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
match checkHasItemsInArsenal itemType player with match checkHasItemsInArsenal itemType player with
| Ok _ -> let itemStore = Embeds.getSellEmbed itemType player | Ok _ -> let itemStore = Embeds.getSellEmbed itemType player
do! ctx.FollowUp(itemStore) |> Async.AwaitTask do! ctx.FollowUp(itemStore) |> Async.AwaitTask
@ -44,7 +45,7 @@ let sell itemType (ctx : IDiscordContext) =
// TODO: When you buy a shield, prompt the user to activate it // TODO: When you buy a shield, prompt the user to activate it
let handleBuyItem (ctx : IDiscordContext) itemId = let handleBuyItem (ctx : IDiscordContext) itemId =
PlayerInteractions.executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
let item = Armory.battleItems |> Array.find (fun w -> w.Id = itemId) let item = Armory.battleItems |> Array.find (fun w -> w.Id = itemId)
do! player do! player
|> checkHasSufficientFunds item |> checkHasSufficientFunds item
@ -58,7 +59,7 @@ let handleBuyItem (ctx : IDiscordContext) itemId =
}) })
let handleSell (ctx : IDiscordContext) itemId = let handleSell (ctx : IDiscordContext) itemId =
PlayerInteractions.executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
let item = Armory.getItem itemId let item = Armory.getItem itemId
do! do!
player player

View File

@ -7,6 +7,7 @@ open DSharpPlus.Entities
open DSharpPlus.EventArgs open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands open DSharpPlus.SlashCommands
open Degenz.Messaging open Degenz.Messaging
open Degenz.PlayerInteractions
let ThiefCooldown = TimeSpan.FromMinutes(1) let ThiefCooldown = TimeSpan.FromMinutes(1)
let VictimRecovery = TimeSpan.FromHours(1) let VictimRecovery = TimeSpan.FromHours(1)
@ -119,7 +120,7 @@ let calculateWinPercentage amountRequested bank attackerStrength defenderStrengt
//calculateWinPercentage 50 200 100 85 //calculateWinPercentage 50 200 100 85
let steal target amount (ctx : IDiscordContext) = let steal target amount (ctx : IDiscordContext) =
PlayerInteractions.executePlayerActionWithTarget target ctx (fun thief victim -> async { do! executePlayerActionWithTarget target ctx (fun thief victim -> async { do!
thief thief
|> checkPlayerIsAttackingThemselves victim |> checkPlayerIsAttackingThemselves victim
// |> checkVictimStealingCooldown victim // |> checkVictimStealingCooldown victim
@ -219,7 +220,7 @@ let handleSteal (ctx : IDiscordContext) =
} }
if answer = "yes" then if answer = "yes" then
let targetId = uint64 tokens.[2] let targetId = uint64 tokens.[2]
PlayerInteractions.executePlayerActionWithTargetId true targetId ctx (fun attacker defender -> async { executePlayerActionWithTargetId true targetId ctx (fun attacker defender -> async {
do! attacker do! attacker
|> Player.removeExpiredActions |> Player.removeExpiredActions
// |> checkVictimStealingCooldown defender // |> checkVictimStealingCooldown defender

View File

@ -4,7 +4,6 @@ open System.Text
open System.Threading.Tasks open System.Threading.Tasks
open DSharpPlus open DSharpPlus
open DSharpPlus.Entities open DSharpPlus.Entities
open DSharpPlus.EventArgs
open Degenz.Types open Degenz.Types
open Degenz.Messaging open Degenz.Messaging

View File

@ -135,9 +135,3 @@ let updateMessageWithGreyedOutButtons (ctx : IDiscordContext) interactiveMessage
builder.Content <- interactiveMessage.Message builder.Content <- interactiveMessage.Message
do! ctx.Respond(InteractionResponseType.UpdateMessage, builder) |> Async.AwaitTask do! ctx.Respond(InteractionResponseType.UpdateMessage, builder) |> Async.AwaitTask
} }
let handleResultWithResponse ctx fn (player : Result<PlayerData, string>) =
match player with
| Ok p -> fn p
| Error e -> async { do! sendFollowUpMessage ctx e }

View File

@ -53,6 +53,11 @@ let executePlayerActionWithTargetId defer (targetId : uint64) (ctx : IDiscordCon
| _ , None -> do! Messaging.sendFollowUpMessage ctx "Your target is not connected to the network, they must join first by using the /redpill command" | _ , None -> do! Messaging.sendFollowUpMessage ctx "Your target is not connected to the network, they must join first by using the /redpill command"
} |> Async.StartAsTask :> Task } |> Async.StartAsTask :> Task
let handleResultWithResponse ctx fn (player : Result<PlayerData, string>) =
match player with
| Ok p -> fn p
| Error e -> async { do! Messaging.sendFollowUpMessage ctx e }
module Commands = module Commands =
let newPlayer nickname (membr : uint64) = let newPlayer nickname (membr : uint64) =
let rand = System.Random(System.Guid.NewGuid().GetHashCode()) let rand = System.Random(System.Guid.NewGuid().GetHashCode())