Print it nicer

This commit is contained in:
Joseph Ferano 2022-02-03 00:05:05 +07:00
parent d6888d5e4a
commit 12ba17de30
2 changed files with 11 additions and 20 deletions

View File

@ -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}." 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 | 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 checkIfHackHasCooldown hackId attacker =
let mostRecentHackAttack = let mostRecentHackAttack =
attacker.Actions attacker.Actions
|> Array.tryFind (fun a -> a.ActionId = hackId) |> Array.tryFind (fun a -> a.ActionId = hackId)
|> function |> function
| Some a -> a.Timestamp | Some a -> a.Timestamp
| None -> DateTime.MinValue; | None -> DateTime.MinValue
if DateTime.UtcNow - mostRecentHackAttack > TimeSpan.FromMinutes(5) then let item = Armory.getItem hackId
if DateTime.UtcNow - mostRecentHackAttack > TimeSpan.FromMinutes(int item.Cooldown) then
Ok attacker Ok attacker
else 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) let item = Armory.battleItems |> Array.find (fun i -> i.Id = hackId)
Error $"{item.Name} is currently on cooldown, wait {cooldown} to use it again." Error $"{item.Name} is currently on cooldown, wait {cooldown} to use it again."

View File

@ -117,13 +117,13 @@ module Messaging =
} }
let getTimeTillCooldownFinishes (timespan : TimeSpan) timestamp = let getTimeTillCooldownFinishes (timespan : TimeSpan) timestamp =
let timeRemaining = timespan - (DateTime.UtcNow - timestamp) let remaining = timespan - (DateTime.UtcNow - timestamp)
if timeRemaining.Hours > 0 then let plural amount = if amount = 1 then "" else "s"
$"{timeRemaining.Hours} hours" let ``and`` = if remaining.Hours > 0 then "and " else ""
elif timeRemaining.Minutes > 0 then let hours = if remaining.Hours > 0 then $"{remaining.Hours} hour{plural remaining.Hours} {``and``}" else String.Empty
$"{timeRemaining.Minutes} minutes" let totalMins = remaining.Minutes + 1
else let minutes = if totalMins > 0 then $"{totalMins} minute{plural totalMins}" else "1 minute"
$"{timeRemaining.Seconds} seconds" $"{hours}{minutes}"
let battleItemFormat (items : BattleItem array) = let battleItemFormat (items : BattleItem array) =
match items with match items with