From 12ba17de3054f5333906a7fcc23bc0c97cc4ec28 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Thu, 3 Feb 2022 00:05:05 +0700 Subject: [PATCH] Print it nicer --- Bot/HackerBattle.fs | 17 ++++------------- Shared/Shared.fs | 14 +++++++------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Bot/HackerBattle.fs b/Bot/HackerBattle.fs index cdf7888..970377d 100644 --- a/Bot/HackerBattle.fs +++ b/Bot/HackerBattle.fs @@ -26,27 +26,18 @@ let checkForExistingTarget defenderId attacker = Error $"You can only hack the same target once every {Player.SameTargetAttackCooldown.Hours} hours, wait {cooldown} to attempt another hack on {target.Name}." | None -> Ok attacker -let checkHackForCooldown (hack : BattleItem) attacker = - attacker - |> Player.attacks - |> Array.tryFind (fun (act) -> act.ActionId = hack.Id) - |> function - | Some act -> - let cooldown = getTimeTillCooldownFinishes Player.SameTargetAttackCooldown act.Timestamp - Error $"{hack.Name} is currently on cooldown, wait {cooldown} to use it again." - | None -> Ok attacker - let checkIfHackHasCooldown hackId attacker = let mostRecentHackAttack = attacker.Actions |> Array.tryFind (fun a -> a.ActionId = hackId) |> function | Some a -> a.Timestamp - | None -> DateTime.MinValue; - if DateTime.UtcNow - mostRecentHackAttack > TimeSpan.FromMinutes(5) then + | None -> DateTime.MinValue + let item = Armory.getItem hackId + if DateTime.UtcNow - mostRecentHackAttack > TimeSpan.FromMinutes(int item.Cooldown) then Ok attacker else - let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(5)) mostRecentHackAttack + let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(int item.Cooldown)) mostRecentHackAttack let item = Armory.battleItems |> Array.find (fun i -> i.Id = hackId) Error $"{item.Name} is currently on cooldown, wait {cooldown} to use it again." diff --git a/Shared/Shared.fs b/Shared/Shared.fs index f559449..cf61b8e 100644 --- a/Shared/Shared.fs +++ b/Shared/Shared.fs @@ -117,13 +117,13 @@ module Messaging = } let getTimeTillCooldownFinishes (timespan : TimeSpan) timestamp = - let timeRemaining = timespan - (DateTime.UtcNow - timestamp) - if timeRemaining.Hours > 0 then - $"{timeRemaining.Hours} hours" - elif timeRemaining.Minutes > 0 then - $"{timeRemaining.Minutes} minutes" - else - $"{timeRemaining.Seconds} seconds" + let remaining = timespan - (DateTime.UtcNow - timestamp) + let plural amount = if amount = 1 then "" else "s" + let ``and`` = if remaining.Hours > 0 then "and " else "" + let hours = if remaining.Hours > 0 then $"{remaining.Hours} hour{plural remaining.Hours} {``and``}" else String.Empty + let totalMins = remaining.Minutes + 1 + let minutes = if totalMins > 0 then $"{totalMins} minute{plural totalMins}" else "1 minute" + $"{hours}{minutes}" let battleItemFormat (items : BattleItem array) = match items with