Exemplo n.º 1
0
    public void FindNeighbors(RuneSlot[,] runeSlots)
    {
        //Debug.Log("Finding Neighbors for " + runeData.RuneTemplateId);

        if (neighbors == null)
        {
            neighbors = new RuneSlot[(int)runeData.RuneTemplate.sides];
        }

        int page_h = runeSlots.GetLength(0);
        int page_w = runeSlots.GetLength(1);

        int rune_x = -1;
        int rune_y = -1;

        for (int h = 0; h < page_h; h++)
        {
            for (int w = 0; w < page_w; w++)
            {
                if (runeSlots[h, w] == this)
                {
                    rune_x = w;
                    rune_y = h;
                }
            }
        }

        if (rune_x == -1 || rune_y == -1)
        {
            Debug.Log("Error: RuneData not in Page.");
            return;
        }

        Debug.Log("Current Index : " + rune_y + " " + rune_x);

        switch (runeData.RuneTemplate.sides)
        {
        case 4:

            Vector2[] possibleNeighbors =
            {
                new Vector2(rune_x + 1, rune_y),
                new Vector2(rune_x,     rune_y - 1),
                new Vector2(rune_x - 1, rune_y),
                new Vector2(rune_x,     rune_y + 1)
            };

            for (int i = 0; i < 4; i++)
            {
                Vector2 possibleNeighbor = possibleNeighbors[i];
                int     n_x = (int)possibleNeighbor.x;
                int     n_y = (int)possibleNeighbor.y;

                if (n_x < 0 || n_x >= page_w || n_y < 0 || n_y >= page_h)
                {
                    neighbors[i] = null;
                }
                else
                {
                    RuneSlot neighbor = runeSlots[n_y, n_x];

                    int neighborConnectionPort = (i + 2) % 4;

                    neighbors[i] = neighbor.PortOpen(neighborConnectionPort) ? neighbor : null;
                }
            }
            break;

        case 6:
            break;

        case 3:
            break;
        }
    }