コード例 #1
0
        // Forgive me father for I have sinned
        // someone replace this horrid code.... maybe loop through types and reflect them all OR circumvent the need for this

        public static Optional <Equipment> GetBasedOnOwnersType(GameObject owner)
        {
            Charger charger = owner.GetComponent <Charger>();

            if (charger != null)
            {
                return(Optional <Equipment> .Of((Equipment)charger.ReflectionGet("equipment")));
            }

            BaseNuclearReactor baseNuclearReactor = owner.GetComponent <BaseNuclearReactor>();

            if (baseNuclearReactor != null)
            {
                return(Optional <Equipment> .Of((Equipment)baseNuclearReactor.ReflectionGet("_equipment")));
            }

            CyclopsDecoyLoadingTube cyclopsDecoyLoadingTube = owner.GetComponent <CyclopsDecoyLoadingTube>();

            if (cyclopsDecoyLoadingTube != null)
            {
                return(Optional <Equipment> .Of(cyclopsDecoyLoadingTube.decoySlots));
            }

            Exosuit exosuit = owner.GetComponent <Exosuit>();

            if (exosuit != null)
            {
                return(Optional <Equipment> .Of(exosuit.modules));
            }

            SeaMoth seamoth = owner.GetComponent <SeaMoth>();

            if (seamoth != null)
            {
                return(Optional <Equipment> .Of(seamoth.modules));
            }

            UpgradeConsole upgradeConsole = owner.GetComponent <UpgradeConsole>();

            if (upgradeConsole != null)
            {
                return(Optional <Equipment> .Of(upgradeConsole.modules));
            }

            Vehicle vehicle = owner.GetComponent <Vehicle>();

            if (vehicle != null)
            {
                return(Optional <Equipment> .Of(vehicle.modules));
            }

            VehicleUpgradeConsoleInput vehicleUpgradeConsoleInput = owner.GetComponent <VehicleUpgradeConsoleInput>();

            if (vehicleUpgradeConsoleInput != null)
            {
                return(Optional <Equipment> .Of(vehicleUpgradeConsoleInput.equipment));
            }

            return(Optional <Equipment> .Empty());
        }
コード例 #2
0
        protected float GetNuclearReactorAvailableCharge(BaseNuclearReactor reactor)
        {
            if (BaseNuclearReactor_charge == null)
            {
                BaseNuclearReactor_charge = typeof(BaseNuclearReactor).GetField("charge", BindingFlags.NonPublic | BindingFlags.Static);
            }

            Dictionary <TechType, float> chargeValues = (Dictionary <TechType, float>)BaseNuclearReactor_charge.GetValue(null);
            Equipment items = GetNuclearReactorItems(reactor);

            var   e   = items.GetEquipment();
            float sum = 0;

            while (e.MoveNext())
            {
                if (e.Current.Value == null)
                {
                    continue;
                }

                Pickupable item            = e.Current.Value.item;
                TechType   techType        = item.GetTechType();
                float      itemChargeValue = 0;
                if (chargeValues.TryGetValue(techType, out itemChargeValue))
                {
                    sum += itemChargeValue;
                }
            }

            return(sum - reactor._toConsume);
        }
コード例 #3
0
        protected Equipment GetNuclearReactorItems(BaseNuclearReactor reactor)
        {
            if (BaseNuclearReactor_get_equipment == null)
            {
                BaseNuclearReactor_get_equipment = typeof(BaseNuclearReactor).GetMethod("get_equipment", BindingFlags.NonPublic | BindingFlags.Instance);
            }

            return((Equipment)BaseNuclearReactor_get_equipment.Invoke(reactor, new object[] { }));
        }
コード例 #4
0
ファイル: Mod.cs プロジェクト: snoopybeegle/Subnautica-Mods-2
        public static bool Prefix(BaseNuclearReactor __instance, float __result, float requested)
        {
            string[]  slotIDs   = Values.GetValue <BaseNuclearReactor>("slotIDs") as string[];
            Equipment equipment = Values.GetValue(__instance, "equipment") as Equipment;
            Dictionary <TechType, float> charge = Values.GetValue <BaseNuclearReactor>("charge") as Dictionary <TechType, float>;

            GameObject    prefabForTechType = CraftData.GetPrefabForTechType(TechType.DepletedReactorRod, true);
            GameObject    gameObject        = Object.Instantiate <GameObject>(prefabForTechType);
            Pickupable    pickupable        = gameObject.GetComponent <Pickupable>().Pickup(false);
            InventoryItem depletedRod       = new InventoryItem(pickupable);

            float num = 0f;

            if (requested > 0f)
            {
                __instance._toConsume += requested;
                num = requested;
                int num2 = 0;
                for (int i = 0; i < slotIDs.Length; i++)
                {
                    string        slot       = slotIDs[i];
                    InventoryItem itemInSlot = equipment.GetItemInSlot(slot);
                    if (itemInSlot != null)
                    {
                        Pickupable item = itemInSlot.item;
                        if (item != null)
                        {
                            TechType techType = item.GetTechType();
                            if (charge.TryGetValue(techType, out float num3))
                            {
                                if (__instance._toConsume < num3)
                                {
                                    num2++;
                                }
                                else
                                {
                                    __instance._toConsume -= num3;
                                    InventoryItem inventoryItem = equipment.RemoveItem(slot, true, false);
                                    Object.Destroy(inventoryItem.item.gameObject);
                                    equipment.AddItem(slot, depletedRod, true);
                                }
                            }
                        }
                    }
                }
                if (num2 == 0)
                {
                    num -= __instance._toConsume;
                    __instance._toConsume = 0f;
                }
            }
            __result = num;
            return(false);
        }
コード例 #5
0
 internal static void Postfix(BaseNuclearReactor __instance)
 {
     __instance._powerSource.maxPower = Mathf.Max(maxPower, 0);
 }
コード例 #6
0
        internal static void Postfix(BaseNuclearReactor __instance)
        {
            float powerDelta = __instance._powerSource.power - powerLevel;

            __instance._powerSource.SetPower(powerLevel + powerDelta * powerModifier);
        }
コード例 #7
0
 internal static void Prefix(BaseNuclearReactor __instance)
 {
     powerLevel = __instance._powerSource.power;
 }
コード例 #8
0
 public NuclearReactorPowerSourceInfo(PowerSource source) : base(source, TechType.BaseNuclearReactor)
 {
     reactor = source.GetComponent <BaseNuclearReactor>();
 }