Room.java clean-up

This commit is contained in:
Stankman 2023-07-23 20:18:43 -05:00
parent b80f3da289
commit cb154377e9
10 changed files with 57 additions and 73 deletions

View File

@ -52,11 +52,16 @@ public class InteractionDefault extends RoomItem {
public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) { public void onMove(Room room, RoomTile oldLocation, RoomTile newLocation) {
super.onMove(room, oldLocation, newLocation); super.onMove(room, oldLocation, newLocation);
//Check if there a no rollers
if (room.getRoomItemManager().getItemsAt(oldLocation).stream().noneMatch(item -> item.getClass().isAssignableFrom(InteractionRoller.class))) { if (room.getRoomItemManager().getItemsAt(oldLocation).stream().noneMatch(item -> item.getClass().isAssignableFrom(InteractionRoller.class))) {
for (RoomUnit unit : room.getRoomUnitManager().getCurrentRoomUnits().values()) { for (RoomUnit unit : room.getRoomUnitManager().getCurrentRoomUnits().values()) {
if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) if (!oldLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) {
continue; // If the unit was previously on the furni... continue; // If the unit was previously on the furni...
if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore... }
if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) {
continue; // but is not anymore...
}
try { try {
this.onWalkOff(unit, room, new Object[]{oldLocation, newLocation}); // the unit walked off! this.onWalkOff(unit, room, new Object[]{oldLocation, newLocation}); // the unit walked off!

View File

@ -179,7 +179,7 @@ public class InteractionObstacle extends RoomItem implements ICycleable {
} }
for(RoomTile tile : this.middleTiles) { for(RoomTile tile : this.middleTiles) {
for(RoomUnit roomUnit : tile.getRoomUnits()) { for(RoomUnit roomUnit : room.getRoomUnitManager().getRoomUnitsAt(tile)) {
if(roomUnit == null) { if(roomUnit == null) {
continue; continue;
} }

View File

@ -76,9 +76,7 @@ public class InteractionOneWayGate extends RoomItem {
if (unit == null) if (unit == null)
return; return;
if (tileInfront.getX() == unit.getCurrentPosition().getX()) { if (tileInfront.equals(unit.getCurrentPosition()) && !room.getRoomUnitManager().areRoomUnitsAt(currentLocation)) {
if (tileInfront.getY() == unit.getCurrentPosition().getY()) {
if (!currentLocation.hasUnits()) {
List<Runnable> onSuccess = new ArrayList<>(); List<Runnable> onSuccess = new ArrayList<>();
List<Runnable> onFail = new ArrayList<>(); List<Runnable> onFail = new ArrayList<>();
@ -122,8 +120,6 @@ public class InteractionOneWayGate extends RoomItem {
} }
} }
} }
}
}
private void refresh(Room room) { private void refresh(Room room) {
this.setExtradata("0"); this.setExtradata("0");

View File

@ -414,7 +414,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
boolean walkable = this.layout.tileWalkable(x, y); boolean walkable = this.layout.tileWalkable(x, y);
RoomTile tile = this.getLayout().getTile(x, y); RoomTile tile = this.getLayout().getTile(x, y);
if ((walkable && tile != null) && (tile.hasUnits() && !this.roomInfo.isAllowWalkthrough())) { if ((walkable && tile != null) && (this.roomUnitManager.areRoomUnitsAt(tile) && !this.roomInfo.isAllowWalkthrough())) {
walkable = false; walkable = false;
} }
@ -953,7 +953,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
itemsOnRoller.remove(roller); itemsOnRoller.remove(roller);
if (!rollerTile.hasUnits() && itemsOnRoller.isEmpty()) if (!this.roomUnitManager.areRoomUnitsAt(rollerTile) && itemsOnRoller.isEmpty())
return true; return true;
RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation()); RoomTile tileInFront = Room.this.layout.getTileInFront(Room.this.layout.getTile(roller.getX(), roller.getY()), roller.getRotation());
@ -970,7 +970,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.getState() == RoomTileState.SIT || tileInFront.getState() == RoomTileState.LAY)) if (!tileInFront.getAllowStack() && !(tileInFront.isWalkable() || tileInFront.getState() == RoomTileState.SIT || tileInFront.getState() == RoomTileState.LAY))
return true; return true;
if (tileInFront.hasUnits()) if (this.roomUnitManager.areRoomUnitsAt(tileInFront))
return true; return true;
THashSet<RoomItem> itemsNewTile = new THashSet<>(); THashSet<RoomItem> itemsNewTile = new THashSet<>();
@ -1025,9 +1025,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
roomUserRolledEvent = new UserRolledEvent(null, null, null); roomUserRolledEvent = new UserRolledEvent(null, null, null);
} }
ArrayList<RoomUnit> unitsOnTile = new ArrayList<>(rollerTile.getRoomUnits()); ArrayList<RoomUnit> unitsOnTile = new ArrayList<>(this.roomUnitManager.getRoomUnitsAt(rollerTile));
for (RoomUnit roomUnit : rollerTile.getRoomUnits()) { for (RoomUnit roomUnit : this.roomUnitManager.getRoomUnitsAt(rollerTile)) {
if (roomUnit instanceof RoomPet) { if (roomUnit instanceof RoomPet) {
Pet pet = this.roomUnitManager.getPetByRoomUnit(roomUnit); Pet pet = this.roomUnitManager.getPetByRoomUnit(roomUnit);
if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null) { if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null) {

View File

@ -304,7 +304,7 @@ public class RoomLayout {
continue; continue;
} }
if (currentAdj.hasUnits() && doorTile.distance(currentAdj) > 2 && (!isWalktroughRetry || !this.room.getRoomInfo().isAllowWalkthrough() || currentAdj.equals(goalLocation))) { if (this.room.getRoomUnitManager().areRoomUnitsAt(currentAdj) && doorTile.distance(currentAdj) > 2 && (!isWalktroughRetry || !this.room.getRoomInfo().isAllowWalkthrough() || currentAdj.equals(goalLocation))) {
closedList.add(currentAdj); closedList.add(currentAdj);
openList.remove(currentAdj); openList.remove(currentAdj);
continue; continue;

View File

@ -6,9 +6,7 @@ import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
public class RoomTile { public class RoomTile {
@Getter @Getter
@ -165,12 +163,6 @@ public class RoomTile {
return this.x == x && this.y == y; return this.x == x && this.y == y;
} }
public List<RoomUnit> getRoomUnits() {
synchronized (this.roomUnits) {
return new ArrayList<>(this.roomUnits);
}
}
public void addRoomUnit(RoomUnit roomUnit) { public void addRoomUnit(RoomUnit roomUnit) {
synchronized (this.roomUnits) { synchronized (this.roomUnits) {
if (!this.roomUnits.contains(roomUnit)) { if (!this.roomUnits.contains(roomUnit)) {
@ -185,12 +177,7 @@ public class RoomTile {
} }
} }
public boolean hasUnits() { //TODO Move this to RoomUnit
synchronized (this.roomUnits) {
return !this.roomUnits.isEmpty();
}
}
public boolean unitIsOnFurniOnTile(RoomUnit roomUnit, Item item) { public boolean unitIsOnFurniOnTile(RoomUnit roomUnit, Item item) {
if ((roomUnit.getCurrentPosition().getX() < this.x || roomUnit.getCurrentPosition().getX() >= this.x + item.getLength())) { if ((roomUnit.getCurrentPosition().getX() < this.x || roomUnit.getCurrentPosition().getX() >= this.x + item.getLength())) {
return false; return false;

View File

@ -2,18 +2,9 @@ package com.eu.habbo.habbohotel.rooms;
public enum RoomTileState { public enum RoomTileState {
OPEN, OPEN,
BLOCKED, BLOCKED,
INVALID, INVALID,
SIT, SIT,
LAY LAY
} }

View File

@ -160,9 +160,14 @@ public class RoomUnitManager {
return this.currentRoomUnits.values().stream().filter(roomUnit -> roomUnit.getCurrentPosition().equals(tile)).collect(Collectors.toSet()); return this.currentRoomUnits.values().stream().filter(roomUnit -> roomUnit.getCurrentPosition().equals(tile)).collect(Collectors.toSet());
} }
public boolean areRoomUnitsAt(RoomTile tile) {
return this.currentRoomUnits.values().stream().anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile));
}
public Collection<RoomUnit> getAvatarsAt(RoomTile tile) { public Collection<RoomUnit> getAvatarsAt(RoomTile tile) {
return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList()); return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList());
} }
public Collection<Habbo> getRoomHabbos() { public Collection<Habbo> getRoomHabbos() {
return this.currentRoomHabbos.values(); return this.currentRoomHabbos.values();
} }

View File

@ -88,7 +88,7 @@ public class RoomAvatar extends RoomUnit {
if (this.getPath().isEmpty()) { if (this.getPath().isEmpty()) {
this.setSitUpdate(true); this.setSitUpdate(true);
if (next != null && next.hasUnits() && !overrideChecks) { if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) {
this.setStatusUpdateNeeded(false); this.setStatusUpdateNeeded(false);
return false; return false;
} }

View File

@ -54,7 +54,7 @@ public class RoomPet extends RoomUnit {
if (this.getPath().isEmpty()) { if (this.getPath().isEmpty()) {
this.setSitUpdate(true); this.setSitUpdate(true);
if (next != null && next.hasUnits() && !overrideChecks) { if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) {
this.setStatusUpdateNeeded(false); this.setStatusUpdateNeeded(false);
return false; return false;
} }