fr.quatrevieux.araknemu.game.item.factory.UsableFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 3 1
A create(ItemTemplate,ItemType,List) 0 6 1
A create(ItemTemplate,ItemType,GameItemSet,boolean) 0 3 1
A retrieve(ItemTemplate,ItemType,GameItemSet,List) 0 3 1
A UsableFactory(EffectMapper,EffectMapper) 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.factory;
21
22
import fr.quatrevieux.araknemu.data.value.ItemTemplateEffectEntry;
23
import fr.quatrevieux.araknemu.data.world.entity.item.ItemTemplate;
24
import fr.quatrevieux.araknemu.data.world.entity.item.ItemType;
25
import fr.quatrevieux.araknemu.game.item.GameItemSet;
26
import fr.quatrevieux.araknemu.game.item.Item;
27
import fr.quatrevieux.araknemu.game.item.SuperType;
28
import fr.quatrevieux.araknemu.game.item.effect.SpecialEffect;
29
import fr.quatrevieux.araknemu.game.item.effect.UseEffect;
30
import fr.quatrevieux.araknemu.game.item.effect.mapping.EffectMapper;
31
import fr.quatrevieux.araknemu.game.item.type.UsableItem;
32
import org.checkerframework.checker.nullness.qual.Nullable;
33
34
import java.util.List;
35
36
/**
37
 * Factory for usable items.
38
 */
39
public final class UsableFactory implements ItemFactory {
40
    private final EffectMapper<UseEffect> useEffectEffectMapper;
41
    private final EffectMapper<SpecialEffect> specialEffectEffectMapper;
42
43 1
    public UsableFactory(EffectMapper<UseEffect> useEffectEffectMapper, EffectMapper<SpecialEffect> specialEffectEffectMapper) {
44 1
        this.useEffectEffectMapper = useEffectEffectMapper;
45 1
        this.specialEffectEffectMapper = specialEffectEffectMapper;
46 1
    }
47
48
    @Override
49
    public Item create(ItemTemplate template, ItemType type, @Nullable GameItemSet set, boolean maximize) {
50 1
        return create(template, type, template.effects());
51
    }
52
53
    @Override
54
    public Item retrieve(ItemTemplate template, ItemType type, @Nullable GameItemSet set, List<ItemTemplateEffectEntry> effects) {
55 1
        return create(template, type, effects);
56
    }
57
58
    @Override
59
    public SuperType type() {
60 1
        return SuperType.USABLE;
61
    }
62
63
    private Item create(ItemTemplate template, ItemType type, List<ItemTemplateEffectEntry> effects) {
64 1
        return new UsableItem(
65
            template,
66
            type,
67 1
            useEffectEffectMapper.create(effects),
68 1
            specialEffectEffectMapper.create(effects, true)
69
        );
70
    }
71
}
72