/// <summary> /// </summary> /// <returns> /// </returns> public bool Read() { foreach (DBItem item in ItemDao.GetAllInContainer((int)this.Identity.Type, this.Identity.Instance)) { Item newItem = new Item(item.quality, item.lowid, item.highid); newItem.SetAttribute(412, item.multiplecount); this.Content.Add(item.containerplacement, newItem); // Make item visible // TODO: Other flags must be set too newItem.Flags |= 0x1; } foreach (DBInstancedItem item in InstancedItemDao.GetAllInContainer((int)this.Identity.Type, this.Identity.Instance)) { Item newItem = new Item(item.quality, item.lowid, item.highid); newItem.SetAttribute(412, item.multiplecount); Identity temp = new Identity(); temp.Type = (IdentityType)item.itemtype; temp.Instance = item.iteminstance; newItem.Identity = temp; byte[] binaryStats = item.stats.ToArray(); for (int i = 0; i < binaryStats.Length / 8; i++) { int statid = BitConverter.ToInt32(binaryStats, i * 8); int statvalue = BitConverter.ToInt32(binaryStats, i * 8 + 4); newItem.SetAttribute(statid, statvalue); } // Make item visible // TODO: Other flags must be set too // Anything -> =0x01 // Containers -> =0x02 // ????? -> |0x20 // ????? -> |0x80 (maybe unique) // Found online: 0xa1 for nano instruction disc // 0x02 for any bag // 0x81 for unique totw rings newItem.Flags |= 0x1; } return(true); }
/// <summary> /// </summary> /// <returns> /// </returns> public bool Write() { List <DBInstancedItem> DBinstanced = new List <DBInstancedItem>(); List <DBItem> DBuninstanced = new List <DBItem>(); foreach (KeyValuePair <int, IItem> kv in this.Content) { if (kv.Value.Identity.Type != IdentityType.None) { DBInstancedItem dbi = new DBInstancedItem { containerinstance = this.Identity.Instance, containertype = (int)this.Identity.Type, containerplacement = kv.Key, itemtype = (int)kv.Value.Identity.Type, iteminstance = kv.Value.Identity.Instance, lowid = kv.Value.LowID, highid = kv.Value.HighID, quality = kv.Value.Quality, multiplecount = kv.Value.MultipleCount, stats = new Binary(kv.Value.GetItemAttributes()) }; DBinstanced.Add(dbi); } else { DBItem dbi = new DBItem { containerinstance = this.Identity.Instance, containertype = (int)this.Identity.Type, containerplacement = kv.Key, lowid = kv.Value.LowID, highid = kv.Value.HighID, quality = kv.Value.Quality, multiplecount = kv.Value.MultipleCount }; DBuninstanced.Add(dbi); } } ItemDao.Save(DBuninstanced); InstancedItemDao.Save(DBinstanced); return(true); }
/// <summary> /// </summary> /// <param name="slotNum"> /// </param> /// <returns> /// </returns> /// <exception cref="NotImplementedException"> /// </exception> public IItem Remove(int slotNum) { // TODO: Item placement switches could cause items to disappear when zoneengine crashes at that moment if (!this.Content.ContainsKey(slotNum)) { throw new ArgumentOutOfRangeException( "No item in slot " + slotNum + " of container " + this.Identity.Type + ":" + this.Identity.Instance); } IItem temp = this.Content[slotNum]; if (temp.Identity.Type == IdentityType.None) { ItemDao.RemoveItem((int)this.Identity.Type, this.Identity.Instance, slotNum); } else { InstancedItemDao.RemoveItem((int)this.Identity.Type, this.Identity.Instance, slotNum); } this.Content.Remove(slotNum); return(temp); }