Update events before updating the currency

This commit is contained in:
Joseph Ferano 2022-06-26 11:45:59 +07:00
parent fb9c638848
commit ff75ed15d0

View File

@ -90,7 +90,7 @@ let runHackerBattle defender (hack : HackItem) =
| _ -> false | _ -> false
| _ -> false) | _ -> false)
let updateCombatants successfulHack (attacker : PlayerData) (defender : PlayerData) (hack : HackItem) prize = let updateEvents successfulHack (attacker : PlayerData) (defender : PlayerData) (hack : HackItem) =
let event isDefenderEvent = let event isDefenderEvent =
let hackEvent = { let hackEvent = {
HackId = hack.Id HackId = hack.Id
@ -102,12 +102,16 @@ let updateCombatants successfulHack (attacker : PlayerData) (defender : PlayerDa
Timestamp = DateTime.UtcNow Timestamp = DateTime.UtcNow
Cooldown = if isDefenderEvent then int WeaponClass.SameTargetAttackCooldown.TotalMinutes * 1<mins> else hack.Cooldown } Cooldown = if isDefenderEvent then int WeaponClass.SameTargetAttackCooldown.TotalMinutes * 1<mins> else hack.Cooldown }
[ DbService.updatePlayerCurrency prize attacker.DiscordId [ DbService.addPlayerEvent attacker.DiscordId (event false)
DbService.updatePlayerCurrency -prize defender.DiscordId
DbService.addPlayerEvent attacker.DiscordId (event false)
DbService.addPlayerEvent defender.DiscordId (event true) ] DbService.addPlayerEvent defender.DiscordId (event true) ]
|> Async.Parallel |> Async.Parallel
|> Async.Ignore |> Async.Ignore
let updatePrizes (attacker : PlayerData) (defender : PlayerData) prize =
[ DbService.updatePlayerCurrency prize attacker.DiscordId
DbService.updatePlayerCurrency -prize defender.DiscordId ]
|> Async.Parallel
|> Async.Ignore
let hackerResult successfulHack (ctx : IDiscordContext) attacker defender (hack : HackItem) = let hackerResult successfulHack (ctx : IDiscordContext) attacker defender (hack : HackItem) =
async { async {
@ -121,6 +125,8 @@ let hackerResult successfulHack (ctx : IDiscordContext) attacker defender (hack
then gbt hack.Power , 0<GBT> then gbt hack.Power , 0<GBT>
else attacker.Bank , 0<GBT> else attacker.Bank , 0<GBT>
do! updateEvents successfulHack attacker defender hack
let! defenderMember = ctx.GetGuild().GetMemberAsync(defender.DiscordId) |> Async.AwaitTask let! defenderMember = ctx.GetGuild().GetMemberAsync(defender.DiscordId) |> Async.AwaitTask
// let failedMsg = $"Hack failed! {defender.Name} was able to mount a successful defense! You lost {lostAmount} 💰$GBT!" // let failedMsg = $"Hack failed! {defender.Name} was able to mount a successful defense! You lost {lostAmount} 💰$GBT!"
let embed = Embeds.responseSuccessfulHack2 successfulHack attacker defender (ctx.GetDiscordMember()) defenderMember prizeAmount bonus hack let embed = Embeds.responseSuccessfulHack2 successfulHack attacker defender (ctx.GetDiscordMember()) defenderMember prizeAmount bonus hack
@ -128,7 +134,7 @@ let hackerResult successfulHack (ctx : IDiscordContext) attacker defender (hack
|> Async.AwaitTask |> Async.AwaitTask
|> Async.Ignore |> Async.Ignore
do! updateCombatants successfulHack attacker defender hack prizeAmount do! updatePrizes attacker defender prizeAmount
let builder = DiscordMessageBuilder().WithAllowedMention(UserMention(defender.DiscordId)) let builder = DiscordMessageBuilder().WithAllowedMention(UserMention(defender.DiscordId))
if successfulHack then if successfulHack then