diff --git a/src/AttributeSystem/StatAttribute.cs b/src/AttributeSystem/StatAttribute.cs index 4d53cdbff..3f5982035 100644 --- a/src/AttributeSystem/StatAttribute.cs +++ b/src/AttributeSystem/StatAttribute.cs @@ -40,7 +40,7 @@ public StatAttribute(AttributeDefinition definition, float baseValue) { get { - if (this.Definition.MaximumValue.HasValue) + if (this.Definition?.MaximumValue.HasValue is true) { return Math.Min(this.Definition.MaximumValue.Value, this._statValue); } diff --git a/src/Web/Shared/Components/Form/ItemStorageField.razor b/src/Web/Shared/Components/Form/ItemStorageField.razor index 9f7f87b60..c493d47e3 100644 --- a/src/Web/Shared/Components/Form/ItemStorageField.razor +++ b/src/Web/Shared/Components/Form/ItemStorageField.razor @@ -70,10 +70,12 @@ @if (this._selectedItem is null) { + } else { + } @@ -192,4 +194,25 @@ this._selectedItem = item; } } + + private void OnDuplicateItemClickAsync() + { + if (this._selectedItem is null || this.Value is not { } itemStorage) + { + return; + } + + var duplicate = this.PersistenceContext.CreateNew(); + duplicate.AssignValues(this._selectedItem); + + // Place the duplicate in the next available slot after the source item + var occupiedSlots = itemStorage.Items.Select(i => i.ItemSlot).ToHashSet(); + var nextSlot = Enumerable.Range(this._selectedItem.ItemSlot + 1, byte.MaxValue - this._selectedItem.ItemSlot) + .Select(i => (byte)i) + .FirstOrDefault(s => !occupiedSlots.Contains(s)); + duplicate.ItemSlot = nextSlot; + + itemStorage.Items.Add(duplicate); + this._selectedItem = duplicate; + } } diff --git a/src/Web/Shared/Components/Form/ValueListWrapper.cs b/src/Web/Shared/Components/Form/ValueListWrapper.cs index e06407816..242b7ef38 100644 --- a/src/Web/Shared/Components/Form/ValueListWrapper.cs +++ b/src/Web/Shared/Components/Form/ValueListWrapper.cs @@ -64,25 +64,28 @@ public void CopyTo(TValue[] array, int arrayIndex) /// public bool Remove(TValue item) { - if (this._innerList.Remove(item)) + var wrapperIndex = this.FindIndex(v => Equals(v.Value, item)); + if (wrapperIndex >= 0) { - var wrapperIndex = this.FindIndex(v => Equals(v.Value, item)); - if (wrapperIndex >= 0) - { - this[wrapperIndex].PropertyChanged -= this.OnValueChanged; - this.RemoveAt(wrapperIndex); - for (int i = wrapperIndex; i < this._innerList.Count; i++) - { - this[i].Index = i; - } - } - + this.RemoveAt(wrapperIndex); return true; } return false; } + /// + public new void RemoveAt(int index) + { + this[index].PropertyChanged -= this.OnValueChanged; + base.RemoveAt(index); + this._innerList.RemoveAt(index); + for (int i = index; i < this.Count; i++) + { + this[i].Index = i; + } + } + /// public bool IsReadOnly => this._innerList.IsReadOnly;