Improve steal game presentation and fix exploit. Fix bug
This commit is contained in:
parent
94dfce126c
commit
63e3853788
@ -80,7 +80,7 @@ module Player =
|
|||||||
player.Events
|
player.Events
|
||||||
|> Array.filter (fun (act : PlayerEvent) ->
|
|> Array.filter (fun (act : PlayerEvent) ->
|
||||||
let itemCooldown =
|
let itemCooldown =
|
||||||
if act.ItemId < 12 then
|
if act.ItemId > 0 && act.ItemId < 12 then
|
||||||
(Armory.getItem act.ItemId).Cooldown
|
(Armory.getItem act.ItemId).Cooldown
|
||||||
else
|
else
|
||||||
match act.Type with
|
match act.Type with
|
||||||
|
94
Bot/Thief.fs
94
Bot/Thief.fs
@ -40,11 +40,11 @@ let payout defenderBank chance =
|
|||||||
let randomAmount = baseAmount + randomBonus |> int
|
let randomAmount = baseAmount + randomBonus |> int
|
||||||
max 1 randomAmount
|
max 1 randomAmount
|
||||||
|
|
||||||
let getStealEmbed (chance : double) prize (target : PlayerData) =
|
let getStealEmbed amount (chance : double) prize (target : PlayerData) =
|
||||||
let chance = int (chance * 100.0)
|
let chance = int (chance * 100.0)
|
||||||
let buttons =
|
let buttons =
|
||||||
// let yes , no = getRandomStealBtnLabels ()
|
// let yes , no = getRandomStealBtnLabels ()
|
||||||
let btnId = $"Steal-yes-{target.DiscordId}-{target.Name}-{chance}-{prize}"
|
let btnId = $"Steal-yes-{target.DiscordId}-{target.Name}-{amount}"
|
||||||
[ DiscordButtonComponent(ButtonStyle.Success, btnId, "Do it") ]
|
[ DiscordButtonComponent(ButtonStyle.Success, btnId, "Do it") ]
|
||||||
// DiscordButtonComponent(ButtonStyle.Danger, $"Steal-no", no) ]
|
// DiscordButtonComponent(ButtonStyle.Danger, $"Steal-no", no) ]
|
||||||
|> Seq.cast<DiscordComponent>
|
|> Seq.cast<DiscordComponent>
|
||||||
@ -59,27 +59,36 @@ let getStealEmbed (chance : double) prize (target : PlayerData) =
|
|||||||
.AddComponents(buttons)
|
.AddComponents(buttons)
|
||||||
.AsEphemeral(true)
|
.AsEphemeral(true)
|
||||||
|
|
||||||
let getResultEmbed targetName result =
|
let getResultEmbed chance prize (bank : int<GBT>) thief (victim : DiscordPlayer) result =
|
||||||
let resultMsg , msg , img =
|
let embed =
|
||||||
|
DiscordEmbedBuilder()
|
||||||
|
.AddField("Thief", $"<@{thief.DiscordId}>")
|
||||||
|
.AddField("Victim", $"<@{victim.Id}>")
|
||||||
|
.AddField("Chance of Success" , $"{chance * 100.0 |> int}%%", true)
|
||||||
|
let msg , img , color =
|
||||||
match result with
|
match result with
|
||||||
| Success ->
|
| Success ->
|
||||||
"You successfully robbed the poor bastard"
|
embed.AddField("Loot" , $"{prize}", true)
|
||||||
, "Your mean ugly face and athletic physique intimidated your poor victim into giving you their money"
|
.AddField("New GoodBoyTokenⒸ Balance", $"`{bank}` => 💰 `{bank + prize}` (+{prize}) ") |> ignore
|
||||||
|
($"\n\n You **STOLE** `{prize} $GBT` 🎉\n\n"
|
||||||
|
+ "Your mean ugly face and athletic physique intimidated your poor victim into giving you their money")
|
||||||
, "https://f8n-production-collection-assets.imgix.net/0x3B3ee1931Dc30C1957379FAc9aba94D1C48a5405/127502/QmPLPg1CLovKzS7mP8QkrMoHws1D4VZTzpfbZBALLwKZ5b/nft.png"
|
, "https://f8n-production-collection-assets.imgix.net/0x3B3ee1931Dc30C1957379FAc9aba94D1C48a5405/127502/QmPLPg1CLovKzS7mP8QkrMoHws1D4VZTzpfbZBALLwKZ5b/nft.png"
|
||||||
| WentToPrison ->
|
, DiscordColor.Green
|
||||||
"Looks like you went to prison"
|
|
||||||
, $"{targetName} knows Karate and elbowed you in the nose. While unconscious, they called the cops. You're on your way to prison now... "
|
|
||||||
, "https://thumbs.dreamstime.com/b/vector-pixel-art-prisoner-isolated-cartoon-vector-pixel-art-prisoner-129807237.jpg"
|
|
||||||
| VictimRanAway ->
|
| VictimRanAway ->
|
||||||
"You tried to snatch their money and they ran away"
|
embed.AddField("Result" , $"Ran Away", true) |> ignore
|
||||||
, $"{targetName} got nervous seeing a shadowy figure and ran in the opposite direction"
|
$"Target **ran away**...\n\n{thief.Name} saw a shadowy figure and got nervous so they ran in the opposite direction"
|
||||||
, "https://i.imgur.com/NLHMvVK.jpg"
|
, "https://i.imgur.com/NLHMvVK.jpg"
|
||||||
|
, DiscordColor.Grayple
|
||||||
|
| WentToPrison ->
|
||||||
|
embed.AddField("Result" , $"Imprisoned", true) |> ignore
|
||||||
|
$"You're going to **PRISON**...\n\n{thief.Name} knows Karate and elbowed you in the nose. While unconscious, they called the cops."
|
||||||
|
, "https://thumbs.dreamstime.com/b/vector-pixel-art-prisoner-isolated-cartoon-vector-pixel-art-prisoner-129807237.jpg"
|
||||||
|
, DiscordColor.Red
|
||||||
|
|
||||||
DiscordEmbedBuilder()
|
embed.WithTitle($"Steal Results")
|
||||||
// .AddField("Result" , resultMsg)
|
.WithColor(color)
|
||||||
.WithDescription(msg)
|
.WithDescription(msg)
|
||||||
// .WithImageUrl(img)
|
.WithImageUrl(img)
|
||||||
.WithTitle($"Robbery Results")
|
|
||||||
|
|
||||||
let checkVictimStealingCooldown defender attacker =
|
let checkVictimStealingCooldown defender attacker =
|
||||||
defender
|
defender
|
||||||
@ -110,26 +119,23 @@ let checkThiefCooldown attacker =
|
|||||||
|
|
||||||
|
|
||||||
let calculateWinPercentage amountRequested bank attackerStrength defenderStrength =
|
let calculateWinPercentage amountRequested bank attackerStrength defenderStrength =
|
||||||
let powerPercentage = float (attackerStrength - defenderStrength) * 0.005 + 0.25
|
let powerPercentage = float (attackerStrength - defenderStrength) * 0.005 + 0.1
|
||||||
printfn $"{(attackerStrength - defenderStrength)}"
|
|
||||||
printfn $"{powerPercentage}"
|
|
||||||
let cappedAmount = float bank * 0.5
|
let cappedAmount = float bank * 0.5
|
||||||
let cappedRequest = min amountRequested (cappedAmount |> ceil)
|
let cappedRequest = min amountRequested (cappedAmount |> ceil)
|
||||||
let wagerPercentage = 1.0 - (cappedRequest / cappedAmount)
|
let wagerPercentage = 1.0 - (cappedRequest / cappedAmount)
|
||||||
// Max chance of success is 97.5%
|
// Max chance of success is 90.0%
|
||||||
( cappedRequest , max 0.0 (wagerPercentage * 0.7 + powerPercentage * 1.3 ) / 2.05 )
|
( cappedRequest , max 0.0 (wagerPercentage * 0.7 + powerPercentage * 1.3 ) / 2.0 )
|
||||||
|
|
||||||
//calculateWinPercentage 500 1000 100 50
|
//calculateWinPercentage 50 200 100 85
|
||||||
|
|
||||||
let steal target amount (ctx : IDiscordContext) =
|
let steal target amount (ctx : IDiscordContext) =
|
||||||
Game.executePlayerActionWithTarget target ctx (fun attacker defender -> async {
|
Game.executePlayerActionWithTarget target ctx (fun attacker defender -> async { do!
|
||||||
do!
|
|
||||||
attacker
|
attacker
|
||||||
|> checkVictimStealingCooldown defender
|
|> checkVictimStealingCooldown defender
|
||||||
>>= checkThiefCooldown
|
>>= checkThiefCooldown
|
||||||
|> handleResultWithResponse ctx (fun _ -> async {
|
|> handleResultWithResponse ctx (fun _ -> async {
|
||||||
let cappedPrize , winPercentage = calculateWinPercentage amount (int defender.Bank) attacker.Traits.Strength defender.Traits.Strength
|
let cappedPrize , winPercentage = calculateWinPercentage amount (int defender.Bank) attacker.Traits.Strength defender.Traits.Strength
|
||||||
let embed = getStealEmbed winPercentage cappedPrize defender
|
let embed = getStealEmbed amount winPercentage cappedPrize defender
|
||||||
|
|
||||||
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
do! ctx.FollowUp(embed) |> Async.AwaitTask
|
||||||
})
|
})
|
||||||
@ -139,44 +145,46 @@ let handleSteal (ctx : IDiscordContext) =
|
|||||||
let split = ctx.GetInteractionId().Split("-")
|
let split = ctx.GetInteractionId().Split("-")
|
||||||
let answer = split.[1]
|
let answer = split.[1]
|
||||||
|
|
||||||
let handleYes (player : PlayerData) = async {
|
let handleYes (victim : PlayerData) (thief : PlayerData) = async {
|
||||||
let targetId = uint64 split.[2]
|
let targetId = uint64 split.[2]
|
||||||
let targetName = split.[3]
|
let targetName = split.[3]
|
||||||
let chance = double split.[4]
|
let amount = int split.[4]
|
||||||
let prize = int split.[5] * 1<GBT>
|
let prize , winPercentage = calculateWinPercentage amount (int victim.Bank) thief.Traits.Strength victim.Traits.Strength
|
||||||
|
let prize = int prize * 1<GBT>
|
||||||
|
|
||||||
let rand = Random(Guid.NewGuid().GetHashCode())
|
let rand = Random(Guid.NewGuid().GetHashCode())
|
||||||
|
|
||||||
let result = chance >= rand.NextDouble() , rand.Next(0,3) = 0
|
let num = rand.NextDouble()
|
||||||
|
let result = winPercentage >= num , rand.Next(0,3) = 0
|
||||||
let dp = { DiscordPlayer.Id = targetId ; DiscordPlayer.Name = targetName }
|
let dp = { DiscordPlayer.Id = targetId ; DiscordPlayer.Name = targetName }
|
||||||
let stealAction result = { ItemId = -1 ; Type = PlayerEventType.Steal ; Result = result ; Adversary = dp ; Timestamp = DateTime.UtcNow }
|
let stealAction result = { ItemId = -1 ; Type = PlayerEventType.Steal ; Result = result ; Adversary = dp ; Timestamp = DateTime.UtcNow }
|
||||||
|
let getResultEmbed' = getResultEmbed winPercentage prize thief.Bank thief dp
|
||||||
// TODO: Send event to the hall of privacy
|
// TODO: Send event to the hall of privacy
|
||||||
// TODO: We need to check if the player is on cooldown
|
// TODO: We need to check if the player is on cooldown
|
||||||
match result with
|
match result with
|
||||||
| true , _ ->
|
| true , _ ->
|
||||||
let xp = 25
|
let embed = getResultEmbed' Success
|
||||||
let embed = getResultEmbed targetName Success
|
// let xp = 25
|
||||||
embed.AddField("$GBT Stolen", string prize) |> ignore
|
// embed.AddField("XP Gained", $"{xp}") |> ignore
|
||||||
embed.AddField("XP Gained", $"{xp}") |> ignore
|
|
||||||
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
||||||
match! DbService.tryFindPlayer targetId with
|
match! DbService.tryFindPlayer targetId with
|
||||||
| Some t ->
|
| Some t ->
|
||||||
let mugged = { ItemId = -1 ; Type = PlayerEventType.Steal ; Result = PlayerEventResult.Negative ; Adversary = player.basicPlayer ; Timestamp = DateTime.UtcNow }
|
let mugged = { ItemId = -1 ; Type = PlayerEventType.Steal ; Result = PlayerEventResult.Negative ; Adversary = thief.basicPlayer ; Timestamp = DateTime.UtcNow }
|
||||||
let actions = t |> Player.removeExpiredActions false |> fun p -> Array.append [| mugged |] p.Events
|
let actions = t |> Player.removeExpiredActions false |> fun p -> Array.append [| mugged |] p.Events
|
||||||
do! DbService.updatePlayer { t with Bank = max (t.Bank - prize) 0<GBT> ; Events = actions }
|
do! DbService.updatePlayer { t with Bank = max (t.Bank - prize) 0<GBT> ; Events = actions }
|
||||||
| None -> ()
|
| None -> ()
|
||||||
let stole = { ItemId = -1 ; Type = PlayerEventType.Steal ; Result = PlayerEventResult.Positive ; Adversary = dp ; Timestamp = DateTime.UtcNow }
|
let stole = { ItemId = -1 ; Type = PlayerEventType.Steal ; Result = PlayerEventResult.Positive ; Adversary = dp ; Timestamp = DateTime.UtcNow }
|
||||||
let actions = player |> Player.removeExpiredActions false |> fun p -> Array.append [| stole |] p.Events
|
let actions = thief |> Player.removeExpiredActions false |> fun p -> Array.append [| stole |] p.Events
|
||||||
do! DbService.updatePlayer { player with Bank = player.Bank + prize ; XP = player.XP + xp ; Events = actions }
|
do! DbService.updatePlayer { thief with Bank = thief.Bank + prize ; XP = thief.XP + 0 ; Events = actions }
|
||||||
do! Async.Sleep 2000
|
// do! Async.Sleep 2000
|
||||||
do! ctx.FollowUp (XP.getRewardsEmbed 1 player) |> Async.AwaitTask
|
// do! ctx.FollowUp (XP.getRewardsEmbed 1 player) |> Async.AwaitTask
|
||||||
| false , false ->
|
| false , false ->
|
||||||
let embed = getResultEmbed targetName VictimRanAway
|
let embed = getResultEmbed' VictimRanAway
|
||||||
do! DbService.updatePlayer { player with Events = Array.append [| stealAction PlayerEventResult.Neutral |] player.Events }
|
do! DbService.updatePlayer { thief with Events = Array.append [| stealAction PlayerEventResult.Neutral |] thief.Events }
|
||||||
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
|
||||||
| false , true ->
|
| false , true ->
|
||||||
let embed = getResultEmbed targetName WentToPrison
|
let embed = getResultEmbed' WentToPrison
|
||||||
do! DbService.updatePlayer { player with Events = Array.append [| stealAction PlayerEventResult.Neutral |] player.Events }
|
do! DbService.updatePlayer { thief with Events = Array.append [| stealAction PlayerEventResult.Neutral |] thief.Events }
|
||||||
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)
|
||||||
@ -189,7 +197,7 @@ let handleSteal (ctx : IDiscordContext) =
|
|||||||
|> Player.removeExpiredActions false
|
|> Player.removeExpiredActions false
|
||||||
|> checkVictimStealingCooldown defender
|
|> checkVictimStealingCooldown defender
|
||||||
>>= checkThiefCooldown
|
>>= checkThiefCooldown
|
||||||
|> handleResultWithResponse ctx handleYes
|
|> handleResultWithResponse ctx (handleYes defender )
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
async {
|
async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user