From 954bcd8ccadd7364f25f6d8caff9f6e775aa3382 Mon Sep 17 00:00:00 2001 From: sven-n Date: Thu, 11 Jul 2024 18:32:19 +0200 Subject: [PATCH] Ignore and log invalid items --- src/GameLogic/Player.cs | 31 +++++++++++++++++++++++++++++++ src/GameLogic/Storage.cs | 3 ++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/GameLogic/Player.cs b/src/GameLogic/Player.cs index c2899a6e2..d824fbaef 100644 --- a/src/GameLogic/Player.cs +++ b/src/GameLogic/Player.cs @@ -213,6 +213,7 @@ public Account? Account this._accountLoggingScope?.Dispose(); this._accountLoggingScope = this.Logger.BeginScope("Account: {Name}", this._account!.LoginName); this.IsVaultLocked = !string.IsNullOrWhiteSpace(this._account.VaultPassword); + this.LogInvalidVaultItems(); } } } @@ -1829,6 +1830,8 @@ private async ValueTask OnPlayerEnteredWorldAsync() this.AddMissingStatAttributes(); this.Attributes = new ItemAwareAttributeSystem(this.Account!, this.SelectedCharacter!); + this.LogInvalidInventoryItems(); + this.Inventory = new InventoryStorage(this, this.GameContext); this.ShopStorage = new ShopStorage(this); this.TemporaryStorage = new Storage(InventoryConstants.TemporaryStorageSize, new TemporaryItemStorage()); @@ -1879,6 +1882,34 @@ await this.MagicEffectList.AddEffectAsync(new MagicEffect( } } + private void LogInvalidVaultItems() + { + var invalidItems = this.Account?.Vault?.Items.Where(i => i.Definition is null); + if (invalidItems is null) + { + return; + } + + foreach (var item in invalidItems) + { + this.Logger.LogWarning("Account {name} has item without definition in vault, Slot: {slot}, ID: {id}", this.Account?.LoginName, item.ItemSlot, item.GetId()); + } + } + + private void LogInvalidInventoryItems() + { + var invalidItems = this.SelectedCharacter?.Inventory?.Items.Where(i => i.Definition is null); + if (invalidItems is null) + { + return; + } + + foreach (var item in invalidItems) + { + this.Logger.LogWarning("Character {name} has item without definition in inventory, Slot: {slot}, ID: {id}", this.SelectedCharacter?.Name, item.ItemSlot, item.GetId()); + } + } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "Catching all Exceptions.")] private async void OnTransformationSkinChanged(object? sender, EventArgs args) { diff --git a/src/GameLogic/Storage.cs b/src/GameLogic/Storage.cs index 2558dbb5b..64d6c0047 100644 --- a/src/GameLogic/Storage.cs +++ b/src/GameLogic/Storage.cs @@ -46,6 +46,7 @@ public Storage(int numberOfSlots, int boxOffset, int slotOffset, ItemStorage ite List? unfittingItems = null; this.ItemStorage.Items .Where(item => item.ItemSlot <= lastSlot && item.ItemSlot >= slotOffset) + .Where(item => item.Definition is not null) .ForEach(item => { if (!this.AddItemInternal((byte)(item.ItemSlot - slotOffset), item)) @@ -58,7 +59,7 @@ public Storage(int numberOfSlots, int boxOffset, int slotOffset, ItemStorage ite { return; } - + // we first try to add them. for (var index = unfittingItems.Count - 1; index >= 0; index--) {