diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java b/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java index 6f5cb00..17bed39 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/ai/AI.java @@ -35,13 +35,13 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Note; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Lectern; -import org.bukkit.block.data.BlockData; -import org.bukkit.block.data.Openable; -import org.bukkit.block.data.Powerable; +import org.bukkit.block.data.*; import org.bukkit.block.data.type.Comparator; import org.bukkit.block.data.type.NoteBlock; import org.bukkit.block.data.type.Repeater; +import org.bukkit.block.data.type.Switch; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -249,12 +249,34 @@ public abstract class AI { powerable.setPowered(false); block.setBlockData(powerable); + updateButton(block); }, type.name().endsWith("STONE_BUTTON") ? 20 : 30); } powerable.setPowered(!isPowered); } block.setBlockData(data); + if(data instanceof Switch) { + updateButton(block); + } + } + + private void updateButton(Block block) { + Switch sw = (Switch) block.getBlockData(); + FaceAttachable.AttachedFace face = sw.getAttachedFace(); + if (face == FaceAttachable.AttachedFace.FLOOR) { + update(block.getRelative(BlockFace.DOWN)); + } else if (face == FaceAttachable.AttachedFace.CEILING) { + update(block.getRelative(BlockFace.UP)); + } else { + update(block.getRelative(sw.getFacing().getOppositeFace())); + } + } + + private void update(Block block) { + BlockData data = block.getBlockData(); + block.setType(Material.BARRIER); + block.setBlockData(data); } private void run() { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java b/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java index 2a89353..35e7eef 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelAI.java @@ -21,40 +21,101 @@ package de.steamwar.fightsystem.ai; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.util.Vector; +import java.util.ArrayList; import java.util.List; import java.util.Random; public class LixfelAI extends AI { - private final Random random = new Random(); + private Random random; private LixfelPathplanner pathplanner; + private List cannons; + private List shootingList; public LixfelAI(FightTeam team, String user) { super(team, SteamwarUser.get(user)); } - @Override public SchematicNode chooseSchematic() { + random = new Random(); + cannons = new ArrayList<>(); + shootingList = new ArrayList<>(); + List publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); - SchematicNode schem = publics.get(new Random().nextInt(publics.size())); + SchematicNode schem = publics.get(random.nextInt(publics.size())); + schem = publics.stream().filter(s -> s.getName().equals("TheUnderground")).findAny().orElse(schem); + pathplanner = new LixfelPathplanner(schem); + + cannons.add(new Cannon(new Vector(11,25,11), 10,23,14, 12,23,14, 10,23,12, 12,23,12, 12,24,15, 10,24,14, 12,23,15, 12,24,14, 11,24,12, 10,24,15, 12,24,12, 10,23,15, 10,24,12)); + cannons.add(new Cannon(new Vector(39,25,11), 38,24,15, 38,23,12, 40,23,14, 40,24,12, 40,23,15, 40,24,14, 39,24,12, 38,23,14, 40,24,15, 40,23,12, 38,23,15, 38,24,12, 38,24,14)); + 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)); + return schem; } @Override protected void plan() { setReady(); - Vector destination = pathplanner.getWalkable().get(random.nextInt(pathplanner.getWalkable().size())); + if(shootingList.isEmpty()) + shootingList.addAll(cannons); + + if(shootingList.isEmpty() || FightState.getFightState() != FightState.RUNNING) { + moveTo(pathplanner.getWalkable().get(random.nextInt(pathplanner.getWalkable().size()))); + return; + } + + Cannon cannon = shootingList.remove(0); + cannon.shoot(); + } + + private boolean moveTo(Vector destination) { List path = pathplanner.plan(getPosition(), destination); - if(!path.isEmpty()) - chat("Path size: " + path.size()); - for(Vector p : path) { - move(p); + if(path.isEmpty()) + return false; + + path.forEach(this::move); + return true; + } + + private class Cannon { + private final Vector activator; + private final List tnt = new ArrayList<>(); + private final Vector entityLocation; + + public Cannon(Vector activator, int... tntpos) { + this.activator = activator; + + for(int i = 0; i < tntpos.length; i+=3) { + tnt.add(new Vector(tntpos[i], tntpos[i+1], tntpos[i+2])); + } + + List locations = new ArrayList<>(tnt); + if(activator != null) + locations.add(activator); + entityLocation = pathplanner.walkableNearby(getEntity().getEyeHeight(), 5, locations); + } + + public boolean shoot() { + if(entityLocation == null) + return false; + + if(!moveTo(entityLocation)) + return false; + + tnt.forEach(LixfelAI.this::setTNT); + if(activator != null) + interact(activator); + + return true; } } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java b/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java index b2e593e..5e5c8e7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/ai/LixfelPathplanner.java @@ -30,6 +30,7 @@ import org.bukkit.util.Vector; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; public class LixfelPathplanner { @@ -87,6 +88,14 @@ public class LixfelPathplanner { } } + public Vector walkableNearby(double eyeHeight, double distance, List nearby) { + List 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)) + .findAny().orElse(null); + } + public List planToAnywhere(Vector start, Vector destination) { Vector intermediate = walkable.stream().filter(vector -> neighbouring(vector, destination)).findAny().orElse(null);