Passed
Push — master ( a1b3f0...93435f )
by Vincent
06:31 queued 23s
created

checkTarget(UseEffect,ExplorationPlayer,ExplorationPlayer,ExplorationMapCell)   A

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.item.effect.use;
21
22
import fr.arakne.utils.value.helper.RandomUtil;
23
import fr.quatrevieux.araknemu.data.constant.Characteristic;
24
import fr.quatrevieux.araknemu.game.exploration.ExplorationPlayer;
25
import fr.quatrevieux.araknemu.game.exploration.map.cell.ExplorationMapCell;
26
import fr.quatrevieux.araknemu.game.item.effect.UseEffect;
27
import fr.quatrevieux.araknemu.network.game.out.info.Information;
28
import org.checkerframework.checker.nullness.qual.Nullable;
29
30
/**
31
 * Effect handler for add characteristic
32
 */
33
public final class AddCharacteristicEffect implements UseEffectHandler {
34
    private final Characteristic characteristic;
35
36 1
    private final RandomUtil random = new RandomUtil();
37
38 1
    public AddCharacteristicEffect(Characteristic characteristic) {
39 1
        this.characteristic = characteristic;
40 1
    }
41
42
    @Override
43
    public void apply(UseEffect effect, ExplorationPlayer caster) {
44 1
        final int value = random.rand(effect.arguments());
45 1
        final Information info = Information.characteristicBoosted(characteristic, value);
46
47 1
        caster.player().properties().characteristics().base().add(characteristic, value);
48
49 1
        if (info != null) {
50 1
            caster.send(info);
51
        }
52 1
    }
53
54
    @Override
55
    public boolean check(UseEffect effect, ExplorationPlayer caster) {
56 1
        return true;
57
    }
58
59
    @Override
60
    public boolean checkTarget(UseEffect effect, ExplorationPlayer caster, @Nullable ExplorationPlayer target, @Nullable ExplorationMapCell cell) {
61 1
        return false;
62
    }
63
}
64