Skip to content

Commit

Permalink
Fix 12 code smells in BombshipCombatTask
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhatminh451 committed Oct 16, 2023
1 parent 2e8a55c commit 6112ea4
Showing 1 changed file with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,20 @@
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.entities.factories.ProjectileFactory;
import com.csse3200.game.physics.PhysicsEngine;
import com.csse3200.game.physics.PhysicsLayer;
import com.csse3200.game.physics.raycast.RaycastHit;
import com.csse3200.game.services.GameTime;
import com.csse3200.game.services.ServiceLocator;


import java.util.ArrayList;

/**
* The AI Task for the Engineer entity. The Engineer will scan for targets within its detection range
* and trigger events to change its state accordingly. This task must be called once the Engineer has
* appropiately moved into position.
*/
public class BombshipCombatTask extends DefaultTask implements PriorityTask {

private static final int INTERVAL = 1; // The time interval for each target scan from the Engineer.
private static final int PRIORITY = 3; // Default priority of the combat task when mobs are in range.
private static final short TARGET1 = PhysicsLayer.BOSS; // The type of targets that the Engineer will detect.
private static final short TARGET2 = PhysicsLayer.XENO;
// private static final short TARGET1 = PhysicsLayer.BOSS; // The type of targets that the Engineer will detect.
// private static final short TARGET2 = PhysicsLayer.XENO;

// Animation event names for the Engineer's state machine.
private static final String START = "start";
Expand All @@ -34,18 +26,17 @@ public class BombshipCombatTask extends DefaultTask implements PriorityTask {

// The Engineer's attributes.
private final float maxRange; // The maximum range of the bombship.

private Vector2 bombShipPosition = new Vector2(0, 0); // Placeholder value for the Bombship's position.
private final Vector2 maxRangePosition = new Vector2();
private PhysicsEngine physics;
private GameTime timeSource;
private long endTime;
/*
private long reloadTime;
/**
private ArrayList<RaycastHit> hits = new ArrayList<>();
private final RaycastHit hit = new RaycastHit();
private ArrayList<Vector2> targets = new ArrayList<>();
*/

/** The Engineer's states. */
private enum STATE {
IDLE, START , DESTROY
Expand All @@ -64,8 +55,11 @@ public BombshipCombatTask(float maxRange) {
@Override
public void start() {
super.start();
this.bombShipPosition = owner.getEntity().getCenterPosition();

// Placeholder value for the Bombship's position.
Vector2 bombShipPosition = owner.getEntity().getCenterPosition();
this.maxRangePosition.set(bombShipPosition.x + maxRange, bombShipPosition.y);

// Default to idle mode
owner.getEntity().getEvents().trigger(IDLE);
endTime = timeSource.getTime() + (INTERVAL * 500);
Expand Down Expand Up @@ -104,9 +98,7 @@ public void updateBombshipState() {
owner.getEntity().getEvents().trigger(START);
}
}
case DESTROY -> {
owner.getEntity().getEvents().trigger(DESTROY);
}
default -> owner.getEntity().getEvents().trigger(DESTROY); // DESTROY
}
}

Expand All @@ -117,13 +109,6 @@ private void combatState() {
owner.getEntity().getEvents().trigger(START);
bombshipState = STATE.START;
}
/**
* For stopping the running task
*/
@Override
public void stop() {
super.stop();
}

/**
* Simplified getPriority function, returns the priority of the task
Expand All @@ -141,9 +126,7 @@ public int getPriority() {
* @return true if a target is detected, false otherwise
*/
public boolean isEngineerDied() {
//if (engineerCount < maxEngineers) {
return true;
//}
return true;
}

/**
Expand Down

0 comments on commit 6112ea4

Please sign in to comment.