Fix issue with new stealing related actions where it tries to get a weapon
This commit is contained in:
parent
18aeab599c
commit
537145dae6
@ -5,6 +5,7 @@ open DSharpPlus
|
|||||||
open DSharpPlus.SlashCommands
|
open DSharpPlus.SlashCommands
|
||||||
open Degenz
|
open Degenz
|
||||||
open Degenz.HackerBattle
|
open Degenz.HackerBattle
|
||||||
|
open Degenz.RockPaperScissors
|
||||||
open Degenz.Store
|
open Degenz.Store
|
||||||
open Degenz.Thief
|
open Degenz.Thief
|
||||||
open Emzi0767.Utilities
|
open Emzi0767.Utilities
|
||||||
@ -43,6 +44,7 @@ let storeCommands = storeBot.UseSlashCommands()
|
|||||||
|
|
||||||
hackerCommands.RegisterCommands<HackerGame>(guild);
|
hackerCommands.RegisterCommands<HackerGame>(guild);
|
||||||
hackerCommands.RegisterCommands<StealGame>(guild);
|
hackerCommands.RegisterCommands<StealGame>(guild);
|
||||||
|
hackerCommands.RegisterCommands<RPSGame>(guild);
|
||||||
storeCommands.RegisterCommands<Store>(guild);
|
storeCommands.RegisterCommands<Store>(guild);
|
||||||
//sc3.RegisterCommands<SlotMachine>(guild);
|
//sc3.RegisterCommands<SlotMachine>(guild);
|
||||||
|
|
||||||
|
25
Bot/Game.fs
25
Bot/Game.fs
@ -82,18 +82,28 @@ module Player =
|
|||||||
let getShields (player : PlayerData) = getItems ItemType.Shield player
|
let getShields (player : PlayerData) = getItems ItemType.Shield player
|
||||||
let getAttacks player =
|
let getAttacks player =
|
||||||
player.Actions
|
player.Actions
|
||||||
|> Array.filter (fun act -> match act.Type with Attack _ -> true | _ -> false)
|
|> Array.filter (fun act -> match act.Type with Attack _ -> true | _ -> false || act.ActionId < 12)
|
||||||
let getDefenses player = player.Actions |> Array.filter (fun act -> match act.Type with Defense -> true | _ -> false)
|
let getDefenses player =
|
||||||
|
player.Actions
|
||||||
|
|> Array.filter (fun act -> match act.Type with Defense -> true | _ -> false || act.ActionId < 12)
|
||||||
|
|
||||||
let removeExpiredActions filterByAttackCooldown player =
|
let removeExpiredActions filterByAttackCooldown player =
|
||||||
let actions =
|
let actions =
|
||||||
player.Actions
|
player.Actions
|
||||||
|> Array.filter (fun (act : Action) ->
|
|> Array.filter (fun (act : Action) ->
|
||||||
let item = Armory.getItem act.ActionId
|
let itemCooldown =
|
||||||
|
if act.ActionId < 12 then
|
||||||
|
(Armory.getItem act.ActionId).Cooldown
|
||||||
|
else
|
||||||
|
match act.Type with
|
||||||
|
| Attack _ -> 1<mins>
|
||||||
|
| Defense -> 720<mins>
|
||||||
|
|> int
|
||||||
|
|
||||||
match act.Type , filterByAttackCooldown with
|
match act.Type , filterByAttackCooldown with
|
||||||
| Attack _ , true -> System.DateTime.UtcNow - act.Timestamp < System.TimeSpan.FromMinutes(int item.Cooldown)
|
| Attack _ , true -> System.DateTime.UtcNow - act.Timestamp < System.TimeSpan.FromMinutes(itemCooldown)
|
||||||
| Attack _ , false -> System.DateTime.UtcNow - act.Timestamp < Game.SameTargetAttackCooldown
|
| Attack _ , false -> System.DateTime.UtcNow - act.Timestamp < Game.SameTargetAttackCooldown
|
||||||
| Defense , _ -> System.DateTime.UtcNow - act.Timestamp < System.TimeSpan.FromMinutes(int item.Cooldown))
|
| Defense , _ -> System.DateTime.UtcNow - act.Timestamp < System.TimeSpan.FromMinutes(itemCooldown))
|
||||||
{ player with Actions = actions }
|
{ player with Actions = actions }
|
||||||
|
|
||||||
let modifyBank (player : PlayerData) amount = { player with Bank = max (player.Bank + amount) 0<GBT> }
|
let modifyBank (player : PlayerData) amount = { player with Bank = max (player.Bank + amount) 0<GBT> }
|
||||||
@ -110,7 +120,10 @@ module Arsenal =
|
|||||||
match actions with
|
match actions with
|
||||||
| [||] -> "None"
|
| [||] -> "None"
|
||||||
| _ ->
|
| _ ->
|
||||||
let hacks , defenses = actions |> Array.partition (fun act -> match act.Type with Attack _ -> true | Defense -> false)
|
let hacks , defenses =
|
||||||
|
actions
|
||||||
|
|> Array.filter (fun act -> act.ActionId < 12)
|
||||||
|
|> Array.partition (fun act -> match act.Type with Attack _ -> true | Defense -> false)
|
||||||
let hacks = hacks |> Array.take (min hacks.Length 10)
|
let hacks = hacks |> Array.take (min hacks.Length 10)
|
||||||
hacks
|
hacks
|
||||||
|> Array.append defenses
|
|> Array.append defenses
|
||||||
|
@ -178,7 +178,7 @@ let handleDefense (ctx : IDiscordContext) =
|
|||||||
|> checkPlayerOwnsWeapon shieldId
|
|> checkPlayerOwnsWeapon shieldId
|
||||||
>>= checkPlayerHasShieldSlotsAvailable shield
|
>>= checkPlayerHasShieldSlotsAvailable shield
|
||||||
>>= checkItemHasCooldown shieldId
|
>>= checkItemHasCooldown shieldId
|
||||||
|> handleResultWithResponse ctx (fun p -> async {
|
|> handleResultWithResponse ctx (fun _ -> async { // Don't use this player, it removes player cooldowns
|
||||||
let embed = Embeds.responseCreatedShield (Armory.getItem shieldId)
|
let embed = Embeds.responseCreatedShield (Armory.getItem shieldId)
|
||||||
do! ctx.FollowUp embed |> Async.AwaitTask
|
do! ctx.FollowUp embed |> Async.AwaitTask
|
||||||
let defense = { ActionId = shieldId ; Type = Defense ; Timestamp = DateTime.UtcNow }
|
let defense = { ActionId = shieldId ; Type = Defense ; Timestamp = DateTime.UtcNow }
|
||||||
@ -192,21 +192,6 @@ let handleDefense (ctx : IDiscordContext) =
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
|
|
||||||
let eventCtx = DiscordEventContext event :> IDiscordContext
|
|
||||||
match event.Id with
|
|
||||||
| id when id.StartsWith("Attack") -> handleAttack eventCtx
|
|
||||||
| id when id.StartsWith("Defend") -> handleDefense eventCtx
|
|
||||||
| id when id.StartsWith("Trainer") -> Trainer.handleButtonEvent eventCtx |> Async.StartAsTask :> Task
|
|
||||||
| id when id.StartsWith("Steal") -> Thief.handleSteal eventCtx
|
|
||||||
| _ ->
|
|
||||||
task {
|
|
||||||
let builder = DiscordInteractionResponseBuilder()
|
|
||||||
builder.IsEphemeral <- true
|
|
||||||
builder.Content <- $"Incorrect Action identifier {eventCtx.GetInteractionId()}"
|
|
||||||
do! eventCtx.Respond InteractionResponseType.ChannelMessageWithSource builder |> Async.AwaitTask
|
|
||||||
}
|
|
||||||
|
|
||||||
let arsenal (ctx : IDiscordContext) =
|
let arsenal (ctx : IDiscordContext) =
|
||||||
Game.executePlayerAction ctx (fun player -> async {
|
Game.executePlayerAction ctx (fun player -> async {
|
||||||
let updatedPlayer = Player.removeExpiredActions false player
|
let updatedPlayer = Player.removeExpiredActions false player
|
||||||
@ -219,6 +204,22 @@ let arsenal (ctx : IDiscordContext) =
|
|||||||
do! DbService.updatePlayer updatedPlayer
|
do! DbService.updatePlayer updatedPlayer
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
|
||||||
|
let eventCtx = DiscordEventContext event :> IDiscordContext
|
||||||
|
match event.Id with
|
||||||
|
| id when id.StartsWith("Attack") -> handleAttack eventCtx
|
||||||
|
| id when id.StartsWith("Defend") -> handleDefense eventCtx
|
||||||
|
| id when id.StartsWith("Trainer") -> Trainer.handleButtonEvent eventCtx |> Async.StartAsTask :> Task
|
||||||
|
| id when id.StartsWith("Steal") -> Thief.handleSteal eventCtx
|
||||||
|
| id when id.StartsWith("Steal") -> RockPaperScissors.handleRPS eventCtx
|
||||||
|
| _ ->
|
||||||
|
task {
|
||||||
|
let builder = DiscordInteractionResponseBuilder()
|
||||||
|
builder.IsEphemeral <- true
|
||||||
|
builder.Content <- $"Incorrect Action identifier {eventCtx.GetInteractionId()}"
|
||||||
|
do! eventCtx.Respond InteractionResponseType.ChannelMessageWithSource builder |> Async.AwaitTask
|
||||||
|
}
|
||||||
|
|
||||||
type HackerGame() =
|
type HackerGame() =
|
||||||
inherit ApplicationCommandModule ()
|
inherit ApplicationCommandModule ()
|
||||||
|
|
||||||
|
@ -29,11 +29,22 @@ let player1Won p1m p2m =
|
|||||||
|
|
||||||
let playRPS target ctx =
|
let playRPS target ctx =
|
||||||
Game.executePlayerActionWithTarget target ctx (fun attacker defender -> async {
|
Game.executePlayerActionWithTarget target ctx (fun attacker defender -> async {
|
||||||
|
let buttons =
|
||||||
|
[ DiscordButtonComponent(ButtonStyle.Primary, $"RPS-rock-{defender.DiscordId}-{defender.Name}", "🪨 Rock")
|
||||||
|
DiscordButtonComponent(ButtonStyle.Primary, $"RPS-paper", "📜 Paper")
|
||||||
|
DiscordButtonComponent(ButtonStyle.Primary, $"RPS-scissors", "✂ Scissors") ]
|
||||||
|
|> Seq.cast<DiscordComponent>
|
||||||
|
|
||||||
return ()
|
let builder = DiscordFollowupMessageBuilder()
|
||||||
|
builder.AddComponents(buttons) |> ignore
|
||||||
|
builder.IsEphemeral <- true
|
||||||
|
|
||||||
|
do! ctx.FollowUp builder |> Async.AwaitTask
|
||||||
})
|
})
|
||||||
|
|
||||||
type StealGame() =
|
let handleRPS ctx = async.Zero() |> Async.StartAsTask
|
||||||
|
|
||||||
|
type RPSGame() =
|
||||||
inherit ApplicationCommandModule ()
|
inherit ApplicationCommandModule ()
|
||||||
|
|
||||||
let enforceChannel (ctx : IDiscordContext) (storeFn : IDiscordContext -> Task) =
|
let enforceChannel (ctx : IDiscordContext) (storeFn : IDiscordContext -> Task) =
|
||||||
|
@ -173,6 +173,7 @@ let handleSteal (ctx : IDiscordContext) =
|
|||||||
let targetId = uint64 split.[2]
|
let targetId = uint64 split.[2]
|
||||||
Game.executePlayerActionWithTargetId targetId ctx (fun attacker defender -> async {
|
Game.executePlayerActionWithTargetId targetId ctx (fun attacker defender -> async {
|
||||||
do! attacker
|
do! attacker
|
||||||
|
|> Player.removeExpiredActions false
|
||||||
|> checkVictimStealingCooldown defender
|
|> checkVictimStealingCooldown defender
|
||||||
>>= checkThiefCooldown
|
>>= checkThiefCooldown
|
||||||
|> handleResultWithResponse ctx handleYes
|
|> handleResultWithResponse ctx handleYes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user