Skip to content

Commit

Permalink
Fixed Citadel spawning outside Citadel
Browse files Browse the repository at this point in the history
  • Loading branch information
Slotterleet committed Apr 24, 2024
1 parent 1a647d9 commit 87d9c6a
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions src/fos/type/blocks/units/WaveSpawnerBlock.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package fos.type.blocks.units;

import arc.Events;
import arc.func.Cons;
import arc.graphics.g2d.TextureRegion;
import arc.math.Mathf;
import arc.util.*;
import arc.util.io.Writes;
import mindustry.Vars;
import mindustry.content.StatusEffects;
import mindustry.entities.Effect;
Expand Down Expand Up @@ -57,6 +59,21 @@ public void drawPlan(BuildPlan plan, Eachable<BuildPlan> list, boolean valid) {

@SuppressWarnings("unused")
public class WaveSpawnerBuild extends Building {
public Cons<EventType.WaveEvent> listener = e -> {
// mindustry's wave counter is a mess, so add 1
if (isValid() && Vars.state.wave == wave + 1) {
Time.run(spawnDelay, () -> {
Unit u = unitType.spawn(team, this);
u.rotation(90f);
if (boss) u.apply(StatusEffects.boss);

// consider this unit spawned from a wave.
Events.fire(new EventType.UnitSpawnEvent(u));

tileOn().remove();
});
}
};
public float progress;

@Override
Expand All @@ -77,21 +94,13 @@ public void drawLight() {

@Override
public void created() {
Events.on(EventType.WaveEvent.class, e -> {
// mindustry's wave counter is a mess, so add 1
if (isValid() && Vars.state.wave == wave + 1) {
Time.run(spawnDelay, () -> {
Unit u = unitType.spawn(team, this);
u.rotation(90f);
if (boss) u.apply(StatusEffects.boss);

// consider this unit spawned from a wave.
Events.fire(new EventType.UnitSpawnEvent(u));

tileOn().remove();
});
}
});
Events.on(EventType.WaveEvent.class, listener);
}

@Override
public void onRemoved() {
super.onRemoved();
Events.remove(EventType.WaveEvent.class, listener);
}

@Override
Expand All @@ -110,5 +119,12 @@ public void updateTile() {
public float totalProgress() {
return progress;
}

@Override
public void write(Writes write) {
// this actually does nothing IO-related, I just want to remove the event listener after world exit.
Events.remove(EventType.WaveEvent.class, listener);
Log.info("Removed listener?: @", listener);
}
}
}

0 comments on commit 87d9c6a

Please sign in to comment.