Passed
Pull Request — master (#241)
by Vincent
13:19
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
26
/**
27
 * Operation to apply on a creature
28
 *
29
 * @param <R> The result type of the operation.
30
 *           This value must be returned by the {@link ExplorationCreature#apply(Operation)} method
31
 *           The type must be Boolean for apply on map using {@link fr.quatrevieux.araknemu.game.exploration.map.cell.ExplorationMapCell#apply(Operation)}
32
 */
33
public interface Operation<R> {
34
    /**
35
     * Apply the operation on an exploration player
36
     */
37
    public default R onExplorationPlayer(ExplorationPlayer player) {
38 1
        return onCreature(player);
39
    }
40
41
    /**
42
     * Apply the operation on a NPC
43
     */
44
    public default R onNpc(GameNpc npc) {
45 1
        return onCreature(npc);
46
    }
47
48
    /**
49
     * Apply the operation on a monster group
50
     */
51
    public default R onMonsterGroup(MonsterGroup monsterGroup) {
52 1
        return onCreature(monsterGroup);
53
    }
54
55
    /**
56
     * Generic operation to apply to all creatures
57
     */
58
    public default R onCreature(ExplorationCreature creature) {
59 1
        return (R) null;
60
    }
61
}
62