Esempio n. 1
0
 private static void Postfix(PowerRelay __instance, IPowerInterface powerInterface)
 {
     try
     {
         if (!Main.config.doSort)
         {
             return;
         }
         List <IPowerInterface> info = __instance.inboundPowerSources;
         List <IPowerInterface> test = new List <IPowerInterface>(info);
         test.Sort((i, i2) =>
         {
             UnityEngine.MonoBehaviour p  = (UnityEngine.MonoBehaviour)i;
             UnityEngine.MonoBehaviour p2 = (UnityEngine.MonoBehaviour)i2;
             int pn  = GetOrderNumber(p.gameObject.name);
             int p2n = GetOrderNumber(p2.gameObject.name);
             return(Math.Sign(pn - p2n));
         });
         __instance.inboundPowerSources = test;
         Main.config.doSort             = false;
     }
     catch (Exception e)
     {
         Logger.Log(Logger.Level.Error, ex: e);
     }
 }
        public static void Postfix(PowerRelay __instance, ref float __result)
        {
            IPowerInterface powerInterface = __instance.inboundPowerSources.Find((x) => x is BaseInboundRelay || x is OtherConnectionRelay);

            if (powerInterface != null)
            {
                PowerControl powerControl = null;
                switch (powerInterface)
                {
                case BaseInboundRelay baseConnectionRelay:
                    powerControl = baseConnectionRelay.gameObject.GetComponent <PowerControl>();
                    break;

                case OtherConnectionRelay otherConnectionRelay:
                    powerControl = otherConnectionRelay.gameObject.GetComponent <PowerControl>();
                    break;
                }

                PowerRelay endRelay = powerControl.powerRelay.GetEndpoint();

                float endPower  = endRelay.GetMaxPower();
                float powerHere = powerInterface.GetMaxPower();

                if (endPower > powerHere)
                {
                    __result += endPower - powerHere;
                }
            }
        }
Esempio n. 3
0
        public static void Postfix(PowerRelay __instance, ref bool __result, ref float amount, ref float modified)
        {
            if (!__result)
            {
                IPowerInterface powerInterface = __instance.inboundPowerSources.Find((x) => x is BaseInboundRelay || x is OtherConnectionRelay);

                if (powerInterface != null)
                {
                    PowerControl powerControl = null;
                    switch (powerInterface)
                    {
                    case BaseInboundRelay baseConnectionRelay:
                        powerControl = baseConnectionRelay.gameObject.GetComponent <PowerControl>();
                        break;

                    case OtherConnectionRelay otherConnectionRelay:
                        powerControl = otherConnectionRelay.gameObject.GetComponent <PowerControl>();
                        break;
                    }

                    PowerRelay endRelay = powerControl.powerRelay.GetEndpoint();

                    if (endRelay.GetMaxPower() > powerInterface.GetMaxPower())
                    {
                        __result  = endRelay.ModifyPowerFromInbound(amount, out float newModified);
                        modified += newModified;
                    }
                }
            }
        }
        private PowerSource TryGetPowerSource(IPowerInterface power)
        {
            PowerSource source = power as PowerSource;

            if (source == null && (power as Component) != null)
            {
                source = (power as Component).gameObject.GetComponent <PowerSource>();
            }
            return(source);
        }
        private BatterySource TryGetBatterySource(IPowerInterface power)
        {
            BatterySource source = power as BatterySource;

            if (source == null && (power as Component) != null)
            {
                source = (power as Component).gameObject.GetComponent <BatterySource>();
            }
            return(source);
        }
Esempio n. 6
0
 private static void Prefix(PowerRelay __instance, IPowerInterface powerInterface)
 {
     try
     {
         if (__instance?.inboundPowerSources == null || __instance.inboundPowerSources.Contains(powerInterface))
         {
             return;
         }
         Logger.Log(Logger.Level.Debug, $"{Regex.Replace(__instance.gameObject.name, @"\(.*?\)", "")} AddInboundPower: {Regex.Replace(powerInterface.GetType().Name, @"\(.*?\)", "")}");
         Main.config.doSort = true;
     }
     catch (Exception e)
     {
         Logger.Log(Logger.Level.Error, ex: e);
     }
 }
Esempio n. 7
0
        /**
         * Gets the transform/location of a power interface.
         */
        private static UnityEngine.Transform GetTransform(IPowerInterface powerInterface)
        {
            if (powerInterface is BatterySource)
            {
                return(((BatterySource)powerInterface).transform);
            }
            else if (powerInterface is PowerSource)
            {
                return(((PowerSource)powerInterface).transform);
            }
            else if (powerInterface is PowerRelay)
            {
                return(((PowerRelay)powerInterface).transform);
            }

            return(null);
        }
Esempio n. 8
0
        public static bool ConsumeEnergyBase(ref IPowerInterface powerInterface, ref float amount, bool __result)
        {
            amount = AdjustConsumeEnergy(amount, isPowerInRadiation(powerInterface), powerInterface is BasePowerRelay);

            // In vanilla if you try to use 5 power from your Fabricator but you only have 4 power, then you not only
            // fail but also lose your 4 power. That was already a little bit irritating, but it becomes grotesque and
            // feels unfair when power requirements are e.g. 15. This next block prevents the not-actually-enough power
            // from being lost, merely doesn't produce the item.
            if (DeathRun.craftingSemaphore && (powerInterface.GetPower() < amount))
            {
                ErrorMessage.AddMessage("Not Enough Power");
                __result = false;
                return(false);
            }

            return(true);
        }
        // IPowerAssignmentInterface
        public void SetPower(IPowerInterface inPower, EPowerSetting inPowerSetting)
        {
            var newStatus = new PowerStatus(inPower, inPower.CanActivatePower(gameObject));

            if (_registeredPowers.ContainsKey(inPowerSetting))
            {
                _registeredPowers[inPowerSetting].CurrentPower.OnPowerCleared();
                _registeredPowers[inPowerSetting] = newStatus;
            }
            else
            {
                _registeredPowers.Add(inPowerSetting, newStatus);
            }

            inPower.OnPowerSet(gameObject);

            UnityMessageEventFunctions.InvokeMessageEventWithDispatcher(gameObject, new PowerSetMessage(inPower, inPowerSetting));
            UnityMessageEventFunctions.InvokeMessageEventWithDispatcher(gameObject, new PowerUpdateMessage(inPowerSetting, newStatus.Activatable, inPower.GetPowerCooldownPercentage()));
        }
        public static void Postfix(ref PowerRelay __result)
        {
            PowerControl powerControl;
            bool         isCyclops = __result?.gameObject.name.Contains("Cyclops") ?? false;

            if (__result != null && (__result is BasePowerRelay || isCyclops))
            {
                IPowerInterface powerInterface = __result.inboundPowerSources.Where((x) => x is BaseInboundRelay)?.FirstOrFallback(null);

                if (powerInterface is null)
                {
                    powerControl = UWE.Utils.GetEntityRoot(__result.gameObject).GetComponentInChildren <PowerControl>();

                    if (powerControl?.powerRelay != null && !powerControl.powerRelay.dontConnectToRelays)
                    {
                        if (isCyclops)
                        {
                            __result.AddInboundPower(powerControl.powerRelay);
                        }
                        __result = powerControl.powerRelay;
                        return;
                    }
                    return;
                }

                BaseInboundRelay baseInboundRelay = powerInterface as BaseInboundRelay;

                if (baseInboundRelay.gameObject.TryGetComponent(out powerControl))
                {
                    if (powerControl?.powerRelay != null && !powerControl.powerRelay.dontConnectToRelays)
                    {
                        if (isCyclops)
                        {
                            __result.AddInboundPower(powerControl.powerRelay);
                        }
                        __result = powerControl.powerRelay;
                        return;
                    }
                }
            }
        }
Esempio n. 11
0
 public PowerSetMessage(IPowerInterface inPowerInterface, EPowerSetting inPowerSetting)
     : base()
 {
     PowerInterface = inPowerInterface;
     PowerSetting   = inPowerSetting;
 }
 public static void AddEnergyBase(ref IPowerInterface powerInterface, ref float amount)
 {
     AddEnergy(GetTransform(powerInterface), ref amount);
 }
Esempio n. 13
0
 /**
  * @return true if the power interface is currently in radiation
  */
 private static bool isPowerInRadiation(IPowerInterface powerInterface)
 {
     return(isTransformInRadiation(GetTransform(powerInterface)));
 }
 public bool GetInboundHasSource(IPowerInterface powerInterface)
 {
     return(false);
 }
 public bool HasInboundPower(IPowerInterface powerInterface)
 {
     return(false);
 }
 public GenericPowerSourceInfo(IPowerInterface source, string displayOverride = null) : base(null, TechType.None)
 {
     iSource = source;
     this.displayOverride = displayOverride;
 }
        private PowerRelay TryGetPowerRelay(IPowerInterface power)
        {
            PowerRelay relay = power as PowerRelay;

            return(relay);
        }
Esempio n. 18
0
 public void SetPower(IPowerInterface inPower, EPowerSetting inPowerSetting)
 {
     SetPowerInterface = inPower;
     SetPowerSetting   = inPowerSetting;
 }
 private void AddGenericPowerEntry(IPowerInterface source)
 {
     powerSources.Add(new GenericPowerSourceInfo(source));
 }
Esempio n. 20
0
 public static bool AddEnergyBase(ref IPowerInterface powerInterface, ref float amount)
 {
     amount = AdjustAddEnergy(amount, isPowerInRadiation(powerInterface));
     return(true);
 }
 public PowerStatus(IPowerInterface inPower, bool inActivatable)
 {
     CurrentPower = inPower;
     Activatable  = inActivatable;
 }