Passed
Pull Request — master (#203)
by Vincent
14:28 queued 03:42
created

fr.quatrevieux.araknemu.game.handler.fight.KickFighter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A packet() 0 3 1
A handle(GameSession,KickFighterRequest) 0 18 5
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
18
 */
19
20
package fr.quatrevieux.araknemu.game.handler.fight;
21
22
import fr.quatrevieux.araknemu.core.network.exception.ErrorPacket;
23
import fr.quatrevieux.araknemu.core.network.parser.PacketHandler;
24
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter;
25
import fr.quatrevieux.araknemu.game.fight.state.PlacementState;
26
import fr.quatrevieux.araknemu.network.game.GameSession;
27
import fr.quatrevieux.araknemu.network.game.in.fight.KickFighterRequest;
28
import fr.quatrevieux.araknemu.network.game.out.basic.Noop;
29
30
/**
31
 * Kick a fighter during placement state
32
 *
33
 * Unlike leave, the kicked fighter will not be punished.
34
 * Only the team leader can kick a fighter, expect himself.
35
 *
36
 * @see PlacementState#kick(Fighter)
37
 */
38 1
public final class KickFighter implements PacketHandler<GameSession, KickFighterRequest> {
39
    @Override
40
    public void handle(GameSession session, KickFighterRequest packet) {
41 1
        final Fighter fighter = session.fighter();
42
43 1
        if (!fighter.isTeamLeader() || packet.fighterId() == fighter.id()) {
44
            // @todo Im error ?
0 ignored issues
show
introduced by
Comment matches to-do format '(TODO:)|(@todo )'.
Loading history...
45 1
            throw new ErrorPacket(new Noop());
46
        }
47
48 1
        for (Fighter teammate : fighter.team().fighters()) {
49 1
            if (teammate.id() == packet.fighterId()) {
50 1
                fighter.fight().state(PlacementState.class).kick(teammate);
51 1
                return;
52
            }
53 1
        }
54
55
        // @todo Im error ?
0 ignored issues
show
introduced by
Comment matches to-do format '(TODO:)|(@todo )'.
Loading history...
56 1
        session.send(new Noop());
57 1
    }
58
59
    @Override
60
    public Class<KickFighterRequest> packet() {
61 1
        return KickFighterRequest.class;
62
    }
63
}
64