コード例 #1
0
        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());
            };
        }
コード例 #2
0
        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();
            }
        }