added LowestPointsWinScore and Stickfight win condition
This commit is contained in:
@@ -2,7 +2,7 @@ package eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight;
|
|||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
import eu.mhsl.minenet.minigames.score.LowestPointsWinScore;
|
||||||
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
import eu.mhsl.minenet.minigames.world.generator.terrain.CircularPlateTerrainGenerator;
|
||||||
import io.github.togar2.pvp.events.FinalAttackEvent;
|
import io.github.togar2.pvp.events.FinalAttackEvent;
|
||||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||||
@@ -13,15 +13,17 @@ import net.minestom.server.instance.block.Block;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
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 = 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<>();
|
||||||
|
|
||||||
public Stickfight() {
|
public Stickfight() {
|
||||||
super(Dimension.OVERWORLD.key, "Stickfight", new LastWinsScore());
|
super(Dimension.OVERWORLD.key, "Stickfight", new LowestPointsWinScore());
|
||||||
|
|
||||||
eventNode().addChild(
|
eventNode().addChild(
|
||||||
CombatFeatures.empty()
|
CombatFeatures.empty()
|
||||||
@@ -66,6 +68,11 @@ public class Stickfight extends StatelessGame {
|
|||||||
super.start();
|
super.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
this.scoreMap.forEach((player, score) -> getScore().insertResult(player, score));
|
||||||
|
}
|
||||||
|
|
||||||
private void generateBridge(int startX, int startY, int startZ) {
|
private void generateBridge(int startX, int startY, int startZ) {
|
||||||
int steps = (int) (radius * 1.5);
|
int steps = (int) (radius * 1.5);
|
||||||
for (int i = 0; i < steps; i++) {
|
for (int i = 0; i < steps; i++) {
|
||||||
@@ -78,19 +85,22 @@ public class Stickfight extends StatelessGame {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
if(!spawnPoints.containsKey(playerMoveEvent.getPlayer())) {
|
Player player = playerMoveEvent.getPlayer();
|
||||||
|
if(!spawnPoints.containsKey(player)) {
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isBeforeBeginning) {
|
if(isBeforeBeginning) {
|
||||||
if(spawnPoints.get(playerMoveEvent.getPlayer()).distance(playerMoveEvent.getNewPosition()) < 1) return;
|
if(spawnPoints.get(player).distance(playerMoveEvent.getNewPosition()) < 1) return;
|
||||||
playerMoveEvent.setCancelled(true);
|
playerMoveEvent.setCancelled(true);
|
||||||
playerMoveEvent.getPlayer().teleport(spawnPoints.get(playerMoveEvent.getPlayer()));
|
player.teleport(spawnPoints.get(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(playerMoveEvent.getNewPosition().y() < 40) {
|
if(playerMoveEvent.getNewPosition().y() < 40) {
|
||||||
playerMoveEvent.getPlayer().teleport(spawnPoints.get(playerMoveEvent.getPlayer()));
|
player.teleport(spawnPoints.get(player));
|
||||||
|
this.scoreMap.putIfAbsent(player, 0);
|
||||||
|
this.scoreMap.put(player, this.scoreMap.get(player) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,16 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.score;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.util.MapUtil;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class LowestPointsWinScore extends PointsWinScore {
|
||||||
|
@Override
|
||||||
|
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
||||||
|
this.scoreOrder.put(p, currentPoints);
|
||||||
|
this.scoreOrder = MapUtil.sortReversedByValue(this.scoreOrder);
|
||||||
|
getScores().clear();
|
||||||
|
this.scoreOrder.forEach((player, integer) -> getScores().addFirst(player));
|
||||||
|
}
|
||||||
|
}
|
@@ -12,7 +12,7 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PointsWinScore extends Score {
|
public class PointsWinScore extends Score {
|
||||||
private Map<Set<Player>, Integer> scoreOrder = new HashMap<>();
|
Map<Set<Player>, Integer> scoreOrder = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
protected void insertResultImplementation(Set<Player> p, int currentPoints) {
|
||||||
|
@@ -1,9 +1,6 @@
|
|||||||
package eu.mhsl.minenet.minigames.util;
|
package eu.mhsl.minenet.minigames.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MapUtil {
|
public class MapUtil {
|
||||||
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
|
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
|
||||||
@@ -17,4 +14,16 @@ public class MapUtil {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <K, V extends Comparable<? super V>> Map<K, V> sortReversedByValue(Map<K, V> map) {
|
||||||
|
List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet());
|
||||||
|
list.sort(Map.Entry.<K, V>comparingByValue().reversed());
|
||||||
|
|
||||||
|
Map<K, V> result = new LinkedHashMap<>();
|
||||||
|
for (Map.Entry<K, V> entry : list) {
|
||||||
|
result.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user