From 512e686a50a8451ed6b4e5201a664d5da46993c6 Mon Sep 17 00:00:00 2001 From: upa-r-upa Date: Mon, 11 Mar 2024 19:23:55 +0900 Subject: [PATCH] feat: Add dungeon key count Subscription field --- .../GraphTypes/Types/DungeonStateType.cs | 24 +++++++++++++++++++ .../GraphTypes/Types/UserStateType.cs | 5 ++++ backend/app/Savor22b/States/DungeonState.cs | 5 ++++ 3 files changed, 34 insertions(+) create mode 100644 backend/app/Savor22b/GraphTypes/Types/DungeonStateType.cs diff --git a/backend/app/Savor22b/GraphTypes/Types/DungeonStateType.cs b/backend/app/Savor22b/GraphTypes/Types/DungeonStateType.cs new file mode 100644 index 00000000..cc4e8313 --- /dev/null +++ b/backend/app/Savor22b/GraphTypes/Types/DungeonStateType.cs @@ -0,0 +1,24 @@ +namespace Savor22b.GraphTypes.Types; + +using GraphQL.Types; +using Libplanet.Blockchain; +using Libplanet.Net; +using Libplanet.Store; +using Savor22b.States; + +public class DungeonStateType : ObjectGraphType +{ + public DungeonStateType( + BlockChain blockChain, + BlockRenderer blockRenderer, + IStore store, + Swarm? swarm = null + ) + { + Field>( + name: "DungeonKeyCount", + description: "The number of dungeon keys the user has.", + resolve: context => context.Source.GetDungeonKeyCount(blockChain.Count) + ); + } +} diff --git a/backend/app/Savor22b/GraphTypes/Types/UserStateType.cs b/backend/app/Savor22b/GraphTypes/Types/UserStateType.cs index d4ef68da..250b1dcf 100644 --- a/backend/app/Savor22b/GraphTypes/Types/UserStateType.cs +++ b/backend/app/Savor22b/GraphTypes/Types/UserStateType.cs @@ -17,5 +17,10 @@ public UserStateType() description: "The village state of the user.", resolve: context => context.Source.VillageState ); + Field>( + name: "dungeonState", + description: "The dungeon state of the user.", + resolve: context => context.Source.DungeonState + ); } } diff --git a/backend/app/Savor22b/States/DungeonState.cs b/backend/app/Savor22b/States/DungeonState.cs index da76a49d..d1f2ffc0 100644 --- a/backend/app/Savor22b/States/DungeonState.cs +++ b/backend/app/Savor22b/States/DungeonState.cs @@ -44,6 +44,11 @@ public IValue Serialize() }); } + public int GetDungeonKeyCount(long blockIndex) + { + return MaxDungeonKey - GetCurrentDungeonKeyHistories(blockIndex).Count; + } + public ImmutableList GetCurrentDungeonKeyHistories(long blockIndex) { var lowerBoundIndex = blockIndex - (MaxDungeonKey * DungeonKeyChargeIntervalBlock);