Skip to content

Commit

Permalink
stun works against towers but not mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 9, 2023
1 parent c4fa82d commit 2edb077
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public void start() {
*/
@Override
public void update() {

// death check
if (mob.getComponent(CombatStatsComponent.class).getHealth() <= 0 && !deathFlag) {
changeState(State.DEATH);
Expand Down

0 comments on commit 2edb077

Please sign in to comment.