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..d5cd93db9 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 @@ -87,6 +87,7 @@ public void disposeAll() { priorityTasksToBeRestored.add(priorityTasks.get(i)); } for (int i = 0; i < priorityTasks.size(); i++) { + System.out.println(priorityTasks.get(i)); priorityTasks.remove(i); } } diff --git a/source/core/src/main/com/csse3200/game/components/EffectComponent.java b/source/core/src/main/com/csse3200/game/components/EffectComponent.java index cfd389edb..367be90dd 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectComponent.java @@ -5,6 +5,7 @@ import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.Component; import com.csse3200.game.components.ProjectileEffects; +import com.csse3200.game.components.tasks.MovementTask; import com.csse3200.game.components.tower.TowerUpgraderComponent; import com.csse3200.game.entities.Entity; import com.csse3200.game.physics.PhysicsLayer; @@ -22,6 +23,7 @@ public class EffectComponent extends Component { private boolean isSlowed; private boolean stunFlag; private boolean isStunned; + private boolean mob; private Entity host; private Entity target; private long lastTimeBurned; @@ -31,6 +33,7 @@ public class EffectComponent extends Component { private static long BURN_TICK = 1000; public EffectComponent(boolean mob) { + this.mob = mob; this.gameTime = ServiceLocator.getTimeSource(); } @@ -122,12 +125,23 @@ private void stunEffect(boolean stunned) { if (targetAI == null) { return; } + Vector2 targetInitialSpeed = target.getComponent(PhysicsMovementComponent.class).getSpeed(); + if (targetInitialSpeed == null) { + return; + } - if (stunned) { - targetAI.disposeAll(); - targetAI.dispose(); + if (mob) { + if (stunned) { + target.getComponent(PhysicsMovementComponent.class).setSpeed(new Vector2(0f,0f)); + } else { + target.getComponent(PhysicsMovementComponent.class).setSpeed(targetInitialSpeed); + } } else { - targetAI.restore(); + if (stunned) { + targetAI.disposeAll(); + } else { + targetAI.restore(); + } } } } 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 481497bd8..e2a081504 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,9 +9,14 @@ import com.csse3200.game.components.TouchAttackComponent; import com.csse3200.game.components.npc.*; import com.csse3200.game.components.tasks.MobDodgeTask; +import com.csse3200.game.components.tasks.MobMeleeAttackTask; +import com.csse3200.game.components.tasks.MobRangedAttackTask; import com.csse3200.game.components.tasks.MobTask.MobTask; import com.csse3200.game.components.tasks.MobTask.MobType; +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; import com.csse3200.game.entities.configs.*; import com.csse3200.game.files.FileLoader; import com.csse3200.game.physics.PhysicsLayer; @@ -24,6 +29,7 @@ import com.csse3200.game.rendering.TextureRenderComponent; import com.csse3200.game.services.ServiceLocator; import java.util.ArrayList; +import java.util.Arrays; import java.util.Currency; /** @@ -335,40 +341,40 @@ public static Entity createGregRangeMob(int health) { } -// /** -// * Creates a xeno grunt entity. -// * -// * @return entity -// */ -// public static Entity createXenoGrunt(int health) { -// Entity xenoGrunt = createMeleeBaseNPC(); -// BaseEnemyConfig config = configs.xenoGrunt; -// ArrayList melee = new ArrayList<>(Arrays.asList(PredefinedWeapons.sword, PredefinedWeapons.kick)); -// // tester projectiles -// ArrayList projectiles = new ArrayList<>(Arrays.asList(PredefinedWeapons.fireBall, PredefinedWeapons.frostBall)); -// ArrayList drops = new ArrayList<>(); -// -// AnimationRenderComponent animator = -// new AnimationRenderComponent( -// ServiceLocator.getResourceService().getAsset("images/mobs/xenoGrunt.atlas", TextureAtlas.class)); -// animator.addAnimation("xeno_run", 0.1f, Animation.PlayMode.LOOP); -// animator.addAnimation("xeno_hurt", 0.1f, Animation.PlayMode.LOOP); -// animator.addAnimation("xeno_shoot", 0.1f); -// animator.addAnimation("xeno_melee_1", 0.1f); -// animator.addAnimation("xeno_melee_2", 0.1f); -// animator.addAnimation("xeno_die", 0.1f); -// animator.addAnimation("default", 0.1f); -// xenoGrunt -// .addComponent(new CombatStatsComponent(health, config.baseAttack, drops, melee, projectiles)) -//// .addComponent(new CombatStatsComponent(config.fullHeath, config.baseAttack, drops, melee, projectiles)) -// .addComponent(animator) -// .addComponent(new XenoAnimationController()); -// -// xenoGrunt.getComponent(HitboxComponent.class).setAsBoxAligned(new Vector2(.3f, .5f), PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM); -// xenoGrunt.getComponent(AnimationRenderComponent.class).scaleEntity(); -// -// return xenoGrunt; -// } + /** + * Creates a xeno grunt entity. + * + * @return entity + */ + public static Entity createXenoGrunt(int health) { + Entity xenoGrunt = createMeleeBaseNPC(); + BaseEnemyConfig config = configs.xenoGrunt; + ArrayList melee = new ArrayList<>(Arrays.asList(PredefinedWeapons.sword, PredefinedWeapons.kick)); + // tester projectiles + ArrayList projectiles = new ArrayList<>(Arrays.asList(PredefinedWeapons.fireBall, PredefinedWeapons.frostBall)); + ArrayList drops = new ArrayList<>(); + + AnimationRenderComponent animator = + new AnimationRenderComponent( + ServiceLocator.getResourceService().getAsset("images/mobs/xenoGrunt.atlas", TextureAtlas.class)); + animator.addAnimation("xeno_run", 0.1f, Animation.PlayMode.LOOP); + animator.addAnimation("xeno_hurt", 0.1f, Animation.PlayMode.LOOP); + animator.addAnimation("xeno_shoot", 0.1f); + animator.addAnimation("xeno_melee_1", 0.1f); + animator.addAnimation("xeno_melee_2", 0.1f); + animator.addAnimation("xeno_die", 0.1f); + animator.addAnimation("default", 0.1f); + xenoGrunt + .addComponent(new CombatStatsComponent(health, config.baseAttack, drops, melee, projectiles)) +// .addComponent(new CombatStatsComponent(config.fullHeath, config.baseAttack, drops, melee, projectiles)) + .addComponent(animator) + .addComponent(new XenoAnimationController()); + + xenoGrunt.getComponent(HitboxComponent.class).setAsBoxAligned(new Vector2(.3f, .5f), PhysicsComponent.AlignX.RIGHT, PhysicsComponent.AlignY.BOTTOM); + xenoGrunt.getComponent(AnimationRenderComponent.class).scaleEntity(); + + return xenoGrunt; + } public static Entity createBaseNPC() { Entity npc = @@ -383,56 +389,56 @@ public static Entity createBaseNPC() { return npc; } -// /** -// * Creates a generic NPC to be used as a base entity by more specific NPC creation methods. -// * -// * @return entity -// */ -// public static Entity createMeleeBaseNPC() { -// AITaskComponent aiComponent = -// new AITaskComponent() -// .addTask(new MobWanderTask(new Vector2(2f, 2f), 2f)) -// .addTask(new MobMeleeAttackTask(2, 2f)); -// // .addTask(new MobAttackTask(2, 2f)); -// // .addTask(new MeleeMobTask(new Vector2(2f, 2f), 2f)); -// -// // .addTask(new MobAttackTask(2, 40)); -// Entity npc = -// new Entity() -// .addComponent(new PhysicsComponent()) -// .addComponent(new PhysicsMovementComponent()) -// .addComponent(new ColliderComponent()) -// .addComponent(new HitboxComponent().setLayer(PhysicsLayer.XENO)) -// .addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS)) -// .addComponent(aiComponent); -// PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f); -// return npc; -// } -// /** -// * Creates a generic NPC to be used as a base entity by more specific NPC creation methods. -// * -// * @return entity -// */ -// public static Entity createRangedBaseNPC() { -// AITaskComponent aiComponent = -// new AITaskComponent() -// .addTask(new MobWanderTask(new Vector2(2f, 2f), 2f)) -// // .addTask(new MobAttackTask(2, 2f)); -// .addTask(new MobRangedAttackTask(2, 2f)); -// // .addTask(new MeleeMobTask(new Vector2(2f, 2f), 2f)); -// -// // .addTask(new MobAttackTask(2, 40)); -// Entity npc = -// new Entity() -// .addComponent(new PhysicsComponent()) -// .addComponent(new PhysicsMovementComponent()) -// .addComponent(new ColliderComponent()) -// .addComponent(new HitboxComponent().setLayer(PhysicsLayer.XENO)) -// .addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS)) -// .addComponent(aiComponent); -// PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f); -// return npc; -// } + /** + * Creates a generic NPC to be used as a base entity by more specific NPC creation methods. + * + * @return entity + */ + public static Entity createMeleeBaseNPC() { + AITaskComponent aiComponent = + new AITaskComponent() + .addTask(new MobWanderTask(new Vector2(2f, 2f), 2f)) + .addTask(new MobMeleeAttackTask(2, 2f)); + // .addTask(new MobAttackTask(2, 2f)); + // .addTask(new MeleeMobTask(new Vector2(2f, 2f), 2f)); + + // .addTask(new MobAttackTask(2, 40)); + Entity npc = + new Entity() + .addComponent(new PhysicsComponent()) + .addComponent(new PhysicsMovementComponent()) + .addComponent(new ColliderComponent()) + .addComponent(new HitboxComponent().setLayer(PhysicsLayer.XENO)) + .addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS)) + .addComponent(aiComponent); + PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f); + return npc; + } + /** + * Creates a generic NPC to be used as a base entity by more specific NPC creation methods. + * + * @return entity + */ + public static Entity createRangedBaseNPC() { + AITaskComponent aiComponent = + new AITaskComponent() + .addTask(new MobWanderTask(new Vector2(2f, 2f), 2f)) + // .addTask(new MobAttackTask(2, 2f)); + .addTask(new MobRangedAttackTask(2, 2f)); + // .addTask(new MeleeMobTask(new Vector2(2f, 2f), 2f)); + + // .addTask(new MobAttackTask(2, 40)); + Entity npc = + new Entity() + .addComponent(new PhysicsComponent()) + .addComponent(new PhysicsMovementComponent()) + .addComponent(new ColliderComponent()) + .addComponent(new HitboxComponent().setLayer(PhysicsLayer.XENO)) + .addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS)) + .addComponent(aiComponent); + PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f); + return npc; + } private NPCFactory() { throw new IllegalStateException("Instantiating static util class"); diff --git a/source/core/src/test/com/csse3200/game/components/DeflectingComponentTest.java b/source/core/src/test/com/csse3200/game/components/DeflectingComponentTest.java index 735af2f17..4a1118802 100644 --- a/source/core/src/test/com/csse3200/game/components/DeflectingComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/DeflectingComponentTest.java @@ -220,7 +220,7 @@ public void shouldNotChangeHealthWhenDisabled() { } Entity createDeflectMob(int amount, float posX, float posY) { - Entity mob = NPCFactory.createRangedBaseNPC(); + Entity mob = NPCFactory.createBaseNPC(); mob.addComponent(new DeflectingComponent(PhysicsLayer.PROJECTILE, PhysicsLayer.TOWER, amount)); mob.addComponent(new CombatStatsComponent(DEFAULT_ATTACK, DEFAULT_DEFENSE)); diff --git a/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java b/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java index 95e0b60fd..7b23c77b6 100644 --- a/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java +++ b/source/core/src/test/com/csse3200/game/components/DodgingComponentTest.java @@ -91,7 +91,7 @@ public void shouldInvokeDodgeEvent() { } Entity createDodgeMob(float posX, float posY) { - Entity mob = NPCFactory.createRangedBaseNPC(); + Entity mob = NPCFactory.createBaseNPC(); mob.addComponent(new CombatStatsComponent(10, 10)); mob.addComponent(new DodgingComponent(PhysicsLayer.PROJECTILE)); @@ -102,7 +102,7 @@ Entity createDodgeMob(float posX, float posY) { Entity createDodgeMob(float posX, float posY, float rangeDetection, float dodgeSpeed) { - Entity mob = NPCFactory.createRangedBaseNPC(); + Entity mob = NPCFactory.createBaseNPC(); mob.addComponent(new CombatStatsComponent(10, 10)); mob.addComponent(new DodgingComponent(PhysicsLayer.PROJECTILE, rangeDetection, dodgeSpeed)); diff --git a/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java b/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java index 81731a2ff..bbc733275 100644 --- a/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java +++ b/source/core/src/test/com/csse3200/game/components/SplitMoblingsTest.java @@ -309,7 +309,7 @@ public void shouldScaleXAndYbasedOnParamsMultiAmt() { } Entity createSplitMob(int amount) { - Entity mob = NPCFactory.createRangedBaseNPC(); + Entity mob = NPCFactory.createBaseNPC(); mob.addComponent(new CombatStatsComponent(10, 10)); mob.addComponent(new SplitMoblings(amount)); ServiceLocator.getEntityService().register(mob); @@ -317,7 +317,7 @@ Entity createSplitMob(int amount) { } Entity createSplitMob(int amount, float scale) { - Entity mob = NPCFactory.createRangedBaseNPC(); + Entity mob = NPCFactory.createBaseNPC(); mob.addComponent(new SplitMoblings(amount, scale)); mob.addComponent(new CombatStatsComponent(10, 10)); ServiceLocator.getEntityService().register(mob); @@ -325,7 +325,7 @@ Entity createSplitMob(int amount, float scale) { } Entity createSplitMob(int amount, float scaleX, float scaleY) { - Entity mob = NPCFactory.createRangedBaseNPC(); + Entity mob = NPCFactory.createBaseNPC(); mob.addComponent(new SplitMoblings(amount, scaleX, scaleY)); mob.addComponent(new CombatStatsComponent(10, 10)); ServiceLocator.getEntityService().register(mob);