public void ExportData(out PartyMemberSnapshot snapshot, out PartyMember data) { snapshot = this._Snapshot; data = this._Data; if (this._Inventory != null) { if (data.Inventory == null) { data.Inventory = new InventoryComponent(); } else { data.Inventory.Items.Clear(); } data.Inventory.Items.AddRange(this._Inventory.RawItems); foreach (var viewModel in this._Inventory.Items) { var bitWriter = new BitWriter(0x1000); InventoryComponent.WriteItemData(bitWriter, viewModel.Data); var rawItem = new InventoryComponent.RawItemData(); rawItem.Id = viewModel.Id; rawItem.DataBytes = bitWriter.GetBytes(); rawItem.DataLength = bitWriter.Position; data.Inventory.Items.Add(rawItem); } } }
public void ImportData(PartyMemberSnapshot snapshot, PartyMember data) { this._Snapshot = snapshot; this._Data = data; if (this._Inventory != null) { if (data.Inventory != null) { foreach (var rawItem in data.Inventory.Items) { if (rawItem.DataBytes == null || rawItem.DataLength == 0) { this._Inventory.RawItems.Add(rawItem); continue; } var bitReader = new BitReader(rawItem.DataBytes, rawItem.DataLength); ItemData item; try { item = InventoryComponent.ReadItemData(bitReader, data.Inventory.ReadVersion); } catch (Exception e) { this._Inventory.RawItems.Add(rawItem); continue; } Items.ItemViewModel viewModel; if (item.GetType() == typeof(ItemData)) { viewModel = new Items.ItemViewModel(rawItem.Id, item); } else if (item.GetType() == typeof(GearItemData)) { viewModel = new Items.GearItemViewModel(rawItem.Id, (GearItemData)item); } else if (item.GetType() == typeof(RangedWeaponItemData)) { viewModel = new Items.RangedWeaponItemViewModel(rawItem.Id, (RangedWeaponItemData)item); } else if (item.GetType() == typeof(PowerItemData)) { viewModel = new Items.PowerItemViewModel(rawItem.Id, (PowerItemData)item); } else { this._Inventory.RawItems.Add(rawItem); continue; } this._Inventory.Items.Add(viewModel); } } } }