Skip to content

Commit

Permalink
fix: account for rotation on tower destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Sep 30, 2024
1 parent 07cbddb commit 5515db1
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class PlacedTower<T extends TowerLevel> {
protected final int id;
protected final @NotNull Point basePoint;
protected final @NotNull Direction facing;
protected final @NotNull Rotation rotation;
protected final @NotNull GameUser owner;

protected @NotNull T level;
Expand All @@ -51,6 +52,7 @@ protected PlacedTower(@NotNull GameHandler gameHandler, Tower configuration, int
this.id = id;
this.basePoint = basePoint;
this.facing = facing;
this.rotation = Rotation.values()[DirectionUtil.fromDirection(facing).getTurns()];
this.owner = owner;

this.level = (T) configuration.getLevel(level);
Expand Down Expand Up @@ -106,10 +108,7 @@ public void upgrade(int level, @Nullable GameUser user) {
// todo re-investigate using a batch to apply in the future
// it was buggy last time it was tried
private void placeLevel() {
int turns = DirectionUtil.fromDirection(this.facing).getTurns();
Rotation rotation = Rotation.values()[turns];

this.level.getSchematic().apply(rotation, (relativePoint, block) -> {
this.level.getSchematic().apply(this.rotation, (relativePoint, block) -> {
// Add the ID_TAG with the tower's ID to each block
block = block.withTag(ID_TAG, this.id);

Expand All @@ -130,11 +129,8 @@ private void placeBase() {
}

private void removeNonUpdatedBlocks(TowerLevel oldLevel, TowerLevel newLevel) {
int turns = DirectionUtil.fromDirection(this.facing).getTurns();
Rotation rotation = Rotation.values()[turns];

Set<Point> oldRelativePoints = SchemUtils.getRelativeBlockPoints(rotation, oldLevel.getSchematic());
Set<Point> newRelativePoints = SchemUtils.getRelativeBlockPoints(rotation, newLevel.getSchematic());
Set<Point> oldRelativePoints = SchemUtils.getRelativeBlockPoints(this.rotation, oldLevel.getSchematic());
Set<Point> newRelativePoints = SchemUtils.getRelativeBlockPoints(this.rotation, newLevel.getSchematic());

TowerDefenceInstance instance = this.gameHandler.getInstance();
for (Point relativePoint : oldRelativePoints) {
Expand All @@ -148,7 +144,7 @@ public void destroy() {
Set<Point> relativePositions = this.getConfiguration().getLevels().stream()
.filter(level -> level.asInteger() <= this.level.asInteger())
.map(TowerLevel::getSchematic)
.map(schem -> SchemUtils.getRelativeBlockPoints(Rotation.NONE, schem))
.map(schem -> SchemUtils.getRelativeBlockPoints(this.rotation, schem))
.flatMap(Set::stream)
.collect(Collectors.toSet());

Expand Down

0 comments on commit 5515db1

Please sign in to comment.