private bool CheckForMovement()
    {
        DestinationTile = Pd.CurrentTile;
        if (Input.GetAxisRaw("Vertical") > 0)
        {
            Direction = Tile.Sides.Top;
            if (Pd.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Top))
            {
                DestinationTile = Pd.CurrentTile.Neighbours[Tile.Sides.Top];
            }
        }
        else if (Input.GetAxisRaw("Vertical") < 0)
        {
            Direction = Tile.Sides.Bottom;
            if (Pd.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Bottom))
            {
                DestinationTile = Pd.CurrentTile.Neighbours[Tile.Sides.Bottom];
            }
        }
        else if (Input.GetAxisRaw("Horizontal") > 0)
        {
            Direction = Tile.Sides.Right;
            if (Pd.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Right))
            {
                DestinationTile = Pd.CurrentTile.Neighbours[Tile.Sides.Right];
            }
        }
        else if (Input.GetAxisRaw("Horizontal") < 0)
        {
            Direction = Tile.Sides.Left;
            if (Pd.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Left))
            {
                DestinationTile = Pd.CurrentTile.Neighbours[Tile.Sides.Left];
            }
        }
        else
        {
            Pd.IsPerformingMovingAction = false;
            return(false);
        }
        float step = Mathf.Abs(Pd.MovementSpeed / Pd.CurrentTile.MovementCost) * Time.deltaTime;

        if (DestinationTile.IsWalkable)
        {
            transform.position = Vector3.MoveTowards(transform.position, DestinationTile.Position, step);
        }
        else if (Vector3.Distance(DestinationTile.Position, Pd.CurrentTile.Position) > Grid.TileSize / 2)
        {
            transform.position = Vector3.MoveTowards(transform.position, Pd.CurrentTile.Position, step);
        }
        Pd.DiscoverTiles();
        Pd.CalculateCurrentTIle();
        Pd.IsPerformingMovingAction = true;
        return(true);
    }
 private Tile AddDiscoveredTile(Tile t, Tile.Sides side, HashSet <Tile> revealed)
 {
     if (t != null && t.Neighbours.ContainsKey(side))
     {
         DiscoveredTiles.Add(t.Neighbours[side]);
         revealed.Add(t.Neighbours[side]);
         t.Neighbours[side].IsDiscovered = true;
         t.Neighbours[side].IsRevealed   = true;
         return(t.Neighbours[side]);
     }
     return(null);
 }
    private int AddTileIndex(int idx, HashSet <int> indices, Tile.Sides side)
    {
        if (idx == -1)
        {
            return(-1);
        }
        idx = GetEvenIndex(idx);
        switch (side)
        {
        case Tile.Sides.Top:
            idx = idx - Grid.NumColumns * 2;
            if (idx < 0)
            {
                return(-1);
            }
            indices.Add(idx);
            return(idx);

        case Tile.Sides.Left:
            if (idx % Grid.NumColumns == 0)
            {
                return(-1);
            }
            indices.Add(idx - 2);
            return(idx - 2);

        case Tile.Sides.Right:
            int curRow = (idx / Grid.NumColumns) + 1;
            if (idx == (curRow * Grid.NumColumns) - 2)
            {
                return(-1);
            }
            indices.Add(idx + 2);
            return(idx + 2);

        case Tile.Sides.Bottom:
            idx = idx + Grid.NumColumns * 2;
            if (idx >= Grid.NumTiles * 2)
            {
                return(-1);
            }
            indices.Add(idx);
            return(idx);
        }
        return(-1);
    }
    private void CreateSandOrWater(int i, int tileIdx, int nIdx, JSONNode bRatio, Tile.Sides nDirection, Tile.Sides tDirection)
    {
        Vector3 position = GetPositionFromIndex(tileIdx, Grid);

        if (Random.Range(0.0f, 100.0f) <= bRatio[((int)Tile.TileType.Sand).ToString()])
        {
            Tiles[tileIdx] = new Tile(Tile.TileType.Sand, tileIdx, position);
        }
        else
        {
            Tiles[tileIdx] = new Tile(Tile.TileType.Water, tileIdx, position);
        }
        if (i > 0)
        {
            Tiles[tileIdx].AddNeighbour(nDirection, Tiles[nIdx]);
            Tiles[nIdx].AddNeighbour(tDirection, Tiles[tileIdx]);
        }
    }
    protected void Attack()
    {
        if (GetPlayerData().Stamina < GetPlayerData().AttackStaminaCost)
        {
            ErrorSound.Play();
            GUItext.text = "Not enough stamina! Need " + GetPlayerData().AttackStaminaCost + " stamina!!!";
            return;
        }
        else if (GetPlayerData().IsAttackOnCooldown == true)
        {
            float multi = Mathf.Lerp(0.0f, 1.0f, AttackStep);
            float asdf  = AttackStep - (AttackStep * multi);
            GUItext.text = "Attack is on cooldown! " + asdf.ToString("F2") + " seconds remain.";
            return;
        }
        else if (GetPlayerData().IsPerformingAction)
        {
            ErrorSound.Play();
            GUItext.text = "Cannot attack while performing another action!";
            return;
        }
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 100.0f))
        {
            Animator animCtrl = this.gameObject.GetComponent <Animator>();
            Vector2  diff     = ray.origin - GetPlayerData().gameObject.transform.position;
            foreach (KeyValuePair <PlayerAnimationActions, string> e in AnimationActions)
            {
                animCtrl.ResetTrigger(e.Value);
            }
            Dictionary <Tile.Sides, Tile> neigh = GetPlayerData().CurrentTile.Neighbours;
            bool exec = false;
            if (Math.Abs(diff.x) > Math.Abs(diff.y))
            {
                if (diff.x > 0 && neigh.ContainsKey(Tile.Sides.Right) && neigh[Tile.Sides.Right].CurrentGameObject != null)
                {
                    if (this.GetComponent <PlayerInput>().Direction == Tile.Sides.Top)
                    {
                        animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.MoveRight]);
                    }
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.IdleRight]);
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.AttackRight]);
                    neigh[Tile.Sides.Right].CurrentGameObject.GetComponent <EnemyData>().DamageEnemy(GetPlayerData().Damage);
                    this.GetComponent <PlayerInput>().Direction = Tile.Sides.Right;
                    exec = true;
                }
                else if (diff.x < 0 && neigh.ContainsKey(Tile.Sides.Left) && neigh[Tile.Sides.Left].CurrentGameObject != null)
                {
                    if (this.GetComponent <PlayerInput>().Direction == Tile.Sides.Top)
                    {
                        animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.MoveRight]);
                    }
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.IdleLeft]);
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.AttackLeft]);
                    neigh[Tile.Sides.Left].CurrentGameObject.GetComponent <EnemyData>().DamageEnemy(GetPlayerData().Damage);
                    this.GetComponent <PlayerInput>().Direction = Tile.Sides.Left;
                    exec = true;
                }
            }
            else
            {
                if (diff.y > 0 && neigh.ContainsKey(Tile.Sides.Top) && neigh[Tile.Sides.Top].CurrentGameObject != null)
                {
                    neigh[Tile.Sides.Top].CurrentGameObject.GetComponent <EnemyData>().DamageEnemy(GetPlayerData().Damage);
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.IdleRight]);
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.MoveUp]);
                    exec = true;
                }
                else if (diff.y < 0 && neigh.ContainsKey(Tile.Sides.Bottom) && neigh[Tile.Sides.Bottom].CurrentGameObject != null)
                {
                    neigh[Tile.Sides.Bottom].CurrentGameObject.GetComponent <EnemyData>().DamageEnemy(GetPlayerData().Damage);
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.IdleRight]);
                    animCtrl.SetTrigger(AnimationActions[PlayerAnimationActions.MoveDown]);
                    exec = true;
                }
            }
            if (exec)
            {
                AttackSound.Play();
                GetPlayerData().Stamina           -= GetPlayerData().AttackStaminaCost;
                GetPlayerData().IsAttackOnCooldown = true;
            }
        }
    }
    private void Movement()
    {
        if (!this.GetPlayerData().IsPerformingAction)
        {
            WalkSound.loop  = true;
            DestinationTile = PlayerData.CurrentTile;
            if (Input.GetAxisRaw("Vertical") > 0)
            {
                Direction = Tile.Sides.Top;
                if (PlayerData.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Top))
                {
                    DestinationTile = PlayerData.CurrentTile.Neighbours[Tile.Sides.Top];
                }
            }
            else if (Input.GetAxisRaw("Vertical") < 0)
            {
                Direction = Tile.Sides.Bottom;
                if (PlayerData.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Bottom))
                {
                    DestinationTile = PlayerData.CurrentTile.Neighbours[Tile.Sides.Bottom];
                }
            }
            else if (Input.GetAxisRaw("Horizontal") > 0)
            {
                Direction = Tile.Sides.Right;
                if (PlayerData.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Right))
                {
                    DestinationTile = PlayerData.CurrentTile.Neighbours[Tile.Sides.Right];
                }
            }
            else if (Input.GetAxisRaw("Horizontal") < 0)
            {
                Direction = Tile.Sides.Left;
                if (PlayerData.CurrentTile.Neighbours.ContainsKey(Tile.Sides.Left))
                {
                    DestinationTile = PlayerData.CurrentTile.Neighbours[Tile.Sides.Left];
                }
            }
            else
            {
                WalkSound.loop = false;
                return;
            }
            if (!WalkSound.isPlaying)
            {
                WalkSound.Play();
            }
            float step = Mathf.Abs(PlayerData.MovementSpeed / PlayerData.CurrentTile.MovementCost) * Time.deltaTime;

            if (DestinationTile != PlayerData.CurrentTile && DestinationTile.CurrentGameObject == this.gameObject)
            {
                DestinationTile.CurrentGameObject = null;
            }

            if (DestinationTile.IsWalkable && (DestinationTile.CurrentGameObject == null || DestinationTile.CurrentGameObject == this.gameObject))
            {
                transform.position = Vector3.MoveTowards(transform.position, DestinationTile.Position, step);
            }
            else if (Vector3.Distance(DestinationTile.Position, PlayerData.CurrentTile.Position) > 0.5)
            {
                transform.position = Vector3.MoveTowards(transform.position, PlayerData.CurrentTile.Position, step);
            }
            PlayerData.DiscoverTiles();
            PlayerData.CalculateCurrentTIle();
        }
    }