added Sumo Minigame
This commit is contained in:
@ -13,8 +13,7 @@ import eu.mhsl.minenet.minigames.instance.game.stateless.types.minerun.MinerunFa
|
|||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.spleef.SpleefFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight.StickFightFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.stickfight.StickFightFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.TetrisFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tetris.TetrisFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.test.Test;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.test.SumoFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.test.TestFactory;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tntrun.TntRunFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.tntrun.TntRunFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.TowerdefenseFactory;
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory;
|
import eu.mhsl.minenet.minigames.instance.game.stateless.types.trafficlightrace.TrafficLightRaceFactory;
|
||||||
@ -35,7 +34,7 @@ public enum GameList {
|
|||||||
ELYTRARACE(new ElytraRaceFactory(), GameType.PVP),
|
ELYTRARACE(new ElytraRaceFactory(), GameType.PVP),
|
||||||
SPLEEF(new SpleefFactory(), GameType.PVP),
|
SPLEEF(new SpleefFactory(), GameType.PVP),
|
||||||
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
JUMPDIVE(new JumpDiveFactory(), GameType.JUMPNRUN),
|
||||||
Test(new TestFactory(), GameType.OTHER);
|
Test(new SumoFactory(), GameType.OTHER);
|
||||||
|
|
||||||
private final GameFactory factory;
|
private final GameFactory factory;
|
||||||
private final GameType type;
|
private final GameType type;
|
||||||
@ -48,6 +47,6 @@ public enum GameList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GameType getType() {
|
public GameType getType() {
|
||||||
return type;
|
return this.type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class AnvilRunFactory implements GameFactory {
|
|||||||
public ConfigManager configuration() {
|
public ConfigManager configuration() {
|
||||||
return new ConfigManager()
|
return new ConfigManager()
|
||||||
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 10, 15, 20, 25, 30))
|
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 5, 10, 15, 20, 25, 30))
|
||||||
.addOption(new NumericOption("seconds", Material.STICK, TranslatedComponent.byId("optionCommon#seconds"), 10, 30, 60, 90, 120));
|
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 10, 30, 60, 90, 120));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,128 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.test;
|
||||||
|
|
||||||
|
import eu.mhsl.minenet.minigames.instance.Dimension;
|
||||||
|
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
||||||
|
import eu.mhsl.minenet.minigames.score.LastWinsScore;
|
||||||
|
import io.github.togar2.pvp.events.FinalAttackEvent;
|
||||||
|
import io.github.togar2.pvp.events.PrepareAttackEvent;
|
||||||
|
import io.github.togar2.pvp.feature.CombatFeatures;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.event.player.PlayerMoveEvent;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
|
import net.minestom.server.timer.TaskSchedule;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class Sumo extends StatelessGame {
|
||||||
|
int radius;
|
||||||
|
int health;
|
||||||
|
int seconds;
|
||||||
|
|
||||||
|
int originalRadius;
|
||||||
|
int timer;
|
||||||
|
|
||||||
|
WeakHashMap<Player, Integer> healthMap = new WeakHashMap<>();
|
||||||
|
|
||||||
|
public Sumo(int radius, int health, int seconds) {
|
||||||
|
super(Dimension.OVERWORLD.key, "Sumo", new LastWinsScore());
|
||||||
|
this.getScore().setIgnoreLastPlayers(1);
|
||||||
|
this.setTime(6000);
|
||||||
|
this.setTimeRate(0);
|
||||||
|
|
||||||
|
this.radius = radius;
|
||||||
|
this.health = health;
|
||||||
|
this.seconds = seconds;
|
||||||
|
|
||||||
|
this.originalRadius = radius;
|
||||||
|
this.timer = seconds;
|
||||||
|
|
||||||
|
this.eventNode().addChild(
|
||||||
|
CombatFeatures.empty()
|
||||||
|
.add(CombatFeatures.VANILLA_ATTACK)
|
||||||
|
.add(CombatFeatures.VANILLA_DAMAGE)
|
||||||
|
.add(CombatFeatures.VANILLA_KNOCKBACK)
|
||||||
|
.build().createNode()
|
||||||
|
);
|
||||||
|
|
||||||
|
this.eventNode().addListener(PrepareAttackEvent.class, prepareAttackEvent -> {
|
||||||
|
if (this.isBeforeBeginning)
|
||||||
|
prepareAttackEvent.setCancelled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.eventNode().addListener(FinalAttackEvent.class, finalAttackEvent -> {
|
||||||
|
finalAttackEvent.setBaseDamage(0);
|
||||||
|
((Player) finalAttackEvent.getTarget()).setHealth(20);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start() {
|
||||||
|
this.getPlayers().forEach(player -> {
|
||||||
|
this.healthMap.put(player, this.health);
|
||||||
|
player.setLevel(this.healthMap.get(player));
|
||||||
|
});
|
||||||
|
|
||||||
|
MinecraftServer.getSchedulerManager().scheduleTask(
|
||||||
|
() -> {
|
||||||
|
if(this.isBeforeBeginning) return TaskSchedule.seconds(1);
|
||||||
|
this.timer--;
|
||||||
|
double percent = (double) this.timer / this.seconds;
|
||||||
|
int radius = (int) (this.originalRadius * percent);
|
||||||
|
if (this.radius >= 5) {
|
||||||
|
this.radius = radius;
|
||||||
|
this.generatePlatform();
|
||||||
|
return TaskSchedule.seconds(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TaskSchedule.stop();
|
||||||
|
},
|
||||||
|
TaskSchedule.seconds(1)
|
||||||
|
);
|
||||||
|
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
||||||
|
this.generatePlatform();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generatePlatform() {
|
||||||
|
int buffer = 5;
|
||||||
|
for(int x = -this.radius - buffer; x <= this.radius + buffer; x++) {
|
||||||
|
for(int z = -this.radius - buffer; z <= this.radius + buffer; z++) {
|
||||||
|
double distance = new Pos(x, 0, z).distance(new Pos(0, 0, 0));
|
||||||
|
if(distance <= this.radius) {
|
||||||
|
boolean isEdge = this.radius - 1 < distance;
|
||||||
|
this.setBlock(x, 0, z, isEdge ? Block.RED_CONCRETE : Block.WHITE_CONCRETE);
|
||||||
|
} else {
|
||||||
|
this.setBlock(x, 0, z, Block.AIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPlayerMove(@NotNull PlayerMoveEvent playerMoveEvent) {
|
||||||
|
Player player = playerMoveEvent.getPlayer();
|
||||||
|
if(playerMoveEvent.getNewPosition().y() < -10) {
|
||||||
|
player.teleport(this.getSpawn());
|
||||||
|
this.healthMap.put(player, this.healthMap.get(player) - 1);
|
||||||
|
player.setLevel(this.healthMap.get(player));
|
||||||
|
if (this.healthMap.get(player) == 0) {
|
||||||
|
this.getScore().insertResult(player);
|
||||||
|
player.setGameMode(GameMode.SPECTATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pos getSpawn() {
|
||||||
|
return new Pos(0, 2, 0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package eu.mhsl.minenet.minigames.instance.game.stateless.types.test;
|
||||||
|
|
||||||
|
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.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.message.component.TranslatedComponent;
|
||||||
|
import net.minestom.server.item.Material;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SumoFactory implements GameFactory {
|
||||||
|
@Override
|
||||||
|
public TranslatedComponent name() {return TranslatedComponent.byId("game_Sumo#name");}
|
||||||
|
public TranslatedComponent description() {
|
||||||
|
return TranslatedComponent.byId("game_Sumo#description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigManager configuration() {
|
||||||
|
return new ConfigManager()
|
||||||
|
.addOption(new NumericOption("radius", Material.HEART_OF_THE_SEA, TranslatedComponent.byId("optionCommon#radius"), 10, 20, 30))
|
||||||
|
.addOption(new NumericOption("health", Material.GOLDEN_APPLE, TranslatedComponent.byId("game_Sumo#lives"), 1, 2, 3, 4, 5))
|
||||||
|
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 30, 60, 90, 120));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
||||||
|
return new Sumo(configuration.get("radius").getAsInt(), configuration.get("health").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
|
||||||
|
}
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.test;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.Dimension;
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.stateless.StatelessGame;
|
|
||||||
import eu.mhsl.minenet.minigames.score.FirstWinsScore;
|
|
||||||
import net.minestom.server.coordinate.Pos;
|
|
||||||
import net.minestom.server.event.player.PlayerBlockInteractEvent;
|
|
||||||
import net.minestom.server.instance.block.Block;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class Test extends StatelessGame {
|
|
||||||
|
|
||||||
int zähler = 0;
|
|
||||||
|
|
||||||
public Test() {
|
|
||||||
super(Dimension.THE_END.key, "test", new FirstWinsScore());
|
|
||||||
eventNode().addListener(PlayerBlockInteractEvent.class, event -> {
|
|
||||||
if (!isBeforeBeginning) {
|
|
||||||
zähler++;
|
|
||||||
}
|
|
||||||
if (zähler >= 10) {
|
|
||||||
getScore().insertResult(event.getPlayer());
|
|
||||||
System.out.println("Sieg");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onLoad(@NotNull CompletableFuture<Void> callback) {
|
|
||||||
for(int x = 0; x <= 10; x++) {
|
|
||||||
for(int z = 0; z <= 10; z++) {
|
|
||||||
setBlock(x, 0, z, Block.BEDROCK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setBlock(3,1,6, Block.BIRCH_BUTTON.withProperty("face", "floor"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Pos getSpawn() {
|
|
||||||
return new Pos(5, 3, 5);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package eu.mhsl.minenet.minigames.instance.game.stateless.types.test;
|
|
||||||
|
|
||||||
import eu.mhsl.minenet.minigames.instance.game.Game;
|
|
||||||
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.room.Room;
|
|
||||||
import eu.mhsl.minenet.minigames.message.component.TranslatedComponent;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TestFactory implements GameFactory {
|
|
||||||
@Override
|
|
||||||
public TranslatedComponent name() {
|
|
||||||
return TranslatedComponent.byId("test");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Game manufacture(Room parent, Map<String, Option<?>> configuration) throws Exception {
|
|
||||||
return new Test().setParent(parent);
|
|
||||||
}
|
|
||||||
}
|
|
@ -130,3 +130,8 @@ description;Run away from falling anvils;Renne von fallenden Ambossen davon
|
|||||||
ns:game_jumpDive#;;
|
ns:game_jumpDive#;;
|
||||||
name;Jump dive;Wassersprung
|
name;Jump dive;Wassersprung
|
||||||
description;Jump into the water, avoiding already used spots!;Springe ins wasser an stellen, in denen noch niemand zuvor gelandet ist!
|
description;Jump into the water, avoiding already used spots!;Springe ins wasser an stellen, in denen noch niemand zuvor gelandet ist!
|
||||||
|
;;
|
||||||
|
ns:game_Sumo#;;
|
||||||
|
name;Sumo;Sumo
|
||||||
|
lives;Lives;Leben
|
||||||
|
description;Knock your enemies off and stay on top!;Versuche deinen Gegner von der Plattform zu schubsen!
|
||||||
|
Can't render this file because it has a wrong number of fields in line 114.
|
Reference in New Issue
Block a user