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

stop()   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 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
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.fighter.monster;
21
22
import java.util.Optional;
23
24
import fr.arakne.utils.maps.constant.Direction;
25
import fr.quatrevieux.araknemu.data.constant.Characteristic;
26
import fr.quatrevieux.araknemu.game.fight.Fight;
27
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.BuffList;
28
import fr.quatrevieux.araknemu.game.fight.castable.weapon.CastableWeapon;
29
import fr.quatrevieux.araknemu.game.fight.fighter.BaseFighterLife;
30
import fr.quatrevieux.araknemu.game.fight.fighter.Fighter;
31
import fr.quatrevieux.araknemu.game.fight.fighter.FighterCharacteristics;
32
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife;
33
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
34
import fr.quatrevieux.araknemu.game.fight.fighter.States;
35
import fr.quatrevieux.araknemu.game.fight.fighter.operation.FighterOperation;
36
import fr.quatrevieux.araknemu.game.fight.map.FightCell;
37
import fr.quatrevieux.araknemu.game.fight.team.FightTeam;
38
import fr.quatrevieux.araknemu.game.fight.turn.FightTurn;
39
import fr.quatrevieux.araknemu.game.spell.SpellList;
40
import fr.quatrevieux.araknemu.game.world.creature.Sprite;
41
42
final public class InvocationFighter implements Fighter {
0 ignored issues
show
introduced by
'public' modifier out of order with the JLS suggestions.
Loading history...
43
    final private Fighter fighter;
0 ignored issues
show
introduced by
'private' modifier out of order with the JLS suggestions.
Loading history...
44
    final private PassiveFighter invoker;
0 ignored issues
show
introduced by
'private' modifier out of order with the JLS suggestions.
Loading history...
45
    final private FighterLife life;
0 ignored issues
show
introduced by
'private' modifier out of order with the JLS suggestions.
Loading history...
46
47 1
    public InvocationFighter(Fighter fighter, PassiveFighter invoker) {
48 1
        this.fighter = fighter;
49 1
        this.invoker = invoker;
50
51 1
        float rate = 1 + ((Fighter)invoker).level() / 100 ;
0 ignored issues
show
Bug introduced by
Math operands should be cast to prevent unwanted loss of precision when mixing types. Consider casting one of the operands of this addition to float.
Loading history...
introduced by
';' is preceded with whitespace.
Loading history...
introduced by
'typecast' is not followed by whitespace.
Loading history...
introduced by
Variable 'rate' should be declared final.
Loading history...
52 1
        int vitality = Math.round(fighter.life().max() * rate);
0 ignored issues
show
introduced by
Variable 'vitality' should be declared final.
Loading history...
53
54 1
        this.life = new BaseFighterLife(fighter, vitality, vitality);
55 1
        this.scaleCharacteristicsBasedOnInvokerLevel(rate);
56 1
    }
57
58
    private void scaleCharacteristicsBasedOnInvokerLevel(float rate) {
59 1
        int strength = fighter.characteristics().get(Characteristic.STRENGTH);
0 ignored issues
show
introduced by
Variable 'strength' should be declared final.
Loading history...
60 1
        int wisdom = fighter.characteristics().get(Characteristic.WISDOM);
0 ignored issues
show
introduced by
Variable 'wisdom' should be declared final.
Loading history...
61 1
        int luck = fighter.characteristics().get(Characteristic.LUCK);
0 ignored issues
show
introduced by
Variable 'luck' should be declared final.
Loading history...
62 1
        int agility = fighter.characteristics().get(Characteristic.AGILITY);
0 ignored issues
show
introduced by
Variable 'agility' should be declared final.
Loading history...
63
64 1
        fighter.characteristics().alter(Characteristic.STRENGTH, Math.round(strength * rate));
65 1
        fighter.characteristics().alter(Characteristic.WISDOM, Math.round(wisdom * rate));
66 1
        fighter.characteristics().alter(Characteristic.LUCK, Math.round(luck * rate));
67 1
        fighter.characteristics().alter(Characteristic.AGILITY, Math.round(agility * rate));
68 1
    }
69
70
    @Override
71
    public <O extends FighterOperation> O apply(O operation) {
72 1
        operation.onInvocation(this);
73
74 1
        return operation;
75
    }
76
77
    @Override
78
    public int level() {
79
        return fighter.level();
80
    }
81
82
    @Override
83
    public boolean ready() {
84
        return fighter.ready();
85
    }
86
87
    @Override
88
    public FightTeam team() {
89
        return fighter.team();
90
    }
91
92
    @Override
93
    public CastableWeapon weapon() {
94
        return fighter.weapon();
95
    }
96
97
    @Override
98
    public int id() {
99
        return fighter.id();
100
    }
101
102
    @Override
103
    public Sprite sprite() {
104 1
        return fighter.sprite();
105
    }
106
107
    @Override
108
    public SpellList spells() {
109
        return fighter.spells();
110
    }
111
112
    @Override
113
    public FighterCharacteristics characteristics() {
114
        return fighter.characteristics();
115
    }
116
117
    @Override
118
    public FighterLife life() {
119
        return life;
120
    }
121
122
    @Override
123
    public Optional<PassiveFighter> invoker() {
124 1
        return Optional.of(invoker);
125
    }
126
127
    @Override
128
    public void attach(Object key, Object value) {
129
        fighter.attach(key, value);
130
    }
131
132
    @Override
133
    public Fight fight() {
134
        return fighter.fight();
135
    }
136
137
    @Override
138
    public void init() {
139 1
        fighter.init();
140 1
    }
141
142
    @Override
143
    public boolean isOnFight() {
144
        return fighter.isOnFight();
145
    }
146
147
    @Override
148
    public void joinFight(Fight fight, FightCell startCell) {
149 1
        fighter.joinFight(fight, startCell);
150 1
    }
151
152
    @Override
153
    public void play(FightTurn turn) {
154
        fighter.play(turn);
155
    }
156
157
    @Override
158
    public void setOrientation(Direction orientation) {
159
        fighter.setOrientation(orientation);
160
    }
161
162
    @Override
163
    public void stop() {
164
        fighter.stop();
165
    }
166
167
    @Override
168
    public FightCell cell() {
169
        return fighter.cell();
170
    }
171
172
    @Override
173
    public Direction orientation() {
174
        return fighter.orientation();
175
    }
176
177
    @Override
178
    public void dispatch(Object event) {
179
        fighter.dispatch(event);
180
    }
181
182
    @Override
183
    public Object attachment(Object key) {
184
        return fighter.attachment(key);
185
    }
186
187
    @Override
188
    public void move(FightCell cell) {
189
        fighter.move(cell);
190
    }
191
192
    @Override
193
    public States states() {
194
        return fighter.states();
195
    }
196
197
    @Override
198
    public FightTurn turn() {
199
        return fighter.turn();
200
    }
201
202
    @Override
203
    public BuffList buffs() {
204
        return fighter.buffs();
205
    }
206
}
207