Пример #1
0
    public static void ShowSpellRange(CellScript center, SpellScript spell)
    {
        // Foreach to set cells to "inSpellRange"
        // If obstacle, ally, ext.. check is spell possible
        // If spell have vision,
        // Then bresenham to check if you can see it
        List <CellScript> cells = new List <CellScript>();
        int distance;

        foreach (CellScript cell in grid)
        {
            distance = center.Distance(cell);
            if (distance <= spell.minRange && distance >= spell.maxRange)
            {
                // Conditions are inversed so we can factorize the code
                if (cell.target == null && !spell.onEmpty)
                {
                    continue;
                }
                switch (cell.target.GetTypeOfTarget())
                {
                case Type.ally: if (!spell.onAlly)
                    {
                        continue;
                    }
                    break;

                case Type.water: if (!spell.onWater)
                    {
                        continue;
                    }
                    break;

                case Type.ennemy: if (!spell.onEnnemy)
                    {
                        continue;
                    }
                    break;

                case Type.obstacle: if (!spell.onObstacle)
                    {
                        continue;
                    }
                    break;
                }
                cell.isInSpellRange = true;
                cells.Add(cell);
            }
        }
        if (spell.needVision)
        {
            BresenhamLine(center, cells);
        }
    }