added stickfight start and working length option
This commit is contained in:
@@ -28,7 +28,7 @@ public class StickFightFactory implements GameFactory {
|
||||
@Override
|
||||
public ConfigManager configuration() {
|
||||
return new ConfigManager()
|
||||
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 5, 7, 9, 11));
|
||||
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 7, 10, 13, 16, 19));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,7 +40,7 @@ public class StickFightFactory implements GameFactory {
|
||||
|
||||
@Override
|
||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
|
||||
return new Stickfight().setParent(parent);
|
||||
return new Stickfight(configuration.get("length").getAsInt()).setParent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,12 +18,14 @@ import java.util.WeakHashMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class Stickfight extends StatelessGame {
|
||||
private final double radius = 20;
|
||||
private final double radius;
|
||||
private final WeakHashMap<Player, Pos> spawnPoints = new WeakHashMap<>();
|
||||
private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
|
||||
private boolean countdownStarted = false;
|
||||
|
||||
public Stickfight() {
|
||||
public Stickfight(int length) {
|
||||
super(Dimension.OVERWORLD.key, "Stickfight", new LowestPointsWinScore());
|
||||
this.radius = length;
|
||||
|
||||
eventNode().addChild(
|
||||
CombatFeatures.empty()
|
||||
@@ -34,6 +36,7 @@ public class Stickfight extends StatelessGame {
|
||||
);
|
||||
|
||||
eventNode().addListener(FinalAttackEvent.class, finalAttackEvent -> {
|
||||
if(isBeforeBeginning) finalAttackEvent.setCancelled(true);
|
||||
finalAttackEvent.setBaseDamage(0);
|
||||
((Player) finalAttackEvent.getTarget()).setHealth(20);
|
||||
});
|
||||
@@ -43,14 +46,26 @@ public class Stickfight extends StatelessGame {
|
||||
|
||||
@Override
|
||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||
setBlock(0, 50, 0, Block.DIAMOND_BLOCK);
|
||||
this.replaceCircle(Block.SANDSTONE);
|
||||
}
|
||||
|
||||
private void replaceCircle(Block block) {
|
||||
int radius = 8;
|
||||
for (int x = -radius; x <= radius; x++) {
|
||||
for (int z = -radius; z <= radius; z++) {
|
||||
Pos blockPosition = this.getSpawn().add(x, -1, z);
|
||||
if(blockPosition.distance(this.getSpawn().sub(0, 1, 0)) <= radius) this.setBlock(blockPosition, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void start() {
|
||||
List<Player> players = getPlayers().stream().toList();
|
||||
int numPlayers = players.size();
|
||||
this.countdownStarted = true;
|
||||
|
||||
this.replaceCircle(Block.AIR);
|
||||
for (int i = 0; i < numPlayers; i++) {
|
||||
double angle = (2 * Math.PI / numPlayers) * i;
|
||||
int spawnX = (int) (radius * Math.cos(angle));
|
||||
@@ -87,7 +102,8 @@ public class Stickfight extends StatelessGame {
|
||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||
Player player = playerMoveEvent.getPlayer();
|
||||
if(!spawnPoints.containsKey(player)) {
|
||||
playerMoveEvent.setCancelled(true);
|
||||
if(playerMoveEvent.getNewPosition().y() < 45) player.teleport(this.getSpawn());
|
||||
if(this.countdownStarted) playerMoveEvent.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user