Passed
Pull Request — master (#266)
by Vincent
14:00
created

iterator()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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-2022 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.fight.fighter;
21
22
import fr.quatrevieux.araknemu.game.spell.Spell;
23
import fr.quatrevieux.araknemu.game.spell.SpellList;
24
import fr.quatrevieux.araknemu.game.spell.boost.SimpleSpellsBoosts;
25
import fr.quatrevieux.araknemu.game.spell.boost.SpellsBoosts;
26
27
import java.util.Iterator;
28
import java.util.stream.StreamSupport;
29
30
/**
31
 * Decorate base spell list for handle fighter spell boosts
32
 */
33
public final class BaseFighterSpellList implements FighterSpellList {
34
    private final SpellList list;
35
    private final SpellsBoosts boosts;
36
37
    /**
38
     * @param list Base spell list
39
     */
40
    public BaseFighterSpellList(SpellList list) {
41 1
        this(list, new SimpleSpellsBoosts());
42 1
    }
43
44
    /**
45
     * @param list Base spell list
46
     * @param boosts Boost instance to use
47
     */
48 1
    public BaseFighterSpellList(SpellList list, SpellsBoosts boosts) {
49 1
        this.list = list;
50 1
        this.boosts = boosts;
51 1
    }
52
53
    @Override
54
    public Spell get(int spellId) {
55 1
        return boosts.get(list.get(spellId));
56
    }
57
58
    @Override
59
    public boolean has(int spellId) {
60 1
        return list.has(spellId);
61
    }
62
63
    @Override
64
    public Iterator<Spell> iterator() {
65 1
        return StreamSupport.stream(list.spliterator(), false)
66 1
            .map(boosts::get)
67 1
            .iterator()
68
        ;
69
    }
70
71
    @Override
72
    public void boost(int spellId, SpellsBoosts.Modifier modifier, int value) {
73 1
        boosts.boost(spellId, modifier, value);
74 1
    }
75
}
76