2019-01-16 13:01:24 +01:00
|
|
|
package com.songoda.epicenchants.wrappers;
|
|
|
|
|
2019-02-11 11:49:22 +01:00
|
|
|
import com.songoda.epicenchants.enums.TriggerType;
|
2019-01-17 17:11:59 +01:00
|
|
|
import com.songoda.epicenchants.objects.LeveledModifier;
|
2019-01-17 00:16:30 +01:00
|
|
|
import com.songoda.epicenchants.utils.GeneralUtils;
|
2019-01-17 17:11:59 +01:00
|
|
|
import com.songoda.epicenchants.utils.ItemBuilder;
|
2019-01-21 15:01:25 +01:00
|
|
|
import de.tr7zw.itemnbtapi.NBTEntity;
|
|
|
|
import de.tr7zw.itemnbtapi.NBTList;
|
|
|
|
import de.tr7zw.itemnbtapi.NBTListCompound;
|
|
|
|
import de.tr7zw.itemnbtapi.NBTType;
|
2019-01-16 13:01:24 +01:00
|
|
|
import lombok.Builder;
|
2019-01-17 00:16:30 +01:00
|
|
|
import org.bukkit.Location;
|
2019-01-21 15:01:25 +01:00
|
|
|
import org.bukkit.entity.*;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
2019-01-30 11:58:37 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2019-01-16 13:01:24 +01:00
|
|
|
|
2019-01-17 00:16:30 +01:00
|
|
|
import static java.util.concurrent.ThreadLocalRandom.current;
|
|
|
|
|
2019-01-16 13:01:24 +01:00
|
|
|
@Builder
|
|
|
|
public class MobWrapper {
|
2019-01-17 00:16:30 +01:00
|
|
|
private String displayName;
|
2019-01-16 13:01:24 +01:00
|
|
|
private EntityType entityType;
|
2019-01-24 12:00:57 +01:00
|
|
|
private LeveledModifier attackDamage;
|
2019-02-11 11:49:22 +01:00
|
|
|
private TriggerType triggerType;
|
2019-01-24 12:00:57 +01:00
|
|
|
private LeveledModifier equipmentDropChance;
|
2019-01-17 17:11:59 +01:00
|
|
|
private LeveledModifier spawnPercentage;
|
2019-01-24 12:00:57 +01:00
|
|
|
private LeveledModifier health;
|
|
|
|
private ItemBuilder helmet, chestPlate, leggings, boots, handItem;
|
2019-01-16 13:01:24 +01:00
|
|
|
private boolean hostile;
|
2019-01-24 12:00:57 +01:00
|
|
|
private LeveledModifier maxAmount;
|
2019-01-17 00:16:30 +01:00
|
|
|
|
2019-02-11 11:49:22 +01:00
|
|
|
public void trySpawn(@NotNull Player player, @Nullable LivingEntity opponent, int level, TriggerType triggerType) {
|
|
|
|
if (this.triggerType != triggerType) {
|
2019-01-24 12:00:57 +01:00
|
|
|
return;
|
2019-01-17 00:16:30 +01:00
|
|
|
}
|
|
|
|
|
2019-01-24 12:00:57 +01:00
|
|
|
if (!GeneralUtils.chance(spawnPercentage.get(level, 100))) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-21 15:01:25 +01:00
|
|
|
|
2019-01-24 12:00:57 +01:00
|
|
|
Location location = player.getLocation();
|
2019-01-21 15:01:25 +01:00
|
|
|
|
2019-01-24 12:00:57 +01:00
|
|
|
for (int i = 0; i < current().nextInt((int) (maxAmount.get(level, 1) + 1)); i++) {
|
2019-01-17 00:16:30 +01:00
|
|
|
Location spawnLocation = location.clone().add(current().nextInt(-3, 3), 0, current().nextInt(-3, 3));
|
|
|
|
int y = location.getWorld().getHighestBlockAt(spawnLocation).getY();
|
|
|
|
|
|
|
|
if (y < location.getY() - 10 || y > location.getY() + 10) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:01:25 +01:00
|
|
|
Entity entity = location.getWorld().spawnEntity(spawnLocation, entityType);
|
2019-01-17 00:16:30 +01:00
|
|
|
|
2019-01-24 12:00:57 +01:00
|
|
|
entity.setCustomName(displayName.replace("{level}", "" + level));
|
2019-01-17 00:16:30 +01:00
|
|
|
entity.setCustomNameVisible(true);
|
2019-01-21 15:01:25 +01:00
|
|
|
|
|
|
|
if (entity instanceof LivingEntity) {
|
|
|
|
LivingEntity livingEntity = (LivingEntity) entity;
|
2019-01-24 12:00:57 +01:00
|
|
|
int dropChance = (int) equipmentDropChance.get(level, 0);
|
|
|
|
|
|
|
|
if (helmet != null) livingEntity.getEquipment().setHelmet(helmet.buildWithWrappers(level));
|
|
|
|
if (chestPlate != null) livingEntity.getEquipment().setChestplate(chestPlate.buildWithWrappers(level));
|
|
|
|
if (leggings != null) livingEntity.getEquipment().setLeggings(leggings.buildWithWrappers(level));
|
|
|
|
if (boots != null) livingEntity.getEquipment().setBoots(boots.buildWithWrappers(level));
|
|
|
|
livingEntity.getEquipment().setHelmetDropChance(dropChance);
|
|
|
|
livingEntity.getEquipment().setLeggingsDropChance(dropChance);
|
|
|
|
livingEntity.getEquipment().setHelmetDropChance(dropChance);
|
|
|
|
livingEntity.getEquipment().setChestplateDropChance(dropChance);
|
|
|
|
|
|
|
|
if (handItem != null) livingEntity.getEquipment().setItemInMainHand(handItem.buildWithWrappers(level));
|
|
|
|
livingEntity.getEquipment().setItemInMainHandDropChance(dropChance);
|
2019-01-21 15:01:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (entity instanceof Monster && opponent != null) {
|
|
|
|
((Monster) entity).setTarget(opponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NBTEntity nbtEntity = new NBTEntity(entity);
|
2019-01-30 11:58:37 +01:00
|
|
|
|
|
|
|
nbtEntity.setBoolean(player.getUniqueId().toString(), true);
|
|
|
|
|
2019-01-21 15:01:25 +01:00
|
|
|
NBTList list = nbtEntity.getList("Attributes", NBTType.NBTTagCompound);
|
|
|
|
|
|
|
|
for (int j = 0; j < list.size(); j++) {
|
|
|
|
NBTListCompound lc = list.getCompound(j);
|
|
|
|
if (lc.getString("Name").equals("generic.attackDamage")) {
|
2019-01-24 12:00:57 +01:00
|
|
|
lc.setDouble("Base", attackDamage.get(level, (int) lc.getDouble("Base")));
|
2019-01-21 15:01:25 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lc.getString("Name").equals("generic.maxHealth")) {
|
2019-01-24 12:00:57 +01:00
|
|
|
lc.setDouble("Base", health.get(level, (int) lc.getDouble("Base")));
|
2019-01-21 15:01:25 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-17 00:16:30 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-16 13:01:24 +01:00
|
|
|
}
|