resolve(C,C)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2020 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.spell.effect.area;
21
22
import fr.arakne.utils.maps.MapCell;
23
import fr.arakne.utils.maps.constant.Direction;
24
import fr.quatrevieux.araknemu.data.value.EffectArea;
25
26
import java.util.HashSet;
27
import java.util.Set;
28
29
/**
30
 * Resolve perpendicular line (i.e. baton area)
31
 */
32
public final class PerpendicularLineArea implements SpellEffectArea {
33
    private final EffectArea area;
34
35 1
    public PerpendicularLineArea(EffectArea area) {
36 1
        this.area = area;
37 1
    }
38
39
    @Override
40
    public <C extends MapCell<C>> Set<C> resolve(C target, C source) {
41 1
        final Set<C> cells = new HashSet<>(area.size() * 2 + 1);
42 1
        final Direction direction = source.coordinate().directionTo(target).orthogonal();
43
44 1
        cells.add(target);
45
46 1
        LineArea.addCells(cells, target, direction, area.size());
47 1
        LineArea.addCells(cells, target, direction.opposite(), area.size());
48
49 1
        return cells;
50
    }
51
52
    @Override
53
    public EffectArea.Type type() {
54 1
        return EffectArea.Type.PERPENDICULAR_LINE;
55
    }
56
57
    @Override
58
    public int size() {
59 1
        return area.size();
60
    }
61
}
62