highground finished
This commit is contained in:
@ -36,7 +36,7 @@ public enum GameList {
|
|||||||
SPLEEF(new SpleefFactory(), GameType.PVP),
|
SPLEEF(new SpleefFactory(), GameType.PVP),
|
||||||
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
||||||
SUMO(new SumoFactory(), GameType.PVP),
|
SUMO(new SumoFactory(), GameType.PVP),
|
||||||
HIGHGROUND(new HighGroundFactory(), GameType.PROTOTYPE);
|
HIGHGROUND(new HighGroundFactory(), GameType.PVP);
|
||||||
|
|
||||||
private final GameFactory factory;
|
private final GameFactory factory;
|
||||||
private final GameType type;
|
private final GameType type;
|
||||||
|
@ -10,17 +10,23 @@ import io.github.togar2.pvp.events.PrepareAttackEvent;
|
|||||||
import io.github.togar2.pvp.feature.CombatFeatures;
|
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||||
import net.minestom.server.coordinate.Pos;
|
import net.minestom.server.coordinate.Pos;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.event.instance.InstanceTickEvent;
|
||||||
import net.minestom.server.event.player.PlayerMoveEvent;
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.WeakHashMap;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class HighGround extends StatelessGame {
|
class HighGround extends StatelessGame {
|
||||||
|
private final int radius;
|
||||||
|
private final int seconds;
|
||||||
|
private final WeakHashMap<Player, Integer> scoreMap = new WeakHashMap<>();
|
||||||
|
|
||||||
int radius = 5;
|
HighGround(int radius, int seconds) {
|
||||||
public HighGround() {
|
|
||||||
super(Dimension.THE_END.key, "highground", new PointsWinScore());
|
super(Dimension.THE_END.key, "highground", new PointsWinScore());
|
||||||
|
this.radius = radius;
|
||||||
|
this.seconds = seconds;
|
||||||
|
|
||||||
this.eventNode().addChild(
|
this.eventNode().addChild(
|
||||||
CombatFeatures.empty()
|
CombatFeatures.empty()
|
||||||
@ -46,12 +52,23 @@ public class HighGround extends StatelessGame {
|
|||||||
EntityKnockbackEvent.class,
|
EntityKnockbackEvent.class,
|
||||||
entityKnockbackEvent -> entityKnockbackEvent.setStrength(1.1f)
|
entityKnockbackEvent -> entityKnockbackEvent.setStrength(1.1f)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.eventNode().addListener(InstanceTickEvent.class, instanceTickEvent -> {
|
||||||
|
if (this.isBeforeBeginning || !this.isRunning) return;
|
||||||
|
this.getPlayers().forEach(player -> {
|
||||||
|
if((player.isOnGround() && player.getPosition().y() >= 1) || (!player.isOnGround() && player.getPosition().y() >= 1.5)){
|
||||||
|
this.scoreMap.put(player, this.scoreMap.get(player) + 1);
|
||||||
|
player.setLevel(this.scoreMap.get(player) / 20);
|
||||||
|
player.setExp((this.scoreMap.get(player) % 20) / 20.0f);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
for (int y = 0; y >= -3; y--) {
|
for (int y = 0; y >= -3; y--) {
|
||||||
int radius = (Math.abs(y) * 5) + 5;
|
int radius = (Math.abs(y) * 5) + this.radius;
|
||||||
for (int x = -radius; x <= radius; x++) {
|
for (int x = -radius; x <= radius; x++) {
|
||||||
for (int z = -radius; z <= radius; z++) {
|
for (int z = -radius; z <= radius; z++) {
|
||||||
double distance = new Pos(x, 0, z).distance(0, 0, 0);
|
double distance = new Pos(x, 0, z).distance(0, 0, 0);
|
||||||
@ -80,6 +97,22 @@ public class HighGround extends StatelessGame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start() {
|
||||||
|
this.getPlayers().forEach(player -> this.scoreMap.put(player, 0));
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
this.setTimeLimit(this.seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
this.getPlayers().forEach(player -> this.getScore().insertResult(player, this.scoreMap.get(player)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pos getSpawn() {
|
public Pos getSpawn() {
|
||||||
double theta = this.rnd.nextDouble() * 2 * Math.PI;
|
double theta = this.rnd.nextDouble() * 2 * Math.PI;
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.highGround;
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.highGround;
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
import eu.mhsl.minenet.minigames.instance.game.Game;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.config.ConfigManager;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.config.GameFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.config.Option;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.config.common.NumericOption;
|
||||||
import eu.mhsl.minenet.minigames.instance.room.Room;
|
import eu.mhsl.minenet.minigames.instance.room.Room;
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -14,8 +17,20 @@ public class HighGroundFactory implements GameFactory {
|
|||||||
return TranslatedComponent.byId("game_Highground#name");
|
return TranslatedComponent.byId("game_Highground#name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent description() {
|
||||||
|
return TranslatedComponent.byId("game_Highground#description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigManager configuration() {
|
||||||
|
return new ConfigManager()
|
||||||
|
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 3, 5, 7, 10))
|
||||||
|
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 30, 60, 90, 120));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
return new HighGround().setParent(parent);
|
return new HighGround(configuration.get("radius").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,8 @@ public class Room extends MineNetInstance implements Spawnable {
|
|||||||
p.getInventory().clear();
|
p.getInventory().clear();
|
||||||
p.setGameMode(GameMode.ADVENTURE);
|
p.setGameMode(GameMode.ADVENTURE);
|
||||||
p.setInvisible(false);
|
p.setInvisible(false);
|
||||||
|
p.setExp(0);
|
||||||
|
p.setLevel(0);
|
||||||
rooms.add(room);
|
rooms.add(room);
|
||||||
players.put(p, room);
|
players.put(p, room);
|
||||||
MoveInstance.move(p, room);
|
MoveInstance.move(p, room);
|
||||||
@ -88,29 +90,29 @@ public class Room extends MineNetInstance implements Spawnable {
|
|||||||
private Room(Player owner) {
|
private Room(Player owner) {
|
||||||
super(Dimension.THE_END.key);
|
super(Dimension.THE_END.key);
|
||||||
this.apiDriven = false;
|
this.apiDriven = false;
|
||||||
construct();
|
this.construct();
|
||||||
setOwner(owner);
|
this.setOwner(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Room() {
|
protected Room() {
|
||||||
super(Dimension.THE_END.key);
|
super(Dimension.THE_END.key);
|
||||||
this.apiDriven = true;
|
this.apiDriven = true;
|
||||||
construct();
|
this.construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void construct() {
|
private void construct() {
|
||||||
MinecraftServer.getInstanceManager().registerInstance(this);
|
MinecraftServer.getInstanceManager().registerInstance(this);
|
||||||
setChunkLoader(new AnvilLoader(Resource.LOBBY_MAP.getPath()));
|
this.setChunkLoader(new AnvilLoader(Resource.LOBBY_MAP.getPath()));
|
||||||
|
|
||||||
this.gameSelector = new GameSelector();
|
this.gameSelector = new GameSelector();
|
||||||
this.gameSelector.setInstance(this, new Pos(0.5, 50, 19.5));
|
this.gameSelector.setInstance(this, new Pos(0.5, 50, 19.5));
|
||||||
|
|
||||||
eventNode().addListener(PlayerBlockBreakEvent.class, CommonEventHandles::cancel);
|
this.eventNode().addListener(PlayerBlockBreakEvent.class, CommonEventHandles::cancel);
|
||||||
eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> unsetRoom(playerDisconnectEvent.getPlayer()));
|
this.eventNode().addListener(PlayerDisconnectEvent.class, playerDisconnectEvent -> unsetRoom(playerDisconnectEvent.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getOwner() {
|
public Player getOwner() {
|
||||||
return owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOwner(Player newOwner) {
|
public void setOwner(Player newOwner) {
|
||||||
@ -123,7 +125,7 @@ public class Room extends MineNetInstance implements Spawnable {
|
|||||||
|
|
||||||
if(p != this.owner) return;
|
if(p != this.owner) return;
|
||||||
|
|
||||||
getAllMembers().stream()
|
this.getAllMembers().stream()
|
||||||
.filter(player -> player != p) // exclude the current leaving owner
|
.filter(player -> player != p) // exclude the current leaving owner
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.ifPresentOrElse(
|
.ifPresentOrElse(
|
||||||
@ -133,8 +135,8 @@ public class Room extends MineNetInstance implements Spawnable {
|
|||||||
|
|
||||||
Room.unsetRoom(p);
|
Room.unsetRoom(p);
|
||||||
|
|
||||||
new ChatMessage(Icon.ERROR).appendStatic("The room leader left!").send(getAllMembers());
|
new ChatMessage(Icon.ERROR).appendStatic("The room leader left!").send(this.getAllMembers());
|
||||||
new ChatMessage(Icon.SCIENCE).appendStatic(this.owner.getUsername()).appendStatic(" is the new Leader!").send(getAllMembers().stream().filter(player -> player != this.owner).collect(Collectors.toSet()));
|
new ChatMessage(Icon.SCIENCE).appendStatic(this.owner.getUsername()).appendStatic(" is the new Leader!").send(this.getAllMembers().stream().filter(player -> player != this.owner).collect(Collectors.toSet()));
|
||||||
new ChatMessage(Icon.SUCCESS).appendStatic("You are now the leader.").send(this.owner);
|
new ChatMessage(Icon.SUCCESS).appendStatic("You are now the leader.").send(this.owner);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -135,3 +135,7 @@ ns:game_Sumo#;;
|
|||||||
name;Sumo;Sumo
|
name;Sumo;Sumo
|
||||||
lives;Lives;Leben
|
lives;Lives;Leben
|
||||||
description;Knock your enemies off and stay on top!;Versuche deinen Gegner von der Plattform zu schubsen!
|
description;Knock your enemies off and stay on top!;Versuche deinen Gegner von der Plattform zu schubsen!
|
||||||
|
;;
|
||||||
|
ns:game_Highground#;;
|
||||||
|
name;Highground;Hochburg
|
||||||
|
description;Stay on the high ground to win!;Bleibe solange wie möglich auf der Hochburg, um zu gewinnen!
|
||||||
|
Can't render this file because it has a wrong number of fields in line 114.
|
Reference in New Issue
Block a user