diff --git a/Bot/Games/HackerBattle.fs b/Bot/Games/HackerBattle.fs index 40895fa..cde79a1 100644 --- a/Bot/Games/HackerBattle.fs +++ b/Bot/Games/HackerBattle.fs @@ -69,7 +69,7 @@ let checkTargetHasFunds target player = | true -> Error $"Looks like the poor bastard has no $GBT... pick a different victim." | false -> Ok player -let checkTargetCompletedTraining target (player : PlayerData) = async { +let checkTargetIsNoob target (player : PlayerData) = async { let! targetCompletedTraining = DbService.checkHasAchievement target.DiscordId Trainer.TrainerAchievement if targetCompletedTraining || not target.Inventory.IsEmpty then return Ok player @@ -143,7 +143,7 @@ let failedHack (ctx : IDiscordContext) attacker defender (hack : HackItem) = let hack (target : DiscordUser) (ctx : IDiscordContext) = executePlayerActionWithTarget target ctx (fun attacker defender -> async { - let! result = checkTargetCompletedTraining defender attacker + let! result = checkTargetIsNoob defender attacker do! attacker |> Player.removeExpiredActions |> checkAlreadyHackedTarget defender @@ -307,6 +307,35 @@ let handleMessageCreated (_ : DiscordClient) (event : MessageCreateEventArgs) = do! event.Message.DeleteAsync() } :> Task +let BeginnerProtectionHours = 24 +let ShieldEvents () = [ + { Timestamp = System.DateTime.UtcNow + Cooldown = BeginnerProtectionHours * 60 + Type = Shielding (string ItemId.FIREWALL) } + { Timestamp = System.DateTime.UtcNow + Cooldown = BeginnerProtectionHours * 60 + Type = Shielding (string ItemId.ENCRYPTION) } + { Timestamp = System.DateTime.UtcNow + Cooldown = BeginnerProtectionHours * 60 + Type = Shielding (string ItemId.CYPHER) } +] + +let handleMemberUpdated (client : DiscordClient) (event : GuildMemberUpdateEventArgs) = + let addedRole (rolesBefore : DiscordRole seq) (rolesAfter : DiscordRole seq) = + rolesAfter |> Seq.filter ((fun role -> rolesBefore |> Seq.exists (fun r -> role.Id = r.Id)) >> not) + task { + let symmetricDifference = addedRole event.RolesBefore event.RolesAfter |> Seq.toList + match symmetricDifference with + | [] -> () + | role::_ -> + if role.Name = "Pregen" then + do! ShieldEvents () + |> List.map (DbService.addPlayerEvent event.Member.Id) + |> Async.Parallel + |> Async.Ignore + return () + } :> Task + type HackerGame() = inherit ApplicationCommandModule () diff --git a/Bot/Games/Trainer.fs b/Bot/Games/Trainer.fs index 45ab6b9..ccffa7b 100644 --- a/Bot/Games/Trainer.fs +++ b/Bot/Games/Trainer.fs @@ -13,7 +13,6 @@ let hackItem = Arsenal.weapons |> Inventory.findItemById (string ItemId.REMOTE) let shieldItem = Arsenal.weapons |> Inventory.findItemById (string ItemId.FIREWALL) let defaultHack = (Inventory.getHackItem hackItem).Value let defaultShield = (Inventory.getShieldItem shieldItem ).Value -let BeginnerProtectionHours = 24 let HackEvent () = { Timestamp = System.DateTime.UtcNow @@ -25,17 +24,12 @@ let HackEvent () = { HackId = defaultHack.Id } } -let ShieldEvents () = [ - { Timestamp = System.DateTime.UtcNow - Cooldown = BeginnerProtectionHours * 60 - Type = Shielding (string ItemId.FIREWALL) } - { Timestamp = System.DateTime.UtcNow - Cooldown = BeginnerProtectionHours * 60 - Type = Shielding (string ItemId.ENCRYPTION) } - { Timestamp = System.DateTime.UtcNow - Cooldown = BeginnerProtectionHours * 60 - Type = Shielding (string ItemId.CYPHER) } -] + +let ShieldEvent () = { + Timestamp = System.DateTime.UtcNow + Cooldown = defaultShield.Cooldown + Type = Shielding defaultShield.Id +} let sendInitialEmbed (ctx : IDiscordContext) = async { @@ -169,9 +163,6 @@ Here, I'm going to gift you: 1. A hack - `{defaultHack.Name}`, 2. A shield - `{defaultShield.Name}`, -I'm also going to give you some **TEMPORARY SHIELDS** until you buy your own. -They will **ONLY** protect you from hacks for **{BeginnerProtectionHours} hrs**... - To finish your training and collect all your **GIFTS**, type the `/arsenal` command NOW""" @@ -201,14 +192,6 @@ let handleArsenal (ctx : IDiscordContext) = PlayerInteractions.executePlayerActi do! DbService.addToPlayerInventory player.DiscordId hackItem |> Async.Ignore if player.Inventory |> List.exists (fun i -> i.Id = shieldItem.Id) |> not then do! DbService.addToPlayerInventory player.DiscordId shieldItem |> Async.Ignore - try - do! ShieldEvents () @ [ HackEvent () ] - |> List.map (DbService.addPlayerEvent player.DiscordId) - |> Async.Parallel - |> Async.Ignore - with ex -> - printfn "%s" ex.Message - () let updatedPlayer = { player with @@ -216,9 +199,8 @@ let handleArsenal (ctx : IDiscordContext) = PlayerInteractions.executePlayerActi player |> Player.removeExpiredActions |> fun p -> p.Events - |> List.filter (fun e -> match e.Type with Shielding _ -> false | _ -> true) - |> List.append (ShieldEvents()) - |> List.consTo (HackEvent()) + |> List.filter (fun e -> match e.Type with Shielding shieldId -> shieldId <> defaultShield.Id | _ -> true) + |> (@) [ HackEvent() ; ShieldEvent() ] Inventory = player.Inventory |> addIfDoesntExist hackItem diff --git a/Bot/Prelude.fs b/Bot/Prelude.fs index 329a920..e224ddf 100644 --- a/Bot/Prelude.fs +++ b/Bot/Prelude.fs @@ -5,8 +5,8 @@ module ResultHelpers = let (>>=) x f = Result.bind f x let () x f = Result.map f x -[] [] +[] module List = let cons xs x = x :: xs let consTo x xs = x :: xs