From 2604815f3e26bc84b811cac2c78151d37995b18a Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Wed, 25 Jan 2023 10:31:50 +0100 Subject: [PATCH] =?UTF-8?q?Implemented=20useItem(=E2=80=A6=20Player)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/bitbiome/commands/UseCommand.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index d35b331..1ec7bbf 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -10,6 +10,8 @@ public class UseCommand implements CommandAPI { @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { System.out.println(getUseMessage(message.split(" ", 2)[1], engine)); + if(engine.getPlayer().getHp() <= 0) + System.exit(0); } private String getUseMessage(String msg, TravelEngine engine) { @@ -40,7 +42,15 @@ public class UseCommand implements CommandAPI { } private String useItem(Item item, Player target) { - return "You used " + item + " on " + target; + float hp = target.getHp(); + hp -= item.getDamage(); + String retString = "You used " + item.getName() + " on yourself"; + if(hp <= 0) { + target.setHp(0); + return retString + " and died."; + } + target.setHp(hp); + return retString; } private String useItem(Item item, Mob target, Location location) {