startDiscernment()   A
last analyzed

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-2020 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.player.race;
21
22
import fr.arakne.utils.value.constant.Race;
23
import fr.quatrevieux.araknemu.data.constant.Characteristic;
24
import fr.quatrevieux.araknemu.data.value.BoostStatsData;
25
import fr.quatrevieux.araknemu.data.value.Position;
26
import fr.quatrevieux.araknemu.data.world.entity.character.PlayerRace;
27
import fr.quatrevieux.araknemu.game.spell.SpellLevels;
28
import fr.quatrevieux.araknemu.game.world.creature.characteristics.Characteristics;
29
import org.checkerframework.checker.index.qual.Positive;
30
31
import java.util.Collection;
32
import java.util.LinkedHashMap;
33
import java.util.List;
34
import java.util.Map;
35
import java.util.function.Function;
36
import java.util.stream.Collectors;
37
38
/**
39
 * Player race data
40
 */
41
public final class GamePlayerRace {
42
    private final PlayerRace entity;
43
    private final Map<Integer, SpellLevels> spells;
44
45 1
    public GamePlayerRace(PlayerRace entity, List<SpellLevels> spells) {
46 1
        this.entity = entity;
47 1
        this.spells = spells.stream()
48 1
            .collect(
49 1
                Collectors.toMap(
50
                    SpellLevels::id,
51 1
                    Function.identity(),
52
                    (o, o2) -> {
53
                        throw new IllegalArgumentException("Duplicate");
54
                    },
55
                    LinkedHashMap::new
56
                )
57
            )
58
        ;
59 1
    }
60
61
    /**
62
     * Get the race life per level
63
     */
64
    public @Positive int life(@Positive int level) {
65 1
        return entity.startLife() + (level - 1) * entity.perLevelLife();
66
    }
67
68
    /**
69
     * Get the race id
70
     */
71
    public Race race() {
72 1
        return entity.race();
73
    }
74
75
    /**
76
     * Get the race name
77
     */
78
    public String name() {
79 1
        return entity.name();
80
    }
81
82
    /**
83
     * Get the race start stats
84
     */
85
    public Characteristics baseStats(@Positive int level) {
86 1
        for (Map.Entry<Integer, Characteristics> entry  : entity.baseStats().entrySet()) {
87 1
            if (entry.getKey() <= level) {
88 1
                return entry.getValue();
89
            }
90 1
        }
91
92
        throw new IllegalArgumentException("Not handled level " + level + " for race stats " + name());
93
    }
94
95
    /**
96
     * Get start discernment
97
     */
98
    public int startDiscernment() {
99 1
        return entity.startDiscernment();
100
    }
101
102
    /**
103
     * Get start pods
104
     */
105
    public @Positive int startPods() {
106 1
        return entity.startPods();
107
    }
108
109
    /**
110
     * Get the initiative value for current life
111
     */
112
    public int initiative(int life) {
113 1
        return life / (boost(Characteristic.VITALITY, 0).boost() * 4);
114
    }
115
116
    /**
117
     * Get the boost stats interval for the current characteristic and value
118
     *
119
     * @param characteristic Characteristic to check
120
     * @param currentValue The current player base characteristic value
121
     */
122
    public BoostStatsData.Interval boost(Characteristic characteristic, int currentValue) {
123 1
        return entity.boostStats().get(characteristic, currentValue);
124
    }
125
126
    public Collection<SpellLevels> spells() {
127 1
        return spells.values();
128
    }
129
130
    /**
131
     * The Astrub statue position
132
     */
133
    public Position astrubPosition() {
134 1
        return entity.astrubPosition();
135
    }
136
}
137