map()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
ccs 1
cts 1
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.fight.map;
21
22
import fr.arakne.utils.maps.CoordinateCell;
23
import fr.arakne.utils.maps.serializer.CellData;
24
import fr.quatrevieux.araknemu.game.fight.exception.FightMapException;
25
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter;
26
import org.checkerframework.checker.index.qual.NonNegative;
27
import org.checkerframework.checker.nullness.qual.Nullable;
28
29
/**
30
 * Non walkable fight cell
31
 */
32
public final class UnwalkableFightCell implements FightCell {
33
    private final FightMap map;
34
    private final CellData template;
35
    private final @NonNegative int id;
36
    private final CoordinateCell<BattlefieldCell> coordinate;
37
38
    @SuppressWarnings({"assignment", "argument"})
39 1
    public UnwalkableFightCell(FightMap map, CellData template, @NonNegative int id) {
40 1
        this.map = map;
41 1
        this.template = template;
42 1
        this.id = id;
43 1
        this.coordinate = new CoordinateCell<>(this);
44 1
    }
45
46
    @Override
47
    public FightMap map() {
48 1
        return map;
49
    }
50
51
    @Override
52
    public @NonNegative int id() {
53 1
        return id;
54
    }
55
56
    @Override
57
    public boolean walkable() {
58 1
        return false;
59
    }
60
61
    @Override
62
    public boolean walkableIgnoreFighter() {
63 1
        return false;
64
    }
65
66
    @Override
67
    public boolean sightBlocking() {
68 1
        return !template.lineOfSight();
69
    }
70
71
    @Override
72
    public CoordinateCell<BattlefieldCell> coordinate() {
73 1
        return coordinate;
74
    }
75
76
    @Override
77
    public @Nullable Fighter fighter() {
78 1
        return null;
79
    }
80
81
    @Override
82
    public void set(Fighter fighter) {
83 1
        throw new FightMapException("Cannot add fighter on unwalkable cell");
84
    }
85
86
    @Override
87
    public void removeFighter() {
88 1
        throw new FightMapException("Cannot remove fighter on unwalkable cell");
89
    }
90
91
    @Override
92
    public int hashCode() {
93 1
        return id;
94
    }
95
96
    @Override
97
    public boolean equals(@Nullable Object o) {
98 1
        if (this == o) {
99 1
            return true;
100
        }
101
102 1
        if (o == null || getClass() != o.getClass()) {
103 1
            return false;
104
        }
105
106 1
        final UnwalkableFightCell that = (UnwalkableFightCell) o;
107
108 1
        return id == that.id && map == that.map;
109
    }
110
}
111