From cd52e05a9ba348e7776daf898919ff08121cf12b Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Fri, 6 Oct 2023 08:25:48 +1000 Subject: [PATCH 1/8] changed demon jumpComplete to rely on animation so the slow effect wouldn't mess up the animation --- .../com/csse3200/game/areas/ForestGameArea.java | 15 ++++++++------- .../components/tasks/bosstask/DemonBossTask.java | 8 +++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 43e3408ef..dc7a2b224 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -320,10 +320,11 @@ public void create() { // Set up infrastructure for end game tracking player = spawnPlayer(); - waves = WaveFactory.createWaves(); - spawnEntity(waves); - waves.getEvents().addListener("spawnWave", this::spawnMob); +// waves = WaveFactory.createWaves(); +// spawnEntity(waves); +// waves.getEvents().addListener("spawnWave", this::spawnMob); // spawnGregMob(); + spawnDemonBoss(); spawnScrap(); spawnGapScanners(); @@ -395,10 +396,10 @@ private Entity spawnPlayer(GridPoint2 position) { } // commented 383 - 386 out as there was a missing arg? -// private void spawnDemonBoss() { -// Entity demon = MobBossFactory.createDemonBoss(); -// spawnEntityAt(demon, new GridPoint2(19, 5), true, false); -// } + private void spawnDemonBoss() { + Entity demon = MobBossFactory.createDemonBoss(5000); + spawnEntityAt(demon, new GridPoint2(19, 5), true, false); + } private void spawnPatrick() { Entity patrick = MobBossFactory.createPatrickBoss(3000); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java index 6349e51ab..e77461793 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java @@ -338,12 +338,18 @@ private Vector2 getJumpPos() { * @return if demon has completed jump or not */ private boolean jumpComplete() { - if (currentPos.dst(jumpPos) <= STOP_DISTANCE && isJumping) { + if (animation.isFinished() && isJumping) { applyAoeDamage(getNearbyHumans(SMASH_RADIUS), SMASH_DAMAGE); // do damage upon landing isJumping = false; jumpTask.stop(); return true; } +// if (currentPos.dst(jumpPos) <= STOP_DISTANCE && isJumping) { +// applyAoeDamage(getNearbyHumans(SMASH_RADIUS), SMASH_DAMAGE); // do damage upon landing +// isJumping = false; +// jumpTask.stop(); +// return true; +// } return false; } From e0aa90f40529ae490690cfc8ca76e713ac405ac1 Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Mon, 9 Oct 2023 19:49:50 +1000 Subject: [PATCH 2/8] created new component to handle mob effects given by projectiles --- .../csse3200/game/areas/ForestGameArea.java | 6 +- .../components/npc/MobEffectComponent.java | 58 +++++++++++++++++++ .../components/tasks/MobTask/MobTask.java | 1 + 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 source/core/src/main/com/csse3200/game/components/npc/MobEffectComponent.java diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index d2a2ccdf6..4698d2515 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -335,7 +335,7 @@ public void create() { spawnGapScanners(); // spawnTNTTower(); -// spawnWeaponTower(); + spawnWeaponTower(new GridPoint2(10, 4)); // spawnGapScanners(); // spawnDroidTower(); // spawnFireWorksTower(); // Commented these out until they are needed for Demonstration @@ -818,7 +818,7 @@ private void spawnSplitFireWorksFireBall(Vector2 position, short targetLayer, in spawnEntity(projectile); } - private void spawnWeaponTower() { + private void spawnWeaponTower(GridPoint2 pos) { GridPoint2 minPos = new GridPoint2(0, 0); GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1); @@ -832,6 +832,8 @@ private void spawnWeaponTower() { spawnEntityAt(stunTower, randomPos2, true, true); spawnEntityAt(wallTower, randomPos2, true, true); } +// Entity fireTower = TowerFactory.createDroidTower(); +// spawnEntityAt(fireTower, pos, true, true); } // * TEMPORARY FOR TESTING diff --git a/source/core/src/main/com/csse3200/game/components/npc/MobEffectComponent.java b/source/core/src/main/com/csse3200/game/components/npc/MobEffectComponent.java new file mode 100644 index 000000000..8005dfb39 --- /dev/null +++ b/source/core/src/main/com/csse3200/game/components/npc/MobEffectComponent.java @@ -0,0 +1,58 @@ +package com.csse3200.game.components.npc; + +import com.csse3200.game.components.Component; +import com.csse3200.game.components.ProjectileEffects; +import com.csse3200.game.services.GameTime; +import com.csse3200.game.services.ServiceLocator; + +public class MobEffectComponent extends Component { + private static final long EFFECT_DURATION = 5000; + private GameTime gameTime; + // effect flags + private boolean burnFlag; + private boolean slowFlag; + private boolean stunFlag; + private long burnTime; + private long slowTime; + private long stunTime; + + public MobEffectComponent() { + gameTime = ServiceLocator.getTimeSource(); + } + + public void start() { + burnTime = 0; + slowTime = 0; + stunTime = 0; + } + + @Override + public void update() { + // update effect flags + if (burnTime > gameTime.getTime()) { + burnFlag = true; + } else { + burnFlag = false; + } + if (slowTime > gameTime.getTime()) { + slowFlag = true; + } else { + slowFlag = false; + } + if (stunTime > gameTime.getTime()) { + stunFlag = true; + } else { + stunFlag = false; + } + + // apply effects + + } + public void applyEffect(ProjectileEffects effect) { + switch (effect) { + case BURN -> burnTime = gameTime.getTime() + EFFECT_DURATION; + case SLOW -> slowTime = gameTime.getTime() + EFFECT_DURATION; + case STUN -> stunTime = gameTime.getTime() + EFFECT_DURATION; + } + } +} 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 50076b40b..27e21b7a3 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 @@ -5,6 +5,7 @@ import com.csse3200.game.ai.tasks.DefaultTask; import com.csse3200.game.ai.tasks.PriorityTask; import com.csse3200.game.components.CombatStatsComponent; +import com.csse3200.game.components.EffectsComponent; import com.csse3200.game.components.ProjectileEffects; import com.csse3200.game.components.tasks.MovementTask; import com.csse3200.game.entities.Entity; From 5fa61bfca2c9b4de2d5c651f853bb12a2cdc901a Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Mon, 9 Oct 2023 21:51:39 +1000 Subject: [PATCH 3/8] burn functionality complete for towers and mobs --- .../csse3200/game/areas/ForestGameArea.java | 23 ++++---- ...ectComponent.java => EffectComponent.java} | 52 +++++++++---------- ...t.java => ProjectileEffectsComponent.java} | 10 ++-- .../components/tasks/MobTask/MobTask.java | 2 +- .../game/entities/factories/NPCFactory.java | 9 +--- .../entities/factories/PlayerFactory.java | 2 + .../entities/factories/ProjectileFactory.java | 8 +-- 7 files changed, 50 insertions(+), 56 deletions(-) rename source/core/src/main/com/csse3200/game/components/{npc/MobEffectComponent.java => EffectComponent.java} (59%) rename source/core/src/main/com/csse3200/game/components/{EffectsComponent.java => ProjectileEffectsComponent.java} (96%) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 5079b61c8..fd4b3ae56 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -326,12 +326,13 @@ public void create() { // waves.getEvents().addListener("spawnWave", this::spawnMob); // spawnGregMob(); // spawnDemonBoss(); + spawnEffectProjectile(new Vector2(2f,2f), PhysicsLayer.HUMANS, -1, new Vector2(1f,1f), ProjectileEffects.BURN, false); spawnScrap(); spawnGapScanners(); // spawnTNTTower(); - spawnWeaponTower(new GridPoint2(10, 4)); +// spawnWeaponTower(new GridPoint2(10, 4)); // spawnGapScanners(); // spawnDroidTower(); // spawnFireWorksTower(); // Commented these out until they are needed for Demonstration @@ -489,9 +490,9 @@ private void spawnProjectile(Vector2 position, short targetLayer, int space, int public void spawnMob(String entity, GridPoint2 randomPos, int health) { Entity mob; switch (entity) { - case "Xeno": - mob = NPCFactory.createXenoGrunt(health); - break; +// case "Xeno": +// mob = NPCFactory.createDragonKnight(health); +// break; case "SplittingWaterSlime": mob = NPCFactory.createSplittingWaterSlime(health); break; @@ -521,7 +522,7 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) { mob = MobBossFactory.createPatrickBoss(health); break; default: - mob = NPCFactory.createXenoGrunt(health); + mob = NPCFactory.createDragonKnight(health); break; } @@ -623,12 +624,12 @@ public void spawnMob(String entity, GridPoint2 randomPos, int health) { // spawnEntityAt(waterSlime, randomPos, true, false); // } // } - private void spawnSplittingXenoGrunt(int x, int y) { - GridPoint2 pos = new GridPoint2(x, y); - Entity xenoGrunt = NPCFactory.createSplittingXenoGrunt(100); - xenoGrunt.setScale(1.5f, 1.5f); - spawnEntityAt(xenoGrunt, pos, true, true); - } +// private void spawnSplittingXenoGrunt(int x, int y) { +// GridPoint2 pos = new GridPoint2(x, y); +// Entity xenoGrunt = NPCFactory.createSplittingXenoGrunt(100); +// xenoGrunt.setScale(1.5f, 1.5f); +// spawnEntityAt(xenoGrunt, pos, true, true); +// } // * TEMPORARY FOR TESTING private void spawnDodgingDragonKnight(int x, int y) { diff --git a/source/core/src/main/com/csse3200/game/components/npc/MobEffectComponent.java b/source/core/src/main/com/csse3200/game/components/EffectComponent.java similarity index 59% rename from source/core/src/main/com/csse3200/game/components/npc/MobEffectComponent.java rename to source/core/src/main/com/csse3200/game/components/EffectComponent.java index b5b05965f..1246a998b 100644 --- a/source/core/src/main/com/csse3200/game/components/npc/MobEffectComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectComponent.java @@ -1,4 +1,4 @@ -package com.csse3200.game.components.npc; +package com.csse3200.game.components; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.Component; @@ -7,19 +7,22 @@ import com.csse3200.game.services.GameTime; import com.csse3200.game.services.ServiceLocator; -public class MobEffectComponent extends Component { +public class EffectComponent extends Component { private static final long EFFECT_DURATION = 5000; private GameTime gameTime; // effect flags private boolean burnFlag; private boolean slowFlag; private boolean stunFlag; + private Entity host; + private Entity target; + private long lastTimeBurned; private long burnTime; private long slowTime; private long stunTime; private static long BURN_TICK = 1000; - public MobEffectComponent() { + public EffectComponent() { this.gameTime = ServiceLocator.getTimeSource(); } @@ -32,49 +35,42 @@ public void start() { @Override public void update() { // update effect flags - if (burnTime > gameTime.getTime()) { - burnFlag = true; - } else { - burnFlag = false; - } - if (slowTime > gameTime.getTime()) { - slowFlag = true; - } else { - slowFlag = false; - } - if (stunTime > gameTime.getTime()) { - stunFlag = true; - } else { - stunFlag = false; + burnFlag = burnTime > gameTime.getTime(); + slowFlag = slowTime > gameTime.getTime(); + stunFlag = stunTime > gameTime.getTime(); + + // apply effects + if (burnFlag && gameTime.getTime() > lastTimeBurned + BURN_TICK) { + burnEffect(); } } public void applyEffect(ProjectileEffects effect, Entity host, Entity target) { + this.host = host; + this.target = target; switch (effect) { case BURN -> { + burnFlag = true; burnTime = gameTime.getTime() + EFFECT_DURATION; - burnEffect(host, target); + lastTimeBurned = gameTime.getTime(); } case SLOW -> { + slowFlag = true; slowTime = gameTime.getTime() + EFFECT_DURATION; slowEffect(host, target); } case STUN -> { + stunFlag = true; stunTime = gameTime.getTime() + EFFECT_DURATION; stunEffect(host, target); } } } - private void burnEffect(Entity host, Entity target) { - long lastTimeHit = gameTime.getTime(); - while(burnFlag) { - CombatStatsComponent hostCombat = host.getComponent(CombatStatsComponent.class); - CombatStatsComponent targetCombat = target.getComponent(CombatStatsComponent.class); - if (gameTime.getTime() > lastTimeHit + BURN_TICK) { - lastTimeHit = gameTime.getTime(); - targetCombat.hit(hostCombat); - } - } + private void burnEffect() { + CombatStatsComponent hostCombat = this.host.getComponent(CombatStatsComponent.class); + CombatStatsComponent targetCombat = this.target.getComponent(CombatStatsComponent.class); + targetCombat.hit(hostCombat); + lastTimeBurned = gameTime.getTime(); } private void slowEffect(Entity host, Entity target) { diff --git a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java b/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java similarity index 96% rename from source/core/src/main/com/csse3200/game/components/EffectsComponent.java rename to source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java index 7970915fb..9f321732e 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectsComponent.java +++ b/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java @@ -5,7 +5,6 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Fixture; import com.csse3200.game.ai.tasks.AITaskComponent; -import com.csse3200.game.components.npc.MobEffectComponent; import com.csse3200.game.components.tower.TowerUpgraderComponent; import com.csse3200.game.entities.Entity; import com.csse3200.game.physics.BodyUserData; @@ -24,7 +23,7 @@ * slow, and stun. Component also handles the targeting of specific layers and an area of effect * application of effects. */ -public class EffectsComponent extends Component { +public class ProjectileEffectsComponent extends Component { private final float radius; private final ProjectileEffects effect; private final boolean aoe; @@ -38,7 +37,7 @@ public class EffectsComponent extends Component { * * @param radius The radius of the area-of-effect. */ - public EffectsComponent(short targetLayer, float radius, ProjectileEffects effect, boolean aoe) { + public ProjectileEffectsComponent(short targetLayer, float radius, ProjectileEffects effect, boolean aoe) { this.targetLayer = targetLayer; this.radius = radius; this.effect = effect; @@ -88,6 +87,7 @@ private void onCollisionEnd(Fixture me, Fixture other) { * @param effect effect to be applied to entity */ public void applySingleEffect(ProjectileEffects effect, Entity targetEntity) { + System.out.println("apply"); Entity hostEntity = getEntity(); CombatStatsComponent hostCombatStats = hostEntity.getComponent(CombatStatsComponent.class); @@ -97,7 +97,7 @@ public void applySingleEffect(ProjectileEffects effect, Entity targetEntity) { } // apply effect - targetEntity.getComponent(MobEffectComponent.class).applyEffect( + targetEntity.getComponent(EffectComponent.class).applyEffect( effect, hostEntity, targetEntity); } /** @@ -127,7 +127,7 @@ public void applyAoeEffect(ProjectileEffects effect) { } // apply effect - targetEntity.getComponent(MobEffectComponent.class).applyEffect( + targetEntity.getComponent(EffectComponent.class).applyEffect( effect, hostEntity, targetEntity); } } 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 27e21b7a3..f8a221515 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 @@ -5,7 +5,7 @@ import com.csse3200.game.ai.tasks.DefaultTask; import com.csse3200.game.ai.tasks.PriorityTask; import com.csse3200.game.components.CombatStatsComponent; -import com.csse3200.game.components.EffectsComponent; +import com.csse3200.game.components.ProjectileEffectsComponent; import com.csse3200.game.components.ProjectileEffects; import com.csse3200.game.components.tasks.MovementTask; import com.csse3200.game.entities.Entity; 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 bec5f1655..8c7ee1bc6 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 @@ -5,17 +5,13 @@ import com.badlogic.gdx.math.Vector2; import com.csse3200.game.ai.tasks.AITaskComponent; import com.csse3200.game.components.CombatStatsComponent; +import com.csse3200.game.components.EffectComponent; 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; @@ -28,7 +24,6 @@ import com.csse3200.game.rendering.TextureRenderComponent; import com.csse3200.game.services.ServiceLocator; import java.util.ArrayList; -import java.util.Arrays; import java.util.Currency; /** @@ -381,7 +376,7 @@ public static Entity createBaseNPC() { .addComponent(new PhysicsComponent()) .addComponent(new PhysicsMovementComponent()) .addComponent(new ColliderComponent()) - .addComponent(new MobEffectComponent()) + .addComponent(new EffectComponent()) .addComponent(new HitboxComponent().setLayer(PhysicsLayer.NPC)) .addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS)); PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f); 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 d07b91497..be993d97a 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 @@ -2,6 +2,7 @@ import com.csse3200.game.ai.tasks.AITaskComponent; import com.csse3200.game.components.CombatStatsComponent; +import com.csse3200.game.components.EffectComponent; import com.csse3200.game.components.TouchAttackComponent; import com.csse3200.game.components.player.InventoryComponent; import com.csse3200.game.components.player.PlayerActions; @@ -47,6 +48,7 @@ public static Entity createPlayer() { .addComponent(new CombatStatsComponent(1000, 0)) .addComponent(new InventoryComponent(stats.gold)) .addComponent(inputComponent) + .addComponent(new EffectComponent()) .addComponent(new PlayerStatsDisplay()); PhysicsUtils.setScaledCollider(player, 0.6f, 0.3f); diff --git a/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java index ce160b65b..69ea2b0df 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/ProjectileFactory.java @@ -51,7 +51,7 @@ public static Entity createEffectProjectile(short targetLayer, Vector2 destinati switch (effect) { case FIREBALL -> { - projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.FIREBALL, aoe)); + projectile.addComponent(new ProjectileEffectsComponent(targetLayer, 3, ProjectileEffects.FIREBALL, aoe)); AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService() @@ -64,7 +64,7 @@ public static Entity createEffectProjectile(short targetLayer, Vector2 destinati .addComponent(new ProjectileAnimationController()); } case BURN -> { - projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.BURN, aoe)); + projectile.addComponent(new ProjectileEffectsComponent(targetLayer, 3, ProjectileEffects.BURN, aoe)); AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService() @@ -77,7 +77,7 @@ public static Entity createEffectProjectile(short targetLayer, Vector2 destinati .addComponent(new BurnEffectProjectileAnimationController()); } case SLOW -> { - projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.SLOW, aoe)); + projectile.addComponent(new ProjectileEffectsComponent(targetLayer, 3, ProjectileEffects.SLOW, aoe)); AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService() @@ -95,7 +95,7 @@ public static Entity createEffectProjectile(short targetLayer, Vector2 destinati return projectile; } case STUN -> { - projectile.addComponent(new EffectsComponent(targetLayer, 3, ProjectileEffects.STUN, aoe)); + projectile.addComponent(new ProjectileEffectsComponent(targetLayer, 3, ProjectileEffects.STUN, aoe)); AnimationRenderComponent animator = new AnimationRenderComponent( ServiceLocator.getResourceService() From 149448829afa024890797f4dcf437c8c470fca83 Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:02:00 +1000 Subject: [PATCH 4/8] added effect component to towers and finalised burn effect testing --- .../csse3200/game/areas/ForestGameArea.java | 34 +++++++++---------- .../ProjectileEffectsComponent.java | 14 +++++--- .../components/tasks/DroidCombatTask.java | 1 + .../game/entities/factories/TowerFactory.java | 4 ++- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index fd4b3ae56..0fe132deb 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -326,13 +326,13 @@ public void create() { // waves.getEvents().addListener("spawnWave", this::spawnMob); // spawnGregMob(); // spawnDemonBoss(); - spawnEffectProjectile(new Vector2(2f,2f), PhysicsLayer.HUMANS, -1, new Vector2(1f,1f), ProjectileEffects.BURN, false); + spawnEffectProjectile(new Vector2(10f,2f), PhysicsLayer.HUMANS, -1, new Vector2(1f,1f), ProjectileEffects.BURN, false); spawnScrap(); spawnGapScanners(); // spawnTNTTower(); -// spawnWeaponTower(new GridPoint2(10, 4)); + spawnWeaponTower(new GridPoint2(2, 2)); // spawnGapScanners(); // spawnDroidTower(); // spawnFireWorksTower(); // Commented these out until they are needed for Demonstration @@ -816,21 +816,21 @@ private void spawnSplitFireWorksFireBall(Vector2 position, short targetLayer, in } private void spawnWeaponTower(GridPoint2 pos) { - GridPoint2 minPos = new GridPoint2(0, 0); - GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1); - - for (int i = 0; i < NUM_WEAPON_TOWERS + 7 ; i++) { - GridPoint2 randomPos1 = RandomUtils.random(minPos, maxPos); - GridPoint2 randomPos2 = RandomUtils.random(minPos, maxPos); - Entity wallTower = TowerFactory.createWallTower(); - Entity fireTower = TowerFactory.createFireTower(); - Entity stunTower = TowerFactory.createStunTower(); - spawnEntityAt(fireTower, randomPos1, true, true); - spawnEntityAt(stunTower, randomPos2, true, true); - spawnEntityAt(wallTower, randomPos2, true, true); - } -// Entity fireTower = TowerFactory.createDroidTower(); -// spawnEntityAt(fireTower, pos, true, true); +// GridPoint2 minPos = new GridPoint2(0, 0); +// GridPoint2 maxPos = terrain.getMapBounds(0).sub(5, 1); +// +// for (int i = 0; i < NUM_WEAPON_TOWERS + 7 ; i++) { +// GridPoint2 randomPos1 = RandomUtils.random(minPos, maxPos); +// GridPoint2 randomPos2 = RandomUtils.random(minPos, maxPos); +// Entity wallTower = TowerFactory.createWallTower(); +// Entity fireTower = TowerFactory.createFireTower(); +// Entity stunTower = TowerFactory.createStunTower(); +// spawnEntityAt(fireTower, randomPos1, true, true); +// spawnEntityAt(stunTower, randomPos2, true, true); +// spawnEntityAt(wallTower, randomPos2, true, true); +// } + Entity fireTower = TowerFactory.createDroidTower(); + spawnEntityAt(fireTower, pos, true, true); } // * TEMPORARY FOR TESTING diff --git a/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java b/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java index 9f321732e..c64986dc8 100644 --- a/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java +++ b/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java @@ -97,8 +97,11 @@ public void applySingleEffect(ProjectileEffects effect, Entity targetEntity) { } // apply effect - targetEntity.getComponent(EffectComponent.class).applyEffect( - effect, hostEntity, targetEntity); + EffectComponent effectComponent = targetEntity.getComponent(EffectComponent.class); + if (effectComponent == null) { + return; + } + effectComponent.applyEffect(effect, hostEntity, targetEntity); } /** * Used for aoe projectiles to apply effects to all entities within the area of effect (radius). @@ -127,8 +130,11 @@ public void applyAoeEffect(ProjectileEffects effect) { } // apply effect - targetEntity.getComponent(EffectComponent.class).applyEffect( - effect, hostEntity, targetEntity); + EffectComponent effectComponent = targetEntity.getComponent(EffectComponent.class); + if (effectComponent == null) { + return; + } + effectComponent.applyEffect(effect, hostEntity, targetEntity); } } diff --git a/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java index 384549af7..8c05158d7 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java @@ -83,6 +83,7 @@ public void start() { */ @Override public void update() { + System.out.println(owner.getEntity().getComponent(CombatStatsComponent.class).getHealth()); if (timeSource.getTime() >= endTime) { updateTowerState(); if (towerState == STATE.SHOOT_UP || towerState == STATE.SHOOT_DOWN) { diff --git a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java index a92dbb234..8aabf9bfe 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java @@ -1,6 +1,7 @@ package com.csse3200.game.entities.factories; import com.badlogic.gdx.physics.box2d.Filter; +import com.csse3200.game.components.EffectComponent; import com.csse3200.game.components.tasks.DroidCombatTask; import com.csse3200.game.components.tasks.TNTTowerCombatTask; import com.csse3200.game.components.tasks.*; @@ -471,7 +472,8 @@ public static Entity createBaseTower() { .addComponent(new ColliderComponent()) .addComponent(new HitboxComponent().setLayer(PhysicsLayer.TOWER)) // TODO: we might have to change the names of the layers .addComponent(new PhysicsComponent().setBodyType(BodyType.StaticBody)) - .addComponent(new TowerUpgraderComponent()); + .addComponent(new TowerUpgraderComponent()) + .addComponent(new EffectComponent()); tower.setLayer(1); // Set priority to 1, which is 1 below scrap (which is 0) From c4fa82dd3f219ef49af69f904179ed7442aa159f Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:56:19 +1000 Subject: [PATCH 5/8] slow works against mobs and towers --- .../csse3200/game/areas/ForestGameArea.java | 10 ++--- .../game/components/EffectComponent.java | 43 ++++++++++++++++--- .../ProjectileEffectsComponent.java | 1 - .../components/tasks/DroidCombatTask.java | 3 +- .../components/tasks/MobTask/MobTask.java | 1 - .../game/entities/factories/NPCFactory.java | 2 +- .../entities/factories/PlayerFactory.java | 2 +- .../game/entities/factories/TowerFactory.java | 2 +- 8 files changed, 46 insertions(+), 18 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 0fe132deb..adbf8ac61 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -324,9 +324,9 @@ public void create() { // waves = WaveFactory.createWaves(); // spawnEntity(waves); // waves.getEvents().addListener("spawnWave", this::spawnMob); -// spawnGregMob(); + spawnGregMob(18, 2); // spawnDemonBoss(); - spawnEffectProjectile(new Vector2(10f,2f), PhysicsLayer.HUMANS, -1, new Vector2(1f,1f), ProjectileEffects.BURN, false); + spawnEffectProjectile(new Vector2(5f,2f), PhysicsLayer.HUMANS, -1, new Vector2(1f,1f), ProjectileEffects.SLOW, false); spawnScrap(); spawnGapScanners(); @@ -724,10 +724,10 @@ private void spawnDeflectWizard(int x, int y) { // } // } - private void spawnGregMob() { + private void spawnGregMob(int x, int y) { Entity gregMob = NPCFactory.createBaseWaterSlime(100); gregMob.setScale(1.5f, 1.5f); - spawnEntityAt(gregMob, new GridPoint2(17, 4), false, false); + spawnEntityAt(gregMob, new GridPoint2(x, y), false, false); } /** @@ -829,7 +829,7 @@ private void spawnWeaponTower(GridPoint2 pos) { // spawnEntityAt(stunTower, randomPos2, true, true); // spawnEntityAt(wallTower, randomPos2, true, true); // } - Entity fireTower = TowerFactory.createDroidTower(); + Entity fireTower = TowerFactory.createWeaponTower(); spawnEntityAt(fireTower, pos, true, true); } 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 1246a998b..ffca46c14 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectComponent.java @@ -1,9 +1,14 @@ package com.csse3200.game.components; +import com.badlogic.gdx.math.Vector2; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.Component; import com.csse3200.game.components.ProjectileEffects; +import com.csse3200.game.components.tower.TowerUpgraderComponent; import com.csse3200.game.entities.Entity; +import com.csse3200.game.physics.PhysicsLayer; +import com.csse3200.game.physics.components.HitboxComponent; +import com.csse3200.game.physics.components.PhysicsMovementComponent; import com.csse3200.game.services.GameTime; import com.csse3200.game.services.ServiceLocator; @@ -13,6 +18,7 @@ public class EffectComponent extends Component { // effect flags private boolean burnFlag; private boolean slowFlag; + private boolean isSlowed; private boolean stunFlag; private Entity host; private Entity target; @@ -22,7 +28,7 @@ public class EffectComponent extends Component { private long stunTime; private static long BURN_TICK = 1000; - public EffectComponent() { + public EffectComponent(boolean mob) { this.gameTime = ServiceLocator.getTimeSource(); } @@ -39,10 +45,19 @@ public void update() { slowFlag = slowTime > gameTime.getTime(); stunFlag = stunTime > gameTime.getTime(); - // apply effects + // apply burn effect if (burnFlag && gameTime.getTime() > lastTimeBurned + BURN_TICK) { burnEffect(); } + + // apply slow effect + if (slowFlag && !isSlowed) { + slowEffect(2); + } else if (!slowFlag && isSlowed) { + isSlowed = false; + slowEffect(5); + } + } public void applyEffect(ProjectileEffects effect, Entity host, Entity target) { this.host = host; @@ -56,12 +71,10 @@ public void applyEffect(ProjectileEffects effect, Entity host, Entity target) { case SLOW -> { slowFlag = true; slowTime = gameTime.getTime() + EFFECT_DURATION; - slowEffect(host, target); } case STUN -> { stunFlag = true; stunTime = gameTime.getTime() + EFFECT_DURATION; - stunEffect(host, target); } } } @@ -73,11 +86,29 @@ private void burnEffect() { lastTimeBurned = gameTime.getTime(); } - private void slowEffect(Entity host, Entity target) { + private void slowEffect(int amount) { + isSlowed = true; + if (PhysicsLayer.contains(PhysicsLayer.HUMANS, + target.getComponent(HitboxComponent.class).getLayer())) { + // if slowing human + target.getEvents().trigger("upgradeTower", + TowerUpgraderComponent.UPGRADE.FIRERATE, amount); + } else if (PhysicsLayer.contains(PhysicsLayer.NPC, + target.getComponent(HitboxComponent.class).getLayer())) { + // if slowing npc + PhysicsMovementComponent targetPhysics = target.getComponent( + PhysicsMovementComponent.class); + if (targetPhysics == null) { + return; + } + // Halve the mob speed + targetPhysics.setSpeed(new Vector2(targetPhysics.getSpeed().x/2, + targetPhysics.getSpeed().y/2)); + } } - private void stunEffect(Entity host, Entity target) { + private void stunEffect() { } } diff --git a/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java b/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java index c64986dc8..87a5c4a0a 100644 --- a/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java +++ b/source/core/src/main/com/csse3200/game/components/ProjectileEffectsComponent.java @@ -87,7 +87,6 @@ private void onCollisionEnd(Fixture me, Fixture other) { * @param effect effect to be applied to entity */ public void applySingleEffect(ProjectileEffects effect, Entity targetEntity) { - System.out.println("apply"); Entity hostEntity = getEntity(); CombatStatsComponent hostCombatStats = hostEntity.getComponent(CombatStatsComponent.class); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java b/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java index 8c05158d7..b40a3715a 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/DroidCombatTask.java @@ -83,7 +83,6 @@ public void start() { */ @Override public void update() { - System.out.println(owner.getEntity().getComponent(CombatStatsComponent.class).getHealth()); if (timeSource.getTime() >= endTime) { updateTowerState(); if (towerState == STATE.SHOOT_UP || towerState == STATE.SHOOT_DOWN) { @@ -91,7 +90,7 @@ public void update() { } else { endTime = timeSource.getTime() + (INTERVAL * 1000); } - } + } } /** 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 f8a221515..fc300e4c2 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 @@ -195,7 +195,6 @@ private void animate() { case RUN -> owner.getEntity().getEvents().trigger("water_slime_walk"); case ATTACK -> owner.getEntity().getEvents().trigger("water_slime_attack"); case DEATH -> { - System.out.println("hi"); owner.getEntity().getEvents().trigger("water_slime_death"); } case DEFAULT -> owner.getEntity().getEvents().trigger("default"); 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 8c7ee1bc6..481497bd8 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 @@ -376,7 +376,7 @@ public static Entity createBaseNPC() { .addComponent(new PhysicsComponent()) .addComponent(new PhysicsMovementComponent()) .addComponent(new ColliderComponent()) - .addComponent(new EffectComponent()) + .addComponent(new EffectComponent(true)) .addComponent(new HitboxComponent().setLayer(PhysicsLayer.NPC)) .addComponent(new TouchAttackComponent(PhysicsLayer.HUMANS)); PhysicsUtils.setScaledCollider(npc, 0.3f, 0.5f); 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 be993d97a..d48bae4b7 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 @@ -48,7 +48,7 @@ public static Entity createPlayer() { .addComponent(new CombatStatsComponent(1000, 0)) .addComponent(new InventoryComponent(stats.gold)) .addComponent(inputComponent) - .addComponent(new EffectComponent()) + .addComponent(new EffectComponent(false)) .addComponent(new PlayerStatsDisplay()); PhysicsUtils.setScaledCollider(player, 0.6f, 0.3f); diff --git a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java index 8aabf9bfe..d75f7ee14 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java @@ -473,7 +473,7 @@ public static Entity createBaseTower() { .addComponent(new HitboxComponent().setLayer(PhysicsLayer.TOWER)) // TODO: we might have to change the names of the layers .addComponent(new PhysicsComponent().setBodyType(BodyType.StaticBody)) .addComponent(new TowerUpgraderComponent()) - .addComponent(new EffectComponent()); + .addComponent(new EffectComponent(false)); tower.setLayer(1); // Set priority to 1, which is 1 below scrap (which is 0) From 2edb0776173c4f1bb856c7ed1b03a7b510eb7eea Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:22:13 +1000 Subject: [PATCH 6/8] stun works against towers but not mobs --- .../csse3200/game/areas/ForestGameArea.java | 4 ++-- .../game/components/EffectComponent.java | 21 ++++++++++++++++++- .../components/tasks/MobTask/MobTask.java | 1 - 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index adbf8ac61..7a4a7f81a 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -326,7 +326,7 @@ public void create() { // waves.getEvents().addListener("spawnWave", this::spawnMob); spawnGregMob(18, 2); // spawnDemonBoss(); - spawnEffectProjectile(new Vector2(5f,2f), PhysicsLayer.HUMANS, -1, new Vector2(1f,1f), ProjectileEffects.SLOW, false); + spawnEffectProjectile(new Vector2(5f,2f), PhysicsLayer.HUMANS, 20, new Vector2(1f,1f), ProjectileEffects.STUN, false); spawnScrap(); spawnGapScanners(); @@ -829,7 +829,7 @@ private void spawnWeaponTower(GridPoint2 pos) { // spawnEntityAt(stunTower, randomPos2, true, true); // spawnEntityAt(wallTower, randomPos2, true, true); // } - Entity fireTower = TowerFactory.createWeaponTower(); + Entity fireTower = TowerFactory.createStunTower(); spawnEntityAt(fireTower, pos, true, true); } 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 ffca46c14..cfd389edb 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectComponent.java @@ -1,6 +1,7 @@ package com.csse3200.game.components; import com.badlogic.gdx.math.Vector2; +import com.csse3200.game.ai.tasks.AITaskComponent; import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.Component; import com.csse3200.game.components.ProjectileEffects; @@ -20,6 +21,7 @@ public class EffectComponent extends Component { private boolean slowFlag; private boolean isSlowed; private boolean stunFlag; + private boolean isStunned; private Entity host; private Entity target; private long lastTimeBurned; @@ -58,6 +60,12 @@ public void update() { slowEffect(5); } + // apply stun effect + if (stunFlag && !isStunned) { + stunEffect(true); + } else if (!stunFlag && isStunned) { + stunEffect(false); + } } public void applyEffect(ProjectileEffects effect, Entity host, Entity target) { this.host = host; @@ -108,7 +116,18 @@ private void slowEffect(int amount) { } } - private void stunEffect() { + private void stunEffect(boolean stunned) { + isStunned = true; + AITaskComponent targetAI = target.getComponent(AITaskComponent.class); + if (targetAI == null) { + return; + } + if (stunned) { + targetAI.disposeAll(); + targetAI.dispose(); + } else { + targetAI.restore(); + } } } 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 fc300e4c2..02eb957e0 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 @@ -98,7 +98,6 @@ public void start() { */ @Override public void update() { - // death check if (mob.getComponent(CombatStatsComponent.class).getHealth() <= 0 && !deathFlag) { changeState(State.DEATH); From 73fe55d4a5e004cbb3cb1343f1d96f07d55fb887 Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:26:32 +1000 Subject: [PATCH 7/8] changed stun functionality to just stop movement for mobs --- .../game/ai/tasks/AITaskComponent.java | 1 + .../game/components/EffectComponent.java | 22 ++- .../game/entities/factories/NPCFactory.java | 174 +++++++++--------- .../components/DeflectingComponentTest.java | 2 +- .../game/components/DodgingComponentTest.java | 4 +- .../game/components/SplitMoblingsTest.java | 6 +- 6 files changed, 115 insertions(+), 94 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..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); From 9a0ffde54db4331feb9055cd2eb77bd45094f401 Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Tue, 10 Oct 2023 12:09:36 +1000 Subject: [PATCH 8/8] stun effect fully functional for mobs: constantly sets speed to 0 while its stunned --- .../game/components/EffectComponent.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) 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 367be90dd..7ffe399eb 100644 --- a/source/core/src/main/com/csse3200/game/components/EffectComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectComponent.java @@ -16,7 +16,7 @@ public class EffectComponent extends Component { private static final long EFFECT_DURATION = 5000; - private GameTime gameTime; + private final GameTime gameTime; // effect flags private boolean burnFlag; private boolean slowFlag; @@ -30,7 +30,9 @@ public class EffectComponent extends Component { private long burnTime; private long slowTime; private long stunTime; - private static long BURN_TICK = 1000; + private Vector2 initialSpeed; + private static final Vector2 STUN_SPEED = new Vector2(0f,0f); + private static final long BURN_TICK = 1000; public EffectComponent(boolean mob) { this.mob = mob; @@ -64,10 +66,24 @@ public void update() { } // apply stun effect - if (stunFlag && !isStunned) { - stunEffect(true); - } else if (!stunFlag && isStunned) { - stunEffect(false); + if (mob) { + if (stunFlag) { + if (initialSpeed == null) { + return; + } + target.getComponent(PhysicsMovementComponent.class).setSpeed(STUN_SPEED); + } else { + if (target == null) { + return; + } + target.getComponent(PhysicsMovementComponent.class).setSpeed(initialSpeed); + } + } else { + if (stunFlag && !isStunned) { + stunEffect(true); + } else if (!stunFlag && isStunned) { + stunEffect(false); + } } } public void applyEffect(ProjectileEffects effect, Entity host, Entity target) { @@ -86,6 +102,7 @@ public void applyEffect(ProjectileEffects effect, Entity host, Entity target) { case STUN -> { stunFlag = true; stunTime = gameTime.getTime() + EFFECT_DURATION; + initialSpeed = entity.getComponent(PhysicsMovementComponent.class).getSpeed(); } } } @@ -125,23 +142,10 @@ private void stunEffect(boolean stunned) { if (targetAI == null) { return; } - Vector2 targetInitialSpeed = target.getComponent(PhysicsMovementComponent.class).getSpeed(); - if (targetInitialSpeed == null) { - return; - } - - if (mob) { - if (stunned) { - target.getComponent(PhysicsMovementComponent.class).setSpeed(new Vector2(0f,0f)); - } else { - target.getComponent(PhysicsMovementComponent.class).setSpeed(targetInitialSpeed); - } + if (stunned) { + targetAI.disposeAll(); } else { - if (stunned) { - targetAI.disposeAll(); - } else { - targetAI.restore(); - } + targetAI.restore(); } } }