//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.GameLogic;
///
/// A storage which keeps items backed up - to be able to revert them after cancellation of an action.
///
public class BackupItemStorage
{
private readonly IList<(Item Item, byte Slot)> _initialItemStates;
///
/// Initializes a new instance of the class.
///
/// The item storage.
public BackupItemStorage(ItemStorage itemStorage)
{
var items = new List- ();
items.AddRange(itemStorage.Items);
this.Items = items;
this.Money = itemStorage.Money;
this._initialItemStates = this.Items.Select(item => (item, item.ItemSlot)).ToList();
}
///
/// Gets or sets the items.
///
public ICollection
- Items { get; set; }
///
/// Gets or sets the money.
///
public int Money { get; set; }
///
/// Restores the initial item states.
///
public void RestoreItemStates()
{
this._initialItemStates.ForEach(state => state.Item.ItemSlot = state.Slot);
}
}