Compare commits
7 Commits
modular-fi
...
FightSyste
| Author | SHA1 | Date | |
|---|---|---|---|
| a07067725f | |||
| 264e541fc7 | |||
| 82a59f772e | |||
| 2c44e50846 | |||
| f51bce6a69 | |||
| bf26dfed56 | |||
| 395303d04f |
@@ -23,14 +23,12 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.fight.JoinRequest;
|
||||
import de.steamwar.fightsystem.listener.Chat;
|
||||
import de.steamwar.fightsystem.record.GlobalRecorder;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import de.steamwar.fightsystem.utils.Region;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.Getter;
|
||||
@@ -54,7 +52,6 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
@@ -87,6 +84,8 @@ public abstract class AI {
|
||||
private final BukkitTask task;
|
||||
private final Queue<Action> queue = new ArrayDeque<>();
|
||||
|
||||
protected final NavMesh navMesh;
|
||||
|
||||
protected AI(FightTeam team, SteamwarUser user) {
|
||||
this.team = team;
|
||||
|
||||
@@ -98,6 +97,8 @@ public abstract class AI {
|
||||
ais.put(entity.getUniqueId(), this);
|
||||
team.addMember(entity, user);
|
||||
|
||||
navMesh = new NavMesh(team);
|
||||
|
||||
if(FightState.Schem.contains(FightState.getFightState()))
|
||||
Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> schematic(team.getClipboard()));
|
||||
}
|
||||
@@ -134,58 +135,61 @@ public abstract class AI {
|
||||
Chat.broadcastChat("PARTICIPANT_CHAT", team.getColoredName(), entity.getName(), message);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
Location location = entity.getLocation();
|
||||
Region extend = team.getExtendRegion();
|
||||
if(Fight.getUnrotated() == team)
|
||||
return new Vector(
|
||||
location.getX() - extend.getMinX(),
|
||||
location.getY() - team.getSchemRegion().getMinY(),
|
||||
location.getZ() - extend.getMinZ()
|
||||
);
|
||||
else
|
||||
return new Vector(
|
||||
extend.getMaxX() - location.getX(),
|
||||
location.getY() - team.getSchemRegion().getMinY(),
|
||||
extend.getMaxZ() - location.getZ()
|
||||
);
|
||||
public LocalCoordinate getPosition() {
|
||||
return WorldCoordinate.from(entity.getLocation()).toLocal(team);
|
||||
}
|
||||
|
||||
public Material getBlock(Vector pos) {
|
||||
public Material getBlock(WorldCoordinate pos) {
|
||||
return getBlock(pos.toLocal(team));
|
||||
}
|
||||
|
||||
public Material getBlock(LocalCoordinate pos) {
|
||||
queue.add(new Action(1));
|
||||
return translate(pos).getBlock().getType();
|
||||
return pos.toWorld(team).toLocation(Config.world).getBlock().getType();
|
||||
}
|
||||
|
||||
public BlockData getBlockData(Vector pos) {
|
||||
public BlockData getBlockData(WorldCoordinate pos) {
|
||||
return getBlockData(pos.toLocal(team));
|
||||
}
|
||||
|
||||
public BlockData getBlockData(LocalCoordinate pos) {
|
||||
queue.add(new Action(1));
|
||||
return translate(pos).getBlock().getBlockData();
|
||||
return pos.toWorld(team).toLocation(Config.world).getBlock().getBlockData();
|
||||
}
|
||||
|
||||
public void setTNT(Vector pos) {
|
||||
public void setTNT(WorldCoordinate pos) {
|
||||
setTNT(pos.toLocal(team));
|
||||
}
|
||||
|
||||
public void setTNT(LocalCoordinate pos) {
|
||||
queue.add(new Action(1) {
|
||||
@Override
|
||||
public void run() {
|
||||
if(FightState.getFightState() != FightState.RUNNING)
|
||||
return;
|
||||
|
||||
Location location = translate(pos);
|
||||
Location location = pos.toWorld(team).toLocation(Config.world);
|
||||
if(interactionDistanceViolation(location)) {
|
||||
chat("InteractionDistanceViolation: setTNT");
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = location.getBlock();
|
||||
if(block.getType() == Material.AIR)
|
||||
if(block.getType() == Material.AIR || block.getType() == Material.WATER || block.getType() == Material.LAVA || block.getType() == Material.TNT)
|
||||
block.setType(Material.TNT);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void interact(Vector pos) {
|
||||
public void interact(WorldCoordinate pos) {
|
||||
interact(pos.toLocal(team));
|
||||
}
|
||||
|
||||
public void interact(LocalCoordinate pos) {
|
||||
queue.add(new Action(1) {
|
||||
@Override
|
||||
public void run() {
|
||||
Location location = translate(pos);
|
||||
Location location = pos.toWorld(team).toLocation(Config.world);
|
||||
if(interactionDistanceViolation(location)) {
|
||||
chat("InteractionDistanceViolation: interact");
|
||||
return;
|
||||
@@ -196,11 +200,15 @@ public abstract class AI {
|
||||
});
|
||||
}
|
||||
|
||||
public void interact(Vector pos, int n) {
|
||||
public void interact(WorldCoordinate pos, int n) {
|
||||
interact(pos.toLocal(team), n);
|
||||
}
|
||||
|
||||
public void interact(LocalCoordinate pos, int n) {
|
||||
queue.add(new Action(1) {
|
||||
@Override
|
||||
public void run() {
|
||||
Location location = translate(pos);
|
||||
Location location = pos.toWorld(team).toLocation(Config.world);
|
||||
if (interactionDistanceViolation(location))
|
||||
return;
|
||||
Block block = location.getBlock();
|
||||
@@ -217,39 +225,75 @@ public abstract class AI {
|
||||
});
|
||||
}
|
||||
|
||||
public void move(Vector pos) {
|
||||
public MoveResult checkMove(WorldCoordinate target) {
|
||||
Location location = entity.getLocation();
|
||||
if(!entity.isOnGround() && location.getBlock().getType() != Material.LADDER) {
|
||||
return MoveResult.FALLING;
|
||||
}
|
||||
|
||||
if(Math.abs(location.getX() - target.getX()) > 1.5 || Math.abs(location.getY() - target.getY()) > 1.5 || Math.abs(location.getZ() - target.getZ()) > 1.5) {
|
||||
return MoveResult.OVERDISTANCE;
|
||||
}
|
||||
|
||||
if(!team.getFightPlayer(entity).canEntern() && !team.getExtendRegion().inRegion(target.toLocation(null)))
|
||||
return MoveResult.OUT_OF_BORDER;
|
||||
return MoveResult.OK;
|
||||
}
|
||||
|
||||
public enum MoveResult {
|
||||
FALLING,
|
||||
OVERDISTANCE,
|
||||
OUT_OF_BORDER,
|
||||
OK,
|
||||
}
|
||||
|
||||
public void move(WorldCoordinate pos) {
|
||||
queue.add(new Action(MOVEMENT_DELAY) {
|
||||
@Override
|
||||
public void run() {
|
||||
Location location = entity.getLocation();
|
||||
if(!entity.isOnGround() && location.getBlock().getType() != Material.LADDER) {
|
||||
FightSystem.getPlugin().getLogger().log(Level.INFO, "Entity falling");
|
||||
return;
|
||||
MoveResult moveResult = checkMove(pos);
|
||||
switch (moveResult) {
|
||||
case FALLING:
|
||||
FightSystem.getPlugin().getLogger().log(Level.INFO, "Entity falling");
|
||||
return;
|
||||
case OVERDISTANCE:
|
||||
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + ": Overdistance movement " + entity.getLocation().toVector() + " " + pos);
|
||||
return;
|
||||
case OUT_OF_BORDER:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Location target = translate(pos);
|
||||
if(Math.abs(location.getX() - target.getX()) > 1.0 || Math.abs(location.getY() - target.getY()) > 1.5 || Math.abs(location.getZ() - target.getZ()) > 1.0) {
|
||||
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> entity.getName() + ": Overdistance movement " + location.toVector() + " " + target.toVector());
|
||||
return;
|
||||
Location currentLocation = entity.getLocation();
|
||||
Location target = pos.toLocation(Config.world);
|
||||
if (currentLocation.getBlockX() != target.getBlockX() || currentLocation.getBlockY() != target.getBlockY() || currentLocation.getBlockZ() != target.getBlockZ()) {
|
||||
target.setDirection(target.toVector().subtract(currentLocation.toVector()));
|
||||
}
|
||||
if (currentLocation.getBlockX() == target.getBlockX() && currentLocation.getBlockZ() == target.getBlockZ()) {
|
||||
target.setYaw(currentLocation.getYaw());
|
||||
}
|
||||
|
||||
if(!team.getFightPlayer(entity).canEntern() && !team.getExtendRegion().inRegion(target))
|
||||
return;
|
||||
|
||||
if(!entity.teleport(target, PlayerTeleportEvent.TeleportCause.PLUGIN))
|
||||
FightSystem.getPlugin().getLogger().log(Level.INFO, "Entity not teleported: " + entity.isValid());
|
||||
|
||||
GlobalRecorder.getInstance().entityMoves(entity);
|
||||
navMesh.update(getPosition().toWorld(team));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void move(LocalCoordinate pos) {
|
||||
move(pos.toWorld(team));
|
||||
}
|
||||
|
||||
private boolean interactionDistanceViolation(Location location) {
|
||||
return location.distance(entity.getEyeLocation()) > INTERACTION_RANGE;
|
||||
}
|
||||
|
||||
private void interact(Block block) {
|
||||
BlockData data = block.getBlockData(); //TODO only 1.14+ compatible at the moment
|
||||
System.out.println(block + " " + data);
|
||||
if (data instanceof NoteBlock) {
|
||||
NoteBlock noteBlock = (NoteBlock) data;
|
||||
Note note = noteBlock.getNote();
|
||||
@@ -280,6 +324,7 @@ public abstract class AI {
|
||||
}
|
||||
|
||||
powerable.setPowered(!isPowered);
|
||||
System.out.println(powerable);
|
||||
}
|
||||
block.setBlockData(data);
|
||||
if(data instanceof Switch) {
|
||||
@@ -319,24 +364,6 @@ public abstract class AI {
|
||||
queue.poll().run();
|
||||
}
|
||||
|
||||
public Location translate(Vector pos) {
|
||||
Region extend = team.getExtendRegion();
|
||||
if(Fight.getUnrotated() == team)
|
||||
return new Location(
|
||||
Config.world,
|
||||
pos.getX() + extend.getMinX(),
|
||||
pos.getY() + team.getSchemRegion().getMinY(),
|
||||
pos.getZ() + extend.getMinZ()
|
||||
);
|
||||
else
|
||||
return new Location(
|
||||
Config.world,
|
||||
extend.getMaxX() - pos.getX(),
|
||||
pos.getY() + team.getSchemRegion().getMinY(),
|
||||
extend.getMaxZ() - pos.getZ()
|
||||
);
|
||||
}
|
||||
|
||||
private static class Action {
|
||||
private int delay;
|
||||
public Action(int delay) {
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.ai.yoyonow.YoyoNowAI;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -35,7 +37,8 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class AIManager {
|
||||
private static final List<AIManager> AIs = Arrays.asList(
|
||||
new AIManager(DummyAI.class, Material.STONE, () -> ArenaMode.Test.contains(Config.mode))
|
||||
new AIManager(DummyAI.class, Material.STONE, () -> ArenaMode.Test.contains(Config.mode)),
|
||||
new AIManager(YoyoNowAI.class, Material.SLIME_BLOCK, () -> Config.GameModeConfig.Schematic.Type.toDB().equals("miniwargear") && Core.getVersion() >= 14)
|
||||
);
|
||||
|
||||
public static List<AIManager> availableAIs() {
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import de.steamwar.fightsystem.ai.schematic.Cannon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface Action {
|
||||
|
||||
Result step(AI ai);
|
||||
|
||||
enum Result {
|
||||
ONGOING,
|
||||
FINISHED,
|
||||
FAILED,
|
||||
;
|
||||
}
|
||||
|
||||
class MultiAction implements Action {
|
||||
|
||||
protected final List<Action> actions = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Result step(AI ai) {
|
||||
if (!actions.isEmpty()) {
|
||||
Action.Result result = actions.get(0).step(ai);
|
||||
if (result == Action.Result.FAILED) {
|
||||
ai.chat(this + " + " + actions.get(0) + " failed");
|
||||
actions.clear();
|
||||
return Result.FAILED;
|
||||
}
|
||||
if (result == Action.Result.FINISHED) {
|
||||
ai.chat(this + " + " + actions.get(0) + " finished");
|
||||
actions.remove(0);
|
||||
}
|
||||
}
|
||||
return actions.isEmpty() ? Result.FINISHED : Result.ONGOING;
|
||||
}
|
||||
}
|
||||
|
||||
class WaitAction implements Action {
|
||||
|
||||
private int delay;
|
||||
|
||||
public WaitAction(int delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result step(AI ai) {
|
||||
if (--delay > 0) {
|
||||
return Result.ONGOING;
|
||||
} else {
|
||||
return Result.FINISHED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MoveAction implements Action {
|
||||
|
||||
private final WorldCoordinate destination;
|
||||
private List<WorldCoordinate> path;
|
||||
private int overDistanceCounter = 0;
|
||||
|
||||
public MoveAction(AI ai, LocalCoordinate destination) {
|
||||
this(ai, destination.toWorld(ai.team));
|
||||
}
|
||||
|
||||
public MoveAction(AI ai, WorldCoordinate destination) {
|
||||
this.destination = destination;
|
||||
this.path = ai.navMesh.pathToNearest(ai.getPosition().toWorld(ai.team), destination);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result step(AI ai) {
|
||||
if (this.path.isEmpty()) return Result.FAILED;
|
||||
WorldCoordinate coordinate = path.get(0);
|
||||
|
||||
if (!ai.navMesh.isWalkable(coordinate)) {
|
||||
path = ai.navMesh.pathToNearest(ai.getPosition().toWorld(ai.team), destination);
|
||||
if (path.isEmpty()) return Result.FAILED;
|
||||
coordinate = path.get(0);
|
||||
}
|
||||
|
||||
AI.MoveResult moveResult = ai.checkMove(coordinate);
|
||||
if (moveResult == AI.MoveResult.OVERDISTANCE) {
|
||||
if (overDistanceCounter == 5) {
|
||||
path = ai.navMesh.pathToNearest(ai.getPosition().toWorld(ai.team), destination);
|
||||
return path.isEmpty() ? Result.FAILED : Result.ONGOING;
|
||||
}
|
||||
if (overDistanceCounter++ > 5) {
|
||||
return Result.FAILED;
|
||||
}
|
||||
return Result.ONGOING;
|
||||
}
|
||||
overDistanceCounter = 0;
|
||||
|
||||
if (moveResult == AI.MoveResult.FALLING) {
|
||||
return Result.ONGOING;
|
||||
}
|
||||
|
||||
if (moveResult == AI.MoveResult.OK) {
|
||||
path.remove(0);
|
||||
ai.move(coordinate);
|
||||
}
|
||||
return path.isEmpty() ? Result.FINISHED : Result.ONGOING;
|
||||
}
|
||||
}
|
||||
|
||||
class InteractAction implements Action {
|
||||
private final LocalCoordinate destination;
|
||||
|
||||
public InteractAction(LocalCoordinate destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result step(AI ai) {
|
||||
ai.interact(destination);
|
||||
return Result.FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
class ReadyAction implements Action {
|
||||
|
||||
@Override
|
||||
public Result step(AI ai) {
|
||||
ai.setReady();
|
||||
return Result.FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
class PlaceTNTAction implements Action {
|
||||
|
||||
private final LocalCoordinate destination;
|
||||
|
||||
public PlaceTNTAction(LocalCoordinate destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result step(AI ai) {
|
||||
ai.setTNT(destination);
|
||||
return Result.FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
class LoadCannon extends MultiAction {
|
||||
|
||||
public LoadCannon(AI ai, Cannon cannon) {
|
||||
for (LocalCoordinate tntPosition : cannon.getTntPositions()) {
|
||||
actions.add(new MoveAction(ai, tntPosition.toWorld(ai.team)));
|
||||
actions.add(new PlaceTNTAction(tntPosition));
|
||||
}
|
||||
|
||||
LocalCoordinate trigger = cannon.getTriggerPositions().iterator().next();
|
||||
actions.add(new MoveAction(ai, trigger.toWorld(ai.team)));
|
||||
actions.add(new InteractAction(trigger));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.utils.Region;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class LocalCoordinate {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public int getBlockX() {
|
||||
return NumberConversions.floor(x);
|
||||
}
|
||||
|
||||
public int getBlockY() {
|
||||
return NumberConversions.floor(y);
|
||||
}
|
||||
|
||||
public int getBlockZ() {
|
||||
return NumberConversions.floor(z);
|
||||
}
|
||||
|
||||
public double distanceSquared(LocalCoordinate coordinate) {
|
||||
return NumberConversions.square(x - coordinate.x) + NumberConversions.square(y - coordinate.y) + NumberConversions.square(z - coordinate.z);
|
||||
}
|
||||
|
||||
public WorldCoordinate toWorld(FightTeam team) {
|
||||
// TODO: Fix the of by one blue/red
|
||||
// Team Red is not correct!
|
||||
// NightTown is team blue unrotated!
|
||||
Region extend = team.getExtendRegion();
|
||||
if(Fight.getUnrotated() == team) {
|
||||
return new WorldCoordinate(
|
||||
x + extend.getMinX(),
|
||||
y + team.getSchemRegion().getMinY(),
|
||||
z + extend.getMinZ()
|
||||
);
|
||||
} else {
|
||||
return new WorldCoordinate(
|
||||
extend.getMaxX() - x - 1,
|
||||
y + team.getSchemRegion().getMinY(),
|
||||
extend.getMaxZ() - z - 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public LocalCoordinate add(LocalCoordinate localCoordinate) {
|
||||
this.x += localCoordinate.x;
|
||||
this.y += localCoordinate.y;
|
||||
this.z += localCoordinate.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalCoordinate add(double x, double y, double z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Local{" + x + "," + y + "," + z + "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,402 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import de.steamwar.entity.RBlockDisplay;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.OneShotStateDependent;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.bukkit.util.Transformation;
|
||||
import org.bukkit.util.VoxelShape;
|
||||
import org.joml.AxisAngle4f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class NavMesh {
|
||||
|
||||
private static final double PLAYER_FALL_DISTANCE = 3;
|
||||
private static final double PLAYER_JUMP_HEIGHT = 1.25;
|
||||
private static final double PLAYER_HEIGHT = 1.8;
|
||||
private static final Cuboid PLAYER_SHADOW = new Cuboid(0.2, 0, 0.2, 0.6, 1, 0.6);
|
||||
|
||||
private static final Set<Pos> RELATIVE_BLOCKS = new HashSet<>();
|
||||
protected static final BlockData PATH_BLOCK = Material.LIME_STAINED_GLASS.createBlockData();
|
||||
|
||||
static {
|
||||
for (int y = (int) -Math.ceil(PLAYER_FALL_DISTANCE); y <= Math.ceil(PLAYER_JUMP_HEIGHT); y++) {
|
||||
RELATIVE_BLOCKS.add(new Pos(-1, y, 0));
|
||||
RELATIVE_BLOCKS.add(new Pos(1, y, 0));
|
||||
RELATIVE_BLOCKS.add(new Pos(0, y, -1));
|
||||
RELATIVE_BLOCKS.add(new Pos(0, y, 1));
|
||||
}
|
||||
RELATIVE_BLOCKS.add(new Pos(0, 1, 0));
|
||||
RELATIVE_BLOCKS.add(new Pos(0, -1, 0));
|
||||
}
|
||||
|
||||
private FightTeam fightTeam;
|
||||
private REntityServer server = new REntityServer();
|
||||
|
||||
private Map<Pos, Pos> walkable = new HashMap<>();
|
||||
private Map<Pos, Set<Pos>> connections = new HashMap<>(); // Reverse connections!
|
||||
|
||||
@Getter
|
||||
private boolean ready = false;
|
||||
|
||||
public NavMesh(FightTeam fightTeam) {
|
||||
this.fightTeam = fightTeam;
|
||||
|
||||
new OneShotStateDependent(ArenaMode.All, FightState.PostSchemSetup, () -> {
|
||||
Bukkit.getOnlinePlayers().forEach(server::addPlayer);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> {
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
fightTeam.getExtendRegion().forEach((x, y, z) -> {
|
||||
if (y < fightTeam.getSchemRegion().getMinY()) return;
|
||||
calculatePosition(new Pos(x, y, z), walkable);
|
||||
});
|
||||
|
||||
walkable.values().forEach(this::checkNeighbouring);
|
||||
|
||||
System.out.println("NavMesh initialized in " + (System.currentTimeMillis() - time) + " ms");
|
||||
ready = true;
|
||||
}, 20);
|
||||
});
|
||||
new OneShotStateDependent(ArenaMode.All, FightState.Spectate, () -> {
|
||||
ready = false;
|
||||
});
|
||||
}
|
||||
|
||||
private void calculatePosition(Pos pos, Map<Pos, Pos> walkable) {
|
||||
Block block = Config.world.getBlockAt(pos.x, pos.y, pos.z);
|
||||
// Air is not walkable
|
||||
if (block.isPassable()) return;
|
||||
|
||||
// Ignore Ladders from floor calculation!
|
||||
if (block.getType() != Material.LADDER) {
|
||||
// Floor Position
|
||||
pos.floor = playerCollisionMax(block.getCollisionShape());
|
||||
// If no walkable block remove
|
||||
if (pos.floor == 0) return;
|
||||
} else {
|
||||
pos.floor = 0.5;
|
||||
}
|
||||
|
||||
// Ceiling Position
|
||||
pos.ceiling = fightTeam.getExtendRegion().getMaxY() - pos.y;
|
||||
for (int y = pos.y + 1; y <= fightTeam.getExtendRegion().getMaxY() + 3; y++) {
|
||||
block = Config.world.getBlockAt(pos.x, y, pos.z);
|
||||
if (block.isPassable()) continue;
|
||||
double min = playerCollisionMin(block.getCollisionShape());
|
||||
if (min >= 1.0) continue;
|
||||
pos.ceiling = y + min - pos.y;
|
||||
break;
|
||||
}
|
||||
// If player cannot fit remove
|
||||
if (pos.ceiling - pos.floor < PLAYER_HEIGHT) return;
|
||||
|
||||
walkable.put(pos, pos);
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
private static class Pos {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private double floor = 0;
|
||||
private double ceiling = 0;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return x + "," + y + "(" + floor + ".." + ceiling + ")" + "," + z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Pos)) return false;
|
||||
Pos pos = (Pos) o;
|
||||
return x == pos.x && y == pos.y && z == pos.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, y, z);
|
||||
}
|
||||
|
||||
public Pos add(Pos pos) {
|
||||
return new Pos(x + pos.x, y + pos.y, z + pos.z);
|
||||
}
|
||||
|
||||
public WorldCoordinate toWorld() {
|
||||
return new WorldCoordinate(x, y + floor, z);
|
||||
}
|
||||
|
||||
public double floorPosition() {
|
||||
return y + floor;
|
||||
}
|
||||
|
||||
public double ceilingPosition() {
|
||||
return y + ceiling;
|
||||
}
|
||||
}
|
||||
|
||||
private double playerCollisionMax(VoxelShape voxelShape) {
|
||||
List<Double> yList = voxelShape.getBoundingBoxes().stream()
|
||||
.flatMap(boundingBox -> Stream.of(boundingBox.getMinY(), boundingBox.getMaxY()))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
double collisionY = 0;
|
||||
for (double y : yList) {
|
||||
if (voxelShape.getBoundingBoxes()
|
||||
.stream()
|
||||
.noneMatch(boundingBox -> collides(y, boundingBox))) {
|
||||
collisionY = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return collisionY;
|
||||
}
|
||||
|
||||
private double playerCollisionMin(VoxelShape voxelShape) {
|
||||
List<Double> yList = voxelShape.getBoundingBoxes().stream()
|
||||
.flatMap(boundingBox -> Stream.of(boundingBox.getMinY(), boundingBox.getMaxY()))
|
||||
.sorted(Comparator.reverseOrder())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
double collisionY = 1.5;
|
||||
for (double y : yList) {
|
||||
if (voxelShape.getBoundingBoxes()
|
||||
.stream()
|
||||
.noneMatch(boundingBox -> collides(y - 1, boundingBox))) {
|
||||
collisionY = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return collisionY;
|
||||
}
|
||||
|
||||
private boolean collides(double y, BoundingBox boundingBox) {
|
||||
Cuboid second = new Cuboid(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getWidthX(), boundingBox.getHeight(), boundingBox.getWidthZ());
|
||||
return PLAYER_SHADOW.setY(y).intersects(second);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private static class Cuboid {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private double dx;
|
||||
private double dy;
|
||||
private double dz;
|
||||
|
||||
public boolean intersects(Cuboid cuboid) {
|
||||
double minx = x - cuboid.dx;
|
||||
double miny = y - cuboid.dy;
|
||||
double minz = z - cuboid.dz;
|
||||
double maxx = minx + dx + cuboid.dx;
|
||||
double maxy = miny + dy + cuboid.dy;
|
||||
double maxz = minz + dz + cuboid.dz;
|
||||
return maxx > cuboid.x && maxy > cuboid.y && maxz > cuboid.z && minx < cuboid.x && miny < cuboid.y && minz < cuboid.z;
|
||||
}
|
||||
|
||||
public Cuboid setY(double y) {
|
||||
return new Cuboid(x, y, z, dx, dy, dz);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(WorldCoordinate coordinate) {
|
||||
final int px = coordinate.getBlockX();
|
||||
final int py = coordinate.getBlockY();
|
||||
final int pz = coordinate.getBlockZ();
|
||||
|
||||
for (int x = -2; x <= 2; x++) {
|
||||
for (int z = -2; z <= 2; z++) {
|
||||
for (int y = fightTeam.getSchemRegion().getMinY(); y <= py + 2; y++) {
|
||||
Pos current = new Pos(px + x, y, pz + z);
|
||||
walkable.remove(current);
|
||||
calculatePosition(current, walkable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walkable.values().forEach(this::checkNeighbouring);
|
||||
}
|
||||
|
||||
private void checkNeighbouring(Pos pos) {
|
||||
for (Set<Pos> value : connections.values()) {
|
||||
value.remove(pos);
|
||||
}
|
||||
|
||||
for (Pos relative : RELATIVE_BLOCKS) {
|
||||
Pos other = walkable.get(pos.add(relative));
|
||||
if (other == null) continue;
|
||||
|
||||
Block thisBlock = Config.world.getBlockAt(pos.x, pos.y, pos.z);
|
||||
Block otherBlock = Config.world.getBlockAt(other.x, other.y, other.z);
|
||||
|
||||
if (thisBlock.getType() != Material.LADDER && otherBlock.getType() == Material.LADDER) {
|
||||
if ((relative.x != 0 || relative.z != 0) && pos.y != other.y) continue;
|
||||
} else {
|
||||
// Check if jumpable vertical distance
|
||||
if (other.floorPosition() - pos.floorPosition() > PLAYER_JUMP_HEIGHT) continue;
|
||||
// Check if Ceiling is high enough for player walking down!
|
||||
if (other.ceilingPosition() < pos.floorPosition() + PLAYER_HEIGHT) continue;
|
||||
}
|
||||
|
||||
connections.computeIfAbsent(other, __ -> new LinkedHashSet<>()).add(pos);
|
||||
}
|
||||
}
|
||||
|
||||
private Pos toPos(WorldCoordinate coordinate) {
|
||||
Pos pos = new Pos(coordinate.getBlockX(), coordinate.getBlockY(), coordinate.getBlockZ());
|
||||
if (walkable.containsKey(pos)) return walkable.get(pos);
|
||||
pos = new Pos(pos.x, pos.y - 1, pos.z);
|
||||
if (walkable.containsKey(pos)) return walkable.get(pos);
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isWalkable(WorldCoordinate coordinate) {
|
||||
Pos pos = new Pos(coordinate.getBlockX(), NumberConversions.floor(coordinate.getY() - 0.0625), coordinate.getBlockZ());
|
||||
return walkable.containsKey(pos);
|
||||
}
|
||||
|
||||
public List<WorldCoordinate> walkable() {
|
||||
return walkable.values().stream().map(Pos::toWorld).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<WorldCoordinate> pathToNearest(WorldCoordinate fromCoordinate, WorldCoordinate toCoordinate) {
|
||||
Pos to = toPos(toCoordinate);
|
||||
if (walkable.containsKey(to)) return path(toPos(fromCoordinate), to);
|
||||
|
||||
Pos closestTo = walkable.values()
|
||||
.stream()
|
||||
.filter(pos -> {
|
||||
double distance = pos.toWorld().distanceSquared(toCoordinate);
|
||||
return distance < AI.INTERACTION_RANGE * AI.INTERACTION_RANGE && distance > 1.5 * 1.5;
|
||||
})
|
||||
.min(Comparator.comparing(pos -> pos.toWorld().distanceSquared(toCoordinate)))
|
||||
.orElse(null);
|
||||
|
||||
if (closestTo == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return path(toPos(fromCoordinate), closestTo);
|
||||
}
|
||||
|
||||
public List<WorldCoordinate> path(WorldCoordinate fromCoordinate, WorldCoordinate toCoordinate) {
|
||||
Pos from = toPos(fromCoordinate);
|
||||
Pos to = toPos(toCoordinate);
|
||||
return path(from, to);
|
||||
}
|
||||
|
||||
private List<WorldCoordinate> path(Pos from, Pos to) {
|
||||
server.getEntities().forEach(REntity::die);
|
||||
|
||||
if (from == null || to == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (from.equals(to)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Pos> checking = new ArrayList<>(Arrays.asList(to));
|
||||
Map<Pos, Pos> route = new HashMap<>();
|
||||
while (!checking.isEmpty()) {
|
||||
Set<Pos> toCheck = new HashSet<>();
|
||||
for (Pos pos : checking) {
|
||||
boolean foundFrom = false;
|
||||
Set<Pos> successors = connections.get(pos);
|
||||
if (successors == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
for (Pos p : successors) {
|
||||
if (route.containsKey(p)) continue;
|
||||
route.put(p, pos);
|
||||
toCheck.add(p);
|
||||
foundFrom = p.equals(from);
|
||||
if (foundFrom) break;
|
||||
}
|
||||
|
||||
if (foundFrom) {
|
||||
List<Pos> path = new ArrayList<>();
|
||||
path.add(from);
|
||||
|
||||
while (path.get(path.size() - 1) != to) {
|
||||
path.add(route.get(path.get(path.size() - 1)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < path.size(); i++) {
|
||||
path.set(i, walkable.get(path.get(i)));
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (i < path.size() - 1) {
|
||||
Pos current = path.get(i);
|
||||
Pos next = path.get(i + 1);
|
||||
|
||||
if (current.floorPosition() > next.floorPosition() + 1) {
|
||||
Pos between = new Pos(next.x, current.y, next.z);
|
||||
between.floor = current.floor;
|
||||
path.add(i + 1, between);
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
List<WorldCoordinate> coordinates = path.stream().skip(1).map(Pos::toWorld).collect(Collectors.toList());
|
||||
coordinates.forEach(coordinate -> {
|
||||
RBlockDisplay block = new RBlockDisplay(server, coordinate.toLocation(Config.world));
|
||||
block.setBlock(PATH_BLOCK);
|
||||
block.setTransform(new Transformation(new Vector3f(0, 0, 0), new AxisAngle4f(0, 0, 0, 0), new Vector3f(1, 0.001F, 1), new AxisAngle4f(0, 0, 0, 0)));
|
||||
});
|
||||
|
||||
coordinates.forEach(vector -> vector.add(0.5, 0, 0.5));
|
||||
return coordinates;
|
||||
}
|
||||
}
|
||||
|
||||
checking.clear();
|
||||
checking.addAll(toCheck);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.utils.Region;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class WorldCoordinate {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public static WorldCoordinate from(Location location) {
|
||||
return new WorldCoordinate(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public static WorldCoordinate from(Vector vector) {
|
||||
return new WorldCoordinate(vector.getX(), vector.getY(), vector.getZ());
|
||||
}
|
||||
|
||||
public int getBlockX() {
|
||||
return NumberConversions.floor(x);
|
||||
}
|
||||
|
||||
public int getBlockY() {
|
||||
return NumberConversions.floor(y);
|
||||
}
|
||||
|
||||
public int getBlockZ() {
|
||||
return NumberConversions.floor(z);
|
||||
}
|
||||
|
||||
public double distanceSquared(WorldCoordinate coordinate) {
|
||||
return NumberConversions.square(x - coordinate.x) + NumberConversions.square(y - coordinate.y) + NumberConversions.square(z - coordinate.z);
|
||||
}
|
||||
|
||||
public LocalCoordinate toLocal(FightTeam team) {
|
||||
// TODO: Fix the of by one blue/red
|
||||
Region extend = team.getExtendRegion();
|
||||
if (Fight.getUnrotated() == team) {
|
||||
return new LocalCoordinate(
|
||||
x - extend.getMinX(),
|
||||
y - team.getSchemRegion().getMinY(),
|
||||
z - extend.getMinZ()
|
||||
);
|
||||
} else {
|
||||
return new LocalCoordinate(
|
||||
extend.getMaxX() - x + 1,
|
||||
y - team.getSchemRegion().getMinY(),
|
||||
extend.getMaxZ() - z + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public WorldCoordinate add(WorldCoordinate worldCoordinate) {
|
||||
this.x += worldCoordinate.x;
|
||||
this.y += worldCoordinate.y;
|
||||
this.z += worldCoordinate.z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WorldCoordinate add(double x, double y, double z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector toVector() {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public Location toLocation(World world) {
|
||||
return new Location(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "World{" + x + "," + y + "," + z + "}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai.schematic;
|
||||
|
||||
import de.steamwar.fightsystem.ai.LocalCoordinate;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
public class Bridge {
|
||||
|
||||
private final Set<LocalCoordinate> shieldActivators = new HashSet<>();
|
||||
private LocalCoordinate automaticActivator = null;
|
||||
private int automaticActivatorTime = 0;
|
||||
|
||||
public Bridge addShieldActivator(LocalCoordinate shieldActivator) {
|
||||
this.shieldActivators.add(shieldActivator);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Bridge addAutomaticActivator(LocalCoordinate automaticActivator, int automaticActivatorTime) {
|
||||
this.automaticActivator = automaticActivator;
|
||||
this.automaticActivatorTime = automaticActivatorTime;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai.schematic;
|
||||
|
||||
import de.steamwar.fightsystem.ai.LocalCoordinate;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
public class Cannon {
|
||||
|
||||
private final List<LocalCoordinate> tntPositions = new ArrayList<>();
|
||||
private final Set<LocalCoordinate> triggerPositions = new HashSet<>();
|
||||
|
||||
public Cannon addTnt(LocalCoordinate tnt) {
|
||||
tntPositions.add(tnt);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Cannon addTrigger(LocalCoordinate trigger) {
|
||||
triggerPositions.add(trigger);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai.schematic;
|
||||
|
||||
import de.steamwar.fightsystem.ai.LocalCoordinate;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class WarMachine {
|
||||
|
||||
private int schematicId = 0;
|
||||
private Bridge bridge = new Bridge();
|
||||
private List<Cannon> cannons = new ArrayList<>();
|
||||
private List<LocalCoordinate> tntChests = new ArrayList<>();
|
||||
|
||||
public WarMachine setSchematicId(int schematicId) {
|
||||
this.schematicId = schematicId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public WarMachine editBridge(Consumer<Bridge> initializer) {
|
||||
initializer.accept(bridge);
|
||||
return this;
|
||||
}
|
||||
|
||||
public WarMachine addCannon(Consumer<Cannon> initializer) {
|
||||
Cannon cannon = new Cannon();
|
||||
initializer.accept(cannon);
|
||||
cannons.add(cannon);
|
||||
return this;
|
||||
}
|
||||
|
||||
public WarMachine addTnTChest(LocalCoordinate chest) {
|
||||
tntChests.add(chest);
|
||||
return this;
|
||||
}
|
||||
|
||||
public WarMachine finish(List<WarMachine> list) {
|
||||
list.add(this);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai.schematic.impl;
|
||||
|
||||
import de.steamwar.fightsystem.ai.LocalCoordinate;
|
||||
import de.steamwar.fightsystem.ai.schematic.WarMachine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class MiniWarGear20 {
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
private static final List<WarMachine> MiniWarGear20 = new ArrayList<>();
|
||||
|
||||
public static WarMachine select() {
|
||||
return MiniWarGear20.get(RANDOM.nextInt(MiniWarGear20.size()));
|
||||
}
|
||||
|
||||
public static WarMachine select(int schematicId) {
|
||||
return MiniWarGear20.stream()
|
||||
.filter(warMachine -> warMachine.getSchematicId() == schematicId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static final WarMachine DPR_PV1_Reaper = new WarMachine()
|
||||
.setSchematicId(135745)
|
||||
.editBridge(bridge -> {
|
||||
bridge.addShieldActivator(new LocalCoordinate(22, 15, 18));
|
||||
bridge.addShieldActivator(new LocalCoordinate(31, 3, 12));
|
||||
bridge.addShieldActivator(new LocalCoordinate(19, 3, 12));
|
||||
})
|
||||
.addCannon(cannon -> {
|
||||
cannon.addTnt(new LocalCoordinate(29, 1, 21));
|
||||
cannon.addTnt(new LocalCoordinate(29, 1, 22));
|
||||
cannon.addTnt(new LocalCoordinate(29, 1, 23));
|
||||
cannon.addTnt(new LocalCoordinate(30, 1, 22));
|
||||
cannon.addTnt(new LocalCoordinate(30, 1, 23));
|
||||
cannon.addTnt(new LocalCoordinate(29, 2, 24));
|
||||
cannon.addTnt(new LocalCoordinate(30, 2, 24));
|
||||
cannon.addTnt(new LocalCoordinate(29, 2, 25));
|
||||
cannon.addTnt(new LocalCoordinate(30, 2, 25));
|
||||
cannon.addTnt(new LocalCoordinate(29, 3, 24));
|
||||
cannon.addTnt(new LocalCoordinate(30, 3, 24));
|
||||
cannon.addTnt(new LocalCoordinate(29, 3, 25));
|
||||
cannon.addTnt(new LocalCoordinate(30, 3, 25));
|
||||
cannon.addTrigger(new LocalCoordinate(30, 3, 19));
|
||||
cannon.addTrigger(new LocalCoordinate(31, 3, 18));
|
||||
cannon.addTrigger(new LocalCoordinate(31, 3, 20));
|
||||
})
|
||||
.finish(MiniWarGear20);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.ai.yoyonow;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import de.steamwar.fightsystem.ai.AI;
|
||||
import de.steamwar.fightsystem.ai.Action;
|
||||
import de.steamwar.fightsystem.ai.schematic.Cannon;
|
||||
import de.steamwar.fightsystem.ai.schematic.WarMachine;
|
||||
import de.steamwar.fightsystem.ai.schematic.impl.MiniWarGear20;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class YoyoNowAI extends AI {
|
||||
|
||||
private WarMachine selectedSchematic;
|
||||
|
||||
protected YoyoNowAI(FightTeam team) {
|
||||
super(team, SteamwarUser.get("YoyoNow.AI"));
|
||||
getEntity().setGlowing(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchematicNode chooseSchematic() {
|
||||
selectedSchematic = MiniWarGear20.select();
|
||||
return SchematicNode.getSchematicNode(selectedSchematic.getSchematicId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schematic(Clipboard clipboard) {
|
||||
selectedSchematic = MiniWarGear20.select(team.getSchematic());
|
||||
if (selectedSchematic == null) stop();
|
||||
}
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
private List<Action> actions = new ArrayList<>();
|
||||
|
||||
private boolean setupDone = false;
|
||||
|
||||
@Override
|
||||
protected void plan() {
|
||||
if (!navMesh.isReady()) return;
|
||||
|
||||
if (!actions.isEmpty()) {
|
||||
Action.Result result = actions.get(0).step(this);
|
||||
if (result == Action.Result.FAILED) {
|
||||
chat(actions.get(0) + " failed");
|
||||
actions.clear();
|
||||
return;
|
||||
}
|
||||
if (result == Action.Result.FINISHED) {
|
||||
chat(actions.get(0) + " finished");
|
||||
actions.remove(0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!setupDone && FightState.getFightState() == FightState.POST_SCHEM_SETUP) {
|
||||
chat("Setup actions to perform!");
|
||||
selectedSchematic.getBridge().getShieldActivators().forEach(localCoordinate -> {
|
||||
actions.add(new Action.MoveAction(this, localCoordinate.toWorld(getTeam())));
|
||||
actions.add(new Action.InteractAction(localCoordinate));
|
||||
});
|
||||
actions.add(new Action.ReadyAction());
|
||||
chat("Actions: " + actions.size());
|
||||
setupDone = true;
|
||||
}
|
||||
|
||||
if (FightState.getFightState() == FightState.RUNNING) {
|
||||
Cannon cannon = selectedSchematic.getCannons().get(random.nextInt(selectedSchematic.getCannons().size()));
|
||||
actions.add(new Action.LoadCannon(this, cannon));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,3 +92,13 @@ tasks.register<FightServer>("QuickGear20") {
|
||||
worldName = "arenas/WarGearPark"
|
||||
config = "QuickGear20.yml"
|
||||
}
|
||||
|
||||
tasks.register<FightServer>("MiniWarGear20") {
|
||||
group = "run"
|
||||
description = "Run a MiniWarGear 1.20 Fight Server"
|
||||
dependsOn(":SpigotCore:shadowJar")
|
||||
dependsOn(":FightSystem:shadowJar")
|
||||
template = "MiniWarGear20"
|
||||
worldName = "arenas/NightTown"
|
||||
config = "MiniWarGear20.yml"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user