public void Load(ItemContainer container) { using (TimeWarning.New("ItemContainer.Load", 0.1f)) { this.uid = (uint)container.UID; this.capacity = (int)container.slots; List <Item> itemList = this.itemList; this.itemList = (List <Item>)Pool.GetList <Item>(); this.temperature = (float)container.temperature; this.flags = (ItemContainer.Flag)container.flags; this.allowedContents = container.allowedContents == null ? ItemContainer.ContentsType.Generic : (ItemContainer.ContentsType)container.allowedContents; this.onlyAllowedItem = container.allowedItem != null?ItemManager.FindItemDefinition((int)container.allowedItem) : (ItemDefinition)null; this.maxStackSize = (int)container.maxStackSize; this.availableSlots.Clear(); for (int index = 0; index < ((List <int>)container.availableSlots).Count; ++index) { this.availableSlots.Add((ItemSlot)((List <int>)container.availableSlots)[index]); } using (TimeWarning.New("container.contents", 0.1f)) { using (List <Item> .Enumerator enumerator = ((List <Item>)container.contents).GetEnumerator()) { while (enumerator.MoveNext()) { Item current = enumerator.Current; Item created = (Item)null; foreach (Item obj in itemList) { if ((int)obj.uid == current.UID) { created = obj; break; } } Item obj1 = ItemManager.Load(current, created, this.isServer); if (obj1 != null) { obj1.parent = this; obj1.position = (int)current.slot; this.Insert(obj1); } } } } using (TimeWarning.New("Delete old items", 0.1f)) { foreach (Item obj in itemList) { if (!this.itemList.Contains(obj)) { obj.Remove(0.0f); } } } this.dirty = true; // ISSUE: cast to a reference type Pool.FreeList <Item>((List <M0>&) ref itemList); } }
public void ServerInitialize(Item parentItem, int iMaxCapacity) { this.parent = parentItem; this.capacity = iMaxCapacity; this.uid = 0; this.isServer = true; if ((int)this.allowedContents == 0) { this.allowedContents = ItemContainer.ContentsType.Generic; } this.MarkDirty(); }
public void CreateInventory(bool giveUID) { this.inventory = new ItemContainer(); this.inventory.entityOwner = (BaseEntity)this; this.inventory.allowedContents = this.allowedContents == (ItemContainer.ContentsType) 0 ? ItemContainer.ContentsType.Generic : this.allowedContents; this.inventory.onlyAllowedItem = this.onlyAllowedItem; this.inventory.maxStackSize = this.maxStackSize; this.inventory.ServerInitialize((Item)null, this.numSlots); if (giveUID) { this.inventory.GiveUID(); } this.inventory.onItemAddedRemoved = new Action <Item, bool>(this.OnItemAddedOrRemoved); }
public void CreateInventory(bool giveUID) { this.inventory = new ItemContainer(); this.inventory.entityOwner = (BaseEntity)this; this.inventory.allowedContents = this.allowedContents == (ItemContainer.ContentsType) 0 ? ItemContainer.ContentsType.Generic : this.allowedContents; this.inventory.onlyAllowedItem = this.allowedItem; this.inventory.maxStackSize = this.maxStackSize; this.inventory.ServerInitialize((Item)null, this.inventorySlots); if (giveUID) { this.inventory.GiveUID(); } this.inventory.onDirty += new Action(this.OnInventoryDirty); this.inventory.onItemAddedRemoved = new Action <Item, bool>(this.OnItemAddedOrRemoved); if (this.onlyAcceptCategory == ItemCategory.All) { return; } this.inventory.canAcceptItem = new Func <Item, int, bool>(this.ItemFilter); }
public void Load(ProtoBuf.ItemContainer container) { ItemContainer.ContentsType contentsType; ItemDefinition itemDefinition; using (TimeWarning timeWarning = TimeWarning.New("ItemContainer.Load", 0.1f)) { this.uid = container.UID; this.capacity = container.slots; List <Item> items = this.itemList; this.itemList = Pool.GetList <Item>(); this.temperature = container.temperature; this.flags = (ItemContainer.Flag)container.flags; if (container.allowedContents == 0) { contentsType = ItemContainer.ContentsType.Generic; } else { contentsType = (ItemContainer.ContentsType)container.allowedContents; } this.allowedContents = contentsType; if (container.allowedItem != 0) { itemDefinition = ItemManager.FindItemDefinition(container.allowedItem); } else { itemDefinition = null; } this.onlyAllowedItem = itemDefinition; this.maxStackSize = container.maxStackSize; this.availableSlots.Clear(); for (int i = 0; i < container.availableSlots.Count; i++) { this.availableSlots.Add((ItemSlot)container.availableSlots[i]); } using (TimeWarning timeWarning1 = TimeWarning.New("container.contents", 0.1f)) { foreach (ProtoBuf.Item content in container.contents) { Item item = null; foreach (Item item1 in items) { if (item1.uid != content.UID) { continue; } item = item1; goto Label0; } Label0: item = ItemManager.Load(content, item, this.isServer); if (item == null) { continue; } item.parent = this; item.position = content.slot; this.Insert(item); } } using (timeWarning1 = TimeWarning.New("Delete old items", 0.1f)) { foreach (Item item2 in items) { if (this.itemList.Contains(item2)) { continue; } item2.Remove(0f); } } this.dirty = true; Pool.FreeList <Item>(ref items); } }