From 7526d8bd7ceb358bafe7c86cd21ebf5004151b59 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 15 Apr 2022 09:33:32 +0700 Subject: [PATCH] Filter out targets the player has hacked already --- Bot/DbService.fs | 2 +- Bot/Games/HackerBattle.fs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Bot/DbService.fs b/Bot/DbService.fs index 53b7655..12d0af4 100644 --- a/Bot/DbService.fs +++ b/Bot/DbService.fs @@ -246,7 +246,7 @@ let getRandomHackablePlayers (did : uint64) = JOIN user_achievements_achievement uaa ON "user".id = uaa.user_id JOIN achievement a ON uaa.achievement_id = a.id AND a.symbol = 'FINISHED_TRAINER' WHERE "user".in_game = true AND gbt > 20 AND "user".discord_id != @did - ORDER BY random() LIMIT 5 + ORDER BY random() LIMIT 10 """ |> Sql.executeAsync (fun read -> {| Id = read.string "discord_id" |> uint64 ; Name = read.string "display_name" |}) |> Async.AwaitTask diff --git a/Bot/Games/HackerBattle.fs b/Bot/Games/HackerBattle.fs index a16790a..1b8cf03 100644 --- a/Bot/Games/HackerBattle.fs +++ b/Bot/Games/HackerBattle.fs @@ -228,8 +228,16 @@ let handleDefense (ctx : IDiscordContext) = }) let scan (ctx : IDiscordContext) = - executePlayerAction ctx (fun _ -> async { + executePlayerAction ctx (fun player -> async { let! targets = DbService.getRandomHackablePlayers (ctx.GetDiscordMember().Id) + let targets = + let hackedIds = + player.Events + |> List.choose (fun e -> + match e.Type with | Hacking hack -> Some hack.Adversary.Id | _ -> None) + targets + |> List.filter (fun t -> hackedIds |> List.exists (fun hid -> hid = t.Id) |> not) + |> List.truncate 5 let sb = StringBuilder() let mutable count = 0 for t in targets do