Skip to content

Commit

Permalink
Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Nov 7, 2023
1 parent 37be10a commit f3aba21
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions NineChronicles.Headless/GraphTypes/StateQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,22 @@ public StateQuery()

Field<NonNullGraphType<ArenaInfoResultType>>(
"arenaInfo",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<AddressType>>
{
Name = "avatarAddress"
}),
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AddressType>>
{
Name = "avatarAddress"
},
new QueryArgument<NonNullGraphType<BooleanGraphType>>
{
Name = "filter",
DefaultValue = true,
}
),
resolve: context =>
{
var blockIndex = context.Source.BlockIndex;
var currentAvatarAddr = context.GetArgument<Address>("avatarAddress");
var filter = context.GetArgument<bool>("filter");
var currentRoundData = context.Source.AccountState.GetSheet<ArenaSheet>().GetRoundByBlockIndex(blockIndex);
var participantsAddr = ArenaParticipants.DeriveAddress(
currentRoundData.ChampionshipId,
Expand All @@ -681,7 +689,7 @@ public StateQuery()
currentRoundData.Round)))
.ToArray();
// NOTE: If addresses is too large, and split and get separately.
int playerScore = 0;
int playerScore = ArenaScore.ArenaScoreDefault;
var scores = context.Source.GetStates(
avatarAndScoreAddrList.Select(tuple => tuple.Item2).ToList());
var avatarAddrAndScores = new List<(Address avatarAddr, int score)>();
Expand Down Expand Up @@ -881,6 +889,10 @@ List runeSlotList
? new ArenaAvatarState(iValue2)
: null;
long lastBattleBlockIndex = arenaAvatarState?.LastBattleBlockIndex ?? 0L;
if (filter)
{
result = GetBoundsWithPlayerScore(result, currentRoundData.ArenaType, playerScore);
}
return (result, purchasedCountDuringInterval, lastBattleBlockIndex);
}
);
Expand Down Expand Up @@ -908,5 +920,20 @@ List runeSlotList

return result;
}

private static List<ArenaParticipant> GetBoundsWithPlayerScore(
List<ArenaParticipant> arenaInformation,
ArenaType arenaType,
int playerScore)
{
var bounds = ArenaHelper.ScoreLimits.ContainsKey(arenaType)
? ArenaHelper.ScoreLimits[arenaType]
: ArenaHelper.ScoreLimits.First().Value;

bounds = (bounds.upper + playerScore, bounds.lower + playerScore);
return arenaInformation
.Where(a => a.Score <= bounds.upper && a.Score >= bounds.lower)
.ToList();
}
}
}

0 comments on commit f3aba21

Please sign in to comment.