diff --git a/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java b/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java index d8eaa7be5..270f5afa8 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/npc/XenoAnimationController.java @@ -27,38 +27,30 @@ public void create() { } void animateRun() { - if (!Objects.equals(animator.getCurrentAnimation(), "xeno_shoot")) { - animator.stopAnimation(); - animator.startAnimation("xeno_run"); - } + animator.startAnimation("xeno_run"); } void animateHurt() { - animator.stopAnimation(); animator.startAnimation("xeno_hurt"); } void animateShoot() { - animator.stopAnimation(); animator.startAnimation("xeno_shoot"); } void animateMelee1() { - animator.stopAnimation(); animator.startAnimation("xeno_melee_1"); } void animateMelee2() { - animator.stopAnimation(); animator.startAnimation("xeno_melee_2"); } void animateDie() { - animator.stopAnimation(); animator.startAnimation("xeno_die"); } void stopAnimation() { - animator.stopAnimation(); + animator.startAnimation("default"); } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java index 1292d116b..fa6e41433 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobAttackTask.java @@ -30,7 +30,7 @@ public class MobAttackTask extends DefaultTask implements PriorityTask { private static final String STOW = "wanderStart"; private static final String DEPLOY = "deployStart"; private static final String FIRING = "shootStart"; - private static final String IDLE = "idleStart"; + private static final String IDLE = "stop"; private Fixture target; @@ -76,7 +76,7 @@ public void start() { this.maxRangePosition.set(0, mobPosition.y); //owner.getEntity().getEvents().trigger(IDLE); endTime = timeSource.getTime() + (INTERVAL * 500); - owner.getEntity().getEvents().trigger("shootStart"); +// owner.getEntity().getEvents().trigger("shootStart"); } /** @@ -102,7 +102,7 @@ public void updateMobState() { case IDLE -> { if (isTargetVisible()) { // targets detected in idle mode - start deployment - owner.getEntity().getEvents().trigger(DEPLOY); +// owner.getEntity().getEvents().trigger(DEPLOY); mobState = STATE.DEPLOY; } } @@ -111,10 +111,10 @@ public void updateMobState() { // currently deploying, if (isTargetVisible() || this.meleeOrProjectile() != null) { owner.getEntity().getComponent(PhysicsMovementComponent.class).setEnabled(false); - owner.getEntity().getEvents().trigger(FIRING); + this.owner.getEntity().getEvents().trigger(FIRING); mobState = STATE.FIRING; } else { - owner.getEntity().getEvents().trigger(STOW); + this.owner.getEntity().getEvents().trigger(STOW); mobState = STATE.STOW; } } @@ -122,7 +122,7 @@ public void updateMobState() { case FIRING -> { // targets gone or cannot be attacked - stop firing if (!isTargetVisible() || this.meleeOrProjectile() == null) { - owner.getEntity().getEvents().trigger(STOW); + this.owner.getEntity().getEvents().trigger(STOW); mobState = STATE.STOW; } else { if (this.meleeOrProjectile() instanceof Melee) { @@ -130,6 +130,7 @@ public void updateMobState() { TouchAttackComponent attackComp = owner.getEntity().getComponent(TouchAttackComponent.class); HitboxComponent hitboxComp = owner.getEntity().getComponent(HitboxComponent.class); attackComp.onCollisionStart(hitboxComp.getFixture(), target); + this.owner.getEntity().getEvents().trigger("meleeStart"); } else { Entity newProjectile = ProjectileFactory.createMobBall(PhysicsLayer.HUMANS, new Vector2(0, owner.getEntity().getPosition().y), new Vector2(2f,2f)); newProjectile.setPosition((float) (owner.getEntity().getPosition().x), (float) (owner.getEntity().getPosition().y)); @@ -137,7 +138,7 @@ public void updateMobState() { ServiceLocator.getEntityService().register(newProjectile); // System.out.printf("ANIMATION: " + owner.getEntity().getComponent(AnimationRenderComponent.class).getCurrentAnimation() + "\n"); - owner.getEntity().getEvents().trigger(FIRING); + this.owner.getEntity().getEvents().trigger(FIRING); mobState = STATE.STOW; } } @@ -148,7 +149,7 @@ public void updateMobState() { case STOW -> { // currently stowing if (isTargetVisible()) { - owner.getEntity().getEvents().trigger(DEPLOY); +// owner.getEntity().getEvents().trigger(DEPLOY); mobState = STATE.DEPLOY; } else { owner.getEntity().getEvents().trigger(IDLE); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/MobDeathTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobDeathTask.java deleted file mode 100644 index 434a6ab76..000000000 --- a/source/core/src/main/com/csse3200/game/components/tasks/MobDeathTask.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.csse3200.game.components.tasks; - -import com.badlogic.gdx.math.Vector2; -import com.csse3200.game.ai.tasks.DefaultTask; -import com.csse3200.game.ai.tasks.PriorityTask; -import com.csse3200.game.components.CombatStatsComponent; -import com.csse3200.game.entities.Entity; -import com.csse3200.game.entities.factories.DropFactory; -import com.csse3200.game.physics.PhysicsEngine; -import com.csse3200.game.physics.raycast.RaycastHit; -import com.csse3200.game.services.GameTime; -import com.csse3200.game.services.ServiceLocator; -//import com.csse3200.game.rendering.DebugRenderer; - - -/** - * THIS TASK IS NO LONGER USED. It may be deleted at a later date. - * Do not read this aweful task. - * - * DOES NOT DO ANYTHING. - * - * This task didn't work with the Wander & ShootTasks, - * and then it was - * decided to have mob death in wanderTask. - */ -public class MobDeathTask extends DefaultTask implements PriorityTask { - private static final int INTERVAL = 1; // time interval to scan for towers in - - private final int priority; - private Vector2 mobPosition = new Vector2(10f,10f); - private final PhysicsEngine physics; - private GameTime timeSource; - private long endTime; - private final RaycastHit hit = new RaycastHit(); - - private int mobHealth; - - /** - * @param priority Task priority when shooting (0 when not chasing). - */ - public MobDeathTask(int priority) { - this.priority = priority; - - physics = ServiceLocator.getPhysicsService().getPhysics(); - - timeSource = ServiceLocator.getTimeSource(); - } - - @Override - public void start() { - super.start(); - // gets starting health - this.mobHealth = owner.getEntity().getComponent(CombatStatsComponent.class).getHealth(); - //sets mob position - this.mobPosition = owner.getEntity().getCenterPosition(); - //sets endTime - endTime = timeSource.getTime() + (INTERVAL * 500); - this.owner.getEntity().getEvents().trigger("dieStart"); - } - - @Override - public void update() { - if (timeSource.getTime() >= endTime) { - updateMobState(); - endTime = timeSource.getTime() + (INTERVAL * 1000); - } - } - - public void updateMobState() { - - mobHealth = owner.getEntity().getComponent(CombatStatsComponent.class).getHealth(); - // TODO: inset a bit that picks from a list of drop options and drops this - - if (mobIsDead(mobHealth)) { - killMob(); - dropCurrency(); - } - - } - - @Override - public void stop() { - super.stop(); - } - - @Override - public int getPriority() { - if (status == Status.ACTIVE) { - return getActivePriority(); - } - - return getInactivePriority(); - } - - private int getActivePriority() { - if (mobHealth > 0) { - return -1; - } - return priority; - } - - private int getInactivePriority() { - if (mobHealth <= 0) { - return priority; - } - return -1; - } - private boolean mobIsDead(int mobhealth) { - - if (mobhealth <= 0) { - return true; - } - return false; - } - - private void killMob() { - owner.getEntity().dispose(); - } - - private void dropCurrency() { - - Entity scrap = DropFactory.createScrapDrop(); - scrap.setPosition(mobPosition.x,mobPosition.y); - ServiceLocator.getEntityService().register(scrap); - - } - -} diff --git a/source/core/src/main/com/csse3200/game/components/tasks/WanderTask.java b/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java similarity index 84% rename from source/core/src/main/com/csse3200/game/components/tasks/WanderTask.java rename to source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java index f02852bdb..ccd7acf8c 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/WanderTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/MobWanderTask.java @@ -1,31 +1,23 @@ package com.csse3200.game.components.tasks; -import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.DefaultTask; import com.csse3200.game.ai.tasks.PriorityTask; import com.csse3200.game.ai.tasks.Task; -import com.csse3200.game.areas.ForestGameArea; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.factories.DropFactory; -import com.csse3200.game.physics.PhysicsLayer; -import com.csse3200.game.physics.components.ColliderComponent; -import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.rendering.AnimationRenderComponent; import com.csse3200.game.services.ServiceLocator; -import com.csse3200.game.utils.math.RandomUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.TimeUnit; - /** * Wander around by moving a random position within a range of the starting position. Wait a little * bit between movements. Requires an entity with a PhysicsMovementComponent. */ -public class WanderTask extends DefaultTask implements PriorityTask { - private static final Logger logger = LoggerFactory.getLogger(WanderTask.class); +public class MobWanderTask extends DefaultTask implements PriorityTask { + private static final Logger logger = LoggerFactory.getLogger(MobWanderTask.class); private final Vector2 wanderRange; private final float waitTime; @@ -41,7 +33,7 @@ public class WanderTask extends DefaultTask implements PriorityTask { * called. * @param waitTime How long in seconds to wait between wandering. */ - public WanderTask(Vector2 wanderRange, float waitTime) { + public MobWanderTask(Vector2 wanderRange, float waitTime) { this.wanderRange = wanderRange; this.waitTime = waitTime; } @@ -67,7 +59,7 @@ public void start() { currentTask = movementTask; - this.owner.getEntity().getEvents().trigger("wanderStart"); +// this.owner.getEntity().getEvents().trigger("wanderStart"); } @Override @@ -81,7 +73,7 @@ public void update() { // This method is the idea of Ahmad who very kindly helped // with section, massive props to him for his help! if (!isDead && owner.getEntity().getComponent(CombatStatsComponent.class).isDead()) { - owner.getEntity().getEvents().trigger("dieStart"); + this.owner.getEntity().getEvents().trigger("dieStart"); currentTask.stop(); isDead = true; } @@ -115,12 +107,14 @@ else if (!isDead) { private void startWaiting() { logger.debug("Starting waiting"); + this.owner.getEntity().getEvents().trigger("stop"); swapTask(waitTask); } private void startMoving() { logger.debug("Starting moving"); movementTask.setTarget(getDirection()); + this.owner.getEntity().getEvents().trigger("wanderStart"); swapTask(movementTask); } diff --git a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java index 11dccd986..331ffd8f8 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/NPCFactory.java @@ -9,8 +9,7 @@ import com.csse3200.game.components.npc.GhostAnimationController; import com.csse3200.game.components.npc.XenoAnimationController; import com.csse3200.game.components.tasks.MobAttackTask; -import com.csse3200.game.components.tasks.MobDeathTask; -import com.csse3200.game.components.tasks.WanderTask; +import com.csse3200.game.components.tasks.MobWanderTask; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.Melee; import com.csse3200.game.entities.PredefinedWeapons; @@ -139,7 +138,7 @@ public static Entity createXenoGrunt(Entity target) { public static Entity createBaseNPC(Entity target) { AITaskComponent aiComponent = new AITaskComponent() - .addTask(new WanderTask(new Vector2(2f, 2f), 2f)) + .addTask(new MobWanderTask(new Vector2(2f, 2f), 2f)) .addTask(new MobAttackTask(2, 40)); Entity npc = new Entity() diff --git a/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java index 1f4f2f3f1..80bbc26b8 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/PlayerFactory.java @@ -1,14 +1,11 @@ package com.csse3200.game.entities.factories; -import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.AITaskComponent; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.player.InventoryComponent; import com.csse3200.game.components.player.PlayerActions; import com.csse3200.game.components.player.PlayerStatsDisplay; -import com.csse3200.game.components.tasks.MobAttackTask; import com.csse3200.game.components.tasks.SpawnWaveTask; -import com.csse3200.game.components.tasks.WanderTask; import com.csse3200.game.entities.Entity; import com.csse3200.game.entities.configs.PlayerConfig; import com.csse3200.game.files.FileLoader; diff --git a/source/core/src/test/com/csse3200/game/components/tasks/WanderTaskTest.java b/source/core/src/test/com/csse3200/game/components/tasks/MobWanderTaskTest.java similarity index 61% rename from source/core/src/test/com/csse3200/game/components/tasks/WanderTaskTest.java rename to source/core/src/test/com/csse3200/game/components/tasks/MobWanderTaskTest.java index 28fedd6c5..46b2a2ab9 100644 --- a/source/core/src/test/com/csse3200/game/components/tasks/WanderTaskTest.java +++ b/source/core/src/test/com/csse3200/game/components/tasks/MobWanderTaskTest.java @@ -19,7 +19,7 @@ @ExtendWith(GameExtension.class) @ExtendWith(MockitoExtension.class) -class WanderTaskTest { +class MobWanderTaskTest { @Mock GameTime gameTime; @@ -28,20 +28,20 @@ void beforeEach() { ServiceLocator.registerTimeSource(gameTime); } - @Test - void shouldTriggerEvent() { - WanderTask wanderTask = new WanderTask(Vector2Utils.ONE, 1f); - - AITaskComponent aiTaskComponent = new AITaskComponent().addTask(wanderTask); - Entity entity = new Entity().addComponent(aiTaskComponent).addComponent(new PhysicsMovementComponent()); - entity.create(); - - // Register callbacks - EventListener0 callback = mock(EventListener0.class); - entity.getEvents().addListener("wanderStart", callback); - - wanderTask.start(); - - verify(callback).handle(); - } +// @Test +// void shouldTriggerEvent() { +// MobWanderTask mobWanderTask = new MobWanderTask(Vector2Utils.ONE, 1f); +// +// AITaskComponent aiTaskComponent = new AITaskComponent().addTask(mobWanderTask); +// Entity entity = new Entity().addComponent(aiTaskComponent).addComponent(new PhysicsMovementComponent()); +// entity.create(); +// +// // Register callbacks +// EventListener0 callback = mock(EventListener0.class); +// entity.getEvents().addListener("wanderStart", callback); +// +// mobWanderTask.start(); +// +// verify(callback).handle(); +// } } \ No newline at end of file