public NuclearUpgradeHandler() : base(CyclopsModule.NuclearChargerID, canRecharge: false) { OnBatteryDrained += (BatteryDetails details) => { this.TotalBatteryCapacity -= details.BatteryRef._capacity; Equipment modules = details.ParentEquipment; string slotName = details.SlotName; // Drained nuclear batteries are handled just like how the Nuclear Reactor handles depleated reactor rods InventoryItem inventoryItem = modules.RemoveItem(slotName, true, false); GameObject.Destroy(inventoryItem.item.gameObject); modules.AddItem(slotName, CyclopsModule.SpawnCyclopsModule(CyclopsModule.DepletedNuclearModuleID), true); ErrorMessage.AddMessage(DepletedNuclearModule.DepletedEvent); }; OnFirstTimeMaxCountReached += () => { ErrorMessage.AddMessage(CyclopsModule.MaxNuclearReached()); }; }
public void OnProtoDeserializeObjectTree(ProtobufSerializer serializer) { if (SaveData.Load()) { // Because the items here aren't being serialized with everything else normally, // I've used custom save data to handle whatever gets left in these slots. QuickLogger.Debug("Loading save data"); // The following is a recreation of the essential parts of the Equipment.ResponseEquipment method. foreach (string slot in SlotHelper.SlotNames) { // These slots need to be added before we can add items to them this.Modules.AddSlot(slot); EmModuleSaveData savedModule = SaveData.GetModuleInSlot(slot); if (savedModule.ItemID == 0) // (int)TechType.None { continue; // Nothing here } InventoryItem spanwedItem = CyclopsModule.SpawnCyclopsModule((TechType)savedModule.ItemID); QuickLogger.Debug($"Spawned in {savedModule.ItemID} from save data"); if (spanwedItem is null) { continue; } if (savedModule.RemainingCharge > 0f) // Modules without batteries are stored with a -1 value for charge { spanwedItem.item.GetComponent <Battery>().charge = savedModule.RemainingCharge; } this.Modules.AddItem(slot, spanwedItem, true); } } else { UnlockDefaultModuleSlots(); } }
internal void SetupChargingUpgrades(int maxChargingModules) { UpgradeManager.RegisterOneTimeUseHandlerCreator(() => { QuickLogger.Debug("UpgradeHandler Registered: SolarCharger Upgrade"); SolarCharger = new ChargingUpgradeHandler(CyclopsModule.SolarChargerID) { MaxCount = maxChargingModules }; SolarCharger.OnFirstTimeMaxCountReached += () => { ErrorMessage.AddMessage(CyclopsModule.MaxSolarReached()); }; return(SolarCharger); }); UpgradeManager.RegisterOneTimeUseHandlerCreator(() => { QuickLogger.Debug("UpgradeHandler Registered: SolarChargerMk2 Upgrade"); SolarChargerMk2 = new BatteryUpgradeHandler(CyclopsModule.SolarChargerMk2ID, canRecharge: true) { MaxCount = maxChargingModules }; SolarChargerMk2.OnFirstTimeMaxCountReached += () => { ErrorMessage.AddMessage(CyclopsModule.MaxSolarReached()); }; SolarCharger.SiblingUpgrade = SolarChargerMk2; SolarChargerMk2.SiblingUpgrade = SolarCharger; return(SolarChargerMk2); }); UpgradeManager.RegisterOneTimeUseHandlerCreator(() => { QuickLogger.Debug("UpgradeHandler Registered: ThermalCharger Upgrade"); ThermalCharger = new ChargingUpgradeHandler(TechType.CyclopsThermalReactorModule) { MaxCount = maxChargingModules }; ThermalCharger.OnFirstTimeMaxCountReached += () => { ErrorMessage.AddMessage(CyclopsModule.MaxThermalReached()); }; return(ThermalCharger); }); UpgradeManager.RegisterOneTimeUseHandlerCreator(() => { QuickLogger.Debug("UpgradeHandler Registered: ThermalChargerMk2 Upgrade"); ThermalChargerMk2 = new BatteryUpgradeHandler(CyclopsModule.ThermalChargerMk2ID, canRecharge: true) { MaxCount = maxChargingModules }; ThermalChargerMk2.OnFirstTimeMaxCountReached += () => { ErrorMessage.AddMessage(CyclopsModule.MaxThermalReached()); }; ThermalCharger.SiblingUpgrade = ThermalChargerMk2; ThermalChargerMk2.SiblingUpgrade = ThermalCharger; return(ThermalChargerMk2); }); UpgradeManager.RegisterOneTimeUseHandlerCreator(() => { QuickLogger.Debug("UpgradeHandler Registered: NuclearReactor Upgrade"); NuclearCharger = new NuclearUpgradeHandler() { MaxCount = maxChargingModules }; return(NuclearCharger); }); UpgradeManager.RegisterOneTimeUseHandlerCreator(() => { QuickLogger.Debug("UpgradeHandler Registered: BioBooster Upgrade"); BioBoosters = new BioBoosterUpgradeHandler(); return(BioBoosters); }); }