예제 #1
0
 public void Update(float dt)
 {
     if (m_subsystemTime.PeriodicGameTimeEvent(2.5, 0.0))
     {
         foreach (Point3 key2 in m_toDegrade.Keys)
         {
             if (base.SubsystemTerrain.Terrain.GetCellContents(key2.X, key2.Y, key2.Z) == 168)
             {
                 int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key2.X, key2.Y, key2.Z);
                 base.SubsystemTerrain.ChangeCell(key2.X, key2.Y, key2.Z, Terrain.ReplaceContents(cellValue, 2));
             }
         }
         m_toDegrade.Clear();
     }
     if (m_subsystemTime.PeriodicGameTimeEvent(10.0, 0.0))
     {
         foreach (KeyValuePair <Point3, bool> item in m_toHydrate)
         {
             Point3 key        = item.Key;
             bool   value      = item.Value;
             int    cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z);
             if (Terrain.ExtractContents(cellValue2) == 168)
             {
                 int data   = SoilBlock.SetHydration(Terrain.ExtractData(cellValue2), value);
                 int value2 = Terrain.ReplaceData(cellValue2, data);
                 base.SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, value2);
             }
         }
         m_toHydrate.Clear();
     }
 }
예제 #2
0
 public virtual IEnumerable <int> GetCreativeValues()
 {
     if (DefaultCreativeData >= 0)
     {
         yield return(Terrain.ReplaceContents(Terrain.ReplaceData(0, DefaultCreativeData), BlockIndex));
     }
 }
        public bool SetCellOnFire(int x, int y, int z, float fireExpandability)
        {
            int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z);
            int num       = Terrain.ExtractContents(cellValue);

            if (BlocksManager.Blocks[num].FireDuration == 0f)
            {
                return(false);
            }
            bool result = false;

            for (int i = 0; i < 5; i++)
            {
                Point3 point      = CellFace.FaceToPoint3(i);
                int    cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(x + point.X, y + point.Y, z + point.Z);
                int    num2       = Terrain.ExtractContents(cellValue2);
                if (num2 == 0 || num2 == 104 || num2 == 61)
                {
                    int num3 = (num2 == 104) ? Terrain.ExtractData(cellValue2) : 0;
                    int num4 = CellFace.OppositeFace(i);
                    num3     |= ((1 << num4) & 0xF);
                    cellValue = Terrain.ReplaceData(Terrain.ReplaceContents(0, 104), num3);
                    AddFire(x + point.X, y + point.Y, z + point.Z, fireExpandability);
                    base.SubsystemTerrain.ChangeCell(x + point.X, y + point.Y, z + point.Z, cellValue);
                    result = true;
                }
            }
            return(result);
        }
예제 #4
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            Vector3 forward = Matrix.CreateFromQuaternion(componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation).Forward;
            float   num     = Vector3.Dot(forward, Vector3.UnitZ);
            float   num2    = Vector3.Dot(forward, Vector3.UnitX);
            float   num3    = Vector3.Dot(forward, -Vector3.UnitZ);
            float   num4    = Vector3.Dot(forward, -Vector3.UnitX);
            int     data    = 0;

            if (num == MathUtils.Max(num, num2, num3, num4))
            {
                data = 0;
            }
            else if (num2 == MathUtils.Max(num, num2, num3, num4))
            {
                data = 1;
            }
            else if (num3 == MathUtils.Max(num, num2, num3, num4))
            {
                data = 2;
            }
            else if (num4 == MathUtils.Max(num, num2, num3, num4))
            {
                data = 3;
            }
            BlockPlacementData result = default(BlockPlacementData);

            result.Value    = Terrain.ReplaceData(Terrain.ReplaceContents(0, 132), data);
            result.CellFace = raycastResult.CellFace;
            return(result);
        }
예제 #5
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            int value2 = 0;

            if (raycastResult.CellFace.Face == 0)
            {
                value2 = Terrain.ReplaceData(Terrain.ReplaceContents(0, 121), 0);
            }
            if (raycastResult.CellFace.Face == 1)
            {
                value2 = Terrain.ReplaceData(Terrain.ReplaceContents(0, 121), 1);
            }
            if (raycastResult.CellFace.Face == 2)
            {
                value2 = Terrain.ReplaceData(Terrain.ReplaceContents(0, 121), 2);
            }
            if (raycastResult.CellFace.Face == 3)
            {
                value2 = Terrain.ReplaceData(Terrain.ReplaceContents(0, 121), 3);
            }
            BlockPlacementData result = default(BlockPlacementData);

            result.Value    = value2;
            result.CellFace = raycastResult.CellFace;
            return(result);
        }
예제 #6
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            int  rotation;
            bool upsideDown;

            if (raycastResult.CellFace.Face < 4)
            {
                rotation   = raycastResult.CellFace.Face;
                upsideDown = (raycastResult.HitPoint().Y - (float)raycastResult.CellFace.Y > 0.5f);
            }
            else
            {
                Vector3 forward = Matrix.CreateFromQuaternion(componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation).Forward;
                float   num     = Vector3.Dot(forward, Vector3.UnitZ);
                float   num2    = Vector3.Dot(forward, Vector3.UnitX);
                float   num3    = Vector3.Dot(forward, -Vector3.UnitZ);
                float   num4    = Vector3.Dot(forward, -Vector3.UnitX);
                rotation   = ((num == MathUtils.Max(num, num2, num3, num4)) ? 2 : ((num2 == MathUtils.Max(num, num2, num3, num4)) ? 3 : ((num3 != MathUtils.Max(num, num2, num3, num4)) ? ((num4 == MathUtils.Max(num, num2, num3, num4)) ? 1 : 0) : 0)));
                upsideDown = (raycastResult.CellFace.Face == 5);
            }
            int data = SetOpen(SetRotation(SetUpsideDown(0, upsideDown), rotation), open: false);
            BlockPlacementData result = default(BlockPlacementData);

            result.Value    = Terrain.ReplaceData(Terrain.ReplaceContents(0, BlockIndex), data);
            result.CellFace = raycastResult.CellFace;
            return(result);
        }
예제 #7
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            BlockPlacementData result = default(BlockPlacementData);

            result.Value    = Terrain.ReplaceData(Terrain.ReplaceContents(0, BlockIndex), 0);
            result.CellFace = raycastResult.CellFace;
            return(result);
        }
예제 #8
0
        public static int SetWireFacesBitmask(int value, int bitmask)
        {
            int num = Terrain.ExtractData(value);

            num &= -64;
            num |= (bitmask & 0x3F);
            return(Terrain.ReplaceData(Terrain.ReplaceContents(value, 133), num));
        }
예제 #9
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            Vector3 forward = Matrix.CreateFromQuaternion(componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation).Forward;
            float   num     = Vector3.Dot(forward, Vector3.UnitZ);
            float   num2    = Vector3.Dot(forward, Vector3.UnitX);
            float   num3    = Vector3.Dot(forward, -Vector3.UnitZ);
            float   num4    = Vector3.Dot(forward, -Vector3.UnitX);
            int     num5    = 0;

            if (num == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 2;
            }
            else if (num2 == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 3;
            }
            else if (num3 == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 0;
            }
            else if (num4 == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 1;
            }
            Point3 point       = CellFace.FaceToPoint3(raycastResult.CellFace.Face);
            int    num6        = raycastResult.CellFace.X + point.X;
            int    y           = raycastResult.CellFace.Y + point.Y;
            int    num7        = raycastResult.CellFace.Z + point.Z;
            bool   rightHanded = true;

            switch (num5)
            {
            case 0:
                rightHanded = BlocksManager.Blocks[subsystemTerrain.Terrain.GetCellContents(num6 - 1, y, num7)].IsTransparent;
                break;

            case 1:
                rightHanded = BlocksManager.Blocks[subsystemTerrain.Terrain.GetCellContents(num6, y, num7 + 1)].IsTransparent;
                break;

            case 2:
                rightHanded = BlocksManager.Blocks[subsystemTerrain.Terrain.GetCellContents(num6 + 1, y, num7)].IsTransparent;
                break;

            case 3:
                rightHanded = BlocksManager.Blocks[subsystemTerrain.Terrain.GetCellContents(num6, y, num7 - 1)].IsTransparent;
                break;
            }
            int data = SetRightHanded(SetOpen(SetRotation(0, num5), open: false), rightHanded);
            BlockPlacementData result = default(BlockPlacementData);

            result.Value    = Terrain.ReplaceData(Terrain.ReplaceContents(0, BlockIndex), data);
            result.CellFace = raycastResult.CellFace;
            return(result);
        }
예제 #10
0
        public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
        {
            int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z);

            if (DegradesSoilIfOnTopOfIt(cellValue))
            {
                int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(x, y, z);
                base.SubsystemTerrain.ChangeCell(x, y, z, Terrain.ReplaceContents(cellValue2, 2));
            }
        }
        public override void OnNeighborBlockChanged(int x, int y, int z, int neighborX, int neighborY, int neighborZ)
        {
            int num = Terrain.ExtractData(base.SubsystemTerrain.Terrain.GetCellValue(x, y, z));

            if ((num & 1) != 0 && BlocksManager.Blocks[base.SubsystemTerrain.Terrain.GetCellContents(x, y, z + 1)].FireDuration == 0f)
            {
                num &= -2;
            }
            if ((num & 2) != 0 && BlocksManager.Blocks[base.SubsystemTerrain.Terrain.GetCellContents(x + 1, y, z)].FireDuration == 0f)
            {
                num &= -3;
            }
            if ((num & 4) != 0 && BlocksManager.Blocks[base.SubsystemTerrain.Terrain.GetCellContents(x, y, z - 1)].FireDuration == 0f)
            {
                num &= -5;
            }
            if ((num & 8) != 0 && BlocksManager.Blocks[base.SubsystemTerrain.Terrain.GetCellContents(x - 1, y, z)].FireDuration == 0f)
            {
                num &= -9;
            }
            if (m_fireData.TryGetValue(new Point3(x, y, z), out FireData value))
            {
                if ((num & 1) != 0 && neighborX == x && neighborY == y && neighborZ == z + 1)
                {
                    InitializeFireDataTime(value, 0);
                }
                if ((num & 2) != 0 && neighborX == x + 1 && neighborY == y && neighborZ == z)
                {
                    InitializeFireDataTime(value, 1);
                }
                if ((num & 4) != 0 && neighborX == x && neighborY == y && neighborZ == z - 1)
                {
                    InitializeFireDataTime(value, 2);
                }
                if ((num & 8) != 0 && neighborX == x - 1 && neighborY == y && neighborZ == z)
                {
                    InitializeFireDataTime(value, 3);
                }
                if (num == 0 && neighborX == x && neighborY == y - 1 && neighborZ == z)
                {
                    InitializeFireDataTime(value, 5);
                }
            }
            int contents = 104;

            if (num == 0 && BlocksManager.Blocks[base.SubsystemTerrain.Terrain.GetCellContents(x, y - 1, z)].FireDuration == 0f)
            {
                contents = 0;
            }
            int value2 = Terrain.ReplaceData(Terrain.ReplaceContents(0, contents), num);

            base.SubsystemTerrain.ChangeCell(x, y, z, value2);
        }
        public override void OnPoll(int value, int x, int y, int z, int pollPass)
        {
            if (Terrain.ExtractData(value) != 0 || m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode != 0)
            {
                return;
            }
            int num = Terrain.ExtractLight(base.SubsystemTerrain.Terrain.GetCellValue(x, y + 1, z));

            if (num == 0)
            {
                m_toUpdate[new Point3(x, y, z)] = Terrain.ReplaceContents(value, 8);
            }
            if (num < 13)
            {
                return;
            }
            for (int i = x - 1; i <= x + 1; i++)
            {
                for (int j = z - 1; j <= z + 1; j++)
                {
                    for (int k = y - 2; k <= y + 1; k++)
                    {
                        int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(i, k, j);
                        if (Terrain.ExtractContents(cellValue) != 2)
                        {
                            continue;
                        }
                        int cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(i, k + 1, j);
                        if (KillsGrassIfOnTopOfIt(cellValue2) || Terrain.ExtractLight(cellValue2) < 13 || !(m_random.Float(0f, 1f) < 0.1f))
                        {
                            continue;
                        }
                        int num2 = Terrain.ReplaceContents(cellValue, 8);
                        m_toUpdate[new Point3(i, k, j)] = num2;
                        if (Terrain.ExtractContents(cellValue2) == 0)
                        {
                            int temperature = base.SubsystemTerrain.Terrain.GetTemperature(i, j);
                            int humidity    = base.SubsystemTerrain.Terrain.GetHumidity(i, j);
                            int num3        = PlantsManager.GenerateRandomPlantValue(m_random, num2, temperature, humidity, k + 1);
                            if (num3 != 0)
                            {
                                m_toUpdate[new Point3(i, k + 1, j)] = num3;
                            }
                        }
                    }
                }
            }
        }
        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);

            if (terrainRaycastResult.HasValue)
            {
                if (terrainRaycastResult.Value.CellFace.Face == 4)
                {
                    int   cellValue = m_subsystemTerrain.Terrain.GetCellValue(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z);
                    int   num       = Terrain.ExtractContents(cellValue);
                    Block block     = BlocksManager.Blocks[num];
                    switch (num)
                    {
                    case 2:
                    {
                        int value2 = Terrain.ReplaceContents(cellValue, 168);
                        m_subsystemTerrain.ChangeCell(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, value2);
                        m_subsystemAudio.PlayRandomSound("Audio/Impacts/Dirt", 0.5f, 0f, new Vector3(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z), 3f, autoDelay: true);
                        Vector3 position2 = new Vector3((float)terrainRaycastResult.Value.CellFace.X + 0.5f, (float)terrainRaycastResult.Value.CellFace.Y + 1.25f, (float)terrainRaycastResult.Value.CellFace.Z + 0.5f);
                        m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, position2, cellValue, 0.5f));
                        break;
                    }

                    case 8:
                    {
                        int value = Terrain.ReplaceContents(cellValue, 2);
                        m_subsystemTerrain.ChangeCell(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, value);
                        m_subsystemAudio.PlayRandomSound("Audio/Impacts/Plant", 0.5f, 0f, new Vector3(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z), 3f, autoDelay: true);
                        Vector3 position = new Vector3((float)terrainRaycastResult.Value.CellFace.X + 0.5f, (float)terrainRaycastResult.Value.CellFace.Y + 1.2f, (float)terrainRaycastResult.Value.CellFace.Z + 0.5f);
                        m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, position, cellValue, 0.75f));
                        break;
                    }
                    }
                }
                componentMiner.DamageActiveTool(1);
                return(true);
            }
            return(false);
        }
예제 #14
0
        public override bool OnUse(Vector3 start, Vector3 direction, ComponentMiner componentMiner)
        {
            int               activeBlockValue = componentMiner.ActiveBlockValue;
            var               result           = componentMiner.PickTerrainForDigging(start, direction);
            Entity            entity;
            Vector3           position;
            BodyRaycastResult?body;

            if (activeBlockValue == ItemBlock.IdTable["Wrench"])
            {
                body = componentMiner.PickBody(start, direction);
                Matrix matrix = componentMiner.ComponentCreature.ComponentBody.Matrix;
                position = matrix.Translation + 1f * matrix.Forward + Vector3.UnitY;
                if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
                {
                    entity = body.Value.ComponentBody.Entity;
                    if (entity.FindComponent <ComponentTrain>() != null || entity.FindComponent <ComponentBoatI>() != null)
                    {
                        for (var i = entity.FindComponents <IInventory>().GetEnumerator(); i.MoveNext();)
                        {
                            i.Current.DropAllItems(position);
                        }
                        Utils.SubsystemPickables.AddPickable(ItemBlock.IdTable[entity.ValuesDictionary.DatabaseObject.Name.Length == 8 ? "Minecart" : entity.ValuesDictionary.DatabaseObject.Name], 1, position, null, null);
                        Project.RemoveEntity(entity, true);
                        return(true);
                    }
                }
            }
            else if ((activeBlockValue == ItemBlock.IdTable["Train"] || activeBlockValue == ItemBlock.IdTable["Minecart"]) && result.HasValue && Terrain.ExtractContents(result.Value.Value) == RailBlock.Index)
            {
                position = new Vector3(result.Value.CellFace.Point) + new Vector3(0.5f);
                entity   = DatabaseManager.CreateEntity(Project, activeBlockValue == ItemBlock.IdTable["Minecart"] ? "Carriage" : "Train", true);

                var rotation = componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation.ToForwardVector();
                entity.FindComponent <ComponentTrain>(true).SetDirection(RailBlock.IsDirectionX(RailBlock.GetRailType(Terrain.ExtractData(result.Value.Value)))
                                        ? rotation.Z < 0 ? 0 : 2
                                        : rotation.X < 0 ? 1 : 3);
                entity.FindComponent <ComponentBody>(true).Position       = position;
                entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0f;
                Project.AddEntity(entity);
                var componentTrain = entity.FindComponent <ComponentTrain>(true);
                if (activeBlockValue == ItemBlock.IdTable["Minecart"])
                {
                    componentTrain.Update(0);
                    var train = componentTrain.FindNearestTrain();
                    if (train != null)
                    {
                        componentTrain.ParentBody = train;
                    }
                }
                componentMiner.RemoveActiveTool(1);
                Utils.SubsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, true);
                return(true);
            }

            /*else if (activeBlockValue == ItemBlock.IdTable["Minecart"])
             * {
             *      entity = DatabaseManager.CreateEntity(Project, "Carriage", true);
             *      body = componentMiner.PickBody(start, direction);
             *      if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
             *      {
             *              body = componentMiner.PickBody(start, direction);
             *              var componentTrain = entity.FindComponent<ComponentTrain>(true);
             *              var train = body.Value.ComponentBody.Entity.FindComponent<ComponentTrain>();
             *              if (train != null)
             *                      componentTrain.ParentBody = train;
             *      }
             *      else if (result.HasValue)
             *              position = result.Value.RaycastStart + Vector3.Normalize(result.Value.RaycastEnd - result.Value.RaycastStart) * result.Value.Distance; ;
             *      var rotation = componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation.ToForwardVector();
             *      entity.FindComponent<ComponentTrain>(true).SetDirection(RailBlock.IsDirectionX(RailBlock.GetRailType(Terrain.ExtractData(result.Value.Value)))
             *              ? rotation.Z < 0 ? 0 : 2
             *              : rotation.X < 0 ? 1 : 3);
             *      goto put;
             * }*/
            else if (activeBlockValue == ItemBlock.IdTable["基因查看器"])
            {
                body = componentMiner.PickBody(start, direction);
                if (body.HasValue && (!result.HasValue || body.Value.Distance < result.Value.Distance))
                {
                    var cv = body.Value.ComponentBody.Entity.FindComponent <ComponentVariant>();
                    if (cv != null)
                    {
                        DialogsManager.ShowDialog(componentMiner.ComponentPlayer?.View.GameWidget, new MessageDialog("Result", cv.Genome.ToString(), "OK", null, null));
                    }
                    return(true);
                }
            }
            else if (result.HasValue)
            {
                position = result.Value.RaycastStart + Vector3.Normalize(result.Value.RaycastEnd - result.Value.RaycastStart) * result.Value.Distance;
                if (activeBlockValue == ItemBlock.IdTable["SteamBoat"])
                {
                    entity = DatabaseManager.CreateEntity(Project, "SteamBoat", true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    goto put;
                }

                /*else if (activeBlockValue == ItemBlock.IdTable["Minecart"])
                 * {
                 *      entity = DatabaseManager.CreateEntity(Project, "Carriage", true);
                 *      entity.FindComponent<ComponentFrame>(true).Position = position;
                 *      entity.FindComponent<ComponentSpawn>(true).SpawnDuration = 0f;
                 *      var componentTrain = entity.FindComponent<ComponentTrain>(true);
                 *      var componentMount = componentTrain.FindNearestTrain();
                 *      if (componentMount != null)
                 *              componentTrain.ParentBody = componentMount.m_componentBody;
                 *      goto put;
                 * }*/
                else if (activeBlockValue == ItemBlock.IdTable["Airship"])
                {
                    entity = DatabaseManager.CreateEntity(Project, "Airship", true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    goto put;
                }
                else if (BlocksManager.Blocks[Terrain.ExtractContents(activeBlockValue)] is ItemBlock itemblock && itemblock.GetItem(ref activeBlockValue) is Mine mine)
                {
                    entity = DatabaseManager.CreateEntity(Project, "Mine", new ValuesDictionary
                    {
                        { "Mine", new ValuesDictionary {
                              { "Type", mine.MineType }
                          } }
                    }, true);
                    entity.FindComponent <ComponentFrame>(true).Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, m_random.UniformFloat(0f, 6.283185f));
                    var componentMine = entity.FindComponent <ComponentMine>(true);
                    componentMine.ExplosionPressure = mine.ExplosionPressure;
                    componentMine.Delay             = mine.Delay;
                    goto put;
                }
            }
            IInventory           inventory = componentMiner.Inventory;
            TerrainRaycastResult?result2;

            if (Terrain.ExtractContents(activeBlockValue) == 90)
            {
                result2 = componentMiner.PickTerrainForGathering(start, direction);
                if (result2.HasValue)
                {
                    CellFace cellFace  = result2.Value.CellFace;
                    int      cellValue = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z), 0);
                    if (cellValue != (RottenMeatBlock.Index | 1 << 4 << 14))
                    {
                        return(false);
                    }
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, RottenMeatBlock.Index | 2 << 4 << 14, 1);
                    }
                    Utils.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, false, false);
                    return(true);
                }
            }
            if (activeBlockValue == (RottenMeatBlock.Index | 2 << 4 << 14))
            {
                result2 = componentMiner.PickTerrainForInteraction(start, direction);
                if (result2.HasValue && componentMiner.Place(result2.Value, RottenMeatBlock.Index | 1 << 4 << 14))
                {
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, Terrain.ReplaceContents(activeBlockValue, 90), 1);
                    }
                    return(true);
                }
            }
            return(false);

put:
            entity.FindComponent <ComponentBody>(true).Position       = position;
            entity.FindComponent <ComponentSpawn>(true).SpawnDuration = 0f;
            Project.AddEntity(entity);
            componentMiner.RemoveActiveTool(1);
            Utils.SubsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, position, 3f, true);
            return(true);
        }
        public override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
        {
            IInventory inventory        = componentMiner.Inventory;
            int        activeBlockValue = componentMiner.ActiveBlockValue;
            int        num = Terrain.ExtractContents(activeBlockValue);

            if (num == 90)
            {
                object obj = componentMiner.Raycast(ray, RaycastMode.Gathering);
                if (obj is TerrainRaycastResult)
                {
                    CellFace cellFace  = ((TerrainRaycastResult)obj).CellFace;
                    int      cellValue = base.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z);
                    int      num2      = Terrain.ExtractContents(cellValue);
                    int      data      = Terrain.ExtractData(cellValue);
                    Block    block     = BlocksManager.Blocks[num2];
                    if (block is WaterBlock && FluidBlock.GetLevel(data) == 0)
                    {
                        int value = Terrain.ReplaceContents(activeBlockValue, 91);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value, 1);
                        }
                        base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false);
                        return(true);
                    }
                    if (block is MagmaBlock && FluidBlock.GetLevel(data) == 0)
                    {
                        int value2 = Terrain.ReplaceContents(activeBlockValue, 93);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value2, 1);
                        }
                        base.SubsystemTerrain.DestroyCell(0, cellFace.X, cellFace.Y, cellFace.Z, 0, noDrop: false, noParticleSystem: false);
                        return(true);
                    }
                }
                else if (obj is BodyRaycastResult)
                {
                    ComponentUdder componentUdder = ((BodyRaycastResult)obj).ComponentBody.Entity.FindComponent <ComponentUdder>();
                    if (componentUdder != null && componentUdder.Milk(componentMiner))
                    {
                        int value3 = Terrain.ReplaceContents(activeBlockValue, 110);
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, inventory.GetSlotCount(inventory.ActiveSlotIndex));
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value3, 1);
                        }
                        m_subsystemAudio.PlaySound("Audio/Milked", 1f, 0f, ray.Position, 2f, autoDelay: true);
                    }
                    return(true);
                }
            }
            if (num == 91)
            {
                TerrainRaycastResult?terrainRaycastResult = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);
                if (terrainRaycastResult.HasValue && componentMiner.Place(terrainRaycastResult.Value, Terrain.MakeBlockValue(18)))
                {
                    inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                    if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                    {
                        int value4 = Terrain.ReplaceContents(activeBlockValue, 90);
                        inventory.AddSlotItems(inventory.ActiveSlotIndex, value4, 1);
                    }
                    return(true);
                }
            }
            if (num == 93)
            {
                TerrainRaycastResult?terrainRaycastResult2 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Interaction);
                if (terrainRaycastResult2.HasValue)
                {
                    if (componentMiner.Place(terrainRaycastResult2.Value, Terrain.MakeBlockValue(92)))
                    {
                        inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
                        if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0)
                        {
                            int value5 = Terrain.ReplaceContents(activeBlockValue, 90);
                            inventory.AddSlotItems(inventory.ActiveSlotIndex, value5, 1);
                        }
                    }
                    return(true);
                }
            }
            switch (num)
            {
            case 110:
            case 245:
                return(true);

            case 251:
            case 252:
                return(true);

            case 128:
            case 129:
            {
                TerrainRaycastResult?terrainRaycastResult3 = componentMiner.Raycast <TerrainRaycastResult>(ray, RaycastMode.Digging);
                if (terrainRaycastResult3.HasValue)
                {
                    CellFace cellFace2  = terrainRaycastResult3.Value.CellFace;
                    int      cellValue2 = base.SubsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
                    int      num3       = Terrain.ExtractContents(cellValue2);
                    Block    block2     = BlocksManager.Blocks[num3];
                    if (block2 is IPaintableBlock)
                    {
                        Vector3 normal   = CellFace.FaceToVector3(terrainRaycastResult3.Value.CellFace.Face);
                        Vector3 position = terrainRaycastResult3.Value.HitPoint();
                        int?    num4     = (num == 128) ? null : new int?(PaintBucketBlock.GetColor(Terrain.ExtractData(activeBlockValue)));
                        Color   color    = num4.HasValue ? SubsystemPalette.GetColor(base.SubsystemTerrain, num4) : new Color(128, 128, 128, 128);
                        int     value6   = ((IPaintableBlock)block2).Paint(base.SubsystemTerrain, cellValue2, num4);
                        base.SubsystemTerrain.ChangeCell(cellFace2.X, cellFace2.Y, cellFace2.Z, value6);
                        componentMiner.DamageActiveTool(1);
                        m_subsystemAudio.PlayRandomSound("Audio/Paint", 0.4f, m_random.Float(-0.1f, 0.1f), componentMiner.ComponentCreature.ComponentBody.Position, 2f, autoDelay: true);
                        m_subsystemParticles.AddParticleSystem(new PaintParticleSystem(base.SubsystemTerrain, position, normal, color));
                    }
                    return(true);
                }
                break;
            }
            }
            return(false);
        }
 public void Update(float dt)
 {
     if (m_firePointsCopy.Count == 0)
     {
         m_firePointsCopy.Count += m_fireData.Count;
         m_fireData.Keys.CopyTo(m_firePointsCopy.Array, 0);
         m_copyIndex        = 0;
         m_lastScanDuration = (float)(m_subsystemTime.GameTime - m_lastScanTime);
         m_lastScanTime     = m_subsystemTime.GameTime;
         if (m_firePointsCopy.Count == 0)
         {
             m_fireSoundVolume = 0f;
         }
     }
     if (m_firePointsCopy.Count > 0)
     {
         float num  = MathUtils.Min(1f * dt * (float)m_firePointsCopy.Count + m_remainderToScan, 50f);
         int   num2 = (int)num;
         m_remainderToScan = num - (float)num2;
         int num3 = MathUtils.Min(m_copyIndex + num2, m_firePointsCopy.Count);
         while (m_copyIndex < num3)
         {
             if (m_fireData.TryGetValue(m_firePointsCopy.Array[m_copyIndex], out FireData value))
             {
                 int x    = value.Point.X;
                 int y    = value.Point.Y;
                 int z    = value.Point.Z;
                 int num4 = Terrain.ExtractData(base.SubsystemTerrain.Terrain.GetCellValue(x, y, z));
                 m_fireSoundIntensity += 1f / (m_subsystemAudio.CalculateListenerDistanceSquared(new Vector3(x, y, z)) + 0.01f);
                 if ((num4 & 1) != 0)
                 {
                     value.Time0 -= m_lastScanDuration;
                     if (value.Time0 <= 0f)
                     {
                         QueueBurnAway(x, y, z + 1, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x + expansionProbability.Key.X, y + expansionProbability.Key.Y, z + 1 + expansionProbability.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if ((num4 & 2) != 0)
                 {
                     value.Time1 -= m_lastScanDuration;
                     if (value.Time1 <= 0f)
                     {
                         QueueBurnAway(x + 1, y, z, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability2 in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability2.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x + 1 + expansionProbability2.Key.X, y + expansionProbability2.Key.Y, z + expansionProbability2.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if ((num4 & 4) != 0)
                 {
                     value.Time2 -= m_lastScanDuration;
                     if (value.Time2 <= 0f)
                     {
                         QueueBurnAway(x, y, z - 1, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability3 in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability3.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x + expansionProbability3.Key.X, y + expansionProbability3.Key.Y, z - 1 + expansionProbability3.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if ((num4 & 8) != 0)
                 {
                     value.Time3 -= m_lastScanDuration;
                     if (value.Time3 <= 0f)
                     {
                         QueueBurnAway(x - 1, y, z, value.FireExpandability * 0.85f);
                     }
                     foreach (KeyValuePair <Point3, float> expansionProbability4 in m_expansionProbabilities)
                     {
                         if (m_random.Float(0f, 1f) < expansionProbability4.Value * m_lastScanDuration * value.FireExpandability)
                         {
                             m_toExpand[new Point3(x - 1 + expansionProbability4.Key.X, y + expansionProbability4.Key.Y, z + expansionProbability4.Key.Z)] = value.FireExpandability * 0.85f;
                         }
                     }
                 }
                 if (num4 == 0)
                 {
                     value.Time5 -= m_lastScanDuration;
                     if (value.Time5 <= 0f)
                     {
                         QueueBurnAway(x, y - 1, z, value.FireExpandability * 0.85f);
                     }
                 }
             }
             m_copyIndex++;
         }
         if (m_copyIndex >= m_firePointsCopy.Count)
         {
             m_fireSoundVolume = 0.75f * m_fireSoundIntensity;
             m_firePointsCopy.Clear();
             m_fireSoundIntensity = 0f;
         }
     }
     if (m_subsystemTime.PeriodicGameTimeEvent(5.0, 0.0))
     {
         int num5 = 0;
         int num6 = 0;
         foreach (KeyValuePair <Point3, float> item in m_toBurnAway)
         {
             Point3 key    = item.Key;
             float  value2 = item.Value;
             base.SubsystemTerrain.ChangeCell(key.X, key.Y, key.Z, Terrain.ReplaceContents(0, 0));
             if (value2 > 0.25f)
             {
                 for (int i = 0; i < 5; i++)
                 {
                     Point3 point = CellFace.FaceToPoint3(i);
                     SetCellOnFire(key.X + point.X, key.Y + point.Y, key.Z + point.Z, value2);
                 }
             }
             float num7 = m_subsystemViews.CalculateDistanceFromNearestView(new Vector3(key));
             if (num5 < 15 && num7 < 24f)
             {
                 m_subsystemParticles.AddParticleSystem(new BurntDebrisParticleSystem(base.SubsystemTerrain, key.X, key.Y, key.Z));
                 num5++;
             }
             if (num6 < 4 && num7 < 16f)
             {
                 m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.25f, 0.25f), new Vector3(key.X, key.Y, key.Z), 3f, autoDelay: true);
                 num6++;
             }
         }
         foreach (KeyValuePair <Point3, float> item2 in m_toExpand)
         {
             SetCellOnFire(item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value);
         }
         m_toBurnAway.Clear();
         m_toExpand.Clear();
     }
     m_subsystemAmbientSounds.FireSoundVolume = MathUtils.Max(m_subsystemAmbientSounds.FireSoundVolume, m_fireSoundVolume);
 }
예제 #17
0
        public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
        {
            Vector3 forward = Matrix.CreateFromQuaternion(componentMiner.ComponentCreature.ComponentCreatureModel.EyeRotation).Forward;
            float   num     = Vector3.Dot(forward, Vector3.UnitZ);
            float   num2    = Vector3.Dot(forward, Vector3.UnitX);
            float   num3    = Vector3.Dot(forward, -Vector3.UnitZ);
            float   num4    = Vector3.Dot(forward, -Vector3.UnitX);
            int     num5    = 0;

            if (num == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 2;
            }
            else if (num2 == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 3;
            }
            else if (num3 == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 0;
            }
            else if (num4 == MathUtils.Max(num, num2, num3, num4))
            {
                num5 = 1;
            }
            Point3 point = CellFace.FaceToPoint3(raycastResult.CellFace.Face);
            int    num6  = raycastResult.CellFace.X + point.X;
            int    y     = raycastResult.CellFace.Y + point.Y;
            int    num7  = raycastResult.CellFace.Z + point.Z;
            int    num8  = 0;
            int    num9  = 0;

            switch (num5)
            {
            case 0:
                num8 = -1;
                break;

            case 1:
                num9 = 1;
                break;

            case 2:
                num8 = 1;
                break;

            default:
                num9 = -1;
                break;
            }
            int   cellValue           = subsystemTerrain.Terrain.GetCellValue(num6 + num8, y, num7 + num9);
            int   cellValue2          = subsystemTerrain.Terrain.GetCellValue(num6 - num8, y, num7 - num9);
            Block block               = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)];
            Block block2              = BlocksManager.Blocks[Terrain.ExtractContents(cellValue2)];
            int   data                = Terrain.ExtractData(cellValue);
            int   data2               = Terrain.ExtractData(cellValue2);
            bool  flag                = false;
            int   data3               = SetRightHanded(rightHanded: (block is FenceGateBlock && GetRotation(data) == num5) || ((!(block2 is FenceGateBlock) || GetRotation(data2) != num5) && !block.IsCollidable), data: SetOpen(SetRotation(Terrain.ExtractData(value), num5), open: false));
            BlockPlacementData result = default(BlockPlacementData);

            result.Value    = Terrain.ReplaceData(Terrain.ReplaceContents(0, BlockIndex), data3);
            result.CellFace = raycastResult.CellFace;
            return(result);
        }
예제 #18
0
        public void Update(float dt)
        {
            Point3 coordinates = m_componentBlockEntity.Coordinates;

            if (m_heatLevel > 0f)
            {
                m_fireTimeRemaining = MathUtils.Max(0f, m_fireTimeRemaining - dt);
                if (m_fireTimeRemaining == 0f)
                {
                    m_heatLevel = 0f;
                }
            }
            if (m_updateSmeltingRecipe)
            {
                m_updateSmeltingRecipe = false;
                float heatLevel = 0f;
                if (m_heatLevel > 0f)
                {
                    heatLevel = m_heatLevel;
                }
                else
                {
                    Slot slot = m_slots[FuelSlotIndex];
                    if (slot.Count > 0)
                    {
                        int num = Terrain.ExtractContents(slot.Value);
                        heatLevel = BlocksManager.Blocks[num].FuelHeatLevel;
                    }
                }
                CraftingRecipe craftingRecipe = FindSmeltingRecipe(heatLevel);
                if (craftingRecipe != m_smeltingRecipe)
                {
                    m_smeltingRecipe   = ((craftingRecipe != null && craftingRecipe.ResultValue != 0) ? craftingRecipe : null);
                    m_smeltingProgress = 0f;
                }
            }
            if (m_smeltingRecipe == null)
            {
                m_heatLevel         = 0f;
                m_fireTimeRemaining = 0f;
            }
            if (m_smeltingRecipe != null && m_fireTimeRemaining <= 0f)
            {
                Slot slot2 = m_slots[FuelSlotIndex];
                if (slot2.Count > 0)
                {
                    int   num2  = Terrain.ExtractContents(slot2.Value);
                    Block block = BlocksManager.Blocks[num2];
                    if (block.GetExplosionPressure(slot2.Value) > 0f)
                    {
                        slot2.Count = 0;
                        m_subsystemExplosions.TryExplodeBlock(coordinates.X, coordinates.Y, coordinates.Z, slot2.Value);
                    }
                    else if (block.FuelHeatLevel > 0f)
                    {
                        slot2.Count--;
                        m_fireTimeRemaining = block.FuelFireDuration;
                        m_heatLevel         = block.FuelHeatLevel;
                    }
                }
            }
            if (m_fireTimeRemaining <= 0f)
            {
                m_smeltingRecipe   = null;
                m_smeltingProgress = 0f;
            }
            if (m_smeltingRecipe != null)
            {
                m_smeltingProgress = MathUtils.Min(m_smeltingProgress + 0.15f * dt, 1f);
                if (m_smeltingProgress >= 1f)
                {
                    for (int i = 0; i < m_furnaceSize; i++)
                    {
                        if (m_slots[i].Count > 0)
                        {
                            m_slots[i].Count--;
                        }
                    }
                    m_slots[ResultSlotIndex].Value  = m_smeltingRecipe.ResultValue;
                    m_slots[ResultSlotIndex].Count += m_smeltingRecipe.ResultCount;
                    if (m_smeltingRecipe.RemainsValue != 0 && m_smeltingRecipe.RemainsCount > 0)
                    {
                        m_slots[RemainsSlotIndex].Value  = m_smeltingRecipe.RemainsValue;
                        m_slots[RemainsSlotIndex].Count += m_smeltingRecipe.RemainsCount;
                    }
                    m_smeltingRecipe       = null;
                    m_smeltingProgress     = 0f;
                    m_updateSmeltingRecipe = true;
                }
            }
            TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(coordinates.X, coordinates.Z);

            if (chunkAtCell != null && chunkAtCell.State == TerrainChunkState.Valid)
            {
                int cellValue = m_subsystemTerrain.Terrain.GetCellValue(coordinates.X, coordinates.Y, coordinates.Z);
                m_subsystemTerrain.ChangeCell(coordinates.X, coordinates.Y, coordinates.Z, Terrain.ReplaceContents(cellValue, (m_heatLevel > 0f) ? 65 : 64));
            }
        }