Passed
Push — master ( bbdd9e...bfd11a )
by Vincent
05:16 queued 12s
created

fr.quatrevieux.araknemu.game.fight.map.WalkableFightCell   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 96.43%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 53
dl 0
loc 86
ccs 27
cts 28
cp 0.9643
rs 10
c 1
b 0
f 0
wmc 17

12 Methods

Rating   Name   Duplication   Size   Complexity  
A fighter() 0 3 1
A hashCode() 0 3 1
A removeFighter() 0 7 2
A WalkableFightCell(FightMap,CellData,int) 0 5 1
A id() 0 3 1
A coordinate() 0 3 1
A map() 0 3 1
A equals(Object) 0 13 4
A set(PassiveFighter) 0 7 2
A walkable() 0 3 1
A walkableIgnoreFighter() 0 3 1
A sightBlocking() 0 3 1
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.PassiveFighter;
26
27
import java.util.Optional;
28
29
/**
30
 * Base fight cell
31
 */
32
public final class WalkableFightCell implements FightCell {
33
    private final FightMap map;
34
    private final CellData template;
35
    private final int id;
36
    private final CoordinateCell<FightCell> coordinate;
37
38
    private PassiveFighter fighter;
39
40 1
    public WalkableFightCell(FightMap map, CellData template, int id) {
41 1
        this.map = map;
42 1
        this.template = template;
43 1
        this.id = id;
44 1
        this.coordinate = new CoordinateCell<>(this);
45 1
    }
46
47
    @Override
48
    public int id() {
49 1
        return id;
50
    }
51
52
    @Override
53
    public FightMap map() {
54 1
        return map;
55
    }
56
57
    @Override
58
    public boolean walkable() {
59 1
        return fighter == null;
60
    }
61
62
    @Override
63
    public boolean walkableIgnoreFighter() {
64 1
        return true;
65
    }
66
67
    @Override
68
    public boolean sightBlocking() {
69 1
        return !template.lineOfSight() || fighter != null;
70
    }
71
72
    @Override
73
    public CoordinateCell<FightCell> coordinate() {
74 1
        return coordinate;
75
    }
76
77
    @Override
78
    public Optional<PassiveFighter> fighter() {
79 1
        return Optional.ofNullable(fighter);
80
    }
81
82
    @Override
83
    public void set(PassiveFighter fighter) {
84 1
        if (this.fighter != null) {
85 1
            throw new FightMapException("A fighter is already set on this cell (" + id + ")");
86
        }
87
88 1
        this.fighter = fighter;
89 1
    }
90
91
    @Override
92
    public void removeFighter() {
93 1
        if (this.fighter == null) {
94 1
            throw new FightMapException("No fighter found on cell " + id);
95
        }
96
97 1
        this.fighter = null;
98 1
    }
99
100
    @Override
101
    public int hashCode() {
102 1
        return id;
103
    }
104
105
    @Override
106
    public boolean equals(Object o) {
107 1
        if (this == o) {
108 1
            return true;
109
        }
110
111 1
        if (o == null || getClass() != o.getClass()) {
112
            return false;
113
        }
114
115 1
        final WalkableFightCell that = (WalkableFightCell) o;
116
117 1
        return id == that.id && map == that.map;
118
    }
119
}
120