From cdf8db1b50d8941b21450386f93152465d746624 Mon Sep 17 00:00:00 2001 From: Sen Date: Sat, 14 Jun 2025 13:08:46 +0200 Subject: [PATCH] add exp command, fix game over screen --- .../java/client/gui/ingame/GuiGameOver.java | 10 +++-- .../java/common/entity/npc/EntityNPC.java | 10 +++-- .../server/command/CommandEnvironment.java | 1 + .../server/command/commands/CommandExp.java | 44 +++++++++++++++++++ 4 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 server/src/main/java/server/command/commands/CommandExp.java diff --git a/client/src/main/java/client/gui/ingame/GuiGameOver.java b/client/src/main/java/client/gui/ingame/GuiGameOver.java index 25c90ec..5fec815 100755 --- a/client/src/main/java/client/gui/ingame/GuiGameOver.java +++ b/client/src/main/java/client/gui/ingame/GuiGameOver.java @@ -4,7 +4,9 @@ import client.gui.Gui; import client.gui.element.ActButton; import client.gui.element.ButtonCallback; import common.color.TextColor; +import common.util.ExtMath; import client.gui.element.Label; +import client.gui.element.MultiLabel; import client.gui.element.PressType; public class GuiGameOver extends Gui { @@ -18,9 +20,9 @@ public class GuiGameOver extends Gui { public void init(int width, int height) { this.timer = 0; - this.add(new Label(0, 0, 200, 0, "Du bist gestorben!")); - this.add(new Label(0, 32, 200, 0, "Punktestand: " + TextColor.YELLOW + this.gm.player.experienceLevel)); - this.button = this.add(new ActButton(0, 100, 200, 0, new ButtonCallback() { + this.add(new Label(0, 0, 400, 0, TextColor.DRED + "Du bist gestorben!")); + this.add(new MultiLabel(0, 32, 400, 42, String.format(TextColor.GREEN + "Letzte Position" + TextColor.GRAY + ":\n" + TextColor.YELLOW + "%d, %d, %d\n" + TextColor.YELLOW + "%s", ExtMath.floord(this.gm.player.posX), ExtMath.floord(this.gm.player.posY), ExtMath.floord(this.gm.player.posZ), this.gm.player.worldObj.dimension.getFormattedName(false)))); + this.button = this.add(new ActButton(100, 100, 200, 0, new ButtonCallback() { public void use(ActButton elem, PressType action) { GuiGameOver.this.gm.player.respawnPlayer(); GuiGameOver.this.gm.displayGuiScreen(null); @@ -31,7 +33,7 @@ public class GuiGameOver extends Gui { } public String getTitle() { - return "Game over"; + return "Game over - Wiederbeleben?"; } public void updateScreen() { diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index dae3ff5..cb902ca 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -2755,9 +2755,6 @@ public abstract class EntityNPC extends EntityLiving return !this.worldObj.getState(pos).getBlock().isNormalCube() && (this.height <= 1.0f || !this.worldObj.getState(pos.up()).getBlock().isNormalCube()); } - /** - * Sets the current XP, total XP, and level number. - */ public void setXPStats(float currentXP, int maxXP, int level) { this.experience = currentXP; @@ -2819,7 +2816,7 @@ public abstract class EntityNPC extends EntityLiving // START MP - public void addExperienceLevel(int levels) { + private void addExperienceLevel(int levels) { this.experienceLevel += levels; if (this.experienceLevel < 0) @@ -4075,6 +4072,11 @@ public abstract class EntityNPC extends EntityLiving { return this.isPlayer() ? this.inventory.armorItemInSlot(slot) : this.equipment[slot + 1]; } + + public void setExperience(int points) { + this.setXPStats(0.0f, 0, 0); + this.addExperience(points); + } public void addExperience(int amount) { diff --git a/server/src/main/java/server/command/CommandEnvironment.java b/server/src/main/java/server/command/CommandEnvironment.java index 55b3df1..756e7d2 100644 --- a/server/src/main/java/server/command/CommandEnvironment.java +++ b/server/src/main/java/server/command/CommandEnvironment.java @@ -261,5 +261,6 @@ public class CommandEnvironment { this.registerExecutable(new CommandItem()); this.registerExecutable(new CommandRunat()); this.registerExecutable(new CommandRunas()); + this.registerExecutable(new CommandExp()); } } diff --git a/server/src/main/java/server/command/commands/CommandExp.java b/server/src/main/java/server/command/commands/CommandExp.java new file mode 100644 index 0000000..359ce85 --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandExp.java @@ -0,0 +1,44 @@ +package server.command.commands; + +import java.util.List; + +import common.entity.npc.EntityNPC; +import server.command.Command; +import server.command.CommandEnvironment; +import server.command.Executor; +import server.command.UserPolicy; + +public class CommandExp extends Command { + public CommandExp() { + super("exp"); + + this.setParamsOptional(); + this.addInt("points", 1, Integer.MAX_VALUE); + this.addFlag("reset", 'r'); + this.setParamsRequired(); + this.addPlayerEntityList("players", 'p', true, UserPolicy.NON_ADMINS_OR_SELF); + } + + public void exec(CommandEnvironment env, Executor exec, Integer points, boolean reset, List players) { + for(EntityNPC player : players) { + if(points == null && !reset) { + exec.log("Erfahrung von %s: Level %d, %d/%d (%d Punkte)", player.getCommandName(), player.experienceLevel, (int)((float)player.xpBarCap() * player.experience), player.xpBarCap(), player.experienceTotal); + } + else if(reset) { + player.setExperience(points == null ? 0 : points); + exec.log("Erfahrung von %s " + (points == null ? "zurückgesetzt" : "auf %d Punkte gesetzt (Level %d)"), player.getCommandName(), player.experienceTotal, player.experienceLevel); + } + else { + int level = player.experienceLevel; + player.addExperience(points); + exec.log("%d Erfahrungspunkte an %s gegeben" + (player.experienceLevel != level ? ", ist jetzt Level %d" : ""), points, player.getCommandName(), player.experienceLevel); + } + } + if(players.size() > 1) { + if(reset) + exec.log("Erfahrung von %d Spielern " + (points == null ? "zurückgesetzt" : "auf %d Punkte gesetzt"), players.size(), points); + else if(points != null) + exec.log("%d Erfahrungspunkte an %d Spieler gegeben", points * players.size(), players.size()); + } + } +}