Lucky dip improvements

This commit is contained in:
jvyden 2021-11-10 00:29:43 -05:00
commit 4373c23ff4
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -1,5 +1,6 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Serialization;
@ -115,15 +116,19 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (token == null) return this.BadRequest(); if (token == null) return this.BadRequest();
GameVersion gameVersion = token.GameVersion; GameVersion gameVersion = token.GameVersion;
int slotCount = await this.database.Slots.Where(s => s.GameVersion <= gameVersion).CountAsync();
pageSize = Math.Min(pageSize, 30);
int skipCount = new Random().Next(seed, slotCount) + pageStart - 1;
// TODO: Incorporate seed? // TODO: Incorporate seed?
IOrderedEnumerable<Slot> slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion) IEnumerable<Slot> slots = this.database.Slots.Where(s => s.GameVersion <= gameVersion)
.Include(s => s.Creator) .Include(s => s.Creator)
.Include(s => s.Location) .Include(s => s.Location)
.Skip(pageStart - 1) .Skip(skipCount)
.Take(Math.Min(pageSize, 30)) .Take(pageSize)
.AsEnumerable() .AsEnumerable();
.OrderBy(_ => Guid.NewGuid());
string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize()); string response = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "hint_start", pageStart + Math.Min(pageSize, 30))); return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "hint_start", pageStart + Math.Min(pageSize, 30)));