diff --git a/Refresh.GameServer/Database/GameDatabaseContext.cs b/Refresh.GameServer/Database/GameDatabaseContext.cs index 408dd7f2..5bdd216b 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.cs @@ -75,13 +75,21 @@ private int GetOrCreateSequentialId() where T : IRealmObject, ISequentialId storage.SequentialId += 1; return storage.SequentialId; } + + int objectCount = this._realm.All().Count(); storage = new SequentialIdStorage { TypeName = name, - SequentialId = this._realm.All().Count() * 2, // skip over a bunch of ids incase table is broken }; + if (objectCount != 0) + storage.SequentialId = this._realm.All() + .AsEnumerable() // because realm. + .Max(t => t.SequentialId) + 1; + else + storage.SequentialId = 0; + // no need to do write block, this should only be called in a write transaction this.SequentialIdStorage.Add(storage); diff --git a/Refresh.GameServer/Database/ISequentialId.cs b/Refresh.GameServer/Database/ISequentialId.cs index 44892663..2616a782 100644 --- a/Refresh.GameServer/Database/ISequentialId.cs +++ b/Refresh.GameServer/Database/ISequentialId.cs @@ -2,5 +2,5 @@ namespace Refresh.GameServer.Database; public interface ISequentialId { - int SequentialId { set; } + int SequentialId { get; set; } } \ No newline at end of file diff --git a/Refresh.GameServer/Types/Levels/GameLevel.cs b/Refresh.GameServer/Types/Levels/GameLevel.cs index af994f11..d67e5de4 100644 --- a/Refresh.GameServer/Types/Levels/GameLevel.cs +++ b/Refresh.GameServer/Types/Levels/GameLevel.cs @@ -127,6 +127,7 @@ public GameSkillReward[] SkillRewards public int SequentialId { + get => this.LevelId; set => this.LevelId = value; } diff --git a/Refresh.GameServer/Types/Photos/GamePhoto.cs b/Refresh.GameServer/Types/Photos/GamePhoto.cs index 5a0cdf06..d5a409a0 100644 --- a/Refresh.GameServer/Types/Photos/GamePhoto.cs +++ b/Refresh.GameServer/Types/Photos/GamePhoto.cs @@ -139,6 +139,7 @@ private void ClearSubjects() [JsonIgnore] public int SequentialId { + get => this.PhotoId; set => this.PhotoId = value; } } \ No newline at end of file diff --git a/Refresh.GameServer/Types/Reviews/GameReview.cs b/Refresh.GameServer/Types/Reviews/GameReview.cs index e672c25a..6ab1461a 100644 --- a/Refresh.GameServer/Types/Reviews/GameReview.cs +++ b/Refresh.GameServer/Types/Reviews/GameReview.cs @@ -23,6 +23,7 @@ public partial class GameReview : IRealmObject, ISequentialId public int SequentialId { + get => this.ReviewId; set => this.ReviewId = value; } } \ No newline at end of file