コード例 #1
0
 public void Press()
 {
     if (!m_wasPressed && !ElectricElement.IsSignalHigh(m_voltage))
     {
         m_wasPressed = true;
         CellFace cellFace = base.CellFaces[0];
         base.SubsystemElectricity.SubsystemAudio.PlaySound("Audio/Click", 1f, 0f, new Vector3(cellFace.X, cellFace.Y, cellFace.Z), 2f, autoDelay: true);
         base.SubsystemElectricity.QueueElectricElementForSimulation(this, base.SubsystemElectricity.CircuitStep + 1);
     }
 }
コード例 #2
0
        public override bool Simulate()
        {
            float voltage = m_voltage;
            bool  flag    = false;
            bool  flag2   = false;

            _ = base.Rotation;
            foreach (ElectricConnection connection in base.Connections)
            {
                if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0)
                {
                    if (ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace)))
                    {
                        if (m_clockAllowed)
                        {
                            flag           = true;
                            m_clockAllowed = false;
                        }
                    }
                    else
                    {
                        m_clockAllowed = true;
                    }
                    flag2 = true;
                }
            }
            if (flag2)
            {
                if (flag)
                {
                    m_voltage = GetRandomVoltage();
                }
            }
            else
            {
                m_voltage = GetRandomVoltage();
                base.SubsystemElectricity.QueueElectricElementForSimulation(this, base.SubsystemElectricity.CircuitStep + MathUtils.Max((int)(s_random.Float(0.25f, 0.75f) / 0.01f), 1));
            }
            if (m_voltage != voltage)
            {
                base.SubsystemElectricity.WritePersistentVoltage(base.CellFaces[0].Point, m_voltage);
                return(true);
            }
            return(false);
        }
コード例 #3
0
        public override bool Simulate()
        {
            float voltage = m_voltage;

            m_voltage = CalculateVoltage();
            if (ElectricElement.IsSignalHigh(m_voltage) != ElectricElement.IsSignalHigh(voltage))
            {
                if (ElectricElement.IsSignalHigh(m_voltage))
                {
                    m_glowPoint.Color = m_color;
                }
                else
                {
                    m_glowPoint.Color = Color.Transparent;
                }
            }
            return(false);
        }
コード例 #4
0
 public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem)
 {
     if (m_score == 0 && !ElectricElement.IsSignalHigh(m_voltage))
     {
         if (cellFace.Face == 0 || cellFace.Face == 2)
         {
             float num  = worldItem.Position.X - (float)cellFace.X - 0.5f;
             float num2 = worldItem.Position.Y - (float)cellFace.Y - 0.5f;
             float num3 = MathUtils.Sqrt(num * num + num2 * num2);
             m_score = MathUtils.Clamp((int)MathUtils.Round(8f * (1f - num3 / 0.707f)), 1, 8);
         }
         else
         {
             float num4 = worldItem.Position.Z - (float)cellFace.Z - 0.5f;
             float num5 = worldItem.Position.Y - (float)cellFace.Y - 0.5f;
             float num6 = MathUtils.Sqrt(num4 * num4 + num5 * num5);
             m_score = MathUtils.Clamp((int)MathUtils.Round(8f * (1f - num6 / 0.5f)), 1, 8);
         }
         base.SubsystemElectricity.QueueElectricElementForSimulation(this, base.SubsystemElectricity.CircuitStep + 1);
     }
 }
コード例 #5
0
        public override bool Simulate()
        {
            float voltage = m_voltage;

            if (m_pressure > 0f && Time.FrameIndex - m_lastPressFrameIndex < 2)
            {
                m_voltage = PressureToVoltage(m_pressure);
                base.SubsystemElectricity.QueueElectricElementForSimulation(this, base.SubsystemElectricity.CircuitStep + 10);
            }
            else
            {
                if (ElectricElement.IsSignalHigh(m_voltage))
                {
                    CellFace cellFace = base.CellFaces[0];
                    base.SubsystemElectricity.SubsystemAudio.PlaySound("Audio/BlockPlaced", 0.6f, -0.1f, new Vector3(cellFace.X, cellFace.Y, cellFace.Z), 2.5f, autoDelay: true);
                }
                m_voltage  = 0f;
                m_pressure = 0f;
            }
            return(m_voltage != voltage);
        }
コード例 #6
0
        public override bool Simulate()
        {
            int  counter  = m_counter;
            bool overflow = m_overflow;
            bool flag     = false;
            bool flag2    = false;
            bool flag3    = false;
            int  rotation = base.Rotation;

            foreach (ElectricConnection connection in base.Connections)
            {
                if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0)
                {
                    ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(base.CellFaces[0].Face, rotation, connection.ConnectorFace);
                    if (connectorDirection.HasValue)
                    {
                        if (connectorDirection == ElectricConnectorDirection.Right)
                        {
                            flag = ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace));
                        }
                        else if (connectorDirection == ElectricConnectorDirection.Left)
                        {
                            flag2 = ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace));
                        }
                        else if (connectorDirection == ElectricConnectorDirection.In)
                        {
                            flag3 = ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace));
                        }
                    }
                }
            }
            if (flag && m_plusAllowed)
            {
                m_plusAllowed = false;
                if (m_counter < 15)
                {
                    m_counter++;
                    m_overflow = false;
                }
                else
                {
                    m_counter  = 0;
                    m_overflow = true;
                }
            }
            else if (flag2 && m_minusAllowed)
            {
                m_minusAllowed = false;
                if (m_counter > 0)
                {
                    m_counter--;
                    m_overflow = false;
                }
                else
                {
                    m_counter  = 15;
                    m_overflow = true;
                }
            }
            else if (flag3 && m_resetAllowed)
            {
                m_counter  = 0;
                m_overflow = false;
            }
            if (!flag)
            {
                m_plusAllowed = true;
            }
            if (!flag2)
            {
                m_minusAllowed = true;
            }
            if (!flag3)
            {
                m_resetAllowed = true;
            }
            if (m_counter != counter || m_overflow != overflow)
            {
                base.SubsystemElectricity.WritePersistentVoltage(base.CellFaces[0].Point, (float)m_counter / 15f * (float)((!m_overflow) ? 1 : (-1)));
                return(true);
            }
            return(false);
        }
        public override bool Simulate()
        {
            float voltage = m_voltage;

            m_voltage = 0f;
            int rotation = base.Rotation;

            foreach (ElectricConnection connection in base.Connections)
            {
                if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0 && ElectricElement.IsSignalHigh(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace)))
                {
                    ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(base.CellFaces[0].Face, rotation, connection.ConnectorFace);
                    if (connectorDirection.HasValue)
                    {
                        if (connectorDirection.Value == ElectricConnectorDirection.Top)
                        {
                            m_voltage += 71f / (339f * (float)Math.PI);
                        }
                        if (connectorDirection.Value == ElectricConnectorDirection.Right)
                        {
                            m_voltage += 142f / (339f * (float)Math.PI);
                        }
                        if (connectorDirection.Value == ElectricConnectorDirection.Bottom)
                        {
                            m_voltage += 4f / 15f;
                        }
                        if (connectorDirection.Value == ElectricConnectorDirection.Left)
                        {
                            m_voltage += 8f / 15f;
                        }
                    }
                }
            }
            return(m_voltage != voltage);
        }