addActionPoints(FighterData,int)   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
eloc 2
dl 0
loc 2
ccs 1
cts 1
cp 1
c 0
b 0
f 0
cc 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.network.game.out.fight.action;
21
22
import fr.quatrevieux.araknemu.game.fight.castable.effect.buff.Buff;
23
import fr.quatrevieux.araknemu.game.fight.fighter.FighterData;
24
import fr.quatrevieux.araknemu.game.fight.map.FightCell;
25
import fr.quatrevieux.araknemu.game.spell.Spell;
26
import org.apache.commons.lang3.StringUtils;
27
28
/**
29
 * Effect of a fight action
30
 */
31
public final class ActionEffect {
32
    private final int id;
33
    private final FighterData caster;
34
    private final Object[] arguments;
35
36 1
    public ActionEffect(int id, FighterData caster, Object... arguments) {
37 1
        this.id = id;
38 1
        this.caster = caster;
39 1
        this.arguments = arguments;
40 1
    }
41
42
    @Override
43
    public String toString() {
44 1
        return "GA;" + id + ";" + caster.id() + ";" + StringUtils.join(arguments, ",");
45
    }
46
47
    /**
48
     * Send used movement points after a movement
49
     *
50
     * @param fighter The fighter
51
     * @param quantity The MP quantity
52
     */
53
    public static ActionEffect usedMovementPoints(FighterData fighter, int quantity) {
54 1
        return new ActionEffect(129, fighter, fighter.id(), -quantity);
55
    }
56
57
    /**
58
     * Send used action points after an action
59
     *
60
     * @param fighter The fighter
61
     * @param quantity The AP quantity
62
     */
63
    public static ActionEffect usedActionPoints(FighterData fighter, int quantity) {
64 1
        return new ActionEffect(102, fighter, fighter.id(), -quantity);
65
    }
66
67
    /**
68
     * Change target life
69
     *
70
     * @param caster The effect castet
71
     * @param target The target
72
     * @param quantity The life points difference. Negative for damage, Positive for heal
73
     */
74
    public static ActionEffect alterLifePoints(FighterData caster, FighterData target, int quantity) {
75 1
        return new ActionEffect(100, caster, target.id(), quantity);
76
    }
77
78
    /**
79
     * Critical hit for spell
80
     *
81
     * @param caster The spell caster
82
     * @param spell The launched spell
83
     */
84
    public static ActionEffect criticalHitSpell(FighterData caster, Spell spell) {
85 1
        return new ActionEffect(301, caster, spell.id());
86
    }
87
88
    /**
89
     * Critical hit for close combat cast
90
     *
91
     * @param caster The weapon caster
92
     */
93
    public static ActionEffect criticalHitCloseCombat(FighterData caster) {
94 1
        return new ActionEffect(304, caster);
95
    }
96
97
    /**
98
     * A fighter die
99
     *
100
     * @param caster The spell caster
101
     * @param fighter The dead fighter
102
     */
103
    public static ActionEffect fighterDie(FighterData caster, FighterData fighter) {
104 1
        return new ActionEffect(103, caster, fighter.id());
105
    }
106
107
    /**
108
     * Teleport a fighter
109
     *
110
     * @param caster The spell caster
111
     * @param fighter The teleport fighter
112
     * @param target The target cell
113
     */
114
    public static ActionEffect teleport(FighterData caster, FighterData fighter, FightCell target) {
115 1
        return new ActionEffect(4, caster, fighter.id(), target.id());
116
    }
117
118
    /**
119
     * The fighter skip the next turn
120
     *
121
     * @param caster The buff caster
122
     * @param fighter The target fighter
123
     */
124
    public static ActionEffect skipNextTurn(FighterData caster, FighterData fighter) {
125 1
        return new ActionEffect(140, caster, fighter.id());
126
    }
127
128
    /**
129
     * The fighter return the spell
130
     *
131
     * @param fighter The fighter
132
     * @param success true is the spell is successfully returned
133
     */
134
    public static ActionEffect returnSpell(FighterData fighter, boolean success) {
135 1
        return new ActionEffect(106, fighter, fighter.id(), success ? "1" : "0");
136
    }
137
138
    /**
139
     * Buff effect for characteristic change
140
     *
141
     * @param buff The applied buff
142
     */
143
    public static ActionEffect buff(Buff buff, int value) {
144 1
        return new ActionEffect(buff.effect().effect(), buff.caster(), buff.target().id(), value, buff.effect().duration());
145
    }
146
147
    /**
148
     * Boost the sight of the target for a given duration
149
     *
150
     * @param caster Spell caster
151
     * @param target Target
152
     * @param value Boosted value
153
     * @param duration Effect duration
154
     */
155
    public static ActionEffect boostSight(FighterData caster, FighterData target, int value, int duration) {
156 1
        return new ActionEffect(117, caster, target.id(), value, duration);
157
    }
158
159
    /**
160
     * Decrease the sight of the target for a given duration
161
     *
162
     * @param caster Spell caster
163
     * @param target Target
164
     * @param value Decrease value
165
     * @param duration Effect duration
166
     */
167
    public static ActionEffect decreaseSight(FighterData caster, FighterData target, int value, int duration) {
168 1
        return new ActionEffect(116, caster, target.id(), value, duration);
169
    }
170
171
    /**
172
     * Add action points for the current turn
173
     *
174
     * @param fighter The fighter
175
     * @param quantity The AP quantity
176
     */
177
    public static ActionEffect addActionPoints(FighterData fighter, int quantity) {
178 1
        return new ActionEffect(120, fighter, fighter.id(), quantity);
179
    }
180
181
    /**
182
     * Remove action points for the current turn
183
     *
184
     * @param fighter The fighter
185
     * @param quantity The AP quantity
186
     */
187
    public static ActionEffect removeActionPoints(FighterData fighter, int quantity) {
188 1
        return new ActionEffect(168, fighter, fighter.id(), -quantity);
189
    }
190
191
    /**
192
     * Add movement points for the current turn
193
     *
194
     * @param fighter The fighter
195
     * @param quantity The MP quantity
196
     */
197
    public static ActionEffect addMovementPoints(FighterData fighter, int quantity) {
198 1
        return new ActionEffect(128, fighter, fighter.id(), quantity);
199
    }
200
201
    /**
202
     * Remove movement points for the current turn
203
     *
204
     * @param fighter The fighter
205
     * @param quantity The MP quantity
206
     */
207
    public static ActionEffect removeMovementPoints(FighterData fighter, int quantity) {
208 1
        return new ActionEffect(169, fighter, fighter.id(), -quantity);
209
    }
210
211
    /**
212
     * Suffered damage value is reduced
213
     *
214
     * @param fighter The fighter
215
     * @param value The reduction value
216
     */
217
    public static ActionEffect reducedDamage(FighterData fighter, int value) {
218 1
        return new ActionEffect(105, fighter, fighter.id(), value);
219
    }
220
221
    /**
222
     * Add state to the fighter
223
     *
224
     * @param fighter The fighter
225
     * @param state The state id to add
226
     */
227
    public static ActionEffect addState(FighterData fighter, int state) {
228 1
        return new ActionEffect(950, fighter, fighter.id(), state, 1);
229
    }
230
231
    /**
232
     * Remove state from the fighter
233
     *
234
     * @param fighter The fighter
235
     * @param state The state id to remove
236
     */
237
    public static ActionEffect removeState(FighterData fighter, int state) {
238 1
        return new ActionEffect(950, fighter, fighter.id(), state, 0);
239
    }
240
241
    /**
242
     * Remove all buffs that can be removed from the target
243
     * 
244
     * @param caster The caster
245
     * @param target The target
246
     */
247
    public static ActionEffect dispelBuffs(FighterData caster, FighterData target) {
248 1
        return new ActionEffect(132, caster, target.id());
249
    }
250
251
    /**
252
     * The fighter has been slided (i.e. move back or front) by the caster
253
     *
254
     * @param caster The spell caster
255
     * @param target The target (which has moved)
256
     * @param destination The destination cell
257
     */
258
    public static ActionEffect slide(FighterData caster, FighterData target, FightCell destination) {
259 1
        return new ActionEffect(5, caster, target.id(), destination.id());
260
    }
261
262
    /**
263
     * Damage as been reflected by the target
264
     *
265
     * @param castTarget The original cast target
266
     * @param value Reflected value
267
     */
268
    public static ActionEffect reflectedDamage(FighterData castTarget, int value) {
269 1
        return new ActionEffect(107, castTarget, castTarget.id(), value);
270
    }
271
272
    /**
273
     * The target has dodged the lost of action points
274
     *
275
     * @param caster The spell caster
276
     * @param target The target (which has dodged point lost)
277
     * @param value The dodged point list value
278
     */
279
    public static ActionEffect dodgeActionPointLost(FighterData caster, FighterData target, int value) {
280 1
        return new ActionEffect(308, caster, target.id(), value);
281
    }
282
283
    /**
284
     * The target has dodged the lost of movement points
285
     *
286
     * @param caster The spell caster
287
     * @param target The target (which has dodged point lost)
288
     * @param value The dodged point list value
289
     */
290
    public static ActionEffect dodgeMovementPointLost(FighterData caster, FighterData target, int value) {
291 1
        return new ActionEffect(309, caster, target.id(), value);
292
    }
293
294
    /**
295
     * Change the appearance of the target
296
     *
297
     * @param caster The spell caster
298
     * @param target The effect target
299
     * @param newAppearance The new appearance id (can be found in `clips/sprites/[id].swf)
300
     * @param duration The effect duration
301
     */
302
    public static ActionEffect changeAppearance(FighterData caster, FighterData target, int newAppearance, int duration) {
303 1
        return new ActionEffect(149, caster, target.id(), target.sprite().gfxId(), newAppearance, duration);
304
    }
305
306
    /**
307
     * Reset the appearance of the target
308
     */
309
    public static ActionEffect resetAppearance(FighterData caster, FighterData target) {
310 1
        final int baseGfxId = target.sprite().gfxId();
311
312 1
        return new ActionEffect(149, caster, target.id(), baseGfxId, baseGfxId, 0);
313
    }
314
315
    /**
316
     * Launch visual effect of a spell
317
     *
318
     * @param caster The visual effect caster
319
     * @param targetCell The target cell
320
     * @param spell Spell which contains sprite arguments
321
     */
322
    public static ActionEffect launchVisualEffect(FighterData caster, FightCell targetCell, Spell spell) {
323 1
        return new ActionEffect(208, caster, targetCell.id(), spell.spriteId(), spell.spriteArgs(), spell.level());
324
    }
325
326
    /**
327
     * The fighter has been make invisible
328
     *
329
     * @param caster Spell caster
330
     * @param target Effect target
331
     */
332
    public static ActionEffect fighterHidden(FighterData caster, FighterData target) {
333 1
        return new ActionEffect(150, caster, target.id(), 1);
334
    }
335
336
    /**
337
     * The invisibility effect is terminated
338
     *
339
     * @param caster Spell caster
340
     * @param target Effect target
341
     */
342
    public static ActionEffect fighterVisible(FighterData caster, FighterData target) {
343 1
        return new ActionEffect(150, caster, target.id(), 0);
344
    }
345
346
    /**
347
     * Add an invoked creature to the fight
348
     *
349
     * @param caster Invoker
350
     * @param invocation Invocation to add
351
     */
352
    public static ActionEffect addInvocation(FighterData caster, FighterData invocation) {
353 1
        return new ActionEffect(181, caster, "+" + invocation.sprite());
354
    }
355
356
    /**
357
     * Send a custom packet, but queued on the caster sequencer
358
     *
359
     * @param caster Effect caster
360
     * @param packet Packet to send
361
     */
362
    public static ActionEffect packet(FighterData caster, Object packet) {
363 1
        return new ActionEffect(999, caster, packet);
364
    }
365
}
366