public void StoreContent(Item source) { PrintDebug("Removing content for an item"); var contents = source.contents?.itemList; if (contents != null) { for (var i = contents.Count - 1; i >= 0; i--) { var item = contents[i]; item.parent = null; contents.RemoveAt(i); _storedContent.Add(item); } } var magazine = (source.GetHeldEntity() as BaseProjectile)?.primaryMagazine; _storedMagazine = magazine?.Save(); if (magazine != null) // Just in case so they won't be able to take out the ammo { magazine.contents = 0; } }
public void SetupContent(Item destination) { PrintDebug("Setting up content for an item"); if (destination == null) { PrintDebug("Destination is null!"); return; } if (_storedMagazine != null) { (destination.GetHeldEntity() as BaseProjectile)?.primaryMagazine?.Load(_storedMagazine); _storedMagazine = null; } var contents = destination.contents?.itemList; if (contents == null) { PrintDebug("// Contents null"); return; } for (var i = _storedContent.Count - 1; i >= 0; i--) { var item = _storedContent[i]; item.parent = destination.contents; item.RemoveFromWorld(); _storedContent.RemoveAt(i); contents.Add(item); item.MarkDirty(); foreach (var itemMod in item.info.itemMods) { itemMod.OnParentChanged(item); } } _storedContent.Clear(); }