Esempio n. 1
0
    private HitInfo LinearTrap(Vector2 origin, Vector2 end, Character caster, Ability ability, bool drawFloor, bool setTrap)
    {
        HitInfo info      = new HitInfo();
        Vector2 direction = (end - origin).normalized * ability.range0;
        float   thickness = ability.thickness;

        Cell[]      affectedCells_1 = LinearAim(origin, direction);
        List <Cell> validCells_1    = CalculateLinearImpact(affectedCells_1);
        List <Cell> validCells      = new List <Cell>();

        if (thickness > 0)
        {
            Vector2 gap = (new Vector2(direction.y, direction.x).normalized) * thickness / 2;

            Cell[]      affectedCells_0 = LinearAim(origin, direction, -gap);
            Cell[]      affectedCells_2 = LinearAim(origin, direction, gap);
            List <Cell> validCells_0    = CalculateLinearImpact(affectedCells_0);
            List <Cell> validCells_2    = CalculateLinearImpact(affectedCells_2);

            foreach (Cell cell in validCells_0)
            {
                if (!validCells.Contains(cell))
                {
                    validCells.Add(cell);
                }
            }
            foreach (Cell cell in validCells_1)
            {
                if (!validCells.Contains(cell))
                {
                    validCells.Add(cell);
                }
            }
            foreach (Cell cell in validCells_2)
            {
                if (!validCells.Contains(cell))
                {
                    validCells.Add(cell);
                }
            }
        }
        else
        {
            validCells = validCells_1;
        }
        if (drawFloor)
        {
            for (int i = 0; i < lastAimed.Count; i++)
            {
                lastAimed[i].SetBaseColor();
            }
            for (int i = 0; i < validCells.Count; i++)
            {
                validCells[i].SetAbilityDamageAoE();
            }
        }
        lastAimed = validCells;

        if (setTrap)
        {
            trapMan.SetTrap(caster, validCells, ability);
        }

        return(info);
    }