Just read the stats from the user table. Remove dbconnectione everywhere
This commit is contained in:
parent
53f60bcf86
commit
05cdb98bee
@ -4,27 +4,23 @@ open System
|
|||||||
open Npgsql.FSharp
|
open Npgsql.FSharp
|
||||||
open Degenz
|
open Degenz
|
||||||
|
|
||||||
|
let connStr = GuildEnvironment.connectionString
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
Name : string
|
Name : string
|
||||||
DiscordId : uint64
|
DiscordId : uint64
|
||||||
Bank : int<GBT>
|
Bank : int<GBT>
|
||||||
Strength : int
|
|
||||||
Inventory : int list
|
Inventory : int list
|
||||||
|
Strength : int
|
||||||
|
Focus : int
|
||||||
|
Charisma : int
|
||||||
|
Luck : int
|
||||||
}
|
}
|
||||||
|
|
||||||
let mapBack user : PlayerData =
|
let getPlayerEvents (did : uint64) =
|
||||||
{ DiscordId = user.DiscordId
|
|
||||||
Name = user.Name
|
|
||||||
Inventory = user.Inventory |> List.choose (fun id -> Armory.weapons |> List.tryFind (fun item -> item.Id = id))
|
|
||||||
Events = [||]
|
|
||||||
Stats = { Stats.empty with Strength = { Id = StatId.Strength ; ModMinMax = Range(0, 100) ; Amount = user.Strength; LastRead = DateTime.UtcNow } }
|
|
||||||
Bank = user.Bank
|
|
||||||
}
|
|
||||||
|
|
||||||
let getPlayerEvents connStr (player : PlayerData) =
|
|
||||||
connStr
|
connStr
|
||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters [ "did", Sql.string (string player.DiscordId) ]
|
|> Sql.parameters [ "did", Sql.string (string did) ]
|
||||||
|> Sql.query """
|
|> Sql.query """
|
||||||
WITH usr AS (SELECT id FROM "user" WHERE discord_id = @did)
|
WITH usr AS (SELECT id FROM "user" WHERE discord_id = @did)
|
||||||
SELECT event_type, success, is_instigator, item_id, cooldown, adversary_id, adversary_name, created_at
|
SELECT event_type, success, is_instigator, item_id, cooldown, adversary_id, adversary_name, created_at
|
||||||
@ -48,8 +44,25 @@ let getPlayerEvents connStr (player : PlayerData) =
|
|||||||
)
|
)
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
|
||||||
let tryFindPlayer connStr (discordId : uint64) =
|
let updatePlayerStats (player : PlayerData) =
|
||||||
async {
|
connStr
|
||||||
|
|> Sql.connect
|
||||||
|
|> Sql.parameters
|
||||||
|
[ ( "did" , Sql.string (string player.DiscordId) )
|
||||||
|
( "strength", Sql.int player.Stats.Strength.Amount )
|
||||||
|
( "focus", Sql.int player.Stats.Focus.Amount )
|
||||||
|
( "charisma", Sql.int player.Stats.Charisma.Amount )
|
||||||
|
( "luck", Sql.int player.Stats.Luck.Amount ) ]
|
||||||
|
|> Sql.query """
|
||||||
|
WITH usr AS (SELECT id FROM "user" WHERE discord_id = @did)
|
||||||
|
UPDATE player_stat SET strength = @strength, focus = @focus, charisma = @charisma, luck = @luck,
|
||||||
|
updated_at = now() at time zone 'utc'
|
||||||
|
FROM usr WHERE usr.id = user_id;
|
||||||
|
"""
|
||||||
|
|> Sql.executeNonQueryAsync
|
||||||
|
|> Async.AwaitTask
|
||||||
|
|
||||||
|
let tryFindPlayer (discordId : uint64) = async {
|
||||||
try
|
try
|
||||||
let! user =
|
let! user =
|
||||||
// use cert = new X509Certificate2("~/Downloads/ca-certificate.crt")
|
// use cert = new X509Certificate2("~/Downloads/ca-certificate.crt")
|
||||||
@ -62,45 +75,61 @@ let tryFindPlayer connStr (discordId : uint64) =
|
|||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters [ "did", Sql.string (string discordId) ]
|
|> Sql.parameters [ "did", Sql.string (string discordId) ]
|
||||||
|> Sql.query """
|
|> Sql.query """
|
||||||
SELECT discord_id, display_name, gbt, strength, inventory FROM "user" WHERE discord_id = @did
|
SELECT discord_id, display_name, gbt, inventory, strength, focus, charisma, luck FROM "user"
|
||||||
|
WHERE discord_id = @did
|
||||||
"""
|
"""
|
||||||
|> Sql.executeAsync (fun read ->
|
|> Sql.executeAsync (fun read -> {
|
||||||
{
|
|
||||||
DiscordId = read.string "discord_id" |> uint64
|
DiscordId = read.string "discord_id" |> uint64
|
||||||
Name = read.string "display_name"
|
Name = read.string "display_name"
|
||||||
Bank = read.int "gbt" * 1<GBT>
|
Bank = read.int "gbt" * 1<GBT>
|
||||||
Strength = read.int "strength"
|
|
||||||
Inventory = read.intArray "inventory" |> Array.toList
|
Inventory = read.intArray "inventory" |> Array.toList
|
||||||
|
Strength = read.int "strength"
|
||||||
|
Focus = read.int "focus"
|
||||||
|
Charisma = read.int "charm"
|
||||||
|
Luck = read.int "luck"
|
||||||
})
|
})
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
match List.tryHead user with
|
match List.tryHead user with
|
||||||
| None -> return None
|
| None -> return None
|
||||||
| Some u ->
|
| Some u ->
|
||||||
let player = mapBack u
|
let! events = getPlayerEvents u.DiscordId
|
||||||
let! events = getPlayerEvents connStr player
|
let inventory = u.Inventory |> List.choose (fun id -> Armory.weapons |> List.tryFind (fun item -> item.Id = id))
|
||||||
return Some { player with Events = events |> List.toArray }
|
let strength = PlayerStats.calculateActiveStat StatId.Strength u.Strength inventory
|
||||||
|
let focus = PlayerStats.calculateActiveStat StatId.Focus u.Focus inventory
|
||||||
|
let charisma = PlayerStats.calculateActiveStat StatId.Charisma u.Charisma inventory
|
||||||
|
let luck = PlayerStats.calculateActiveStat StatId.Luck u.Luck inventory
|
||||||
|
return Some
|
||||||
|
{ DiscordId = u.DiscordId
|
||||||
|
Name = u.Name
|
||||||
|
Inventory = inventory
|
||||||
|
Events = events
|
||||||
|
Stats = { Strength = strength ; Focus = focus ; Charisma = charisma ; Luck = luck }
|
||||||
|
Bank = u.Bank }
|
||||||
with e ->
|
with e ->
|
||||||
printfn $"Got an error{e.Message}"
|
printfn $"Got an error{e.Message}"
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
let updatePlayer connStr (player : PlayerData) =
|
let updatePlayer (player : PlayerData) =
|
||||||
connStr
|
connStr
|
||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters [
|
|> Sql.parameters [
|
||||||
"did", Sql.string (string player.DiscordId)
|
"did", Sql.string (string player.DiscordId)
|
||||||
"gbt", Sql.int (int player.Bank)
|
"gbt", Sql.int (int player.Bank)
|
||||||
"str", Sql.int (player.Stats.Strength.Amount |> int)
|
|
||||||
"inv", Sql.intArray (player.Inventory |> Array.ofList |> Array.map (fun item -> item.Id))
|
"inv", Sql.intArray (player.Inventory |> Array.ofList |> Array.map (fun item -> item.Id))
|
||||||
]
|
"strength", Sql.int player.Stats.Strength.Amount
|
||||||
|> Sql.query """
|
"focus", Sql.int player.Stats.Focus.Amount
|
||||||
UPDATE "user" SET gbt = @gbt, strength = @str, inventory = @inv
|
"charisma", Sql.int player.Stats.Charisma.Amount
|
||||||
|
"luck", Sql.int player.Stats.Luck.Amount
|
||||||
|
] |> Sql.query """
|
||||||
|
UPDATE "user" SET gbt = @gbt, inventory = @inv,
|
||||||
|
strength = @strength, focus = @focus, charisma = @charisma, luck = @luck
|
||||||
WHERE discord_id = @did
|
WHERE discord_id = @did
|
||||||
"""
|
"""
|
||||||
|> Sql.executeNonQueryAsync
|
|> Sql.executeNonQueryAsync
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
|
||||||
let addAchievement connStr (did : uint64) (achievement : string) =
|
let addAchievement (did : uint64) (achievement : string) =
|
||||||
connStr
|
connStr
|
||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters
|
|> Sql.parameters
|
||||||
@ -114,7 +143,7 @@ let addAchievement connStr (did : uint64) (achievement : string) =
|
|||||||
|> Sql.executeNonQueryAsync
|
|> Sql.executeNonQueryAsync
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
|
||||||
let checkHasAchievement connStr (did : uint64) (achievement : string) = async {
|
let checkHasAchievement (did : uint64) (achievement : string) = async {
|
||||||
let! result =
|
let! result =
|
||||||
connStr
|
connStr
|
||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
@ -131,7 +160,7 @@ let checkHasAchievement connStr (did : uint64) (achievement : string) = async {
|
|||||||
return List.isEmpty result |> not
|
return List.isEmpty result |> not
|
||||||
}
|
}
|
||||||
|
|
||||||
let removeShieldEvent connStr (did : uint64) shieldId =
|
let removeShieldEvent (did : uint64) shieldId =
|
||||||
connStr
|
connStr
|
||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters
|
|> Sql.parameters
|
||||||
@ -144,7 +173,7 @@ let removeShieldEvent connStr (did : uint64) shieldId =
|
|||||||
|> Sql.executeNonQueryAsync
|
|> Sql.executeNonQueryAsync
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
|
||||||
let addPlayerEvent connStr (did : uint64) (playerEvent : PlayerEvent) =
|
let addPlayerEvent (did : uint64) (playerEvent : PlayerEvent) =
|
||||||
let sqlParams , query =
|
let sqlParams , query =
|
||||||
match playerEvent.Type with
|
match playerEvent.Type with
|
||||||
| Hacking h ->
|
| Hacking h ->
|
||||||
|
@ -91,15 +91,15 @@ module WeaponClass =
|
|||||||
module Player =
|
module Player =
|
||||||
let getHackEvents player =
|
let getHackEvents player =
|
||||||
player.Events
|
player.Events
|
||||||
|> Array.filter (fun act -> match act.Type with PlayerEventType.Hacking h -> h.IsInstigator | _ -> false)
|
|> List.filter (fun act -> match act.Type with PlayerEventType.Hacking h -> h.IsInstigator | _ -> false)
|
||||||
let getShieldEvents player =
|
let getShieldEvents player =
|
||||||
player.Events
|
player.Events
|
||||||
|> Array.filter (fun act -> match act.Type with PlayerEventType.Shielding _ -> true | _ -> false)
|
|> List.filter (fun act -> match act.Type with PlayerEventType.Shielding _ -> true | _ -> false)
|
||||||
|
|
||||||
let removeExpiredActions player =
|
let removeExpiredActions player =
|
||||||
let actions =
|
let actions =
|
||||||
player.Events
|
player.Events
|
||||||
|> Array.filter (fun (act : PlayerEvent) ->
|
|> List.filter (fun (act : PlayerEvent) ->
|
||||||
let cooldown = System.TimeSpan.FromMinutes(int act.Cooldown)
|
let cooldown = System.TimeSpan.FromMinutes(int act.Cooldown)
|
||||||
System.DateTime.UtcNow - act.Timestamp < cooldown)
|
System.DateTime.UtcNow - act.Timestamp < cooldown)
|
||||||
{ player with Events = actions }
|
{ player with Events = actions }
|
||||||
@ -108,24 +108,23 @@ module Player =
|
|||||||
|
|
||||||
module PlayerStats =
|
module PlayerStats =
|
||||||
// 4.17f would go from 100 to 0 in roughly 24 hours
|
// 4.17f would go from 100 to 0 in roughly 24 hours
|
||||||
let Strength = { Id = StatId.Strength ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
|
let Strength = { Id = StatId.Strength ; BaseDecayRate = 4.17 ; BaseRange = Range.normalized }
|
||||||
let Focus = { Id = StatId.Focus ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
|
let Focus = { Id = StatId.Focus ; BaseDecayRate = 4.17 ; BaseRange = Range.normalized }
|
||||||
let Luck = { Id = StatId.Luck ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
|
let Luck = { Id = StatId.Luck ; BaseDecayRate = 4.17 ; BaseRange = Range.normalized }
|
||||||
let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
|
let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 4.17 ; BaseRange = Range.normalized }
|
||||||
|
|
||||||
let stats = [ Strength ; Focus ; Luck ; Charisma ]
|
let stats = [ Strength ; Focus ; Luck ; Charisma ]
|
||||||
|
|
||||||
let calculateStatDecay (stat : PlayerStat) =
|
let calculateActiveStat statId amount items =
|
||||||
let statConfig = stats |> List.find (fun s -> s.Id = stat.Id)
|
let statConfig = stats |> List.find (fun s -> s.Id = statId)
|
||||||
let hoursElapsed = (DateTime.UtcNow - stat.LastRead).Hours
|
// let hoursElapsed = (DateTime.UtcNow - lastRead).Hours
|
||||||
let totalDecay = float hoursElapsed * statConfig.BaseDecayRate
|
// let totalDecay = float hoursElapsed * statConfig.BaseDecayRate
|
||||||
{ stat with Amount = max stat.ModMinMax.Start.Value (stat.Amount - int totalDecay) ; LastRead = DateTime.UtcNow }
|
let modMinMax =
|
||||||
|
let min = items |> List.sumBy (fun item -> match item.Type with | Accessory(_,floorBoost,_) -> floorBoost | _ -> 0)
|
||||||
let statConsumableMap =
|
let max = items |> List.sumBy (fun item -> match item.Type with | Accessory(_,_,ceilBoost) -> ceilBoost | _ -> 0)
|
||||||
[ ( StatId.Strength , 12 )
|
Range.create (statConfig.BaseRange.Min + min) (statConfig.BaseRange.Max + max)
|
||||||
( StatId.Focus , 13 )
|
let amountAfterDecay = modMinMax |> Range.constrain amount
|
||||||
( StatId.Luck , 14 )
|
{ Id = statId ; Amount = amountAfterDecay ; ModRange = modMinMax ; LastRead = DateTime.UtcNow }
|
||||||
( StatId.Charisma , 15 ) ]
|
|
||||||
|
|
||||||
module Arsenal =
|
module Arsenal =
|
||||||
let battleItemFormat (items : Item list) =
|
let battleItemFormat (items : Item list) =
|
||||||
@ -133,12 +132,12 @@ module Arsenal =
|
|||||||
| [] -> "None"
|
| [] -> "None"
|
||||||
| _ -> items |> List.map (fun item -> item.Name) |> String.concat ", "
|
| _ -> items |> List.map (fun item -> item.Name) |> String.concat ", "
|
||||||
|
|
||||||
let actionFormat (actions : PlayerEvent array) =
|
let actionFormat (actions : PlayerEvent List) =
|
||||||
match actions with
|
match actions with
|
||||||
| [||] -> "None"
|
| [] -> "None"
|
||||||
| acts ->
|
| acts ->
|
||||||
acts
|
acts
|
||||||
|> Array.map (fun act ->
|
|> List.map (fun act ->
|
||||||
match act.Type with
|
match act.Type with
|
||||||
| Hacking h ->
|
| Hacking h ->
|
||||||
let item = Armory.weapons |> Inventory.findHackById h.HackId
|
let item = Armory.weapons |> Inventory.findHackById h.HackId
|
||||||
@ -149,12 +148,12 @@ module Arsenal =
|
|||||||
let cooldown = Messaging.getTimeText true (System.TimeSpan.FromMinutes(int act.Cooldown)) act.Timestamp
|
let cooldown = Messaging.getTimeText true (System.TimeSpan.FromMinutes(int act.Cooldown)) act.Timestamp
|
||||||
$"{item.Name} Shield active for {cooldown}"
|
$"{item.Name} Shield active for {cooldown}"
|
||||||
| _ -> "")
|
| _ -> "")
|
||||||
|> Array.filter (System.String.IsNullOrWhiteSpace >> not)
|
|> List.filter (System.String.IsNullOrWhiteSpace >> not)
|
||||||
|> String.concat "\n"
|
|> String.concat "\n"
|
||||||
|
|
||||||
let statusFormat p =
|
let statusFormat p =
|
||||||
let hacks = Player.getHackEvents p
|
let hacks = Player.getHackEvents p
|
||||||
$"**Hacks:** {Inventory.filterByHacks p.Inventory |> battleItemFormat}\n
|
$"**Hacks:** {Inventory.filterByHacks p.Inventory |> battleItemFormat}\n
|
||||||
**Shields:** {Inventory.filterByShields p.Inventory |> battleItemFormat}\n
|
**Shields:** {Inventory.filterByShields p.Inventory |> battleItemFormat}\n
|
||||||
**Hack Attacks:**\n{ hacks |> Array.take (min hacks.Length 10) |> actionFormat}\n
|
**Hack Attacks:**\n{ hacks |> List.take (min hacks.Length 10) |> actionFormat}\n
|
||||||
**Active Shields:**\n{Player.getShieldEvents p |> actionFormat}"
|
**Active Shields:**\n{Player.getShieldEvents p |> actionFormat}"
|
||||||
|
@ -10,6 +10,13 @@ type mins
|
|||||||
[<Measure>]
|
[<Measure>]
|
||||||
type GBT
|
type GBT
|
||||||
|
|
||||||
|
type Range = { Min : int ; Max : int }
|
||||||
|
|
||||||
|
module Range =
|
||||||
|
let normalized = { Min = 0 ; Max = 100 }
|
||||||
|
let create min max = { Min = min ; Max = max }
|
||||||
|
let constrain value range = if value < range.Min then range.Min elif value > range.Max then range.Max else value
|
||||||
|
|
||||||
type ItemId =
|
type ItemId =
|
||||||
| Virus = 0
|
| Virus = 0
|
||||||
| RemoteAccess = 1
|
| RemoteAccess = 1
|
||||||
@ -27,16 +34,16 @@ type StatId =
|
|||||||
type StatConfig = {
|
type StatConfig = {
|
||||||
Id : StatId
|
Id : StatId
|
||||||
BaseDecayRate : float
|
BaseDecayRate : float
|
||||||
BaseMinMax : Range
|
BaseRange : Range
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlayerStat = {
|
type PlayerStat = {
|
||||||
Id : StatId
|
Id : StatId
|
||||||
Amount : int
|
Amount : int
|
||||||
ModMinMax : Range
|
ModRange : Range
|
||||||
LastRead : DateTime
|
LastRead : DateTime
|
||||||
}
|
}
|
||||||
with static member empty = { Id = StatId.Strength ; Amount = 0 ; ModMinMax = Range(0, 100) ; LastRead = DateTime.UtcNow}
|
with static member empty = { Id = StatId.Strength ; Amount = 0 ; ModRange = Range.normalized ; LastRead = DateTime.UtcNow}
|
||||||
|
|
||||||
type Stats = {
|
type Stats = {
|
||||||
Strength : PlayerStat
|
Strength : PlayerStat
|
||||||
@ -101,14 +108,15 @@ type AccessoryItem = {
|
|||||||
Name : string
|
Name : string
|
||||||
Price : int<GBT>
|
Price : int<GBT>
|
||||||
TargetStat : StatId
|
TargetStat : StatId
|
||||||
PassiveBoost : int
|
FloorBoost : int
|
||||||
|
CeilBoost : int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemType =
|
type ItemType =
|
||||||
| Hack of power : int * hackClass : int * cooldown : int<mins>
|
| Hack of power : int * hackClass : int * cooldown : int<mins>
|
||||||
| Shield of shieldClass : int * cooldown : int<mins>
|
| Shield of shieldClass : int * cooldown : int<mins>
|
||||||
| Food of targetStat : StatId * boostAmount : int
|
| Food of targetStat : StatId * boostAmount : int
|
||||||
| Accessory of targetStat : StatId * passiveBoost : int
|
| Accessory of targetStat : StatId * floorBoost : int * ceilBoost : int
|
||||||
and Item = {
|
and Item = {
|
||||||
Id : int
|
Id : int
|
||||||
Name : string
|
Name : string
|
||||||
@ -120,18 +128,18 @@ and PlayerData = {
|
|||||||
DiscordId : uint64
|
DiscordId : uint64
|
||||||
Name : string
|
Name : string
|
||||||
Inventory : Inventory
|
Inventory : Inventory
|
||||||
Events : PlayerEvent array
|
Events : PlayerEvent list
|
||||||
Stats : Stats
|
Stats : Stats
|
||||||
Bank : int<GBT>
|
Bank : int<GBT>
|
||||||
}
|
}
|
||||||
// Achievements : string array
|
// Achievements : string array
|
||||||
// XP : int
|
// XP : int
|
||||||
with member this.basicPlayer = { Id = this.DiscordId ; Name = this.Name }
|
with member this.toDiscordPlayer = { Id = this.DiscordId ; Name = this.Name }
|
||||||
static member empty =
|
static member empty =
|
||||||
{ DiscordId = 0uL
|
{ DiscordId = 0uL
|
||||||
Name = "None"
|
Name = "None"
|
||||||
Inventory = []
|
Inventory = []
|
||||||
Events = [||]
|
Events = []
|
||||||
Stats = Stats.empty
|
Stats = Stats.empty
|
||||||
// Achievements = [||]
|
// Achievements = [||]
|
||||||
// XP = 0
|
// XP = 0
|
||||||
|
@ -85,7 +85,7 @@ let updateCombatants successfulHack (attacker : PlayerData) (defender : PlayerDa
|
|||||||
let event isDefenderEvent =
|
let event isDefenderEvent =
|
||||||
let hackEvent = {
|
let hackEvent = {
|
||||||
HackId = hack.Id
|
HackId = hack.Id
|
||||||
Adversary = if isDefenderEvent then attacker.basicPlayer else defender.basicPlayer
|
Adversary = if isDefenderEvent then attacker.toDiscordPlayer else defender.toDiscordPlayer
|
||||||
IsInstigator = not isDefenderEvent
|
IsInstigator = not isDefenderEvent
|
||||||
Success = successfulHack
|
Success = successfulHack
|
||||||
}
|
}
|
||||||
@ -93,10 +93,10 @@ 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.updatePlayer GuildEnvironment.pgDb <| updatePlayer prize (event false) attacker
|
[ DbService.updatePlayer <| updatePlayer prize (event false) attacker
|
||||||
DbService.updatePlayer GuildEnvironment.pgDb <| updatePlayer -prize (event true) defender
|
DbService.updatePlayer <| updatePlayer -prize (event true) defender
|
||||||
DbService.addPlayerEvent GuildEnvironment.pgDb attacker.DiscordId (event false)
|
DbService.addPlayerEvent attacker.DiscordId (event false)
|
||||||
DbService.addPlayerEvent GuildEnvironment.pgDb defender.DiscordId (event true) ]
|
DbService.addPlayerEvent defender.DiscordId (event true) ]
|
||||||
|> Async.Parallel
|
|> Async.Parallel
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ let handleAttack (ctx : IDiscordContext) =
|
|||||||
let hack = Armory.weapons |> Inventory.findHackById hackId
|
let hack = Armory.weapons |> Inventory.findHackById hackId
|
||||||
let hackAsItem = Inventory.hackToItem hack
|
let hackAsItem = Inventory.hackToItem hack
|
||||||
let resultId , targetId = UInt64.TryParse tokens.[2]
|
let resultId , targetId = UInt64.TryParse tokens.[2]
|
||||||
let! resultTarget = DbService.tryFindPlayer GuildEnvironment.pgDb targetId
|
let! resultTarget = DbService.tryFindPlayer targetId
|
||||||
|
|
||||||
match resultTarget , true , resultId with
|
match resultTarget , true , resultId with
|
||||||
| Some defender , true , true ->
|
| Some defender , true , true ->
|
||||||
@ -202,9 +202,9 @@ let handleDefense (ctx : IDiscordContext) =
|
|||||||
Cooldown = shield.Cooldown
|
Cooldown = shield.Cooldown
|
||||||
Timestamp = DateTime.UtcNow
|
Timestamp = DateTime.UtcNow
|
||||||
}
|
}
|
||||||
do! DbService.updatePlayer GuildEnvironment.pgDb p
|
do! DbService.updatePlayer p
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
do! DbService.addPlayerEvent GuildEnvironment.pgDb p.DiscordId defense
|
do! DbService.addPlayerEvent p.DiscordId defense
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
let builder = DiscordMessageBuilder()
|
let builder = DiscordMessageBuilder()
|
||||||
builder.WithContent($"{ctx.GetDiscordMember().Username} has protected their system!") |> ignore
|
builder.WithContent($"{ctx.GetDiscordMember().Username} has protected their system!") |> ignore
|
||||||
@ -224,7 +224,7 @@ let arsenal (ctx : IDiscordContext) =
|
|||||||
builder.AddEmbed(embed) |> ignore
|
builder.AddEmbed(embed) |> ignore
|
||||||
builder.IsEphemeral <- true
|
builder.IsEphemeral <- true
|
||||||
do! ctx.FollowUp(builder) |> Async.AwaitTask
|
do! ctx.FollowUp(builder) |> Async.AwaitTask
|
||||||
do! DbService.updatePlayer GuildEnvironment.pgDb updatedPlayer
|
do! DbService.updatePlayer updatedPlayer
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -23,10 +23,10 @@ type SlotMachine() =
|
|||||||
|| (results.[0] <> results.[1] && results.[1] <> results.[2] && results.[0] <> results.[2])
|
|| (results.[0] <> results.[1] && results.[1] <> results.[2] && results.[0] <> results.[2])
|
||||||
|
|
||||||
if winConditions then
|
if winConditions then
|
||||||
do! DbService.updatePlayer GuildEnvironment.pgDb { player with Bank = player.Bank + 10<GBT> }
|
do! DbService.updatePlayer { player with Bank = player.Bank + 10<GBT> }
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
else
|
else
|
||||||
do! DbService.updatePlayer GuildEnvironment.pgDb { player with Bank = max (player.Bank - 1<GBT>) 0<GBT> }
|
do! DbService.updatePlayer { player with Bank = max (player.Bank - 1<GBT>) 0<GBT> }
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ let handleBuyItem (ctx : IDiscordContext) itemId =
|
|||||||
|> handleResultWithResponse ctx (fun player -> async {
|
|> handleResultWithResponse ctx (fun player -> async {
|
||||||
let newBalance = player.Bank - item.Price
|
let newBalance = player.Bank - item.Price
|
||||||
let p = { player with Bank = newBalance ; Inventory = item::player.Inventory }
|
let p = { player with Bank = newBalance ; Inventory = item::player.Inventory }
|
||||||
do! DbService.updatePlayer GuildEnvironment.pgDb p |> Async.Ignore
|
do! DbService.updatePlayer p |> Async.Ignore
|
||||||
do! sendFollowUpMessage ctx $"Successfully purchased {item.Name}! You now have {newBalance} 💰$GBT remaining"
|
do! sendFollowUpMessage ctx $"Successfully purchased {item.Name}! You now have {newBalance} 💰$GBT remaining"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -125,8 +125,8 @@ let handleSell (ctx : IDiscordContext) itemId =
|
|||||||
Inventory = player.Inventory |> List.filter (fun i -> i.Id <> itemId)
|
Inventory = player.Inventory |> List.filter (fun i -> i.Id <> itemId)
|
||||||
}
|
}
|
||||||
do!
|
do!
|
||||||
[ DbService.updatePlayer GuildEnvironment.pgDb updatedPlayer |> Async.Ignore
|
[ DbService.updatePlayer updatedPlayer |> Async.Ignore
|
||||||
DbService.removeShieldEvent GuildEnvironment.pgDb updatedPlayer.DiscordId itemId |> Async.Ignore
|
DbService.removeShieldEvent updatedPlayer.DiscordId itemId |> Async.Ignore
|
||||||
sendFollowUpMessage ctx $"Sold {item.Type} {item.Name} for {item.Price}! Current Balance: {updatedPlayer.Bank}" ]
|
sendFollowUpMessage ctx $"Sold {item.Type} {item.Name} for {item.Price}! Current Balance: {updatedPlayer.Bank}" ]
|
||||||
|> Async.Parallel
|
|> Async.Parallel
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
|
@ -175,15 +175,15 @@ let handleSteal (ctx : IDiscordContext) =
|
|||||||
| true ->
|
| true ->
|
||||||
let embed = getResultEmbed' Success
|
let embed = getResultEmbed' Success
|
||||||
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
||||||
match! DbService.tryFindPlayer GuildEnvironment.pgDb targetId with
|
match! DbService.tryFindPlayer targetId with
|
||||||
| Some t ->
|
| Some t ->
|
||||||
let mugged = {
|
let mugged = {
|
||||||
Type = Stealing ( false , thief.basicPlayer )
|
Type = Stealing ( false , thief.toDiscordPlayer )
|
||||||
Timestamp = DateTime.UtcNow
|
Timestamp = DateTime.UtcNow
|
||||||
Cooldown = VictimRecovery.Minutes * 1<mins>
|
Cooldown = VictimRecovery.Minutes * 1<mins>
|
||||||
}
|
}
|
||||||
do! DbService.updatePlayer GuildEnvironment.pgDb { t with Bank = max (t.Bank - prize) 0<GBT> } |> Async.Ignore
|
do! DbService.updatePlayer { t with Bank = max (t.Bank - prize) 0<GBT> } |> Async.Ignore
|
||||||
do! DbService.addPlayerEvent GuildEnvironment.pgDb victim.DiscordId mugged |> Async.Ignore
|
do! DbService.addPlayerEvent victim.DiscordId mugged |> Async.Ignore
|
||||||
| None -> ()
|
| None -> ()
|
||||||
|
|
||||||
let stole = {
|
let stole = {
|
||||||
@ -191,8 +191,8 @@ let handleSteal (ctx : IDiscordContext) =
|
|||||||
Cooldown = ThiefCooldown.Minutes * 1<mins>
|
Cooldown = ThiefCooldown.Minutes * 1<mins>
|
||||||
Timestamp = DateTime.UtcNow
|
Timestamp = DateTime.UtcNow
|
||||||
}
|
}
|
||||||
do! DbService.updatePlayer GuildEnvironment.pgDb { thief with Bank = thief.Bank + prize } |> Async.Ignore
|
do! DbService.updatePlayer { thief with Bank = thief.Bank + prize } |> Async.Ignore
|
||||||
do! DbService.addPlayerEvent GuildEnvironment.pgDb victim.DiscordId stole |> Async.Ignore
|
do! DbService.addPlayerEvent victim.DiscordId stole |> Async.Ignore
|
||||||
let builder = DiscordMessageBuilder()
|
let builder = DiscordMessageBuilder()
|
||||||
builder.WithContent($"{thief.Name} stole {prize} from <@{victim.DiscordId}>!") |> ignore
|
builder.WithContent($"{thief.Name} stole {prize} from <@{victim.DiscordId}>!") |> ignore
|
||||||
let channel = ctx.GetGuild().GetChannel(GuildEnvironment.channelEventsHackerBattle)
|
let channel = ctx.GetGuild().GetChannel(GuildEnvironment.channelEventsHackerBattle)
|
||||||
@ -206,7 +206,7 @@ let handleSteal (ctx : IDiscordContext) =
|
|||||||
Cooldown = ThiefCooldown.Minutes * 1<mins>
|
Cooldown = ThiefCooldown.Minutes * 1<mins>
|
||||||
Timestamp = DateTime.UtcNow
|
Timestamp = DateTime.UtcNow
|
||||||
}
|
}
|
||||||
do! DbService.addPlayerEvent GuildEnvironment.pgDb victim.DiscordId imprisoned |> Async.Ignore
|
do! DbService.addPlayerEvent victim.DiscordId imprisoned |> Async.Ignore
|
||||||
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
||||||
do! Async.Sleep 2000
|
do! Async.Sleep 2000
|
||||||
let role = ctx.GetGuild().GetRole(GuildEnvironment.rolePrisoner)
|
let role = ctx.GetGuild().GetRole(GuildEnvironment.rolePrisoner)
|
||||||
|
@ -146,9 +146,9 @@ let handleHack (ctx : IDiscordContext) =
|
|||||||
|
|
||||||
let sb = StringBuilder("Here, ")
|
let sb = StringBuilder("Here, ")
|
||||||
|
|
||||||
let! completed = DbService.checkHasAchievement GuildEnvironment.pgDb player.DiscordId trainerAchievement
|
let! completed = DbService.checkHasAchievement player.DiscordId trainerAchievement
|
||||||
if not completed then
|
if not completed then
|
||||||
do! DbService.addAchievement GuildEnvironment.pgDb player.DiscordId trainerAchievement
|
do! DbService.addAchievement player.DiscordId trainerAchievement
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
|
|
||||||
sb.Append($"I'm going to gift you a hack,`{defaultHack.Name}` and a shield, `{defaultShield.Name}`") |> ignore
|
sb.Append($"I'm going to gift you a hack,`{defaultHack.Name}` and a shield, `{defaultShield.Name}`") |> ignore
|
||||||
@ -180,15 +180,15 @@ let handleArsenal (ctx : IDiscordContext) =
|
|||||||
Player.removeExpiredActions player
|
Player.removeExpiredActions player
|
||||||
if not hasStockWeapons then
|
if not hasStockWeapons then
|
||||||
do!
|
do!
|
||||||
[ DbService.addPlayerEvent GuildEnvironment.pgDb player.DiscordId TrainerEvents.[0]
|
[ DbService.addPlayerEvent player.DiscordId TrainerEvents.[0]
|
||||||
DbService.addPlayerEvent GuildEnvironment.pgDb player.DiscordId TrainerEvents.[1]
|
DbService.addPlayerEvent player.DiscordId TrainerEvents.[1]
|
||||||
DbService.updatePlayer GuildEnvironment.pgDb updatedPlayer ]
|
DbService.updatePlayer updatedPlayer ]
|
||||||
|> Async.Parallel
|
|> Async.Parallel
|
||||||
|> Async.Ignore
|
|> Async.Ignore
|
||||||
let embed = Embeds.getArsenalEmbed updatedPlayer
|
let embed = Embeds.getArsenalEmbed updatedPlayer
|
||||||
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
||||||
|
|
||||||
let! completed = DbService.checkHasAchievement GuildEnvironment.pgDb player.DiscordId trainerAchievement
|
let! completed = DbService.checkHasAchievement player.DiscordId trainerAchievement
|
||||||
if not completed then
|
if not completed then
|
||||||
do! Async.Sleep 3000
|
do! Async.Sleep 3000
|
||||||
let rewards = [ $"{defaultHack.Name} Hack" ; $"{defaultShield.Name} Shield" ]
|
let rewards = [ $"{defaultHack.Name} Hack" ; $"{defaultShield.Name} Shield" ]
|
||||||
|
@ -11,7 +11,7 @@ DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../.dev.env" ], overwriteEx
|
|||||||
let getVar str = Environment.GetEnvironmentVariable(str)
|
let getVar str = Environment.GetEnvironmentVariable(str)
|
||||||
let getId str = getVar str |> uint64
|
let getId str = getVar str |> uint64
|
||||||
|
|
||||||
let pgDb = (getVar "DATABASE_URL").Replace("postgresql://", "postgres://").Replace("?sslmode=require", "")
|
let connectionString = (getVar "DATABASE_URL").Replace("postgresql://", "postgres://").Replace("?sslmode=require", "")
|
||||||
|
|
||||||
let guildId = getId "DISCORD_GUILD"
|
let guildId = getId "DISCORD_GUILD"
|
||||||
let tokenPlayerInteractions = getVar "TOKEN_PLAYER_INTERACTIONS"
|
let tokenPlayerInteractions = getVar "TOKEN_PLAYER_INTERACTIONS"
|
||||||
|
@ -10,7 +10,7 @@ let executePlayerAction (ctx : IDiscordContext) (dispatch : PlayerData -> Async<
|
|||||||
async {
|
async {
|
||||||
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true)
|
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true)
|
||||||
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) |> Async.AwaitTask
|
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) |> Async.AwaitTask
|
||||||
let! playerResult = tryFindPlayer GuildEnvironment.pgDb (ctx.GetDiscordMember().Id)
|
let! playerResult = tryFindPlayer (ctx.GetDiscordMember().Id)
|
||||||
match playerResult with
|
match playerResult with
|
||||||
| Some player -> do! dispatch player
|
| Some player -> do! dispatch player
|
||||||
| None -> do! Messaging.sendFollowUpMessage ctx "You are currently not a hacker, first use the /redpill command to become one"
|
| None -> do! Messaging.sendFollowUpMessage ctx "You are currently not a hacker, first use the /redpill command to become one"
|
||||||
@ -23,8 +23,8 @@ let executePlayerActionWithTarget (targetPlayer : DiscordUser) (ctx : IDiscordCo
|
|||||||
builder.Content <- "Content"
|
builder.Content <- "Content"
|
||||||
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) |> Async.AwaitTask
|
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) |> Async.AwaitTask
|
||||||
let! players =
|
let! players =
|
||||||
[ tryFindPlayer GuildEnvironment.pgDb (ctx.GetDiscordMember().Id)
|
[ tryFindPlayer (ctx.GetDiscordMember().Id)
|
||||||
tryFindPlayer GuildEnvironment.pgDb targetPlayer.Id ]
|
tryFindPlayer targetPlayer.Id ]
|
||||||
|> Async.Parallel
|
|> Async.Parallel
|
||||||
match players.[0] , players.[1] with
|
match players.[0] , players.[1] with
|
||||||
| Some player , Some target -> do! dispatch player target
|
| Some player , Some target -> do! dispatch player target
|
||||||
@ -43,8 +43,8 @@ let executePlayerActionWithTargetId defer (targetId : uint64) (ctx : IDiscordCon
|
|||||||
if defer then
|
if defer then
|
||||||
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) |> Async.AwaitTask
|
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) |> Async.AwaitTask
|
||||||
let! players =
|
let! players =
|
||||||
[ tryFindPlayer GuildEnvironment.pgDb (ctx.GetDiscordMember().Id)
|
[ tryFindPlayer (ctx.GetDiscordMember().Id)
|
||||||
tryFindPlayer GuildEnvironment.pgDb targetId ]
|
tryFindPlayer targetId ]
|
||||||
|> Async.Parallel
|
|> Async.Parallel
|
||||||
match players.[0] , players.[1] with
|
match players.[0] , players.[1] with
|
||||||
| Some player , Some target -> do! dispatch player target
|
| Some player , Some target -> do! dispatch player target
|
||||||
|
Loading…
x
Reference in New Issue
Block a user