Passed
Push — master ( bbdd9e...bfd11a )
by Vincent
05:16 queued 12s
created

forCode(int)   A

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.network.game.out.info;
21
22
import fr.arakne.utils.value.Interval;
23
24
import java.util.HashMap;
25
import java.util.Map;
26
27
/**
28
 * Error message
29
 */
30
public final class Error extends AbstractInformationMessage {
31 1
    private static final Map<Integer, Error> simpleErrorsByCode = new HashMap<>();
32
33
    public Error(Entry... entries) {
34 1
        super(Type.ERROR, entries);
35 1
    }
36
37
    public Error(int id) {
38 1
        this(new Entry(id));
39 1
    }
40
41
    public Error(int id, Object... arguments) {
42 1
        this(new Entry(id, arguments));
43 1
    }
44
45
    /**
46
     * Get the welcome message
47
     */
48
    public static Error welcome() {
49 1
        return forCode(89);
50
    }
51
52
    /**
53
     * Cannot do the action on this server
54
     */
55
    public static Error cantDoOnServer() {
56 1
        return forCode(226);
57
    }
58
59
    /**
60
     * Cannot do the action on the current state
61
     */
62
    public static Error cantDoOnCurrentState() {
63 1
        return forCode(116);
64
    }
65
66
    /**
67
     * Cannot learn the spell
68
     *
69
     * @param spellId The spell
70
     */
71
    public static Error cantLearnSpell(int spellId) {
72 1
        return new Error(7, spellId);
73
    }
74
75
    /**
76
     * Cannot cast the spell : not in the spell list
77
     */
78
    public static Error cantCastNotFound() {
79 1
        return forCode(169);
80
    }
81
82
    /**
83
     * Cannot cast the spell : not enough action points
84
     *
85
     * @param available The available action points
86
     * @param required The required action points for cast the spell
87
     */
88
    public static Error cantCastNotEnoughActionPoints(int available, int required) {
89 1
        return new Error(170, available, required);
90
    }
91
92
    /**
93
     * Cannot cast the spell : The target cell is invalid
94
     */
95
    public static Error cantCastInvalidCell() {
96 1
        return forCode(193);
97
    }
98
99
    /**
100
     * Cannot cast the spell : The target cell is not available
101
     */
102
    public static Error cantCastCellNotAvailable() {
103 1
        return forCode(172);
104
    }
105
106
    /**
107
     * Cannot cast the spell : The target cell is not in line
108
     */
109
    public static Error cantCastLineLaunch() {
110 1
        return forCode(173);
111
    }
112
113
    /**
114
     * Cannot cast the spell : The sight is blocked
115
     */
116
    public static Error cantCastSightBlocked() {
117 1
        return forCode(174);
118
    }
119
120
    /**
121
     * Cannot cast the spell : The cast is in invalid state
122
     */
123
    public static Error cantCastBadState() {
124 1
        return forCode(116);
125
    }
126
127
    /**
128
     * Cannot cast the spell : the cell is out of range
129
     *
130
     * @param range The spell range
131
     * @param distance The cell distance
132
     */
133
    public static Error cantCastBadRange(Interval range, int distance) {
134 1
        return new Error(171, range.min(), range.max(), distance);
135
    }
136
137
    /**
138
     * Cannot cast the spell
139
     */
140
    public static Error cantCast() {
141 1
        return forCode(175);
142
    }
143
144
    /**
145
     * Cannot perform the action during fight
146
     */
147
    public static Error cantDoDuringFight() {
148 1
        return forCode(91);
149
    }
150
151
    /**
152
     * Cannot move : the player is overweight
153
     */
154
    public static Error cantMoveOverweight() {
155 1
        return forCode(12);
156
    }
157
158
    /**
159
     * A shutdown is scheduled
160
     *
161
     * @param delay The delay string. The value is not translated.
162
     */
163
    public static Error shutdownScheduled(String delay) {
164 1
        return new Error(15, delay);
165
    }
166
167
    /**
168
     * A game server save is in progress
169
     */
170
    public static Error saveInProgress() {
171 1
        return forCode(164);
172
    }
173
174
    /**
175
     * The current game server save is terminated
176
     */
177
    public static Error saveTerminated() {
178 1
        return forCode(165);
179
    }
180
181
    /**
182
     * Create and cache a simple Error with a code
183
     *
184
     * @param code The error code
185
     *
186
     * @return The Error instance
187
     */
188
    private static Error forCode(int code) {
189 1
        return simpleErrorsByCode.computeIfAbsent(code, Error::new);
190
    }
191
}
192