From ee7affc5de1332df6eabeb648eb67dc5eac1f131 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 16 Oct 2023 17:03:54 +1000 Subject: [PATCH] Fixed XLINT error that appears on game launch; fixed some code smells --- .../game/ai/tasks/AITaskComponent.java | 20 ++++++------------- .../components/tasks/MobTask/MobTask.java | 8 ++++++-- 2 files changed, 12 insertions(+), 16 deletions(-) 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); + + } }