Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Set;

import static net.countercraft.movecraft.util.ChatUtils.ERROR_PREFIX;

public class AADirectors extends Directors implements Listener {
public static final NamespacedKey ALLOW_AA_DIRECTOR_SIGN = new NamespacedKey("movecraft-combat", "allow_aa_director_sign");
private static final String HEADER = "AA Director";
public static int AADirectorDistance = 50;
public static int AADirectorNodeDistance = 3;
public static int AADirectorRange = 120;
private long lastCheck = 0;

Expand All @@ -46,6 +50,7 @@ public static void register() {

public static void load(@NotNull FileConfiguration config) {
AADirectorDistance = config.getInt("AADirectorDistance", 50);
AADirectorNodeDistance = config.getInt("AADirectorNodeDistance", 3);
AADirectorRange = config.getInt("AADirectorRange", 120);
}

Expand Down Expand Up @@ -75,28 +80,45 @@ private void processFireball(@NotNull SmallFireball fireball) {
if (!(c instanceof PlayerCraft) || !hasDirector((PlayerCraft) c))
return;

Player p = getDirector((PlayerCraft) c);
HashSet<DirectorData> craftDirectors = getCraftDirectors((PlayerCraft) c);
Player player;
Player dominantPlayer = null;

MovecraftLocation midPoint = c.getHitBox().getMidPoint();
int distX = Math.abs(midPoint.getX() - fireball.getLocation().getBlockX());
int distY = Math.abs(midPoint.getY() - fireball.getLocation().getBlockY());
int distZ = Math.abs(midPoint.getZ() - fireball.getLocation().getBlockZ());
if (distX > AADirectorDistance || distY > AADirectorDistance || distZ > AADirectorDistance)
return;
for (DirectorData data : craftDirectors) {
if (data.getSelectedNodes().isEmpty() || data.getSignLocations().isEmpty()) {
dominantPlayer = data.getPlayer();
}
}
if (dominantPlayer != null) {
player = dominantPlayer;
} else {
player = getClosestDirectorFromProjectile(
craftDirectors,
fireball.getLocation().toVector(),
AADirectorNodeDistance
);
}

fireball.setShooter(p);
if (player == null || player.getInventory().getItemInMainHand().getType() != Directors.DirectorTool)
return;

if (p == null || p.getInventory().getItemInMainHand().getType() != Directors.DirectorTool)
MovecraftLocation midpoint = c.getHitBox().getMidPoint();
int distX = Math.abs(midpoint.getX() - fireball.getLocation().getBlockX());
int distY = Math.abs(midpoint.getY() - fireball.getLocation().getBlockY());
int distZ = Math.abs(midpoint.getZ() - fireball.getLocation().getBlockZ());
if (distX*distX + distY*distY + distZ*distZ >= AADirectorDistance*AADirectorDistance)
return;

fireball.setShooter(player);

Vector fireballVector = fireball.getVelocity();
double speed = fireballVector.length(); // store the speed to add it back in later, since all the values we will be using are "normalized", IE: have a speed of 1
fireballVector = fireballVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far

Block targetBlock = DirectorUtils.getDirectorBlock(p, AADirectorRange);
Block targetBlock = DirectorUtils.getDirectorBlock(player, AADirectorRange);
Vector targetVector;
if (targetBlock == null || targetBlock.getType().equals(Material.AIR)) // the player is looking at nothing, shoot in that general direction
targetVector = p.getLocation().getDirection();
targetVector = player.getLocation().getDirection();
else { // shoot directly at the block the player is looking at (IE: with convergence)
targetVector = targetBlock.getLocation().toVector().subtract(fireball.getLocation().toVector());
targetVector = targetVector.normalize();
Expand Down Expand Up @@ -177,8 +199,15 @@ public void onSignClick(@NotNull PlayerInteractEvent e) {
return;
}

Set<String> selectedLines = processSign(sign);
if (isNodesShared(selectedLines, foundCraft, p)) {
p.sendMessage(ERROR_PREFIX + " " + I18nSupport.getInternationalisedString("AADirector - Must Not Share Nodes"));
return;
}

clearDirector(p);
addDirector(foundCraft, p);
addDirector(p, foundCraft, selectedLines);

p.sendMessage(I18nSupport.getInternationalisedString("AADirector - Directing"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
import net.countercraft.movecraft.util.MathUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.data.type.TNT;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
Expand All @@ -33,7 +35,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import static net.countercraft.movecraft.util.ChatUtils.ERROR_PREFIX;
Expand All @@ -42,11 +46,11 @@ public class CannonDirectors extends Directors implements Listener {
public static final NamespacedKey ALLOW_CANNON_DIRECTOR_SIGN = new NamespacedKey("movecraft-combat", "allow_cannon_director_sign");
private static final String HEADER = "Cannon Director";
public static int CannonDirectorDistance = 100;
public static int CannonDirectorNodeDistance = 3;
public static int CannonDirectorRange = 120;
private final Object2DoubleOpenHashMap<TNTPrimed> tracking = new Object2DoubleOpenHashMap<>();
private long lastCheck = 0;


public CannonDirectors() {
super();
}
Expand All @@ -57,6 +61,7 @@ public static void register() {

public static void load(@NotNull FileConfiguration config) {
CannonDirectorDistance = config.getInt("CannonDirectorDistance", 100);
CannonDirectorNodeDistance = config.getInt("CannonDirectorNodeDistance", 3);
CannonDirectorRange = config.getInt("CannonDirectorRange", 120);
}

Expand Down Expand Up @@ -98,16 +103,33 @@ private void processTNT(@NotNull TNTPrimed tnt) {
if (!(c instanceof PlayerCraft))
return;

MovecraftLocation midpoint = c.getHitBox().getMidPoint();
int distX = Math.abs(midpoint.getX() - tnt.getLocation().getBlockX());
int distY = Math.abs(midpoint.getY() - tnt.getLocation().getBlockY());
int distZ = Math.abs(midpoint.getZ() - tnt.getLocation().getBlockZ());
if (!hasDirector((PlayerCraft) c) || distX >= CannonDirectorDistance
|| distY >= CannonDirectorDistance || distZ >= CannonDirectorDistance)
// Automatically calibrate the TNT location based on its velocity to make it closer to the firing point.
Location correctedLocation = tnt.getLocation().clone().add(tnt.getVelocity().clone().multiply(-1.2));
Vector correctedPosition = correctedLocation.toVector();

HashSet<DirectorData> craftDirectors = getCraftDirectors((PlayerCraft) c);
Player player = null;
for (DirectorData data : craftDirectors) {
if (data.getSelectedNodes().isEmpty()) {
player = data.getPlayer();
}
}
if (player == null) {
player = getClosestDirectorFromProjectile(
craftDirectors,
correctedPosition,
CannonDirectorNodeDistance
);
}

if (player == null || player.getInventory().getItemInMainHand().getType() != Directors.DirectorTool)
return;

Player p = getDirector((PlayerCraft) c);
if (p == null || p.getInventory().getItemInMainHand().getType() != Directors.DirectorTool)
MovecraftLocation midpoint = c.getHitBox().getMidPoint();
int distX = Math.abs(midpoint.getX() - correctedPosition.getBlockX());
int distY = Math.abs(midpoint.getY() - correctedPosition.getBlockY());
int distZ = Math.abs(midpoint.getZ() - correctedPosition.getBlockZ());
if (distX*distX + distY*distY + distZ*distZ >= CannonDirectorDistance*CannonDirectorDistance)
return;

// Store the speed to add it back in later, since all the values we will be using are "normalized", IE: have a speed of 1
Expand All @@ -117,10 +139,10 @@ private void processTNT(@NotNull TNTPrimed tnt) {
double horizontalSpeed = tntVector.length();
tntVector = tntVector.normalize(); // you normalize it for comparison with the new direction to see if we are trying to steer too far

Block targetBlock = DirectorUtils.getDirectorBlock(p, CannonDirectorRange);
Block targetBlock = DirectorUtils.getDirectorBlock(player, CannonDirectorRange);
Vector targetVector;
if (targetBlock == null || targetBlock.getType().equals(Material.AIR)) // the player is looking at nothing, shoot in that general direction
targetVector = p.getLocation().getDirection();
targetVector = player.getLocation().getDirection();
else // shoot directly at the block the player is looking at (IE: with convergence)
targetVector = targetBlock.getLocation().toVector().subtract(tnt.getLocation().toVector());

Expand Down Expand Up @@ -207,8 +229,15 @@ public final void onSignClick(@NotNull PlayerInteractEvent e) {
return;
}

Set<String> selectedLines = processSign(sign);
if (isNodesShared(selectedLines, foundCraft, p)) {
p.sendMessage(ERROR_PREFIX + " " + I18nSupport.getInternationalisedString("CannonDirector - Must Not Share Nodes"));
return;
}

clearDirector(p);
addDirector(foundCraft, p);
addDirector(p, foundCraft, selectedLines);

p.sendMessage(I18nSupport.getInternationalisedString("CannonDirector - Directing"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package net.countercraft.movecraft.combat.features.directors;

import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.craft.PlayerCraft;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Set;

public class DirectorData {
private final Player player;
private final PlayerCraft craft;
private final Set<String> selectedNodes;
private Set<Vector> signLocations = new HashSet<>();
private MovecraftLocation currentLocation;

public DirectorData(Player player, PlayerCraft craft, Set<String> selectedNodes) {
this.player = player;
this.craft = craft;
this.selectedNodes = selectedNodes;
}

@NotNull
public Set<Vector> getSignLocations() {
if (selectedNodes.isEmpty()) return signLocations;
//If the craft stays in the same position, return the already known sign locations.
MovecraftLocation midpoint = craft.getHitBox().getMidPoint();
if (currentLocation == null) currentLocation = midpoint;
if (currentLocation.equals(midpoint) && !signLocations.isEmpty()) {
return signLocations;
}

currentLocation = midpoint;
for (MovecraftLocation location : craft.getHitBox()) {
Block block = craft.getWorld().getBlockAt(
location.getX(),
location.getY(),
location.getZ()
);
if (!(block.getState() instanceof Sign)) continue;
Sign sign = (Sign) block.getState();

if (!sign.getLine(0).equalsIgnoreCase("subcraft rotate")) continue;
if (sign.getLine(3).isBlank()) continue;
if (!selectedNodes.contains(sign.getLine(3))) continue;

Vector relativeVector = sign.getLocation().toVector();
signLocations.add(relativeVector);
}
return signLocations;
}

@NotNull
public Player getPlayer() {
return player;
}

@NotNull
public PlayerCraft getCraft() {
return craft;
}

@NotNull
public Set<String> getSelectedNodes() {
return selectedNodes;
}
}
Loading