Fixed a bunch of pathfinder bugs & improved performance

This commit is contained in:
Beny 2019-05-12 08:59:01 +01:00
parent 3c4c118d96
commit 40ab27002b
12 changed files with 155 additions and 155 deletions

View File

@ -102,6 +102,7 @@ public class InteractionTeleport extends HabboItem
walkable = this.getBaseItem().allowWalk(); walkable = this.getBaseItem().allowWalk();
room.updateTile(currentLocation); room.updateTile(currentLocation);
tryTeleport(client, room); tryTeleport(client, room);
unit.removeOverrideTile(currentLocation);
}); });
onFail.add(() -> { onFail.add(() -> {
@ -110,10 +111,12 @@ public class InteractionTeleport extends HabboItem
this.setExtradata("0"); this.setExtradata("0");
room.updateItem(this); room.updateItem(this);
this.roomUnitID = -1; this.roomUnitID = -1;
unit.removeOverrideTile(currentLocation);
}); });
walkable = true; walkable = true;
room.updateTile(currentLocation); room.updateTile(currentLocation);
unit.addOverrideTile(currentLocation);
unit.setGoalLocation(currentLocation); unit.setGoalLocation(currentLocation);
Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail)); Emulator.getThreading().run(new RoomUnitWalkToLocation(unit, currentLocation, room, onSuccess, onFail));
} }

View File

@ -11,6 +11,7 @@ import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.pets.PetLevelUpdatedComposer; import com.eu.habbo.messages.outgoing.rooms.pets.PetLevelUpdatedComposer;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetExperienceComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetExperienceComposer;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetRespectComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetRespectComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserRemoveComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTalkComposer; import com.eu.habbo.messages.outgoing.rooms.users.RoomUserTalkComposer;
import com.eu.habbo.plugin.events.pets.PetTalkEvent; import com.eu.habbo.plugin.events.pets.PetTalkEvent;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
@ -876,4 +877,24 @@ public class Pet implements ISerialize, Runnable
{ {
this.levelHunger = levelHunger; this.levelHunger = levelHunger;
} }
public void removeFromRoom() {
removeFromRoom(false);
}
public void removeFromRoom(boolean dontSendPackets) {
if(this.roomUnit != null && this.roomUnit.getCurrentLocation() != null) {
this.roomUnit.getCurrentLocation().removeUnit(this.roomUnit);
}
if(!dontSendPackets) {
room.sendComposer(new RoomUserRemoveComposer(this.roomUnit).compose());
room.removePet(this.id);
}
this.roomUnit = null;
this.room = null;
this.needsUpdate = true;
}
} }

View File

@ -701,59 +701,17 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
public boolean tileWalkable(short x, short y) public boolean tileWalkable(short x, short y)
{ {
boolean walkable = this.layout.tileWalkable(x, y); boolean walkable = this.layout.tileWalkable(x, y);
RoomTile tile = this.getLayout().getTile(x, y);
if (walkable) if (walkable && tile != null)
{ {
if (this.hasHabbosAt(x, y) && !this.allowWalkthrough) if (tile.hasUnits() && !this.allowWalkthrough)
{ {
walkable = false; walkable = false;
} }
} }
return walkable; //&& (!this.allowWalkthrough && !this.hasHabbosAt(x, y)));
//if(this.layout.tileWalkable(x, y))
//
//
//
//
//
//
//
return walkable;
} }
public void pickUpItem(HabboItem item, Habbo picker) public void pickUpItem(HabboItem item, Habbo picker)
@ -849,7 +807,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
else else
{ {
roomUnit.setZ(item.getZ() + item.getBaseItem().getHeight()); roomUnit.setZ(item.getZ() + Item.getCurrentHeight(item));
} }
if (oldZ != roomUnit.getZ()) if (oldZ != roomUnit.getZ())
@ -899,11 +857,11 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
else else
{ {
habbo.getRoomUnit().setZ(item.getZ() + item.getBaseItem().getHeight()); habbo.getRoomUnit().setZ(item.getZ() + Item.getCurrentHeight(item));
if (item.getBaseItem().allowLay()) if (item.getBaseItem().allowLay())
{ {
habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + item.getBaseItem().getHeight()) + ""); habbo.getRoomUnit().setStatus(RoomUnitStatus.LAY, (item.getZ() + Item.getCurrentHeight(item)) + "");
} }
} }
} }
@ -938,10 +896,9 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
for(Pet pet : pets) for(Pet pet : pets)
{ {
pet.setRoom(null); pet.removeFromRoom();
pet.needsUpdate = true; Emulator.getThreading().run(pet);
habbo.getInventory().getPetsComponent().addPet(pet); habbo.getInventory().getPetsComponent().addPet(pet);
this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose());
habbo.getClient().sendResponse(new AddPetComposer(pet)); habbo.getClient().sendResponse(new AddPetComposer(pet));
this.currentPets.remove(pet.getId()); this.currentPets.remove(pet.getId());
} }
@ -1596,7 +1553,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
for(HabboItem item : getItemsAt(rollerTile)) for(HabboItem item : getItemsAt(rollerTile))
{ {
if(item.getZ() >= roller.getZ() + roller.getBaseItem().getHeight()) { if(item.getZ() >= roller.getZ() + Item.getCurrentHeight(roller)) {
itemsOnRoller.add(item); itemsOnRoller.add(item);
} }
} }
@ -1689,7 +1646,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
else else
{ {
zOffset = -roller.getBaseItem().getHeight() + tileInFront.getStackHeight() - rollerTile.z; zOffset = -Item.getCurrentHeight(roller) + tileInFront.getStackHeight() - rollerTile.z;
} }
if (allowUsers) if (allowUsers)
@ -1917,7 +1874,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
if (!unit.isWalking() && !unit.cmdSit) if (!unit.isWalking() && !unit.cmdSit)
{ {
HabboItem topItem = this.getLowestChair(unit.getX(), unit.getY()); HabboItem topItem = this.getLowestChair(this.getLayout().getTile(unit.getX(), unit.getY()));
if (topItem == null || !topItem.getBaseItem().allowSit()) if (topItem == null || !topItem.getBaseItem().allowSit())
{ {
@ -1932,15 +1889,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
if (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate) if (!unit.hasStatus(RoomUnitStatus.SIT) || unit.sitUpdate)
{ {
this.dance(unit, DanceType.NONE); this.dance(unit, DanceType.NONE);
int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z; //int tileHeight = this.layout.getTile(topItem.getX(), topItem.getY()).z;
if (topItem instanceof InteractionMultiHeight) unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + "");
{
unit.setStatus(RoomUnitStatus.SIT, (Item.getCurrentHeight(topItem) * 1.0D) + "");
}
else
{
unit.setStatus(RoomUnitStatus.SIT, (topItem.getBaseItem().getHeight() * 1.0D) + "");
}
unit.setPreviousLocationZ(topItem.getZ()); unit.setPreviousLocationZ(topItem.getZ());
unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]); unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]);
unit.sitUpdate = false; unit.sitUpdate = false;
@ -1966,14 +1916,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
{ {
if (!unit.hasStatus(RoomUnitStatus.LAY)) if (!unit.hasStatus(RoomUnitStatus.LAY))
{ {
if (topItem instanceof InteractionMultiHeight) unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + "");
{
unit.setStatus(RoomUnitStatus.LAY, Item.getCurrentHeight(topItem) * 1.0D + "");
}
else
{
unit.setStatus(RoomUnitStatus.LAY, topItem.getBaseItem().getHeight() * 1.0D + "");
}
unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]); unit.setRotation(RoomUserRotation.values()[topItem.getRotation()]);
if (topItem.getRotation() == 0 || topItem.getRotation() == 4) if (topItem.getRotation() == 0 || topItem.getRotation() == 4)
@ -2392,9 +2335,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
for (Pet pet : this.currentPets.valueCollection()) { for (Pet pet : this.currentPets.valueCollection()) {
try { try {
if (pet.getUserId() != excludeUserId) { if (pet.getUserId() != excludeUserId) {
pet.setRoom(null);
removedPets.add(pet); pet.removeFromRoom();
this.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose());
Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId()); Habbo habbo = Emulator.getGameEnvironment().getHabboManager().getHabbo(pet.getUserId());
if (habbo != null) { if (habbo != null) {
@ -3194,8 +3136,20 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
} }
} }
public void removeHabbo(Habbo habbo) public void removeHabbo(Habbo habbo) {
removeHabbo(habbo, false);
}
public void removeHabbo(Habbo habbo, boolean sendRemovePacket)
{ {
if(habbo.getRoomUnit() != null && habbo.getRoomUnit().getCurrentLocation() != null) {
habbo.getRoomUnit().getCurrentLocation().removeUnit(habbo.getRoomUnit());
}
if(sendRemovePacket && habbo.getRoomUnit() != null) {
this.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose());
}
HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY()); HabboItem item = this.getTopItemAt(habbo.getRoomUnit().getX(), habbo.getRoomUnit().getY());
if (item != null) if (item != null)
@ -3408,6 +3362,10 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
{ {
if (this.currentBots.containsKey(bot.getId())) if (this.currentBots.containsKey(bot.getId()))
{ {
if(bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentLocation() != null) {
bot.getRoomUnit().getCurrentLocation().removeUnit(bot.getRoomUnit());
}
this.currentBots.remove(bot.getId()); this.currentBots.remove(bot.getId());
bot.getRoomUnit().setInRoom(false); bot.getRoomUnit().setInRoom(false);
bot.setRoom(null); bot.setRoom(null);
@ -3570,7 +3528,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
public void teleportHabboToItem(Habbo habbo, HabboItem item) public void teleportHabboToItem(Habbo habbo, HabboItem item)
{ {
this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight()); this.teleportRoomUnitToLocation(habbo.getRoomUnit(), item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item));
} }
public void teleportHabboToLocation(Habbo habbo, short x, short y) public void teleportHabboToLocation(Habbo habbo, short x, short y)
@ -3580,7 +3538,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
public void teleportRoomUnitToItem(RoomUnit roomUnit, HabboItem item) public void teleportRoomUnitToItem(RoomUnit roomUnit, HabboItem item)
{ {
this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + item.getBaseItem().getHeight()); this.teleportRoomUnitToLocation(roomUnit, item.getX(), item.getY(), item.getZ() + Item.getCurrentHeight(item));
} }
public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y) public void teleportRoomUnitToLocation(RoomUnit roomUnit, short x, short y)
@ -4208,7 +4166,8 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
{ {
item = habboItem; item = habboItem;
} }
} else }
else
{ {
if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1) if (habboItem.getBaseItem().getWidth() <= 1 && habboItem.getBaseItem().getLength() <= 1)
{ {
@ -4240,7 +4199,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
HabboItem item = this.getTopItemAt(x, y); HabboItem item = this.getTopItemAt(x, y);
if(item != null) if(item != null)
return (item.getZ() + item.getBaseItem().getHeight()); return (item.getZ() + Item.getCurrentHeight(item));
else else
return this.layout.getHeightAtSquare(x, y); return this.layout.getHeightAtSquare(x, y);
} }
@ -4319,6 +4278,12 @@ public class Room implements Comparable<Room>, ISerialize, Runnable
canStack = item.getBaseItem().allowStack(); canStack = item.getBaseItem().allowStack();
height = item.getZ() + Item.getCurrentHeight(item); height = item.getZ() + Item.getCurrentHeight(item);
} }
HabboItem lowestChair = this.getLowestChair(x, y);
if(lowestChair != null) {
canStack = true;
height = lowestChair.getZ() + Item.getCurrentHeight(lowestChair);
}
} }
} }

View File

@ -262,7 +262,7 @@ public class RoomLayout
return this.heightmap.replace("\r\n", "\r"); return this.heightmap.replace("\r\n", "\r");
} }
public final Deque<RoomTile> findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation) public final Deque<RoomTile> findPath(RoomTile oldTile, RoomTile newTile, RoomTile goalLocation, RoomUnit roomUnit)
{ {
LinkedList<RoomTile> openList = new LinkedList<>(); LinkedList<RoomTile> openList = new LinkedList<>();
try try
@ -274,20 +274,6 @@ public class RoomLayout
openList.add(oldTile.copy()); openList.add(oldTile.copy());
List<RoomTile> unitsAt = new ArrayList<>();
for(Bot b : this.room.getCurrentBots().valueCollection()) {
unitsAt.add(b.getRoomUnit().getCurrentLocation());
}
for(Habbo b : this.room.getCurrentHabbos().values()) {
unitsAt.add(b.getRoomUnit().getCurrentLocation());
}
for(Pet b : this.room.getCurrentPets().valueCollection()) {
unitsAt.add(b.getRoomUnit().getCurrentLocation());
}
long startMillis = System.currentTimeMillis(); long startMillis = System.currentTimeMillis();
while (true) while (true)
{ {
@ -310,6 +296,14 @@ public class RoomLayout
{ {
if (closedList.contains(currentAdj)) continue; if (closedList.contains(currentAdj)) continue;
if(roomUnit.canOverrideTile(currentAdj) || (currentAdj.state != RoomTileState.BLOCKED && currentAdj.x == doorX && currentAdj.y == doorY)) {
currentAdj.setPrevious(current);
currentAdj.sethCosts(this.findTile(openList, newTile.x, newTile.y));
currentAdj.setgCosts(current);
openList.add(currentAdj);
continue;
}
//If the tile is sitable or layable and its not our goal tile, we cannot walk over it. //If the tile is sitable or layable and its not our goal tile, we cannot walk over it.
if (!currentAdj.equals(goalLocation) && (currentAdj.state == RoomTileState.BLOCKED || currentAdj.state == RoomTileState.SIT || currentAdj.state == RoomTileState.LAY)) if (!currentAdj.equals(goalLocation) && (currentAdj.state == RoomTileState.BLOCKED || currentAdj.state == RoomTileState.SIT || currentAdj.state == RoomTileState.LAY))
{ {
@ -329,7 +323,7 @@ public class RoomLayout
if (currentAdj.state == RoomTileState.OPEN && height > MAXIMUM_STEP_HEIGHT) continue; if (currentAdj.state == RoomTileState.OPEN && height > MAXIMUM_STEP_HEIGHT) continue;
//Check if the tile has habbos. //Check if the tile has habbos.
if (unitsAt.contains(currentAdj) && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation))) if (currentAdj.hasUnits() && (!this.room.isAllowWalkthrough() || currentAdj.equals(goalLocation)))
{ {
closedList.add(currentAdj); closedList.add(currentAdj);
openList.remove(currentAdj); openList.remove(currentAdj);

View File

@ -750,7 +750,8 @@ public class RoomManager
if (habbo.getHabboInfo().getCurrentRoom() != room && habbo.getHabboInfo().getCurrentRoom() != null) if (habbo.getHabboInfo().getCurrentRoom() != room && habbo.getHabboInfo().getCurrentRoom() != null)
{ {
habbo.getHabboInfo().getCurrentRoom().removeHabbo(habbo); habbo.getHabboInfo().getCurrentRoom().removeHabbo(habbo);
} else if (!habbo.getHabboStats().blockFollowing && habbo.getHabboInfo().getCurrentRoom() == null) }
else if (!habbo.getHabboStats().blockFollowing && habbo.getHabboInfo().getCurrentRoom() == null)
{ {
habbo.getMessenger().connectionChanged(habbo, true, true); habbo.getMessenger().connectionChanged(habbo, true, true);
} }
@ -824,7 +825,6 @@ public class RoomManager
if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting) if (habbo.getRoomUnit().getCurrentLocation() == null && !habbo.getRoomUnit().isTeleporting)
{ {
RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY()); RoomTile doorTile = room.getLayout().getTile(room.getLayout().getDoorX(), room.getLayout().getDoorY());
if (doorTile != null) if (doorTile != null)
@ -836,6 +836,7 @@ public class RoomManager
habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); habbo.getRoomUnit().setBodyRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]); habbo.getRoomUnit().setHeadRotation(RoomUserRotation.values()[room.getLayout().getDoorDirection()]);
} }
habbo.getRoomUnit().setPathFinderRoom(room); habbo.getRoomUnit().setPathFinderRoom(room);
habbo.getRoomUnit().resetIdleTimer(); habbo.getRoomUnit().resetIdleTimer();
@ -1100,9 +1101,8 @@ public class RoomManager
habbo.getRoomUnit().setPathFinderRoom(null); habbo.getRoomUnit().setPathFinderRoom(null);
this.logExit(habbo); this.logExit(habbo);
room.removeHabbo(habbo); room.removeHabbo(habbo, true);
room.sendComposer(new RoomUserRemoveComposer(habbo.getRoomUnit()).compose());
if (redirectToHotelView) if (redirectToHotelView)
{ {
habbo.getClient().sendResponse(new HotelViewComposer()); habbo.getClient().sendResponse(new HotelViewComposer());

View File

@ -1,5 +1,7 @@
package com.eu.habbo.habbohotel.rooms; package com.eu.habbo.habbohotel.rooms;
import gnu.trove.set.hash.THashSet;
public class RoomTile public class RoomTile
{ {
public final short x; public final short x;
@ -10,12 +12,13 @@ public class RoomTile
private double stackHeight; private double stackHeight;
private boolean allowStack = true; private boolean allowStack = true;
private RoomTile previous = null; private RoomTile previous = null;
private boolean diagonally; private boolean diagonally;
private short gCosts; private short gCosts;
private short hCosts; private short hCosts;
private THashSet<RoomUnit> units;
public RoomTile(short x, short y, short z, RoomTileState state, boolean allowStack) public RoomTile(short x, short y, short z, RoomTileState state, boolean allowStack)
{ {
@ -25,6 +28,7 @@ public class RoomTile
this.stackHeight = z; this.stackHeight = z;
this.state = state; this.state = state;
this.setAllowStack(allowStack); this.setAllowStack(allowStack);
this.units = new THashSet<>();
} }
public RoomTile(RoomTile tile) public RoomTile(RoomTile tile)
@ -43,6 +47,7 @@ public class RoomTile
{ {
this.allowStack = false; this.allowStack = false;
} }
this.units = tile.units;
} }
public double getStackHeight() public double getStackHeight()
@ -199,4 +204,18 @@ public class RoomTile
{ {
return this.x == x && this.y == y; return this.x == x && this.y == y;
} }
public void addUnit(RoomUnit unit) {
if(!this.units.contains(unit)) {
this.units.add(unit);
}
}
public void removeUnit(RoomUnit unit) {
this.units.remove(unit);
}
public boolean hasUnits() {
return this.units.size() > 0;
}
} }

View File

@ -21,7 +21,9 @@ import com.eu.habbo.threading.runnables.RoomUnitKick;
import com.eu.habbo.util.pathfinding.Rotation; import com.eu.habbo.util.pathfinding.Rotation;
import gnu.trove.map.TMap; import gnu.trove.map.TMap;
import gnu.trove.map.hash.THashMap; import gnu.trove.map.hash.THashMap;
import gnu.trove.set.hash.THashSet;
import java.awt.geom.RectangularShape;
import java.util.Deque; import java.util.Deque;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map; import java.util.Map;
@ -72,6 +74,7 @@ public class RoomUnit
private int idleTimer; private int idleTimer;
private Room room; private Room room;
private RoomRightLevels rightsLevel = RoomRightLevels.NONE; private RoomRightLevels rightsLevel = RoomRightLevels.NONE;
private THashSet<Integer> overridableTiles;
public RoomUnit() public RoomUnit()
{ {
@ -87,6 +90,7 @@ public class RoomUnit
this.walkTimeOut = Emulator.getIntUnixTimestamp(); this.walkTimeOut = Emulator.getIntUnixTimestamp();
this.effectId = 0; this.effectId = 0;
this.isKicked = false; this.isKicked = false;
this.overridableTiles = new THashSet<>();
} }
public void clearWalking() public void clearWalking()
@ -113,11 +117,6 @@ public class RoomUnit
{ {
try try
{ {
if (this.isTeleporting)
{
return false;
}
Habbo rider = null; Habbo rider = null;
if(this.getRoomUnitType() == RoomUnitType.PET) { if(this.getRoomUnitType() == RoomUnitType.PET) {
Pet pet = room.getPet(this); Pet pet = room.getPet(this);
@ -179,25 +178,20 @@ public class RoomUnit
canfastwalk = false; canfastwalk = false;
} }
if (canfastwalk && this.fastWalk && this.path.size() >= 3)
{
this.path.poll();
this.path.poll();
}
RoomTile next = this.path.poll(); RoomTile next = this.path.poll();
boolean overrideChecks = next != null && this.canOverrideTile(next);
if (this.path.isEmpty()) if (this.path.isEmpty())
{ {
this.sitUpdate = true; this.sitUpdate = true;
if (next != null && room.hasHabbosAt(next.x, next.y)) if (next != null && next.hasUnits() && !overrideChecks)
{ {
return false; return false;
} }
} }
Deque<RoomTile> peekPath = room.getLayout().findPath(this.currentLocation, this.path.peek(), this.goalLocation); Deque<RoomTile> peekPath = room.getLayout().findPath(this.currentLocation, this.path.peek(), this.goalLocation, this);
if (peekPath.size() >= 3) if (peekPath.size() >= 3)
{ {
path.pop(); path.pop();
@ -214,6 +208,13 @@ public class RoomUnit
} }
} }
if (canfastwalk && this.fastWalk)
{
if(this.path.size() > 1) {
next = this.path.poll();
}
}
if (next == null) if (next == null)
return true; return true;
@ -252,7 +253,7 @@ public class RoomUnit
//if(!(this.path.size() == 0 && canSitNextTile)) //if(!(this.path.size() == 0 && canSitNextTile))
{ {
if (!room.tileWalkable(next.x, next.y)) if (!room.tileWalkable(next.x, next.y) && !overrideChecks)
{ {
this.room = room; this.room = room;
this.findPath(); this.findPath();
@ -281,7 +282,7 @@ public class RoomUnit
item = lowestChair; item = lowestChair;
} }
if (next.equals(this.goalLocation) && next.state == RoomTileState.SIT) if (next.equals(this.goalLocation) && next.state == RoomTileState.SIT && !overrideChecks)
{ {
if (item == null || item.getZ() - this.getZ() > RoomLayout.MAXIMUM_STEP_HEIGHT) if (item == null || item.getZ() - this.getZ() > RoomLayout.MAXIMUM_STEP_HEIGHT)
{ {
@ -343,20 +344,7 @@ public class RoomUnit
if (!item.getBaseItem().allowSit() && !item.getBaseItem().allowLay()) if (!item.getBaseItem().allowSit() && !item.getBaseItem().allowLay())
{ {
zHeight += item.getBaseItem().getHeight(); zHeight += Item.getCurrentHeight(item);
if (item instanceof InteractionMultiHeight)
{
if (item.getExtradata().length() == 0)
{
item.setExtradata("0");
}
zHeight += Item.getCurrentHeight(item);
}
else if (item instanceof InteractionFreezeBlock)
{
zHeight -= item.getBaseItem().getHeight();
}
} }
} }
else else
@ -574,8 +562,8 @@ public class RoomUnit
if (location != null) if (location != null)
{ {
this.startLocation = location; this.startLocation = location;
this.previousLocation = location; setPreviousLocation(location);
this.currentLocation = location; setCurrentLocation(location);
this.goalLocation = location; this.goalLocation = location;
} }
} }
@ -584,7 +572,11 @@ public class RoomUnit
{ {
if (location != null) if (location != null)
{ {
this.currentLocation = location; if(this.currentLocation != null) {
this.currentLocation.removeUnit(this);
}
this.currentLocation = location;
location.addUnit(this);
} }
} }
@ -616,9 +608,9 @@ public class RoomUnit
public void findPath() public void findPath()
{ {
if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.x, this.goalLocation.y))) if (this.room != null && this.room.getLayout() != null && this.goalLocation != null && (this.goalLocation.isWalkable() || this.room.canSitOrLayAt(this.goalLocation.x, this.goalLocation.y) || this.canOverrideTile(this.goalLocation)))
{ {
this.path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation); this.path = this.room.getLayout().findPath(this.currentLocation, this.goalLocation, this.goalLocation, this);
} }
} }
@ -811,4 +803,25 @@ public class RoomUnit
public Room getRoom() { public Room getRoom() {
return room; return room;
} }
public boolean canOverrideTile(RoomTile tile) {
int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1;
return this.overridableTiles.contains(tileIndex);
}
public void addOverrideTile(RoomTile tile) {
int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1;
if(!this.overridableTiles.contains(tileIndex)) {
this.overridableTiles.add(tileIndex);
}
}
public void removeOverrideTile(RoomTile tile) {
int tileIndex = (room.getLayout().getMapSizeY() * tile.y) + tile.x + 1;
this.overridableTiles.remove(tileIndex);
}
public void clearOverrideTiles() {
this.overridableTiles.clear();
}
} }

View File

@ -26,11 +26,8 @@ public class RequestRoomLoadEvent extends MessageHandler
{ {
Emulator.getGameEnvironment().getRoomManager().logExit(this.client.getHabbo()); Emulator.getGameEnvironment().getRoomManager().logExit(this.client.getHabbo());
if (this.client.getHabbo().getRoomUnit() != null) room.removeHabbo(this.client.getHabbo(), true);
{
room.sendComposer(new RoomUserRemoveComposer(this.client.getHabbo().getRoomUnit()).compose());
}
room.removeHabbo(this.client.getHabbo());
this.client.getHabbo().getHabboInfo().setCurrentRoom(null); this.client.getHabbo().getHabboInfo().setCurrentRoom(null);
} }
Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password); Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), roomId, password);

View File

@ -45,12 +45,7 @@ public class CompostMonsterplantEvent extends MessageHandler
room.sendComposer(new AddFloorItemComposer(compost, this.client.getHabbo().getHabboInfo().getUsername()).compose()); room.sendComposer(new AddFloorItemComposer(compost, this.client.getHabbo().getHabboInfo().getUsername()).compose());
} }
pet.setRoom(null); pet.removeFromRoom();
pet.setUserId(0);
room.removePet(petId);
room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose());
pet.setRoomUnit(null);
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_pets WHERE id = ? LIMIT 1")) try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM users_pets WHERE id = ? LIMIT 1"))
{ {
statement.setInt(1, pet.getId()); statement.setInt(1, pet.getId());

View File

@ -44,12 +44,7 @@ public class PetPickupEvent extends MessageHandler
} }
} }
room.sendComposer(new RoomUserRemoveComposer(pet.getRoomUnit()).compose()); pet.removeFromRoom();
room.removePet(petId);
pet.setRoomUnit(null);
pet.setRoom(null);
pet.needsUpdate = true;
Emulator.getThreading().run(pet); Emulator.getThreading().run(pet);
if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId()) if (this.client.getHabbo().getHabboInfo().getId() == pet.getUserId())

View File

@ -35,8 +35,6 @@ class TeleportActionFive implements Runnable
if (tile != null) if (tile != null)
{ {
this.client.getHabbo().getRoomUnit().setPreviousLocation(currentLocation);
this.client.getHabbo().getRoomUnit().setPreviousLocationZ(currentLocation.getStackHeight());
this.client.getHabbo().getRoomUnit().setGoalLocation(tile); this.client.getHabbo().getRoomUnit().setGoalLocation(tile);
this.client.getHabbo().getRoomUnit().statusUpdate(true); this.client.getHabbo().getRoomUnit().statusUpdate(true);
} }

View File

@ -68,7 +68,7 @@ class TeleportActionThree implements Runnable
if(targetRoom != this.room) if(targetRoom != this.room)
{ {
this.room.sendComposer(new RoomUserRemoveComposer(this.client.getHabbo().getRoomUnit()).compose()); this.room.removeHabbo(this.client.getHabbo(), true);
Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation); Emulator.getGameEnvironment().getRoomManager().enterRoom(this.client.getHabbo(), targetRoom.getId(), "", Emulator.getConfig().getBoolean("hotel.teleport.locked.allowed"), teleportLocation);
} }