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

invoker()   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 1 Features 0
Metric Value
cc 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 1
f 0
eloc 3
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 java.util.Optional;
23
24
import fr.arakne.utils.maps.constant.Direction;
25
import fr.quatrevieux.araknemu.game.fight.ai.AI;
26
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buffs;
27
import fr.quatrevieux.araknemu.game.fight.fighter.FighterCharacteristics;
28
import fr.quatrevieux.araknemu.game.fight.fighter.FighterLife;
29
import fr.quatrevieux.araknemu.game.fight.fighter.PassiveFighter;
30
import fr.quatrevieux.araknemu.game.fight.fighter.States;
31
import fr.quatrevieux.araknemu.game.fight.map.FightCell;
32
import fr.quatrevieux.araknemu.game.fight.team.Team;
33
import fr.quatrevieux.araknemu.game.world.creature.Sprite;
34
import org.checkerframework.checker.index.qual.Positive;
35
import org.checkerframework.checker.nullness.qual.Nullable;
36
37
/**
38
 * Proxy class for override properties of other fighters
39
 *
40
 * Note: this object is immutable
41
 */
42
public final class ProxyPassiveFighter implements PassiveFighter {
43
    private final PassiveFighter fighter;
44
    private final AI ai;
45
46
    /**
47
     * @param fighter The fighter to wrap
48
     * @param ai The AI instance use to resolve the cell instance
49
     */
50 1
    public ProxyPassiveFighter(PassiveFighter fighter, AI ai) {
51 1
        this.fighter = fighter;
52 1
        this.ai = ai;
53 1
    }
54
55
    @Override
56
    public int id() {
57 1
        return fighter.id();
58
    }
59
60
    @Override
61
    @SuppressWarnings("argument") // cell id always valid
62
    public FightCell cell() {
63 1
        return ai.map().get(fighter.cell().id());
64
    }
65
66
    @Override
67
    public Sprite sprite() {
68 1
        return fighter.sprite();
69
    }
70
71
    @Override
72
    public Direction orientation() {
73 1
        return fighter.orientation();
74
    }
75
76
    @Override
77
    public void move(@Nullable FightCell cell) {
78 1
        throw new UnsupportedOperationException("This is a proxy fighter");
79
    }
80
81
    @Override
82
    public FighterLife life() {
83 1
        return fighter.life();
84
    }
85
86
    @Override
87
    public Buffs buffs() {
88 1
        return fighter.buffs();
89
    }
90
91
    @Override
92
    public States states() {
93 1
        return fighter.states();
94
    }
95
96
    @Override
97
    public @Positive int level() {
98
        return fighter.level();
99
    }
100
101
    @Override
102
    public FighterCharacteristics characteristics() {
103 1
        return fighter.characteristics();
104
    }
105
106
    @Override
107
    public Team<? extends PassiveFighter> team() {
108 1
        return fighter.team();
109
    }
110
111
    @Override
112
    public boolean dead() {
113 1
        return fighter.dead();
114
    }
115
116
    @Override
117
    public boolean hidden() {
118 1
        return fighter.hidden();
119
    }
120
121
    @Override
122
    public void setHidden(PassiveFighter caster, boolean hidden) {
123 1
        throw new UnsupportedOperationException("Cannot modify a proxy fighter");
124
    }
125
126
    @Override
127
    public boolean equals(@Nullable Object o) {
128 1
        if (this == o) {
129 1
            return true;
130
        }
131
132 1
        if (!(o instanceof PassiveFighter)) {
133 1
            return false;
134
        }
135
136 1
        final PassiveFighter that = (PassiveFighter) o;
137
138 1
        return id() == that.id();
139
    }
140
141
    @Override
142
    public int hashCode() {
143 1
        return fighter.hashCode();
144
    }
145
146
    @Override
147
    public Optional<PassiveFighter> invoker() {
148 1
        return fighter.invoker();
149
    }
150
}
151