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