diff --git a/backend/app/Savor22b/GraphTypes/Types/UserDungeonStateType.cs b/backend/app/Savor22b/GraphTypes/Types/UserDungeonStateType.cs index fc046b17..33baf851 100644 --- a/backend/app/Savor22b/GraphTypes/Types/UserDungeonStateType.cs +++ b/backend/app/Savor22b/GraphTypes/Types/UserDungeonStateType.cs @@ -1,9 +1,12 @@ namespace Savor22b.GraphTypes.Types; +using GraphQL; using GraphQL.Types; +using Libplanet; using Libplanet.Blockchain; using Libplanet.Net; using Libplanet.Store; +using Savor22b.Action.Exceptions; using Savor22b.States; public class UserDungeonStateType : ObjectGraphType @@ -20,5 +23,36 @@ public UserDungeonStateType( description: "The number of dungeon keys the user has.", resolve: context => context.Source.GetDungeonKeyCount(blockChain.Count) ); + + Field( + name: "IsDungeonConquestRewardReceivable", + description: "점령한 던전의 주기적 보상을 받을 수 있는지 여부를 반환합니다. 점령한 던전이 아니라면 null을 반환합니다.", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "dungeonId", + Description = "보상을 받고자 하는 던전(점령한)의 ID", + } + ), + resolve: context => + { + int dungeonId = context.GetArgument("dungeonId"); + + DungeonConquestHistoryState? history = context.Source.CurrentConquestDungeonHistory( + dungeonId + ); + + if (history is null) + { + return null; + } + + return context.Source.IsDungeonConquestRewardReceivable( + dungeonId, + history.BlockIndex, + blockChain.Count + ); + } + ); } } diff --git a/backend/app/Savor22b/States/UserDungeonState.cs b/backend/app/Savor22b/States/UserDungeonState.cs index af5f9672..16f3e374 100644 --- a/backend/app/Savor22b/States/UserDungeonState.cs +++ b/backend/app/Savor22b/States/UserDungeonState.cs @@ -143,6 +143,24 @@ public ImmutableList GetCurrentDungeonHistories(long blockI return result.ToImmutableList(); } + public bool IsDungeonConquestRewardReceivable( + int dungeonId, + long blockIndex, + long currentBlockIndex + ) + { + var history = CurrentConquestDungeonHistory(dungeonId); + + if (history is null) + { + return false; + } + + var count = PresentDungeonPeriodicRewardCount(dungeonId, currentBlockIndex, blockIndex); + + return count > 0; + } + public DungeonConquestHistoryState? CurrentConquestDungeonHistory(int dungeonId) { for (int i = DungeonConquestHistories.Count - 1; i >= 0; i--)