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 Degenz
|
||||
open Degenz.HackerBattle
|
||||
open Degenz.RockPaperScissors
|
||||
open Degenz.Store
|
||||
open Degenz.Thief
|
||||
open Emzi0767.Utilities
|
||||
@ -43,6 +44,7 @@ let storeCommands = storeBot.UseSlashCommands()
|
||||
|
||||
hackerCommands.RegisterCommands<HackerGame>(guild);
|
||||
hackerCommands.RegisterCommands<StealGame>(guild);
|
||||
hackerCommands.RegisterCommands<RPSGame>(guild);
|
||||
storeCommands.RegisterCommands<Store>(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 getAttacks player =
|
||||
player.Actions
|
||||
|> Array.filter (fun act -> match act.Type with Attack _ -> true | _ -> false)
|
||||
let getDefenses player = player.Actions |> Array.filter (fun act -> match act.Type with Defense -> 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 || act.ActionId < 12)
|
||||
|
||||
let removeExpiredActions filterByAttackCooldown player =
|
||||
let actions =
|
||||
player.Actions
|
||||
|> 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
|
||||
| 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
|
||||
| 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 }
|
||||
|
||||
let modifyBank (player : PlayerData) amount = { player with Bank = max (player.Bank + amount) 0<GBT> }
|
||||
@ -110,7 +120,10 @@ module Arsenal =
|
||||
match actions with
|
||||
| [||] -> "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)
|
||||
hacks
|
||||
|> Array.append defenses
|
||||
|
@ -178,7 +178,7 @@ let handleDefense (ctx : IDiscordContext) =
|
||||
|> checkPlayerOwnsWeapon shieldId
|
||||
>>= checkPlayerHasShieldSlotsAvailable shield
|
||||
>>= 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)
|
||||
do! ctx.FollowUp embed |> Async.AwaitTask
|
||||
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) =
|
||||
Game.executePlayerAction ctx (fun player -> async {
|
||||
let updatedPlayer = Player.removeExpiredActions false player
|
||||
@ -219,6 +204,22 @@ let arsenal (ctx : IDiscordContext) =
|
||||
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() =
|
||||
inherit ApplicationCommandModule ()
|
||||
|
||||
|
@ -29,11 +29,22 @@ let player1Won p1m p2m =
|
||||
|
||||
let playRPS target ctx =
|
||||
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 ()
|
||||
|
||||
let enforceChannel (ctx : IDiscordContext) (storeFn : IDiscordContext -> Task) =
|
||||
|
@ -173,6 +173,7 @@ let handleSteal (ctx : IDiscordContext) =
|
||||
let targetId = uint64 split.[2]
|
||||
Game.executePlayerActionWithTargetId targetId ctx (fun attacker defender -> async {
|
||||
do! attacker
|
||||
|> Player.removeExpiredActions false
|
||||
|> checkVictimStealingCooldown defender
|
||||
>>= checkThiefCooldown
|
||||
|> handleResultWithResponse ctx handleYes
|
||||
|
Loading…
x
Reference in New Issue
Block a user