🆙 Not 100% yet but it is working : Banzai teleporters while riding horse and better timing/animations to match official habbo

This commit is contained in:
duckietm 2025-02-07 15:16:08 +01:00
parent 808d9b45ea
commit 1d6ef05206
4 changed files with 150 additions and 81 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ config.ini
*.zip *.zip
.DS_Store .DS_Store
/Emulator/plugins

View File

@ -116,19 +116,15 @@ public class RoomUnit {
public boolean cycle(Room room) { public boolean cycle(Room room) {
try { try {
Habbo rider = null; Habbo rider;
if (this.getRoomUnitType() == RoomUnitType.PET) { if (this.getRoomUnitType() == RoomUnitType.PET) {
Pet pet = room.getPet(this); Pet pet = room.getPet(this);
if (pet instanceof RideablePet) { if (pet instanceof RideablePet) {
rider = ((RideablePet) pet).getRider(); rider = ((RideablePet) pet).getRider();
}
}
if (rider != null) { if (rider != null) {
// copy things from rider if (this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatusMap().containsKey(RoomUnitStatus.MOVE))
if (this.status.containsKey(RoomUnitStatus.MOVE) && !rider.getRoomUnit().getStatusMap().containsKey(RoomUnitStatus.MOVE)) {
this.status.remove(RoomUnitStatus.MOVE); this.status.remove(RoomUnitStatus.MOVE);
}
if (rider.getRoomUnit().getCurrentLocation().x != this.getX() || rider.getRoomUnit().getCurrentLocation().y != this.getY()) { if (rider.getRoomUnit().getCurrentLocation().x != this.getX() || rider.getRoomUnit().getCurrentLocation().y != this.getY()) {
this.status.put(RoomUnitStatus.MOVE, rider.getRoomUnit().getCurrentLocation().x + "," + rider.getRoomUnit().getCurrentLocation().y + "," + (rider.getRoomUnit().getCurrentLocation().getStackHeight())); this.status.put(RoomUnitStatus.MOVE, rider.getRoomUnit().getCurrentLocation().x + "," + rider.getRoomUnit().getCurrentLocation().y + "," + (rider.getRoomUnit().getCurrentLocation().getStackHeight()));
@ -140,7 +136,8 @@ public class RoomUnit {
return this.statusUpdate; return this.statusUpdate;
} }
}
}
if (!this.isWalking() && !this.isKicked) { if (!this.isWalking() && !this.isKicked) {
if (this.status.remove(RoomUnitStatus.MOVE) == null) { if (this.status.remove(RoomUnitStatus.MOVE) == null) {
@ -248,7 +245,8 @@ public class RoomUnit {
//if(!(this.path.size() == 0 && canSitNextTile)) //if(!(this.path.size() == 0 && canSitNextTile))
{ {
double height = next.getStackHeight() - this.currentLocation.getStackHeight(); double height = next.getStackHeight() - this.currentLocation.getStackHeight();
if (!room.tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) || (next.state == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) { if (!room.tileWalkable(next) || (!RoomLayout.ALLOW_FALLING && height < -RoomLayout.MAXIMUM_STEP_HEIGHT) ||
(next.state == RoomTileState.OPEN && height > RoomLayout.MAXIMUM_STEP_HEIGHT)) {
this.room = room; this.room = room;
this.path.clear(); this.path.clear();
this.findPath(); this.findPath();
@ -257,8 +255,7 @@ public class RoomUnit {
this.status.remove(RoomUnitStatus.MOVE); this.status.remove(RoomUnitStatus.MOVE);
return false; return false;
} }
next = (RoomTile)this.path.pop(); next = this.path.pop();
} }
} }
@ -330,7 +327,7 @@ public class RoomUnit {
zHeight += room.getLayout().getHeightAtSquare(next.x, next.y); zHeight += room.getLayout().getHeightAtSquare(next.x, next.y);
} }
Optional<HabboItem> stackHelper = room.getItemsAt(next).stream().filter(i -> i instanceof InteractionTileWalkMagic).findAny(); Optional<HabboItem> stackHelper = this.room.getItemsAt(next).stream().filter(i -> i instanceof InteractionTileWalkMagic).findAny();
if (stackHelper.isPresent()) { if (stackHelper.isPresent()) {
zHeight = stackHelper.get().getZ(); zHeight = stackHelper.get().getZ();
} }

View File

@ -1,74 +1,145 @@
package com.eu.habbo.threading.runnables; package com.eu.habbo.threading.runnables;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.rooms.RoomTile; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.rooms.RoomUnit;
import com.eu.habbo.habbohotel.rooms.RoomUserRotation;
import com.eu.habbo.habbohotel.users.HabboItem; import com.eu.habbo.habbohotel.users.HabboItem;
import com.eu.habbo.habbohotel.pets.Pet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class BanzaiRandomTeleport implements Runnable { public class BanzaiRandomTeleport implements Runnable {
private final HabboItem item; private static final Logger LOGGER = LoggerFactory.getLogger(BanzaiRandomTeleport.class);
private final HabboItem toItem;
private final RoomUnit habbo;
private final Room room;
public BanzaiRandomTeleport(HabboItem item, HabboItem toItem, RoomUnit habbo, Room room) { private final HabboItem initialTeleporter;
this.item = item; private final HabboItem targetTeleporter;
this.toItem = toItem; private final RoomUnit roomUnit;
this.habbo = habbo; private final Room room;
private RoomUserRotation newRotation;
public BanzaiRandomTeleport(HabboItem initialTeleporter, HabboItem targetTeleporter, RoomUnit roomUnit, Room room) {
this(initialTeleporter, targetTeleporter, roomUnit, room, getRandomRotation());
}
public BanzaiRandomTeleport(HabboItem initialTeleporter, HabboItem targetTeleporter, RoomUnit roomUnit, Room room, RoomUserRotation newRotation) {
this.initialTeleporter = initialTeleporter;
this.targetTeleporter = targetTeleporter;
this.roomUnit = roomUnit;
this.room = room; this.room = room;
this.newRotation = newRotation;
}
private static RoomUserRotation getRandomRotation() {
RoomUserRotation[] rotations = RoomUserRotation.values();
return rotations[Emulator.getRandom().nextInt(rotations.length)];
} }
@Override @Override
public void run() { public void run() {
HabboItem topItemNow = this.room.getTopItemAt(this.habbo.getX(), this.habbo.getY()); if (roomUnit == null || room == null || roomUnit.getCurrentLocation() == null) {
RoomTile lastLocation = this.habbo.getCurrentLocation(); LOGGER.warn("RoomUnit or Room reference is null, teleport aborted.");
RoomTile newLocation = this.room.getLayout().getTile(toItem.getX(), toItem.getY()); return;
}
if(topItemNow != null) { final RoomTile teleporterTile = room.getLayout().getTile(initialTeleporter.getX(), initialTeleporter.getY());
try { final RoomTile newLocation = room.getLayout().getTile(targetTeleporter.getX(), targetTeleporter.getY());
topItemNow.onWalkOff(this.habbo, this.room, new Object[] { lastLocation, newLocation, this });
} catch (Exception e) { // Determine if the user is riding a pet
LoggerFactory.getLogger(BanzaiRandomTeleport.class).error("BanzaiRandomTeleport exception", e); final boolean isRiding = isUserRiding();
final Habbo rider = isRiding ? room.getHabbo(roomUnit) : null;
final RoomUnit petUnit;
if (rider != null && rider.getHabboInfo().getRiding() != null) {
petUnit = rider.getHabboInfo().getRiding().getRoomUnit();
} else {
petUnit = null;
} }
// Move the pet onto the teleport tile before teleporting
if (petUnit != null) {
// Temporarily override the pet's movement logic to force it onto the teleport tile
petUnit.setCanWalk(true); // Ensure the pet can walk
petUnit.setGoalLocation(teleporterTile); // Set the goal location
petUnit.setCurrentLocation(teleporterTile); // Force the pet to the teleport tile
petUnit.setZ(teleporterTile.getStackHeight()); // Set the correct Z-height
LOGGER.info("Pet {} moved onto teleporter tile at ({}, {})", petUnit.getId(), teleporterTile.x, teleporterTile.y);
// Ensure both pet and rider face the same direction
roomUnit.setRotation(this.newRotation);
petUnit.setRotation(this.newRotation);
// Get correct Z-height
final double baseZ = targetTeleporter.getZ();
final double finalPetZ = baseZ;
final double finalRiderZ = baseZ + (isRiding ? 1 : 0); // Rider stays above pet if riding
// Delay to ensure the pet has reached the teleport tile
Emulator.getThreading().run(() -> {
room.teleportRoomUnitToLocation(petUnit, newLocation.x, newLocation.y, finalPetZ);
petUnit.setZ(finalPetZ);
LOGGER.info("Pet {} teleported to ({}, {}), Z = {}", petUnit.getId(), newLocation.x, newLocation.y, finalPetZ);
room.teleportRoomUnitToLocation(roomUnit, newLocation.x, newLocation.y, finalRiderZ);
roomUnit.setZ(finalRiderZ);
LOGGER.info("Rider {} teleported to ({}, {}), Z = {}", roomUnit.getId(), newLocation.x, newLocation.y, finalRiderZ);
// Synchronize rotations after teleportation
petUnit.setRotation(roomUnit.getBodyRotation());
petUnit.setBodyRotation(roomUnit.getBodyRotation());
petUnit.setHeadRotation(roomUnit.getHeadRotation());
// Re-enable walking after teleportation
Emulator.getThreading().run(() -> {
roomUnit.setCanWalk(true);
petUnit.setCanWalk(true);
// Update teleporter states
if ("1".equals(initialTeleporter.getExtradata())) {
initialTeleporter.setExtradata("0");
room.updateItemState(initialTeleporter);
} }
if ("1".equals(targetTeleporter.getExtradata())) {
targetTeleporter.setExtradata("0");
room.updateItemState(targetTeleporter);
}
}, 650); // Delay to ensure smooth transition
}, 1000); // Increased delay to ensure pet reaches the teleport tile
} else {
// If not riding, proceed with teleportation for the rider only
roomUnit.setRotation(this.newRotation);
final double baseZ = targetTeleporter.getZ();
final double finalRiderZ = baseZ;
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
if (this.item.getExtradata().equals("1")) { room.teleportRoomUnitToLocation(roomUnit, newLocation.x, newLocation.y, finalRiderZ);
this.item.setExtradata("0"); roomUnit.setZ(finalRiderZ);
this.room.updateItemState(this.item); LOGGER.info("Rider {} teleported to ({}, {}), Z = {}", roomUnit.getId(), newLocation.x, newLocation.y, finalRiderZ);
}
}, 500);
if(!this.toItem.getExtradata().equals("1")) {
this.toItem.setExtradata("1");
this.room.updateItemState(this.toItem);
}
Emulator.getThreading().run(() -> { Emulator.getThreading().run(() -> {
this.habbo.setCanWalk(true); roomUnit.setCanWalk(true);
HabboItem topItemNext = this.room.getTopItemAt(this.habbo.getX(), this.habbo.getY());
if(topItemNext != null) { // Update teleporter states
try { if ("1".equals(initialTeleporter.getExtradata())) {
topItemNext.onWalkOn(this.habbo, this.room, new Object[] { lastLocation, newLocation, this }); initialTeleporter.setExtradata("0");
} catch (Exception e) { room.updateItemState(initialTeleporter);
LoggerFactory.getLogger(BanzaiRandomTeleport.class).error("BanzaiRandomTeleport exception", e); }
if ("1".equals(targetTeleporter.getExtradata())) {
targetTeleporter.setExtradata("0");
room.updateItemState(targetTeleporter);
}
}, 650); // Delay to ensure smooth transition
}, 700); // Standard delay for non-ridden teleportation
} }
} }
if (this.toItem.getExtradata().equals("1")) { private boolean isUserRiding() {
this.toItem.setExtradata("0"); if (roomUnit.getRoomUnitType() != RoomUnitType.USER) {
this.room.updateItemState(this.toItem); return false;
} }
}, 750); Habbo habbo = room.getHabbo(roomUnit);
return habbo != null && habbo.getHabboInfo().getRiding() != null;
Emulator.getThreading().run(() -> {
this.habbo.setRotation(RoomUserRotation.fromValue(Emulator.getRandom().nextInt(8)));
this.room.teleportRoomUnitToLocation(this.habbo, newLocation.x, newLocation.y, newLocation.getStackHeight());
}, 250);
} }
} }