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

buff(CastScope,EffectScope)   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
eloc 3
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