Esempio n. 1
0
        public void Update(float dt)
        {
            Point3 coordinates = m_componentBlockEntity.Coordinates;

            if (m_updateSmeltingRecipe)
            {
                m_updateSmeltingRecipe = false;
                result[0] = m_matchedIngredients[7];
                result[1] = m_matchedIngredients[8];
                result[2] = m_matchedIngredients[9];
                bool flag = FindSmeltingRecipe(5f);
                if (result[0] != m_matchedIngredients[7] || result[1] != m_matchedIngredients[8] || result[2] != m_matchedIngredients[9])
                {
                    SmeltingProgress = 0f;
                    m_time           = 0;
                }
                m_smeltingRecipe2 = flag;
                if (flag != m_smeltingRecipe)
                {
                    m_smeltingRecipe = flag;
                    SmeltingProgress = 0f;
                    m_time           = 0;
                }
            }
            if (m_smeltingRecipe2 && Utils.SubsystemTime.PeriodicGameTimeEvent(0.2, 0.0))
            {
                int num = 1;
                int num2 = 0;
                var point = CellFace.FaceToPoint3(FourDirectionalBlock.GetDirection(Utils.Terrain.GetCellValue(coordinates.X, coordinates.Y, coordinates.Z)));
                int num3 = coordinates.X - point.X;
                int num4 = coordinates.Y - point.Y;
                int num5 = coordinates.Z - point.Z, v;
                for (int i = -1; i < 2; i++)
                {
                    for (int j = -1; j < 3; j++)
                    {
                        for (int k = -1; k < 2; k++)
                        {
                            int cellValue     = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(num3 + i, num4 + j, num5 + k), 0);
                            int cellContents2 = Terrain.ExtractContents(cellValue);
                            if (j == 1 && cellValue != (MetalBlock.Index | 96 << 14))
                            {
                                num = 0;
                                break;
                            }
                            if (i * i + k * k == 1 && j == 0 && cellContents2 == 0 && ((v = Utils.Terrain.GetCellValue(num3 + 2 * i, num4 + j, num5 + 2 * k)) != (BlastBlowerBlock.Index | FurnaceNBlock.SetHeatLevel(Terrain.ExtractData(v), 1) << 14)) && (num3 + i != coordinates.X || num5 + k != coordinates.Z))
                            {
                                num = 0;
                                break;
                            }
                            if (i * i + k * k == 1 && j == 0 && cellContents2 == 0)
                            {
                                num2++;
                            }
                            if (i * i + k * k == 1 && j == 0 && cellContents2 != 0 && cellValue != (MetalBlock.Index | 96 << 14) && (num3 + i != coordinates.X || num5 + k != coordinates.Z))
                            {
                                num = 0;
                                break;
                            }
                            if (i * i + k * k == 2 && j == 0 && cellValue != (MetalBlock.Index | 96 << 14))
                            {
                                num = 0;
                                break;
                            }
                            if (j < 0 && cellValue != (MetalBlock.Index | 64 << 14))
                            {
                                num = 0;
                                break;
                            }
                        }
                    }
                }
                if (num == 0 || num2 == 0)
                {
                    m_smeltingRecipe = false;
                }
                if (num == 1 && num2 >= 2 && !m_smeltingRecipe)
                {
                    m_smeltingRecipe = m_smeltingRecipe2;
                }
            }

            if (!m_smeltingRecipe)
            {
                HeatLevel           = 0f;
                m_fireTimeRemaining = 0f;
                SmeltingProgress    = 0f;
            }
            if (m_smeltingRecipe && m_fireTimeRemaining <= 0f)
            {
                HeatLevel = 5f;
            }
            if (m_smeltingRecipe)
            {
                SmeltingProgress = MathUtils.Min(SmeltingProgress + 0.1f * dt, 1f);
                if (SmeltingProgress >= 1f)
                {
                    int[] array = new int[]
                    {
                        IronIngotBlock.Index,
                        ItemBlock.IdTable["ScrapIron"],
                        ItemBlock.IdTable["AluminumOrePowder"],
                        ItemBlock.IdTable["ChromiumOrePowder"],
                        ItemBlock.IdTable["CokeCoalPowder"]
                    };
                    for (int l = 0; l < 5; l++)
                    {
                        if (m_matchedIngredients[l] > 0)
                        {
                            int b = array[l];
                            for (int m = 0; m < m_furnaceSize; m++)
                            {
                                if (m_slots[m].Count > 0 && GetSlotValue(m) == b)
                                {
                                    if (m_slots[m].Count >= m_matchedIngredients[l])
                                    {
                                        m_slots[m].Count       -= m_matchedIngredients[l];
                                        m_matchedIngredients[l] = 0;
                                    }
                                    else
                                    {
                                        m_matchedIngredients[l] -= m_slots[m].Count;
                                        m_slots[m].Count         = 0;
                                    }
                                    if (m_matchedIngredients[l] == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (m_matchedIngredients[5] >= 1)
                    {
                        m_slots[ResultSlotIndex].Value  = ItemBlock.IdTable["SteelIngot"];
                        m_slots[ResultSlotIndex].Count += m_matchedIngredients[5];
                    }
                    if (m_matchedIngredients[6] >= 1)
                    {
                        m_slots[ResultSlotIndex].Value  = IronIngotBlock.Index;
                        m_slots[ResultSlotIndex].Count += m_matchedIngredients[6];
                    }
                    if (m_matchedIngredients[7] >= 1)
                    {
                        m_slots[ResultSlotIndex].Value  = ItemBlock.IdTable["FeAlCrAlloyIngot"];
                        m_slots[ResultSlotIndex].Count += m_matchedIngredients[7];
                    }
                    m_smeltingRecipe       = false;
                    SmeltingProgress       = 0f;
                    m_updateSmeltingRecipe = true;
                }
            }
        }
Esempio n. 2
0
        public void Update(float dt)
        {
            Point3 coordinates = m_componentBlockEntity.Coordinates;

            if (coordinates.Y < 0 || coordinates.Y > 127)
            {
                return;
            }
            if (HeatLevel > 0f)
            {
                m_fireTimeRemaining = MathUtils.Max(0f, m_fireTimeRemaining - dt * m_speed);
                if (m_fireTimeRemaining == 0f)
                {
                    HeatLevel = 0f;
                }
            }
            Slot slot;

            if (m_updateSmeltingRecipe)
            {
                m_updateSmeltingRecipe = false;
                if (HeatLevel <= 0f)
                {
                    slot = m_slots[FuelSlotIndex];
                    if (slot.Count > 0)
                    {
                        Block block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                        HeatLevel = block is IFuel fuel?fuel.GetHeatLevel(slot.Value) : block.FuelHeatLevel;
                    }
                }
                if (!"text".Equals(m_smeltingRecipe))
                {
                    m_smeltingRecipe = "text";
                    SmeltingProgress = 0f;
                    //m_music = 0;
                }
            }
            if (m_smeltingRecipe == null)
            {
                HeatLevel           = 0f;
                m_fireTimeRemaining = 0f;
                //m_music = -1;
            }
            else if (m_fireTimeRemaining <= 0f)
            {
                slot = m_slots[FuelSlotIndex];
                if (slot.Count > 0)
                {
                    var block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                    if (block.GetExplosionPressure(slot.Value) > 0f)
                    {
                        slot.Count = 0;
                        Utils.SubsystemExplosions.TryExplodeBlock(coordinates.X, coordinates.Y, coordinates.Z, slot.Value);
                    }
                    else
                    {
                        slot.Count--;
                        if (block is IFuel fuel)
                        {
                            HeatLevel  = fuel.GetHeatLevel(slot.Value);
                            m_fireTime = m_fireTimeRemaining = fuel.GetFuelFireDuration(slot.Value);
                        }
                        else
                        {
                            HeatLevel  = block.FuelHeatLevel;
                            m_fireTime = m_fireTimeRemaining = block.FuelFireDuration;
                        }
                    }
                }
            }
            if (m_fireTimeRemaining <= 0f)
            {
                m_smeltingRecipe = null;
                SmeltingProgress = 0f;
                //m_music = -1;
            }
            if (m_smeltingRecipe != null)
            {
                if (m_fireTime == 0f)
                {
                    m_fireTime = m_fireTimeRemaining;
                }
                SmeltingProgress = MathUtils.Min(m_fireTimeRemaining / m_fireTime, 1f);
                if (SmeltingProgress >= 2f)
                {
                    m_smeltingRecipe       = null;
                    SmeltingProgress       = 0f;
                    m_updateSmeltingRecipe = true;
                }
            }
            TerrainChunk chunk = Utils.Terrain.GetChunkAtCell(coordinates.X, coordinates.Z);

            if (chunk != null && chunk.State == TerrainChunkState.Valid)
            {
                int cellValue = chunk.GetCellValueFast(coordinates.X & 15, coordinates.Y, coordinates.Z & 15);
                Utils.SubsystemTerrain.ChangeCell(coordinates.X, coordinates.Y, coordinates.Z, Terrain.ReplaceData(cellValue, FurnaceNBlock.SetHeatLevel(Terrain.ExtractData(cellValue), HeatLevel > 0f ? 1 : 0)));
            }
        }
Esempio n. 3
0
        public void Update(float dt)
        {
            Point3 coordinates = m_componentBlockEntity.Coordinates;

            if (HeatLevel > 0f)
            {
                m_fireTimeRemaining = MathUtils.Max(0f, m_fireTimeRemaining - dt);
                if (m_fireTimeRemaining == 0f)
                {
                    HeatLevel = 0f;
                }
            }
            Slot slot;

            if (m_updateSmeltingRecipe)
            {
                m_updateSmeltingRecipe = false;
                float heatLevel = 0f;
                if (HeatLevel > 0f)
                {
                    heatLevel = HeatLevel;
                }
                else
                {
                    slot = m_slots[FuelSlotIndex];
                    if (slot.Count > 0)
                    {
                        Block block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                        heatLevel = block is IFuel fuel?fuel.GetHeatLevel(slot.Value) : block.FuelHeatLevel;
                    }
                }
                string text = FindSmeltingRecipe(heatLevel);
                if (text != m_smeltingRecipe)
                {
                    m_smeltingRecipe = text;
                    SmeltingProgress = 0f;
                    //m_music = 0;
                }
            }
            if (m_smeltingRecipe == null)
            {
                HeatLevel           = 0f;
                m_fireTimeRemaining = 0f;
                //m_music = -1;
            }
            if (m_smeltingRecipe != null && m_fireTimeRemaining <= 0f)
            {
                slot = m_slots[FuelSlotIndex];
                if (slot.Count > 0)
                {
                    var block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                    if (block.GetExplosionPressure(slot.Value) > 0f)
                    {
                        slot.Count = 0;
                        Utils.SubsystemExplosions.TryExplodeBlock(coordinates.X, coordinates.Y, coordinates.Z, slot.Value);
                    }
                    else if (block.FuelHeatLevel > 0f)
                    {
                        slot.Count--;
                        if (block is IFuel fuel)
                        {
                            HeatLevel           = fuel.GetHeatLevel(slot.Value);
                            m_fireTimeRemaining = fuel.GetFuelFireDuration(slot.Value);
                        }
                        else
                        {
                            HeatLevel           = block.FuelHeatLevel;
                            m_fireTimeRemaining = block.FuelFireDuration;
                        }
                    }
                }
            }
            if (m_fireTimeRemaining <= 0f)
            {
                m_smeltingRecipe = null;
                SmeltingProgress = 0f;
                //m_music = -1;
            }
            if (m_smeltingRecipe != null)
            {
                SmeltingProgress = MathUtils.Min(SmeltingProgress + 0.02f * dt, 1f);
                if (SmeltingProgress >= 1f)
                {
                    for (int i = 0; i < m_furnaceSize; i++)
                    {
                        if (m_slots[i].Count > 0)
                        {
                            m_slots[i].Count--;
                        }
                    }
                    if (string.Equals(m_smeltingRecipe, "SteelWheel") || string.Equals(m_smeltingRecipe, "SteelGear") || string.Equals(m_smeltingRecipe, "ScrapIron"))
                    {
                        m_slots[ResultSlotIndex].Value = ItemBlock.IdTable[m_smeltingRecipe];
                        m_slots[ResultSlotIndex].Count++;
                    }
                    m_smeltingRecipe       = null;
                    SmeltingProgress       = 0f;
                    m_updateSmeltingRecipe = true;
                }
            }
            if (Utils.Terrain.GetCellContents(coordinates.X, coordinates.Y, coordinates.Z) != 0)
            {
                int cellValue = Utils.Terrain.GetCellValue(coordinates.X, coordinates.Y, coordinates.Z);
                Utils.SubsystemTerrain.ChangeCell(coordinates.X, coordinates.Y, coordinates.Z, Terrain.ReplaceData(cellValue, FurnaceNBlock.SetHeatLevel(Terrain.ExtractData(cellValue), HeatLevel > 0f ? 1 : 0)));
            }
        }
Esempio n. 4
0
        public void Update(float dt)
        {
            if (Coordinates.Y < 0 || Coordinates.Y > 127)
            {
                return;
            }
            if (HeatLevel > 0f)
            {
                m_fireTimeRemaining = MathUtils.Max(0f, m_fireTimeRemaining - dt);
                if (m_fireTimeRemaining == 0f)
                {
                    HeatLevel = 0f;
                }
            }
            Slot slot;

            if (m_updateSmeltingRecipe)
            {
                m_updateSmeltingRecipe = false;
                float heatLevel = 0f;
                if (HeatLevel > 0f)
                {
                    heatLevel = HeatLevel;
                }
                else
                {
                    slot = m_slots[FuelSlotIndex];
                    if (slot.Count > 0)
                    {
                        var block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                        heatLevel = block is IFuel fuel?fuel.GetHeatLevel(slot.Value) : block.FuelHeatLevel;
                    }
                }
                string text = FindSmeltingRecipe(heatLevel);
                if (text != m_smeltingRecipe)
                {
                    m_smeltingRecipe = text;
                    SmeltingProgress = 0f;
                    m_music          = 0;
                }
            }
            if (m_smeltingRecipe == null)
            {
                HeatLevel           = 0f;
                m_fireTimeRemaining = 0f;
                m_music             = -1;
            }
            else if (m_smeltingRecipe != null && m_fireTimeRemaining <= 0f)
            {
                slot = m_slots[FuelSlotIndex];
                if (slot.Count > 0)
                {
                    var block = BlocksManager.Blocks[Terrain.ExtractContents(slot.Value)];
                    if (block.GetExplosionPressure(slot.Value) > 0f)
                    {
                        slot.Count = 0;
                        Utils.SubsystemExplosions.TryExplodeBlock(Coordinates.X, Coordinates.Y, Coordinates.Z, slot.Value);
                    }
                    else
                    {
                        slot.Count--;
                        if (block is IFuel fuel)
                        {
                            HeatLevel           = fuel.GetHeatLevel(slot.Value);
                            m_fireTimeRemaining = fuel.GetFuelFireDuration(slot.Value);
                        }
                        else
                        {
                            HeatLevel           = block.FuelHeatLevel;
                            m_fireTimeRemaining = block.FuelFireDuration;
                        }
                    }
                }
            }
            if (m_fireTimeRemaining <= 0f)
            {
                m_smeltingRecipe = null;
                SmeltingProgress = 0f;
                m_music          = -1;
            }
            if (m_smeltingRecipe != null)
            {
                SmeltingProgress = MathUtils.Min(SmeltingProgress + 0.02f * dt, 1f);
                if (m_music % 90 == 0)
                {
                    Utils.SubsystemAudio.PlaySound("Audio/SteamEngine", 1f, 0f, new Vector3(Coordinates), 4f, true);
                }
                m_music++;
                if (SmeltingProgress >= 1.0)
                {
                    for (int i = 0; i < m_furnaceSize; i++)
                    {
                        if (m_slots[i].Count > 0)
                        {
                            m_slots[i].Count--;
                        }
                    }
                    m_slots[ResultSlotIndex].Value = 90;
                    m_slots[ResultSlotIndex].Count++;
                    m_smeltingRecipe       = null;
                    SmeltingProgress       = 0f;
                    m_updateSmeltingRecipe = true;
                }
            }
            if (m_componentBlockEntity != null)
            {
                TerrainChunk chunk = Utils.Terrain.GetChunkAtCell(Coordinates.X, Coordinates.Z);
                if (chunk != null && chunk.State == TerrainChunkState.Valid)
                {
                    int cellValue = chunk.GetCellValueFast(Coordinates.X & 15, Coordinates.Y, Coordinates.Z & 15);
                    Utils.SubsystemTerrain.ChangeCell(Coordinates.X, Coordinates.Y, Coordinates.Z, Terrain.ReplaceData(cellValue, FurnaceNBlock.SetHeatLevel(Terrain.ExtractData(cellValue), HeatLevel > 0f ? 1 : 0)));
                }
            }
        }