Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gregchan550 committed Oct 10, 2023
2 parents bc8c0e6 + 9a0ffde commit 25e27bb
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 109 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
48 changes: 26 additions & 22 deletions source/core/src/main/com/csse3200/game/areas/ForestGameArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,13 @@ public void create() {
// spawnSplittingXenoGrunt(17, 2);
// spawnPatrick();
// spawnDemonBoss();
spawnEffectProjectile(new Vector2(5f,2f), PhysicsLayer.HUMANS, 20, new Vector2(1f,1f), ProjectileEffects.STUN, false);

spawnScrap();
spawnGapScanners();

// spawnTNTTower();
// spawnWeaponTower();
spawnWeaponTower(new GridPoint2(2, 2));
// spawnGapScanners();
// spawnDroidTower();
// spawnFireWorksTower(); // Commented these out until they are needed for Demonstration
Expand Down Expand Up @@ -494,9 +495,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;
Expand Down Expand Up @@ -531,7 +532,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;
}

Expand Down Expand Up @@ -727,10 +728,11 @@ private void spawnDeflectWizard(int x, int y) {
// }
// }

private void spawnCoat() {
Entity gregMob = NPCFactory.createCoat(100);

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

/**
Expand Down Expand Up @@ -818,20 +820,22 @@ private void spawnSplitFireWorksFireBall(Vector2 position, short targetLayer, in
spawnEntity(projectile);
}

private void spawnWeaponTower() {
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);
}
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.createStunTower();
spawnEntityAt(fireTower, pos, true, true);
}

// * TEMPORARY FOR TESTING
Expand Down
151 changes: 151 additions & 0 deletions source/core/src/main/com/csse3200/game/components/EffectComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
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;
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;
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;

public class EffectComponent extends Component {
private static final long EFFECT_DURATION = 5000;
private final GameTime gameTime;
// effect flags
private boolean burnFlag;
private boolean slowFlag;
private boolean isSlowed;
private boolean stunFlag;
private boolean isStunned;
private boolean mob;
private Entity host;
private Entity target;
private long lastTimeBurned;
private long burnTime;
private long slowTime;
private long stunTime;
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;
this.gameTime = ServiceLocator.getTimeSource();
}

public void start() {
burnTime = 0;
slowTime = 0;
stunTime = 0;
}

@Override
public void update() {
// update effect flags
burnFlag = burnTime > gameTime.getTime();
slowFlag = slowTime > gameTime.getTime();
stunFlag = stunTime > gameTime.getTime();

// 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);
}

// apply stun effect
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) {
this.host = host;
this.target = target;
switch (effect) {
case BURN -> {
burnFlag = true;
burnTime = gameTime.getTime() + EFFECT_DURATION;
lastTimeBurned = gameTime.getTime();
}
case SLOW -> {
slowFlag = true;
slowTime = gameTime.getTime() + EFFECT_DURATION;
}
case STUN -> {
stunFlag = true;
stunTime = gameTime.getTime() + EFFECT_DURATION;
initialSpeed = entity.getComponent(PhysicsMovementComponent.class).getSpeed();
}
}
}

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(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(boolean stunned) {
isStunned = true;
AITaskComponent targetAI = target.getComponent(AITaskComponent.class);
if (targetAI == null) {
return;
}
if (stunned) {
targetAI.disposeAll();
} else {
targetAI.restore();
}
}
}
Loading

0 comments on commit 25e27bb

Please sign in to comment.