SteamWar/FightSystem
Archiviert
13
1

Merge remote-tracking branch 'origin/lixfel-ai-v1' into chaos-ai

Dieser Commit ist enthalten in:
Chaoscaot 2023-09-02 23:19:43 +02:00
Commit c507e7ec97
Signiert von: Chaoscaot
GPG-Schlüssel-ID: BDF8FADD7D5EDB7A
3 geänderte Dateien mit 70 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.sql.SteamwarUser;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
@ -58,6 +59,10 @@ public class LixfelAI extends AI {
cannons.add(new Cannon(new Vector(12,18,11), 13,17,15, 13,17,16, 13,18,16, 13,18,14, 14,18,14, 14,17,15, 14,17,16, 14,18,16, 13,17,14, 14,17,14, 13,18,15, 14,18,15));
cannons.add(new Cannon(new Vector(38,18,11), 37,18,14, 36,18,14, 36,17,15, 37,17,15, 37,18,15, 36,18,15, 36,17,14, 37,17,14, 36,17,16, 37,17,16, 36,18,16, 37,18,16));
cannons.add(new Cannon(new Vector(8,9,16), 10,11,17, 10,8,19, 10,8,17, 11,8,19, 11,8,15, 10,8,15, 12,8,15, 10,10,15, 12,7,19, 11,10,15, 12,8,19, 12,7,15, 11,7,15, 10,9,17, 11,9,19, 12,9,19, 10,9,19, 10,7,17, 11,7,19, 10,7,15, 10,7,19, 10,10,17, 12,9,15, 10,9,15, 11,9,15, 12,10,19, 11,10,19, 12,10,15, 10,6,17, 10,10,19));
//cannons.add(new Cannon(null, 23,5,9, 23,6,9, 23,7,9, 23,8,9));
//cannons.add(new Cannon(null, 27,5,9, 27,6,9, 27,7,9, 27,8,9));
cannons.add(new Cannon(null, 23,5,9, 23,6,9, 23,7,9, 23,8,9, 27,5,9, 27,6,9, 27,7,9, 27,8,9, 23,5,9, 23,6,9, 23,7,9, 23,8,9, 27,5,9, 27,6,9, 27,7,9, 27,8,9, 23,5,9, 23,6,9, 23,7,9, 23,8,9, 27,5,9, 27,6,9, 27,7,9, 27,8,9, 23,5,9, 23,6,9, 23,7,9, 23,8,9, 27,5,9, 27,6,9, 27,7,9, 27,8,9));
Collections.shuffle(cannons);
return schem;
}

Datei anzeigen

@ -19,13 +19,18 @@
package de.steamwar.fightsystem.ai;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BaseBlock;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.utils.WorldeditWrapper;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.*;
import org.bukkit.util.Vector;
import java.io.IOException;
@ -34,16 +39,40 @@ import java.util.stream.Collectors;
public class LixfelPathplanner {
private static BlockType getBlockType(Clipboard clipboard, BlockVector3 vector) {
return clipboard.getBlock(vector).getBlockType();
private static double blockHeight(Clipboard clipboard, BlockVector3 vector) {
BaseBlock block = clipboard.getFullBlock(vector);
if(block.getBlockType().getMaterial().isFullCube())
return 1.0;
BlockData data = BukkitAdapter.adapt(block);
Material material = data.getMaterial();
if(material.isSolid()) {
if(material.isInteractable()) {
if(data instanceof Stairs)
return 1.0;
else if(data instanceof Fence)
return 1.5;
else if(data instanceof Bed)
return 0.5625;
} else {
if(data instanceof Slab)
return ((Slab)data).getType() == Slab.Type.BOTTOM ? 0.5 : 1.0;
else if(data instanceof Wall)
return 1.5;
else if(data instanceof GlassPane || material == Material.IRON_BARS)
return 1.0;
}
} else {
if(material == Material.LADDER || material == Material.SCAFFOLDING)
return -1.0;
else if(material.name().endsWith("_CARPET"))
return 0.0625;
}
return 0.0;
}
private static boolean nonsolid(Clipboard clipboard, BlockVector3 vector) {
return !getBlockType(clipboard, vector).getMaterial().isSolid();
}
private static Vector toBukkit(BlockVector3 vector) {
return new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5);
private static Vector toBukkit(BlockVector3 vector, double height) {
return new Vector(vector.getX() + 0.5, vector.getY() + height, vector.getZ() + 0.5);
}
private final List<Vector> walkable = new ArrayList<>();
@ -62,25 +91,33 @@ public class LixfelPathplanner {
}
private void fillWalkable(Clipboard clipboard) {
BlockVector3 min = clipboard.getRegion().getMinimumPoint().subtract(Config.PreperationArea, 0, Config.PreperationArea); //TODO assumes nonextended Schematic with maximal size
Vector clipboardToSchem = new Vector(Config.BluePasteRegion.getSizeX(), Config.BluePasteRegion.getSizeY(), Config.BluePasteRegion.getSizeZ())
.subtract(WorldeditWrapper.impl.getDimensions(clipboard))
.multiply(0.5)
.add(new Vector(Config.PreperationArea, 0, Config.PreperationArea));
BlockVector3 diff = clipboard.getRegion().getMinimumPoint().subtract(clipboardToSchem.getBlockX(), clipboardToSchem.getBlockY(), clipboardToSchem.getBlockZ());
Region region = clipboard.getRegion();
clipboard.getRegion().forEach(vector -> {
BlockVector3 below = vector.subtract(0, 1, 0);
if(!region.contains(below))
BlockVector3 above = vector.add(0, 1, 0);
double aboveHeight = region.contains(above) ? blockHeight(clipboard, above) : 0.0;
if(aboveHeight > 0.0)
return;
BlockType belowMaterial = getBlockType(clipboard, below);
BlockVector3 above = vector.add(0, 1, 0);
if(nonsolid(clipboard, vector)) {
if(
(belowMaterial.getMaterial().isSolid() || belowMaterial.getId().equals("minecraft:ladder")) &&
(!region.contains(above) || nonsolid(clipboard, above))
)
walkable.add(toBukkit(vector.subtract(min)));
} else {
if(!region.contains(above))
walkable.add(toBukkit(above.subtract(min)));
}
double belowHeight = region.contains(below) ? blockHeight(clipboard, below) : 0.0;
double height = blockHeight(clipboard, vector);
if(height == 0.0 && Math.abs(belowHeight) < 1.0)
return;
if(height >= 1.0 && region.contains(above))
return;
if(height < 0.0)
height = 0.0;
walkable.add(toBukkit(vector.subtract(diff), height));
});
for(Vector vector : walkable) {
@ -92,7 +129,7 @@ public class LixfelPathplanner {
List<Vector> moddedNearby = nearby.stream().map(n -> n.clone().subtract(new Vector(0, eyeHeight, 0))).collect(Collectors.toList());
return walkable.stream()
.filter(vector -> moddedNearby.stream()
.allMatch(n -> n.distance(vector) <= distance))
.allMatch(n -> n.distance(vector) <= distance && !neighbouring(n, vector)))
.findAny().orElse(null);
}

Datei anzeigen

@ -76,6 +76,10 @@ public class Region {
return maxX - minX;
}
public int getSizeY() {
return maxY - minY;
}
public int getSizeZ() {
return maxZ - minZ;
}