SteamWar/FightSystem
Archiviert
13
1

Fix Button press, Lixfel AI v1
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2023-09-02 21:51:05 +02:00
Ursprung 84be0b3244
Commit 78ae119719
3 geänderte Dateien mit 103 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -35,13 +35,13 @@ import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Note; import org.bukkit.Note;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Lectern; import org.bukkit.block.Lectern;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.*;
import org.bukkit.block.data.Openable;
import org.bukkit.block.data.Powerable;
import org.bukkit.block.data.type.Comparator; import org.bukkit.block.data.type.Comparator;
import org.bukkit.block.data.type.NoteBlock; import org.bukkit.block.data.type.NoteBlock;
import org.bukkit.block.data.type.Repeater; import org.bukkit.block.data.type.Repeater;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -249,12 +249,34 @@ public abstract class AI {
powerable.setPowered(false); powerable.setPowered(false);
block.setBlockData(powerable); block.setBlockData(powerable);
updateButton(block);
}, type.name().endsWith("STONE_BUTTON") ? 20 : 30); }, type.name().endsWith("STONE_BUTTON") ? 20 : 30);
} }
powerable.setPowered(!isPowered); powerable.setPowered(!isPowered);
} }
block.setBlockData(data); 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() { private void run() {

Datei anzeigen

@ -21,40 +21,101 @@ package de.steamwar.fightsystem.ai;
import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
public class LixfelAI extends AI { public class LixfelAI extends AI {
private final Random random = new Random(); private Random random;
private LixfelPathplanner pathplanner; private LixfelPathplanner pathplanner;
private List<Cannon> cannons;
private List<Cannon> shootingList;
public LixfelAI(FightTeam team, String user) { public LixfelAI(FightTeam team, String user) {
super(team, SteamwarUser.get(user)); super(team, SteamwarUser.get(user));
} }
@Override @Override
public SchematicNode chooseSchematic() { public SchematicNode chooseSchematic() {
random = new Random();
cannons = new ArrayList<>();
shootingList = new ArrayList<>();
List<SchematicNode> publics = SchematicNode.getAllSchematicsOfType(0, Config.SchematicType.toDB()); List<SchematicNode> 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); 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; return schem;
} }
@Override @Override
protected void plan() { protected void plan() {
setReady(); 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<Vector> path = pathplanner.plan(getPosition(), destination); List<Vector> path = pathplanner.plan(getPosition(), destination);
if(!path.isEmpty()) if(path.isEmpty())
chat("Path size: " + path.size()); return false;
for(Vector p : path) {
move(p); path.forEach(this::move);
return true;
}
private class Cannon {
private final Vector activator;
private final List<Vector> 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<Vector> 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;
} }
} }
} }

Datei anzeigen

@ -30,6 +30,7 @@ import org.bukkit.util.Vector;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
public class LixfelPathplanner { public class LixfelPathplanner {
@ -87,6 +88,14 @@ public class LixfelPathplanner {
} }
} }
public Vector walkableNearby(double eyeHeight, double distance, List<Vector> nearby) {
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))
.findAny().orElse(null);
}
public List<Vector> planToAnywhere(Vector start, Vector destination) { public List<Vector> planToAnywhere(Vector start, Vector destination) {
Vector intermediate = walkable.stream().filter(vector -> neighbouring(vector, destination)).findAny().orElse(null); Vector intermediate = walkable.stream().filter(vector -> neighbouring(vector, destination)).findAny().orElse(null);