Small improvements to the hack/shield embeds. Delete active shield after selling
This commit is contained in:
		
							parent
							
								
									0e3909d4f2
								
							
						
					
					
						commit
						2603833fc6
					
				| @ -20,32 +20,36 @@ let getShieldGif = function | |||||||
|     | ShieldId.Cypher -> "https://s10.gifyu.com/images/Cypher-Smaller.jpg" |     | ShieldId.Cypher -> "https://s10.gifyu.com/images/Cypher-Smaller.jpg" | ||||||
|     | _ -> shieldGif |     | _ -> shieldGif | ||||||
| 
 | 
 | ||||||
|  | let constructButtons (actionType: string) (playerInfo: string) (items: BattleItem array) = | ||||||
|  |     items | ||||||
|  |     |> Array.map (fun item -> DiscordButtonComponent(Game.getClassButtonColor item.Class, $"{actionType}-{item.Id}-{playerInfo}", $"{item.Name}")) | ||||||
|  | 
 | ||||||
| let pickDefense actionId player = | let pickDefense actionId player = | ||||||
|     let buttons = |     let buttons = | ||||||
|         Messaging.constructButtons actionId (string player.DiscordId) (Player.shields player) |         constructButtons actionId (string player.DiscordId) (Player.shields player) | ||||||
|         |> Seq.cast<DiscordComponent> |         |> Seq.cast<DiscordComponent> | ||||||
| 
 | 
 | ||||||
|     let embed = |     let embed = | ||||||
|         DiscordEmbedBuilder() |         DiscordEmbedBuilder() | ||||||
|             .WithColor(DiscordColor.Blurple) |             .WithTitle("Shields") | ||||||
|             .WithDescription("Pick a shield to protect yourself from hacks") |             .WithDescription("Pick a shield to protect yourself from hacks") | ||||||
|             .WithImageUrl(shieldGif) |             .WithImageUrl(shieldGif) | ||||||
| 
 | 
 | ||||||
|     DiscordFollowupMessageBuilder() |     DiscordFollowupMessageBuilder() | ||||||
|         .AddComponents(buttons) |         .AddComponents(buttons) | ||||||
|         .AddEmbed(embed) |         .AddEmbed(embed) | ||||||
|         .AsEphemeral true |         .AsEphemeral(true) | ||||||
| 
 | 
 | ||||||
| let pickHack actionId attacker defender = | let pickHack actionId attacker defender = | ||||||
|     let buttons = |     let buttons = | ||||||
|         let hacks = Player.hacks attacker |         let hacks = Player.hacks attacker | ||||||
|         Messaging.constructButtons actionId $"{defender.DiscordId}-{defender.Name}"  hacks |         constructButtons actionId $"{defender.DiscordId}-{defender.Name}" hacks | ||||||
|         |> Seq.cast<DiscordComponent> |         |> Seq.cast<DiscordComponent> | ||||||
| 
 | 
 | ||||||
|     let embed = |     let embed = | ||||||
|         DiscordEmbedBuilder() |         DiscordEmbedBuilder() | ||||||
|             .WithColor(DiscordColor.Blurple) |             .WithTitle("Hacks") | ||||||
|             .WithDescription("Pick the hack that you want to use") |             .WithDescription($"Pick the hack that you want to use against {defender.Name}") | ||||||
|             .WithImageUrl(hackGif) |             .WithImageUrl(hackGif) | ||||||
| 
 | 
 | ||||||
|     DiscordFollowupMessageBuilder() |     DiscordFollowupMessageBuilder() | ||||||
|  | |||||||
| @ -188,12 +188,12 @@ let handleDefense (event : ComponentInteractionCreateEventArgs) = | |||||||
|         | _ , false -> |         | _ , false -> | ||||||
|             let timestamp = updatedDefenses |> Array.rev |> Array.head |> fun a -> a.Timestamp // This should be the next expiring timestamp |             let timestamp = updatedDefenses |> Array.rev |> Array.head |> fun a -> a.Timestamp // This should be the next expiring timestamp | ||||||
|             let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(int shield.Cooldown)) timestamp |             let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(int shield.Cooldown)) timestamp | ||||||
|             do! sendFollowUpMessage event $"You are only allowed two shields at a time. Wait {cooldown} minutes to add another shield" |             do! sendFollowUpMessage event $"You are only allowed two shields at a time. Wait {cooldown} to add another shield" | ||||||
|             do! DbService.updatePlayer <| { player with Actions = updatedDefenses } |             do! DbService.updatePlayer <| { player with Actions = updatedDefenses } | ||||||
|         | true , _ -> |         | true , _ -> | ||||||
|             let timestamp = updatedDefenses |> Array.find (fun d -> d.ActionId = int shieldId) |> fun a -> a.Timestamp |             let timestamp = updatedDefenses |> Array.find (fun d -> d.ActionId = int shieldId) |> fun a -> a.Timestamp | ||||||
|             let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(int shield.Cooldown)) timestamp |             let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(int shield.Cooldown)) timestamp | ||||||
|             do! sendFollowUpMessage event $"{shieldId} shield is already in use. Wait {cooldown} minutes to use this shield again" |             do! sendFollowUpMessage event $"{shield.Name} shield is already in use. Wait {cooldown} to use this shield again" | ||||||
|             do! DbService.updatePlayer <| { player with Actions = updatedDefenses } |             do! DbService.updatePlayer <| { player with Actions = updatedDefenses } | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								Bot/Store.fs
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								Bot/Store.fs
									
									
									
									
									
								
							| @ -67,7 +67,6 @@ let buy itemType (ctx : InteractionContext) = | |||||||
|             |> Async.Ignore |             |> Async.Ignore | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
| // TODO: Remove active shield when selling |  | ||||||
| let sell itemType (ctx : InteractionContext) = | let sell itemType (ctx : InteractionContext) = | ||||||
|     Game.executePlayerInteraction ctx (fun player -> async { |     Game.executePlayerInteraction ctx (fun player -> async { | ||||||
|         match checkHasItemsInArsenal itemType player with |         match checkHasItemsInArsenal itemType player with | ||||||
| @ -101,7 +100,15 @@ let handleSell (event : ComponentInteractionCreateEventArgs) itemId = | |||||||
|         do! player |         do! player | ||||||
|             |> checkSoldItemAlready item |             |> checkSoldItemAlready item | ||||||
|             |> handleResultWithResponseFromEvent event (fun player -> async { |             |> handleResultWithResponseFromEvent event (fun player -> async { | ||||||
|                 let updatedPlayer = { player with Bank = player.Bank + item.Cost ; Arsenal = player.Arsenal |> Array.filter (fun w -> w.Id <> itemId) } |                 let updatedPlayer = { | ||||||
|  |                     player with | ||||||
|  |                         Bank = player.Bank + item.Cost | ||||||
|  |                         Arsenal = player.Arsenal |> Array.filter (fun i -> i.Id <> itemId) | ||||||
|  |                         Actions = | ||||||
|  |                             if item.Type = ItemType.Shield | ||||||
|  |                                 then player.Actions |> Array.filter (fun a -> a.ActionId <> itemId) | ||||||
|  |                                 else player.Actions | ||||||
|  |                 } | ||||||
|                 do! DbService.updatePlayer updatedPlayer |                 do! DbService.updatePlayer updatedPlayer | ||||||
|                 do! sendFollowUpMessage event $"Sold {item.Type} {item.Name} for {item.Cost}! Current Balance: {updatedPlayer.Bank}" |                 do! sendFollowUpMessage event $"Sold {item.Type} {item.Name} for {item.Cost}! Current Balance: {updatedPlayer.Bank}" | ||||||
|             }) |             }) | ||||||
| @ -135,7 +142,7 @@ type Store() = | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|     [<SlashCommand("arsenal", "Get the Hacks and Shields you own, and which ones are active")>] |     [<SlashCommand("arsenal", "Get the Hacks and Shields you own, and which ones are active")>] | ||||||
|     member this.Arsenal (ctx : InteractionContext) = enforceChannel ctx arsenal |     member this.Arsenal (ctx : InteractionContext) = arsenal ctx | ||||||
| 
 | 
 | ||||||
|     [<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>] |     [<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>] | ||||||
|     member _.BuyHack (ctx : InteractionContext) = enforceChannel ctx (buy ItemType.Hack) |     member _.BuyHack (ctx : InteractionContext) = enforceChannel ctx (buy ItemType.Hack) | ||||||
|  | |||||||
| @ -122,10 +122,6 @@ module Messaging = | |||||||
|                     $"{item.Name} active for {cooldown}") |                     $"{item.Name} active for {cooldown}") | ||||||
|             |> String.concat "\n" |             |> String.concat "\n" | ||||||
| 
 | 
 | ||||||
|     let constructButtons (actionType: string) (playerInfo: string) (weapons: BattleItem array) = |  | ||||||
|         weapons |  | ||||||
|         |> Array.map (fun w -> DiscordButtonComponent(ButtonStyle.Success, $"{actionType}-{w.Id}-{playerInfo}", $"{w.Name}")) |  | ||||||
| 
 |  | ||||||
|     let sendSimpleResponse (ctx: InteractionContext) msg = |     let sendSimpleResponse (ctx: InteractionContext) msg = | ||||||
|         async { |         async { | ||||||
|             let builder = DiscordInteractionResponseBuilder() |             let builder = DiscordInteractionResponseBuilder() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user