Passed
Push — master ( 668211...ef514d )
by Vincent
08:40 queued 13s
created

toString()   B

Complexity

Conditions 5

Size

Total Lines 33
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 23
c 1
b 0
f 0
dl 0
loc 33
ccs 19
cts 19
cp 1
crap 5
rs 8.8613
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.network.game.out.fight.turn;
21
22
import fr.quatrevieux.araknemu.data.constant.Characteristic;
23
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter;
24
25
import java.util.Collection;
26
27
/**
28
 * Send fighters information between two turns
29
 *
30
 * https://github.com/Emudofus/Dofus/blob/1.29/dofus/aks/Game.as#L326
31
 */
32
public final class TurnMiddle {
33
    private final Collection<Fighter> fighters;
34
35 1
    public TurnMiddle(Collection<Fighter> fighters) {
36 1
        this.fighters = fighters;
37 1
    }
38
39
    @Override
40
    public String toString() {
41 1
        final StringBuilder sb = new StringBuilder("GTM");
42
43 1
        for (Fighter fighter : fighters) {
44 1
            sb.append('|').append(fighter.id()).append(';');
45
46 1
            if (fighter.dead()) {
47 1
                sb.append(1);
48 1
                continue;
49
            }
50
51
            final int actionPoints;
52
            final int movementPoints;
53
54 1
            if (fighter.isPlaying()) {
55 1
                actionPoints = fighter.turn().points().actionPoints();
56 1
                movementPoints = fighter.turn().points().movementPoints();
57
            } else {
58 1
                actionPoints = fighter.characteristics().get(Characteristic.ACTION_POINT);
59 1
                movementPoints = fighter.characteristics().get(Characteristic.MOVEMENT_POINT);
60
            }
61
62 1
            sb.append("0;").append(fighter.life().current()).append(';')
63 1
                .append(actionPoints).append(';')
64 1
                .append(movementPoints).append(';')
65 1
                .append(fighter.hidden() ? -1 : fighter.cell().id()).append(';') // @todo send real cell to hidden fighter ?
0 ignored issues
show
introduced by
Comment matches to-do format '(TODO:)|(@todo )'.
Loading history...
66 1
                .append(';') // Not used by client (line 348)
67 1
                .append(fighter.life().max())
68
            ;
69 1
        }
70
71 1
        return sb.toString();
72
    }
73
}
74