Skip to content

Commit

Permalink
feat: Add dungeon key count Subscription field
Browse files Browse the repository at this point in the history
  • Loading branch information
upa-r-upa committed Mar 11, 2024
1 parent d613778 commit 512e686
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions backend/app/Savor22b/GraphTypes/Types/DungeonStateType.cs
Original file line number Diff line number Diff line change
@@ -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<DungeonState>
{
public DungeonStateType(
BlockChain blockChain,
BlockRenderer blockRenderer,
IStore store,
Swarm? swarm = null
)
{
Field<NonNullGraphType<IntGraphType>>(
name: "DungeonKeyCount",
description: "The number of dungeon keys the user has.",
resolve: context => context.Source.GetDungeonKeyCount(blockChain.Count)
);
}
}
5 changes: 5 additions & 0 deletions backend/app/Savor22b/GraphTypes/Types/UserStateType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ public UserStateType()
description: "The village state of the user.",
resolve: context => context.Source.VillageState
);
Field<NonNullGraphType<DungeonStateType>>(
name: "dungeonState",
description: "The dungeon state of the user.",
resolve: context => context.Source.DungeonState
);
}
}
5 changes: 5 additions & 0 deletions backend/app/Savor22b/States/DungeonState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public IValue Serialize()
});
}

public int GetDungeonKeyCount(long blockIndex)
{
return MaxDungeonKey - GetCurrentDungeonKeyHistories(blockIndex).Count;
}

public ImmutableList<DungeonKeyHistory> GetCurrentDungeonKeyHistories(long blockIndex)
{
var lowerBoundIndex = blockIndex - (MaxDungeonKey * DungeonKeyChargeIntervalBlock);
Expand Down

0 comments on commit 512e686

Please sign in to comment.