add exp command, fix game over screen
This commit is contained in:
parent
8f1fda3f3d
commit
cdf8db1b50
4 changed files with 57 additions and 8 deletions
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -261,5 +261,6 @@ public class CommandEnvironment {
|
|||
this.registerExecutable(new CommandItem());
|
||||
this.registerExecutable(new CommandRunat());
|
||||
this.registerExecutable(new CommandRunas());
|
||||
this.registerExecutable(new CommandExp());
|
||||
}
|
||||
}
|
||||
|
|
44
server/src/main/java/server/command/commands/CommandExp.java
Normal file
44
server/src/main/java/server/command/commands/CommandExp.java
Normal file
|
@ -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<EntityNPC> 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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue