Passed
Pull Request — master (#148)
by
unknown
10:40
created

fr.quatrevieux.araknemu.game.fight.castable.effect.handler.invocations.MonsterInvocationHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
c 2
b 0
f 0
dl 0
loc 31
ccs 13
cts 15
cp 0.8667
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A MonsterInvocationHandler(MonsterService,Fight) 0 3 1
A buff(CastScope,EffectScope) 0 3 1
A handle(CastScope,EffectScope) 0 3 1
A addMonsterToFight(CastScope,EffectScope) 0 12 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-2021 Vincent Quatrevieux Jean-Alexandre Valentin
18
 */
19
20
package fr.quatrevieux.araknemu.game.fight.castable.effect.handler.invocations;
21
22
import java.util.Collections;
23
24
import fr.quatrevieux.araknemu.game.fight.Fight;
25
import fr.quatrevieux.araknemu.game.fight.castable.CastScope;
26
import fr.quatrevieux.araknemu.game.fight.castable.CastScope.EffectScope;
27
import fr.quatrevieux.araknemu.game.fight.castable.effect.handler.EffectHandler;
28
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter;
29
import fr.quatrevieux.araknemu.game.fight.fighter.monster.InvocationFighter;
30
import fr.quatrevieux.araknemu.game.fight.fighter.monster.MonsterFighter;
31
import fr.quatrevieux.araknemu.game.monster.MonsterService;
32
import fr.quatrevieux.araknemu.network.game.out.fight.action.ActionEffect;
33
import fr.quatrevieux.araknemu.network.game.out.fight.turn.FighterTurnOrder;
34
import fr.quatrevieux.araknemu.network.game.out.game.AddSprites;
35
36
final public class MonsterInvocationHandler implements EffectHandler {
0 ignored issues
show
introduced by
'public' modifier out of order with the JLS suggestions.
Loading history...
37
    final private MonsterService monsterService;
0 ignored issues
show
introduced by
'private' modifier out of order with the JLS suggestions.
Loading history...
38
    final private Fight fight;
0 ignored issues
show
introduced by
'private' modifier out of order with the JLS suggestions.
Loading history...
39
40 1
    public MonsterInvocationHandler(MonsterService monsterService, Fight fight) {
41 1
        this.monsterService = monsterService;
42 1
        this.fight = fight;
43 1
    }
44
45
    @Override
46
    public void buff(CastScope cast, EffectScope effect) {
47
        addMonsterToFight(cast, effect); // sadida lvl 100 puppet hit here
48
    }
49
50
    @Override
51
    public void handle(CastScope cast, EffectScope effect) {
52 1
        addMonsterToFight(cast, effect); // normal invocations
53 1
    }
54
55
    private void addMonsterToFight(CastScope cast, EffectScope effect) {
56 1
        final Fighter invocation = fight.addInvocation((id) -> new InvocationFighter(
57
            new MonsterFighter(
58
                id,
59 1
                monsterService.load(effect.effect().min()).get(effect.effect().max()),
60 1
                fight.turnList().currentFighter().team()
61
            ),
62 1
            cast.caster()
63 1
        ), cast.target());
64
65 1
        fight.send(new ActionEffect(181, cast.caster(), (new AddSprites(Collections.singleton(invocation.sprite()))).toString()));
66 1
        fight.send(new ActionEffect(999, cast.caster(), (new FighterTurnOrder(fight.turnList())).toString()));
67 1
    }
68
}
69