From 7e44262764f874fa7195117af3ef1e24ddb4e5e0 Mon Sep 17 00:00:00 2001 From: gregchan550 Date: Wed, 6 Sep 2023 22:24:36 +1000 Subject: [PATCH] removed createAoeProjectile and instead replaced it with createEffectProjectile which has parameters that accepts different effects and whether it is an aoe projectile or not --- ...oeComponent.java => EffectsComponent.java} | 19 ++++- .../entities/factories/ProjectileFactory.java | 76 ++++++++++++++----- 2 files changed, 72 insertions(+), 23 deletions(-) rename source/core/src/main/com/csse3200/game/components/{AoeComponent.java => EffectsComponent.java} (77%) diff --git a/source/core/src/main/com/csse3200/game/components/AoeComponent.java b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java similarity index 77% rename from source/core/src/main/com/csse3200/game/components/AoeComponent.java rename to source/core/src/main/com/csse3200/game/components/EffectsComponent.java index 93403e8aa..e1e970ec5 100644 --- a/source/core/src/main/com/csse3200/game/components/AoeComponent.java +++ b/source/core/src/main/com/csse3200/game/components/EffectsComponent.java @@ -2,14 +2,16 @@ import com.badlogic.gdx.physics.box2d.Fixture; import com.csse3200.game.entities.Entity; -import com.csse3200.game.physics.BodyUserData; +import com.csse3200.game.entities.factories.ProjectileFactory; import com.csse3200.game.physics.components.HitboxComponent; import com.csse3200.game.services.ServiceLocator; import com.badlogic.gdx.utils.Array; -public class AoeComponent extends Component { +public class EffectsComponent extends Component { private final float radius; + private final ProjectileFactory.ProjectileEffects effect; + private final boolean aoe; private HitboxComponent hitboxComponent; /** @@ -17,8 +19,10 @@ public class AoeComponent extends Component { * * @param radius The radius of the area-of-effect. */ - public AoeComponent(float radius) { + public EffectsComponent(float radius, ProjectileFactory.ProjectileEffects effect, boolean aoe) { this.radius = radius; + this.effect = effect; + this.aoe = aoe; } @Override @@ -37,7 +41,14 @@ private void onCollisionEnd(Fixture me, Fixture other) { // Not triggered by hitbox, ignore return; } - applyAoeDamage(); + switch (effect) { + case FIREBALL -> { + applyAoeDamage(); + } + case BURN -> {} + case SLOW -> {} + case STUN -> {} + } } /** * Apply damage to all entities within the area of effect (radius). 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 33d596599..4d451d93f 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 @@ -1,6 +1,6 @@ package com.csse3200.game.entities.factories; -import com.csse3200.game.components.AoeComponent; +import com.csse3200.game.components.EffectsComponent; import com.csse3200.game.components.TouchAttackComponent; import com.csse3200.game.components.tasks.TrajectTask; import com.csse3200.game.ai.tasks.AITaskComponent; @@ -23,9 +23,47 @@ */ public class ProjectileFactory { + public enum ProjectileEffects { + FIREBALL, //fireball projectile - deals damage based on baseAttack + BURN, //burn projectile - does 5 extra ticks of damage over 5 seconds + SLOW, //slow projectile - slows entity by half for 5 seconds + STUN //stun projectile - stuns entity for 5 seconds + } + private static final NPCConfigs configs = FileLoader.readClass(NPCConfigs.class, "configs/NPCs.json"); + /** + * Creates a single-targeting projectile with specified effect + * + * @param target The enemy entities that the projectile collides with. + * @param destination The destination the projectile heads towards. + * @param speed The speed of the projectile. + * @param effect Specified effect from the ProjectileEffects enums + * @return Returns a new single-target projectile entity + */ + public static Entity createEffectProjectile(Entity target, Vector2 destination, Vector2 speed, + ProjectileEffects effect, boolean aoe) { + BaseEntityConfig config = configs.fireBall; + Entity projectile = createFireBall(target, destination, speed); + + switch(effect) { + case FIREBALL -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.FIREBALL, aoe)); + } + case BURN -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.BURN, aoe)); + } + case SLOW -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.SLOW, aoe)); + } + case STUN -> { + projectile.addComponent(new EffectsComponent(3, ProjectileEffects.STUN, aoe)); + } + } + return projectile; + } + /** * Creates a fireball Entity. * @@ -56,24 +94,24 @@ public static Entity createFireBall(Entity target, Vector2 destination, Vector2 return projectile; } - /** - * Creates an AOE fireball Entity. - * - * @param target The enemy entities that the projectile collides with. - * @param destination The destination the projectile heads towards. - * @param speed The speed of the projectile. - * @param aoeSize The size of the AOE. - * @return Returns the new aoe projectile entity. - */ - public static Entity createAOEFireBall(Entity target, Vector2 destination, Vector2 speed, int aoeSize) { - BaseEntityConfig config = configs.fireBall; - Entity projectile = createFireBall(target, destination, speed); - projectile - // This is the component that allows the projectile to damage a specified target. - .addComponent(new AoeComponent(aoeSize)); - - return projectile; - } +// /** +// * Creates an AOE fireball Entity. +// * +// * @param target The enemy entities that the projectile collides with. +// * @param destination The destination the projectile heads towards. +// * @param speed The speed of the projectile. +// * @param aoeSize The size of the AOE. +// * @return Returns the new aoe projectile entity. +// */ +// public static Entity createAOEFireBall(Entity target, Vector2 destination, Vector2 speed, int aoeSize) { +// BaseEntityConfig config = configs.fireBall; +// Entity projectile = createFireBall(target, destination, speed); +// projectile +// // This is the component that allows the projectile to damage a specified target. +// .addComponent(new EffectsComponent(aoeSize, ProjectileEffects.FIREBALL, true)); +// +// return projectile; +// } /** * Creates a generic projectile entity that can be used for multiple types of * projectiles.