Skip to content

Commit

Permalink
Fixed XLINT error that appears on game launch; fixed some code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Oct 16, 2023
1 parent d70f4dd commit ee7affc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public AITaskComponent addTask(PriorityTask task) {
*/
public <T extends PriorityTask> T getTask(Class<T> 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);
Expand Down Expand Up @@ -83,25 +83,17 @@ 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();
}

/**
* Restores the priorityTasks List. Adds all of the entity's disposed tasks
* 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);



}
}

0 comments on commit ee7affc

Please sign in to comment.