Passed
Pull Request — master (#280)
by Vincent
15:50 queued 01:38
created

life()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
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-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.game.fight.fighter.monster;
21
22
import java.util.Optional;
23
24
import fr.quatrevieux.araknemu.game.fight.castable.weapon.CastableWeapon;
25
import fr.quatrevieux.araknemu.game.fight.exception.FightException;
26
import fr.quatrevieux.araknemu.game.fight.fighter.AbstractFighter;
27
import fr.quatrevieux.araknemu.game.fight.fighter.BaseFighterLife;
28
import fr.quatrevieux.araknemu.game.fight.fighter.BaseFighterSpellList;
29
import fr.quatrevieux.araknemu.game.fight.fighter.FighterCharacteristics;
30
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife;
31
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
32
import fr.quatrevieux.araknemu.game.fight.fighter.FighterSpellList;
33
import fr.quatrevieux.araknemu.game.fight.fighter.operation.FighterOperation;
34
import fr.quatrevieux.araknemu.game.fight.team.FightTeam;
35
import fr.quatrevieux.araknemu.game.monster.Monster;
36
import fr.quatrevieux.araknemu.game.monster.reward.MonsterReward;
37
import fr.quatrevieux.araknemu.game.world.creature.Sprite;
38
import org.checkerframework.checker.index.qual.Positive;
39
40
/**
41
 * Fighter for a monster
42
 */
43
public final class MonsterFighter extends AbstractFighter {
44
    private final int id;
45
    private final Monster monster;
46
    private final FightTeam team;
47
48
    private final BaseFighterLife life;
49
    private final MonsterFighterCharacteristics characteristics;
50
    private final MonsterFighterSprite sprite;
51
    private final FighterSpellList spells;
52
53
    @SuppressWarnings({"assignment", "argument"})
54 1
    public MonsterFighter(int id, Monster monster, FightTeam team) {
55 1
        this.id = id;
56 1
        this.monster = monster;
57 1
        this.team = team;
58
59 1
        this.life = new BaseFighterLife(this, monster.life());
60 1
        this.characteristics = new MonsterFighterCharacteristics(monster, this);
61 1
        this.sprite = new MonsterFighterSprite(this, monster);
62 1
        this.spells = new BaseFighterSpellList(monster.spells());
63 1
    }
64
65
    @Override
66
    public int id() {
67 1
        return id;
68
    }
69
70
    @Override
71
    public Sprite sprite() {
72 1
        return sprite;
73
    }
74
75
    @Override
76
    public FighterLife life() {
77 1
        return life;
78
    }
79
80
    @Override
81
    public FighterCharacteristics characteristics() {
82 1
        return characteristics;
83
    }
84
85
    @Override
86
    public FighterSpellList spells() {
87 1
        return spells;
88
    }
89
90
    @Override
91
    public CastableWeapon weapon() {
92 1
        throw new FightException("The fighter do not have any weapon");
93
    }
94
95
    @Override
96
    public @Positive int level() {
97 1
        return monster.level();
98
    }
99
100
    @Override
101
    public FightTeam team() {
102 1
        return team;
103
    }
104
105
    @Override
106
    public boolean ready() {
107 1
        return true;
108
    }
109
110
    @Override
111
    public <O extends FighterOperation> O apply(O operation) {
112 1
        operation.onMonster(this);
113
114 1
        return operation;
115
    }
116
117
    /**
118
     * Get the end fight rewards
119
     *
120
     * @see Monster#reward()
121
     */
122
    public MonsterReward reward() {
123 1
        return monster.reward();
124
    }
125
126
    /**
127
     * Get the monster data for the fighter
128
     */
129
    public Monster monster() {
130 1
        return monster;
131
    }
132
133
    @Override
134
    public Optional<PassiveFighter> invoker() {
135 1
        return Optional.empty();
136
    }
137
}
138