Skip to content

Commit

Permalink
changed stun functionality to just stop movement for mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 10, 2023
1 parent 2edb077 commit 73fe55d
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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> melee = new ArrayList<>(Arrays.asList(PredefinedWeapons.sword, PredefinedWeapons.kick));
// // tester projectiles
// ArrayList<ProjectileConfig> projectiles = new ArrayList<>(Arrays.asList(PredefinedWeapons.fireBall, PredefinedWeapons.frostBall));
// ArrayList<Currency> 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> melee = new ArrayList<>(Arrays.asList(PredefinedWeapons.sword, PredefinedWeapons.kick));
// tester projectiles
ArrayList<ProjectileConfig> projectiles = new ArrayList<>(Arrays.asList(PredefinedWeapons.fireBall, PredefinedWeapons.frostBall));
ArrayList<Currency> 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 =
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,23 @@ 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);
return mob;
}

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);
return mob;
}

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);
Expand Down

0 comments on commit 73fe55d

Please sign in to comment.