Skip to content

Commit

Permalink
feat: Add periodic dungeon reward check subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
upa-r-upa committed Apr 15, 2024
1 parent 0fe5351 commit 7ae4627
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
34 changes: 34 additions & 0 deletions backend/app/Savor22b/GraphTypes/Types/UserDungeonStateType.cs
Original file line number Diff line number Diff line change
@@ -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<UserDungeonState>
Expand All @@ -20,5 +23,36 @@ public UserDungeonStateType(
description: "The number of dungeon keys the user has.",
resolve: context => context.Source.GetDungeonKeyCount(blockChain.Count)
);

Field<BooleanGraphType>(
name: "IsDungeonConquestRewardReceivable",
description: "점령한 던전의 주기적 보상을 받을 수 있는지 여부를 반환합니다. 점령한 던전이 아니라면 null을 반환합니다.",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<IntGraphType>>
{
Name = "dungeonId",
Description = "보상을 받고자 하는 던전(점령한)의 ID",
}
),
resolve: context =>
{
int dungeonId = context.GetArgument<int>("dungeonId");
DungeonConquestHistoryState? history = context.Source.CurrentConquestDungeonHistory(
dungeonId
);
if (history is null)
{
return null;
}
return context.Source.IsDungeonConquestRewardReceivable(
dungeonId,
history.BlockIndex,
blockChain.Count
);
}
);
}
}
18 changes: 18 additions & 0 deletions backend/app/Savor22b/States/UserDungeonState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ public ImmutableList<DungeonHistoryState> 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--)
Expand Down

0 comments on commit 7ae4627

Please sign in to comment.