diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java index a8864c13..0b681fc2 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java @@ -79,8 +79,8 @@ public abstract class AI { public static AI getAI(UUID uuid) { return ais.get(uuid); } - @Getter + @Getter protected final FightTeam team; @Getter private final LivingEntity entity; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java index 8952c762..90fcd3d0 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/DummyAI.java @@ -32,6 +32,8 @@ import java.util.Random; public class DummyAI extends AI { + private static final Random random = new Random(); + public DummyAI(FightTeam team) { super(team, SteamwarUser.get("public")); @@ -42,7 +44,7 @@ public class DummyAI extends AI { @Override public SchematicNode chooseSchematic() { List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); - return publics.get(new Random().nextInt(publics.size())); + return publics.get(random.nextInt(publics.size())); } @Override diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java deleted file mode 100644 index 2a89353c..00000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.fightsystem.ai; - -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.sql.SchematicNode; -import de.steamwar.sql.SteamwarUser; -import org.bukkit.util.Vector; - -import java.util.List; -import java.util.Random; - -public class LixfelAI extends AI { - - private final Random random = new Random(); - private LixfelPathplanner pathplanner; - - public LixfelAI(FightTeam team, String user) { - super(team, SteamwarUser.get(user)); - } - - - @Override - public SchematicNode chooseSchematic() { - List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); - SchematicNode schem = publics.get(new Random().nextInt(publics.size())); - pathplanner = new LixfelPathplanner(schem); - return schem; - } - - @Override - protected void plan() { - setReady(); - Vector destination = pathplanner.getWalkable().get(random.nextInt(pathplanner.getWalkable().size())); - List path = pathplanner.plan(getPosition(), destination); - if(!path.isEmpty()) - chat("Path size: " + path.size()); - for(Vector p : path) { - move(p); - } - } -} diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java deleted file mode 100644 index b2e593e8..00000000 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2023 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.fightsystem.ai; - -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 de.steamwar.fightsystem.Config; -import de.steamwar.sql.SchematicData; -import de.steamwar.sql.SchematicNode; -import org.bukkit.util.Vector; - -import java.io.IOException; -import java.util.*; - -public class LixfelPathplanner { - - private static BlockType getBlockType(Clipboard clipboard, BlockVector3 vector) { - return clipboard.getBlock(vector).getBlockType(); - } - - 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 final List walkable = new ArrayList<>(); - private final Map neighbours = new HashMap<>(); - - public LixfelPathplanner(SchematicNode schem) { - try { - fillWalkable(new SchematicData(schem).load()); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - public List getWalkable() { - return walkable; - } - - private void fillWalkable(Clipboard clipboard) { - BlockVector3 min = clipboard.getRegion().getMinimumPoint().subtract(Config.PreperationArea, 0, Config.PreperationArea); //TODO assumes nonextended Schematic with maximal size - Region region = clipboard.getRegion(); - clipboard.getRegion().forEach(vector -> { - BlockVector3 below = vector.subtract(0, 1, 0); - if(!region.contains(below)) - 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))); - } - }); - - for(Vector vector : walkable) { - neighbours.put(vector, walkable.stream().filter(neighbour -> neighbouring(neighbour, vector)).filter(neighbour -> neighbour != vector).toArray(Vector[]::new)); - } - } - - public List planToAnywhere(Vector start, Vector destination) { - Vector intermediate = walkable.stream().filter(vector -> neighbouring(vector, destination)).findAny().orElse(null); - - if(intermediate == null) - return Collections.emptyList(); - - List plan = plan(start, intermediate); - plan.add(destination); - - return plan; - } - - public List plan(Vector start, Vector destination) { - if(neighbouring(start, destination)) - return Collections.singletonList(destination); - - Map approach = new HashMap<>(); - Set checking = Collections.singleton(destination); - - while(!checking.isEmpty()) { - Set toCheck = new HashSet<>(); - for(Vector current : checking) { - Vector firstStep = Arrays.stream(neighbours.get(current)) - .filter(vector -> !approach.containsKey(vector)) - .filter(next -> { - approach.put(next, current); - toCheck.add(next); - return neighbouring(next, start); - }) - .findAny().orElse(null); - - if(firstStep != null) { - List path = new ArrayList<>(); - path.add(firstStep); - - while(path.get(path.size()-1) != destination) { - path.add(approach.get(path.get(path.size()-1))); - } - - return path; - } - } - checking = toCheck; - } - - return Collections.emptyList(); - } - - private boolean neighbouring(Vector a, Vector b) { - return Math.abs(a.getX() - b.getX()) <= 1 && Math.abs(a.getY() - b.getY()) <= 1 && Math.abs(a.getZ() - b.getZ()) <= 1; - } -}