Esempio n. 1
0
    private void ForceMove(BlockInstance bI, Vector3Int pos) //z is layer
    {
        //move thing to grid pos
        if (CurrentLevel[bI.gridPos.x, bI.gridPos.y, bI.gridPos.z] == bI)
        {
            CurrentLevel[bI.gridPos.x, bI.gridPos.y, bI.gridPos.z] = null;
        }
        CurrentLevel[pos.x, pos.y, pos.z] = bI;
        bI.gridPos = pos;

        bI.gameObject.transform.localPosition = new Vector3(pos.x, 0, pos.y);
    }
Esempio n. 2
0
        public World(int startPointX, int endPointX, int startPointY, int endPointY)
        {
            StartPointX = startPointX;
            EndPointX   = endPointX;
            StartPointY = startPointY;
            EndPointY   = endPointY;

            Chunk     = new BlockInstance[Mathf.Abs(StartPointY) + Mathf.Abs(EndPointY), Mathf.Abs(StartPointX) + Mathf.Abs(EndPointX)];
            Changes   = new BlockInstance[Mathf.Abs(StartPointY) + Mathf.Abs(EndPointY), Mathf.Abs(StartPointX) + Mathf.Abs(EndPointX)];
            Obstacles = new List <BlockInstance>();
            Items     = new List <ItemInstance>();
        }
        public override void UpdateInstance(BlockInstance instance)
        {
            var data = instance.GetData <MotionData>();

            if (HitForward(instance))
            {
                if (HitBackward(instance))
                {
                    data.velocity = Vector2.zero;
                }
                else if (Mathf.Approximately(data.velocity.magnitude, 0))
                {
                    data.velocity = (Direction == MoveDirection.Horizontal ? Vector2.left : Vector2.down) * Speed;
                }
                else
                {
                    data.velocity = -data.velocity;
                }
            }
            else if (Mathf.Approximately(data.velocity.magnitude, 0))
            {
                data.velocity = (Direction == MoveDirection.Horizontal ? Vector2.left : Vector2.down) * Speed;
            }

            instance.GetComponent <Rigidbody2D>().velocity = data.velocity;

            /*
             * if (MergeMode == BlockMergeMode.Both)
             * {
             *
             * }
             * else
             * {
             *  var pos = instance.transform.position.ToVector2() + instance.BoxCollider.offset;
             *  var dir = instance.BoxCollider.size / 2 * data.velocity.normalized;
             *  var count = Physics2D.RaycastNonAlloc(pos, dir.normalized, hits, dir.magnitude, 1 << 11);
             *  Debug.DrawLine(pos, pos + dir, Color.red);
             *  for (int i = 0; i < count; i++)
             *  {
             *      if (hits[i].collider.isTrigger)
             *          continue;
             *      if (hits[i].rigidbody == instance.GetComponent<Rigidbody2D>())
             *          continue;
             *      var block = hits[i].rigidbody?.GetComponent<IBlockInstance>()?.GetContactedBlock(hits[i].point, hits[i].normal);
             *      if (block)
             *      {
             *          data.velocity = -data.velocity;
             *          break;
             *      }
             *  }
             *
             * }*/
        }
Esempio n. 4
0
    public void UpdateTick()
    {
        if (Engine.CurrentState != GameState.Playing)
        {
            return;
        }

        HitInfo info = GetHit();

        if (Input.GetMouseButtonUp(0))
        {
            currentAdd(info);
        }

        if (Input.GetMouseButtonUp(1))
        {
            DeleteBlock(info);
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            PickBlock(info);
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            UndoManager.Undo();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            UndoManager.Redo();
        }

        if (!reticleEnabled)
        {
            DisableReticle();
            return;
        }

        if (info.hit)
        {
            Vector3i pos = info.hitPos;
            currentBlock = new BlockInstance(Map.GetBlockSafe(pos.x, pos.y, pos.z), pos.x, pos.y, pos.z);
            EnableReticle();
            reticle.position = info.hitPos;
        }
        else
        {
            DisableReticle();
        }
    }
Esempio n. 5
0
    private void QueueBlocksForUnflowing()
    {
        for (int i = 0; i < blocksToUnflow.Count; i++)
        {
            BlockInstance b = blocksToUnflow[i];
            MapLight.RecomputeLighting(b.x, b.y, b.z);
            Map.FlagChunkForUpdate(b.x, b.y, b.z);

            unflowQueue.Enqueue(blocksToUnflow[i]);
        }

        Map.UpdateMeshes();
        blocksToUnflow = new List <BlockInstance>(128);
    }
Esempio n. 6
0
    public static void RegisterAction(BlockInstance prevBlock, BlockInstance newBlock)
    {
        List <BlockInstance> prevBlocks = new List <BlockInstance>();
        List <BlockInstance> newBlocks  = new List <BlockInstance>();

        prevBlocks.Add(prevBlock);
        newBlocks.Add(newBlock);

        Modification mod = new Modification(prevBlocks, newBlocks);

        undoStack.Push(mod);

        redoStack.Clear();
    }
Esempio n. 7
0
    public BlockInstance LoadBlock(LevelTemplate.BlockDefinition bD, BlockInstance linkedInstance, BlockInstance ownerInstance)
    {
        GameObject instance      = Instantiate(bD.block.Prefab, transform);
        Vector3    localPosition = bD.block.Prefab.gameObject.transform.localPosition + new Vector3(bD.position.x, 0.0f, bD.position.y);

        instance.transform.localPosition = localPosition;
        BlockInstance someBlockInstance = new BlockInstance
        {
            block       = bD.block,
            gameObject  = instance,
            gridPos     = Vector3Int.zero, //assign to this post def so we can check props for layer
            linkedBlock = null,            //assign in way we can undo
            ownerBlock  = null,
        };

        if (ownerInstance != null)
        {
            SetBlockOwner(someBlockInstance, ownerInstance);
        }
        if (linkedInstance != null)
        {
            SetBlockLink(someBlockInstance, linkedInstance);
        }
        List <Block.PROPERTY> sbProps = someBlockInstance.block.Properties;
        int layerAssign = 0;

        if (sbProps.Contains(Block.PROPERTY.Player))
        {
            layerAssign = 2;
        }
        else if (sbProps.Contains(Block.PROPERTY.Solid))
        {
            layerAssign = 1;
        }

        someBlockInstance.gridPos = new Vector3Int(bD.position.x, bD.position.y, layerAssign);
        if (sbProps.Contains(Block.PROPERTY.Solution))
        {
            SolutionBlockPositions.Add(someBlockInstance.gridPos);
        }

        CurrentLevel[bD.position.x, bD.position.y, layerAssign] = someBlockInstance;
        instance.SendMessage("SetBlockInstance", someBlockInstance, SendMessageOptions.DontRequireReceiver);
        //to undo
        Action unMake = () => { RemoveAt(new Vector3Int(bD.position.x, bD.position.y, layerAssign)); };

        undoInstructions.Peek().Enqueue(unMake);
        return(someBlockInstance);
    }
Esempio n. 8
0
    private void Update()
    {
        switch (info)
        {
        case DebugInfo.ID:
            Block block = MapInteraction.CurrentBlock.block;
            label.text = "Block: " + (int)block.ID + " (" + block.Name() + "), Data: " + block.data;
            break;

        case DebugInfo.Position:
            BlockInstance blockInst = MapInteraction.CurrentBlock;
            label.text = "Position: " + blockInst.x + " " + blockInst.y + " " + blockInst.z;
            break;
        }
    }
Esempio n. 9
0
        public static BlockInstance[,] ListToArray(List <List <BlockInstance> > list)
        {
            int height = list.Count;
            int width  = list[0].Count;

            BlockInstance[,] arr = new BlockInstance[height, width];

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    arr[y, x] = list[y][x];
                }
            }
            return(arr);
        }
Esempio n. 10
0
    private static void UnflowFluid(BlockInstance blockInst)
    {
        MapIndex curIndex   = new MapIndex(blockInst.x, blockInst.y, blockInst.z);
        int      fluidLevel = blockInst.block.FluidLevel;

        if (fluidLevel <= MinFluidLevel)
        {
            return;
        }

        UnflowIfPossible(blockInst.x, blockInst.y - 1, blockInst.z, curIndex, fluidLevel + 1);
        UnflowIfPossible(blockInst.x - 1, blockInst.y, blockInst.z, curIndex, fluidLevel);
        UnflowIfPossible(blockInst.x + 1, blockInst.y, blockInst.z, curIndex, fluidLevel);
        UnflowIfPossible(blockInst.x, blockInst.y, blockInst.z - 1, curIndex, fluidLevel);
        UnflowIfPossible(blockInst.x, blockInst.y, blockInst.z + 1, curIndex, fluidLevel);
    }
Esempio n. 11
0
    // public void ResetPlayerPosition()
    // {
    //    Player.transform.position = new Vector3(Levels[CurrentLevelIndex].PlayerStartPostion.x, 0.0f, Levels[CurrentLevelIndex].PlayerStartPostion.y);
    //    Player.transform.SetParent(gameObject.transform, false);
    //}

    public bool AttemptMove(BlockInstance someBlock, Vector2Int direction)
    {
        Vector2Int target = (Vector2Int)someBlock.gridPos + direction;

        if (WithinBounds(target, out int x, out int y) && CurrentLevel[target.x, target.y, 2] != null)
        {
            return(false);
        }

        if (someBlock.linkedBlock != null)
        {
            if (!someBlock.linkedBlock.script.CanLinkedMove(direction, someBlock.gridPos))
            {
                return(false);
            }
        }


        if (!CanMoveTo(someBlock, target, direction))
        {
            return(false);
        }
        //if (!(WithinBounds(target, out int x, out int y)))
        //{
        //    return false;
        //}

        //if (CurrentLevel[x, y, 1] != null) //solid at that position
        //{
        //    return false;
        //}
        //all clear
        //move self then cascade back
        //do not return control until all is done
        //Vector3Int storedPos = someBlock.gridPos;
        //Action unMove = () => { ForceMove(someBlock, storedPos); };

        //undoInstructions.Peek().Enqueue(unMove);

        //someBlock.gridPos = new Vector3Int(target.x, target.y, someBlock.gridPos.z); //stay in your lane
        //if (CurrentLevel[storedPos.x, storedPos.y, storedPos.z] == someBlock)
        //    CurrentLevel[storedPos.x, storedPos.y, storedPos.z] = null; //remove self from last pos if something else isn't there
        //CurrentLevel[someBlock.gridPos.x, someBlock.gridPos.y, someBlock.gridPos.z] = someBlock; //assign self to new pos

        return(true);
    }
Esempio n. 12
0
        private async Task SelectedBlock(BlockInstance block)
        {
            // If we're switching between 2 blocks that have a Monaco Editor, do this to force a refresh
            // of the component, otherwise the text in the editor does not update
            if (selectedBlock != null && HasMonacoEditor(selectedBlock) &&
                block != null && HasMonacoEditor(block))
            {
                selectedBlock = null;
                StateHasChanged();
                await Task.Delay(1);

                selectedBlock = block;
            }
            else
            {
                selectedBlock = block;
            }
        }
Esempio n. 13
0
        private async Task SelectedBlock(BlockInstance block)
        {
            // If we're switching between 2 lolicode blocks, do this to force a refresh
            // of the component, otherwise the text in the editor does not update
            if (selectedBlock != null && selectedBlock is LoliCodeBlockInstance &&
                block != null && block is LoliCodeBlockInstance)
            {
                selectedBlock = null;
                StateHasChanged();
                await Task.Delay(1);

                selectedBlock = block;
            }
            else
            {
                selectedBlock = block;
            }
        }
Esempio n. 14
0
        public bool TrySetBlock(WorldPosition worldPosition, BlockInstance blockInstance)
        {
            var   chunkPosition = worldPosition.ToChunkPosition();
            Chunk chunk         = this.TryGetChunk(chunkPosition);

            if (chunk == null)
            {
                return(false);
            }

            var blockPosition = worldPosition.ToBlockPosition();

            chunk.TrySetBlock(blockPosition, blockInstance);
            chunk.UpdateMesh();

            if (blockPosition.X == 0)
            {
                this.UpdateChunkMesh(chunkPosition.PreviousX());
            }
            if (blockPosition.X == Constants.Context.ChunkDimensionLength - 1)
            {
                this.UpdateChunkMesh(chunkPosition.NextX());
            }

            if (blockPosition.Y == 0)
            {
                this.UpdateChunkMesh(chunkPosition.PreviousY());
            }
            if (blockPosition.Y == Constants.Context.ChunkDimensionLength - 1)
            {
                this.UpdateChunkMesh(chunkPosition.NextY());
            }

            if (blockPosition.Z == 0)
            {
                this.UpdateChunkMesh(chunkPosition.PreviousZ());
            }
            if (blockPosition.Z == Constants.Context.ChunkDimensionLength - 1)
            {
                this.UpdateChunkMesh(chunkPosition.NextZ());
            }

            return(true);
        }
Esempio n. 15
0
 public override void OnCollision(BlockInstance instance, Collision2D collision)
 {
     /*
      * if (collision.rigidbody.GetComponent<GameEntity>())
      *  return;
      * var data = instance.GetData<MotionData>();
      * for (int i = 0; i < collision.contactCount; i++)
      * {
      *  var contacts = new ContactPoint2D[10];
      *  instance.GetComponent<CompositeCollider2D>().co
      *  var contact = collision.GetContact(i);
      *  if (Vector2.Dot(contact.normal, data.velocity.normalized) < -0.9f)
      *  {
      *      Debug.DrawLine(contact.point, contact.point + contact.normal, Color.blue);
      *      data.velocity = -data.velocity;
      *      instance.GetComponent<Rigidbody2D>().velocity = data.velocity;
      *  }
      * }*/
 }
Esempio n. 16
0
    public BlockInstance GetBlock(int x, int y, int z)
    {
        Chunk containerChunk = GetChunk(x, y, z);

        if (containerChunk != null)
        {
            BlockInstance block = containerChunk.GetBlock(
                x - containerChunk.pos.x,
                y - containerChunk.pos.y,
                z - containerChunk.pos.z);

            return(block);
        }
        else
        {
//            Debug.LogError("Block isn't in containerChunk", this);
            return(new BlockInstance());
//            return BlockDatabase.GetBlock(0);
        }
    }
Esempio n. 17
0
        /// <summary>
        /// Gets a block by <paramref name="id"/> and casts it to the requested type.
        /// </summary>
        public static T GetBlock <T>(string id) where T : BlockInstance
        {
            if (!Globals.DescriptorsRepository.Descriptors.TryGetValue(id, out BlockDescriptor descriptor))
            {
                throw new Exception($"Invalid block id: {id}");
            }

            BlockInstance instance = descriptor switch
            {
                AutoBlockDescriptor x => new AutoBlockInstance(x),
                KeycheckBlockDescriptor x => new KeycheckBlockInstance(x),
                HttpRequestBlockDescriptor x => new HttpRequestBlockInstance(x),
                ParseBlockDescriptor x => new ParseBlockInstance(x),
                ScriptBlockDescriptor x => new ScriptBlockInstance(x),
                _ => throw new NotImplementedException()
            };

            return(instance as T);
        }
    }
        void GenerateBlockInstance()
        {
            var position = transform.position.ToVector2();

            rotatedBlocks = new Blocks.BlocksCollection(ComponentData.Component.Rotate(rotateStep));
            if (!blockInstance)
            {
                blockInstance = BlockInstance.CreateInstance(new BlockInstanceOptions()
                {
                    BlockType        = rotatedBlocks.First().BlockType,
                    Blocks           = rotatedBlocks,
                    GenerateRenderer = true,
                    GenerateCollider = true,
                    IsTrigger        = true,
                    IsStatic         = true,
                    GameObject       = gameObject
                });
                var rigidbody = blockInstance.GetComponent <Rigidbody2D>();
                rigidbody.bodyType                    = RigidbodyType2D.Kinematic;
                rigidbody.sleepMode                   = RigidbodySleepMode2D.NeverSleep;
                blockInstance.transform.parent        = transform;
                blockInstance.transform.localPosition = Vector3.zero;
                BlockInstance = blockInstance;
            }
            else
            {
                blockInstance.UpdateInstance(new BlockInstanceOptions()
                {
                    BlockType        = rotatedBlocks.First().BlockType,
                    Blocks           = rotatedBlocks,
                    GenerateRenderer = true,
                    GenerateCollider = true,
                    IsTrigger        = true,
                    IsStatic         = true,
                    GameObject       = gameObject
                });
            }
            UI.sizeDelta = rotatedBlocks.Bound.size.ToVector2();
            MoveTo(position);
            renderers = GetComponentsInChildren <SpriteRenderer>();
        }
Esempio n. 19
0
    public LevelManager.BlockInstance[] GetAdjacentsOnLayer(Vector3Int pos)
    {
        Vector2Int upPos    = (Vector2Int)pos + Vector2Int.up;
        Vector2Int downPos  = (Vector2Int)pos + Vector2Int.down;
        Vector2Int leftPos  = (Vector2Int)pos + Vector2Int.left;
        Vector2Int rightPos = (Vector2Int)pos + Vector2Int.right;
        int        x        = 0;
        int        y        = 0;

        LevelManager.BlockInstance[] returnArray = new BlockInstance[4];
        returnArray[0] = (WithinBounds(upPos, out x, out y) &&
                          CurrentLevel[x, y, pos.z] != null) ? CurrentLevel[x, y, pos.z] : null;
        returnArray[1] = (WithinBounds(downPos, out x, out y) &&
                          CurrentLevel[x, y, pos.z] != null) ? CurrentLevel[x, y, pos.z] : null;
        returnArray[2] = (WithinBounds(leftPos, out x, out y) &&
                          CurrentLevel[x, y, pos.z] != null) ? CurrentLevel[x, y, pos.z] : null;
        returnArray[3] = (WithinBounds(rightPos, out x, out y) &&
                          CurrentLevel[x, y, pos.z] != null) ? CurrentLevel[x, y, pos.z] : null;

        return(returnArray);
    }
Esempio n. 20
0
        private void LoadMap()
        {
            World loadedWorld = World.LoadMap(World.WorldName, Seed);

            if (loadedWorld == null)
            {
                return;
            }
            var changes = loadedWorld.Changes;
            var chunk   = World.Chunk;

            World.Changes = changes;

            int height = chunk.GetLength(0);
            int width  = chunk.GetLength(1);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    var block = changes [y, x];
                    if (block != null)
                    {
                        Debug.Log(block);
                        if (block.BlockType == BlockTypes.Void)
                        {
                            Destroy(chunk[y, x].GameObject);
                            chunk [y, x] = null;
                        }
                        else
                        {
                            var current = Instantiate(PrefabRepository.Instance.GetBlockPrefab(block.BlockType), new Vector3(block.X, block.Y), Quaternion.identity) as GameObject;
                            current.transform.parent = Map.transform.GetChild(0).transform;
                            BlockInstance newBlock = new BlockInstance(block.BlockType, current, block.X, block.Y);
                            chunk[y, x] = newBlock;
                        }
                    }
                }
            }
        }
Esempio n. 21
0
        private void SearchForBlock()
        {
            var chunk  = World.Chunk;
            int height = chunk.GetLength(0);
            int width  = chunk.GetLength(1);

            int yCoord = height / 2 + Mathf.RoundToInt(CurrentMousePosition.y - 0.5f);
            int xCoord = width / 2 + Mathf.RoundToInt(CurrentMousePosition.x);

            BlockInstance block = (xCoord >= 0 && xCoord < width && yCoord >= 0 && yCoord < height)
                ? chunk[yCoord, xCoord]
                : null;

            if (block != null)
            {
                PrefabRepository.Instance.TxtBlockType.GetComponent <Text>().text = block.ToString();
            }
            else
            {
                PrefabRepository.Instance.TxtBlockType.GetComponent <Text>().text = "void";
            }
        }
Esempio n. 22
0
    public static void SetBlockAdvanced(int x, int y, int z, Block block, Vector3i normal, bool undo)
    {
        if (InBounds(x, y, z))
        {
            if (!block.CanPlace(normal, x, y, z))
            {
                return;
            }

            BlockInstance prevInst = new BlockInstance(GetBlock(x, y, z), x, y, z);
            BlockInstance newBlock = new BlockInstance(block, x, y, z);

            if (block.ID == BlockID.Air)
            {
                if (!prevInst.block.CanDelete())
                {
                    return;
                }

                prevInst.block.OnDelete(x, y, z);
            }
            else
            {
                block.OnPlace(normal, x, y, z);
            }

            if (undo)
            {
                UndoManager.RegisterAction(prevInst, newBlock);
            }

            SetBlock(x, y, z, block);

            MapLight.RecomputeLighting(x, y, z);

            FlagChunkForUpdate(x, y, z);
            UpdateMeshes();
        }
    }
Esempio n. 23
0
    public List <HashSet <Block.PROPERTY> > getBlockPropertiesAtEachSolutionPosition()
    {
        List <HashSet <Block.PROPERTY> > blockPropertiesAtEachSolutionPosition = new List <HashSet <Block.PROPERTY> >();

        foreach (Vector3Int solutionBlockPosition in SolutionBlockPositions)
        {
            HashSet <Block.PROPERTY> propertiesAtSolutionBlockPosition = new HashSet <Block.PROPERTY>();
            blockPropertiesAtEachSolutionPosition.Add(propertiesAtSolutionBlockPosition);

            // Check layers 1 and 2 for objects
            for (int zLayer = 0; zLayer < 3; zLayer++)
            {
                BlockInstance blockAtSolution = CurrentLevel[solutionBlockPosition.x, solutionBlockPosition.y, zLayer];

                if (blockAtSolution != null)
                {
                    propertiesAtSolutionBlockPosition.UnionWith(blockAtSolution.block.Properties);
                }
            }
        }

        return(blockPropertiesAtEachSolutionPosition);
    }
Esempio n. 24
0
        bool HitForward(BlockInstance instance)
        {
            var data = instance.GetData <MotionData>();
            var dir  = data.velocity.normalized * .5f;

            if (Mathf.Approximately(data.velocity.magnitude, 0))
            {
                dir = this.Direction == MoveDirection.Horizontal
                    ? Vector2.right
                    : Vector2.up;
            }
            dir += dir.normalized * 0.01f;
            for (var blockIdx = 0; blockIdx < instance.Blocks.BlocksList.Count; blockIdx++)
            {
                var block = instance.Blocks.BlocksList[blockIdx];
                var pos   = block.Position.ToVector3() - instance.Blocks.Bound.center + instance.transform.position + new Vector3(.5f, .5f, 0);
                var count = Physics2D.RaycastNonAlloc(pos, dir.normalized, hits, dir.magnitude, 1 << 11);
                Debug.DrawLine(pos, pos + dir.ToVector3(), Color.red);
                for (int i = 0; i < count; i++)
                {
                    if (hits[i].collider.isTrigger)
                    {
                        continue;
                    }
                    if (hits[i].rigidbody == instance.GetComponent <Rigidbody2D>())
                    {
                        continue;
                    }
                    var hitBlock = hits[i].rigidbody?.GetComponent <IBlockInstance>()?.GetContactedBlock(hits[i].point, hits[i].normal);
                    if (hitBlock)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 25
0
    public void RemoveAtUnchecked(Vector3Int pos)
    {
        if (CurrentLevel[pos.x, pos.y, pos.z] != null)
        {
            BlockInstance blockAtPos = CurrentLevel[pos.x, pos.y, pos.z];
            //LevelTemplate.BlockDefinition remakeDef = new LevelTemplate.BlockDefinition {
            //    position = new Vector2Int(pos.x, pos.y),
            //    block = CurrentLevel[pos.x,pos.y, pos.z].block};
            //Action remake = () => { LoadBlock(remakeDef, CurrentLevel[pos.x, pos.y, pos.z]?.linkedBlock, CurrentLevel[pos.x, pos.y, pos.z]?.ownerBlock); };
            Action revive = () => { ReviveBlock(blockAtPos); };
            undoInstructions.Peek().Enqueue(revive);
            CurrentLevel[pos.x, pos.y, pos.z].gameObject.SetActive(false);
        }
        if (CurrentLevel[pos.x, pos.y, pos.z]?.ownerBlock != null)
        {
            SetBlockLink(CurrentLevel[pos.x, pos.y, pos.z].ownerBlock, null);
        }
        //CurrentLevel[pos.x, pos.y, pos.z].ownerBlock.linkedBlock = null; //clear self from parent
        //make sure link is now a solid
        //if (CurrentLevel[pos.x, pos.y, pos.z]?.linkedBlock != null)
        //ProjectToSolid(CurrentLevel[pos.x, pos.y, pos.z].linkedBlock);

        CurrentLevel[pos.x, pos.y, pos.z] = null;
    }
Esempio n. 26
0
    private static void FlowFluid(BlockInstance blockInst)
    {
        MapIndex curIndex   = new MapIndex(blockInst.x, blockInst.y, blockInst.z);
        int      fluidLevel = blockInst.block.FluidLevel;

        // Flowing fluid reduces the fluid level by 1. Add 1 to MaxFluidLevel so that when we flow fluid
        // downward, it remains at the max level.
        bool success = FlowIfPossible(blockInst.x, blockInst.y - 1, blockInst.z, curIndex, MaxFluidLevel + 1, true);

        if (success)
        {
            return;
        }

        if (fluidLevel <= MinFluidLevel)
        {
            return;
        }

        FlowIfPossible(blockInst.x - 1, blockInst.y, blockInst.z, curIndex, fluidLevel);
        FlowIfPossible(blockInst.x + 1, blockInst.y, blockInst.z, curIndex, fluidLevel);
        FlowIfPossible(blockInst.x, blockInst.y, blockInst.z - 1, curIndex, fluidLevel);
        FlowIfPossible(blockInst.x, blockInst.y, blockInst.z + 1, curIndex, fluidLevel);
    }
Esempio n. 27
0
 /// <summary>
 /// Evaluates if the user is authorized to perform the requested action
 /// </summary>
 /// <param name="action"></param>
 /// <returns></returns>
 public bool UserAuthorized(string action)
 {
     return(BlockInstance.Authorized(action, CurrentUser));
 }
Esempio n. 28
0
 private IEnumerable <string> GetOutputVariables(BlockInstance block)
 => block switch
 {
Esempio n. 29
0
        private void RegenerateMap()
        {
            var chunk     = new BlockInstance[Mathf.Abs(World.StartPointY) + Mathf.Abs(World.EndPointY), Mathf.Abs(World.StartPointX) + Mathf.Abs(World.EndPointX)];
            var obstacles = new List <BlockInstance>();

            float blockWidth  = _repo.GetBlockPrefab(BlockTypes.Dirt).transform.lossyScale.x;
            float blockHeight = _repo.GetBlockPrefab(BlockTypes.Dirt).transform.lossyScale.y;

            int yOffset = Mathf.Abs(World.StartPointY);
            int xOffset = Mathf.Abs(World.StartPointX);

            for (int x = World.StartPointX; x < World.EndPointX; x++)
            {
                int curHeight = noise.GetNoise(x - World.StartPointX, World.EndPointY - World.StartPointY);
                for (int y = World.StartPointY; y < World.EndPointY; y++)
                {
                    if (y == World.StartPointY + curHeight)
                    {
                        float rand = Random.Range(0.0f, 1.0f);
                        if (rand > 0.95)
                        {
                            GameObject current = Instantiate(_repo.GetBlockPrefab(BlockTypes.Tree), new Vector3(x, y + 1.5f),
                                                             Quaternion.identity);
                            current.transform.parent = Map.transform.GetChild(1).transform;
                        }
                    }
                    else if (y < World.StartPointY + curHeight)
                    {
                        GameObject current = null;
                        if (y == World.StartPointY + curHeight - 1)
                        {
                            current = Instantiate(_repo.GetBlockPrefab(BlockTypes.Grass), new Vector2(x * blockWidth, y * blockHeight),
                                                  Quaternion.identity);
                            chunk[yOffset + y, xOffset + x] = new BlockInstance(BlockTypes.Grass, current, x, y);
                        }
                        else if (y < World.StartPointY + 0.5 * curHeight)
                        {
                            if (y < World.StartPointY + 0.25 * curHeight)
                            {
                                float rand = Random.Range(0.0f, 1.0f);
                                if (rand > 0.975)
                                {
                                    current = Instantiate(_repo.GetBlockPrefab(BlockTypes.Ore),
                                                          new Vector2(x * blockWidth, y * blockHeight),
                                                          Quaternion.identity);
                                    chunk[yOffset + y, xOffset + x] = new BlockInstance(BlockTypes.Ore, current, x, y);
                                }
                                else
                                {
                                    current = Instantiate(_repo.GetBlockPrefab(BlockTypes.Stone),
                                                          new Vector2(x * blockWidth, y * blockHeight),
                                                          Quaternion.identity);
                                    chunk[yOffset + y, xOffset + x] = new BlockInstance(BlockTypes.Stone, current, x, y);
                                }
                            }
                            else
                            {
                                current = Instantiate(_repo.GetBlockPrefab(BlockTypes.Stone),
                                                      new Vector2(x * blockWidth, y * blockHeight),
                                                      Quaternion.identity);
                                chunk[yOffset + y, xOffset + x] = new BlockInstance(BlockTypes.Stone, current, x, y);
                            }
                        }
                        else
                        {
                            current = Instantiate(_repo.GetBlockPrefab(BlockTypes.Dirt), new Vector2(x * blockWidth, y * blockHeight),
                                                  Quaternion.identity);
                            chunk[yOffset + y, xOffset + x] = new BlockInstance(BlockTypes.Dirt, current, x, y);
                        }
                        current.transform.parent = Map.transform.GetChild(0).transform;
                    }
                }
            }

            World.Chunk     = chunk;
            World.Obstacles = obstacles;
        }
Esempio n. 30
0
        /// <summary>
        /// Adds icons to the configuration area of a block instance.  Can be overridden to
        /// add additionsl icons
        /// </summary>
        /// <param name="canConfig"></param>
        /// <param name="canEdit"></param>
        /// <returns></returns>
        public virtual List <Control> GetConfigurationControls(bool canConfig, bool canEdit)
        {
            List <Control> configControls = new List <Control>();

            if (canConfig || canEdit)
            {
                // Attributes
                CompiledTemplateBuilder upContent = new CompiledTemplateBuilder(
                    delegate(Control content)
                {
                    Button trigger       = new Button();
                    trigger.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                    trigger.ID           = string.Format("blck-cnfg-trggr-{0}", BlockInstance.Id.ToString());
                    trigger.Click       += trigger_Click;
                    content.Controls.Add(trigger);

                    HiddenField triggerData  = new HiddenField();
                    triggerData.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                    triggerData.ID           = string.Format("blck-cnfg-trggr-data-{0}", BlockInstance.Id.ToString());
                    content.Controls.Add(triggerData);
                }
                    );

                UpdatePanel upTrigger = new UpdatePanel();
                upTrigger.ContentTemplate = upContent;
                configControls.Add(upTrigger);
                upTrigger.Attributes.Add("style", "display:none");

                // Icon to display block properties
                HtmlGenericControl aAttributes = new HtmlGenericControl("a");
                aAttributes.Attributes.Add("class", "properties icon-button show-modal-iframe");
                aAttributes.Attributes.Add("height", "500px");
                aAttributes.Attributes.Add("href", ResolveUrl(string.Format("~/BlockProperties/{0}?t=Block Properties", BlockInstance.Id)));
                //aAttributes.Attributes.Add( "instance-id", BlockInstance.Id.ToString() );
                configControls.Add(aAttributes);
            }

            if (canConfig)
            {
                // Security
                HtmlGenericControl aSecureBlock = new HtmlGenericControl("a");
                aSecureBlock.Attributes.Add("class", "security icon-button show-modal-iframe");
                aSecureBlock.Attributes.Add("height", "500px");
                aSecureBlock.Attributes.Add("href", ResolveUrl(string.Format("~/Secure/{0}/{1}?t=Block Security",
                                                                             Security.Authorization.EncodeEntityTypeName(BlockInstance.GetType()), BlockInstance.Id)));
                configControls.Add(aSecureBlock);

                // Move
                HtmlGenericControl aMoveBlock = new HtmlGenericControl("a");
                aMoveBlock.Attributes.Add("class", "block-move icon-button blockinstance-move");
                aMoveBlock.Attributes.Add("href", BlockInstance.Id.ToString());
                aMoveBlock.Attributes.Add("zone", BlockInstance.Zone);
                aMoveBlock.Attributes.Add("zoneloc", BlockInstance.BlockInstanceLocation.ToString());
                aMoveBlock.Attributes.Add("title", "Move");
                configControls.Add(aMoveBlock);

                // Delete
                HtmlGenericControl aDeleteBlock = new HtmlGenericControl("a");
                aDeleteBlock.Attributes.Add("class", "delete icon-button blockinstance-delete");
                aDeleteBlock.Attributes.Add("href", BlockInstance.Id.ToString());
                aDeleteBlock.Attributes.Add("title", "Delete");
                configControls.Add(aDeleteBlock);
            }

            return(configControls);
        }