-
Notifications
You must be signed in to change notification settings - Fork 2
/
StatusEffect.java
323 lines (278 loc) · 12.3 KB
/
StatusEffect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
* QuestManager: An RPG plugin for the Bukkit API.
* Copyright (C) 2015-2016 Github Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.skyisland.questmanager.magic.spell.effect;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.skyisland.questmanager.QuestManagerPlugin;
import com.skyisland.questmanager.configuration.utils.YamlWriter;
import com.skyisland.questmanager.fanciful.FancyMessage;
import com.skyisland.questmanager.magic.MagicUser;
import com.skyisland.questmanager.player.PlayerOptions;
import com.skyisland.questmanager.player.QuestPlayer;
/**
* Wrapper class for potion effects put into spells
*
*/
public class StatusEffect extends ImbuementEffect {
/**
* Registers this class as configuration serializable with all defined
* {@link aliases aliases}
*/
public static void registerWithAliases() {
for (aliases alias : aliases.values()) {
ConfigurationSerialization.registerClass(StatusEffect.class, alias.getAlias());
}
}
/**
* Registers this class as configuration serializable with only the default alias
*/
public static void registerWithoutAliases() {
ConfigurationSerialization.registerClass(StatusEffect.class);
}
private enum aliases {
DEFAULT(StatusEffect.class.getName()),
OLD("com.SkyIsland.QuestManager.Magic.Spell.Effect." + StatusEffect.class.getSimpleName()),
LONGI("SpellStatus"),
LONG("StatusSpell"),
SHORT("SStatus");
private String alias;
aliases(String alias) {
this.alias = alias;
}
public String getAlias() {
return alias;
}
}
public static StatusEffect valueOf(Map<String, Object> map) {
return new StatusEffect((PotionEffect) map.get("effect"));
}
@Override
public Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<>();
map.put("effect", effect);
return map;
}
private PotionEffect effect;
public StatusEffect(PotionEffect effect) {
this.effect = effect;
}
@Override
public void apply(Entity e, MagicUser cause) {
if (e instanceof LivingEntity) {
LivingEntity targ = (LivingEntity) e;
effect.apply(targ);
if (e instanceof Player) {
QuestPlayer qp = QuestManagerPlugin.questManagerPlugin.getPlayerManager()
.getPlayer((Player) e);
if (qp.getOptions().getOption(PlayerOptions.Key.CHAT_COMBAT_DAMAGE)) {
String msg;
if (cause instanceof QuestPlayer && ((QuestPlayer) cause).getPlayer().getUniqueId()
.equals(qp.getPlayer().getUniqueId())) {
//healed self
msg = ChatColor.DARK_GRAY + "You gained the effect ";
} else {
String name = cause.getEntity().getCustomName();
if (cause.getEntity() instanceof Player) {
name = ((Player) cause.getEntity()).getName();
}
if (name == null) {
name = cause.getEntity().getType().toString();
}
msg = ChatColor.GRAY + name + ChatColor.DARK_GRAY
+ " gave you the effect ";
}
String name = YamlWriter.toStandardFormat(effect.getType().getName());
FancyMessage message = new FancyMessage(msg);
message.then(name)
.color(ChatColor.DARK_PURPLE)
.tooltip(getEffectTooltip(effect, name));
message.send(qp.getPlayer().getPlayer());
}
} else {
//non player
//damage them for 0 if it's negative effect?
if (isEffectHarmful(effect.getType())) {
targ.setMetadata(DamageEffect.DAMAGE_META_KEY, new FixedMetadataValue
(QuestManagerPlugin.questManagerPlugin, true));
targ.damage(0.0, cause.getEntity());
targ.setMetadata(DamageEffect.DAMAGE_META_KEY, new FixedMetadataValue
(QuestManagerPlugin.questManagerPlugin, false));
}
}
}
}
@Override
public void apply(Location loc, MagicUser cause) {
//can't damage a location
//do nothing
;
}
public static List<String> getEffectTooltip(PotionEffect effect, String displayName) {
List<String> list = new LinkedList<>();
if (effect == null)
return list;
list.add(ChatColor.AQUA + displayName);
if (effect.getType().equals(PotionEffectType.ABSORPTION)) {
list.add(ChatColor.WHITE + "Grants temporary health that cannot be");
list.add(ChatColor.WHITE + "regenerated, but will be deducted from");
list.add(ChatColor.WHITE + "first");
list.add(ChatColor.GOLD + " Bonus Health: " + ChatColor.GREEN + (4 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.DAMAGE_RESISTANCE)) {
list.add(ChatColor.WHITE + "Reduces damage taken from all sources");
list.add(ChatColor.GOLD + " Damage Reduction: " + ChatColor.GREEN + (20 * (effect.getAmplifier() + 1))
+ "%" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.FAST_DIGGING)) {
list.add(ChatColor.WHITE + "Improves attack speed and digging speed");
list.add(ChatColor.GOLD + " Swing Speed: " + ChatColor.GREEN + "+"
+ (10 * effect.getAmplifier()) + "%");
list.add(ChatColor.GOLD + " Mining Speed: " + ChatColor.GREEN + "+"
+ (20 * effect.getAmplifier()) + "%" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.HEALTH_BOOST)) {
list.add(ChatColor.WHITE + "Grants a boost to maximum health for");
list.add(ChatColor.WHITE + "the duration of the effect");
list.add(ChatColor.GOLD + " Bonus Health: " + ChatColor.GREEN + (4 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.INCREASE_DAMAGE)) {
list.add(ChatColor.WHITE + "Increases melee damage dealt");
list.add(ChatColor.GOLD + " Damage Increase: " + ChatColor.GREEN + (3 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.LUCK)) {
list.add(ChatColor.WHITE + "Increases the chance of getting better");
list.add(ChatColor.WHITE + "loot from monsters and chests");
list.add(ChatColor.GOLD + " Luck Bonus: " + ChatColor.GREEN + (effect.getAmplifier() + 1)
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.POISON)) {
list.add(ChatColor.WHITE + "Deals damage over time until cured");
list.add(ChatColor.WHITE + "or the effect runs out");
int rate = 25, c = effect.getAmplifier();
while (c > 0 && rate > 1) {
c --;
rate /= 2;
}
list.add(String.format(ChatColor.GOLD + " Damage: " + ChatColor.RED + (effect.getDuration() / rate)
+ ChatColor.GOLD + " over " + ChatColor.RED + "%.2f seconds" + ChatColor.RESET,
(float) effect.getDuration() / 20));
} else if (effect.getType().equals(PotionEffectType.REGENERATION)) {
list.add(ChatColor.WHITE + "Restores health gradually");
int rate = 50, c = effect.getAmplifier();
while (c > 0 && rate > 1) {
c --;
rate /= 2;
}
list.add(String.format(ChatColor.GOLD + " Health: " + ChatColor.GREEN +(effect.getDuration() / rate)
+ ChatColor.GOLD + " over " + ChatColor.GREEN + "%.2f seconds" + ChatColor.RESET,
(float) effect.getDuration() / 20));
} else if (effect.getType().equals(PotionEffectType.SLOW)) {
list.add(ChatColor.WHITE + "Reduces all movement speed");
list.add(ChatColor.GOLD + " Reduction: " + ChatColor.RED + (15 * (effect.getAmplifier() + 1))
+ "%" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.SLOW_DIGGING)) {
list.add(ChatColor.WHITE + "Reduces swing and mining speed");
list.add(ChatColor.GOLD + " Swing Speed: " + ChatColor.RED + "-"
+ (10 * effect.getAmplifier()) + "%");
} else if (effect.getType().equals(PotionEffectType.SPEED)) {
list.add(ChatColor.WHITE + "Increases movement speed");
list.add(ChatColor.GOLD + " Reduction: " + ChatColor.GREEN + (20 * (effect.getAmplifier() + 1))
+ "%" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.WEAKNESS)) {
list.add(ChatColor.WHITE + "Decreases melee damage dealt");
list.add(ChatColor.GOLD + " Damage Penalty: " + ChatColor.RED + (4 * (effect.getAmplifier() + 1))
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.WITHER)) {
list.add(ChatColor.WHITE + "Deals damage over time until cured");
list.add(ChatColor.WHITE + ", the effect runs out, or death");
int rate = 40, c = effect.getAmplifier();
while (c > 0 && rate > 1) {
c --;
rate /= 2;
}
list.add(String.format(ChatColor.GOLD + " Damage: " + ChatColor.RED + (effect.getDuration() / rate)
+ ChatColor.GOLD + " over " + ChatColor.RED + "%.2f seconds" + ChatColor.RESET,
(float) effect.getDuration() / 20));
} else if (effect.getType().equals(PotionEffectType.BLINDNESS)) {
list.add(ChatColor.WHITE + "Decreases vision" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.CONFUSION)) {
list.add(ChatColor.WHITE + "Disorients the target" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.FIRE_RESISTANCE)) {
list.add(ChatColor.WHITE + "Negates all fire and lava damage" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.GLOWING)) {
list.add(ChatColor.WHITE + "Allows target to be seen through");
list.add(ChatColor.WHITE + "blocks and air alike" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.HUNGER)) {
list.add(ChatColor.WHITE + "Decreases food level over time" + ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.INVISIBILITY)) {
list.add(ChatColor.WHITE + "Renders the target invisible, making");
list.add(ChatColor.WHITE + "it harder for entities to detect them");
} else if (effect.getType().equals(PotionEffectType.JUMP)) {
list.add(ChatColor.WHITE + "Increases maximum jump height");
} else if (effect.getType().equals(PotionEffectType.LEVITATION)) {
list.add(ChatColor.WHITE + "Causes the target to float up");
list.add(ChatColor.WHITE + "into the air uncontrollably");
} else if (effect.getType().equals(PotionEffectType.NIGHT_VISION)) {
list.add(ChatColor.WHITE + "Negates the effects of darkness");
} else if (effect.getType().equals(PotionEffectType.SATURATION)) {
list.add(ChatColor.WHITE + "Replenishes hunger levels");
} else if (effect.getType().equals(PotionEffectType.UNLUCK)) {
list.add(ChatColor.WHITE + "Decreases the chance of getting better");
list.add(ChatColor.WHITE + "loot from monsters and chests");
list.add(ChatColor.GOLD + " Luck Penalty: " + ChatColor.RED + effect.getAmplifier()
+ ChatColor.RESET);
} else if (effect.getType().equals(PotionEffectType.WATER_BREATHING)) {
list.add(ChatColor.WHITE + "Grants unlimited breath underwater");
} else {
;
}
return list;
}
public PotionEffect getEffect() {
return effect;
}
public boolean isEffectHarmful(PotionEffectType type) {
return type.equals(PotionEffectType.BLINDNESS)
|| type.equals(PotionEffectType.CONFUSION)
|| type.equals(PotionEffectType.HARM)
|| type.equals(PotionEffectType.HUNGER)
|| type.equals(PotionEffectType.LEVITATION)
|| type.equals(PotionEffectType.POISON)
|| type.equals(PotionEffectType.SLOW)
|| type.equals(PotionEffectType.SLOW_DIGGING)
|| type.equals(PotionEffectType.UNLUCK)
|| type.equals(PotionEffectType.WEAKNESS)
|| type.equals(PotionEffectType.WITHER);
}
@Override
public ImbuementEffect getCopyAtPotency(double potency) {
PotionEffect ef = this.effect;
ef = new PotionEffect(ef.getType(), ef.getAmplifier(), (int) (ef.getDuration() * potency));
StatusEffect effect = new StatusEffect(ef);
effect.setDisplayName(getDisplayName());
return effect;
}
}