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.item.effect; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.data.constant.Effect; |
23
|
|
|
import fr.quatrevieux.araknemu.data.value.ItemTemplateEffectEntry; |
24
|
|
|
import fr.quatrevieux.araknemu.game.exploration.ExplorationPlayer; |
25
|
|
|
import fr.quatrevieux.araknemu.game.exploration.map.cell.ExplorationMapCell; |
26
|
|
|
import fr.quatrevieux.araknemu.game.fight.fighter.player.PlayerFighter; |
27
|
|
|
import fr.quatrevieux.araknemu.game.item.effect.use.UseEffectHandler; |
28
|
|
|
import org.checkerframework.checker.index.qual.NonNegative; |
29
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
30
|
|
|
import org.checkerframework.common.value.qual.ArrayLen; |
31
|
|
|
|
32
|
|
|
import java.util.Arrays; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Effect for usable items |
36
|
|
|
*/ |
37
|
|
|
public final class UseEffect implements ItemEffect { |
38
|
|
|
private final UseEffectHandler handler; |
39
|
|
|
private final Effect effect; |
40
|
|
|
private final @NonNegative int @ArrayLen(3) [] arguments; |
41
|
|
|
|
42
|
1 |
|
public UseEffect(UseEffectHandler handler, Effect effect, @NonNegative int @ArrayLen(3)[] arguments) { |
43
|
1 |
|
this.handler = handler; |
44
|
1 |
|
this.effect = effect; |
45
|
1 |
|
this.arguments = arguments; |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
@Override |
49
|
|
|
public Effect effect() { |
50
|
1 |
|
return effect; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
@Override |
54
|
|
|
public ItemTemplateEffectEntry toTemplate() { |
55
|
1 |
|
return new ItemTemplateEffectEntry( |
56
|
|
|
effect, |
57
|
|
|
arguments[0], |
58
|
|
|
arguments[1], |
59
|
|
|
arguments[2], |
60
|
|
|
"" |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public @NonNegative int @ArrayLen(3)[] arguments() { |
65
|
1 |
|
return arguments; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
@Override |
69
|
|
|
public boolean equals(@Nullable Object o) { |
70
|
1 |
|
if (this == o) { |
71
|
1 |
|
return true; |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
if (o == null || getClass() != o.getClass()) { |
75
|
1 |
|
return false; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
final UseEffect useEffect = (UseEffect) o; |
79
|
|
|
|
80
|
1 |
|
return effect == useEffect.effect |
81
|
1 |
|
&& Arrays.equals(arguments, useEffect.arguments) |
82
|
|
|
; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Check if the player can use the effect |
87
|
|
|
* |
88
|
|
|
* @see UseEffectHandler#check(UseEffect, ExplorationPlayer) |
89
|
|
|
*/ |
90
|
|
|
public boolean check(ExplorationPlayer caster) { |
91
|
1 |
|
return handler.check(this, caster); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Check if the player can use the effect to the target |
96
|
|
|
* |
97
|
|
|
* @see UseEffectHandler#checkTarget(UseEffect, ExplorationPlayer, ExplorationPlayer, ExplorationMapCell) |
98
|
|
|
*/ |
99
|
|
|
public boolean checkTarget(ExplorationPlayer caster, @Nullable ExplorationPlayer target, @Nullable ExplorationMapCell cell) { |
100
|
1 |
|
return handler.checkTarget(this, caster, target, cell); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Check if the fighter can use the effect |
105
|
|
|
* |
106
|
|
|
* @see UseEffectHandler#checkFighter(UseEffect, PlayerFighter) |
107
|
|
|
*/ |
108
|
|
|
public boolean checkFighter(PlayerFighter fighter) { |
109
|
1 |
|
return handler.checkFighter(this, fighter); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Apply the effect to the player |
114
|
|
|
* |
115
|
|
|
* @see UseEffectHandler#apply(UseEffect, ExplorationPlayer) |
116
|
|
|
*/ |
117
|
|
|
public void apply(ExplorationPlayer caster) { |
118
|
1 |
|
handler.apply(this, caster); |
119
|
1 |
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Apply the effect to the target |
123
|
|
|
* |
124
|
|
|
* @see UseEffectHandler#applyToTarget(UseEffect, ExplorationPlayer, ExplorationPlayer, ExplorationMapCell) |
125
|
|
|
*/ |
126
|
|
|
public void applyToTarget(ExplorationPlayer caster, @Nullable ExplorationPlayer target, @Nullable ExplorationMapCell cell) { |
127
|
1 |
|
handler.applyToTarget(this, caster, target, cell); |
128
|
1 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Apply the effect to the fighter |
132
|
|
|
* |
133
|
|
|
* @see UseEffectHandler#applyToFighter(UseEffect, PlayerFighter) |
134
|
|
|
*/ |
135
|
|
|
public void applyToFighter(PlayerFighter fighter) { |
136
|
1 |
|
handler.applyToFighter(this, fighter); |
137
|
1 |
|
} |
138
|
|
|
|
139
|
|
|
@Override |
140
|
|
|
public int hashCode() { |
141
|
1 |
|
int result = effect.hashCode(); |
142
|
|
|
|
143
|
1 |
|
result = 31 * result + Arrays.hashCode(arguments); |
144
|
|
|
|
145
|
1 |
|
return result; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
@Override |
149
|
|
|
public String toString() { |
150
|
1 |
|
return "UseEffect{" + effect + ":" + Arrays.toString(arguments) + '}'; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|