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

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create(ItemTemplate,ItemType,GameItemSet,List,boolean) 0 7 1
A create(ItemTemplate,ItemType,GameItemSet,boolean) 0 3 1
A WearableFactory(SuperType,EffectMapper,EffectMapper) 0 4 1
A type() 0 3 1
A retrieve(ItemTemplate,ItemType,GameItemSet,List) 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.CharacteristicEffect;
29
import fr.quatrevieux.araknemu.game.item.effect.SpecialEffect;
30
import fr.quatrevieux.araknemu.game.item.effect.mapping.EffectMapper;
31
import fr.quatrevieux.araknemu.game.item.type.Wearable;
32
import org.checkerframework.checker.nullness.qual.Nullable;
33
34
import java.util.List;
35
36
/**
37
 * Factory for wearable
38
 */
39
public final class WearableFactory implements ItemFactory {
40
    private final SuperType type;
41
    private final EffectMapper<CharacteristicEffect> characteristicEffectEffectMapper;
42
    private final EffectMapper<SpecialEffect> specialEffectEffectMapper;
43
44 1
    public WearableFactory(SuperType type, EffectMapper<CharacteristicEffect> characteristicEffectEffectMapper, EffectMapper<SpecialEffect> specialEffectEffectMapper) {
45 1
        this.type = type;
46 1
        this.characteristicEffectEffectMapper = characteristicEffectEffectMapper;
47 1
        this.specialEffectEffectMapper = specialEffectEffectMapper;
48 1
    }
49
50
    @Override
51
    public Item create(ItemTemplate template, ItemType type, @Nullable GameItemSet set, boolean maximize) {
52 1
        return create(template, type, set, template.effects(), maximize);
53
    }
54
55
    @Override
56
    public Item retrieve(ItemTemplate template, ItemType type, @Nullable GameItemSet set, List<ItemTemplateEffectEntry> effects) {
57 1
        return create(template, type, set, effects, false);
58
    }
59
60
    @Override
61
    public SuperType type() {
62 1
        return type;
63
    }
64
65
    private Item create(ItemTemplate template, ItemType type, @Nullable GameItemSet set, List<ItemTemplateEffectEntry> effects, boolean maximize) {
66 1
        return new Wearable(
67
            template,
68
            type,
69
            set,
70 1
            characteristicEffectEffectMapper.create(effects, maximize),
71 1
            specialEffectEffectMapper.create(effects, maximize)
72
        );
73
    }
74
}
75