mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-24 01:19:22 +00:00
Added target modes
This commit is contained in:
@@ -227,6 +227,18 @@ public class EcoBoss extends PluginDependent {
|
||||
*/
|
||||
private final Map<String, List<String>> effectNames;
|
||||
|
||||
/**
|
||||
* The target distance.
|
||||
*/
|
||||
@Getter
|
||||
private final double targetDistance;
|
||||
|
||||
/**
|
||||
* The targeting mode.
|
||||
*/
|
||||
@Getter
|
||||
private final TargetMode targetMode;
|
||||
|
||||
/**
|
||||
* Create a new Boss.
|
||||
*
|
||||
@@ -444,6 +456,10 @@ public class EcoBoss extends PluginDependent {
|
||||
}
|
||||
});
|
||||
|
||||
// Targeting
|
||||
this.targetDistance = this.getConfig().getDouble("attacks.target.range");
|
||||
this.targetMode = TargetMode.getByName(this.getConfig().getString("attacks.target.mode"));
|
||||
|
||||
if (this.getConfig().getBool("enabled")) {
|
||||
EcoBosses.addBoss(this);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class LivingEcoBoss extends PluginDependent {
|
||||
// Tickers
|
||||
this.tickers = new HashSet<>();
|
||||
this.tickers.add(new HealthPlaceholderTicker());
|
||||
this.tickers.add(new TargetTicker());
|
||||
this.tickers.add(new TargetTicker(boss.getTargetMode(), boss.getTargetDistance()));
|
||||
if (boss.isBossbarEnabled()) {
|
||||
this.tickers.add(
|
||||
new BossBarTicker(
|
||||
|
||||
@@ -2,23 +2,57 @@ package com.willfp.ecobosses.bosses.tick.tickers;
|
||||
|
||||
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||
import com.willfp.ecobosses.bosses.tick.BossTicker;
|
||||
import com.willfp.ecobosses.bosses.util.obj.TargetMode;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TargetTicker implements BossTicker {
|
||||
/**
|
||||
* The targeting mode.
|
||||
*/
|
||||
private final TargetMode mode;
|
||||
|
||||
/**
|
||||
* The maximum range.
|
||||
*/
|
||||
private final double range;
|
||||
|
||||
/**
|
||||
* Create new target ticker.
|
||||
*
|
||||
* @param mode The targeting mode.
|
||||
* @param range The range.
|
||||
*/
|
||||
public TargetTicker(@NotNull final TargetMode mode,
|
||||
final double range) {
|
||||
this.mode = mode;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(@NotNull final EcoBoss boss,
|
||||
@NotNull final LivingEntity entity,
|
||||
final long tick) {
|
||||
Mob mob = (Mob) entity;
|
||||
if (tick % 10 == 0) {
|
||||
for (Entity nearbyEntity : entity.getNearbyEntities(10, 5, 10)) {
|
||||
if (nearbyEntity instanceof Player && entity instanceof Mob) {
|
||||
((Mob) entity).setTarget((Player) nearbyEntity);
|
||||
List<Player> nearbyPlayers = new ArrayList<>();
|
||||
for (Entity nearbyEntity : entity.getNearbyEntities(range, range, range)) {
|
||||
if (nearbyEntity instanceof Player) {
|
||||
nearbyPlayers.add((Player) nearbyEntity);
|
||||
}
|
||||
}
|
||||
|
||||
if (nearbyPlayers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mob.setTarget(mode.getTarget(nearbyPlayers, entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.willfp.ecobosses.bosses.util.obj;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class TargetMode {
|
||||
/**
|
||||
* All registered target modes.
|
||||
*/
|
||||
private static final Map<String, TargetMode> VALUES = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Random nearby player.
|
||||
*/
|
||||
public static final TargetMode RANDOM = new TargetMode("random", (list, entity) -> {
|
||||
return list.get(NumberUtils.randInt(0, list.size() - 1));
|
||||
});
|
||||
|
||||
/**
|
||||
* Closest player.
|
||||
*/
|
||||
public static final TargetMode CLOSEST = new TargetMode("closest", (list, entity) -> {
|
||||
Player player = null;
|
||||
double nearestD2 = 10000;
|
||||
for (Player nearbyPlayer : list) {
|
||||
double d2 = nearbyPlayer.getLocation().distanceSquared(entity.getLocation());
|
||||
if (d2 < nearestD2) {
|
||||
player = nearbyPlayer;
|
||||
}
|
||||
}
|
||||
return player;
|
||||
});
|
||||
|
||||
/**
|
||||
* Player with lowest health.
|
||||
*/
|
||||
public static final TargetMode LOWEST_HEALTH = new TargetMode("lowest-health", (list, entity) -> {
|
||||
Player player = null;
|
||||
double lowest = 100;
|
||||
for (Player nearbyPlayer : list) {
|
||||
double health = nearbyPlayer.getHealth();
|
||||
if (health < lowest) {
|
||||
player = nearbyPlayer;
|
||||
}
|
||||
}
|
||||
return player;
|
||||
});
|
||||
|
||||
/**
|
||||
* Player with highest health.
|
||||
*/
|
||||
public static final TargetMode HIGHEST_HEALTH = new TargetMode("highest-health", (list, entity) -> {
|
||||
Player player = null;
|
||||
double highest = 0;
|
||||
for (Player nearbyPlayer : list) {
|
||||
double health = nearbyPlayer.getHealth();
|
||||
if (health > highest) {
|
||||
player = nearbyPlayer;
|
||||
}
|
||||
}
|
||||
return player;
|
||||
});
|
||||
|
||||
/**
|
||||
* The name of the target mode.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The function to find a player out of a list.
|
||||
*/
|
||||
private final BiFunction<List<Player>, LivingEntity, Player> function;
|
||||
|
||||
protected TargetMode(@NotNull final String name,
|
||||
@NotNull final BiFunction<List<Player>, LivingEntity, Player> function) {
|
||||
this.name = name;
|
||||
this.function = function;
|
||||
|
||||
VALUES.put(name, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target from list of players.
|
||||
*
|
||||
* @param list The list.
|
||||
* @param entity The boss.
|
||||
* @return The target.
|
||||
*/
|
||||
public Player getTarget(@NotNull final List<Player> list,
|
||||
@NotNull final LivingEntity entity) {
|
||||
return function.apply(list, entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target mode by name.
|
||||
*
|
||||
* @param name The name.
|
||||
* @return The target mode, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public static TargetMode getByName(@NotNull final String name) {
|
||||
return VALUES.get(name);
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,11 @@ attacks:
|
||||
# Chance to shuffle your hotbar as a percentage - set to 0 to disable.
|
||||
shuffle-chance: 0
|
||||
|
||||
# How the boss decides who to attack
|
||||
target:
|
||||
distance: 15 # The distance to check for nearby players.
|
||||
mode: random
|
||||
|
||||
sounds:
|
||||
# Sounds are formatted like this:
|
||||
# sound:volume:pitch
|
||||
|
||||
@@ -94,6 +94,11 @@ attacks:
|
||||
# Chance to shuffle your hotbar as a percentage - set to 0 to disable.
|
||||
shuffle-chance: 10
|
||||
|
||||
# How the boss decides who to attack
|
||||
target:
|
||||
distance: 15 # The distance to check for nearby players.
|
||||
mode: random
|
||||
|
||||
sounds:
|
||||
# Sounds are formatted like this:
|
||||
# sound:volume:pitch
|
||||
|
||||
@@ -95,6 +95,11 @@ attacks:
|
||||
# Chance to shuffle your hotbar as a percentage - set to 0 to disable.
|
||||
shuffle-chance: 30
|
||||
|
||||
# How the boss decides who to attack
|
||||
target:
|
||||
distance: 15 # The distance to check for nearby players.
|
||||
mode: random
|
||||
|
||||
sounds:
|
||||
# Sounds are formatted like this:
|
||||
# sound:volume:pitch
|
||||
|
||||
@@ -96,6 +96,11 @@ attacks:
|
||||
# Chance to shuffle your hotbar as a percentage - set to 0 to disable.
|
||||
shuffle-chance: 0
|
||||
|
||||
# How the boss decides who to attack
|
||||
target:
|
||||
distance: 15 # The distance to check for nearby players.
|
||||
mode: random
|
||||
|
||||
sounds:
|
||||
# Sounds are formatted like this:
|
||||
# sound:volume:pitch
|
||||
|
||||
Reference in New Issue
Block a user