Skip to content

Commit

Permalink
Ignore and log invalid items
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-n committed Jul 11, 2024
1 parent e91861c commit 954bcd8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/GameLogic/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion src/GameLogic/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public Storage(int numberOfSlots, int boxOffset, int slotOffset, ItemStorage ite
List<Item>? 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))
Expand All @@ -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--)
{
Expand Down

0 comments on commit 954bcd8

Please sign in to comment.