|
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.spell; |
|
21
|
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.data.world.entity.SpellTemplate; |
|
23
|
|
|
import org.checkerframework.checker.index.qual.NonNegative; |
|
24
|
|
|
import org.checkerframework.checker.index.qual.Positive; |
|
25
|
|
|
|
|
26
|
|
|
import java.util.NoSuchElementException; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Wrap spell levels |
|
30
|
|
|
*/ |
|
31
|
|
|
public final class SpellLevels { |
|
32
|
|
|
private final SpellTemplate entity; |
|
33
|
|
|
private final Spell[] levels; |
|
34
|
|
|
|
|
35
|
1 |
|
public SpellLevels(SpellTemplate entity, Spell[] levels) { |
|
36
|
1 |
|
this.entity = entity; |
|
37
|
1 |
|
this.levels = levels; |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get the spell id |
|
42
|
|
|
*/ |
|
43
|
|
|
public int id() { |
|
44
|
1 |
|
return entity.id(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the spell name |
|
49
|
|
|
*/ |
|
50
|
|
|
public String name() { |
|
51
|
1 |
|
return entity.name(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get spell at level |
|
56
|
|
|
*/ |
|
57
|
|
|
public Spell level(@Positive int level) { |
|
58
|
1 |
|
final int index = level - 1; |
|
59
|
|
|
|
|
60
|
1 |
|
if (index >= levels.length) { |
|
61
|
1 |
|
throw new NoSuchElementException("Invalid level " + level + " for spell " + entity.id()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
return levels[index]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get the maximum spell level |
|
69
|
|
|
*/ |
|
70
|
|
|
public @NonNegative int max() { |
|
71
|
1 |
|
return levels.length; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|