forked from ZsoltMolnarrr/SpellEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpellContainer.java
More file actions
46 lines (37 loc) · 1.35 KB
/
SpellContainer.java
File metadata and controls
46 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package net.spell_engine.api.spell;
import java.util.ArrayList;
import java.util.List;
public class SpellContainer { public SpellContainer() { }
public String pool;
public int max_spell_count = 1;
public List<String> spell_ids;
public SpellContainer(String pool, int max_spell_count, List<String> spell_ids) {
this.pool = pool;
this.max_spell_count = max_spell_count;
this.spell_ids = spell_ids;
}
// MARK: Helpers
public int cappedIndex(int selected) {
if (spell_ids.isEmpty()) { return 0; }
var remainder = selected % spell_ids.size();
return (remainder >= 0) ? remainder : (remainder + spell_ids.size());
}
public String spellId(int selected) {
if (spell_ids == null || spell_ids.isEmpty()) {
return null;
}
var index = cappedIndex(selected);
return spell_ids.get(index);
}
public boolean isValid() {
return max_spell_count > 0 && spell_ids != null
// Valid pool (staves) or non-empty spell list (wands)
&& ( (pool != null && !pool.isEmpty()) || !spell_ids.isEmpty() );
}
public boolean isUsable() {
return isValid() && !spell_ids.isEmpty();
}
public SpellContainer copy() {
return new SpellContainer(pool, max_spell_count, new ArrayList<>(spell_ids));
}
}