forked from SteamWar/SteamWar
Fix Action.MoveAction
Fix NavMesh.isWalkable
This commit is contained in:
@@ -64,9 +64,17 @@ public interface Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AI.MoveResult moveResult = ai.checkMove(coordinate);
|
AI.MoveResult moveResult = ai.checkMove(coordinate);
|
||||||
if (moveResult == AI.MoveResult.OVERDISTANCE && overDistanceCounter++ > 5) {
|
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.FAILED;
|
||||||
}
|
}
|
||||||
|
return Result.ONGOING;
|
||||||
|
}
|
||||||
|
overDistanceCounter = 0;
|
||||||
|
|
||||||
if (moveResult == AI.MoveResult.FALLING) {
|
if (moveResult == AI.MoveResult.FALLING) {
|
||||||
return Result.ONGOING;
|
return Result.ONGOING;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import de.steamwar.entity.RBlockDisplay;
|
|||||||
import de.steamwar.entity.REntity;
|
import de.steamwar.entity.REntity;
|
||||||
import de.steamwar.entity.REntityServer;
|
import de.steamwar.entity.REntityServer;
|
||||||
import de.steamwar.fightsystem.ArenaMode;
|
import de.steamwar.fightsystem.ArenaMode;
|
||||||
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.FightSystem;
|
import de.steamwar.fightsystem.FightSystem;
|
||||||
import de.steamwar.fightsystem.fight.FightTeam;
|
import de.steamwar.fightsystem.fight.FightTeam;
|
||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
@@ -32,12 +33,11 @@ import lombok.Getter;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
import org.bukkit.util.BoundingBox;
|
import org.bukkit.util.BoundingBox;
|
||||||
|
import org.bukkit.util.NumberConversions;
|
||||||
import org.bukkit.util.Transformation;
|
import org.bukkit.util.Transformation;
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
import org.bukkit.util.VoxelShape;
|
import org.bukkit.util.VoxelShape;
|
||||||
import org.joml.AxisAngle4f;
|
import org.joml.AxisAngle4f;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
@@ -48,7 +48,6 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class NavMesh {
|
public class NavMesh {
|
||||||
|
|
||||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
|
||||||
private static final double PLAYER_FALL_DISTANCE = 3;
|
private static final double PLAYER_FALL_DISTANCE = 3;
|
||||||
private static final double PLAYER_JUMP_HEIGHT = 1.25;
|
private static final double PLAYER_JUMP_HEIGHT = 1.25;
|
||||||
private static final double PLAYER_HEIGHT = 1.8;
|
private static final double PLAYER_HEIGHT = 1.8;
|
||||||
@@ -103,7 +102,7 @@ public class NavMesh {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void calculatePosition(Pos pos, Map<Pos, Pos> walkable) {
|
private void calculatePosition(Pos pos, Map<Pos, Pos> walkable) {
|
||||||
Block block = WORLD.getBlockAt(pos.x, pos.y, pos.z);
|
Block block = Config.world.getBlockAt(pos.x, pos.y, pos.z);
|
||||||
// Air is not walkable
|
// Air is not walkable
|
||||||
if (block.isPassable()) return;
|
if (block.isPassable()) return;
|
||||||
|
|
||||||
@@ -120,7 +119,7 @@ public class NavMesh {
|
|||||||
// Ceiling Position
|
// Ceiling Position
|
||||||
pos.ceiling = fightTeam.getExtendRegion().getMaxY() - pos.y;
|
pos.ceiling = fightTeam.getExtendRegion().getMaxY() - pos.y;
|
||||||
for (int y = pos.y + 1; y <= fightTeam.getExtendRegion().getMaxY() + 3; y++) {
|
for (int y = pos.y + 1; y <= fightTeam.getExtendRegion().getMaxY() + 3; y++) {
|
||||||
block = WORLD.getBlockAt(pos.x, y, pos.z);
|
block = Config.world.getBlockAt(pos.x, y, pos.z);
|
||||||
if (block.isPassable()) continue;
|
if (block.isPassable()) continue;
|
||||||
double min = playerCollisionMin(block.getCollisionShape());
|
double min = playerCollisionMin(block.getCollisionShape());
|
||||||
if (min >= 1.0) continue;
|
if (min >= 1.0) continue;
|
||||||
@@ -244,13 +243,14 @@ public class NavMesh {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(WorldCoordinate coordinate) {
|
public void update(WorldCoordinate coordinate) {
|
||||||
Pos pos = toPos(coordinate);
|
final int px = coordinate.getBlockX();
|
||||||
if (pos == null) return;
|
final int py = coordinate.getBlockY();
|
||||||
|
final int pz = coordinate.getBlockZ();
|
||||||
|
|
||||||
for (int x = -2; x <= 2; x++) {
|
for (int x = -2; x <= 2; x++) {
|
||||||
for (int z = -2; z <= 2; z++) {
|
for (int z = -2; z <= 2; z++) {
|
||||||
for (int y = fightTeam.getSchemRegion().getMinY(); y <= pos.y + 2; y++) {
|
for (int y = fightTeam.getSchemRegion().getMinY(); y <= py + 2; y++) {
|
||||||
Pos current = new Pos(pos.x + x, y, pos.z + z);
|
Pos current = new Pos(px + x, y, pz + z);
|
||||||
walkable.remove(current);
|
walkable.remove(current);
|
||||||
calculatePosition(current, walkable);
|
calculatePosition(current, walkable);
|
||||||
}
|
}
|
||||||
@@ -269,8 +269,8 @@ public class NavMesh {
|
|||||||
Pos other = walkable.get(pos.add(relative));
|
Pos other = walkable.get(pos.add(relative));
|
||||||
if (other == null) continue;
|
if (other == null) continue;
|
||||||
|
|
||||||
Block thisBlock = WORLD.getBlockAt(pos.x, pos.y, pos.z);
|
Block thisBlock = Config.world.getBlockAt(pos.x, pos.y, pos.z);
|
||||||
Block otherBlock = WORLD.getBlockAt(other.x, other.y, other.z);
|
Block otherBlock = Config.world.getBlockAt(other.x, other.y, other.z);
|
||||||
|
|
||||||
if (thisBlock.getType() != Material.LADDER && otherBlock.getType() == Material.LADDER) {
|
if (thisBlock.getType() != Material.LADDER && otherBlock.getType() == Material.LADDER) {
|
||||||
if ((relative.x != 0 || relative.z != 0) && pos.y != other.y) continue;
|
if ((relative.x != 0 || relative.z != 0) && pos.y != other.y) continue;
|
||||||
@@ -294,7 +294,7 @@ public class NavMesh {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWalkable(WorldCoordinate coordinate) {
|
public boolean isWalkable(WorldCoordinate coordinate) {
|
||||||
Pos pos = new Pos(coordinate.getBlockX(), coordinate.getBlockY(), coordinate.getBlockZ());
|
Pos pos = new Pos(coordinate.getBlockX(), NumberConversions.floor(coordinate.getY() - 0.0625), coordinate.getBlockZ());
|
||||||
return walkable.containsKey(pos);
|
return walkable.containsKey(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +376,7 @@ public class NavMesh {
|
|||||||
|
|
||||||
List<WorldCoordinate> coordinates = path.stream().skip(1).map(Pos::toWorld).collect(Collectors.toList());
|
List<WorldCoordinate> coordinates = path.stream().skip(1).map(Pos::toWorld).collect(Collectors.toList());
|
||||||
coordinates.forEach(coordinate -> {
|
coordinates.forEach(coordinate -> {
|
||||||
RBlockDisplay block = new RBlockDisplay(server, coordinate.toLocation(WORLD));
|
RBlockDisplay block = new RBlockDisplay(server, coordinate.toLocation(Config.world));
|
||||||
block.setBlock(PATH_BLOCK);
|
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)));
|
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)));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ public class YoyoNowAI extends AI {
|
|||||||
WorldCoordinate destination = walkable.get(random.nextInt(walkable.size()));
|
WorldCoordinate destination = walkable.get(random.nextInt(walkable.size()));
|
||||||
Action action = new Action.MoveAction(this, destination);
|
Action action = new Action.MoveAction(this, destination);
|
||||||
if (!action.isCompletable()) return;
|
if (!action.isCompletable()) return;
|
||||||
chat("Now moving to: " + destination);
|
|
||||||
actions.add(action);
|
actions.add(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user