fr.quatrevieux.araknemu.game.item.effect.WeaponEffect   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0
eloc 43
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A extra() 0 2 1
A min() 0 2 1
A toTemplate() 0 3 1
A equals(Object) 0 16 4
A WeaponEffect(Effect,int,int,int) 0 5 1
A hashCode() 0 9 1
A max() 0 2 1
A toString() 0 3 1
A effect() 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-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.item.effect;
21
22
import fr.quatrevieux.araknemu.data.constant.Effect;
23
import fr.quatrevieux.araknemu.data.value.ItemTemplateEffectEntry;
24
import org.checkerframework.checker.index.qual.NonNegative;
25
import org.checkerframework.checker.nullness.qual.Nullable;
26
27
/**
28
 * Effect for weapon items
29
 */
30
public final class WeaponEffect implements ItemEffect {
31
    private final Effect effect;
32
    private final @NonNegative int min;
33
    private final @NonNegative int max;
34
    private final @NonNegative int extra;
35
36 1
    public WeaponEffect(Effect effect, @NonNegative int min, @NonNegative int max, @NonNegative int extra) {
37 1
        this.effect = effect;
38 1
        this.min = min;
39 1
        this.max = max;
40 1
        this.extra = extra;
41 1
    }
42
43
    @Override
44
    public Effect effect() {
45 1
        return effect;
46
    }
47
48
    @Override
49
    public ItemTemplateEffectEntry toTemplate() {
50 1
        return new ItemTemplateEffectEntry(effect, min, max, extra, "1d" + (max - min + 1) + "+" + (min - 1));
51
    }
52
53
    public @NonNegative int min() {
54 1
        return min;
55
    }
56
57
    public @NonNegative int max() {
58 1
        return max;
59
    }
60
61
    public @NonNegative int extra() {
62 1
        return extra;
63
    }
64
65
    @Override
66
    public boolean equals(@Nullable Object o) {
67 1
        if (this == o) {
68 1
            return true;
69
        }
70
71 1
        if (o == null || getClass() != o.getClass()) {
72 1
            return false;
73
        }
74
75 1
        final WeaponEffect that = (WeaponEffect) o;
76
77 1
        return min == that.min
78
            && max == that.max
79
            && extra == that.extra
80
            && effect == that.effect
81
        ;
82
    }
83
84
    @Override
85
    public int hashCode() {
86 1
        int result = effect.hashCode();
87
88 1
        result = 31 * result + min;
89 1
        result = 31 * result + max;
90 1
        result = 31 * result + extra;
91
92 1
        return result;
93
    }
94
95
    @Override
96
    public String toString() {
97 1
        return "WeaponEffect{" + effect + ":" + min + ", " + max + ", " + extra + '}';
98
    }
99
}
100