Passed
Push — master ( a1f065...b3961b )
by Vincent
07:02 queued 12s
created

onCreature(ExplorationCreature)   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
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-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.exploration.creature;
21
22
import fr.quatrevieux.araknemu.game.exploration.ExplorationPlayer;
23
import fr.quatrevieux.araknemu.game.exploration.npc.GameNpc;
24
import fr.quatrevieux.araknemu.game.monster.group.MonsterGroup;
25
import org.checkerframework.checker.nullness.qual.Nullable;
26
27
/**
28
 * Operation to apply on a creature
29
 *
30
 * @param <R> The result type of the operation.
31
 *           This value must be returned by the {@link ExplorationCreature#apply(Operation)} method
32
 *           The type must be Boolean for apply on map using {@link fr.quatrevieux.araknemu.game.exploration.map.cell.ExplorationMapCell#apply(Operation)}
33
 */
34
public interface Operation<R> {
35
    /**
36
     * Apply the operation on an exploration player
37
     */
38
    public default @Nullable R onExplorationPlayer(ExplorationPlayer player) {
39 1
        return onCreature(player);
40
    }
41
42
    /**
43
     * Apply the operation on a NPC
44
     */
45
    public default @Nullable R onNpc(GameNpc npc) {
46 1
        return onCreature(npc);
47
    }
48
49
    /**
50
     * Apply the operation on a monster group
51
     */
52
    public default @Nullable R onMonsterGroup(MonsterGroup monsterGroup) {
53 1
        return onCreature(monsterGroup);
54
    }
55
56
    /**
57
     * Generic operation to apply to all creatures
58
     */
59
    public default @Nullable R onCreature(ExplorationCreature creature) {
60 1
        return null;
61
    }
62
}
63