Example #1
0
        public void FindMovingBlocksCollisionBoxes(Vector3 position, DynamicArray <CollisionBox> result)
        {
            Vector3     boxSize     = BoxSize;
            BoundingBox boundingBox = new BoundingBox(position - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f), position + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f));

            boundingBox.Min -= new Vector3(1f);
            boundingBox.Max += new Vector3(1f);
            m_movingBlockSets.Clear();
            m_subsystemMovingBlocks.FindMovingBlocks(boundingBox, extendToFillCells: false, m_movingBlockSets);
            for (int i = 0; i < m_movingBlockSets.Count; i++)
            {
                IMovingBlockSet movingBlockSet = m_movingBlockSets.Array[i];
                for (int j = 0; j < movingBlockSet.Blocks.Count; j++)
                {
                    MovingBlock movingBlock = movingBlockSet.Blocks[j];
                    int         num         = Terrain.ExtractContents(movingBlock.Value);
                    Block       block       = BlocksManager.Blocks[num];
                    if (block.IsCollidable)
                    {
                        BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(m_subsystemTerrain, movingBlock.Value);
                        Vector3       v = new Vector3(movingBlock.Offset) + movingBlockSet.Position;
                        for (int k = 0; k < customCollisionBoxes.Length; k++)
                        {
                            result.Add(new CollisionBox
                            {
                                Box           = new BoundingBox(v + customCollisionBoxes[k].Min, v + customCollisionBoxes[k].Max),
                                BlockValue    = movingBlock.Value,
                                BlockVelocity = movingBlockSet.CurrentVelocity
                            });
                        }
                    }
                }
            }
        }
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemTime             = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemTerrain          = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemSky              = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemAnimatedTextures = base.Project.FindSubsystem <SubsystemAnimatedTextures>(throwOnError: true);
     m_shader = ContentManager.Get <Shader>("Shaders/AlphaTested");
     foreach (ValuesDictionary value9 in valuesDictionary.GetValue <ValuesDictionary>("MovingBlockSets").Values)
     {
         Vector3            value  = value9.GetValue <Vector3>("Position");
         Vector3            value2 = value9.GetValue <Vector3>("TargetPosition");
         float              value3 = value9.GetValue <float>("Speed");
         float              value4 = value9.GetValue <float>("Acceleration");
         float              value5 = value9.GetValue <float>("Drag");
         Vector2            value6 = value9.GetValue("Smoothness", Vector2.Zero);
         string             value7 = value9.GetValue <string>("Id", null);
         object             value8 = value9.GetValue <object>("Tag", null);
         List <MovingBlock> list   = new List <MovingBlock>();
         string[]           array  = value9.GetValue <string>("Blocks").Split(new char[1]
         {
             ';'
         }, StringSplitOptions.RemoveEmptyEntries);
         foreach (string obj2 in array)
         {
             MovingBlock item   = default(MovingBlock);
             string[]    array2 = obj2.Split(new char[1]
             {
                 ','
             }, StringSplitOptions.RemoveEmptyEntries);
             item.Value    = HumanReadableConverter.ConvertFromString <int>(array2[0]);
             item.Offset.X = HumanReadableConverter.ConvertFromString <int>(array2[1]);
             item.Offset.Y = HumanReadableConverter.ConvertFromString <int>(array2[2]);
             item.Offset.Z = HumanReadableConverter.ConvertFromString <int>(array2[3]);
             list.Add(item);
         }
         AddMovingBlockSet(value, value2, value3, value4, value5, value6, list, value7, value8, testCollision: false);
     }
 }
Example #3
0
 public bool TryModifyItem(ScannedItemData itemData, int newValue)
 {
     if (itemData.Container is IInventory)
     {
         IInventory obj = (IInventory)itemData.Container;
         obj.RemoveSlotItems(itemData.IndexInContainer, itemData.Count);
         int slotCapacity = obj.GetSlotCapacity(itemData.IndexInContainer, newValue);
         obj.AddSlotItems(itemData.IndexInContainer, newValue, MathUtils.Min(itemData.Count, slotCapacity));
         return(true);
     }
     if (itemData.Container is WorldItem)
     {
         ((WorldItem)itemData.Container).Value = newValue;
         return(true);
     }
     if (itemData.Container is IMovingBlockSet)
     {
         IMovingBlockSet obj2        = (IMovingBlockSet)itemData.Container;
         MovingBlock     movingBlock = obj2.Blocks.ElementAt(itemData.IndexInContainer);
         obj2.SetBlock(movingBlock.Offset, newValue);
         return(true);
     }
     return(false);
 }
Example #4
0
        public bool MovePiston(Point3 position, int length)
        {
            Terrain    terrain      = m_subsystemTerrain.Terrain;
            int        data         = Terrain.ExtractData(terrain.GetCellValue(position.X, position.Y, position.Z));
            int        face         = PistonBlock.GetFace(data);
            PistonMode mode         = PistonBlock.GetMode(data);
            int        maxExtension = PistonBlock.GetMaxExtension(data);
            int        pullCount    = PistonBlock.GetPullCount(data);
            int        speed        = PistonBlock.GetSpeed(data);
            Point3     point        = CellFace.FaceToPoint3(face);

            length = MathUtils.Clamp(length, 0, maxExtension + 1);
            int num = 0;

            m_movingBlocks.Clear();
            Point3      offset = point;
            MovingBlock item;

            while (m_movingBlocks.Count < 8)
            {
                int cellValue = terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z);
                int num2      = Terrain.ExtractContents(cellValue);
                int face2     = PistonHeadBlock.GetFace(Terrain.ExtractData(cellValue));
                if (num2 != 238 || face2 != face)
                {
                    break;
                }
                DynamicArray <MovingBlock> movingBlocks = m_movingBlocks;
                item = new MovingBlock
                {
                    Offset = offset,
                    Value  = cellValue
                };
                movingBlocks.Add(item);
                offset += point;
                num++;
            }
            if (length > num)
            {
                DynamicArray <MovingBlock> movingBlocks2 = m_movingBlocks;
                item = new MovingBlock
                {
                    Offset = Point3.Zero,
                    Value  = Terrain.MakeBlockValue(238, 0, PistonHeadBlock.SetFace(PistonHeadBlock.SetMode(PistonHeadBlock.SetIsShaft(0, num > 0), mode), face))
                };
                movingBlocks2.Add(item);
                int num3 = 0;
                while (num3 < 8)
                {
                    int cellValue2 = terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z);
                    if (!IsBlockMovable(cellValue2, face, position.Y + offset.Y, out bool isEnd))
                    {
                        break;
                    }
                    DynamicArray <MovingBlock> movingBlocks3 = m_movingBlocks;
                    item = new MovingBlock
                    {
                        Offset = offset,
                        Value  = cellValue2
                    };
                    movingBlocks3.Add(item);
                    num3++;
                    offset += point;
                    if (isEnd)
                    {
                        break;
                    }
                }
                if (!IsBlockBlocking(terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z)))
                {
                    GetSpeedAndSmoothness(speed, out float speed2, out Vector2 smoothness);
                    Point3 p = position + (length - num) * point;
                    if (m_subsystemMovingBlocks.AddMovingBlockSet(new Vector3(position) + 0.01f * new Vector3(point), new Vector3(p), speed2, 0f, 0f, smoothness, m_movingBlocks, "Piston", position, testCollision: true) != null)
                    {
                        m_allowPistonHeadRemove = true;
                        try
                        {
                            foreach (MovingBlock movingBlock in m_movingBlocks)
                            {
                                if (movingBlock.Offset != Point3.Zero)
                                {
                                    m_subsystemTerrain.ChangeCell(position.X + movingBlock.Offset.X, position.Y + movingBlock.Offset.Y, position.Z + movingBlock.Offset.Z, 0);
                                }
                            }
                        }
                        finally
                        {
                            m_allowPistonHeadRemove = false;
                        }
                        m_subsystemTerrain.ChangeCell(position.X, position.Y, position.Z, Terrain.MakeBlockValue(237, 0, PistonBlock.SetIsExtended(data, isExtended: true)));
                        m_subsystemAudio.PlaySound("Audio/Piston", 1f, 0f, new Vector3(position), 2f, autoDelay: true);
                    }
                }
                return(false);
            }
            if (length < num)
            {
                if (mode != 0)
                {
                    int num4 = 0;
                    for (int i = 0; i < pullCount + 1; i++)
                    {
                        int cellValue3 = terrain.GetCellValue(position.X + offset.X, position.Y + offset.Y, position.Z + offset.Z);
                        if (!IsBlockMovable(cellValue3, face, position.Y + offset.Y, out bool isEnd2))
                        {
                            break;
                        }
                        DynamicArray <MovingBlock> movingBlocks4 = m_movingBlocks;
                        item = new MovingBlock
                        {
                            Offset = offset,
                            Value  = cellValue3
                        };
                        movingBlocks4.Add(item);
                        offset += point;
                        num4++;
                        if (isEnd2)
                        {
                            break;
                        }
                    }
                    if (mode == PistonMode.StrictPulling && num4 < pullCount + 1)
                    {
                        return(false);
                    }
                }
                GetSpeedAndSmoothness(speed, out float speed3, out Vector2 smoothness2);
                float   s = (length == 0) ? 0.01f : 0f;
                Vector3 targetPosition = new Vector3(position) + (length - num) * new Vector3(point) + s * new Vector3(point);
                if (m_subsystemMovingBlocks.AddMovingBlockSet(new Vector3(position), targetPosition, speed3, 0f, 0f, smoothness2, m_movingBlocks, "Piston", position, testCollision: true) != null)
                {
                    m_allowPistonHeadRemove = true;
                    try
                    {
                        foreach (MovingBlock movingBlock2 in m_movingBlocks)
                        {
                            m_subsystemTerrain.ChangeCell(position.X + movingBlock2.Offset.X, position.Y + movingBlock2.Offset.Y, position.Z + movingBlock2.Offset.Z, 0);
                        }
                    }
                    finally
                    {
                        m_allowPistonHeadRemove = false;
                    }
                    m_subsystemAudio.PlaySound("Audio/Piston", 1f, 0f, new Vector3(position), 2f, autoDelay: true);
                }
                return(false);
            }
            return(true);
        }