public void ConnectToInventory(Dictionary <InventoryItem, uGUI_ItemIcon> lookup) { this.InventoryMapping = lookup; (Container as IItemsContainer).onAddItem += OnAddItemLate; if (this.MaterialsProcessing.Count == 0) { return; } foreach (KeyValuePair <InventoryItem, uGUI_ItemIcon> pair in lookup) { InventoryItem item = pair.Key; uGUI_ItemIcon icon = pair.Value; BioEnergy bioEnergy = this.MaterialsProcessing.Find(item.item); if (bioEnergy is null) { QuickLogger.Debug("Matching pickable in bioreactor not found", true); continue; } bioEnergy.AddDisplayText(icon); } }
public void SaveMaterialsProcessing(IList <BioEnergy> materialsInProcessor) { _materials.Values.Clear(); for (int m = 0; m < materialsInProcessor.Count; m++) { BioEnergy item = materialsInProcessor[m]; _materials.Add(new EmModuleSaveData { ItemID = (int)item.Pickupable.GetTechType(), RemainingCharge = item.RemainingEnergy }); } }
public bool UpdateBoosterCount(int boosterCount) { if (boosterCount > MaxBoosters) { return(false); } if (lastKnownBioBooster == boosterCount) { return(false); } var nextStats = ReactorStats.GetStatsForBoosterCount(boosterCount); Battery._capacity = nextStats.Capacity; if (!isLoadingSaveData) { Battery._charge = Mathf.Min(Battery._charge, Battery._capacity); if (lastKnownBioBooster > boosterCount) // Getting smaller { int nextAvailableSpace = nextStats.TotalSpaces; while (this.MaterialsProcessing.SpacesOccupied > nextAvailableSpace) { BioEnergy material = this.MaterialsProcessing.GetCandidateForRemoval(); if (material == null) { break; } QuickLogger.Debug($"Removing material of size {material.Size}", true); this.MaterialsProcessing.Remove(material, Container); } } } Container.Resize(this.StorageWidth = nextStats.Width, this.StorageHeight = nextStats.Height); Container.Sort(); ChargePerSecondPerItem = baselineChargeRate / this.TotalContainerSpaces * 2; lastKnownBioBooster = boosterCount; return(true); }
private void OnAddItemLate(InventoryItem item) { if (this.InventoryMapping is null) { return; } if (this.InventoryMapping.TryGetValue(item, out uGUI_ItemIcon icon)) { BioEnergy bioEnergy = this.MaterialsProcessing.Find(item.item); if (bioEnergy is null) { QuickLogger.Debug("Matching pickable in bioreactor not found", true); return; } bioEnergy.AddDisplayText(icon); } }
private void OnAddItem(InventoryItem item) { item.isEnabled = false; if (isLoadingSaveData) { return; } if (BaseBioReactor.charge.TryGetValue(item.item.GetTechType(), out float bioEnergyValue) && bioEnergyValue > 0f) { var bioenergy = new BioEnergy(item.item, bioEnergyValue, bioEnergyValue) { Size = item.width * item.height }; this.MaterialsProcessing.Add(bioenergy); } else { Destroy(item.item.gameObject); // Failsafe } }