Exemple #1
0
        internal static BaseInboundRelay AddNewBaseConnectionRelay(PowerRelay originalRelay, PowerControl powerControl)
        {
            BaseInboundRelay additionalRelay = originalRelay.gameObject.AddComponent <BaseInboundRelay>();

            additionalRelay.dontConnectToRelays = powerControl.baseConnectionsDisabled;
            additionalRelay.maxOutboundDistance = 10000;
            additionalRelay.constructable       = originalRelay.constructable;

            if (originalRelay.powerFX != null && originalRelay.powerFX.vfxPrefab != null)
            {
                BaseInboundRelayPowerFX powerFX = originalRelay.gameObject.AddComponent <BaseInboundRelayPowerFX>();
                powerFX.attachPoint = originalRelay.powerFX.attachPoint;
                powerFX.vfxPrefab   = GameObject.Instantiate(originalRelay.powerFX.vfxPrefab);
                powerFX.vfxPrefab.SetActive(false);
                powerFX.vfxPrefab.GetComponent <LineRenderer>().material.SetColor(ShaderPropertyID._Color, Color.magenta);


                additionalRelay.powerFX = powerFX;
            }
            additionalRelay.AddInboundPower(originalRelay);

            return(additionalRelay);
        }
        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);
            }
        }