예제 #1
0
        public static bool Prefix(TechLight __instance, ref PowerRelay __result, GameObject fromObject)
        {
            PowerRelay result = null;
            float      num    = float.MaxValue;

            for (int i = 0; i < PowerRelay.relayList.Count; i++)
            {
                PowerRelay powerRelay = PowerRelay.relayList[i];
                if (powerRelay is OtherConnectionRelay && powerRelay.gameObject.activeInHierarchy && powerRelay.enabled && !powerRelay.dontConnectToRelays && !(Builder.GetGhostModel() == powerRelay.gameObject))
                {
                    float magnitude = (powerRelay.GetConnectPoint(fromObject.transform.position) - fromObject.transform.position).magnitude;
                    if (magnitude <= TechLight.connectionDistance && magnitude < num)
                    {
                        num    = magnitude;
                        result = powerRelay;
                    }
                }
            }

            if (result != null)
            {
                __result = result;
                return(false);
            }

            return(true);
        }
예제 #2
0
        public static bool testDistance(PowerRelay relay)
        {
            Vector3 connectPoint = relay.GetConnectPoint();

            if ((relay.outboundRelay.GetConnectPoint(connectPoint) - connectPoint).sqrMagnitude < (relay.maxOutboundDistance * relay.maxOutboundDistance))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void LateUpdate()
        {
#if SN1
            if (subRoot != null && subRoot.name.Contains("Cyclops") && GameModeUtils.RequiresPower())
            {
                float chargeNeeded = (subRoot.powerRelay.GetMaxPower() - subRoot.powerRelay.GetPower());
                subRoot.powerRelay.AddEnergy(chargeNeeded, out float amountStored);
                powerRelay.GetEndpoint().ConsumeEnergy(amountStored, out float amountConsumed);

                if (amountStored > amountConsumed)
                {
                    subRoot.powerRelay.ConsumeEnergy(amountStored - amountConsumed, out _);
                }
            }
#elif BZ
            if (truckSegment?.relay != null && GameModeUtils.RequiresPower())
            {
                float chargeNeeded = (truckSegment.relay.GetMaxPower() - truckSegment.relay.GetPower());
                truckSegment.relay.AddEnergy(chargeNeeded, out float amountStored);
                powerRelay.GetEndpoint().ConsumeEnergy(amountStored, out float amountConsumed);

                if (amountStored > amountConsumed)
                {
                    truckSegment.relay.ConsumeEnergy(amountStored - amountConsumed, out _);
                }
            }
#endif
            if (vehicle?.energyInterface != null && GameModeUtils.RequiresPower())
            {
                vehicle.energyInterface.GetValues(out float charge, out float capacity);
                float chargeNeeded = (capacity - charge);
                float amountStored = vehicle.energyInterface.AddEnergy(chargeNeeded);
                powerRelay.GetEndpoint().ConsumeEnergy(amountStored, out float amountConsumed);

                if (amountStored > amountConsumed)
                {
                    vehicle.energyInterface.ConsumeEnergy(amountStored - amountConsumed);
                }
            }


            powerRelay.maxOutboundDistance = Main.config.BlueBeamRange;

            if (powerRelay.outboundRelay != null)
            {
                Vector3 position1 = powerRelay.GetConnectPoint(powerRelay.outboundRelay.GetConnectPoint(powerRelay.GetConnectPoint(powerRelay.outboundRelay.GetConnectPoint())));
                Vector3 position2 = powerRelay.outboundRelay.GetConnectPoint(position1);

                if (Vector3.Distance(position1, position2) > powerRelay.maxOutboundDistance)
                {
                    powerRelay.DisconnectFromRelay();
                    return;
                }

                if (Main.config.LOSBlue && Physics.Linecast(position1, position2, Voxeland.GetTerrainLayerMask()))
                {
                    powerRelay.DisconnectFromRelay();
                    return;
                }
            }
            else if (constructable?.constructed ?? false)
            {
                powerRelay.UpdateConnection();
            }

            GameObject target = powerRelay?.powerFX?.target;
            if (target != null)
            {
                powerRelay.powerFX.SetTarget(target);
            }


            bool openOtherConnector = false;

            foreach (OtherConnectionRelay otherConnectionRelay in otherConnectionRelays)
            {
                if (otherConnectionRelay.outboundRelay == null)
                {
                    openOtherConnector = true;
                }
            }

            if (!openOtherConnector)
            {
                OtherConnectionRelay.AddNewOtherConnectionRelay(powerRelay, this);
            }

            if (baseInboundRelay is null && !baseConnectionsDisabled)
            {
                baseInboundRelay = BaseInboundRelay.AddNewBaseConnectionRelay(powerRelay, this);
            }
        }
        public static bool Prefix(PowerRelay __instance, PowerRelay relay, ref bool __result)
        {
            if (__instance is null || relay is null)
            {
                return(true);
            }

            SubRoot subRoot1 = __instance.gameObject.GetComponentInParent <SubRoot>();
            SubRoot subRoot2 = relay.gameObject.GetComponentInParent <SubRoot>();

            if (!(__instance is OtherConnectionRelay) && !(__instance is BaseInboundRelay) && !__instance.gameObject.name.Contains("Transmitter") && subRoot1 != null && subRoot1 == subRoot2)
            {
                __result = false;
                return(false);
            }

            if (__instance is BaseInboundRelay && (subRoot1 is null || subRoot1 != subRoot2))
            {
                __result = false;
                return(false);
            }

            if (relay is OtherConnectionRelay)
            {
                __result = false;
                return(false);
            }

            if (__instance is OtherConnectionRelay && relay is BasePowerRelay)
            {
                __result = false;
                return(false);
            }

            if (__instance is OtherConnectionRelay && relay.gameObject.name.Contains("Transmitter"))
            {
                __result = false;
                return(false);
            }

            if (!(__instance is OtherConnectionRelay) && !(__instance is BaseInboundRelay) && __instance.gameObject.name.Contains("Transmitter") && !relay.gameObject.name.Contains("Transmitter"))
            {
                __result = false;
                return(false);
            }


            if (relay is BaseInboundRelay)
            {
                __result = false;
                return(false);
            }

            if (__instance is BaseInboundRelay && !(relay is BasePowerRelay))
            {
                __result = false;
                return(false);
            }

            if (!(__instance is BaseInboundRelay) && relay is BasePowerRelay && __instance.gameObject.name.Contains("Transmitter"))
            {
                __result = false;
                return(false);
            }

            if (relay != __instance.outboundRelay && (relay.GetType() == typeof(BasePowerRelay) || relay.GetType() == typeof(PowerRelay)) && relay.inboundPowerSources.Where((x) => x.GetType() == typeof(BaseInboundRelay) || x.GetType() == typeof(OtherConnectionRelay)).Any())
            {
                __result = false;
                return(false);
            }

            if (Main.config.LOSBlue && !(__instance is OtherConnectionRelay) && !(__instance is BaseInboundRelay) && __instance.gameObject.name.Contains("Transmitter") && Physics.Linecast(__instance.GetConnectPoint(), relay.GetConnectPoint(), Voxeland.GetTerrainLayerMask()))
            {
                __result = false;
                return(false);
            }

            return(true);
        }
예제 #5
0
        public static void Postfix(PowerRelay __instance, PowerRelay potentialRelay, ref bool __result)
        {
            if (!__result)
            {
                return;
            }

            if (__instance is null || potentialRelay is null)
            {
                return;
            }

            var subRoot1 = __instance.gameObject.GetComponentInParent <SubRoot>();
            var subRoot2 = potentialRelay.gameObject.GetComponentInParent <SubRoot>();

            if (__instance is not OtherConnectionRelay && __instance is not BaseInboundRelay && !__instance.gameObject.name.Contains("Transmitter") && subRoot1 is not null && subRoot1 == subRoot2)
            {
                __result = false;
                return;
            }

            if (__instance is BaseInboundRelay && (subRoot1 is null || subRoot1 != subRoot2))
            {
                __result = false;
                return;
            }

            if (potentialRelay is OtherConnectionRelay)
            {
                __result = false;
                return;
            }

            if (__instance is OtherConnectionRelay && potentialRelay is BasePowerRelay)
            {
                __result = false;
                return;
            }

            if (__instance is OtherConnectionRelay && potentialRelay.gameObject.name.Contains("Transmitter"))
            {
                __result = false;
                return;
            }

            if (__instance is not OtherConnectionRelay && __instance is not BaseInboundRelay && __instance.gameObject.name.Contains("Transmitter") && !potentialRelay.gameObject.name.Contains("Transmitter"))
            {
                __result = false;
                return;
            }

            if (potentialRelay is BaseInboundRelay)
            {
                __result = false;
                return;
            }

            if (__instance is BaseInboundRelay && potentialRelay is not BasePowerRelay)
            {
                __result = false;
                return;
            }

            if (potentialRelay is BasePowerRelay && __instance.gameObject.name.Contains("Transmitter") && __instance is not BaseInboundRelay)
            {
                __result = false;
                return;
            }

            if (potentialRelay != __instance.outboundRelay && potentialRelay.GetType() == typeof(PowerRelay) && potentialRelay.inboundPowerSources.Any(x => x is OtherConnectionRelay))
            {
                __result = false;
                return;
            }

            if (__instance is OtherConnectionRelay or BaseInboundRelay)
            {
                return;
            }

            if (Main.Config.LOSBlue && __instance.gameObject.name.Contains("Transmitter") && Physics.Linecast(__instance.GetConnectPoint(), potentialRelay.GetConnectPoint(), Voxeland.GetTerrainLayerMask()))
            {
                __result = false;
                return;
            }

            var position1 = __instance.GetConnectPoint(potentialRelay.GetConnectPoint(__instance.GetConnectPoint(potentialRelay.GetConnectPoint())));
            var position2 = potentialRelay.GetConnectPoint(position1);

            if (Vector3.Distance(position1, position2) > __instance.maxOutboundDistance)
            {
                __result = false;
            }
        }