From 2b44d99b7a30618c58785ca08f6cbe8c91cc8a7c Mon Sep 17 00:00:00 2001 From: fdai7430 Date: Sat, 28 Jan 2023 14:15:25 +0100 Subject: [PATCH] refactoring: Created ArrayList for all enemy mobs --- .../org/bitbiome/commands/UseCommand.java | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/bitbiome/commands/UseCommand.java b/src/main/java/org/bitbiome/commands/UseCommand.java index 8c4d555..4bfe3c5 100644 --- a/src/main/java/org/bitbiome/commands/UseCommand.java +++ b/src/main/java/org/bitbiome/commands/UseCommand.java @@ -7,29 +7,33 @@ import org.bitbiome.classes.*; import org.bitbiome.entities.*; public class UseCommand implements CommandAPI { +ArrayList enemies = new ArrayList(); + @Override public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine engine) { + ArrayList allMobs = engine.getPlayer().getLocation().getMobList(); + for(int i = 0; i mobs = loc.getMobList(); - for(int i = 0; i 0); + } while(enemies.size() > 0); } private String getUseMessage(String msg, TravelEngine engine) { @@ -72,26 +76,17 @@ public class UseCommand implements CommandAPI { } private String useItem(Item item, Mob target, Location location) { + if(target.isFriendly()) + enemies.add(target); float hp = target.getHp(); float dmg = item.getDamage(); if(dmg>=hp) { location.getMobList().remove(target); + enemies.remove(target); return "You killed " + target.getName() + " with " + item.getName(); } target.setHp(hp-dmg); target.setFriendly(false); return "You used " + item.getName() + " on " + target.getName(); } - - private int getNumOfEnemyMobs(TravelEngine engine) { - Location loc = engine.getPlayer().getLocation(); - ArrayList mobs = loc.getMobList(); - int count = 0; - for(int i = 0; i