Passed
Pull Request — master (#222)
by Vincent
11:14
created

fr.quatrevieux.araknemu.game.fight.ai.proxy.ProxyPassiveFighter   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 91
Duplicated Lines 14.29 %

Test Coverage

Coverage 95.65%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 53
dl 13
loc 91
ccs 22
cts 23
cp 0.9565
rs 10
c 1
b 0
f 0
wmc 17

15 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 3 1
A cell() 0 3 1
A ProxyPassiveFighter(PassiveFighter,AI) 0 3 1
A hashCode() 0 3 1
A move(FightCell) 0 3 1
A level() 0 3 1
A dead() 0 3 1
A team() 0 3 1
A equals(Object) 13 13 3
A buffs() 0 3 1
A states() 0 3 1
A life() 0 3 1
A orientation() 0 3 1
A characteristics() 0 3 1
A sprite() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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.fight.ai.proxy;
21
22
import fr.arakne.utils.maps.constant.Direction;
23
import fr.quatrevieux.araknemu.game.fight.ai.AI;
24
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buffs;
25
import fr.quatrevieux.araknemu.game.fight.fighter.FighterCharacteristics;
26
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife;
27
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
28
import fr.quatrevieux.araknemu.game.fight.fighter.States;
29
import fr.quatrevieux.araknemu.game.fight.map.FightCell;
30
import fr.quatrevieux.araknemu.game.fight.team.Team;
31
import fr.quatrevieux.araknemu.game.world.creature.Sprite;
32
33
/**
34
 * Proxy class for override properties of other fighters
35
 *
36
 * Note: this object is immutable
37
 */
38
public final class ProxyPassiveFighter implements PassiveFighter {
39
    private final PassiveFighter fighter;
40
    private final AI ai;
41
42
    /**
43
     * @param fighter The fighter to wrap
44
     * @param ai The AI instance use to resolve the cell instance
45
     */
46 1
    public ProxyPassiveFighter(PassiveFighter fighter, AI ai) {
47 1
        this.fighter = fighter;
48 1
        this.ai = ai;
49 1
    }
50
51
    @Override
52
    public int id() {
53 1
        return fighter.id();
54
    }
55
56
    @Override
57
    public FightCell cell() {
58 1
        return ai.map().get(fighter.cell().id());
59
    }
60
61
    @Override
62
    public Sprite sprite() {
63 1
        return fighter.sprite();
64
    }
65
66
    @Override
67
    public Direction orientation() {
68 1
        return fighter.orientation();
69
    }
70
71
    @Override
72
    public void move(FightCell cell) {
73 1
        throw new UnsupportedOperationException("This is a proxy fighter");
74
    }
75
76
    @Override
77
    public FighterLife life() {
78 1
        return fighter.life();
79
    }
80
81
    @Override
82
    public Buffs buffs() {
83 1
        return fighter.buffs();
84
    }
85
86
    @Override
87
    public States states() {
88 1
        return fighter.states();
89
    }
90
91
    @Override
92
    public int level() {
93
        return fighter.level();
94
    }
95
96
    @Override
97
    public FighterCharacteristics characteristics() {
98 1
        return fighter.characteristics();
99
    }
100
101
    @Override
102
    public Team<? extends PassiveFighter> team() {
103 1
        return fighter.team();
104
    }
105
106
    @Override
107
    public boolean dead() {
108 1
        return fighter.dead();
109
    }
110
111 View Code Duplication
    @Override
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
112
    public boolean equals(Object o) {
113 1
        if (this == o) {
114 1
            return true;
115
        }
116
117 1
        if (!(o instanceof PassiveFighter)) {
118 1
            return false;
119
        }
120
121 1
        final PassiveFighter that = (PassiveFighter) o;
122
123 1
        return id() == that.id();
124
    }
125
126
    @Override
127
    public int hashCode() {
128 1
        return fighter.hashCode();
129
    }
130
}
131