diff --git a/source/core/src/main/com/csse3200/game/ai/tasks/AITaskComponent.java b/source/core/src/main/com/csse3200/game/ai/tasks/AITaskComponent.java index 93798e8d4..b54745014 100644 --- a/source/core/src/main/com/csse3200/game/ai/tasks/AITaskComponent.java +++ b/source/core/src/main/com/csse3200/game/ai/tasks/AITaskComponent.java @@ -46,8 +46,8 @@ public AITaskComponent addTask(PriorityTask task) { */ public T getTask(Class task) { for (PriorityTask priorityTask : priorityTasks) { - if (priorityTask.getClass() == task) { - return (T) priorityTask; + if (task.isInstance(priorityTask)) { + return task.cast(priorityTask); } } logger.info("Task {} not found", task); @@ -83,12 +83,8 @@ public void dispose() { */ public void disposeAll() { currentTask = null; - for (int i = 0; i < priorityTasks.size(); i++) { - priorityTasksToBeRestored.add(priorityTasks.get(i)); - } - for (int i = 0; i < priorityTasks.size(); i++) { - priorityTasks.remove(i); - } + priorityTasksToBeRestored.addAll(priorityTasks); + priorityTasks.clear(); } /** @@ -96,12 +92,8 @@ public void disposeAll() { * back into priorityTasks. */ public void restore() { - for (int i = 0; i < priorityTasksToBeRestored.size(); i++) { - priorityTasks.add(priorityTasksToBeRestored.get(i)); - } - for (int i = 0; i < priorityTasksToBeRestored.size(); i++) { - priorityTasksToBeRestored.remove(i); - } + priorityTasks.addAll(priorityTasksToBeRestored); + priorityTasksToBeRestored.clear(); this.update(); } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java index e183c0386..a5c7b78c1 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobTask/MobTask.java @@ -341,14 +341,18 @@ private void dropCurrency() { Entity currency; if (randomValue <= CRYSTAL_DROP_RATE) { currency = DropFactory.createCrystalDrop(); + currency.setPosition(mob.getPosition().x,mob.getPosition().y); + ServiceLocator.getEntityService().register(currency); } else if (randomValue <= SCRAP_DROP_RATE) { currency = DropFactory.createScrapDrop(); + currency.setPosition(mob.getPosition().x,mob.getPosition().y); + ServiceLocator.getEntityService().register(currency); } - currency.setPosition(mob.getPosition().x,mob.getPosition().y); - ServiceLocator.getEntityService().register(currency); + + } }