mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-26 16:30:52 +01:00
Room.java clean-up
This commit is contained in:
parent
b80f3da289
commit
cb154377e9
@ -52,11 +52,16 @@ public class InteractionDefault extends RoomItem {
|
||||
public void onMove(Room room, RoomTile oldLocation, RoomTile 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))) {
|
||||
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...
|
||||
if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) continue; // but is not anymore...
|
||||
}
|
||||
|
||||
if (newLocation.unitIsOnFurniOnTile(unit, this.getBaseItem())) {
|
||||
continue; // but is not anymore...
|
||||
}
|
||||
|
||||
try {
|
||||
this.onWalkOff(unit, room, new Object[]{oldLocation, newLocation}); // the unit walked off!
|
||||
|
@ -179,7 +179,7 @@ public class InteractionObstacle extends RoomItem implements ICycleable {
|
||||
}
|
||||
|
||||
for(RoomTile tile : this.middleTiles) {
|
||||
for(RoomUnit roomUnit : tile.getRoomUnits()) {
|
||||
for(RoomUnit roomUnit : room.getRoomUnitManager().getRoomUnitsAt(tile)) {
|
||||
if(roomUnit == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -76,9 +76,7 @@ public class InteractionOneWayGate extends RoomItem {
|
||||
if (unit == null)
|
||||
return;
|
||||
|
||||
if (tileInfront.getX() == unit.getCurrentPosition().getX()) {
|
||||
if (tileInfront.getY() == unit.getCurrentPosition().getY()) {
|
||||
if (!currentLocation.hasUnits()) {
|
||||
if (tileInfront.equals(unit.getCurrentPosition()) && !room.getRoomUnitManager().areRoomUnitsAt(currentLocation)) {
|
||||
List<Runnable> onSuccess = new ArrayList<>();
|
||||
List<Runnable> onFail = new ArrayList<>();
|
||||
|
||||
@ -122,8 +120,6 @@ public class InteractionOneWayGate extends RoomItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refresh(Room room) {
|
||||
this.setExtradata("0");
|
||||
|
@ -414,7 +414,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
boolean walkable = this.layout.tileWalkable(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;
|
||||
}
|
||||
|
||||
@ -953,7 +953,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
|
||||
itemsOnRoller.remove(roller);
|
||||
|
||||
if (!rollerTile.hasUnits() && itemsOnRoller.isEmpty())
|
||||
if (!this.roomUnitManager.areRoomUnitsAt(rollerTile) && itemsOnRoller.isEmpty())
|
||||
return true;
|
||||
|
||||
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))
|
||||
return true;
|
||||
|
||||
if (tileInFront.hasUnits())
|
||||
if (this.roomUnitManager.areRoomUnitsAt(tileInFront))
|
||||
return true;
|
||||
|
||||
THashSet<RoomItem> itemsNewTile = new THashSet<>();
|
||||
@ -1025,9 +1025,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
|
||||
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) {
|
||||
Pet pet = this.roomUnitManager.getPetByRoomUnit(roomUnit);
|
||||
if (pet instanceof RideablePet rideablePet && rideablePet.getRider() != null) {
|
||||
|
@ -304,7 +304,7 @@ public class RoomLayout {
|
||||
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);
|
||||
openList.remove(currentAdj);
|
||||
continue;
|
||||
|
@ -6,9 +6,7 @@ import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class RoomTile {
|
||||
@Getter
|
||||
@ -165,12 +163,6 @@ public class RoomTile {
|
||||
return this.x == x && this.y == y;
|
||||
}
|
||||
|
||||
public List<RoomUnit> getRoomUnits() {
|
||||
synchronized (this.roomUnits) {
|
||||
return new ArrayList<>(this.roomUnits);
|
||||
}
|
||||
}
|
||||
|
||||
public void addRoomUnit(RoomUnit roomUnit) {
|
||||
synchronized (this.roomUnits) {
|
||||
if (!this.roomUnits.contains(roomUnit)) {
|
||||
@ -185,12 +177,7 @@ public class RoomTile {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasUnits() {
|
||||
synchronized (this.roomUnits) {
|
||||
return !this.roomUnits.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Move this to RoomUnit
|
||||
public boolean unitIsOnFurniOnTile(RoomUnit roomUnit, Item item) {
|
||||
if ((roomUnit.getCurrentPosition().getX() < this.x || roomUnit.getCurrentPosition().getX() >= this.x + item.getLength())) {
|
||||
return false;
|
||||
|
@ -2,18 +2,9 @@ package com.eu.habbo.habbohotel.rooms;
|
||||
|
||||
|
||||
public enum RoomTileState {
|
||||
|
||||
OPEN,
|
||||
|
||||
|
||||
BLOCKED,
|
||||
|
||||
|
||||
INVALID,
|
||||
|
||||
|
||||
SIT,
|
||||
|
||||
|
||||
LAY
|
||||
}
|
||||
|
@ -160,9 +160,14 @@ public class RoomUnitManager {
|
||||
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) {
|
||||
return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Collection<Habbo> getRoomHabbos() {
|
||||
return this.currentRoomHabbos.values();
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class RoomAvatar extends RoomUnit {
|
||||
if (this.getPath().isEmpty()) {
|
||||
this.setSitUpdate(true);
|
||||
|
||||
if (next != null && next.hasUnits() && !overrideChecks) {
|
||||
if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) {
|
||||
this.setStatusUpdateNeeded(false);
|
||||
return false;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public class RoomPet extends RoomUnit {
|
||||
if (this.getPath().isEmpty()) {
|
||||
this.setSitUpdate(true);
|
||||
|
||||
if (next != null && next.hasUnits() && !overrideChecks) {
|
||||
if (next != null && room.getRoomUnitManager().areRoomUnitsAt(next) && !overrideChecks) {
|
||||
this.setStatusUpdateNeeded(false);
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user