Пример #1
0
        public static void Postfix(PowerRelay __instance, ref bool __result, ref float amount, ref float modified)
        {
            if (__result)
            {
                return;
            }
            var powerInterface = __instance.inboundPowerSources.Find((x) => x is BaseInboundRelay or OtherConnectionRelay);

            var powerControl = powerInterface switch
            {
                BaseInboundRelay baseConnectionRelay => baseConnectionRelay.gameObject.GetComponent <PowerControl>(),
                OtherConnectionRelay otherConnectionRelay => otherConnectionRelay.gameObject.GetComponent <PowerControl>(),
                _ => null
            };

            if (powerControl is null)
            {
                return;
            }
            var endRelay = powerControl.Relay.GetEndpoint();

            if (!(endRelay.GetMaxPower() > powerInterface.GetMaxPower()))
            {
                return;
            }
            __result  = endRelay.ModifyPowerFromInbound(amount, out var newModified);
            modified += newModified;
        }
    }
        public static void Postfix(PowerRelay __instance, ref float __result)
        {
            var powerInterface = __instance.inboundPowerSources.Find((x) => x is BaseInboundRelay or OtherConnectionRelay);
            var powerControl   = powerInterface switch
            {
                BaseInboundRelay baseConnectionRelay => baseConnectionRelay.gameObject.GetComponent <PowerControl>(),
                OtherConnectionRelay otherConnectionRelay => otherConnectionRelay.gameObject.GetComponent <PowerControl>(),
                _ => null
            };

            if (powerControl is null)
            {
                return;
            }

            var endRelay  = powerControl.Relay.GetEndpoint();
            var endPower  = endRelay.GetMaxPower();
            var powerHere = powerInterface.GetMaxPower();

            if (endPower > powerHere)
            {
                __result += endPower - powerHere;
            }
        }
    }
        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;
                    }
                }
            }
        }