Passed
Pull Request — master (#241)
by Vincent
13:19
created

fr.quatrevieux.araknemu.game.exploration.map.cell.ExplorationMapCell   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 31
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
free() 0 1 ?
map() 0 2 ?
id() 0 2 ?
B apply(Operation) 0 12 6
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.exploration.map.cell;
21
22
import fr.arakne.utils.maps.MapCell;
23
import fr.quatrevieux.araknemu.game.exploration.creature.ExplorationCreature;
24
import fr.quatrevieux.araknemu.game.exploration.creature.Operation;
25
import fr.quatrevieux.araknemu.game.exploration.map.ExplorationMap;
26
import org.checkerframework.checker.index.qual.NonNegative;
27
import org.checkerframework.checker.nullness.qual.Nullable;
28
29
/**
30
 * Cell of exploration map
31
 */
32
public interface ExplorationMapCell extends MapCell<ExplorationMapCell> {
33
    @Override
34
    public @NonNegative int id();
35
36
    @Override
37
    public ExplorationMap map();
38
39
    /**
40
     * Does the cell is free ?
41
     * A cell is free if a new sprite can be added on, and no other objects is present
42
     */
43
    public boolean free();
44
45
    /**
46
     * Apply an operation to all creatures on current cell
47
     * If the operation return false, the iteration will be stopped
48
     *
49
     * @see ExplorationCreature#apply(Operation)
50
     */
51
    public default void apply(Operation<@Nullable Boolean> operation)  {
52
        // Optimisation : the cell is not walkable, no creatures can be located here
53 1
        if (!walkable()) {
54 1
            return;
55
        }
56
57 1
        for (ExplorationCreature creature : map().creatures()) {
58 1
            if (equals(creature.cell())) {
59 1
                final Boolean result = creature.apply(operation);
60
61 1
                if (result != null && !result) {
62 1
                    break;
63
                }
64
            }
65 1
        }
66 1
    }
67
}
68