Compare commits
3 Commits
develop
...
develop-fa
Author | SHA1 | Date | |
---|---|---|---|
ae59482d7c | |||
123c01da14 | |||
e871c0bcb5 |
@@ -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"), 7, 10, 13, 16, 19));
|
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 5, 7, 9, 11));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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(configuration.get("length").getAsInt()).setParent(parent);
|
return new Stickfight().setParent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,14 +18,12 @@ 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;
|
private final double radius = 20;
|
||||||
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(int length) {
|
public Stickfight() {
|
||||||
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()
|
||||||
@@ -36,7 +34,6 @@ 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);
|
||||||
});
|
});
|
||||||
@@ -46,26 +43,14 @@ public class Stickfight extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
this.replaceCircle(Block.SANDSTONE);
|
setBlock(0, 50, 0, Block.DIAMOND_BLOCK);
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
||||||
@@ -102,8 +87,7 @@ 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)) {
|
||||||
if(playerMoveEvent.getNewPosition().y() < 45) player.teleport(this.getSpawn());
|
playerMoveEvent.setCancelled(true);
|
||||||
if(this.countdownStarted) playerMoveEvent.setCancelled(true);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,12 +3,25 @@ package eu.mhsl.minenet.minigames.score;
|
|||||||
import eu.mhsl.minenet.minigames.util.MapUtil;
|
import eu.mhsl.minenet.minigames.util.MapUtil;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class LowestPointsWinScore extends PointsWinScore {
|
public class LowestPointsWinScore extends PointsWinScore {
|
||||||
@Override
|
@Override
|
||||||
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
||||||
this.scoreOrder.put(p, currentPoints);
|
Set<Player> combined = scoreOrder.entrySet().stream()
|
||||||
|
.filter(entrySet -> Objects.equals(entrySet.getValue(), currentPoints))
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(() -> {
|
||||||
|
Set<Player> s = new HashSet<>();
|
||||||
|
scoreOrder.put(s, currentPoints);
|
||||||
|
return s;
|
||||||
|
});
|
||||||
|
combined.addAll(p);
|
||||||
|
|
||||||
this.scoreOrder = MapUtil.sortReversedByValue(this.scoreOrder);
|
this.scoreOrder = MapUtil.sortReversedByValue(this.scoreOrder);
|
||||||
getScores().clear();
|
getScores().clear();
|
||||||
this.scoreOrder.forEach((player, integer) -> getScores().addFirst(player));
|
this.scoreOrder.forEach((player, integer) -> getScores().addFirst(player));
|
||||||
|
@@ -16,7 +16,17 @@ public class PointsWinScore extends Score {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
||||||
this.scoreOrder.put(p, currentPoints);
|
Set<Player> combined = scoreOrder.entrySet().stream()
|
||||||
|
.filter(entrySet -> Objects.equals(entrySet.getValue(), currentPoints))
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(() -> {
|
||||||
|
Set<Player> s = new HashSet<>();
|
||||||
|
scoreOrder.put(s, currentPoints);
|
||||||
|
return s;
|
||||||
|
});
|
||||||
|
combined.addAll(p);
|
||||||
|
|
||||||
this.scoreOrder = MapUtil.sortByValue(this.scoreOrder);
|
this.scoreOrder = MapUtil.sortByValue(this.scoreOrder);
|
||||||
getScores().clear();
|
getScores().clear();
|
||||||
this.scoreOrder.forEach((player, integer) -> getScores().addFirst(player));
|
this.scoreOrder.forEach((player, integer) -> getScores().addFirst(player));
|
||||||
@@ -42,13 +52,12 @@ public class PointsWinScore extends Score {
|
|||||||
.filter(player -> !player.getUsername().isBlank())
|
.filter(player -> !player.getUsername().isBlank())
|
||||||
.toList()
|
.toList()
|
||||||
.isEmpty())
|
.isEmpty())
|
||||||
.map(players -> players
|
.map(players -> players.stream()
|
||||||
.stream()
|
.map(Player::getUsername)
|
||||||
.filter(player -> scoreOrder.get(Set.of(player)) != null)
|
.sorted()
|
||||||
.map(player -> player.getUsername()+" : "+scoreOrder.get(Set.of(player)).toString())
|
.collect(Collectors.joining(", "))
|
||||||
.collect(Collectors.joining(", "))
|
+ " : " + scoreOrder.get(players)
|
||||||
)
|
).toList()
|
||||||
.toList()
|
|
||||||
)
|
)
|
||||||
.undent()
|
.undent()
|
||||||
.newLine()
|
.newLine()
|
||||||
|
@@ -4,6 +4,7 @@ import eu.mhsl.minenet.minigames.score.Score;
|
|||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Tournament {
|
public class Tournament {
|
||||||
private final List<Score> gameScores = new ArrayList<>();
|
private final List<Score> gameScores = new ArrayList<>();
|
||||||
@@ -43,9 +44,11 @@ public class Tournament {
|
|||||||
public Rewards getRewards() {
|
public Rewards getRewards() {
|
||||||
Map<UUID, Integer> itemCount = new HashMap<>();
|
Map<UUID, Integer> itemCount = new HashMap<>();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Player player : getPlaces()) {
|
for (Set<Player> players : getPlaces()) {
|
||||||
if(count >= this.rewardConfiguration.rewardCount().size()) break;
|
if(count >= this.rewardConfiguration.rewardCount().size()) break;
|
||||||
itemCount.put(player.getUuid(), this.rewardConfiguration.rewardCount().get(count));
|
for(Player player : players) {
|
||||||
|
itemCount.put(player.getUuid(), this.rewardConfiguration.rewardCount().get(count));
|
||||||
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,18 +56,21 @@ public class Tournament {
|
|||||||
this.memorialConfiguration.memorialMaterial().namespace().value(),
|
this.memorialConfiguration.memorialMaterial().namespace().value(),
|
||||||
this.memorialConfiguration.memorialTitle(),
|
this.memorialConfiguration.memorialTitle(),
|
||||||
this.memorialConfiguration.memorialLore(),
|
this.memorialConfiguration.memorialLore(),
|
||||||
getPlaces().stream().map(Player::getUuid).toList(),
|
getGameScores().keySet().stream().map(Player::getUuid).toList(),
|
||||||
this.rewardConfiguration.item().namespace().value(),
|
this.rewardConfiguration.item().namespace().value(),
|
||||||
itemCount
|
itemCount
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Player> getPlaces() {
|
public List<Set<Player>> getPlaces() {
|
||||||
List<Player> players = new ArrayList<>(
|
List<Set<Player>> players = new ArrayList<>(
|
||||||
getGameScores().entrySet().stream()
|
getGameScores().entrySet().stream()
|
||||||
.sorted(Map.Entry.comparingByValue())
|
.collect(
|
||||||
.map(Map.Entry::getKey)
|
Collectors.groupingBy(
|
||||||
.toList()
|
Map.Entry::getValue,
|
||||||
|
Collectors.mapping(Map.Entry::getKey, Collectors.toSet())
|
||||||
|
)
|
||||||
|
).values()
|
||||||
);
|
);
|
||||||
|
|
||||||
Collections.reverse(players);
|
Collections.reverse(players);
|
||||||
|
@@ -12,10 +12,12 @@ import net.minestom.server.entity.*;
|
|||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
import net.minestom.server.instance.anvil.AnvilLoader;
|
import net.minestom.server.instance.anvil.AnvilLoader;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class TournamentDisplay extends MineNetInstance implements Spawnable {
|
public class TournamentDisplay extends MineNetInstance implements Spawnable {
|
||||||
private final List<Player> places;
|
private final List<Set<Player>> places;
|
||||||
private final Tournament tournament;
|
private final Tournament tournament;
|
||||||
|
|
||||||
private final Pos[] placePositions = new Pos[] {
|
private final Pos[] placePositions = new Pos[] {
|
||||||
@@ -30,7 +32,7 @@ public class TournamentDisplay extends MineNetInstance implements Spawnable {
|
|||||||
this.places = tournament.getPlaces();
|
this.places = tournament.getPlaces();
|
||||||
this.tournament = tournament;
|
this.tournament = tournament;
|
||||||
|
|
||||||
this.places.forEach(player -> player.setGameMode(GameMode.ADVENTURE));
|
this.places.forEach(players -> players.forEach(player -> player.setGameMode(GameMode.ADVENTURE)));
|
||||||
|
|
||||||
eventNode().addListener(PlayerMoveEvent.class, playerMoveEvent -> {
|
eventNode().addListener(PlayerMoveEvent.class, playerMoveEvent -> {
|
||||||
if(isOnDisplay(playerMoveEvent.getPlayer()) && !playerMoveEvent.getNewPosition().sameBlock(placePositions[getRankPosition(playerMoveEvent.getPlayer())])) {
|
if(isOnDisplay(playerMoveEvent.getPlayer()) && !playerMoveEvent.getNewPosition().sameBlock(placePositions[getRankPosition(playerMoveEvent.getPlayer())])) {
|
||||||
@@ -45,7 +47,10 @@ public class TournamentDisplay extends MineNetInstance implements Spawnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getRankPosition(Player player) {
|
private int getRankPosition(Player player) {
|
||||||
return this.places.indexOf(player);
|
for (int i = 0; i < places.size(); i++) {
|
||||||
|
if (places.get(i).contains(player)) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,8 +61,11 @@ public class TournamentDisplay extends MineNetInstance implements Spawnable {
|
|||||||
p.teleport(placePositions[getRankPosition(p)]);
|
p.teleport(placePositions[getRankPosition(p)]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
List<Player> players = this.places.stream()
|
||||||
|
.flatMap(s -> s.stream().sorted(Comparator.comparing(Player::getUsername)))
|
||||||
|
.toList();
|
||||||
new ChatMessage(Icon.STAR)
|
new ChatMessage(Icon.STAR)
|
||||||
.numberedList(this.places.stream().map(player -> String.format("%s - %s Punkte", player.getUsername(), tournament.getGameScores().get(player))).toList())
|
.list(players.stream().map(player -> String.format("%d. %s - %s Punkte", this.getRankPosition(player)+1, player.getUsername(), tournament.getGameScores().get(player))).toList())
|
||||||
.send(p);
|
.send(p);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ public enum BlockPallet {
|
|||||||
STONE(new Block[] {Block.CHISELED_STONE_BRICKS, Block.STONE_BRICKS, Block.POLISHED_ANDESITE, Block.POLISHED_BLACKSTONE, Block.POLISHED_DIORITE}),
|
STONE(new Block[] {Block.CHISELED_STONE_BRICKS, Block.STONE_BRICKS, Block.POLISHED_ANDESITE, Block.POLISHED_BLACKSTONE, Block.POLISHED_DIORITE}),
|
||||||
WINTER(new Block[] {Block.SNOW_BLOCK, Block.ICE, Block.PACKED_ICE, Block.BLUE_CONCRETE, Block.SEA_LANTERN}),
|
WINTER(new Block[] {Block.SNOW_BLOCK, Block.ICE, Block.PACKED_ICE, Block.BLUE_CONCRETE, Block.SEA_LANTERN}),
|
||||||
STREET(new Block[] {Block.BLACK_CONCRETE_POWDER, Block.GRAY_CONCRETE_POWDER, Block.GRAVEL, Block.BLACK_CONCRETE, Block.GRAY_CONCRETE}),
|
STREET(new Block[] {Block.BLACK_CONCRETE_POWDER, Block.GRAY_CONCRETE_POWDER, Block.GRAVEL, Block.BLACK_CONCRETE, Block.GRAY_CONCRETE}),
|
||||||
FLOWER(new Block[] {Block.ORANGE_TULIP, Block.PINK_TULIP, Block.RED_TULIP, Block.WHITE_TULIP, Block.DANDELION, Block.POPPY, Block.CORNFLOWER}),
|
FLOWER(new Block[] {Block.ORANGE_TULIP, Block.PINK_TULIP, Block.RED_TULIP, Block.WHITE_TULIP}),
|
||||||
PRESSURE_PLATES(new Block[] {Block.ACACIA_PRESSURE_PLATE, Block.BIRCH_PRESSURE_PLATE, Block.CRIMSON_PRESSURE_PLATE, Block.JUNGLE_PRESSURE_PLATE, Block.OAK_PRESSURE_PLATE, Block.DARK_OAK_PRESSURE_PLATE, Block.HEAVY_WEIGHTED_PRESSURE_PLATE, Block.HEAVY_WEIGHTED_PRESSURE_PLATE, Block.POLISHED_BLACKSTONE_PRESSURE_PLATE, Block.SPRUCE_PRESSURE_PLATE, Block.STONE_PRESSURE_PLATE, Block.WARPED_PRESSURE_PLATE});
|
PRESSURE_PLATES(new Block[] {Block.ACACIA_PRESSURE_PLATE, Block.BIRCH_PRESSURE_PLATE, Block.CRIMSON_PRESSURE_PLATE, Block.JUNGLE_PRESSURE_PLATE, Block.OAK_PRESSURE_PLATE, Block.DARK_OAK_PRESSURE_PLATE, Block.HEAVY_WEIGHTED_PRESSURE_PLATE, Block.HEAVY_WEIGHTED_PRESSURE_PLATE, Block.POLISHED_BLACKSTONE_PRESSURE_PLATE, Block.SPRUCE_PRESSURE_PLATE, Block.STONE_PRESSURE_PLATE, Block.WARPED_PRESSURE_PLATE});
|
||||||
|
|
||||||
final List<Block> list;
|
final List<Block> list;
|
||||||
|
@@ -55,19 +55,7 @@ public class HeightTerrainGenerator extends BaseGenerator {
|
|||||||
synchronized (batches) {
|
synchronized (batches) {
|
||||||
double batchNoise = batches.getNoise(bottomPoint.x(), bottomPoint.z());
|
double batchNoise = batches.getNoise(bottomPoint.x(), bottomPoint.z());
|
||||||
|
|
||||||
Block block = batchNoise < 0.9 ? batchNoise > -0.2 ? Block.GRASS_BLOCK : Block.SOUL_SAND : Block.STONE;
|
unit.modifier().fill(bottomPoint, bottomPoint.add(1, heightModifier, 1), batchNoise < 0.9 ? batchNoise > 0 ? Block.GRASS_BLOCK : Block.SOUL_SAND : Block.STONE);
|
||||||
unit.modifier().fill(bottomPoint, bottomPoint.add(1, heightModifier, 1), block);
|
|
||||||
if(rnd.nextInt(0, 5) < 1 && block == Block.GRASS_BLOCK) {
|
|
||||||
int randomInt = rnd.nextInt(0, 6);
|
|
||||||
if(randomInt > 1) {
|
|
||||||
unit.modifier().setBlock(bottomPoint.add(0, heightModifier, 0), Block.SHORT_GRASS);
|
|
||||||
} else if(randomInt > 0) {
|
|
||||||
unit.modifier().setBlock(bottomPoint.add(0, heightModifier, 0), BlockPallet.FLOWER.rnd());
|
|
||||||
} else {
|
|
||||||
unit.modifier().setBlock(bottomPoint.add(0, heightModifier, 0), Block.TALL_GRASS);
|
|
||||||
unit.modifier().setBlock(bottomPoint.add(0, heightModifier+1, 0), Block.TALL_GRASS.withProperty("half", "upper"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(calculateSeaLevel != null) {
|
if(calculateSeaLevel != null) {
|
||||||
Point absoluteHeight = bottomPoint.add(0, heightModifier, 0);
|
Point absoluteHeight = bottomPoint.add(0, heightModifier, 0);
|
||||||
|
Reference in New Issue
Block a user