setPosition(Position)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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-2020 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.data.living.entity.player;
21
22
import fr.arakne.utils.value.Colors;
23
import fr.arakne.utils.value.constant.Gender;
24
import fr.arakne.utils.value.constant.Race;
25
import fr.quatrevieux.araknemu.data.living.entity.WalletEntity;
26
import fr.quatrevieux.araknemu.data.value.Position;
27
import fr.quatrevieux.araknemu.game.chat.ChannelType;
28
import fr.quatrevieux.araknemu.game.world.creature.characteristics.DefaultCharacteristics;
29
import fr.quatrevieux.araknemu.game.world.creature.characteristics.MutableCharacteristics;
30
import org.checkerframework.checker.index.qual.NonNegative;
31
import org.checkerframework.checker.index.qual.Positive;
32
33
import java.util.EnumSet;
34
import java.util.Set;
35
36
/**
37
 * Entity class for player
38
 */
39
@SuppressWarnings({"argument"}) // @todo refactor repository PK system
0 ignored issues
show
introduced by
Comment matches to-do format '(TODO:)|(@todo )'.
Loading history...
40
public final class Player implements WalletEntity {
41
    private final int id;
42
    private final int accountId;
43
    private final int serverId;
44
    private String name;
45
    private Race race;
46
    private Gender gender;
47
    private Colors colors;
48
    private @Positive int level;
49
    private MutableCharacteristics stats;
50
    private Position position;
51
    private Set<ChannelType> channels;
52
    private @NonNegative int boostPoints;
53
    private @NonNegative int spellPoints;
54
    private @NonNegative int life;
55
    private @NonNegative long experience;
56
    private Position savedPosition;
57
    private @NonNegative long kamas;
58
59 1
    public Player(int id, int accountId, int serverId, String name, Race race, Gender gender, Colors colors, @Positive int level, MutableCharacteristics stats, Position position, Set<ChannelType> channels, @NonNegative int boostPoints, @NonNegative int spellPoints, @NonNegative int life, @NonNegative long experience, Position savedPosition, @NonNegative long kamas) {
0 ignored issues
show
Comprehensibility introduced by
Constructor has 17 parameters, which is greater than 7 authorized.
Loading history...
60 1
        this.id = id;
61 1
        this.accountId = accountId;
62 1
        this.serverId = serverId;
63 1
        this.name = name;
64 1
        this.race = race;
65 1
        this.gender = gender;
66 1
        this.colors = colors;
67 1
        this.level = level;
68 1
        this.stats = stats;
69 1
        this.position = position;
70 1
        this.channels = channels;
71 1
        this.boostPoints = boostPoints;
72 1
        this.spellPoints = spellPoints;
73 1
        this.life = life;
74 1
        this.experience = experience;
75 1
        this.savedPosition = savedPosition;
76 1
        this.kamas = kamas;
77 1
    }
78
79
    public Player(int id, int accountId, int serverId, String name, Race race, Gender gender, Colors colors, @Positive int level, MutableCharacteristics characteristics) {
0 ignored issues
show
Comprehensibility introduced by
Constructor has 9 parameters, which is greater than 7 authorized.
Loading history...
80 1
        this(id, accountId, serverId, name, race, gender, colors, level, characteristics, new Position(0, 0), EnumSet.noneOf(ChannelType.class), 0, 0, Integer.MAX_VALUE, 0, new Position(0, 0), 0);
81 1
    }
82
83
    public Player(int id) {
84 1
        this(id, 0, 0, null, null, null, null, 1, new DefaultCharacteristics());
85 1
    }
86
87
    public int id() {
88 1
        return id;
89
    }
90
91
    public int accountId() {
92 1
        return accountId;
93
    }
94
95
    public int serverId() {
96 1
        return serverId;
97
    }
98
99
    public String name() {
100 1
        return name;
101
    }
102
103
    public Race race() {
104 1
        return race;
105
    }
106
107
    public Gender gender() {
108 1
        return gender;
109
    }
110
111
    public Colors colors() {
112 1
        return colors;
113
    }
114
115
    public @Positive int level() {
116 1
        return level;
117
    }
118
119
    public void setLevel(@Positive int level) {
120 1
        this.level = level;
121 1
    }
122
123
    public MutableCharacteristics stats() {
124 1
        return stats;
125
    }
126
127
    public Position position() {
128 1
        return position;
129
    }
130
131
    public void setPosition(Position position) {
132 1
        this.position = position;
133 1
    }
134
135
    public Set<ChannelType> channels() {
136 1
        return channels;
137
    }
138
139
    public void setChannels(Set<ChannelType> channels) {
140 1
        this.channels = channels;
141 1
    }
142
143
    public @NonNegative int boostPoints() {
144 1
        return boostPoints;
145
    }
146
147
    public void setBoostPoints(@NonNegative int boostPoints) {
148 1
        this.boostPoints = boostPoints;
149 1
    }
150
151
    public @NonNegative int spellPoints() {
152 1
        return spellPoints;
153
    }
154
155
    public void setSpellPoints(@NonNegative int spellPoints) {
156 1
        this.spellPoints = spellPoints;
157 1
    }
158
159
    public @NonNegative int life() {
160 1
        return life;
161
    }
162
163
    public void setLife(@NonNegative int life) {
164 1
        this.life = life;
165 1
    }
166
167
    public @NonNegative long experience() {
168 1
        return experience;
169
    }
170
171
    public void setExperience(@NonNegative long experience) {
172 1
        this.experience = experience;
173 1
    }
174
175
    public Position savedPosition() {
176 1
        return savedPosition;
177
    }
178
179
    public void setSavedPosition(Position savedPosition) {
180 1
        this.savedPosition = savedPosition;
181 1
    }
182
183
    @Override
184
    public @NonNegative long kamas() {
185 1
        return kamas;
186
    }
187
188
    @Override
189
    public void setKamas(@NonNegative long kamas) {
190 1
        this.kamas = kamas;
191 1
    }
192
193
    /**
194
     * Create a new player with new race
195
     *
196
     * @param newId The new race
197
     */
198
    public Player withId(int newId) {
199 1
        return new Player(
200
            newId,
201
            accountId,
202
            serverId,
203
            name,
204
            race,
205
            gender,
206
            colors,
207
            level,
208
            stats,
209
            position,
210
            channels,
211
            boostPoints,
212
            spellPoints,
213
            life,
214
            experience,
215
            savedPosition,
216
            kamas
217
        );
218
    }
219
220
    /**
221
     * Constructor for character creation
222
     * The player race will be set to -1
223
     */
224
    public static Player forCreation(int accountId, int serverId, String name, Race race, Gender gender, Colors colors) {
225 1
        return new Player(-1, accountId, serverId, name, race, gender, colors, 1, new DefaultCharacteristics());
226
    }
227
228
    /**
229
     * Get a player for load for entering game
230
     *
231
     * @see fr.quatrevieux.araknemu.data.living.repository.player.PlayerRepository#getForGame(Player)
232
     */
233
    public static Player forGame(int playerId, int accountId, int serverId) {
234 1
        return new Player(playerId, accountId, serverId, null, null, null, null, 1, null, null, null, 0, 0, Integer.MAX_VALUE, 0, null, 0);
235
    }
236
}
237