Bot Placement

This commit is contained in:
Stankman 2023-08-02 20:43:44 -05:00
parent e11def5965
commit 71062dc2fc
5 changed files with 71 additions and 17 deletions

View File

@ -2,6 +2,7 @@ package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator; import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.PetManager; import com.eu.habbo.habbohotel.pets.PetManager;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation; import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
@ -14,9 +15,14 @@ import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet;
import com.eu.habbo.habbohotel.units.Unit; import com.eu.habbo.habbohotel.units.Unit;
import com.eu.habbo.habbohotel.users.DanceType; import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.habbohotel.users.Habbo; import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer;
import com.eu.habbo.messages.outgoing.inventory.BotRemovedFromInventoryComposer;
import com.eu.habbo.messages.outgoing.inventory.PetAddedToInventoryComposer; import com.eu.habbo.messages.outgoing.inventory.PetAddedToInventoryComposer;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer; import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer; import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer;
import com.eu.habbo.plugin.Event;
import com.eu.habbo.plugin.events.bots.BotPlacedEvent;
import gnu.trove.set.hash.THashSet; import gnu.trove.set.hash.THashSet;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -218,19 +224,66 @@ public class RoomUnitManager {
return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet()); return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet());
} }
public void placeBot(Bot bot, Habbo habbo, int x, int y) {
synchronized (this.currentBots) {
RoomTile spawnTile = room.getLayout().getTile((short) x, (short) y);
if(spawnTile == null) {
spawnTile = room.getLayout().getDoorTile();
}
if (Emulator.getPluginManager().isRegistered(BotPlacedEvent.class, false)) {
Event event = new BotPlacedEvent(bot, spawnTile, habbo);
Emulator.getPluginManager().fireEvent(event);
if (event.isCancelled()) {
return;
}
}
if(this.currentBots.size() >= Room.MAXIMUM_BOTS && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) {
habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS));
return;
}
if((!spawnTile.isWalkable() && !this.room.canSitOrLayAt(spawnTile)) || this.areRoomUnitsAt(spawnTile)) {
habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE));
return;
}
RoomBot roomBot = bot.getRoomUnit();
roomBot.setRoom(this.room);
roomBot.setCurrentPosition(spawnTile);
roomBot.setCurrentZ(spawnTile.getZ());
roomBot.setRotation(RoomRotation.SOUTH);
roomBot.setCanWalk(this.room.isAllowBotsWalk());
this.addRoomUnit(bot);
this.room.sendComposer(new RoomUsersComposer(bot).compose());
roomBot.instantUpdate();
habbo.getInventory().getBotsComponent().removeBot(bot);
habbo.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot));
bot.onPlace(habbo, room);
}
}
public void placePet(Pet pet, Room room, short x, short y, double z) { public void placePet(Pet pet, Room room, short x, short y, double z) {
synchronized (this.currentPets) { synchronized (this.currentPets) {
RoomTile tile = room.getLayout().getTile(x, y); RoomTile spawnTile = room.getLayout().getTile(x, y);
if (tile == null) { if (spawnTile == null) {
tile = room.getLayout().getDoorTile(); spawnTile = room.getLayout().getDoorTile();
} }
pet.setRoomUnit(new RoomPet()); pet.setRoomUnit(new RoomPet());
pet.getRoomUnit().setUnit(pet); pet.getRoomUnit().setUnit(pet);
pet.setRoom(room); pet.setRoom(room);
pet.getRoomUnit().walkTo(tile); pet.getRoomUnit().walkTo(spawnTile);
pet.getRoomUnit().setLocation(tile) pet.getRoomUnit().setLocation(spawnTile)
.setRoomUnitType(RoomUnitType.PET) .setRoomUnitType(RoomUnitType.PET)
.setCanWalk(true) .setCanWalk(true)
.setCurrentZ(z); .setCurrentZ(z);
@ -343,8 +396,8 @@ public class RoomUnitManager {
bot.getRoomUnit().setInRoom(false); bot.getRoomUnit().setInRoom(false);
bot.setRoom(null); bot.setRoom(null);
bot.getRoomUnit().getRoom().sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose());
bot.setRoomUnit(null); this.room.sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose());
return true; return true;
} }
} }

View File

@ -201,8 +201,8 @@ public abstract class RoomUnit extends RoomEntity {
} }
if(this.nextPosition != null) { if(this.nextPosition != null) {
this.currentPosition = this.nextPosition; this.setCurrentPosition(this.nextPosition);
this.currentZ = this.nextZ; this.setCurrentZ(this.nextZ);
} }
this.targetPosition = goalLocation; this.targetPosition = goalLocation;
@ -212,7 +212,7 @@ public abstract class RoomUnit extends RoomEntity {
public RoomUnit setLocation(RoomTile location) { public RoomUnit setLocation(RoomTile location) {
if (location != null) { if (location != null) {
this.currentPosition = location; this.setCurrentPosition(location);
this.targetPosition = location; this.targetPosition = location;
} }
return this; return this;
@ -492,8 +492,8 @@ public abstract class RoomUnit extends RoomEntity {
this.statuses.entrySet().removeIf(entry -> entry.getKey().isRemoveWhenWalking()); this.statuses.entrySet().removeIf(entry -> entry.getKey().isRemoveWhenWalking());
if(this.getNextPosition() != null) { if(this.getNextPosition() != null) {
this.currentPosition = this.getNextPosition(); this.setCurrentPosition(this.getNextPosition());
this.currentZ = this.getNextZ(); this.setCurrentZ(this.getNextZ());
} }
if(!this.path.isEmpty()) { if(!this.path.isEmpty()) {
@ -563,12 +563,14 @@ public abstract class RoomUnit extends RoomEntity {
*/ */
private boolean isValidTile(RoomTile tile) { private boolean isValidTile(RoomTile tile) {
boolean canOverrideTile = this.canOverrideTile(tile); boolean canOverrideTile = this.canOverrideTile(tile);
if (canOverrideTile) { if (canOverrideTile) {
return true; return true;
} }
double heightDifference = tile.getStackHeight() - this.currentZ; double heightDifference = tile.getStackHeight() - this.currentZ;
//TODO Why bots are not being detected?
boolean areRoomUnitsAtTile = this.room.getRoomUnitManager().areRoomUnitsAt(tile); boolean areRoomUnitsAtTile = this.room.getRoomUnitManager().areRoomUnitsAt(tile);
boolean isAboveMaximumStepHeight = (!RoomLayout.ALLOW_FALLING && heightDifference < -RoomLayout.MAXIMUM_STEP_HEIGHT); boolean isAboveMaximumStepHeight = (!RoomLayout.ALLOW_FALLING && heightDifference < -RoomLayout.MAXIMUM_STEP_HEIGHT);
boolean isOpenTileAboveMaxHeight = (tile.getState() == RoomTileState.OPEN && heightDifference > RoomLayout.MAXIMUM_STEP_HEIGHT); boolean isOpenTileAboveMaxHeight = (tile.getState() == RoomTileState.OPEN && heightDifference > RoomLayout.MAXIMUM_STEP_HEIGHT);

View File

@ -18,7 +18,9 @@ public class RoomPet extends RoomUnit {
} }
@Override @Override
public void cycle() {} public void cycle() {
super.cycle();
}
public boolean handleRider(Pet pet, Room room) { public boolean handleRider(Pet pet, Room room) {
Habbo rider = null; Habbo rider = null;

View File

@ -1,6 +1,5 @@
package com.eu.habbo.messages.incoming.rooms.bots; package com.eu.habbo.messages.incoming.rooms.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.rooms.Room; import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.messages.incoming.MessageHandler; import com.eu.habbo.messages.incoming.MessageHandler;
@ -23,6 +22,6 @@ public class PlaceBotEvent extends MessageHandler {
int x = this.packet.readInt(); int x = this.packet.readInt();
int y = this.packet.readInt(); int y = this.packet.readInt();
Emulator.getGameEnvironment().getBotManager().placeBot(bot, this.client.getHabbo(), room, room.getLayout().getTile((short) x, (short) y)); room.getRoomUnitManager().placeBot(bot, this.client.getHabbo(), x, y);
} }
} }

View File

@ -19,8 +19,6 @@ public class MoveAvatarEvent extends MessageHandler {
int x = this.packet.readInt(); int x = this.packet.readInt();
int y = this.packet.readInt(); int y = this.packet.readInt();
log.info("CLICKED ON TILE [x]: {} [y]: {}", x, y);
Habbo habbo = this.client.getHabbo(); Habbo habbo = this.client.getHabbo();
if(habbo == null) { if(habbo == null) {