Prevent guardians from instantly retargeting.

The vanilla behavior for most mobs is that they just stop minding their
targets' business if aggro is lost. The same applies to guardians and
elder guardians.

To prevent the pace of gameplay from stagnating, MobArena compensates
for target loss by helping the mobs find a new target. The issue with
this in terms of guardians is that breaking line of sight is the only
way - besides killing it very quickly - to avoid taking damage from a
guardian due to its lock-on laser attack. This means that guardians and
elder guardians need to be excluded from the retargeting logic to make
sense in an arena setting.

This commit introduces a new EnumSet of EntityTypes to exclude from the
retargeting logic. It is not a particularly pretty solution, especially
not since ArenaListener is such a huge class already, but it does make
it easier to add more mobs later down the road, and it does a slightly
better job at giving way to a config setting at some point.

For the Mobs Rework, a per-monster flag like `auto-retarget` or similar
might be a much better solution, so it's possible to have encounters
like a small batch of guardians that _don't_ lose their targets but have
very little health, so the "race against time"-aspect can exist, but in
a much more configurable way.

Fixes #601
This commit is contained in:
Andreas Troelsen 2020-07-28 09:45:18 +02:00
parent 6de0a2fa83
commit b0969c655c
2 changed files with 13 additions and 0 deletions

View File

@ -20,6 +20,7 @@ These changes will (most likely) be included in the next version.
- The `player-time-in-arena` setting has been fixed.
- The `soft-restore` setting has been fixed for blocks broken by players. Note that the functionality is still unreliable for non-trivial blocks.
- Config-file errors imposed by incorrect usage of `/ma setting` no longer cause "internal errors". Instead, the errors are properly communicated in the command output similar to how the `/ma reload` command works.
- Guardians and elder guardians no longer instantly retarget players when they break line of sight. This should make their behavior work a bit closer to vanilla.
- The MagicSpells integration has been removed. This means that the extra `magicspells.yml` config-file (if it exists) no longer does anything and can be removed.
## [0.104.2] - 2020-01-03

View File

@ -95,6 +95,7 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@ -125,6 +126,8 @@ public class ArenaListener
private Set<Player> banned;
private EnumSet<EntityType> excludeFromRetargeting;
public ArenaListener(Arena arena, MobArena plugin) {
this.plugin = plugin;
this.arena = arena;
@ -154,6 +157,11 @@ public class ArenaListener
this.classLimits = arena.getClassLimitManager();
this.banned = new HashSet<>();
this.excludeFromRetargeting = EnumSet.of(
EntityType.ELDER_GUARDIAN,
EntityType.GUARDIAN
);
}
void pvpActivate() {
@ -849,6 +857,10 @@ public class ArenaListener
private void onMonsterTarget(EntityTargetEvent event, Entity monster, Entity target) {
// Null means we lost our target or the target died, so find a new one
if (target == null) {
// ... unless the monster is excluded from retargeting
if (excludeFromRetargeting.contains(monster.getType())) {
return;
}
event.setTarget(MAUtils.getClosestPlayer(plugin, monster, arena));
return;
}