diff --git a/NineChronicles.Headless.Tests/GraphTypes/States/Models/AvatarStateTypeTest.cs b/NineChronicles.Headless.Tests/GraphTypes/States/Models/AvatarStateTypeTest.cs index ddbd69d8d..ee08b8e96 100644 --- a/NineChronicles.Headless.Tests/GraphTypes/States/Models/AvatarStateTypeTest.cs +++ b/NineChronicles.Headless.Tests/GraphTypes/States/Models/AvatarStateTypeTest.cs @@ -94,6 +94,39 @@ public async Task QueryWithCombinationSlotState(AvatarState avatarState, Diction Assert.Equal(expected, data); } + [Theory] + [MemberData(nameof(ActionPointMembers))] + public async Task QueryActionPoint(bool modern, Dictionary expected) + { + const string query = @" + { + actionPoint + dailyRewardReceivedIndex + }"; + IWorld mockWorld = new World(MockWorldState.CreateModern()); + mockWorld = mockWorld.SetAvatarState( + Fixtures.AvatarAddress, + Fixtures.AvatarStateFX, + true, + true, + true, + true); + mockWorld = mockWorld.SetAgentState(Fixtures.UserAddress, Fixtures.AgentStateFx); + if (modern) + { + mockWorld = mockWorld.SetDailyRewardReceivedBlockIndex(Fixtures.AvatarAddress, 1L) + .SetActionPoint(Fixtures.AvatarAddress, 5); + } + var queryResult = await ExecuteQueryAsync( + query, + source: new AvatarStateType.AvatarStateContext( + Fixtures.AvatarStateFX, + mockWorld, + 0, new StateMemoryCache())); + var data = (Dictionary)((ExecutionNode)queryResult.Data!).ToValue()!; + Assert.Equal(expected, data); + } + public static IEnumerable Members => new List { new object[] @@ -128,5 +161,27 @@ public async Task QueryWithCombinationSlotState(AvatarState avatarState, Diction } } }; + + public static IEnumerable ActionPointMembers = new List() + { + new object[] + { + false, + new Dictionary + { + ["actionPoint"] = Fixtures.AvatarStateFX.actionPoint, + ["dailyRewardReceivedIndex"] = Fixtures.AvatarStateFX.dailyRewardReceivedIndex, + } + }, + new object[] + { + true, + new Dictionary + { + ["actionPoint"] = 5, + ["dailyRewardReceivedIndex"] = 1L, + } + } + }; } } diff --git a/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs b/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs index 8e5e15fe7..eb5211594 100644 --- a/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs +++ b/NineChronicles.Headless/GraphTypes/States/AvatarStateType.cs @@ -46,7 +46,18 @@ public AvatarStateType() Field>( nameof(AvatarState.dailyRewardReceivedIndex), description: "Block index at the DailyReward execution.", - resolve: context => context.Source.AvatarState.dailyRewardReceivedIndex); + resolve: context => + { + try + { + return context.Source.WorldState.GetDailyRewardReceivedBlockIndex(context.Source.AvatarState + .address); + } + catch (FailedLoadStateException) + { + return context.Source.AvatarState.dailyRewardReceivedIndex; + } + }); Field>( nameof(AvatarState.agentAddress), description: "Address of agent.", @@ -86,7 +97,17 @@ public AvatarStateType() Field>( nameof(AvatarState.actionPoint), description: "Current ActionPoint.", - resolve: context => context.Source.AvatarState.actionPoint); + resolve: context => + { + try + { + return context.Source.WorldState.GetActionPoint(context.Source.AvatarState.address); + } + catch (FailedLoadStateException) + { + return context.Source.AvatarState.actionPoint; + } + }); Field>( nameof(AvatarState.ear), description: "Index of ear color.",