Skip to content

Commit

Permalink
Merge pull request #2336 from planetarium/feature/rune-summon
Browse files Browse the repository at this point in the history
Introduce rune summon action query
  • Loading branch information
ipdae authored Dec 4, 2023
2 parents da3c225 + 5753c16 commit 027e866
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
29 changes: 29 additions & 0 deletions NineChronicles.Headless.Tests/GraphTypes/ActionQueryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,5 +1490,34 @@ public async Task ClaimItems(int claimDataCount, bool hasMemo)
Assert.Null(action.Memo);
}
}

[Fact]
public async Task RuneSummon()
{
var random = new Random();
var avatarAddress = new PrivateKey().Address;
var groupId = random.Next(20001, 20002 + 1);
// FIXME: Change 10 to AuraSummon.SummonLimit
var summonCount = random.Next(1, 10 + 1);

var query = $@"{{
runeSummon(
avatarAddress: ""{avatarAddress}"",
groupId: {groupId},
summonCount: {summonCount}
)
}}";

var queryResult = await ExecuteQueryAsync<ActionQuery>(query, standaloneContext: _standaloneContext);
var data = (Dictionary<string, object>)((ExecutionNode)queryResult.Data!).ToValue()!;
var plainValue = _codec.Decode(ByteUtil.ParseHex((string)data["runeSummon"]));
Assert.IsType<Dictionary>(plainValue);
var actionBase = DeserializeNCAction(plainValue);
var action = Assert.IsType<RuneSummon>(actionBase);

Assert.Equal(avatarAddress, action.AvatarAddress);
Assert.Equal(groupId, action.GroupId);
Assert.Equal(summonCount, action.SummonCount);
}
}
}
35 changes: 35 additions & 0 deletions NineChronicles.Headless/GraphTypes/ActionQueryFields/Summon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,40 @@ private void RegisterSummon()
return Encode(context, action);
}
);

Field<NonNullGraphType<ByteStringType>>(
"runeSummon",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AddressType>>
{
Name = "avatarAddress",
Description = "Avatar address to get summoned items"
},
new QueryArgument<NonNullGraphType<IntGraphType>>
{
Name = "groupId",
Description = "Summon group id"
},
new QueryArgument<NonNullGraphType<IntGraphType>>
{
Name = "summonCount",
Description = "Count to summon. Must between 1 and 10."
}
),
resolve: context =>
{
var avatarAddr = context.GetArgument<Address>("avatarAddress");
var groupId = context.GetArgument<int>("groupId");
var summonCount = context.GetArgument<int>("summonCount");
ActionBase action = new RuneSummon
{
AvatarAddress = avatarAddr,
GroupId = groupId,
SummonCount = summonCount,
};
return Encode(context, action);
}
);
}
}

0 comments on commit 027e866

Please sign in to comment.