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);